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

  1. //
  2. // $Id: DistributedGameManager.h,v 1.6 1997/10/31 05:44:19 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 "GameManager.h"
  30.  
  31. //======================================================================
  32.  
  33. @interface DistributedGameManager : GameManager <EmpireGameManagerProtocol>
  34. {
  35.     // Client:
  36.     DistributedGameManager *master;
  37.     NSConnection *masterConnection;
  38.     Player clientPlayer;
  39.  
  40.     // Server
  41.     DistributedGameManager *playerManagers[4];
  42.     NSConnection *clientConnections[4];
  43.     int unreadyRemotePlayers; // Accessed by different threads?
  44.  
  45.     // Both, but the server has a bit different semantics
  46.     Map *cachedMaps[4]; // Just a reference to part of a player.
  47. }
  48.  
  49. + (void) initialize;
  50.  
  51. - init;
  52. - (void) dealloc;
  53.  
  54. //======================================================================
  55. // Empire Game Manager Protocol
  56. //======================================================================
  57.  
  58. - (void) ping;
  59. - (void) aboutToDisconnect:sender;
  60. - (void) peer:clientGameManager forPlayer:(Player)number;
  61. - (Map *) remoteFetchMapForPlayer:(Player)number;
  62. - (void) otherMaps:(Map *)map1:(Map *)map2 forPlayer:(Player)number;
  63.  
  64. - (void) remoteUpdateMapAroundCitiesForPlayer:(Player)number;
  65.  
  66. - (void) remoteTurn:(int)turn withCookie:(NSNumber *)aCookie forPlayer:(Player)number;
  67. - (void) remoteTurnDone:(NSNumber *)aCookie forPlayer:(Player)number updatedMap:(Map *)newMap;
  68.  
  69. //======================================================================
  70. // Establish Game
  71. //======================================================================
  72.  
  73. - (void) startGameWithMapNamed:(NSString *)mapName;
  74. - (void) tryToStart;
  75. - (void) stopGame;
  76. - (void) startGameWithMap:(Map *)worldMap master:masterGameManager;
  77. - (void) addRemotePlayer:(Player)number forClient:remoteClient;
  78. - (void) notifyMasterForPlayer:(Player)number;
  79. - (void) distributeMaps;
  80.  
  81. //======================================================================
  82. // Turn Handling
  83. //======================================================================
  84.  
  85. - (void) turnDone:(NSNumber *)aCookie;
  86.  
  87. // Here???
  88. - (void) distributeMapsToRemotePlayer:(Player)p;
  89.  
  90. //======================================================================
  91. // Empire Game Manager Protocol:
  92. //======================================================================
  93.  
  94. //----------------------------------------------------------------------
  95. // Game Initialization / Termination
  96. //----------------------------------------------------------------------
  97.  
  98. - (City *) remoteRandomNeutralCity;
  99. - (void) remoteGameHasStopped:(Player)number activePlayers:(int)activePlayers;
  100.  
  101. //----------------------------------------------------------------------
  102. // Combat Support
  103. //----------------------------------------------------------------------
  104.  
  105. - (void) remoteSet3x3Tokens:(struct NineTokens)tokens aroundLocation:(EMMapLocation)target forPlayer:(Player)number;
  106. - (void) remoteSetToken:(MapToken)token atLocation:(EMMapLocation)target forPlayer:(Player)number;
  107.  
  108. - (MoveResult) remoteUnitWithCombatProfile:(CombatProfile)attackerProfile
  109.                              attacksPlayer:(Player)cityPlayer
  110.                             cityAtLocation:(EMMapLocation)target
  111.                  playersAdjacentToDefender:(int)adjacentPlayers;
  112.  
  113. - (MoveResult) remoteUnitWithCombatProfile:(CombatProfile)attackerProfile
  114.                              attacksPlayer:(Player)defender
  115.                             unitAtLocation:(EMMapLocation)target
  116.                            withBombardment:(BOOL)bombarding
  117.                  playersAdjacentToDefender:(int)adjacentPlayers;
  118.  
  119. - (CombatProfile) remoteReadyDefendingCityAtLocation:(EMMapLocation)target forPlayer:(Player)number;
  120. - (CombatProfile) remoteReadyDefendingUnitAtLocation:(EMMapLocation)target
  121.                                            forPlayer:(Player)number
  122.                                   againstBombardment:(BOOL)bombarding;
  123. - (void) remoteShowExplosions:(int)count forPlayer:(Player)number atLocation:(EMMapLocation)target;
  124. - (void) remoteHitDefendingUnit:(Player)number withDamage:(int)damage;
  125. - (City *) remoteLostDefendingCityOfPlayer:(Player)number;
  126. - (void) remoteHitAttacker:(Player)number withDamage:(int)damage;
  127. - (void) remotePlayer:(Player)number hasCapturedCity:(City *)capturedCity;
  128. - (void) remoteFinishedCombatForPlayer:(Player)number;
  129.  
  130. - (BOOL) remoteCheckForEndOfPlayer:(Player)number;
  131. - (BOOL) remoteHasPlayerLost:(Player)number;
  132. - (void) remotePlayerHasLost:(Player)number activePlayers:(int)activePlayers;
  133. - (BOOL) remotePlayerHasWon:(Player)number activePlayers:(int)activePlayers;
  134.  
  135. //----------------------------------------------------------------------
  136. // Methods that may communicate with remote game managers:
  137. //----------------------------------------------------------------------
  138.  
  139. - (void) gameHasStopped:(Player)number activePlayers:(int)activePlayers;
  140. - (void) set3x3Tokens:(MapToken *)tokens aroundLocation:(EMMapLocation)target forPlayer:(Player)number;
  141.  
  142. - (City *) randomNeutralCity;
  143.  
  144. - (MoveResult) unitWithCombatProfile:(CombatProfile)attackerProfile
  145.                        attacksPlayer:(Player)cityPlayer
  146.                       cityAtLocation:(EMMapLocation)target
  147.            playersAdjacentToDefender:(int)adjacentPlayers;
  148.  
  149. - (MoveResult) unitWithCombatProfile:(CombatProfile)attackerProfile
  150.                        attacksPlayer:(Player)defender
  151.                       unitAtLocation:(EMMapLocation)target
  152.                      withBombardment:(BOOL)bombarding
  153.            playersAdjacentToDefender:(int)adjacentPlayers;
  154.  
  155. - (CombatProfile) readyDefendingCityAtLocation:(EMMapLocation)target forPlayer:(Player)number;
  156. - (CombatProfile) readyDefendingUnitAtLocation:(EMMapLocation)target forPlayer:(Player)number againstBombardment:(BOOL)bombarding;
  157. - (void) showExplosions:(int)count forPlayer:(Player)number atLocation:(EMMapLocation)target;
  158. - (void) hitDefendingUnit:(Player)number withDamage:(int)damage;
  159. - (City *) lostDefendingCityOfPlayer:(Player)number;
  160. - (void) hitAttacker:(Player)number withDamage:(int)damage;
  161. - (void) player:(Player)number hasCapturedCity:(City *)capturedCity;
  162. - (void) finishedCombatForPlayer:(Player)number;
  163.  
  164. - (BOOL) checkForEndOfPlayer:(Player)number;
  165. - (BOOL) hasPlayerLost:(Player)number;
  166. - (void) playerHasLost:(Player)number activePlayers:(int)activePlayers;
  167. - (BOOL) playerHasWon:(Player)number activePlayers:(int)activePlayers;
  168.  
  169. //======================================================================
  170.  
  171. - (Map *) mapForPlayer:(Player)number;
  172. - (Map *) fetchMapForPlayer:(Player)number;
  173. - (void) set3x3Tokens:(MapToken *)tokens aroundLocation:(EMMapLocation)target forPlayer:(Player)number;
  174. - (void) setToken:(MapToken)token atLocation:(EMMapLocation)target forPlayer:(Player)number;
  175.  
  176. - (void) remove:(Icon)icon atLocation:(EMMapLocation)target forPlayer:(Player)number;
  177. - (void) put:(Icon)icon atLocation:(EMMapLocation)target forPlayer:(Player)number;
  178. - (void) setCityAtLocation:(EMMapLocation)target toPlayer:(Player)newCityPlayer forPlayer:(Player)number;
  179.  
  180.  
  181.  
  182. - (void) remoteUpdateMapAroundCitiesForPlayer:(Player)number;
  183. - (void) updateMapAroundCitiesForPlayer:(Player)number;
  184.  
  185. - (void) connectionDidDie:(NSNotification *)notification;
  186.  
  187.  
  188. - (void) remoteResignPlayerFromGame:(Player)number;
  189. - (void) resignPlayerFromGame:(Player)number;
  190.  
  191. - (NSArray *) remoteRemainingCitiesForPlayer:(Player)number;
  192. - (NSArray *) remainingCitiesForPlayer:(Player)number;
  193.  
  194.  
  195. - (void) deactivatePlayer:(Player)number;
  196.  
  197. - (void) remotePlayerHasResigned:(Player)number activePlayers:(int)activePlayers;
  198. - (void) playerHasResigned:(Player)number activePlayers:(int)activePlayers;
  199.  
  200. - (Map *) remoteFinalMapForPlayer:(Player)number;
  201. - (Map *) finalMapForPlayer:(Player)number;
  202.  
  203. - (void) remoteNotifyPlayer:(Player)number aPlayerHasResigned:(Player)resignedPlayer;
  204. - (void) notifyPlayer:(Player)number aPlayerHasResigned:(Player)resignedPlayer;
  205.  
  206. - (void) logStatus;
  207.  
  208. @end
  209.