ScummVM API documentation
speldefs.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_SPELDEFS_H
27 #define SAGA2_SPELDEFS_H
28 
29 #include "saga2/tile.h"
30 #include "saga2/objects.h"
31 
32 namespace Saga2 {
33 
34 struct StorageSpellTarget;
35 class SpellInstance;
36 struct StorageEffectron;
37 class SpellDisplayPrototype;
38 class EffectDisplayPrototype;
39 struct ResourceSpellItem;
40 struct StorageSpellInstance;
41 
42 /* ===================================================================== *
43  Constants
44  * ===================================================================== */
45 
46 // this determines the maimum nuber of spells the system can handle.
47 
48 #define MAX_SPELLS 128
49 #define continuouslyImplemented (-1)
50 
51 /* ===================================================================== *
52  Types
53  * ===================================================================== */
54 
55 //-----------------------------------------------------------------------
56 // index into the Visual Effect list
57 
58 typedef uint16 EffectID;
59 
60 //-----------------------------------------------------------------------
61 // Spell Sprite Pose
62 
63 typedef uint16 SpellPoseID;
64 
65 //-----------------------------------------------------------------------
66 // height to use for collision detection
67 
68 typedef uint8 spellHeight;
69 
70 //-----------------------------------------------------------------------
71 // breadth to use for collision detection
72 
73 typedef uint8 spellBreadth;
74 
75 //-----------------------------------------------------------------------
76 // SpellAge type
77 
78 typedef int32 SpellAge;
79 
80 //-----------------------------------------------------------------------
81 // SpellPositionSeed type
82 // Both a location indicator and a direction indicator can be
83 // gotten from this type
84 
85 typedef int32 SpellPositionSeed;
86 
87 // Get the Position part of the seed
88 inline uint16 SpellPosition(SpellPositionSeed sps) {
89  return sps & 0xFFFF;
90 }
91 
92 // Get the Direction part of the seed (used in explosions)
93 inline uint16 SpellDirection(SpellPositionSeed sps) {
94  return ((sps >> 16) & 0xFFFF);
95 }
96 
97 //-----------------------------------------------------------------------
98 // SpellSpritationSeed type
99 
100 typedef int32 SpellSpritationSeed;
101 
102 //-----------------------------------------------------------------------
103 // SpellCaster type (identical to GameObject)
104 
105 typedef GameObject SpellCaster;
106 
107 /* ===================================================================== *
108  Misplaced
109  * ===================================================================== */
110 
111 // some cheesy inlines for extracting location info
112 // they should probably be member functions of other classes but
113 // I didn't want to modify those headers
114 
115 inline TilePoint TAGPos(ActiveItem *ai) {
116  if (ai == NULL) return Nowhere;
117  assert(ai->_data.itemType == kActiveTypeInstance);
118  return TilePoint(
119  ai->_data.instance.u << kTileUVShift,
120  ai->_data.instance.v << kTileUVShift,
121  ai->_data.instance.h);
122 }
123 
124 inline TilePoint objPos(GameObject *go) {
125  if (go == NULL) return Nowhere;
126  TilePoint t = go->getWorldLocation();
127  t.z += go->proto()->height / 2;
128  return t;
129 }
130 
131 /* ===================================================================== *
132  another type
133  * ===================================================================== */
134 
135 //-----------------------------------------------------------------------
136 // SpellTarget type
137 // allows access to several types of targets with the same code
138 
139 class SpellTarget {
140  friend struct StorageSpellTarget;
141 
142 public :
143  enum spellTargetType {
144  kSpellTargetNone = 0, // invalid
145  kSpellTargetPoint, // targeted on a particular point
146  kSpellTargetObjectPoint, // targeted on an object's location
147  kSpellTargetObject, // targeted on an object (tracking)
148  kSpellTargetTAG // targeted on an object (tracking)
149  };
150 
151 private:
152  spellTargetType _type;
153 
154  TilePoint _loc;
155  GameObject *_obj;
156  ActiveItem *_tag;
157 
158 public:
159  SpellTarget *_next;
160 
161  SpellTarget() {
162  _type = kSpellTargetNone;
163  _obj = nullptr;
164  _loc.u = 0;
165  _loc.v = 0;
166  _loc.z = 0;
167  _next = nullptr;
168  _tag = nullptr;
169  }
170 
171  // This constructor is for non-tracking targets
172  SpellTarget(GameObject &object) {
173  _type = kSpellTargetObjectPoint;
174  _loc = object.getWorldLocation();
175  _loc.z += object.proto()->height / 2;
176  _next = nullptr;
177  _obj = &object;
178  _tag = nullptr;
179  }
180 
181  // This constructor is for tracking targets
182  SpellTarget(GameObject *object) {
183  _type = kSpellTargetObject;
184  _obj = object;
185  _next = nullptr;
186  _tag = nullptr;
187  }
188  SpellTarget(TilePoint &tp) {
189  _type = kSpellTargetPoint;
190  _loc = tp;
191  _next = nullptr;
192  _tag = nullptr;
193  _obj = nullptr;
194  }
195  SpellTarget(ActiveItem *ai) {
196  _type = kSpellTargetTAG;
197  _tag = ai;
198  _next = nullptr;
199  _tag = nullptr;
200  _obj = nullptr;
201  }
203 
204  SpellTarget &operator=(const SpellTarget &src) {
205  _type = src._type;
206  _loc = src._loc;
207  _obj = src._obj;
208  _tag = src._tag;
209  _next = src._next;
210  return *this;
211  }
212  SpellTarget(const SpellTarget &src) {
213  _type = src._type;
214  _loc = src._loc;
215  _obj = src._obj;
216  _tag = src._tag;
217  _next = src._next;
218  }
219 
220  ~SpellTarget() {
221  if (_next)
222  delete _next;
223  _next = nullptr;
224  };
225 
226  TilePoint getPoint() {
227  switch (_type) {
228  case kSpellTargetPoint :
229  case kSpellTargetObjectPoint :
230  return _loc;
231  case kSpellTargetObject :
232  return objPos(_obj);
233  case kSpellTargetTAG :
234  return TAGPos(_tag);
235  case kSpellTargetNone :
236  default :
237  return Nowhere;
238  }
239  }
240 
241  spellTargetType getType() {
242  return _type;
243  }
244 
245  GameObject *getObject() {
246  assert(_type == kSpellTargetObject);
247  return _obj;
248  }
249 
250  ActiveItem *getTAG() {
251  assert(_type == kSpellTargetTAG);
252  return _tag;
253  }
254 
255 };
256 
257 //-----------------------------------------------------------------------
258 // Effectron flags
259 
260 enum EffectronFlagMasks {
261  kEffectronOK = 0,
262  kEffectronHidden = (1 << 0),
263  kEffectronDead = (1 << 1),
264  kEffectronBumped = (1 << 2)
265 };
266 
267 typedef uint32 EffectronFlags;
268 
269 //-----------------------------------------------------------------------
270 // EffectronSize Type
271 
272 typedef Extent16 EffectronSize;
273 
274 //-----------------------------------------------------------------------
275 // Effectron
276 
277 class Effectron {
278  friend struct StorageEffectron;
279 
280  EffectronFlags _flags; // this effectrons status
281  EffectronSize _size; // this effectrons size
282  Rect16 _hitBox; // hitbox for clicking this item
283  // dispnode needs the latter
284 
285 public:
286  SpellInstance *_parent; // pointer back to the spell that spawned this
287 
288  int16 _partno; // Which effectron in a group this represents
289  Point16 _screenCoords; // screen coordinates last drawn at
290 
291  TilePoint _start, // travelling from
292  _finish, // travelling to
293  _current, // current position
294  _velocity, // current velocity
295  _acceleration; // current acceleration
296  uint16 _totalSteps, // discrete jumps in the path
297  _stepNo; // current jump
298 
299  spellHeight _hgt; // collision detection stuff
300  spellBreadth _brd;
301 
302  SpellPositionSeed _pos; // These three are part of an old way of
303  SpellSpritationSeed _spr; // updating effectrons
304  SpellAge _age;
305 
306 
307 
308  Effectron();
309  Effectron(uint16 newPos, uint16 newDir);
311 
312  void drawEffect();
313  void updateEffect(int32 deltaTime);
314 
315  inline TilePoint SpellPos() {
316  return _current;
317  }
318  inline int32 spriteID() {
319  return _spr;
320  }
321 
322  inline void hide() {
323  _flags |= kEffectronHidden;
324  }
325  inline void unhide() {
326  _flags &= (~kEffectronHidden);
327  }
328  inline bool isHidden() const {
329  return _flags & kEffectronHidden;
330  }
331  inline void kill() {
332  _flags |= kEffectronDead;
333  }
334  inline int isDead() const {
335  return _flags & kEffectronDead;
336  }
337  inline void bump();
338  inline int isBumped() const {
339  return _flags & kEffectronBumped;
340  }
341 
342  inline GameWorld *world() const;
343  inline int16 getMapNum() const;
344 
345  inline EffectID spellID();
346  inline SpellDisplayPrototype *spell();
347  inline EffectID effectID();
348  inline EffectDisplayPrototype *effect();
349  inline EffectronFlags staCall();
350  inline TilePoint posCall();
351  inline SpellSpritationSeed sprCall();
352  inline spellHeight hgtCall();
353  inline spellBreadth brdCall();
354  inline void initCall(int16);
355 };
356 
357 } // end of namespace Saga2
358 
359 #endif
Definition: speldefs.h:277
Definition: tile.h:388
Definition: actor.h:32
Definition: tcoords.h:127
Definition: spelshow.h:229
Definition: rect.h:42
Definition: spelshow.h:292
Definition: objects.h:768
Definition: objects.h:118
Definition: spellio.h:156
Definition: speldefs.h:139
Definition: spelshow.h:112
Definition: rect.h:290
Definition: spellio.h:115