Browse Source

Clean up some players references

pull/2752/head
Anders Jenbo 5 years ago
parent
commit
4044fadeb5
  1. 13
      Source/control.cpp
  2. 2
      Source/debug.cpp
  3. 21
      Source/diablo.cpp
  4. 18
      Source/inv.cpp
  5. 4
      Source/inv.h
  6. 82
      Source/items.cpp
  7. 19
      Source/items.h
  8. 43
      Source/loadsave.cpp
  9. 2
      Source/menu.cpp
  10. 15
      Source/missiles.cpp
  11. 16
      Source/msg.cpp
  12. 4
      Source/multi.cpp
  13. 2
      Source/objects.cpp
  14. 10
      Source/pack.cpp
  15. 2
      Source/pack.h
  16. 12
      Source/pfile.cpp
  17. 2
      Source/pfile.h
  18. 148
      Source/player.cpp
  19. 14
      Source/player.h
  20. 4
      Source/spells.cpp
  21. 23
      Source/stores.cpp
  22. 2
      test/writehero_test.cpp

13
Source/control.cpp

@ -571,10 +571,8 @@ void ControlUpDown(int v)
} }
} }
void RemoveGold(int pnum, int goldIndex) void RemoveGold(PlayerStruct &player, int goldIndex)
{ {
auto &player = Players[pnum];
int gi = goldIndex - INVITEM_INV_FIRST; int gi = goldIndex - INVITEM_INV_FIRST;
player.InvList[gi]._ivalue -= dropGoldValue; player.InvList[gi]._ivalue -= dropGoldValue;
if (player.InvList[gi]._ivalue > 0) if (player.InvList[gi]._ivalue > 0)
@ -582,7 +580,7 @@ void RemoveGold(int pnum, int goldIndex)
else else
player.RemoveInvItem(gi); player.RemoveInvItem(gi);
SetPlrHandItem(player.HoldItem, IDI_GOLD); SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem); SetGoldSeed(player, player.HoldItem);
player.HoldItem._ivalue = dropGoldValue; player.HoldItem._ivalue = dropGoldValue;
player.HoldItem._iStatFlag = true; player.HoldItem._iStatFlag = true;
ControlSetGoldCurs(player); ControlSetGoldCurs(player);
@ -1864,19 +1862,20 @@ void DrawGoldSplit(const Surface &out, int amount)
void control_drop_gold(char vkey) void control_drop_gold(char vkey)
{ {
char input[6]; auto &myPlayer = Players[MyPlayerId];
if (Players[MyPlayerId]._pHitPoints >> 6 <= 0) { if (myPlayer._pHitPoints >> 6 <= 0) {
dropGoldFlag = false; dropGoldFlag = false;
dropGoldValue = 0; dropGoldValue = 0;
return; return;
} }
char input[6];
memset(input, 0, sizeof(input)); memset(input, 0, sizeof(input));
snprintf(input, sizeof(input), "%i", dropGoldValue); snprintf(input, sizeof(input), "%i", dropGoldValue);
if (vkey == DVL_VK_RETURN) { if (vkey == DVL_VK_RETURN) {
if (dropGoldValue > 0) if (dropGoldValue > 0)
RemoveGold(MyPlayerId, initialDropGoldIndex); RemoveGold(myPlayer, initialDropGoldIndex);
dropGoldFlag = false; dropGoldFlag = false;
} else if (vkey == DVL_VK_ESCAPE) { } else if (vkey == DVL_VK_ESCAPE) {
dropGoldFlag = false; dropGoldFlag = false;

2
Source/debug.cpp

@ -129,7 +129,7 @@ std::string DebugCmdGiveGoldCheat(const string_view parameter)
myPlayer._pGold += GOLD_MAX_LIMIT; myPlayer._pGold += GOLD_MAX_LIMIT;
itemId = myPlayer._pNumInv; itemId = myPlayer._pNumInv;
} }
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
return "You are now rich! If only this was as easy in real life..."; return "You are now rich! If only this was as easy in real life...";
} }

21
Source/diablo.cpp

@ -1615,9 +1615,11 @@ bool TryIconCurs()
return true; return true;
} }
auto &myPlayer = Players[MyPlayerId];
if (pcurs == CURSOR_IDENTIFY) { if (pcurs == CURSOR_IDENTIFY) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
CheckIdentify(MyPlayerId, pcursinvitem); CheckIdentify(myPlayer, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
@ -1625,7 +1627,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_REPAIR) { if (pcurs == CURSOR_REPAIR) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
DoRepair(MyPlayerId, pcursinvitem); DoRepair(myPlayer, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
@ -1633,7 +1635,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_RECHARGE) { if (pcurs == CURSOR_RECHARGE) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
DoRecharge(MyPlayerId, pcursinvitem); DoRecharge(myPlayer, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
@ -1641,14 +1643,13 @@ bool TryIconCurs()
if (pcurs == CURSOR_OIL) { if (pcurs == CURSOR_OIL) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
DoOil(MyPlayerId, pcursinvitem); DoOil(myPlayer, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
} }
if (pcurs == CURSOR_TELEPORT) { if (pcurs == CURSOR_TELEPORT) {
auto &myPlayer = Players[MyPlayerId];
if (pcursmonst != -1) if (pcursmonst != -1)
NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell));
else if (pcursplr != -1) else if (pcursplr != -1)
@ -1882,12 +1883,11 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
IncProgress(); IncProgress();
for (int i = 0; i < MAX_PLRS; i++) { for (auto &player : Players) {
auto &player = Players[i];
if (player.plractive && currlevel == player.plrlevel) { if (player.plractive && currlevel == player.plrlevel) {
InitPlayerGFX(player); InitPlayerGFX(player);
if (lvldir != ENTRY_LOAD) if (lvldir != ENTRY_LOAD)
InitPlayer(i, firstflag); InitPlayer(player, firstflag);
} }
} }
@ -1979,12 +1979,11 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
GetPortalLvlPos(); GetPortalLvlPos();
IncProgress(); IncProgress();
for (int i = 0; i < MAX_PLRS; i++) { for (auto &player : Players) {
auto &player = Players[i];
if (player.plractive && currlevel == player.plrlevel) { if (player.plractive && currlevel == player.plrlevel) {
InitPlayerGFX(player); InitPlayerGFX(player);
if (lvldir != ENTRY_LOAD) if (lvldir != ENTRY_LOAD)
InitPlayer(i, firstflag); InitPlayer(player, firstflag);
} }
} }
IncProgress(); IncProgress();

18
Source/inv.cpp

@ -340,7 +340,7 @@ bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation,
} }
NetSendCmdChItem(false, bodyLocation); NetSendCmdChItem(false, bodyLocation);
CalcPlrInv(playerId, true); CalcPlrInv(player, true);
} }
return true; return true;
@ -672,7 +672,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
case ILOC_INVALID: case ILOC_INVALID:
break; break;
} }
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
if (pnum == MyPlayerId) { if (pnum == MyPlayerId) {
if (cn == CURSOR_HAND && !IsHardwareCursor()) if (cn == CURSOR_HAND && !IsHardwareCursor())
SetCursorPos(MousePosition.x + (cursW / 2), MousePosition.y + (cursH / 2)); SetCursorPos(MousePosition.x + (cursW / 2), MousePosition.y + (cursH / 2));
@ -865,7 +865,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
player._pGold = CalculateGold(player); player._pGold = CalculateGold(player);
} }
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
CheckItemStats(player); CheckItemStats(player);
if (pnum == MyPlayerId) { if (pnum == MyPlayerId) {
@ -1521,14 +1521,12 @@ bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex)
return true; return true;
} }
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff) void CheckInvSwap(PlayerStruct &player, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff)
{ {
auto &item = Items[MAXITEMS]; auto &item = Items[MAXITEMS];
memset(&item, 0, sizeof(item)); memset(&item, 0, sizeof(item));
RecreateItem(item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0); RecreateItem(item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
auto &player = Players[pnum];
player.HoldItem = item; player.HoldItem = item;
if (bId) { if (bId) {
@ -1545,18 +1543,16 @@ void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId
} }
} }
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
void inv_update_rem_item(int pnum, BYTE iv) void inv_update_rem_item(PlayerStruct &player, BYTE iv)
{ {
auto &player = Players[pnum];
if (iv < NUM_INVLOC) { if (iv < NUM_INVLOC) {
player.InvBody[iv]._itype = ITYPE_NONE; player.InvBody[iv]._itype = ITYPE_NONE;
} }
CalcPlrInv(pnum, player._pmode != PM_DEATH); CalcPlrInv(player, player._pmode != PM_DEATH);
} }
void CheckInvItem(bool isShiftHeld) void CheckInvItem(bool isShiftHeld)

4
Source/inv.h

@ -104,8 +104,8 @@ bool AutoPlaceItemInInventorySlot(PlayerStruct &player, int slotIndex, const Ite
bool AutoPlaceItemInBelt(PlayerStruct &player, const ItemStruct &item, bool persistItem = false); bool AutoPlaceItemInBelt(PlayerStruct &player, const ItemStruct &item, bool persistItem = false);
bool GoldAutoPlace(PlayerStruct &player); bool GoldAutoPlace(PlayerStruct &player);
bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex); bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex);
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); void CheckInvSwap(PlayerStruct &player, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
void inv_update_rem_item(int pnum, BYTE iv); void inv_update_rem_item(PlayerStruct &player, BYTE iv);
void CheckInvItem(bool isShiftHeld = false); void CheckInvItem(bool isShiftHeld = false);
void CheckInvScrn(bool isShiftHeld); void CheckInvScrn(bool isShiftHeld);
void CheckItemStats(PlayerStruct &player); void CheckItemStats(PlayerStruct &player);

82
Source/items.cpp

@ -24,6 +24,7 @@
#include "lighting.h" #include "lighting.h"
#include "missiles.h" #include "missiles.h"
#include "options.h" #include "options.h"
#include "player.h"
#include "stores.h" #include "stores.h"
#include "utils/language.h" #include "utils/language.h"
#include "utils/math.h" #include "utils/math.h"
@ -126,6 +127,7 @@ enum class PlayerArmorGraphic : uint8_t {
Heavy = 1 << 5, Heavy = 1 << 5,
// clang-format on // clang-format on
}; };
ItemStruct curruitem; ItemStruct curruitem;
/** Holds item get records, tracking items being recently looted. This is in an effort to prevent items being picked up more than once. */ /** Holds item get records, tracking items being recently looted. This is in an effort to prevent items being picked up more than once. */
@ -2623,10 +2625,8 @@ void InitItems()
initItemGetRecords(); initItemGetRecords();
} }
void CalcPlrItemVals(int playerId, bool loadgfx) void CalcPlrItemVals(PlayerStruct &player, bool loadgfx)
{ {
auto &player = Players[playerId];
int mind = 0; // min damage int mind = 0; // min damage
int maxd = 0; // max damage int maxd = 0; // max damage
int tac = 0; // accuracy int tac = 0; // accuracy
@ -2754,7 +2754,7 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
lrad = clamp(lrad, 2, 15); lrad = clamp(lrad, 2, 15);
if (player._pLightRad != lrad && playerId == MyPlayerId) { if (player._pLightRad != lrad && &player == &Players[MyPlayerId]) {
ChangeLightRadius(player._plid, lrad); ChangeLightRadius(player._plid, lrad);
ChangeVisionRadius(player._pvid, lrad); ChangeVisionRadius(player._pvid, lrad);
player._pLightRad = lrad; player._pLightRad = lrad;
@ -2863,8 +2863,8 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
player._pMaxHP = ihp + player._pMaxHPBase; player._pMaxHP = ihp + player._pMaxHPBase;
player._pHitPoints = std::min(ihp + player._pHPBase, player._pMaxHP); player._pHitPoints = std::min(ihp + player._pHPBase, player._pMaxHP);
if (playerId == MyPlayerId && (player._pHitPoints >> 6) <= 0) { if (&player == &Players[MyPlayerId] && (player._pHitPoints >> 6) <= 0) {
SetPlayerHitPoints(playerId, 0); SetPlayerHitPoints(player, 0);
} }
player._pMaxMana = imana + player._pMaxManaBase; player._pMaxMana = imana + player._pMaxManaBase;
@ -2977,7 +2977,7 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
MaxGold = GOLD_MAX_LIMIT; MaxGold = GOLD_MAX_LIMIT;
if (half != MaxGold) if (half != MaxGold)
StripTopGold(playerId); StripTopGold(player);
} else { } else {
MaxGold = GOLD_MAX_LIMIT * 2; MaxGold = GOLD_MAX_LIMIT * 2;
} }
@ -2986,15 +2986,13 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
drawhpflag = true; drawhpflag = true;
} }
void CalcPlrInv(int playerId, bool loadgfx) void CalcPlrInv(PlayerStruct &player, bool loadgfx)
{ {
auto &player = Players[playerId];
CalcPlrItemMin(player); CalcPlrItemMin(player);
CalcSelfItems(player); CalcSelfItems(player);
CalcPlrItemVals(playerId, loadgfx); CalcPlrItemVals(player, loadgfx);
CalcPlrItemMin(player); CalcPlrItemMin(player);
if (playerId == MyPlayerId) { if (&player == &Players[MyPlayerId]) {
CalcPlrBookVals(player); CalcPlrBookVals(player);
player.CalcScrolls(); player.CalcScrolls();
CalcPlrStaff(player); CalcPlrStaff(player);
@ -3047,12 +3045,7 @@ void GetPlrHandSeed(ItemStruct *h)
h->_iSeed = AdvanceRndSeed(); h->_iSeed = AdvanceRndSeed();
} }
/** void SetGoldSeed(PlayerStruct &player, ItemStruct &gold)
* @brief Set a new unique seed value on the given item
* @param pnum Player id
* @param h Item to update
*/
void GetGoldSeed(int pnum, ItemStruct *h)
{ {
int s = 0; int s = 0;
@ -3066,15 +3059,15 @@ void GetGoldSeed(int pnum, ItemStruct *h)
if (item._iSeed == s) if (item._iSeed == s)
doneflag = false; doneflag = false;
} }
if (pnum == MyPlayerId) { if (&player == &Players[MyPlayerId]) {
for (int i = 0; i < Players[pnum]._pNumInv; i++) { for (int i = 0; i < player._pNumInv; i++) {
if (Players[pnum].InvList[i]._iSeed == s) if (player.InvList[i]._iSeed == s)
doneflag = false; doneflag = false;
} }
} }
} while (!doneflag); } while (!doneflag);
h->_iSeed = s; gold._iSeed = s;
} }
int GetGoldCursor(int value) int GetGoldCursor(int value)
@ -3202,7 +3195,7 @@ void CreatePlrItems(int playerId)
player.InvList[player._pNumInv++] = player.HoldItem; player.InvList[player._pNumInv++] = player.HoldItem;
player.InvGrid[30] = player._pNumInv; player.InvGrid[30] = player._pNumInv;
CalcPlrItemVals(playerId, false); CalcPlrItemVals(player, false);
} }
bool ItemSpaceOk(Point position) bool ItemSpaceOk(Point position)
@ -3769,28 +3762,26 @@ void GetItemStr(ItemStruct &item)
} }
} }
void CheckIdentify(int pnum, int cii) void CheckIdentify(PlayerStruct &player, int cii)
{ {
ItemStruct *pi; ItemStruct *pi;
if (cii >= NUM_INVLOC) if (cii >= NUM_INVLOC)
pi = &Players[pnum].InvList[cii - NUM_INVLOC]; pi = &player.InvList[cii - NUM_INVLOC];
else else
pi = &Players[pnum].InvBody[cii]; pi = &player.InvBody[cii];
pi->_iIdentified = true; pi->_iIdentified = true;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
if (pnum == MyPlayerId) if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
void DoRepair(int pnum, int cii) void DoRepair(PlayerStruct &player, int cii)
{ {
ItemStruct *pi; ItemStruct *pi;
auto &player = Players[pnum];
PlaySfxLoc(IS_REPAIR, player.position.tile); PlaySfxLoc(IS_REPAIR, player.position.tile);
if (cii >= NUM_INVLOC) { if (cii >= NUM_INVLOC) {
@ -3800,17 +3791,16 @@ void DoRepair(int pnum, int cii)
} }
RepairItem(*pi, player._pLevel); RepairItem(*pi, player._pLevel);
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
if (pnum == MyPlayerId) if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
void DoRecharge(int pnum, int cii) void DoRecharge(PlayerStruct &player, int cii)
{ {
ItemStruct *pi; ItemStruct *pi;
auto &player = Players[pnum];
if (cii >= NUM_INVLOC) { if (cii >= NUM_INVLOC) {
pi = &player.InvList[cii - NUM_INVLOC]; pi = &player.InvList[cii - NUM_INVLOC];
} else { } else {
@ -3820,24 +3810,26 @@ void DoRecharge(int pnum, int cii)
int r = GetSpellBookLevel(pi->_iSpell); int r = GetSpellBookLevel(pi->_iSpell);
r = GenerateRnd(player._pLevel / r) + 1; r = GenerateRnd(player._pLevel / r) + 1;
RechargeItem(*pi, r); RechargeItem(*pi, r);
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
if (pnum == MyPlayerId) if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
void DoOil(int pnum, int cii) void DoOil(PlayerStruct &player, int cii)
{ {
if (cii < NUM_INVLOC && cii != INVLOC_HEAD && (cii <= INVLOC_AMULET || cii > INVLOC_CHEST)) ItemStruct *pi;
return; if (cii >= NUM_INVLOC) {
auto &player = Players[pnum]; pi = &player.InvList[cii - NUM_INVLOC];
if (!ApplyOilToItem(player.InvBody[cii], player)) } else {
pi = &player.InvBody[cii];
}
if (!ApplyOilToItem(*pi, player))
return; return;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
if (pnum == MyPlayerId) { if (&player == &Players[MyPlayerId])
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
}
} }
void PrintItemPower(char plidx, ItemStruct *x) void PrintItemPower(char plidx, ItemStruct *x)

19
Source/items.h

@ -396,6 +396,8 @@ struct CornerStoneStruct {
ItemStruct item; ItemStruct item;
}; };
struct PlayerStruct;
extern ItemStruct Items[MAXITEMS + 1]; extern ItemStruct Items[MAXITEMS + 1];
extern int ActiveItems[MAXITEMS]; extern int ActiveItems[MAXITEMS];
extern int ActiveItemCount; extern int ActiveItemCount;
@ -409,11 +411,14 @@ bool IsItemAvailable(int i);
bool IsUniqueAvailable(int i); bool IsUniqueAvailable(int i);
void InitItemGFX(); void InitItemGFX();
void InitItems(); void InitItems();
void CalcPlrItemVals(int p, bool Loadgfx); void CalcPlrItemVals(PlayerStruct &player, bool Loadgfx);
void CalcPlrInv(int p, bool Loadgfx); void CalcPlrInv(PlayerStruct &player, bool Loadgfx);
void SetPlrHandItem(ItemStruct &item, int itemData); void SetPlrHandItem(ItemStruct &item, int itemData);
void GetPlrHandSeed(ItemStruct *h); void GetPlrHandSeed(ItemStruct *h);
void GetGoldSeed(int pnum, ItemStruct *h); /**
* @brief Set a new unique seed value on the given item
*/
void SetGoldSeed(PlayerStruct &player, ItemStruct &gold);
int GetGoldCursor(int value); int GetGoldCursor(int value);
void SetPlrHandGoldCurs(ItemStruct &gold); void SetPlrHandGoldCurs(ItemStruct &gold);
void CreatePlrItems(int playerId); void CreatePlrItems(int playerId);
@ -443,10 +448,10 @@ void ProcessItems();
void FreeItemGFX(); void FreeItemGFX();
void GetItemFrm(ItemStruct &item); void GetItemFrm(ItemStruct &item);
void GetItemStr(ItemStruct &item); void GetItemStr(ItemStruct &item);
void CheckIdentify(int pnum, int cii); void CheckIdentify(PlayerStruct &player, int cii);
void DoRepair(int pnum, int cii); void DoRepair(PlayerStruct &player, int cii);
void DoRecharge(int pnum, int cii); void DoRecharge(PlayerStruct &player, int cii);
void DoOil(int pnum, int cii); void DoOil(PlayerStruct &player, int cii);
void PrintItemPower(char plidx, ItemStruct *x); void PrintItemPower(char plidx, ItemStruct *x);
void DrawUniqueInfo(const Surface &out); void DrawUniqueInfo(const Surface &out);
void PrintItemDetails(ItemStruct *x); void PrintItemDetails(ItemStruct *x);

43
Source/loadsave.cpp

@ -304,10 +304,8 @@ void LoadItems(LoadHelper *file, const int n, ItemStruct *pItem)
} }
} }
void LoadPlayer(LoadHelper *file, int p) void LoadPlayer(LoadHelper *file, PlayerStruct &player)
{ {
auto &player = Players[p];
player._pmode = static_cast<PLR_MODE>(file->NextLE<int32_t>()); player._pmode = static_cast<PLR_MODE>(file->NextLE<int32_t>());
for (int8_t &step : player.walkpath) { for (int8_t &step : player.walkpath) {
@ -516,7 +514,7 @@ void LoadPlayer(LoadHelper *file, int p)
player.pDifficulty = static_cast<_difficulty>(file->NextLE<uint32_t>()); player.pDifficulty = static_cast<_difficulty>(file->NextLE<uint32_t>());
player.pDamAcFlags = file->NextLE<uint32_t>(); player.pDamAcFlags = file->NextLE<uint32_t>();
file->Skip(20); // Available bytes file->Skip(20); // Available bytes
CalcPlrItemVals(p, false); CalcPlrItemVals(player, false);
// Omit pointer _pNData // Omit pointer _pNData
// Omit pointer _pWData // Omit pointer _pWData
@ -635,10 +633,8 @@ void LoadMonster(LoadHelper *file, MonsterStruct &monster)
SyncMonsterAnim(monster); SyncMonsterAnim(monster);
} }
void LoadMissile(LoadHelper *file, int i) void LoadMissile(LoadHelper *file, MissileStruct &missile)
{ {
auto &missile = Missiles[i];
missile._mitype = static_cast<missile_id>(file->NextLE<int32_t>()); missile._mitype = static_cast<missile_id>(file->NextLE<int32_t>());
missile.position.tile.x = file->NextLE<int32_t>(); missile.position.tile.x = file->NextLE<int32_t>();
missile.position.tile.y = file->NextLE<int32_t>(); missile.position.tile.y = file->NextLE<int32_t>();
@ -973,10 +969,8 @@ void SaveItems(SaveHelper *file, ItemStruct *pItem, const int n)
} }
} }
void SavePlayer(SaveHelper *file, int p) void SavePlayer(SaveHelper *file, PlayerStruct &player)
{ {
auto &player = Players[p];
file->WriteLE<int32_t>(player._pmode); file->WriteLE<int32_t>(player._pmode);
for (int8_t step : player.walkpath) for (int8_t step : player.walkpath)
file->WriteLE<int8_t>(step); file->WriteLE<int8_t>(step);
@ -1285,10 +1279,8 @@ void SaveMonster(SaveHelper *file, MonsterStruct &monster)
// Omit pointer MData; // Omit pointer MData;
} }
void SaveMissile(SaveHelper *file, int i) void SaveMissile(SaveHelper *file, MissileStruct &missile)
{ {
auto &missile = Missiles[i];
file->WriteLE<int32_t>(missile._mitype); file->WriteLE<int32_t>(missile._mitype);
file->WriteLE<int32_t>(missile.position.tile.x); file->WriteLE<int32_t>(missile.position.tile.x);
file->WriteLE<int32_t>(missile.position.tile.y); file->WriteLE<int32_t>(missile.position.tile.y);
@ -1702,9 +1694,11 @@ void LoadGame(bool firstflag)
file.Skip(4); // Skip loading gnLevelTypeTbl file.Skip(4); // Skip loading gnLevelTypeTbl
} }
LoadPlayer(&file, MyPlayerId); auto &myPlayer = Players[MyPlayerId];
sgGameInitInfo.nDifficulty = Players[MyPlayerId].pDifficulty; LoadPlayer(&file, myPlayer);
sgGameInitInfo.nDifficulty = myPlayer.pDifficulty;
if (sgGameInitInfo.nDifficulty < DIFF_NORMAL || sgGameInitInfo.nDifficulty > DIFF_HELL) if (sgGameInitInfo.nDifficulty < DIFF_NORMAL || sgGameInitInfo.nDifficulty > DIFF_HELL)
sgGameInitInfo.nDifficulty = DIFF_NORMAL; sgGameInitInfo.nDifficulty = DIFF_NORMAL;
@ -1715,7 +1709,7 @@ void LoadGame(bool firstflag)
if (gbIsHellfireSaveGame != gbIsHellfire) { if (gbIsHellfireSaveGame != gbIsHellfire) {
ConvertLevels(); ConvertLevels();
RemoveEmptyInventory(Players[MyPlayerId]); RemoveEmptyInventory(myPlayer);
} }
LoadGameLevel(firstflag, ENTRY_LOAD); LoadGameLevel(firstflag, ENTRY_LOAD);
@ -1742,7 +1736,7 @@ void LoadGame(bool firstflag)
for (int &missileId : AvailableMissiles) for (int &missileId : AvailableMissiles)
missileId = file.NextLE<int8_t>(); missileId = file.NextLE<int8_t>();
for (int i = 0; i < ActiveMissileCount; i++) for (int i = 0; i < ActiveMissileCount; i++)
LoadMissile(&file, ActiveMissiles[i]); LoadMissile(&file, Missiles[ActiveMissiles[i]]);
for (int &objectId : ActiveObjects) for (int &objectId : ActiveObjects)
objectId = file.NextLE<int8_t>(); objectId = file.NextLE<int8_t>();
for (int &objectId : AvailableObjects) for (int &objectId : AvailableObjects)
@ -1918,8 +1912,9 @@ void SaveGameData()
file.WriteBE<int32_t>(gnLevelTypeTbl[i]); file.WriteBE<int32_t>(gnLevelTypeTbl[i]);
} }
Players[MyPlayerId].pDifficulty = sgGameInitInfo.nDifficulty; auto &myPlayer = Players[MyPlayerId];
SavePlayer(&file, MyPlayerId); myPlayer.pDifficulty = sgGameInitInfo.nDifficulty;
SavePlayer(&file, myPlayer);
for (int i = 0; i < giNumberQuests; i++) for (int i = 0; i < giNumberQuests; i++)
SaveQuest(&file, i); SaveQuest(&file, i);
@ -1938,7 +1933,7 @@ void SaveGameData()
for (int missileId : AvailableMissiles) for (int missileId : AvailableMissiles)
file.WriteLE<int8_t>(missileId); file.WriteLE<int8_t>(missileId);
for (int i = 0; i < ActiveMissileCount; i++) for (int i = 0; i < ActiveMissileCount; i++)
SaveMissile(&file, ActiveMissiles[i]); SaveMissile(&file, Missiles[ActiveMissiles[i]]);
for (int objectId : ActiveObjects) for (int objectId : ActiveObjects)
file.WriteLE<int8_t>(objectId); file.WriteLE<int8_t>(objectId);
for (int objectId : AvailableObjects) for (int objectId : AvailableObjects)
@ -2037,7 +2032,9 @@ void SaveLevel()
{ {
PFileScopedArchiveWriter scopedWriter; PFileScopedArchiveWriter scopedWriter;
DoUnVision(Players[MyPlayerId].position.tile, Players[MyPlayerId]._pLightRad); // fix for vision staying on the level auto &myPlayer = Players[MyPlayerId];
DoUnVision(myPlayer.position.tile, myPlayer._pLightRad); // fix for vision staying on the level
if (currlevel == 0) if (currlevel == 0)
glSeedTbl[0] = AdvanceRndSeed(); glSeedTbl[0] = AdvanceRndSeed();
@ -2111,9 +2108,9 @@ void SaveLevel()
} }
if (!setlevel) if (!setlevel)
Players[MyPlayerId]._pLvlVisited[currlevel] = true; myPlayer._pLvlVisited[currlevel] = true;
else else
Players[MyPlayerId]._pSLvlVisited[setlvlnum] = true; myPlayer._pSLvlVisited[setlvlnum] = true;
} }
void LoadLevel() void LoadLevel()

2
Source/menu.cpp

@ -115,7 +115,7 @@ bool mainmenu_select_hero_dialog(GameData *gameData)
return false; return false;
} }
pfile_read_player_from_save(gSaveNumber, MyPlayerId); pfile_read_player_from_save(gSaveNumber, Players[MyPlayerId]);
return true; return true;
} }

15
Source/missiles.cpp

@ -1226,7 +1226,7 @@ void InitMissiles()
if (missile._mitype == MIS_INFRA) { if (missile._mitype == MIS_INFRA) {
int src = missile._misource; int src = missile._misource;
if (src == MyPlayerId) if (src == MyPlayerId)
CalcPlrItemVals(MyPlayerId, true); CalcPlrItemVals(myPlayer, true);
} }
} }
} }
@ -1240,7 +1240,7 @@ void InitMissiles()
if (missile._mitype == MIS_BLODBOIL) { if (missile._mitype == MIS_BLODBOIL) {
if (missile._misource == MyPlayerId) { if (missile._misource == MyPlayerId) {
int missingHP = myPlayer._pMaxHP - myPlayer._pHitPoints; int missingHP = myPlayer._pMaxHP - myPlayer._pHitPoints;
CalcPlrItemVals(MyPlayerId, true); CalcPlrItemVals(myPlayer, true);
ApplyPlrDamage(MyPlayerId, 0, 1, missingHP + missile.var2); ApplyPlrDamage(MyPlayerId, 0, 1, missingHP + missile.var2);
} }
} }
@ -1505,7 +1505,7 @@ void AddManaTrap(MissileStruct &missile, Point /*dst*/, Direction /*midir*/)
player._pMana = 0; player._pMana = 0;
player._pManaBase = player._pMana + player._pMaxManaBase - player._pMaxMana; player._pManaBase = player._pMana + player._pMaxManaBase - player._pMaxMana;
CalcPlrInv(pid, false); CalcPlrInv(player, false);
drawmanaflag = true; drawmanaflag = true;
PlaySfxLoc(TSFX_COW7, target); PlaySfxLoc(TSFX_COW7, target);
} }
@ -2619,7 +2619,7 @@ void AddBlodboil(MissileStruct &missile, Point /*dst*/, Direction /*midir*/)
missile.var2 = tmp; missile.var2 = tmp;
int lvl = player._pLevel * 2; int lvl = player._pLevel * 2;
missile._mirange = lvl + 10 * missile._mispllvl + 245; missile._mirange = lvl + 10 * missile._mispllvl + 245;
CalcPlrItemVals(missile._misource, true); CalcPlrItemVals(player, true);
force_redraw = 255; force_redraw = 255;
player.Say(HeroSpeech::Aaaaargh); player.Say(HeroSpeech::Aaaaargh);
} }
@ -3881,11 +3881,12 @@ void MI_FirewallC(MissileStruct &missile)
void MI_Infra(MissileStruct &missile) void MI_Infra(MissileStruct &missile)
{ {
auto &player = Players[missile._misource];
missile._mirange--; missile._mirange--;
Players[missile._misource]._pInfraFlag = true; player._pInfraFlag = true;
if (missile._mirange == 0) { if (missile._mirange == 0) {
missile._miDelFlag = true; missile._miDelFlag = true;
CalcPlrItemVals(missile._misource, true); CalcPlrItemVals(player, true);
} }
} }
@ -4014,7 +4015,7 @@ void MI_Blodboil(MissileStruct &missile)
hpdif += missile.var2; hpdif += missile.var2;
} }
CalcPlrItemVals(id, true); CalcPlrItemVals(player, true);
ApplyPlrDamage(id, 0, 1, hpdif); ApplyPlrDamage(id, 0, 1, hpdif);
force_redraw = 255; force_redraw = 255;
player.Say(HeroSpeech::HeavyBreathing); player.Say(HeroSpeech::HeavyBreathing);

16
Source/msg.cpp

@ -1446,12 +1446,14 @@ DWORD OnChangePlayerItems(TCmd *pCmd, int pnum)
auto *p = (TCmdChItem *)pCmd; auto *p = (TCmdChItem *)pCmd;
auto bodyLocation = static_cast<inv_body_loc>(p->bLoc); auto bodyLocation = static_cast<inv_body_loc>(p->bLoc);
auto &player = Players[pnum];
if (gbBufferMsgs == 1) if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p)); SendPacket(pnum, p, sizeof(*p));
else if (pnum != MyPlayerId) else if (pnum != MyPlayerId)
CheckInvSwap(pnum, p->bLoc, p->wIndx, p->wCI, p->dwSeed, p->bId != 0, p->dwBuff); CheckInvSwap(player, p->bLoc, p->wIndx, p->wCI, p->dwSeed, p->bId != 0, p->dwBuff);
Players[pnum].ReadySpellFromEquipment(bodyLocation); player.ReadySpellFromEquipment(bodyLocation);
return sizeof(*p); return sizeof(*p);
} }
@ -1463,7 +1465,7 @@ DWORD OnDeletePlayerItems(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p)); SendPacket(pnum, p, sizeof(*p));
else if (pnum != MyPlayerId) else if (pnum != MyPlayerId)
inv_update_rem_item(pnum, p->bLoc); inv_update_rem_item(Players[pnum], p->bLoc);
return sizeof(*p); return sizeof(*p);
} }
@ -1616,7 +1618,7 @@ DWORD OnSetStrength(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p)); SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId) else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrStr(pnum, p->wParam1); SetPlrStr(Players[pnum], p->wParam1);
return sizeof(*p); return sizeof(*p);
} }
@ -1628,7 +1630,7 @@ DWORD OnSetDexterity(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p)); SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId) else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrDex(pnum, p->wParam1); SetPlrDex(Players[pnum], p->wParam1);
return sizeof(*p); return sizeof(*p);
} }
@ -1640,7 +1642,7 @@ DWORD OnSetMagic(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p)); SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId) else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrMag(pnum, p->wParam1); SetPlrMag(Players[pnum], p->wParam1);
return sizeof(*p); return sizeof(*p);
} }
@ -1652,7 +1654,7 @@ DWORD OnSetVitality(TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) if (gbBufferMsgs == 1)
SendPacket(pnum, p, sizeof(*p)); SendPacket(pnum, p, sizeof(*p));
else if (p->wParam1 <= 750 && pnum != MyPlayerId) else if (p->wParam1 <= 750 && pnum != MyPlayerId)
SetPlrVit(pnum, p->wParam1); SetPlrVit(Players[pnum], p->wParam1);
return sizeof(*p); return sizeof(*p);
} }

4
Source/multi.cpp

@ -454,7 +454,7 @@ bool InitMulti(GameData *gameData)
MyPlayerId = playerId; MyPlayerId = playerId;
gbIsMultiplayer = true; gbIsMultiplayer = true;
pfile_read_player_from_save(gSaveNumber, MyPlayerId); pfile_read_player_from_save(gSaveNumber, Players[MyPlayerId]);
return true; return true;
} }
@ -802,7 +802,7 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
sgwPackPlrOffsetTbl[pnum] = 0; sgwPackPlrOffsetTbl[pnum] = 0;
PlayerLeftMsg(pnum, false); PlayerLeftMsg(pnum, false);
UnPackPlayer(&netplr[pnum], pnum, true); UnPackPlayer(&netplr[pnum], player, true);
if (!recv) { if (!recv) {
return; return;

2
Source/objects.cpp

@ -3711,7 +3711,7 @@ void OperateShrine(int pnum, int i, _sfx_id sType)
break; break;
} }
CalcPlrInv(pnum, true); CalcPlrInv(Players[pnum], true);
force_redraw = 255; force_redraw = 255;
if (pnum == MyPlayerId) if (pnum == MyPlayerId)

10
Source/pack.cpp

@ -197,10 +197,8 @@ void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
*id = item; *id = item;
} }
void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync) void UnPackPlayer(const PkPlayerStruct *pPack, PlayerStruct &player, bool netSync)
{ {
auto &player = Players[pnum];
player.position.tile = { pPack->px, pPack->py }; player.position.tile = { pPack->px, pPack->py };
player.position.future = { pPack->px, pPack->py }; player.position.future = { pPack->px, pPack->py };
player.plrlevel = pPack->plrlevel; player.plrlevel = pPack->plrlevel;
@ -208,7 +206,7 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
player.destAction = ACTION_NONE; player.destAction = ACTION_NONE;
strcpy(player._pName, pPack->pName); strcpy(player._pName, pPack->pName);
player._pClass = (HeroClass)pPack->pClass; player._pClass = (HeroClass)pPack->pClass;
InitPlayer(pnum, true); InitPlayer(player, true);
player._pBaseStr = pPack->pBaseStr; player._pBaseStr = pPack->pBaseStr;
player._pStrength = pPack->pBaseStr; player._pStrength = pPack->pBaseStr;
player._pBaseMag = pPack->pBaseMag; player._pBaseMag = pPack->pBaseMag;
@ -261,12 +259,12 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
UnPackItem(&packedItem, &player.SpdList[i], isHellfire); UnPackItem(&packedItem, &player.SpdList[i], isHellfire);
} }
if (pnum == MyPlayerId) { if (&player == &Players[MyPlayerId]) {
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
witchitem[i]._itype = ITYPE_NONE; witchitem[i]._itype = ITYPE_NONE;
} }
CalcPlrInv(pnum, false); CalcPlrInv(player, false);
player.wReflections = SDL_SwapLE16(pPack->wReflections); player.wReflections = SDL_SwapLE16(pPack->wReflections);
player.pTownWarps = 0; player.pTownWarps = 0;
player.pDungMsgs = 0; player.pDungMsgs = 0;

2
Source/pack.h

@ -80,7 +80,7 @@ struct PkPlayerStruct {
#pragma pack(pop) #pragma pack(pop)
void PackPlayer(PkPlayerStruct *pPack, const PlayerStruct &player, bool manashield); void PackPlayer(PkPlayerStruct *pPack, const PlayerStruct &player, bool manashield);
void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync); void UnPackPlayer(const PkPlayerStruct *pPack, PlayerStruct &player, bool netSync);
void PackItem(PkItemStruct *id, const ItemStruct *is); void PackItem(PkItemStruct *id, const ItemStruct *is);
void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire); void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire);

12
Source/pfile.cpp

@ -300,12 +300,12 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0; pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0;
auto &player = Players[0]; auto &player = Players[0];
UnPackPlayer(&pkplr, 0, false); UnPackPlayer(&pkplr, player, false);
CloseArchive(&archive); CloseArchive(&archive);
LoadHeroItems(player); LoadHeroItems(player);
RemoveEmptyInventory(player); RemoveEmptyInventory(player);
CalcPlrInv(0, false); CalcPlrInv(player, false);
Game2UiPlayer(player, &uihero, hasSaveGame); Game2UiPlayer(player, &uihero, hasSaveGame);
uiAddHeroInfo(&uihero); uiAddHeroInfo(&uihero);
@ -375,7 +375,7 @@ bool pfile_delete_save(_uiheroinfo *heroInfo)
return true; return true;
} }
void pfile_read_player_from_save(uint32_t saveNum, int playerId) void pfile_read_player_from_save(uint32_t saveNum, PlayerStruct &player)
{ {
HANDLE archive; HANDLE archive;
PkPlayerStruct pkplr; PkPlayerStruct pkplr;
@ -392,13 +392,11 @@ void pfile_read_player_from_save(uint32_t saveNum, int playerId)
CloseArchive(&archive); CloseArchive(&archive);
auto &player = Players[playerId]; UnPackPlayer(&pkplr, player, false);
UnPackPlayer(&pkplr, playerId, false);
LoadHeroItems(player); LoadHeroItems(player);
RemoveEmptyInventory(player); RemoveEmptyInventory(player);
CalcPlrInv(playerId, false); CalcPlrInv(player, false);
} }
bool LevelFileExists() bool LevelFileExists()

2
Source/pfile.h

@ -34,7 +34,7 @@ void pfile_ui_set_class_stats(unsigned int playerClass, _uidefaultstats *classSt
uint32_t pfile_ui_get_first_unused_save_num(); uint32_t pfile_ui_get_first_unused_save_num();
bool pfile_ui_save_create(_uiheroinfo *heroinfo); bool pfile_ui_save_create(_uiheroinfo *heroinfo);
bool pfile_delete_save(_uiheroinfo *heroInfo); bool pfile_delete_save(_uiheroinfo *heroInfo);
void pfile_read_player_from_save(uint32_t saveNum, int playerId); void pfile_read_player_from_save(uint32_t saveNum, PlayerStruct &player);
bool LevelFileExists(); bool LevelFileExists();
void GetTempLevelNames(char *szTemp); void GetTempLevelNames(char *szTemp);
void GetPermLevelNames(char *szPerm); void GetPermLevelNames(char *szPerm);

148
Source/player.cpp

@ -625,7 +625,7 @@ int DropGold(int pnum, int amount, bool skipFullStacks)
if (amount < item._ivalue) { if (amount < item._ivalue) {
item._ivalue -= amount; item._ivalue -= amount;
SetPlrHandItem(player.HoldItem, IDI_GOLD); SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem); SetGoldSeed(player, player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem); SetPlrHandGoldCurs(player.HoldItem);
player.HoldItem._ivalue = amount; player.HoldItem._ivalue = amount;
DeadItem(player, &player.HoldItem, { 0, 0 }); DeadItem(player, &player.HoldItem, { 0, 0 });
@ -635,7 +635,7 @@ int DropGold(int pnum, int amount, bool skipFullStacks)
amount -= item._ivalue; amount -= item._ivalue;
player.RemoveInvItem(i); player.RemoveInvItem(i);
SetPlrHandItem(player.HoldItem, IDI_GOLD); SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem); SetGoldSeed(player, player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem); SetPlrHandGoldCurs(player.HoldItem);
player.HoldItem._ivalue = item._ivalue; player.HoldItem._ivalue = item._ivalue;
DeadItem(player, &player.HoldItem, { 0, 0 }); DeadItem(player, &player.HoldItem, { 0, 0 });
@ -768,19 +768,17 @@ bool DoWalk(int pnum, int variant)
return false; return false;
} }
bool WeaponDecay(int pnum, int ii) bool WeaponDecay(PlayerStruct &player, int ii)
{ {
auto &player = Players[pnum];
if (!player.InvBody[ii].isEmpty() && player.InvBody[ii]._iClass == ICLASS_WEAPON && (player.InvBody[ii]._iDamAcFlags & ISPLHF_DECAY) != 0) { if (!player.InvBody[ii].isEmpty() && player.InvBody[ii]._iClass == ICLASS_WEAPON && (player.InvBody[ii]._iDamAcFlags & ISPLHF_DECAY) != 0) {
player.InvBody[ii]._iPLDam -= 5; player.InvBody[ii]._iPLDam -= 5;
if (player.InvBody[ii]._iPLDam <= -100) { if (player.InvBody[ii]._iPLDam <= -100) {
NetSendCmdDelItem(true, ii); NetSendCmdDelItem(true, ii);
player.InvBody[ii]._itype = ITYPE_NONE; player.InvBody[ii]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
return true; return true;
} }
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
return false; return false;
} }
@ -791,20 +789,20 @@ bool DamageWeapon(int pnum, int durrnd)
return false; return false;
} }
if (WeaponDecay(pnum, INVLOC_HAND_LEFT)) if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("WeaponDur: illegal player %i", pnum);
}
auto &player = Players[pnum];
if (WeaponDecay(player, INVLOC_HAND_LEFT))
return true; return true;
if (WeaponDecay(pnum, INVLOC_HAND_RIGHT)) if (WeaponDecay(player, INVLOC_HAND_RIGHT))
return true; return true;
if (GenerateRnd(durrnd) != 0) { if (GenerateRnd(durrnd) != 0) {
return false; return false;
} }
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("WeaponDur: illegal player %i", pnum);
}
auto &player = Players[pnum];
if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON) { if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON) {
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) { if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) {
return false; return false;
@ -814,7 +812,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability <= 0) { if (player.InvBody[INVLOC_HAND_LEFT]._iDurability <= 0) {
NetSendCmdDelItem(true, INVLOC_HAND_LEFT); NetSendCmdDelItem(true, INVLOC_HAND_LEFT);
player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
return true; return true;
} }
} }
@ -828,7 +826,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) { if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_RIGHT); NetSendCmdDelItem(true, INVLOC_HAND_RIGHT);
player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
return true; return true;
} }
} }
@ -842,7 +840,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) { if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_RIGHT); NetSendCmdDelItem(true, INVLOC_HAND_RIGHT);
player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
return true; return true;
} }
} }
@ -856,7 +854,7 @@ bool DamageWeapon(int pnum, int durrnd)
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == 0) { if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_LEFT); NetSendCmdDelItem(true, INVLOC_HAND_LEFT);
player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
return true; return true;
} }
} }
@ -1362,7 +1360,7 @@ void ShieldDur(int pnum)
if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == 0) { if (player.InvBody[INVLOC_HAND_LEFT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_LEFT); NetSendCmdDelItem(true, INVLOC_HAND_LEFT);
player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; player.InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
} }
@ -1372,7 +1370,7 @@ void ShieldDur(int pnum)
if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) { if (player.InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) {
NetSendCmdDelItem(true, INVLOC_HAND_RIGHT); NetSendCmdDelItem(true, INVLOC_HAND_RIGHT);
player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; player.InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
} }
} }
@ -1444,7 +1442,7 @@ void DamageArmor(int pnum)
NetSendCmdDelItem(true, INVLOC_HEAD); NetSendCmdDelItem(true, INVLOC_HEAD);
} }
pi->_itype = ITYPE_NONE; pi->_itype = ITYPE_NONE;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
bool DoSpell(int pnum) bool DoSpell(int pnum)
@ -2571,7 +2569,7 @@ void NextPlrLevel(int pnum)
player._pLevel++; player._pLevel++;
player._pMaxLvl++; player._pMaxLvl++;
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
if (CalcStatDiff(player) < 5) { if (CalcStatDiff(player) < 5) {
player._pStatPts = CalcStatDiff(player); player._pStatPts = CalcStatDiff(player);
@ -2618,7 +2616,7 @@ void NextPlrLevel(int pnum)
if (sgbControllerActive) if (sgbControllerActive)
FocusOnCharInfo(); FocusOnCharInfo();
CalcPlrInv(pnum, true); CalcPlrInv(player, true);
} }
void AddPlrExperience(int pnum, int lvl, int exp) void AddPlrExperience(int pnum, int lvl, int exp)
@ -2692,18 +2690,14 @@ void AddPlrMonstExper(int lvl, int exp, char pmask)
} }
} }
void InitPlayer(int pnum, bool firstTime) void InitPlayer(PlayerStruct &player, bool firstTime)
{ {
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("InitPlayer: illegal player %i", pnum);
}
auto &player = Players[pnum];
auto &myPlayer = Players[MyPlayerId]; auto &myPlayer = Players[MyPlayerId];
if (firstTime) { if (firstTime) {
player._pRSplType = RSPLTYPE_INVALID; player._pRSplType = RSPLTYPE_INVALID;
player._pRSpell = SPL_INVALID; player._pRSpell = SPL_INVALID;
if (pnum == MyPlayerId) if (&player == &myPlayer)
LoadHotkeys(); LoadHotkeys();
player._pSBkSpell = SPL_INVALID; player._pSBkSpell = SPL_INVALID;
player._pSpell = player._pRSpell; player._pSpell = player._pRSpell;
@ -2734,7 +2728,7 @@ void InitPlayer(int pnum, bool firstTime)
player._pdir = DIR_S; player._pdir = DIR_S;
if (pnum == MyPlayerId) { if (&player == &myPlayer) {
if (!firstTime || currlevel != 0) { if (!firstTime || currlevel != 0) {
player.position.tile = { ViewX, ViewY }; player.position.tile = { ViewX, ViewY };
} }
@ -2750,13 +2744,13 @@ void InitPlayer(int pnum, bool firstTime)
player.walkpath[0] = WALK_NONE; player.walkpath[0] = WALK_NONE;
player.destAction = ACTION_NONE; player.destAction = ACTION_NONE;
if (pnum == MyPlayerId) { if (&player == &myPlayer) {
player._plid = AddLight(player.position.tile, player._pLightRad); player._plid = AddLight(player.position.tile, player._pLightRad);
ChangeLightXY(myPlayer._plid, myPlayer.position.tile); // fix for a bug where old light is still visible at the entrance after reentering level ChangeLightXY(myPlayer._plid, myPlayer.position.tile); // fix for a bug where old light is still visible at the entrance after reentering level
} else { } else {
player._plid = NO_LIGHT; player._plid = NO_LIGHT;
} }
player._pvid = AddVision(player.position.tile, player._pLightRad, pnum == MyPlayerId); player._pvid = AddVision(player.position.tile, player._pLightRad, &player == &myPlayer);
} }
if (player._pClass == HeroClass::Warrior) { if (player._pClass == HeroClass::Warrior) {
@ -2782,7 +2776,7 @@ void InitPlayer(int pnum, bool firstTime)
player._pNextExper = ExpLvlsTbl[player._pLevel]; player._pNextExper = ExpLvlsTbl[player._pLevel];
player._pInvincible = false; player._pInvincible = false;
if (pnum == MyPlayerId) { if (&player == &myPlayer) {
deathdelay = 0; deathdelay = 0;
MyPlayerIsDead = false; MyPlayerIsDead = false;
ScrollInfo.offset = { 0, 0 }; ScrollInfo.offset = { 0, 0 };
@ -3026,14 +3020,14 @@ StartPlayerKill(int pnum, int earflag)
player._pBlockFlag = false; player._pBlockFlag = false;
player._pmode = PM_DEATH; player._pmode = PM_DEATH;
player._pInvincible = true; player._pInvincible = true;
SetPlayerHitPoints(pnum, 0); SetPlayerHitPoints(player, 0);
player.deathFrame = 1; player.deathFrame = 1;
if (pnum != MyPlayerId && earflag == 0 && !diablolevel) { if (pnum != MyPlayerId && earflag == 0 && !diablolevel) {
for (auto &item : player.InvBody) { for (auto &item : player.InvBody) {
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
} }
CalcPlrInv(pnum, false); CalcPlrInv(player, false);
} }
if (player.plrlevel == currlevel) { if (player.plrlevel == currlevel) {
@ -3087,22 +3081,17 @@ StartPlayerKill(int pnum, int earflag)
DeadItem(player, &item, Displacement::fromDirection(pdd)); DeadItem(player, &item, Displacement::fromDirection(pdd));
} }
CalcPlrInv(pnum, false); CalcPlrInv(player, false);
} }
} }
} }
} }
} }
SetPlayerHitPoints(pnum, 0); SetPlayerHitPoints(player, 0);
} }
void StripTopGold(int pnum) void StripTopGold(PlayerStruct &player)
{ {
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StripTopGold: illegal player %i", pnum);
}
auto &player = Players[pnum];
ItemStruct tmpItem = player.HoldItem; ItemStruct tmpItem = player.HoldItem;
for (int i = 0; i < player._pNumInv; i++) { for (int i = 0; i < player._pNumInv; i++) {
@ -3111,7 +3100,7 @@ void StripTopGold(int pnum)
int val = player.InvList[i]._ivalue - MaxGold; int val = player.InvList[i]._ivalue - MaxGold;
player.InvList[i]._ivalue = MaxGold; player.InvList[i]._ivalue = MaxGold;
SetPlrHandItem(player.HoldItem, 0); SetPlrHandItem(player.HoldItem, 0);
GetGoldSeed(pnum, &player.HoldItem); SetGoldSeed(player, player.HoldItem);
player.HoldItem._ivalue = val; player.HoldItem._ivalue = val;
SetPlrHandGoldCurs(player.HoldItem); SetPlrHandGoldCurs(player.HoldItem);
if (!GoldAutoPlace(player)) if (!GoldAutoPlace(player))
@ -3162,7 +3151,7 @@ void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int
} }
int minHitPoints = minHP << 6; int minHitPoints = minHP << 6;
if (player._pHitPoints < minHitPoints) { if (player._pHitPoints < minHitPoints) {
SetPlayerHitPoints(pnum, minHitPoints); SetPlayerHitPoints(player, minHitPoints);
} }
if (player._pHitPoints >> 6 <= 0) { if (player._pHitPoints >> 6 <= 0) {
SyncPlrKill(pnum, earflag); SyncPlrKill(pnum, earflag);
@ -3174,11 +3163,11 @@ void SyncPlrKill(int pnum, int earflag)
auto &player = Players[pnum]; auto &player = Players[pnum];
if (player._pHitPoints <= 0 && currlevel == 0) { if (player._pHitPoints <= 0 && currlevel == 0) {
SetPlayerHitPoints(pnum, 64); SetPlayerHitPoints(player, 64);
return; return;
} }
SetPlayerHitPoints(pnum, 0); SetPlayerHitPoints(player, 0);
StartPlayerKill(pnum, earflag); StartPlayerKill(pnum, earflag);
} }
@ -3261,12 +3250,12 @@ void RestartTownLvl(int pnum)
player.plrlevel = 0; player.plrlevel = 0;
player._pInvincible = false; player._pInvincible = false;
SetPlayerHitPoints(pnum, 64); SetPlayerHitPoints(player, 64);
player._pMana = 0; player._pMana = 0;
player._pManaBase = player._pMana - (player._pMaxMana - player._pMaxManaBase); player._pManaBase = player._pMana - (player._pMaxMana - player._pMaxManaBase);
CalcPlrInv(pnum, false); CalcPlrInv(player, false);
if (pnum == MyPlayerId) { if (pnum == MyPlayerId) {
player._pmode = PM_NEWLVL; player._pmode = PM_NEWLVL;
@ -3701,7 +3690,7 @@ void ModifyPlrStr(int p, int l)
player._pStrength += l; player._pStrength += l;
player._pBaseStr += l; player._pBaseStr += l;
CalcPlrInv(p, true); CalcPlrInv(player, true);
if (p == MyPlayerId) { if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETSTR, player._pBaseStr); NetSendCmdParam1(false, CMD_SETSTR, player._pBaseStr);
@ -3737,7 +3726,7 @@ void ModifyPlrMag(int p, int l)
player._pMana += ms; player._pMana += ms;
} }
CalcPlrInv(p, true); CalcPlrInv(player, true);
if (p == MyPlayerId) { if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETMAG, player._pBaseMag); NetSendCmdParam1(false, CMD_SETMAG, player._pBaseMag);
@ -3758,7 +3747,7 @@ void ModifyPlrDex(int p, int l)
player._pDexterity += l; player._pDexterity += l;
player._pBaseDex += l; player._pBaseDex += l;
CalcPlrInv(p, true); CalcPlrInv(player, true);
if (p == MyPlayerId) { if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETDEX, player._pBaseDex); NetSendCmdParam1(false, CMD_SETDEX, player._pBaseDex);
@ -3790,51 +3779,34 @@ void ModifyPlrVit(int p, int l)
player._pHitPoints += ms; player._pHitPoints += ms;
player._pMaxHP += ms; player._pMaxHP += ms;
CalcPlrInv(p, true); CalcPlrInv(player, true);
if (p == MyPlayerId) { if (p == MyPlayerId) {
NetSendCmdParam1(false, CMD_SETVIT, player._pBaseVit); NetSendCmdParam1(false, CMD_SETVIT, player._pBaseVit);
} }
} }
void SetPlayerHitPoints(int pnum, int val) void SetPlayerHitPoints(PlayerStruct &player, int val)
{ {
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("SetPlayerHitPoints: illegal player %i", pnum);
}
auto &player = Players[pnum];
player._pHitPoints = val; player._pHitPoints = val;
player._pHPBase = val + player._pMaxHPBase - player._pMaxHP; player._pHPBase = val + player._pMaxHPBase - player._pMaxHP;
if (pnum == MyPlayerId) { if (&player == &Players[MyPlayerId]) {
drawhpflag = true; drawhpflag = true;
} }
} }
void SetPlrStr(int p, int v) void SetPlrStr(PlayerStruct &player, int v)
{ {
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrStr: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseStr = v; player._pBaseStr = v;
CalcPlrInv(p, true); CalcPlrInv(player, true);
} }
void SetPlrMag(int p, int v) void SetPlrMag(PlayerStruct &player, int v)
{ {
int m;
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrMag: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseMag = v; player._pBaseMag = v;
m = v << 6; int m = v << 6;
if (player._pClass == HeroClass::Sorcerer) { if (player._pClass == HeroClass::Sorcerer) {
m *= 2; m *= 2;
} else if (player._pClass == HeroClass::Bard) { } else if (player._pClass == HeroClass::Bard) {
@ -3843,39 +3815,27 @@ void SetPlrMag(int p, int v)
player._pMaxManaBase = m; player._pMaxManaBase = m;
player._pMaxMana = m; player._pMaxMana = m;
CalcPlrInv(p, true); CalcPlrInv(player, true);
} }
void SetPlrDex(int p, int v) void SetPlrDex(PlayerStruct &player, int v)
{ {
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrDex: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseDex = v; player._pBaseDex = v;
CalcPlrInv(p, true); CalcPlrInv(player, true);
} }
void SetPlrVit(int p, int v) void SetPlrVit(PlayerStruct &player, int v)
{ {
int hp;
if ((DWORD)p >= MAX_PLRS) {
app_fatal("SetPlrVit: illegal player %i", p);
}
auto &player = Players[p];
player._pBaseVit = v; player._pBaseVit = v;
hp = v << 6; int hp = v << 6;
if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) { if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) {
hp *= 2; hp *= 2;
} }
player._pHPBase = hp; player._pHPBase = hp;
player._pMaxHPBase = hp; player._pMaxHPBase = hp;
CalcPlrInv(p, true); CalcPlrInv(player, true);
} }
void InitDungMsgs(PlayerStruct &player) void InitDungMsgs(PlayerStruct &player)

14
Source/player.h

@ -597,7 +597,7 @@ void NextPlrLevel(int pnum);
void AddPlrExperience(int pnum, int lvl, int exp); void AddPlrExperience(int pnum, int lvl, int exp);
void AddPlrMonstExper(int lvl, int exp, char pmask); void AddPlrMonstExper(int lvl, int exp, char pmask);
void ApplyPlrDamage(int pnum, int dam, int minHP = 0, int frac = 0, int earflag = 0); void ApplyPlrDamage(int pnum, int dam, int minHP = 0, int frac = 0, int earflag = 0);
void InitPlayer(int pnum, bool FirstTime); void InitPlayer(PlayerStruct &player, bool FirstTime);
void InitMultiView(); void InitMultiView();
void PlrClrTrans(Point position); void PlrClrTrans(Point position);
void PlrDoTrans(Point position); void PlrDoTrans(Point position);
@ -609,7 +609,7 @@ void FixPlrWalkTags(int pnum);
void RemovePlrFromMap(int pnum); void RemovePlrFromMap(int pnum);
void StartPlrHit(int pnum, int dam, bool forcehit); void StartPlrHit(int pnum, int dam, bool forcehit);
void StartPlayerKill(int pnum, int earflag); void StartPlayerKill(int pnum, int earflag);
void StripTopGold(int pnum); void StripTopGold(PlayerStruct &player);
void SyncPlrKill(int pnum, int earflag); void SyncPlrKill(int pnum, int earflag);
void RemovePlrMissiles(int pnum); void RemovePlrMissiles(int pnum);
void StartNewLvl(int pnum, interface_mode fom, int lvl); void StartNewLvl(int pnum, interface_mode fom, int lvl);
@ -629,11 +629,11 @@ void ModifyPlrStr(int p, int l);
void ModifyPlrMag(int p, int l); void ModifyPlrMag(int p, int l);
void ModifyPlrDex(int p, int l); void ModifyPlrDex(int p, int l);
void ModifyPlrVit(int p, int l); void ModifyPlrVit(int p, int l);
void SetPlayerHitPoints(int pnum, int val); void SetPlayerHitPoints(PlayerStruct &player, int val);
void SetPlrStr(int p, int v); void SetPlrStr(PlayerStruct &player, int v);
void SetPlrMag(int p, int v); void SetPlrMag(PlayerStruct &player, int v);
void SetPlrDex(int p, int v); void SetPlrDex(PlayerStruct &player, int v);
void SetPlrVit(int p, int v); void SetPlrVit(PlayerStruct &player, int v);
void InitDungMsgs(PlayerStruct &player); void InitDungMsgs(PlayerStruct &player);
void PlayDungMsgs(); void PlayDungMsgs();

4
Source/spells.cpp

@ -285,13 +285,13 @@ void DoResurrect(int pnum, uint16_t rid)
if (target._pMaxHPBase < (10 << 6)) { if (target._pMaxHPBase < (10 << 6)) {
hp = target._pMaxHPBase; hp = target._pMaxHPBase;
} }
SetPlayerHitPoints(rid, hp); SetPlayerHitPoints(target, hp);
target._pHPBase = target._pHitPoints + (target._pMaxHPBase - target._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed target._pHPBase = target._pHitPoints + (target._pMaxHPBase - target._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed
target._pMana = 0; target._pMana = 0;
target._pManaBase = target._pMana + (target._pMaxManaBase - target._pMaxMana); target._pManaBase = target._pMana + (target._pMaxManaBase - target._pMaxMana);
CalcPlrInv(rid, true); CalcPlrInv(target, true);
if (target.plrlevel == currlevel) { if (target.plrlevel == currlevel) {
StartStand(rid, target._pdir); StartStand(rid, target._pdir);

23
Source/stores.cpp

@ -1302,7 +1302,8 @@ void SmithEnter()
*/ */
void SmithBuyItem() void SmithBuyItem()
{ {
auto &item = Players[MyPlayerId].HoldItem; auto &myPlayer = Players[MyPlayerId];
auto &item = myPlayer.HoldItem;
TakePlrsMoney(item._iIvalue); TakePlrsMoney(item._iIvalue);
if (item._iMagical == ITEM_QUALITY_NORMAL) if (item._iMagical == ITEM_QUALITY_NORMAL)
@ -1317,7 +1318,7 @@ void SmithBuyItem()
} }
smithitem[idx]._itype = ITYPE_NONE; smithitem[idx]._itype = ITYPE_NONE;
} }
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
} }
void SmitBuyEnter() void SmitBuyEnter()
@ -1469,7 +1470,7 @@ void PlaceStoreGold(int v)
for (auto &gridNum : myPlayer.InvGrid) { for (auto &gridNum : myPlayer.InvGrid) {
if (gridNum == 0) { if (gridNum == 0) {
int ii = myPlayer._pNumInv; int ii = myPlayer._pNumInv;
GetGoldSeed(MyPlayerId, &golditem); SetGoldSeed(myPlayer, golditem);
myPlayer.InvList[ii] = golditem; myPlayer.InvList[ii] = golditem;
myPlayer._pNumInv++; myPlayer._pNumInv++;
gridNum = myPlayer._pNumInv; gridNum = myPlayer._pNumInv;
@ -1649,7 +1650,7 @@ void WitchBuyItem()
} }
} }
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
} }
void WitchBuyEnter() void WitchBuyEnter()
@ -1723,7 +1724,7 @@ void WitchRechargeItem()
else else
myPlayer.InvList[i]._iCharges = myPlayer.InvList[i]._iMaxCharges; myPlayer.InvList[i]._iCharges = myPlayer.InvList[i]._iMaxCharges;
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
} }
void WitchRechargeEnter() void WitchRechargeEnter()
@ -1778,11 +1779,12 @@ void BoyEnter()
void BoyBuyItem() void BoyBuyItem()
{ {
TakePlrsMoney(Players[MyPlayerId].HoldItem._iIvalue); auto &myPlayer = Players[MyPlayerId];
TakePlrsMoney(myPlayer.HoldItem._iIvalue);
StoreAutoPlace(); StoreAutoPlace();
boyitem._itype = ITYPE_NONE; boyitem._itype = ITYPE_NONE;
stextshold = STORE_BOY; stextshold = STORE_BOY;
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
stextlhold = 12; stextlhold = 12;
} }
@ -1791,7 +1793,8 @@ void BoyBuyItem()
*/ */
void HealerBuyItem() void HealerBuyItem()
{ {
auto &item = Players[MyPlayerId].HoldItem; auto &myPlayer = Players[MyPlayerId];
auto &item = myPlayer.HoldItem;
int idx = stextvhold + ((stextlhold - stextup) / 4); int idx = stextvhold + ((stextlhold - stextup) / 4);
if (!gbIsMultiplayer) { if (!gbIsMultiplayer) {
@ -1823,7 +1826,7 @@ void HealerBuyItem()
} }
healitem[idx]._itype = ITYPE_NONE; healitem[idx]._itype = ITYPE_NONE;
} }
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
} }
void BoyBuyEnter() void BoyBuyEnter()
@ -1892,7 +1895,7 @@ void StorytellerIdentifyItem()
} }
myPlayer.HoldItem._iIdentified = true; myPlayer.HoldItem._iIdentified = true;
TakePlrsMoney(myPlayer.HoldItem._iIvalue); TakePlrsMoney(myPlayer.HoldItem._iIvalue);
CalcPlrInv(MyPlayerId, true); CalcPlrInv(myPlayer, true);
} }
void ConfirmEnter() void ConfirmEnter()

2
test/writehero_test.cpp

@ -339,7 +339,7 @@ TEST(Writehero, pfile_write_hero)
pfile_ui_save_create(&info); pfile_ui_save_create(&info);
PkPlayerStruct pks; PkPlayerStruct pks;
PackPlayerTest(&pks); PackPlayerTest(&pks);
UnPackPlayer(&pks, MyPlayerId, true); UnPackPlayer(&pks, Players[MyPlayerId], true);
AssertPlayer(Players[0]); AssertPlayer(Players[0]);
pfile_write_hero(); pfile_write_hero();

Loading…
Cancel
Save