26 |
#include <Foundation/NSException.h> |
#include <Foundation/NSException.h> |
27 |
#include <Foundation/NSCoder.h> |
#include <Foundation/NSCoder.h> |
28 |
#include <Foundation/NSValue.h> |
#include <Foundation/NSValue.h> |
29 |
|
#include <Foundation/NSNotification.h> |
30 |
|
|
31 |
#include "GameEngine/HgGame.h" |
#include "GameEngine/HgGame.h" |
32 |
#include "GameEngine/HgPlayer.h" |
#include "GameEngine/HgPlayer.h" |
102 |
|
|
103 |
/** |
/** |
104 |
* Add player to the current game. The player mustn't be already in game. |
* Add player to the current game. The player mustn't be already in game. |
105 |
|
* Post an notification named "addPlayer" containing the HgPlayer object. |
106 |
*/ |
*/ |
107 |
- (void) addPlayer: (HgPlayer *)player |
- (void) addPlayer: (HgPlayer *)player |
108 |
{ |
{ |
110 |
NSParameterAssert ([[_players allKeysForObject: player] count] == 0); |
NSParameterAssert ([[_players allKeysForObject: player] count] == 0); |
111 |
|
|
112 |
NSNumber *numId = [NSNumber numberWithInt: [player identifier]]; |
NSNumber *numId = [NSNumber numberWithInt: [player identifier]]; |
113 |
|
|
114 |
[_players setObject: player forKey: numId]; |
[_players setObject: player forKey: numId]; |
115 |
|
|
116 |
|
[[NSNotificationCenter defaultCenter] |
117 |
|
postNotificationName: @"addPlayer" object: player]; |
118 |
} |
} |
119 |
|
|
120 |
/** |
/** |
121 |
* Remove player from the current game. The player must be contained in |
* Remove player from the current game. The player must be contained in |
122 |
* the game. |
* the game. |
123 |
|
* Post an notification named "removePlayer" containing the HgPlayer object. |
124 |
*/ |
*/ |
125 |
-(void) removePlayer: (HgPlayer *)player |
-(void) removePlayer: (HgPlayer *)player |
126 |
{ |
{ |
130 |
NSNumber *numId = [NSNumber numberWithInt: [player identifier]]; |
NSNumber *numId = [NSNumber numberWithInt: [player identifier]]; |
131 |
|
|
132 |
[_players removeObjectForKey: numId]; |
[_players removeObjectForKey: numId]; |
133 |
|
|
134 |
|
[[NSNotificationCenter defaultCenter] |
135 |
|
postNotificationName: @"removePlayer" object: player]; |
136 |
} |
} |
137 |
|
|
138 |
/** |
/** |
145 |
|
|
146 |
/** |
/** |
147 |
* Add team to the current game. The team mustn't be already in game. |
* Add team to the current game. The team mustn't be already in game. |
148 |
|
* Post an notification named "addTeam" containing the HgTeam object. |
149 |
*/ |
*/ |
150 |
- (void) addTeam: (HgTeam *)team |
- (void) addTeam: (HgTeam *)team |
151 |
{ |
{ |
155 |
NSNumber *numId = [NSNumber numberWithInt: [team identifier]]; |
NSNumber *numId = [NSNumber numberWithInt: [team identifier]]; |
156 |
|
|
157 |
[_teams setObject: team forKey: numId]; |
[_teams setObject: team forKey: numId]; |
158 |
|
|
159 |
|
[[NSNotificationCenter defaultCenter] |
160 |
|
postNotificationName: @"addTeam" object: team]; |
161 |
} |
} |
162 |
|
|
163 |
/** |
/** |
164 |
* Remove team from the current game. The team must be contained in |
* Remove team from the current game. The team must be contained in |
165 |
* the game. |
* the game. |
166 |
|
* Post an notification named "removeTeam" containing the HgTeam object. |
167 |
*/ |
*/ |
168 |
- (void) removeTeam: (HgTeam *)team |
- (void) removeTeam: (HgTeam *)team |
169 |
{ |
{ |
173 |
NSNumber *numId = [NSNumber numberWithInt: [team identifier]]; |
NSNumber *numId = [NSNumber numberWithInt: [team identifier]]; |
174 |
|
|
175 |
[_teams removeObjectForKey: numId]; |
[_teams removeObjectForKey: numId]; |
176 |
|
|
177 |
|
[[NSNotificationCenter defaultCenter] |
178 |
|
postNotificationName: @"removeTeam" object: team]; |
179 |
} |
} |
180 |
|
|
181 |
/** |
/** |
212 |
|
|
213 |
/** |
/** |
214 |
* Add object to the current game. The object mustn't be already in game. |
* Add object to the current game. The object mustn't be already in game. |
215 |
|
* Post an notification named "addObject" containing the HgObject object. |
216 |
*/ |
*/ |
217 |
- (void) addObject: (HgObject *)object |
- (void) addObject: (HgObject *)object |
218 |
{ |
{ |
222 |
NSNumber *numId = [NSNumber numberWithInt: [object identifier]]; |
NSNumber *numId = [NSNumber numberWithInt: [object identifier]]; |
223 |
|
|
224 |
[_objects setObject: object forKey: numId]; |
[_objects setObject: object forKey: numId]; |
225 |
|
|
226 |
|
[[NSNotificationCenter defaultCenter] |
227 |
|
postNotificationName: @"addObject" object: object]; |
228 |
} |
} |
229 |
|
|
230 |
/** |
/** |
231 |
* Remove object from the current game. The player must be contained in |
* Remove object from the current game. The object must be contained in |
232 |
* the game. |
* the game. |
233 |
|
* Post an notification named "removeObject" containing the HgObject object. |
234 |
*/ |
*/ |
235 |
- (void) removeObject: (HgObject *)object |
- (void) removeObject: (HgObject *)object |
236 |
{ |
{ |
238 |
NSParameterAssert ([[_objects allKeysForObject: object] count] != 0); |
NSParameterAssert ([[_objects allKeysForObject: object] count] != 0); |
239 |
|
|
240 |
NSNumber *numId = [NSNumber numberWithInt: [object identifier]]; |
NSNumber *numId = [NSNumber numberWithInt: [object identifier]]; |
241 |
|
|
242 |
[_objects removeObjectForKey: numId]; |
[_objects removeObjectForKey: numId]; |
243 |
|
|
244 |
|
[[NSNotificationCenter defaultCenter] |
245 |
|
postNotificationName: @"removeObject" object: object]; |
246 |
} |
} |
247 |
|
|
248 |
/** |
/** |
268 |
|
|
269 |
- (id)initWithCoder: (NSCoder *)decoder |
- (id)initWithCoder: (NSCoder *)decoder |
270 |
{ |
{ |
271 |
if ( (self = [super init]) ) |
self = [super init]; |
272 |
|
if (self != nil) |
273 |
{ |
{ |
274 |
ASSIGN(_name, [decoder decodeObject]); |
_currentGame = self; |
|
ASSIGN(_players, [decoder decodeObject]); |
|
|
ASSIGN(_teams, [decoder decodeObject]); |
|
|
ASSIGN(_map, [decoder decodeObject]); |
|
|
ASSIGN(_objects, [decoder decodeObject]); |
|
|
} |
|
275 |
|
|
276 |
|
_name = RETAIN([decoder decodeObject]); |
277 |
|
_players = RETAIN([decoder decodeObject]); |
278 |
|
_teams = RETAIN([decoder decodeObject]); |
279 |
|
_map = RETAIN([decoder decodeObject]); |
280 |
|
_objects = RETAIN([decoder decodeObject]); |
281 |
|
} |
282 |
|
|
283 |
return self; |
return self; |
284 |
} |
} |
285 |
|
|