ftp.nice.ch/Attic/openStep/games/Empire.0.6.m.NIS.bs.tgz#/Empire.0.6/src/Human.subproj/HCombatReportState.m

This is HCombatReportState.m in view mode; [Download] [Up]

//
// $Id: HCombatReportState.m,v 1.2 1997/10/31 03:38:00 nygard Exp $
//

//
//  This file is a part of Empire, a game of exploration and conquest.
//  Copyright (C) 1996  Steve Nygard
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//  You may contact the author by:
//     e-mail:  nygard@telusplanet.net
//

#import "Empire.h"

RCSID ("$Id: HCombatReportState.m,v 1.2 1997/10/31 03:38:00 nygard Exp $");

#import "HCombatReportState.h"

#import "Brain.h"
#import "CombatEvent.h"
#import "Human.h"
#import "Map.h"
#import "MapView.h"

//======================================================================
// Show the map as it was at the end of the previous turn, and then
// replay the combat events (with a delay between each) that occurred
// while this player was idle.
//======================================================================

@implementation HCombatReportState

- initWithGameManager:(GameManager *)theGameManager
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [super initWithGameManager:theGameManager];

    eventEnumerator = nil;
    currentMap = nil;
    eventTimer = nil;
    debugCombatEvents = [defaults boolForKey:DK_DebugCombatEvents];
    counter = 0;

    return self;
}

//======================================================================
// Subclass responsibilities
//======================================================================

- (NSString *) stateName
{
    return @"Combat Report";
}
  
//----------------------------------------------------------------------

- (NSString *) stateKey
{
    return HS_COMBAT_REPORT;
}
  
//----------------------------------------------------------------------

- (void) stateEntered:(Human *)context
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    MapView *mapView = [context mapView];

    // Set cursor
    [mapView setCursorEnabled:NO];
    [context setStatusLine:@""];

    // Disable both buttons
    [context enableContinueButton:NO];
    [context enableEndTurnButton:NO];

    currentMap = [[[context savedMap] copyWithZone:[self zone]] autorelease];
    [mapView setMap:currentMap];

    eventEnumerator = [[[context combatEvents] objectEnumerator] retain];

    counter = 0;

    // Set up timer
    eventTimer = [[NSTimer scheduledTimerWithTimeInterval:[defaults floatForKey:@"CombatEventDelay"]
                           target:self
                           selector:@selector (showNextCombatEvent:)
                           userInfo:context
                           repeats:YES] retain];

    NSAssert (eventTimer != nil, @"Event timer is nil.");
}

//======================================================================
// Other
//======================================================================

- (void) showNextCombatEvent:(NSTimer *)aTimer
{
    Human *context = [aTimer userInfo];
    MapView *mapView = [context mapView];
    CombatEvent *combatEvent;

    NSAssert (eventEnumerator != nil, @"enumerator was nil");

    combatEvent = [eventEnumerator nextObject];

    if (combatEvent != nil)
    {
        // show it
        [combatEvent replayCombatFor:currentMap in:mapView];
        if (debugCombatEvents == YES)
        {
            [context setStatusLine:[NSString stringWithFormat:@"[%3d]: %@", counter++, [combatEvent description]]];
        }
    }
    else
    {
        // stop timer
        [eventTimer invalidate];
        SNRelease (eventTimer);

        // release enumerator
        SNRelease (eventEnumerator);

        // restore map
        [mapView setMap:[context map]];

        [context restoreState];
    }
}
  
@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.