diff options
author | Paul Gilbert | 2018-03-18 20:02:45 -0400 |
---|---|---|
committer | Paul Gilbert | 2018-03-18 20:02:45 -0400 |
commit | 500ed10658001ccb55578a59d245ee2bfda63385 (patch) | |
tree | 143646496271cf417c069fdc68010225172aba1c /engines/xeen | |
parent | 23fd97c99a650cf2e99df72a74326520b9347fc7 (diff) | |
download | scummvm-rg350-500ed10658001ccb55578a59d245ee2bfda63385.tar.gz scummvm-rg350-500ed10658001ccb55578a59d245ee2bfda63385.tar.bz2 scummvm-rg350-500ed10658001ccb55578a59d245ee2bfda63385.zip |
XEEN: Add an enum SpellsCategory enum, code simplification using it
Diffstat (limited to 'engines/xeen')
-rw-r--r-- | engines/xeen/character.cpp | 14 | ||||
-rw-r--r-- | engines/xeen/character.h | 21 | ||||
-rw-r--r-- | engines/xeen/combat.cpp | 2 | ||||
-rw-r--r-- | engines/xeen/debugger.cpp | 2 | ||||
-rw-r--r-- | engines/xeen/dialogs/dialogs_spells.cpp | 115 | ||||
-rw-r--r-- | engines/xeen/party.cpp | 46 | ||||
-rw-r--r-- | engines/xeen/scripts.cpp | 24 |
7 files changed, 56 insertions, 168 deletions
diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp index 77c01fe8fc..3776e51e5d 100644 --- a/engines/xeen/character.cpp +++ b/engines/xeen/character.cpp @@ -134,7 +134,7 @@ void Character::synchronize(Common::Serializer &s) { } // Synchronize spell list - for (int i = 0; i < MAX_SPELLS_PER_CLASS; ++i) + for (int i = 0; i < CHAR_MAX_SPELLS; ++i) s.syncAsByte(_spells[i]); s.syncAsByte(_lloydMap); s.syncAsByte(_lloydPosition.x); @@ -1194,18 +1194,22 @@ bool Character::hasMissileWeapon() const { return false; } -int Character::getClassCategory() const { +SpellsCategory Character::getSpellsCategory() const { switch (_class) { + case CLASS_PALADIN: + case CLASS_CLERIC: + return SPELLCAT_CLERICAL; + case CLASS_ARCHER: case CLASS_SORCERER: - return 1; + return SPELLCAT_WIZARDRY; case CLASS_DRUID: case CLASS_RANGER: - return 2; + return SPELLCAT_DRUIDIC; default: - return 0; + return SPELLCAT_INVALID; } } diff --git a/engines/xeen/character.h b/engines/xeen/character.h index 05a61c3f2e..b37431a40f 100644 --- a/engines/xeen/character.h +++ b/engines/xeen/character.h @@ -34,7 +34,8 @@ namespace Xeen { #define INV_ITEMS_TOTAL 9 -#define MAX_SPELLS_PER_CLASS 39 +#define CHAR_MAX_SPELLS 39 +#define SPELLS_PER_CLASS 40 #define AWARDS_TOTAL 88 #define WARZONE_AWARD 9 @@ -83,6 +84,11 @@ enum QuickAction { QUICK_ATTACK = 0, QUICK_SPELL = 1, QUICK_BLOCK = 2, QUICK_RUN = 3 }; +enum SpellsCategory { + SPELLCAT_INVALID = -1, SPELLCAT_CLERICAL = 0, SPELLCAT_WIZARDRY = 1, SPELLCAT_DRUIDIC = 2 +}; + + class XeenEngine; class AttributePair { @@ -119,7 +125,7 @@ public: int _tempAge; int _skills[18]; int _awards[128]; - bool _spells[MAX_SPELLS_PER_CLASS]; + bool _spells[CHAR_MAX_SPELLS]; int _lloydMap; Common::Point _lloydPosition; bool _hasSpells; @@ -311,9 +317,16 @@ public: bool hasMissileWeapon() const; /** - * Returns a category index for a character, used such for indexing into spell data + * Returns the spells category for the character's class + */ + SpellsCategory getSpellsCategory() const; + + /** + * Returns an expense factor for purchasing spells by certain character classes */ - int getClassCategory() const; + int getSpellsExpenseFactor() const { + return (_class == CLASS_PALADIN || _class == CLASS_ARCHER || _class == CLASS_RANGER) ? 1 : 0; + } /** * Clears the character of any currently set conditions diff --git a/engines/xeen/combat.cpp b/engines/xeen/combat.cpp index aa811b4808..044b650965 100644 --- a/engines/xeen/combat.cpp +++ b/engines/xeen/combat.cpp @@ -1590,7 +1590,7 @@ void Combat::quickFight() { break; case QUICK_SPELL: if (c->_currentSpell != -1) { - spells.castSpell(c, (MagicSpell)Res.SPELLS_ALLOWED[c->getClassCategory()][c->_currentSpell]); + spells.castSpell(c, (MagicSpell)Res.SPELLS_ALLOWED[c->getSpellsCategory()][c->_currentSpell]); } break; case QUICK_BLOCK: diff --git a/engines/xeen/debugger.cpp b/engines/xeen/debugger.cpp index 32d0ce7f4c..21e58195d7 100644 --- a/engines/xeen/debugger.cpp +++ b/engines/xeen/debugger.cpp @@ -95,7 +95,7 @@ bool Debugger::cmdSpells(int argc, const char **argv) { for (uint charIdx = 0; charIdx < party._activeParty.size(); ++charIdx) { Character &c = party._activeParty[charIdx]; - Common::fill(c._spells, c._spells + MAX_SPELLS_PER_CLASS, true); + Common::fill(c._spells, c._spells + CHAR_MAX_SPELLS, true); c._currentSp = 9999; } diff --git a/engines/xeen/dialogs/dialogs_spells.cpp b/engines/xeen/dialogs/dialogs_spells.cpp index 7f7df8d7c8..d2b473086e 100644 --- a/engines/xeen/dialogs/dialogs_spells.cpp +++ b/engines/xeen/dialogs/dialogs_spells.cpp @@ -141,23 +141,10 @@ Character *SpellsDialog::execute(ButtonContainer *priorDialog, Character *c, int windows[10].writeString(Common::String::format(Res.GUILD_OPTIONS, XeenEngine::printMil(party._gold).c_str(), Res.GUILD_TEXT, c->_name.c_str())); } else { - int category; - switch (c->_class) { - case CLASS_ARCHER: - case CLASS_SORCERER: - category = 1; - break; - case CLASS_DRUID: - case CLASS_RANGER: - category = 2; - break; - default: - category = 0; - break; - } - - int spellIndex = (c->_currentSpell == -1) ? 39 : c->_currentSpell; + SpellsCategory category = c->getSpellsCategory(); + int spellIndex = (c->_currentSpell == -1) ? SPELLS_PER_CLASS - 1 : c->_currentSpell; int spellId = Res.SPELLS_ALLOWED[category][spellIndex]; + windows[10].writeString(Common::String::format(Res.CAST_SPELL_DETAILS, c->_name.c_str(), spells._spellNames[spellId].c_str(), spells.calcSpellPoints(spellId, c->getCurrentLevel()), @@ -197,34 +184,8 @@ Character *SpellsDialog::execute(ButtonContainer *priorDialog, Character *c, int (_buttonValue - Common::KEYCODE_1)); if (newSelection < (int)_spells.size()) { - int expenseFactor = 0; - int category = 0; - - switch (c->_class) { - case CLASS_PALADIN: - expenseFactor = 1; - category = 0; - break; - case CLASS_ARCHER: - expenseFactor = 1; - category = 1; - break; - case CLASS_CLERIC: - category = 0; - break; - case CLASS_SORCERER: - category = 1; - break; - case CLASS_DRUID: - category = 2; - break; - case CLASS_RANGER: - expenseFactor = 1; - category = 2; - break; - default: - break; - } + SpellsCategory category = c->getSpellsCategory(); + int expenseFactor = c->getSpellsExpenseFactor(); int spellIndex = _spells[newSelection]._spellIndex; int spellId = Res.SPELLS_ALLOWED[category][spellIndex]; @@ -316,47 +277,20 @@ const char *SpellsDialog::setSpellText(Character *c, int mode) { Party &party = *_vm->_party; Spells &spells = *_vm->_spells; int ccNum = _vm->_files->_ccNum; - int expenseFactor = 0; int currLevel = c->getCurrentLevel(); - int category; + SpellsCategory category = c->getSpellsCategory(); + int expenseFactor = c->getSpellsExpenseFactor(); if ((mode & 0x7f) == 0) { - switch (c->_class) { - case CLASS_PALADIN: - expenseFactor = 1; - category = 0; - break; - case CLASS_ARCHER: - expenseFactor = 1; - category = 1; - break; - case CLASS_CLERIC: - category = 0; - break; - case CLASS_SORCERER: - category = 1; - break; - case CLASS_DRUID: - category = 2; - break; - case CLASS_RANGER: - expenseFactor = 1; - category = 2; - break; - default: - category = -1; - break; - } - - if (category != -1) { + if (category != SPELLCAT_INVALID) { if (party._mazeId == 49 || party._mazeId == 37) { for (uint spellId = 0; spellId < 76; ++spellId) { int idx = 0; - while (idx < MAX_SPELLS_PER_CLASS && Res.SPELLS_ALLOWED[category][idx] != (int)spellId) + while (idx < CHAR_MAX_SPELLS && Res.SPELLS_ALLOWED[category][idx] != (int)spellId) ++idx; // Handling if the spell is appropriate for the character's class - if (idx < MAX_SPELLS_PER_CLASS) { + if (idx < CHAR_MAX_SPELLS) { if (!c->_spells[idx] || (mode & 0x80)) { int cost = spells.calcSpellCost(Res.SPELLS_ALLOWED[category][idx], expenseFactor); _spells.push_back(SpellEntry(Common::String::format("\x3l%s\x3r\x9""000%u", @@ -370,10 +304,10 @@ const char *SpellsDialog::setSpellText(Character *c, int mode) { for (int spellId = Res.DARK_SPELL_RANGES[groupIndex][0]; spellId < Res.DARK_SPELL_RANGES[groupIndex][1]; ++spellId) { int idx = 0; - while (idx < 40 && Res.SPELLS_ALLOWED[category][idx] == + while (idx < SPELLS_PER_CLASS && Res.SPELLS_ALLOWED[category][idx] == Res.DARK_SPELL_OFFSETS[category][spellId]); - if (idx < 40) { + if (idx < SPELLS_PER_CLASS) { if (!c->_spells[idx] || (mode & 0x80)) { int cost = spells.calcSpellCost(Res.SPELLS_ALLOWED[category][idx], expenseFactor); _spells.push_back(SpellEntry(Common::String::format("\x3l%s\x3r\x9""000%u", @@ -386,10 +320,10 @@ const char *SpellsDialog::setSpellText(Character *c, int mode) { for (int spellId = 0; spellId < 20; ++spellId) { int idx = 0; while (Res.CLOUDS_SPELL_OFFSETS[party._mazeId - 29][spellId] != - (int)Res.SPELLS_ALLOWED[category][idx] && idx <= MAX_SPELLS_PER_CLASS) + (int)Res.SPELLS_ALLOWED[category][idx] && idx < SPELLS_PER_CLASS) ++idx; - if (idx <= MAX_SPELLS_PER_CLASS) { + if (idx < SPELLS_PER_CLASS) { if (!c->_spells[idx] || (mode & 0x80)) { int cost = spells.calcSpellCost(Res.SPELLS_ALLOWED[category][idx], expenseFactor); _spells.push_back(SpellEntry(Common::String::format("\x3l%s\x3r\x9""000%u", @@ -405,26 +339,10 @@ const char *SpellsDialog::setSpellText(Character *c, int mode) { return Res.NOT_A_SPELL_CASTER; } else if ((mode & 0x7f) == 1) { - switch (c->_class) { - case CLASS_ARCHER: - case CLASS_SORCERER: - category = 1; - break; - case CLASS_DRUID: - case CLASS_RANGER: - category = 2; - break; - case CLASS_PALADIN: - case CLASS_CLERIC: - default: - category = 0; - break; - } - if (c->getMaxSP() == 0) { return Res.NOT_A_SPELL_CASTER; } else { - for (int spellIndex = 0; spellIndex < MAX_SPELLS_PER_CLASS; ++spellIndex) { + for (int spellIndex = 0; spellIndex < SPELLS_PER_CLASS; ++spellIndex) { if (c->_spells[spellIndex]) { int spellId = Res.SPELLS_ALLOWED[category][spellIndex]; int gemCost = Res.SPELL_GEM_COST[spellId]; @@ -522,7 +440,8 @@ int CastSpell::execute(Character *&c) { bool redrawFlag = true; do { if (redrawFlag) { - int category = c->getClassCategory(); + SpellsCategory category = c->getSpellsCategory(); + assert(category != SPELLCAT_INVALID); int spellIndex = c->_currentSpell != -1 ? c->_currentSpell : 39; spellId = Res.SPELLS_ALLOWED[category][spellIndex]; int gemCost = Res.SPELL_GEM_COST[spellId]; diff --git a/engines/xeen/party.cpp b/engines/xeen/party.cpp index 8e94c939c3..839dc41b10 100644 --- a/engines/xeen/party.cpp +++ b/engines/xeen/party.cpp @@ -906,26 +906,11 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int ps._conditions[takeVal] = 0; break; case 19: { - int idx2 = 0; - switch (ps._class) { - case CLASS_PALADIN: - case CLASS_CLERIC: - idx2 = 0; - break; - case CLASS_ARCHER: - case CLASS_SORCERER: - idx2 = 1; - break; - case CLASS_DRUID: - case CLASS_RANGER: - idx2 = 2; - break; - default: - break; - } + SpellsCategory category = ps.getSpellsCategory(); + assert(category != SPELLCAT_INVALID); - for (int idx = 0; idx < 39; ++idx) { - if (Res.SPELLS_ALLOWED[idx2][idx] == (int)takeVal) { + for (int idx = 0; idx < SPELLS_PER_CLASS; ++idx) { + if (Res.SPELLS_ALLOWED[category][idx] == (int)takeVal) { ps._spells[idx] = false; break; } @@ -1175,26 +1160,11 @@ bool Party::giveTake(int takeMode, uint takeVal, int giveMode, uint giveVal, int ps._currentHp = 0; break; case 19: { - int idx2 = 0; - switch (ps._class) { - case CLASS_PALADIN: - case CLASS_CLERIC: - idx2 = 0; - break; - case CLASS_ARCHER: - case CLASS_SORCERER: - idx2 = 1; - break; - case CLASS_DRUID: - case CLASS_RANGER: - idx2 = 2; - break; - default: - break; - } + SpellsCategory category = ps.getSpellsCategory(); + assert(category != SPELLCAT_INVALID); - for (int idx = 0; idx < 39; ++idx) { - if (Res.SPELLS_ALLOWED[idx2][idx] == (int)giveVal) { + for (int idx = 0; idx < SPELLS_PER_CLASS; ++idx) { + if (Res.SPELLS_ALLOWED[category][idx] == (int)giveVal) { ps._spells[idx] = true; intf.spellFX(&ps); break; diff --git a/engines/xeen/scripts.cpp b/engines/xeen/scripts.cpp index 91db032d79..cc42081f5c 100644 --- a/engines/xeen/scripts.cpp +++ b/engines/xeen/scripts.cpp @@ -1550,29 +1550,11 @@ bool Scripts::ifProc(int action, uint32 val, int mode, int charIndex) { break; case 19: { // Can player cast a given spell - - // Get the type of character - int category; - switch (ps._class) { - case CLASS_KNIGHT: - case CLASS_ARCHER: - category = 0; - break; - case CLASS_PALADIN: - case CLASS_CLERIC: - category = 1; - break; - case CLASS_BARBARIAN: - case CLASS_DRUID: - category = 2; - break; - default: - category = 0; - break; - } + SpellsCategory category = ps.getSpellsCategory(); + assert(category != SPELLCAT_INVALID); // Check if the character class can cast the particular spell - for (int idx = 0; idx < 39; ++idx) { + for (int idx = 0; idx < SPELLS_PER_CLASS; ++idx) { if (Res.SPELLS_ALLOWED[category][idx] == (int)val) { // Can cast it. Check if the player has it in their spellbook if (ps._spells[idx]) |