ScummVM API documentation
property.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 *
21 * Based on the original sources
22 * Faery Tale II -- The Halls of the Dead
23 * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24 */
25
26#ifndef SAGA2_PROPERTY_H
27#define SAGA2_PROPERTY_H
28namespace Saga2 {
29
30/* ===================================================================== *
31 Property class template
32 * ===================================================================== */
33
34// This is an abstract property function object class. A property function
35// object can be used to determine if an object of type T has a certain
36// property. In order to do this, a pointer to an object of type T is
37// passed to the operator () member function, which returns true if the
38// object has the property and false if it does not.
39
40// These function objects can be used to process only subset of object of
41// type T which meet certain criteria, without having to know what those
42// criteria are.
43
44template < class T >
45class Property {
46public:
47 virtual ~Property() {}
48
49 virtual bool operator()(T *obj) const = 0;
50};
51
52/* ===================================================================== *
53 SimpleProperty class template
54 * ===================================================================== */
55
56// This class defines the most simple type of property function object.
57// A simple property is constructed with a pointer to a function which will
58// accept as a parameter a pointer to an object of type T and evaluate the
59// object to determine if it has a certain property. The only task of the
60// operator () member function is to call this function and return its
61// result.
62
63template < class T >
64class SimpleProperty : public Property< T > {
65 bool (*_propertyFunc)(T *); // The pointer to the property
66 // evaluation function
67
68public:
69 // Constructor
70 SimpleProperty(bool (*func)(T *)) :
71 _propertyFunc(func) {
72 }
73
74 bool operator()(T *obj) const;
75};
76
77template < class T >
78bool SimpleProperty< T >::operator()(T *obj) const {
79 // Simply pass this call through to the property evaluation function
80 return (*_propertyFunc)(obj);
81}
82
83/* ===================================================================== *
84 CompoundProperty class template
85 * ===================================================================== */
86
87// This is an abstract base class for all compound properties: properties
88// which are defined in terms of one or more other properties. This class
89// cosists of a pointer to an array of pointers to Property's and a count
90// of the number of pointers in the array.
91
92template < class T >
93class CompoundProperty : public Property< T > {
94protected:
95 Property< T > **_propertyArray; // A pointer to an array of pointers
96 // to Properties.
97 uint16 _arraySize; // The number of elements in the
98 // array
99
100public:
101 // Constructor
102 CompoundProperty(Property< T > **array, uint16 size);
103
104 // Virtual destructor
105 virtual ~CompoundProperty();
106};
107
108template < class T >
110 Property< T > **array,
111 uint16 size) {
112 // Determine the number of bytes needed to copy the array
113 uint16 arrayBytes = sizeof(Property< T > *) * size;
114
115 // Allocate memory to copy the array.
116 _propertyArray = (Property< T > **)malloc(arrayBytes);
117 assert(_propertyArray);
118
119 // Copy the array
120 memcpy(_propertyArray, array, arrayBytes);
121 _arraySize = size;
122}
123
124
125template < class T >
126CompoundProperty< T >::~CompoundProperty() {
127 // Free the array memory
128 free(_propertyArray);
129}
130
131/* ===================================================================== *
132 PropertyAnd class template
133 * ===================================================================== */
134
135// This class defines an 'and' compound property. Each of the sub
136// properties in the compound property list must evaluate to true for this
137// function object to evaluate to true.
138
139template < class T >
140class PropertyAnd : public CompoundProperty< T > {
141public:
142 // Constructor
143 PropertyAnd(Property< T > **array, uint16 size) :
144 CompoundProperty< T >(array, size) {
145 }
146
147 bool operator()(T *obj) const;
148};
149
150template < class T >
151bool PropertyAnd< T >::operator()(T *obj) const {
152#if 0
153 uint16 i;
154
155 // Iterate through each element in the array and if any evaluate to
156 // false, return false immediately.
157 for (i = 0; i < arraySize; i++)
158 if ((*propertyArray[i])(obj) == false) return false;
159#endif
160 warning("STUB: PropertyAnd");
161
162 return true;
163}
164
165/* ===================================================================== *
166 PropertyOr class template
167 * ===================================================================== */
168
169// This class defines an 'or' compound property. If any of the sub
170// properties in the compound property list evaluate to true this function
171// object will evaluate to true.
172
173template < class T >
174class PropertyOr : public CompoundProperty< T > {
175public:
176 // Constructor
177 PropertyOr(Property< T > **array, uint16 size) :
178 CompoundProperty< T >(array, size) {
179 }
180
181 bool operator()(T *obj) const;
182};
183
184template < class T >
185bool PropertyOr< T >::operator()(T *obj) const {
186#if 0
187 uint16 i;
188
189 // Iterate through each element in the array and if any evaluate to
190 // true, return true immediately.
191 for (i = 0; i < arraySize; i++)
192 if ((*propertyArray[i])(obj)) return true;
193#endif
194 warning("STUB: PropertyOr");
195
196 return false;
197}
198
199/* ===================================================================== *
200 Object properties
201 * ===================================================================== */
202
203class GameObject;
204
205typedef Property< GameObject > ObjectProperty;
206typedef SimpleProperty< GameObject > SimpleObjectProperty;
207typedef PropertyAnd< GameObject > ObjectPropertyAnd;
208typedef PropertyOr< GameObject > ObjectPropertyOr;
209
210typedef int16 ObjectPropertyID;
211
212enum {
213 kObjPropIDObject,
214 kObjPropIDActor,
215 kObjPropIDWorld,
216 kObjPropIDLocked,
217 kObjPropIDUnlocked,
218 kObjPropIDKey,
219 kObjPropIDPlayerActor,
220 kObjPropIDEnemy,
221
222 kObjPropIDCount
223};
224
225/* ===================================================================== *
226 Actor properties
227 * ===================================================================== */
228
229class Actor;
230
231typedef Property< Actor > ActorProperty;
232typedef SimpleProperty< Actor > SimpleActorProperty;
233typedef PropertyAnd< Actor > ActorPropertyAnd;
234typedef PropertyOr< Actor > ActorPropertyOr;
235
236typedef int16 ActorPropertyID;
237
238enum {
239 kActorPropIDDead,
240 kActorPropIDCenterActor,
241 kActorPropIDPlayerActor,
242 kActorPropIDEnemy,
243
244 kActorPropIDCount
245};
246
247/* ===================================================================== *
248 Tile properties
249 * ===================================================================== */
250
251struct TileInfo;
252
253typedef Property< TileInfo > TileProperty;
254typedef SimpleProperty< TileInfo > SimpleTileProperty;
255typedef PropertyAnd< TileInfo > TilePropertyAnd;
256typedef PropertyOr< TileInfo > TilePropertyOr;
257
258typedef int16 TilePropertyID;
259
260enum {
261 kTilePropIDHasWater,
262
263 kTilePropIDCount
264};
265
266/* ===================================================================== *
267 MetaTile properties
268 * ===================================================================== */
269
270class MetaTile;
271
272/* ===================================================================== *
273 MetaTileProperty class
274 * ===================================================================== */
275
276// The MetaTileProperty class hierarchy is similar to the Property template
277// class hierarchy. The reason that MetaTile's have a separate Property
278// class hierarchy, is because a MetaTile may only be uniquely identified
279// if the location of the MetaTile is specifed, as well as a pointer to the
280// MetaTile structure. This difference alters the interface of the
281// operator () member function by requiring an additional TilePoint
282// parameter.
283
285public:
286 virtual ~MetaTileProperty() {}
287 virtual bool operator()(
288 MetaTile *mt,
289 int16 mapNum,
290 const TilePoint &tp) const = 0;
291};
292
293/* ===================================================================== *
294 SimpleMetaTileProperty class
295 * ===================================================================== */
296
298 // Pointer to the property evaluation function.
299 bool (*_propertyFunc)(MetaTile *, int16, const TilePoint &);
300
301public:
302 // Constructor
303 SimpleMetaTileProperty(bool (*func)(MetaTile *, int16, const TilePoint &)) :
304 _propertyFunc(func) {
305 }
306
307 virtual ~SimpleMetaTileProperty() {}
308
309 bool operator()(
310 MetaTile *mt,
311 int16 mapNum,
312 const TilePoint &tp) const;
313};
314
315/* ===================================================================== *
316 CompoundMetaTileProperty class
317 * ===================================================================== */
318
320protected:
321 MetaTileProperty **_propertyArray; // Array of pointers to
322 // MetaTileProperty's
323 uint16 _arraySize; // Elements in the array
324
325public:
326 // Constructor
327 CompoundMetaTileProperty(MetaTileProperty **array, uint16 size);
328
329 // Virtual destructor
331};
332
333/* ===================================================================== *
334 MetaTilePropertyAnd class
335 * ===================================================================== */
336
338public:
339 // Constructor
340 MetaTilePropertyAnd(MetaTileProperty **array, uint16 size) :
341 CompoundMetaTileProperty(array, size) {
342 }
343
344 bool operator()(
345 MetaTile *mt,
346 int16 mapNum,
347 const TilePoint &tp) const;
348};
349
350/* ===================================================================== *
351 MetaTilePropertyOr class
352 * ===================================================================== */
353
355public:
356 // Constructor
357 MetaTilePropertyOr(MetaTileProperty **array, uint16 size) :
358 CompoundMetaTileProperty(array, size) {
359 }
360
361 bool operator()(
362 MetaTile *mt,
363 int16 mapNum,
364 const TilePoint &tp) const;
365};
366
367typedef int16 MetaTilePropertyID;
368
369enum {
370 kMetaTilePropIDHasWater,
371
372 kMetaTilePropIDCount
373};
374
375bool objIsObject(GameObject *obj);
376
377bool objIsActor(GameObject *obj);
378
379bool objIsWorld(GameObject *obj);
380
381bool objIsLocked(GameObject *obj);
382
383bool objIsUnlocked(GameObject *obj);
384
385bool objIsKey(GameObject *obj);
386
387bool objIsPlayerActor(GameObject *obj);
388
389bool objIsEnemy(GameObject *obj);
390
391bool actorIsDead(Actor *a);
392
393bool actorIsCenterActor(Actor *a);
394
395bool actorIsPlayerActor(Actor *a);
396
397bool actorIsEnemy(Actor *a);
398
399bool tileHasWater(TileInfo *ti);
400
401bool metaTileHasWater(MetaTile *mt, int16 mapNum, const TilePoint &mCoords);
402
404private:
406 Common::Array<ActorProperty *> _actorPropArray;
407 Common::Array<TileProperty *> _tilePropArray;
408 Common::Array<MetaTileProperty *> _metaTilePropArray;
409
410public:
411
412 Properties();
413 ~Properties();
414
415 const ObjectProperty *getObjProp(ObjectPropertyID id) {
416 return _objPropArray[id];
417 }
418
419 const ActorProperty *getActorProp(ActorPropertyID id) {
420 return _actorPropArray[id];
421 }
422
423 const TileProperty *getTileProp(TilePropertyID id) {
424 return _tilePropArray[id];
425 }
426
427 const MetaTileProperty *getMetaTileProp(MetaTilePropertyID id) {
428 return _metaTilePropArray[id];
429 }
430};
431
432} // end of namespace Saga2
433
434#endif
Definition: array.h:52
Definition: property.h:319
Definition: property.h:93
Definition: tile.h:804
Definition: property.h:337
Definition: property.h:284
Definition: property.h:354
Definition: property.h:403
Definition: property.h:140
Definition: property.h:45
Definition: property.h:174
Definition: property.h:297
Definition: property.h:64
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: tcoords.h:127