Debian Codegraph @

engine/include/spells.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name spells.h - The Spells. */
11 //
12 // (c) Copyright 1999-2016 by Vladi Belperchinov-Shabanski,
13 // Joris DAUPHIN, and Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28
29 #ifndef __SPELLS_H__
30 #define __SPELLS_H__
31
32 //@{
33
34 /*----------------------------------------------------------------------------
35 -- Includes
36 ----------------------------------------------------------------------------*/
37
38 #include <string>
39 #include <vector>
40 #include "unitsound.h"
41
42 /*----------------------------------------------------------------------------
43 -- Declarations
44 ----------------------------------------------------------------------------*/
45
46 class CUnit;
47 class CUnitType;
48 class CPlayer;
49 struct lua_State;
50 class SpellType;
51 class MissileType;
52
53 /*----------------------------------------------------------------------------
54 -- Definitons
55 ----------------------------------------------------------------------------*/
56
57 /**
58 ** Different targets.
59 */
60 enum TargetType {
61 TargetSelf,
62 TargetPosition,
63 TargetUnit
64 };
65
66 /**
67 ** Different targets.
68 */
69 enum LocBaseType {
70 LocBaseCaster,
71 LocBaseTarget
72 };
73
74 /**
75 ** This struct is used for defining a missile start/stop location.
76 **
77 ** It's evaluated like this, and should be more or less flexible.:
78 ** base coordinates(caster or target) + (AddX,AddY) + (rand()%AddRandX,rand()%AddRandY)
79 */
80 class SpellActionMissileLocation {
81 public:
82 SpellActionMissileLocation(LocBaseType base) : Base(base), AddX(0), AddY(0),
83 AddRandX(0), AddRandY(0) {} ;
84
85 LocBaseType Base; /// The base for the location (caster/target)
86 int AddX; /// Add to the X coordinate
87 int AddY; /// Add to the X coordinate
88 int AddRandX; /// Random add to the X coordinate
89 int AddRandY; /// Random add to the X coordinate
90 };
91
92 class SpellActionTypeAdjustVariable {
93 public:
94 SpellActionTypeAdjustVariable() : Enable(0), Value(0), Max(0), Increase(0),
95 ModifEnable(0), ModifValue(0), ModifMax(0), ModifIncrease(0),
96 InvertEnable(0), AddValue(0), AddMax(0), AddIncrease(0), IncreaseTime(0),
97 TargetIsCaster(0) {};
98
99 int Enable; /// Value to affect to this field.
100 int Value; /// Value to affect to this field.
101 int Max; /// Value to affect to this field.
102 int Increase; /// Value to affect to this field.
103
104 char ModifEnable; /// true if we modify this field.
105 char ModifValue; /// true if we modify this field.
106 char ModifMax; /// true if we modify this field.
107 char ModifIncrease; /// true if we modify this field.
108
109 char InvertEnable; /// true if we invert this field.
110 int AddValue; /// Add this value to this field.
111 int AddMax; /// Add this value to this field.
112 int AddIncrease; /// Add this value to this field.
113 int IncreaseTime; /// How many time increase the Value field.
114 char TargetIsCaster; /// true if the target is the caster.
115 };
116
117
118 /**
119 ** Generic spell action virtual class.
120 ** Spells are sub class of this one
121 */
122 class SpellActionType {
123 public:
124 SpellActionType(int mod = 0) : ModifyChargeCaster(mod) {};
125 virtual ~SpellActionType() {};
126
127 virtual int Cast(CUnit *caster, const SpellType *spell,
128 CUnit *target, int x, int y) = 0;
129
130 const int ModifyChargeCaster;
131 };
132
133 //
134 // Specific spells.
135 //
136
137 class AreaAdjustVitals : public SpellActionType
138 {
139 public:
140 AreaAdjustVitals() : HP(0), Charge(0) {};
141 virtual int Cast(CUnit *caster, const SpellType *spell,
142 CUnit *target, int x, int y);
143
144 int HP; /// Target HP gain.(can be negative)
145 int Charge; /// Target charge gain.(can be negative)
146 } ;
147
148 class SpawnMissile : public SpellActionType {
149 public:
150 SpawnMissile() : Damage(0), TTL(-1), Delay(0),
151 StartPoint(LocBaseCaster), EndPoint(LocBaseTarget), Missile(0) {};
152 virtual int Cast(CUnit *caster, const SpellType *spell,
153 CUnit *target, int x, int y);
154
155 int Damage; /// Missile damage.
156 int TTL; /// Missile TTL.
157 int Delay; /// Missile original delay.
158 SpellActionMissileLocation StartPoint; /// Start point description.
159 SpellActionMissileLocation EndPoint; /// Start point description.
160 MissileType *Missile; /// Missile fired on cast
161 };
162
163 class Demolish : public SpellActionType {
164 public:
165 Demolish() : Damage(0), Range(0) {};
166 virtual int Cast(CUnit *caster, const SpellType *spell,
167 CUnit *target, int x, int y);
168
169 int Damage; /// Damage for every unit in range.
170 int Range; /// Range of the explosion.
171 };
172
173 class AreaBombardment : public SpellActionType {
174 public:
175 AreaBombardment() : Fields(0), Shards(0), Damage(0),
176 StartOffsetX(0), StartOffsetY(0), Missile(NULL) {};
177 virtual int Cast(CUnit *caster, const SpellType *spell,
178 CUnit *target, int x, int y);
179
180 int Fields; /// The size of the affected square.
181 int Shards; /// Number of shards thrown.
182 int Damage; /// Damage for every shard.
183 int StartOffsetX; /// The offset of the missile start point to the hit location.
184 int StartOffsetY; /// The offset of the missile start point to the hit location.
185 MissileType *Missile; /// Missile fired on cast
186 };
187
188 class SpawnPortal : public SpellActionType {
189 public:
190 SpawnPortal() : PortalType(0) {};
191 virtual int Cast(CUnit *caster, const SpellType *spell,
192 CUnit *target, int x, int y);
193
194 CUnitType *PortalType; /// The unit type spawned
195 };
196
197 class AdjustVariable : public SpellActionType {
198 public:
199 AdjustVariable() : Var (NULL) {};
200 ~AdjustVariable() { delete [] (this->Var); };
201 virtual int Cast(CUnit *caster, const SpellType *spell,
202 CUnit *target, int x, int y);
203
204 SpellActionTypeAdjustVariable *Var;
205 };
206
207 class AdjustVitals : public SpellActionType {
208 public:
209 AdjustVitals() : SpellActionType(1), HP(0), Charge(0), MaxMultiCast(0) {};
210 virtual int Cast(CUnit *caster, const SpellType *spell,
211 CUnit *target, int x, int y);
212
213 int HP; /// Target HP gain.(can be negative)
214 int Charge; /// Target Charge gain.(can be negative)
215 /// This spell is designed to be used wit very small amounts. The spell
216 /// can scale up to MaxMultiCast times. Use 0 for infinite.
217 int MaxMultiCast;
218 };
219
220 class Polymorph : public SpellActionType {
221 public:
222 Polymorph() : SpellActionType(1), NewForm(NULL), PlayerNeutral(0) {};
223 virtual int Cast(CUnit *caster, const SpellType *spell,
224 CUnit *target, int x, int y);
225
226 CUnitType *NewForm; /// The new form
227 int PlayerNeutral; /// Convert the unit to the neutral player.
228 // TODO: temporary polymorphs would be awesome, but hard to implement
229 };
230
231 class Summon : public SpellActionType {
232 public:
233 Summon() : SpellActionType(1), UnitType(NULL), TTL(0), RequireCorpse(0) {};
234 virtual int Cast(CUnit *caster, const SpellType *spell,
235 CUnit *target, int x, int y);
236
237 CUnitType *UnitType; /// Type of unit to be summoned.
238 int TTL; /// Time to live for summoned unit. 0 means infinite
239 int RequireCorpse; /// Corpse consumed while summoning.
240 };
241
242 class Capture : public SpellActionType {
243 public:
244 Capture() : SacrificeEnable(0), Damage(0), DamagePercent(0) {};
245 virtual int Cast(CUnit *caster, const SpellType *spell,
246 CUnit *target, int x, int y);
247
248 char SacrificeEnable; /// true if the caster dies after casting.
249 int Damage; /// damage the spell does if unable to caputre
250 int DamagePercent; /// percent the target must be damaged for a
251 /// capture to suceed.
252 };
253
254 /*
255 ** *******************
256 ** Target definition.
257 ** *******************
258 */
259
260 class Target {
261 public:
262 Target(TargetType type, CUnit *unit, int x, int y) :
263 Type(type), Unit(unit), X(x), Y(y) {}
264
265 TargetType Type; /// type of target.
266 CUnit *Unit; /// Unit target.
267 int X; /// x coord.
268 int Y; /// y coord.
269 };
270
271 /*
272 ** *******************
273 ** Conditions definition.
274 ** *******************
275 */
276
277 class ConditionInfoVariable {
278 public:
279 ConditionInfoVariable() : Enable(0), MinValue(0), MaxValue(0),
280 MinMax(0), MinValuePercent(0), MaxValuePercent(0),
281 ConditionApplyOnCaster(0) {};
282
283 char Enable; /// Target is 'user defined variable'.
284
285 int MinValue; /// Target must have more Value than that.
286 int MaxValue; /// Target must have less Value than that.
287 int MinMax; /// Target must have more Max than that.
288 int MinValuePercent; /// Target must have more (100 * Value / Max) than that.
289 int MaxValuePercent; /// Target must have less (100 * Value / Max) than that.
290
291 char ConditionApplyOnCaster; /// true if these condition are for caster.
292 // FIXME : More (increase, MaxMax) ?
293 };
294
295 /**
296 ** Conditions for a spell.
297 **
298 ** @todo Move more parameters into this structure.
299 */
300 class ConditionInfo {
301 public:
302 ConditionInfo() : Alliance(0), Opponent(0), TargetSelf(0),
303 Building(0), Organic(0), Variable(NULL) {};
304 ~ConditionInfo() {
305 delete[] Variable;
306 };
307
308 //
309 // Conditions that check specific flags. Possible values are the defines below.
310 //
311 #define CONDITION_FALSE 1
312 #define CONDITION_TRUE 0
313 #define CONDITION_ONLY 2
314 char Alliance; /// Target is allied. (neutral is neither allied, nor opponent)
315 char Opponent; /// Target is opponent. (neutral is neither allied, nor opponent)
316 char TargetSelf; /// Target is the same as the caster.
317
318 char Building; /// Target is a building
319 char Organic; /// Target is organic
320
321 ConditionInfoVariable *Variable;
322 //
323 // @todo more? feel free to add, here and to
324 // @todo PassCondition, CclSpellParseCondition, SaveSpells
325 //
326 };
327
328 /**
329 ** Informations about the autocasting mode.
330 */
331 class AutoCastInfo {
332 public:
333 AutoCastInfo() : Range(0), Condition(0), Combat(0) {};
334 ~AutoCastInfo() { delete Condition; };
335 /// @todo this below is SQUARE!!!
336 int Range; /// Max range of the target.
337
338 ConditionInfo *Condition; /// Conditions to cast the spell.
339
340 /// Detalied generic conditions (not per-target, where Condition is evaluated.)
341 /// Combat mode is when there are hostile non-coward units around
342 int Combat; /// If it should be casted in combat
343
344 /// @todo Add stuff here for target preference.
345 /// @todo Heal units with the lowest hit points first.
346 };
347
348 /**
349 ** Base structure of a spell type.
350 */
351 class SpellType {
352 public:
353 SpellType(int slot, const std::string &ident);
354 ~SpellType();
355
356 // Identification stuff
357 std::string Ident; /// Spell unique identifier (spell-holy-vision)
358 std::string Name; /// Spell name shown by the engine
359 int Slot; /// Spell numeric identifier
360
361 // Spell Specifications
362 TargetType Target; /// Targetting information. See TargetType.
363 std::vector<SpellActionType *> Action; /// More arguments for spell (damage, delay, additional sounds...).
364
365 int Range; /// Max range of the target.
366 #define INFINITE_RANGE 0xFFFFFFF
367 int ChargeCost; /// Required charge for each cast.
368 int RepeatCast; /// If the spell will be cast again until out of targets.
369
370 int DependencyId; /// Id of upgrade, -1 if no upgrade needed for cast the spell.
371 ConditionInfo *Condition; /// Conditions to cast the spell. (generic (no test for each target))
372
373 // Autocast informations. No AICast means the AI use AutoCast.
374 AutoCastInfo *AutoCast; /// AutoCast information for your own units
375 AutoCastInfo *AICast; /// AutoCast information for ai. More detalied.
376
377 // Graphics and sounds. Add something else here?
378 SoundConfig SoundWhenCast; /// Sound played if cast
379 };
380
381 /*----------------------------------------------------------------------------
382 -- Variables
383 ----------------------------------------------------------------------------*/
384
385 /**
386 ** Define the names and effects of all available spells.
387 */
388 extern std::vector<SpellType *> SpellTypeTable;
389
390
391 /*----------------------------------------------------------------------------
392 -- Functions
393 ----------------------------------------------------------------------------*/
394
395 /// register fonction.
396 extern void SpellCclRegister(void);
397
398 /// init spell tables
399 extern void InitSpells(void);
400
401 /// done spell tables
402 extern void CleanSpells(void);
403
404 /// return 1 if spell is availible, 0 if not (must upgrade)
405 extern bool SpellIsAvailable(const CPlayer *player, int SpellId);
406
407 /// returns true if spell can be casted (enough charge, valid target)
408 extern bool CanCastSpell(const CUnit *caster, const SpellType *spell,
409 const CUnit *target, int x, int y);
410
411 /// cast spell on target unit or place at x,y
412 extern int SpellCast(CUnit *caster, const SpellType *spell,
413 CUnit *target, int x, int y);
414
415 /// auto cast the spell if possible
416 extern int AutoCastSpell(CUnit *caster, const SpellType *spell);
417
418 /// return spell type by ident string
419 extern SpellType *SpellTypeByIdent(const std::string &ident);
420
421 /// return 0, 1, 2 for true, only, false.
422 extern char Ccl2Condition(lua_State *l, const char *value);
423
424 //@}
425
426 #endif // !__SPELLS_H__