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
28
namespace
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
44
template
<
class
T >
45
class
Property
{
46
public
:
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
63
template
<
class
T >
64
class
SimpleProperty
:
public
Property
< T > {
65
bool (*_propertyFunc)(T *);
// The pointer to the property
66
// evaluation function
67
68
public
:
69
// Constructor
70
SimpleProperty
(
bool
(*func)(T *)) :
71
_propertyFunc(func) {
72
}
73
74
bool
operator()(T *obj)
const
;
75
};
76
77
template
<
class
T >
78
bool
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
92
template
<
class
T >
93
class
CompoundProperty
:
public
Property
< T > {
94
protected
:
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
100
public
:
101
// Constructor
102
CompoundProperty
(
Property< T >
**array, uint16 size);
103
104
// Virtual destructor
105
virtual
~
CompoundProperty
();
106
};
107
108
template
<
class
T >
109
CompoundProperty< T >::CompoundProperty
(
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
125
template
<
class
T >
126
CompoundProperty< 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
139
template
<
class
T >
140
class
PropertyAnd
:
public
CompoundProperty
< T > {
141
public
:
142
// Constructor
143
PropertyAnd
(
Property< T >
**array, uint16 size) :
144
CompoundProperty< T >
(array, size) {
145
}
146
147
bool
operator()(T *obj)
const
;
148
};
149
150
template
<
class
T >
151
bool
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
173
template
<
class
T >
174
class
PropertyOr
:
public
CompoundProperty
< T > {
175
public
:
176
// Constructor
177
PropertyOr
(
Property< T >
**array, uint16 size) :
178
CompoundProperty< T >
(array, size) {
179
}
180
181
bool
operator()(T *obj)
const
;
182
};
183
184
template
<
class
T >
185
bool
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
203
class
GameObject
;
204
205
typedef
Property< GameObject >
ObjectProperty
;
206
typedef
SimpleProperty< GameObject >
SimpleObjectProperty
;
207
typedef
PropertyAnd< GameObject >
ObjectPropertyAnd
;
208
typedef
PropertyOr< GameObject >
ObjectPropertyOr
;
209
210
typedef
int16 ObjectPropertyID;
211
212
enum
{
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
229
class
Actor
;
230
231
typedef
Property< Actor >
ActorProperty
;
232
typedef
SimpleProperty< Actor >
SimpleActorProperty
;
233
typedef
PropertyAnd< Actor >
ActorPropertyAnd
;
234
typedef
PropertyOr< Actor >
ActorPropertyOr
;
235
236
typedef
int16 ActorPropertyID;
237
238
enum
{
239
kActorPropIDDead,
240
kActorPropIDCenterActor,
241
kActorPropIDPlayerActor,
242
kActorPropIDEnemy,
243
244
kActorPropIDCount
245
};
246
247
/* ===================================================================== *
248
Tile properties
249
* ===================================================================== */
250
251
struct
TileInfo
;
252
253
typedef
Property< TileInfo >
TileProperty
;
254
typedef
SimpleProperty< TileInfo >
SimpleTileProperty
;
255
typedef
PropertyAnd< TileInfo >
TilePropertyAnd
;
256
typedef
PropertyOr< TileInfo >
TilePropertyOr
;
257
258
typedef
int16 TilePropertyID;
259
260
enum
{
261
kTilePropIDHasWater,
262
263
kTilePropIDCount
264
};
265
266
/* ===================================================================== *
267
MetaTile properties
268
* ===================================================================== */
269
270
class
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
284
class
MetaTileProperty
{
285
public
:
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
297
class
SimpleMetaTileProperty
:
public
MetaTileProperty
{
298
// Pointer to the property evaluation function.
299
bool (*_propertyFunc)(
MetaTile
*, int16,
const
TilePoint
&);
300
301
public
:
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
319
class
CompoundMetaTileProperty
:
public
MetaTileProperty
{
320
protected
:
321
MetaTileProperty
**_propertyArray;
// Array of pointers to
322
// MetaTileProperty's
323
uint16 _arraySize;
// Elements in the array
324
325
public
:
326
// Constructor
327
CompoundMetaTileProperty
(
MetaTileProperty
**array, uint16 size);
328
329
// Virtual destructor
330
virtual
~
CompoundMetaTileProperty
();
331
};
332
333
/* ===================================================================== *
334
MetaTilePropertyAnd class
335
* ===================================================================== */
336
337
class
MetaTilePropertyAnd
:
public
CompoundMetaTileProperty
{
338
public
:
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
354
class
MetaTilePropertyOr
:
public
CompoundMetaTileProperty
{
355
public
:
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
367
typedef
int16 MetaTilePropertyID;
368
369
enum
{
370
kMetaTilePropIDHasWater,
371
372
kMetaTilePropIDCount
373
};
374
375
bool
objIsObject(
GameObject
*obj);
376
377
bool
objIsActor(
GameObject
*obj);
378
379
bool
objIsWorld(
GameObject
*obj);
380
381
bool
objIsLocked(
GameObject
*obj);
382
383
bool
objIsUnlocked(
GameObject
*obj);
384
385
bool
objIsKey(
GameObject
*obj);
386
387
bool
objIsPlayerActor(
GameObject
*obj);
388
389
bool
objIsEnemy(
GameObject
*obj);
390
391
bool
actorIsDead(
Actor
*a);
392
393
bool
actorIsCenterActor(
Actor
*a);
394
395
bool
actorIsPlayerActor(
Actor
*a);
396
397
bool
actorIsEnemy(
Actor
*a);
398
399
bool
tileHasWater(
TileInfo
*ti);
400
401
bool
metaTileHasWater(
MetaTile
*mt, int16 mapNum,
const
TilePoint
&mCoords);
402
403
class
Properties
{
404
private
:
405
Common::Array<ObjectProperty *>
_objPropArray;
406
Common::Array<ActorProperty *>
_actorPropArray;
407
Common::Array<TileProperty *>
_tilePropArray;
408
Common::Array<MetaTileProperty *>
_metaTilePropArray;
409
410
public
:
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
Saga2::PropertyAnd
Definition:
property.h:140
Saga2::TileInfo
Definition:
tile.h:239
warning
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Common::Array
Definition:
array.h:52
Saga2::MetaTileProperty
Definition:
property.h:284
Saga2
Definition:
actor.h:32
Saga2::TilePoint
Definition:
tcoords.h:127
Saga2::Actor
Definition:
actor.h:589
Saga2::Properties
Definition:
property.h:403
Saga2::MetaTile
Definition:
tile.h:804
Saga2::GameObject
Definition:
objects.h:118
Saga2::SimpleProperty
Definition:
property.h:64
Saga2::CompoundProperty
Definition:
property.h:93
Saga2::MetaTilePropertyOr
Definition:
property.h:354
Saga2::PropertyOr
Definition:
property.h:174
Saga2::CompoundMetaTileProperty
Definition:
property.h:319
Saga2::MetaTilePropertyAnd
Definition:
property.h:337
Saga2::Property
Definition:
property.h:45
Saga2::SimpleMetaTileProperty
Definition:
property.h:297
engines
saga2
property.h
Generated on Fri Aug 30 2024 09:17:33 for ScummVM API documentation by
1.8.13