ScummVM API documentation
target.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_TARGET_H
27 #define SAGA2_TARGET_H
28 
29 namespace Saga2 {
30 
31 struct StandingTileInfo;
32 
33 const int kMaxObjDist = kPlatformWidth * kTileUVSize * 8;
34 const int kMaxTileDist = kPlatformWidth * kTileUVSize * 2;
35 const int kMaxMetaDist = kPlatformWidth * kTileUVSize * 8;
36 
37 enum TargetType {
38  kLocationTarget,
39  kSpecificTileTarget,
40  kTilePropertyTarget,
41  kSpecificMetaTileTarget,
42  kMetaTilePropertyTarget,
43  kSpecificObjectTarget,
44  kObjectPropertyTarget,
45  kSpecificActorTarget,
46  kActorPropertyTarget
47 };
48 
49 /* ===================================================================== *
50  Misc. function prototypes
51  * ===================================================================== */
52 
53 class Target;
54 
55 // Deletes targets allocated on the heap using new
56 void deleteTarget(Target *t);
57 
58 void readTarget(void *mem, Common::InSaveFile *in);
59 void writeTarget(const Target *t, Common::MemoryWriteStreamDynamic *out);
60 int32 targetArchiveSize(const Target *t);
61 
62 /* ===================================================================== *
63  TargetLocationArray structure
64  * ===================================================================== */
65 
66 // This structure is used to query the target class for multiple target
67 // locations
69  const int16 size; // number of allocated elements in array
70  int16 locs; // number of array elements with valid data
71 
72  // These arrays must be allocated by calling function
73  TilePoint *const locArray; // pointer to location array
74  int16 *const distArray; // pointer to distance array
75 
76  // Constructor
77  TargetLocationArray(int16 s, TilePoint *arr, int16 *dArr) :
78  size(s),
79  locs(0),
80  locArray(arr),
81  distArray(dArr) {
82  }
83 };
84 
85 /* ===================================================================== *
86  TargetObjectArray structure
87  * ===================================================================== */
88 
89 // This structure is used to query the target class for multiple target
90 // objects
92  const int16 size; // number of allocated elements in array
93  int16 objs; // number of array elements with valid data
94 
95  // These arrays must be allocated by calling function
96  GameObject **const objArray; // pointer to object pointer array
97  int16 *const distArray; // pointer to distance array
98 
99  // Constructor
100  TargetObjectArray(int16 s, GameObject **arr, int16 *dArr) :
101  size(s),
102  objs(0),
103  objArray(arr),
104  distArray(dArr) {
105  }
106 };
107 
108 /* ===================================================================== *
109  TargetActorArray structure
110  * ===================================================================== */
111 
112 // This structure is used to query the target class for multiple target
113 // actors
115  const int16 size; // number of allocated elements in array
116  int16 actors; // number of array elements with valid data
117 
118  // These arrays must be allocated by calling function
119  Actor **const actorArray; // pointer to actor pointer array
120  int16 *const distArray; // pointer to distance array
121 
122  // Constructor
123  TargetActorArray(int16 s, Actor **arr, int16 *dArr) :
124  size(s),
125  actors(0),
126  actorArray(arr),
127  distArray(dArr) {
128  }
129 };
130 
131 /* ===================================================================== *
132  Target class
133  * ===================================================================== */
134 
135 class Target {
136 public:
137  // virtual destructor
138  virtual ~Target() {}
139 
140  // Return the number of bytes needed to archive this object in
141  // a buffer
142  virtual int32 archiveSize() const = 0;
143 
144  virtual void write(Common::MemoryWriteStreamDynamic *out) const = 0;
145 
146  // Return an integer representing the type of target
147  virtual int16 getType() const = 0;
148 
149  // Virtual function returning the sizeof this target
150  virtual size_t size() const = 0;
151 
152  // Create a copy of this target at the specified address
153  virtual void clone(void *mem) const = 0;
154 
155  // Determine if the specified target is equivalent to this target
156  virtual bool operator == (const Target &t) const = 0;
157  bool operator != (const Target &t) const {
158  return !operator == (t);
159  }
160 
161  // Overloaded memory management functions for constructing and
162  // destructing Targets in place.
163  void *operator new (size_t, void *p) {
164  return p;
165  }
166 
167  virtual bool isObjectTarget() const;
168  virtual bool isActorTarget() const;
169 
170  // Return location of closest instance of target
171  virtual TilePoint where(GameWorld *world, const TilePoint &tp) const = 0;
172  // Fill array with locations of closest instances of target
173  virtual int16 where(
174  GameWorld *world,
175  const TilePoint &tp,
176  TargetLocationArray &tla) const = 0;
177 };
178 
179 /* ===================================================================== *
180  LocationTarget class
181  * ===================================================================== */
182 
183 class LocationTarget : public Target {
184  TilePoint _loc;
185 
186 public:
187  // Constructor -- initial construction
188  LocationTarget(const TilePoint &tp) : _loc(tp) {}
189 
191 
192  // Return the number of bytes needed to archive this object in
193  // a buffer
194  int32 archiveSize() const;
195 
196  void write(Common::MemoryWriteStreamDynamic *out) const;
197 
198  // Return an integer representing the type of target
199  int16 getType() const;
200 
201  // Virtual function returning the sizeof this target
202  size_t size() const;
203 
204  // Create a copy of this target at the specified address
205  void clone(void *mem) const;
206 
207  // Determine if the specified target is equivalent to this target
208  bool operator == (const Target &t) const;
209 
210  // Determine if the specified location target is equivalent to this
211  // location target
212  bool operator == (const LocationTarget &lt) const {
213  return _loc == lt._loc;
214  }
215  bool operator != (const LocationTarget &lt) const {
216  return _loc != lt._loc;
217  }
218 
219  TilePoint where(GameWorld *world, const TilePoint &tp) const;
220  int16 where(
221  GameWorld *world,
222  const TilePoint &tp,
223  TargetLocationArray &tla) const;
224 };
225 
226 /* ===================================================================== *
227  TileTarget class
228  * ===================================================================== */
229 
230 class TileTarget : public Target {
231 public:
232  virtual bool isTarget(StandingTileInfo &sti) const = 0;
233 
234  TilePoint where(GameWorld *world, const TilePoint &tp) const;
235  int16 where(
236  GameWorld *world,
237  const TilePoint &tp,
238  TargetLocationArray &tla) const;
239 };
240 
241 /* ===================================================================== *
242  SpecificTileTarget class
243  * ===================================================================== */
244 
246  TileID _tile;
247 
248 public:
249  // Constructor -- initial construction
250  SpecificTileTarget(TileID t) : _tile(t) {}
251 
253 
254  // Return the number of bytes needed to archive this object in
255  // a buffer
256  int32 archiveSize() const;
257 
258  void write(Common::MemoryWriteStreamDynamic *out) const;
259 
260  // Return an integer representing the type of target
261  int16 getType() const;
262 
263  // Virtual function returning the sizeof this target
264  size_t size() const;
265 
266  // Create a copy of this target at the specified address
267  void clone(void *mem) const;
268 
269  // Determine if the specified target is equivalent to this target
270  bool operator == (const Target &t) const;
271 
272  bool isTarget(StandingTileInfo &sti) const;
273 };
274 
275 /* ===================================================================== *
276  TilePropertyTarget class
277  * ===================================================================== */
278 
280  TilePropertyID _tileProp;
281 
282 public:
283  // Constructor -- initial construction
284  TilePropertyTarget(TilePropertyID tProp) : _tileProp(tProp) {}
285 
287 
288  // Return the number of bytes needed to archive this object in
289  // a buffer
290  int32 archiveSize() const;
291 
292  void write(Common::MemoryWriteStreamDynamic *out) const;
293 
294  // Return an integer representing the type of target
295  int16 getType() const;
296 
297  // Virtual function returning the sizeof this target
298  size_t size() const;
299 
300  // Create a copy of this target at the specified address
301  void clone(void *mem) const;
302 
303  // Determine if the specified target is equivalent to this target
304  bool operator == (const Target &t) const;
305 
306  bool isTarget(StandingTileInfo &sti) const;
307 };
308 
309 /* ===================================================================== *
310  MetaTileTarget class
311  * ===================================================================== */
312 
313 class MetaTileTarget : public Target {
314 public:
315  virtual bool isTarget(
316  MetaTile *mt,
317  int16 mapNum,
318  const TilePoint &tp) const = 0;
319 
320  TilePoint where(GameWorld *world, const TilePoint &tp) const;
321  int16 where(
322  GameWorld *world,
323  const TilePoint &tp,
324  TargetLocationArray &tla) const;
325 };
326 
327 /* ===================================================================== *
328  SpecificMetaTileTarget class
329  * ===================================================================== */
330 
332  MetaTileID _meta;
333 
334 public:
335  // Constructor -- initial construction
336  SpecificMetaTileTarget(MetaTileID mt) : _meta(mt) {}
337 
339 
340  // Return the number of bytes needed to archive this object in
341  // a buffer
342  int32 archiveSize() const;
343 
344  void write(Common::MemoryWriteStreamDynamic *out) const;
345 
346  // Return an integer representing the type of target
347  int16 getType() const;
348 
349  // Virtual function returning the sizeof this target
350  size_t size() const;
351 
352  // Create a copy of this target at the specified address
353  void clone(void *mem) const;
354 
355  // Determine if the specified target is equivalent to this target
356  bool operator == (const Target &t) const;
357 
358  bool isTarget(MetaTile *mt, int16 mapNum, const TilePoint &tp) const;
359 };
360 
361 /* ===================================================================== *
362  MetaTilePropertyTarget class
363  * ===================================================================== */
364 
366  MetaTilePropertyID _metaProp;
367 
368 public:
369  // Constructor -- initial construction
370  MetaTilePropertyTarget(MetaTilePropertyID mtProp) :
371  _metaProp(mtProp) {
372  }
373 
375 
376  // Return the number of bytes needed to archive this object in
377  // a buffer
378  int32 archiveSize() const;
379 
380  void write(Common::MemoryWriteStreamDynamic *out) const;
381 
382  // Return an integer representing the type of target
383  int16 getType() const;
384 
385  // Virtual function returning the sizeof this target
386  size_t size() const;
387 
388  // Create a copy of this target at the specified address
389  void clone(void *mem) const;
390 
391  // Determine if the specified target is equivalent to this target
392  bool operator == (const Target &t) const;
393 
394  bool isTarget(MetaTile *mt, int16 mapNum, const TilePoint &tp) const;
395 };
396 
397 /* ===================================================================== *
398  ObjectTarget class
399  * ===================================================================== */
400 
401 class ObjectTarget : public Target {
402 
403  // These are recursive functions used to fill a target array
404  // by inspecting an object and all of the objects contained in
405  // that object
406  void searchObject(
407  GameObject *obj,
408  int16 dist,
409  TargetObjectArray &toa) const;
410  void searchObject(
411  GameObject *obj,
412  const TilePoint &tp,
413  int16 dist,
414  TargetLocationArray &tla) const;
415 
416 public:
417  bool isObjectTarget() const;
418 
419  TilePoint where(GameWorld *world, const TilePoint &tp) const;
420  int16 where(
421  GameWorld *world,
422  const TilePoint &tp,
423  TargetLocationArray &tla) const;
424 
425  // Determine if the specified object meets the target criterion
426  virtual bool isTarget(GameObject *testObj) const = 0;
427 
428  // Return closest instance of target object
429  virtual GameObject *object(GameWorld *world, const TilePoint &tp) const;
430  // Fill array with closest instances of target object
431  virtual int16 object(
432  GameWorld *world,
433  const TilePoint &tp,
434  TargetObjectArray &toa) const;
435 };
436 
437 /* ===================================================================== *
438  SpecificObjectTarget class
439  * ===================================================================== */
440 
442  ObjectID _obj;
443 
444 public:
445  // Constructors -- initial construction
446  SpecificObjectTarget(ObjectID id) :
447  _obj(id) {
448  assert(isObject(_obj));
449  }
450  SpecificObjectTarget(GameObject *ptr) : _obj((assert(isObject(ptr)), ptr->thisID())) {}
451 
453 
454  // Return the number of bytes needed to archive this object in
455  // a buffer
456  int32 archiveSize() const;
457 
458  void write(Common::MemoryWriteStreamDynamic *out) const;
459 
460  // Return an integer representing the type of target
461  int16 getType() const;
462 
463  // Virtual function returning the sizeof this target
464  size_t size() const;
465 
466  // Create a copy of this target at the specified address
467  void clone(void *mem) const;
468 
469  // Determine if the specified target is equivalent to this target
470  bool operator == (const Target &t) const;
471 
472  bool isTarget(GameObject *testObj) const;
473 
474  TilePoint where(GameWorld *world, const TilePoint &tp) const;
475  int16 where(
476  GameWorld *world,
477  const TilePoint &tp,
478  TargetLocationArray &tla) const;
479 
480  GameObject *object(GameWorld *world, const TilePoint &tp) const;
481  int16 object(
482  GameWorld *world,
483  const TilePoint &tp,
484  TargetObjectArray &toa) const;
485 
486  // Return a pointer to the target object, unconditionally
487  GameObject *getTargetObject() const {
488  return GameObject::objectAddress(_obj);
489  }
490 };
491 
492 /* ===================================================================== *
493  ObjectPropertTarget class
494  * ===================================================================== */
495 
497  ObjectPropertyID _objProp;
498 
499 public:
500  // Constructor -- initial construction
501  ObjectPropertyTarget(ObjectPropertyID prop) : _objProp(prop) {}
502 
504 
505  // Return the number of bytes needed to archive this object in
506  // a buffer
507  int32 archiveSize() const;
508 
509  void write(Common::MemoryWriteStreamDynamic *out) const;
510 
511  // Return an integer representing the type of target
512  int16 getType() const;
513 
514  // Virtual function returning the sizeof this target
515  size_t size() const;
516 
517  // Create a copy of this target at the specified address
518  void clone(void *mem) const;
519 
520  // Determine if the specified target is equivalent to this target
521  bool operator == (const Target &t) const;
522 
523  bool isTarget(GameObject *testObj) const;
524 };
525 
526 /* ===================================================================== *
527  ActorTarget class
528  * ===================================================================== */
529 
530 class ActorTarget : public ObjectTarget {
531 
532 public:
533  bool isActorTarget() const;
534 
535  bool isTarget(GameObject *testObj) const;
536  virtual bool isTarget(Actor *testActor) const = 0;
537 
538  virtual Actor *actor(GameWorld *world, const TilePoint &tp) const;
539  virtual int16 actor(
540  GameWorld *world,
541  const TilePoint &tp,
542  TargetActorArray &taa) const;
543 };
544 
545 /* ===================================================================== *
546  SpecificActorTarget class
547  * ===================================================================== */
548 
550  Actor *_a;
551 
552 public:
553  // Constructor -- initial construction
554  SpecificActorTarget(Actor *actor_) : _a(actor_) {}
555 
557 
558  // Return the number of bytes needed to archive this object in
559  // a buffer
560  int32 archiveSize() const;
561 
562  void write(Common::MemoryWriteStreamDynamic *out) const;
563 
564  // Return an integer representing the type of target
565  int16 getType() const;
566 
567  // Virtual function returning the sizeof this target
568  size_t size() const;
569 
570  // Create a copy of this target at the specified address
571  void clone(void *mem) const;
572 
573  // Determine if the specified target is equivalent to this target
574  bool operator == (const Target &t) const;
575 
576  bool isTarget(Actor *testActor) const;
577 
578  TilePoint where(GameWorld *world, const TilePoint &tp) const;
579  int16 where(
580  GameWorld *world,
581  const TilePoint &tp,
582  TargetLocationArray &tla) const;
583 
584  GameObject *object(GameWorld *world, const TilePoint &tp) const;
585  int16 object(
586  GameWorld *world,
587  const TilePoint &tp,
588  TargetObjectArray &toa) const;
589 
590  Actor *actor(GameWorld *world, const TilePoint &tp) const;
591  int16 actor(
592  GameWorld *world,
593  const TilePoint &tp,
594  TargetActorArray &taa) const;
595 
596  // Return a pointer to the target actor, unconditionally
597  Actor *getTargetActor() const {
598  return _a;
599  }
600 };
601 
602 /* ===================================================================== *
603  ActorPropertyTarget class
604  * ===================================================================== */
605 
607  ActorPropertyID _actorProp;
608 
609 public:
610  // Constructor -- initial construction
611  ActorPropertyTarget(ActorPropertyID aProp) : _actorProp(aProp) {}
612 
614 
615  // Return the number of bytes needed to archive this object in
616  // a buffer
617  int32 archiveSize() const;
618 
619  void write(Common::MemoryWriteStreamDynamic *out) const;
620 
621  // Return an integer representing the type of target
622  int16 getType() const;
623 
624  // Virtual function returning the sizeof this target
625  size_t size() const;
626 
627  // Create a copy of this target at the specified address
628  void clone(void *mem) const;
629 
630  // Determine if the specified target is equivalent to this target
631  bool operator == (const Target &t) const;
632 
633  bool isTarget(Actor *testActor) const;
634 };
635 
636 /* ===================================================================== *
637  Constants
638  * ===================================================================== */
639 
640 // This const and typedef are used to define an area of memory large enough
641 // to contain any target. The sizeof( LocationTarget ) is used because
642 // the LocationTarget takes the most memory.
643 
644 const size_t kTargetBytes = sizeof(LocationTarget);
645 
646 typedef uint8 TargetPlaceHolder[kTargetBytes];
647 
648 } // end of namespace Saga2
649 
650 #endif
Definition: target.h:245
Definition: target.h:135
Definition: target.h:401
Definition: target.h:331
Definition: actor.h:32
Definition: target.h:549
Definition: target.h:606
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: stream.h:745
Definition: actor.h:589
Definition: target.h:441
Definition: target.h:230
Definition: tile.h:634
Definition: tile.h:804
Definition: target.h:183
Definition: target.h:114
Definition: objects.h:768
Definition: objects.h:118
Definition: target.h:365
Definition: target.h:530
Definition: target.h:91
Definition: target.h:313
Definition: target.h:496
Definition: idtypes.h:73
Definition: target.h:68
Definition: target.h:279