Browse Source

Clean up `GetSpellLevel`

Remove the buggy `GetSpellLevel` implementation and use
`Player#GetSpellLevel` throughout instead.
pull/4872/head
Gleb Mazovetskiy 4 years ago
parent
commit
17f8cdddc4
  1. 4
      Source/control.cpp
  2. 6
      Source/diablo.cpp
  3. 18
      Source/missiles.cpp
  4. 3
      Source/missiles.h
  5. 4
      Source/panels/spell_book.cpp
  6. 4
      Source/panels/spell_list.cpp
  7. 4
      Source/player.cpp
  8. 4
      Source/player.h
  9. 4
      Source/spells.cpp

4
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)));

6
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;
}

18
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 &parameter)
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;

3
Source/missiles.h

@ -138,8 +138,7 @@ struct Missile {
extern std::list<Missile> 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.

4
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);

4
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;
}

4
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);

4
Source/player.h

@ -5,9 +5,11 @@
*/
#pragma once
#include <array>
#include <cstdint>
#include <algorithm>
#include <array>
#include "diablo.h"
#include "engine.h"
#include "engine/actor_position.hpp"

4
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;
}

Loading…
Cancel
Save