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

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__
CPlayer
Diplomacy states for CommandDiplomacy.
Definition: player.h:83
SpellType::Condition
ConditionInfo * Condition
Id of upgrade, -1 if no upgrade needed for cast the spell.
Definition: spells.h:228
MissileType
Base structure of missile-types.
Definition: missile.h:343
AutoCastInfo::Attacker
int Attacker
If it should be casted in combat.
Definition: spells.h:195
ConditionInfo::TargetSelf
char TargetSelf
Target is opponent. (neutral is neither allied, nor opponent)
Definition: spells.h:155
SpellType::AutoCast
AutoCastInfo * AutoCast
Conditions to cast the spell. (generic (no test for each target))
Definition: spells.h:231
ConditionInfoVariable::MinMax
int MinMax
Target must have less Value than that.
Definition: spells.h:123
MaxCosts
@ MaxCosts
resource 6
Definition: upgrade_structs.h:70
Target::Type
TargetType Type
Definition: spells.h:98
SpellType::Ident
std::string Ident
Definition: spells.h:212
ConditionInfo::ConditionInfo
ConditionInfo()
Definition: spells.h:139
Target::Target
Target(TargetType type, CUnit *unit, const Vec2i &pos)
Definition: spells.h:95
ConditionInfo::~ConditionInfo
~ConditionInfo()
Definition: spells.h:141
SpellType::SpellType
SpellType(int slot, const std::string &ident)
Definition: spells.cpp:574
AutoCastInfo::Corpse
int Corpse
If it should be casted on unit which attacks.
Definition: spells.h:196
AutoCastInfo::PriorytyVar
int PriorytyVar
Min range of the target.
Definition: spells.h:187
AutoCastInfo::Combat
int Combat
Conditions to cast the spell.
Definition: spells.h:194
SpellActionType::Cast
virtual int Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos)=0
SpellActionType::SpellActionType
SpellActionType(int mod=0)
Definition: spells.h:66
AutoCastInfo::Range
int Range
Definition: spells.h:182
vec2i.h
SpellType::Name
std::string Name
Spell unique identifier (spell-holy-vision)
Definition: spells.h:213
AutoCastInfo::MinRange
int MinRange
Max range of the target.
Definition: spells.h:185
TargetSelf
@ TargetSelf
Definition: spells.h:81
ConditionInfo::Alliance
char Alliance
Definition: spells.h:153
ConditionInfoVariable::Check
bool Check
Target is 'user defined variable'.
Definition: spells.h:117
SpellType::IsCasterOnly
bool IsCasterOnly() const
Sound played if cast.
Definition: spells.h:237
SoundConfig
Definition: unitsound.h:54
CONDITION_FALSE
#define CONDITION_FALSE
Definition: spells.h:150
CUnitType
Definition: unittype.h:508
CanCastSpell
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:457
SpellActionType::Parse
virtual void Parse(lua_State *l, int startIndex, int endIndex)=0
Target
Definition: spells.h:92
SpellType::Costs
int Costs[MaxCosts]
If the spell will be cast again until out of targets.
Definition: spells.h:224
SpellType::Action
std::vector< SpellActionType * > Action
Targeting information. See TargetType.
Definition: spells.h:218
ConditionInfoVariable::ConditionInfoVariable
ConditionInfoVariable()
Definition: spells.h:112
SpellType::CoolDown
int CoolDown
Resource costs of spell.
Definition: spells.h:225
SpellTypeTable
std::vector< SpellType * > SpellTypeTable
Definition: spells.cpp:64
Vec2T
Definition: vec2i.h:36
ConditionInfoVariable::Enable
char Enable
Definition: spells.h:114
AutoCastInfo::ReverseSort
bool ReverseSort
Variable to sort autocast targets by priority.
Definition: spells.h:188
SpellActionType
Definition: spells.h:63
SpellType::Slot
int Slot
Spell name shown by the engine.
Definition: spells.h:214
Target::Unit
CUnit * Unit
type of target.
Definition: spells.h:99
ConditionInfo::Opponent
char Opponent
Target is allied. (neutral is neither allied, nor opponent)
Definition: spells.h:154
ConditionInfoVariable::MaxValuePercent
int MaxValuePercent
Target must have more (100 * Value / Max) than that.
Definition: spells.h:125
ConditionInfoVariable::MinValuePercent
int MinValuePercent
Target must have more Max than that.
Definition: spells.h:124
SpellCast
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:511
AutoCastInfo
Definition: spells.h:170
AutoCastSpell
int AutoCastSpell(CUnit &caster, const SpellType &spell)
auto cast the spell if possible
Definition: spells.cpp:474
SpellType::Target
TargetType Target
Spell numeric identifier.
Definition: spells.h:217
AutoCastInfo::AutoCastInfo
AutoCastInfo()
Definition: spells.h:176
SpellCclRegister
void SpellCclRegister()
register fonction.
Definition: script_spell.cpp:437
SpellActionType::~SpellActionType
virtual ~SpellActionType()
Definition: spells.h:67
ConditionInfo::BoolFlag
char * BoolFlag
Target is the same as the caster.
Definition: spells.h:157
SpellType::DependencyId
int DependencyId
How much time spell needs to be cast again.
Definition: spells.h:227
ConditionInfo
Definition: spells.h:136
ConditionInfoVariable::MaxValue
int MaxValue
Target must have more Value than that.
Definition: spells.h:122
AutoCastInfo::PositionAutoCast
LuaCallback * PositionAutoCast
If it should be casted on corpses.
Definition: spells.h:199
SpellTypeByIdent
SpellType * SpellTypeByIdent(const std::string &ident)
return spell type by ident string
Definition: spells.cpp:418
SpellType::Range
int Range
More arguments for spell (damage, delay, additional sounds...).
Definition: spells.h:220
InitSpells
void InitSpells()
init spell tables
Definition: spells.cpp:407
Ccl2Condition
char Ccl2Condition(lua_State *l, const char *value)
return 0, 1, 2 for true, only, false.
Definition: script_spell.cpp:118
SpellIsAvailable
bool SpellIsAvailable(const CPlayer &player, int SpellId)
return 1 if spell is available, 0 if not (must upgrade)
Definition: spells.cpp:439
TargetPosition
@ TargetPosition
Definition: spells.h:82
SpellActionType::ModifyManaCaster
const int ModifyManaCaster
Definition: spells.h:73
LuaCallback
Definition: luacallback.h:41
SpellType::RepeatCast
int RepeatCast
Required mana for each cast.
Definition: spells.h:223
AutoCastInfo::~AutoCastInfo
~AutoCastInfo()
Definition: spells.h:178
unitsound.h
luacallback.h
SpellType::ManaCost
int ManaCost
Definition: spells.h:222
AutoCastInfo::Condition
ConditionInfo * Condition
If true, small values have the highest priority.
Definition: spells.h:190
ConditionInfoVariable::ExactValue
int ExactValue
True if need to check that variable.
Definition: spells.h:119
ConditionInfoVariable::ExceptValue
int ExceptValue
Target must have exactly ExactValue of it's value.
Definition: spells.h:120
SpellType::AICast
AutoCastInfo * AICast
AutoCast information for your own units.
Definition: spells.h:232
TargetType
TargetType
Definition: spells.h:80
SpellType::SoundWhenCast
SoundConfig SoundWhenCast
AutoCast information for ai. More detalied.
Definition: spells.h:235
Target::targetPos
Vec2i targetPos
Unit target.
Definition: spells.h:100
ConditionInfoVariable::ConditionApplyOnCaster
char ConditionApplyOnCaster
Target must have less (100 * Value / Max) than that.
Definition: spells.h:127
CleanSpells
void CleanSpells()
done spell tables
Definition: spells.cpp:605
ConditionInfoVariable
Definition: spells.h:109
ACP_NOVALUE
#define ACP_NOVALUE
Definition: spells.h:174
SpellType
Definition: spells.h:205
SpellType::ForceUseAnimation
bool ForceUseAnimation
Definition: spells.h:241
CUnit
The big unit structure.
Definition: unit.h:135
TargetUnit
@ TargetUnit
Definition: spells.h:83
ConditionInfo::Variable
ConditionInfoVariable * Variable
User defined boolean flag.
Definition: spells.h:159
SpellType::~SpellType
~SpellType()
Definition: spells.cpp:586
ConditionInfo::CheckFunc
LuaCallback * CheckFunc
Definition: spells.h:160
ConditionInfoVariable::MinValue
int MinValue
Target mustn't have ExceptValue of it's value.
Definition: spells.h:121
(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.