home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Games / Empire-0.6-MIS / GameManager.h < prev    next >
Encoding:
Text File  |  1997-10-31  |  9.5 KB  |  282 lines

  1. //
  2. // $Id: GameManager.h,v 1.12 1997/10/31 05:44:21 nygard Exp $
  3. //
  4.  
  5. //
  6. //  This file is a part of Empire, a game of exploration and conquest.
  7. //  Copyright (C) 1996  Steve Nygard
  8. //
  9. //  This program is free software; you can redistribute it and/or modify
  10. //  it under the terms of the GNU General Public License as published by
  11. //  the Free Software Foundation; either version 2 of the License, or
  12. //  (at your option) any later version.
  13. //
  14. //  This program is distributed in the hope that it will be useful,
  15. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. //  GNU General Public License for more details.
  18. //
  19. //  You should have received a copy of the GNU General Public License
  20. //  along with this program; if not, write to the Free Software
  21. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. //
  23. //  You may contact the author by:
  24. //     e-mail:  nygard@telusplanet.net
  25. //
  26.  
  27. #import <AppKit/AppKit.h>
  28. #import <Foundation/NSConnection.h>
  29. #import "Empire.h"
  30. #import "EmpireProtocols.h"
  31.  
  32. @class City;
  33. @class EmPlayer;
  34. @class Human;
  35. @class Map;
  36. @class ShipReportController;
  37. @class StatusController;
  38. @class Unit;
  39. @class WarReportController;
  40. @class World;
  41.  
  42. typedef enum _GameState
  43. {
  44.     gs_no_game,
  45.     gs_establishing_game,
  46.     gs_client_active,
  47.     gs_player1_turn,
  48.     gs_player2_turn,
  49.     gs_player3_turn,
  50.     gs_game_over
  51. } GameState;
  52.  
  53. #define ADJ_PLAYER1 0x01
  54. #define ADJ_PLAYER2 0x02
  55. #define ADJ_PLAYER3 0x04
  56.  
  57. NSString *NSStringFromGameState (GameState state);
  58.  
  59. #define AGSReason(state1) [NSString stringWithFormat:@"Current game state is (%@).  Expected game state to be %@.", NSStringFromGameState (gameState), NSStringFromGameState (state1)]
  60.  
  61. #define AssertGameState(state1) NSAssert1 (gameState == state1, @"%@", AGSReason (state1))
  62. #define AssertNotGameState(state1) NSAssert1 (gameState != state1, @"%@", AGSReason (state1))
  63.  
  64. //======================================================================
  65.  
  66. @interface GameManager : NSObject
  67. {
  68.     //----------------------------------------
  69.     // General window management/user interface stuff.
  70.     //----------------------------------------
  71.     StatusController *gameStatusController;
  72.     WarReportController *warReportController;
  73.     ShipReportController *shipReportController;
  74.  
  75.     //IBOutlet NSWindow *wizardWindow;
  76.     //id wizardController;
  77.  
  78.     BOOL berserk;
  79.  
  80.     //----------------------------------------
  81.     // World information (part of establishing a game)
  82.     //----------------------------------------
  83.     World *world;
  84.     
  85.     //----------------------------------------
  86.     // Game Establishment:
  87.     //----------------------------------------
  88.     int activePlayerCount;
  89.     EmPlayer *players[4];
  90.     BOOL playersActive[4]; // Only master game manager should use this.
  91.  
  92.     //----------------------------------------
  93.     // Game state:
  94.     //----------------------------------------
  95.     int currentTurn;
  96.     GameState gameState;
  97.  
  98.     //----------------------------------------
  99.     // Revised turn handling:
  100.     //----------------------------------------
  101.     NSNumber *awaitingCookie;
  102.  
  103.     //----------------------------------------
  104.     // Combat
  105.     //----------------------------------------
  106.  
  107.     Unit *attackingUnit;
  108.     Unit *defendingUnit;
  109.     City *defendingCity;
  110.  
  111.     // By storing them here, it is independent of releasing the finished players...
  112.     // In distributed games, only used by the server.
  113.     Map *finalMaps[4];
  114. }
  115.  
  116. + (void) initialize;
  117.  
  118. - init;
  119. - (void) dealloc;
  120.  
  121. //======================================================================
  122. // Interface Managment
  123. //======================================================================
  124.  
  125. - (void) showWarReport:sender forPlayer:(EmPlayer *)player;
  126. - (void) showShipReport:sender forPlayer:(EmPlayer *)player;
  127.  
  128. //======================================================================
  129. // Debugging
  130. //======================================================================
  131.  
  132. - (void) showCrystalBall:sender;
  133. - (void) removeCrystalBall:sender;
  134. - (void) setBerserk:(BOOL)flag;
  135. - (BOOL) isBerserk;
  136. - (void) toggleBerserk:sender;
  137.  
  138. //======================================================================
  139. // Menu Actions
  140. //======================================================================
  141.  
  142. //======================================================================
  143. // World Information
  144. //======================================================================
  145.  
  146. - (int) worldCityCount;
  147. - (City *) randomNeutralCity;
  148.  
  149. //======================================================================
  150. // Establish Game
  151. //======================================================================
  152.  
  153. - (void) startGameWithMapNamed:(NSString *)mapName;
  154. - (BOOL) addPlayer:(Player)number name:(NSString *)name type:(NSString *)playerType withEfficiencies:(int)pe:(int)ce;
  155. - (void) beginGame;
  156. - (void) tryToStart;
  157. - (void) stopGame;
  158. - (void) gameHasStopped:(Player)number activePlayers:(int)activePlayers;
  159. - (void) gameOver;
  160.  
  161. //======================================================================
  162. // Game State
  163. //======================================================================
  164.  
  165. - (int) turnNumber;
  166. - (BOOL) gameInProgress;
  167.  
  168. //======================================================================
  169. // Turn Handling
  170. //======================================================================
  171.  
  172. - (Player) nextPlayerTurn;
  173. - (void) turnDone:(NSNumber *)aCookie;
  174.  
  175. //======================================================================
  176. // Movement and combat
  177. //======================================================================
  178.  
  179. - (MoveResult) moveUnit:(Unit *)thisUnit inDirection:(Direction)dir;
  180.  
  181. //======================================================================
  182. // Map access/management
  183. //======================================================================
  184.  
  185. // Methods to be overridden in subclasses (DGM)
  186. - (Map *) mapForPlayer:(Player)number;
  187. - (Map *) fetchMapForPlayer:(Player)number;
  188. - (void) set3x3Tokens:(MapToken *)tokens aroundLocation:(EMMapLocation)target forPlayer:(Player)number;
  189. - (void) remove:(Icon)icon atLocation:(EMMapLocation)target forPlayer:(Player)number;
  190. - (void) put:(Icon)icon atLocation:(EMMapLocation)target forPlayer:(Player)number;
  191. - (void) setCityAtLocation:(EMMapLocation)target toPlayer:(Player)newCityPlayer forPlayer:(Player)number;
  192.  
  193. //======================================================================
  194. // Etc.
  195. //======================================================================
  196.  
  197. - (MapToken) canonTokenAtLocation:(EMMapLocation)target;
  198. - (int) playersAdjacentToLocation:(EMMapLocation)target;
  199. - (void) explorePlayer:(Player)number around3x3Location:(EMMapLocation)target updateOtherPlayers:(BOOL)flag;
  200.  
  201. - (void) get3x3flags:(int *)flags forPlayer:(Player)number aroundLocation:(EMMapLocation)target;
  202.  
  203. //======================================================================
  204. // Combating...
  205. //======================================================================
  206.  
  207. - (MoveResult) unit:(Unit *)attacker attacksPlayer:(Player)cityPlayer cityAtLocation:(EMMapLocation)target;
  208.  
  209. - (MoveResult) unitWithCombatProfile:(CombatProfile)attackerProfile
  210.                        attacksPlayer:(Player)cityPlayer
  211.                       cityAtLocation:(EMMapLocation)target
  212.            playersAdjacentToDefender:(int)adjacentPlayers;
  213.  
  214. - (MoveResult) unit:(Unit *)attacker
  215.       attacksPlayer:(Player)defender
  216.      unitAtLocation:(EMMapLocation)target
  217.     withBombardment:(BOOL)bombarding;
  218.  
  219. - (MoveResult) unitWithCombatProfile:(CombatProfile)attackerProfile
  220.                        attacksPlayer:(Player)defender
  221.                       unitAtLocation:(EMMapLocation)target
  222.                      withBombardment:(BOOL)bombarding
  223.            playersAdjacentToDefender:(int)adjacentPlayers;
  224.  
  225. - (MoveResult) attackerWithCombatProfile:(CombatProfile)attackerProfile
  226.         attacksDefenderWithCombatProfile:(CombatProfile)defenderProfile;
  227.  
  228.  
  229. - (CombatProfile) readyDefendingCityAtLocation:(EMMapLocation)target forPlayer:(Player)number;
  230. - (CombatProfile) readyDefendingUnitAtLocation:(EMMapLocation)target forPlayer:(Player)number againstBombardment:(BOOL)bombarding;
  231.  
  232. - (void) showExplosions:(int)count atLocation:(EMMapLocation)target toPlayers:(int)playerMask;
  233. - (void) showExplosions:(int)count forPlayer:(Player)number atLocation:(EMMapLocation)target;
  234.  
  235. - (void) hitDefendingUnit:(Player)number withDamage:(int)damage;
  236. - (City *) lostDefendingCityOfPlayer:(Player)number;
  237. - (void) hitAttacker:(Player)number withDamage:(int)damage;
  238.  
  239. - (void) player:(Player)number hasCapturedCity:(City *)capturedCity;
  240. - (void) finishedCombatForPlayer:(Player)number;
  241.  
  242. - (BOOL) checkForEndOfPlayer:(Player)number;
  243. - (BOOL) hasPlayerLost:(Player)number;
  244. - (void) playerHasLost:(Player)number activePlayers:(int)activePlayers;
  245. - (BOOL) playerHasWon:(Player)number activePlayers:(int)activePlayers;
  246.  
  247.  
  248.  
  249.  
  250. - (void) resignPlayerFromGame:(Player)number;
  251. - (int) activePlayers;
  252.  
  253. - (void) notifyPlayer:(Player)number aPlayerHasResigned:(Player)resignedPlayer;
  254.  
  255. - (Player) activePlayer; //Needed? Yes.
  256.  
  257. - (NSArray *) remainingCitiesForPlayer:(Player)number;
  258.  
  259. - (void) deactivatePlayer:(Player)number;
  260.  
  261. - (void) playerHasResigned:(Player)number activePlayers:(int)activePlayers;
  262.  
  263. - (void) storeFinalMapForPlayer:(Player)number;
  264. - (Map *) finalMapForPlayer:(Player)number;
  265.  
  266. - (void) logStatus;
  267.  
  268. - (void) theGameIsOver;
  269.  
  270. //----------------------------------------------------------------------
  271. // Game Status support
  272. //----------------------------------------------------------------------
  273.  
  274. - (NSString *) gameStatus;
  275. - (NSDictionary *) playerStatus:(Player)number;
  276.  
  277. - (void) setGameState:(GameState)gameState;
  278.  
  279. - (BOOL) validateMenuItem:(NSMenuItem *)menuCell;
  280.  
  281. @end
  282.