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

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

//
// $Id: WarReportController.m,v 1.7 1997/10/31 04:52:12 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: WarReportController.m,v 1.7 1997/10/31 04:52:12 nygard Exp $");

#import "WarReportController.h"

#import "EmpireImageVendor.h"
#import "EmPlayer.h"
#import "Unit.h"

//======================================================================
// The War Report provides a summary of the number of units in combat,
// lost by this player, destroyed by this player, under construction and
// the number of turns before the soonest unit of each type is produced.
//
// It also shows the number of cities controlled by this player, the
// total number of cities in the world, and the percent of the world
// that has been explored.
//
// It's a modal panel, since it is shared among players and so that we
// don't have to dynamically updated the statistics.
//======================================================================

#define WarReportController_VERSION 1

@implementation WarReportController

+ (void) initialize
{
    if (self == [WarReportController class])
    {
        [self setVersion:WarReportController_VERSION];
    }
}

//----------------------------------------------------------------------

- (void) awakeFromNib
{
    [self setPlayer:p_neutral];
    [[EmpireImageVendor instance] attach:self];
}

//----------------------------------------------------------------------

- init
{
    NSString *nibFile;
    BOOL loaded, okay;

    [super init];

    lastPlayer = p_neutral;

    nibFile = @"WarReport.nib";
    loaded = [NSBundle loadNibNamed:nibFile owner:self];
    if (loaded == NO)
    {
        NSLog (@"Could not load %@.", nibFile);
        [super dealloc];
        return nil;
    }

    okay = [warReportWindow setFrameAutosaveName:[warReportWindow title]];
    if (okay == NO)
        NSLog (@"Could not set frame autosave name of War Report window.");

    return self;
}

//----------------------------------------------------------------------

- (void) dealloc
{
    [[EmpireImageVendor instance] detach:self];

    [super dealloc];
}

//----------------------------------------------------------------------

- (void) warReportForPlayer:(EmPlayer *)player
{
    WarStatistics stats;
    int l;

    [warReportWindow disableFlushWindow];

    [self setPlayer:[player playerNumber]];

    stats = [player warStatistics];

    [cityCountText setIntValue:stats.city_count];
    [cityTotalCountText setIntValue:stats.world_city_count];
    [percentExploredText setStringValue:[NSString stringWithFormat:@"%d %%", stats.percent_explored]];

    for (l = 1; l < UNIT_TYPE_COUNT; l++)
    {
        [[underConstructionMatrix cellAtRow:l - 1 column:0] setIntValue:stats.under_construction[l]];
        if (stats.under_construction[l] > 0)
            [[soonestCompleteMatrix cellAtRow:l - 1 column:0] setIntValue:stats.soonest_complete[l]];
        else
            [[soonestCompleteMatrix cellAtRow:l - 1 column:0] setStringValue:@"--"];
      
        [[inCombatMatrix cellAtRow:l - 1 column:0] setIntValue:stats.in_combat[l]];
        [[destroyedMatrix cellAtRow:l - 1 column:0] setIntValue:stats.destroyed_units[l]];
        [[lostMatrix cellAtRow:l - 1 column:0] setIntValue:stats.lost_units[l]];
    }

    [warReportWindow enableFlushWindow];

    [warReportWindow makeKeyAndOrderFront:self];
    [NSApp runModalForWindow:warReportWindow];
}

//----------------------------------------------------------------------

- (void) vendorImagesUpdated:(BOOL)player1:(BOOL)player2:(BOOL)player3:(BOOL)other
{
    [cityButton setNeedsDisplay:YES];
    [unitImageMatrix setNeedsDisplay:YES];
}

//----------------------------------------------------------------------
// Update the images if the player number has changed.
//----------------------------------------------------------------------

- (void) setPlayer:(Player)playerNumber
{
    if (lastPlayer != playerNumber)
    {
        EmpireImageVendor *vendor;
        int l;
        NSImage *city;
        NSImage **onLand;
        NSImage **onWater;
        NSImage **onCity;
        int loop_to_land[2] = {0, 2};
        int loop_to_water[7] = {1, 3, 4, 5, 6, 8, 9};

        lastPlayer = playerNumber;

        vendor = [EmpireImageVendor instance];

        [vendor player:playerNumber:&city:&onLand:&onWater:&onCity:NULL];
    
        [cityButton setImage:city];
        for (l = 0; l < 2; l++)
            [[unitImageMatrix cellAtRow:l column:0] setImage:onLand[loop_to_land[l]]];
        for (l = 0; l < 7; l++)
            [[unitImageMatrix cellAtRow:l+2 column:0] setImage:onWater[loop_to_water[l]]];

        [cityButton setNeedsDisplay:YES];
        [unitImageMatrix setNeedsDisplay:YES];
    } 
}

//----------------------------------------------------------------------

- (void) warReportStopAction:sender
{
    [NSApp stopModal];
    [warReportWindow orderOut:self]; 
}

@end

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