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

This is GameManager.h in view mode; [Download] [Up]

//
// $Id: GameManager.h,v 1.12 1997/10/31 05:44:21 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 <AppKit/AppKit.h>
#import <Foundation/NSConnection.h>
#import "Empire.h"
#import "EmpireProtocols.h"

@class City;
@class EmPlayer;
@class Human;
@class Map;
@class ShipReportController;
@class StatusController;
@class Unit;
@class WarReportController;
@class World;

typedef enum _GameState
{
    gs_no_game,
    gs_establishing_game,
    gs_client_active,
    gs_player1_turn,
    gs_player2_turn,
    gs_player3_turn,
    gs_game_over
} GameState;

#define ADJ_PLAYER1 0x01
#define ADJ_PLAYER2 0x02
#define ADJ_PLAYER3 0x04

NSString *NSStringFromGameState (GameState state);

#define AGSReason(state1) [NSString stringWithFormat:@"Current game state is (%@).  Expected game state to be %@.", NSStringFromGameState (gameState), NSStringFromGameState (state1)]

#define AssertGameState(state1) NSAssert1 (gameState == state1, @"%@", AGSReason (state1))
#define AssertNotGameState(state1) NSAssert1 (gameState != state1, @"%@", AGSReason (state1))

//======================================================================

@interface GameManager : NSObject
{
    //----------------------------------------
    // General window management/user interface stuff.
    //----------------------------------------
    StatusController *gameStatusController;
    WarReportController *warReportController;
    ShipReportController *shipReportController;

    //IBOutlet NSWindow *wizardWindow;
    //id wizardController;

    BOOL berserk;

    //----------------------------------------
    // World information (part of establishing a game)
    //----------------------------------------
    World *world;
    
    //----------------------------------------
    // Game Establishment:
    //----------------------------------------
    int activePlayerCount;
    EmPlayer *players[4];
    BOOL playersActive[4]; // Only master game manager should use this.

    //----------------------------------------
    // Game state:
    //----------------------------------------
    int currentTurn;
    GameState gameState;

    //----------------------------------------
    // Revised turn handling:
    //----------------------------------------
    NSNumber *awaitingCookie;

    //----------------------------------------
    // Combat
    //----------------------------------------

    Unit *attackingUnit;
    Unit *defendingUnit;
    City *defendingCity;

    // By storing them here, it is independent of releasing the finished players...
    // In distributed games, only used by the server.
    Map *finalMaps[4];
}

+ (void) initialize;

- init;
- (void) dealloc;

//======================================================================
// Interface Managment
//======================================================================

- (void) showWarReport:sender forPlayer:(EmPlayer *)player;
- (void) showShipReport:sender forPlayer:(EmPlayer *)player;

//======================================================================
// Debugging
//======================================================================

- (void) showCrystalBall:sender;
- (void) removeCrystalBall:sender;
- (void) setBerserk:(BOOL)flag;
- (BOOL) isBerserk;
- (void) toggleBerserk:sender;

//======================================================================
// Menu Actions
//======================================================================

//======================================================================
// World Information
//======================================================================

- (int) worldCityCount;
- (City *) randomNeutralCity;

//======================================================================
// Establish Game
//======================================================================

- (void) startGameWithMapNamed:(NSString *)mapName;
- (BOOL) addPlayer:(Player)number name:(NSString *)name type:(NSString *)playerType withEfficiencies:(int)pe:(int)ce;
- (void) beginGame;
- (void) tryToStart;
- (void) stopGame;
- (void) gameHasStopped:(Player)number activePlayers:(int)activePlayers;
- (void) gameOver;

//======================================================================
// Game State
//======================================================================

- (int) turnNumber;
- (BOOL) gameInProgress;

//======================================================================
// Turn Handling
//======================================================================

- (Player) nextPlayerTurn;
- (void) turnDone:(NSNumber *)aCookie;

//======================================================================
// Movement and combat
//======================================================================

- (MoveResult) moveUnit:(Unit *)thisUnit inDirection:(Direction)dir;

//======================================================================
// Map access/management
//======================================================================

// Methods to be overridden in subclasses (DGM)
- (Map *) mapForPlayer:(Player)number;
- (Map *) fetchMapForPlayer:(Player)number;
- (void) set3x3Tokens:(MapToken *)tokens aroundLocation:(EMMapLocation)target forPlayer:(Player)number;
- (void) remove:(Icon)icon atLocation:(EMMapLocation)target forPlayer:(Player)number;
- (void) put:(Icon)icon atLocation:(EMMapLocation)target forPlayer:(Player)number;
- (void) setCityAtLocation:(EMMapLocation)target toPlayer:(Player)newCityPlayer forPlayer:(Player)number;

//======================================================================
// Etc.
//======================================================================

- (MapToken) canonTokenAtLocation:(EMMapLocation)target;
- (int) playersAdjacentToLocation:(EMMapLocation)target;
- (void) explorePlayer:(Player)number around3x3Location:(EMMapLocation)target updateOtherPlayers:(BOOL)flag;

- (void) get3x3flags:(int *)flags forPlayer:(Player)number aroundLocation:(EMMapLocation)target;

//======================================================================
// Combating...
//======================================================================

- (MoveResult) unit:(Unit *)attacker attacksPlayer:(Player)cityPlayer cityAtLocation:(EMMapLocation)target;

- (MoveResult) unitWithCombatProfile:(CombatProfile)attackerProfile
                       attacksPlayer:(Player)cityPlayer
                      cityAtLocation:(EMMapLocation)target
           playersAdjacentToDefender:(int)adjacentPlayers;

- (MoveResult) unit:(Unit *)attacker
      attacksPlayer:(Player)defender
     unitAtLocation:(EMMapLocation)target
    withBombardment:(BOOL)bombarding;

- (MoveResult) unitWithCombatProfile:(CombatProfile)attackerProfile
                       attacksPlayer:(Player)defender
                      unitAtLocation:(EMMapLocation)target
                     withBombardment:(BOOL)bombarding
           playersAdjacentToDefender:(int)adjacentPlayers;

- (MoveResult) attackerWithCombatProfile:(CombatProfile)attackerProfile
        attacksDefenderWithCombatProfile:(CombatProfile)defenderProfile;


- (CombatProfile) readyDefendingCityAtLocation:(EMMapLocation)target forPlayer:(Player)number;
- (CombatProfile) readyDefendingUnitAtLocation:(EMMapLocation)target forPlayer:(Player)number againstBombardment:(BOOL)bombarding;

- (void) showExplosions:(int)count atLocation:(EMMapLocation)target toPlayers:(int)playerMask;
- (void) showExplosions:(int)count forPlayer:(Player)number atLocation:(EMMapLocation)target;

- (void) hitDefendingUnit:(Player)number withDamage:(int)damage;
- (City *) lostDefendingCityOfPlayer:(Player)number;
- (void) hitAttacker:(Player)number withDamage:(int)damage;

- (void) player:(Player)number hasCapturedCity:(City *)capturedCity;
- (void) finishedCombatForPlayer:(Player)number;

- (BOOL) checkForEndOfPlayer:(Player)number;
- (BOOL) hasPlayerLost:(Player)number;
- (void) playerHasLost:(Player)number activePlayers:(int)activePlayers;
- (BOOL) playerHasWon:(Player)number activePlayers:(int)activePlayers;




- (void) resignPlayerFromGame:(Player)number;
- (int) activePlayers;

- (void) notifyPlayer:(Player)number aPlayerHasResigned:(Player)resignedPlayer;

- (Player) activePlayer; //Needed? Yes.

- (NSArray *) remainingCitiesForPlayer:(Player)number;

- (void) deactivatePlayer:(Player)number;

- (void) playerHasResigned:(Player)number activePlayers:(int)activePlayers;

- (void) storeFinalMapForPlayer:(Player)number;
- (Map *) finalMapForPlayer:(Player)number;

- (void) logStatus;

- (void) theGameIsOver;

//----------------------------------------------------------------------
// Game Status support
//----------------------------------------------------------------------

- (NSString *) gameStatus;
- (NSDictionary *) playerStatus:(Player)number;

- (void) setGameState:(GameState)gameState;

- (BOOL) validateMenuItem:(NSMenuItem *)menuCell;

@end

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