Skip to content

Commit

Permalink
Rename Player struct variables: _pMemSpells
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Jul 27, 2024
1 parent 5ae0e5e commit c0e174a
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Source/controls/modifier_hints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void DrawSpellsCircleMenuHint(const Surface &out, const Point &origin)
hintBoxPositions[2] + spellIconDisplacement,
hintBoxPositions[3] + spellIconDisplacement,
};
uint64_t spells = myPlayer._pAblSpells | myPlayer._pMemSpells | myPlayer._pScrlSpells | myPlayer._pISpells;
uint64_t spells = myPlayer._pAblSpells | myPlayer.learnedSpells | myPlayer._pScrlSpells | myPlayer._pISpells;
SpellID splId;
SpellType splType;

Expand Down
4 changes: 2 additions & 2 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3066,12 +3066,12 @@ void CreatePlrItems(Player &player)
const PlayerStartingLoadoutData &loadout = GetPlayerStartingLoadoutForClass(player._pClass);

if (loadout.spell != SpellID::Null && loadout.spellLevel > 0) {
player._pMemSpells = GetSpellBitmask(loadout.spell);
player.learnedSpells = GetSpellBitmask(loadout.spell);
player._pRSplType = SpellType::Spell;
player._pRSpell = loadout.spell;
player._pSplLvl[static_cast<unsigned>(loadout.spell)] = loadout.spellLevel;
} else {
player._pMemSpells = 0;
player.learnedSpells = 0;
}

if (loadout.skill != SpellID::Null) {
Expand Down
4 changes: 2 additions & 2 deletions Source/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void LoadPlayer(LoadHelper &file, Player &player)
}

file.Skip(7); // Alignment
player._pMemSpells = file.NextLE<uint64_t>();
player.learnedSpells = file.NextLE<uint64_t>();
player._pAblSpells = file.NextLE<uint64_t>();
player._pScrlSpells = file.NextLE<uint64_t>();
player._pSpellFlags = static_cast<SpellFlag>(file.NextLE<uint8_t>());
Expand Down Expand Up @@ -1232,7 +1232,7 @@ void SavePlayer(SaveHelper &file, const Player &player)
file.WriteLE<uint8_t>(spellLevel);

file.Skip(7); // Alignment
file.WriteLE<uint64_t>(player._pMemSpells);
file.WriteLE<uint64_t>(player.learnedSpells);
file.WriteLE<uint64_t>(player._pAblSpells);
file.WriteLE<uint64_t>(player._pScrlSpells);
file.WriteLE<uint8_t>(static_cast<uint8_t>(player._pSpellFlags));
Expand Down
2 changes: 1 addition & 1 deletion Source/lua/modules/dev/player/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::string DebugCmdSetSpellsLevel(uint8_t level)
}
}
if (level == 0)
MyPlayer->_pMemSpells = 0;
MyPlayer->learnedSpells = 0;

return StrCat("Set all spell levels to ", level);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ size_t OnChangeSpellLevel(const TCmd *pCmd, Player &player) // NOLINT(misc-unuse
if (gbBufferMsgs == 1) {
SendPacket(player, pCmd, sizeof(*pCmd));
} else {
player._pMemSpells |= GetSpellBitmask(spellID);
player.learnedSpells |= GetSpellBitmask(spellID);
player._pSplLvl[static_cast<size_t>(spellID)] = spellLevel;
}

Expand Down
8 changes: 4 additions & 4 deletions Source/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@ void OperateShrineEnchanted(DiabloGenerator &rng, Player &player)
int cnt = 0;
uint64_t spell = 1;
uint8_t maxSpells = gbIsHellfire ? MAX_SPELLS : 37;
uint64_t spells = player._pMemSpells;
uint64_t spells = player.learnedSpells;
for (uint16_t j = 0; j < maxSpells; j++) {
if ((spell & spells) != 0)
cnt++;
Expand All @@ -2444,11 +2444,11 @@ void OperateShrineEnchanted(DiabloGenerator &rng, Player &player)
int spellToReduce;
do {
spellToReduce = rng.generateRnd(maxSpells) + 1;
} while ((player._pMemSpells & GetSpellBitmask(static_cast<SpellID>(spellToReduce))) == 0);
} while ((player.learnedSpells & GetSpellBitmask(static_cast<SpellID>(spellToReduce))) == 0);

spell = 1;
for (uint8_t j = static_cast<uint8_t>(SpellID::Firebolt); j < maxSpells; j++) {
if ((player._pMemSpells & spell) != 0 && player._pSplLvl[j] < MaxSpellLevel && j != spellToReduce) {
if ((player.learnedSpells & spell) != 0 && player._pSplLvl[j] < MaxSpellLevel && j != spellToReduce) {
uint8_t newSpellLevel = static_cast<uint8_t>(player._pSplLvl[j] + 1);
player._pSplLvl[j] = newSpellLevel;
NetSendCmdParam2(true, CMD_CHANGE_SPELL_LEVEL, j, newSpellLevel);
Expand Down Expand Up @@ -2497,7 +2497,7 @@ void OperateShrineCostOfWisdom(Player &player, SpellID spellId, diablo_message m
if (&player != MyPlayer)
return;

player._pMemSpells |= GetSpellBitmask(spellId);
player.learnedSpells |= GetSpellBitmask(spellId);

uint8_t curSpellLevel = player._pSplLvl[static_cast<int8_t>(spellId)];
if (curSpellLevel < MaxSpellLevel) {
Expand Down
8 changes: 4 additions & 4 deletions Source/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void PackPlayer(PlayerPack &packed, const Player &player)
packed.pMaxHPBase = SDL_SwapLE32(player._pMaxHPBase);
packed.pManaBase = SDL_SwapLE32(player._pManaBase);
packed.pMaxManaBase = SDL_SwapLE32(player._pMaxManaBase);
packed.pMemSpells = SDL_SwapLE64(player._pMemSpells);
packed.pMemSpells = SDL_SwapLE64(player.learnedSpells);

for (int i = 0; i < 37; i++) // Should be MAX_SPELLS but set to 37 to make save games compatible
packed.pSplLvl[i] = player._pSplLvl[i];
Expand Down Expand Up @@ -332,7 +332,7 @@ void PackNetPlayer(PlayerNetPack &packed, const Player &player)
packed.pMaxHPBase = SDL_SwapLE32(player._pMaxHPBase);
packed.pManaBase = SDL_SwapLE32(player._pManaBase);
packed.pMaxManaBase = SDL_SwapLE32(player._pMaxManaBase);
packed.pMemSpells = SDL_SwapLE64(player._pMemSpells);
packed.pMemSpells = SDL_SwapLE64(player.learnedSpells);

for (int i = 0; i < MAX_SPELLS; i++)
packed.pSplLvl[i] = player._pSplLvl[i];
Expand Down Expand Up @@ -483,7 +483,7 @@ void UnPackPlayer(const PlayerPack &packed, Player &player)
player._pMaxManaBase = SDL_SwapLE32(packed.pMaxManaBase);
player._pManaBase = SDL_SwapLE32(packed.pManaBase);
player._pManaBase = std::min<int32_t>(player._pManaBase, player._pMaxManaBase);
player._pMemSpells = SDL_SwapLE64(packed.pMemSpells);
player.learnedSpells = SDL_SwapLE64(packed.pMemSpells);

// Only read spell levels for learnable spells (Diablo)
for (int i = 0; i < 37; i++) { // Should be MAX_SPELLS but set to 36 to make save games compatible
Expand Down Expand Up @@ -613,7 +613,7 @@ bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player)
player._pExperience = SDL_SwapLE32(packed.pExperience);
player._pMaxManaBase = baseManaMax;
player._pManaBase = baseMana;
player._pMemSpells = SDL_SwapLE64(packed.pMemSpells);
player.learnedSpells = SDL_SwapLE64(packed.pMemSpells);
player.wReflections = SDL_SwapLE16(packed.wReflections);
player.pDiabloKillLevel = packed.pDiabloKillLevel;
player.pManaShield = packed.pManaShield != 0;
Expand Down
4 changes: 2 additions & 2 deletions Source/panels/spell_book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void DrawSpellBook(const Surface &out)

ClxDraw(out, GetPanelPosition(UiPanels::Spell, { SpellBookButtonX + buttonX, SpellBookButtonY }), (*spellBookButtons)[sbooktab]);
Player &player = *InspectPlayer;
uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells;
uint64_t spl = player.learnedSpells | player._pISpells | player._pAblSpells;

const int lineHeight = 18;

Expand Down Expand Up @@ -211,7 +211,7 @@ void CheckSBook()
if (iconArea.contains(MousePosition) && !IsInspectingPlayer()) {
SpellID sn = GetSpellFromSpellPage(sbooktab, (MousePosition.y - iconArea.position.y) / SpellBookDescription.height);
Player &player = *InspectPlayer;
uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells;
uint64_t spl = player.learnedSpells | player._pISpells | player._pAblSpells;
if (IsValidSpell(sn) && (spl & GetSpellBitmask(sn)) != 0) {
SpellType st = SpellType::Spell;
if ((player._pISpells & GetSpellBitmask(sn)) != 0) {
Expand Down
6 changes: 3 additions & 3 deletions Source/panels/spell_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ std::vector<SpellListItem> GetSpellListItems()
mask = myPlayer._pAblSpells;
break;
case SpellType::Spell:
mask = myPlayer._pMemSpells;
mask = myPlayer.learnedSpells;
break;
case SpellType::Scroll:
mask = myPlayer._pScrlSpells;
Expand Down Expand Up @@ -305,7 +305,7 @@ bool IsValidSpeedSpell(size_t slot)
spells = myPlayer._pAblSpells;
break;
case SpellType::Spell:
spells = myPlayer._pMemSpells;
spells = myPlayer.learnedSpells;
break;
case SpellType::Scroll:
spells = myPlayer._pScrlSpells;
Expand Down Expand Up @@ -349,7 +349,7 @@ void DoSpeedBook()
spells = myPlayer._pAblSpells;
break;
case SpellType::Spell:
spells = myPlayer._pMemSpells;
spells = myPlayer.learnedSpells;
break;
case SpellType::Scroll:
spells = myPlayer._pScrlSpells;
Expand Down
2 changes: 1 addition & 1 deletion Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ void ValidatePlayer()
}
}

myPlayer._pMemSpells &= msk;
myPlayer.learnedSpells &= msk;
myPlayer._pInfraFlag = false;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ struct Player {
uint8_t _pSplLvl[64];
/** @brief Bitmask of staff spell */
uint64_t _pISpells;
/** @brief Bitmask of learned spells */
uint64_t _pMemSpells;
/** @brief Bitmask of learned spells (_pMemSpells) */
uint64_t learnedSpells;
/** @brief Bitmask of abilities */
uint64_t _pAblSpells;
/** @brief Bitmask of spells available via scrolls */
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/memory_map/player.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ R 32 _pSBkSpell
R 8 _pSBkSplType
M 64 8 spellLevel
R 56 alignment
R 64 _pMemSpells
R 64 learnedSpells
R 64 _pAblSpells
R 64 _pScrlSpells
R 8 _pSpellFlags
Expand Down
2 changes: 1 addition & 1 deletion test/player_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void AssertPlayer(Player &player)
ASSERT_EQ(player.getBaseToBlock(), 20);
ASSERT_EQ(player._pMaxManaBase, 1440);
ASSERT_EQ(player._pManaBase, 1440);
ASSERT_EQ(player._pMemSpells, 0);
ASSERT_EQ(player.learnedSpells, 0);
ASSERT_EQ(player._pNumInv, 1);
ASSERT_EQ(player.wReflections, 0);
ASSERT_EQ(player.pTownWarps, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/writehero_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void AssertPlayer(Player &player)
ASSERT_EQ(player.getBaseToBlock(), 20);
ASSERT_EQ(player._pMaxManaBase, 11104);
ASSERT_EQ(player._pManaBase, 11104);
ASSERT_EQ(player._pMemSpells, 66309357295);
ASSERT_EQ(player.learnedSpells, 66309357295);
ASSERT_EQ(player._pNumInv, 2);
ASSERT_EQ(player.wReflections, 0);
ASSERT_EQ(player.pTownWarps, 0);
Expand Down

0 comments on commit c0e174a

Please sign in to comment.