/* 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/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])(); } 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; } } _vm->_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() { error("TODO: spell"); } void Spells::awaken() { error("TODO: spell"); } void Spells::magicArrow() { error("TODO: spell"); } void Spells::firstAid() { error("TODO: spell"); } 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