26 |
#include <Foundation/NSCoder.h> |
#include <Foundation/NSCoder.h> |
27 |
#include <Foundation/NSValue.h> |
#include <Foundation/NSValue.h> |
28 |
#include <Foundation/NSNotification.h> |
#include <Foundation/NSNotification.h> |
29 |
|
#include <Foundation/NSValue.h> |
30 |
|
|
31 |
#include "GameEngine/HgObject.h" |
#include "GameEngine/HgObject.h" |
32 |
#include "GameEngine/HgGame.h" |
#include "GameEngine/HgGame.h" |
33 |
|
#include "GameEngine/HgPlayer.h" |
34 |
|
|
35 |
/** |
/** |
36 |
* HgObject stores all principal caracteritic wich belongs to the |
* HgObject stores all principal caracteritic wich belongs to the |
75 |
static unsigned lastIdentifier = 0; |
static unsigned lastIdentifier = 0; |
76 |
|
|
77 |
NSParameterAssert (game); |
NSParameterAssert (game); |
78 |
|
|
79 |
/* |
/* |
80 |
* FIXME - needs to be checked |
* FIXME - needs to be checked |
81 |
*/ |
*/ |
88 |
_delegate = nil; |
_delegate = nil; |
89 |
[self setPosition: position]; |
[self setPosition: position]; |
90 |
_game = RETAIN(game); |
_game = RETAIN(game); |
91 |
_player = RETAIN(player); |
|
92 |
|
if (player != nil) |
93 |
|
_playerIdentifier = [[NSNumber alloc] |
94 |
|
initWithUnsignedInt: [player identifier]]; |
95 |
|
else |
96 |
|
_playerIdentifier = nil; |
97 |
} |
} |
98 |
|
|
99 |
return self; |
return self; |
103 |
{ |
{ |
104 |
RELEASE(_delegate); |
RELEASE(_delegate); |
105 |
RELEASE(_game); |
RELEASE(_game); |
106 |
RELEASE(_player); |
RELEASE(_playerIdentifier); |
107 |
|
|
108 |
[super dealloc]; |
[super dealloc]; |
109 |
} |
} |
110 |
|
|
111 |
/** |
/** |
|
* Returns the player. |
|
|
*/ |
|
|
- (HgPlayer *) player |
|
|
{ |
|
|
return _player; |
|
|
} |
|
|
|
|
|
/** |
|
112 |
* Returns the object identifier. |
* Returns the object identifier. |
113 |
*/ |
*/ |
114 |
- (unsigned) identifier |
- (unsigned) identifier |
203 |
return _game; |
return _game; |
204 |
} |
} |
205 |
|
|
206 |
|
/** |
207 |
|
* Returns the player associated with the current object. |
208 |
|
*/ |
209 |
|
- (HgPlayer *) player |
210 |
|
{ |
211 |
|
return [[_game players] objectForKey: _playerIdentifier]; |
212 |
|
} |
213 |
|
|
214 |
@end |
@end |
215 |
|
|
216 |
@implementation HgObject (NSCoding) |
@implementation HgObject (NSCoding) |
223 |
[encoder encodeValueOfObjCType: "I" at: &_identifier]; |
[encoder encodeValueOfObjCType: "I" at: &_identifier]; |
224 |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_position]; |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_position]; |
225 |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
226 |
|
[encoder encodeValueOfObjCType: @encode(NSNumber) at: &_playerIdentifier]; |
227 |
} |
} |
228 |
|
|
229 |
- (id)initWithCoder: (NSCoder *)decoder |
- (id)initWithCoder: (NSCoder *)decoder |
248 |
{ |
{ |
249 |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_position]; |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_position]; |
250 |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
251 |
|
[decoder decodeValueOfObjCType: @encode(NSNumber) at:&_playerIdentifier]; |
252 |
} |
} |
253 |
|
|
254 |
return self; |
return self; |