1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "xeen/spells.h"
#include "xeen/dialogs_spells.h"
#include "xeen/files.h"
#include "xeen/resources.h"
#include "xeen/xeen.h"
namespace Xeen {
Spells::Spells(XeenEngine *vm) : _vm(vm) {
_lastCaster = 0;
load();
}
void Spells::load() {
File f1("spells.xen");
while (f1.pos() < f1.size())
_spellNames.push_back(f1.readString());
f1.close();
}
int Spells::calcSpellCost(int spellId, int expenseFactor) const {
int amount = SPELL_COSTS[spellId];
return (amount >= 0) ? (amount * 100) << expenseFactor :
(amount * -500) << expenseFactor;
}
int Spells::calcSpellPoints(int spellId, int expenseFactor) const {
int amount = SPELL_COSTS[spellId];
return (amount >= 0) ? amount : amount * -1 * expenseFactor;
}
typedef void(Spells::*SpellMethodPtr)();
void Spells::executeSpell(int spellId) {
static const SpellMethodPtr SPELL_LIST[73] = {
&Spells::light, &Spells::awaken, &Spells::magicArrow, &Spells::firstAid,
&Spells::flyingFist, &Spells::energyBlast, &Spells::sleep,
&Spells::revitalize, &Spells::cureWounds, &Spells::sparks,
&Spells::shrapMetal, &Spells::insectSpray, &Spells::toxicCloud,
&Spells::protectionFromElements, &Spells::pain, &Spells::jump,
&Spells::beastMaster, &Spells::clairvoyance, &Spells::turnUndead,
&Spells::levitate,
&Spells::wizardEye, &Spells::bless, &Spells::identifyMonster,
&Spells::lightningBolt, &Spells::holyBonus, &Spells::powerCure,
&Spells::naturesCure, &Spells::lloydsBeacon, &Spells::powerShield,
&Spells::heroism,
&Spells::hypnotize, &Spells::walkOnWater, &Spells::frostByte,
&Spells::detectMonster, &Spells::fireball, &Spells::coldRay,
&Spells::curePoison, &Spells::acidSpray, &Spells::timeDistortion,
&Spells::dragonSleep,
&Spells::cureDisease, &Spells::teleport, &Spells::fingerOfDeath,
&Spells::cureParalysis, &Spells::golemStopper, &Spells::poisonVolley,
&Spells::deadlySwarm, &Spells::superShelter, &Spells::dayOfProtection,
&Spells::dayOfSorcery,
&Spells::createFood, &Spells::fieryFlail, &Spells::rechargeItem,
&Spells::fantasticFreeze, &Spells::townPortal, &Spells::stoneToFlesh,
&Spells::raiseDead, &Spells::etherialize, &Spells::dancingSword,
&Spells::moonRay,
&Spells::massDistortion, &Spells::prismaticLight, &Spells::enchantItem,
&Spells::incinerate, &Spells::holyWord, &Spells::resurrection,
&Spells::elementalStorm, &Spells::megaVolts, &Spells::inferno,
&Spells::sunRay,
&Spells::implosion, &Spells::starBurst, &Spells::divineIntervention
};
(this->*SPELL_LIST[spellId])();
}
/**
* Spell being cast failed
*/
void Spells::spellFailed() {
ErrorScroll::show(_vm, SPELL_FAILED, WT_NONFREEZED_WAIT);
}
/**
* Cast a spell associated with an item
*/
void Spells::castItemSpell(int spellId) {
if (_vm->_mode == MODE_COMBAT) {
if (spellId == 15 || spellId == 20 || spellId == 27 || spellId == 41
|| spellId == 47 || spellId == 54 || spellId == 57) {
ErrorDialog::show(_vm, Common::String::format(CANT_CAST_WHILE_ENGAGED,
_spellNames[spellId].c_str()));
return;
}
}
executeSpell(spellId);
}
/**
* Cast a given spell
*/
int Spells::castSpell(Character *c, int spellId) {
Combat &combat = *_vm->_combat;
Interface &intf = *_vm->_interface;
int oldTillMove = intf._tillMove;
int result = 1;
combat._oldCharacter = c;
// Try and subtract the SP and gem requirements for the spell
int resultError = subSpellCost(*c, spellId);
if (resultError) {
CantCast::show(_vm, spellId, resultError);
result = -1;
} else {
// Some spells have special handling
switch (spellId) {
case 19: // Enchant item
case 21: // Etherialize
case 40: // Jump
case 44: // Lloyd's Beacon
case 66: // Super Shelter
case 69: // Teleport
case 71: // Town Portal
case 75: // Wizard Eye
if (_vm->_mode != MODE_COMBAT) {
executeSpell(spellId);
} else {
// Return the spell costs and flag that another spell can be selected
addSpellCost(*c, spellId);
ErrorDialog::show(_vm, Common::String::format(CANT_CAST_WHILE_ENGAGED,
_spellNames[spellId]));
result = -1;
}
break;
default:
executeSpell(spellId);
break;
}
}
combat._moveMonsters = 1;
intf._tillMove = oldTillMove;
return result;
}
/**
* Subtract the requirements for a given spell if available, returning
* true if there was sufficient
*/
int Spells::subSpellCost(Character &c, int spellId) {
Party &party = *_vm->_party;
int gemCost = SPELL_GEM_COST[spellId];
int spCost = SPELL_COSTS[spellId];
// Negative SP costs indicate it's dependent on the character's level
if (spCost <= 0) {
spCost = c.getCurrentLevel() * (spCost * -1);
}
if (spCost > c._currentSp)
// Not enough SP
return 1;
if (gemCost > (int)party._gems)
// Not enough gems
return 2;
c._currentSp -= spCost;
party._gems -= gemCost;
return 0;
}
/**
* Add the SP and gem requirements for a given spell to the given
* character and party
*/
void Spells::addSpellCost(Character &c, int spellId) {
Party &party = *_vm->_party;
int gemCost = SPELL_GEM_COST[spellId];
int spCost = SPELL_COSTS[spellId];
if (spCost < 1)
spCost *= -1 * c.getCurrentLevel();
c._currentSp += spCost;
party._gems += gemCost;
}
void Spells::light() {
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;
SoundManager &sound = *_vm->_sound;
++party._lightCount;
if (intf._intrIndex1)
party._stepped = true;
sound.playFX(39);
}
void Spells::awaken() {
Interface &intf = *_vm->_interface;
Party &party = *_vm->_party;
SoundManager &sound = *_vm->_sound;
for (uint idx = 0; idx < party._activeParty.size(); ++idx) {
Character &c = party._activeParty[idx];
c._conditions[ASLEEP] = 0;
if (c._currentHp > 0)
c._conditions[UNCONSCIOUS] = 0;
}
intf.drawParty(true);
sound.playFX(30);
}
void Spells::magicArrow() {
Combat &combat = *_vm->_combat;
combat._monsterDamage = 0;
combat._damageType = DT_MAGIC_ARROW;
combat._rangeType = RT_SINGLE;
combat.multiAttack(11);
}
void Spells::firstAid() {
Combat &combat = *_vm->_combat;
Party &party = *_vm->_party;
SoundManager &sound = *_vm->_sound;
int charIndex = SpellOnWho::show(_vm, MS_FirstAid);
if (charIndex == -1)
return;
Character &c = combat._combatMode == 2 ? *combat._combatParty[charIndex] :
party._activeParty[charIndex];
if (c.isDead()) {
spellFailed();
} else {
sound.playFX(30);
c.addHitPoints(6);
}
}
void Spells::flyingFist() { error("TODO: spell"); }
void Spells::energyBlast() { error("TODO: spell"); }
void Spells::sleep() { error("TODO: spell"); }
void Spells::revitalize() { error("TODO: spell"); }
void Spells::cureWounds() { error("TODO: spell"); }
void Spells::sparks() { error("TODO: spell"); }
void Spells::shrapMetal() { error("TODO: spell"); }
void Spells::insectSpray() { error("TODO: spell"); }
void Spells::toxicCloud() { error("TODO: spell"); }
void Spells::protectionFromElements() { error("TODO: spell"); }
void Spells::pain() { error("TODO: spell"); }
void Spells::jump() { error("TODO: spell"); } // Not while engaged
void Spells::beastMaster() { error("TODO: spell"); }
void Spells::clairvoyance() { error("TODO: spell"); }
void Spells::turnUndead() { error("TODO: spell"); }
void Spells::levitate() { error("TODO: spell"); }
void Spells::wizardEye() { error("TODO: spell"); } // Not while engaged
void Spells::bless() { error("TODO: spell"); }
void Spells::identifyMonster() { error("TODO: spell"); }
void Spells::lightningBolt() { error("TODO: spell"); }
void Spells::holyBonus() { error("TODO: spell"); }
void Spells::powerCure() { error("TODO: spell"); }
void Spells::naturesCure() { error("TODO: spell"); }
void Spells::lloydsBeacon() { error("TODO: spell"); } // Not while engaged
void Spells::powerShield() { error("TODO: spell"); }
void Spells::heroism() { error("TODO: spell"); }
void Spells::hypnotize() { error("TODO: spell"); }
void Spells::walkOnWater() { error("TODO: spell"); }
void Spells::frostByte() { error("TODO: spell"); }
void Spells::detectMonster() { error("TODO: spell"); }
void Spells::fireball() { error("TODO: spell"); }
void Spells::coldRay() { error("TODO: spell"); }
void Spells::curePoison() { error("TODO: spell"); }
void Spells::acidSpray() { error("TODO: spell"); }
void Spells::timeDistortion() { error("TODO: spell"); }
void Spells::dragonSleep() { error("TODO: spell"); }
void Spells::cureDisease() { error("TODO: spell"); }
void Spells::teleport() { error("TODO: spell"); } // Not while engaged
void Spells:: fingerOfDeath() { error("TODO: spell"); }
void Spells::cureParalysis() { error("TODO: spell"); }
void Spells::golemStopper() { error("TODO: spell"); }
void Spells::poisonVolley() { error("TODO: spell"); }
void Spells::deadlySwarm() { error("TODO: spell"); }
void Spells::superShelter() { error("TODO: spell"); } // Not while engaged
void Spells::dayOfProtection() { error("TODO: spell"); }
void Spells::dayOfSorcery() { error("TODO: spell"); }
void Spells::createFood() { error("TODO: spell"); }
void Spells::fieryFlail() { error("TODO: spell"); }
void Spells::rechargeItem() { error("TODO: spell"); }
void Spells::fantasticFreeze() { error("TODO: spell"); }
void Spells::townPortal() { error("TODO: spell"); } // Not while engaged
void Spells::stoneToFlesh() { error("TODO: spell"); }
void Spells::raiseDead() { error("TODO: spell"); }
void Spells::etherialize() { error("TODO: spell"); } // Not while engaged
void Spells::dancingSword() { error("TODO: spell"); }
void Spells::moonRay() { error("TODO: spell"); }
void Spells::massDistortion() { error("TODO: spell"); }
void Spells::prismaticLight() { error("TODO: spell"); }
void Spells::enchantItem() { error("TODO: spell"); }
void Spells::incinerate() { error("TODO: spell"); }
void Spells::holyWord() { error("TODO: spell"); }
void Spells::resurrection() { error("TODO: spell"); }
void Spells::elementalStorm() { error("TODO: spell"); }
void Spells::megaVolts() { error("TODO: spell"); }
void Spells::inferno() { error("TODO: spell"); }
void Spells::sunRay() { error("TODO: spell"); }
void Spells::implosion() { error("TODO: spell"); }
void Spells::starBurst() { error("TODO: spell"); }
void Spells::divineIntervention() { error("TODO: spell"); }
} // End of namespace Xeen
|