_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
spells.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1999-2006 by Vladi Belperchinov-Shabanski,
14 // Joris DAUPHIN, and Jimmy Salmon
15 //
16 // This program is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; only version 2 of the License.
19 //
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with this program; if not, write to the Free Software
27 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 // 02111-1307, USA.
29 //
30 
31 #ifndef __SPELLS_H__
32 #define __SPELLS_H__
33 
35 
36 /*----------------------------------------------------------------------------
37 -- Includes
38 ----------------------------------------------------------------------------*/
39 
40 #include "luacallback.h"
41 #include "unitsound.h"
42 #include "vec2i.h"
43 
44 /*----------------------------------------------------------------------------
45 -- Declarations
46 ----------------------------------------------------------------------------*/
47 
48 class CUnit;
49 class CUnitType;
50 class CPlayer;
51 struct lua_State;
52 class SpellType;
53 class MissileType;
54 
55 /*----------------------------------------------------------------------------
56 -- Definitons
57 ----------------------------------------------------------------------------*/
58 
64 {
65 public:
66  SpellActionType(int mod = 0) : ModifyManaCaster(mod) {};
67  virtual ~SpellActionType() {};
68 
69  virtual int Cast(CUnit &caster, const SpellType &spell,
70  CUnit *target, const Vec2i &goalPos) = 0;
71  virtual void Parse(lua_State *l, int startIndex, int endIndex) = 0;
72 
73  const int ModifyManaCaster;
74 };
75 
76 
80 enum TargetType {
84 };
85 
86 /*
87 ** *******************
88 ** Target definition.
89 ** *******************
90 */
91 
92 class Target
93 {
94 public:
95  Target(TargetType type, CUnit *unit, const Vec2i &pos) :
96  Type(type), Unit(unit), targetPos(pos) {}
97 
101 };
102 
103 /*
104 ** *******************
105 ** Conditions definition.
106 ** *******************
107 */
108 
110 {
111 public:
115 
116  char Enable;
117  bool Check;
118 
121  int MinValue;
122  int MaxValue;
123  int MinMax;
126 
128  // FIXME : More (increase, MaxMax) ?
129 };
130 
137 {
138 public:
140  BoolFlag(NULL), Variable(NULL), CheckFunc(NULL) {};
142  {
143  delete[] BoolFlag;
144  delete[] Variable;
145  delete CheckFunc;
146  };
147  //
148  // Conditions that check specific flags. Possible values are the defines below.
149  //
150 #define CONDITION_FALSE 1
151 #define CONDITION_TRUE 0
152 #define CONDITION_ONLY 2
153  char Alliance;
154  char Opponent;
155  char TargetSelf;
156 
157  char *BoolFlag;
158 
161  //
162  // @todo more? feel free to add, here and to
163  // @todo PassCondition, CclSpellParseCondition, SaveSpells
164  //
165 };
166 
171 {
172 public:
173  // Special flags for priority sorting
174 #define ACP_NOVALUE -1
175 #define ACP_DISTANCE -2
179  {
180  delete Condition;
181  delete PositionAutoCast;
182  };
184  int Range;
185  int MinRange;
186 
188  bool ReverseSort;
189 
191 
194  int Combat;
195  int Attacker;
196  int Corpse;
197 
198  // Position autocast callback
200 };
201 
206 {
207 public:
208  SpellType(int slot, const std::string &ident);
209  ~SpellType();
210 
211  // Identification stuff
212  std::string Ident;
213  std::string Name;
214  int Slot;
215 
216  // Spell Specifications
218  std::vector<SpellActionType *> Action;
219 
220  int Range;
221 #define INFINITE_RANGE 0xFFFFFFF
222  int ManaCost;
225  int CoolDown;
226 
229 
230  // Autocast information. No AICast means the AI use AutoCast.
233 
234  // Graphics and sounds. Add something else here?
236 
237  bool IsCasterOnly() const
238  {
239  return !Range && Target == TargetSelf;
240  }
242 
243 };
244 
245 /*----------------------------------------------------------------------------
246 -- Variables
247 ----------------------------------------------------------------------------*/
248 
252 extern std::vector<SpellType *> SpellTypeTable;
253 
254 
255 /*----------------------------------------------------------------------------
256 -- Functions
257 ----------------------------------------------------------------------------*/
258 
260 extern void SpellCclRegister();
261 
263 extern void InitSpells();
264 
266 extern void CleanSpells();
267 
269 extern bool SpellIsAvailable(const CPlayer &player, int SpellId);
270 
272 extern bool CanCastSpell(const CUnit &caster, const SpellType &spell,
273  const CUnit *target, const Vec2i &goalPos);
274 
276 extern int SpellCast(CUnit &caster, const SpellType &spell,
277  CUnit *target, const Vec2i &goalPos);
278 
280 extern int AutoCastSpell(CUnit &caster, const SpellType &spell);
281 
283 extern SpellType *SpellTypeByIdent(const std::string &ident);
284 
286 extern char Ccl2Condition(lua_State *l, const char *value);
287 
289 
290 #endif // !__SPELLS_H__
int Range
Definition: spells.h:182
Definition: spells.h:136
ConditionInfo()
Definition: spells.h:139
int Corpse
If it should be casted on unit which attacks.
Definition: spells.h:196
virtual void Parse(lua_State *l, int startIndex, int endIndex)=0
~SpellType()
Definition: spells.cpp:584
SpellType(int slot, const std::string &ident)
Definition: spells.cpp:572
Definition: spells.h:81
Definition: spells.h:83
TargetType
Definition: spells.h:80
resource 6
Definition: upgrade_structs.h:70
int RepeatCast
Required mana for each cast.
Definition: spells.h:223
~ConditionInfo()
Definition: spells.h:141
bool CanCastSpell(const CUnit &caster, const SpellType &spell, const CUnit *target, const Vec2i &goalPos)
returns true if spell can be casted (enough mana, valid target)
Definition: spells.cpp:455
Definition: spells.h:92
std::string Name
Spell unique identifier (spell-holy-vision)
Definition: spells.h:213
int Attacker
If it should be casted in combat.
Definition: spells.h:195
int ManaCost
Definition: spells.h:222
int AutoCastSpell(CUnit &caster, const SpellType &spell)
auto cast the spell if possible
Definition: spells.cpp:472
bool ReverseSort
Variable to sort autocast targets by priority.
Definition: spells.h:188
ConditionInfoVariable * Variable
User defined boolean flag.
Definition: spells.h:159
The big unit structure.
Definition: unit.h:119
AutoCastInfo * AICast
AutoCast information for your own units.
Definition: spells.h:232
ConditionInfoVariable()
Definition: spells.h:112
int ExactValue
True if need to check that variable.
Definition: spells.h:119
bool IsCasterOnly() const
Sound played if cast.
Definition: spells.h:237
bool ForceUseAnimation
Definition: spells.h:241
int Combat
Conditions to cast the spell.
Definition: spells.h:194
int MinValuePercent
Target must have more Max than that.
Definition: spells.h:124
Definition: unitsound.h:54
int PriorytyVar
Min range of the target.
Definition: spells.h:187
LuaCallback * CheckFunc
Definition: spells.h:160
char Enable
Definition: spells.h:114
int MinRange
Max range of the target.
Definition: spells.h:185
Definition: unittype.h:467
TargetType Target
Spell numeric identifier.
Definition: spells.h:217
AutoCastInfo * AutoCast
Conditions to cast the spell. (generic (no test for each target))
Definition: spells.h:231
Definition: spells.h:170
virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos)=0
#define ACP_NOVALUE
Definition: spells.h:174
bool Check
Target is 'user defined variable'.
Definition: spells.h:117
TargetType Type
Definition: spells.h:98
char TargetSelf
Target is opponent. (neutral is neither allied, nor opponent)
Definition: spells.h:155
~AutoCastInfo()
Definition: spells.h:178
Definition: spells.h:63
int CoolDown
Resource costs of spell.
Definition: spells.h:225
SpellActionType(int mod=0)
Definition: spells.h:66
void CleanSpells()
done spell tables
Definition: spells.cpp:603
int Costs[MaxCosts]
If the spell will be cast again until out of targets.
Definition: spells.h:224
char Alliance
Definition: spells.h:153
SoundConfig SoundWhenCast
AutoCast information for ai. More detalied.
Definition: spells.h:235
int MinMax
Target must have less Value than that.
Definition: spells.h:123
Definition: spells.h:109
Diplomacy states for CommandDiplomacy.
Definition: player.h:79
std::string Ident
Definition: spells.h:212
Target(TargetType type, CUnit *unit, const Vec2i &pos)
Definition: spells.h:95
int ExceptValue
Target must have exactly ExactValue of it's value.
Definition: spells.h:120
Base structure of missile-types.
Definition: missile.h:343
AutoCastInfo()
Definition: spells.h:176
char Opponent
Target is allied. (neutral is neither allied, nor opponent)
Definition: spells.h:154
SpellType * SpellTypeByIdent(const std::string &ident)
return spell type by ident string
Definition: spells.cpp:416
int MinValue
Target mustn't have ExceptValue of it's value.
Definition: spells.h:121
Definition: luacallback.h:38
int Range
More arguments for spell (damage, delay, additional sounds...).
Definition: spells.h:220
LuaCallback * PositionAutoCast
If it should be casted on corpses.
Definition: spells.h:199
void SpellCclRegister()
register fonction.
Definition: script_spell.cpp:425
ConditionInfo * Condition
Id of upgrade, -1 if no upgrade needed for cast the spell.
Definition: spells.h:228
int SpellCast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos)
cast spell on target unit or place at x,y
Definition: spells.cpp:509
int DependencyId
How much time spell needs to be cast again.
Definition: spells.h:227
char ConditionApplyOnCaster
Target must have less (100 * Value / Max) than that.
Definition: spells.h:127
virtual ~SpellActionType()
Definition: spells.h:67
Definition: vec2i.h:36
int MaxValue
Target must have more Value than that.
Definition: spells.h:122
Definition: spells.h:82
int MaxValuePercent
Target must have more (100 * Value / Max) than that.
Definition: spells.h:125
char * BoolFlag
Target is the same as the caster.
Definition: spells.h:157
std::vector< SpellType * > SpellTypeTable
Definition: spells.cpp:64
CUnit * Unit
type of target.
Definition: spells.h:99
#define CONDITION_FALSE
Definition: spells.h:150
ConditionInfo * Condition
If true, small values have the highest priority.
Definition: spells.h:190
std::vector< SpellActionType * > Action
Targeting information. See TargetType.
Definition: spells.h:218
const int ModifyManaCaster
Definition: spells.h:73
void InitSpells()
init spell tables
Definition: spells.cpp:405
char Ccl2Condition(lua_State *l, const char *value)
return 0, 1, 2 for true, only, false.
Definition: script_spell.cpp:118
Vec2i targetPos
Unit target.
Definition: spells.h:100
bool SpellIsAvailable(const CPlayer &player, int SpellId)
return 1 if spell is available, 0 if not (must upgrade)
Definition: spells.cpp:437
int Slot
Spell name shown by the engine.
Definition: spells.h:214
Definition: spells.h:205
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.