diff --git a/Source/automap.cpp b/Source/automap.cpp index 6675eac31..219a96934 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -209,10 +209,11 @@ void DrawAutomapTile(const CelOutputBuffer &out, Point center, uint16_t automapT void SearchAutomapItem(const CelOutputBuffer &out) { - Point tile = plr[myplr].position.tile; - if (plr[myplr]._pmode == PM_WALK3) { - tile = plr[myplr].position.future; - if (plr[myplr]._pdir == DIR_W) + auto &myPlayer = plr[myplr]; + Point tile = myPlayer.position.tile; + if (myPlayer._pmode == PM_WALK3) { + tile = myPlayer.position.future; + if (myPlayer._pdir == DIR_W) tile.x++; else tile.y++; @@ -256,10 +257,11 @@ void DrawAutomapPlr(const CelOutputBuffer &out, int playerId) { int playerColor = MapColorsPlayer + (8 * playerId) % 128; - Point tile = plr[playerId].position.tile; - if (plr[playerId]._pmode == PM_WALK3) { - tile = plr[playerId].position.future; - if (plr[playerId]._pdir == DIR_W) + auto &player = plr[playerId]; + Point tile = player.position.tile; + if (player._pmode == PM_WALK3) { + tile = player.position.future; + if (player._pdir == DIR_W) tile.x++; else tile.y++; @@ -269,8 +271,8 @@ void DrawAutomapPlr(const CelOutputBuffer &out, int playerId) int py = tile.y - 2 * AutomapOffset.y - ViewY; Point base = { - (plr[playerId].position.offset.x * AutoMapScale / 100 / 2) + (ScrollInfo.offset.x * AutoMapScale / 100 / 2) + (px - py) * AmLine16 + gnScreenWidth / 2, - (plr[playerId].position.offset.y * AutoMapScale / 100 / 2) + (ScrollInfo.offset.y * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - PANEL_HEIGHT) / 2 + (player.position.offset.x * AutoMapScale / 100 / 2) + (ScrollInfo.offset.x * AutoMapScale / 100 / 2) + (px - py) * AmLine16 + gnScreenWidth / 2, + (player.position.offset.y * AutoMapScale / 100 / 2) + (ScrollInfo.offset.y * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - PANEL_HEIGHT) / 2 }; if (CanPanelsCoverView()) { @@ -281,7 +283,7 @@ void DrawAutomapPlr(const CelOutputBuffer &out, int playerId) } base.y -= AmLine8; - switch (plr[playerId]._pdir) { + switch (player._pdir) { case DIR_N: { const Point point { base.x, base.y - AmLine16 }; DrawVerticalLine(out, point, AmLine16, playerColor); @@ -615,7 +617,8 @@ void DrawAutomap(const CelOutputBuffer &out) } for (unsigned playerId = 0; playerId < MAX_PLRS; playerId++) { - if (plr[playerId].plrlevel == plr[myplr].plrlevel && plr[playerId].plractive && !plr[playerId]._pLvlChanging) { + auto &player = plr[playerId]; + if (player.plrlevel == plr[myplr].plrlevel && player.plractive && !player._pLvlChanging) { DrawAutomapPlr(out, playerId); } } diff --git a/Source/control.cpp b/Source/control.cpp index 5708ff5b6..eac996159 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -298,12 +298,13 @@ void SetSpellTrans(spell_type t) */ static void DrawSpell(const CelOutputBuffer &out) { - spell_id spl = plr[myplr]._pRSpell; - spell_type st = plr[myplr]._pRSplType; + auto &myPlayer = plr[myplr]; + spell_id spl = myPlayer._pRSpell; + spell_type st = myPlayer._pRSplType; // 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 = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[spl]; + int tlvl = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spl]; if (!CheckSpell(myplr, spl, st, true)) st = RSPLTYPE_INVALID; if (tlvl <= 0) @@ -311,8 +312,6 @@ static void DrawSpell(const CelOutputBuffer &out) } if (currlevel == 0 && st != RSPLTYPE_INVALID && !spelldata[spl].sTownSpell) st = RSPLTYPE_INVALID; - if (plr[myplr]._pRSpell < 0) - st = RSPLTYPE_INVALID; SetSpellTrans(st); if (spl != SPL_INVALID) DrawSpellCel(out, PANEL_X + 565, PANEL_Y + 119, *pSpellCels, SpellITbl[spl]); @@ -320,7 +319,7 @@ static void DrawSpell(const CelOutputBuffer &out) DrawSpellCel(out, PANEL_X + 565, PANEL_Y + 119, *pSpellCels, 27); } -static void PrintSBookHotkey(const CelOutputBuffer& out, int x, int y, const std::string &text) +static void PrintSBookHotkey(const CelOutputBuffer &out, int x, int y, const std::string &text) { x -= GetLineWidth(text.c_str()) + 5; x += SPLICONLENGTH; @@ -344,24 +343,25 @@ void DrawSpellList(const CelOutputBuffer &out) ClearPanel(); for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) { + auto &myPlayer = plr[myplr]; switch ((spell_type)i) { case RSPLTYPE_SKILL: SetSpellTrans(RSPLTYPE_SKILL); - mask = plr[myplr]._pAblSpells; + mask = myPlayer._pAblSpells; c = SPLICONLAST + 3; break; case RSPLTYPE_SPELL: - mask = plr[myplr]._pMemSpells; + mask = myPlayer._pMemSpells; c = SPLICONLAST + 4; break; case RSPLTYPE_SCROLL: SetSpellTrans(RSPLTYPE_SCROLL); - mask = plr[myplr]._pScrlSpells; + mask = myPlayer._pScrlSpells; c = SPLICONLAST + 1; break; case RSPLTYPE_CHARGES: SetSpellTrans(RSPLTYPE_CHARGES); - mask = plr[myplr]._pISpells; + mask = myPlayer._pISpells; c = SPLICONLAST + 2; break; case RSPLTYPE_INVALID: @@ -372,7 +372,7 @@ void DrawSpellList(const CelOutputBuffer &out) if ((mask & spl) == 0) continue; if (i == RSPLTYPE_SPELL) { - s = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[j]; + s = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[j]; if (s < 0) s = 0; spell_type trans = RSPLTYPE_INVALID; @@ -388,7 +388,7 @@ void DrawSpellList(const CelOutputBuffer &out) if (MouseX >= lx && MouseX < lx + SPLICONLENGTH && MouseY >= ly && MouseY < ly + SPLICONLENGTH) { pSpell = (spell_id)j; pSplType = (spell_type)i; - if (plr[myplr]._pClass == HeroClass::Monk && j == SPL_SEARCH) + if (myPlayer._pClass == HeroClass::Monk && j == SPL_SEARCH) pSplType = RSPLTYPE_SKILL; DrawSpellCel(out, x, y, *pSpellCels, c); switch (pSplType) { @@ -410,14 +410,14 @@ void DrawSpellList(const CelOutputBuffer &out) case RSPLTYPE_SCROLL: { strcpy(infostr, fmt::format(_("Scroll of {:s}"), _(spelldata[pSpell].sNameText)).c_str()); int v = 0; - for (int t = 0; t < plr[myplr]._pNumInv; t++) { - if (!plr[myplr].InvList[t].isEmpty() - && (plr[myplr].InvList[t]._iMiscId == IMISC_SCROLL || plr[myplr].InvList[t]._iMiscId == IMISC_SCROLLT) - && plr[myplr].InvList[t]._iSpell == pSpell) { + for (int t = 0; t < myPlayer._pNumInv; t++) { + if (!myPlayer.InvList[t].isEmpty() + && (myPlayer.InvList[t]._iMiscId == IMISC_SCROLL || myPlayer.InvList[t]._iMiscId == IMISC_SCROLLT) + && myPlayer.InvList[t]._iSpell == pSpell) { v++; } } - for (auto &item : plr[myplr].SpdList) { + for (auto &item : myPlayer.SpdList) { if (!item.isEmpty() && (item._iMiscId == IMISC_SCROLL || item._iMiscId == IMISC_SCROLLT) && item._iSpell == pSpell) { @@ -429,7 +429,7 @@ void DrawSpellList(const CelOutputBuffer &out) } break; case RSPLTYPE_CHARGES: { strcpy(infostr, fmt::format(_("Staff of {:s}"), _(spelldata[pSpell].sNameText)).c_str()); - int charges = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges; + int charges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges; strcpy(tempstr, fmt::format(ngettext("{:d} Charge", "{:d} Charges", charges), charges).c_str()); AddPanelString(tempstr); } break; @@ -437,7 +437,7 @@ void DrawSpellList(const CelOutputBuffer &out) break; } for (int t = 0; t < 4; t++) { - if (plr[myplr]._pSplHotKey[t] == pSpell && plr[myplr]._pSplTHotKey[t] == pSplType) { + if (myPlayer._pSplHotKey[t] == pSpell && myPlayer._pSplTHotKey[t] == pSplType) { auto hotkeyName = keymapper.keyNameForAction(quickSpellActionIndexes[t]); PrintSBookHotkey(out, x, y, hotkeyName); strcpy(tempstr, fmt::format(_("Spell Hotkey {:s}"), hotkeyName.c_str()).c_str()); @@ -463,54 +463,63 @@ void DrawSpellList(const CelOutputBuffer &out) void SetSpell() { spselflag = false; - if (pSpell != SPL_INVALID) { - ClearPanel(); - plr[myplr]._pRSpell = pSpell; - plr[myplr]._pRSplType = pSplType; - force_redraw = 255; + if (pSpell == SPL_INVALID) { + return; } + + ClearPanel(); + + auto &myPlayer = plr[myplr]; + myPlayer._pRSpell = pSpell; + myPlayer._pRSplType = pSplType; + + force_redraw = 255; } void SetSpeedSpell(int slot) { - if (pSpell != SPL_INVALID) { - for (int i = 0; i < 4; ++i) { - if (plr[myplr]._pSplHotKey[i] == pSpell && plr[myplr]._pSplTHotKey[i] == pSplType) - plr[myplr]._pSplHotKey[i] = SPL_INVALID; - } - plr[myplr]._pSplHotKey[slot] = pSpell; - plr[myplr]._pSplTHotKey[slot] = pSplType; + if (pSpell == SPL_INVALID) { + return; + } + auto &myPlayer = plr[myplr]; + for (int i = 0; i < 4; ++i) { + if (myPlayer._pSplHotKey[i] == pSpell && myPlayer._pSplTHotKey[i] == pSplType) + myPlayer._pSplHotKey[i] = SPL_INVALID; } + myPlayer._pSplHotKey[slot] = pSpell; + myPlayer._pSplTHotKey[slot] = pSplType; } void ToggleSpell(int slot) { uint64_t spells; - if (plr[myplr]._pSplHotKey[slot] == SPL_INVALID) { + auto &myPlayer = plr[myplr]; + + if (myPlayer._pSplHotKey[slot] == SPL_INVALID) { return; } - switch (plr[myplr]._pSplTHotKey[slot]) { + switch (myPlayer._pSplTHotKey[slot]) { case RSPLTYPE_SKILL: - spells = plr[myplr]._pAblSpells; + spells = myPlayer._pAblSpells; break; case RSPLTYPE_SPELL: - spells = plr[myplr]._pMemSpells; + spells = myPlayer._pMemSpells; break; case RSPLTYPE_SCROLL: - spells = plr[myplr]._pScrlSpells; + spells = myPlayer._pScrlSpells; break; case RSPLTYPE_CHARGES: - spells = plr[myplr]._pISpells; + spells = myPlayer._pISpells; break; case RSPLTYPE_INVALID: return; } - if ((spells & GetSpellBitmask(plr[myplr]._pSplHotKey[slot])) != 0) { - plr[myplr]._pRSpell = plr[myplr]._pSplHotKey[slot]; - plr[myplr]._pRSplType = plr[myplr]._pSplTHotKey[slot]; + if ((spells & GetSpellBitmask(myPlayer._pSplHotKey[slot])) != 0) { + myPlayer._pRSpell = myPlayer._pSplHotKey[slot]; + myPlayer._pRSplType = myPlayer._pSplTHotKey[slot]; force_redraw = 255; } } @@ -550,7 +559,7 @@ void DrawPanelBox(const CelOutputBuffer &out, int x, int y, int w, int h, int sx * @param y0 Top of the flask cel section to draw. * @param y1 Bottom of the flask cel section to draw. */ -static void DrawFlaskTop(const CelOutputBuffer &out, int sx, int sy, const CelOutputBuffer& celBuf, int y0, int y1) +static void DrawFlaskTop(const CelOutputBuffer &out, int sx, int sy, const CelOutputBuffer &celBuf, int y0, int y1) { const BYTE *src = celBuf.at(0, y0); BYTE *dst = out.at(sx, sy); @@ -588,12 +597,14 @@ static void DrawFlask(const CelOutputBuffer &out, const CelOutputBuffer &celBuf, void DrawLifeFlask(const CelOutputBuffer &out) { + auto &myPlayer = plr[myplr]; + double p = 0.0; - if (plr[myplr]._pMaxHP > 0) { - p = (double)plr[myplr]._pHitPoints / (double)plr[myplr]._pMaxHP * 80.0; + if (myPlayer._pMaxHP > 0) { + p = (double)myPlayer._pHitPoints / (double)myPlayer._pMaxHP * 80.0; } - plr[myplr]._pHPPer = p; - int filled = plr[myplr]._pHPPer; + myPlayer._pHPPer = p; + int filled = myPlayer._pHPPer; if (filled > 80) filled = 80; @@ -610,12 +621,14 @@ void DrawLifeFlask(const CelOutputBuffer &out) void UpdateLifeFlask(const CelOutputBuffer &out) { + auto &myPlayer = plr[myplr]; + double p = 0.0; - if (plr[myplr]._pMaxHP > 0) { - p = (double)plr[myplr]._pHitPoints / (double)plr[myplr]._pMaxHP * 80.0; + if (myPlayer._pMaxHP > 0) { + p = (double)myPlayer._pHitPoints / (double)myPlayer._pMaxHP * 80.0; } int filled = p; - plr[myplr]._pHPPer = filled; + myPlayer._pHPPer = filled; if (filled > 69) filled = 69; @@ -644,19 +657,23 @@ void DrawManaFlask(const CelOutputBuffer &out) void control_update_life_mana() { - int maxMana = std::max(plr[myplr]._pMaxMana, 0); - int mana = std::max(plr[myplr]._pMana, 0); - plr[myplr]._pManaPer = maxMana != 0 ? ((double)mana / (double)maxMana * 80.0) : 0; - plr[myplr]._pHPPer = (double)plr[myplr]._pHitPoints / (double)plr[myplr]._pMaxHP * 80.0; + auto &myPlayer = plr[myplr]; + + int maxMana = std::max(myPlayer._pMaxMana, 0); + int mana = std::max(myPlayer._pMana, 0); + myPlayer._pManaPer = maxMana != 0 ? ((double)mana / (double)maxMana * 80.0) : 0; + myPlayer._pHPPer = (double)myPlayer._pHitPoints / (double)myPlayer._pMaxHP * 80.0; } void UpdateManaFlask(const CelOutputBuffer &out) { - int maxMana = std::max(plr[myplr]._pMaxMana, 0); - int mana = std::max(plr[myplr]._pMana, 0); + auto &myPlayer = plr[myplr]; + + int maxMana = std::max(myPlayer._pMaxMana, 0); + int mana = std::max(myPlayer._pMana, 0); int filled = maxMana != 0 ? ((double)mana / (double)maxMana * 80.0) : 0; - plr[myplr]._pManaPer = filled; + myPlayer._pManaPer = filled; filled = std::min(filled, 69); if (filled != 69) @@ -729,17 +746,20 @@ void InitControlPan() pSBkIconCels = LoadCel("Data\\SpellI2.CEL", 37); sbooktab = 0; sbookflag = false; - if (plr[myplr]._pClass == HeroClass::Warrior) { + + auto &myPlayer = plr[myplr]; + + if (myPlayer._pClass == HeroClass::Warrior) { SpellPages[0][0] = SPL_REPAIR; - } else if (plr[myplr]._pClass == HeroClass::Rogue) { + } else if (myPlayer._pClass == HeroClass::Rogue) { SpellPages[0][0] = SPL_DISARM; - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { + } else if (myPlayer._pClass == HeroClass::Sorcerer) { SpellPages[0][0] = SPL_RECHARGE; - } else if (plr[myplr]._pClass == HeroClass::Monk) { + } else if (myPlayer._pClass == HeroClass::Monk) { SpellPages[0][0] = SPL_SEARCH; - } else if (plr[myplr]._pClass == HeroClass::Bard) { + } else if (myPlayer._pClass == HeroClass::Bard) { SpellPages[0][0] = SPL_IDENTIFY; - } else if (plr[myplr]._pClass == HeroClass::Barbarian) { + } else if (myPlayer._pClass == HeroClass::Barbarian) { SpellPages[0][0] = SPL_BLODBOIL; } pQLogCel = LoadCel("Data\\Quest.CEL", SPANEL_WIDTH); @@ -785,27 +805,29 @@ void DoSpeedBook() int x = xo + SPLICONLENGTH / 2; int y = yo - SPLICONLENGTH / 2; - if (plr[myplr]._pRSpell != SPL_INVALID) { + auto &myPlayer = plr[myplr]; + + if (myPlayer._pRSpell != SPL_INVALID) { for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) { uint64_t spells; switch (i) { case RSPLTYPE_SKILL: - spells = plr[myplr]._pAblSpells; + spells = myPlayer._pAblSpells; break; case RSPLTYPE_SPELL: - spells = plr[myplr]._pMemSpells; + spells = myPlayer._pMemSpells; break; case RSPLTYPE_SCROLL: - spells = plr[myplr]._pScrlSpells; + spells = myPlayer._pScrlSpells; break; case RSPLTYPE_CHARGES: - spells = plr[myplr]._pISpells; + spells = myPlayer._pISpells; break; } uint64_t spell = 1; for (int j = 1; j < MAX_SPELLS; j++) { if ((spell & spells) != 0) { - if (j == plr[myplr]._pRSpell && i == plr[myplr]._pRSplType) { + if (j == myPlayer._pRSpell && i == myPlayer._pRSplType) { x = xo + SPLICONLENGTH / 2; y = yo - SPLICONLENGTH / 2; } @@ -847,8 +869,9 @@ void DoPanBtn() } if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) { if ((SDL_GetModState() & KMOD_SHIFT) != 0) { - plr[myplr]._pRSpell = SPL_INVALID; - plr[myplr]._pRSplType = RSPLTYPE_INVALID; + auto &myPlayer = plr[myplr]; + myPlayer._pRSpell = SPL_INVALID; + myPlayer._pRSplType = RSPLTYPE_INVALID; force_redraw = 255; return; } @@ -932,9 +955,10 @@ void CheckPanelInfo() pinfoflag = true; strcpy(tempstr, _("Hotkey: 's'")); AddPanelString(tempstr); - spell_id v = plr[myplr]._pRSpell; + auto &myPlayer = plr[myplr]; + spell_id v = myPlayer._pRSpell; if (v != SPL_INVALID) { - switch (plr[myplr]._pRSplType) { + switch (myPlayer._pRSplType) { case RSPLTYPE_SKILL: strcpy(tempstr, fmt::format(_("{:s} Skill"), _(spelldata[v].sSkillText)).c_str()); AddPanelString(tempstr); @@ -942,7 +966,7 @@ void CheckPanelInfo() case RSPLTYPE_SPELL: { strcpy(tempstr, fmt::format(_("{:s} Spell"), _(spelldata[v].sNameText)).c_str()); AddPanelString(tempstr); - int c = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[v]; + int c = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[v]; if (c < 0) c = 0; if (c == 0) @@ -955,14 +979,14 @@ void CheckPanelInfo() strcpy(tempstr, fmt::format(_("Scroll of {:s}"), _(spelldata[v].sNameText)).c_str()); AddPanelString(tempstr); int s = 0; - for (int i = 0; i < plr[myplr]._pNumInv; i++) { - if (!plr[myplr].InvList[i].isEmpty() - && (plr[myplr].InvList[i]._iMiscId == IMISC_SCROLL || plr[myplr].InvList[i]._iMiscId == IMISC_SCROLLT) - && plr[myplr].InvList[i]._iSpell == v) { + for (int i = 0; i < myPlayer._pNumInv; i++) { + if (!myPlayer.InvList[i].isEmpty() + && (myPlayer.InvList[i]._iMiscId == IMISC_SCROLL || myPlayer.InvList[i]._iMiscId == IMISC_SCROLLT) + && myPlayer.InvList[i]._iSpell == v) { s++; } } - for (auto &item : plr[myplr].SpdList) { + for (auto &item : myPlayer.SpdList) { if (!item.isEmpty() && (item._iMiscId == IMISC_SCROLL || item._iMiscId == IMISC_SCROLLT) && item._iSpell == v) { @@ -975,7 +999,7 @@ void CheckPanelInfo() case RSPLTYPE_CHARGES: strcpy(tempstr, fmt::format(_("Staff of {:s}"), _(spelldata[v].sNameText)).c_str()); AddPanelString(tempstr); - strcpy(tempstr, fmt::format(ngettext("{:d} Charge", "{:d} Charges", plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges), plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges).c_str()); + strcpy(tempstr, fmt::format(ngettext("{:d} Charge", "{:d} Charges", myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges), myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges).c_str()); AddPanelString(tempstr); break; case RSPLTYPE_INVALID: @@ -1119,21 +1143,22 @@ void DrawInfoBox(const CelOutputBuffer &out) if (spselflag || trigflag) { infoclr = UIS_SILVER; } else if (pcurs >= CURSOR_FIRSTITEM) { - if (plr[myplr].HoldItem._itype == ITYPE_GOLD) { - int nGold = plr[myplr].HoldItem._ivalue; + auto &myPlayer = plr[myplr]; + if (myPlayer.HoldItem._itype == ITYPE_GOLD) { + int nGold = myPlayer.HoldItem._ivalue; strcpy(infostr, fmt::format(ngettext("{:d} gold piece", "{:d} gold pieces", nGold), nGold).c_str()); - } else if (!plr[myplr].HoldItem._iStatFlag) { + } else if (!myPlayer.HoldItem._iStatFlag) { ClearPanel(); AddPanelString(_("Requirements not met")); pinfoflag = true; } else { - if (plr[myplr].HoldItem._iIdentified) - strcpy(infostr, plr[myplr].HoldItem._iIName); + if (myPlayer.HoldItem._iIdentified) + strcpy(infostr, myPlayer.HoldItem._iIName); else - strcpy(infostr, plr[myplr].HoldItem._iName); - if (plr[myplr].HoldItem._iMagical == ITEM_QUALITY_MAGIC) + strcpy(infostr, myPlayer.HoldItem._iName); + if (myPlayer.HoldItem._iMagical == ITEM_QUALITY_MAGIC) infoclr = UIS_BLUE; - if (plr[myplr].HoldItem._iMagical == ITEM_QUALITY_UNIQUE) + if (myPlayer.HoldItem._iMagical == ITEM_QUALITY_UNIQUE) infoclr = UIS_GOLD; } } else { @@ -1160,11 +1185,12 @@ void DrawInfoBox(const CelOutputBuffer &out) } if (pcursplr != -1) { infoclr = UIS_GOLD; - strcpy(infostr, plr[pcursplr]._pName); + auto &target = plr[pcursplr]; + strcpy(infostr, target._pName); ClearPanel(); - strcpy(tempstr, fmt::format(_("{:s}, Level: {:d}"), _(ClassStrTbl[static_cast(plr[pcursplr]._pClass)]), plr[pcursplr]._pLevel).c_str()); + strcpy(tempstr, fmt::format(_("{:s}, Level: {:d}"), _(ClassStrTbl[static_cast(target._pClass)]), target._pLevel).c_str()); AddPanelString(tempstr); - strcpy(tempstr, fmt::format(_("Hit Points {:d} of {:d}"), plr[pcursplr]._pHitPoints >> 6, plr[pcursplr]._pMaxHP >> 6).c_str()); + strcpy(tempstr, fmt::format(_("Hit Points {:d} of {:d}"), target._pHitPoints >> 6, target._pMaxHP >> 6).c_str()); AddPanelString(tempstr); } } @@ -1177,71 +1203,73 @@ void DrawChr(const CelOutputBuffer &out) uint32_t style = UIS_SILVER; char chrstr[64]; + auto &myPlayer = plr[myplr]; + CelDrawTo(out, 0, 351, *pChrPanel, 1); - DrawString(out, plr[myplr]._pName, { 20, 32, 131, 0 }, UIS_SILVER | UIS_CENTER); + DrawString(out, myPlayer._pName, { 20, 32, 131, 0 }, UIS_SILVER | UIS_CENTER); - DrawString(out, _(ClassStrTbl[static_cast(plr[myplr]._pClass)]), { 168, 32, 131, 0 }, UIS_SILVER | UIS_CENTER); + DrawString(out, _(ClassStrTbl[static_cast(myPlayer._pClass)]), { 168, 32, 131, 0 }, UIS_SILVER | UIS_CENTER); - sprintf(chrstr, "%i", plr[myplr]._pLevel); + sprintf(chrstr, "%i", myPlayer._pLevel); DrawString(out, chrstr, { 66, 69, 43, 0 }, UIS_SILVER | UIS_CENTER); - sprintf(chrstr, "%i", plr[myplr]._pExperience); + sprintf(chrstr, "%i", myPlayer._pExperience); DrawString(out, chrstr, { 216, 69, 84, 0 }, UIS_SILVER | UIS_CENTER); - if (plr[myplr]._pLevel == MAXCHARLEVEL - 1) { + if (myPlayer._pLevel == MAXCHARLEVEL - 1) { strcpy(chrstr, _("None")); style = UIS_GOLD; } else { - sprintf(chrstr, "%i", plr[myplr]._pNextExper); + sprintf(chrstr, "%i", myPlayer._pNextExper); style = UIS_SILVER; } DrawString(out, chrstr, { 216, 97, 84, 0 }, style | UIS_CENTER); - sprintf(chrstr, "%i", plr[myplr]._pGold); + sprintf(chrstr, "%i", myPlayer._pGold); DrawString(out, chrstr, { 216, 146, 84, 0 }, UIS_SILVER | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pIBonusAC > 0) + if (myPlayer._pIBonusAC > 0) style = UIS_BLUE; - if (plr[myplr]._pIBonusAC < 0) + if (myPlayer._pIBonusAC < 0) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pIBonusAC + plr[myplr]._pIAC + plr[myplr]._pDexterity / 5); + sprintf(chrstr, "%i", myPlayer._pIBonusAC + myPlayer._pIAC + myPlayer._pDexterity / 5); DrawString(out, chrstr, { 258, 183, 43, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pIBonusToHit > 0) + if (myPlayer._pIBonusToHit > 0) style = UIS_BLUE; - if (plr[myplr]._pIBonusToHit < 0) + if (myPlayer._pIBonusToHit < 0) style = UIS_RED; - sprintf(chrstr, "%i%%", (plr[myplr]._pDexterity / 2) + plr[myplr]._pIBonusToHit + 50); + sprintf(chrstr, "%i%%", (myPlayer._pDexterity / 2) + myPlayer._pIBonusToHit + 50); DrawString(out, chrstr, { 258, 211, 43, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pIBonusDam > 0) + if (myPlayer._pIBonusDam > 0) style = UIS_BLUE; - if (plr[myplr]._pIBonusDam < 0) + if (myPlayer._pIBonusDam < 0) style = UIS_RED; - int mindam = plr[myplr]._pIMinDam; - mindam += plr[myplr]._pIBonusDam * mindam / 100; - mindam += plr[myplr]._pIBonusDamMod; - if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_BOW) { - if (plr[myplr]._pClass == HeroClass::Rogue) - mindam += plr[myplr]._pDamageMod; + int mindam = myPlayer._pIMinDam; + mindam += myPlayer._pIBonusDam * mindam / 100; + mindam += myPlayer._pIBonusDamMod; + if (myPlayer.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_BOW) { + if (myPlayer._pClass == HeroClass::Rogue) + mindam += myPlayer._pDamageMod; else - mindam += plr[myplr]._pDamageMod / 2; + mindam += myPlayer._pDamageMod / 2; } else { - mindam += plr[myplr]._pDamageMod; - } - int maxdam = plr[myplr]._pIMaxDam; - maxdam += plr[myplr]._pIBonusDam * maxdam / 100; - maxdam += plr[myplr]._pIBonusDamMod; - if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_BOW) { - if (plr[myplr]._pClass == HeroClass::Rogue) - maxdam += plr[myplr]._pDamageMod; + mindam += myPlayer._pDamageMod; + } + int maxdam = myPlayer._pIMaxDam; + maxdam += myPlayer._pIBonusDam * maxdam / 100; + maxdam += myPlayer._pIBonusDamMod; + if (myPlayer.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_BOW) { + if (myPlayer._pClass == HeroClass::Rogue) + maxdam += myPlayer._pDamageMod; else - maxdam += plr[myplr]._pDamageMod / 2; + maxdam += myPlayer._pDamageMod / 2; } else { - maxdam += plr[myplr]._pDamageMod; + maxdam += myPlayer._pDamageMod; } sprintf(chrstr, "%i-%i", mindam, maxdam); if (mindam >= 100 || maxdam >= 100) @@ -1250,10 +1278,10 @@ void DrawChr(const CelOutputBuffer &out) DrawString(out, chrstr, { 258, 239, 43, 0 }, style | UIS_CENTER, 0); style = UIS_BLUE; - if (plr[myplr]._pMagResist == 0) + if (myPlayer._pMagResist == 0) style = UIS_SILVER; - if (plr[myplr]._pMagResist < MAXRESIST) { - sprintf(chrstr, "%i%%", plr[myplr]._pMagResist); + if (myPlayer._pMagResist < MAXRESIST) { + sprintf(chrstr, "%i%%", myPlayer._pMagResist); } else { style = UIS_GOLD; strcpy(chrstr, _(/* TRANSLATORS: UI Constrains. Keep translation short please!*/ "MAX")); @@ -1261,10 +1289,10 @@ void DrawChr(const CelOutputBuffer &out) DrawString(out, chrstr, { 257, 276, 43, 0 }, style | UIS_CENTER); style = UIS_BLUE; - if (plr[myplr]._pFireResist == 0) + if (myPlayer._pFireResist == 0) style = UIS_SILVER; - if (plr[myplr]._pFireResist < MAXRESIST) { - sprintf(chrstr, "%i%%", plr[myplr]._pFireResist); + if (myPlayer._pFireResist < MAXRESIST) { + sprintf(chrstr, "%i%%", myPlayer._pFireResist); } else { style = UIS_GOLD; strcpy(chrstr, _("MAX")); @@ -1272,10 +1300,10 @@ void DrawChr(const CelOutputBuffer &out) DrawString(out, chrstr, { 257, 304, 43, 0 }, style | UIS_CENTER); style = UIS_BLUE; - if (plr[myplr]._pLghtResist == 0) + if (myPlayer._pLghtResist == 0) style = UIS_SILVER; - if (plr[myplr]._pLghtResist < MAXRESIST) { - sprintf(chrstr, "%i%%", plr[myplr]._pLghtResist); + if (myPlayer._pLghtResist < MAXRESIST) { + sprintf(chrstr, "%i%%", myPlayer._pLghtResist); } else { style = UIS_GOLD; strcpy(chrstr, _("MAX")); @@ -1283,97 +1311,97 @@ void DrawChr(const CelOutputBuffer &out) DrawString(out, chrstr, { 257, 332, 43, 0 }, style | UIS_CENTER); style = UIS_SILVER; - sprintf(chrstr, "%i", plr[myplr]._pBaseStr); - if (plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Strength) == plr[myplr]._pBaseStr) + sprintf(chrstr, "%i", myPlayer._pBaseStr); + if (myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength) == myPlayer._pBaseStr) style = UIS_GOLD; DrawString(out, chrstr, { 95, 155, 31, 0 }, style | UIS_CENTER); style = UIS_SILVER; - sprintf(chrstr, "%i", plr[myplr]._pBaseMag); - if (plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Magic) == plr[myplr]._pBaseMag) + sprintf(chrstr, "%i", myPlayer._pBaseMag); + if (myPlayer.GetMaximumAttributeValue(CharacterAttribute::Magic) == myPlayer._pBaseMag) style = UIS_GOLD; DrawString(out, chrstr, { 95, 183, 31, 0 }, style | UIS_CENTER); style = UIS_SILVER; - sprintf(chrstr, "%i", plr[myplr]._pBaseDex); - if (plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Dexterity) == plr[myplr]._pBaseDex) + sprintf(chrstr, "%i", myPlayer._pBaseDex); + if (myPlayer.GetMaximumAttributeValue(CharacterAttribute::Dexterity) == myPlayer._pBaseDex) style = UIS_GOLD; DrawString(out, chrstr, { 95, 211, 31, 0 }, style | UIS_CENTER); style = UIS_SILVER; - sprintf(chrstr, "%i", plr[myplr]._pBaseVit); - if (plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Vitality) == plr[myplr]._pBaseVit) + sprintf(chrstr, "%i", myPlayer._pBaseVit); + if (myPlayer.GetMaximumAttributeValue(CharacterAttribute::Vitality) == myPlayer._pBaseVit) style = UIS_GOLD; DrawString(out, chrstr, { 95, 239, 31, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pStrength > plr[myplr]._pBaseStr) + if (myPlayer._pStrength > myPlayer._pBaseStr) style = UIS_BLUE; - if (plr[myplr]._pStrength < plr[myplr]._pBaseStr) + if (myPlayer._pStrength < myPlayer._pBaseStr) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pStrength); + sprintf(chrstr, "%i", myPlayer._pStrength); DrawString(out, chrstr, { 143, 155, 30, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pMagic > plr[myplr]._pBaseMag) + if (myPlayer._pMagic > myPlayer._pBaseMag) style = UIS_BLUE; - if (plr[myplr]._pMagic < plr[myplr]._pBaseMag) + if (myPlayer._pMagic < myPlayer._pBaseMag) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pMagic); + sprintf(chrstr, "%i", myPlayer._pMagic); DrawString(out, chrstr, { 143, 183, 30, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pDexterity > plr[myplr]._pBaseDex) + if (myPlayer._pDexterity > myPlayer._pBaseDex) style = UIS_BLUE; - if (plr[myplr]._pDexterity < plr[myplr]._pBaseDex) + if (myPlayer._pDexterity < myPlayer._pBaseDex) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pDexterity); + sprintf(chrstr, "%i", myPlayer._pDexterity); DrawString(out, chrstr, { 143, 211, 30, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pVitality > plr[myplr]._pBaseVit) + if (myPlayer._pVitality > myPlayer._pBaseVit) style = UIS_BLUE; - if (plr[myplr]._pVitality < plr[myplr]._pBaseVit) + if (myPlayer._pVitality < myPlayer._pBaseVit) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pVitality); + sprintf(chrstr, "%i", myPlayer._pVitality); DrawString(out, chrstr, { 143, 239, 30, 0 }, style | UIS_CENTER); - if (plr[myplr]._pStatPts > 0) { - if (CalcStatDiff(plr[myplr]) < plr[myplr]._pStatPts) { - plr[myplr]._pStatPts = CalcStatDiff(plr[myplr]); + if (myPlayer._pStatPts > 0) { + if (CalcStatDiff(myPlayer) < myPlayer._pStatPts) { + myPlayer._pStatPts = CalcStatDiff(myPlayer); } } - if (plr[myplr]._pStatPts > 0) { - sprintf(chrstr, "%i", plr[myplr]._pStatPts); + if (myPlayer._pStatPts > 0) { + sprintf(chrstr, "%i", myPlayer._pStatPts); DrawString(out, chrstr, { 95, 266, 31, 0 }, UIS_RED | UIS_CENTER); - if (plr[myplr]._pBaseStr < plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Strength)) + if (myPlayer._pBaseStr < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength)) CelDrawTo(out, 137, 159, *pChrButtons, chrbtn[static_cast(CharacterAttribute::Strength)] ? 3 : 2); - if (plr[myplr]._pBaseMag < plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Magic)) + if (myPlayer._pBaseMag < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Magic)) CelDrawTo(out, 137, 187, *pChrButtons, chrbtn[static_cast(CharacterAttribute::Magic)] ? 5 : 4); - if (plr[myplr]._pBaseDex < plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Dexterity)) + if (myPlayer._pBaseDex < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Dexterity)) CelDrawTo(out, 137, 216, *pChrButtons, chrbtn[static_cast(CharacterAttribute::Dexterity)] ? 7 : 6); - if (plr[myplr]._pBaseVit < plr[myplr].GetMaximumAttributeValue(CharacterAttribute::Vitality)) + if (myPlayer._pBaseVit < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Vitality)) CelDrawTo(out, 137, 244, *pChrButtons, chrbtn[static_cast(CharacterAttribute::Vitality)] ? 9 : 8); } style = UIS_SILVER; - if (plr[myplr]._pMaxHP > plr[myplr]._pMaxHPBase) + if (myPlayer._pMaxHP > myPlayer._pMaxHPBase) style = UIS_BLUE; - sprintf(chrstr, "%i", plr[myplr]._pMaxHP >> 6); + sprintf(chrstr, "%i", myPlayer._pMaxHP >> 6); DrawString(out, chrstr, { 95, 304, 31, 0 }, style | UIS_CENTER); - if (plr[myplr]._pHitPoints != plr[myplr]._pMaxHP) + if (myPlayer._pHitPoints != myPlayer._pMaxHP) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pHitPoints >> 6); + sprintf(chrstr, "%i", myPlayer._pHitPoints >> 6); DrawString(out, chrstr, { 143, 304, 31, 0 }, style | UIS_CENTER); style = UIS_SILVER; - if (plr[myplr]._pMaxMana > plr[myplr]._pMaxManaBase) + if (myPlayer._pMaxMana > myPlayer._pMaxManaBase) style = UIS_BLUE; - sprintf(chrstr, "%i", plr[myplr]._pMaxMana >> 6); + sprintf(chrstr, "%i", myPlayer._pMaxMana >> 6); DrawString(out, chrstr, { 95, 332, 31, 0 }, style | UIS_CENTER); - if (plr[myplr]._pMana != plr[myplr]._pMaxMana) + if (myPlayer._pMana != myPlayer._pMaxMana) style = UIS_RED; - sprintf(chrstr, "%i", plr[myplr]._pMana >> 6); + sprintf(chrstr, "%i", myPlayer._pMana >> 6); DrawString(out, chrstr, { 143, 332, 31, 0 }, style | UIS_CENTER); } @@ -1401,26 +1429,28 @@ void DrawLevelUpIcon(const CelOutputBuffer &out) void CheckChrBtns() { - if (chrbtnactive || plr[myplr]._pStatPts == 0) + auto &myPlayer = plr[myplr]; + + if (chrbtnactive || myPlayer._pStatPts == 0) return; for (auto attribute : enum_values()) { - int max = plr[myplr].GetMaximumAttributeValue(attribute); + int max = myPlayer.GetMaximumAttributeValue(attribute); switch (attribute) { case CharacterAttribute::Strength: - if (plr[myplr]._pBaseStr >= max) + if (myPlayer._pBaseStr >= max) continue; break; case CharacterAttribute::Magic: - if (plr[myplr]._pBaseMag >= max) + if (myPlayer._pBaseMag >= max) continue; break; case CharacterAttribute::Dexterity: - if (plr[myplr]._pBaseDex >= max) + if (myPlayer._pBaseDex >= max) continue; break; case CharacterAttribute::Vitality: - if (plr[myplr]._pBaseVit >= max) + if (myPlayer._pBaseVit >= max) continue; break; default: @@ -1459,26 +1489,26 @@ void ReleaseChrBtns(bool addAllStatPoints) && MouseX <= ChrBtnsRect[buttonId].x + ChrBtnsRect[buttonId].w && MouseY >= ChrBtnsRect[buttonId].y && MouseY <= ChrBtnsRect[buttonId].y + ChrBtnsRect[buttonId].h) { - auto &player = plr[myplr]; + auto &myPlayer = plr[myplr]; int statPointsToAdd = 1; if (addAllStatPoints) - statPointsToAdd = CapStatPointsToAdd(player._pStatPts, player, attribute); + statPointsToAdd = CapStatPointsToAdd(myPlayer._pStatPts, myPlayer, attribute); switch (attribute) { case CharacterAttribute::Strength: NetSendCmdParam1(true, CMD_ADDSTR, statPointsToAdd); - player._pStatPts -= statPointsToAdd; + myPlayer._pStatPts -= statPointsToAdd; break; case CharacterAttribute::Magic: NetSendCmdParam1(true, CMD_ADDMAG, statPointsToAdd); - player._pStatPts -= statPointsToAdd; + myPlayer._pStatPts -= statPointsToAdd; break; case CharacterAttribute::Dexterity: NetSendCmdParam1(true, CMD_ADDDEX, statPointsToAdd); - player._pStatPts -= statPointsToAdd; + myPlayer._pStatPts -= statPointsToAdd; break; case CharacterAttribute::Vitality: NetSendCmdParam1(true, CMD_ADDVIT, statPointsToAdd); - player._pStatPts -= statPointsToAdd; + myPlayer._pStatPts -= statPointsToAdd; break; } } @@ -1535,11 +1565,11 @@ void DrawDurIcon(const CelOutputBuffer &out) x -= SPANEL_WIDTH - (gnScreenWidth - PANEL_WIDTH) / 2; } - PlayerStruct *p = &plr[myplr]; - x = DrawDurIcon4Item(out, &p->InvBody[INVLOC_HEAD], x, 4); - x = DrawDurIcon4Item(out, &p->InvBody[INVLOC_CHEST], x, 3); - x = DrawDurIcon4Item(out, &p->InvBody[INVLOC_HAND_LEFT], x, 0); - DrawDurIcon4Item(out, &p->InvBody[INVLOC_HAND_RIGHT], x, 0); + auto &myPlayer = plr[myplr]; + x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HEAD], x, 4); + x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_CHEST], x, 3); + x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HAND_LEFT], x, 0); + DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HAND_RIGHT], x, 0); } void RedBack(const CelOutputBuffer &out) @@ -1562,20 +1592,21 @@ static void PrintSBookStr(const CelOutputBuffer &out, int x, int y, const char * spell_type GetSBookTrans(spell_id ii, bool townok) { - if ((plr[myplr]._pClass == HeroClass::Monk) && (ii == SPL_SEARCH)) + auto &myPlayer = plr[myplr]; + if ((myPlayer._pClass == HeroClass::Monk) && (ii == SPL_SEARCH)) return RSPLTYPE_SKILL; spell_type st = RSPLTYPE_SPELL; - if ((plr[myplr]._pISpells & GetSpellBitmask(ii)) != 0) { + if ((myPlayer._pISpells & GetSpellBitmask(ii)) != 0) { st = RSPLTYPE_CHARGES; } - if ((plr[myplr]._pAblSpells & GetSpellBitmask(ii)) != 0) { + if ((myPlayer._pAblSpells & GetSpellBitmask(ii)) != 0) { st = RSPLTYPE_SKILL; } if (st == RSPLTYPE_SPELL) { if (!CheckSpell(myplr, ii, st, true)) { st = RSPLTYPE_INVALID; } - if ((char)(plr[myplr]._pSplLvl[ii] + plr[myplr]._pISplLvlAdd) <= 0) { + if ((char)(myPlayer._pSplLvl[ii] + myPlayer._pISplLvlAdd) <= 0) { st = RSPLTYPE_INVALID; } } @@ -1599,7 +1630,8 @@ void DrawSpellBook(const CelOutputBuffer &out) } CelDrawTo(out, sx, 348, *pSBkBtnCel, sbooktab + 1); } - uint64_t spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells; + auto &myPlayer = plr[myplr]; + uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells; int yp = 55; for (int i = 1; i < 8; i++) { @@ -1608,7 +1640,7 @@ void DrawSpellBook(const CelOutputBuffer &out) spell_type st = GetSBookTrans(sn, true); SetSpellTrans(st); DrawSpellCel(out, RIGHT_PANEL_X + 11, yp, *pSBkIconCels, SpellITbl[sn]); - if (sn == plr[myplr]._pRSpell && st == plr[myplr]._pRSplType) { + if (sn == myPlayer._pRSpell && st == myPlayer._pRSplType) { SetSpellTrans(RSPLTYPE_SKILL); DrawSpellCel(out, RIGHT_PANEL_X + 11, yp, *pSBkIconCels, SPLICONLAST); } @@ -1618,7 +1650,7 @@ void DrawSpellBook(const CelOutputBuffer &out) strcpy(tempstr, _("Skill")); break; case RSPLTYPE_CHARGES: { - int charges = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges; + int charges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges; strcpy(tempstr, fmt::format(ngettext("Staff ({:d} charge)", "Staff ({:d} charges)", charges), charges).c_str()); } break; default: { @@ -1635,7 +1667,7 @@ void DrawSpellBook(const CelOutputBuffer &out) strcpy(tempstr, fmt::format(_(/* TRANSLATORS: Dam refers to damage. UI constrains, keep short please.*/ "Mana: {:d} Dam: 1/3 tgt hp"), mana).c_str()); } PrintSBookStr(out, 10, yp - 1, tempstr); - int lvl = plr[myplr]._pSplLvl[sn] + plr[myplr]._pISplLvlAdd; + int lvl = myPlayer._pSplLvl[sn] + myPlayer._pISplLvlAdd; if (lvl < 0) { lvl = 0; } @@ -1656,17 +1688,18 @@ void CheckSBook() { if (MouseX >= RIGHT_PANEL + 11 && MouseX < RIGHT_PANEL + 48 && MouseY >= 18 && MouseY < 314) { spell_id sn = SpellPages[sbooktab][(MouseY - 18) / 43]; - uint64_t spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells; + auto &myPlayer = plr[myplr]; + uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells; if (sn != SPL_INVALID && (spl & GetSpellBitmask(sn)) != 0) { spell_type st = RSPLTYPE_SPELL; - if ((plr[myplr]._pISpells & GetSpellBitmask(sn)) != 0) { + if ((myPlayer._pISpells & GetSpellBitmask(sn)) != 0) { st = RSPLTYPE_CHARGES; } - if ((plr[myplr]._pAblSpells & GetSpellBitmask(sn)) != 0) { + if ((myPlayer._pAblSpells & GetSpellBitmask(sn)) != 0) { st = RSPLTYPE_SKILL; } - plr[myplr]._pRSpell = sn; - plr[myplr]._pRSplType = st; + myPlayer._pRSpell = sn; + myPlayer._pRSplType = st; force_redraw = 255; } } @@ -1735,36 +1768,29 @@ void control_drop_gold(char vkey) } } -void control_remove_gold(int pnum, int goldIndex) +static void control_set_gold_curs(PlayerStruct &player) { - if (goldIndex <= INVITEM_INV_LAST) { - int gi = goldIndex - INVITEM_INV_FIRST; - plr[pnum].InvList[gi]._ivalue -= dropGoldValue; - if (plr[pnum].InvList[gi]._ivalue > 0) - SetGoldCurs(pnum, gi); - else - plr[pnum].RemoveInvItem(gi); - } else { - int gi = goldIndex - INVITEM_BELT_FIRST; - plr[pnum].SpdList[gi]._ivalue -= dropGoldValue; - if (plr[pnum].SpdList[gi]._ivalue > 0) - SetSpdbarGoldCurs(pnum, gi); - else - RemoveSpdBarItem(pnum, gi); - } - SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &plr[pnum].HoldItem); - plr[pnum].HoldItem._ivalue = dropGoldValue; - plr[pnum].HoldItem._iStatFlag = true; - control_set_gold_curs(pnum); - plr[pnum]._pGold = CalculateGold(plr[pnum]); - dropGoldValue = 0; + SetPlrHandGoldCurs(&player.HoldItem); + NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); } -void control_set_gold_curs(int pnum) +void control_remove_gold(int pnum, int goldIndex) { - SetPlrHandGoldCurs(&plr[pnum].HoldItem); - NewCursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); + auto &player = plr[pnum]; + + int gi = goldIndex - INVITEM_INV_FIRST; + player.InvList[gi]._ivalue -= dropGoldValue; + if (player.InvList[gi]._ivalue > 0) + SetPlrHandGoldCurs(&player.InvList[gi]); + else + player.RemoveInvItem(gi); + SetPlrHandItem(&player.HoldItem, IDI_GOLD); + GetGoldSeed(pnum, &player.HoldItem); + player.HoldItem._ivalue = dropGoldValue; + player.HoldItem._iStatFlag = true; + control_set_gold_curs(player); + player._pGold = CalculateGold(player); + dropGoldValue = 0; } void DrawTalkPan(const CelOutputBuffer &out) @@ -1810,8 +1836,9 @@ void DrawTalkPan(const CelOutputBuffer &out) nCel += 4; CelDrawTo(out, 172 + PANEL_X, 84 + 18 * talkBtn + PANEL_Y, *pTalkBtns, nCel); } - if (plr[i].plractive) { - DrawString(out, plr[i]._pName, { x, y + 60 + talkBtn * 18, 204, 0 }, color); + auto &player = plr[i]; + if (player.plractive) { + DrawString(out, player._pName, { x, y + 60 + talkBtn * 18, 204, 0 }, color); } talkBtn++; diff --git a/Source/control.h b/Source/control.h index 1d9791270..3ac6aa518 100644 --- a/Source/control.h +++ b/Source/control.h @@ -133,7 +133,6 @@ void CheckSBook(); void DrawGoldSplit(const CelOutputBuffer &out, int amount); void control_drop_gold(char vkey); void control_remove_gold(int pnum, int goldIndex); -void control_set_gold_curs(int pnum); void DrawTalkPan(const CelOutputBuffer &out); bool control_check_talk_btn(); void control_release_talk_btn(); diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index c6c2cb3a5..64d173108 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -54,15 +54,15 @@ int slot = SLOTXY_INV_FIRST; */ int GetRotaryDistance(int x, int y) { - int d, d1, d2; + auto &myPlayer = plr[myplr]; - if (plr[myplr].position.future.x == x && plr[myplr].position.future.y == y) + if (myPlayer.position.future.x == x && myPlayer.position.future.y == y) return -1; - d1 = plr[myplr]._pdir; - d2 = GetDirection(plr[myplr].position.future, { x, y }); + int d1 = myPlayer._pdir; + int d2 = GetDirection(myPlayer.position.future, { x, y }); - d = abs(d1 - d2); + int d = abs(d1 - d2); if (d > 4) return 4 - (d % 4); @@ -76,7 +76,9 @@ int GetRotaryDistance(int x, int y) */ int GetMinDistance(int dx, int dy) { - return std::max(abs(plr[myplr].position.future.x - dx), abs(plr[myplr].position.future.y - dy)); + auto &myPlayer = plr[myplr]; + + return std::max(abs(myPlayer.position.future.x - dx), abs(myPlayer.position.future.y - dy)); } /** @@ -326,21 +328,24 @@ void CheckPlayerNearby() if (pcursmonst != -1) return; - int spl = plr[myplr]._pRSpell; + auto &myPlayer = plr[myplr]; + + int spl = myPlayer._pRSpell; if (gbFriendlyMode && spl != SPL_RESURRECT && spl != SPL_HEALOTHER) return; for (int i = 0; i < MAX_PLRS; i++) { if (i == myplr) continue; - const int mx = plr[i].position.future.x; - const int my = plr[i].position.future.y; + auto &player = plr[i]; + const int mx = player.position.future.x; + const int my = player.position.future.y; if (dPlayer[mx][my] == 0 || (dFlags[mx][my] & BFLAG_LIT) == 0 - || (plr[i]._pHitPoints == 0 && spl != SPL_RESURRECT)) + || (player._pHitPoints == 0 && spl != SPL_RESURRECT)) continue; - if (plr[myplr]._pwtype == WT_RANGED || HasRangedSpell() || spl == SPL_HEALOTHER) { + if (myPlayer._pwtype == WT_RANGED || HasRangedSpell() || spl == SPL_HEALOTHER) { newDdistance = GetDistanceRanged(mx, my); } else { newDdistance = GetDistance(mx, my, distance); @@ -582,14 +587,15 @@ std::pair GetItemSizeOnSlot(int slot, char &itemInvId) { if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { int ig = slot - SLOTXY_INV_FIRST; - char ii = plr[myplr].InvGrid[ig]; + auto &myPlayer = plr[myplr]; + char ii = myPlayer.InvGrid[ig]; if (ii != 0) { int iv = ii; if (ii <= 0) { iv = -ii; } - ItemStruct &item = plr[myplr].InvList[iv - 1]; + ItemStruct &item = myPlayer.InvList[iv - 1]; if (!item.isEmpty()) { std::pair size = GetInvItemSize(item._iCurs + CURSOR_FIRSTITEM); size.first /= INV_SLOT_SIZE_PX; @@ -679,6 +685,7 @@ void InvMove(AxisDirection dir) slot = SLOTXY_BELT_LAST; const int initialSlot = slot; + auto &myPlayer = plr[myplr]; // when item is on cursor (pcurs > 1), this is the real cursor XY if (dir.x == AxisDirectionX_LEFT) { @@ -693,10 +700,10 @@ void InvMove(AxisDirection dir) } else if (slot > SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) { slot -= 1; mousePos = BeltGetSlotCoord(slot); - } else if (plr[myplr].HoldItem._itype == ITYPE_RING) { + } else if (myPlayer.HoldItem._itype == ITYPE_RING) { slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); - } else if (plr[myplr].HoldItem.isWeapon() || plr[myplr].HoldItem.isShield()) { + } else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) { if (slot == SLOTXY_HAND_LEFT_FIRST) { slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); @@ -743,10 +750,10 @@ void InvMove(AxisDirection dir) } else if (slot >= SLOTXY_BELT_FIRST && slot < SLOTXY_BELT_LAST) { slot += 1; mousePos = BeltGetSlotCoord(slot); - } else if (plr[myplr].HoldItem._itype == ITYPE_RING) { + } else if (myPlayer.HoldItem._itype == ITYPE_RING) { slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); - } else if (plr[myplr].HoldItem.isWeapon() || plr[myplr].HoldItem.isShield()) { + } else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) { if (slot == SLOTXY_HAND_LEFT_FIRST) { slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); @@ -788,7 +795,7 @@ void InvMove(AxisDirection dir) slot -= INV_ROW_SLOT_SIZE; mousePos = InvGetSlotCoord(slot); } else if (slot >= SLOTXY_INV_FIRST) { - if (plr[myplr].HoldItem._itype == ITYPE_RING) { + if (myPlayer.HoldItem._itype == ITYPE_RING) { if (slot >= SLOTXY_INV_ROW1_FIRST && slot <= SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2) - 1) { slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); @@ -796,19 +803,19 @@ void InvMove(AxisDirection dir) slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); } - } else if (plr[myplr].HoldItem.isWeapon()) { + } else if (myPlayer.HoldItem.isWeapon()) { slot = SLOTXY_HAND_LEFT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); - } else if (plr[myplr].HoldItem.isShield()) { + } else if (myPlayer.HoldItem.isShield()) { slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); - } else if (plr[myplr].HoldItem.isHelm()) { + } else if (myPlayer.HoldItem.isHelm()) { slot = SLOTXY_HEAD_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); - } else if (plr[myplr].HoldItem.isArmor()) { + } else if (myPlayer.HoldItem.isArmor()) { slot = SLOTXY_CHEST_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); - } else if (plr[myplr].HoldItem._itype == ITYPE_AMULET) { + } else if (myPlayer.HoldItem._itype == ITYPE_AMULET) { slot = SLOTXY_AMULET; mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); } @@ -854,7 +861,7 @@ void InvMove(AxisDirection dir) } else if (slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) { slot += INV_ROW_SLOT_SIZE; mousePos = InvGetSlotCoord(slot); - } else if (slot <= SLOTXY_INV_LAST && plr[myplr].HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items + } else if (slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items slot += INV_ROW_SLOT_SIZE; if (slot > SLOTXY_BELT_LAST) slot = SLOTXY_BELT_LAST; @@ -905,7 +912,7 @@ void InvMove(AxisDirection dir) // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId if (itemInvId < 0) { for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) { - if (plr[myplr].InvGrid[s] == -itemInvId) { + if (myPlayer.InvGrid[s] == -itemInvId) { slot = SLOTXY_INV_FIRST + s; break; } @@ -1093,11 +1100,13 @@ bool CanChangeDirection(const PlayerStruct &player) void WalkInDir(int playerId, AxisDirection dir) { - const int x = plr[playerId].position.future.x; - const int y = plr[playerId].position.future.y; + auto &player = plr[playerId]; + + const int x = player.position.future.x; + const int y = player.position.future.y; if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) { - if (sgbControllerActive && plr[playerId].walkpath[0] != WALK_NONE && plr[playerId].destAction == ACTION_NONE) + if (sgbControllerActive && player.walkpath[0] != WALK_NONE && player.destAction == ACTION_NONE) NetSendCmdLoc(playerId, true, CMD_WALKXY, { x, y }); // Stop walking return; } @@ -1106,8 +1115,8 @@ void WalkInDir(int playerId, AxisDirection dir) const int dx = x + Offsets[pdir][0]; const int dy = y + Offsets[pdir][1]; - if (CanChangeDirection(plr[playerId])) - plr[playerId]._pdir = pdir; + if (CanChangeDirection(player)) + player._pdir = pdir; if (PosOkPlayer(playerId, dx, dy) && IsPathBlocked(x, y, pdir)) return; // Don't start backtrack around obstacles @@ -1227,18 +1236,19 @@ void StoreSpellCoords() int yo = endY; for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) { std::uint64_t spells; + auto &myPlayer = plr[myplr]; switch (i) { case RSPLTYPE_SKILL: - spells = plr[myplr]._pAblSpells; + spells = myPlayer._pAblSpells; break; case RSPLTYPE_SPELL: - spells = plr[myplr]._pMemSpells; + spells = myPlayer._pMemSpells; break; case RSPLTYPE_SCROLL: - spells = plr[myplr]._pScrlSpells; + spells = myPlayer._pScrlSpells; break; case RSPLTYPE_CHARGES: - spells = plr[myplr]._pISpells; + spells = myPlayer._pISpells; break; } std::uint64_t spell = 1; @@ -1363,12 +1373,13 @@ void plrctrls_after_game_logic() void UseBeltItem(int type) { for (int i = 0; i < MAXBELTITEMS; i++) { - const int id = AllItemsList[plr[myplr].SpdList[i].IDidx].iMiscId; - const int spellId = AllItemsList[plr[myplr].SpdList[i].IDidx].iSpell; + auto &myPlayer = plr[myplr]; + const int id = AllItemsList[myPlayer.SpdList[i].IDidx].iMiscId; + const int spellId = AllItemsList[myPlayer.SpdList[i].IDidx].iSpell; if ((type == BLT_HEALING && (id == IMISC_HEAL || id == IMISC_FULLHEAL || (id == IMISC_SCROLL && spellId == SPL_HEAL))) || (type == BLT_MANA && (id == IMISC_MANA || id == IMISC_FULLMANA)) || id == IMISC_REJUV || id == IMISC_FULLREJUV) { - if (plr[myplr].SpdList[i]._itype > -1) { + if (myPlayer.SpdList[i]._itype > -1) { UseInvItem(myplr, INVITEM_BELT_FIRST + i); break; } @@ -1433,14 +1444,12 @@ void UpdateSpellTarget() pcursplr = -1; pcursmonst = -1; - const PlayerStruct &player = plr[myplr]; - int range = 1; if (plr[myplr]._pRSpell == SPL_TELEPORT) range = 4; - cursmx = player.position.future.x + Offsets[player._pdir][0] * range; - cursmy = player.position.future.y + Offsets[player._pdir][1] * range; + cursmx = plr[myplr].position.future.x + Offsets[plr[myplr]._pdir][0] * range; + cursmy = plr[myplr].position.future.y + Offsets[plr[myplr]._pdir][1] * range; } /** @@ -1448,12 +1457,14 @@ void UpdateSpellTarget() */ bool TryDropItem() { - cursmx = plr[myplr].position.future.x + 1; - cursmy = plr[myplr].position.future.y; + const auto &myPlayer = plr[myplr]; + + cursmx = myPlayer.position.future.x + 1; + cursmy = myPlayer.position.future.y; if (!DropItemBeforeTrig()) { // Try to drop on the other side - cursmx = plr[myplr].position.future.x; - cursmy = plr[myplr].position.future.y + 1; + cursmx = myPlayer.position.future.x; + cursmy = myPlayer.position.future.y + 1; DropItemBeforeTrig(); } @@ -1488,10 +1499,11 @@ void PerformSpellAction() return; } - int spl = plr[myplr]._pRSpell; + const auto &myPlayer = plr[myplr]; + int spl = myPlayer._pRSpell; if ((pcursplr == -1 && (spl == SPL_RESURRECT || spl == SPL_HEALOTHER)) || (pcursobj == -1 && spl == SPL_DISARM)) { - plr[myplr].Say(HeroSpeech::ICantCastThatHere); + myPlayer.Say(HeroSpeech::ICantCastThatHere); return; } @@ -1506,10 +1518,12 @@ void CtrlUseInvItem() if (pcursinvitem == -1) return; + auto &myPlayer = plr[myplr]; + if (pcursinvitem <= INVITEM_INV_LAST) - item = &plr[myplr].InvList[pcursinvitem - INVITEM_INV_FIRST]; + item = &myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]; else - item = &plr[myplr].SpdList[pcursinvitem - INVITEM_BELT_FIRST]; + item = &myPlayer.SpdList[pcursinvitem - INVITEM_BELT_FIRST]; if ((item->_iMiscId == IMISC_SCROLLT || item->_iMiscId == IMISC_SCROLL) && spelldata[item->_iSpell].sTargeted) { return; diff --git a/Source/cursor.cpp b/Source/cursor.cpp index eccef3b99..a328a5cae 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -278,18 +278,18 @@ void CheckCursMove() // Adjust by player offset and tile grid alignment CalcTileOffset(&xo, &yo); - PlayerStruct *pPlayer = &plr[myplr]; + const auto &myPlayer = plr[myplr]; Point offset = ScrollInfo.offset; - if (pPlayer->IsWalking()) - offset = GetOffsetForWalking(pPlayer->AnimInfo, pPlayer->_pdir, true); + if (myPlayer.IsWalking()) + offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); sx -= offset.x - xo; sy -= offset.y - yo; // Predict the next frame when walking to avoid input jitter - fx = plr[myplr].position.offset2.x / 256; - fy = plr[myplr].position.offset2.y / 256; - fx -= (plr[myplr].position.offset2.x + plr[myplr].position.velocity.x) / 256; - fy -= (plr[myplr].position.offset2.y + plr[myplr].position.velocity.y) / 256; + fx = myPlayer.position.offset2.x / 256; + fy = myPlayer.position.offset2.y / 256; + fx -= (myPlayer.position.offset2.x + myPlayer.position.velocity.x) / 256; + fy -= (myPlayer.position.offset2.y + myPlayer.position.velocity.y) / 256; if (ScrollInfo._sdir != SDIR_NONE) { sx -= fx; sy -= fy; @@ -364,7 +364,7 @@ void CheckCursMove() panelflag = false; trigflag = false; - if (plr[myplr]._pInvincible) { + if (myPlayer._pInvincible) { return; } if (pcurs >= CURSOR_FIRSTITEM || spselflag) { diff --git a/Source/debug.cpp b/Source/debug.cpp index 3c809a50d..47d668acd 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -53,54 +53,57 @@ void CheckDungeonClear() void GiveGoldCheat() { - int i, ni; - - for (i = 0; i < NUM_INV_GRID_ELEM; i++) { - if (plr[myplr].InvGrid[i] == 0) { - ni = plr[myplr]._pNumInv++; - SetPlrHandItem(&plr[myplr].InvList[ni], IDI_GOLD); - GetPlrHandSeed(&plr[myplr].InvList[ni]); - plr[myplr].InvList[ni]._ivalue = GOLD_MAX_LIMIT; - plr[myplr].InvList[ni]._iCurs = ICURS_GOLD_LARGE; - plr[myplr]._pGold += GOLD_MAX_LIMIT; - plr[myplr].InvGrid[i] = plr[myplr]._pNumInv; + auto &myPlayer = plr[myplr]; + + for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { + if (myPlayer.InvGrid[i] == 0) { + int ni = myPlayer._pNumInv++; + SetPlrHandItem(&myPlayer.InvList[ni], IDI_GOLD); + GetPlrHandSeed(&myPlayer.InvList[ni]); + myPlayer.InvList[ni]._ivalue = GOLD_MAX_LIMIT; + myPlayer.InvList[ni]._iCurs = ICURS_GOLD_LARGE; + myPlayer._pGold += GOLD_MAX_LIMIT; + myPlayer.InvGrid[i] = myPlayer._pNumInv; } } } void TakeGoldCheat() { - int i; - char ig; + auto &myPlayer = plr[myplr]; - for (i = 0; i < NUM_INV_GRID_ELEM; i++) { - ig = plr[myplr].InvGrid[i]; - if (ig > 0 && plr[myplr].InvList[ig - 1]._itype == ITYPE_GOLD) - plr[myplr].RemoveInvItem(ig - 1); + for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { + int8_t ig = myPlayer.InvGrid[i]; + if (ig > 0 && myPlayer.InvList[ig - 1]._itype == ITYPE_GOLD) + myPlayer.RemoveInvItem(ig - 1); } - for (i = 0; i < MAXBELTITEMS; i++) { - if (plr[myplr].SpdList[i]._itype == ITYPE_GOLD) - plr[myplr].SpdList[i]._itype = ITYPE_NONE; + for (int i = 0; i < MAXBELTITEMS; i++) { + if (myPlayer.SpdList[i]._itype == ITYPE_GOLD) + myPlayer.SpdList[i]._itype = ITYPE_NONE; } - plr[myplr]._pGold = 0; + myPlayer._pGold = 0; } void MaxSpellsCheat() { + auto &myPlayer = plr[myplr]; + for (int i = SPL_FIREBOLT; i < MAX_SPELLS; i++) { if (GetSpellBookLevel((spell_id)i) != -1) { - plr[myplr]._pMemSpells |= GetSpellBitmask(i); - plr[myplr]._pSplLvl[i] = 10; + myPlayer._pMemSpells |= GetSpellBitmask(i); + myPlayer._pSplLvl[i] = 10; } } } void SetSpellLevelCheat(spell_id spl, int spllvl) { - plr[myplr]._pMemSpells |= GetSpellBitmask(spl); - plr[myplr]._pSplLvl[spl] = spllvl; + auto &myPlayer = plr[myplr]; + + myPlayer._pMemSpells |= GetSpellBitmask(spl); + myPlayer._pSplLvl[spl] = spllvl; } void SetAllSpellsCheat() @@ -138,20 +141,22 @@ void PrintDebugPlayer(bool bNextPlayer) if (bNextPlayer) dbgplr = ((BYTE)dbgplr + 1) & 3; - sprintf(dstr, "Plr %i : Active = %i", dbgplr, plr[dbgplr].plractive); + auto &player = plr[dbgplr]; + + sprintf(dstr, "Plr %i : Active = %i", dbgplr, player.plractive); NetSendCmdString(1 << myplr, dstr); - if (plr[dbgplr].plractive) { - sprintf(dstr, " Plr %i is %s", dbgplr, plr[dbgplr]._pName); + if (player.plractive) { + sprintf(dstr, " Plr %i is %s", dbgplr, player._pName); NetSendCmdString(1 << myplr, dstr); - sprintf(dstr, " Lvl = %i : Change = %i", plr[dbgplr].plrlevel, plr[dbgplr]._pLvlChanging); + sprintf(dstr, " Lvl = %i : Change = %i", player.plrlevel, player._pLvlChanging); NetSendCmdString(1 << myplr, dstr); - const Point target = plr[dbgplr].GetTargetPosition(); - sprintf(dstr, " x = %i, y = %i : tx = %i, ty = %i", plr[dbgplr].position.tile.x, plr[dbgplr].position.tile.y, target.x, target.y); + const Point target = player.GetTargetPosition(); + sprintf(dstr, " x = %i, y = %i : tx = %i, ty = %i", player.position.tile.x, player.position.tile.y, target.x, target.y); NetSendCmdString(1 << myplr, dstr); - sprintf(dstr, " mode = %i : daction = %i : walk[0] = %i", plr[dbgplr]._pmode, plr[dbgplr].destAction, plr[dbgplr].walkpath[0]); + sprintf(dstr, " mode = %i : daction = %i : walk[0] = %i", player._pmode, player.destAction, player.walkpath[0]); NetSendCmdString(1 << myplr, dstr); - sprintf(dstr, " inv = %i : hp = %i", plr[dbgplr]._pInvincible, plr[dbgplr]._pHitPoints); + sprintf(dstr, " inv = %i : hp = %i", player._pInvincible, player._pHitPoints); NetSendCmdString(1 << myplr, dstr); } } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 490703e74..d8b99c9b9 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -805,12 +805,13 @@ static bool LeftMouseCmd(bool bShift) if (pcursitem == -1 && pcursmonst == -1 && pcursplr == -1) return true; } else { - bNear = abs(plr[myplr].position.tile.x - cursmx) < 2 && abs(plr[myplr].position.tile.y - cursmy) < 2; + auto &myPlayer = plr[myplr]; + bNear = abs(myPlayer.position.tile.x - cursmx) < 2 && abs(myPlayer.position.tile.y - cursmy) < 2; if (pcursitem != -1 && pcurs == CURSOR_HAND && !bShift) { NetSendCmdLocParam1(true, invflag ? CMD_GOTOGETITEM : CMD_GOTOAGETITEM, { cursmx, cursmy }, pcursitem); } else if (pcursobj != -1 && (!objectIsDisabled(pcursobj)) && (!bShift || (bNear && object[pcursobj]._oBreak == 1))) { NetSendCmdLocParam1(true, pcurs == CURSOR_DISARM ? CMD_DISARMXY : CMD_OPOBJXY, { cursmx, cursmy }, pcursobj); - } else if (plr[myplr]._pwtype == WT_RANGED) { + } else if (myPlayer._pwtype == WT_RANGED) { if (bShift) { NetSendCmdLoc(myplr, true, CMD_RATTACKXY, { cursmx, cursmy }); } else if (pcursmonst != -1) { @@ -896,12 +897,13 @@ bool TryIconCurs() } if (pcurs == CURSOR_TELEPORT) { + auto &myPlayer = plr[myplr]; if (pcursmonst != -1) - NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, plr[myplr]._pTSpell, GetSpellLevel(myplr, plr[myplr]._pTSpell)); + NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(myplr, myPlayer._pTSpell)); else if (pcursplr != -1) - NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, plr[myplr]._pTSpell, GetSpellLevel(myplr, plr[myplr]._pTSpell)); + NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, GetSpellLevel(myplr, myPlayer._pTSpell)); else - NetSendCmdLocParam2(true, CMD_TSPELLXY, { cursmx, cursmy }, plr[myplr]._pTSpell, GetSpellLevel(myplr, plr[myplr]._pTSpell)); + NetSendCmdLocParam2(true, CMD_TSPELLXY, { cursmx, cursmy }, myPlayer._pTSpell, GetSpellLevel(myplr, myPlayer._pTSpell)); NewCursor(CURSOR_HAND); return true; } @@ -1004,25 +1006,29 @@ static void LeftMouseUp(int wParam) static void RightMouseDown() { - if (!gmenu_is_active() && sgnTimeoutCurs == CURSOR_NONE && PauseMode != 2 && !plr[myplr]._pInvincible) { - if (DoomFlag) { - doom_close(); - return; - } - if (stextflag != STORE_NONE) - return; - if (spselflag) { - SetSpell(); - } else if (MouseY >= SPANEL_HEIGHT - || ((!sbookflag || MouseX <= RIGHT_PANEL) - && !TryIconCurs() - && (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)))) { - if (pcurs == CURSOR_HAND) { - if (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)) - CheckPlrSpell(); - } else if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) { - NewCursor(CURSOR_HAND); - } + if (gmenu_is_active() || sgnTimeoutCurs != CURSOR_NONE || PauseMode == 2 || plr[myplr]._pInvincible) { + return; + } + + if (DoomFlag) { + doom_close(); + return; + } + if (stextflag != STORE_NONE) + return; + if (spselflag) { + SetSpell(); + return; + } + if (MouseY >= SPANEL_HEIGHT + || ((!sbookflag || MouseX <= RIGHT_PANEL) + && !TryIconCurs() + && (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)))) { + if (pcurs == CURSOR_HAND) { + if (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)) + CheckPlrSpell(); + } else if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) { + NewCursor(CURSOR_HAND); } } } @@ -1285,15 +1291,16 @@ static void PressChar(int32_t vkey) if (arrowdebug > 2) { arrowdebug = 0; } + auto &myPlayer = plr[myplr]; if (arrowdebug == 0) { - plr[myplr]._pIFlags &= ~ISPL_FIRE_ARROWS; - plr[myplr]._pIFlags &= ~ISPL_LIGHT_ARROWS; + myPlayer._pIFlags &= ~ISPL_FIRE_ARROWS; + myPlayer._pIFlags &= ~ISPL_LIGHT_ARROWS; } if (arrowdebug == 1) { - plr[myplr]._pIFlags |= ISPL_FIRE_ARROWS; + myPlayer._pIFlags |= ISPL_FIRE_ARROWS; } if (arrowdebug == 2) { - plr[myplr]._pIFlags |= ISPL_LIGHT_ARROWS; + myPlayer._pIFlags |= ISPL_LIGHT_ARROWS; } arrowdebug++; } @@ -1316,7 +1323,8 @@ static void PressChar(int32_t vkey) case 'a': if (debug_mode_key_inverted_v) { spelldata[SPL_TELEPORT].sTownSpell = true; - plr[myplr]._pSplLvl[plr[myplr]._pSpell]++; + auto &myPlayer = plr[myplr]; + myPlayer._pSplLvl[myPlayer._pSpell]++; } return; case 'D': @@ -1349,7 +1357,8 @@ static void PressChar(int32_t vkey) case 'T': case 't': if (debug_mode_key_inverted_v) { - sprintf(tempstr, "PX = %i PY = %i", plr[myplr].position.tile.x, plr[myplr].position.tile.y); + auto &myPlayer = plr[myplr]; + sprintf(tempstr, "PX = %i PY = %i", myPlayer.position.tile.x, myPlayer.position.tile.y); NetSendCmdString(1 << myplr, tempstr); sprintf(tempstr, "CX = %i CY = %i DP = %i", cursmx, cursmy, dungeon[cursmx][cursmy]); NetSendCmdString(1 << myplr, tempstr); @@ -1637,9 +1646,6 @@ static void UpdateMonsterLights() void LoadGameLevel(bool firstflag, lvl_entry lvldir) { - int i, j; - bool visited; - if (setseed != 0) glSeedTbl[currlevel] = setseed; @@ -1678,6 +1684,8 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) InitLevelMonsters(); IncProgress(); + auto &myPlayer = plr[myplr]; + if (!setlevel) { CreateLevel(lvldir); IncProgress(); @@ -1705,8 +1713,9 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) IncProgress(); - for (i = 0; i < MAX_PLRS; i++) { - if (plr[i].plractive && currlevel == plr[i].plrlevel) { + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = plr[i]; + if (player.plractive && currlevel == player.plrlevel) { InitPlayerGFX(i); if (lvldir != ENTRY_LOAD) InitPlayer(i, firstflag); @@ -1717,17 +1726,18 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) InitMultiView(); IncProgress(); - visited = false; + bool visited = false; int players = gbIsMultiplayer ? MAX_PLRS : 1; - for (i = 0; i < players; i++) { - if (plr[i].plractive) - visited = visited || plr[i]._pLvlVisited[currlevel]; + for (int i = 0; i < players; i++) { + auto &player = plr[i]; + if (player.plractive) + visited = visited || player._pLvlVisited[currlevel]; } SetRndSeed(glSeedTbl[currlevel]); if (leveltype != DTYPE_TOWN) { - if (firstflag || lvldir == ENTRY_LOAD || !plr[myplr]._pLvlVisited[currlevel] || gbIsMultiplayer) { + if (firstflag || lvldir == ENTRY_LOAD || !myPlayer._pLvlVisited[currlevel] || gbIsMultiplayer) { HoldThemeRooms(); glMid1Seed[currlevel] = GetRndSeed(); InitMonsters(); @@ -1758,8 +1768,8 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) IncProgress(); } } else { - for (i = 0; i < MAXDUNX; i++) { - for (j = 0; j < MAXDUNY; j++) + for (int i = 0; i < MAXDUNX; i++) { + for (int j = 0; j < MAXDUNY; j++) dFlags[i][j] |= BFLAG_LIT; } @@ -1768,7 +1778,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) InitMissiles(); IncProgress(); - if (!firstflag && lvldir != ENTRY_LOAD && plr[myplr]._pLvlVisited[currlevel] && !gbIsMultiplayer) + if (!firstflag && lvldir != ENTRY_LOAD && myPlayer._pLvlVisited[currlevel] && !gbIsMultiplayer) LoadLevel(); if (gbIsMultiplayer) DeltaLoadLevel(); @@ -1797,8 +1807,9 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) GetPortalLvlPos(); IncProgress(); - for (i = 0; i < MAX_PLRS; i++) { - if (plr[i].plractive && currlevel == plr[i].plrlevel) { + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = plr[i]; + if (player.plractive && currlevel == player.plrlevel) { InitPlayerGFX(i); if (lvldir != ENTRY_LOAD) InitPlayer(i, firstflag); @@ -1809,7 +1820,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) InitMultiView(); IncProgress(); - if (firstflag || lvldir == ENTRY_LOAD || !plr[myplr]._pSLvlVisited[setlvlnum]) { + if (firstflag || lvldir == ENTRY_LOAD || !myPlayer._pSLvlVisited[setlvlnum]) { InitItems(); SavePreLighting(); } else { @@ -1822,15 +1833,16 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) SyncPortals(); - for (i = 0; i < MAX_PLRS; i++) { - if (plr[i].plractive && plr[i].plrlevel == currlevel && (!plr[i]._pLvlChanging || i == myplr)) { - if (plr[i]._pHitPoints > 0) { + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = plr[i]; + if (player.plractive && player.plrlevel == currlevel && (!player._pLvlChanging || i == myplr)) { + if (player._pHitPoints > 0) { if (!gbIsMultiplayer) - dPlayer[plr[i].position.tile.x][plr[i].position.tile.y] = i + 1; + dPlayer[player.position.tile.x][player.position.tile.y] = i + 1; else SyncInitPlrPos(i); } else { - dFlags[plr[i].position.tile.x][plr[i].position.tile.y] |= BFLAG_DEAD_PLAYER; + dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER; } } } @@ -2212,7 +2224,8 @@ void initKeymapActions() std::string("BeltItem") + std::to_string(i + 1), '1' + i, [i] { - if (!plr[myplr].SpdList[i].isEmpty() && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { + auto &myPlayer = plr[myplr]; + if (!myPlayer.SpdList[i].isEmpty() && myPlayer.SpdList[i]._itype != ITYPE_GOLD) { UseInvItem(myplr, INVITEM_BELT_FIRST + i); } }, diff --git a/Source/effects.cpp b/Source/effects.cpp index eeb5073f5..350ff9731 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -1340,20 +1340,23 @@ void sound_init() mask |= (sfx_ROGUE | sfx_SORCERER); if (gbIsHellfire) mask |= sfx_MONK; - } else if (plr[myplr]._pClass == HeroClass::Warrior) { - mask |= sfx_WARRIOR; - } else if (plr[myplr]._pClass == HeroClass::Rogue) { - mask |= sfx_ROGUE; - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { - mask |= sfx_SORCERER; - } else if (plr[myplr]._pClass == HeroClass::Monk) { - mask |= sfx_MONK; - } else if (plr[myplr]._pClass == HeroClass::Bard) { - mask |= sfx_ROGUE; - } else if (plr[myplr]._pClass == HeroClass::Barbarian) { - mask |= sfx_WARRIOR; } else { - app_fatal("effects:1"); + auto &myPlayer = plr[myplr]; + if (myPlayer._pClass == HeroClass::Warrior) { + mask |= sfx_WARRIOR; + } else if (myPlayer._pClass == HeroClass::Rogue) { + mask |= sfx_ROGUE; + } else if (myPlayer._pClass == HeroClass::Sorcerer) { + mask |= sfx_SORCERER; + } else if (myPlayer._pClass == HeroClass::Monk) { + mask |= sfx_MONK; + } else if (myPlayer._pClass == HeroClass::Bard) { + mask |= sfx_ROGUE; + } else if (myPlayer._pClass == HeroClass::Barbarian) { + mask |= sfx_WARRIOR; + } else { + app_fatal("effects:1"); + } } priv_sound_init(mask); diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index 2ed7e9168..f67292010 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -78,13 +78,9 @@ const char *const sound_toggle_names[] = { void gamemenu_update_single() { - bool enable; - gmenu_enable(&sgSingleMenu[3], gbValidSaveFile); - enable = false; - if (plr[myplr]._pmode != PM_DEATH && !deathflag) - enable = true; + bool enable = plr[myplr]._pmode != PM_DEATH && !deathflag; gmenu_enable(&sgSingleMenu[0], enable); } @@ -101,11 +97,9 @@ void gamemenu_previous(bool bActivate) void gamemenu_new_game(bool bActivate) { - int i; - - for (i = 0; i < MAX_PLRS; i++) { - plr[i]._pmode = PM_QUIT; - plr[i]._pInvincible = true; + for (auto &player : plr) { + player._pmode = PM_QUIT; + player._pInvincible = true; } deathflag = false; diff --git a/Source/interfac.cpp b/Source/interfac.cpp index c583df483..5ee31ef90 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -237,6 +237,8 @@ void ShowProgress(interface_mode uMsg) sound_init(); IncProgress(); + auto &myPlayer = plr[myplr]; + switch (uMsg) { case WM_DIABLOADGAME: IncProgress(); @@ -246,7 +248,7 @@ void ShowProgress(interface_mode uMsg) IncProgress(); break; case WM_DIABNEWGAME: - plr[myplr].pOriginalCathedral = !gbIsHellfire; + myPlayer.pOriginalCathedral = !gbIsHellfire; IncProgress(); FreeGameMem(); IncProgress(); @@ -266,7 +268,7 @@ void ShowProgress(interface_mode uMsg) FreeGameMem(); currlevel++; leveltype = gnLevelTypeTbl[currlevel]; - assert(plr[myplr].plrlevel == currlevel); + assert(myPlayer.plrlevel == currlevel); IncProgress(); LoadGameLevel(false, ENTRY_MAIN); IncProgress(); @@ -282,7 +284,7 @@ void ShowProgress(interface_mode uMsg) FreeGameMem(); currlevel--; leveltype = gnLevelTypeTbl[currlevel]; - assert(plr[myplr].plrlevel == currlevel); + assert(myPlayer.plrlevel == currlevel); IncProgress(); LoadGameLevel(false, ENTRY_PREV); IncProgress(); @@ -341,9 +343,8 @@ void ShowProgress(interface_mode uMsg) } IncProgress(); FreeGameMem(); - currlevel = plr[myplr].plrlevel; + currlevel = myPlayer.plrlevel; leveltype = gnLevelTypeTbl[currlevel]; - assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(false, ENTRY_TWARPDN); IncProgress(); @@ -357,9 +358,8 @@ void ShowProgress(interface_mode uMsg) } IncProgress(); FreeGameMem(); - currlevel = plr[myplr].plrlevel; + currlevel = myPlayer.plrlevel; leveltype = gnLevelTypeTbl[currlevel]; - assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(false, ENTRY_TWARPUP); IncProgress(); @@ -373,9 +373,8 @@ void ShowProgress(interface_mode uMsg) } IncProgress(); FreeGameMem(); - currlevel = plr[myplr].plrlevel; + currlevel = myPlayer.plrlevel; leveltype = gnLevelTypeTbl[currlevel]; - assert(plr[myplr].plrlevel == currlevel); IncProgress(); LoadGameLevel(false, ENTRY_MAIN); IncProgress(); @@ -390,11 +389,11 @@ void ShowProgress(interface_mode uMsg) saveProc = SetWindowProc(saveProc); assert(saveProc == DisableInputWndProc); - NetSendCmdLocParam1(true, CMD_PLAYER_JOINLEVEL, plr[myplr].position.tile, plr[myplr].plrlevel); + NetSendCmdLocParam1(true, CMD_PLAYER_JOINLEVEL, myPlayer.position.tile, myPlayer.plrlevel); plrmsg_delay(false); ResetPal(); - if (gbSomebodyWonGameKludge && plr[myplr].plrlevel == 16) { + if (gbSomebodyWonGameKludge && myPlayer.plrlevel == 16) { PrepDoEnding(); } diff --git a/Source/inv.cpp b/Source/inv.cpp index 0429417d0..d9e30c861 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -136,20 +136,22 @@ void FreeInvGFX() void InitInv() { - if (plr[myplr]._pClass == HeroClass::Warrior) { + auto &myPlayer = plr[myplr]; + + if (myPlayer._pClass == HeroClass::Warrior) { pInvCels = LoadCel("Data\\Inv\\Inv.CEL", SPANEL_WIDTH); - } else if (plr[myplr]._pClass == HeroClass::Rogue) { + } else if (myPlayer._pClass == HeroClass::Rogue) { pInvCels = LoadCel("Data\\Inv\\Inv_rog.CEL", SPANEL_WIDTH); - } else if (plr[myplr]._pClass == HeroClass::Sorcerer) { + } else if (myPlayer._pClass == HeroClass::Sorcerer) { pInvCels = LoadCel("Data\\Inv\\Inv_Sor.CEL", SPANEL_WIDTH); - } else if (plr[myplr]._pClass == HeroClass::Monk) { + } else if (myPlayer._pClass == HeroClass::Monk) { if (!gbIsSpawn) pInvCels = LoadCel("Data\\Inv\\Inv_Sor.CEL", SPANEL_WIDTH); else pInvCels = LoadCel("Data\\Inv\\Inv.CEL", SPANEL_WIDTH); - } else if (plr[myplr]._pClass == HeroClass::Bard) { + } else if (myPlayer._pClass == HeroClass::Bard) { pInvCels = LoadCel("Data\\Inv\\Inv_rog.CEL", SPANEL_WIDTH); - } else if (plr[myplr]._pClass == HeroClass::Barbarian) { + } else if (myPlayer._pClass == HeroClass::Barbarian) { pInvCels = LoadCel("Data\\Inv\\Inv.CEL", SPANEL_WIDTH); } @@ -199,13 +201,15 @@ void DrawInv(const CelOutputBuffer &out) { 133, 160 }, // chest }; + auto &myPlayer = plr[myplr]; + for (int slot = INVLOC_HEAD; slot < NUM_INVLOC; slot++) { - if (!plr[myplr].InvBody[slot].isEmpty()) { + if (!myPlayer.InvBody[slot].isEmpty()) { int screenX = slotPos[slot].X; int screenY = slotPos[slot].Y; InvDrawSlotBack(out, RIGHT_PANEL_X + screenX, screenY, slotSize[slot].X * INV_SLOT_SIZE_PX, slotSize[slot].Y * INV_SLOT_SIZE_PX); - int frame = plr[myplr].InvBody[slot]._iCurs + CURSOR_FIRSTITEM; + int frame = myPlayer.InvBody[slot]._iCurs + CURSOR_FIRSTITEM; int frameW; int frameH; @@ -224,16 +228,16 @@ void DrawInv(const CelOutputBuffer &out) const int celFrame = GetInvItemFrame(frame); if (pcursinvitem == slot) { - CelBlitOutlineTo(out, GetOutlineColor(plr[myplr].InvBody[slot], true), RIGHT_PANEL_X + screenX, screenY, cel, celFrame, false); + CelBlitOutlineTo(out, GetOutlineColor(myPlayer.InvBody[slot], true), RIGHT_PANEL_X + screenX, screenY, cel, celFrame, false); } - CelDrawItem(plr[myplr].InvBody[slot]._iStatFlag, out, RIGHT_PANEL_X + screenX, screenY, cel, celFrame); + CelDrawItem(myPlayer.InvBody[slot]._iStatFlag, out, RIGHT_PANEL_X + screenX, screenY, cel, celFrame); if (slot == INVLOC_HAND_LEFT) { - if (plr[myplr].InvBody[slot]._iLoc == ILOC_TWOHAND) { - if (plr[myplr]._pClass != HeroClass::Barbarian - || (plr[myplr].InvBody[slot]._itype != ITYPE_SWORD - && plr[myplr].InvBody[slot]._itype != ITYPE_MACE)) { + if (myPlayer.InvBody[slot]._iLoc == ILOC_TWOHAND) { + if (myPlayer._pClass != HeroClass::Barbarian + || (myPlayer.InvBody[slot]._itype != ITYPE_SWORD + && myPlayer.InvBody[slot]._itype != ITYPE_MACE)) { InvDrawSlotBack(out, RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].X, slotPos[INVLOC_HAND_RIGHT].Y, slotSize[INVLOC_HAND_RIGHT].X * INV_SLOT_SIZE_PX, slotSize[INVLOC_HAND_RIGHT].Y * INV_SLOT_SIZE_PX); light_table_index = 0; cel_transparency_active = true; @@ -250,7 +254,7 @@ void DrawInv(const CelOutputBuffer &out) } for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { - if (plr[myplr].InvGrid[i] != 0) { + if (myPlayer.InvGrid[i] != 0) { InvDrawSlotBack( out, InvRect[i + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, @@ -261,9 +265,9 @@ void DrawInv(const CelOutputBuffer &out) } for (int j = 0; j < NUM_INV_GRID_ELEM; j++) { - if (plr[myplr].InvGrid[j] > 0) { // first slot of an item - int ii = plr[myplr].InvGrid[j] - 1; - int frame = plr[myplr].InvList[ii]._iCurs + CURSOR_FIRSTITEM; + if (myPlayer.InvGrid[j] > 0) { // first slot of an item + int ii = myPlayer.InvGrid[j] - 1; + int frame = myPlayer.InvList[ii]._iCurs + CURSOR_FIRSTITEM; const auto &cel = GetInvItemSprite(frame); const int celFrame = GetInvItemFrame(frame); @@ -271,14 +275,14 @@ void DrawInv(const CelOutputBuffer &out) if (pcursinvitem == ii + INVITEM_INV_FIRST) { CelBlitOutlineTo( out, - GetOutlineColor(plr[myplr].InvList[ii], true), + GetOutlineColor(myPlayer.InvList[ii], true), InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, InvRect[j + SLOTXY_INV_FIRST].Y - 1, cel, celFrame, false); } CelDrawItem( - plr[myplr].InvList[ii]._iStatFlag, + myPlayer.InvList[ii]._iStatFlag, out, InvRect[j + SLOTXY_INV_FIRST].X + RIGHT_PANEL_X, InvRect[j + SLOTXY_INV_FIRST].Y - 1, @@ -295,28 +299,30 @@ void DrawInvBelt(const CelOutputBuffer &out) DrawPanelBox(out, 205, 21, 232, 28, PANEL_X + 205, PANEL_Y + 5); + auto &myPlayer = plr[myplr]; + for (int i = 0; i < MAXBELTITEMS; i++) { - if (plr[myplr].SpdList[i].isEmpty()) { + if (myPlayer.SpdList[i].isEmpty()) { continue; } InvDrawSlotBack(out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, INV_SLOT_SIZE_PX, INV_SLOT_SIZE_PX); - int frame = plr[myplr].SpdList[i]._iCurs + CURSOR_FIRSTITEM; + int frame = myPlayer.SpdList[i]._iCurs + CURSOR_FIRSTITEM; const auto &cel = GetInvItemSprite(frame); const int celFrame = GetInvItemFrame(frame); if (pcursinvitem == i + INVITEM_BELT_FIRST) { if (!sgbControllerActive || invflag) { - CelBlitOutlineTo(out, GetOutlineColor(plr[myplr].SpdList[i], true), InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame, false); + CelBlitOutlineTo(out, GetOutlineColor(myPlayer.SpdList[i], true), InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame, false); } } - CelDrawItem(plr[myplr].SpdList[i]._iStatFlag, out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame); + CelDrawItem(myPlayer.SpdList[i]._iStatFlag, out, InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X, InvRect[i + SLOTXY_BELT_FIRST].Y + PANEL_Y - 1, cel, celFrame); - if (AllItemsList[plr[myplr].SpdList[i].IDidx].iUsable - && plr[myplr].SpdList[i]._iStatFlag - && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) { + if (AllItemsList[myPlayer.SpdList[i].IDidx].iUsable + && myPlayer.SpdList[i]._iStatFlag + && myPlayer.SpdList[i]._itype != ITYPE_GOLD) { sprintf(tempstr, "%i", i + 1); SDL_Rect rect { InvRect[i + SLOTXY_BELT_FIRST].X + PANEL_X + INV_SLOT_SIZE_PX - GetLineWidth(tempstr), @@ -394,22 +400,22 @@ bool CanBePlacedOnBelt(const ItemStruct &item) * @brief Checks whether the given item can be placed on the specified player's belt. Returns 'True' when the item can be placed * on belt slots and the player has at least one empty slot in his belt. * If 'persistItem' is 'True', the item is also placed in the belt. - * @param playerNumber The player number on whose belt will be checked. + * @param player The player on whose belt will be checked. * @param item The item to be checked. * @param persistItem Pass 'True' to actually place the item in the belt. The default is 'False'. * @return 'True' in case the item can be placed on the player's belt and 'False' otherwise. */ -bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistItem) +bool AutoPlaceItemInBelt(PlayerStruct &player, const ItemStruct &item, bool persistItem) { if (!CanBePlacedOnBelt(item)) { return false; } - for (auto &beltItem : plr[playerNumber].SpdList) { + for (auto &beltItem : player.SpdList) { if (beltItem.isEmpty()) { if (persistItem) { beltItem = item; - plr[playerNumber].CalcScrolls(); + player.CalcScrolls(); drawsbarflag = true; } @@ -435,17 +441,16 @@ bool CanEquip(const ItemStruct &item) /** * @brief A specialized version of 'CanEquip(int, ItemStruct&, int)' that specifically checks whether the item can be equipped * in one/both of the player's hands. - * @param playerNumber The player number whose inventory will be checked for compatibility with the item. + * @param player The player whose inventory will be checked for compatibility with the item. * @param item The item to check. * @return 'True' if the player can currently equip the item in either one of his hands (i.e. the required hands are empty and * allow the item), and 'False' otherwise. */ -bool CanWield(int playerNumber, const ItemStruct &item) +bool CanWield(PlayerStruct &player, const ItemStruct &item) { if (!CanEquip(item) || (item._iLoc != ILOC_ONEHAND && item._iLoc != ILOC_TWOHAND)) return false; - auto &player = plr[playerNumber]; ItemStruct &leftHandItem = player.InvBody[INVLOC_HAND_LEFT]; ItemStruct &rightHandItem = player.InvBody[INVLOC_HAND_RIGHT]; @@ -487,15 +492,14 @@ bool CanWield(int playerNumber, const ItemStruct &item) /** * @brief Checks whether the specified item can be equipped in the desired body location on the player. - * @param playerNumber The player number whose inventory will be checked for compatibility with the item. + * @param player The player whose inventory will be checked for compatibility with the item. * @param item The item to check. * @param bodyLocation The location in the inventory to be checked against. * @return 'True' if the player can currently equip the item in the specified body location (i.e. the body location is empty and * allows the item), and 'False' otherwise. */ -bool CanEquip(int playerNumber, const ItemStruct &item, inv_body_loc bodyLocation) +bool CanEquip(PlayerStruct &player, const ItemStruct &item, inv_body_loc bodyLocation) { - auto &player = plr[playerNumber]; if (!CanEquip(item) || player._pmode > PM_WALK3 || !player.InvBody[bodyLocation].isEmpty()) { return false; } @@ -509,7 +513,7 @@ bool CanEquip(int playerNumber, const ItemStruct &item, inv_body_loc bodyLocatio case INVLOC_HAND_LEFT: case INVLOC_HAND_RIGHT: - return CanWield(playerNumber, item); + return CanWield(player, item); case INVLOC_HEAD: return item._iLoc == ILOC_HELM; @@ -526,28 +530,30 @@ bool CanEquip(int playerNumber, const ItemStruct &item, inv_body_loc bodyLocatio /** * @brief Automatically attempts to equip the specified item in a specific location in the player's body. * @note On success, this will broadcast an equipment_change event to let other players know about the equipment change. - * @param playerNumber The player number whose inventory will be checked for compatibility with the item. + * @param playerId The player number whose inventory will be checked for compatibility with the item. * @param item The item to equip. * @param bodyLocation The location in the inventory where the item should be equipped. * @param persistItem Indicates whether or not the item should be persisted in the player's body. Pass 'False' to check * whether the player can equip the item but you don't want the item to actually be equipped. 'True' by default. * @return 'True' if the item was equipped and 'False' otherwise. */ -bool AutoEquip(int playerNumber, const ItemStruct &item, inv_body_loc bodyLocation, bool persistItem) +bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation, bool persistItem) { - if (!CanEquip(playerNumber, item, bodyLocation)) { + auto &player = plr[playerId]; + + if (!CanEquip(player, item, bodyLocation)) { return false; } if (persistItem) { - plr[playerNumber].InvBody[bodyLocation] = item; + player.InvBody[bodyLocation] = item; - if (sgOptions.Audio.bAutoEquipSound && playerNumber == myplr) { + if (sgOptions.Audio.bAutoEquipSound && playerId == myplr) { PlaySFX(ItemInvSnds[ItemCAnimTbl[item._iCurs]]); } NetSendCmdChItem(false, bodyLocation); - CalcPlrInv(playerNumber, true); + CalcPlrInv(playerId, true); } return true; @@ -793,7 +799,9 @@ int SwapItem(ItemStruct *a, ItemStruct *b) void CheckInvPaste(int pnum, int mx, int my) { - SetICursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); + auto &player = plr[pnum]; + + SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); int i = mx + (icursW / 2); int j = my + (icursH / 2); int sx = icursW28; @@ -840,24 +848,24 @@ void CheckInvPaste(int pnum, int mx, int my) if (r >= SLOTXY_BELT_FIRST && r <= SLOTXY_BELT_LAST) il = ILOC_BELT; - done = plr[pnum].HoldItem._iLoc == il; + done = player.HoldItem._iLoc == il; - if (il == ILOC_ONEHAND && plr[pnum].HoldItem._iLoc == ILOC_TWOHAND) { - if (plr[pnum]._pClass == HeroClass::Barbarian - && (plr[pnum].HoldItem._itype == ITYPE_SWORD || plr[pnum].HoldItem._itype == ITYPE_MACE)) + if (il == ILOC_ONEHAND && player.HoldItem._iLoc == ILOC_TWOHAND) { + if (player._pClass == HeroClass::Barbarian + && (player.HoldItem._itype == ITYPE_SWORD || player.HoldItem._itype == ITYPE_MACE)) il = ILOC_ONEHAND; else il = ILOC_TWOHAND; done = true; } - if (plr[pnum].HoldItem._iLoc == ILOC_UNEQUIPABLE && il == ILOC_BELT) { + if (player.HoldItem._iLoc == ILOC_UNEQUIPABLE && il == ILOC_BELT) { if (sx == 1 && sy == 1) { done = true; - if (!AllItemsList[plr[pnum].HoldItem.IDidx].iUsable) + if (!AllItemsList[player.HoldItem.IDidx].iUsable) done = false; - if (!plr[pnum].HoldItem._iStatFlag) + if (!player.HoldItem._iStatFlag) done = false; - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) + if (player.HoldItem._itype == ITYPE_GOLD) done = false; } } @@ -866,13 +874,13 @@ void CheckInvPaste(int pnum, int mx, int my) if (il == ILOC_UNEQUIPABLE) { done = true; int ii = r - SLOTXY_INV_FIRST; - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) { + if (player.HoldItem._itype == ITYPE_GOLD) { int yy = 10 * (ii / 10); int xx = ii % 10; - if (plr[pnum].InvGrid[xx + yy] != 0) { - int iv = plr[pnum].InvGrid[xx + yy]; + if (player.InvGrid[xx + yy] != 0) { + int iv = player.InvGrid[xx + yy]; if (iv > 0) { - if (plr[pnum].InvList[iv - 1]._itype != ITYPE_GOLD) { + if (player.InvList[iv - 1]._itype != ITYPE_GOLD) { it = iv; } } else { @@ -893,8 +901,8 @@ void CheckInvPaste(int pnum, int mx, int my) if (xx >= 10) { done = false; } else { - if (plr[pnum].InvGrid[xx + yy] != 0) { - int iv = plr[pnum].InvGrid[xx + yy]; + if (player.InvGrid[xx + yy] != 0) { + int iv = player.InvGrid[xx + yy]; if (iv < 0) iv = -iv; if (it != 0) { @@ -915,199 +923,199 @@ void CheckInvPaste(int pnum, int mx, int my) if (!done) return; - if (il != ILOC_UNEQUIPABLE && il != ILOC_BELT && !plr[pnum].HoldItem._iStatFlag) { + if (il != ILOC_UNEQUIPABLE && il != ILOC_BELT && !player.HoldItem._iStatFlag) { done = false; - plr[pnum].Say(HeroSpeech::ICantUseThisYet); + player.Say(HeroSpeech::ICantUseThisYet); } if (!done) return; if (pnum == myplr) - PlaySFX(ItemInvSnds[ItemCAnimTbl[plr[pnum].HoldItem._iCurs]]); + PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]); int cn = CURSOR_HAND; switch (il) { case ILOC_HELM: NetSendCmdChItem(false, INVLOC_HEAD); - if (plr[pnum].InvBody[INVLOC_HEAD].isEmpty()) - plr[pnum].InvBody[INVLOC_HEAD] = plr[pnum].HoldItem; + if (player.InvBody[INVLOC_HEAD].isEmpty()) + player.InvBody[INVLOC_HEAD] = player.HoldItem; else - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HEAD], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HEAD], &player.HoldItem); break; case ILOC_RING: if (r == SLOTXY_RING_LEFT) { NetSendCmdChItem(false, INVLOC_RING_LEFT); - if (plr[pnum].InvBody[INVLOC_RING_LEFT].isEmpty()) - plr[pnum].InvBody[INVLOC_RING_LEFT] = plr[pnum].HoldItem; + if (player.InvBody[INVLOC_RING_LEFT].isEmpty()) + player.InvBody[INVLOC_RING_LEFT] = player.HoldItem; else - cn = SwapItem(&plr[pnum].InvBody[INVLOC_RING_LEFT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_RING_LEFT], &player.HoldItem); } else { NetSendCmdChItem(false, INVLOC_RING_RIGHT); - if (plr[pnum].InvBody[INVLOC_RING_RIGHT].isEmpty()) - plr[pnum].InvBody[INVLOC_RING_RIGHT] = plr[pnum].HoldItem; + if (player.InvBody[INVLOC_RING_RIGHT].isEmpty()) + player.InvBody[INVLOC_RING_RIGHT] = player.HoldItem; else - cn = SwapItem(&plr[pnum].InvBody[INVLOC_RING_RIGHT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_RING_RIGHT], &player.HoldItem); } break; case ILOC_AMULET: NetSendCmdChItem(false, INVLOC_AMULET); - if (plr[pnum].InvBody[INVLOC_AMULET].isEmpty()) - plr[pnum].InvBody[INVLOC_AMULET] = plr[pnum].HoldItem; + if (player.InvBody[INVLOC_AMULET].isEmpty()) + player.InvBody[INVLOC_AMULET] = player.HoldItem; else - cn = SwapItem(&plr[pnum].InvBody[INVLOC_AMULET], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_AMULET], &player.HoldItem); break; case ILOC_ONEHAND: if (r <= SLOTXY_HAND_LEFT_LAST) { - if (plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty()) { - if ((plr[pnum].InvBody[INVLOC_HAND_RIGHT].isEmpty() || plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iClass != plr[pnum].HoldItem._iClass) - || (plr[pnum]._pClass == HeroClass::Bard && plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON && plr[pnum].HoldItem._iClass == ICLASS_WEAPON)) { + if (player.InvBody[INVLOC_HAND_LEFT].isEmpty()) { + if ((player.InvBody[INVLOC_HAND_RIGHT].isEmpty() || player.InvBody[INVLOC_HAND_RIGHT]._iClass != player.HoldItem._iClass) + || (player._pClass == HeroClass::Bard && player.InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON)) { NetSendCmdChItem(false, INVLOC_HAND_LEFT); - plr[pnum].InvBody[INVLOC_HAND_LEFT] = plr[pnum].HoldItem; + player.InvBody[INVLOC_HAND_LEFT] = player.HoldItem; } else { NetSendCmdChItem(false, INVLOC_HAND_RIGHT); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_RIGHT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HAND_RIGHT], &player.HoldItem); } break; } - if ((plr[pnum].InvBody[INVLOC_HAND_RIGHT].isEmpty() || plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iClass != plr[pnum].HoldItem._iClass) - || (plr[pnum]._pClass == HeroClass::Bard && plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON && plr[pnum].HoldItem._iClass == ICLASS_WEAPON)) { + if ((player.InvBody[INVLOC_HAND_RIGHT].isEmpty() || player.InvBody[INVLOC_HAND_RIGHT]._iClass != player.HoldItem._iClass) + || (player._pClass == HeroClass::Bard && player.InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON)) { NetSendCmdChItem(false, INVLOC_HAND_LEFT); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_LEFT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HAND_LEFT], &player.HoldItem); break; } NetSendCmdChItem(false, INVLOC_HAND_RIGHT); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_RIGHT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HAND_RIGHT], &player.HoldItem); break; } - if (plr[pnum].InvBody[INVLOC_HAND_RIGHT].isEmpty()) { - if ((plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty() || plr[pnum].InvBody[INVLOC_HAND_LEFT]._iLoc != ILOC_TWOHAND) - || (plr[pnum]._pClass == HeroClass::Barbarian && (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE))) { - if ((plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty() || plr[pnum].InvBody[INVLOC_HAND_LEFT]._iClass != plr[pnum].HoldItem._iClass) - || (plr[pnum]._pClass == HeroClass::Bard && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON && plr[pnum].HoldItem._iClass == ICLASS_WEAPON)) { + if (player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { + if ((player.InvBody[INVLOC_HAND_LEFT].isEmpty() || player.InvBody[INVLOC_HAND_LEFT]._iLoc != ILOC_TWOHAND) + || (player._pClass == HeroClass::Barbarian && (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE))) { + if ((player.InvBody[INVLOC_HAND_LEFT].isEmpty() || player.InvBody[INVLOC_HAND_LEFT]._iClass != player.HoldItem._iClass) + || (player._pClass == HeroClass::Bard && player.InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON)) { NetSendCmdChItem(false, INVLOC_HAND_RIGHT); - plr[pnum].InvBody[INVLOC_HAND_RIGHT] = plr[pnum].HoldItem; + player.InvBody[INVLOC_HAND_RIGHT] = player.HoldItem; break; } NetSendCmdChItem(false, INVLOC_HAND_LEFT); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_LEFT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HAND_LEFT], &player.HoldItem); break; } NetSendCmdDelItem(false, INVLOC_HAND_LEFT); NetSendCmdChItem(false, INVLOC_HAND_RIGHT); - SwapItem(&plr[pnum].InvBody[INVLOC_HAND_RIGHT], &plr[pnum].InvBody[INVLOC_HAND_LEFT]); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_RIGHT], &plr[pnum].HoldItem); + SwapItem(&player.InvBody[INVLOC_HAND_RIGHT], &player.InvBody[INVLOC_HAND_LEFT]); + cn = SwapItem(&player.InvBody[INVLOC_HAND_RIGHT], &player.HoldItem); break; } - if ((!plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty() && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iClass == plr[pnum].HoldItem._iClass) - && !(plr[pnum]._pClass == HeroClass::Bard && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON && plr[pnum].HoldItem._iClass == ICLASS_WEAPON)) { + if ((!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._iClass == player.HoldItem._iClass) + && !(player._pClass == HeroClass::Bard && player.InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON)) { NetSendCmdChItem(false, INVLOC_HAND_LEFT); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_LEFT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HAND_LEFT], &player.HoldItem); break; } NetSendCmdChItem(false, INVLOC_HAND_RIGHT); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_RIGHT], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_HAND_RIGHT], &player.HoldItem); break; case ILOC_TWOHAND: - if (!plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty() && !plr[pnum].InvBody[INVLOC_HAND_RIGHT].isEmpty()) { - ItemStruct tempitem = plr[pnum].HoldItem; - if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) - plr[pnum].HoldItem = plr[pnum].InvBody[INVLOC_HAND_RIGHT]; + if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && !player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { + ItemStruct tempitem = player.HoldItem; + if (player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) + player.HoldItem = player.InvBody[INVLOC_HAND_RIGHT]; else - plr[pnum].HoldItem = plr[pnum].InvBody[INVLOC_HAND_LEFT]; + player.HoldItem = player.InvBody[INVLOC_HAND_LEFT]; if (pnum == myplr) - NewCursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); else - SetICursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); - bool done2h = AutoPlaceItemInInventory(plr[pnum], plr[pnum].HoldItem, true); - plr[pnum].HoldItem = tempitem; + SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); + bool done2h = AutoPlaceItemInInventory(player, player.HoldItem, true); + player.HoldItem = tempitem; if (pnum == myplr) - NewCursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); else - SetICursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); + SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); if (!done2h) return; - if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) - plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; + if (player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) + player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; else - plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; + player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; } NetSendCmdDelItem(false, INVLOC_HAND_RIGHT); - if (!plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty() || !plr[pnum].InvBody[INVLOC_HAND_RIGHT].isEmpty()) { + if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() || !player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { NetSendCmdChItem(false, INVLOC_HAND_LEFT); - if (plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty()) - SwapItem(&plr[pnum].InvBody[INVLOC_HAND_LEFT], &plr[pnum].InvBody[INVLOC_HAND_RIGHT]); - cn = SwapItem(&plr[pnum].InvBody[INVLOC_HAND_LEFT], &plr[pnum].HoldItem); + if (player.InvBody[INVLOC_HAND_LEFT].isEmpty()) + SwapItem(&player.InvBody[INVLOC_HAND_LEFT], &player.InvBody[INVLOC_HAND_RIGHT]); + cn = SwapItem(&player.InvBody[INVLOC_HAND_LEFT], &player.HoldItem); } else { NetSendCmdChItem(false, INVLOC_HAND_LEFT); - plr[pnum].InvBody[INVLOC_HAND_LEFT] = plr[pnum].HoldItem; + player.InvBody[INVLOC_HAND_LEFT] = player.HoldItem; } - if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_STAFF && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iSpell != SPL_NULL && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iCharges > 0) { - plr[pnum]._pRSpell = plr[pnum].InvBody[INVLOC_HAND_LEFT]._iSpell; - plr[pnum]._pRSplType = RSPLTYPE_CHARGES; + if (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_STAFF && player.InvBody[INVLOC_HAND_LEFT]._iSpell != SPL_NULL && player.InvBody[INVLOC_HAND_LEFT]._iCharges > 0) { + player._pRSpell = player.InvBody[INVLOC_HAND_LEFT]._iSpell; + player._pRSplType = RSPLTYPE_CHARGES; force_redraw = 255; } break; case ILOC_ARMOR: NetSendCmdChItem(false, INVLOC_CHEST); - if (plr[pnum].InvBody[INVLOC_CHEST].isEmpty()) - plr[pnum].InvBody[INVLOC_CHEST] = plr[pnum].HoldItem; + if (player.InvBody[INVLOC_CHEST].isEmpty()) + player.InvBody[INVLOC_CHEST] = player.HoldItem; else - cn = SwapItem(&plr[pnum].InvBody[INVLOC_CHEST], &plr[pnum].HoldItem); + cn = SwapItem(&player.InvBody[INVLOC_CHEST], &player.HoldItem); break; case ILOC_UNEQUIPABLE: - if (plr[pnum].HoldItem._itype == ITYPE_GOLD && it == 0) { + if (player.HoldItem._itype == ITYPE_GOLD && it == 0) { int ii = r - SLOTXY_INV_FIRST; int yy = 10 * (ii / 10); int xx = ii % 10; - if (plr[pnum].InvGrid[yy + xx] > 0) { - int il = plr[pnum].InvGrid[yy + xx] - 1; - int gt = plr[pnum].InvList[il]._ivalue; - int ig = plr[pnum].HoldItem._ivalue + gt; + if (player.InvGrid[yy + xx] > 0) { + int il = player.InvGrid[yy + xx] - 1; + int gt = player.InvList[il]._ivalue; + int ig = player.HoldItem._ivalue + gt; if (ig <= MaxGold) { - plr[pnum].InvList[il]._ivalue = ig; - plr[pnum]._pGold += plr[pnum].HoldItem._ivalue; - SetPlrHandGoldCurs(&plr[pnum].InvList[il]); + player.InvList[il]._ivalue = ig; + player._pGold += player.HoldItem._ivalue; + SetPlrHandGoldCurs(&player.InvList[il]); } else { ig = MaxGold - gt; - plr[pnum]._pGold += ig; - plr[pnum].HoldItem._ivalue -= ig; - plr[pnum].InvList[il]._ivalue = MaxGold; - plr[pnum].InvList[il]._iCurs = ICURS_GOLD_LARGE; + player._pGold += ig; + player.HoldItem._ivalue -= ig; + player.InvList[il]._ivalue = MaxGold; + player.InvList[il]._iCurs = ICURS_GOLD_LARGE; // BUGFIX: incorrect values here are leftover from beta (fixed) - cn = GetGoldCursor(plr[pnum].HoldItem._ivalue); + cn = GetGoldCursor(player.HoldItem._ivalue); cn += CURSOR_FIRSTITEM; } } else { - int il = plr[pnum]._pNumInv; - plr[pnum].InvList[il] = plr[pnum].HoldItem; - plr[pnum]._pNumInv++; - plr[pnum].InvGrid[yy + xx] = plr[pnum]._pNumInv; - plr[pnum]._pGold += plr[pnum].HoldItem._ivalue; - SetPlrHandGoldCurs(&plr[pnum].InvList[il]); + int il = player._pNumInv; + player.InvList[il] = player.HoldItem; + player._pNumInv++; + player.InvGrid[yy + xx] = player._pNumInv; + player._pGold += player.HoldItem._ivalue; + SetPlrHandGoldCurs(&player.InvList[il]); } } else { if (it == 0) { - plr[pnum].InvList[plr[pnum]._pNumInv] = plr[pnum].HoldItem; - plr[pnum]._pNumInv++; - it = plr[pnum]._pNumInv; + player.InvList[player._pNumInv] = player.HoldItem; + player._pNumInv++; + it = player._pNumInv; } else { int il = it - 1; - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) - plr[pnum]._pGold += plr[pnum].HoldItem._ivalue; - cn = SwapItem(&plr[pnum].InvList[il], &plr[pnum].HoldItem); - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) - plr[pnum]._pGold = CalculateGold(plr[pnum]); + if (player.HoldItem._itype == ITYPE_GOLD) + player._pGold += player.HoldItem._ivalue; + cn = SwapItem(&player.InvList[il], &player.HoldItem); + if (player.HoldItem._itype == ITYPE_GOLD) + player._pGold = CalculateGold(player); for (i = 0; i < NUM_INV_GRID_ELEM; i++) { - if (plr[pnum].InvGrid[i] == it) - plr[pnum].InvGrid[i] = 0; - if (plr[pnum].InvGrid[i] == -it) - plr[pnum].InvGrid[i] = 0; + if (player.InvGrid[i] == it) + player.InvGrid[i] = 0; + if (player.InvGrid[i] == -it) + player.InvGrid[i] = 0; } } int ii = r - SLOTXY_INV_FIRST; @@ -1116,44 +1124,44 @@ void CheckInvPaste(int pnum, int mx, int my) int xx = std::max(ii % 10 - ((sx - 1) / 2), 0); int yy = std::max(10 * (ii / 10 - ((sy - 1) / 2)), 0); - AddItemToInvGrid(plr[pnum], xx + yy, it, sx, sy); + AddItemToInvGrid(player, xx + yy, it, sx, sy); } break; case ILOC_BELT: { int ii = r - SLOTXY_BELT_FIRST; - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) { - if (!plr[pnum].SpdList[ii].isEmpty()) { - if (plr[pnum].SpdList[ii]._itype == ITYPE_GOLD) { - i = plr[pnum].HoldItem._ivalue + plr[pnum].SpdList[ii]._ivalue; + if (player.HoldItem._itype == ITYPE_GOLD) { + if (!player.SpdList[ii].isEmpty()) { + if (player.SpdList[ii]._itype == ITYPE_GOLD) { + i = player.HoldItem._ivalue + player.SpdList[ii]._ivalue; if (i <= MaxGold) { - plr[pnum].SpdList[ii]._ivalue = i; - plr[pnum]._pGold += plr[pnum].HoldItem._ivalue; - SetPlrHandGoldCurs(&plr[pnum].SpdList[ii]); + player.SpdList[ii]._ivalue = i; + player._pGold += player.HoldItem._ivalue; + SetPlrHandGoldCurs(&player.SpdList[ii]); } else { - i = MaxGold - plr[pnum].SpdList[ii]._ivalue; - plr[pnum]._pGold += i; - plr[pnum].HoldItem._ivalue -= i; - plr[pnum].SpdList[ii]._ivalue = MaxGold; - plr[pnum].SpdList[ii]._iCurs = ICURS_GOLD_LARGE; + i = MaxGold - player.SpdList[ii]._ivalue; + player._pGold += i; + player.HoldItem._ivalue -= i; + player.SpdList[ii]._ivalue = MaxGold; + player.SpdList[ii]._iCurs = ICURS_GOLD_LARGE; // BUGFIX: incorrect values here are leftover from beta (fixed) - cn = GetGoldCursor(plr[pnum].HoldItem._ivalue); + cn = GetGoldCursor(player.HoldItem._ivalue); cn += CURSOR_FIRSTITEM; } } else { - plr[pnum]._pGold += plr[pnum].HoldItem._ivalue; - cn = SwapItem(&plr[pnum].SpdList[ii], &plr[pnum].HoldItem); + player._pGold += player.HoldItem._ivalue; + cn = SwapItem(&player.SpdList[ii], &player.HoldItem); } } else { - plr[pnum].SpdList[ii] = plr[pnum].HoldItem; - plr[pnum]._pGold += plr[pnum].HoldItem._ivalue; + player.SpdList[ii] = player.HoldItem; + player._pGold += player.HoldItem._ivalue; } - } else if (plr[pnum].SpdList[ii].isEmpty()) { - plr[pnum].SpdList[ii] = plr[pnum].HoldItem; + } else if (player.SpdList[ii].isEmpty()) { + player.SpdList[ii] = player.HoldItem; } else { - cn = SwapItem(&plr[pnum].SpdList[ii], &plr[pnum].HoldItem); - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) - plr[pnum]._pGold = CalculateGold(plr[pnum]); + cn = SwapItem(&player.SpdList[ii], &player.HoldItem); + if (player.HoldItem._itype == ITYPE_GOLD) + player._pGold = CalculateGold(player); } drawsbarflag = true; } break; @@ -1175,6 +1183,7 @@ void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId RecreateItem(MAXITEMS, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0); auto &player = plr[pnum]; + player.HoldItem = items[MAXITEMS]; if (bId) { @@ -1347,14 +1356,14 @@ void CheckInvCut(int pnum, int mx, int my, bool automaticMove) holdItem = player.InvList[iv - 1]; if (automaticMove) { if (CanBePlacedOnBelt(holdItem)) { - automaticallyMoved = AutoPlaceItemInBelt(pnum, holdItem, true); + automaticallyMoved = AutoPlaceItemInBelt(player, holdItem, true); } else { automaticallyMoved = automaticallyEquipped = AutoEquip(pnum, holdItem); } } if (!automaticMove || automaticallyMoved) { - plr[pnum].RemoveInvItem(iv - 1, false); + player.RemoveInvItem(iv - 1, false); } } } @@ -1409,19 +1418,13 @@ void CheckInvCut(int pnum, int mx, int my, bool automaticMove) void inv_update_rem_item(int pnum, BYTE iv) { + auto &player = plr[pnum]; + if (iv < NUM_INVLOC) { - plr[pnum].InvBody[iv]._itype = ITYPE_NONE; + player.InvBody[iv]._itype = ITYPE_NONE; } - CalcPlrInv(pnum, plr[pnum]._pmode != PM_DEATH); -} - -void RemoveSpdBarItem(int pnum, int iv) -{ - plr[pnum].SpdList[iv]._itype = ITYPE_NONE; - - plr[pnum].CalcScrolls(); - force_redraw = 255; + CalcPlrInv(pnum, player._pmode != PM_DEATH); } void CheckInvItem(bool isShiftHeld) @@ -1520,6 +1523,8 @@ static void CheckNaKrulNotes(PlayerStruct &player) static void CheckQuestItem(PlayerStruct &player) { + auto &myPlayer = plr[myplr]; + if (player.HoldItem.IDidx == IDI_OPTAMULET && quests[Q_BLIND]._qactive == QUEST_ACTIVE) quests[Q_BLIND]._qactive = QUEST_DONE; @@ -1533,12 +1538,12 @@ static void CheckQuestItem(PlayerStruct &player) quests[Q_ANVIL]._qactive = QUEST_ACTIVE; } if (quests[Q_ANVIL]._qlog) { - plr[myplr].Say(HeroSpeech::INeedToGetThisToGriswold, 10); + myPlayer.Say(HeroSpeech::INeedToGetThisToGriswold, 10); } } if (player.HoldItem.IDidx == IDI_GLDNELIX && quests[Q_VEIL]._qactive != QUEST_NOTAVAIL) { - plr[myplr].Say(HeroSpeech::INeedToGetThisToLachdanan, 30); + myPlayer.Say(HeroSpeech::INeedToGetThisToLachdanan, 30); } if (player.HoldItem.IDidx == IDI_ROCK && quests[Q_ROCK]._qactive != QUEST_NOTAVAIL) { @@ -1546,13 +1551,13 @@ static void CheckQuestItem(PlayerStruct &player) quests[Q_ROCK]._qactive = QUEST_ACTIVE; } if (quests[Q_ROCK]._qlog) { - plr[myplr].Say(HeroSpeech::ThisMustBeWhatGriswoldWanted, 10); + myPlayer.Say(HeroSpeech::ThisMustBeWhatGriswoldWanted, 10); } } if (player.HoldItem.IDidx == IDI_ARMOFVAL && quests[Q_BLOOD]._qactive == QUEST_ACTIVE) { quests[Q_BLOOD]._qactive = QUEST_DONE; - plr[myplr].Say(HeroSpeech::MayTheSpiritOfArkaineProtectMe, 20); + myPlayer.Say(HeroSpeech::MayTheSpiritOfArkaineProtectMe, 20); } if (player.HoldItem.IDidx == IDI_MAPOFDOOM) { @@ -1600,21 +1605,23 @@ void InvGetItem(int pnum, ItemStruct *item, int ii) if (dItem[item->position.x][item->position.y] == 0) return; + auto &player = plr[pnum]; + if (myplr == pnum && pcurs >= CURSOR_FIRSTITEM) - NetSendCmdPItem(true, CMD_SYNCPUTITEM, plr[myplr].position.tile); + NetSendCmdPItem(true, CMD_SYNCPUTITEM, player.position.tile); item->_iCreateInfo &= ~CF_PREGEN; - plr[pnum].HoldItem = *item; - CheckQuestItem(plr[pnum]); - CheckBookLevel(plr[pnum]); - CheckItemStats(plr[pnum]); + player.HoldItem = *item; + CheckQuestItem(player); + CheckBookLevel(player); + CheckItemStats(player); bool cursorUpdated = false; - if (plr[pnum].HoldItem._itype == ITYPE_GOLD && GoldAutoPlace(plr[pnum])) + if (player.HoldItem._itype == ITYPE_GOLD && GoldAutoPlace(player)) cursorUpdated = true; CleanupItems(item, ii); pcursitem = -1; if (!cursorUpdated) - NewCursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); } void AutoGetItem(int pnum, ItemStruct *item, int ii) @@ -1633,25 +1640,27 @@ void AutoGetItem(int pnum, ItemStruct *item, int ii) if (dItem[item->position.x][item->position.y] == 0) return; + auto &player = plr[pnum]; + item->_iCreateInfo &= ~CF_PREGEN; - plr[pnum].HoldItem = *item; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug - CheckQuestItem(plr[pnum]); - CheckBookLevel(plr[pnum]); - CheckItemStats(plr[pnum]); - SetICursor(plr[pnum].HoldItem._iCurs + CURSOR_FIRSTITEM); - if (plr[pnum].HoldItem._itype == ITYPE_GOLD) { - done = GoldAutoPlace(plr[pnum]); + player.HoldItem = *item; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug + CheckQuestItem(player); + CheckBookLevel(player); + CheckItemStats(player); + SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); + if (player.HoldItem._itype == ITYPE_GOLD) { + done = GoldAutoPlace(player); if (!done) { - item->_ivalue = plr[pnum].HoldItem._ivalue; + item->_ivalue = player.HoldItem._ivalue; SetPlrHandGoldCurs(item); } } else { - done = AutoEquipEnabled(plr[pnum], plr[pnum].HoldItem) && AutoEquip(pnum, plr[pnum].HoldItem); + done = AutoEquipEnabled(player, player.HoldItem) && AutoEquip(pnum, player.HoldItem); if (!done) { - done = AutoPlaceItemInBelt(pnum, plr[pnum].HoldItem, true); + done = AutoPlaceItemInBelt(player, player.HoldItem, true); } if (!done) { - done = AutoPlaceItemInInventory(plr[pnum], plr[pnum].HoldItem, true); + done = AutoPlaceItemInInventory(player, player.HoldItem, true); } } @@ -1661,12 +1670,12 @@ void AutoGetItem(int pnum, ItemStruct *item, int ii) } if (pnum == myplr) { - plr[pnum].Say(HeroSpeech::ICantCarryAnymore); + player.Say(HeroSpeech::ICantCarryAnymore); } - plr[pnum].HoldItem = *item; + player.HoldItem = *item; RespawnItem(item, true); NetSendCmdPItem(true, CMD_RESPAWNITEM, item->position); - plr[pnum].HoldItem._itype = ITYPE_NONE; + player.HoldItem._itype = ITYPE_NONE; } int FindGetItem(int idx, uint16_t ci, int iseed) @@ -1754,23 +1763,25 @@ bool TryInvPut() if (numitems >= MAXITEMS) return false; - Direction dir = GetDirection(plr[myplr].position.tile, { cursmx, cursmy }); - Point position = plr[myplr].position.tile + dir; + auto &myPlayer = plr[myplr]; + + Direction dir = GetDirection(myPlayer.position.tile, { cursmx, cursmy }); + Point position = myPlayer.position.tile + dir; if (CanPut(position.x, position.y)) { return true; } - position = plr[myplr].position.tile + left[dir]; + position = myPlayer.position.tile + left[dir]; if (CanPut(position.x, position.y)) { return true; } - position = plr[myplr].position.tile + right[dir]; + position = myPlayer.position.tile + right[dir]; if (CanPut(position.x, position.y)) { return true; } - return CanPut(plr[myplr].position.tile.x, plr[myplr].position.tile.y); + return CanPut(myPlayer.position.tile.x, myPlayer.position.tile.y); } void DrawInvMsg(const char *msg) @@ -1782,34 +1793,34 @@ void DrawInvMsg(const char *msg) } } -static bool PutItem(int pnum, Point &position) +static bool PutItem(PlayerStruct &player, Point &position) { if (numitems >= MAXITEMS) return false; - auto relativePosition = position - plr[pnum].position.tile; + auto relativePosition = position - player.position.tile; - Direction d = GetDirection(plr[pnum].position.tile, position); + Direction d = GetDirection(player.position.tile, position); if (abs(relativePosition.x) > 1 || abs(relativePosition.y) > 1) { - position = plr[pnum].position.tile + d; + position = player.position.tile + d; } if (CanPut(position.x, position.y)) return true; - position = plr[pnum].position.tile + left[d]; + position = player.position.tile + left[d]; if (CanPut(position.x, position.y)) return true; - position = plr[pnum].position.tile + right[d]; + position = player.position.tile + right[d]; if (CanPut(position.x, position.y)) return true; for (int l = 1; l < 50; l++) { for (int j = -l; j <= l; j++) { - int yp = j + plr[pnum].position.tile.y; + int yp = j + player.position.tile.y; for (int i = -l; i <= l; i++) { - int xp = i + plr[pnum].position.tile.x; + int xp = i + player.position.tile.x; if (!CanPut(xp, yp)) continue; @@ -1822,17 +1833,17 @@ static bool PutItem(int pnum, Point &position) return false; } -int InvPutItem(int pnum, Point position) +int InvPutItem(PlayerStruct &player, Point position) { - if (!PutItem(pnum, position)) + if (!PutItem(player, position)) return -1; if (currlevel == 0) { int yp = cursmy; int xp = cursmx; - if (plr[pnum].HoldItem._iCurs == ICURS_RUNE_BOMB && xp >= 79 && xp <= 82 && yp >= 61 && yp <= 64) { - Point relativePosition = position - plr[pnum].position.tile; - NetSendCmdLocParam2(false, CMD_OPENHIVE, plr[pnum].position.tile, relativePosition.x, relativePosition.y); + if (player.HoldItem._iCurs == ICURS_RUNE_BOMB && xp >= 79 && xp <= 82 && yp >= 61 && yp <= 64) { + Point relativePosition = position - player.position.tile; + NetSendCmdLocParam2(false, CMD_OPENHIVE, player.position.tile, relativePosition.x, relativePosition.y); quests[Q_FARMER]._qactive = QUEST_DONE; if (gbIsMultiplayer) { NetSendCmdQuest(true, Q_FARMER); @@ -1840,7 +1851,7 @@ int InvPutItem(int pnum, Point position) } return -1; } - if (plr[pnum].HoldItem.IDidx == IDI_MAPOFDOOM && xp >= 35 && xp <= 38 && yp >= 20 && yp <= 24) { + if (player.HoldItem.IDidx == IDI_MAPOFDOOM && xp >= 35 && xp <= 38 && yp >= 20 && yp <= 24) { NetSendCmd(false, CMD_OPENCRYPT); quests[Q_GRAVE]._qactive = QUEST_DONE; if (gbIsMultiplayer) { @@ -1855,7 +1866,7 @@ int InvPutItem(int pnum, Point position) int ii = AllocateItem(); dItem[position.x][position.y] = ii + 1; - items[ii] = plr[pnum].HoldItem; + items[ii] = player.HoldItem; items[ii].position = position; RespawnItem(&items[ii], true); @@ -1870,9 +1881,9 @@ int InvPutItem(int pnum, Point position) return ii; } -int SyncPutItem(int pnum, Point position, int idx, uint16_t icreateinfo, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac) +int SyncPutItem(PlayerStruct &player, Point position, int idx, uint16_t icreateinfo, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac) { - if (!PutItem(pnum, position)) + if (!PutItem(player, position)) return -1; assert(CanPut(position.x, position.y)); @@ -1938,6 +1949,7 @@ char CheckInvHLight() infoclr = UIS_SILVER; ItemStruct *pi = nullptr; auto &myPlayer = plr[myplr]; + ClearPanel(); if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) { rv = INVLOC_HEAD; @@ -2008,21 +2020,23 @@ char CheckInvHLight() void RemoveScroll(int pnum) { - for (int i = 0; i < plr[pnum]._pNumInv; i++) { - if (!plr[pnum].InvList[i].isEmpty() - && (plr[pnum].InvList[i]._iMiscId == IMISC_SCROLL || plr[pnum].InvList[i]._iMiscId == IMISC_SCROLLT) - && plr[pnum].InvList[i]._iSpell == plr[pnum]._pRSpell) { - plr[pnum].RemoveInvItem(i); - plr[pnum].CalcScrolls(); + auto &player = plr[pnum]; + + for (int i = 0; i < player._pNumInv; i++) { + if (!player.InvList[i].isEmpty() + && (player.InvList[i]._iMiscId == IMISC_SCROLL || player.InvList[i]._iMiscId == IMISC_SCROLLT) + && player.InvList[i]._iSpell == player._pRSpell) { + player.RemoveInvItem(i); + player.CalcScrolls(); return; } } for (int i = 0; i < MAXBELTITEMS; i++) { - if (!plr[pnum].SpdList[i].isEmpty() - && (plr[pnum].SpdList[i]._iMiscId == IMISC_SCROLL || plr[pnum].SpdList[i]._iMiscId == IMISC_SCROLLT) - && plr[pnum].SpdList[i]._iSpell == plr[pnum]._pSpell) { - RemoveSpdBarItem(pnum, i); - plr[pnum].CalcScrolls(); + if (!player.SpdList[i].isEmpty() + && (player.SpdList[i]._iMiscId == IMISC_SCROLL || player.SpdList[i]._iMiscId == IMISC_SCROLLT) + && player.SpdList[i]._iSpell == player._pSpell) { + player.RemoveSpdBarItem(i); + player.CalcScrolls(); return; } } @@ -2032,20 +2046,23 @@ bool UseScroll() { if (pcurs != CURSOR_HAND) return false; - if (leveltype == DTYPE_TOWN && !spelldata[plr[myplr]._pRSpell].sTownSpell) + + auto &myPlayer = plr[myplr]; + + if (leveltype == DTYPE_TOWN && !spelldata[myPlayer._pRSpell].sTownSpell) return false; - for (int i = 0; i < plr[myplr]._pNumInv; i++) { - if (!plr[myplr].InvList[i].isEmpty() - && (plr[myplr].InvList[i]._iMiscId == IMISC_SCROLL || plr[myplr].InvList[i]._iMiscId == IMISC_SCROLLT) - && plr[myplr].InvList[i]._iSpell == plr[myplr]._pRSpell) { + for (int i = 0; i < myPlayer._pNumInv; i++) { + if (!myPlayer.InvList[i].isEmpty() + && (myPlayer.InvList[i]._iMiscId == IMISC_SCROLL || myPlayer.InvList[i]._iMiscId == IMISC_SCROLLT) + && myPlayer.InvList[i]._iSpell == myPlayer._pRSpell) { return true; } } - for (auto &item : plr[myplr].SpdList) { + for (auto &item : myPlayer.SpdList) { if (!item.isEmpty() && (item._iMiscId == IMISC_SCROLL || item._iMiscId == IMISC_SCROLLT) - && item._iSpell == plr[myplr]._pRSpell) { + && item._iSpell == myPlayer._pRSpell) { return true; } } @@ -2053,17 +2070,24 @@ bool UseScroll() return false; } +static bool CanUseStaff(ItemStruct &staff, spell_id spell) +{ + return !staff.isEmpty() + && (staff._iMiscId == IMISC_STAFF || staff._iMiscId == IMISC_UNIQUE) + && staff._iSpell == spell + && staff._iCharges > 0; +} + void UseStaffCharge(int pnum) { - if (!plr[pnum].InvBody[INVLOC_HAND_LEFT].isEmpty() - && (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iMiscId == IMISC_STAFF - || plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMiscId == IMISC_UNIQUE // BUGFIX: myplr->pnum - ) - && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iSpell == plr[pnum]._pRSpell - && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iCharges > 0) { - plr[pnum].InvBody[INVLOC_HAND_LEFT]._iCharges--; - CalcPlrStaff(pnum); - } + auto &player = plr[pnum]; + auto &staff = player.InvBody[INVLOC_HAND_LEFT]; + + if (!CanUseStaff(staff, player._pRSpell)) + return; + + staff._iCharges--; + CalcPlrStaff(pnum); } bool UseStaff() @@ -2072,21 +2096,25 @@ bool UseStaff() return false; } - return !plr[myplr].InvBody[INVLOC_HAND_LEFT].isEmpty() - && (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMiscId == IMISC_STAFF || plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMiscId == IMISC_UNIQUE) - && plr[myplr].InvBody[INVLOC_HAND_LEFT]._iSpell == plr[myplr]._pRSpell - && plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges > 0; + auto &myPlayer = plr[myplr]; + + return CanUseStaff(myPlayer.InvBody[INVLOC_HAND_LEFT], myPlayer._pRSpell); } void StartGoldDrop() { initialDropGoldIndex = pcursinvitem; + + auto &myPlayer = plr[myplr]; + if (pcursinvitem <= INVITEM_INV_LAST) - initialDropGoldValue = plr[myplr].InvList[pcursinvitem - INVITEM_INV_FIRST]._ivalue; + initialDropGoldValue = myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]._ivalue; else - initialDropGoldValue = plr[myplr].SpdList[pcursinvitem - INVITEM_BELT_FIRST]._ivalue; + initialDropGoldValue = myPlayer.SpdList[pcursinvitem - INVITEM_BELT_FIRST]._ivalue; + dropGoldFlag = true; dropGoldValue = 0; + if (talkflag) control_reset_talk(); } @@ -2096,7 +2124,9 @@ bool UseInvItem(int pnum, int cii) int c; ItemStruct *item; - if (plr[pnum]._pInvincible && plr[pnum]._pHitPoints == 0 && pnum == myplr) + auto &player = plr[pnum]; + + if (player._pInvincible && player._pHitPoints == 0 && pnum == myplr) return true; if (pcurs != CURSOR_HAND) return true; @@ -2108,22 +2138,22 @@ bool UseInvItem(int pnum, int cii) bool speedlist = false; if (cii <= INVITEM_INV_LAST) { c = cii - INVITEM_INV_FIRST; - item = &plr[pnum].InvList[c]; + item = &player.InvList[c]; } else { if (talkflag) return true; c = cii - INVITEM_BELT_FIRST; - item = &plr[pnum].SpdList[c]; + item = &player.SpdList[c]; speedlist = true; } switch (item->IDidx) { case IDI_MUSHROOM: - plr[pnum].Say(HeroSpeech::NowThatsOneBigMushroom, 10); + player.Say(HeroSpeech::NowThatsOneBigMushroom, 10); return true; case IDI_FUNGALTM: PlaySFX(IS_IBOOK); - plr[pnum].Say(HeroSpeech::ThatDidntDoAnything, 10); + player.Say(HeroSpeech::ThatDidntDoAnything, 10); return true; } @@ -2131,7 +2161,7 @@ bool UseInvItem(int pnum, int cii) return false; if (!item->_iStatFlag) { - plr[pnum].Say(HeroSpeech::ICantUseThisYet); + player.Say(HeroSpeech::ICantUseThisYet); return true; } @@ -2166,22 +2196,22 @@ bool UseInvItem(int pnum, int cii) UseItem(pnum, item->_iMiscId, item->_iSpell); if (speedlist) { - if (plr[pnum].SpdList[c]._iMiscId == IMISC_NOTE) { + if (player.SpdList[c]._iMiscId == IMISC_NOTE) { InitQTextMsg(TEXT_BOOK9); invflag = false; return true; } - RemoveSpdBarItem(pnum, c); + player.RemoveSpdBarItem(c); return true; } - if (plr[pnum].InvList[c]._iMiscId == IMISC_MAPOFDOOM) + if (player.InvList[c]._iMiscId == IMISC_MAPOFDOOM) return true; - if (plr[pnum].InvList[c]._iMiscId == IMISC_NOTE) { + if (player.InvList[c]._iMiscId == IMISC_NOTE) { InitQTextMsg(TEXT_BOOK9); invflag = false; return true; } - plr[pnum].RemoveInvItem(c); + player.RemoveInvItem(c); return true; } @@ -2200,12 +2230,7 @@ void DoTelekinesis() int CalculateGold(PlayerStruct &player) { int gold = 0; - for (auto &item : player.SpdList) { - if (item._itype == ITYPE_GOLD) { - gold += item._ivalue; - force_redraw = 255; - } - } + for (int i = 0; i < player._pNumInv; i++) { if (player.InvList[i]._itype == ITYPE_GOLD) gold += player.InvList[i]._ivalue; @@ -2216,13 +2241,13 @@ int CalculateGold(PlayerStruct &player) bool DropItemBeforeTrig() { - if (TryInvPut()) { - NetSendCmdPItem(true, CMD_PUTITEM, { cursmx, cursmy }); - NewCursor(CURSOR_HAND); - return true; + if (!TryInvPut()) { + return false; } - return false; + NetSendCmdPItem(true, CMD_PUTITEM, { cursmx, cursmy }); + NewCursor(CURSOR_HAND); + return true; } } // namespace devilution diff --git a/Source/inv.h b/Source/inv.h index b46a3bfbd..2c4c5d9c2 100644 --- a/Source/inv.h +++ b/Source/inv.h @@ -97,15 +97,14 @@ void DrawInv(const CelOutputBuffer &out); void DrawInvBelt(const CelOutputBuffer &out); bool AutoEquipEnabled(const PlayerStruct &player, const ItemStruct &item); -bool AutoEquip(int playerNumber, const ItemStruct &item, bool persistItem = true); +bool AutoEquip(int playerId, const ItemStruct &item, bool persistItem = true); bool AutoPlaceItemInInventory(PlayerStruct &player, const ItemStruct &item, bool persistItem = false); bool AutoPlaceItemInInventorySlot(PlayerStruct &player, int slotIndex, const ItemStruct &item, bool persistItem); -bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistItem = false); +bool AutoPlaceItemInBelt(PlayerStruct &player, const ItemStruct &item, bool persistItem = false); bool GoldAutoPlace(PlayerStruct &player); bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex); void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); void inv_update_rem_item(int pnum, BYTE iv); -void RemoveSpdBarItem(int pnum, int iv); void CheckInvItem(bool isShiftHeld = false); void CheckInvScrn(bool isShiftHeld); void CheckItemStats(PlayerStruct &player); @@ -116,8 +115,8 @@ void SyncGetItem(int x, int y, int idx, uint16_t ci, int iseed); bool CanPut(int x, int y); bool TryInvPut(); void DrawInvMsg(const char *msg); -int InvPutItem(int pnum, Point position); -int SyncPutItem(int pnum, Point position, int idx, uint16_t icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac); +int InvPutItem(PlayerStruct &player, Point position); +int SyncPutItem(PlayerStruct &player, Point position, int idx, uint16_t icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac); char CheckInvHLight(); void RemoveScroll(int pnum); bool UseScroll(); diff --git a/Source/items.cpp b/Source/items.cpp index 5280cd17a..185f9a01b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3082,19 +3082,19 @@ static void RepairItem(ItemStruct *i, int lvl) void DoRepair(int pnum, int cii) { - PlayerStruct *p; ItemStruct *pi; - p = &plr[pnum]; - PlaySfxLoc(IS_REPAIR, p->position.tile.x, p->position.tile.y); + auto &player = plr[pnum]; + + PlaySfxLoc(IS_REPAIR, player.position.tile.x, player.position.tile.y); if (cii >= NUM_INVLOC) { - pi = &p->InvList[cii - NUM_INVLOC]; + pi = &player.InvList[cii - NUM_INVLOC]; } else { - pi = &p->InvBody[cii]; + pi = &player.InvBody[cii]; } - RepairItem(pi, p->_pLevel); + RepairItem(pi, player._pLevel); CalcPlrInv(pnum, true); if (pnum == myplr) @@ -3121,15 +3121,15 @@ void DoRecharge(int pnum, int cii) { ItemStruct *pi; - PlayerStruct *p = &plr[pnum]; + auto &player = plr[pnum]; if (cii >= NUM_INVLOC) { - pi = &p->InvList[cii - NUM_INVLOC]; + pi = &player.InvList[cii - NUM_INVLOC]; } else { - pi = &p->InvBody[cii]; + pi = &player.InvBody[cii]; } if (pi->_itype == ITYPE_STAFF && pi->_iSpell != SPL_NULL) { int r = GetSpellBookLevel(pi->_iSpell); - r = GenerateRnd(p->_pLevel / r) + 1; + r = GenerateRnd(player._pLevel / r) + 1; RechargeItem(pi, r); CalcPlrInv(pnum, true); } @@ -3138,7 +3138,7 @@ void DoRecharge(int pnum, int cii) NewCursor(CURSOR_HAND); } -static bool OilItem(ItemStruct *x, PlayerStruct *p) +static bool OilItem(ItemStruct *x, PlayerStruct &player) { int r; @@ -3152,7 +3152,7 @@ static bool OilItem(ItemStruct *x, PlayerStruct *p) return false; } - switch (p->_pOilType) { + switch (player._pOilType) { case IMISC_OILACC: case IMISC_OILMAST: case IMISC_OILSHARP: @@ -3178,7 +3178,7 @@ static bool OilItem(ItemStruct *x, PlayerStruct *p) break; } - switch (p->_pOilType) { + switch (player._pOilType) { case IMISC_OILACC: if (x->_iPLToHit < 50) { x->_iPLToHit += GenerateRnd(2) + 1; @@ -3251,8 +3251,8 @@ void DoOil(int pnum, int cii) { if (cii < NUM_INVLOC && cii != INVLOC_HEAD && (cii <= INVLOC_AMULET || cii > INVLOC_CHEST)) return; - PlayerStruct *p = &plr[pnum]; - if (!OilItem(&p->InvBody[cii], p)) + auto &player = plr[pnum]; + if (!OilItem(&player.InvBody[cii], player)) return; CalcPlrInv(pnum, true); if (pnum == myplr) { diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 5f11ed3a0..bdd8ef386 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -302,226 +302,214 @@ static void LoadItems(LoadHelper *file, const int n, ItemStruct *pItem) static void LoadPlayer(LoadHelper *file, int p) { - PlayerStruct *pPlayer = &plr[p]; + auto &player = plr[p]; - pPlayer->_pmode = static_cast(file->nextLE()); + player._pmode = static_cast(file->nextLE()); - for (int8_t &step : pPlayer->walkpath) { + for (int8_t &step : player.walkpath) { step = file->nextLE(); } - pPlayer->plractive = file->nextBool8(); + player.plractive = file->nextBool8(); file->skip(2); // Alignment - pPlayer->destAction = static_cast(file->nextLE()); - pPlayer->destParam1 = file->nextLE(); - pPlayer->destParam2 = file->nextLE(); - pPlayer->destParam3 = static_cast(file->nextLE()); - pPlayer->destParam4 = file->nextLE(); - pPlayer->plrlevel = file->nextLE(); - pPlayer->position.tile.x = file->nextLE(); - pPlayer->position.tile.y = file->nextLE(); - pPlayer->position.future.x = file->nextLE(); - pPlayer->position.future.y = file->nextLE(); + player.destAction = static_cast(file->nextLE()); + player.destParam1 = file->nextLE(); + player.destParam2 = file->nextLE(); + player.destParam3 = static_cast(file->nextLE()); + player.destParam4 = file->nextLE(); + player.plrlevel = file->nextLE(); + player.position.tile.x = file->nextLE(); + player.position.tile.y = file->nextLE(); + player.position.future.x = file->nextLE(); + player.position.future.y = file->nextLE(); file->skip(8); // Skip _ptargx and _ptargy - pPlayer->position.last.x = file->nextLE(); - pPlayer->position.last.y = file->nextLE(); - pPlayer->position.old.x = file->nextLE(); - pPlayer->position.old.y = file->nextLE(); - pPlayer->position.offset.x = file->nextLE(); - pPlayer->position.offset.y = file->nextLE(); - pPlayer->position.velocity.x = file->nextLE(); - pPlayer->position.velocity.y = file->nextLE(); - pPlayer->_pdir = static_cast(file->nextLE()); + player.position.last.x = file->nextLE(); + player.position.last.y = file->nextLE(); + player.position.old.x = file->nextLE(); + player.position.old.y = file->nextLE(); + player.position.offset.x = file->nextLE(); + player.position.offset.y = file->nextLE(); + player.position.velocity.x = file->nextLE(); + player.position.velocity.y = file->nextLE(); + player._pdir = static_cast(file->nextLE()); file->skip(4); // Unused - pPlayer->_pgfxnum = file->nextLE(); + player._pgfxnum = file->nextLE(); file->skip(4); // Skip pointer pData - pPlayer->AnimInfo.DelayLen = file->nextLE(); - pPlayer->AnimInfo.DelayCounter = file->nextLE(); - pPlayer->AnimInfo.NumberOfFrames = file->nextLE(); - pPlayer->AnimInfo.CurrentFrame = file->nextLE(); - // Skip _pAnimWidth - file->skip(4); - // Skip _pAnimWidth2 - file->skip(4); + player.AnimInfo.DelayLen = file->nextLE(); + player.AnimInfo.DelayCounter = file->nextLE(); + player.AnimInfo.NumberOfFrames = file->nextLE(); + player.AnimInfo.CurrentFrame = file->nextLE(); + file->skip(4); // Skip _pAnimWidth + file->skip(4); // Skip _pAnimWidth2 file->skip(4); // Skip _peflag - pPlayer->_plid = file->nextLE(); - pPlayer->_pvid = file->nextLE(); + player._plid = file->nextLE(); + player._pvid = file->nextLE(); - pPlayer->_pSpell = static_cast(file->nextLE()); - pPlayer->_pSplType = static_cast(file->nextLE()); - pPlayer->_pSplFrom = file->nextLE(); + player._pSpell = static_cast(file->nextLE()); + player._pSplType = static_cast(file->nextLE()); + player._pSplFrom = file->nextLE(); file->skip(2); // Alignment - pPlayer->_pTSpell = static_cast(file->nextLE()); - pPlayer->_pTSplType = static_cast(file->nextLE()); + player._pTSpell = static_cast(file->nextLE()); + player._pTSplType = static_cast(file->nextLE()); file->skip(3); // Alignment - pPlayer->_pRSpell = static_cast(file->nextLE()); - pPlayer->_pRSplType = static_cast(file->nextLE()); + player._pRSpell = static_cast(file->nextLE()); + player._pRSplType = static_cast(file->nextLE()); file->skip(3); // Alignment - pPlayer->_pSBkSpell = static_cast(file->nextLE()); - pPlayer->_pSBkSplType = static_cast(file->nextLE()); - for (int8_t &spellLevel : pPlayer->_pSplLvl) + player._pSBkSpell = static_cast(file->nextLE()); + player._pSBkSplType = static_cast(file->nextLE()); + for (int8_t &spellLevel : player._pSplLvl) spellLevel = file->nextLE(); file->skip(7); // Alignment - pPlayer->_pMemSpells = file->nextLE(); - pPlayer->_pAblSpells = file->nextLE(); - pPlayer->_pScrlSpells = file->nextLE(); - pPlayer->_pSpellFlags = file->nextLE(); + player._pMemSpells = file->nextLE(); + player._pAblSpells = file->nextLE(); + player._pScrlSpells = file->nextLE(); + player._pSpellFlags = file->nextLE(); file->skip(3); // Alignment - for (auto &spell : pPlayer->_pSplHotKey) + for (auto &spell : player._pSplHotKey) spell = static_cast(file->nextLE()); - for (auto &spellType : pPlayer->_pSplTHotKey) + for (auto &spellType : player._pSplTHotKey) spellType = static_cast(file->nextLE()); - pPlayer->_pwtype = static_cast(file->nextLE()); - pPlayer->_pBlockFlag = file->nextBool8(); - pPlayer->_pInvincible = file->nextBool8(); - pPlayer->_pLightRad = file->nextLE(); - pPlayer->_pLvlChanging = file->nextBool8(); + player._pwtype = static_cast(file->nextLE()); + player._pBlockFlag = file->nextBool8(); + player._pInvincible = file->nextBool8(); + player._pLightRad = file->nextLE(); + player._pLvlChanging = file->nextBool8(); - file->nextBytes(pPlayer->_pName, PLR_NAME_LEN); - pPlayer->_pClass = static_cast(file->nextLE()); + file->nextBytes(player._pName, PLR_NAME_LEN); + player._pClass = static_cast(file->nextLE()); file->skip(3); // Alignment - pPlayer->_pStrength = file->nextLE(); - pPlayer->_pBaseStr = file->nextLE(); - pPlayer->_pMagic = file->nextLE(); - pPlayer->_pBaseMag = file->nextLE(); - pPlayer->_pDexterity = file->nextLE(); - pPlayer->_pBaseDex = file->nextLE(); - pPlayer->_pVitality = file->nextLE(); - pPlayer->_pBaseVit = file->nextLE(); - pPlayer->_pStatPts = file->nextLE(); - pPlayer->_pDamageMod = file->nextLE(); - pPlayer->_pBaseToBlk = file->nextLE(); - if (pPlayer->_pBaseToBlk == 0) - pPlayer->_pBaseToBlk = ToBlkTbl[static_cast(pPlayer->_pClass)]; - pPlayer->_pHPBase = file->nextLE(); - pPlayer->_pMaxHPBase = file->nextLE(); - pPlayer->_pHitPoints = file->nextLE(); - pPlayer->_pMaxHP = file->nextLE(); - pPlayer->_pHPPer = file->nextLE(); - pPlayer->_pManaBase = file->nextLE(); - pPlayer->_pMaxManaBase = file->nextLE(); - pPlayer->_pMana = file->nextLE(); - pPlayer->_pMaxMana = file->nextLE(); - pPlayer->_pManaPer = file->nextLE(); - pPlayer->_pLevel = file->nextLE(); - pPlayer->_pMaxLvl = file->nextLE(); + player._pStrength = file->nextLE(); + player._pBaseStr = file->nextLE(); + player._pMagic = file->nextLE(); + player._pBaseMag = file->nextLE(); + player._pDexterity = file->nextLE(); + player._pBaseDex = file->nextLE(); + player._pVitality = file->nextLE(); + player._pBaseVit = file->nextLE(); + player._pStatPts = file->nextLE(); + player._pDamageMod = file->nextLE(); + player._pBaseToBlk = file->nextLE(); + if (player._pBaseToBlk == 0) + player._pBaseToBlk = ToBlkTbl[static_cast(player._pClass)]; + player._pHPBase = file->nextLE(); + player._pMaxHPBase = file->nextLE(); + player._pHitPoints = file->nextLE(); + player._pMaxHP = file->nextLE(); + player._pHPPer = file->nextLE(); + player._pManaBase = file->nextLE(); + player._pMaxManaBase = file->nextLE(); + player._pMana = file->nextLE(); + player._pMaxMana = file->nextLE(); + player._pManaPer = file->nextLE(); + player._pLevel = file->nextLE(); + player._pMaxLvl = file->nextLE(); file->skip(2); // Alignment - pPlayer->_pExperience = file->nextLE(); - pPlayer->_pMaxExp = file->nextLE(); - pPlayer->_pNextExper = file->nextLE(); - pPlayer->_pArmorClass = file->nextLE(); - pPlayer->_pMagResist = file->nextLE(); - pPlayer->_pFireResist = file->nextLE(); - pPlayer->_pLghtResist = file->nextLE(); - pPlayer->_pGold = file->nextLE(); - - pPlayer->_pInfraFlag = file->nextBool32(); - pPlayer->position.temp.x = file->nextLE(); - pPlayer->position.temp.y = file->nextLE(); - pPlayer->tempDirection = static_cast(file->nextLE()); - pPlayer->_pVar4 = file->nextLE(); - pPlayer->_pVar5 = file->nextLE(); - pPlayer->position.offset2.x = file->nextLE(); - pPlayer->position.offset2.y = file->nextLE(); - // Skip actionFrame - file->skip(4); + player._pExperience = file->nextLE(); + player._pMaxExp = file->nextLE(); + player._pNextExper = file->nextLE(); + player._pArmorClass = file->nextLE(); + player._pMagResist = file->nextLE(); + player._pFireResist = file->nextLE(); + player._pLghtResist = file->nextLE(); + player._pGold = file->nextLE(); + + player._pInfraFlag = file->nextBool32(); + player.position.temp.x = file->nextLE(); + player.position.temp.y = file->nextLE(); + player.tempDirection = static_cast(file->nextLE()); + player._pVar4 = file->nextLE(); + player._pVar5 = file->nextLE(); + player.position.offset2.x = file->nextLE(); + player.position.offset2.y = file->nextLE(); + file->skip(4); // Skip actionFrame for (uint8_t i = 0; i < giNumberOfLevels; i++) - pPlayer->_pLvlVisited[i] = file->nextBool8(); + player._pLvlVisited[i] = file->nextBool8(); for (uint8_t i = 0; i < giNumberOfLevels; i++) - pPlayer->_pSLvlVisited[i] = file->nextBool8(); + player._pSLvlVisited[i] = file->nextBool8(); - file->skip(2); // Alignment - - // skip _pGFXLoad - file->skip(4); + file->skip(2); // Alignment + file->skip(4); // skip _pGFXLoad file->skip(4 * 8); // Skip pointers _pNAnim - pPlayer->_pNFrames = file->nextLE(); - // skip _pNWidth - file->skip(4); + player._pNFrames = file->nextLE(); + file->skip(4); // skip _pNWidth file->skip(4 * 8); // Skip pointers _pWAnim - pPlayer->_pWFrames = file->nextLE(); - // skip _pWWidth - file->skip(4); + player._pWFrames = file->nextLE(); + file->skip(4); // skip _pWWidth file->skip(4 * 8); // Skip pointers _pAAnim - pPlayer->_pAFrames = file->nextLE(); - // skip _pAWidth - file->skip(4); - pPlayer->_pAFNum = file->nextLE(); + player._pAFrames = file->nextLE(); + file->skip(4); // skip _pAWidth + player._pAFNum = file->nextLE(); file->skip(4 * 8); // Skip pointers _pLAnim file->skip(4 * 8); // Skip pointers _pFAnim file->skip(4 * 8); // Skip pointers _pTAnim - pPlayer->_pSFrames = file->nextLE(); - // skip _pSWidth - file->skip(4); - pPlayer->_pSFNum = file->nextLE(); + player._pSFrames = file->nextLE(); + file->skip(4); // skip _pSWidth + player._pSFNum = file->nextLE(); file->skip(4 * 8); // Skip pointers _pHAnim - pPlayer->_pHFrames = file->nextLE(); - // skip _pHWidth - file->skip(4); + player._pHFrames = file->nextLE(); + file->skip(4); // skip _pHWidth file->skip(4 * 8); // Skip pointers _pDAnim - pPlayer->_pDFrames = file->nextLE(); - // skip _pDWidth - file->skip(4); + player._pDFrames = file->nextLE(); + file->skip(4); // skip _pDWidth file->skip(4 * 8); // Skip pointers _pBAnim - pPlayer->_pBFrames = file->nextLE(); - // skip _pBWidth - file->skip(4); - - LoadItems(file, NUM_INVLOC, pPlayer->InvBody); - LoadItems(file, NUM_INV_GRID_ELEM, pPlayer->InvList); - pPlayer->_pNumInv = file->nextLE(); - for (int8_t &cell : pPlayer->InvGrid) + player._pBFrames = file->nextLE(); + file->skip(4); // skip _pBWidth + + LoadItems(file, NUM_INVLOC, player.InvBody); + LoadItems(file, NUM_INV_GRID_ELEM, player.InvList); + player._pNumInv = file->nextLE(); + for (int8_t &cell : player.InvGrid) cell = file->nextLE(); - LoadItems(file, MAXBELTITEMS, pPlayer->SpdList); - LoadItemData(file, &pPlayer->HoldItem); - - pPlayer->_pIMinDam = file->nextLE(); - pPlayer->_pIMaxDam = file->nextLE(); - pPlayer->_pIAC = file->nextLE(); - pPlayer->_pIBonusDam = file->nextLE(); - pPlayer->_pIBonusToHit = file->nextLE(); - pPlayer->_pIBonusAC = file->nextLE(); - pPlayer->_pIBonusDamMod = file->nextLE(); + LoadItems(file, MAXBELTITEMS, player.SpdList); + LoadItemData(file, &player.HoldItem); + + player._pIMinDam = file->nextLE(); + player._pIMaxDam = file->nextLE(); + player._pIAC = file->nextLE(); + player._pIBonusDam = file->nextLE(); + player._pIBonusToHit = file->nextLE(); + player._pIBonusAC = file->nextLE(); + player._pIBonusDamMod = file->nextLE(); file->skip(4); // Alignment - pPlayer->_pISpells = file->nextLE(); - pPlayer->_pIFlags = file->nextLE(); - pPlayer->_pIGetHit = file->nextLE(); - pPlayer->_pISplLvlAdd = file->nextLE(); + player._pISpells = file->nextLE(); + player._pIFlags = file->nextLE(); + player._pIGetHit = file->nextLE(); + player._pISplLvlAdd = file->nextLE(); file->skip(1); // Unused file->skip(2); // Alignment - pPlayer->_pISplDur = file->nextLE(); - pPlayer->_pIEnAc = file->nextLE(); - pPlayer->_pIFMinDam = file->nextLE(); - pPlayer->_pIFMaxDam = file->nextLE(); - pPlayer->_pILMinDam = file->nextLE(); - pPlayer->_pILMaxDam = file->nextLE(); - pPlayer->_pOilType = static_cast(file->nextLE()); - pPlayer->pTownWarps = file->nextLE(); - pPlayer->pDungMsgs = file->nextLE(); - pPlayer->pLvlLoad = file->nextLE(); + player._pISplDur = file->nextLE(); + player._pIEnAc = file->nextLE(); + player._pIFMinDam = file->nextLE(); + player._pIFMaxDam = file->nextLE(); + player._pILMinDam = file->nextLE(); + player._pILMaxDam = file->nextLE(); + player._pOilType = static_cast(file->nextLE()); + player.pTownWarps = file->nextLE(); + player.pDungMsgs = file->nextLE(); + player.pLvlLoad = file->nextLE(); if (gbIsHellfireSaveGame) { - pPlayer->pDungMsgs2 = file->nextLE(); - pPlayer->pBattleNet = false; + player.pDungMsgs2 = file->nextLE(); + player.pBattleNet = false; } else { - pPlayer->pDungMsgs2 = 0; - pPlayer->pBattleNet = file->nextBool8(); + player.pDungMsgs2 = 0; + player.pBattleNet = file->nextBool8(); } - pPlayer->pManaShield = file->nextBool8(); + player.pManaShield = file->nextBool8(); if (gbIsHellfireSaveGame) { - pPlayer->pOriginalCathedral = file->nextBool8(); + player.pOriginalCathedral = file->nextBool8(); } else { file->skip(1); - pPlayer->pOriginalCathedral = true; + player.pOriginalCathedral = true; } file->skip(2); // Available bytes - pPlayer->wReflections = file->nextLE(); + player.wReflections = file->nextLE(); file->skip(14); // Available bytes - pPlayer->pDiabloKillLevel = file->nextLE(); - pPlayer->pDifficulty = static_cast<_difficulty>(file->nextLE()); - pPlayer->pDamAcFlags = file->nextLE(); + player.pDiabloKillLevel = file->nextLE(); + player.pDifficulty = static_cast<_difficulty>(file->nextLE()); + player.pDamAcFlags = file->nextLE(); file->skip(20); // Available bytes CalcPlrItemVals(p, false); @@ -709,8 +697,7 @@ static void LoadObject(LoadHelper *file, int i) pObject->_oAnimLen = file->nextLE(); pObject->_oAnimFrame = file->nextLE(); pObject->_oAnimWidth = file->nextLE(); - // Skip _oAnimWidth2 - file->skip(4); + file->skip(4); // Skip _oAnimWidth2 pObject->_oDelFlag = file->nextBool32(); pObject->_oBreak = file->nextLE(); file->skip(3); // Alignment @@ -958,7 +945,7 @@ static void LoadMatchingItems(LoadHelper *file, const int n, ItemStruct *pItem) } } -void LoadHeroItems(PlayerStruct *pPlayer) +void LoadHeroItems(PlayerStruct &player) { LoadHelper file("heroitems"); if (!file.isValid()) @@ -966,9 +953,9 @@ void LoadHeroItems(PlayerStruct *pPlayer) gbIsHellfireSaveGame = file.nextBool8(); - LoadMatchingItems(&file, NUM_INVLOC, pPlayer->InvBody); - LoadMatchingItems(&file, NUM_INV_GRID_ELEM, pPlayer->InvList); - LoadMatchingItems(&file, MAXBELTITEMS, pPlayer->SpdList); + LoadMatchingItems(&file, NUM_INVLOC, player.InvBody); + LoadMatchingItems(&file, NUM_INV_GRID_ELEM, player.InvList); + LoadMatchingItems(&file, MAXBELTITEMS, player.SpdList); gbIsHellfireSaveGame = gbIsHellfire; } @@ -1296,221 +1283,214 @@ static void SaveItems(SaveHelper *file, ItemStruct *pItem, const int n) static void SavePlayer(SaveHelper *file, int p) { - PlayerStruct *pPlayer = &plr[p]; + auto &player = plr[p]; - file->writeLE(pPlayer->_pmode); - for (int8_t step : pPlayer->walkpath) + file->writeLE(player._pmode); + for (int8_t step : player.walkpath) file->writeLE(step); - file->writeLE(pPlayer->plractive); + file->writeLE(player.plractive); file->skip(2); // Alignment - file->writeLE(pPlayer->destAction); - file->writeLE(pPlayer->destParam1); - file->writeLE(pPlayer->destParam2); - file->writeLE(pPlayer->destParam3); - file->writeLE(pPlayer->destParam4); - file->writeLE(pPlayer->plrlevel); - file->writeLE(pPlayer->position.tile.x); - file->writeLE(pPlayer->position.tile.y); - file->writeLE(pPlayer->position.future.x); - file->writeLE(pPlayer->position.future.y); + file->writeLE(player.destAction); + file->writeLE(player.destParam1); + file->writeLE(player.destParam2); + file->writeLE(player.destParam3); + file->writeLE(player.destParam4); + file->writeLE(player.plrlevel); + file->writeLE(player.position.tile.x); + file->writeLE(player.position.tile.y); + file->writeLE(player.position.future.x); + file->writeLE(player.position.future.y); // For backwards compatibility - const Point target = pPlayer->GetTargetPosition(); + const Point target = player.GetTargetPosition(); file->writeLE(target.x); file->writeLE(target.y); - file->writeLE(pPlayer->position.last.x); - file->writeLE(pPlayer->position.last.y); - file->writeLE(pPlayer->position.old.x); - file->writeLE(pPlayer->position.old.y); - file->writeLE(pPlayer->position.offset.x); - file->writeLE(pPlayer->position.offset.y); - file->writeLE(pPlayer->position.velocity.x); - file->writeLE(pPlayer->position.velocity.y); - file->writeLE(pPlayer->_pdir); + file->writeLE(player.position.last.x); + file->writeLE(player.position.last.y); + file->writeLE(player.position.old.x); + file->writeLE(player.position.old.y); + file->writeLE(player.position.offset.x); + file->writeLE(player.position.offset.y); + file->writeLE(player.position.velocity.x); + file->writeLE(player.position.velocity.y); + file->writeLE(player._pdir); file->skip(4); // Unused - file->writeLE(pPlayer->_pgfxnum); + file->writeLE(player._pgfxnum); file->skip(4); // Skip pointer _pAnimData - file->writeLE(pPlayer->AnimInfo.DelayLen); - file->writeLE(pPlayer->AnimInfo.DelayCounter); - file->writeLE(pPlayer->AnimInfo.NumberOfFrames); - file->writeLE(pPlayer->AnimInfo.CurrentFrame); + file->writeLE(player.AnimInfo.DelayLen); + file->writeLE(player.AnimInfo.DelayCounter); + file->writeLE(player.AnimInfo.NumberOfFrames); + file->writeLE(player.AnimInfo.CurrentFrame); // write _pAnimWidth for vanilla compatibility - int animWidth = pPlayer->AnimInfo.pCelSprite == nullptr ? 96 : pPlayer->AnimInfo.pCelSprite->Width(); + int animWidth = player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width(); file->writeLE(animWidth); // write _pAnimWidth2 for vanilla compatibility file->writeLE(CalculateWidth2(animWidth)); file->skip(4); // Skip _peflag - file->writeLE(pPlayer->_plid); - file->writeLE(pPlayer->_pvid); + file->writeLE(player._plid); + file->writeLE(player._pvid); - file->writeLE(pPlayer->_pSpell); - file->writeLE(pPlayer->_pSplType); - file->writeLE(pPlayer->_pSplFrom); + file->writeLE(player._pSpell); + file->writeLE(player._pSplType); + file->writeLE(player._pSplFrom); file->skip(2); // Alignment - file->writeLE(pPlayer->_pTSpell); - file->writeLE(pPlayer->_pTSplType); + file->writeLE(player._pTSpell); + file->writeLE(player._pTSplType); file->skip(3); // Alignment - file->writeLE(pPlayer->_pRSpell); - file->writeLE(pPlayer->_pRSplType); + file->writeLE(player._pRSpell); + file->writeLE(player._pRSplType); file->skip(3); // Alignment - file->writeLE(pPlayer->_pSBkSpell); - file->writeLE(pPlayer->_pSBkSplType); - for (int8_t spellLevel : pPlayer->_pSplLvl) + file->writeLE(player._pSBkSpell); + file->writeLE(player._pSBkSplType); + for (int8_t spellLevel : player._pSplLvl) file->writeLE(spellLevel); file->skip(7); // Alignment - file->writeLE(pPlayer->_pMemSpells); - file->writeLE(pPlayer->_pAblSpells); - file->writeLE(pPlayer->_pScrlSpells); - file->writeLE(pPlayer->_pSpellFlags); + file->writeLE(player._pMemSpells); + file->writeLE(player._pAblSpells); + file->writeLE(player._pScrlSpells); + file->writeLE(player._pSpellFlags); file->skip(3); // Alignment - for (auto &spellId : pPlayer->_pSplHotKey) + for (auto &spellId : player._pSplHotKey) file->writeLE(spellId); - for (auto &spellType : pPlayer->_pSplTHotKey) + for (auto &spellType : player._pSplTHotKey) file->writeLE(spellType); - file->writeLE(pPlayer->_pwtype); - file->writeLE(pPlayer->_pBlockFlag); - file->writeLE(pPlayer->_pInvincible); - file->writeLE(pPlayer->_pLightRad); - file->writeLE(pPlayer->_pLvlChanging); + file->writeLE(player._pwtype); + file->writeLE(player._pBlockFlag); + file->writeLE(player._pInvincible); + file->writeLE(player._pLightRad); + file->writeLE(player._pLvlChanging); - file->writeBytes(pPlayer->_pName, PLR_NAME_LEN); - file->writeLE(static_cast(pPlayer->_pClass)); + file->writeBytes(player._pName, PLR_NAME_LEN); + file->writeLE(static_cast(player._pClass)); file->skip(3); // Alignment - file->writeLE(pPlayer->_pStrength); - file->writeLE(pPlayer->_pBaseStr); - file->writeLE(pPlayer->_pMagic); - file->writeLE(pPlayer->_pBaseMag); - file->writeLE(pPlayer->_pDexterity); - file->writeLE(pPlayer->_pBaseDex); - file->writeLE(pPlayer->_pVitality); - file->writeLE(pPlayer->_pBaseVit); - file->writeLE(pPlayer->_pStatPts); - file->writeLE(pPlayer->_pDamageMod); - - file->writeLE(pPlayer->_pBaseToBlk); - file->writeLE(pPlayer->_pHPBase); - file->writeLE(pPlayer->_pMaxHPBase); - file->writeLE(pPlayer->_pHitPoints); - file->writeLE(pPlayer->_pMaxHP); - file->writeLE(pPlayer->_pHPPer); - file->writeLE(pPlayer->_pManaBase); - file->writeLE(pPlayer->_pMaxManaBase); - file->writeLE(pPlayer->_pMana); - file->writeLE(pPlayer->_pMaxMana); - file->writeLE(pPlayer->_pManaPer); - file->writeLE(pPlayer->_pLevel); - file->writeLE(pPlayer->_pMaxLvl); + file->writeLE(player._pStrength); + file->writeLE(player._pBaseStr); + file->writeLE(player._pMagic); + file->writeLE(player._pBaseMag); + file->writeLE(player._pDexterity); + file->writeLE(player._pBaseDex); + file->writeLE(player._pVitality); + file->writeLE(player._pBaseVit); + file->writeLE(player._pStatPts); + file->writeLE(player._pDamageMod); + + file->writeLE(player._pBaseToBlk); + file->writeLE(player._pHPBase); + file->writeLE(player._pMaxHPBase); + file->writeLE(player._pHitPoints); + file->writeLE(player._pMaxHP); + file->writeLE(player._pHPPer); + file->writeLE(player._pManaBase); + file->writeLE(player._pMaxManaBase); + file->writeLE(player._pMana); + file->writeLE(player._pMaxMana); + file->writeLE(player._pManaPer); + file->writeLE(player._pLevel); + file->writeLE(player._pMaxLvl); file->skip(2); // Alignment - file->writeLE(pPlayer->_pExperience); - file->writeLE(pPlayer->_pMaxExp); - file->writeLE(pPlayer->_pNextExper); - file->writeLE(pPlayer->_pArmorClass); - file->writeLE(pPlayer->_pMagResist); - file->writeLE(pPlayer->_pFireResist); - file->writeLE(pPlayer->_pLghtResist); - file->writeLE(pPlayer->_pGold); - - file->writeLE(pPlayer->_pInfraFlag); - file->writeLE(pPlayer->position.temp.x); - file->writeLE(pPlayer->position.temp.y); - file->writeLE(pPlayer->tempDirection); - file->writeLE(pPlayer->_pVar4); - file->writeLE(pPlayer->_pVar5); - file->writeLE(pPlayer->position.offset2.x); - file->writeLE(pPlayer->position.offset2.y); + file->writeLE(player._pExperience); + file->writeLE(player._pMaxExp); + file->writeLE(player._pNextExper); + file->writeLE(player._pArmorClass); + file->writeLE(player._pMagResist); + file->writeLE(player._pFireResist); + file->writeLE(player._pLghtResist); + file->writeLE(player._pGold); + + file->writeLE(player._pInfraFlag); + file->writeLE(player.position.temp.x); + file->writeLE(player.position.temp.y); + file->writeLE(player.tempDirection); + file->writeLE(player._pVar4); + file->writeLE(player._pVar5); + file->writeLE(player.position.offset2.x); + file->writeLE(player.position.offset2.y); // Write actionFrame for vanilla compatibility file->writeLE(0); for (uint8_t i = 0; i < giNumberOfLevels; i++) - file->writeLE(pPlayer->_pLvlVisited[i]); + file->writeLE(player._pLvlVisited[i]); for (uint8_t i = 0; i < giNumberOfLevels; i++) - file->writeLE(pPlayer->_pSLvlVisited[i]); // only 10 used + file->writeLE(player._pSLvlVisited[i]); // only 10 used file->skip(2); // Alignment // Write _pGFXLoad for vanilla compatibility file->writeLE(0); file->skip(4 * 8); // Skip pointers _pNAnim - file->writeLE(pPlayer->_pNFrames); - // Skip _pNWidth - file->skip(4); + file->writeLE(player._pNFrames); + file->skip(4); // Skip _pNWidth file->skip(4 * 8); // Skip pointers _pWAnim - file->writeLE(pPlayer->_pWFrames); - // Skip _pWWidth - file->skip(4); + file->writeLE(player._pWFrames); + file->skip(4); // Skip _pWWidth file->skip(4 * 8); // Skip pointers _pAAnim - file->writeLE(pPlayer->_pAFrames); - // Skip _pAWidth - file->skip(4); - file->writeLE(pPlayer->_pAFNum); + file->writeLE(player._pAFrames); + file->skip(4); // Skip _pAWidth + file->writeLE(player._pAFNum); file->skip(4 * 8); // Skip pointers _pLAnim file->skip(4 * 8); // Skip pointers _pFAnim file->skip(4 * 8); // Skip pointers _pTAnim - file->writeLE(pPlayer->_pSFrames); - // Skip _pSWidth - file->skip(4); - file->writeLE(pPlayer->_pSFNum); + file->writeLE(player._pSFrames); + file->skip(4); // Skip _pSWidth + file->writeLE(player._pSFNum); file->skip(4 * 8); // Skip pointers _pHAnim - file->writeLE(pPlayer->_pHFrames); - // Skip _pHWidth - file->skip(4); + file->writeLE(player._pHFrames); + file->skip(4); // Skip _pHWidth file->skip(4 * 8); // Skip pointers _pDAnim - file->writeLE(pPlayer->_pDFrames); - // Skip _pDWidth - file->skip(4); + file->writeLE(player._pDFrames); + file->skip(4); // Skip _pDWidth file->skip(4 * 8); // Skip pointers _pBAnim - file->writeLE(pPlayer->_pBFrames); - // Skip _pBWidth - file->skip(4); - - SaveItems(file, pPlayer->InvBody, NUM_INVLOC); - SaveItems(file, pPlayer->InvList, NUM_INV_GRID_ELEM); - file->writeLE(pPlayer->_pNumInv); - for (int8_t cell : pPlayer->InvGrid) + file->writeLE(player._pBFrames); + file->skip(4); // Skip _pBWidth + + SaveItems(file, player.InvBody, NUM_INVLOC); + SaveItems(file, player.InvList, NUM_INV_GRID_ELEM); + file->writeLE(player._pNumInv); + for (int8_t cell : player.InvGrid) file->writeLE(cell); - SaveItems(file, pPlayer->SpdList, MAXBELTITEMS); - SaveItem(file, &pPlayer->HoldItem); - - file->writeLE(pPlayer->_pIMinDam); - file->writeLE(pPlayer->_pIMaxDam); - file->writeLE(pPlayer->_pIAC); - file->writeLE(pPlayer->_pIBonusDam); - file->writeLE(pPlayer->_pIBonusToHit); - file->writeLE(pPlayer->_pIBonusAC); - file->writeLE(pPlayer->_pIBonusDamMod); + SaveItems(file, player.SpdList, MAXBELTITEMS); + SaveItem(file, &player.HoldItem); + + file->writeLE(player._pIMinDam); + file->writeLE(player._pIMaxDam); + file->writeLE(player._pIAC); + file->writeLE(player._pIBonusDam); + file->writeLE(player._pIBonusToHit); + file->writeLE(player._pIBonusAC); + file->writeLE(player._pIBonusDamMod); file->skip(4); // Alignment - file->writeLE(pPlayer->_pISpells); - file->writeLE(pPlayer->_pIFlags); - file->writeLE(pPlayer->_pIGetHit); + file->writeLE(player._pISpells); + file->writeLE(player._pIFlags); + file->writeLE(player._pIGetHit); - file->writeLE(pPlayer->_pISplLvlAdd); + file->writeLE(player._pISplLvlAdd); file->skip(1); // Unused file->skip(2); // Alignment - file->writeLE(pPlayer->_pISplDur); - file->writeLE(pPlayer->_pIEnAc); - file->writeLE(pPlayer->_pIFMinDam); - file->writeLE(pPlayer->_pIFMaxDam); - file->writeLE(pPlayer->_pILMinDam); - file->writeLE(pPlayer->_pILMaxDam); - file->writeLE(pPlayer->_pOilType); - file->writeLE(pPlayer->pTownWarps); - file->writeLE(pPlayer->pDungMsgs); - file->writeLE(pPlayer->pLvlLoad); + file->writeLE(player._pISplDur); + file->writeLE(player._pIEnAc); + file->writeLE(player._pIFMinDam); + file->writeLE(player._pIFMaxDam); + file->writeLE(player._pILMinDam); + file->writeLE(player._pILMaxDam); + file->writeLE(player._pOilType); + file->writeLE(player.pTownWarps); + file->writeLE(player.pDungMsgs); + file->writeLE(player.pLvlLoad); if (gbIsHellfire) - file->writeLE(pPlayer->pDungMsgs2); + file->writeLE(player.pDungMsgs2); else - file->writeLE(pPlayer->pBattleNet); - file->writeLE(pPlayer->pManaShield); - file->writeLE(pPlayer->pOriginalCathedral); + file->writeLE(player.pBattleNet); + file->writeLE(player.pManaShield); + file->writeLE(player.pOriginalCathedral); file->skip(2); // Available bytes - file->writeLE(pPlayer->wReflections); + file->writeLE(player.wReflections); file->skip(14); // Available bytes - file->writeLE(pPlayer->pDiabloKillLevel); - file->writeLE(pPlayer->pDifficulty); - file->writeLE(pPlayer->pDamAcFlags); + file->writeLE(player.pDiabloKillLevel); + file->writeLE(player.pDifficulty); + file->writeLE(player.pDamAcFlags); file->skip(20); // Available bytes // Omit pointer _pNData @@ -1777,16 +1757,16 @@ static void SavePortal(SaveHelper *file, int i) const int DiabloItemSaveSize = 368; const int HellfireItemSaveSize = 372; -void SaveHeroItems(PlayerStruct *pPlayer) +void SaveHeroItems(PlayerStruct &player) { size_t items = NUM_INVLOC + NUM_INV_GRID_ELEM + MAXBELTITEMS; SaveHelper file("heroitems", items * (gbIsHellfire ? HellfireItemSaveSize : DiabloItemSaveSize) + sizeof(uint8_t)); file.writeLE(gbIsHellfire); - SaveItems(&file, pPlayer->InvBody, NUM_INVLOC); - SaveItems(&file, pPlayer->InvList, NUM_INV_GRID_ELEM); - SaveItems(&file, pPlayer->SpdList, MAXBELTITEMS); + SaveItems(&file, player.InvBody, NUM_INVLOC); + SaveItems(&file, player.InvList, NUM_INV_GRID_ELEM); + SaveItems(&file, player.SpdList, MAXBELTITEMS); } // 256 kilobytes + 3 bytes (demo leftover) for file magic (262147) diff --git a/Source/loadsave.h b/Source/loadsave.h index 8207b819d..253abe4db 100644 --- a/Source/loadsave.h +++ b/Source/loadsave.h @@ -17,7 +17,7 @@ int RemapItemIdxFromDiablo(int i); int RemapItemIdxToDiablo(int i); bool IsHeaderValid(uint32_t magicNumber); void LoadHotkeys(); -void LoadHeroItems(PlayerStruct *pPlayer); +void LoadHeroItems(PlayerStruct &pPlayer); /** * @brief Remove invalid inventory items from the inventory grid * @param pnum The id of the player @@ -25,7 +25,7 @@ void LoadHeroItems(PlayerStruct *pPlayer); void RemoveEmptyInventory(int pnum); void LoadGame(bool firstflag); void SaveHotkeys(); -void SaveHeroItems(PlayerStruct *pPlayer); +void SaveHeroItems(PlayerStruct &pPlayer); void SaveGameData(); void SaveGame(); void SaveLevel(); diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 85a035fe8..dc1ccf13c 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1526,7 +1526,7 @@ void AddStealPotions(int mi, int sx, int sy, int dx, int dy, int midir, int8_t m break; case IMISC_HEAL: case IMISC_MANA: - RemoveSpdBarItem(pnum, si); + plr[pnum].RemoveSpdBarItem(si); break; case IMISC_FULLMANA: ii = ItemMiscIdIdx(IMISC_MANA); diff --git a/Source/msg.cpp b/Source/msg.cpp index 51afbf837..dc9d0d19d 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1446,7 +1446,7 @@ static DWORD On_GETITEM(TCmd *pCmd, int pnum) if ((currlevel == p->bLevel || p->bPnum == myplr) && p->bMaster != myplr) { if (p->bPnum == myplr) { if (currlevel != p->bLevel) { - ii = SyncPutItem(myplr, plr[myplr].position.tile, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); + ii = SyncPutItem(plr[myplr], plr[myplr].position.tile, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); if (ii != -1) InvGetItem(myplr, &items[ii], ii); } else @@ -1508,7 +1508,7 @@ static DWORD On_AGETITEM(TCmd *pCmd, int pnum) if ((currlevel == p->bLevel || p->bPnum == myplr) && p->bMaster != myplr) { if (p->bPnum == myplr) { if (currlevel != p->bLevel) { - int ii = SyncPutItem(myplr, plr[myplr].position.tile, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); + int ii = SyncPutItem(plr[myplr], plr[myplr].position.tile, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); if (ii != -1) AutoGetItem(myplr, &items[ii], ii); } else @@ -1547,9 +1547,9 @@ static DWORD On_PUTITEM(TCmd *pCmd, int pnum) else if (currlevel == plr[pnum].plrlevel) { int ii; if (pnum == myplr) - ii = InvPutItem(pnum, { p->x, p->y }); + ii = InvPutItem(plr[pnum], { p->x, p->y }); else - ii = SyncPutItem(pnum, { p->x, p->y }, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); + ii = SyncPutItem(plr[pnum], { p->x, p->y }, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); if (ii != -1) { PutItemRecord(p->dwSeed, p->wCI, p->wIndx); delta_put_item(p, items[ii].position.x, items[ii].position.y, plr[pnum].plrlevel); @@ -1572,7 +1572,7 @@ static DWORD On_SYNCPUTITEM(TCmd *pCmd, int pnum) if (gbBufferMsgs == 1) msg_send_packet(pnum, p, sizeof(*p)); else if (currlevel == plr[pnum].plrlevel) { - int ii = SyncPutItem(pnum, { p->x, p->y }, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); + int ii = SyncPutItem(plr[pnum], { p->x, p->y }, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); if (ii != -1) { PutItemRecord(p->dwSeed, p->wCI, p->wIndx); delta_put_item(p, items[ii].position.x, items[ii].position.y, plr[pnum].plrlevel); @@ -1596,7 +1596,7 @@ static DWORD On_RESPAWNITEM(TCmd *pCmd, int pnum) msg_send_packet(pnum, p, sizeof(*p)); else { if (currlevel == plr[pnum].plrlevel && pnum != myplr) { - SyncPutItem(pnum, { p->x, p->y }, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); + SyncPutItem(plr[pnum], { p->x, p->y }, p->wIndx, p->wCI, p->dwSeed, p->bId, p->bDur, p->bMDur, p->bCh, p->bMCh, p->wValue, p->dwBuff, p->wToHit, p->wMaxDam, p->bMinStr, p->bMinMag, p->bMinDex, p->bAC); } PutItemRecord(p->dwSeed, p->wCI, p->wIndx); delta_put_item(p, p->x, p->y, plr[pnum].plrlevel); diff --git a/Source/objects.cpp b/Source/objects.cpp index ac8068e7a..bad530913 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3902,7 +3902,7 @@ bool OperateShrineSpiritual(int pnum) gridItem = plr[pnum]._pNumInv; plr[pnum].InvList[t]._ivalue = r; plr[pnum]._pGold += r; - SetGoldCurs(pnum, t); + SetPlrHandGoldCurs(&plr[pnum].InvList[t]); } } diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 6d8aa6578..8f81dff82 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -236,23 +236,23 @@ void pfile_write_hero(bool write_game_data, bool clear_tables) pfile_encode_hero(&pkplr); if (!gbVanilla) { SaveHotkeys(); - SaveHeroItems(&plr[myplr]); + SaveHeroItems(plr[myplr]); } } -static void game_2_ui_player(const PlayerStruct *p, _uiheroinfo *heroinfo, bool bHasSaveFile) +static void game_2_ui_player(const PlayerStruct &player, _uiheroinfo *heroinfo, bool bHasSaveFile) { memset(heroinfo, 0, sizeof(*heroinfo)); - strncpy(heroinfo->name, p->_pName, sizeof(heroinfo->name) - 1); + strncpy(heroinfo->name, player._pName, sizeof(heroinfo->name) - 1); heroinfo->name[sizeof(heroinfo->name) - 1] = '\0'; - heroinfo->level = p->_pLevel; - heroinfo->heroclass = p->_pClass; - heroinfo->strength = p->_pStrength; - heroinfo->magic = p->_pMagic; - heroinfo->dexterity = p->_pDexterity; - heroinfo->vitality = p->_pVitality; + heroinfo->level = player._pLevel; + heroinfo->heroclass = player._pClass; + heroinfo->strength = player._pStrength; + heroinfo->magic = player._pMagic; + heroinfo->dexterity = player._pDexterity; + heroinfo->vitality = player._pVitality; heroinfo->hassaved = bHasSaveFile; - heroinfo->herorank = p->pDiabloKillLevel; + heroinfo->herorank = player.pDiabloKillLevel; heroinfo->spawned = gbIsSpawn; } @@ -274,11 +274,11 @@ bool pfile_ui_set_hero_infos(bool (*ui_add_hero_info)(_uiheroinfo *)) UnPackPlayer(&pkplr, 0, false); pfile_SFileCloseArchive(&archive); - LoadHeroItems(&plr[0]); + LoadHeroItems(plr[0]); RemoveEmptyInventory(0); CalcPlrInv(0, false); - game_2_ui_player(&plr[0], &uihero, hasSaveGame); + game_2_ui_player(plr[0], &uihero, hasSaveGame); ui_add_hero_info(&uihero); } pfile_SFileCloseArchive(&archive); @@ -335,10 +335,10 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) player._pName[PLR_NAME_LEN - 1] = '\0'; PackPlayer(&pkplr, player, true); pfile_encode_hero(&pkplr); - game_2_ui_player(&player, heroinfo, false); + game_2_ui_player(player, heroinfo, false); if (!gbVanilla) { SaveHotkeys(); - SaveHeroItems(&player); + SaveHeroItems(player); } mpqapi_flush_and_close(true); @@ -400,7 +400,7 @@ void pfile_read_player_from_save(char name[16], int playerId) UnPackPlayer(&pkplr, playerId, false); - LoadHeroItems(&plr[playerId]); + LoadHeroItems(plr[playerId]); RemoveEmptyInventory(playerId); CalcPlrInv(playerId, false); } diff --git a/Source/player.cpp b/Source/player.cpp index 6c34bcbc8..5bf33c398 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -265,6 +265,14 @@ void PlayerStruct::RemoveInvItem(int iv, bool calcScrolls) CalcScrolls(); } +void PlayerStruct::RemoveSpdBarItem(int iv) +{ + SpdList[iv]._itype = ITYPE_NONE; + + CalcScrolls(); + force_redraw = 255; +} + int PlayerStruct::GetBaseAttributeValue(CharacterAttribute attribute) const { switch (attribute) { @@ -1781,116 +1789,53 @@ StartPlayerKill(int pnum, int earflag) SetPlayerHitPoints(pnum, 0); } -void DropHalfPlayersGold(int pnum) +static int DropGold(int pnum, int amount, bool skipFullStacks) { - int i, hGold; + auto &player = plr[pnum]; + + for (int i = 0; i < player._pNumInv && amount > 0; i++) { + auto &item = player.InvList[i]; + + if (item._itype != ITYPE_GOLD || (skipFullStacks && item._ivalue == MaxGold)) + continue; + + if (amount < item._ivalue) { + item._ivalue -= amount; + SetPlrHandItem(&player.HoldItem, IDI_GOLD); + GetGoldSeed(pnum, &player.HoldItem); + SetPlrHandGoldCurs(&player.HoldItem); + player.HoldItem._ivalue = amount; + PlrDeadItem(player, &player.HoldItem, 0, 0); + return 0; + } + + amount -= item._ivalue; + player.RemoveInvItem(i); + SetPlrHandItem(&player.HoldItem, IDI_GOLD); + GetGoldSeed(pnum, &player.HoldItem); + SetPlrHandGoldCurs(&player.HoldItem); + player.HoldItem._ivalue = item._ivalue; + PlrDeadItem(player, &player.HoldItem, 0, 0); + i = -1; + } + return amount; +} + +void DropHalfPlayersGold(int pnum) +{ if ((DWORD)pnum >= MAX_PLRS) { app_fatal("DropHalfPlayersGold: illegal player %i", pnum); } auto &player = plr[pnum]; - hGold = player._pGold / 2; - for (i = 0; i < MAXBELTITEMS && hGold > 0; i++) { - if (player.SpdList[i]._itype == ITYPE_GOLD && player.SpdList[i]._ivalue != MaxGold) { - if (hGold < player.SpdList[i]._ivalue) { - player.SpdList[i]._ivalue -= hGold; - SetSpdbarGoldCurs(pnum, i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = hGold; - PlrDeadItem(player, &player.HoldItem, 0, 0); - hGold = 0; - } else { - hGold -= player.SpdList[i]._ivalue; - RemoveSpdBarItem(pnum, i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = player.SpdList[i]._ivalue; - PlrDeadItem(player, &player.HoldItem, 0, 0); - i = -1; - } - } - } - if (hGold > 0) { - for (i = 0; i < MAXBELTITEMS && hGold > 0; i++) { - if (player.SpdList[i]._itype == ITYPE_GOLD) { - if (hGold < player.SpdList[i]._ivalue) { - player.SpdList[i]._ivalue -= hGold; - SetSpdbarGoldCurs(pnum, i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = hGold; - PlrDeadItem(player, &player.HoldItem, 0, 0); - hGold = 0; - } else { - hGold -= player.SpdList[i]._ivalue; - RemoveSpdBarItem(pnum, i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = player.SpdList[i]._ivalue; - PlrDeadItem(player, &player.HoldItem, 0, 0); - i = -1; - } - } - } - } - force_redraw = 255; - if (hGold > 0) { - for (i = 0; i < player._pNumInv && hGold > 0; i++) { - if (player.InvList[i]._itype == ITYPE_GOLD && player.InvList[i]._ivalue != MaxGold) { - if (hGold < player.InvList[i]._ivalue) { - player.InvList[i]._ivalue -= hGold; - SetGoldCurs(pnum, i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = hGold; - PlrDeadItem(player, &player.HoldItem, 0, 0); - hGold = 0; - } else { - hGold -= player.InvList[i]._ivalue; - player.RemoveInvItem(i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = player.InvList[i]._ivalue; - PlrDeadItem(player, &player.HoldItem, 0, 0); - i = -1; - } - } - } - } - if (hGold > 0) { - for (i = 0; i < player._pNumInv && hGold > 0; i++) { - if (player.InvList[i]._itype == ITYPE_GOLD) { - if (hGold < player.InvList[i]._ivalue) { - player.InvList[i]._ivalue -= hGold; - SetGoldCurs(pnum, i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = hGold; - PlrDeadItem(player, &player.HoldItem, 0, 0); - hGold = 0; - } else { - hGold -= player.InvList[i]._ivalue; - player.RemoveInvItem(i); - SetPlrHandItem(&player.HoldItem, IDI_GOLD); - GetGoldSeed(pnum, &player.HoldItem); - SetPlrHandGoldCurs(&player.HoldItem); - player.HoldItem._ivalue = player.InvList[i]._ivalue; - PlrDeadItem(player, &player.HoldItem, 0, 0); - i = -1; - } - } - } - } - player._pGold = CalculateGold(player); + int hGold = player._pGold / 2; + + hGold = DropGold(pnum, hGold, true); + if (hGold > 0) + DropGold(pnum, hGold, false); + + player._pGold -= hGold; } void StripTopGold(int pnum) @@ -1910,7 +1855,6 @@ void StripTopGold(int pnum) if (player.InvList[i]._ivalue > MaxGold) { val = player.InvList[i]._ivalue - MaxGold; player.InvList[i]._ivalue = MaxGold; - SetGoldCurs(pnum, i); SetPlrHandItem(&player.HoldItem, 0); GetGoldSeed(pnum, &player.HoldItem); player.HoldItem._ivalue = val; diff --git a/Source/player.h b/Source/player.h index 0c0779a53..755b010e9 100644 --- a/Source/player.h +++ b/Source/player.h @@ -312,6 +312,8 @@ struct PlayerStruct { */ void RemoveInvItem(int iv, bool calcScrolls = true); + void RemoveSpdBarItem(int iv); + /** * @brief Gets the most valuable item out of all the player's items that match the given predicate. * @param itemPredicate The predicate used to match the items. diff --git a/Source/portal.cpp b/Source/portal.cpp index f98ce7c29..c596214ef 100644 --- a/Source/portal.cpp +++ b/Source/portal.cpp @@ -140,23 +140,25 @@ void GetPortalLevel() currlevel = 0; plr[myplr].plrlevel = 0; leveltype = DTYPE_TOWN; + return; + } + + if (portal[portalindex].setlvl) { + setlevel = true; + setlvlnum = (_setlevels)portal[portalindex].level; + currlevel = portal[portalindex].level; + plr[myplr].plrlevel = setlvlnum; + leveltype = portal[portalindex].ltype; } else { - if (portal[portalindex].setlvl) { - setlevel = true; - setlvlnum = (_setlevels)portal[portalindex].level; - currlevel = portal[portalindex].level; - plr[myplr].plrlevel = setlvlnum; - leveltype = portal[portalindex].ltype; - } else { - setlevel = false; - currlevel = portal[portalindex].level; - plr[myplr].plrlevel = currlevel; - leveltype = portal[portalindex].ltype; - } - if (portalindex == myplr) { - NetSendCmd(true, CMD_DEACTIVATEPORTAL); - DeactivatePortal(portalindex); - } + setlevel = false; + currlevel = portal[portalindex].level; + plr[myplr].plrlevel = currlevel; + leveltype = portal[portalindex].ltype; + } + + if (portalindex == myplr) { + NetSendCmd(true, CMD_DEACTIVATEPORTAL); + DeactivatePortal(portalindex); } } diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index 35b1b4f98..e4cbca02a 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -68,7 +68,7 @@ void DrawXPBar(const CelOutputBuffer &out) if (!sgOptions.Gameplay.bExperienceBar) return; - const PlayerStruct &player = plr[myplr]; + const auto &player = plr[myplr]; const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155; const int backY = PANEL_TOP + PANEL_HEIGHT - 11; @@ -119,7 +119,7 @@ bool CheckXPBarInfo() if (MouseX < backX || MouseX >= backX + BACK_WIDTH || MouseY < backY || MouseY >= backY + BACK_HEIGHT) return false; - const PlayerStruct &player = plr[myplr]; + const auto &player = plr[myplr]; const int charLevel = player._pLevel; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index f6927da27..0e962ffdb 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -408,10 +408,10 @@ static void DrawPlayer(const CelOutputBuffer &out, int pnum, int x, int y, int p return; } - PlayerStruct *pPlayer = &plr[pnum]; + auto &player = plr[pnum]; - auto *pCelSprite = pPlayer->AnimInfo.pCelSprite; - int nCel = pPlayer->AnimInfo.GetFrameToUseForRendering(); + auto *pCelSprite = player.AnimInfo.pCelSprite; + int nCel = player.AnimInfo.GetFrameToUseForRendering(); if (pCelSprite == nullptr) { Log("Drawing player {} \"{}\": NULL CelSprite", pnum, plr[pnum]._pName); @@ -471,17 +471,14 @@ static void DrawPlayer(const CelOutputBuffer &out, int pnum, int x, int y, int p */ void DrawDeadPlayer(const CelOutputBuffer &out, int x, int y, int sx, int sy) { - int i, px, py; - PlayerStruct *p; - dFlags[x][y] &= ~BFLAG_DEAD_PLAYER; - for (i = 0; i < MAX_PLRS; i++) { - p = &plr[i]; - if (p->plractive && p->_pHitPoints == 0 && p->plrlevel == (BYTE)currlevel && p->position.tile.x == x && p->position.tile.y == y) { + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = plr[i]; + if (player.plractive && player._pHitPoints == 0 && player.plrlevel == (BYTE)currlevel && player.position.tile.x == x && player.position.tile.y == y) { dFlags[x][y] |= BFLAG_DEAD_PLAYER; - px = sx + p->position.offset.x - CalculateWidth2(p->AnimInfo.pCelSprite == nullptr ? 96 : p->AnimInfo.pCelSprite->Width()); - py = sy + p->position.offset.y; + int px = sx + player.position.offset.x - CalculateWidth2(player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width()); + int py = sy + player.position.offset.y; DrawPlayer(out, i, x, y, px, py); } } @@ -711,13 +708,13 @@ static void DrawPlayerHelper(const CelOutputBuffer &out, int x, int y, int sx, i Log("draw player: tried to draw illegal player {}", p); return; } + auto &player = plr[p]; - PlayerStruct *pPlayer = &plr[p]; - Point offset = pPlayer->position.offset; - if (pPlayer->IsWalking()) { - offset = GetOffsetForWalking(pPlayer->AnimInfo, pPlayer->_pdir); + Point offset = player.position.offset; + if (player.IsWalking()) { + offset = GetOffsetForWalking(player.AnimInfo, player._pdir); } - int px = sx + offset.x - CalculateWidth2(pPlayer->AnimInfo.pCelSprite == nullptr ? 96 : pPlayer->AnimInfo.pCelSprite->Width()); + int px = sx + offset.x - CalculateWidth2(player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width()); int py = sy + offset.y; DrawPlayer(out, p, x, y, px, py); @@ -1147,10 +1144,10 @@ static void DrawGame(const CelOutputBuffer &full_out, int x, int y) : full_out.subregionY(0, (gnViewportHeight + 1) / 2); // Adjust by player offset and tile grid alignment - PlayerStruct *pPlayer = &plr[myplr]; + auto &myPlayer = plr[myplr]; Point offset = ScrollInfo.offset; - if (pPlayer->IsWalking()) - offset = GetOffsetForWalking(pPlayer->AnimInfo, pPlayer->_pdir, true); + if (myPlayer.IsWalking()) + offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); sx = offset.x + tileOffsetX; sy = offset.y + tileOffsetY; diff --git a/Source/stores.cpp b/Source/stores.cpp index de3156336..8254e197b 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -197,14 +197,17 @@ void PrintStoreItem(ItemStruct *x, int l, uint16_t flags) void StoreAutoPlace() { - bool done = false; - if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem)) { - done = true; + auto &myPlayer = plr[myplr]; + + if (AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem)) { + return; } - if (!done) { - AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, true) || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, true); + if (AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, true)) { + return; } + + AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, true); } void S_StartSmith() @@ -252,20 +255,22 @@ void S_ScrollSBuy(int idx) void S_StartSBuy() { - int i; - stextsize = true; stextscrl = true; stextsval = 0; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); S_ScrollSBuy(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, false); OffsetSTextY(22, 6); + storenumh = 0; - for (i = 0; !smithitem[i].isEmpty(); i++) { + for (int i = 0; !smithitem[i].isEmpty(); i++) { storenumh++; } @@ -303,10 +308,8 @@ void S_ScrollSPBuy(int boughtitems) bool S_StartSPBuy() { - int i; - storenumh = 0; - for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) { + for (int i = 0; i < SMITH_PREMIUM_ITEMS; i++) { if (!premiumitems[i].isEmpty()) storenumh++; } @@ -320,7 +323,9 @@ bool S_StartSPBuy() stextscrl = true; stextsval = 0; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "I have these premium items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("I have these premium items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); @@ -404,15 +409,18 @@ void S_StartSSell() bool sellok = false; storenumh = 0; - for (int i = 0; i < 48; i++) + for (int i = 0; i < 48; i++) { storehold[i]._itype = ITYPE_NONE; + } + + const auto &myPlayer = plr[myplr]; - for (int i = 0; i < plr[myplr]._pNumInv; i++) { + for (int i = 0; i < myPlayer._pNumInv; i++) { if (storenumh >= 48) break; if (SmithSellOk(i)) { sellok = true; - storehold[storenumh] = plr[myplr].InvList[i]; + storehold[storenumh] = myPlayer.InvList[i]; if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) storehold[storenumh]._ivalue = storehold[storenumh]._iIvalue; @@ -428,8 +436,8 @@ void S_StartSSell() if (storenumh >= 48) break; if (SmithSellOk(-(i + 1))) { - storehold[storenumh] = plr[myplr].SpdList[i]; sellok = true; + storehold[storenumh] = myPlayer.SpdList[i]; if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) storehold[storenumh]._ivalue = storehold[storenumh]._iIvalue; @@ -443,35 +451,44 @@ void S_StartSSell() if (!sellok) { stextscrl = false; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "You have nothing I want. Your gold: {:d}"), plr[myplr]._pGold).c_str()); - AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); - AddSLine(3); - AddSLine(21); - AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); - OffsetSTextY(22, 6); - } else { - stextscrl = true; - stextsval = 0; - stextsmax = plr[myplr]._pNumInv; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "Which item is for sale? Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("You have nothing I want. Your gold: {:d}"), myPlayer._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); + return; } + + stextscrl = true; + stextsval = 0; + stextsmax = myPlayer._pNumInv; + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("Which item is for sale? Your gold: {:d}"), myPlayer._pGold).c_str()); + + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); + AddSLine(3); + AddSLine(21); + S_ScrollSSell(stextsval); + AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); + OffsetSTextY(22, 6); } bool SmithRepairOk(int i) { - if (plr[myplr].InvList[i].isEmpty()) + const auto &myPlayer = plr[myplr]; + + if (myPlayer.InvList[i].isEmpty()) return false; - if (plr[myplr].InvList[i]._itype == ITYPE_MISC) + if (myPlayer.InvList[i]._itype == ITYPE_MISC) return false; - if (plr[myplr].InvList[i]._itype == ITYPE_GOLD) + if (myPlayer.InvList[i]._itype == ITYPE_GOLD) return false; - if (plr[myplr].InvList[i]._iDurability == plr[myplr].InvList[i]._iMaxDur) + if (myPlayer.InvList[i]._iDurability == myPlayer.InvList[i]._iMaxDur) return false; return true; @@ -479,41 +496,54 @@ bool SmithRepairOk(int i) void S_StartSRepair() { - bool repairok; - int i; - stextsize = true; - repairok = false; + bool repairok = false; storenumh = 0; - for (i = 0; i < 48; i++) + + for (int i = 0; i < 48; i++) storehold[i]._itype = ITYPE_NONE; - if (!plr[myplr].InvBody[INVLOC_HEAD].isEmpty() && plr[myplr].InvBody[INVLOC_HEAD]._iDurability != plr[myplr].InvBody[INVLOC_HEAD]._iMaxDur) { + + auto &myPlayer = plr[myplr]; + + auto &helmet = myPlayer.InvBody[INVLOC_HEAD]; + if (!helmet.isEmpty() && helmet._iDurability != helmet._iMaxDur) { repairok = true; - AddStoreHoldRepair(plr[myplr].InvBody, -1); + AddStoreHoldRepair(&helmet, -1); } - if (!plr[myplr].InvBody[INVLOC_CHEST].isEmpty() && plr[myplr].InvBody[INVLOC_CHEST]._iDurability != plr[myplr].InvBody[INVLOC_CHEST]._iMaxDur) { + + auto &armor = myPlayer.InvBody[INVLOC_CHEST]; + if (!armor.isEmpty() && armor._iDurability != armor._iMaxDur) { repairok = true; - AddStoreHoldRepair(&plr[myplr].InvBody[INVLOC_CHEST], -2); + AddStoreHoldRepair(&armor, -2); } - if (!plr[myplr].InvBody[INVLOC_HAND_LEFT].isEmpty() && plr[myplr].InvBody[INVLOC_HAND_LEFT]._iDurability != plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMaxDur) { + + auto &leftHand = myPlayer.InvBody[INVLOC_HAND_LEFT]; + if (!leftHand.isEmpty() && leftHand._iDurability != leftHand._iMaxDur) { repairok = true; - AddStoreHoldRepair(&plr[myplr].InvBody[INVLOC_HAND_LEFT], -3); + AddStoreHoldRepair(&leftHand, -3); } - if (!plr[myplr].InvBody[INVLOC_HAND_RIGHT].isEmpty() && plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iDurability != plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iMaxDur) { + + auto &rightHand = myPlayer.InvBody[INVLOC_HAND_RIGHT]; + if (!rightHand.isEmpty() && rightHand._iDurability != rightHand._iMaxDur) { repairok = true; - AddStoreHoldRepair(&plr[myplr].InvBody[INVLOC_HAND_RIGHT], -4); + AddStoreHoldRepair(&rightHand, -4); } - for (i = 0; i < plr[myplr]._pNumInv; i++) { + + for (int i = 0; i < myPlayer._pNumInv; i++) { if (storenumh >= 48) break; if (SmithRepairOk(i)) { repairok = true; - AddStoreHoldRepair(&plr[myplr].InvList[i], i); + AddStoreHoldRepair(&myPlayer.InvList[i], i); } } + if (!repairok) { stextscrl = false; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "You have nothing to repair. Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("You have nothing to repair. Your gold: {:d}"), myPlayer._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); @@ -524,8 +554,11 @@ void S_StartSRepair() stextscrl = true; stextsval = 0; - stextsmax = plr[myplr]._pNumInv; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "Repair which item? Your gold: {:d}"), plr[myplr]._pGold).c_str()); + stextsmax = myPlayer._pNumInv; + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("Repair which item? Your gold: {:d}"), myPlayer._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); @@ -538,11 +571,14 @@ void FillManaPlayer() { if (!sgOptions.Gameplay.bAdriaRefillsMana) return; - if (plr[myplr]._pMana != plr[myplr]._pMaxMana) { + + auto &myPlayer = plr[myplr]; + + if (myPlayer._pMana != myPlayer._pMaxMana) { PlaySFX(IS_CAST8); } - plr[myplr]._pMana = plr[myplr]._pMaxMana; - plr[myplr]._pManaBase = plr[myplr]._pMaxManaBase; + myPlayer._pMana = myPlayer._pMaxMana; + myPlayer._pManaBase = myPlayer._pMaxManaBase; drawmanaflag = true; } @@ -596,7 +632,10 @@ void S_StartWBuy() stextscrl = true; stextsval = 0; stextsmax = 20; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); @@ -615,10 +654,9 @@ void S_StartWBuy() bool WitchSellOk(int i) { - bool rv; ItemStruct *pI; - rv = false; + bool rv = false; if (i >= 0) pI = &plr[myplr].InvList[i]; @@ -642,88 +680,91 @@ bool WitchSellOk(int i) void S_StartWSell() { - int i; - bool sellok; - stextsize = true; - sellok = false; + bool sellok = false; storenumh = 0; - for (i = 0; i < 48; i++) + for (int i = 0; i < 48; i++) storehold[i]._itype = ITYPE_NONE; - for (i = 0; i < plr[myplr]._pNumInv; i++) { + const auto &myPlayer = plr[myplr]; + + for (int i = 0; i < myPlayer._pNumInv; i++) { if (storenumh >= 48) break; if (WitchSellOk(i)) { sellok = true; - storehold[storenumh] = plr[myplr].InvList[i]; + storehold[storenumh] = myPlayer.InvList[i]; if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) storehold[storenumh]._ivalue = storehold[storenumh]._iIvalue; - if ((storehold[storenumh]._ivalue >>= 2) == 0) - storehold[storenumh]._ivalue = 1; - + storehold[storenumh]._ivalue = std::max(storehold[storenumh]._ivalue / 4, 1); storehold[storenumh]._iIvalue = storehold[storenumh]._ivalue; - storehidx[storenumh++] = i; + storehidx[storenumh] = i; + storenumh++; } } - for (i = 0; i < MAXBELTITEMS; i++) { + for (int i = 0; i < MAXBELTITEMS; i++) { if (storenumh >= 48) break; - if (!plr[myplr].SpdList[i].isEmpty() && WitchSellOk(-(i + 1))) { + if (!myPlayer.SpdList[i].isEmpty() && WitchSellOk(-(i + 1))) { sellok = true; - storehold[storenumh] = plr[myplr].SpdList[i]; + storehold[storenumh] = myPlayer.SpdList[i]; if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) storehold[storenumh]._ivalue = storehold[storenumh]._iIvalue; - if ((storehold[storenumh]._ivalue >>= 2) == 0) - storehold[storenumh]._ivalue = 1; - + storehold[storenumh]._ivalue = std::max(storehold[storenumh]._ivalue / 4, 1); storehold[storenumh]._iIvalue = storehold[storenumh]._ivalue; - storehidx[storenumh++] = -(i + 1); + storehidx[storenumh] = -(i + 1); + storenumh++; } } if (!sellok) { stextscrl = false; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "You have nothing I want. Your gold: {:d}"), plr[myplr]._pGold).c_str()); - AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); - AddSLine(3); - AddSLine(21); - AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); - OffsetSTextY(22, 6); - } else { - stextscrl = true; - stextsval = 0; - stextsmax = plr[myplr]._pNumInv; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "Which item is for sale? Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("You have nothing I want. Your gold: {:d}"), myPlayer._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); + return; } + + stextscrl = true; + stextsval = 0; + stextsmax = myPlayer._pNumInv; + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("Which item is for sale? Your gold: {:d}"), myPlayer._pGold).c_str()); + + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); + AddSLine(3); + AddSLine(21); + S_ScrollSSell(stextsval); + AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); + OffsetSTextY(22, 6); } bool WitchRechargeOk(int i) { - bool rv; + const auto &item = plr[myplr].InvList[i]; - rv = false; - if (plr[myplr].InvList[i]._itype == ITYPE_STAFF - && plr[myplr].InvList[i]._iCharges != plr[myplr].InvList[i]._iMaxCharges) { - rv = true; + if (item._itype == ITYPE_STAFF && item._iCharges != item._iMaxCharges) { + return true; } - if ((plr[myplr].InvList[i]._iMiscId == IMISC_UNIQUE || plr[myplr].InvList[i]._iMiscId == IMISC_STAFF) - && plr[myplr].InvList[i]._iCharges < plr[myplr].InvList[i]._iMaxCharges) { - rv = true; + + if ((item._iMiscId == IMISC_UNIQUE || item._iMiscId == IMISC_STAFF) && item._iCharges < item._iMaxCharges) { + return true; } - return rv; + + return false; } void AddStoreHoldRecharge(ItemStruct itm, int i) @@ -738,52 +779,58 @@ void AddStoreHoldRecharge(ItemStruct itm, int i) void S_StartWRecharge() { - int i; - bool rechargeok; - stextsize = true; - rechargeok = false; + bool rechargeok = false; storenumh = 0; - for (i = 0; i < 48; i++) { + for (int i = 0; i < 48; i++) { storehold[i]._itype = ITYPE_NONE; } - if ((plr[myplr].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_STAFF || plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMiscId == IMISC_UNIQUE) - && plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges != plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMaxCharges) { + const auto &myPlayer = plr[myplr]; + const auto &leftHand = myPlayer.InvBody[INVLOC_HAND_LEFT]; + + if ((leftHand._itype == ITYPE_STAFF || leftHand._iMiscId == IMISC_UNIQUE) && leftHand._iCharges != leftHand._iMaxCharges) { rechargeok = true; - AddStoreHoldRecharge(plr[myplr].InvBody[INVLOC_HAND_LEFT], -1); + AddStoreHoldRecharge(leftHand, -1); } - for (i = 0; i < plr[myplr]._pNumInv; i++) { + for (int i = 0; i < myPlayer._pNumInv; i++) { if (storenumh >= 48) break; if (WitchRechargeOk(i)) { rechargeok = true; - AddStoreHoldRecharge(plr[myplr].InvList[i], i); + AddStoreHoldRecharge(myPlayer.InvList[i], i); } } if (!rechargeok) { stextscrl = false; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "You have nothing to recharge. Your gold: {:d}"), plr[myplr]._pGold).c_str()); - AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); - AddSLine(3); - AddSLine(21); - AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); - OffsetSTextY(22, 6); - } else { - stextscrl = true; - stextsval = 0; - stextsmax = plr[myplr]._pNumInv; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "Recharge which item? Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("You have nothing to recharge. Your gold: {:d}"), myPlayer._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); + return; } + + stextscrl = true; + stextsval = 0; + stextsmax = myPlayer._pNumInv; + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("Recharge which item? Your gold: {:d}"), myPlayer._pGold).c_str()); + + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); + AddSLine(3); + AddSLine(21); + S_ScrollSSell(stextsval); + AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); + OffsetSTextY(22, 6); } void S_StartNoMoney() @@ -805,18 +852,19 @@ void S_StartNoRoom() void S_StartConfirm() { - bool idprint; - StartStore(stextshold); stextscrl = false; ClearSText(5, 23); - uint16_t iclr = plr[myplr].HoldItem.getTextColor(); - idprint = plr[myplr].HoldItem._iMagical != ITEM_QUALITY_NORMAL; + auto &item = plr[myplr].HoldItem; + + uint16_t iclr = item.getTextColor(); + + bool idprint = item._iMagical != ITEM_QUALITY_NORMAL; if (stextshold == STORE_SIDENTIFY) idprint = false; - if (plr[myplr].HoldItem._iMagical != ITEM_QUALITY_NORMAL && !plr[myplr].HoldItem._iIdentified) { + if (item._iMagical != ITEM_QUALITY_NORMAL && !item._iIdentified) { if (stextshold == STORE_SSELL) idprint = false; if (stextshold == STORE_WSELL) @@ -827,12 +875,12 @@ void S_StartConfirm() idprint = false; } if (idprint) - AddSText(20, 8, plr[myplr].HoldItem._iIName, iclr, false); + AddSText(20, 8, item._iIName, iclr, false); else - AddSText(20, 8, plr[myplr].HoldItem._iName, iclr, false); + AddSText(20, 8, item._iName, iclr, false); - AddSTextVal(8, plr[myplr].HoldItem._iIvalue); - PrintStoreItem(&plr[myplr].HoldItem, 9, iclr); + AddSTextVal(8, item._iIvalue); + PrintStoreItem(&item, 9, iclr); switch (stextshold) { case STORE_BBOY: @@ -888,7 +936,10 @@ void S_StartBBoy() { stextsize = true; stextscrl = false; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "I have this item for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("I have this item for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); @@ -910,11 +961,13 @@ void S_StartBBoy() void HealPlayer() { - if (plr[myplr]._pHitPoints != plr[myplr]._pMaxHP) { + auto &myPlayer = plr[myplr]; + + if (myPlayer._pHitPoints != myPlayer._pMaxHP) { PlaySFX(IS_CAST8); } - plr[myplr]._pHitPoints = plr[myplr]._pMaxHP; - plr[myplr]._pHPBase = plr[myplr]._pMaxHPBase; + myPlayer._pHitPoints = myPlayer._pMaxHP; + myPlayer._pHPBase = myPlayer._pMaxHPBase; drawhpflag = true; } @@ -962,7 +1015,10 @@ void S_StartHBuy() stextsize = true; stextscrl = true; stextsval = 0; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); @@ -1013,74 +1069,94 @@ void AddStoreHoldId(ItemStruct itm, int i) void S_StartSIdentify() { - bool idok; - int i; - - idok = false; + bool idok = false; stextsize = true; storenumh = 0; - for (i = 0; i < 48; i++) + for (int i = 0; i < 48; i++) storehold[i]._itype = ITYPE_NONE; - if (IdItemOk(&plr[myplr].InvBody[INVLOC_HEAD])) { + auto &myPlayer = plr[myplr]; + + auto &helmet = myPlayer.InvBody[INVLOC_HEAD]; + if (IdItemOk(&helmet)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_HEAD], -1); + AddStoreHoldId(helmet, -1); } - if (IdItemOk(&plr[myplr].InvBody[INVLOC_CHEST])) { + + auto &armor = myPlayer.InvBody[INVLOC_CHEST]; + if (IdItemOk(&armor)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_CHEST], -2); + AddStoreHoldId(armor, -2); } - if (IdItemOk(&plr[myplr].InvBody[INVLOC_HAND_LEFT])) { + + auto &leftHand = myPlayer.InvBody[INVLOC_HAND_LEFT]; + if (IdItemOk(&leftHand)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_HAND_LEFT], -3); + AddStoreHoldId(leftHand, -3); } - if (IdItemOk(&plr[myplr].InvBody[INVLOC_HAND_RIGHT])) { + + auto &rightHand = myPlayer.InvBody[INVLOC_HAND_RIGHT]; + if (IdItemOk(&rightHand)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_HAND_RIGHT], -4); + AddStoreHoldId(rightHand, -4); } - if (IdItemOk(&plr[myplr].InvBody[INVLOC_RING_LEFT])) { + + auto &leftRing = myPlayer.InvBody[INVLOC_RING_LEFT]; + if (IdItemOk(&leftRing)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_RING_LEFT], -5); + AddStoreHoldId(leftRing, -5); } - if (IdItemOk(&plr[myplr].InvBody[INVLOC_RING_RIGHT])) { + + auto &rightRing = myPlayer.InvBody[INVLOC_RING_RIGHT]; + if (IdItemOk(&rightRing)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_RING_RIGHT], -6); + AddStoreHoldId(rightRing, -6); } - if (IdItemOk(&plr[myplr].InvBody[INVLOC_AMULET])) { + + auto &amulet = myPlayer.InvBody[INVLOC_AMULET]; + if (IdItemOk(&amulet)) { idok = true; - AddStoreHoldId(plr[myplr].InvBody[INVLOC_AMULET], -7); + AddStoreHoldId(amulet, -7); } - for (i = 0; i < plr[myplr]._pNumInv; i++) { + for (int i = 0; i < myPlayer._pNumInv; i++) { if (storenumh >= 48) break; - if (IdItemOk(&plr[myplr].InvList[i])) { + auto &item = myPlayer.InvList[i]; + if (IdItemOk(&item)) { idok = true; - AddStoreHoldId(plr[myplr].InvList[i], i); + AddStoreHoldId(item, i); } } if (!idok) { stextscrl = false; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "You have nothing to identify. Your gold: {:d}"), plr[myplr]._pGold).c_str()); - AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); - AddSLine(3); - AddSLine(21); - AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); - OffsetSTextY(22, 6); - } else { - stextscrl = true; - stextsval = 0; - stextsmax = plr[myplr]._pNumInv; - strcpy(tempstr, fmt::format(_(/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ "Identify which item? Your gold: {:d}"), plr[myplr]._pGold).c_str()); + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("You have nothing to identify. Your gold: {:d}"), myPlayer._pGold).c_str()); + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); + return; } + + stextscrl = true; + stextsval = 0; + stextsmax = myPlayer._pNumInv; + + /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ + strcpy(tempstr, fmt::format(_("Identify which item? Your gold: {:d}"), myPlayer._pGold).c_str()); + + AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); + AddSLine(3); + AddSLine(21); + S_ScrollSSell(stextsval); + AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); + OffsetSTextY(22, 6); } void S_StartIdShow() @@ -1088,11 +1164,14 @@ void S_StartIdShow() StartStore(stextshold); stextscrl = false; ClearSText(5, 23); - uint16_t iclr = plr[myplr].HoldItem.getTextColor(); + + auto &item = plr[myplr].HoldItem; + + uint16_t iclr = item.getTextColor(); AddSText(0, 7, _("This item is:"), UIS_SILVER | UIS_CENTER, false); - AddSText(20, 11, plr[myplr].HoldItem._iIName, iclr, false); - PrintStoreItem(&plr[myplr].HoldItem, 12, iclr); + AddSText(20, 11, item._iIName, iclr, false); + PrintStoreItem(&item, 12, iclr); AddSText(0, 18, _("Done"), UIS_SILVER | UIS_CENTER, true); } @@ -1212,13 +1291,13 @@ void S_SmithEnter() */ void SmithBuyItem() { - int idx; + auto &item = plr[myplr].HoldItem; - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); - if (plr[myplr].HoldItem._iMagical == ITEM_QUALITY_NORMAL) - plr[myplr].HoldItem._iIdentified = false; + TakePlrsMoney(item._iIvalue); + if (item._iMagical == ITEM_QUALITY_NORMAL) + item._iIdentified = false; StoreAutoPlace(); - idx = stextvhold + ((stextlhold - stextup) / 4); + int idx = stextvhold + ((stextlhold - stextup) / 4); if (idx == SMITH_ITEMS - 1) { smithitem[SMITH_ITEMS - 1]._itype = ITYPE_NONE; } else { @@ -1232,34 +1311,34 @@ void SmithBuyItem() void S_SBuyEnter() { - int idx; - bool done; - if (stextsel == 22) { StartStore(STORE_SMITH); stextsel = 12; - } else { - stextlhold = stextsel; - stextvhold = stextsval; - stextshold = STORE_SBUY; - idx = stextsval + ((stextsel - stextup) / 4); - if (plr[myplr]._pGold < smithitem[idx]._iIvalue) { - StartStore(STORE_NOMONEY); - } else { - plr[myplr].HoldItem = smithitem[idx]; - NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); - done = false; - if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false)) { - done = true; - } + return; + } - if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false)) - StartStore(STORE_CONFIRM); - else - StartStore(STORE_NOROOM); - NewCursor(CURSOR_HAND); - } + stextlhold = stextsel; + stextvhold = stextsval; + stextshold = STORE_SBUY; + + auto &myPlayer = plr[myplr]; + + int idx = stextsval + ((stextsel - stextup) / 4); + if (myPlayer._pGold < smithitem[idx]._iIvalue) { + StartStore(STORE_NOMONEY); + return; } + + myPlayer.HoldItem = smithitem[idx]; + NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); + + bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); + + if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false)) + StartStore(STORE_CONFIRM); + else + StartStore(STORE_NOROOM); + NewCursor(CURSOR_HAND); } /** @@ -1267,9 +1346,13 @@ void S_SBuyEnter() */ void SmithBuyPItem() { - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); - if (plr[myplr].HoldItem._iMagical == ITEM_QUALITY_NORMAL) - plr[myplr].HoldItem._iIdentified = false; + auto &item = plr[myplr].HoldItem; + + TakePlrsMoney(item._iIvalue); + + if (item._iMagical == ITEM_QUALITY_NORMAL) + item._iIdentified = false; + StoreAutoPlace(); int idx = stextvhold + ((stextlhold - stextup) / 4); @@ -1307,16 +1390,18 @@ void S_SPBuyEnter() } } - if (plr[myplr]._pGold < premiumitems[idx]._iIvalue) { + auto &myPlayer = plr[myplr]; + + if (myPlayer._pGold < premiumitems[idx]._iIvalue) { StartStore(STORE_NOMONEY); return; } - plr[myplr].HoldItem = premiumitems[idx]; - NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); - bool done = AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false); + myPlayer.HoldItem = premiumitems[idx]; + NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); + bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); - if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false)) + if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false)) StartStore(STORE_CONFIRM); else StartStore(STORE_NOROOM); @@ -1338,17 +1423,20 @@ bool StoreGoldFit(int idx) if (numsqrs >= sz) return true; + auto &myPlayer = plr[myplr]; + for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { - if (plr[myplr].InvGrid[i] == 0) + if (myPlayer.InvGrid[i] == 0) numsqrs++; } - for (int i = 0; i < plr[myplr]._pNumInv; i++) { - if (plr[myplr].InvList[i]._itype == ITYPE_GOLD && plr[myplr].InvList[i]._ivalue != MaxGold) { - if (cost + plr[myplr].InvList[i]._ivalue <= MaxGold) + for (int i = 0; i < myPlayer._pNumInv; i++) { + const auto &item = myPlayer.InvList[i]; + if (item._itype == ITYPE_GOLD && item._ivalue != MaxGold) { + if (cost + item._ivalue <= MaxGold) cost = 0; else - cost -= MaxGold - plr[myplr].InvList[i]._ivalue; + cost -= MaxGold - item._ivalue; } } @@ -1365,17 +1453,19 @@ bool StoreGoldFit(int idx) */ void PlaceStoreGold(int v) { + auto &myPlayer = plr[myplr]; + for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { int xx = i % 10; int yy = 10 * (i / 10); - if (plr[myplr].InvGrid[xx + yy] == 0) { - int ii = plr[myplr]._pNumInv; + if (myPlayer.InvGrid[xx + yy] == 0) { + int ii = myPlayer._pNumInv; GetGoldSeed(myplr, &golditem); - plr[myplr].InvList[ii] = golditem; - plr[myplr]._pNumInv++; - plr[myplr].InvGrid[xx + yy] = plr[myplr]._pNumInv; - plr[myplr].InvList[ii]._ivalue = v; - SetGoldCurs(myplr, ii); + myPlayer.InvList[ii] = golditem; + myPlayer._pNumInv++; + myPlayer.InvGrid[xx + yy] = myPlayer._pNumInv; + myPlayer.InvList[ii]._ivalue = v; + SetPlrHandGoldCurs(&myPlayer.InvList[ii]); return; } } @@ -1386,11 +1476,13 @@ void PlaceStoreGold(int v) */ void StoreSellItem() { + auto &myPlayer = plr[myplr]; + int idx = stextvhold + ((stextlhold - stextup) / 4); if (storehidx[idx] >= 0) - plr[myplr].RemoveInvItem(storehidx[idx]); + myPlayer.RemoveInvItem(storehidx[idx]); else - RemoveSpdBarItem(myplr, -(storehidx[idx] + 1)); + myPlayer.RemoveSpdBarItem(-(storehidx[idx] + 1)); int cost = storehold[idx]._iIvalue; storenumh--; @@ -1401,18 +1493,18 @@ void StoreSellItem() idx++; } } - plr[myplr]._pGold += cost; - for (int i = 0; i < plr[myplr]._pNumInv && cost > 0; i++) { - if (plr[myplr].InvList[i]._itype == ITYPE_GOLD && plr[myplr].InvList[i]._ivalue != MaxGold) { - if (cost + plr[myplr].InvList[i]._ivalue <= MaxGold) { - plr[myplr].InvList[i]._ivalue += cost; - SetGoldCurs(myplr, i); + myPlayer._pGold += cost; + for (int i = 0; i < myPlayer._pNumInv && cost > 0; i++) { + auto &item = myPlayer.InvList[i]; + if (item._itype == ITYPE_GOLD && item._ivalue != MaxGold) { + if (cost + item._ivalue <= MaxGold) { + item._ivalue += cost; cost = 0; } else { - cost -= MaxGold - plr[myplr].InvList[i]._ivalue; - plr[myplr].InvList[i]._ivalue = MaxGold; - SetGoldCurs(myplr, i); + cost -= MaxGold - item._ivalue; + item._ivalue = MaxGold; } + SetPlrHandGoldCurs(&myPlayer.InvList[i]); } } if (cost > 0) { @@ -1449,7 +1541,9 @@ void S_SSellEnter() */ void SmithRepairItem() { - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); + auto &myPlayer = plr[myplr]; + + TakePlrsMoney(myPlayer.HoldItem._iIvalue); int idx = stextvhold + ((stextlhold - stextup) / 4); storehold[idx]._iDurability = storehold[idx]._iMaxDur; @@ -1458,17 +1552,17 @@ void SmithRepairItem() if (i < 0) { if (i == -1) - plr[myplr].InvBody[INVLOC_HEAD]._iDurability = plr[myplr].InvBody[INVLOC_HEAD]._iMaxDur; + myPlayer.InvBody[INVLOC_HEAD]._iDurability = myPlayer.InvBody[INVLOC_HEAD]._iMaxDur; if (i == -2) - plr[myplr].InvBody[INVLOC_CHEST]._iDurability = plr[myplr].InvBody[INVLOC_CHEST]._iMaxDur; + myPlayer.InvBody[INVLOC_CHEST]._iDurability = myPlayer.InvBody[INVLOC_CHEST]._iMaxDur; if (i == -3) - plr[myplr].InvBody[INVLOC_HAND_LEFT]._iDurability = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMaxDur; + myPlayer.InvBody[INVLOC_HAND_LEFT]._iDurability = myPlayer.InvBody[INVLOC_HAND_LEFT]._iMaxDur; if (i == -4) - plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iDurability = plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iMaxDur; + myPlayer.InvBody[INVLOC_HAND_RIGHT]._iDurability = myPlayer.InvBody[INVLOC_HAND_RIGHT]._iMaxDur; return; } - plr[myplr].InvList[i]._iDurability = plr[myplr].InvList[i]._iMaxDur; + myPlayer.InvList[i]._iDurability = myPlayer.InvList[i]._iMaxDur; } void S_SRepairEnter() @@ -1484,8 +1578,11 @@ void S_SRepairEnter() stextvhold = stextsval; int idx = stextsval + ((stextsel - stextup) / 4); - plr[myplr].HoldItem = storehold[idx]; - if (plr[myplr]._pGold < storehold[idx]._iIvalue) + + auto &myPlayer = plr[myplr]; + + myPlayer.HoldItem = storehold[idx]; + if (myPlayer._pGold < storehold[idx]._iIvalue) StartStore(STORE_NOMONEY); else StartStore(STORE_CONFIRM); @@ -1522,12 +1619,14 @@ void S_WitchEnter() */ void WitchBuyItem() { + auto &myPlayer = plr[myplr]; + int idx = stextvhold + ((stextlhold - stextup) / 4); if (idx < 3) - plr[myplr].HoldItem._iSeed = AdvanceRndSeed(); + myPlayer.HoldItem._iSeed = AdvanceRndSeed(); - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); + TakePlrsMoney(myPlayer.HoldItem._iIvalue); StoreAutoPlace(); if (idx >= 3) { @@ -1556,18 +1655,20 @@ void S_WBuyEnter() stextvhold = stextsval; stextshold = STORE_WBUY; + auto &myPlayer = plr[myplr]; + int idx = stextsval + ((stextsel - stextup) / 4); - if (plr[myplr]._pGold < witchitem[idx]._iIvalue) { + if (myPlayer._pGold < witchitem[idx]._iIvalue) { StartStore(STORE_NOMONEY); return; } - plr[myplr].HoldItem = witchitem[idx]; - NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); - bool done = AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false); + myPlayer.HoldItem = witchitem[idx]; + NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); + bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); - if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false) || AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, false)) + if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false) || AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, false)) StartStore(STORE_CONFIRM); else StartStore(STORE_NOROOM); @@ -1600,16 +1701,18 @@ void S_WSellEnter() */ void WitchRechargeItem() { - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); + auto &myPlayer = plr[myplr]; + + TakePlrsMoney(myPlayer.HoldItem._iIvalue); int idx = stextvhold + ((stextlhold - stextup) / 4); storehold[idx]._iCharges = storehold[idx]._iMaxCharges; int i = storehidx[idx]; if (i < 0) - plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges = plr[myplr].InvBody[INVLOC_HAND_LEFT]._iMaxCharges; + myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iMaxCharges; else - plr[myplr].InvList[i]._iCharges = plr[myplr].InvList[i]._iMaxCharges; + myPlayer.InvList[i]._iCharges = myPlayer.InvList[i]._iMaxCharges; CalcPlrInv(myplr, true); } @@ -1626,9 +1729,11 @@ void S_WRechargeEnter() stextlhold = stextsel; stextvhold = stextsval; + auto &myPlayer = plr[myplr]; + int idx = stextsval + ((stextsel - stextup) / 4); - plr[myplr].HoldItem = storehold[idx]; - if (plr[myplr]._pGold < storehold[idx]._iIvalue) + myPlayer.HoldItem = storehold[idx]; + if (myPlayer._pGold < storehold[idx]._iIvalue) StartStore(STORE_NOMONEY); else StartStore(STORE_CONFIRM); @@ -1677,20 +1782,20 @@ void BoyBuyItem() */ void HealerBuyItem() { - int idx; + auto &item = plr[myplr].HoldItem; - idx = stextvhold + ((stextlhold - stextup) / 4); + int idx = stextvhold + ((stextlhold - stextup) / 4); if (!gbIsMultiplayer) { if (idx < 2) - plr[myplr].HoldItem._iSeed = AdvanceRndSeed(); + item._iSeed = AdvanceRndSeed(); } else { if (idx < 3) - plr[myplr].HoldItem._iSeed = AdvanceRndSeed(); + item._iSeed = AdvanceRndSeed(); } - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); - if (plr[myplr].HoldItem._iMagical == ITEM_QUALITY_NORMAL) - plr[myplr].HoldItem._iIdentified = false; + TakePlrsMoney(item._iIvalue); + if (item._iMagical == ITEM_QUALITY_NORMAL) + item._iIdentified = false; StoreAutoPlace(); if (!gbIsMultiplayer) { @@ -1728,22 +1833,24 @@ void S_BBuyEnter() else price += boyitem._iIvalue / 2; - if (plr[myplr]._pGold < price) { + auto &myPlayer = plr[myplr]; + + if (myPlayer._pGold < price) { StartStore(STORE_NOMONEY); return; } - plr[myplr].HoldItem = boyitem; - plr[myplr].HoldItem._iIvalue = price; - NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); + myPlayer.HoldItem = boyitem; + myPlayer.HoldItem._iIvalue = price; + NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); bool done = false; - if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false)) { + if (AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false)) { done = true; } if (!done) { - done = AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false); + done = AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false); } StartStore(done ? STORE_CONFIRM : STORE_NOROOM); @@ -1753,29 +1860,29 @@ void S_BBuyEnter() void StoryIdItem() { - int idx; + auto &myPlayer = plr[myplr]; - idx = storehidx[((stextlhold - stextup) / 4) + stextvhold]; + int idx = storehidx[((stextlhold - stextup) / 4) + stextvhold]; if (idx < 0) { if (idx == -1) - plr[myplr].InvBody[INVLOC_HEAD]._iIdentified = true; + myPlayer.InvBody[INVLOC_HEAD]._iIdentified = true; if (idx == -2) - plr[myplr].InvBody[INVLOC_CHEST]._iIdentified = true; + myPlayer.InvBody[INVLOC_CHEST]._iIdentified = true; if (idx == -3) - plr[myplr].InvBody[INVLOC_HAND_LEFT]._iIdentified = true; + myPlayer.InvBody[INVLOC_HAND_LEFT]._iIdentified = true; if (idx == -4) - plr[myplr].InvBody[INVLOC_HAND_RIGHT]._iIdentified = true; + myPlayer.InvBody[INVLOC_HAND_RIGHT]._iIdentified = true; if (idx == -5) - plr[myplr].InvBody[INVLOC_RING_LEFT]._iIdentified = true; + myPlayer.InvBody[INVLOC_RING_LEFT]._iIdentified = true; if (idx == -6) - plr[myplr].InvBody[INVLOC_RING_RIGHT]._iIdentified = true; + myPlayer.InvBody[INVLOC_RING_RIGHT]._iIdentified = true; if (idx == -7) - plr[myplr].InvBody[INVLOC_AMULET]._iIdentified = true; + myPlayer.InvBody[INVLOC_AMULET]._iIdentified = true; } else { - plr[myplr].InvList[idx]._iIdentified = true; + myPlayer.InvList[idx]._iIdentified = true; } - plr[myplr].HoldItem._iIdentified = true; - TakePlrsMoney(plr[myplr].HoldItem._iIvalue); + myPlayer.HoldItem._iIdentified = true; + TakePlrsMoney(myPlayer.HoldItem._iIvalue); CalcPlrInv(myplr, true); } @@ -1852,36 +1959,36 @@ void S_HealerEnter() void S_HBuyEnter() { - int idx; - bool done; - if (stextsel == 22) { StartStore(STORE_HEALER); stextsel = 16; - } else { - stextlhold = stextsel; - stextvhold = stextsval; - stextshold = STORE_HBUY; - idx = stextsval + ((stextsel - stextup) / 4); + return; + } - if (plr[myplr]._pGold < healitem[idx]._iIvalue) { - StartStore(STORE_NOMONEY); - } else { - plr[myplr].HoldItem = healitem[idx]; - NewCursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); - done = false; - if (AutoEquipEnabled(plr[myplr], plr[myplr].HoldItem) && AutoEquip(myplr, plr[myplr].HoldItem, false)) { - done = true; - } + stextlhold = stextsel; + stextvhold = stextsval; + stextshold = STORE_HBUY; - if (done || AutoPlaceItemInInventory(plr[myplr], plr[myplr].HoldItem, false) || AutoPlaceItemInBelt(myplr, plr[myplr].HoldItem, false)) - StartStore(STORE_CONFIRM); - else - StartStore(STORE_NOROOM); + int idx = stextsval + ((stextsel - stextup) / 4); - NewCursor(CURSOR_HAND); - } + auto &myPlayer = plr[myplr]; + + if (myPlayer._pGold < healitem[idx]._iIvalue) { + StartStore(STORE_NOMONEY); + return; } + + myPlayer.HoldItem = healitem[idx]; + NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); + + bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); + + if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false) || AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, false)) + StartStore(STORE_CONFIRM); + else + StartStore(STORE_NOROOM); + + NewCursor(CURSOR_HAND); } void S_StoryEnter() @@ -1906,22 +2013,24 @@ void S_StoryEnter() void S_SIDEnter() { - int idx; - if (stextsel == 22) { StartStore(STORE_STORY); stextsel = 14; - } else { - stextshold = STORE_SIDENTIFY; - stextlhold = stextsel; - stextvhold = stextsval; - idx = stextsval + ((stextsel - stextup) / 4); - plr[myplr].HoldItem = storehold[idx]; - if (plr[myplr]._pGold < storehold[idx]._iIvalue) - StartStore(STORE_NOMONEY); - else - StartStore(STORE_CONFIRM); + return; } + + stextshold = STORE_SIDENTIFY; + stextlhold = stextsel; + stextvhold = stextsval; + + auto &myPlayer = plr[myplr]; + + int idx = stextsval + ((stextsel - stextup) / 4); + myPlayer.HoldItem = storehold[idx]; + if (myPlayer._pGold < storehold[idx]._iIvalue) + StartStore(STORE_NOMONEY); + else + StartStore(STORE_CONFIRM); } void S_TalkEnter() @@ -2083,11 +2192,13 @@ void SetupTownStores() { SetRndSeed(glSeedTbl[currlevel] * SDL_GetTicks()); - int l = plr[myplr]._pLevel / 2; + auto &myPlayer = plr[myplr]; + + int l = myPlayer._pLevel / 2; if (!gbIsMultiplayer) { l = 0; for (int i = 0; i < NUMLEVELS; i++) { - if (plr[myplr]._pLvlVisited[i]) + if (myPlayer._pLvlVisited[i]) l = i; } } @@ -2097,7 +2208,7 @@ void SetupTownStores() SpawnSmith(l); SpawnWitch(l); SpawnHealer(l); - SpawnBoy(plr[myplr]._pLevel); + SpawnBoy(myPlayer._pLevel); SpawnPremium(myplr); } @@ -2514,79 +2625,36 @@ void STextNext() } } -void SetGoldCurs(int pnum, int i) +static int TakeGold(PlayerStruct &player, int cost, bool skipMaxPiles) { - SetPlrHandGoldCurs(&plr[pnum].InvList[i]); -} + for (int i = 0; i < player._pNumInv; i++) { + auto &item = player.InvList[i]; + if (item._itype != ITYPE_GOLD || (skipMaxPiles && item._ivalue == MaxGold)) + continue; -void SetSpdbarGoldCurs(int pnum, int i) -{ - SetPlrHandGoldCurs(&plr[pnum].SpdList[i]); + if (cost < item._ivalue) { + item._ivalue -= cost; + SetPlrHandGoldCurs(&player.InvList[i]); + return 0; + } + + cost -= item._ivalue; + player.RemoveInvItem(i); + i = -1; + } + + return cost; } void TakePlrsMoney(int cost) { - int i; + auto &myPlayer = plr[myplr]; - plr[myplr]._pGold = CalculateGold(plr[myplr]) - cost; - for (i = 0; i < MAXBELTITEMS && cost > 0; i++) { - if (plr[myplr].SpdList[i]._itype == ITYPE_GOLD && plr[myplr].SpdList[i]._ivalue != MaxGold) { - if (cost < plr[myplr].SpdList[i]._ivalue) { - plr[myplr].SpdList[i]._ivalue -= cost; - SetSpdbarGoldCurs(myplr, i); - cost = 0; - } else { - cost -= plr[myplr].SpdList[i]._ivalue; - RemoveSpdBarItem(myplr, i); - i = -1; - } - } - } - if (cost > 0) { - for (i = 0; i < MAXBELTITEMS && cost > 0; i++) { - if (plr[myplr].SpdList[i]._itype == ITYPE_GOLD) { - if (cost < plr[myplr].SpdList[i]._ivalue) { - plr[myplr].SpdList[i]._ivalue -= cost; - SetSpdbarGoldCurs(myplr, i); - cost = 0; - } else { - cost -= plr[myplr].SpdList[i]._ivalue; - RemoveSpdBarItem(myplr, i); - i = -1; - } - } - } - } - force_redraw = 255; - if (cost > 0) { - for (i = 0; i < plr[myplr]._pNumInv && cost > 0; i++) { - if (plr[myplr].InvList[i]._itype == ITYPE_GOLD && plr[myplr].InvList[i]._ivalue != MaxGold) { - if (cost < plr[myplr].InvList[i]._ivalue) { - plr[myplr].InvList[i]._ivalue -= cost; - SetGoldCurs(myplr, i); - cost = 0; - } else { - cost -= plr[myplr].InvList[i]._ivalue; - plr[myplr].RemoveInvItem(i); - i = -1; - } - } - } - if (cost > 0) { - for (i = 0; i < plr[myplr]._pNumInv && cost > 0; i++) { - if (plr[myplr].InvList[i]._itype == ITYPE_GOLD) { - if (cost < plr[myplr].InvList[i]._ivalue) { - plr[myplr].InvList[i]._ivalue -= cost; - SetGoldCurs(myplr, i); - cost = 0; - } else { - cost -= plr[myplr].InvList[i]._ivalue; - plr[myplr].RemoveInvItem(i); - i = -1; - } - } - } - } + myPlayer._pGold -= cost; + + cost = TakeGold(myPlayer, cost, true); + if (cost != 0) { + TakeGold(myPlayer, cost, false); } } diff --git a/Source/stores.h b/Source/stores.h index 9fbe3cace..e15cc21cf 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -108,8 +108,6 @@ void STextUp(); void STextDown(); void STextPrior(); void STextNext(); -void SetGoldCurs(int pnum, int i); -void SetSpdbarGoldCurs(int pnum, int i); void TakePlrsMoney(int cost); void STextEnter(); void CheckStoreBtn(); diff --git a/Source/towners.h b/Source/towners.h index bceb5dacf..96312026f 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -59,7 +59,6 @@ struct TownerStruct { /** Specifies the animation frame sequence. */ const uint8_t *animOrder; // unowned std::size_t animOrderSize; - PlayerStruct *_tTalkingToPlayer; void (*talk)(PlayerStruct &player, TownerStruct &barOwner); bool _tbtcnt; _talker_id _ttype; diff --git a/Source/trigs.cpp b/Source/trigs.cpp index 30d807c48..3c2287cce 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -76,7 +76,9 @@ void InitTownTriggers() townwarp = gbIsMultiplayer && !gbIsSpawn; } if (!gbIsSpawn) { - if (gbIsMultiplayer || plr[myplr].pTownWarps & 1 || (gbIsHellfire && plr[myplr]._pLevel >= 10)) { + auto &myPlayer = plr[myplr]; + + if (gbIsMultiplayer || myPlayer.pTownWarps & 1 || (gbIsHellfire && myPlayer._pLevel >= 10)) { townwarps[0] = true; trigs[numtrigs].position = { 49, 21 }; trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; @@ -87,14 +89,14 @@ void InitTownTriggers() #endif numtrigs++; } - if (gbIsMultiplayer || plr[myplr].pTownWarps & 2 || (gbIsHellfire && plr[myplr]._pLevel >= 15)) { + if (gbIsMultiplayer || myPlayer.pTownWarps & 2 || (gbIsHellfire && myPlayer._pLevel >= 15)) { townwarps[1] = true; trigs[numtrigs].position = { 17, 69 }; trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; trigs[numtrigs]._tlvl = 9; numtrigs++; } - if (gbIsMultiplayer || plr[myplr].pTownWarps & 4 || (gbIsHellfire && plr[myplr]._pLevel >= 20)) { + if (gbIsMultiplayer || myPlayer.pTownWarps & 4 || (gbIsHellfire && myPlayer._pLevel >= 20)) { townwarps[2] = true; trigs[numtrigs].position = { 41, 80 }; trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; @@ -816,18 +818,20 @@ void CheckTrigForce() void CheckTriggers() { - if (plr[myplr]._pmode != PM_STAND) + auto &myPlayer = plr[myplr]; + + if (myPlayer._pmode != PM_STAND) return; for (int i = 0; i < numtrigs; i++) { - if (plr[myplr].position.tile != trigs[i].position) { + if (myPlayer.position.tile != trigs[i].position) { continue; } switch (trigs[i]._tmsg) { case WM_DIABNEXTLVL: if (gbIsSpawn && currlevel >= 2) { - NetSendCmdLoc(myplr, true, CMD_WALKXY, { plr[myplr].position.tile.x, plr[myplr].position.tile.y + 1 }); + NetSendCmdLoc(myplr, true, CMD_WALKXY, { myPlayer.position.tile.x, myPlayer.position.tile.y + 1 }); PlaySFX(PS_WARR18); InitDiabloMsg(EMSG_NOT_IN_SHAREWARE); } else { @@ -845,27 +849,27 @@ void CheckTriggers() bool abort = false; diablo_message abortflag; - auto position = plr[myplr].position.tile; - if (trigs[i]._tlvl == 5 && plr[myplr]._pLevel < 8) { + auto position = myPlayer.position.tile; + if (trigs[i]._tlvl == 5 && myPlayer._pLevel < 8) { abort = true; position.y += 1; abortflag = EMSG_REQUIRES_LVL_8; } - if (trigs[i]._tlvl == 9 && plr[myplr]._pLevel < 13) { + if (trigs[i]._tlvl == 9 && myPlayer._pLevel < 13) { abort = true; position.x += 1; abortflag = EMSG_REQUIRES_LVL_13; } - if (trigs[i]._tlvl == 13 && plr[myplr]._pLevel < 17) { + if (trigs[i]._tlvl == 13 && myPlayer._pLevel < 17) { abort = true; position.y += 1; abortflag = EMSG_REQUIRES_LVL_17; } if (abort) { - plr[myplr].Say(HeroSpeech::ICantGetThereFromHere); + myPlayer.Say(HeroSpeech::ICantGetThereFromHere); InitDiabloMsg(abortflag); NetSendCmdLoc(myplr, true, CMD_WALKXY, position); diff --git a/test/control_test.cpp b/test/control_test.cpp index 977a1dcf8..5a265243e 100644 --- a/test/control_test.cpp +++ b/test/control_test.cpp @@ -10,10 +10,11 @@ TEST(Control, SetSpell) pinfoflag = true; pSpell = SPL_FIREBOLT; pSplType = RSPLTYPE_CHARGES; + auto &myPlayer = plr[myplr]; SetSpell(); EXPECT_EQ(spselflag, false); - EXPECT_EQ(plr[myplr]._pRSpell, SPL_FIREBOLT); - EXPECT_EQ(plr[myplr]._pRSplType, RSPLTYPE_CHARGES); + EXPECT_EQ(myPlayer._pRSpell, SPL_FIREBOLT); + EXPECT_EQ(myPlayer._pRSplType, RSPLTYPE_CHARGES); EXPECT_EQ(pnumlines, 0); EXPECT_EQ(pinfoflag, false); EXPECT_EQ(force_redraw, 255); diff --git a/test/inv_test.cpp b/test/inv_test.cpp index 9ab241aa7..50312f003 100644 --- a/test/inv_test.cpp +++ b/test/inv_test.cpp @@ -102,14 +102,14 @@ TEST(Inv, UseScroll_from_belt_invalid_conditions) TEST(Inv, CalculateGold) { plr[myplr]._pNumInv = 10; - // Set up two slots of gold both in the belt and inventory - plr[myplr].SpdList[1]._itype = ITYPE_GOLD; - plr[myplr].SpdList[5]._itype = ITYPE_GOLD; + // Set up 4 slots of gold in the inventory + plr[myplr].InvList[1]._itype = ITYPE_GOLD; + plr[myplr].InvList[5]._itype = ITYPE_GOLD; plr[myplr].InvList[2]._itype = ITYPE_GOLD; plr[myplr].InvList[3]._itype = ITYPE_GOLD; // Set the gold amount to arbitrary values - plr[myplr].SpdList[1]._ivalue = 100; - plr[myplr].SpdList[5]._ivalue = 200; + plr[myplr].InvList[1]._ivalue = 100; + plr[myplr].InvList[5]._ivalue = 200; plr[myplr].InvList[2]._ivalue = 3; plr[myplr].InvList[3]._ivalue = 30; @@ -187,7 +187,7 @@ TEST(Inv, RemoveSpdBarItem) // Put an item in the belt: | x | x | item | x | x | x | x | x | plr[myplr].SpdList[3]._itype = ITYPE_MISC; - RemoveSpdBarItem(myplr, 3); + plr[myplr].RemoveSpdBarItem(3); EXPECT_EQ(plr[myplr].SpdList[3]._itype, ITYPE_NONE); } diff --git a/test/player_test.cpp b/test/player_test.cpp index ccd2b0dc5..f37510b4e 100644 --- a/test/player_test.cpp +++ b/test/player_test.cpp @@ -11,16 +11,18 @@ extern bool PM_DoGotHit(int pnum); int RunBlockTest(int frames, int flags) { int pnum = 0; - plr[pnum]._pHFrames = frames; - plr[pnum]._pIFlags = flags; + auto &player = plr[pnum]; + + player._pHFrames = frames; + player._pIFlags = flags; StartPlrHit(pnum, 5, Direction::DIR_S); int i = 1; for (; i < 100; i++) { PM_DoGotHit(pnum); - if (plr[pnum]._pmode != PM_GOTHIT) + if (player._pmode != PM_GOTHIT) break; - plr[pnum].AnimInfo.CurrentFrame++; + player.AnimInfo.CurrentFrame++; } return i; diff --git a/test/writehero_test.cpp b/test/writehero_test.cpp index 16398eddd..43232f4bc 100644 --- a/test/writehero_test.cpp +++ b/test/writehero_test.cpp @@ -242,113 +242,113 @@ static int CountBool(bool *bools, int n) return count; } -static void AssertPlayer(PlayerStruct *pPlayer) +static void AssertPlayer(PlayerStruct &player) { - ASSERT_EQ(Count8(pPlayer->_pSplLvl, 64), 23); - ASSERT_EQ(Count8(pPlayer->InvGrid, NUM_INV_GRID_ELEM), 9); - ASSERT_EQ(CountItems(pPlayer->InvBody, NUM_INVLOC), 6); - ASSERT_EQ(CountItems(pPlayer->InvList, NUM_INV_GRID_ELEM), 2); - ASSERT_EQ(CountItems(pPlayer->SpdList, MAXBELTITEMS), 8); - ASSERT_EQ(CountItems(&pPlayer->HoldItem, 1), 1); + ASSERT_EQ(Count8(player._pSplLvl, 64), 23); + ASSERT_EQ(Count8(player.InvGrid, NUM_INV_GRID_ELEM), 9); + ASSERT_EQ(CountItems(player.InvBody, NUM_INVLOC), 6); + ASSERT_EQ(CountItems(player.InvList, NUM_INV_GRID_ELEM), 2); + ASSERT_EQ(CountItems(player.SpdList, MAXBELTITEMS), 8); + ASSERT_EQ(CountItems(&player.HoldItem, 1), 1); - ASSERT_EQ(pPlayer->position.tile.x, 75); - ASSERT_EQ(pPlayer->position.tile.y, 68); - ASSERT_EQ(pPlayer->position.future.x, 75); - ASSERT_EQ(pPlayer->position.future.y, 68); - ASSERT_EQ(pPlayer->plrlevel, 0); - ASSERT_EQ(pPlayer->destAction, -1); - ASSERT_STREQ(pPlayer->_pName, "TestPlayer"); - ASSERT_EQ(pPlayer->_pClass, HeroClass::Rogue); - ASSERT_EQ(pPlayer->_pBaseStr, 55); - ASSERT_EQ(pPlayer->_pStrength, 124); - ASSERT_EQ(pPlayer->_pBaseMag, 70); - ASSERT_EQ(pPlayer->_pMagic, 80); - ASSERT_EQ(pPlayer->_pBaseDex, 250); - ASSERT_EQ(pPlayer->_pDexterity, 281); - ASSERT_EQ(pPlayer->_pBaseVit, 80); - ASSERT_EQ(pPlayer->_pVitality, 90); - ASSERT_EQ(pPlayer->_pLevel, 50); - ASSERT_EQ(pPlayer->_pStatPts, 0); - ASSERT_EQ(pPlayer->_pExperience, 1583495809); - ASSERT_EQ(pPlayer->_pGold, 0); - ASSERT_EQ(pPlayer->_pMaxHPBase, 12864); - ASSERT_EQ(pPlayer->_pHPBase, 12864); - ASSERT_EQ(pPlayer->_pBaseToBlk, 20); - ASSERT_EQ(pPlayer->_pMaxManaBase, 11104); - ASSERT_EQ(pPlayer->_pManaBase, 11104); - ASSERT_EQ(pPlayer->_pMemSpells, 66309357295); - ASSERT_EQ(pPlayer->_pNumInv, 2); - ASSERT_EQ(pPlayer->wReflections, 0); - ASSERT_EQ(pPlayer->pTownWarps, 0); - ASSERT_EQ(pPlayer->pDungMsgs, 0); - ASSERT_EQ(pPlayer->pDungMsgs2, 0); - ASSERT_EQ(pPlayer->pLvlLoad, 0); - ASSERT_EQ(pPlayer->pDiabloKillLevel, 3); - ASSERT_EQ(pPlayer->pBattleNet, 0); - ASSERT_EQ(pPlayer->pManaShield, 0); - ASSERT_EQ(pPlayer->pDifficulty, 0); - ASSERT_EQ(pPlayer->pDamAcFlags, 0); + ASSERT_EQ(player.position.tile.x, 75); + ASSERT_EQ(player.position.tile.y, 68); + ASSERT_EQ(player.position.future.x, 75); + ASSERT_EQ(player.position.future.y, 68); + ASSERT_EQ(player.plrlevel, 0); + ASSERT_EQ(player.destAction, -1); + ASSERT_STREQ(player._pName, "TestPlayer"); + ASSERT_EQ(player._pClass, HeroClass::Rogue); + ASSERT_EQ(player._pBaseStr, 55); + ASSERT_EQ(player._pStrength, 124); + ASSERT_EQ(player._pBaseMag, 70); + ASSERT_EQ(player._pMagic, 80); + ASSERT_EQ(player._pBaseDex, 250); + ASSERT_EQ(player._pDexterity, 281); + ASSERT_EQ(player._pBaseVit, 80); + ASSERT_EQ(player._pVitality, 90); + ASSERT_EQ(player._pLevel, 50); + ASSERT_EQ(player._pStatPts, 0); + ASSERT_EQ(player._pExperience, 1583495809); + ASSERT_EQ(player._pGold, 0); + ASSERT_EQ(player._pMaxHPBase, 12864); + ASSERT_EQ(player._pHPBase, 12864); + ASSERT_EQ(player._pBaseToBlk, 20); + ASSERT_EQ(player._pMaxManaBase, 11104); + ASSERT_EQ(player._pManaBase, 11104); + ASSERT_EQ(player._pMemSpells, 66309357295); + ASSERT_EQ(player._pNumInv, 2); + ASSERT_EQ(player.wReflections, 0); + ASSERT_EQ(player.pTownWarps, 0); + ASSERT_EQ(player.pDungMsgs, 0); + ASSERT_EQ(player.pDungMsgs2, 0); + ASSERT_EQ(player.pLvlLoad, 0); + ASSERT_EQ(player.pDiabloKillLevel, 3); + ASSERT_EQ(player.pBattleNet, 0); + ASSERT_EQ(player.pManaShield, 0); + ASSERT_EQ(player.pDifficulty, 0); + ASSERT_EQ(player.pDamAcFlags, 0); - ASSERT_EQ(pPlayer->_pmode, 0); - ASSERT_EQ(Count8(pPlayer->walkpath, MAX_PATH_LENGTH), 25); - ASSERT_EQ(pPlayer->_pgfxnum, 36); - ASSERT_EQ(pPlayer->AnimInfo.DelayLen, 3); - ASSERT_EQ(pPlayer->AnimInfo.DelayCounter, 1); - ASSERT_EQ(pPlayer->AnimInfo.NumberOfFrames, 20); - ASSERT_EQ(pPlayer->AnimInfo.CurrentFrame, 1); - ASSERT_EQ(pPlayer->_pSpell, -1); - ASSERT_EQ(pPlayer->_pSplType, 4); - ASSERT_EQ(pPlayer->_pSplFrom, 0); - ASSERT_EQ(pPlayer->_pTSpell, 0); - ASSERT_EQ(pPlayer->_pTSplType, 0); - ASSERT_EQ(pPlayer->_pRSpell, -1); - ASSERT_EQ(pPlayer->_pRSplType, 4); - ASSERT_EQ(pPlayer->_pSBkSpell, -1); - ASSERT_EQ(pPlayer->_pSBkSplType, 0); - ASSERT_EQ(pPlayer->_pAblSpells, 134217728); - ASSERT_EQ(pPlayer->_pScrlSpells, 0); - ASSERT_EQ(pPlayer->_pSpellFlags, 0); - ASSERT_EQ(pPlayer->_pwtype, 1); - ASSERT_EQ(pPlayer->_pBlockFlag, 0); - ASSERT_EQ(pPlayer->_pLightRad, 11); - ASSERT_EQ(pPlayer->_pDamageMod, 101); - ASSERT_EQ(pPlayer->_pHitPoints, 16640); - ASSERT_EQ(pPlayer->_pMaxHP, 16640); - ASSERT_EQ(pPlayer->_pMana, 14624); - ASSERT_EQ(pPlayer->_pMaxMana, 14624); - ASSERT_EQ(pPlayer->_pNextExper, 2000); - ASSERT_EQ(pPlayer->_pMagResist, 75); - ASSERT_EQ(pPlayer->_pFireResist, 16); - ASSERT_EQ(pPlayer->_pLghtResist, 75); - ASSERT_EQ(CountBool(pPlayer->_pLvlVisited, NUMLEVELS), 0); - ASSERT_EQ(CountBool(pPlayer->_pSLvlVisited, NUMLEVELS), 0); - ASSERT_EQ(pPlayer->_pNFrames, 20); - ASSERT_EQ(pPlayer->_pWFrames, 8); - ASSERT_EQ(pPlayer->_pAFrames, 0); - ASSERT_EQ(pPlayer->_pAFNum, 0); - ASSERT_EQ(pPlayer->_pSFrames, 16); - ASSERT_EQ(pPlayer->_pSFNum, 12); - ASSERT_EQ(pPlayer->_pHFrames, 0); - ASSERT_EQ(pPlayer->_pDFrames, 20); - ASSERT_EQ(pPlayer->_pBFrames, 0); - ASSERT_EQ(pPlayer->_pIMinDam, 1); - ASSERT_EQ(pPlayer->_pIMaxDam, 14); - ASSERT_EQ(pPlayer->_pIAC, 115); - ASSERT_EQ(pPlayer->_pIBonusDam, 0); - ASSERT_EQ(pPlayer->_pIBonusToHit, 0); - ASSERT_EQ(pPlayer->_pIBonusAC, 0); - ASSERT_EQ(pPlayer->_pIBonusDamMod, 0); - ASSERT_EQ(pPlayer->_pISpells, 0); - ASSERT_EQ(pPlayer->_pIFlags, 0); - ASSERT_EQ(pPlayer->_pIGetHit, 0); - ASSERT_EQ(pPlayer->_pISplLvlAdd, 0); - ASSERT_EQ(pPlayer->_pISplDur, 0); - ASSERT_EQ(pPlayer->_pIEnAc, 0); - ASSERT_EQ(pPlayer->_pIFMinDam, 0); - ASSERT_EQ(pPlayer->_pIFMaxDam, 0); - ASSERT_EQ(pPlayer->_pILMinDam, 0); - ASSERT_EQ(pPlayer->_pILMaxDam, 0); - ASSERT_EQ(pPlayer->pOriginalCathedral, 0); + ASSERT_EQ(player._pmode, 0); + ASSERT_EQ(Count8(player.walkpath, MAX_PATH_LENGTH), 25); + ASSERT_EQ(player._pgfxnum, 36); + ASSERT_EQ(player.AnimInfo.DelayLen, 3); + ASSERT_EQ(player.AnimInfo.DelayCounter, 1); + ASSERT_EQ(player.AnimInfo.NumberOfFrames, 20); + ASSERT_EQ(player.AnimInfo.CurrentFrame, 1); + ASSERT_EQ(player._pSpell, -1); + ASSERT_EQ(player._pSplType, 4); + ASSERT_EQ(player._pSplFrom, 0); + ASSERT_EQ(player._pTSpell, 0); + ASSERT_EQ(player._pTSplType, 0); + ASSERT_EQ(player._pRSpell, -1); + ASSERT_EQ(player._pRSplType, 4); + ASSERT_EQ(player._pSBkSpell, -1); + ASSERT_EQ(player._pSBkSplType, 0); + ASSERT_EQ(player._pAblSpells, 134217728); + ASSERT_EQ(player._pScrlSpells, 0); + ASSERT_EQ(player._pSpellFlags, 0); + ASSERT_EQ(player._pwtype, 1); + ASSERT_EQ(player._pBlockFlag, 0); + ASSERT_EQ(player._pLightRad, 11); + ASSERT_EQ(player._pDamageMod, 101); + ASSERT_EQ(player._pHitPoints, 16640); + ASSERT_EQ(player._pMaxHP, 16640); + ASSERT_EQ(player._pMana, 14624); + ASSERT_EQ(player._pMaxMana, 14624); + ASSERT_EQ(player._pNextExper, 2000); + ASSERT_EQ(player._pMagResist, 75); + ASSERT_EQ(player._pFireResist, 16); + ASSERT_EQ(player._pLghtResist, 75); + ASSERT_EQ(CountBool(player._pLvlVisited, NUMLEVELS), 0); + ASSERT_EQ(CountBool(player._pSLvlVisited, NUMLEVELS), 0); + ASSERT_EQ(player._pNFrames, 20); + ASSERT_EQ(player._pWFrames, 8); + ASSERT_EQ(player._pAFrames, 0); + ASSERT_EQ(player._pAFNum, 0); + ASSERT_EQ(player._pSFrames, 16); + ASSERT_EQ(player._pSFNum, 12); + ASSERT_EQ(player._pHFrames, 0); + ASSERT_EQ(player._pDFrames, 20); + ASSERT_EQ(player._pBFrames, 0); + ASSERT_EQ(player._pIMinDam, 1); + ASSERT_EQ(player._pIMaxDam, 14); + ASSERT_EQ(player._pIAC, 115); + ASSERT_EQ(player._pIBonusDam, 0); + ASSERT_EQ(player._pIBonusToHit, 0); + ASSERT_EQ(player._pIBonusAC, 0); + ASSERT_EQ(player._pIBonusDamMod, 0); + ASSERT_EQ(player._pISpells, 0); + ASSERT_EQ(player._pIFlags, 0); + ASSERT_EQ(player._pIGetHit, 0); + ASSERT_EQ(player._pISplLvlAdd, 0); + ASSERT_EQ(player._pISplDur, 0); + ASSERT_EQ(player._pIEnAc, 0); + ASSERT_EQ(player._pIFMinDam, 0); + ASSERT_EQ(player._pIFMaxDam, 0); + ASSERT_EQ(player._pILMinDam, 0); + ASSERT_EQ(player._pILMaxDam, 0); + ASSERT_EQ(player.pOriginalCathedral, 0); } TEST(Writehero, pfile_write_hero) @@ -370,7 +370,7 @@ TEST(Writehero, pfile_write_hero) PkPlayerStruct pks; PackPlayerTest(&pks); UnPackPlayer(&pks, myplr, true); - AssertPlayer(&plr[0]); + AssertPlayer(plr[0]); pfile_write_hero(); std::ifstream f("multi_0.sv", std::ios::binary);