ScummVM API documentation
spelshow.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_SPELSHOW_H
27 #define SAGA2_SPELSHOW_H
28 
29 #include "saga2/dispnode.h"
30 #include "saga2/speldefs.h"
31 
32 namespace Saga2 {
33 
34 //-----------------------------------------------------------------------
35 // Effectron List
36 
37 typedef DisplayNodeList EffectronList;
38 
39 //-----------------------------------------------------------------------
40 // Spell control functions
41 // Various instances of these can be used in different combinations to
42 // yield different shaped spells. Each spell will need one each of
43 // these types of functions:
44 //
45 // Effectron Status
46 // This returns the state of a given effectron as a function of time
47 //
48 // Spell Spritation
49 // Returns a sprite facing as a function of time.
50 //
51 // Spell Location
52 // Returns the position of the effectron as a function of time
53 //
54 // Spell Height
55 // This is NOT the effectron's Z coordinate. It is the height used
56 // for collision detection purposes
57 //
58 // Spell Breadth
59 // This is the effectron's cross section for collision detection
60 // purposes.
61 //
62 
63 //-----------------------------------------------------------------------
64 // Spell Status
65 
66 typedef EffectronFlags SpellStatusFunction(Effectron *);
67 
68 #define SPELLSTATUSFUNCTION(fname) EffectronFlags fname( Effectron * effectron )
69 
70 //-----------------------------------------------------------------------
71 // Spell Spritation
72 
73 typedef SpellPoseID SpellSpritationFunction(const Effectron *const);
74 
75 #define SPELLSPRITATIONFUNCTION(fname) SpellPoseID fname( const Effectron * const effectron )
76 
77 //-----------------------------------------------------------------------
78 // Spell Location Calls
79 
80 typedef TilePoint SpellLocationFunction(const Effectron *const);
81 
82 #define SPELLLOCATIONFUNCTION(fname) TilePoint fname( const Effectron * const effectron )
83 
84 //-----------------------------------------------------------------------
85 // Spell Height
86 
87 typedef spellHeight SpellHeightFunction(const Effectron *const);
88 
89 #define SPELLHEIGHTFUNCTION(fname) spellHeight fname( const Effectron * const effectron )
90 
91 //-----------------------------------------------------------------------
92 // Spell width
93 
94 typedef spellBreadth SpellBreadthFunction(const Effectron *const);
95 
96 #define SPELLBREADTHFUNCTION(fname) spellBreadth fname( const Effectron * const effectron )
97 
98 //-----------------------------------------------------------------------
99 // Spell init
100 
101 typedef void SpellInitFunction(Effectron *);
102 
103 #define SPELLINITFUNCTION(fname) void fname( Effectron * effectron )
104 
105 
106 //-----------------------------------------------------------------------
107 // EffectronDisplayPrototype
108 // This tracks the functions needed to display a particular type of
109 // spell on the screen. (Ball spells, bolt spells, etc)
110 //
111 
113  static SPELLLOCATIONFUNCTION(nullLocation) {
114  return TilePoint(0, 0, 0);
115  }
116  static SPELLSPRITATIONFUNCTION(nullSpritation) {
117  return 0;
118  }
119  static SPELLSTATUSFUNCTION(nullStatus) {
120  return kEffectronDead;
121  }
122  static SPELLHEIGHTFUNCTION(nullHeight) {
123  return 0;
124  }
125  static SPELLBREADTHFUNCTION(nullBreadth) {
126  return 0;
127  }
128  static SPELLINITFUNCTION(nullInit) {
129  }
130 
131  EffectID _ID;
132 public:
133  int16 _nodeCount;
134  EffectDisplayPrototype *_next;
135 
136  SpellLocationFunction *_location;
137  SpellSpritationFunction *_spriteno;
138  SpellStatusFunction *_status;
139  SpellHeightFunction *_height;
140  SpellBreadthFunction *_breadth;
141  SpellInitFunction *_init;
142 
144  _nodeCount = 0;
145  _next = NULL;
146  _location = &nullLocation;
147  _spriteno = &nullSpritation;
148  _status = &nullStatus;
149  _height = &nullHeight;
150  _breadth = &nullBreadth;
151  _init = &nullInit;
152  }
153 
155  int16 nodes,
156  SpellLocationFunction *newLocation,
157  SpellSpritationFunction *newSpriteno,
158  SpellStatusFunction *newStatus,
159  SpellHeightFunction *newHeight,
160  SpellBreadthFunction *newBreadth,
161  SpellInitFunction *newInit);
163  if (_next) delete _next;
164  _next = NULL;
165  }
166  void setID(EffectID i) {
167  _ID = i;
168  }
169  EffectID thisID() {
170  return _ID;
171  }
172 };
173 
175 
176 //-----------------------------------------------------------------------
177 // Effect Display Prototype List
178 //
179 // This class embodies a global list of EDPs
180 //
181 
182 
184  pEffectDisplayPrototype *_effects;
185  uint16 _count;
186  uint16 _maxCount;
187 
188 public:
191 
192  int32 add(EffectDisplayPrototype *edp) ;
193  void cleanup();
194  void append(EffectDisplayPrototype *edp, int32 acount);
195  EffectDisplayPrototype *operator[](EffectID e);
196 };
197 
198 //-----------------------------------------------------------------------
199 // Effectron collision flags
200 //
201 // need to track whether things
202 // bounce/die/stop/ignore
203 // when hitting
204 // actors/objects/terrain
205 //
206 
207 enum effectCollisionCont {
208  kEcFlagNone = 0,
209  kEcFlagBounce,
210  kEcFlagDie,
211  kEcFlagStop
212 };
213 
214 enum effectDirectionInit {
215  kDiFlagZero = 0,
216  kDiFlagInc = 1,
217  kDiFlagInc2 = 2,
218  kDiFlagInc3 = 3,
219  kDiFlagInc4 = 4,
220  kDiFlagRand = 5
221 };
222 
223 
224 //-----------------------------------------------------------------------
225 // SpellDisplayPrototype
226 // All the information needed to display a spell
227 // Combines a SpellEffectPrototype with the appropriate sprites
228 
230  SpellID _ID;
231 public:
232  EffectID _effect; // Effect ID
233  int32 _effParm1; // effect setting 1
234  int32 _effParm2; // effect setting 1
235  int32 _effParm3; // effect setting 1
236  int32 _effParm4; // effect setting 1
237 
238  effectDirectionInit _scatter; // direction init mode
239  effectCollisionCont _elasticity; // collision flags
240 
241  SpellAge _maxAge; // auto self-destruct age
242  SpellAge _implementAge; // auto self-destruct age
243  uint32 _primarySpriteID; // RES_ID(x, y, z, 0) to get sprites
244  uint8 _primarySpriteNo; // sprites available
245  uint32 _secondarySpriteID; // RES_ID(x, y, z, 0) to get sprites
246  uint8 _secondarySpriteNo; // sprites available
247  //uint8 _effCount; // effectrons to allocate
248 
249  uint8 _colorMap[4]; // indirect color map
250  // full init
252  EffectID, int32, int32, int32, int32, effectDirectionInit,
253  effectCollisionCont, SpellAge, uint32, uint8, uint8);
254 
256 
257  void getColorTranslation(ColorTable mainColors, Effectron *); // colors for effectrons
258  void setID(SpellID i) {
259  _ID = i;
260  }
261  SpellID thisID() {
262  return _ID;
263  }
264 };
265 
266 //-----------------------------------------------------------------------
267 // SpellDisplayPrototypeList
268 // A global list of sdp's
269 
271 
273  pSpellDisplayPrototype *_spells;
274  uint16 _count;
275  uint16 _maxCount;
276 
277 public:
278  SpellDisplayPrototypeList(uint16 s);
280 
281  void init();
282  void cleanup();
283  int32 add(SpellDisplayPrototype *sdp);
284  SpellDisplayPrototype *operator[](SpellID s);
285 };
286 
287 //-----------------------------------------------------------------------
288 // SpellInstance
289 // When a SpellDisplayPrototype is instantiated, one of these is created
290 // and the main display loop updates it till it dies
291 
293  friend struct StorageSpellInstance;
294 
295  SpellAge _implementAge; // age at which to implement the spell effects
296 public:
297  EffectDisplayPrototype *_effect; // effect prototype of the current effect
298  SpellDisplayPrototype *_dProto; // effect prototype of the current effect
299  SpellCaster *_caster;
300  SpellTarget *_target;
301  GameWorld *_world;
302  SpellAge _age;
303  EffectronList _eList;
304  SpellID _spell;
305  SpellAge _maxAge;
306  int16 _effSeq; // which effect in a sequence is being played
307 
308  SpellInstance(SpellCaster *newCaster, SpellTarget *newTarget, SpellID);
309  SpellInstance(SpellCaster *newCaster, GameObject &newTarget, SpellID);
310  SpellInstance(SpellCaster *newCaster, GameObject *newTarget, SpellID);
311  SpellInstance(SpellCaster *newCaster, TilePoint &newTarget, SpellID);
313  ~SpellInstance();
314 
315  void init();
316  void initEffect(TilePoint);
317  void readEffect(Common::InSaveFile *in, uint16 eListSize);
318  void writeEffect(Common::MemoryWriteStreamDynamic *out);
319  void termEffect();
320  size_t saveSize();
321 
322  bool buildList();
323  bool updateStates(int32 deltaTime);
324 };
325 
326 //-----------------------------------------------------------------------
327 // SpellDisplayList
328 // This class is used to keep track of all the spells currently
329 // displaying effectrons
330 
332 
334  uint16 _count;
335  uint16 _maxCount;
336 public :
337  pSpellInstance *_spells;
338 
339  void init();
340  void cleanup();
341  SpellDisplayList(uint16 s);
342  ~SpellDisplayList();
343 
344  void add(SpellInstance *newSpell);
345 
346  void tidyKill(uint16 spellNo);
347 
348  void buildList();
349  void updateStates(int32 deltaTime);
350 
351  void write(Common::OutSaveFile *outD);
352  void read(Common::InSaveFile *in);
353  void wipe();
354  size_t saveSize();
355 };
356 
357 
358 /* ===================================================================== *
359  Inlines
360  * ===================================================================== */
361 
362 //-----------------------------------------------------------------------
363 // Some functions that require the above definitions to work
364 
365 inline GameWorld *Effectron::world() const {
366  return _parent->_world;
367 }
368 inline int16 Effectron::getMapNum() const {
369  return _parent->_world->_mapNum;
370 }
371 
372 inline EffectID Effectron::spellID() {
373  return _parent->_spell;
374 }
375 inline SpellDisplayPrototype *Effectron::spell() {
376  return (*g_vm->_sdpList)[(SpellID)spellID()];
377 }
378 inline EffectID Effectron::effectID() {
379  return spell()->_effect;
380 }
381 inline EffectDisplayPrototype *Effectron::effect() {
382  return _parent->_effect;
383 }
384 inline EffectronFlags Effectron::staCall() {
385  return _parent->_effect->_status(this);
386 }
387 inline TilePoint Effectron::posCall() {
388  return _parent->_effect->_location(this);
389 }
390 inline SpellSpritationSeed Effectron::sprCall() {
391  return _parent->_effect->_spriteno(this);
392 }
393 inline spellHeight Effectron::hgtCall() {
394  return _parent->_effect->_height(this);
395 }
396 inline spellBreadth Effectron::brdCall() {
397  return _parent->_effect->_breadth(this);
398 }
399 inline void Effectron::initCall(int16 eno) {
400  _partno = eno;
401  _parent->_effect->_init(this);
402 }
403 
404 /* ===================================================================== *
405  prototypes
406  * ===================================================================== */
407 
408 int16 whichColorMap(EffectID eid, const Effectron *const effectron);
409 
410 //-----------------------------------------------------------------------
411 // Spell building block functions
412 // These are the functions available to update various aspects
413 // of Effectrons
414 
415 SPELLSTATUSFUNCTION(invisibleSpellSta);
416 SPELLSTATUSFUNCTION(auraSpellSta);
417 SPELLSTATUSFUNCTION(projectileSpellSta);
418 SPELLSTATUSFUNCTION(exchangeSpellSta);
419 SPELLSTATUSFUNCTION(boltSpellSta);
420 SPELLSTATUSFUNCTION(coneSpellSta);
421 SPELLSTATUSFUNCTION(ballSpellSta);
422 SPELLSTATUSFUNCTION(squareSpellSta);
423 SPELLSTATUSFUNCTION(waveSpellSta);
424 SPELLSTATUSFUNCTION(stormSpellSta);
425 SPELLSTATUSFUNCTION(beamSpellSta);
426 SPELLSTATUSFUNCTION(wallSpellSta);
427 
428 SPELLLOCATIONFUNCTION(invisibleSpellPos);
429 SPELLLOCATIONFUNCTION(auraSpellPos);
430 SPELLLOCATIONFUNCTION(projectileSpellPos);
431 SPELLLOCATIONFUNCTION(exchangeSpellPos);
432 SPELLLOCATIONFUNCTION(boltSpellPos);
433 SPELLLOCATIONFUNCTION(coneSpellPos);
434 SPELLLOCATIONFUNCTION(ballSpellPos);
435 SPELLLOCATIONFUNCTION(squareSpellPos);
436 SPELLLOCATIONFUNCTION(waveSpellPos);
437 SPELLLOCATIONFUNCTION(stormSpellPos);
438 SPELLLOCATIONFUNCTION(beamSpellPos);
439 SPELLLOCATIONFUNCTION(wallSpellPos);
440 SPELLLOCATIONFUNCTION(glowSpellPos);
441 
442 SPELLSPRITATIONFUNCTION(invisibleSprites);
443 SPELLSPRITATIONFUNCTION(auraSprites);
444 SPELLSPRITATIONFUNCTION(projectileSprites);
445 SPELLSPRITATIONFUNCTION(exchangeSprites);
446 SPELLSPRITATIONFUNCTION(boltSprites);
447 SPELLSPRITATIONFUNCTION(coneSprites);
448 SPELLSPRITATIONFUNCTION(ballSprites);
449 SPELLSPRITATIONFUNCTION(squareSprites);
450 SPELLSPRITATIONFUNCTION(waveSprites);
451 SPELLSPRITATIONFUNCTION(stormSprites);
452 SPELLSPRITATIONFUNCTION(beamSprites);
453 SPELLSPRITATIONFUNCTION(wallSprites);
454 
455 SPELLHEIGHTFUNCTION(ShortTillThere);
456 SPELLHEIGHTFUNCTION(GrowLinear);
457 SPELLBREADTHFUNCTION(StaticHeight);
458 
459 SPELLBREADTHFUNCTION(ThinTillThere);
460 SPELLBREADTHFUNCTION(BulkLinear);
461 SPELLBREADTHFUNCTION(StaticBreadth);
462 
463 SPELLINITFUNCTION(invisibleSpellInit);
464 SPELLINITFUNCTION(auraSpellInit);
465 SPELLINITFUNCTION(projectileSpellInit);
466 SPELLINITFUNCTION(exchangeSpellInit);
467 SPELLINITFUNCTION(boltSpellInit);
468 SPELLINITFUNCTION(coneSpellInit);
469 SPELLINITFUNCTION(ballSpellInit);
470 SPELLINITFUNCTION(squareSpellInit);
471 SPELLINITFUNCTION(waveSpellInit);
472 SPELLINITFUNCTION(stormSpellInit);
473 SPELLINITFUNCTION(glowSpellInit);
474 SPELLINITFUNCTION(beamSpellInit);
475 SPELLINITFUNCTION(wallSpellInit);
476 
477 } // end of namespace Saga2
478 
479 #endif //SPELLBUK_H
Definition: speldefs.h:277
Definition: spellio.h:57
Definition: savefile.h:54
Definition: actor.h:32
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: stream.h:745
Definition: spelshow.h:333
Definition: spelshow.h:183
Definition: spelshow.h:229
Definition: spelshow.h:292
Definition: objects.h:768
Definition: objects.h:118
Definition: spellio.h:132
Definition: speldefs.h:139
Definition: spelshow.h:112
Definition: spelshow.h:272