1 /*
2  * Copyright 2011-2012 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 // Copyright (c) 1999-2000 ARKANE Studios SA. All rights reserved
44 
45 #ifndef ARX_GAME_SPELLS_H
46 #define ARX_GAME_SPELLS_H
47 
48 #include <stddef.h>
49 #include <string>
50 
51 #include "audio/AudioTypes.h"
52 #include "math/MathFwd.h"
53 #include "math/Angle.h"
54 #include "math/Random.h"
55 #include "math/Vector3.h"
56 #include "platform/Flags.h"
57 
58 class Entity;
59 class CSpellFx;
60 class TextureContainer;
61 
62 // Spells symbol list
63 enum Rune {
64 	RUNE_AAM = 0,     // Create
65 	RUNE_NHI,         // Negate
66 	RUNE_MEGA,        // Improve
67 	RUNE_YOK,         // Fire
68 	RUNE_TAAR,        // Projectile
69 	RUNE_KAOM,        // Protection
70 	RUNE_VITAE,       // Life
71 	RUNE_VISTA,       // Vision
72 	RUNE_STREGUM,     // Magic
73 	RUNE_MORTE,       // Death
74 	RUNE_COSUM,       // Object
75 	RUNE_COMUNICATUM, // Communication
76 	RUNE_MOVIS,       // Movement
77 	RUNE_TEMPUS,      // Time
78 	RUNE_FOLGORA,     // Storm
79 	RUNE_SPACIUM,     // Space
80 	RUNE_TERA,        // Earth
81 	RUNE_CETRIUS,     // Poison
82 	RUNE_RHAA,        // Lower
83 	RUNE_FRIDD,       // Ice
84 	RUNE_AKBAA,       // Akbaa
85 	RUNE_NONE = 255
86 };
87 const size_t RUNE_COUNT = 21;
88 
89 enum SpellcastFlag {
90 	SPELLCAST_FLAG_NODRAW         = (1<<0),
91 	SPELLCAST_FLAG_NOANIM         = (1<<1),
92 	SPELLCAST_FLAG_NOMANA         = (1<<2),
93 	SPELLCAST_FLAG_PRECAST        = (1<<3),
94 	SPELLCAST_FLAG_LAUNCHPRECAST  = (1<<4),
95 	SPELLCAST_FLAG_NOCHECKCANCAST = (1<<5),
96 	SPELLCAST_FLAG_NOSOUND        = (1<<6),
97 	SPELLCAST_FLAG_RESTORE        = (1<<7),
98 };
99 DECLARE_FLAGS(SpellcastFlag, SpellcastFlags)
100 DECLARE_FLAGS_OPERATORS(SpellcastFlags)
101 
102 // Spell list
103 enum Spell {
104 
105 	// LEVEL 1
106 	SPELL_MAGIC_SIGHT           ,//= 11,
107 	SPELL_MAGIC_MISSILE         ,//= 12,
108 	SPELL_IGNIT                 ,//= 13,
109 	SPELL_DOUSE                 ,//= 14,
110 	SPELL_ACTIVATE_PORTAL       ,//= 15,
111 
112 	// LEVEL 2
113 	SPELL_HEAL                  ,//= 21,
114 	SPELL_DETECT_TRAP           ,//= 22,
115 	SPELL_ARMOR                 ,//= 23,
116 	SPELL_LOWER_ARMOR           ,//= 24,
117 	SPELL_HARM                  ,//= 25,
118 
119 	// LEVEL 3
120 	SPELL_SPEED                 ,//= 31,
121 	SPELL_DISPELL_ILLUSION      ,//= 32,
122 	SPELL_FIREBALL              ,//= 33,
123 	SPELL_CREATE_FOOD           ,//= 34,
124 	SPELL_ICE_PROJECTILE        ,//= 35,
125 
126 	// LEVEL 4
127 	SPELL_BLESS                 ,//= 41,
128 	SPELL_DISPELL_FIELD         ,//= 42,
129 	SPELL_FIRE_PROTECTION       ,//= 43,
130 	SPELL_TELEKINESIS           ,//= 44,
131 	SPELL_CURSE                 ,//= 45,
132 	SPELL_COLD_PROTECTION       ,//= 46,
133 
134 	// LEVEL 5
135 	SPELL_RUNE_OF_GUARDING      ,//= 51,
136 	SPELL_LEVITATE              ,//= 52,
137 	SPELL_CURE_POISON           ,//= 53,
138 	SPELL_REPEL_UNDEAD          ,//= 54,
139 	SPELL_POISON_PROJECTILE     ,//= 55,
140 
141 	// LEVEL 6
142 	SPELL_RISE_DEAD             ,//= 61,
143 	SPELL_PARALYSE              ,//= 62,
144 	SPELL_CREATE_FIELD          ,//= 63,
145 	SPELL_DISARM_TRAP           ,//= 64,
146 	SPELL_SLOW_DOWN             ,//= 65, //secret
147 
148 	// LEVEL 7
149 	SPELL_FLYING_EYE            ,//= 71,
150 	SPELL_FIRE_FIELD            ,//= 72,
151 	SPELL_ICE_FIELD             ,//= 73,
152 	SPELL_LIGHTNING_STRIKE      ,//= 74,
153 	SPELL_CONFUSE               ,//= 75,
154 
155 	// LEVEL 8
156 	SPELL_INVISIBILITY          ,//= 81,
157 	SPELL_MANA_DRAIN            ,//= 82,
158 	SPELL_EXPLOSION             ,//= 83,
159 	SPELL_ENCHANT_WEAPON        ,//= 84,
160 	SPELL_LIFE_DRAIN            ,//= 85, //secret
161 
162 	// LEVEL 9
163 	SPELL_SUMMON_CREATURE       ,//= 91,
164 	SPELL_NEGATE_MAGIC          ,//= 92,
165 	SPELL_INCINERATE            ,//= 93,
166 	SPELL_MASS_PARALYSE         ,//= 94,
167 
168 	// LEVEL 10
169 	SPELL_MASS_LIGHTNING_STRIKE ,//= 101,
170 	SPELL_CONTROL_TARGET        ,//= 102,
171 	SPELL_FREEZE_TIME           ,//= 103,
172 	SPELL_MASS_INCINERATE       ,//= 104
173 
174 	SPELL_FAKE_SUMMON           ,// special =105
175 
176 	// LEVEL ZOB
177 	SPELL_TELEPORT = SPELL_FAKE_SUMMON + 2, // TODO explicit value for savegame compatability
178 
179 	SPELL_NONE = -1
180 };
181 
182 const size_t SPELL_COUNT = SPELL_FAKE_SUMMON + 1;
183 
184 struct PRECAST_STRUCT {
185 	Spell typ;
186 	long level;
187 	unsigned long launch_time;
188 	SpellcastFlags flags;
189 	long duration;
190 };
191 
192 const size_t MAX_PRECAST = 3;
193 extern PRECAST_STRUCT Precast[MAX_PRECAST];
194 
195 void ARX_SPELLS_Precast_Reset();
196 void ARX_SPELLS_Precast_Launch(long num);
197 
198 Spell GetSpellId(const std::string & spell);
199 void TryToCastSpell(Entity * io, Spell spellid, long level, long target, SpellcastFlags flags, long duration);
200 void ARX_SPELLS_Precast_Check();
201 
202 struct EYEBALL_DEF {
203 	long exist;
204 	Vec3f pos;
205 	Anglef angle;
206 	Vec3f size;
207 	float floating;
208 };
209 
210 extern EYEBALL_DEF eyeball;
211 
212 const size_t MAX_SPELL_SYMBOLS = 6;
213 extern Rune SpellSymbol[MAX_SPELL_SYMBOLS];
214 extern size_t CurrSpellSymbol;
215 
216 struct SPELL {
217 
218 	bool exist;
219 	long caster; //!< Number of the source interactive obj (0==player)
220 	long target; //!< Number of the target interactive obj if any
221 	float caster_level; //!< Level of Magic 1-10
222 
223 	long hand_group;
224 	Vec3f hand_pos; //!< Only valid if hand_group>=0
225 	Vec3f caster_pos;
226 	Vec3f target_pos;
227 
228 	float fdata; //!< Specific use for each spell
229 
230 	Spell type;
231 	Vec3f vsource; // TODO this is used but never set
232 
233 	Vec3f move;
234 	Vec3f scale;
235 	float siz;
236 	unsigned long timcreation;
237 	unsigned long lastupdate;
238 	unsigned long tolive;
239 
240 	TextureContainer * tc;
241 	long longinfo;
242 	long longinfo2;
243 	bool bDuration;
244 	float fManaCostPerSecond;
245 
246 	SpellcastFlags flags;
247 	audio::SourceId snd_loop;
248 	CSpellFx * pSpellFx;
249 	void * misc;
250 };
251 
252 const size_t MAX_SPELLS = 20;
253 extern SPELL spells[MAX_SPELLS];
254 
255 extern long CurrPoint;
256 
257 bool ARX_SPELLS_Launch(Spell typ, long source, SpellcastFlags flags = 0, long level = -1, long target = -1, long duration = -1);
258 void ARX_SPELLS_ResetRecognition();
259 void ARX_SPELLS_AddPoint(const Vec2s & pos);
260 void ARX_SPELLS_AbortSpellSound();
261 void ARX_SPELLS_Init();
262 void ARX_SPELLS_ClearAll();
263 void ARX_SPELLS_Update();
264 
265 void ARX_SPELLS_Kill(long i);
266 long ARX_SPELLS_GetInstance(Spell typ);
267 void ARX_SPELLS_ManageMagic();
268 
269 void ARX_SPELLS_RequestSymbolDraw(Entity * io, const std::string & name, float duration);
270 void ARX_SPELLS_UpdateSymbolDraw();
271 void ARX_SPELLS_ClearAllSymbolDraw();
272 
273 void ARX_SPELLS_Init_Rects();
274 
275 bool ARX_SPELLS_ExistAnyInstance(Spell typ);
276 void ARX_SPELLS_RemoveAllSpellsOn(Entity * io);
277 long ARX_SPELLS_GetSpellOn(const Entity * io, Spell spellid);
278 long ARX_SPELLS_GetInstanceForThisCaster(Spell typ, long caster);
279 
280 void ARX_SPELLS_CancelSpellTarget();
281 void ARX_SPELLS_LaunchSpellTarget(Entity * io);
282 float ARX_SPELLS_ApplyFireProtection(Entity * io, float damages);
283 float ARX_SPELLS_ApplyColdProtection(Entity * io, float damages);
284 void ARX_SPELLS_FizzleAllSpellsFromCaster(long num);
285 
286 #endif // ARX_GAME_SPELLS_H
287