20 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 |
*/ |
*/ |
23 |
|
|
24 |
#include <Foundation/NSArray.h> |
#include <Foundation/NSArray.h> |
25 |
#include <Foundation/NSException.h> |
#include <Foundation/NSException.h> |
26 |
#include <Foundation/NSCoder.h> |
#include <Foundation/NSCoder.h> |
30 |
#include "GameEngine/HgObject.h" |
#include "GameEngine/HgObject.h" |
31 |
#include "GameEngine/HgGame.h" |
#include "GameEngine/HgGame.h" |
32 |
|
|
|
|
|
33 |
/** |
/** |
34 |
* HgObject stores all principal caracteritic wich belongs to the |
* HgObject stores all principal caracteritic wich belongs to the |
35 |
* current object. This class is abstract and must be redefined |
* current object. This class is abstract and must be redefined |
38 |
@implementation HgObject |
@implementation HgObject |
39 |
|
|
40 |
/** |
/** |
41 |
|
* Returns the name of the object class. |
42 |
|
* This method is abstract and must be redefined by concrete subclasses. |
43 |
|
*/ |
44 |
|
+ (NSString *) name |
45 |
|
{ |
46 |
|
[self subclassResponsibility: _cmd]; |
47 |
|
return nil; |
48 |
|
} |
49 |
|
|
50 |
|
/** |
51 |
|
* Returns the model associated with the object class. |
52 |
|
* This method is abstract and must be redefined by concrete subclasses. |
53 |
|
*/ |
54 |
|
+ (MdlModel *) model |
55 |
|
{ |
56 |
|
[self subclassResponsibility: _cmd]; |
57 |
|
return nil; |
58 |
|
} |
59 |
|
|
60 |
|
/** |
61 |
* Initialise an object which will be contained in game. |
* Initialise an object which will be contained in game. |
62 |
* The position must be contained in the game map. |
* The position must be contained in the game map. |
63 |
*/ |
*/ |
79 |
if (self != nil) |
if (self != nil) |
80 |
{ |
{ |
81 |
_identifier = lastIdentifier++; |
_identifier = lastIdentifier++; |
82 |
|
_delegate = nil; |
83 |
|
[self setPosition: position]; |
84 |
_game = RETAIN(game); |
_game = RETAIN(game); |
|
_position = position; |
|
85 |
} |
} |
86 |
|
|
87 |
return self; |
return self; |
89 |
|
|
90 |
- (void) dealloc |
- (void) dealloc |
91 |
{ |
{ |
92 |
|
RELEASE(_delegate); |
93 |
RELEASE(_game); |
RELEASE(_game); |
94 |
|
|
95 |
[super dealloc]; |
[super dealloc]; |
96 |
} |
} |
97 |
|
|
98 |
/** |
/** |
99 |
* Returns the game. |
* Returns the object identifier. |
100 |
*/ |
*/ |
101 |
- (HgGame *) game |
- (unsigned) identifier |
102 |
{ |
{ |
103 |
return _game; |
return _identifier; |
104 |
} |
} |
105 |
|
|
106 |
/** |
/** |
107 |
* Returns the object identifier. |
* Returns the object delegate. |
108 |
*/ |
*/ |
109 |
- (unsigned) identifier |
- (id) delegate |
110 |
{ |
{ |
111 |
return _identifier; |
return _delegate; |
112 |
} |
} |
113 |
|
|
114 |
/** |
/** |
115 |
* Return the name of the object class. This method is abstract and must |
* Sets the object delegate. |
|
* be redifined by the concrete subclasses. |
|
116 |
*/ |
*/ |
117 |
+ (NSString *) name |
- (void) setDelegate: (id)delegate |
118 |
{ |
{ |
119 |
return nil; |
_delegate = RETAIN(delegate); |
120 |
} |
} |
121 |
|
|
122 |
/** |
/** |
123 |
|
* Returns a string describing the current state of the object. |
124 |
|
* This string is used to choose the model animation. |
125 |
|
*/ |
126 |
|
- (NSString *) state |
127 |
|
{ |
128 |
|
return @"DEFAULT"; |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
/** |
133 |
* Returns the current object position. |
* Returns the current object position. |
134 |
*/ |
*/ |
135 |
- (coord_t) position |
- (coord_t) position |
182 |
forKey: @"HgObject"]]; |
forKey: @"HgObject"]]; |
183 |
} |
} |
184 |
|
|
185 |
/* FIXME implementation a revoir */ |
/** |
186 |
- (BOOL) collision: (HgObject *)object |
* Returns the game to wich the object belongs. |
187 |
{ |
*/ |
188 |
NSParameterAssert (object); |
- (HgGame *) game |
|
{ |
|
|
if ( ((_position.x) == (object->_position.x)) |
|
|
&&((_position.y) == (object->_position.y)) |
|
|
&&((_position.z) == (object->_position.z))) |
|
|
return YES; |
|
|
|
|
|
else return NO; |
|
|
} |
|
|
} |
|
|
|
|
|
- (void) setBoundingBoxes: (NSMutableArray *)boundingBoxes |
|
|
{ |
|
|
/* FIXME - not implemented */ |
|
|
NSParameterAssert (boundingBoxes); |
|
|
NSParameterAssert (![_boundingBoxes containsObject: boundingBoxes]); |
|
|
|
|
|
[_boundingBoxes addObject: boundingBoxes]; |
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject" |
|
|
object: _game |
|
|
userInfo: [NSDictionary dictionaryWithObject: self |
|
|
forKey: @"HgObject"]]; |
|
|
} |
|
|
|
|
|
- (void) collide: (HgObject *)object |
|
189 |
{ |
{ |
190 |
/* FIXME - not implemented */ |
return _game; |
191 |
} |
} |
192 |
|
|
193 |
@end |
@end |
202 |
[encoder encodeValueOfObjCType: "I" at: &_identifier]; |
[encoder encodeValueOfObjCType: "I" at: &_identifier]; |
203 |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_position]; |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_position]; |
204 |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
[encoder encodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
|
[encoder encodeObject: _boundingBoxes]; |
|
205 |
} |
} |
206 |
|
|
207 |
- (id)initWithCoder: (NSCoder *)decoder |
- (id)initWithCoder: (NSCoder *)decoder |
226 |
{ |
{ |
227 |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_position]; |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_position]; |
228 |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
[decoder decodeValueOfObjCType: @encode(coord_t) at: &_orientation]; |
|
_boundingBoxes = RETAIN([decoder decodeObject]); |
|
229 |
} |
} |
230 |
|
|
231 |
return self; |
return self; |