diff --git a/Source/control.cpp b/Source/control.cpp index ae5a269ee..9800febdb 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -744,8 +744,8 @@ void CheckPanelInfo() break; case RSPLTYPE_SPELL: { AddPanelString(fmt::format(fmt::runtime(_("{:s} Spell")), pgettext("spell", spelldata[spellId].sNameText))); - int c = std::max(myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spellId], 0); - AddPanelString(c == 0 ? _("Spell Level 0 - Unusable") : fmt::format(fmt::runtime(_("Spell Level {:d}")), c)); + const int spellLevel = myPlayer.GetSpellLevel(spellId); + AddPanelString(spellLevel == 0 ? _("Spell Level 0 - Unusable") : fmt::format(fmt::runtime(_("Spell Level {:d}")), spellLevel)); } break; case RSPLTYPE_SCROLL: { AddPanelString(fmt::format(fmt::runtime(_("Scroll of {:s}")), pgettext("spell", spelldata[spellId].sNameText))); diff --git a/Source/diablo.cpp b/Source/diablo.cpp index c33e315e2..4fef776fb 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1897,11 +1897,11 @@ bool TryIconCurs() if (pcurs == CURSOR_TELEPORT) { if (pcursmonst != -1) - NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(myPlayer, myPlayer._pTSpell)); + NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, myPlayer.GetSpellLevel(myPlayer._pTSpell)); else if (pcursplr != -1) - NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, GetSpellLevel(myPlayer, myPlayer._pTSpell)); + NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, myPlayer.GetSpellLevel(myPlayer._pTSpell)); else - NetSendCmdLocParam2(true, CMD_TSPELLXY, cursPosition, myPlayer._pTSpell, GetSpellLevel(myPlayer, myPlayer._pTSpell)); + NetSendCmdLocParam2(true, CMD_TSPELLXY, cursPosition, myPlayer._pTSpell, myPlayer.GetSpellLevel(myPlayer._pTSpell)); NewCursor(CURSOR_HAND); return true; } diff --git a/Source/missiles.cpp b/Source/missiles.cpp index d1d0c6864..0ad767f60 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -600,7 +600,7 @@ bool GuardianTryFireAt(Missile &missile, Point target) return false; Direction dir = GetDirection(position, target); - AddMissile(position, target, dir, MIS_FIREBOLT, TARGET_MONSTERS, missile._misource, missile._midam, GetSpellLevel(Players[missile._misource], SPL_FIREBOLT), &missile); + AddMissile(position, target, dir, MIS_FIREBOLT, TARGET_MONSTERS, missile._misource, missile._midam, Players[missile._misource].GetSpellLevel(SPL_FIREBOLT), &missile); SetMissDir(missile, 2); missile.var2 = 3; @@ -680,14 +680,14 @@ bool IsMissileBlockedByTile(Point tile) return object != nullptr && !object->_oMissFlag; } -void GetDamageAmt(int i, int *mind, int *maxd) +void GetDamageAmt(spell_id i, int *mind, int *maxd) { assert(MyPlayerId >= 0 && MyPlayerId < MAX_PLRS); assert(i >= 0 && i < 64); Player &myPlayer = *MyPlayer; - int sl = myPlayer._pSplLvl[i] + myPlayer._pISplLvlAdd; + const int sl = myPlayer.GetSpellLevel(i); switch (i) { case SPL_FIREBOLT: @@ -799,17 +799,11 @@ void GetDamageAmt(int i, int *mind, int *maxd) *mind = (myPlayer._pMagic / 2) + 3 * sl - (myPlayer._pMagic / 8); *maxd = *mind; break; + default: + break; } } -int GetSpellLevel(const Player &player, spell_id sn) -{ - if (&player != MyPlayer) - return 1; // BUGFIX spell level will be wrong in multiplayer - - return std::max(player._pISplLvlAdd + player._pSplLvl[sn], 0); -} - Direction16 GetDirection16(Point p1, Point p2) { Displacement offset = p2 - p1; @@ -1164,7 +1158,7 @@ void AddBerserk(Missile &missile, const AddMissileParameter ¶meter) if (targetMonsterPosition) { auto &monster = Monsters[abs(dMonster[targetMonsterPosition->x][targetMonsterPosition->y]) - 1]; Player &player = Players[missile._misource]; - int slvl = GetSpellLevel(player, SPL_BERSERK); + const int slvl = player.GetSpellLevel(SPL_BERSERK); monster._mFlags |= MFLAG_BERSERK | MFLAG_GOLEM; monster.mMinDamage = (GenerateRnd(10) + 120) * monster.mMinDamage / 100 + slvl; monster.mMaxDamage = (GenerateRnd(10) + 120) * monster.mMaxDamage / 100 + slvl; diff --git a/Source/missiles.h b/Source/missiles.h index f2e85c008..a2b99b8dd 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -138,8 +138,7 @@ struct Missile { extern std::list Missiles; extern bool MissilePreFlag; -void GetDamageAmt(int i, int *mind, int *maxd); -int GetSpellLevel(const Player &player, spell_id sn); +void GetDamageAmt(spell_id i, int *mind, int *maxd); /** * @brief Returns the direction a vector from p1(x1, y1) to p2(x2, y2) is pointing to. diff --git a/Source/panels/spell_book.cpp b/Source/panels/spell_book.cpp index 438994595..c317efc62 100644 --- a/Source/panels/spell_book.cpp +++ b/Source/panels/spell_book.cpp @@ -66,7 +66,7 @@ spell_type GetSBookTrans(spell_id ii, bool townok) if (CheckSpell(MyPlayerId, ii, st, true) != SpellCheckResult::Success) { st = RSPLTYPE_INVALID; } - if ((char)(player._pSplLvl[ii] + player._pISplLvlAdd) <= 0) { + if (player.GetSpellLevel(ii) == 0) { st = RSPLTYPE_INVALID; } } @@ -159,7 +159,7 @@ void DrawSpellBook(const Surface &out) } break; default: { int mana = GetManaAmount(player, sn) >> 6; - int lvl = std::max(player._pSplLvl[sn] + player._pISplLvlAdd, 0); + int lvl = player.GetSpellLevel(sn); PrintSBookStr(out, line0, fmt::format(fmt::runtime(pgettext(/* TRANSLATORS: UI constraints, keep short please.*/ "spellbook", "Level {:d}")), lvl), UiFlags::AlignRight); if (lvl == 0) { PrintSBookStr(out, line1, _("Unusable"), UiFlags::AlignRight); diff --git a/Source/panels/spell_list.cpp b/Source/panels/spell_list.cpp index 850c2a853..b4f36c720 100644 --- a/Source/panels/spell_list.cpp +++ b/Source/panels/spell_list.cpp @@ -104,7 +104,7 @@ void DrawSpell(const Surface &out) // BUGFIX: Move the next line into the if statement to avoid OOB (SPL_INVALID is -1) (fixed) if (st == RSPLTYPE_SPELL && spl != SPL_INVALID) { - int tlvl = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spl]; + int tlvl = myPlayer.GetSpellLevel(spl); if (CheckSpell(MyPlayerId, spl, st, true) != SpellCheckResult::Success) st = RSPLTYPE_INVALID; if (tlvl <= 0) @@ -138,7 +138,7 @@ void DrawSpellList(const Surface &out) transType = RSPLTYPE_INVALID; } if (spellListItem.type == RSPLTYPE_SPELL) { - spellLevel = std::max(myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spellListItem.id], 0); + spellLevel = myPlayer.GetSpellLevel(spellListItem.id); if (spellLevel == 0) transType = RSPLTYPE_INVALID; } diff --git a/Source/player.cpp b/Source/player.cpp index 1c04e0601..ea05f500a 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -532,7 +532,7 @@ void StartSpell(int pnum, Direction d, WorldTileCoord cx, WorldTileCoord cy) SetPlayerOld(player); player.position.temp = WorldTilePosition { cx, cy }; - player.spellLevel = GetSpellLevel(player, player._pSpell); + player.spellLevel = player.GetSpellLevel(player._pSpell); } void RespawnDeadItem(Item &&itm, Point target) @@ -3544,7 +3544,7 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType) return; } - int sl = GetSpellLevel(myPlayer, spellID); + int sl = myPlayer.GetSpellLevel(spellID); if (IsWallSpell(spellID)) { LastMouseButtonAction = MouseActionType::Spell; Direction sd = GetDirection(myPlayer.position.tile, cursPosition); diff --git a/Source/player.h b/Source/player.h index 20ce8a7b0..3315a71cf 100644 --- a/Source/player.h +++ b/Source/player.h @@ -5,9 +5,11 @@ */ #pragma once -#include #include +#include +#include + #include "diablo.h" #include "engine.h" #include "engine/actor_position.hpp" diff --git a/Source/spells.cpp b/Source/spells.cpp index ac4ee7f72..6805e0f80 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -130,7 +130,7 @@ int GetManaAmount(const Player &player, spell_id sn) int adj = 0; // spell level - int sl = std::max(player._pSplLvl[sn] + player._pISplLvlAdd - 1, 0); + int sl = std::max(player.GetSpellLevel(sn) - 1, 0); if (sl > 0) { adj = sl * spelldata[sn].sManaAdj; @@ -217,7 +217,7 @@ SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly) } const Player &player = Players[id]; - if (GetSpellLevel(player, sn) <= 0) { + if (player.GetSpellLevel(sn) <= 0) { return SpellCheckResult::Fail_Level0; }