Browse Source

Players[MyPlayerId] -> MyPlayer

pull/4544/merge
qndel 4 years ago committed by Anders Jenbo
parent
commit
354e329644
  1. 16
      Source/automap.cpp
  2. 36
      Source/control.cpp
  3. 2
      Source/controls/modifier_hints.cpp
  4. 61
      Source/controls/plrctrls.cpp
  5. 2
      Source/controls/touch/renderers.cpp
  6. 2
      Source/cursor.cpp
  7. 30
      Source/debug.cpp
  8. 30
      Source/diablo.cpp
  9. 8
      Source/discord/discord.cpp
  10. 6
      Source/drlg_l1.cpp
  11. 6
      Source/effects.cpp
  12. 6
      Source/gamemenu.cpp
  13. 4
      Source/interfac.cpp
  14. 28
      Source/inv.cpp
  15. 26
      Source/items.cpp
  16. 4
      Source/lighting.cpp
  17. 12
      Source/loadsave.cpp
  18. 4
      Source/miniwin/misc_msg.cpp
  19. 62
      Source/missiles.cpp
  20. 22
      Source/monster.cpp
  21. 43
      Source/msg.cpp
  22. 22
      Source/multi.cpp
  23. 66
      Source/objects.cpp
  24. 8
      Source/panels/spell_book.cpp
  25. 18
      Source/panels/spell_list.cpp
  26. 6
      Source/pfile.cpp
  27. 114
      Source/player.cpp
  28. 6
      Source/portal.cpp
  29. 8
      Source/qol/autopickup.cpp
  30. 2
      Source/qol/chatlog.cpp
  31. 6
      Source/qol/stash.cpp
  32. 4
      Source/qol/xpbar.cpp
  33. 8
      Source/quests.cpp
  34. 20
      Source/scrollrt.cpp
  35. 6
      Source/spells.cpp
  36. 48
      Source/stores.cpp
  37. 6
      Source/sync.cpp
  38. 2
      Source/towners.cpp
  39. 2
      Source/track.cpp
  40. 4
      Source/trigs.cpp
  41. 10
      test/effects_test.cpp
  42. 196
      test/inv_test.cpp
  43. 16
      test/pack_test.cpp
  44. 2
      test/player_test.cpp
  45. 4
      test/writehero_test.cpp

16
Source/automap.cpp

@ -344,11 +344,11 @@ void DrawAutomapTile(const Surface &out, Point center, Point map)
void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset)
{
auto &myPlayer = Players[MyPlayerId];
Point tile = myPlayer.position.tile;
if (myPlayer._pmode == PM_WALK3) {
tile = myPlayer.position.future;
if (myPlayer._pdir == Direction::West)
const Player &player = *MyPlayer;
Point tile = player.position.tile;
if (player._pmode == PM_WALK3) {
tile = player.position.future;
if (player._pdir == Direction::West)
tile.x++;
else
tile.y++;
@ -392,7 +392,7 @@ void DrawAutomapPlr(const Surface &out, const Displacement &myPlayerOffset, int
{
int playerColor = MapColorsPlayer + (8 * playerId) % 128;
auto &player = Players[playerId];
Player &player = Players[playerId];
Point tile = player.position.tile;
if (player._pmode == PM_WALK3) {
tile = player.position.future;
@ -665,7 +665,7 @@ void DrawAutomap(const Surface &out)
Automap += AutomapOffset;
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
Displacement myPlayerOffset = ScrollInfo.offset;
if (myPlayer.IsWalking())
myPlayerOffset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);
@ -731,7 +731,7 @@ void DrawAutomap(const Surface &out)
}
for (int playerId = 0; playerId < MAX_PLRS; playerId++) {
auto &player = Players[playerId];
Player &player = Players[playerId];
if (player.plrlevel == myPlayer.plrlevel && player.plractive && !player._pLvlChanging && (&player == &myPlayer || player.friendlyMode)) {
DrawAutomapPlr(out, myPlayerOffset, playerId);
}

36
Source/control.cpp

@ -388,7 +388,7 @@ void RemoveGold(Player &player, int goldIndex)
bool IsLevelUpButtonVisible()
{
if (spselflag || chrflag || Players[MyPlayerId]._pStatPts == 0) {
if (spselflag || chrflag || MyPlayer->_pStatPts == 0) {
return false;
}
if (ControlMode == ControlTypes::VirtualGamepad) {
@ -496,25 +496,25 @@ void DrawPanelBox(const Surface &out, SDL_Rect srcRect, Point targetPosition)
void DrawLifeFlaskUpper(const Surface &out)
{
constexpr int LifeFlaskUpperOffset = 109;
DrawFlaskUpper(out, *pLifeBuff, LifeFlaskUpperOffset, Players[MyPlayerId]._pHPPer);
DrawFlaskUpper(out, *pLifeBuff, LifeFlaskUpperOffset, MyPlayer->_pHPPer);
}
void DrawManaFlaskUpper(const Surface &out)
{
constexpr int ManaFlaskUpperOffset = 475;
DrawFlaskUpper(out, *pManaBuff, ManaFlaskUpperOffset, Players[MyPlayerId]._pManaPer);
DrawFlaskUpper(out, *pManaBuff, ManaFlaskUpperOffset, MyPlayer->_pManaPer);
}
void DrawLifeFlaskLower(const Surface &out)
{
constexpr int LifeFlaskLowerOffset = 96;
DrawFlaskLower(out, *pLifeBuff, LifeFlaskLowerOffset, Players[MyPlayerId]._pHPPer);
DrawFlaskLower(out, *pLifeBuff, LifeFlaskLowerOffset, MyPlayer->_pHPPer);
}
void DrawManaFlaskLower(const Surface &out)
{
constexpr int ManaFlaskLowerOffeset = 464;
DrawFlaskLower(out, *pManaBuff, ManaFlaskLowerOffeset, Players[MyPlayerId]._pManaPer);
DrawFlaskLower(out, *pManaBuff, ManaFlaskLowerOffeset, MyPlayer->_pManaPer);
}
void DrawFlaskValues(const Surface &out, Point pos, int currValue, int maxValue)
@ -534,8 +534,8 @@ void DrawFlaskValues(const Surface &out, Point pos, int currValue, int maxValue)
void control_update_life_mana()
{
Players[MyPlayerId].UpdateManaPercentage();
Players[MyPlayerId].UpdateHitPointPercentage();
MyPlayer->UpdateManaPercentage();
MyPlayer->UpdateHitPointPercentage();
}
void InitControlPan()
@ -621,8 +621,7 @@ void DrawCtrlBtns(const Surface &out)
}
if (PanelButtonIndex == 8) {
CelDrawTo(out, mainPanelPosition + Displacement { 87, 122 }, *multiButtons, PanelButtons[6] ? 1 : 0);
auto &myPlayer = Players[MyPlayerId];
if (myPlayer.friendlyMode)
if (MyPlayer->friendlyMode)
CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, *multiButtons, PanelButtons[7] ? 3 : 2);
else
CelDrawTo(out, mainPanelPosition + Displacement { 527, 122 }, *multiButtons, PanelButtons[7] ? 5 : 4);
@ -654,7 +653,7 @@ void DoPanBtn()
}
if (!spselflag && MousePosition.x >= 565 + mainPanelPosition.x && MousePosition.x < 621 + mainPanelPosition.x && MousePosition.y >= 64 + mainPanelPosition.y && MousePosition.y < 120 + mainPanelPosition.y) {
if ((SDL_GetModState() & KMOD_SHIFT) != 0) {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer._pRSpell = SPL_INVALID;
myPlayer._pRSplType = RSPLTYPE_INVALID;
force_redraw = 255;
@ -710,8 +709,7 @@ void CheckPanelInfo()
if (i != 7) {
InfoString = _(PanBtnStr[i]);
} else {
auto &myPlayer = Players[MyPlayerId];
if (myPlayer.friendlyMode)
if (MyPlayer->friendlyMode)
InfoString = _("Player friendly");
else
InfoString = _("Player attack");
@ -728,7 +726,7 @@ void CheckPanelInfo()
InfoColor = UiFlags::ColorWhite;
panelflag = true;
AddPanelString(_("Hotkey: 's'"));
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
const spell_id spellId = myPlayer._pRSpell;
if (spellId != SPL_INVALID && spellId != SPL_NULL) {
switch (myPlayer._pRSplType) {
@ -873,7 +871,7 @@ void DrawInfoBox(const Surface &out)
InfoColor = UiFlags::ColorWhite;
ClearPanel();
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (spselflag || trigflag) {
InfoColor = UiFlags::ColorWhite;
} else if (!myPlayer.HoldItem.isEmpty()) {
@ -957,7 +955,7 @@ void DrawLevelUpIcon(const Surface &out)
void CheckChrBtns()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (chrbtnactive || myPlayer._pStatPts == 0)
return;
@ -987,7 +985,7 @@ void ReleaseChrBtns(bool addAllStatPoints)
Rectangle button = ChrBtnsRect[buttonId];
button.position = GetPanelPosition(UiPanels::Character, button.position);
if (button.Contains(MousePosition)) {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int statPointsToAdd = 1;
if (addAllStatPoints)
statPointsToAdd = CapStatPointsToAdd(myPlayer._pStatPts, myPlayer, attribute);
@ -1029,7 +1027,7 @@ void DrawDurIcon(const Surface &out)
x -= MainPanel.position.x + MainPanel.size.width - RightPanel.position.x;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
x = DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_HEAD], x, 3);
x = DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_CHEST], x, 2);
x = DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_HAND_LEFT], x, 0);
@ -1082,7 +1080,7 @@ void DrawGoldSplit(const Surface &out, int amount)
void control_drop_gold(char vkey)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pHitPoints >> 6 <= 0) {
CloseGoldDrop();
@ -1136,7 +1134,7 @@ void DrawTalkPan(const Surface &out)
if (i == MyPlayerId)
continue;
auto &player = Players[i];
Player &player = Players[i];
UiFlags color = player.friendlyMode ? UiFlags::ColorWhitegold : UiFlags::ColorRed;
const Point talkPanPosition = mainPanelPosition + Displacement { 172, 84 + 18 * talkBtn };
if (WhisperList[i]) {

2
Source/controls/modifier_hints.cpp

@ -110,7 +110,7 @@ void DrawCircleMenuHint(const Surface &out, const CircleMenuHint &hint, const Po
*/
void DrawSpellsCircleMenuHint(const Surface &out, const Point &origin)
{
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
const Displacement spellIconDisplacement = { (HintBoxSize - IconSize) / 2 + 1, HintBoxSize - (HintBoxSize - IconSize) / 2 - 1 };
Point hintBoxPositions[4] = {
origin + Displacement { 0, LineHeight - HintBoxSize },

61
Source/controls/plrctrls.cpp

@ -60,7 +60,7 @@ bool InGameMenu()
|| qtextflag
|| gmenu_is_active()
|| PauseMode == 2
|| Players[MyPlayerId]._pInvincible;
|| MyPlayer->_pInvincible;
}
namespace {
@ -84,7 +84,7 @@ const Direction FaceDir[3][3] = {
*/
int GetRotaryDistance(Point destination)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer.position.future == destination)
return -1;
@ -105,7 +105,7 @@ int GetRotaryDistance(Point destination)
*/
int GetMinDistance(Point position)
{
return Players[MyPlayerId].position.future.WalkingDistance(position);
return MyPlayer->position.future.WalkingDistance(position);
}
/**
@ -121,7 +121,7 @@ int GetDistance(Point destination, int maxDistance)
}
int8_t walkpath[MAX_PATH_LENGTH];
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int steps = FindPath([&myPlayer](Point position) { return PosOkPlayer(myPlayer, position); }, myPlayer.position.future, destination, walkpath);
if (steps > maxDistance)
return 0;
@ -135,12 +135,12 @@ int GetDistance(Point destination, int maxDistance)
*/
int GetDistanceRanged(Point destination)
{
return Players[MyPlayerId].position.future.ExactDistance(destination);
return MyPlayer->position.future.ExactDistance(destination);
}
void FindItemOrObject()
{
Point futurePosition = Players[MyPlayerId].position.future;
Point futurePosition = MyPlayer->position.future;
int rotations = 5;
auto searchArea = PointsInRectangleRangeColMajor { Rectangle { futurePosition, 1 } };
@ -215,7 +215,7 @@ void CheckTownersNearby()
bool HasRangedSpell()
{
int spl = Players[MyPlayerId]._pRSpell;
int spl = MyPlayer->_pRSpell;
return spl != SPL_INVALID
&& spl != SPL_TOWN
@ -286,7 +286,7 @@ void FindMeleeTarget()
};
std::list<SearchNode> queue;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
{
const int startX = myPlayer.position.future.x;
@ -345,7 +345,7 @@ void FindMeleeTarget()
void CheckMonstersNearby()
{
if (Players[MyPlayerId].UsesRangedWeapon() || HasRangedSpell()) {
if (MyPlayer->UsesRangedWeapon() || HasRangedSpell()) {
FindRangedTarget();
return;
}
@ -362,7 +362,7 @@ void CheckPlayerNearby()
if (pcursmonst != -1)
return;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int spl = myPlayer._pRSpell;
if (myPlayer.friendlyMode && spl != SPL_RESURRECT && spl != SPL_HEALOTHER)
@ -371,7 +371,7 @@ void CheckPlayerNearby()
for (int i = 0; i < MAX_PLRS; i++) {
if (i == MyPlayerId)
continue;
const auto &player = Players[i];
const Player &player = Players[i];
const int mx = player.position.future.x;
const int my = player.position.future.y;
if (dPlayer[mx][my] == 0
@ -483,8 +483,9 @@ void Interact()
}
#endif
Player &myPlayer = *MyPlayer;
if (leveltype != DTYPE_TOWN && stand) {
auto &myPlayer = Players[MyPlayerId];
Direction pdir = myPlayer._pdir;
AxisDirection moveDir = GetMoveDirection();
bool motion = moveDir.x != AxisDirectionX_NONE || moveDir.y != AxisDirectionY_NONE;
@ -497,13 +498,13 @@ void Interact()
position = Monsters[pcursmonst].position.tile;
}
NetSendCmdLoc(MyPlayerId, true, Players[MyPlayerId].UsesRangedWeapon() ? CMD_RATTACKXY : CMD_SATTACKXY, position);
NetSendCmdLoc(MyPlayerId, true, myPlayer.UsesRangedWeapon() ? CMD_RATTACKXY : CMD_SATTACKXY, position);
LastMouseButtonAction = MouseActionType::Attack;
return;
}
if (pcursmonst != -1) {
if (!Players[MyPlayerId].UsesRangedWeapon() || CanTalkToMonst(Monsters[pcursmonst])) {
if (!myPlayer.UsesRangedWeapon() || CanTalkToMonst(Monsters[pcursmonst])) {
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
} else {
NetSendCmdParam1(true, CMD_RATTACKID, pcursmonst);
@ -512,8 +513,8 @@ void Interact()
return;
}
if (leveltype != DTYPE_TOWN && pcursplr != -1 && !Players[MyPlayerId].friendlyMode) {
NetSendCmdParam1(true, Players[MyPlayerId].UsesRangedWeapon() ? CMD_RATTACKPID : CMD_ATTACKPID, pcursplr);
if (leveltype != DTYPE_TOWN && pcursplr != -1 && !myPlayer.friendlyMode) {
NetSendCmdParam1(true, myPlayer.UsesRangedWeapon() ? CMD_RATTACKPID : CMD_ATTACKPID, pcursplr);
LastMouseButtonAction = MouseActionType::AttackPlayerTarget;
return;
}
@ -532,7 +533,7 @@ void AttrIncBtnSnap(AxisDirection dir)
if (dir.y == AxisDirectionY_NONE)
return;
if (chrbtnactive && Players[MyPlayerId]._pStatPts <= 0)
if (chrbtnactive && MyPlayer->_pStatPts <= 0)
return;
// first, find our cursor location
@ -1255,14 +1256,14 @@ bool IsPathBlocked(Point position, Direction dir)
if (IsTileNotSolid(leftStep) && IsTileNotSolid(rightStep))
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
return !PosOkPlayer(myPlayer, leftStep) && !PosOkPlayer(myPlayer, rightStep);
}
void WalkInDir(int playerId, AxisDirection dir)
{
auto &player = Players[playerId];
Player &player = Players[playerId];
if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) {
if (ControlMode != ControlTypes::KeyboardAndMouse && player.walkpath[0] != WALK_NONE && player.destAction == ACTION_NONE)
@ -1325,7 +1326,7 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
if (invflag) {
return &CheckInventoryMove;
}
if (chrflag && Players[MyPlayerId]._pStatPts > 0) {
if (chrflag && MyPlayer->_pStatPts > 0) {
return &AttrIncBtnSnap;
}
if (spselflag) {
@ -1637,7 +1638,7 @@ void plrctrls_after_check_curs_move()
pcurstrig = -1;
pcursquest = Q_INVALID;
cursPosition = { -1, -1 };
if (Players[MyPlayerId]._pInvincible) {
if (MyPlayer->_pInvincible) {
return;
}
if (DoomFlag) {
@ -1666,7 +1667,7 @@ void plrctrls_after_game_logic()
void UseBeltItem(int type)
{
for (int i = 0; i < MAXBELTITEMS; i++) {
Item &item = Players[MyPlayerId].SpdList[i];
Item &item = MyPlayer->SpdList[i];
if (item.isEmpty()) {
continue;
}
@ -1766,7 +1767,7 @@ void PerformPrimaryAction()
return;
}
if (chrflag && !chrbtnactive && Players[MyPlayerId]._pStatPts > 0) {
if (chrflag && !chrbtnactive && MyPlayer->_pStatPts > 0) {
CheckChrBtns();
if (chrbtnactive)
ReleaseChrBtns(false);
@ -1778,7 +1779,7 @@ void PerformPrimaryAction()
bool SpellHasActorTarget()
{
spell_id spl = Players[MyPlayerId]._pRSpell;
spell_id spl = MyPlayer->_pRSpell;
if (spl == SPL_TOWN || spl == SPL_TELEPORT)
return false;
@ -1797,7 +1798,7 @@ void UpdateSpellTarget(spell_id spell)
pcursplr = -1;
pcursmonst = -1;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int range = spell == SPL_TELEPORT ? 4 : 1;
@ -1809,7 +1810,7 @@ void UpdateSpellTarget(spell_id spell)
*/
bool TryDropItem()
{
auto &myPlayer = *MyPlayer;
Player &myPlayer = *MyPlayer;
if (myPlayer.HoldItem.isEmpty()) {
return false;
@ -1877,7 +1878,7 @@ void PerformSpellAction()
return;
}
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
int spl = myPlayer._pRSpell;
if ((pcursplr == -1 && (spl == SPL_RESURRECT || spl == SPL_HEALOTHER))
|| (pcursobj == -1 && spl == SPL_DISARM)) {
@ -1901,7 +1902,7 @@ void CtrlUseInvItem()
return;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
Item &item = GetInventoryItem(myPlayer, pcursinvitem);
if (item.isScroll()) {
if (TargetsMonster(item._iSpell)) {
@ -1949,7 +1950,7 @@ void CtrlUseStashItem()
void PerformSecondaryAction()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (invflag) {
if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) {
TryIconCurs();
@ -1992,7 +1993,7 @@ void PerformSecondaryAction()
void QuickCast(size_t slot)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
spell_id spell = myPlayer._pSplHotKey[slot];
spell_type spellType = myPlayer._pSplTHotKey[slot];

2
Source/controls/touch/renderers.cpp

@ -159,7 +159,7 @@ void LoadPotionArt(Art *potionArt, SDL_Renderer *renderer)
bool InteractsWithCharButton(Point point)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pStatPts == 0)
return false;
for (auto attribute : enum_values<CharacterAttribute>()) {

2
Source/cursor.cpp

@ -278,7 +278,7 @@ void CheckCursMove()
int xo = 0;
int yo = 0;
CalcTileOffset(&xo, &yo);
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
Displacement offset = ScrollInfo.offset;
if (myPlayer.IsWalking())
offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);

30
Source/debug.cpp

@ -87,7 +87,7 @@ uint32_t glEndSeed[NUMLEVELS];
void SetSpellLevelCheat(spell_id spl, int spllvl)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer._pMemSpells |= GetSpellBitmask(spl);
myPlayer._pSplLvl[spl] = spllvl;
@ -168,7 +168,7 @@ std::string DebugCmdHelp(const string_view parameter)
std::string DebugCmdGiveGoldCheat(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (int8_t &itemIndex : myPlayer.InvGrid) {
if (itemIndex != 0)
@ -188,7 +188,7 @@ std::string DebugCmdGiveGoldCheat(const string_view parameter)
std::string DebugCmdTakeGoldCheat(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (auto itemIndex : myPlayer.InvGrid) {
itemIndex -= 1;
@ -208,7 +208,7 @@ std::string DebugCmdTakeGoldCheat(const string_view parameter)
std::string DebugCmdWarpToLevel(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
auto level = atoi(parameter.data());
if (level < 0 || level > (gbIsHellfire ? 24 : 16))
return fmt::format("Level {} is not known. Do you want to write a mod?", level);
@ -310,7 +310,7 @@ std::unordered_map<string_view, _talker_id> TownerShortNameToTownerId = {
std::string DebugCmdVisitTowner(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (setlevel || myPlayer.plrlevel != 0)
return "What kind of friends do you have in dungeons?";
@ -350,7 +350,7 @@ std::string DebugCmdVisitTowner(const string_view parameter)
std::string DebugCmdResetLevel(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
std::stringstream paramsStream(parameter.data());
std::string singleParameter;
@ -469,14 +469,14 @@ std::string DebugCmdSetSpellsLevel(const string_view parameter)
}
}
if (level == 0)
Players[MyPlayerId]._pMemSpells = 0;
MyPlayer->_pMemSpells = 0;
return "Knowledge is power.";
}
std::string DebugCmdRefillHealthMana(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer.RestoreFullLife();
myPlayer.RestoreFullMana();
drawhpflag = true;
@ -487,7 +487,7 @@ std::string DebugCmdRefillHealthMana(const string_view parameter)
std::string DebugCmdChangeHealth(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int change = -1;
if (!parameter.empty())
@ -506,7 +506,7 @@ std::string DebugCmdChangeHealth(const string_view parameter)
std::string DebugCmdChangeMana(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int change = -1;
if (!parameter.empty())
@ -542,7 +542,7 @@ std::string DebugCmdExit(const string_view parameter)
std::string DebugCmdArrow(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer._pIFlags &= ~ItemSpecialEffect::FireArrows;
myPlayer._pIFlags &= ~ItemSpecialEffect::LightningArrows;
@ -641,7 +641,7 @@ std::string DebugCmdSpawnUniqueMonster(const string_view parameter)
LevelMonsterTypes[id].mdeadval = 1;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int spawnedMonster = 0;
@ -727,7 +727,7 @@ std::string DebugCmdSpawnMonster(const string_view parameter)
LevelMonsterTypes[id].mdeadval = 1;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int spawnedMonster = 0;
@ -823,7 +823,7 @@ std::string DebugCmdScrollView(const string_view parameter)
std::string DebugCmdItemInfo(const string_view parameter)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
Item *pItem = nullptr;
if (!myPlayer.HoldItem.isEmpty()) {
pItem = &myPlayer.HoldItem;
@ -866,7 +866,7 @@ std::string DebugCmdPlayerInfo(const string_view parameter)
int playerId = atoi(parameter.data());
if (playerId < 0 || playerId >= MAX_PLRS)
return "My friend, we need a valid playerId.";
auto &player = Players[playerId];
Player &player = Players[playerId];
if (!player.plractive)
return "Player is not active";

30
Source/diablo.cpp

@ -178,7 +178,7 @@ void FreeGame()
FreeInfoBoxGfx();
FreeStoreMem();
for (auto &player : Players)
for (Player &player : Players)
ResetPlayerGFX(player);
FreeCursor();
@ -234,7 +234,7 @@ void LeftMouseCmd(bool bShift)
return;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
bNear = myPlayer.position.tile.WalkingDistance(cursPosition) < 2;
if (pcursitem != -1 && pcurs == CURSOR_HAND && !bShift) {
NetSendCmdLocParam1(true, invflag ? CMD_GOTOGETITEM : CMD_GOTOAGETITEM, cursPosition, pcursitem);
@ -382,7 +382,7 @@ void RightMouseDown(bool isShiftHeld)
{
LastMouseButtonAction = MouseActionType::None;
if (gmenu_is_active() || sgnTimeoutCurs != CURSOR_NONE || PauseMode == 2 || Players[MyPlayerId]._pInvincible) {
if (gmenu_is_active() || sgnTimeoutCurs != CURSOR_NONE || PauseMode == 2 || MyPlayer->_pInvincible) {
return;
}
@ -1210,7 +1210,7 @@ void CreateLevel(lvl_entry lvldir)
void UnstuckChargers()
{
if (gbIsMultiplayer) {
for (auto &player : Players) {
for (Player &player : Players) {
if (!player.plractive)
continue;
if (player._pLvlChanging)
@ -1234,7 +1234,7 @@ void UpdateMonsterLights()
for (int i = 0; i < ActiveMonsterCount; i++) {
auto &monster = Monsters[ActiveMonsters[i]];
if (monster.mlid != NO_LIGHT) {
if (monster.mlid == Players[MyPlayerId]._plid) { // Fix old saves where some monsters had 0 instead of NO_LIGHT
if (monster.mlid == MyPlayer->_plid) { // Fix old saves where some monsters had 0 instead of NO_LIGHT
monster.mlid = NO_LIGHT;
continue;
}
@ -1443,7 +1443,7 @@ void SpellBookKeyPressed()
bool IsPlayerDead()
{
return Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead;
return MyPlayer->_pmode == PM_DEATH || MyPlayerIsDead;
}
bool IsGameRunning()
@ -1465,7 +1465,7 @@ void InitKeymapActions()
N_("Use Belt item."),
'1' + i,
[i] {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (!myPlayer.SpdList[i].isEmpty() && myPlayer.SpdList[i]._itype != ItemType::Gold) {
UseInvItem(MyPlayerId, INVITEM_BELT_FIRST + i);
}
@ -1531,7 +1531,7 @@ void InitKeymapActions()
N_("Stop hero"),
N_("Stops walking and cancel pending actions."),
DVL_VK_INVALID,
[] { Players[MyPlayerId].Stop(); },
[] { MyPlayer->Stop(); },
nullptr,
CanPlayerTakeAction);
sgOptions.Keymapper.AddAction(
@ -1745,7 +1745,7 @@ bool StartGame(bool bNewGame, bool bSinglePlayer)
InitLevels();
InitQuests();
InitPortals();
InitDungMsgs(Players[MyPlayerId]);
InitDungMsgs(*MyPlayer);
DeltaSyncJunk();
}
giNumberOfLevels = gbIsHellfire ? 25 : 17;
@ -1847,7 +1847,7 @@ bool TryIconCurs()
return true;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (pcurs == CURSOR_IDENTIFY) {
if (pcursinvitem != -1)
@ -2125,7 +2125,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
InitLevelMonsters();
IncProgress();
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (!setlevel) {
CreateLevel(lvldir);
@ -2157,7 +2157,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
IncProgress();
for (auto &player : Players) {
for (Player &player : Players) {
if (player.plractive && currlevel == player.plrlevel) {
InitPlayerGFX(player);
if (lvldir != ENTRY_LOAD)
@ -2172,7 +2172,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
bool visited = false;
int players = gbIsMultiplayer ? MAX_PLRS : 1;
for (int i = 0; i < players; i++) {
auto &player = Players[i];
Player &player = Players[i];
if (player.plractive)
visited = visited || player._pLvlVisited[currlevel];
}
@ -2258,7 +2258,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
GetPortalLvlPos();
IncProgress();
for (auto &player : Players) {
for (Player &player : Players) {
if (player.plractive && currlevel == player.plrlevel) {
InitPlayerGFX(player);
if (lvldir != ENTRY_LOAD)
@ -2284,7 +2284,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
SyncPortals();
for (int i = 0; i < MAX_PLRS; i++) {
auto &player = Players[i];
Player &player = Players[i];
if (player.plractive && player.plrlevel == currlevel && (!player._pLvlChanging || i == MyPlayerId)) {
if (player._pHitPoints > 0) {
if (!gbIsMultiplayer)

8
Source/discord/discord.cpp

@ -86,7 +86,7 @@ std::string GetLocationString()
std::string GetCharacterString()
{
const std::string &charClassStr = _(ClassStrTbl[static_cast<int>(Players[MyPlayerId]._pClass)]);
const std::string &charClassStr = _(ClassStrTbl[static_cast<int>(MyPlayer->_pClass)]);
return fmt::format(_(/* TRANSLATORS: Discord character, i.e. "Lv 6 Warrior" */ "Lv {} {}"), tracked_data.playerLevel, charClassStr);
}
@ -104,12 +104,12 @@ std::string GetStateString()
std::string GetTooltipString()
{
return fmt::format("{} - {}", Players[MyPlayerId]._pName, GetCharacterString());
return fmt::format("{} - {}", MyPlayer->_pName, GetCharacterString());
}
std::string GetPlayerAssetString()
{
char heroChar = CharChar[static_cast<int>(Players[MyPlayerId]._pClass)];
char heroChar = CharChar[static_cast<int>(MyPlayer->_pClass)];
char armourChar = ArmourChar[tracked_data.playerGfx >> 4];
char wpnChar = WepChar[tracked_data.playerGfx & 0xF];
@ -134,7 +134,7 @@ void UpdateGame()
return;
auto newData = PlayerData {
leveltype, setlvlnum, currlevel, Players[MyPlayerId]._pLevel, Players[MyPlayerId]._pgfxnum
leveltype, setlvlnum, currlevel, MyPlayer->_pLevel, MyPlayer->_pgfxnum
};
if (newData != tracked_data) {
tracked_data = newData;

6
Source/drlg_l1.cpp

@ -2226,7 +2226,7 @@ void GenerateLevel(lvl_entry entry)
}
} else if (entry == ENTRY_MAIN) {
if (currlevel < 21) {
if (!Players[MyPlayerId].pOriginalCathedral) {
if (!MyPlayer->pOriginalCathedral) {
if (PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1) < 0)
doneflag = false;
if (PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)
@ -2252,7 +2252,7 @@ void GenerateLevel(lvl_entry entry)
}
ViewPosition.y++;
}
} else if (!Players[MyPlayerId].pOriginalCathedral && entry == ENTRY_PREV) {
} else if (!MyPlayer->pOriginalCathedral && entry == ENTRY_PREV) {
if (currlevel < 21) {
if (PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0)
doneflag = false;
@ -2276,7 +2276,7 @@ void GenerateLevel(lvl_entry entry)
}
} else {
if (currlevel < 21) {
if (!Players[MyPlayerId].pOriginalCathedral) {
if (!MyPlayer->pOriginalCathedral) {
if (PlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0)
doneflag = false;
if (PlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0)

6
Source/effects.cpp

@ -1099,7 +1099,7 @@ void StreamUpdate()
void PlaySfxPriv(TSFX *pSFX, bool loc, Point position)
{
if (Players[MyPlayerId].pLvlLoad != 0 && gbIsMultiplayer) {
if (MyPlayer->pLvlLoad != 0 && gbIsMultiplayer) {
return;
}
if (!gbSndInited || !gbSoundOn || gbBufferMsgs != 0) {
@ -1244,7 +1244,7 @@ void FreeMonsterSnd()
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan)
{
const auto &playerPosition = Players[MyPlayerId].position.tile;
const auto &playerPosition = MyPlayer->position.tile;
const auto delta = soundPosition - playerPosition;
int pan = (delta.deltaX - delta.deltaY) * 256;
@ -1322,7 +1322,7 @@ void sound_init()
if (gbIsHellfire)
mask |= sfx_MONK;
} else {
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Warrior:
case HeroClass::Barbarian:
mask |= sfx_WARRIOR;

6
Source/gamemenu.cpp

@ -77,7 +77,7 @@ void GamemenuUpdateSingle()
{
gmenu_enable(&sgSingleMenu[3], gbValidSaveFile);
bool enable = Players[MyPlayerId]._pmode != PM_DEATH && !MyPlayerIsDead;
bool enable = MyPlayer->_pmode != PM_DEATH && !MyPlayerIsDead;
gmenu_enable(&sgSingleMenu[0], enable);
}
@ -94,7 +94,7 @@ void GamemenuPrevious(bool /*bActivate*/)
void GamemenuNewGame(bool /*bActivate*/)
{
for (auto &player : Players) {
for (Player &player : Players) {
player._pmode = PM_QUIT;
player._pInvincible = true;
}
@ -312,7 +312,7 @@ void gamemenu_save_game(bool /*bActivate*/)
return;
}
if (Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead) {
if (MyPlayer->_pmode == PM_DEATH || MyPlayerIsDead) {
gamemenu_off();
return;
}

4
Source/interfac.cpp

@ -56,7 +56,7 @@ Cutscenes PickCutscene(interface_mode uMsg)
case WM_DIABPREVLVL:
case WM_DIABTOWNWARP:
case WM_DIABTWARPUP: {
int lvl = Players[MyPlayerId].plrlevel;
int lvl = MyPlayer->plrlevel;
if (lvl == 1 && uMsg == WM_DIABNEXTLVL)
return CutTown;
if (lvl == 16 && uMsg == WM_DIABNEXTLVL)
@ -237,7 +237,7 @@ void ShowProgress(interface_mode uMsg)
sound_init();
IncProgress();
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
switch (uMsg) {
case WM_DIABLOADGAME:

28
Source/inv.cpp

@ -273,7 +273,7 @@ void ChangeEquipment(Player &player, inv_body_loc bodyLocation, const Item &item
bool AutoEquip(int playerId, const Item &item, inv_body_loc bodyLocation, bool persistItem)
{
auto &player = Players[playerId];
Player &player = Players[playerId];
if (!CanEquip(player, item, bodyLocation)) {
return false;
@ -574,7 +574,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove, bool dropItem)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pmode > PM_WALK3) {
return;
@ -868,7 +868,7 @@ void TryCombineNaKrulNotes(Player &player, Item &noteItem)
}
}
Players[MyPlayerId].Say(HeroSpeech::JustWhatIWasLookingFor, 10);
MyPlayer->Say(HeroSpeech::JustWhatIWasLookingFor, 10);
for (auto note : notes) {
if (idx != note) {
@ -885,7 +885,7 @@ void TryCombineNaKrulNotes(Player &player, Item &noteItem)
void CheckQuestItem(Player &player, Item &questItem)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (questItem.IDidx == IDI_OPTAMULET && Quests[Q_BLIND]._qactive == QUEST_ACTIVE)
Quests[Q_BLIND]._qactive = QUEST_DONE;
@ -926,7 +926,7 @@ void CheckQuestItem(Player &player, Item &questItem)
Quests[Q_GRAVE]._qlog = false;
Quests[Q_GRAVE]._qactive = QUEST_ACTIVE;
if (Quests[Q_GRAVE]._qvar1 != 1) {
Players[MyPlayerId].Say(HeroSpeech::UhHuh, 10);
MyPlayer->Say(HeroSpeech::UhHuh, 10);
Quests[Q_GRAVE]._qvar1 = 1;
}
}
@ -1037,7 +1037,7 @@ void StartGoldDrop()
initialDropGoldIndex = pcursinvitem;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (pcursinvitem <= INVITEM_INV_LAST)
initialDropGoldValue = myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]._ivalue;
@ -1113,7 +1113,7 @@ void FreeInvGFX()
void InitInv()
{
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Warrior:
case HeroClass::Barbarian:
pInvCels = LoadCel("Data\\Inv\\Inv.CEL", SPANEL_WIDTH);
@ -1158,7 +1158,7 @@ void DrawInv(const Surface &out)
{ 133, 160 }, // chest
};
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (int slot = INVLOC_HEAD; slot < NUM_INVLOC; slot++) {
if (!myPlayer.InvBody[slot].isEmpty()) {
@ -1249,7 +1249,7 @@ void DrawInvBelt(const Surface &out)
DrawPanelBox(out, { 205, 21, 232, 28 }, mainPanelPosition + Displacement { 205, 5 });
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (int i = 0; i < MAXBELTITEMS; i++) {
if (myPlayer.SpdList[i].isEmpty()) {
@ -1619,7 +1619,7 @@ void InvGetItem(Player &player, int ii)
void AutoGetItem(int pnum, Item *itemPointer, int ii)
{
Item &item = *itemPointer;
auto &player = Players[pnum];
Player &player = Players[pnum];
if (dropGoldFlag) {
CloseGoldDrop();
@ -1878,7 +1878,7 @@ int8_t CheckInvHLight()
int8_t rv = -1;
InfoColor = UiFlags::ColorWhite;
Item *pi = nullptr;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
ClearPanel();
if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) {
@ -1972,7 +1972,7 @@ bool UseScroll(const spell_id spell)
if (pcurs != CURSOR_HAND)
return false;
Player &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (leveltype == DTYPE_TOWN && !spelldata[spell].sTownSpell)
return false;
@ -2000,7 +2000,7 @@ bool UseStaff(const spell_id spell)
return false;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
return CanUseStaff(myPlayer.InvBody[INVLOC_HAND_LEFT], spell);
}
@ -2021,7 +2021,7 @@ bool UseInvItem(int pnum, int cii)
int c;
Item *item;
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId)
return true;

26
Source/items.cpp

@ -992,7 +992,7 @@ int SaveItemPower(Item &item, ItemPower &power)
item._iLMaxDam = 0;
break;
case IPL_FIRERESCLVL:
item._iPLFR = 30 - Players[MyPlayerId]._pLevel;
item._iPLFR = 30 - MyPlayer->_pLevel;
item._iPLFR = std::max<int16_t>(item._iPLFR, 0);
break;
case IPL_FIRERES_CURSE:
@ -1029,12 +1029,12 @@ int SaveItemPower(Item &item, ItemPower &power)
item._iDamAcFlags |= ItemSpecialEffectHf::ACAgainstUndead;
break;
case IPL_MANATOLIFE: {
int portion = ((Players[MyPlayerId]._pMaxManaBase >> 6) * 50 / 100) << 6;
int portion = ((MyPlayer->_pMaxManaBase >> 6) * 50 / 100) << 6;
item._iPLMana -= portion;
item._iPLHP += portion;
} break;
case IPL_LIFETOMANA: {
int portion = ((Players[MyPlayerId]._pMaxHPBase >> 6) * 40 / 100) << 6;
int portion = ((MyPlayer->_pMaxHPBase >> 6) * 40 / 100) << 6;
item._iPLHP -= portion;
item._iPLMana += portion;
} break;
@ -1956,7 +1956,7 @@ void SpawnOnePremium(Item &premiumItem, int plvl, int playerId)
int itemValue = 0;
bool keepGoing = false;
auto &player = Players[playerId];
Player &player = Players[playerId];
int strength = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Strength), player._pStrength);
int dexterity = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Dexterity), player._pDexterity);
@ -2078,7 +2078,7 @@ bool HealerItemOk(int i)
return AllItemsList[i].iSpell == SPL_HEALOTHER && gbIsMultiplayer;
if (!gbIsMultiplayer) {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (AllItemsList[i].iMiscId == IMISC_ELIXSTR)
return !gbIsHellfire || myPlayer._pBaseStr < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength);
@ -2573,7 +2573,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx)
player._pMaxHP = ihp + player._pMaxHPBase;
player._pHitPoints = std::min(ihp + player._pHPBase, player._pMaxHP);
if (&player == &Players[MyPlayerId] && (player._pHitPoints >> 6) <= 0) {
if (&player == MyPlayer && (player._pHitPoints >> 6) <= 0) {
SetPlayerHitPoints(player, 0);
}
@ -2683,7 +2683,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx)
player._pgfxnum = gfxNum;
}
if (&player == &Players[MyPlayerId]) {
if (&player == MyPlayer) {
if (player.InvBody[INVLOC_AMULET].isEmpty() || player.InvBody[INVLOC_AMULET].IDidx != IDI_AURIC) {
int half = MaxGold;
MaxGold = GOLD_MAX_LIMIT;
@ -2784,7 +2784,7 @@ void SetPlrHandGoldCurs(Item &gold)
void CreatePlrItems(int playerId)
{
auto &player = Players[playerId];
Player &player = Players[playerId];
for (auto &item : player.InvBody) {
item.clear();
@ -2999,7 +2999,7 @@ void GetItemAttrs(Item &item, int itemData, int lvl)
void SetupItem(Item &item)
{
item.setNewAnimation(Players[MyPlayerId].pLvlLoad == 0);
item.setNewAnimation(MyPlayer->pLvlLoad == 0);
item._iIdentified = false;
}
@ -3835,7 +3835,7 @@ void PrintItemDur(const Item &item)
void UseItem(int pnum, item_misc_id mid, spell_id spl)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
switch (mid) {
case IMISC_HEAL:
@ -4178,7 +4178,7 @@ void SpawnBoy(int lvl)
bool keepgoing = false;
int count = 0;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
HeroClass pc = myPlayer._pClass;
int strength = std::max(myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength), myPlayer._pStrength);
@ -4453,7 +4453,7 @@ std::string DebugSpawnItem(std::string itemName)
int ii = AllocateItem();
auto &item = Items[ii];
Point pos = Players[MyPlayerId].position.tile;
Point pos = MyPlayer->position.tile;
GetSuperItemSpace(pos, ii);
uint32_t begin = SDL_GetTicks();
@ -4535,7 +4535,7 @@ std::string DebugSpawnUniqueItem(std::string itemName)
int ii = AllocateItem();
auto &item = Items[ii];
Point pos = Players[MyPlayerId].position.tile;
Point pos = MyPlayer->position.tile;
GetSuperItemSpace(pos, ii);
int i = 0;

4
Source/lighting.cpp

@ -894,7 +894,7 @@ void ToggleLighting()
}
memcpy(dLight, dPreLight, sizeof(dLight));
for (const auto &player : Players) {
for (const Player &player : Players) {
if (player.plractive && player.plrlevel == currlevel) {
DoLighting(player.position.tile, player._pLightRad, -1);
}
@ -1134,7 +1134,7 @@ void ProcessVisionList()
MapExplorationType doautomap = MAP_EXP_SELF;
if (!vision._lflags) {
doautomap = MAP_EXP_OTHERS;
for (const auto &player : Players) {
for (const Player &player : Players) {
// Find player for this vision
if (!player.plractive || player.plrlevel != currlevel || player._pvid != vision._lid)
continue;

12
Source/loadsave.cpp

@ -1826,7 +1826,7 @@ void LoadHotkeys()
if (!file.IsValid())
return;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
size_t nHotkeys = 4; // Defaults to old save format number
// Refill the spell arrays with no selection
@ -1864,7 +1864,7 @@ void LoadHotkeys()
void SaveHotkeys()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
SaveHelper file(CurrentSaveArchive(), "hotkeys", HotkeysSize());
@ -1997,7 +1997,7 @@ void LoadGame(bool firstflag)
file.Skip(4); // Skip loading gnLevelTypeTbl
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
LoadPlayer(file, myPlayer);
@ -2269,7 +2269,7 @@ void SaveGameData()
file.WriteBE<int32_t>(getHellfireLevelType(gnLevelTypeTbl[i]));
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer.pDifficulty = sgGameInitInfo.nDifficulty;
SavePlayer(file, myPlayer);
@ -2396,7 +2396,7 @@ void SaveLevel()
{
PFileScopedArchiveWriter scopedWriter;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
DoUnVision(myPlayer.position.tile, myPlayer._pLightRad); // fix for vision staying on the level
@ -2547,7 +2547,7 @@ void LoadLevel()
UpdateLighting = true;
}
for (auto &player : Players) {
for (Player &player : Players) {
if (player.plractive && currlevel == player.plrlevel)
Lights[player._plid]._lunflag = true;
}

4
Source/miniwin/misc_msg.cpp

@ -81,7 +81,7 @@ void SetCursorPos(Point position)
// Moves the mouse to the first attribute "+" button.
void FocusOnCharInfo()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (invflag || myPlayer._pStatPts <= 0)
return;
@ -298,7 +298,7 @@ bool BlurInventory()
{
if (!MyPlayer->HoldItem.isEmpty()) {
if (!TryDropItem()) {
Players[MyPlayerId].Say(HeroSpeech::WhereWouldIPutThis);
MyPlayer->Say(HeroSpeech::WhereWouldIPutThis);
return false;
}
}

62
Source/missiles.cpp

@ -199,7 +199,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, missile_id t
int hit = GenerateRnd(100);
int hper = 0;
if (pnum != -1) {
const auto &player = Players[pnum];
const Player &player = Players[pnum];
if (MissilesData[t].mType == 0) {
hper = player.GetRangedPiercingToHit();
hper -= player.CalculateArmorPierce(monster.mArmorClass, false);
@ -233,7 +233,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, missile_id t
dam = mindam + GenerateRnd(maxdam - mindam + 1);
}
const auto &player = Players[pnum];
const Player &player = Players[pnum];
if (MissilesData[t].mType == 0 && MissilesData[t].mResist == MISR_NONE) {
dam = player._pIBonusDamMod + dam * player._pIBonusDam / 100 + dam;
@ -275,7 +275,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, missile_id t
bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, missile_id mtype, bool shift, bool *blocked)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
auto &target = Players[p];
if (sgGameInitInfo.bFriendlyFire == 0 && player.friendlyMode)
@ -706,7 +706,7 @@ void GetDamageAmt(int i, int *mind, int *maxd)
assert(MyPlayerId >= 0 && MyPlayerId < MAX_PLRS);
assert(i >= 0 && i < 64);
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int sl = myPlayer._pSplLvl[i] + myPlayer._pISplLvlAdd;
@ -825,11 +825,11 @@ void GetDamageAmt(int i, int *mind, int *maxd)
int GetSpellLevel(int playerId, spell_id sn)
{
auto &player = Players[playerId];
if (playerId != MyPlayerId)
return 1; // BUGFIX spell level will be wrong in multiplayer
Player &player = Players[playerId];
return std::max(player._pISplLvlAdd + player._pSplLvl[sn], 0);
}
@ -915,7 +915,7 @@ bool PlayerMHit(int pnum, Monster *monster, int dist, int mind, int maxd, missil
{
*blocked = false;
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pHitPoints >> 6 <= 0) {
return false;
@ -1056,7 +1056,7 @@ void SetMissDir(Missile &missile, int dir)
void InitMissiles()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
AutoMapShowItems = false;
myPlayer._pSpellFlags &= ~SpellFlag::Etherealize;
@ -1138,7 +1138,7 @@ void AddReflection(Missile &missile, const AddMissileParameter & /*parameter*/)
if (missile._misource < 0)
return;
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
int add = (missile._mispllvl != 0 ? missile._mispllvl : 2) * player._pLevel;
if (player.wReflections + add >= std::numeric_limits<uint16_t>::max())
@ -1257,7 +1257,7 @@ void AddStealPotions(Missile &missile, const AddMissileParameter & /*parameter*/
int8_t pnum = dPlayer[target.x][target.y];
if (pnum == 0)
continue;
auto &player = Players[abs(pnum) - 1];
Player &player = Players[abs(pnum) - 1];
bool hasPlayedSFX = false;
for (int si = 0; si < MAXBELTITEMS; si++) {
@ -1324,7 +1324,7 @@ void AddManaTrap(Missile &missile, const AddMissileParameter & /*parameter*/)
missile.position.start, 0, 2);
if (trappedPlayerPosition) {
auto &player = Players[abs(dPlayer[trappedPlayerPosition->x][trappedPlayerPosition->y]) - 1];
Player &player = Players[abs(dPlayer[trappedPlayerPosition->x][trappedPlayerPosition->y]) - 1];
player._pMana = 0;
player._pManaBase = player._pMana + player._pMaxManaBase - player._pMaxMana;
@ -1341,7 +1341,7 @@ void AddSpecArrow(Missile &missile, const AddMissileParameter &parameter)
int av = 0;
if (missile._micaster == TARGET_MONSTERS) {
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
if (player._pClass == HeroClass::Rogue)
av += (player._pLevel - 1) / 4;
@ -1464,7 +1464,7 @@ void AddLightningArrow(Missile &missile, const AddMissileParameter &parameter)
void AddMana(Missile &missile, const AddMissileParameter & /*parameter*/)
{
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
int manaAmount = (GenerateRnd(10) + 1) << 6;
for (int i = 0; i < player._pLevel; i++) {
@ -1490,7 +1490,7 @@ void AddMana(Missile &missile, const AddMissileParameter & /*parameter*/)
void AddMagi(Missile &missile, const AddMissileParameter & /*parameter*/)
{
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
player._pMana = player._pMaxMana;
player._pManaBase = player._pMaxManaBase;
@ -1558,7 +1558,7 @@ void AddLArrow(Missile &missile, const AddMissileParameter &parameter)
}
int av = 32;
if (missile._micaster == TARGET_MONSTERS) {
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
if (player._pClass == HeroClass::Rogue)
av += (player._pLevel) / 4;
else if (IsAnyOf(player._pClass, HeroClass::Warrior, HeroClass::Bard))
@ -1595,7 +1595,7 @@ void AddArrow(Missile &missile, const AddMissileParameter &parameter)
}
int av = 32;
if (missile._micaster == TARGET_MONSTERS) {
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
if (HasAnyOf(player._pIFlags, ItemSpecialEffect::RandomArrowVelocity)) {
av = GenerateRnd(32) + 16;
@ -1628,7 +1628,7 @@ void UpdateVileMissPos(Missile &missile, Point dst)
int yy = j + dst.y;
for (int i = -k; i <= k; i++) {
int xx = i + dst.x;
if (PosOkPlayer(Players[MyPlayerId], { xx, yy })) {
if (PosOkPlayer(*MyPlayer, { xx, yy })) {
missile.position.tile = { xx, yy };
return;
}
@ -1641,7 +1641,7 @@ void AddRndTeleport(Missile &missile, const AddMissileParameter &parameter)
{
missile._mirange = 2;
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
if (missile._micaster == TARGET_BOTH) {
missile.position.tile = parameter.dst;
@ -1948,7 +1948,7 @@ void AddManashield(Missile &missile, const AddMissileParameter & /*parameter*/)
if (missile._misource < 0)
return;
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
if (player.pManaShield)
return;
@ -1972,7 +1972,7 @@ void AddFiremove(Missile &missile, const AddMissileParameter &parameter)
void AddGuardian(Missile &missile, const AddMissileParameter &parameter)
{
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
int dmg = GenerateRnd(10) + (player._pLevel / 2) + 1;
missile._midam = ScaleSpellEffect(dmg, missile._mispllvl);
@ -2214,7 +2214,7 @@ void AddBoom(Missile &missile, const AddMissileParameter &parameter)
void AddHeal(Missile &missile, const AddMissileParameter & /*parameter*/)
{
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
int hp = GenerateRnd(10) + 1;
hp += GenerateRndSum(4, player._pLevel) + player._pLevel;
@ -2347,7 +2347,7 @@ void AddNova(Missile &missile, const AddMissileParameter &parameter)
void AddBlodboil(Missile &missile, const AddMissileParameter & /*parameter*/)
{
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
if (HasAnyOf(player._pSpellFlags, SpellFlag::RageActive | SpellFlag::RageCooldown) || player._pHitPoints <= player._pLevel << 6) {
missile._miDelFlag = true;
@ -2554,7 +2554,7 @@ void AddDiabApoca(Missile &missile, const AddMissileParameter & /*parameter*/)
{
int players = gbIsMultiplayer ? MAX_PLRS : 1;
for (int pnum = 0; pnum < players; pnum++) {
auto &player = Players[pnum];
Player &player = Players[pnum];
if (!player.plractive)
continue;
if (!LineClearMissile(missile.position.start, player.position.future))
@ -2707,7 +2707,7 @@ void MI_Arrow(Missile &missile)
int maxd;
if (!missile.IsTrap()) {
if (missile._micaster == TARGET_MONSTERS) {
auto &player = Players[p];
Player &player = Players[p];
mind = player._pIMinDam;
maxd = player._pIMaxDam;
} else {
@ -2734,7 +2734,7 @@ void MI_Firebolt(Missile &missile)
int p = missile._misource;
if (!missile.IsTrap()) {
if (missile._micaster == TARGET_MONSTERS) {
auto &player = Players[p];
Player &player = Players[p];
switch (missile._mitype) {
case MIS_FIREBOLT:
d = GenerateRnd(10) + (player._pMagic / 8) + missile._mispllvl + 1;
@ -3131,7 +3131,7 @@ void MI_SpecArrow(Missile &missile)
Direction dir = Direction::South;
mienemy_type micaster = TARGET_PLAYERS;
if (!missile.IsTrap()) {
auto &player = Players[id];
Player &player = Players[id];
dir = player._pdir;
micaster = TARGET_MONSTERS;
@ -3208,7 +3208,7 @@ void MI_Town(Missile &missile)
}
for (int p = 0; p < MAX_PLRS; p++) {
auto &player = Players[p];
Player &player = Players[p];
if (player.plractive && currlevel == player.plrlevel && !player._pLvlChanging && player._pmode == PM_STAND && player.position.tile == missile.position.tile) {
ClrPlrPath(player);
if (p == MyPlayerId) {
@ -3465,7 +3465,7 @@ void MI_Teleport(Missile &missile)
}
int id = missile._misource;
auto &player = Players[id];
Player &player = Players[id];
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
PlrClrTrans(player.position.tile);
@ -3598,7 +3598,7 @@ void MI_FirewallC(Missile &missile)
void MI_Infra(Missile &missile)
{
auto &player = Players[missile._misource];
Player &player = Players[missile._misource];
missile._mirange--;
player._pInfraFlag = true;
if (missile._mirange == 0) {
@ -3720,7 +3720,7 @@ void MI_Blodboil(Missile &missile)
}
int id = missile._misource;
auto &player = Players[id];
Player &player = Players[id];
int hpdif = player._pMaxHP - player._pHitPoints;
@ -3998,7 +3998,7 @@ static void DeleteMissiles()
void ProcessManaShield()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer.pManaShield && myPlayer._pMana <= 0) {
myPlayer.pManaShield = false;
NetSendCmd(true, CMD_REMSHIELD);

22
Source/monster.cpp

@ -738,7 +738,7 @@ void UpdateEnemy(Monster &monster)
const auto &position = monster.position.tile;
if ((monster._mFlags & MFLAG_BERSERK) != 0 || (monster._mFlags & MFLAG_GOLEM) == 0) {
for (int pnum = 0; pnum < MAX_PLRS; pnum++) {
auto &player = Players[pnum];
Player &player = Players[pnum];
if (!player.plractive || currlevel != player.plrlevel || player._pLvlChanging
|| (((player._pHitPoints >> 6) == 0) && gbIsMultiplayer))
continue;
@ -1314,7 +1314,7 @@ void MonsterAttackMonster(int i, int mid, int hper, int mind, int maxd)
void CheckReflect(int mon, int pnum, int dam)
{
auto &monster = Monsters[mon];
auto &player = Players[pnum];
Player &player = Players[pnum];
player.wReflections--;
if (player.wReflections <= 0)
@ -1340,7 +1340,7 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
return;
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pHitPoints >> 6 <= 0 || player._pInvincible || HasAnyOf(player._pSpellFlags, SpellFlag::Etherealize))
return;
@ -3151,7 +3151,7 @@ void LazarusAi(int i)
Direction md = GetMonsterDirection(monster);
if (IsTileVisible(monster.position.tile)) {
if (!gbIsMultiplayer) {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (monster.mtalkmsg == TEXT_VILE13 && monster._mgoal == MGOAL_INQUIRING && myPlayer.position.tile == Point { 35, 46 }) {
PlayInGameMovie("gendata\\fprst3.smk");
monster._mmode = MonsterMode::Talk;
@ -4085,7 +4085,7 @@ void DoEnding()
if (gbIsSpawn)
return;
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Sorcerer:
case HeroClass::Monk:
play_movie("gendata\\DiabVic1.smk", false);
@ -4123,11 +4123,11 @@ void PrepDoEnding()
MyPlayerIsDead = false;
cineflag = true;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer.pDiabloKillLevel = std::max(myPlayer.pDiabloKillLevel, static_cast<uint8_t>(sgGameInitInfo.nDifficulty + 1));
for (auto &player : Players) {
for (Player &player : Players) {
player._pmode = PM_QUIT;
player._pInvincible = true;
if (gbIsMultiplayer) {
@ -4306,7 +4306,7 @@ void ProcessMonsters()
monster.enemyPosition = monster.position.last;
} else {
assert(monster._menemy >= 0 && monster._menemy < MAX_PLRS);
auto &player = Players[monster._menemy];
Player &player = Players[monster._menemy];
monster.enemyPosition = player.position.future;
if (IsTileVisible(monster.position.tile)) {
monster._msquelch = UINT8_MAX;
@ -4700,7 +4700,7 @@ void PrintUniqueHistory()
void PlayEffect(Monster &monster, int mode)
{
if (Players[MyPlayerId].pLvlLoad != 0) {
if (MyPlayer->pLvlLoad != 0) {
return;
}
@ -4870,7 +4870,7 @@ int PreSpawnSkeleton()
void TalktoMonster(Monster &monster)
{
auto &player = Players[monster._menemy];
Player &player = Players[monster._menemy];
monster._mmode = MonsterMode::Talk;
if (monster._mAi != AI_SNOTSPIL && monster._mAi != AI_LACHDAN) {
return;
@ -4894,7 +4894,7 @@ void TalktoMonster(Monster &monster)
void SpawnGolem(int i, Point position, Missile &missile)
{
assert(i >= 0 && i < MAX_PLRS);
auto &player = Players[i];
Player &player = Players[i];
auto &golem = Monsters[i];
dMonster[position.x][position.y] = i + 1;

43
Source/msg.cpp

@ -861,7 +861,7 @@ DWORD OnAutoGetItem(const TCmd *pCmd, int pnum)
if ((currlevel == message.bLevel || message.bPnum == MyPlayerId) && message.bMaster != MyPlayerId) {
if (message.bPnum == MyPlayerId) {
if (currlevel != message.bLevel) {
auto &player = Players[MyPlayerId];
Player &player = *MyPlayer;
int ii = SyncPutItem(player, player.position.tile, message.wIndx, message.wCI, message.dwSeed, message.bId, message.bDur, message.bMDur, message.bCh, message.bMCh, message.wValue, message.dwBuff, message.wToHit, message.wMaxDam, message.bMinStr, message.bMinMag, message.bMinDex, message.bAC);
if (ii != -1)
AutoGetItem(MyPlayerId, &Items[ii], ii);
@ -961,7 +961,7 @@ DWORD OnRespawnItem(const TCmd *pCmd, int pnum)
SendPacket(pnum, &message, sizeof(message));
} else if (IsPItemValid(message)) {
const Point position { message.x, message.y };
auto &player = Players[pnum];
Player &player = Players[pnum];
int playerLevel = player.plrlevel;
if (currlevel == playerLevel && pnum != MyPlayerId) {
SyncPutItem(player, position, message.wIndx, message.wCI, message.dwSeed, message.bId, message.bDur, message.bMDur, message.bCh, message.bMCh, message.wValue, message.dwBuff, message.wToHit, message.wMaxDam, message.bMinStr, message.bMinMag, message.bMinDex, message.bAC);
@ -1623,7 +1623,7 @@ DWORD OnBreakObject(const TCmd *pCmd, int pnum)
DWORD OnChangePlayerItems(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdChItem *>(pCmd);
auto &player = Players[pnum];
Player &player = Players[pnum];
if (message.bLoc >= NUM_INVLOC)
return sizeof(message);
@ -1724,7 +1724,7 @@ DWORD OnPlayerJoinLevel(const TCmd *pCmd, int pnum)
return sizeof(message);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pLvlChanging = false;
if (player._pName[0] != '\0' && !player.plractive) {
@ -1926,7 +1926,7 @@ DWORD OnCheatSpellLevel(const TCmd *pCmd, int pnum) // NOLINT(misc-unused-parame
if (gbBufferMsgs == 1) {
SendPacket(pnum, pCmd, sizeof(*pCmd));
} else {
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pSplLvl[player._pRSpell]++;
}
#endif
@ -1944,7 +1944,7 @@ DWORD OnNova(const TCmd *pCmd, int pnum)
const Point position { message.x, message.y };
if (gbBufferMsgs != 1) {
auto &player = Players[pnum];
Player &player = Players[pnum];
if (currlevel == player.plrlevel && pnum != MyPlayerId && InDungeonBounds(position)) {
ClrPlrPath(player);
player._pSpell = SPL_NOVA;
@ -2237,7 +2237,7 @@ void DeltaSaveLevel()
if (i != MyPlayerId)
ResetPlayerGFX(Players[i]);
}
Players[MyPlayerId]._pLvlVisited[currlevel] = true;
MyPlayer->_pLvlVisited[currlevel] = true;
DeltaLeaveSync(currlevel);
}
@ -2442,8 +2442,7 @@ void NetSendCmdLoc(int playerId, bool bHiPri, _cmd_id bCmd, Point position)
else
NetSendLoPri(playerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, position, 0, 0);
MyPlayer->UpdatePreviewCelSprite(bCmd, position, 0, 0);
}
void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1)
@ -2462,8 +2461,7 @@ void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, position, wParam1, 0);
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, 0);
}
void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2)
@ -2483,8 +2481,7 @@ void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2);
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2);
}
void NetSendCmdLocParam3(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3)
@ -2505,8 +2502,7 @@ void NetSendCmdLocParam3(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2);
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2);
}
void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4)
@ -2528,8 +2524,7 @@ void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3);
MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3);
}
void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1)
@ -2546,8 +2541,7 @@ void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1)
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, {}, wParam1, 0);
MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, 0);
}
void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2)
@ -2579,8 +2573,7 @@ void NetSendCmdParam3(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2);
MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2);
}
void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4)
@ -2600,8 +2593,7 @@ void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
else
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
auto &myPlayer = Players[MyPlayerId];
myPlayer.UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2);
MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2);
}
void NetSendCmdQuest(bool bHiPri, const Quest &quest)
@ -2716,8 +2708,7 @@ void NetSendCmdChItem(bool bHiPri, uint8_t bLoc)
{
TCmdChItem cmd;
Player &myPlayer = Players[MyPlayerId];
Item &item = myPlayer.InvBody[bLoc];
Item &item = MyPlayer->InvBody[bLoc];
cmd.bCmd = CMD_CHANGEPLRITEMS;
cmd.bLoc = bLoc;
@ -2792,7 +2783,7 @@ uint32_t ParseCmd(int pnum, const TCmd *pCmd)
if (sgwPackPlrOffsetTbl[pnum] != 0 && sbLastCmd != CMD_ACK_PLRINFO && sbLastCmd != CMD_SEND_PLRINFO)
return 0;
auto &player = Players[pnum];
Player &player = Players[pnum];
switch (pCmd->bCmd) {
case CMD_SYNCDATA:

22
Source/multi.cpp

@ -118,7 +118,7 @@ byte *ReceivePacket(TBuffer *pBuf, byte *body, size_t *size)
void NetReceivePlayerData(TPkt *pkt)
{
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
const Point target = myPlayer.GetTargetPosition();
pkt->hdr.wCheck = LoadBE32("\0\0ip");
@ -230,7 +230,7 @@ void PlayerLeftMsg(int pnum, bool left)
return;
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (!player.plractive) {
return;
@ -336,7 +336,7 @@ void SendPlayerInfo(int pnum, _cmd_id cmd)
std::unique_ptr<byte[]> pkplr { new byte[sizeof(PlayerPack)] };
PlayerPack *pPack = reinterpret_cast<PlayerPack *>(pkplr.get());
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
PackPlayer(pPack, myPlayer, true, true);
pPack->friendlyMode = myPlayer.friendlyMode ? 1 : 0;
dthread_send_delta(pnum, cmd, std::move(pkplr), sizeof(PlayerPack));
@ -374,7 +374,7 @@ void SetupLocalPositions()
x += plrxoff[MyPlayerId];
y += plryoff[MyPlayerId];
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer.position.tile = { x, y };
myPlayer.position.future = { x, y };
@ -446,7 +446,7 @@ bool InitSingle(GameData *gameData)
}
MyPlayerId = 0;
MyPlayer = &Players[MyPlayerId];
MyPlayer = MyPlayer;
gbIsMultiplayer = false;
pfile_read_player_from_save(gSaveNumber, *MyPlayer);
@ -474,7 +474,7 @@ bool InitMulti(GameData *gameData)
return false;
}
MyPlayerId = playerId;
MyPlayer = &Players[MyPlayerId];
MyPlayer = MyPlayer;
gbIsMultiplayer = true;
pfile_read_player_from_save(gSaveNumber, *MyPlayer);
@ -625,7 +625,7 @@ void multi_process_network_packets()
continue;
if (pkt->wLen != dwMsgSize)
continue;
auto &player = Players[dwID];
Player &player = Players[dwID];
if (!IsNetPlayerValid(player)) {
_cmd_id cmd = *(const _cmd_id *)(pkt + 1);
if (gbBufferMsgs == 0 && IsNoneOf(cmd, CMD_SEND_PLRINFO, CMD_ACK_PLRINFO)) {
@ -739,7 +739,7 @@ bool NetInit(bool bSinglePlayer)
memset(sgbPlayerLeftGameTbl, 0, sizeof(sgbPlayerLeftGameTbl));
memset(sgdwPlayerLeftReasonTbl, 0, sizeof(sgdwPlayerLeftReasonTbl));
memset(sgbSendDeltaTbl, 0, sizeof(sgbSendDeltaTbl));
for (auto &player : Players) {
for (Player &player : Players) {
player.Reset();
}
memset(sgwPackPlrOffsetTbl, 0, sizeof(sgwPackPlrOffsetTbl));
@ -770,7 +770,7 @@ bool NetInit(bool bSinglePlayer)
SetupLocalPositions();
SendPlayerInfo(SNPLAYER_OTHERS, CMD_SEND_PLRINFO);
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
ResetPlayerGFX(myPlayer);
myPlayer.plractive = true;
gbActivePlayers = 1;
@ -793,7 +793,7 @@ bool NetInit(bool bSinglePlayer)
nthread_terminate_game("SNetGetGameInfo2");
PublicGame = DvlNet_IsPublicGame();
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
// separator for marking messages from a different game
AddMessageToChatLog(_("New Game"), nullptr, UiFlags::ColorRed);
AddMessageToChatLog(fmt::format(_("Player '{:s}' (level {:d}) just joined the game"), myPlayer._pName, myPlayer._pLevel));
@ -809,7 +809,7 @@ void recv_plrinfo(int pnum, const TCmdPlrInfoHdr &header, bool recv)
return;
}
assert(pnum >= 0 && pnum < MAX_PLRS);
auto &player = Players[pnum];
Player &player = Players[pnum];
auto &packedPlayer = PackedPlayerBuffer[pnum];
if (sgwPackPlrOffsetTbl[pnum] != header.wOffset) {

66
Source/objects.cpp

@ -724,7 +724,7 @@ void AddDiabObjs()
void AddCryptObject(Object &object, int a2)
{
if (a2 > 5) {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
switch (a2) {
case 6:
switch (myPlayer._pClass) {
@ -1448,7 +1448,7 @@ void UpdateObjectLight(Object &light, int lightRadius)
void UpdateCircle(Object &circle)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer.position.tile != circle.position) {
if (circle._otype == OBJ_MCIRCLE1)
@ -1589,7 +1589,7 @@ void UpdateBurningCrossDamage(Object &cross)
{
int damage[6] = { 6, 8, 10, 12, 10, 12 };
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pmode == PM_DEATH)
return;
@ -2257,7 +2257,7 @@ void OperateBook(int pnum, Object &book)
return;
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (setlevel && setlvlnum == SL_VILEBETRAYER) {
bool missileAdded = false;
@ -2385,7 +2385,7 @@ void OperateChamberOfBoneBook(Object &questBook)
}
_speech_id textdef;
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Warrior:
textdef = TEXT_BONER;
break;
@ -2436,7 +2436,7 @@ void OperateChest(int pnum, int i, bool sendmsg)
}
}
if (Objects[i].IsTrappedChest()) {
auto &player = Players[pnum];
Player &player = Players[pnum];
Direction mdir = GetDirection(Objects[i].position, player.position.tile);
missile_id mtype;
switch (Objects[i]._oVar4) {
@ -2533,7 +2533,7 @@ void OperateSlainHero(int pnum, int i)
return;
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pClass == HeroClass::Warrior) {
CreateMagicArmor(Objects[i].position, ItemType::HeavyArmor, ICURS_BREAST_PLATE, true, false);
@ -2548,7 +2548,7 @@ void OperateSlainHero(int pnum, int i)
} else if (player._pClass == HeroClass::Barbarian) {
CreateMagicWeapon(Objects[i].position, ItemType::Axe, ICURS_BATTLE_AXE, true, false);
}
Players[MyPlayerId].Say(HeroSpeech::RestInPeaceMyFriend);
MyPlayer->Say(HeroSpeech::RestInPeaceMyFriend);
if (pnum == MyPlayerId)
NetSendCmdParam1(false, CMD_OPERATEOBJ, i);
}
@ -2702,7 +2702,7 @@ bool OperateShrineHidden(int pnum)
if (pnum != MyPlayerId)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
int cnt = 0;
for (const auto &item : player.InvBody) {
@ -2755,7 +2755,7 @@ bool OperateShrineGloomy(int pnum)
if (pnum != MyPlayerId)
return true;
auto &player = Players[pnum];
Player &player = Players[pnum];
// Increment armor class by 2 and decrements max damage by 1.
for (Item &item : PlayerItemsRange(player)) {
@ -2793,7 +2793,7 @@ bool OperateShrineWeird(int pnum)
if (pnum != MyPlayerId)
return true;
auto &player = Players[pnum];
Player &player = Players[pnum];
if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._itype != ItemType::Shield)
player.InvBody[INVLOC_HAND_LEFT]._iMaxDam++;
@ -2824,7 +2824,7 @@ bool OperateShrineMagical(int pnum)
if (deltaload)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
AddMissile(
player.position.tile,
@ -2884,7 +2884,7 @@ bool OperateShrineEnchanted(int pnum)
if (pnum != MyPlayerId)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
int cnt = 0;
uint64_t spell = 1;
@ -2949,7 +2949,7 @@ bool OperateShrineCostOfWisdom(int pnum, spell_id spellId, diablo_message messag
if (pnum != MyPlayerId)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pMemSpells |= GetSpellBitmask(spellId);
@ -2984,7 +2984,7 @@ bool OperateShrineCryptic(int pnum)
if (deltaload)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
AddMissile(
player.position.tile,
@ -3065,7 +3065,7 @@ bool OperateShrineDivine(int pnum, Point spawnPosition)
if (pnum != MyPlayerId)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
if (currlevel < 4) {
CreateTypeItem(spawnPosition, false, ItemType::Misc, IMISC_FULLMANA, false, true);
@ -3107,7 +3107,7 @@ bool OperateShrineSpiritual(int pnum)
if (pnum != MyPlayerId)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
for (int8_t &itemIndex : player.InvGrid) {
if (itemIndex == 0) {
@ -3135,7 +3135,7 @@ bool OperateShrineSpooky(int pnum)
return true;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer._pHitPoints = myPlayer._pMaxHP;
myPlayer._pHPBase = myPlayer._pMaxHPBase;
@ -3257,7 +3257,7 @@ bool OperateShrineTainted(int pnum)
ModifyPlrDex(MyPlayerId, v3);
ModifyPlrVit(MyPlayerId, v4);
CheckStats(Players[MyPlayerId]);
CheckStats(*MyPlayer);
InitDiabloMsg(EMSG_SHRINE_TAINTED2);
@ -3279,7 +3279,7 @@ bool OperateShrineOily(int pnum, Point spawnPosition)
if (pnum != MyPlayerId)
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
switch (myPlayer._pClass) {
case HeroClass::Warrior:
@ -3328,7 +3328,7 @@ bool OperateShrineGlowing(int pnum)
if (pnum != MyPlayerId)
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
// Add 0-5 points to Magic (0.1% of the players XP)
ModifyPlrMag(MyPlayerId, static_cast<int>(std::min<uint32_t>(myPlayer._pExperience / 1000, 5)));
@ -3356,7 +3356,7 @@ bool OperateShrineMendicant(int pnum)
if (pnum != MyPlayerId)
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int gold = myPlayer._pGold / 2;
AddPlrExperience(MyPlayerId, myPlayer._pLevel, gold);
@ -3382,7 +3382,7 @@ bool OperateShrineSparkling(int pnum, Point spawnPosition)
if (pnum != MyPlayerId)
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
AddPlrExperience(MyPlayerId, myPlayer._pLevel, 1000 * currlevel);
@ -3416,7 +3416,7 @@ bool OperateShrineTown(int pnum, Point spawnPosition)
if (pnum != MyPlayerId)
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
AddMissile(
spawnPosition,
@ -3440,7 +3440,7 @@ bool OperateShrineShimmering(int pnum)
if (pnum != MyPlayerId)
return false;
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pMana = player._pMaxMana;
player._pManaBase = player._pMaxManaBase;
@ -3485,7 +3485,7 @@ bool OperateShrineMurphys(int pnum)
if (pnum != MyPlayerId)
return false;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
bool broke = false;
for (auto &item : myPlayer.InvBody) {
@ -3820,7 +3820,7 @@ void OperateCauldron(int pnum, int i, _sfx_id sType)
bool OperateFountains(int pnum, int i)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
bool applied = false;
switch (Objects[i]._otype) {
case OBJ_BLOODFTN:
@ -4585,7 +4585,7 @@ void InitObjects()
AddL2Torches();
if (Quests[Q_BLIND].IsAvailable()) {
_speech_id spId;
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Warrior:
spId = TEXT_BLINDING;
break;
@ -4611,7 +4611,7 @@ void InitObjects()
}
if (Quests[Q_BLOOD].IsAvailable()) {
_speech_id spId;
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Warrior:
spId = TEXT_BLOODY;
break;
@ -4644,7 +4644,7 @@ void InitObjects()
if (leveltype == DTYPE_HELL) {
if (Quests[Q_WARLORD].IsAvailable()) {
_speech_id spId;
switch (Players[MyPlayerId]._pClass) {
switch (MyPlayer->_pClass) {
case HeroClass::Warrior:
spId = TEXT_BLOODWAR;
break;
@ -5038,7 +5038,7 @@ void ProcessObjects()
void RedoPlayerVision()
{
for (auto &player : Players) {
for (Player &player : Players) {
if (player.plractive && currlevel == player.plrlevel) {
ChangeVisionXY(player._pvid, player.position.tile);
}
@ -5409,7 +5409,7 @@ void BreakObject(int pnum, Object &object)
{
int objdam = 10;
if (pnum != -1) {
auto &player = Players[pnum];
Player &player = Players[pnum];
int mind = player._pIMinDam;
int maxd = player._pIMaxDam;
objdam = GenerateRnd(maxd - mind + 1) + mind;
@ -5632,7 +5632,7 @@ void GetObjectStr(const Object &object)
default:
break;
}
if (Players[MyPlayerId]._pClass == HeroClass::Rogue) {
if (MyPlayer->_pClass == HeroClass::Rogue) {
if (object._oTrapFlag) {
InfoString = fmt::format(_(/* TRANSLATORS: {:s} will either be a chest or a door */ "Trapped {:s}"), InfoString);
InfoColor = UiFlags::ColorRed;

8
Source/panels/spell_book.cpp

@ -53,7 +53,7 @@ void PrintSBookStr(const Surface &out, Point position, string_view text, UiFlags
spell_type GetSBookTrans(spell_id ii, bool townok)
{
auto &player = Players[MyPlayerId];
Player &player = *MyPlayer;
if ((player._pClass == HeroClass::Monk) && (ii == SPL_SEARCH))
return RSPLTYPE_SKILL;
spell_type st = RSPLTYPE_SPELL;
@ -92,7 +92,7 @@ void InitSpellBook()
}
pSBkIconCels = LoadCel("Data\\SpellI2.CEL", 37);
Player &player = Players[MyPlayerId];
Player &player = *MyPlayer;
if (player._pClass == HeroClass::Warrior) {
SpellPages[0][0] = SPL_REPAIR;
} else if (player._pClass == HeroClass::Rogue) {
@ -128,7 +128,7 @@ void DrawSpellBook(const Surface &out)
}
CelDrawTo(out, GetPanelPosition(UiPanels::Spell, { sx, 348 }), *pSBkBtnCel, sbooktab);
}
auto &player = Players[MyPlayerId];
Player &player = *MyPlayer;
uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells;
const int lineHeight = 18;
@ -194,7 +194,7 @@ void CheckSBook()
Rectangle tabArea = { GetPanelPosition(UiPanels::Spell, { 7, 320 }), { 311 - 7, 349 - 320 } };
if (iconArea.Contains(MousePosition)) {
spell_id sn = SpellPages[sbooktab][(MousePosition.y - GetRightPanel().position.y - 18) / 43];
auto &player = Players[MyPlayerId];
Player &player = *MyPlayer;
uint64_t spl = player._pMemSpells | player._pISpells | player._pAblSpells;
if (sn != SPL_INVALID && (spl & GetSpellBitmask(sn)) != 0) {
spell_type st = RSPLTYPE_SPELL;

18
Source/panels/spell_list.cpp

@ -67,7 +67,7 @@ bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType)
{
pSpell = spell_id::SPL_INVALID;
pSplType = spell_type::RSPLTYPE_INVALID;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (auto &spellListItem : GetSpellListItems()) {
if (spellListItem.isSelected) {
@ -84,7 +84,7 @@ bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType)
std::optional<string_view> GetHotkeyName(spell_id spellId, spell_type spellType)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (size_t t = 0; t < NumHotkeys; t++) {
if (myPlayer._pSplHotKey[t] != spellId || myPlayer._pSplTHotKey[t] != spellType)
continue;
@ -98,7 +98,7 @@ std::optional<string_view> GetHotkeyName(spell_id spellId, spell_type spellType)
void DrawSpell(const Surface &out)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
spell_id spl = myPlayer._pRSpell;
spell_type st = myPlayer._pRSplType;
@ -127,7 +127,7 @@ void DrawSpellList(const Surface &out)
InfoString.clear();
ClearPanel();
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (auto &spellListItem : GetSpellListItems()) {
const spell_id spellId = spellListItem.id;
@ -217,7 +217,7 @@ std::vector<SpellListItem> GetSpellListItems()
int y = mainPanelPosition.y - 17;
for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) {
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
switch ((spell_type)i) {
case RSPLTYPE_SKILL:
mask = myPlayer._pAblSpells;
@ -271,7 +271,7 @@ void SetSpell()
ClearPanel();
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer._pRSpell = pSpell;
myPlayer._pRSplType = pSplType;
@ -286,7 +286,7 @@ void SetSpeedSpell(size_t slot)
if (!GetSpellListSelection(pSpell, pSplType)) {
return;
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (size_t i = 0; i < NumHotkeys; ++i) {
if (myPlayer._pSplHotKey[i] == pSpell && myPlayer._pSplTHotKey[i] == pSplType)
myPlayer._pSplHotKey[i] = SPL_INVALID;
@ -299,7 +299,7 @@ void ToggleSpell(size_t slot)
{
uint64_t spells;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pSplHotKey[slot] == SPL_INVALID) {
return;
@ -339,7 +339,7 @@ void DoSpeedBook()
int x = xo + SPLICONLENGTH / 2;
int y = yo - SPLICONLENGTH / 2;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pRSpell != SPL_INVALID) {
for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) {

6
Source/pfile.cpp

@ -289,7 +289,7 @@ void pfile_write_hero(bool writeGameData, bool clearTables)
RenameTempToPerm();
}
PlayerPack pkplr;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
PackPlayer(&pkplr, myPlayer, !gbIsMultiplayer, false);
EncodeHero(&pkplr);
@ -330,7 +330,7 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
if (hasSaveGame)
pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0;
auto &player = Players[0];
Player &player = Players[0];
player = {};
@ -383,7 +383,7 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo)
SaveWriter.RemoveHashEntries(GetFileName);
CopyUtf8(hero_names[saveNum], heroinfo->name, sizeof(hero_names[saveNum]));
auto &player = Players[0];
Player &player = Players[0];
CreatePlayer(0, heroinfo->heroclass);
CopyUtf8(player._pName, heroinfo->name, PLR_NAME_LEN);
PackPlayer(&pkplr, player, true, false);

114
Source/player.cpp

@ -38,7 +38,7 @@
namespace devilution {
int MyPlayerId;
Player *MyPlayer;
Player *MyPlayer = &Players[MyPlayerId];
Player Players[MAX_PLRS];
bool MyPlayerIsDead;
@ -217,14 +217,14 @@ void PmChangeLightOff(Player &player)
void WalkUpwards(int pnum, const DirectionSettings &walkParams)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
dPlayer[player.position.future.x][player.position.future.y] = -(pnum + 1);
player.position.temp = { walkParams.tileAdd.deltaX, walkParams.tileAdd.deltaY };
}
void WalkDownwards(int pnum, const DirectionSettings & /*walkParams*/)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
dPlayer[player.position.tile.x][player.position.tile.y] = -(pnum + 1);
player.position.temp = player.position.tile;
player.position.tile = player.position.future; // Move player to the next tile to maintain correct render order
@ -236,7 +236,7 @@ void WalkDownwards(int pnum, const DirectionSettings & /*walkParams*/)
void WalkSides(int pnum, const DirectionSettings &walkParams)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
Point const nextPosition = player.position.tile + walkParams.map;
@ -313,7 +313,7 @@ bool PlrDirOK(const Player &player, Direction dir)
void HandleWalkMode(int pnum, Displacement vel, Direction dir)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
const auto &dirModeParams = WalkSettings[static_cast<size_t>(dir)];
SetPlayerOld(player);
if (!PlrDirOK(player, dir)) {
@ -353,7 +353,7 @@ void StartWalkAnimation(Player &player, Direction dir, bool pmWillBeCalled)
*/
void StartWalk(int pnum, Displacement vel, Direction dir, bool pmWillBeCalled)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -391,7 +391,7 @@ void StartWalkStand(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartWalkStand: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pmode = PM_STAND;
player.position.future = player.position.tile;
@ -409,7 +409,7 @@ void ChangeOffset(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_ChangeOffset: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
int px = player.position.offset2.deltaX / 256;
int py = player.position.offset2.deltaY / 256;
@ -437,7 +437,7 @@ void StartAttack(int pnum, Direction d)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartAttack: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -469,7 +469,7 @@ void StartRangeAttack(int pnum, Direction d, int cx, int cy)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartRangeAttack: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -510,7 +510,7 @@ void StartSpell(int pnum, Direction d, int cx, int cy)
{
if ((DWORD)pnum >= MAX_PLRS)
app_fatal("StartSpell: illegal player %i", pnum);
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -604,7 +604,7 @@ void DropHalfPlayersGold(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("DropHalfPlayersGold: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
int remainingGold = DropGold(player, player._pGold / 2, true);
if (remainingGold > 0) {
@ -616,8 +616,8 @@ void DropHalfPlayersGold(int pnum)
void InitLevelChange(int pnum)
{
auto &player = Players[pnum];
auto &myPlayer = Players[MyPlayerId];
Player &player = Players[pnum];
Player &myPlayer = *MyPlayer;
RemovePlrMissiles(pnum);
player.pManaShield = false;
@ -658,7 +658,7 @@ bool DoWalk(int pnum, int variant)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoWalk: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
// Play walking sound effect on certain animation frames
if (*sgOptions.Audio.walkingSound && (currlevel != 0 || sgGameInitInfo.bRunInTown == 0)) {
@ -743,7 +743,7 @@ bool DamageWeapon(int pnum, int durrnd)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("DamageWeapon: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (WeaponDecay(player, INVLOC_HAND_LEFT))
return true;
@ -821,7 +821,7 @@ bool PlrHitMonst(int pnum, int m, bool adjacentDamage = false)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PlrHitMonst: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (!monster.IsPossibleToHit())
return false;
@ -1084,7 +1084,7 @@ bool DoAttack(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoAttack: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.AnimInfo.CurrentFrame == player._pAFNum - 2) {
PlaySfxLoc(PS_SWING, player.position.tile);
@ -1193,7 +1193,7 @@ bool DoRangeAttack(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoRangeAttack: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
int arrows = 0;
if (player.AnimInfo.CurrentFrame == player._pAFNum - 1) {
@ -1268,7 +1268,7 @@ void DamageParryItem(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("DamageParryItem: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Shield || player.InvBody[INVLOC_HAND_LEFT]._itype == ItemType::Staff) {
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) {
@ -1298,7 +1298,7 @@ bool DoBlock(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoBlock: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.AnimInfo.CurrentFrame >= player._pBFrames - 1) {
StartStand(pnum, player._pdir);
@ -1325,7 +1325,7 @@ void DamageArmor(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("DamageArmor: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.InvBody[INVLOC_CHEST].isEmpty() && player.InvBody[INVLOC_HEAD].isEmpty()) {
return;
@ -1366,7 +1366,7 @@ bool DoSpell(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoSpell: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.AnimInfo.CurrentFrame == player._pSFNum) {
CastSpell(
@ -1397,7 +1397,7 @@ bool DoGotHit(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoGotHit: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.AnimInfo.CurrentFrame >= player._pHFrames - 1) {
StartStand(pnum, player._pdir);
@ -1417,7 +1417,7 @@ bool DoDeath(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoDeath: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.AnimInfo.CurrentFrame == player.AnimInfo.NumberOfFrames - 1) {
if (player.AnimInfo.TickCounterOfCurrentFrame == 0) {
@ -1450,7 +1450,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("CheckNewPath: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
int x = 0;
int y = 0;
@ -1774,7 +1774,7 @@ bool PlrDeathModeOK(int p)
if ((DWORD)p >= MAX_PLRS) {
app_fatal("PlrDeathModeOK: illegal player %i", p);
}
auto &player = Players[p];
Player &player = Players[p];
if (player._pmode == PM_DEATH) {
return true;
@ -1794,7 +1794,7 @@ void ValidatePlayer()
if ((DWORD)MyPlayerId >= MAX_PLRS) {
app_fatal("ValidatePlayer: illegal player %i", MyPlayerId);
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pLevel > MAXCHARLEVEL)
myPlayer._pLevel = MAXCHARLEVEL;
@ -2509,7 +2509,7 @@ void CreatePlayer(int playerId, HeroClass c)
if ((DWORD)playerId >= MAX_PLRS) {
app_fatal("CreatePlayer: illegal player %i", playerId);
}
auto &player = Players[playerId];
Player &player = Players[playerId];
player.Reset();
SetRndSeed(SDL_GetTicks());
@ -2666,7 +2666,7 @@ void NextPlrLevel(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("NextPlrLevel: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pLevel++;
player._pMaxLvl++;
@ -2725,7 +2725,7 @@ void AddPlrExperience(int pnum, int lvl, int exp)
if (pnum >= MAX_PLRS || pnum < 0) {
app_fatal("AddPlrExperience: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pHitPoints <= 0) {
return;
@ -2789,7 +2789,7 @@ void AddPlrMonstExper(int lvl, int exp, char pmask)
void InitPlayer(Player &player, bool firstTime)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (firstTime) {
player._pRSplType = RSPLTYPE_INVALID;
@ -2879,7 +2879,7 @@ void InitMultiView()
if ((DWORD)MyPlayerId >= MAX_PLRS) {
app_fatal("InitPlayer: illegal player %i", MyPlayerId);
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
ViewPosition = myPlayer.position.tile;
}
@ -2919,7 +2919,7 @@ void FixPlayerLocation(int pnum, Direction bDir)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("FixPlayerLocation: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
player.position.future = player.position.tile;
player.position.offset = { 0, 0 };
@ -2938,7 +2938,7 @@ void StartStand(int pnum, Direction dir)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartStand: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -2958,7 +2958,7 @@ void StartPlrBlock(int pnum, Direction dir)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartPlrBlock: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -2984,7 +2984,7 @@ void FixPlrWalkTags(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("FixPlrWalkTags: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
int pp = pnum + 1;
int pn = -(pnum + 1);
@ -3016,7 +3016,7 @@ void StartPlrHit(int pnum, int dam, bool forcehit)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartPlrHit: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
@ -3068,7 +3068,7 @@ StartPlayerKill(int pnum, int earflag)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartPlayerKill: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pHitPoints <= 0 && player._pmode == PM_DEATH) {
return;
@ -3184,7 +3184,7 @@ void StripTopGold(Player &player)
void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int earflag /*= 0*/)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
int totalDamage = (dam << 6) + frac;
if (totalDamage > 0 && player.pManaShield) {
@ -3231,7 +3231,7 @@ void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int
void SyncPlrKill(int pnum, int earflag)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player._pHitPoints <= 0 && currlevel == 0) {
SetPlayerHitPoints(player, 64);
@ -3275,8 +3275,8 @@ StartNewLvl(int pnum, interface_mode fom, int lvl)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartNewLvl: illegal player %i", pnum);
}
auto &player = Players[pnum];
auto &myPlayer = Players[MyPlayerId];
Player &player = Players[pnum];
Player &myPlayer = *MyPlayer;
switch (fom) {
case WM_DIABNEXTLVL:
@ -3314,7 +3314,7 @@ void RestartTownLvl(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("RestartTownLvl: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
player.plrlevel = 0;
player._pInvincible = false;
@ -3335,7 +3335,7 @@ void RestartTownLvl(int pnum)
void StartWarpLvl(int pnum, int pidx)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
InitLevelChange(pnum);
@ -3360,7 +3360,7 @@ void ProcessPlayers()
if ((DWORD)MyPlayerId >= MAX_PLRS) {
app_fatal("ProcessPlayers: illegal player %i", MyPlayerId);
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer.pLvlLoad > 0) {
myPlayer.pLvlLoad--;
@ -3391,7 +3391,7 @@ void ProcessPlayers()
ValidatePlayer();
for (int pnum = 0; pnum < MAX_PLRS; pnum++) {
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.plractive && currlevel == player.plrlevel && (pnum == MyPlayerId || !player._pLvlChanging)) {
CheckCheatStats(player);
@ -3530,7 +3530,7 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType)
if ((DWORD)MyPlayerId >= MAX_PLRS) {
app_fatal("CheckPlrSpell: illegal player %i", MyPlayerId);
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (spellID == SPL_INVALID) {
myPlayer.Say(HeroSpeech::IDontHaveASpellReady);
@ -3621,7 +3621,7 @@ void SyncPlrAnim(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("SyncPlrAnim: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
player_graphic graphic;
switch (player._pmode) {
@ -3675,7 +3675,7 @@ void SyncPlrAnim(int pnum)
void SyncInitPlrPos(int pnum)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
if (!gbIsMultiplayer || player.plrlevel != currlevel) {
return;
@ -3713,7 +3713,7 @@ void SyncInitPlr(int pnum)
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("SyncInitPlr: illegal player %i", pnum);
}
auto &player = Players[pnum];
Player &player = Players[pnum];
SetPlrAnims(player);
SyncInitPlrPos(pnum);
@ -3747,7 +3747,7 @@ void ModifyPlrStr(int p, int l)
if ((DWORD)p >= MAX_PLRS) {
app_fatal("ModifyPlrStr: illegal player %i", p);
}
auto &player = Players[p];
Player &player = Players[p];
l = clamp(l, 0 - player._pBaseStr, player.GetMaximumAttributeValue(CharacterAttribute::Strength) - player._pBaseStr);
@ -3766,7 +3766,7 @@ void ModifyPlrMag(int p, int l)
if ((DWORD)p >= MAX_PLRS) {
app_fatal("ModifyPlrMag: illegal player %i", p);
}
auto &player = Players[p];
Player &player = Players[p];
l = clamp(l, 0 - player._pBaseStr, player.GetMaximumAttributeValue(CharacterAttribute::Magic) - player._pBaseMag);
@ -3799,7 +3799,7 @@ void ModifyPlrDex(int p, int l)
if ((DWORD)p >= MAX_PLRS) {
app_fatal("ModifyPlrDex: illegal player %i", p);
}
auto &player = Players[p];
Player &player = Players[p];
l = clamp(l, 0 - player._pBaseDex, player.GetMaximumAttributeValue(CharacterAttribute::Dexterity) - player._pBaseDex);
@ -3817,7 +3817,7 @@ void ModifyPlrVit(int p, int l)
if ((DWORD)p >= MAX_PLRS) {
app_fatal("ModifyPlrVit: illegal player %i", p);
}
auto &player = Players[p];
Player &player = Players[p];
l = clamp(l, 0 - player._pBaseVit, player.GetMaximumAttributeValue(CharacterAttribute::Vitality) - player._pBaseVit);
@ -3846,7 +3846,7 @@ void SetPlayerHitPoints(Player &player, int val)
player._pHitPoints = val;
player._pHPBase = val + player._pMaxHPBase - player._pMaxHP;
if (&player == &Players[MyPlayerId]) {
if (&player == MyPlayer) {
drawhpflag = true;
}
}
@ -3914,7 +3914,7 @@ void PlayDungMsgs()
if ((DWORD)MyPlayerId >= MAX_PLRS) {
app_fatal("PlayDungMsgs: illegal player %i", MyPlayerId);
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (currlevel == 1 && !myPlayer._pLvlVisited[1] && (myPlayer.pDungMsgs & DungMsgCathedral) == 0) {
myPlayer.Say(HeroSpeech::TheSanctityOfThisPlaceHasBeenFouled, 40);

6
Source/portal.cpp

@ -134,7 +134,7 @@ void GetPortalLevel()
if (currlevel != 0) {
setlevel = false;
currlevel = 0;
Players[MyPlayerId].plrlevel = 0;
MyPlayer->plrlevel = 0;
leveltype = DTYPE_TOWN;
return;
}
@ -143,12 +143,12 @@ void GetPortalLevel()
setlevel = true;
setlvlnum = (_setlevels)Portals[portalindex].level;
currlevel = Portals[portalindex].level;
Players[MyPlayerId].plrlevel = setlvlnum;
MyPlayer->plrlevel = setlvlnum;
leveltype = Portals[portalindex].ltype;
} else {
setlevel = false;
currlevel = Portals[portalindex].level;
Players[MyPlayerId].plrlevel = currlevel;
MyPlayer->plrlevel = currlevel;
leveltype = Portals[portalindex].ltype;
}

8
Source/qol/autopickup.cpp

@ -14,7 +14,7 @@ namespace {
bool HasRoomForGold()
{
for (int idx : Players[MyPlayerId].InvGrid) {
for (int idx : MyPlayer->InvGrid) {
// Secondary item cell. No need to check those as we'll go through the main item cells anyway.
if (idx < 0)
continue;
@ -24,7 +24,7 @@ bool HasRoomForGold()
return true;
// Main item cell. Potentially a gold pile so check it.
auto item = Players[MyPlayerId].InvList[idx - 1];
auto item = MyPlayer->InvList[idx - 1];
if (item._itype == ItemType::Gold && item._ivalue < MaxGold)
return true;
}
@ -34,7 +34,7 @@ bool HasRoomForGold()
int NumMiscItemsInInv(int iMiscId)
{
InventoryAndBeltPlayerItemsRange items { Players[MyPlayerId] };
InventoryAndBeltPlayerItemsRange items { *MyPlayer };
return std::count_if(items.begin(), items.end(), [iMiscId](const Item &item) { return item._iMiscId == iMiscId; });
}
@ -44,7 +44,7 @@ bool DoPickup(Item item)
return true;
if (item._itype == ItemType::Misc
&& (AutoPlaceItemInInventory(Players[MyPlayerId], item, false) || AutoPlaceItemInBelt(Players[MyPlayerId], item, false))) {
&& (AutoPlaceItemInInventory(*MyPlayer, item, false) || AutoPlaceItemInBelt(*MyPlayer, item, false))) {
switch (item._iMiscId) {
case IMISC_HEAL:
return *sgOptions.Gameplay.numHealPotionPickup > NumMiscItemsInInv(item._iMiscId);

2
Source/qol/chatlog.cpp

@ -125,7 +125,7 @@ void AddMessageToChatLog(const std::string &message, Player *player, UiFlags fla
} else {
std::string playerInfo = fmt::format(_("{:s} (lvl {:d}): "), player->_pName, player->_pLevel);
ChatLogLines.emplace_back(MultiColoredText { message, { {} }, 20 });
UiFlags nameColor = player == &Players[MyPlayerId] ? UiFlags::ColorWhitegold : UiFlags::ColorBlue;
UiFlags nameColor = player == MyPlayer ? UiFlags::ColorWhitegold : UiFlags::ColorBlue;
ChatLogLines.emplace_back(MultiColoredText { "{0} - {1}", { { timestamp, UiFlags::ColorRed }, { playerInfo, nameColor } } });
}

6
Source/qol/stash.cpp

@ -76,7 +76,7 @@ Point FindSlotUnderCursor(Point cursorPosition)
void CheckStashPaste(Point cursorPosition)
{
auto &player = Players[MyPlayerId];
Player &player = *MyPlayer;
const Size itemSize = GetInventorySize(player.HoldItem);
const Displacement hotPixelOffset = Displacement(itemSize * INV_SLOT_HALF_SIZE_PX);
@ -154,7 +154,7 @@ void CheckStashPaste(Point cursorPosition)
void CheckStashCut(Point cursorPosition, bool automaticMove)
{
auto &player = Players[MyPlayerId];
Player &player = *MyPlayer;
if (IsWithdrawGoldOpen) {
IsWithdrawGoldOpen = false;
@ -585,7 +585,7 @@ void StartGoldWithdraw()
void WithdrawGoldKeyPress(char vkey)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pHitPoints >> 6 <= 0) {
CloseGoldWithdraw();

4
Source/qol/xpbar.cpp

@ -91,7 +91,7 @@ void DrawXPBar(const Surface &out)
if (!*sgOptions.Gameplay.experienceBar || talkflag)
return;
const auto &player = Players[MyPlayerId];
const Player &player = *MyPlayer;
const Rectangle &mainPanel = GetMainPanel();
const Point back = { mainPanel.position.x + mainPanel.size.width / 2 - 155, mainPanel.position.y + mainPanel.size.height - 11 };
@ -141,7 +141,7 @@ bool CheckXPBarInfo()
if (MousePosition.x < backX || MousePosition.x >= backX + BackWidth || MousePosition.y < backY || MousePosition.y >= backY + BackHeight)
return false;
const auto &player = Players[MyPlayerId];
const Player &player = *MyPlayer;
const int8_t charLevel = player._pLevel;

8
Source/quests.cpp

@ -414,17 +414,17 @@ void CheckQuests()
&& ActiveMonsterCount == 4
&& Quests[Q_PWATER]._qactive != QUEST_DONE) {
Quests[Q_PWATER]._qactive = QUEST_DONE;
PlaySfxLoc(IS_QUESTDN, Players[MyPlayerId].position.tile);
PlaySfxLoc(IS_QUESTDN, MyPlayer->position.tile);
LoadPalette("Levels\\L3Data\\L3pwater.pal", false);
UpdatePWaterPalette();
WaterDone = 32;
}
} else if (Players[MyPlayerId]._pmode == PM_STAND) {
} else if (MyPlayer->_pmode == PM_STAND) {
for (auto &quest : Quests) {
if (currlevel == quest._qlevel
&& quest._qslvl != 0
&& quest._qactive != QUEST_NOTAVAIL
&& Players[MyPlayerId].position.tile == quest.position) {
&& MyPlayer->position.tile == quest.position) {
if (quest._qlvltype != DTYPE_NONE) {
setlvltype = quest._qlvltype;
}
@ -463,7 +463,7 @@ void CheckQuestKill(const Monster &monster, bool sendmsg)
if (gbIsSpawn)
return;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (monster.MType->mtype == MT_SKING) {
auto &quest = Quests[Q_SKELKING];

20
Source/scrollrt.cpp

@ -254,7 +254,7 @@ bool ShouldShowCursor()
return true;
if (invflag)
return true;
if (chrflag && Players[MyPlayerId]._pStatPts > 0)
if (chrflag && MyPlayer->_pStatPts > 0)
return true;
return false;
@ -448,7 +448,7 @@ void DrawMonster(const Surface &out, Point tilePosition, Point targetBufferPosit
trn = monster.uniqueTRN.get();
if (monster._mmode == MonsterMode::Petrified)
trn = GetStoneTRN();
if (Players[MyPlayerId]._pInfraFlag && LightTableIndex > 8)
if (MyPlayer->_pInfraFlag && LightTableIndex > 8)
trn = GetInfravisionTRN();
if (trn != nullptr)
Cl2DrawTRN(out, targetBufferPosition.x, targetBufferPosition.y, cel, nCel, trn);
@ -487,7 +487,7 @@ void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_id missi
*/
void DrawPlayerIcons(const Surface &out, int pnum, Point position, bool lighting)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
if (player.pManaShield)
DrawPlayerIconHelper(out, pnum, MFILE_MANASHLD, position, lighting);
if (player.wReflections > 0)
@ -506,11 +506,11 @@ void DrawPlayerIcons(const Surface &out, int pnum, Point position, bool lighting
*/
void DrawPlayer(const Surface &out, int pnum, Point tilePosition, Point targetBufferPosition)
{
if (!IsTileLit(tilePosition) && !Players[MyPlayerId]._pInfraFlag && leveltype != DTYPE_TOWN) {
if (!IsTileLit(tilePosition) && !MyPlayer->_pInfraFlag && leveltype != DTYPE_TOWN) {
return;
}
auto &player = Players[pnum];
Player &player = Players[pnum];
std::optional<CelSprite> sprite = player.AnimInfo.celSprite;
int nCel = player.AnimInfo.GetFrameToUseForRendering();
@ -552,7 +552,7 @@ void DrawPlayer(const Surface &out, int pnum, Point tilePosition, Point targetBu
return;
}
if (!IsTileLit(tilePosition) || (Players[MyPlayerId]._pInfraFlag && LightTableIndex > 8)) {
if (!IsTileLit(tilePosition) || (MyPlayer->_pInfraFlag && LightTableIndex > 8)) {
Cl2DrawTRN(out, spriteBufferPosition.x, spriteBufferPosition.y, *sprite, nCel, GetInfravisionTRN());
DrawPlayerIcons(out, pnum, targetBufferPosition, true);
return;
@ -581,7 +581,7 @@ void DrawDeadPlayer(const Surface &out, Point tilePosition, Point targetBufferPo
dFlags[tilePosition.x][tilePosition.y] &= ~DungeonFlag::DeadPlayer;
for (int i = 0; i < MAX_PLRS; i++) {
auto &player = Players[i];
Player &player = Players[i];
if (player.plractive && player._pHitPoints == 0 && player.plrlevel == (BYTE)currlevel && player.position.tile == tilePosition) {
dFlags[tilePosition.x][tilePosition.y] |= DungeonFlag::DeadPlayer;
const Point playerRenderPosition { targetBufferPosition + player.position.offset };
@ -761,7 +761,7 @@ void DrawMonsterHelper(const Surface &out, Point tilePosition, Point targetBuffe
return;
}
if (!IsTileLit(tilePosition) && !Players[MyPlayerId]._pInfraFlag)
if (!IsTileLit(tilePosition) && !MyPlayer->_pInfraFlag)
return;
if (mi < 0 || mi >= MAXMONSTERS) {
@ -807,7 +807,7 @@ void DrawPlayerHelper(const Surface &out, Point tilePosition, Point targetBuffer
Log("draw player: tried to draw illegal player {}", p);
return;
}
auto &player = Players[p];
Player &player = Players[p];
Displacement offset = player.position.offset;
if (player.IsWalking()) {
@ -1091,7 +1091,7 @@ void DrawGame(const Surface &fullOut, Point position)
: fullOut.subregionY(0, (gnViewportHeight + 1) / 2);
// Adjust by player offset and tile grid alignment
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
Displacement offset = ScrollInfo.offset;
if (myPlayer.IsWalking())
offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);

6
Source/spells.cpp

@ -66,7 +66,7 @@ void ClearReadiedSpell(Player &player)
void PlacePlayer(int pnum)
{
auto &player = Players[pnum];
Player &player = Players[pnum];
Point newPosition = {};
if (player.plrlevel == currlevel) {
@ -174,7 +174,7 @@ void UseMana(int id, spell_id sn)
if (id != MyPlayerId)
return;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
switch (myPlayer._pSplType) {
case RSPLTYPE_SKILL:
@ -225,7 +225,7 @@ SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly)
return SpellCheckResult::Fail_Level0;
}
auto &player = Players[id];
Player &player = Players[id];
if (player._pMana < GetManaAmount(player, sn)) {
return SpellCheckResult::Fail_NoMana;
}

48
Source/stores.cpp

@ -297,17 +297,17 @@ void PrintStoreItem(const Item &item, int l, UiFlags flags)
bool StoreAutoPlace(Item &item, bool persistItem)
{
auto &myPlayer = Players[MyPlayerId];
Player &player = *MyPlayer;
if (AutoEquipEnabled(myPlayer, item) && AutoEquip(MyPlayerId, item, persistItem)) {
if (AutoEquipEnabled(player, item) && AutoEquip(MyPlayerId, item, persistItem)) {
return true;
}
if (AutoPlaceItemInBelt(myPlayer, item, persistItem)) {
if (AutoPlaceItemInBelt(player, item, persistItem)) {
return true;
}
return AutoPlaceItemInInventory(myPlayer, item, persistItem);
return AutoPlaceItemInInventory(player, item, persistItem);
}
void StartSmith()
@ -452,9 +452,9 @@ bool SmithSellOk(int i)
Item *pI;
if (i >= 0) {
pI = &Players[MyPlayerId].InvList[i];
pI = &MyPlayer->InvList[i];
} else {
pI = &Players[MyPlayerId].SpdList[-(i + 1)];
pI = &MyPlayer->SpdList[-(i + 1)];
}
if (pI->isEmpty())
@ -515,7 +515,7 @@ void StartSmithSell()
item.clear();
}
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
for (int8_t i = 0; i < myPlayer._pNumInv; i++) {
if (storenumh >= 48)
@ -574,7 +574,7 @@ void StartSmithSell()
bool SmithRepairOk(int i)
{
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
if (myPlayer.InvList[i].isEmpty())
return false;
@ -597,7 +597,7 @@ void StartSmithRepair()
item.clear();
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
auto &helmet = myPlayer.InvBody[INVLOC_HEAD];
if (!helmet.isEmpty() && helmet._iDurability != helmet._iMaxDur) {
@ -654,7 +654,7 @@ void FillManaPlayer()
if (!*sgOptions.Gameplay.adriaRefillsMana)
return;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pMana != myPlayer._pMaxMana) {
PlaySFX(IS_CAST8);
@ -711,7 +711,7 @@ void WitchBookLevel(Item &bookItem)
if (bookItem._iMiscId != IMISC_BOOK)
return;
bookItem._iMinMag = spelldata[bookItem._iSpell].sMinInt;
int8_t spellLevel = Players[MyPlayerId]._pSplLvl[bookItem._iSpell];
int8_t spellLevel = MyPlayer->_pSplLvl[bookItem._iSpell];
while (spellLevel > 0) {
bookItem._iMinMag += 20 * bookItem._iMinMag / 100;
spellLevel--;
@ -754,9 +754,9 @@ bool WitchSellOk(int i)
bool rv = false;
if (i >= 0)
pI = &Players[MyPlayerId].InvList[i];
pI = &MyPlayer->InvList[i];
else
pI = &Players[MyPlayerId].SpdList[-(i + 1)];
pI = &MyPlayer->SpdList[-(i + 1)];
if (pI->_itype == ItemType::Misc)
rv = true;
@ -783,7 +783,7 @@ void StartWitchSell()
item.clear();
}
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
for (int i = 0; i < myPlayer._pNumInv; i++) {
if (storenumh >= 48)
@ -843,7 +843,7 @@ void StartWitchSell()
bool WitchRechargeOk(int i)
{
const auto &item = Players[MyPlayerId].InvList[i];
const auto &item = MyPlayer->InvList[i];
if (item._itype == ItemType::Staff && item._iCharges != item._iMaxCharges) {
return true;
@ -876,7 +876,7 @@ void StartWitchRecharge()
item.clear();
}
const auto &myPlayer = Players[MyPlayerId];
const Player &myPlayer = *MyPlayer;
const auto &leftHand = myPlayer.InvBody[INVLOC_HAND_LEFT];
if ((leftHand._itype == ItemType::Staff || leftHand._iMiscId == IMISC_UNIQUE) && leftHand._iCharges != leftHand._iMaxCharges) {
@ -1049,7 +1049,7 @@ void SStartBoyBuy()
void HealPlayer()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pHitPoints != myPlayer._pMaxHP) {
PlaySFX(IS_CAST8);
@ -1161,7 +1161,7 @@ void StartStorytellerIdentify()
item.clear();
}
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
auto &helmet = myPlayer.InvBody[INVLOC_HEAD];
if (IdItemOk(&helmet)) {
@ -1487,7 +1487,7 @@ bool StoreGoldFit(Item &item)
*/
void StoreSellItem()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int idx = stextvhold + ((stextlhold - stextup) / 4);
if (storehidx[idx] >= 0)
@ -1545,7 +1545,7 @@ void SmithRepairItem(int price)
int8_t i = storehidx[idx];
auto &myPlayer = *MyPlayer;
Player &myPlayer = *MyPlayer;
if (i < 0) {
if (i == -1)
@ -1699,7 +1699,7 @@ void WitchRechargeItem(int price)
int idx = stextvhold + ((stextlhold - stextup) / 4);
storehold[idx]._iCharges = storehold[idx]._iMaxCharges;
auto &myPlayer = *MyPlayer;
Player &myPlayer = *MyPlayer;
int8_t i = storehidx[idx];
if (i < 0)
@ -1842,7 +1842,7 @@ void BoyBuyEnter()
void StorytellerIdentifyItem(Item &item)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int8_t idx = storehidx[((stextlhold - stextup) / 4) + stextvhold];
if (idx < 0) {
@ -2191,7 +2191,7 @@ void InitStores()
void SetupTownStores()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
int l = myPlayer._pLevel / 2;
if (!gbIsMultiplayer) {
@ -2623,7 +2623,7 @@ void StoreNext()
void TakePlrsMoney(int cost)
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
myPlayer._pGold -= std::min(cost, myPlayer._pGold);

6
Source/sync.cpp

@ -24,7 +24,7 @@ void SyncOneMonster()
for (int i = 0; i < ActiveMonsterCount; i++) {
int m = ActiveMonsters[i];
auto &monster = Monsters[m];
sgnMonsterPriority[m] = Players[MyPlayerId].position.tile.ManhattanDistance(monster.position.tile);
sgnMonsterPriority[m] = MyPlayer->position.tile.ManhattanDistance(monster.position.tile);
if (monster._msquelch == 0) {
sgnMonsterPriority[m] += 0x1000;
} else if (sgwLRU[m] != 0) {
@ -133,7 +133,7 @@ void SyncPlrInv(TSyncHeader *pHdr)
pHdr->bPInvLoc = -1;
assert(sgnSyncPInv > -1 && sgnSyncPInv < NUM_INVLOC);
const auto &item = Players[MyPlayerId].InvBody[sgnSyncPInv];
const auto &item = MyPlayer->InvBody[sgnSyncPInv];
if (!item.isEmpty()) {
pHdr->bPInvLoc = sgnSyncPInv;
pHdr->wPInvIndx = item.IDidx;
@ -160,7 +160,7 @@ void SyncMonster(int pnum, const TSyncMonster &monsterSync)
const int enemyId = monsterSync._menemy;
if (monster._msquelch != 0) {
uint32_t delta = Players[MyPlayerId].position.tile.ManhattanDistance(monster.position.tile);
uint32_t delta = MyPlayer->position.tile.ManhattanDistance(monster.position.tile);
if (delta > 255) {
delta = 255;
}

2
Source/towners.cpp

@ -888,7 +888,7 @@ bool DebugTalkToTowner(std::string targetName)
{
SetupTownStores();
std::transform(targetName.begin(), targetName.end(), targetName.begin(), [](unsigned char c) { return std::tolower(c); });
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
for (auto &townerData : TownersData) {
if (!IsTownerPresent(townerData.type))
continue;

2
Source/track.cpp

@ -74,7 +74,7 @@ void RepeatMouseAction()
if (LastMouseButtonAction == MouseActionType::None)
return;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer.destAction != ACTION_NONE)
return;
if (myPlayer._pInvincible)

4
Source/trigs.cpp

@ -73,7 +73,7 @@ bool IsWarpOpen(dungeon_type type)
if (gbIsMultiplayer && type != DTYPE_NEST) // Opening the nest is part of in town quest
return true;
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (type == DTYPE_CATACOMBS && (myPlayer.pTownWarps & 1) != 0)
return true;
@ -803,7 +803,7 @@ void CheckTrigForce()
void CheckTriggers()
{
auto &myPlayer = Players[MyPlayerId];
Player &myPlayer = *MyPlayer;
if (myPlayer._pmode != PM_STAND)
return;

10
test/effects_test.cpp

@ -7,7 +7,7 @@ using namespace devilution;
TEST(Effects, CalculateSoundPosition_center)
{
Players[MyPlayerId].position.tile = { 50, 50 };
MyPlayer->position.tile = { 50, 50 };
int plVolume = 0;
int plPan = 0;
EXPECT_EQ(CalculateSoundPosition({ 50, 50 }, &plVolume, &plPan), true);
@ -17,7 +17,7 @@ TEST(Effects, CalculateSoundPosition_center)
TEST(Effects, CalculateSoundPosition_near)
{
Players[MyPlayerId].position.tile = { 50, 50 };
MyPlayer->position.tile = { 50, 50 };
int plVolume = 0;
int plPan = 0;
EXPECT_EQ(CalculateSoundPosition({ 55, 50 }, &plVolume, &plPan), true);
@ -27,7 +27,7 @@ TEST(Effects, CalculateSoundPosition_near)
TEST(Effects, CalculateSoundPosition_out_of_range)
{
Players[MyPlayerId].position.tile = { 12, 12 };
MyPlayer->position.tile = { 12, 12 };
int plVolume = 1234;
int plPan = 0;
EXPECT_EQ(CalculateSoundPosition({ 112, 112 }, &plVolume, &plPan), false);
@ -37,7 +37,7 @@ TEST(Effects, CalculateSoundPosition_out_of_range)
TEST(Effects, CalculateSoundPosition_extreme_right)
{
Players[MyPlayerId].position.tile = { 50, 50 };
MyPlayer->position.tile = { 50, 50 };
int plVolume = 0;
int plPan = 0;
EXPECT_EQ(CalculateSoundPosition({ 75, 25 }, &plVolume, &plPan), true);
@ -47,7 +47,7 @@ TEST(Effects, CalculateSoundPosition_extreme_right)
TEST(Effects, CalculateSoundPosition_extreme_left)
{
Players[MyPlayerId].position.tile = { 50, 50 };
MyPlayer->position.tile = { 50, 50 };
int plVolume = 0;
int plPan = 0;
EXPECT_EQ(CalculateSoundPosition({ 25, 75 }, &plVolume, &plPan), true);

196
test/inv_test.cpp

@ -11,7 +11,7 @@ void set_up_scroll(Item &item, spell_id spell)
{
pcurs = CURSOR_HAND;
leveltype = DTYPE_CATACOMBS;
Players[MyPlayerId]._pRSpell = static_cast<spell_id>(spell);
MyPlayer->_pRSpell = static_cast<spell_id>(spell);
item._itype = ItemType::Misc;
item._iMiscId = IMISC_SCROLL;
item._iSpell = spell;
@ -21,25 +21,25 @@ void set_up_scroll(Item &item, spell_id spell)
void clear_inventory()
{
for (int i = 0; i < NUM_INV_GRID_ELEM; i++) {
Players[MyPlayerId].InvList[i] = {};
Players[MyPlayerId].InvGrid[i] = 0;
MyPlayer->InvList[i] = {};
MyPlayer->InvGrid[i] = 0;
}
Players[MyPlayerId]._pNumInv = 0;
MyPlayer->_pNumInv = 0;
}
// Test that the scroll is used in the inventory in correct conditions
TEST(Inv, UseScroll_from_inventory)
{
set_up_scroll(Players[MyPlayerId].InvList[2], SPL_FIREBOLT);
Players[MyPlayerId]._pNumInv = 5;
EXPECT_TRUE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->InvList[2], SPL_FIREBOLT);
MyPlayer->_pNumInv = 5;
EXPECT_TRUE(UseScroll(MyPlayer->_pRSpell));
}
// Test that the scroll is used in the belt in correct conditions
TEST(Inv, UseScroll_from_belt)
{
set_up_scroll(Players[MyPlayerId].SpdList[2], SPL_FIREBOLT);
EXPECT_TRUE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->SpdList[2], SPL_FIREBOLT);
EXPECT_TRUE(UseScroll(MyPlayer->_pRSpell));
}
// Test that the scroll is not used in the inventory for each invalid condition
@ -47,73 +47,73 @@ TEST(Inv, UseScroll_from_inventory_invalid_conditions)
{
// Empty the belt to prevent using a scroll from the belt
for (int i = 0; i < MAXBELTITEMS; i++) {
Players[MyPlayerId].SpdList[i].clear();
MyPlayer->SpdList[i].clear();
}
set_up_scroll(Players[MyPlayerId].InvList[2], SPL_FIREBOLT);
set_up_scroll(MyPlayer->InvList[2], SPL_FIREBOLT);
pcurs = CURSOR_IDENTIFY;
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].InvList[2], SPL_FIREBOLT);
set_up_scroll(MyPlayer->InvList[2], SPL_FIREBOLT);
leveltype = DTYPE_TOWN;
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].InvList[2], SPL_FIREBOLT);
Players[MyPlayerId]._pRSpell = static_cast<spell_id>(SPL_HEAL);
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->InvList[2], SPL_FIREBOLT);
MyPlayer->_pRSpell = static_cast<spell_id>(SPL_HEAL);
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].InvList[2], SPL_FIREBOLT);
Players[MyPlayerId].InvList[2]._iMiscId = IMISC_STAFF;
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->InvList[2], SPL_FIREBOLT);
MyPlayer->InvList[2]._iMiscId = IMISC_STAFF;
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].InvList[2], SPL_FIREBOLT);
Players[MyPlayerId].InvList[2].clear();
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->InvList[2], SPL_FIREBOLT);
MyPlayer->InvList[2].clear();
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
}
// Test that the scroll is not used in the belt for each invalid condition
TEST(Inv, UseScroll_from_belt_invalid_conditions)
{
// Disable the inventory to prevent using a scroll from the inventory
Players[MyPlayerId]._pNumInv = 0;
MyPlayer->_pNumInv = 0;
set_up_scroll(Players[MyPlayerId].SpdList[2], SPL_FIREBOLT);
set_up_scroll(MyPlayer->SpdList[2], SPL_FIREBOLT);
pcurs = CURSOR_IDENTIFY;
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].SpdList[2], SPL_FIREBOLT);
set_up_scroll(MyPlayer->SpdList[2], SPL_FIREBOLT);
leveltype = DTYPE_TOWN;
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].SpdList[2], SPL_FIREBOLT);
Players[MyPlayerId]._pRSpell = static_cast<spell_id>(SPL_HEAL);
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->SpdList[2], SPL_FIREBOLT);
MyPlayer->_pRSpell = static_cast<spell_id>(SPL_HEAL);
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].SpdList[2], SPL_FIREBOLT);
Players[MyPlayerId].SpdList[2]._iMiscId = IMISC_STAFF;
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->SpdList[2], SPL_FIREBOLT);
MyPlayer->SpdList[2]._iMiscId = IMISC_STAFF;
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
set_up_scroll(Players[MyPlayerId].SpdList[2], SPL_FIREBOLT);
Players[MyPlayerId].SpdList[2].clear();
EXPECT_FALSE(UseScroll(Players[MyPlayerId]._pRSpell));
set_up_scroll(MyPlayer->SpdList[2], SPL_FIREBOLT);
MyPlayer->SpdList[2].clear();
EXPECT_FALSE(UseScroll(MyPlayer->_pRSpell));
}
// Test gold calculation
TEST(Inv, CalculateGold)
{
Players[MyPlayerId]._pNumInv = 10;
MyPlayer->_pNumInv = 10;
// Set up 4 slots of gold in the inventory
Players[MyPlayerId].InvList[1]._itype = ItemType::Gold;
Players[MyPlayerId].InvList[5]._itype = ItemType::Gold;
Players[MyPlayerId].InvList[2]._itype = ItemType::Gold;
Players[MyPlayerId].InvList[3]._itype = ItemType::Gold;
MyPlayer->InvList[1]._itype = ItemType::Gold;
MyPlayer->InvList[5]._itype = ItemType::Gold;
MyPlayer->InvList[2]._itype = ItemType::Gold;
MyPlayer->InvList[3]._itype = ItemType::Gold;
// Set the gold amount to arbitrary values
Players[MyPlayerId].InvList[1]._ivalue = 100;
Players[MyPlayerId].InvList[5]._ivalue = 200;
Players[MyPlayerId].InvList[2]._ivalue = 3;
Players[MyPlayerId].InvList[3]._ivalue = 30;
MyPlayer->InvList[1]._ivalue = 100;
MyPlayer->InvList[5]._ivalue = 200;
MyPlayer->InvList[2]._ivalue = 3;
MyPlayer->InvList[3]._ivalue = 30;
EXPECT_EQ(CalculateGold(Players[MyPlayerId]), 333);
EXPECT_EQ(CalculateGold(*MyPlayer), 333);
}
// Test automatic gold placing
@ -124,18 +124,18 @@ TEST(Inv, GoldAutoPlace)
// Put gold into the inventory:
// | 1000 | ... | ...
Players[MyPlayerId].InvList[0]._itype = ItemType::Gold;
Players[MyPlayerId].InvList[0]._ivalue = 1000;
Players[MyPlayerId]._pNumInv = 1;
MyPlayer->InvList[0]._itype = ItemType::Gold;
MyPlayer->InvList[0]._ivalue = 1000;
MyPlayer->_pNumInv = 1;
// Put (max gold - 100) gold, which is 4900, into the player's hand
Players[MyPlayerId].HoldItem._itype = ItemType::Gold;
Players[MyPlayerId].HoldItem._ivalue = GOLD_MAX_LIMIT - 100;
MyPlayer->HoldItem._itype = ItemType::Gold;
MyPlayer->HoldItem._ivalue = GOLD_MAX_LIMIT - 100;
GoldAutoPlace(Players[MyPlayerId], Players[MyPlayerId].HoldItem);
GoldAutoPlace(*MyPlayer, MyPlayer->HoldItem);
// We expect the inventory:
// | 5000 | 900 | ...
EXPECT_EQ(Players[MyPlayerId].InvList[0]._ivalue, GOLD_MAX_LIMIT);
EXPECT_EQ(Players[MyPlayerId].InvList[1]._ivalue, 900);
EXPECT_EQ(MyPlayer->InvList[0]._ivalue, GOLD_MAX_LIMIT);
EXPECT_EQ(MyPlayer->InvList[1]._ivalue, 900);
}
// Test removing an item from inventory with no other items.
@ -144,15 +144,15 @@ TEST(Inv, RemoveInvItem)
clear_inventory();
// Put a two-slot misc item into the inventory:
// | (item) | (item) | ... | ...
Players[MyPlayerId]._pNumInv = 1;
Players[MyPlayerId].InvGrid[0] = 1;
Players[MyPlayerId].InvGrid[1] = -1;
Players[MyPlayerId].InvList[0]._itype = ItemType::Misc;
Players[MyPlayerId].RemoveInvItem(0);
EXPECT_EQ(Players[MyPlayerId].InvGrid[0], 0);
EXPECT_EQ(Players[MyPlayerId].InvGrid[1], 0);
EXPECT_EQ(Players[MyPlayerId]._pNumInv, 0);
MyPlayer->_pNumInv = 1;
MyPlayer->InvGrid[0] = 1;
MyPlayer->InvGrid[1] = -1;
MyPlayer->InvList[0]._itype = ItemType::Misc;
MyPlayer->RemoveInvItem(0);
EXPECT_EQ(MyPlayer->InvGrid[0], 0);
EXPECT_EQ(MyPlayer->InvGrid[1], 0);
EXPECT_EQ(MyPlayer->_pNumInv, 0);
}
// Test removing an item from inventory with other items in it.
@ -161,20 +161,20 @@ TEST(Inv, RemoveInvItem_other_item)
clear_inventory();
// Put a two-slot misc item and a ring into the inventory:
// | (item) | (item) | (ring) | ...
Players[MyPlayerId]._pNumInv = 2;
Players[MyPlayerId].InvGrid[0] = 1;
Players[MyPlayerId].InvGrid[1] = -1;
Players[MyPlayerId].InvList[0]._itype = ItemType::Misc;
Players[MyPlayerId].InvGrid[2] = 2;
Players[MyPlayerId].InvList[1]._itype = ItemType::Ring;
Players[MyPlayerId].RemoveInvItem(0);
EXPECT_EQ(Players[MyPlayerId].InvGrid[0], 0);
EXPECT_EQ(Players[MyPlayerId].InvGrid[1], 0);
EXPECT_EQ(Players[MyPlayerId].InvGrid[2], 1);
EXPECT_EQ(Players[MyPlayerId].InvList[0]._itype, ItemType::Ring);
EXPECT_EQ(Players[MyPlayerId]._pNumInv, 1);
MyPlayer->_pNumInv = 2;
MyPlayer->InvGrid[0] = 1;
MyPlayer->InvGrid[1] = -1;
MyPlayer->InvList[0]._itype = ItemType::Misc;
MyPlayer->InvGrid[2] = 2;
MyPlayer->InvList[1]._itype = ItemType::Ring;
MyPlayer->RemoveInvItem(0);
EXPECT_EQ(MyPlayer->InvGrid[0], 0);
EXPECT_EQ(MyPlayer->InvGrid[1], 0);
EXPECT_EQ(MyPlayer->InvGrid[2], 1);
EXPECT_EQ(MyPlayer->InvList[0]._itype, ItemType::Ring);
EXPECT_EQ(MyPlayer->_pNumInv, 1);
}
// Test removing an item from the belt
@ -182,13 +182,13 @@ TEST(Inv, RemoveSpdBarItem)
{
// Clear the belt
for (int i = 0; i < MAXBELTITEMS; i++) {
Players[MyPlayerId].SpdList[i].clear();
MyPlayer->SpdList[i].clear();
}
// Put an item in the belt: | x | x | item | x | x | x | x | x |
Players[MyPlayerId].SpdList[3]._itype = ItemType::Misc;
MyPlayer->SpdList[3]._itype = ItemType::Misc;
Players[MyPlayerId].RemoveSpdBarItem(3);
EXPECT_TRUE(Players[MyPlayerId].SpdList[3].isEmpty());
MyPlayer->RemoveSpdBarItem(3);
EXPECT_TRUE(MyPlayer->SpdList[3].isEmpty());
}
// Test removing a scroll from the inventory
@ -197,15 +197,15 @@ TEST(Inv, RemoveScroll_inventory)
clear_inventory();
// Put a firebolt scroll into the inventory
Players[MyPlayerId]._pNumInv = 1;
Players[MyPlayerId]._pSpell = static_cast<spell_id>(SPL_FIREBOLT);
Players[MyPlayerId].InvList[0]._itype = ItemType::Misc;
Players[MyPlayerId].InvList[0]._iMiscId = IMISC_SCROLL;
Players[MyPlayerId].InvList[0]._iSpell = SPL_FIREBOLT;
RemoveScroll(Players[MyPlayerId]);
EXPECT_EQ(Players[MyPlayerId].InvGrid[0], 0);
EXPECT_EQ(Players[MyPlayerId]._pNumInv, 0);
MyPlayer->_pNumInv = 1;
MyPlayer->_pSpell = static_cast<spell_id>(SPL_FIREBOLT);
MyPlayer->InvList[0]._itype = ItemType::Misc;
MyPlayer->InvList[0]._iMiscId = IMISC_SCROLL;
MyPlayer->InvList[0]._iSpell = SPL_FIREBOLT;
RemoveScroll(*MyPlayer);
EXPECT_EQ(MyPlayer->InvGrid[0], 0);
EXPECT_EQ(MyPlayer->_pNumInv, 0);
}
// Test removing a scroll from the belt
@ -213,16 +213,16 @@ TEST(Inv, RemoveScroll_belt)
{
// Clear the belt
for (int i = 0; i < MAXBELTITEMS; i++) {
Players[MyPlayerId].SpdList[i].clear();
MyPlayer->SpdList[i].clear();
}
// Put a firebolt scroll into the belt
Players[MyPlayerId]._pSpell = static_cast<spell_id>(SPL_FIREBOLT);
Players[MyPlayerId].SpdList[3]._itype = ItemType::Misc;
Players[MyPlayerId].SpdList[3]._iMiscId = IMISC_SCROLL;
Players[MyPlayerId].SpdList[3]._iSpell = SPL_FIREBOLT;
MyPlayer->_pSpell = static_cast<spell_id>(SPL_FIREBOLT);
MyPlayer->SpdList[3]._itype = ItemType::Misc;
MyPlayer->SpdList[3]._iMiscId = IMISC_SCROLL;
MyPlayer->SpdList[3]._iSpell = SPL_FIREBOLT;
RemoveScroll(Players[MyPlayerId]);
EXPECT_TRUE(Players[MyPlayerId].SpdList[3].isEmpty());
RemoveScroll(*MyPlayer);
EXPECT_TRUE(MyPlayer->SpdList[3].isEmpty());
}
TEST(Inv, ItemSize)

16
test/pack_test.cpp

@ -341,8 +341,8 @@ TEST(PackTest, UnPackItem_diablo)
gbIsMultiplayer = false;
gbIsSpawn = false;
Players[MyPlayerId]._pMaxManaBase = 125 << 6;
Players[MyPlayerId]._pMaxHPBase = 125 << 6;
MyPlayer->_pMaxManaBase = 125 << 6;
MyPlayer->_pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedDiabloItems) / sizeof(*PackedDiabloItems); i++) {
UnPackItem(PackedDiabloItems[i], id, false);
@ -412,8 +412,8 @@ TEST(PackTest, UnPackItem_spawn)
gbIsMultiplayer = false;
gbIsSpawn = true;
Players[MyPlayerId]._pMaxManaBase = 125 << 6;
Players[MyPlayerId]._pMaxHPBase = 125 << 6;
MyPlayer->_pMaxManaBase = 125 << 6;
MyPlayer->_pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedSpawnItems) / sizeof(*PackedSpawnItems); i++) {
UnPackItem(PackedSpawnItems[i], id, false);
@ -456,8 +456,8 @@ TEST(PackTest, UnPackItem_diablo_multiplayer)
gbIsMultiplayer = true;
gbIsSpawn = false;
Players[MyPlayerId]._pMaxManaBase = 125 << 6;
Players[MyPlayerId]._pMaxHPBase = 125 << 6;
MyPlayer->_pMaxManaBase = 125 << 6;
MyPlayer->_pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedDiabloMPItems) / sizeof(*PackedDiabloMPItems); i++) {
UnPackItem(PackedDiabloMPItems[i], id, false);
@ -669,8 +669,8 @@ TEST(PackTest, UnPackItem_hellfire)
gbIsMultiplayer = false;
gbIsSpawn = false;
Players[MyPlayerId]._pMaxManaBase = 125 << 6;
Players[MyPlayerId]._pMaxHPBase = 125 << 6;
MyPlayer->_pMaxManaBase = 125 << 6;
MyPlayer->_pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedHellfireItems) / sizeof(*PackedHellfireItems); i++) {
UnPackItem(PackedHellfireItems[i], id, true);

2
test/player_test.cpp

@ -11,7 +11,7 @@ extern bool TestPlayerDoGotHit(int pnum);
int RunBlockTest(int frames, ItemSpecialEffect flags)
{
int pnum = 0;
auto &player = Players[pnum];
Player &player = Players[pnum];
player._pHFrames = frames;
player._pIFlags = flags;

4
test/writehero_test.cpp

@ -334,7 +334,7 @@ TEST(Writehero, pfile_write_hero)
giNumberOfLevels = 17;
MyPlayerId = 0;
MyPlayer = &Players[MyPlayerId];
MyPlayer = MyPlayer;
*MyPlayer = {};
_uiheroinfo info {};
@ -343,7 +343,7 @@ TEST(Writehero, pfile_write_hero)
pfile_ui_save_create(&info);
PlayerPack pks;
PackPlayerTest(&pks);
UnPackPlayer(&pks, Players[MyPlayerId], true);
UnPackPlayer(&pks, *MyPlayer, true);
AssertPlayer(Players[0]);
pfile_write_hero();

Loading…
Cancel
Save