Browse Source

`enum spell_type` -> `enum class SpellType` (#5674)

pull/5732/head
Eric Robinson 3 years ago committed by GitHub
parent
commit
ef3a57b7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      Source/control.cpp
  2. 6
      Source/controls/modifier_hints.cpp
  3. 2
      Source/controls/plrctrls.cpp
  4. 2
      Source/items.cpp
  5. 22
      Source/loadsave.cpp
  6. 24
      Source/msg.cpp
  7. 34
      Source/panels/spell_book.cpp
  8. 16
      Source/panels/spell_icons.cpp
  9. 2
      Source/panels/spell_icons.hpp
  10. 84
      Source/panels/spell_list.cpp
  11. 2
      Source/panels/spell_list.hpp
  12. 42
      Source/player.cpp
  13. 8
      Source/player.h
  14. 14
      Source/spelldat.h
  15. 28
      Source/spells.cpp
  16. 2
      Source/spells.h
  17. 4
      test/player_test.cpp
  18. 4
      test/writehero_test.cpp

12
Source/control.cpp

@ -773,7 +773,7 @@ void DoPanBtn()
if ((SDL_GetModState() & KMOD_SHIFT) != 0) { if ((SDL_GetModState() & KMOD_SHIFT) != 0) {
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
myPlayer._pRSpell = SPL_INVALID; myPlayer._pRSpell = SPL_INVALID;
myPlayer._pRSplType = RSPLTYPE_INVALID; myPlayer._pRSplType = SpellType::Invalid;
RedrawEverything(); RedrawEverything();
return; return;
} }
@ -843,15 +843,15 @@ void CheckPanelInfo()
const spell_id spellId = myPlayer._pRSpell; const spell_id spellId = myPlayer._pRSpell;
if (IsValidSpell(spellId)) { if (IsValidSpell(spellId)) {
switch (myPlayer._pRSplType) { switch (myPlayer._pRSplType) {
case RSPLTYPE_SKILL: case SpellType::Skill:
AddPanelString(fmt::format(fmt::runtime(_("{:s} Skill")), pgettext("spell", spelldata[spellId].sNameText))); AddPanelString(fmt::format(fmt::runtime(_("{:s} Skill")), pgettext("spell", spelldata[spellId].sNameText)));
break; break;
case RSPLTYPE_SPELL: { case SpellType::Spell: {
AddPanelString(fmt::format(fmt::runtime(_("{:s} Spell")), pgettext("spell", spelldata[spellId].sNameText))); AddPanelString(fmt::format(fmt::runtime(_("{:s} Spell")), pgettext("spell", spelldata[spellId].sNameText)));
const int spellLevel = myPlayer.GetSpellLevel(spellId); const int spellLevel = myPlayer.GetSpellLevel(spellId);
AddPanelString(spellLevel == 0 ? _("Spell Level 0 - Unusable") : fmt::format(fmt::runtime(_("Spell Level {:d}")), spellLevel)); AddPanelString(spellLevel == 0 ? _("Spell Level 0 - Unusable") : fmt::format(fmt::runtime(_("Spell Level {:d}")), spellLevel));
} break; } break;
case RSPLTYPE_SCROLL: { case SpellType::Scroll: {
AddPanelString(fmt::format(fmt::runtime(_("Scroll of {:s}")), pgettext("spell", spelldata[spellId].sNameText))); AddPanelString(fmt::format(fmt::runtime(_("Scroll of {:s}")), pgettext("spell", spelldata[spellId].sNameText)));
const InventoryAndBeltPlayerItemsRange items { myPlayer }; const InventoryAndBeltPlayerItemsRange items { myPlayer };
const int scrollCount = std::count_if(items.begin(), items.end(), [spellId](const Item &item) { const int scrollCount = std::count_if(items.begin(), items.end(), [spellId](const Item &item) {
@ -859,11 +859,11 @@ void CheckPanelInfo()
}); });
AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Scroll", "{:d} Scrolls", scrollCount)), scrollCount)); AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Scroll", "{:d} Scrolls", scrollCount)), scrollCount));
} break; } break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
AddPanelString(fmt::format(fmt::runtime(_("Staff of {:s}")), pgettext("spell", spelldata[spellId].sNameText))); AddPanelString(fmt::format(fmt::runtime(_("Staff of {:s}")), pgettext("spell", spelldata[spellId].sNameText)));
AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Charge", "{:d} Charges", myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges)), myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges)); AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Charge", "{:d} Charges", myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges)), myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges));
break; break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
break; break;
} }
} }

6
Source/controls/modifier_hints.cpp

@ -126,15 +126,15 @@ void DrawSpellsCircleMenuHint(const Surface &out, const Point &origin)
}; };
uint64_t spells = myPlayer._pAblSpells | myPlayer._pMemSpells | myPlayer._pScrlSpells | myPlayer._pISpells; uint64_t spells = myPlayer._pAblSpells | myPlayer._pMemSpells | myPlayer._pScrlSpells | myPlayer._pISpells;
spell_id splId; spell_id splId;
spell_type splType; SpellType splType;
for (int slot = 0; slot < 4; ++slot) { for (int slot = 0; slot < 4; ++slot) {
splId = myPlayer._pSplHotKey[slot]; splId = myPlayer._pSplHotKey[slot];
if (IsValidSpell(splId) && (spells & GetSpellBitmask(splId)) != 0) if (IsValidSpell(splId) && (spells & GetSpellBitmask(splId)) != 0)
splType = (leveltype == DTYPE_TOWN && !spelldata[splId].sTownSpell) ? RSPLTYPE_INVALID : myPlayer._pSplTHotKey[slot]; splType = (leveltype == DTYPE_TOWN && !spelldata[splId].sTownSpell) ? SpellType::Invalid : myPlayer._pSplTHotKey[slot];
else { else {
splType = RSPLTYPE_INVALID; splType = SpellType::Invalid;
splId = SPL_NULL; splId = SPL_NULL;
} }

2
Source/controls/plrctrls.cpp

@ -2138,7 +2138,7 @@ void QuickCast(size_t slot)
MouseActionType prevMouseButtonAction = LastMouseButtonAction; MouseActionType prevMouseButtonAction = LastMouseButtonAction;
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
spell_id spell = myPlayer._pSplHotKey[slot]; spell_id spell = myPlayer._pSplHotKey[slot];
spell_type spellType = myPlayer._pSplTHotKey[slot]; SpellType spellType = myPlayer._pSplTHotKey[slot];
if (ControlMode != ControlTypes::KeyboardAndMouse) { if (ControlMode != ControlTypes::KeyboardAndMouse) {
UpdateSpellTarget(spell); UpdateSpellTarget(spell);

2
Source/items.cpp

@ -3818,7 +3818,7 @@ void UseItem(size_t pnum, item_misc_id mid, spell_id spl)
} else { } else {
ClrPlrPath(player); ClrPlrPath(player);
player.queuedSpell.spellId = spl; player.queuedSpell.spellId = spl;
player.queuedSpell.spellType = RSPLTYPE_SCROLL; player.queuedSpell.spellType = SpellType::Scroll;
player.queuedSpell.spellFrom = 0; player.queuedSpell.spellFrom = 0;
player.destAction = ACTION_SPELL; player.destAction = ACTION_SPELL;
player.destParam1 = cursPosition.x; player.destParam1 = cursPosition.x;

22
Source/loadsave.cpp

@ -357,14 +357,14 @@ void LoadPlayer(LoadHelper &file, Player &player)
player._pvid = file.NextLE<int32_t>(); player._pvid = file.NextLE<int32_t>();
player.queuedSpell.spellId = static_cast<spell_id>(file.NextLE<int32_t>()); player.queuedSpell.spellId = static_cast<spell_id>(file.NextLE<int32_t>());
player.queuedSpell.spellType = static_cast<spell_type>(file.NextLE<int8_t>()); player.queuedSpell.spellType = static_cast<SpellType>(file.NextLE<int8_t>());
player.queuedSpell.spellFrom = file.NextLE<int8_t>(); player.queuedSpell.spellFrom = file.NextLE<int8_t>();
file.Skip(2); // Alignment file.Skip(2); // Alignment
player._pTSpell = static_cast<spell_id>(file.NextLE<int32_t>()); player._pTSpell = static_cast<spell_id>(file.NextLE<int32_t>());
file.Skip<int8_t>(); // Skip _pTSplType file.Skip<int8_t>(); // Skip _pTSplType
file.Skip(3); // Alignment file.Skip(3); // Alignment
player._pRSpell = static_cast<spell_id>(file.NextLE<int32_t>()); player._pRSpell = static_cast<spell_id>(file.NextLE<int32_t>());
player._pRSplType = static_cast<spell_type>(file.NextLE<int8_t>()); player._pRSplType = static_cast<SpellType>(file.NextLE<int8_t>());
file.Skip(3); // Alignment file.Skip(3); // Alignment
player._pSBkSpell = static_cast<spell_id>(file.NextLE<int32_t>()); player._pSBkSpell = static_cast<spell_id>(file.NextLE<int32_t>());
file.Skip<int8_t>(); // Skip _pSBkSplType file.Skip<int8_t>(); // Skip _pSBkSplType
@ -382,7 +382,7 @@ void LoadPlayer(LoadHelper &file, Player &player)
player._pSplHotKey[i] = static_cast<spell_id>(file.NextLE<int32_t>()); player._pSplHotKey[i] = static_cast<spell_id>(file.NextLE<int32_t>());
} }
for (size_t i = 0; i < 4; i++) { for (size_t i = 0; i < 4; i++) {
player._pSplTHotKey[i] = static_cast<spell_type>(file.NextLE<uint8_t>()); player._pSplTHotKey[i] = static_cast<SpellType>(file.NextLE<uint8_t>());
} }
file.Skip<int32_t>(); // Skip _pwtype file.Skip<int32_t>(); // Skip _pwtype
@ -1131,14 +1131,14 @@ void SavePlayer(SaveHelper &file, const Player &player)
file.WriteLE<int32_t>(player._pvid); file.WriteLE<int32_t>(player._pvid);
file.WriteLE<int32_t>(player.queuedSpell.spellId); file.WriteLE<int32_t>(player.queuedSpell.spellId);
file.WriteLE<int8_t>(player.queuedSpell.spellType); file.WriteLE<int8_t>(static_cast<int8_t>(player.queuedSpell.spellType));
file.WriteLE<int8_t>(player.queuedSpell.spellFrom); file.WriteLE<int8_t>(player.queuedSpell.spellFrom);
file.Skip(2); // Alignment file.Skip(2); // Alignment
file.WriteLE<int32_t>(player._pTSpell); file.WriteLE<int32_t>(player._pTSpell);
file.Skip<int8_t>(); // Skip _pTSplType file.Skip<int8_t>(); // Skip _pTSplType
file.Skip(3); // Alignment file.Skip(3); // Alignment
file.WriteLE<int32_t>(player._pRSpell); file.WriteLE<int32_t>(player._pRSpell);
file.WriteLE<int8_t>(player._pRSplType); file.WriteLE<int8_t>(static_cast<uint8_t>(player._pRSplType));
file.Skip(3); // Alignment file.Skip(3); // Alignment
file.WriteLE<int32_t>(player._pSBkSpell); file.WriteLE<int32_t>(player._pSBkSpell);
file.Skip<int8_t>(); // Skip _pSBkSplType file.Skip<int8_t>(); // Skip _pSBkSplType
@ -1158,7 +1158,7 @@ void SavePlayer(SaveHelper &file, const Player &player)
file.WriteLE<int32_t>(player._pSplHotKey[i]); file.WriteLE<int32_t>(player._pSplHotKey[i]);
} }
for (size_t i = 0; i < 4; i++) { for (size_t i = 0; i < 4; i++) {
file.WriteLE<uint8_t>(player._pSplTHotKey[i]); file.WriteLE<uint8_t>(static_cast<uint8_t>(player._pSplTHotKey[i]));
} }
file.WriteLE<int32_t>(player.UsesRangedWeapon() ? 1 : 0); file.WriteLE<int32_t>(player.UsesRangedWeapon() ? 1 : 0);
@ -1903,7 +1903,7 @@ void LoadHotkeys()
// Refill the spell arrays with no selection // Refill the spell arrays with no selection
std::fill(myPlayer._pSplHotKey, myPlayer._pSplHotKey + NumHotkeys, SPL_INVALID); std::fill(myPlayer._pSplHotKey, myPlayer._pSplHotKey + NumHotkeys, SPL_INVALID);
std::fill(myPlayer._pSplTHotKey, myPlayer._pSplTHotKey + NumHotkeys, RSPLTYPE_INVALID); std::fill(myPlayer._pSplTHotKey, myPlayer._pSplTHotKey + NumHotkeys, SpellType::Invalid);
// Checking if the save file has the old format with only 4 hotkeys and no header // Checking if the save file has the old format with only 4 hotkeys and no header
if (file.IsValid(HotkeysSize(nHotkeys))) { if (file.IsValid(HotkeysSize(nHotkeys))) {
@ -1923,7 +1923,7 @@ void LoadHotkeys()
for (size_t i = 0; i < nHotkeys; i++) { for (size_t i = 0; i < nHotkeys; i++) {
// Do not load hotkeys past the size of the spells array, discard the rest // Do not load hotkeys past the size of the spells array, discard the rest
if (i < NumHotkeys) { if (i < NumHotkeys) {
myPlayer._pSplTHotKey[i] = static_cast<spell_type>(file.NextLE<uint8_t>()); myPlayer._pSplTHotKey[i] = static_cast<SpellType>(file.NextLE<uint8_t>());
} else { } else {
file.Skip<uint8_t>(); file.Skip<uint8_t>();
} }
@ -1931,7 +1931,7 @@ void LoadHotkeys()
// Load the selected spell last // Load the selected spell last
myPlayer._pRSpell = static_cast<spell_id>(file.NextLE<int32_t>()); myPlayer._pRSpell = static_cast<spell_id>(file.NextLE<int32_t>());
myPlayer._pRSplType = static_cast<spell_type>(file.NextLE<uint8_t>()); myPlayer._pRSplType = static_cast<SpellType>(file.NextLE<uint8_t>());
} }
void SaveHotkeys(SaveWriter &saveWriter, const Player &player) void SaveHotkeys(SaveWriter &saveWriter, const Player &player)
@ -1946,12 +1946,12 @@ void SaveHotkeys(SaveWriter &saveWriter, const Player &player)
file.WriteLE<int32_t>(spellId); file.WriteLE<int32_t>(spellId);
} }
for (auto &spellType : player._pSplTHotKey) { for (auto &spellType : player._pSplTHotKey) {
file.WriteLE<uint8_t>(spellType); file.WriteLE<uint8_t>(static_cast<uint8_t>(spellType));
} }
// Write the selected spell last // Write the selected spell last
file.WriteLE<int32_t>(player._pRSpell); file.WriteLE<int32_t>(player._pRSpell);
file.WriteLE<uint8_t>(player._pRSplType); file.WriteLE<uint8_t>(static_cast<uint8_t>(player._pRSplType));
} }
void LoadHeroItems(Player &player) void LoadHeroItems(Player &player)

24
Source/msg.cpp

@ -1462,7 +1462,7 @@ size_t OnSpellWall(const TCmd *pCmd, Player &player)
if (wParam1 > SPL_LAST) if (wParam1 > SPL_LAST)
return sizeof(message); return sizeof(message);
const uint16_t wParam2 = SDL_SwapLE16(message.wParam2); const uint16_t wParam2 = SDL_SwapLE16(message.wParam2);
if (wParam2 > RSPLTYPE_INVALID) if (wParam2 > static_cast<uint8_t>(SpellType::LAST))
return sizeof(message); return sizeof(message);
auto spell = static_cast<spell_id>(wParam1); auto spell = static_cast<spell_id>(wParam1);
@ -1482,7 +1482,7 @@ size_t OnSpellWall(const TCmd *pCmd, Player &player)
player.destParam3 = SDL_SwapLE16(message.wParam3); player.destParam3 = SDL_SwapLE16(message.wParam3);
player.destParam4 = SDL_SwapLE16(message.wParam4); player.destParam4 = SDL_SwapLE16(message.wParam4);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = static_cast<spell_type>(wParam2); player.queuedSpell.spellType = static_cast<SpellType>(wParam2);
player.queuedSpell.spellFrom = 0; player.queuedSpell.spellFrom = 0;
return sizeof(message); return sizeof(message);
@ -1503,7 +1503,7 @@ size_t OnSpellTile(const TCmd *pCmd, Player &player)
if (wParam1 > SPL_LAST) if (wParam1 > SPL_LAST)
return sizeof(message); return sizeof(message);
const uint16_t wParam2 = SDL_SwapLE16(message.wParam2); const uint16_t wParam2 = SDL_SwapLE16(message.wParam2);
if (wParam2 > RSPLTYPE_INVALID) if (wParam2 > static_cast<uint8_t>(SpellType::LAST))
return sizeof(message); return sizeof(message);
auto spell = static_cast<spell_id>(wParam1); auto spell = static_cast<spell_id>(wParam1);
@ -1522,7 +1522,7 @@ size_t OnSpellTile(const TCmd *pCmd, Player &player)
player.destParam2 = position.y; player.destParam2 = position.y;
player.destParam3 = SDL_SwapLE16(message.wParam3); player.destParam3 = SDL_SwapLE16(message.wParam3);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = static_cast<spell_type>(wParam2); player.queuedSpell.spellType = static_cast<SpellType>(wParam2);
return sizeof(message); return sizeof(message);
} }
@ -1557,7 +1557,7 @@ size_t OnTargetSpellTile(const TCmd *pCmd, Player &player)
player.destParam2 = position.y; player.destParam2 = position.y;
player.destParam3 = SDL_SwapLE16(message.wParam2); player.destParam3 = SDL_SwapLE16(message.wParam2);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = RSPLTYPE_SCROLL; player.queuedSpell.spellType = SpellType::Scroll;
player.queuedSpell.spellFrom = static_cast<int8_t>(wParam3); player.queuedSpell.spellFrom = static_cast<int8_t>(wParam3);
return sizeof(message); return sizeof(message);
@ -1653,7 +1653,7 @@ size_t OnSpellMonster(const TCmd *pCmd, Player &player)
if (wParam2 > SPL_LAST) if (wParam2 > SPL_LAST)
return sizeof(message); return sizeof(message);
const uint16_t wParam3 = SDL_SwapLE16(message.wParam3); const uint16_t wParam3 = SDL_SwapLE16(message.wParam3);
if (wParam3 > RSPLTYPE_INVALID) if (wParam3 > static_cast<uint8_t>(SpellType::LAST))
return sizeof(message); return sizeof(message);
auto spell = static_cast<spell_id>(wParam2); auto spell = static_cast<spell_id>(wParam2);
@ -1671,7 +1671,7 @@ size_t OnSpellMonster(const TCmd *pCmd, Player &player)
player.destParam1 = monsterIdx; player.destParam1 = monsterIdx;
player.destParam2 = SDL_SwapLE16(message.wParam4); player.destParam2 = SDL_SwapLE16(message.wParam4);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = static_cast<spell_type>(wParam3); player.queuedSpell.spellType = static_cast<SpellType>(wParam3);
player.queuedSpell.spellFrom = 0; player.queuedSpell.spellFrom = 0;
return sizeof(message); return sizeof(message);
@ -1692,7 +1692,7 @@ size_t OnSpellPlayer(const TCmd *pCmd, Player &player)
if (wParam2 > SPL_LAST) if (wParam2 > SPL_LAST)
return sizeof(message); return sizeof(message);
const uint16_t wParam3 = SDL_SwapLE16(message.wParam3); const uint16_t wParam3 = SDL_SwapLE16(message.wParam3);
if (wParam3 > RSPLTYPE_INVALID) if (wParam3 > static_cast<uint8_t>(SpellType::LAST))
return sizeof(message); return sizeof(message);
auto spell = static_cast<spell_id>(wParam2); auto spell = static_cast<spell_id>(wParam2);
@ -1710,7 +1710,7 @@ size_t OnSpellPlayer(const TCmd *pCmd, Player &player)
player.destParam1 = playerIdx; player.destParam1 = playerIdx;
player.destParam2 = SDL_SwapLE16(message.wParam4); player.destParam2 = SDL_SwapLE16(message.wParam4);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = static_cast<spell_type>(wParam3); player.queuedSpell.spellType = static_cast<SpellType>(wParam3);
player.queuedSpell.spellFrom = 0; player.queuedSpell.spellFrom = 0;
return sizeof(message); return sizeof(message);
@ -1745,7 +1745,7 @@ size_t OnTargetSpellMonster(const TCmd *pCmd, Player &player)
player.destParam1 = monsterIdx; player.destParam1 = monsterIdx;
player.destParam2 = SDL_SwapLE16(message.wParam3); player.destParam2 = SDL_SwapLE16(message.wParam3);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = RSPLTYPE_SCROLL; player.queuedSpell.spellType = SpellType::Scroll;
player.queuedSpell.spellFrom = static_cast<int8_t>(wParam4); player.queuedSpell.spellFrom = static_cast<int8_t>(wParam4);
return sizeof(message); return sizeof(message);
@ -1780,7 +1780,7 @@ size_t OnTargetSpellPlayer(const TCmd *pCmd, Player &player)
player.destParam1 = playerIdx; player.destParam1 = playerIdx;
player.destParam2 = SDL_SwapLE16(message.wParam3); player.destParam2 = SDL_SwapLE16(message.wParam3);
player.queuedSpell.spellId = spell; player.queuedSpell.spellId = spell;
player.queuedSpell.spellType = RSPLTYPE_SCROLL; player.queuedSpell.spellType = SpellType::Scroll;
player.queuedSpell.spellFrom = static_cast<int8_t>(wParam4); player.queuedSpell.spellFrom = static_cast<int8_t>(wParam4);
return sizeof(message); return sizeof(message);
@ -2481,7 +2481,7 @@ size_t OnNova(const TCmd *pCmd, Player &player)
if (player.isOnActiveLevel() && &player != MyPlayer && InDungeonBounds(position)) { if (player.isOnActiveLevel() && &player != MyPlayer && InDungeonBounds(position)) {
ClrPlrPath(player); ClrPlrPath(player);
player.queuedSpell.spellId = SPL_NOVA; player.queuedSpell.spellId = SPL_NOVA;
player.queuedSpell.spellType = RSPLTYPE_SCROLL; player.queuedSpell.spellType = SpellType::Scroll;
player.queuedSpell.spellFrom = 3; player.queuedSpell.spellFrom = 3;
player.destAction = ACTION_SPELL; player.destAction = ACTION_SPELL;
player.destParam1 = position.x; player.destParam1 = position.x;

34
Source/panels/spell_book.cpp

@ -48,28 +48,28 @@ void PrintSBookStr(const Surface &out, Point position, string_view text, UiFlags
UiFlags::ColorWhite | flags); UiFlags::ColorWhite | flags);
} }
spell_type GetSBookTrans(spell_id ii, bool townok) SpellType GetSBookTrans(spell_id ii, bool townok)
{ {
Player &player = *MyPlayer; Player &player = *MyPlayer;
if ((player._pClass == HeroClass::Monk) && (ii == SPL_SEARCH)) if ((player._pClass == HeroClass::Monk) && (ii == SPL_SEARCH))
return RSPLTYPE_SKILL; return SpellType::Skill;
spell_type st = RSPLTYPE_SPELL; SpellType st = SpellType::Spell;
if ((player._pISpells & GetSpellBitmask(ii)) != 0) { if ((player._pISpells & GetSpellBitmask(ii)) != 0) {
st = RSPLTYPE_CHARGES; st = SpellType::Charges;
} }
if ((player._pAblSpells & GetSpellBitmask(ii)) != 0) { if ((player._pAblSpells & GetSpellBitmask(ii)) != 0) {
st = RSPLTYPE_SKILL; st = SpellType::Skill;
} }
if (st == RSPLTYPE_SPELL) { if (st == SpellType::Spell) {
if (CheckSpell(*MyPlayer, ii, st, true) != SpellCheckResult::Success) { if (CheckSpell(*MyPlayer, ii, st, true) != SpellCheckResult::Success) {
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
} }
if (player.GetSpellLevel(ii) == 0) { if (player.GetSpellLevel(ii) == 0) {
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
} }
} }
if (townok && leveltype == DTYPE_TOWN && st != RSPLTYPE_INVALID && !spelldata[ii].sTownSpell) { if (townok && leveltype == DTYPE_TOWN && st != SpellType::Invalid && !spelldata[ii].sTownSpell) {
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
} }
return st; return st;
@ -129,12 +129,12 @@ void DrawSpellBook(const Surface &out)
for (int i = 1; i < 8; i++) { for (int i = 1; i < 8; i++) {
spell_id sn = SpellPages[sbooktab][i - 1]; spell_id sn = SpellPages[sbooktab][i - 1];
if (IsValidSpell(sn) && (spl & GetSpellBitmask(sn)) != 0) { if (IsValidSpell(sn) && (spl & GetSpellBitmask(sn)) != 0) {
spell_type st = GetSBookTrans(sn, true); SpellType st = GetSBookTrans(sn, true);
SetSpellTrans(st); SetSpellTrans(st);
const Point spellCellPosition = GetPanelPosition(UiPanels::Spell, { 11, yp + SpellBookDescription.height }); const Point spellCellPosition = GetPanelPosition(UiPanels::Spell, { 11, yp + SpellBookDescription.height });
DrawSmallSpellIcon(out, spellCellPosition, sn); DrawSmallSpellIcon(out, spellCellPosition, sn);
if (sn == player._pRSpell && st == player._pRSplType) { if (sn == player._pRSpell && st == player._pRSplType) {
SetSpellTrans(RSPLTYPE_SKILL); SetSpellTrans(SpellType::Skill);
DrawSmallSpellIconBorder(out, spellCellPosition); DrawSmallSpellIconBorder(out, spellCellPosition);
} }
@ -142,10 +142,10 @@ void DrawSpellBook(const Surface &out)
const Point line1 { 0, yp + textPaddingTop + lineHeight }; const Point line1 { 0, yp + textPaddingTop + lineHeight };
PrintSBookStr(out, line0, pgettext("spell", spelldata[sn].sNameText)); PrintSBookStr(out, line0, pgettext("spell", spelldata[sn].sNameText));
switch (GetSBookTrans(sn, false)) { switch (GetSBookTrans(sn, false)) {
case RSPLTYPE_SKILL: case SpellType::Skill:
PrintSBookStr(out, line1, _("Skill")); PrintSBookStr(out, line1, _("Skill"));
break; break;
case RSPLTYPE_CHARGES: { case SpellType::Charges: {
int charges = player.InvBody[INVLOC_HAND_LEFT]._iCharges; int charges = player.InvBody[INVLOC_HAND_LEFT]._iCharges;
PrintSBookStr(out, line1, fmt::format(fmt::runtime(ngettext("Staff ({:d} charge)", "Staff ({:d} charges)", charges)), charges)); PrintSBookStr(out, line1, fmt::format(fmt::runtime(ngettext("Staff ({:d} charge)", "Staff ({:d} charges)", charges)), charges));
} break; } break;
@ -191,12 +191,12 @@ void CheckSBook()
Player &player = *MyPlayer; Player &player = *MyPlayer;
uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells; uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells;
if (IsValidSpell(sn) && (spl & GetSpellBitmask(sn)) != 0) { if (IsValidSpell(sn) && (spl & GetSpellBitmask(sn)) != 0) {
spell_type st = RSPLTYPE_SPELL; SpellType st = SpellType::Spell;
if ((player._pISpells & GetSpellBitmask(sn)) != 0) { if ((player._pISpells & GetSpellBitmask(sn)) != 0) {
st = RSPLTYPE_CHARGES; st = SpellType::Charges;
} }
if ((player._pAblSpells & GetSpellBitmask(sn)) != 0) { if ((player._pAblSpells & GetSpellBitmask(sn)) != 0) {
st = RSPLTYPE_SKILL; st = SpellType::Skill;
} }
player._pRSpell = sn; player._pRSpell = sn;
player._pRSplType = st; player._pRSplType = st;

16
Source/panels/spell_icons.cpp

@ -97,7 +97,7 @@ void LoadLargeSpellIcons()
LargeSpellIcons = LoadCel("data\\spelicon", SPLICONLENGTH); LargeSpellIcons = LoadCel("data\\spelicon", SPLICONLENGTH);
#endif #endif
} }
SetSpellTrans(RSPLTYPE_SKILL); SetSpellTrans(SpellType::Skill);
} }
void FreeLargeSpellIcons() void FreeLargeSpellIcons()
@ -156,9 +156,9 @@ void DrawSmallSpellIconBorder(const Surface &out, Point position)
UnsafeDrawBorder2px(out, Rectangle { Point { position.x, position.y - height + 1 }, Size { width, height } }, SplTransTbl[PAL8_YELLOW + 2]); UnsafeDrawBorder2px(out, Rectangle { Point { position.x, position.y - height + 1 }, Size { width, height } }, SplTransTbl[PAL8_YELLOW + 2]);
} }
void SetSpellTrans(spell_type t) void SetSpellTrans(SpellType t)
{ {
if (t == RSPLTYPE_SKILL) { if (t == SpellType::Skill) {
for (int i = 0; i < 128; i++) for (int i = 0; i < 128; i++)
SplTransTbl[i] = i; SplTransTbl[i] = i;
} }
@ -167,7 +167,7 @@ void SetSpellTrans(spell_type t)
SplTransTbl[255] = 0; SplTransTbl[255] = 0;
switch (t) { switch (t) {
case RSPLTYPE_SPELL: case SpellType::Spell:
SplTransTbl[PAL8_YELLOW] = PAL16_BLUE + 1; SplTransTbl[PAL8_YELLOW] = PAL16_BLUE + 1;
SplTransTbl[PAL8_YELLOW + 1] = PAL16_BLUE + 3; SplTransTbl[PAL8_YELLOW + 1] = PAL16_BLUE + 3;
SplTransTbl[PAL8_YELLOW + 2] = PAL16_BLUE + 5; SplTransTbl[PAL8_YELLOW + 2] = PAL16_BLUE + 5;
@ -177,7 +177,7 @@ void SetSpellTrans(spell_type t)
SplTransTbl[PAL16_ORANGE - PAL16_BLUE + i] = i; SplTransTbl[PAL16_ORANGE - PAL16_BLUE + i] = i;
} }
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
SplTransTbl[PAL8_YELLOW] = PAL16_BEIGE + 1; SplTransTbl[PAL8_YELLOW] = PAL16_BEIGE + 1;
SplTransTbl[PAL8_YELLOW + 1] = PAL16_BEIGE + 3; SplTransTbl[PAL8_YELLOW + 1] = PAL16_BEIGE + 3;
SplTransTbl[PAL8_YELLOW + 2] = PAL16_BEIGE + 5; SplTransTbl[PAL8_YELLOW + 2] = PAL16_BEIGE + 5;
@ -186,7 +186,7 @@ void SetSpellTrans(spell_type t)
SplTransTbl[PAL16_ORANGE - PAL16_BEIGE + i] = i; SplTransTbl[PAL16_ORANGE - PAL16_BEIGE + i] = i;
} }
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
SplTransTbl[PAL8_YELLOW] = PAL16_ORANGE + 1; SplTransTbl[PAL8_YELLOW] = PAL16_ORANGE + 1;
SplTransTbl[PAL8_YELLOW + 1] = PAL16_ORANGE + 3; SplTransTbl[PAL8_YELLOW + 1] = PAL16_ORANGE + 3;
SplTransTbl[PAL8_YELLOW + 2] = PAL16_ORANGE + 5; SplTransTbl[PAL8_YELLOW + 2] = PAL16_ORANGE + 5;
@ -195,7 +195,7 @@ void SetSpellTrans(spell_type t)
SplTransTbl[PAL16_YELLOW - PAL16_ORANGE + i] = i; SplTransTbl[PAL16_YELLOW - PAL16_ORANGE + i] = i;
} }
break; break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
SplTransTbl[PAL8_YELLOW] = PAL16_GRAY + 1; SplTransTbl[PAL8_YELLOW] = PAL16_GRAY + 1;
SplTransTbl[PAL8_YELLOW + 1] = PAL16_GRAY + 3; SplTransTbl[PAL8_YELLOW + 1] = PAL16_GRAY + 3;
SplTransTbl[PAL8_YELLOW + 2] = PAL16_GRAY + 5; SplTransTbl[PAL8_YELLOW + 2] = PAL16_GRAY + 5;
@ -208,7 +208,7 @@ void SetSpellTrans(spell_type t)
SplTransTbl[PAL16_YELLOW + 15] = 0; SplTransTbl[PAL16_YELLOW + 15] = 0;
SplTransTbl[PAL16_ORANGE + 15] = 0; SplTransTbl[PAL16_ORANGE + 15] = 0;
break; break;
case RSPLTYPE_SKILL: case SpellType::Skill:
break; break;
} }
} }

2
Source/panels/spell_icons.hpp

@ -48,7 +48,7 @@ void DrawSmallSpellIconBorder(const Surface &out, Point position);
/** /**
* @brief Set the color mapping for the `Draw(Small|Large)SpellIcon(Border)` calls. * @brief Set the color mapping for the `Draw(Small|Large)SpellIcon(Border)` calls.
*/ */
void SetSpellTrans(spell_type t); void SetSpellTrans(SpellType t);
void LoadLargeSpellIcons(); void LoadLargeSpellIcons();
void FreeLargeSpellIcons(); void FreeLargeSpellIcons();

84
Source/panels/spell_list.cpp

@ -43,10 +43,10 @@ void PrintSBookHotkey(const Surface &out, Point position, const string_view text
DrawString(out, text, position, UiFlags::ColorWhite | UiFlags::Outlined); DrawString(out, text, position, UiFlags::ColorWhite | UiFlags::Outlined);
} }
bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType) bool GetSpellListSelection(spell_id &pSpell, SpellType &pSplType)
{ {
pSpell = spell_id::SPL_INVALID; pSpell = spell_id::SPL_INVALID;
pSplType = spell_type::RSPLTYPE_INVALID; pSplType = SpellType::Invalid;
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
for (auto &spellListItem : GetSpellListItems()) { for (auto &spellListItem : GetSpellListItems()) {
@ -54,7 +54,7 @@ bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType)
pSpell = spellListItem.id; pSpell = spellListItem.id;
pSplType = spellListItem.type; pSplType = spellListItem.type;
if (myPlayer._pClass == HeroClass::Monk && spellListItem.id == SPL_SEARCH) if (myPlayer._pClass == HeroClass::Monk && spellListItem.id == SPL_SEARCH)
pSplType = RSPLTYPE_SKILL; pSplType = SpellType::Skill;
return true; return true;
} }
} }
@ -62,7 +62,7 @@ bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType)
return false; return false;
} }
std::optional<string_view> GetHotkeyName(spell_id spellId, spell_type spellType) std::optional<string_view> GetHotkeyName(spell_id spellId, SpellType spellType)
{ {
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
for (size_t t = 0; t < NumHotkeys; t++) { for (size_t t = 0; t < NumHotkeys; t++) {
@ -80,23 +80,23 @@ void DrawSpell(const Surface &out)
{ {
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
spell_id spl = myPlayer._pRSpell; spell_id spl = myPlayer._pRSpell;
spell_type st = myPlayer._pRSplType; SpellType st = myPlayer._pRSplType;
if (!IsValidSpell(spl)) { if (!IsValidSpell(spl)) {
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
spl = SPL_NULL; spl = SPL_NULL;
} }
if (st == RSPLTYPE_SPELL) { if (st == SpellType::Spell) {
int tlvl = myPlayer.GetSpellLevel(spl); int tlvl = myPlayer.GetSpellLevel(spl);
if (CheckSpell(*MyPlayer, spl, st, true) != SpellCheckResult::Success) if (CheckSpell(*MyPlayer, spl, st, true) != SpellCheckResult::Success)
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
if (tlvl <= 0) if (tlvl <= 0)
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
} }
if (leveltype == DTYPE_TOWN && st != RSPLTYPE_INVALID && !spelldata[spl].sTownSpell) if (leveltype == DTYPE_TOWN && st != SpellType::Invalid && !spelldata[spl].sTownSpell)
st = RSPLTYPE_INVALID; st = SpellType::Invalid;
SetSpellTrans(st); SetSpellTrans(st);
const Point position = GetMainPanel().position + Displacement { 565, 119 }; const Point position = GetMainPanel().position + Displacement { 565, 119 };
@ -115,16 +115,16 @@ void DrawSpellList(const Surface &out)
for (auto &spellListItem : GetSpellListItems()) { for (auto &spellListItem : GetSpellListItems()) {
const spell_id spellId = spellListItem.id; const spell_id spellId = spellListItem.id;
spell_type transType = spellListItem.type; SpellType transType = spellListItem.type;
int spellLevel = 0; int spellLevel = 0;
const SpellData &spellDataItem = spelldata[static_cast<size_t>(spellListItem.id)]; const SpellData &spellDataItem = spelldata[static_cast<size_t>(spellListItem.id)];
if (leveltype == DTYPE_TOWN && !spellDataItem.sTownSpell) { if (leveltype == DTYPE_TOWN && !spellDataItem.sTownSpell) {
transType = RSPLTYPE_INVALID; transType = SpellType::Invalid;
} }
if (spellListItem.type == RSPLTYPE_SPELL) { if (spellListItem.type == SpellType::Spell) {
spellLevel = myPlayer.GetSpellLevel(spellListItem.id); spellLevel = myPlayer.GetSpellLevel(spellListItem.id);
if (spellLevel == 0) if (spellLevel == 0)
transType = RSPLTYPE_INVALID; transType = SpellType::Invalid;
} }
SetSpellTrans(transType); SetSpellTrans(transType);
@ -141,12 +141,12 @@ void DrawSpellList(const Surface &out)
uint8_t spellColor = PAL16_GRAY + 5; uint8_t spellColor = PAL16_GRAY + 5;
switch (spellListItem.type) { switch (spellListItem.type) {
case RSPLTYPE_SKILL: case SpellType::Skill:
spellColor = PAL16_YELLOW - 46; spellColor = PAL16_YELLOW - 46;
PrintSBookSpellType(out, spellListItem.location, _("Skill"), spellColor); PrintSBookSpellType(out, spellListItem.location, _("Skill"), spellColor);
InfoString = fmt::format(fmt::runtime(_("{:s} Skill")), pgettext("spell", spellDataItem.sNameText)); InfoString = fmt::format(fmt::runtime(_("{:s} Skill")), pgettext("spell", spellDataItem.sNameText));
break; break;
case RSPLTYPE_SPELL: case SpellType::Spell:
if (!myPlayer.isOnLevel(0)) { if (!myPlayer.isOnLevel(0)) {
spellColor = PAL16_BLUE + 5; spellColor = PAL16_BLUE + 5;
} }
@ -160,7 +160,7 @@ void DrawSpellList(const Surface &out)
else else
AddPanelString(fmt::format(fmt::runtime(_("Spell Level {:d}")), spellLevel)); AddPanelString(fmt::format(fmt::runtime(_("Spell Level {:d}")), spellLevel));
break; break;
case RSPLTYPE_SCROLL: { case SpellType::Scroll: {
if (!myPlayer.isOnLevel(0)) { if (!myPlayer.isOnLevel(0)) {
spellColor = PAL16_RED - 59; spellColor = PAL16_RED - 59;
} }
@ -172,7 +172,7 @@ void DrawSpellList(const Surface &out)
}); });
AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Scroll", "{:d} Scrolls", scrollCount)), scrollCount)); AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Scroll", "{:d} Scrolls", scrollCount)), scrollCount));
} break; } break;
case RSPLTYPE_CHARGES: { case SpellType::Charges: {
if (!myPlayer.isOnLevel(0)) { if (!myPlayer.isOnLevel(0)) {
spellColor = PAL16_ORANGE + 5; spellColor = PAL16_ORANGE + 5;
} }
@ -181,7 +181,7 @@ void DrawSpellList(const Surface &out)
int charges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges; int charges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges;
AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Charge", "{:d} Charges", charges)), charges)); AddPanelString(fmt::format(fmt::runtime(ngettext("{:d} Charge", "{:d} Charges", charges)), charges));
} break; } break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
break; break;
} }
if (hotkeyName) { if (hotkeyName) {
@ -200,22 +200,22 @@ std::vector<SpellListItem> GetSpellListItems()
int x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS; int x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
int y = mainPanelPosition.y - 17; int y = mainPanelPosition.y - 17;
for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) { for (auto i : enum_values<SpellType>()) {
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
switch ((spell_type)i) { switch (static_cast<SpellType>(i)) {
case RSPLTYPE_SKILL: case SpellType::Skill:
mask = myPlayer._pAblSpells; mask = myPlayer._pAblSpells;
break; break;
case RSPLTYPE_SPELL: case SpellType::Spell:
mask = myPlayer._pMemSpells; mask = myPlayer._pMemSpells;
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
mask = myPlayer._pScrlSpells; mask = myPlayer._pScrlSpells;
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
mask = myPlayer._pISpells; mask = myPlayer._pISpells;
break; break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
break; break;
} }
int8_t j = SPL_FIREBOLT; int8_t j = SPL_FIREBOLT;
@ -225,7 +225,7 @@ std::vector<SpellListItem> GetSpellListItems()
int lx = x; int lx = x;
int ly = y - SPLICONLENGTH; int ly = y - SPLICONLENGTH;
bool isSelected = (MousePosition.x >= lx && MousePosition.x < lx + SPLICONLENGTH && MousePosition.y >= ly && MousePosition.y < ly + SPLICONLENGTH); bool isSelected = (MousePosition.x >= lx && MousePosition.x < lx + SPLICONLENGTH && MousePosition.y >= ly && MousePosition.y < ly + SPLICONLENGTH);
spellListItems.emplace_back(SpellListItem { { x, y }, (spell_type)i, (spell_id)j, isSelected }); spellListItems.emplace_back(SpellListItem { { x, y }, static_cast<SpellType>(i), (spell_id)j, isSelected });
x -= SPLICONLENGTH; x -= SPLICONLENGTH;
if (x == mainPanelPosition.x + 12 - SPLICONLENGTH) { if (x == mainPanelPosition.x + 12 - SPLICONLENGTH) {
x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS; x = mainPanelPosition.x + 12 + SPLICONLENGTH * SPLROWICONLS;
@ -246,7 +246,7 @@ std::vector<SpellListItem> GetSpellListItems()
void SetSpell() void SetSpell()
{ {
spell_id pSpell; spell_id pSpell;
spell_type pSplType; SpellType pSplType;
spselflag = false; spselflag = false;
if (!GetSpellListSelection(pSpell, pSplType)) { if (!GetSpellListSelection(pSpell, pSplType)) {
@ -263,7 +263,7 @@ void SetSpell()
void SetSpeedSpell(size_t slot) void SetSpeedSpell(size_t slot)
{ {
spell_id pSpell; spell_id pSpell;
spell_type pSplType; SpellType pSplType;
if (!GetSpellListSelection(pSpell, pSplType)) { if (!GetSpellListSelection(pSpell, pSplType)) {
return; return;
@ -289,19 +289,19 @@ void ToggleSpell(size_t slot)
} }
switch (myPlayer._pSplTHotKey[slot]) { switch (myPlayer._pSplTHotKey[slot]) {
case RSPLTYPE_SKILL: case SpellType::Skill:
spells = myPlayer._pAblSpells; spells = myPlayer._pAblSpells;
break; break;
case RSPLTYPE_SPELL: case SpellType::Spell:
spells = myPlayer._pMemSpells; spells = myPlayer._pMemSpells;
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
spells = myPlayer._pScrlSpells; spells = myPlayer._pScrlSpells;
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
spells = myPlayer._pISpells; spells = myPlayer._pISpells;
break; break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
return; return;
} }
@ -324,26 +324,26 @@ void DoSpeedBook()
Player &myPlayer = *MyPlayer; Player &myPlayer = *MyPlayer;
if (IsValidSpell(myPlayer._pRSpell)) { if (IsValidSpell(myPlayer._pRSpell)) {
for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) { for (auto i : enum_values<SpellType>()) {
uint64_t spells; uint64_t spells;
switch (i) { switch (static_cast<SpellType>(i)) {
case RSPLTYPE_SKILL: case SpellType::Skill:
spells = myPlayer._pAblSpells; spells = myPlayer._pAblSpells;
break; break;
case RSPLTYPE_SPELL: case SpellType::Spell:
spells = myPlayer._pMemSpells; spells = myPlayer._pMemSpells;
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
spells = myPlayer._pScrlSpells; spells = myPlayer._pScrlSpells;
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
spells = myPlayer._pISpells; spells = myPlayer._pISpells;
break; break;
} }
uint64_t spell = 1; uint64_t spell = 1;
for (int j = 1; j < MAX_SPELLS; j++) { for (int j = 1; j < MAX_SPELLS; j++) {
if ((spell & spells) != 0) { if ((spell & spells) != 0) {
if (j == myPlayer._pRSpell && i == myPlayer._pRSplType) { if (j == myPlayer._pRSpell && static_cast<SpellType>(i) == myPlayer._pRSplType) {
x = xo + SPLICONLENGTH / 2; x = xo + SPLICONLENGTH / 2;
y = yo - SPLICONLENGTH / 2; y = yo - SPLICONLENGTH / 2;
} }

2
Source/panels/spell_list.hpp

@ -11,7 +11,7 @@ namespace devilution {
struct SpellListItem { struct SpellListItem {
Point location; Point location;
spell_type type; SpellType type;
spell_id id; spell_id id;
bool isSelected; bool isSelected;
}; };

42
Source/player.cpp

@ -453,17 +453,17 @@ void StartSpell(Player &player, Direction d, WorldTileCoord cx, WorldTileCoord c
// Checks conditions for spell again, cause initial check was done when spell was queued and the parameters could be changed meanwhile // Checks conditions for spell again, cause initial check was done when spell was queued and the parameters could be changed meanwhile
bool isValid = true; bool isValid = true;
switch (player.queuedSpell.spellType) { switch (player.queuedSpell.spellType) {
case RSPLTYPE_SKILL: case SpellType::Skill:
case RSPLTYPE_SPELL: case SpellType::Spell:
isValid = CheckSpell(player, player.queuedSpell.spellId, player.queuedSpell.spellType, true) == SpellCheckResult::Success; isValid = CheckSpell(player, player.queuedSpell.spellId, player.queuedSpell.spellType, true) == SpellCheckResult::Success;
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
isValid = CanUseScroll(player, player.queuedSpell.spellId); isValid = CanUseScroll(player, player.queuedSpell.spellId);
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
isValid = CanUseStaff(player, player.queuedSpell.spellId); isValid = CanUseStaff(player, player.queuedSpell.spellId);
break; break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
isValid = false; isValid = false;
break; break;
} }
@ -1236,7 +1236,7 @@ bool DoSpell(Player &player)
player.position.temp.y, player.position.temp.y,
player.executedSpell.spellLevel); player.executedSpell.spellLevel);
if (IsAnyOf(player.executedSpell.spellType, RSPLTYPE_SCROLL, RSPLTYPE_CHARGES)) { if (IsAnyOf(player.executedSpell.spellType, SpellType::Scroll, SpellType::Charges)) {
EnsureValidReadiedSpell(player); EnsureValidReadiedSpell(player);
} }
} }
@ -1997,7 +1997,7 @@ void Player::ReadySpellFromEquipment(inv_body_loc bodyLocation)
auto &item = InvBody[bodyLocation]; auto &item = InvBody[bodyLocation];
if (item._itype == ItemType::Staff && IsValidSpell(item._iSpell) && item._iCharges > 0) { if (item._itype == ItemType::Staff && IsValidSpell(item._iSpell) && item._iCharges > 0) {
_pRSpell = item._iSpell; _pRSpell = item._iSpell;
_pRSplType = RSPLTYPE_CHARGES; _pRSplType = SpellType::Charges;
RedrawEverything(); RedrawEverything();
} }
} }
@ -2540,7 +2540,7 @@ void CreatePlayer(Player &player, HeroClass c)
player._pLightRad = 10; player._pLightRad = 10;
player._pInfraFlag = false; player._pInfraFlag = false;
player._pRSplType = RSPLTYPE_SKILL; player._pRSplType = SpellType::Skill;
if (c == HeroClass::Warrior) { if (c == HeroClass::Warrior) {
player._pAblSpells = GetSpellBitmask(SPL_REPAIR); player._pAblSpells = GetSpellBitmask(SPL_REPAIR);
player._pRSpell = SPL_REPAIR; player._pRSpell = SPL_REPAIR;
@ -2563,7 +2563,7 @@ void CreatePlayer(Player &player, HeroClass c)
if (c == HeroClass::Sorcerer) { if (c == HeroClass::Sorcerer) {
player._pMemSpells = GetSpellBitmask(SPL_FIREBOLT); player._pMemSpells = GetSpellBitmask(SPL_FIREBOLT);
player._pRSplType = RSPLTYPE_SPELL; player._pRSplType = SpellType::Spell;
player._pRSpell = SPL_FIREBOLT; player._pRSpell = SPL_FIREBOLT;
} else { } else {
player._pMemSpells = 0; player._pMemSpells = 0;
@ -2749,7 +2749,7 @@ void AddPlrMonstExper(int lvl, int exp, char pmask)
void InitPlayer(Player &player, bool firstTime) void InitPlayer(Player &player, bool firstTime)
{ {
if (firstTime) { if (firstTime) {
player._pRSplType = RSPLTYPE_INVALID; player._pRSplType = SpellType::Invalid;
player._pRSpell = SPL_INVALID; player._pRSpell = SPL_INVALID;
if (&player == MyPlayer) if (&player == MyPlayer)
LoadHotkeys(); LoadHotkeys();
@ -3417,7 +3417,7 @@ void CalcPlrStaff(Player &player)
} }
} }
void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType) void CheckPlrSpell(bool isShiftHeld, spell_id spellID, SpellType spellType)
{ {
bool addflag = false; bool addflag = false;
@ -3456,23 +3456,23 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType)
SpellCheckResult spellcheck = SpellCheckResult::Success; SpellCheckResult spellcheck = SpellCheckResult::Success;
switch (spellType) { switch (spellType) {
case RSPLTYPE_SKILL: case SpellType::Skill:
case RSPLTYPE_SPELL: case SpellType::Spell:
spellcheck = CheckSpell(*MyPlayer, spellID, spellType, false); spellcheck = CheckSpell(*MyPlayer, spellID, spellType, false);
addflag = spellcheck == SpellCheckResult::Success; addflag = spellcheck == SpellCheckResult::Success;
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
addflag = pcurs == CURSOR_HAND && CanUseScroll(myPlayer, spellID); addflag = pcurs == CURSOR_HAND && CanUseScroll(myPlayer, spellID);
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
addflag = pcurs == CURSOR_HAND && CanUseStaff(myPlayer, spellID); addflag = pcurs == CURSOR_HAND && CanUseStaff(myPlayer, spellID);
break; break;
case RSPLTYPE_INVALID: case SpellType::Invalid:
return; return;
} }
if (!addflag) { if (!addflag) {
if (spellType == RSPLTYPE_SPELL) { if (spellType == SpellType::Spell) {
switch (spellcheck) { switch (spellcheck) {
case SpellCheckResult::Fail_NoMana: case SpellCheckResult::Fail_NoMana:
myPlayer.Say(HeroSpeech::NotEnoughMana); myPlayer.Say(HeroSpeech::NotEnoughMana);
@ -3493,16 +3493,16 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType)
if (IsWallSpell(spellID)) { if (IsWallSpell(spellID)) {
LastMouseButtonAction = MouseActionType::Spell; LastMouseButtonAction = MouseActionType::Spell;
Direction sd = GetDirection(myPlayer.position.tile, cursPosition); Direction sd = GetDirection(myPlayer.position.tile, cursPosition);
NetSendCmdLocParam4(true, CMD_SPELLXYD, cursPosition, spellID, spellType, static_cast<uint16_t>(sd), sl); NetSendCmdLocParam4(true, CMD_SPELLXYD, cursPosition, spellID, static_cast<uint8_t>(spellType), static_cast<uint16_t>(sd), sl);
} else if (pcursmonst != -1 && !isShiftHeld) { } else if (pcursmonst != -1 && !isShiftHeld) {
LastMouseButtonAction = MouseActionType::SpellMonsterTarget; LastMouseButtonAction = MouseActionType::SpellMonsterTarget;
NetSendCmdParam4(true, CMD_SPELLID, pcursmonst, spellID, spellType, sl); NetSendCmdParam4(true, CMD_SPELLID, pcursmonst, spellID, static_cast<uint8_t>(spellType), sl);
} else if (pcursplr != -1 && !isShiftHeld && !myPlayer.friendlyMode) { } else if (pcursplr != -1 && !isShiftHeld && !myPlayer.friendlyMode) {
LastMouseButtonAction = MouseActionType::SpellPlayerTarget; LastMouseButtonAction = MouseActionType::SpellPlayerTarget;
NetSendCmdParam4(true, CMD_SPELLPID, pcursplr, spellID, spellType, sl); NetSendCmdParam4(true, CMD_SPELLPID, pcursplr, spellID, static_cast<uint8_t>(spellType), sl);
} else { } else {
LastMouseButtonAction = MouseActionType::Spell; LastMouseButtonAction = MouseActionType::Spell;
NetSendCmdLocParam3(true, CMD_SPELLXY, cursPosition, spellID, spellType, sl); NetSendCmdLocParam3(true, CMD_SPELLXY, cursPosition, spellID, static_cast<uint8_t>(spellType), sl);
} }
} }

8
Source/player.h

@ -208,7 +208,7 @@ struct PlayerAnimationData {
struct SpellCastInfo { struct SpellCastInfo {
spell_id spellId; spell_id spellId;
spell_type spellType; SpellType spellType;
/* @brief Inventory location for scrolls */ /* @brief Inventory location for scrolls */
int8_t spellFrom; int8_t spellFrom;
/* @brief Used for spell level */ /* @brief Used for spell level */
@ -324,7 +324,7 @@ struct Player {
SpellCastInfo executedSpell; SpellCastInfo executedSpell;
spell_id _pTSpell; spell_id _pTSpell;
spell_id _pRSpell; spell_id _pRSpell;
spell_type _pRSplType; SpellType _pRSplType;
spell_id _pSBkSpell; spell_id _pSBkSpell;
int8_t _pSplLvl[64]; int8_t _pSplLvl[64];
/** @brief Bitmask of staff spell */ /** @brief Bitmask of staff spell */
@ -337,7 +337,7 @@ struct Player {
uint64_t _pScrlSpells; uint64_t _pScrlSpells;
SpellFlag _pSpellFlags; SpellFlag _pSpellFlags;
spell_id _pSplHotKey[NumHotkeys]; spell_id _pSplHotKey[NumHotkeys];
spell_type _pSplTHotKey[NumHotkeys]; SpellType _pSplTHotKey[NumHotkeys];
bool _pBlockFlag; bool _pBlockFlag;
bool _pInvincible; bool _pInvincible;
int8_t _pLightRad; int8_t _pLightRad;
@ -817,7 +817,7 @@ void ClrPlrPath(Player &player);
bool PosOkPlayer(const Player &player, Point position); bool PosOkPlayer(const Player &player, Point position);
void MakePlrPath(Player &player, Point targetPosition, bool endspace); void MakePlrPath(Player &player, Point targetPosition, bool endspace);
void CalcPlrStaff(Player &player); void CalcPlrStaff(Player &player);
void CheckPlrSpell(bool isShiftHeld, spell_id spellID = MyPlayer->_pRSpell, spell_type spellType = MyPlayer->_pRSplType); void CheckPlrSpell(bool isShiftHeld, spell_id spellID = MyPlayer->_pRSpell, SpellType spellType = MyPlayer->_pRSplType);
void SyncPlrAnim(Player &player); void SyncPlrAnim(Player &player);
void SyncInitPlrPos(Player &player); void SyncInitPlrPos(Player &player);
void SyncInitPlr(Player &player); void SyncInitPlr(Player &player);

14
Source/spelldat.h

@ -13,12 +13,14 @@ namespace devilution {
#define MAX_SPELLS 52 #define MAX_SPELLS 52
enum spell_type : uint8_t { enum class SpellType : uint8_t {
RSPLTYPE_SKILL, Skill,
RSPLTYPE_SPELL, FIRST = Skill,
RSPLTYPE_SCROLL, Spell,
RSPLTYPE_CHARGES, Scroll,
RSPLTYPE_INVALID, Charges,
Invalid,
LAST = Invalid,
}; };
enum spell_id : int8_t { enum spell_id : int8_t {

28
Source/spells.cpp

@ -31,15 +31,15 @@ namespace {
bool IsReadiedSpellValid(const Player &player) bool IsReadiedSpellValid(const Player &player)
{ {
switch (player._pRSplType) { switch (player._pRSplType) {
case RSPLTYPE_SKILL: case SpellType::Skill:
case RSPLTYPE_SPELL: case SpellType::Spell:
case RSPLTYPE_INVALID: case SpellType::Invalid:
return true; return true;
case RSPLTYPE_CHARGES: case SpellType::Charges:
return (player._pISpells & GetSpellBitmask(player._pRSpell)) != 0; return (player._pISpells & GetSpellBitmask(player._pRSpell)) != 0;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
return (player._pScrlSpells & GetSpellBitmask(player._pRSpell)) != 0; return (player._pScrlSpells & GetSpellBitmask(player._pRSpell)) != 0;
default: default:
@ -59,8 +59,8 @@ void ClearReadiedSpell(Player &player)
RedrawEverything(); RedrawEverything();
} }
if (player._pRSplType != RSPLTYPE_INVALID) { if (player._pRSplType != SpellType::Invalid) {
player._pRSplType = RSPLTYPE_INVALID; player._pRSplType = SpellType::Invalid;
RedrawEverything(); RedrawEverything();
} }
} }
@ -175,16 +175,16 @@ int GetManaAmount(const Player &player, spell_id sn)
void ConsumeSpell(Player &player, spell_id sn) void ConsumeSpell(Player &player, spell_id sn)
{ {
switch (player.executedSpell.spellType) { switch (player.executedSpell.spellType) {
case RSPLTYPE_SKILL: case SpellType::Skill:
case RSPLTYPE_INVALID: case SpellType::Invalid:
break; break;
case RSPLTYPE_SCROLL: case SpellType::Scroll:
ConsumeScroll(player); ConsumeScroll(player);
break; break;
case RSPLTYPE_CHARGES: case SpellType::Charges:
ConsumeStaffCharge(player); ConsumeStaffCharge(player);
break; break;
case RSPLTYPE_SPELL: case SpellType::Spell:
#ifdef _DEBUG #ifdef _DEBUG
if (DebugGodMode) if (DebugGodMode)
break; break;
@ -210,7 +210,7 @@ void EnsureValidReadiedSpell(Player &player)
} }
} }
SpellCheckResult CheckSpell(const Player &player, spell_id sn, spell_type st, bool manaonly) SpellCheckResult CheckSpell(const Player &player, spell_id sn, SpellType st, bool manaonly)
{ {
#ifdef _DEBUG #ifdef _DEBUG
if (DebugGodMode) if (DebugGodMode)
@ -221,7 +221,7 @@ SpellCheckResult CheckSpell(const Player &player, spell_id sn, spell_type st, bo
return SpellCheckResult::Fail_Busy; return SpellCheckResult::Fail_Busy;
} }
if (st == RSPLTYPE_SKILL) { if (st == SpellType::Skill) {
return SpellCheckResult::Success; return SpellCheckResult::Success;
} }

2
Source/spells.h

@ -21,7 +21,7 @@ bool IsWallSpell(spell_id spl);
bool TargetsMonster(spell_id id); bool TargetsMonster(spell_id id);
int GetManaAmount(const Player &player, spell_id sn); int GetManaAmount(const Player &player, spell_id sn);
void ConsumeSpell(Player &player, spell_id sn); void ConsumeSpell(Player &player, spell_id sn);
SpellCheckResult CheckSpell(const Player &player, spell_id sn, spell_type st, bool manaonly); SpellCheckResult CheckSpell(const Player &player, spell_id sn, SpellType st, bool manaonly);
/** /**
* @brief Ensures the player's current readied spell is a valid selection for the character. If the current selection is * @brief Ensures the player's current readied spell is a valid selection for the character. If the current selection is

4
test/player_test.cpp

@ -139,11 +139,11 @@ static void AssertPlayer(Player &player)
ASSERT_EQ(player._pmode, 0); ASSERT_EQ(player._pmode, 0);
ASSERT_EQ(Count8(player.walkpath, MaxPathLength), 0); ASSERT_EQ(Count8(player.walkpath, MaxPathLength), 0);
ASSERT_EQ(player.queuedSpell.spellId, 0); ASSERT_EQ(player.queuedSpell.spellId, 0);
ASSERT_EQ(player.queuedSpell.spellType, 0); ASSERT_EQ(player.queuedSpell.spellType, SpellType::Skill);
ASSERT_EQ(player.queuedSpell.spellFrom, 0); ASSERT_EQ(player.queuedSpell.spellFrom, 0);
ASSERT_EQ(player._pTSpell, 0); ASSERT_EQ(player._pTSpell, 0);
ASSERT_EQ(player._pRSpell, 28); ASSERT_EQ(player._pRSpell, 28);
ASSERT_EQ(player._pRSplType, 0); ASSERT_EQ(player._pRSplType, SpellType::Skill);
ASSERT_EQ(player._pSBkSpell, 0); ASSERT_EQ(player._pSBkSpell, 0);
ASSERT_EQ(player._pAblSpells, 134217728); ASSERT_EQ(player._pAblSpells, 134217728);
ASSERT_EQ(player._pScrlSpells, 0); ASSERT_EQ(player._pScrlSpells, 0);

4
test/writehero_test.cpp

@ -310,11 +310,11 @@ void AssertPlayer(Player &player)
ASSERT_EQ(player.AnimInfo.numberOfFrames, 20); ASSERT_EQ(player.AnimInfo.numberOfFrames, 20);
ASSERT_EQ(player.AnimInfo.currentFrame, 0); ASSERT_EQ(player.AnimInfo.currentFrame, 0);
ASSERT_EQ(player.queuedSpell.spellId, -1); ASSERT_EQ(player.queuedSpell.spellId, -1);
ASSERT_EQ(player.queuedSpell.spellType, 4); ASSERT_EQ(player.queuedSpell.spellType, SpellType::Invalid);
ASSERT_EQ(player.queuedSpell.spellFrom, 0); ASSERT_EQ(player.queuedSpell.spellFrom, 0);
ASSERT_EQ(player._pTSpell, 0); ASSERT_EQ(player._pTSpell, 0);
ASSERT_EQ(player._pRSpell, -1); ASSERT_EQ(player._pRSpell, -1);
ASSERT_EQ(player._pRSplType, 4); ASSERT_EQ(player._pRSplType, SpellType::Invalid);
ASSERT_EQ(player._pSBkSpell, -1); ASSERT_EQ(player._pSBkSpell, -1);
ASSERT_EQ(player._pAblSpells, 134217728); ASSERT_EQ(player._pAblSpells, 134217728);
ASSERT_EQ(player._pScrlSpells, 0); ASSERT_EQ(player._pScrlSpells, 0);

Loading…
Cancel
Save