Browse Source

Rename player globals

pull/2319/head
Anders Jenbo 5 years ago
parent
commit
96bf75b502
  1. 8
      Source/automap.cpp
  2. 64
      Source/control.cpp
  3. 88
      Source/controls/plrctrls.cpp
  4. 18
      Source/cursor.cpp
  5. 36
      Source/debug.cpp
  6. 88
      Source/diablo.cpp
  7. 6
      Source/drlg_l1.cpp
  8. 2
      Source/dvlnet/base_protocol.h
  9. 8
      Source/effects.cpp
  10. 12
      Source/gamemenu.cpp
  11. 4
      Source/interfac.cpp
  12. 64
      Source/inv.cpp
  13. 82
      Source/items.cpp
  14. 2
      Source/lighting.cpp
  15. 36
      Source/loadsave.cpp
  16. 2
      Source/mainmenu.cpp
  17. 4
      Source/miniwin/misc_msg.cpp
  18. 262
      Source/missiles.cpp
  19. 132
      Source/monster.cpp
  20. 574
      Source/msg.cpp
  21. 124
      Source/multi.cpp
  22. 718
      Source/objects.cpp
  23. 6
      Source/pack.cpp
  24. 26
      Source/pfile.cpp
  25. 318
      Source/player.cpp
  26. 8
      Source/player.h
  27. 4
      Source/plrmsg.cpp
  28. 10
      Source/portal.cpp
  29. 10
      Source/qol/autopickup.cpp
  30. 2
      Source/qol/itemlabels.cpp
  31. 4
      Source/qol/xpbar.cpp
  32. 28
      Source/quests.cpp
  33. 32
      Source/scrollrt.cpp
  34. 72
      Source/spells.cpp
  35. 120
      Source/stores.cpp
  36. 12
      Source/sync.cpp
  37. 8
      Source/town.cpp
  38. 2
      Source/towners.cpp
  39. 6
      Source/track.cpp
  40. 18
      Source/trigs.cpp
  41. 2
      test/control_test.cpp
  42. 10
      test/effects_test.cpp
  43. 174
      test/inv_test.cpp
  44. 16
      test/pack_test.cpp
  45. 2
      test/player_test.cpp
  46. 6
      test/writehero_test.cpp

8
Source/automap.cpp

@ -209,7 +209,7 @@ void DrawAutomapTile(const Surface &out, Point center, uint16_t automapType)
void SearchAutomapItem(const Surface &out) void SearchAutomapItem(const Surface &out)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
Point tile = myPlayer.position.tile; Point tile = myPlayer.position.tile;
if (myPlayer._pmode == PM_WALK3) { if (myPlayer._pmode == PM_WALK3) {
tile = myPlayer.position.future; tile = myPlayer.position.future;
@ -257,7 +257,7 @@ void DrawAutomapPlr(const Surface &out, int playerId)
{ {
int playerColor = MapColorsPlayer + (8 * playerId) % 128; int playerColor = MapColorsPlayer + (8 * playerId) % 128;
auto &player = plr[playerId]; auto &player = Players[playerId];
Point tile = player.position.tile; Point tile = player.position.tile;
if (player._pmode == PM_WALK3) { if (player._pmode == PM_WALK3) {
tile = player.position.future; tile = player.position.future;
@ -617,8 +617,8 @@ void DrawAutomap(const Surface &out)
} }
for (int playerId = 0; playerId < MAX_PLRS; playerId++) { for (int playerId = 0; playerId < MAX_PLRS; playerId++) {
auto &player = plr[playerId]; auto &player = Players[playerId];
if (player.plrlevel == plr[myplr].plrlevel && player.plractive && !player._pLvlChanging) { if (player.plrlevel == Players[MyPlayerId].plrlevel && player.plractive && !player._pLvlChanging) {
DrawAutomapPlr(out, playerId); DrawAutomapPlr(out, playerId);
} }
} }

64
Source/control.cpp

@ -303,14 +303,14 @@ void SetSpellTrans(spell_type t)
void DrawSpell(const Surface &out) void DrawSpell(const Surface &out)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
spell_id spl = myPlayer._pRSpell; spell_id spl = myPlayer._pRSpell;
spell_type st = myPlayer._pRSplType; spell_type st = myPlayer._pRSplType;
// BUGFIX: Move the next line into the if statement to avoid OOB (SPL_INVALID is -1) (fixed) // BUGFIX: Move the next line into the if statement to avoid OOB (SPL_INVALID is -1) (fixed)
if (st == RSPLTYPE_SPELL && spl != SPL_INVALID) { if (st == RSPLTYPE_SPELL && spl != SPL_INVALID) {
int tlvl = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spl]; int tlvl = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spl];
if (!CheckSpell(myplr, spl, st, true)) if (!CheckSpell(MyPlayerId, spl, st, true))
st = RSPLTYPE_INVALID; st = RSPLTYPE_INVALID;
if (tlvl <= 0) if (tlvl <= 0)
st = RSPLTYPE_INVALID; st = RSPLTYPE_INVALID;
@ -350,7 +350,7 @@ void DrawSpellList(const Surface &out)
ClearPanel(); ClearPanel();
for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) { for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
switch ((spell_type)i) { switch ((spell_type)i) {
case RSPLTYPE_SKILL: case RSPLTYPE_SKILL:
SetSpellTrans(RSPLTYPE_SKILL); SetSpellTrans(RSPLTYPE_SKILL);
@ -476,7 +476,7 @@ void SetSpell()
ClearPanel(); ClearPanel();
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
myPlayer._pRSpell = pSpell; myPlayer._pRSpell = pSpell;
myPlayer._pRSplType = pSplType; myPlayer._pRSplType = pSplType;
@ -488,7 +488,7 @@ void SetSpeedSpell(int slot)
if (pSpell == SPL_INVALID) { if (pSpell == SPL_INVALID) {
return; return;
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
if (myPlayer._pSplHotKey[i] == pSpell && myPlayer._pSplTHotKey[i] == pSplType) if (myPlayer._pSplHotKey[i] == pSpell && myPlayer._pSplTHotKey[i] == pSplType)
myPlayer._pSplHotKey[i] = SPL_INVALID; myPlayer._pSplHotKey[i] = SPL_INVALID;
@ -501,7 +501,7 @@ void ToggleSpell(int slot)
{ {
uint64_t spells; uint64_t spells;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pSplHotKey[slot] == SPL_INVALID) { if (myPlayer._pSplHotKey[slot] == SPL_INVALID) {
return; return;
@ -625,31 +625,31 @@ void DrawFlaskLower(const Surface &out, const Surface &sourceBuffer, int offset,
void DrawLifeFlaskUpper(const Surface &out) void DrawLifeFlaskUpper(const Surface &out)
{ {
constexpr int LifeFlaskUpperOffset = 109; constexpr int LifeFlaskUpperOffset = 109;
DrawFlaskUpper(out, pLifeBuff, LifeFlaskUpperOffset, plr[myplr]._pHPPer); DrawFlaskUpper(out, pLifeBuff, LifeFlaskUpperOffset, Players[MyPlayerId]._pHPPer);
} }
void DrawManaFlaskUpper(const Surface &out) void DrawManaFlaskUpper(const Surface &out)
{ {
constexpr int ManaFlaskUpperOffset = 475; constexpr int ManaFlaskUpperOffset = 475;
DrawFlaskUpper(out, pManaBuff, ManaFlaskUpperOffset, plr[myplr]._pManaPer); DrawFlaskUpper(out, pManaBuff, ManaFlaskUpperOffset, Players[MyPlayerId]._pManaPer);
} }
void DrawLifeFlaskLower(const Surface &out) void DrawLifeFlaskLower(const Surface &out)
{ {
constexpr int LifeFlaskLowerOffset = 96; constexpr int LifeFlaskLowerOffset = 96;
DrawFlaskLower(out, pLifeBuff, LifeFlaskLowerOffset, plr[myplr]._pHPPer); DrawFlaskLower(out, pLifeBuff, LifeFlaskLowerOffset, Players[MyPlayerId]._pHPPer);
} }
void DrawManaFlaskLower(const Surface &out) void DrawManaFlaskLower(const Surface &out)
{ {
constexpr int ManaFlaskLowerOffeset = 464; constexpr int ManaFlaskLowerOffeset = 464;
DrawFlaskLower(out, pManaBuff, ManaFlaskLowerOffeset, plr[myplr]._pManaPer); DrawFlaskLower(out, pManaBuff, ManaFlaskLowerOffeset, Players[MyPlayerId]._pManaPer);
} }
void control_update_life_mana() void control_update_life_mana()
{ {
plr[myplr].UpdateManaPercentage(); Players[MyPlayerId].UpdateManaPercentage();
plr[myplr].UpdateHitPointPercentage(); Players[MyPlayerId].UpdateHitPointPercentage();
} }
void InitControlPan() void InitControlPan()
@ -716,7 +716,7 @@ void InitControlPan()
sbooktab = 0; sbooktab = 0;
sbookflag = false; sbookflag = false;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pClass == HeroClass::Warrior) { if (myPlayer._pClass == HeroClass::Warrior) {
SpellPages[0][0] = SPL_REPAIR; SpellPages[0][0] = SPL_REPAIR;
@ -774,7 +774,7 @@ void DoSpeedBook()
int x = xo + SPLICONLENGTH / 2; int x = xo + SPLICONLENGTH / 2;
int y = yo - SPLICONLENGTH / 2; int y = yo - SPLICONLENGTH / 2;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pRSpell != SPL_INVALID) { if (myPlayer._pRSpell != SPL_INVALID) {
for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) { for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) {
@ -838,7 +838,7 @@ void DoPanBtn()
} }
if (!spselflag && MousePosition.x >= 565 + PANEL_LEFT && MousePosition.x < 621 + PANEL_LEFT && MousePosition.y >= 64 + PANEL_TOP && MousePosition.y < 120 + PANEL_TOP) { if (!spselflag && MousePosition.x >= 565 + PANEL_LEFT && MousePosition.x < 621 + PANEL_LEFT && MousePosition.y >= 64 + PANEL_TOP && MousePosition.y < 120 + PANEL_TOP) {
if ((SDL_GetModState() & KMOD_SHIFT) != 0) { if ((SDL_GetModState() & KMOD_SHIFT) != 0) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
myPlayer._pRSpell = SPL_INVALID; myPlayer._pRSpell = SPL_INVALID;
myPlayer._pRSplType = RSPLTYPE_INVALID; myPlayer._pRSplType = RSPLTYPE_INVALID;
force_redraw = 255; force_redraw = 255;
@ -924,7 +924,7 @@ void CheckPanelInfo()
pinfoflag = true; pinfoflag = true;
strcpy(tempstr, _("Hotkey: 's'")); strcpy(tempstr, _("Hotkey: 's'"));
AddPanelString(tempstr); AddPanelString(tempstr);
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
spell_id v = myPlayer._pRSpell; spell_id v = myPlayer._pRSpell;
if (v != SPL_INVALID) { if (v != SPL_INVALID) {
switch (myPlayer._pRSplType) { switch (myPlayer._pRSplType) {
@ -1112,7 +1112,7 @@ void DrawInfoBox(const Surface &out)
if (spselflag || trigflag) { if (spselflag || trigflag) {
infoclr = UIS_SILVER; infoclr = UIS_SILVER;
} else if (pcurs >= CURSOR_FIRSTITEM) { } else if (pcurs >= CURSOR_FIRSTITEM) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer.HoldItem._itype == ITYPE_GOLD) { if (myPlayer.HoldItem._itype == ITYPE_GOLD) {
int nGold = myPlayer.HoldItem._ivalue; int nGold = myPlayer.HoldItem._ivalue;
strcpy(infostr, fmt::format(ngettext("{:d} gold piece", "{:d} gold pieces", nGold), nGold).c_str()); strcpy(infostr, fmt::format(ngettext("{:d} gold piece", "{:d} gold pieces", nGold), nGold).c_str());
@ -1151,7 +1151,7 @@ void DrawInfoBox(const Surface &out)
} }
if (pcursplr != -1) { if (pcursplr != -1) {
infoclr = UIS_GOLD; infoclr = UIS_GOLD;
auto &target = plr[pcursplr]; auto &target = Players[pcursplr];
strcpy(infostr, target._pName); strcpy(infostr, target._pName);
ClearPanel(); ClearPanel();
strcpy(tempstr, fmt::format(_("{:s}, Level: {:d}"), _(ClassStrTbl[static_cast<std::size_t>(target._pClass)]), target._pLevel).c_str()); strcpy(tempstr, fmt::format(_("{:s}, Level: {:d}"), _(ClassStrTbl[static_cast<std::size_t>(target._pClass)]), target._pLevel).c_str());
@ -1169,7 +1169,7 @@ void DrawChr(const Surface &out)
uint32_t style = UIS_SILVER; uint32_t style = UIS_SILVER;
char chrstr[64]; char chrstr[64];
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
CelDrawTo(out, { 0, 351 }, *pChrPanel, 1); CelDrawTo(out, { 0, 351 }, *pChrPanel, 1);
DrawString(out, myPlayer._pName, { { 20, 32 }, { 131, 0 } }, UIS_SILVER | UIS_CENTER); DrawString(out, myPlayer._pName, { { 20, 32 }, { 131, 0 } }, UIS_SILVER | UIS_CENTER);
@ -1395,7 +1395,7 @@ void DrawLevelUpIcon(const Surface &out)
void CheckChrBtns() void CheckChrBtns()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (chrbtnactive || myPlayer._pStatPts == 0) if (chrbtnactive || myPlayer._pStatPts == 0)
return; return;
@ -1447,7 +1447,7 @@ void ReleaseChrBtns(bool addAllStatPoints)
chrbtn[buttonId] = false; chrbtn[buttonId] = false;
if (ChrBtnsRect[buttonId].Contains(MousePosition)) { if (ChrBtnsRect[buttonId].Contains(MousePosition)) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int statPointsToAdd = 1; int statPointsToAdd = 1;
if (addAllStatPoints) if (addAllStatPoints)
statPointsToAdd = CapStatPointsToAdd(myPlayer._pStatPts, myPlayer, attribute); statPointsToAdd = CapStatPointsToAdd(myPlayer._pStatPts, myPlayer, attribute);
@ -1523,7 +1523,7 @@ void DrawDurIcon(const Surface &out)
x -= SPANEL_WIDTH - (gnScreenWidth - PANEL_WIDTH) / 2; x -= SPANEL_WIDTH - (gnScreenWidth - PANEL_WIDTH) / 2;
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HEAD], x, 4); x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HEAD], x, 4);
x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_CHEST], x, 3); x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_CHEST], x, 3);
x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HAND_LEFT], x, 0); x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HAND_LEFT], x, 0);
@ -1550,7 +1550,7 @@ static void PrintSBookStr(const Surface &out, Point position, const char *text)
spell_type GetSBookTrans(spell_id ii, bool townok) spell_type GetSBookTrans(spell_id ii, bool townok)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if ((myPlayer._pClass == HeroClass::Monk) && (ii == SPL_SEARCH)) if ((myPlayer._pClass == HeroClass::Monk) && (ii == SPL_SEARCH))
return RSPLTYPE_SKILL; return RSPLTYPE_SKILL;
spell_type st = RSPLTYPE_SPELL; spell_type st = RSPLTYPE_SPELL;
@ -1561,7 +1561,7 @@ spell_type GetSBookTrans(spell_id ii, bool townok)
st = RSPLTYPE_SKILL; st = RSPLTYPE_SKILL;
} }
if (st == RSPLTYPE_SPELL) { if (st == RSPLTYPE_SPELL) {
if (!CheckSpell(myplr, ii, st, true)) { if (!CheckSpell(MyPlayerId, ii, st, true)) {
st = RSPLTYPE_INVALID; st = RSPLTYPE_INVALID;
} }
if ((char)(myPlayer._pSplLvl[ii] + myPlayer._pISplLvlAdd) <= 0) { if ((char)(myPlayer._pSplLvl[ii] + myPlayer._pISplLvlAdd) <= 0) {
@ -1588,7 +1588,7 @@ void DrawSpellBook(const Surface &out)
} }
CelDrawTo(out, { sx, 348 }, *pSBkBtnCel, sbooktab + 1); CelDrawTo(out, { sx, 348 }, *pSBkBtnCel, sbooktab + 1);
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells; uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells;
int yp = 55; int yp = 55;
@ -1647,7 +1647,7 @@ void CheckSBook()
{ {
if (MousePosition.x >= RIGHT_PANEL + 11 && MousePosition.x < RIGHT_PANEL + 48 && MousePosition.y >= 18 && MousePosition.y < 314) { if (MousePosition.x >= RIGHT_PANEL + 11 && MousePosition.x < RIGHT_PANEL + 48 && MousePosition.y >= 18 && MousePosition.y < 314) {
spell_id sn = SpellPages[sbooktab][(MousePosition.y - 18) / 43]; spell_id sn = SpellPages[sbooktab][(MousePosition.y - 18) / 43];
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells; uint64_t spl = myPlayer._pMemSpells | myPlayer._pISpells | myPlayer._pAblSpells;
if (sn != SPL_INVALID && (spl & GetSpellBitmask(sn)) != 0) { if (sn != SPL_INVALID && (spl & GetSpellBitmask(sn)) != 0) {
spell_type st = RSPLTYPE_SPELL; spell_type st = RSPLTYPE_SPELL;
@ -1713,7 +1713,7 @@ void control_drop_gold(char vkey)
{ {
char input[6]; char input[6];
if (plr[myplr]._pHitPoints >> 6 <= 0) { if (Players[MyPlayerId]._pHitPoints >> 6 <= 0) {
dropGoldFlag = false; dropGoldFlag = false;
dropGoldValue = 0; dropGoldValue = 0;
return; return;
@ -1723,7 +1723,7 @@ void control_drop_gold(char vkey)
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)
control_remove_gold(myplr, initialDropGoldIndex); control_remove_gold(MyPlayerId, initialDropGoldIndex);
dropGoldFlag = false; dropGoldFlag = false;
} else if (vkey == DVL_VK_ESCAPE) { } else if (vkey == DVL_VK_ESCAPE) {
dropGoldFlag = false; dropGoldFlag = false;
@ -1751,7 +1751,7 @@ static void ControlSetGoldCurs(PlayerStruct &player)
void control_remove_gold(int pnum, int goldIndex) void control_remove_gold(int pnum, int goldIndex)
{ {
auto &player = plr[pnum]; 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;
@ -1795,7 +1795,7 @@ void DrawTalkPan(const Surface &out)
x += 46; x += 46;
int talkBtn = 0; int talkBtn = 0;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (i == myplr) if (i == MyPlayerId)
continue; continue;
uint16_t color = UIS_RED; uint16_t color = UIS_RED;
@ -1812,7 +1812,7 @@ void DrawTalkPan(const Surface &out)
nCel += 4; nCel += 4;
CelDrawTo(out, talkPanPosition, *talkButtons, nCel); CelDrawTo(out, talkPanPosition, *talkButtons, nCel);
} }
auto &player = plr[i]; auto &player = Players[i];
if (player.plractive) { if (player.plractive) {
DrawString(out, player._pName, { { x, y + 60 + talkBtn * 18 }, { 204, 0 } }, color); DrawString(out, player._pName, { { x, y + 60 + talkBtn * 18 }, { 204, 0 } }, color);
} }
@ -1859,7 +1859,7 @@ void control_release_talk_btn()
int p = 0; int p = 0;
for (; p < MAX_PLRS && off != -1; p++) { for (; p < MAX_PLRS && off != -1; p++) {
if (p != myplr) if (p != MyPlayerId)
off--; off--;
} }
if (p <= MAX_PLRS) if (p <= MAX_PLRS)

88
Source/controls/plrctrls.cpp

@ -40,7 +40,7 @@ bool InGameMenu()
|| qtextflag || qtextflag
|| gmenu_is_active() || gmenu_is_active()
|| PauseMode == 2 || PauseMode == 2
|| plr[myplr]._pInvincible; || Players[MyPlayerId]._pInvincible;
} }
namespace { namespace {
@ -54,7 +54,7 @@ int slot = SLOTXY_INV_FIRST;
*/ */
int GetRotaryDistance(Point destination) int GetRotaryDistance(Point destination)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer.position.future == destination) if (myPlayer.position.future == destination)
return -1; return -1;
@ -75,7 +75,7 @@ int GetRotaryDistance(Point destination)
*/ */
int GetMinDistance(Point position) int GetMinDistance(Point position)
{ {
return plr[myplr].position.future.WalkingDistance(position); return Players[MyPlayerId].position.future.WalkingDistance(position);
} }
/** /**
@ -91,7 +91,7 @@ int GetDistance(Point destination, int maxDistance)
} }
int8_t walkpath[MAX_PATH_LENGTH]; int8_t walkpath[MAX_PATH_LENGTH];
int steps = FindPath(PosOkPlayer, myplr, plr[myplr].position.future.x, plr[myplr].position.future.y, destination.x, destination.y, walkpath); int steps = FindPath(PosOkPlayer, MyPlayerId, Players[MyPlayerId].position.future.x, Players[MyPlayerId].position.future.y, destination.x, destination.y, walkpath);
if (steps > maxDistance) if (steps > maxDistance)
return 0; return 0;
@ -104,7 +104,7 @@ int GetDistance(Point destination, int maxDistance)
*/ */
int GetDistanceRanged(Point destination) int GetDistanceRanged(Point destination)
{ {
return plr[myplr].position.future.ExactDistance(destination); return Players[MyPlayerId].position.future.ExactDistance(destination);
} }
/** /**
@ -114,8 +114,8 @@ int GetDistanceRanged(Point destination)
*/ */
void FindItemOrObject() void FindItemOrObject()
{ {
int mx = plr[myplr].position.future.x; int mx = Players[MyPlayerId].position.future.x;
int my = plr[myplr].position.future.y; int my = Players[MyPlayerId].position.future.y;
int rotations = 5; int rotations = 5;
// As the player can not stand on the edge of the map this is safe from OOB // As the player can not stand on the edge of the map this is safe from OOB
@ -176,7 +176,7 @@ void CheckTownersNearby()
bool HasRangedSpell() bool HasRangedSpell()
{ {
int spl = plr[myplr]._pRSpell; int spl = Players[MyPlayerId]._pRSpell;
return spl != SPL_INVALID return spl != SPL_INVALID
&& spl != SPL_TOWN && spl != SPL_TOWN
@ -247,8 +247,8 @@ void FindMeleeTarget()
std::list<SearchNode> queue; std::list<SearchNode> queue;
{ {
const int startX = plr[myplr].position.future.x; const int startX = Players[MyPlayerId].position.future.x;
const int startY = plr[myplr].position.future.y; const int startY = Players[MyPlayerId].position.future.y;
visited[startX][startY] = true; visited[startX][startY] = true;
queue.push_back({ startX, startY, 0 }); queue.push_back({ startX, startY, 0 });
} }
@ -269,7 +269,7 @@ void FindMeleeTarget()
continue; continue;
} }
if (!PosOkPlayer(myplr, { dx, dy })) { if (!PosOkPlayer(MyPlayerId, { dx, dy })) {
visited[dx][dy] = true; visited[dx][dy] = true;
if (dMonster[dx][dy] != 0) { if (dMonster[dx][dy] != 0) {
@ -305,7 +305,7 @@ void FindMeleeTarget()
void CheckMonstersNearby() void CheckMonstersNearby()
{ {
if (plr[myplr]._pwtype == WT_RANGED || HasRangedSpell()) { if (Players[MyPlayerId]._pwtype == WT_RANGED || HasRangedSpell()) {
FindRangedTarget(); FindRangedTarget();
return; return;
} }
@ -322,16 +322,16 @@ void CheckPlayerNearby()
if (pcursmonst != -1) if (pcursmonst != -1)
return; return;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int spl = myPlayer._pRSpell; int spl = myPlayer._pRSpell;
if (gbFriendlyMode && spl != SPL_RESURRECT && spl != SPL_HEALOTHER) if (gbFriendlyMode && spl != SPL_RESURRECT && spl != SPL_HEALOTHER)
return; return;
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
if (i == myplr) if (i == MyPlayerId)
continue; continue;
const auto &player = plr[i]; const auto &player = Players[i];
const int mx = player.position.future.x; const int mx = player.position.future.x;
const int my = player.position.future.y; const int my = player.position.future.y;
if (dPlayer[mx][my] == 0 if (dPlayer[mx][my] == 0
@ -442,13 +442,13 @@ void Interact()
if (leveltype == DTYPE_TOWN && pcursmonst != -1) { if (leveltype == DTYPE_TOWN && pcursmonst != -1) {
NetSendCmdLocParam1(true, CMD_TALKXY, towners[pcursmonst].position, pcursmonst); NetSendCmdLocParam1(true, CMD_TALKXY, towners[pcursmonst].position, pcursmonst);
} else if (pcursmonst != -1) { } else if (pcursmonst != -1) {
if (plr[myplr]._pwtype != WT_RANGED || CanTalkToMonst(pcursmonst)) { if (Players[MyPlayerId]._pwtype != WT_RANGED || CanTalkToMonst(pcursmonst)) {
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst); NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
} else { } else {
NetSendCmdParam1(true, CMD_RATTACKID, pcursmonst); NetSendCmdParam1(true, CMD_RATTACKID, pcursmonst);
} }
} else if (leveltype != DTYPE_TOWN && pcursplr != -1 && !gbFriendlyMode) { } else if (leveltype != DTYPE_TOWN && pcursplr != -1 && !gbFriendlyMode) {
NetSendCmdParam1(true, plr[myplr]._pwtype == WT_RANGED ? CMD_RATTACKPID : CMD_ATTACKPID, pcursplr); NetSendCmdParam1(true, Players[MyPlayerId]._pwtype == WT_RANGED ? CMD_RATTACKPID : CMD_ATTACKPID, pcursplr);
} }
} }
@ -459,7 +459,7 @@ void AttrIncBtnSnap(AxisDirection dir)
if (dir.y == AxisDirectionY_NONE) if (dir.y == AxisDirectionY_NONE)
return; return;
if (chrbtnactive && plr[myplr]._pStatPts <= 0) if (chrbtnactive && Players[MyPlayerId]._pStatPts <= 0)
return; return;
// first, find our cursor location // first, find our cursor location
@ -576,7 +576,7 @@ Size GetItemSizeOnSlot(int slot, char &itemInvId)
{ {
if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) {
int ig = slot - SLOTXY_INV_FIRST; int ig = slot - SLOTXY_INV_FIRST;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
char ii = myPlayer.InvGrid[ig]; char ii = myPlayer.InvGrid[ig];
if (ii != 0) { if (ii != 0) {
int iv = ii; int iv = ii;
@ -614,7 +614,7 @@ void ResetInvCursorPosition()
// search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId
if (itemInvId < 0) { if (itemInvId < 0) {
for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) { for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) {
if (plr[myplr].InvGrid[s] == -itemInvId) { if (Players[MyPlayerId].InvGrid[s] == -itemInvId) {
slot = SLOTXY_INV_FIRST + s; slot = SLOTXY_INV_FIRST + s;
break; break;
} }
@ -670,7 +670,7 @@ void InvMove(AxisDirection dir)
slot = SLOTXY_BELT_LAST; slot = SLOTXY_BELT_LAST;
const int initialSlot = slot; const int initialSlot = slot;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
// when item is on cursor (pcurs > 1), this is the real cursor XY // when item is on cursor (pcurs > 1), this is the real cursor XY
if (dir.x == AxisDirectionX_LEFT) { if (dir.x == AxisDirectionX_LEFT) {
@ -952,7 +952,7 @@ void HotSpellMove(AxisDirection dir)
if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE)
return; return;
int spbslot = plr[myplr]._pRSpell; int spbslot = Players[MyPlayerId]._pRSpell;
for (int r = 0; r < speedspellcount; r++) { for (int r = 0; r < speedspellcount; r++) {
if (MousePosition.x >= speedspellscoords[r].x - SPLICONLENGTH / 2 if (MousePosition.x >= speedspellscoords[r].x - SPLICONLENGTH / 2
&& MousePosition.x < speedspellscoords[r].x + SPLICONLENGTH / 2 && MousePosition.x < speedspellscoords[r].x + SPLICONLENGTH / 2
@ -1053,7 +1053,7 @@ bool IsPathBlocked(Point position, Direction dir)
if (!nSolidTable[dPiece[leftStep.x][leftStep.y]] && !nSolidTable[dPiece[rightStep.x][rightStep.y]]) if (!nSolidTable[dPiece[leftStep.x][leftStep.y]] && !nSolidTable[dPiece[rightStep.x][rightStep.y]])
return false; return false;
return !PosOkPlayer(myplr, leftStep) && !PosOkPlayer(myplr, rightStep); return !PosOkPlayer(MyPlayerId, leftStep) && !PosOkPlayer(MyPlayerId, rightStep);
} }
bool CanChangeDirection(const PlayerStruct &player) bool CanChangeDirection(const PlayerStruct &player)
@ -1071,7 +1071,7 @@ bool CanChangeDirection(const PlayerStruct &player)
void WalkInDir(int playerId, AxisDirection dir) void WalkInDir(int playerId, AxisDirection dir)
{ {
auto &player = plr[playerId]; auto &player = Players[playerId];
if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) { if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) {
if (sgbControllerActive && player.walkpath[0] != WALK_NONE && player.destAction == ACTION_NONE) if (sgbControllerActive && player.walkpath[0] != WALK_NONE && player.destAction == ACTION_NONE)
@ -1118,7 +1118,7 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
if (invflag) { if (invflag) {
return &InvMove; return &InvMove;
} }
if (chrflag && plr[myplr]._pStatPts > 0) { if (chrflag && Players[MyPlayerId]._pStatPts > 0) {
return &AttrIncBtnSnap; return &AttrIncBtnSnap;
} }
if (spselflag) { if (spselflag) {
@ -1207,7 +1207,7 @@ void StoreSpellCoords()
int yo = endY; int yo = endY;
for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) { for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) {
std::uint64_t spells; std::uint64_t spells;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
switch (i) { switch (i) {
case RSPLTYPE_SKILL: case RSPLTYPE_SKILL:
spells = myPlayer._pAblSpells; spells = myPlayer._pAblSpells;
@ -1315,7 +1315,7 @@ void plrctrls_after_check_curs_move()
pcursquest = -1; pcursquest = -1;
cursmx = -1; cursmx = -1;
cursmy = -1; cursmy = -1;
if (plr[myplr]._pInvincible) { if (Players[MyPlayerId]._pInvincible) {
return; return;
} }
if (DoomFlag) { if (DoomFlag) {
@ -1339,20 +1339,20 @@ void plrctrls_every_frame()
void plrctrls_after_game_logic() void plrctrls_after_game_logic()
{ {
Movement(myplr); Movement(MyPlayerId);
} }
void UseBeltItem(int type) void UseBeltItem(int type)
{ {
for (int i = 0; i < MAXBELTITEMS; i++) { for (int i = 0; i < MAXBELTITEMS; i++) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
const int id = AllItemsList[myPlayer.SpdList[i].IDidx].iMiscId; const int id = AllItemsList[myPlayer.SpdList[i].IDidx].iMiscId;
const int spellId = AllItemsList[myPlayer.SpdList[i].IDidx].iSpell; const int spellId = AllItemsList[myPlayer.SpdList[i].IDidx].iSpell;
if ((type == BLT_HEALING && (id == IMISC_HEAL || id == IMISC_FULLHEAL || (id == IMISC_SCROLL && spellId == SPL_HEAL))) if ((type == BLT_HEALING && (id == IMISC_HEAL || id == IMISC_FULLHEAL || (id == IMISC_SCROLL && spellId == SPL_HEAL)))
|| (type == BLT_MANA && (id == IMISC_MANA || id == IMISC_FULLMANA)) || (type == BLT_MANA && (id == IMISC_MANA || id == IMISC_FULLMANA))
|| id == IMISC_REJUV || id == IMISC_FULLREJUV) { || id == IMISC_REJUV || id == IMISC_FULLREJUV) {
if (myPlayer.SpdList[i]._itype > -1) { if (myPlayer.SpdList[i]._itype > -1) {
UseInvItem(myplr, INVITEM_BELT_FIRST + i); UseInvItem(MyPlayerId, INVITEM_BELT_FIRST + i);
break; break;
} }
} }
@ -1376,7 +1376,7 @@ void PerformPrimaryAction()
return; return;
} }
if (chrflag && !chrbtnactive && plr[myplr]._pStatPts > 0) { if (chrflag && !chrbtnactive && Players[MyPlayerId]._pStatPts > 0) {
CheckChrBtns(); CheckChrBtns();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (ChrBtnsRect[i].Contains(MousePosition)) { if (ChrBtnsRect[i].Contains(MousePosition)) {
@ -1393,7 +1393,7 @@ void PerformPrimaryAction()
bool SpellHasActorTarget() bool SpellHasActorTarget()
{ {
int spl = plr[myplr]._pRSpell; int spl = Players[MyPlayerId]._pRSpell;
if (spl == SPL_TOWN || spl == SPL_TELEPORT) if (spl == SPL_TOWN || spl == SPL_TELEPORT)
return false; return false;
@ -1414,10 +1414,10 @@ void UpdateSpellTarget()
pcursmonst = -1; pcursmonst = -1;
int range = 1; int range = 1;
if (plr[myplr]._pRSpell == SPL_TELEPORT) if (Players[MyPlayerId]._pRSpell == SPL_TELEPORT)
range = 4; range = 4;
auto cursm = plr[myplr].position.future + Displacement::fromDirection(plr[myplr]._pdir) * range; auto cursm = Players[MyPlayerId].position.future + Displacement::fromDirection(Players[MyPlayerId]._pdir) * range;
cursmx = cursm.x; cursmx = cursm.x;
cursmy = cursm.y; cursmy = cursm.y;
} }
@ -1427,7 +1427,7 @@ void UpdateSpellTarget()
*/ */
bool TryDropItem() bool TryDropItem()
{ {
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
cursmx = myPlayer.position.future.x + 1; cursmx = myPlayer.position.future.x + 1;
cursmy = myPlayer.position.future.y; cursmy = myPlayer.position.future.y;
@ -1469,7 +1469,7 @@ void PerformSpellAction()
return; return;
} }
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
int spl = myPlayer._pRSpell; int spl = myPlayer._pRSpell;
if ((pcursplr == -1 && (spl == SPL_RESURRECT || spl == SPL_HEALOTHER)) if ((pcursplr == -1 && (spl == SPL_RESURRECT || spl == SPL_HEALOTHER))
|| (pcursobj == -1 && spl == SPL_DISARM)) { || (pcursobj == -1 && spl == SPL_DISARM)) {
@ -1488,7 +1488,7 @@ void CtrlUseInvItem()
if (pcursinvitem == -1) if (pcursinvitem == -1)
return; return;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (pcursinvitem <= INVITEM_INV_LAST) if (pcursinvitem <= INVITEM_INV_LAST)
item = &myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]; item = &myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST];
@ -1503,7 +1503,7 @@ void CtrlUseInvItem()
CheckInvItem(true); // auto-equip if it's an equipment CheckInvItem(true); // auto-equip if it's an equipment
ResetInvCursorPosition(); ResetInvCursorPosition();
} else { } else {
UseInvItem(myplr, pcursinvitem); UseInvItem(MyPlayerId, pcursinvitem);
} }
} }
@ -1524,14 +1524,14 @@ void PerformSecondaryAction()
} else if (pcursobj != -1) { } else if (pcursobj != -1) {
NetSendCmdLocParam1(true, CMD_OPOBJXY, { cursmx, cursmy }, pcursobj); NetSendCmdLocParam1(true, CMD_OPOBJXY, { cursmx, cursmy }, pcursobj);
} else if (pcursmissile != -1) { } else if (pcursmissile != -1) {
MakePlrPath(myplr, missile[pcursmissile].position.tile, true); MakePlrPath(MyPlayerId, missile[pcursmissile].position.tile, true);
plr[myplr].destAction = ACTION_WALK; Players[MyPlayerId].destAction = ACTION_WALK;
} else if (pcurstrig != -1) { } else if (pcurstrig != -1) {
MakePlrPath(myplr, trigs[pcurstrig].position, true); MakePlrPath(MyPlayerId, trigs[pcurstrig].position, true);
plr[myplr].destAction = ACTION_WALK; Players[MyPlayerId].destAction = ACTION_WALK;
} else if (pcursquest != -1) { } else if (pcursquest != -1) {
MakePlrPath(myplr, quests[pcursquest].position, true); MakePlrPath(MyPlayerId, quests[pcursquest].position, true);
plr[myplr].destAction = ACTION_WALK; Players[MyPlayerId].destAction = ACTION_WALK;
} }
} }

18
Source/cursor.cpp

@ -192,7 +192,7 @@ void CelDrawCursor(const Surface &out, Point position, int cursId)
const auto &sprite = GetInvItemSprite(cursId); const auto &sprite = GetInvItemSprite(cursId);
const int frame = GetInvItemFrame(cursId); const int frame = GetInvItemFrame(cursId);
if (IsItemSprite(cursId)) { if (IsItemSprite(cursId)) {
const auto &heldItem = plr[myplr].HoldItem; const auto &heldItem = Players[MyPlayerId].HoldItem;
CelBlitOutlineTo(out, GetOutlineColor(heldItem, true), position, sprite, frame, false); CelBlitOutlineTo(out, GetOutlineColor(heldItem, true), position, sprite, frame, false);
CelDrawItem(heldItem, out, position, sprite, frame); CelDrawItem(heldItem, out, position, sprite, frame);
} else { } else {
@ -228,7 +228,7 @@ void CheckTown()
trigflag = true; trigflag = true;
ClearPanel(); ClearPanel();
strcpy(infostr, _("Town Portal")); strcpy(infostr, _("Town Portal"));
strcpy(tempstr, fmt::format(_("from {:s}"), plr[missile[mx]._misource]._pName).c_str()); strcpy(tempstr, fmt::format(_("from {:s}"), Players[missile[mx]._misource]._pName).c_str());
AddPanelString(tempstr); AddPanelString(tempstr);
cursmx = missile[mx].position.tile.x; cursmx = missile[mx].position.tile.x;
cursmy = missile[mx].position.tile.y; cursmy = missile[mx].position.tile.y;
@ -300,7 +300,7 @@ void CheckCursMove()
int xo = 0; int xo = 0;
int yo = 0; int yo = 0;
CalcTileOffset(&xo, &yo); CalcTileOffset(&xo, &yo);
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
Displacement offset = ScrollInfo.offset; Displacement offset = ScrollInfo.offset;
if (myPlayer.IsWalking()) if (myPlayer.IsWalking())
offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);
@ -574,7 +574,7 @@ void CheckCursMove()
if (pcursmonst == -1) { if (pcursmonst == -1) {
if (!flipflag && mx + 1 < MAXDUNX && dPlayer[mx + 1][my] != 0) { if (!flipflag && mx + 1 < MAXDUNX && dPlayer[mx + 1][my] != 0) {
int8_t bv = dPlayer[mx + 1][my] > 0 ? dPlayer[mx + 1][my] - 1 : -(dPlayer[mx + 1][my] + 1); int8_t bv = dPlayer[mx + 1][my] > 0 ? dPlayer[mx + 1][my] - 1 : -(dPlayer[mx + 1][my] + 1);
if (bv != myplr && plr[bv]._pHitPoints != 0) { if (bv != MyPlayerId && Players[bv]._pHitPoints != 0) {
cursmx = mx + 1; cursmx = mx + 1;
cursmy = my; cursmy = my;
pcursplr = bv; pcursplr = bv;
@ -582,7 +582,7 @@ void CheckCursMove()
} }
if (flipflag && my + 1 < MAXDUNY && dPlayer[mx][my + 1] != 0) { if (flipflag && my + 1 < MAXDUNY && dPlayer[mx][my + 1] != 0) {
int8_t bv = dPlayer[mx][my + 1] > 0 ? dPlayer[mx][my + 1] - 1 : -(dPlayer[mx][my + 1] + 1); int8_t bv = dPlayer[mx][my + 1] > 0 ? dPlayer[mx][my + 1] - 1 : -(dPlayer[mx][my + 1] + 1);
if (bv != myplr && plr[bv]._pHitPoints != 0) { if (bv != MyPlayerId && Players[bv]._pHitPoints != 0) {
cursmx = mx; cursmx = mx;
cursmy = my + 1; cursmy = my + 1;
pcursplr = bv; pcursplr = bv;
@ -590,7 +590,7 @@ void CheckCursMove()
} }
if (dPlayer[mx][my] != 0) { if (dPlayer[mx][my] != 0) {
int8_t bv = dPlayer[mx][my] > 0 ? dPlayer[mx][my] - 1 : -(dPlayer[mx][my] + 1); int8_t bv = dPlayer[mx][my] > 0 ? dPlayer[mx][my] - 1 : -(dPlayer[mx][my] + 1);
if (bv != myplr) { if (bv != MyPlayerId) {
cursmx = mx; cursmx = mx;
cursmy = my; cursmy = my;
pcursplr = bv; pcursplr = bv;
@ -598,7 +598,7 @@ void CheckCursMove()
} }
if ((dFlags[mx][my] & BFLAG_DEAD_PLAYER) != 0) { if ((dFlags[mx][my] & BFLAG_DEAD_PLAYER) != 0) {
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
if (plr[i].position.tile.x == mx && plr[i].position.tile.y == my && i != myplr) { if (Players[i].position.tile.x == mx && Players[i].position.tile.y == my && i != MyPlayerId) {
cursmx = mx; cursmx = mx;
cursmy = my; cursmy = my;
pcursplr = i; pcursplr = i;
@ -610,7 +610,7 @@ void CheckCursMove()
for (int yy = -1; yy < 2; yy++) { for (int yy = -1; yy < 2; yy++) {
if (mx + xx < MAXDUNX && my + yy < MAXDUNY && (dFlags[mx + xx][my + yy] & BFLAG_DEAD_PLAYER) != 0) { if (mx + xx < MAXDUNX && my + yy < MAXDUNY && (dFlags[mx + xx][my + yy] & BFLAG_DEAD_PLAYER) != 0) {
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
if (plr[i].position.tile.x == mx + xx && plr[i].position.tile.y == my + yy && i != myplr) { if (Players[i].position.tile.x == mx + xx && Players[i].position.tile.y == my + yy && i != MyPlayerId) {
cursmx = mx + xx; cursmx = mx + xx;
cursmy = my + yy; cursmy = my + yy;
pcursplr = i; pcursplr = i;
@ -622,7 +622,7 @@ void CheckCursMove()
} }
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dPlayer[mx + 1][my + 1] != 0) { if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dPlayer[mx + 1][my + 1] != 0) {
int8_t bv = dPlayer[mx + 1][my + 1] > 0 ? dPlayer[mx + 1][my + 1] - 1 : -(dPlayer[mx + 1][my + 1] + 1); int8_t bv = dPlayer[mx + 1][my + 1] > 0 ? dPlayer[mx + 1][my + 1] - 1 : -(dPlayer[mx + 1][my + 1] + 1);
if (bv != myplr && plr[bv]._pHitPoints != 0) { if (bv != MyPlayerId && Players[bv]._pHitPoints != 0) {
cursmx = mx + 1; cursmx = mx + 1;
cursmy = my + 1; cursmy = my + 1;
pcursplr = bv; pcursplr = bv;

36
Source/debug.cpp

@ -53,7 +53,7 @@ void CheckDungeonClear()
void GiveGoldCheat() void GiveGoldCheat()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (int8_t &itemId : myPlayer.InvGrid) { for (int8_t &itemId : myPlayer.InvGrid) {
if (itemId != 0) if (itemId != 0)
@ -71,7 +71,7 @@ void GiveGoldCheat()
void TakeGoldCheat() void TakeGoldCheat()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (auto itemId : myPlayer.InvGrid) { for (auto itemId : myPlayer.InvGrid) {
itemId -= 1; itemId -= 1;
@ -89,7 +89,7 @@ void TakeGoldCheat()
void MaxSpellsCheat() void MaxSpellsCheat()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (int i = SPL_FIREBOLT; i < MAX_SPELLS; i++) { for (int i = SPL_FIREBOLT; i < MAX_SPELLS; i++) {
if (GetSpellBookLevel((spell_id)i) != -1) { if (GetSpellBookLevel((spell_id)i) != -1) {
@ -101,7 +101,7 @@ void MaxSpellsCheat()
void SetSpellLevelCheat(spell_id spl, int spllvl) void SetSpellLevelCheat(spell_id spl, int spllvl)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
myPlayer._pMemSpells |= GetSpellBitmask(spl); myPlayer._pMemSpells |= GetSpellBitmask(spl);
myPlayer._pSplLvl[spl] = spllvl; myPlayer._pSplLvl[spl] = spllvl;
@ -142,23 +142,23 @@ void PrintDebugPlayer(bool bNextPlayer)
if (bNextPlayer) if (bNextPlayer)
DebugPlayerId = ((BYTE)DebugPlayerId + 1) & 3; DebugPlayerId = ((BYTE)DebugPlayerId + 1) & 3;
auto &player = plr[DebugPlayerId]; auto &player = Players[DebugPlayerId];
sprintf(dstr, "Plr %i : Active = %i", DebugPlayerId, player.plractive ? 1 : 0); sprintf(dstr, "Plr %i : Active = %i", DebugPlayerId, player.plractive ? 1 : 0);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
if (player.plractive) { if (player.plractive) {
sprintf(dstr, " Plr %i is %s", DebugPlayerId, player._pName); sprintf(dstr, " Plr %i is %s", DebugPlayerId, player._pName);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
sprintf(dstr, " Lvl = %i : Change = %i", player.plrlevel, player._pLvlChanging ? 1 : 0); sprintf(dstr, " Lvl = %i : Change = %i", player.plrlevel, player._pLvlChanging ? 1 : 0);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
const Point target = player.GetTargetPosition(); const Point target = player.GetTargetPosition();
sprintf(dstr, " x = %i, y = %i : tx = %i, ty = %i", player.position.tile.x, player.position.tile.y, target.x, target.y); sprintf(dstr, " x = %i, y = %i : tx = %i, ty = %i", player.position.tile.x, player.position.tile.y, target.x, target.y);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
sprintf(dstr, " mode = %i : daction = %i : walk[0] = %i", player._pmode, player.destAction, player.walkpath[0]); sprintf(dstr, " mode = %i : daction = %i : walk[0] = %i", player._pmode, player.destAction, player.walkpath[0]);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
sprintf(dstr, " inv = %i : hp = %i", player._pInvincible ? 1 : 0, player._pHitPoints); sprintf(dstr, " inv = %i : hp = %i", player._pInvincible ? 1 : 0, player._pHitPoints);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
} }
} }
@ -169,7 +169,7 @@ void PrintDebugQuest()
char dstr[128]; char dstr[128];
sprintf(dstr, "Quest %i : Active = %i, Var1 = %i", DebugQuestId, quests[DebugQuestId]._qactive, quests[DebugQuestId]._qvar1); sprintf(dstr, "Quest %i : Active = %i, Var1 = %i", DebugQuestId, quests[DebugQuestId]._qactive, quests[DebugQuestId]._qvar1);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
DebugQuestId++; DebugQuestId++;
if (DebugQuestId == MAXQUESTS) if (DebugQuestId == MAXQUESTS)
@ -183,13 +183,13 @@ void PrintDebugMonster(int m)
char dstr[128]; char dstr[128];
sprintf(dstr, "Monster %i = %s", m, _(Monsters[m].mName)); sprintf(dstr, "Monster %i = %s", m, _(Monsters[m].mName));
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
sprintf(dstr, "X = %i, Y = %i", Monsters[m].position.tile.x, Monsters[m].position.tile.y); sprintf(dstr, "X = %i, Y = %i", Monsters[m].position.tile.x, Monsters[m].position.tile.y);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
sprintf(dstr, "Enemy = %i, HP = %i", Monsters[m]._menemy, Monsters[m]._mhitpoints); sprintf(dstr, "Enemy = %i, HP = %i", Monsters[m]._menemy, Monsters[m]._mhitpoints);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
sprintf(dstr, "Mode = %i, Var1 = %i", Monsters[m]._mmode, Monsters[m]._mVar1); sprintf(dstr, "Mode = %i, Var1 = %i", Monsters[m]._mmode, Monsters[m]._mVar1);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
bActive = false; bActive = false;
@ -199,7 +199,7 @@ void PrintDebugMonster(int m)
} }
sprintf(dstr, "Active List = %i, Squelch = %i", bActive ? 1 : 0, Monsters[m]._msquelch); sprintf(dstr, "Active List = %i, Squelch = %i", bActive ? 1 : 0, Monsters[m]._msquelch);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
} }
int DebugMonsterId; int DebugMonsterId;
@ -229,7 +229,7 @@ void NextDebugMonster()
DebugMonsterId = 0; DebugMonsterId = 0;
sprintf(dstr, "Current debug monster = %i", DebugMonsterId); sprintf(dstr, "Current debug monster = %i", DebugMonsterId);
NetSendCmdString(1 << myplr, dstr); NetSendCmdString(1 << MyPlayerId, dstr);
} }
#endif #endif

88
Source/diablo.cpp

@ -245,7 +245,7 @@ static void DiabloParseFlags(int argc, char **argv)
leveldebug = true; leveldebug = true;
leveltype = (dungeon_type)SDL_atoi(argv[++i]); leveltype = (dungeon_type)SDL_atoi(argv[++i]);
currlevel = SDL_atoi(argv[++i]); currlevel = SDL_atoi(argv[++i]);
plr[0].plrlevel = currlevel; Players[0].plrlevel = currlevel;
} else if (strcasecmp("-m", argv[i]) == 0) { } else if (strcasecmp("-m", argv[i]) == 0) {
monstdebug = true; monstdebug = true;
DebugMonsters[debugmonsttypes++] = (_monster_id)SDL_atoi(argv[++i]); DebugMonsters[debugmonsttypes++] = (_monster_id)SDL_atoi(argv[++i]);
@ -316,7 +316,7 @@ static void FreeGame()
FreeQuestText(); FreeQuestText();
FreeStoreMem(); FreeStoreMem();
for (auto &player : plr) for (auto &player : Players)
ResetPlayerGFX(player); ResetPlayerGFX(player);
FreeCursor(); FreeCursor();
@ -450,7 +450,7 @@ bool StartGame(bool bNewGame, bool bSinglePlayer)
InitLevels(); InitLevels();
InitQuests(); InitQuests();
InitPortals(); InitPortals();
InitDungMsgs(plr[myplr]); InitDungMsgs(Players[MyPlayerId]);
} }
interface_mode uMsg = WM_DIABNEWGAME; interface_mode uMsg = WM_DIABNEWGAME;
if (gbValidSaveFile && gbLoadGame) { if (gbValidSaveFile && gbLoadGame) {
@ -621,7 +621,7 @@ static bool LeftMouseCmd(bool bShift)
if (pcursitem == -1 && pcursmonst == -1 && pcursplr == -1) if (pcursitem == -1 && pcursmonst == -1 && pcursplr == -1)
return true; return true;
} else { } else {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
bNear = myPlayer.position.tile.WalkingDistance({ cursmx, cursmy }) < 2; bNear = myPlayer.position.tile.WalkingDistance({ cursmx, cursmy }) < 2;
if (pcursitem != -1 && pcurs == CURSOR_HAND && !bShift) { if (pcursitem != -1 && pcurs == CURSOR_HAND && !bShift) {
NetSendCmdLocParam1(true, invflag ? CMD_GOTOGETITEM : CMD_GOTOAGETITEM, { cursmx, cursmy }, pcursitem); NetSendCmdLocParam1(true, invflag ? CMD_GOTOGETITEM : CMD_GOTOAGETITEM, { cursmx, cursmy }, pcursitem);
@ -629,7 +629,7 @@ static bool LeftMouseCmd(bool bShift)
NetSendCmdLocParam1(true, pcurs == CURSOR_DISARM ? CMD_DISARMXY : CMD_OPOBJXY, { cursmx, cursmy }, pcursobj); NetSendCmdLocParam1(true, pcurs == CURSOR_DISARM ? CMD_DISARMXY : CMD_OPOBJXY, { cursmx, cursmy }, pcursobj);
} else if (myPlayer._pwtype == WT_RANGED) { } else if (myPlayer._pwtype == WT_RANGED) {
if (bShift) { if (bShift) {
NetSendCmdLoc(myplr, true, CMD_RATTACKXY, { cursmx, cursmy }); NetSendCmdLoc(MyPlayerId, true, CMD_RATTACKXY, { cursmx, cursmy });
} else if (pcursmonst != -1) { } else if (pcursmonst != -1) {
if (CanTalkToMonst(pcursmonst)) { if (CanTalkToMonst(pcursmonst)) {
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst); NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
@ -645,10 +645,10 @@ static bool LeftMouseCmd(bool bShift)
if (CanTalkToMonst(pcursmonst)) { if (CanTalkToMonst(pcursmonst)) {
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst); NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
} else { } else {
NetSendCmdLoc(myplr, true, CMD_SATTACKXY, { cursmx, cursmy }); NetSendCmdLoc(MyPlayerId, true, CMD_SATTACKXY, { cursmx, cursmy });
} }
} else { } else {
NetSendCmdLoc(myplr, true, CMD_SATTACKXY, { cursmx, cursmy }); NetSendCmdLoc(MyPlayerId, true, CMD_SATTACKXY, { cursmx, cursmy });
} }
} else if (pcursmonst != -1) { } else if (pcursmonst != -1) {
NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst); NetSendCmdParam1(true, CMD_ATTACKID, pcursmonst);
@ -682,7 +682,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_IDENTIFY) { if (pcurs == CURSOR_IDENTIFY) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
CheckIdentify(myplr, pcursinvitem); CheckIdentify(MyPlayerId, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
@ -690,7 +690,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_REPAIR) { if (pcurs == CURSOR_REPAIR) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
DoRepair(myplr, pcursinvitem); DoRepair(MyPlayerId, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
@ -698,7 +698,7 @@ bool TryIconCurs()
if (pcurs == CURSOR_RECHARGE) { if (pcurs == CURSOR_RECHARGE) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
DoRecharge(myplr, pcursinvitem); DoRecharge(MyPlayerId, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
@ -706,20 +706,20 @@ bool TryIconCurs()
if (pcurs == CURSOR_OIL) { if (pcurs == CURSOR_OIL) {
if (pcursinvitem != -1) if (pcursinvitem != -1)
DoOil(myplr, pcursinvitem); DoOil(MyPlayerId, pcursinvitem);
else else
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
} }
if (pcurs == CURSOR_TELEPORT) { if (pcurs == CURSOR_TELEPORT) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (pcursmonst != -1) if (pcursmonst != -1)
NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(myplr, myPlayer._pTSpell)); NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell));
else if (pcursplr != -1) else if (pcursplr != -1)
NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, GetSpellLevel(myplr, myPlayer._pTSpell)); NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell));
else else
NetSendCmdLocParam2(true, CMD_TSPELLXY, { cursmx, cursmy }, myPlayer._pTSpell, GetSpellLevel(myplr, myPlayer._pTSpell)); NetSendCmdLocParam2(true, CMD_TSPELLXY, { cursmx, cursmy }, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell));
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
return true; return true;
} }
@ -743,7 +743,7 @@ static bool LeftMouseDown(int wParam)
if (sgnTimeoutCurs != CURSOR_NONE) if (sgnTimeoutCurs != CURSOR_NONE)
return false; return false;
if (deathflag) { if (MyPlayerIsDead) {
control_check_btn_press(); control_check_btn_press();
return false; return false;
} }
@ -788,7 +788,7 @@ static bool LeftMouseDown(int wParam)
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
} else { } else {
if (plr[myplr]._pStatPts != 0 && !spselflag) if (Players[MyPlayerId]._pStatPts != 0 && !spselflag)
CheckLvlBtn(); CheckLvlBtn();
if (!lvlbtndown) if (!lvlbtndown)
return LeftMouseCmd(isShiftHeld); return LeftMouseCmd(isShiftHeld);
@ -822,7 +822,7 @@ static void LeftMouseUp(int wParam)
static void RightMouseDown() static void RightMouseDown()
{ {
if (gmenu_is_active() || sgnTimeoutCurs != CURSOR_NONE || PauseMode == 2 || plr[myplr]._pInvincible) { if (gmenu_is_active() || sgnTimeoutCurs != CURSOR_NONE || PauseMode == 2 || Players[MyPlayerId]._pInvincible) {
return; return;
} }
@ -839,9 +839,9 @@ static void RightMouseDown()
if (MousePosition.y >= SPANEL_HEIGHT if (MousePosition.y >= SPANEL_HEIGHT
|| ((!sbookflag || MousePosition.x <= RIGHT_PANEL) || ((!sbookflag || MousePosition.x <= RIGHT_PANEL)
&& !TryIconCurs() && !TryIconCurs()
&& (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)))) { && (pcursinvitem == -1 || !UseInvItem(MyPlayerId, pcursinvitem)))) {
if (pcurs == CURSOR_HAND) { if (pcurs == CURSOR_HAND) {
if (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)) if (pcursinvitem == -1 || !UseInvItem(MyPlayerId, pcursinvitem))
CheckPlrSpell(); CheckPlrSpell();
} else if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) { } else if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) {
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
@ -969,7 +969,7 @@ static void PressKey(int vkey)
if (vkey == DVL_VK_MENU || vkey == DVL_VK_LMENU || vkey == DVL_VK_RMENU) if (vkey == DVL_VK_MENU || vkey == DVL_VK_LMENU || vkey == DVL_VK_RMENU)
AltPressed(true); AltPressed(true);
if (deathflag) { if (MyPlayerIsDead) {
if (sgnTimeoutCurs != CURSOR_NONE) { if (sgnTimeoutCurs != CURSOR_NONE) {
return; return;
} }
@ -1075,7 +1075,7 @@ static void PressKey(int vkey)
*/ */
static void PressChar(int32_t vkey) static void PressChar(int32_t vkey)
{ {
if (gmenu_is_active() || control_talk_last_key(vkey) || sgnTimeoutCurs != CURSOR_NONE || deathflag) { if (gmenu_is_active() || control_talk_last_key(vkey) || sgnTimeoutCurs != CURSOR_NONE || MyPlayerIsDead) {
return; return;
} }
if ((char)vkey == 'p' || (char)vkey == 'P') { if ((char)vkey == 'p' || (char)vkey == 'P') {
@ -1114,7 +1114,7 @@ static void PressChar(int32_t vkey)
if (arrowdebug > 2) { if (arrowdebug > 2) {
arrowdebug = 0; arrowdebug = 0;
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (arrowdebug == 0) { if (arrowdebug == 0) {
myPlayer._pIFlags &= ~ISPL_FIRE_ARROWS; myPlayer._pIFlags &= ~ISPL_FIRE_ARROWS;
myPlayer._pIFlags &= ~ISPL_LIGHT_ARROWS; myPlayer._pIFlags &= ~ISPL_LIGHT_ARROWS;
@ -1146,7 +1146,7 @@ static void PressChar(int32_t vkey)
case 'a': case 'a':
if (debug_mode_key_inverted_v) { if (debug_mode_key_inverted_v) {
spelldata[SPL_TELEPORT].sTownSpell = true; spelldata[SPL_TELEPORT].sTownSpell = true;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
myPlayer._pSplLvl[myPlayer._pSpell]++; myPlayer._pSplLvl[myPlayer._pSpell]++;
} }
return; return;
@ -1171,20 +1171,20 @@ static void PressChar(int32_t vkey)
case 'R': case 'R':
case 'r': case 'r':
sprintf(tempstr, "seed = %i", glSeedTbl[currlevel]); sprintf(tempstr, "seed = %i", glSeedTbl[currlevel]);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
sprintf(tempstr, "Mid1 = %i : Mid2 = %i : Mid3 = %i", glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel]); sprintf(tempstr, "Mid1 = %i : Mid2 = %i : Mid3 = %i", glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel]);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
sprintf(tempstr, "End = %i", glEndSeed[currlevel]); sprintf(tempstr, "End = %i", glEndSeed[currlevel]);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
return; return;
case 'T': case 'T':
case 't': case 't':
if (debug_mode_key_inverted_v) { if (debug_mode_key_inverted_v) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
sprintf(tempstr, "PX = %i PY = %i", myPlayer.position.tile.x, myPlayer.position.tile.y); sprintf(tempstr, "PX = %i PY = %i", myPlayer.position.tile.x, myPlayer.position.tile.y);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
sprintf(tempstr, "CX = %i CY = %i DP = %i", cursmx, cursmy, dungeon[cursmx][cursmy]); sprintf(tempstr, "CX = %i CY = %i DP = %i", cursmx, cursmy, dungeon[cursmx][cursmy]);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
} }
return; return;
case '|': case '|':
@ -1453,7 +1453,7 @@ static void UpdateMonsterLights()
for (int i = 0; i < ActiveMonsterCount; i++) { for (int i = 0; i < ActiveMonsterCount; i++) {
MonsterStruct *mon = &Monsters[ActiveMonsters[i]]; MonsterStruct *mon = &Monsters[ActiveMonsters[i]];
if (mon->mlid != NO_LIGHT) { if (mon->mlid != NO_LIGHT) {
if (mon->mlid == plr[myplr]._plid) { // Fix old saves where some monsters had 0 instead of NO_LIGHT if (mon->mlid == Players[MyPlayerId]._plid) { // Fix old saves where some monsters had 0 instead of NO_LIGHT
mon->mlid = NO_LIGHT; mon->mlid = NO_LIGHT;
continue; continue;
} }
@ -1506,7 +1506,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
InitLevelMonsters(); InitLevelMonsters();
IncProgress(); IncProgress();
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (!setlevel) { if (!setlevel) {
CreateLevel(lvldir); CreateLevel(lvldir);
@ -1536,7 +1536,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
IncProgress(); IncProgress();
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
auto &player = plr[i]; 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)
@ -1551,7 +1551,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
bool visited = false; bool visited = false;
int players = gbIsMultiplayer ? MAX_PLRS : 1; int players = gbIsMultiplayer ? MAX_PLRS : 1;
for (int i = 0; i < players; i++) { for (int i = 0; i < players; i++) {
auto &player = plr[i]; auto &player = Players[i];
if (player.plractive) if (player.plractive)
visited = visited || player._pLvlVisited[currlevel]; visited = visited || player._pLvlVisited[currlevel];
} }
@ -1631,7 +1631,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
IncProgress(); IncProgress();
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
auto &player = plr[i]; 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)
@ -1657,8 +1657,8 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
SyncPortals(); SyncPortals();
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
auto &player = plr[i]; auto &player = Players[i];
if (player.plractive && player.plrlevel == currlevel && (!player._pLvlChanging || i == myplr)) { if (player.plractive && player.plrlevel == currlevel && (!player._pLvlChanging || i == MyPlayerId)) {
if (player._pHitPoints > 0) { if (player._pHitPoints > 0) {
if (!gbIsMultiplayer) if (!gbIsMultiplayer)
dPlayer[player.position.tile.x][player.position.tile.y] = i + 1; dPlayer[player.position.tile.x][player.position.tile.y] = i + 1;
@ -1849,10 +1849,10 @@ void itemInfoKeyPressed()
Items[pcursitem].IDidx, Items[pcursitem].IDidx,
Items[pcursitem]._iSeed, Items[pcursitem]._iSeed,
Items[pcursitem]._iCreateInfo); Items[pcursitem]._iCreateInfo);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
} }
sprintf(tempstr, "Numitems : %i", ActiveItemCount); sprintf(tempstr, "Numitems : %i", ActiveItemCount);
NetSendCmdString(1 << myplr, tempstr); NetSendCmdString(1 << MyPlayerId, tempstr);
} }
#endif #endif
@ -1954,7 +1954,7 @@ void spellBookKeyPressed()
bool isPlayerDead() bool isPlayerDead()
{ {
return plr[myplr]._pmode == PM_DEATH || deathflag; return Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead;
} }
void initKeymapActions() void initKeymapActions()
@ -2062,7 +2062,7 @@ void initKeymapActions()
_("Hell"), _("Hell"),
}; };
strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */ "{:s}, version = {:s}, mode = {:s}"), gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty]).c_str()); strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */ "{:s}, version = {:s}, mode = {:s}"), gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty]).c_str());
NetSendCmdString(1 << myplr, pszStr); NetSendCmdString(1 << MyPlayerId, pszStr);
}, },
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
@ -2071,9 +2071,9 @@ void initKeymapActions()
std::string("BeltItem") + std::to_string(i + 1), std::string("BeltItem") + std::to_string(i + 1),
'1' + i, '1' + i,
[i] { [i] {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (!myPlayer.SpdList[i].isEmpty() && myPlayer.SpdList[i]._itype != ITYPE_GOLD) { if (!myPlayer.SpdList[i].isEmpty() && myPlayer.SpdList[i]._itype != ITYPE_GOLD) {
UseInvItem(myplr, INVITEM_BELT_FIRST + i); UseInvItem(MyPlayerId, INVITEM_BELT_FIRST + i);
} }
}, },
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
@ -2112,7 +2112,7 @@ void initKeymapActions()
keymapper.addAction({ keymapper.addAction({
"StopHero", "StopHero",
DVL_VK_INVALID, DVL_VK_INVALID,
[] { plr[myplr].Stop(); }, [] { Players[MyPlayerId].Stop(); },
[&]() { return !isPlayerDead(); }, [&]() { return !isPlayerDead(); },
}); });
} }

6
Source/drlg_l1.cpp

@ -2310,7 +2310,7 @@ static void DrlgL5(lvl_entry entry)
} }
} else if (entry == ENTRY_MAIN) { } else if (entry == ENTRY_MAIN) {
if (currlevel < 21) { if (currlevel < 21) {
if (!plr[myplr].pOriginalCathedral) { if (!Players[MyPlayerId].pOriginalCathedral) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0)
@ -2336,7 +2336,7 @@ static void DrlgL5(lvl_entry entry)
} }
ViewY++; ViewY++;
} }
} else if (!plr[myplr].pOriginalCathedral && entry == ENTRY_PREV) { } else if (!Players[MyPlayerId].pOriginalCathedral && entry == ENTRY_PREV) {
if (currlevel < 21) { if (currlevel < 21) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0)
doneflag = false; doneflag = false;
@ -2360,7 +2360,7 @@ static void DrlgL5(lvl_entry entry)
} }
} else { } else {
if (currlevel < 21) { if (currlevel < 21) {
if (!plr[myplr].pOriginalCathedral) { if (!Players[MyPlayerId].pOriginalCathedral) {
if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0)
doneflag = false; doneflag = false;
if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0)

2
Source/dvlnet/base_protocol.h

@ -155,7 +155,7 @@ template <class P>
void base_protocol<P>::send(packet &pkt) void base_protocol<P>::send(packet &pkt)
{ {
if (pkt.dest() < MAX_PLRS) { if (pkt.dest() < MAX_PLRS) {
if (pkt.dest() == myplr) if (pkt.dest() == MyPlayerId)
return; return;
if (peers[pkt.dest()]) if (peers[pkt.dest()])
proto.send(peers[pkt.dest()], pkt.data()); proto.send(peers[pkt.dest()], pkt.data());

8
Source/effects.cpp

@ -1144,7 +1144,7 @@ void FreeMonsterSnd()
bool calc_snd_position(Point soundPosition, int *plVolume, int *plPan) bool calc_snd_position(Point soundPosition, int *plVolume, int *plPan)
{ {
const auto &playerPosition = plr[myplr].position.tile; const auto &playerPosition = Players[MyPlayerId].position.tile;
const auto delta = soundPosition - playerPosition; const auto delta = soundPosition - playerPosition;
int pan = (delta.deltaX - delta.deltaY) * 256; int pan = (delta.deltaX - delta.deltaY) * 256;
@ -1163,7 +1163,7 @@ bool calc_snd_position(Point soundPosition, int *plVolume, int *plPan)
static void PlaySfxPriv(TSFX *pSFX, bool loc, Point position) static void PlaySfxPriv(TSFX *pSFX, bool loc, Point position)
{ {
if (plr[myplr].pLvlLoad != 0 && gbIsMultiplayer) { if (Players[MyPlayerId].pLvlLoad != 0 && gbIsMultiplayer) {
return; return;
} }
if (!gbSndInited || !gbSoundOn || gbBufferMsgs != 0) { if (!gbSndInited || !gbSoundOn || gbBufferMsgs != 0) {
@ -1194,7 +1194,7 @@ static void PlaySfxPriv(TSFX *pSFX, bool loc, Point position)
void PlayEffect(int i, int mode) void PlayEffect(int i, int mode)
{ {
if (plr[myplr].pLvlLoad != 0) { if (Players[MyPlayerId].pLvlLoad != 0) {
return; return;
} }
@ -1337,7 +1337,7 @@ void sound_init()
if (gbIsHellfire) if (gbIsHellfire)
mask |= sfx_MONK; mask |= sfx_MONK;
} else { } else {
switch (plr[myplr]._pClass) { switch (Players[MyPlayerId]._pClass) {
case HeroClass::Warrior: case HeroClass::Warrior:
case HeroClass::Barbarian: case HeroClass::Barbarian:
mask |= sfx_WARRIOR; mask |= sfx_WARRIOR;

12
Source/gamemenu.cpp

@ -80,14 +80,14 @@ void GamemenuUpdateSingle()
{ {
gmenu_enable(&sgSingleMenu[3], gbValidSaveFile); gmenu_enable(&sgSingleMenu[3], gbValidSaveFile);
bool enable = plr[myplr]._pmode != PM_DEATH && !deathflag; bool enable = Players[MyPlayerId]._pmode != PM_DEATH && !MyPlayerIsDead;
gmenu_enable(&sgSingleMenu[0], enable); gmenu_enable(&sgSingleMenu[0], enable);
} }
void GamemenuUpdateMulti() void GamemenuUpdateMulti()
{ {
gmenu_enable(&sgMultiMenu[2], deathflag); gmenu_enable(&sgMultiMenu[2], MyPlayerIsDead);
} }
void GamemenuPrevious(bool /*bActivate*/) void GamemenuPrevious(bool /*bActivate*/)
@ -97,12 +97,12 @@ void GamemenuPrevious(bool /*bActivate*/)
void GamemenuNewGame(bool /*bActivate*/) void GamemenuNewGame(bool /*bActivate*/)
{ {
for (auto &player : plr) { for (auto &player : Players) {
player._pmode = PM_QUIT; player._pmode = PM_QUIT;
player._pInvincible = true; player._pInvincible = true;
} }
deathflag = false; MyPlayerIsDead = false;
force_redraw = 255; force_redraw = 255;
scrollrt_draw_game_screen(); scrollrt_draw_game_screen();
CornerStone.activated = false; CornerStone.activated = false;
@ -319,7 +319,7 @@ void gamemenu_load_game(bool /*bActivate*/)
ClrDiabloMsg(); ClrDiabloMsg();
CornerStone.activated = false; CornerStone.activated = false;
PaletteFadeOut(8); PaletteFadeOut(8);
deathflag = false; MyPlayerIsDead = false;
force_redraw = 255; force_redraw = 255;
DrawAndBlit(); DrawAndBlit();
LoadPWaterPalette(); LoadPWaterPalette();
@ -335,7 +335,7 @@ void gamemenu_save_game(bool /*bActivate*/)
return; return;
} }
if (plr[myplr]._pmode == PM_DEATH || deathflag) { if (Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead) {
gamemenu_off(); gamemenu_off();
return; return;
} }

4
Source/interfac.cpp

@ -55,7 +55,7 @@ static Cutscenes PickCutscene(interface_mode uMsg)
case WM_DIABPREVLVL: case WM_DIABPREVLVL:
case WM_DIABTOWNWARP: case WM_DIABTOWNWARP:
case WM_DIABTWARPUP: { case WM_DIABTWARPUP: {
int lvl = plr[myplr].plrlevel; int lvl = Players[MyPlayerId].plrlevel;
if (lvl == 1 && uMsg == WM_DIABNEXTLVL) if (lvl == 1 && uMsg == WM_DIABNEXTLVL)
return CutTown; return CutTown;
if (lvl == 16 && uMsg == WM_DIABNEXTLVL) if (lvl == 16 && uMsg == WM_DIABNEXTLVL)
@ -235,7 +235,7 @@ void ShowProgress(interface_mode uMsg)
sound_init(); sound_init();
IncProgress(); IncProgress();
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
switch (uMsg) { switch (uMsg) {
case WM_DIABLOADGAME: case WM_DIABLOADGAME:

64
Source/inv.cpp

@ -141,7 +141,7 @@ void FreeInvGFX()
void InitInv() void InitInv()
{ {
switch (plr[myplr]._pClass) { switch (Players[MyPlayerId]._pClass) {
case HeroClass::Warrior: case HeroClass::Warrior:
case HeroClass::Barbarian: case HeroClass::Barbarian:
pInvCels = LoadCel("Data\\Inv\\Inv.CEL", SPANEL_WIDTH); pInvCels = LoadCel("Data\\Inv\\Inv.CEL", SPANEL_WIDTH);
@ -210,7 +210,7 @@ void DrawInv(const Surface &out)
{ 133, 160 }, // chest { 133, 160 }, // chest
}; };
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (int slot = INVLOC_HEAD; slot < NUM_INVLOC; slot++) { for (int slot = INVLOC_HEAD; slot < NUM_INVLOC; slot++) {
if (!myPlayer.InvBody[slot].isEmpty()) { if (!myPlayer.InvBody[slot].isEmpty()) {
@ -303,7 +303,7 @@ void DrawInvBelt(const Surface &out)
DrawPanelBox(out, { 205, 21, 232, 28 }, { PANEL_X + 205, PANEL_Y + 5 }); DrawPanelBox(out, { 205, 21, 232, 28 }, { PANEL_X + 205, PANEL_Y + 5 });
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (int i = 0; i < MAXBELTITEMS; i++) { for (int i = 0; i < MAXBELTITEMS; i++) {
if (myPlayer.SpdList[i].isEmpty()) { if (myPlayer.SpdList[i].isEmpty()) {
@ -534,7 +534,7 @@ bool CanEquip(PlayerStruct &player, const ItemStruct &item, inv_body_loc bodyLoc
*/ */
bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation, bool persistItem) bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation, bool persistItem)
{ {
auto &player = plr[playerId]; auto &player = Players[playerId];
if (!CanEquip(player, item, bodyLocation)) { if (!CanEquip(player, item, bodyLocation)) {
return false; return false;
@ -543,7 +543,7 @@ bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation,
if (persistItem) { if (persistItem) {
player.InvBody[bodyLocation] = item; player.InvBody[bodyLocation] = item;
if (sgOptions.Audio.bAutoEquipSound && playerId == myplr) { if (sgOptions.Audio.bAutoEquipSound && playerId == MyPlayerId) {
PlaySFX(ItemInvSnds[ItemCAnimTbl[item._iCurs]]); PlaySFX(ItemInvSnds[ItemCAnimTbl[item._iCurs]]);
} }
@ -791,7 +791,7 @@ int SwapItem(ItemStruct *a, ItemStruct *b)
void CheckInvPaste(int pnum, Point cursorPosition) void CheckInvPaste(int pnum, Point cursorPosition)
{ {
auto &player = plr[pnum]; auto &player = Players[pnum];
SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
int i = cursorPosition.x + (IsHardwareCursor() ? 0 : (icursW / 2)); int i = cursorPosition.x + (IsHardwareCursor() ? 0 : (icursW / 2));
@ -922,7 +922,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
if (!done) if (!done)
return; return;
if (pnum == myplr) if (pnum == MyPlayerId)
PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]); PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]);
int cn = CURSOR_HAND; int cn = CURSOR_HAND;
@ -1013,13 +1013,13 @@ void CheckInvPaste(int pnum, Point cursorPosition)
player.HoldItem = player.InvBody[INVLOC_HAND_RIGHT]; player.HoldItem = player.InvBody[INVLOC_HAND_RIGHT];
else else
player.HoldItem = player.InvBody[INVLOC_HAND_LEFT]; player.HoldItem = player.InvBody[INVLOC_HAND_LEFT];
if (pnum == myplr) if (pnum == MyPlayerId)
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
else else
SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done2h = AutoPlaceItemInInventory(player, player.HoldItem, true); bool done2h = AutoPlaceItemInInventory(player, player.HoldItem, true);
player.HoldItem = tempitem; player.HoldItem = tempitem;
if (pnum == myplr) if (pnum == MyPlayerId)
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
else else
SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
@ -1122,7 +1122,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
break; break;
} }
CalcPlrInv(pnum, true); CalcPlrInv(pnum, true);
if (pnum == myplr) { 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));
NewCursor(cn); NewCursor(cn);
@ -1134,7 +1134,7 @@ void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId
memset(&Items[MAXITEMS], 0, sizeof(*Items)); memset(&Items[MAXITEMS], 0, sizeof(*Items));
RecreateItem(MAXITEMS, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0); RecreateItem(MAXITEMS, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
auto &player = plr[pnum]; auto &player = Players[pnum];
player.HoldItem = Items[MAXITEMS]; player.HoldItem = Items[MAXITEMS];
@ -1157,7 +1157,7 @@ void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId
void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove) void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
{ {
auto &player = plr[pnum]; auto &player = Players[pnum];
if (player._pmode > PM_WALK3) { if (player._pmode > PM_WALK3) {
return; return;
@ -1343,7 +1343,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
CalcPlrInv(pnum, true); CalcPlrInv(pnum, true);
CheckItemStats(player); CheckItemStats(player);
if (pnum == myplr) { if (pnum == MyPlayerId) {
if (automaticallyEquipped) { if (automaticallyEquipped) {
PlaySFX(ItemInvSnds[ItemCAnimTbl[holdItem._iCurs]]); PlaySFX(ItemInvSnds[ItemCAnimTbl[holdItem._iCurs]]);
} else if (!automaticMove || automaticallyMoved) { } else if (!automaticMove || automaticallyMoved) {
@ -1373,7 +1373,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
void inv_update_rem_item(int pnum, BYTE iv) void inv_update_rem_item(int pnum, BYTE iv)
{ {
auto &player = plr[pnum]; auto &player = Players[pnum];
if (iv < NUM_INVLOC) { if (iv < NUM_INVLOC) {
player.InvBody[iv]._itype = ITYPE_NONE; player.InvBody[iv]._itype = ITYPE_NONE;
@ -1385,9 +1385,9 @@ void inv_update_rem_item(int pnum, BYTE iv)
void CheckInvItem(bool isShiftHeld) void CheckInvItem(bool isShiftHeld)
{ {
if (pcurs >= CURSOR_FIRSTITEM) { if (pcurs >= CURSOR_FIRSTITEM) {
CheckInvPaste(myplr, MousePosition); CheckInvPaste(MyPlayerId, MousePosition);
} else { } else {
CheckInvCut(myplr, MousePosition, isShiftHeld); CheckInvCut(MyPlayerId, MousePosition, isShiftHeld);
} }
} }
@ -1447,7 +1447,7 @@ static void CheckNaKrulNotes(PlayerStruct &player)
} }
} }
plr[myplr].Say(HeroSpeech::JustWhatIWasLookingFor, 10); Players[MyPlayerId].Say(HeroSpeech::JustWhatIWasLookingFor, 10);
for (auto note : notes) { for (auto note : notes) {
if (idx != note) { if (idx != note) {
@ -1466,7 +1466,7 @@ static void CheckNaKrulNotes(PlayerStruct &player)
static void CheckQuestItem(PlayerStruct &player) static void CheckQuestItem(PlayerStruct &player)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (player.HoldItem.IDidx == IDI_OPTAMULET && quests[Q_BLIND]._qactive == QUEST_ACTIVE) if (player.HoldItem.IDidx == IDI_OPTAMULET && quests[Q_BLIND]._qactive == QUEST_ACTIVE)
quests[Q_BLIND]._qactive = QUEST_DONE; quests[Q_BLIND]._qactive = QUEST_DONE;
@ -1507,7 +1507,7 @@ static void CheckQuestItem(PlayerStruct &player)
quests[Q_GRAVE]._qlog = false; quests[Q_GRAVE]._qlog = false;
quests[Q_GRAVE]._qactive = QUEST_ACTIVE; quests[Q_GRAVE]._qactive = QUEST_ACTIVE;
quests[Q_GRAVE]._qvar1 = 1; quests[Q_GRAVE]._qvar1 = 1;
plr[myplr].Say(HeroSpeech::UhHuh, 10); Players[MyPlayerId].Say(HeroSpeech::UhHuh, 10);
} }
CheckNaKrulNotes(player); CheckNaKrulNotes(player);
@ -1548,9 +1548,9 @@ void InvGetItem(int pnum, ItemStruct *item, int ii)
if (dItem[item->position.x][item->position.y] == 0) if (dItem[item->position.x][item->position.y] == 0)
return; return;
auto &player = plr[pnum]; auto &player = Players[pnum];
if (myplr == pnum && pcurs >= CURSOR_FIRSTITEM) if (MyPlayerId == pnum && pcurs >= CURSOR_FIRSTITEM)
NetSendCmdPItem(true, CMD_SYNCPUTITEM, player.position.tile); NetSendCmdPItem(true, CMD_SYNCPUTITEM, player.position.tile);
item->_iCreateInfo &= ~CF_PREGEN; item->_iCreateInfo &= ~CF_PREGEN;
@ -1583,7 +1583,7 @@ void AutoGetItem(int pnum, ItemStruct *item, int ii)
if (dItem[item->position.x][item->position.y] == 0) if (dItem[item->position.x][item->position.y] == 0)
return; return;
auto &player = plr[pnum]; auto &player = Players[pnum];
item->_iCreateInfo &= ~CF_PREGEN; item->_iCreateInfo &= ~CF_PREGEN;
player.HoldItem = *item; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug player.HoldItem = *item; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug
@ -1612,7 +1612,7 @@ void AutoGetItem(int pnum, ItemStruct *item, int ii)
return; return;
} }
if (pnum == myplr) { if (pnum == MyPlayerId) {
player.Say(HeroSpeech::ICantCarryAnymore); player.Say(HeroSpeech::ICantCarryAnymore);
} }
player.HoldItem = *item; player.HoldItem = *item;
@ -1706,7 +1706,7 @@ bool TryInvPut()
if (ActiveItemCount >= MAXITEMS) if (ActiveItemCount >= MAXITEMS)
return false; return false;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
Direction dir = GetDirection(myPlayer.position.tile, { cursmx, cursmy }); Direction dir = GetDirection(myPlayer.position.tile, { cursmx, cursmy });
if (CanPut(myPlayer.position.tile + dir)) { if (CanPut(myPlayer.position.tile + dir)) {
@ -1877,7 +1877,7 @@ char CheckInvHLight()
int8_t rv = -1; int8_t rv = -1;
infoclr = UIS_SILVER; infoclr = UIS_SILVER;
ItemStruct *pi = nullptr; ItemStruct *pi = nullptr;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
ClearPanel(); ClearPanel();
if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) { if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) {
@ -1970,7 +1970,7 @@ bool UseScroll()
if (pcurs != CURSOR_HAND) if (pcurs != CURSOR_HAND)
return false; return false;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (leveltype == DTYPE_TOWN && !spelldata[myPlayer._pRSpell].sTownSpell) if (leveltype == DTYPE_TOWN && !spelldata[myPlayer._pRSpell].sTownSpell)
return false; return false;
@ -2018,7 +2018,7 @@ bool UseStaff()
return false; return false;
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
return CanUseStaff(myPlayer.InvBody[INVLOC_HAND_LEFT], myPlayer._pRSpell); return CanUseStaff(myPlayer.InvBody[INVLOC_HAND_LEFT], myPlayer._pRSpell);
} }
@ -2027,7 +2027,7 @@ void StartGoldDrop()
{ {
initialDropGoldIndex = pcursinvitem; initialDropGoldIndex = pcursinvitem;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (pcursinvitem <= INVITEM_INV_LAST) if (pcursinvitem <= INVITEM_INV_LAST)
initialDropGoldValue = myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]._ivalue; initialDropGoldValue = myPlayer.InvList[pcursinvitem - INVITEM_INV_FIRST]._ivalue;
@ -2046,9 +2046,9 @@ bool UseInvItem(int pnum, int cii)
int c; int c;
ItemStruct *item; ItemStruct *item;
auto &player = plr[pnum]; auto &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == myplr) if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId)
return true; return true;
if (pcurs != CURSOR_HAND) if (pcurs != CURSOR_HAND)
return true; return true;
@ -2113,7 +2113,7 @@ bool UseInvItem(int pnum, int cii)
int idata = ItemCAnimTbl[item->_iCurs]; int idata = ItemCAnimTbl[item->_iCurs];
if (item->_iMiscId == IMISC_BOOK) if (item->_iMiscId == IMISC_BOOK)
PlaySFX(IS_RBOOK); PlaySFX(IS_RBOOK);
else if (pnum == myplr) else if (pnum == MyPlayerId)
PlaySFX(ItemInvSnds[idata]); PlaySFX(ItemInvSnds[idata]);
UseItem(pnum, item->_iMiscId, item->_iSpell); UseItem(pnum, item->_iMiscId, item->_iSpell);
@ -2144,7 +2144,7 @@ void DoTelekinesis()
if (pcursobj != -1) if (pcursobj != -1)
NetSendCmdParam1(true, CMD_OPOBJT, pcursobj); NetSendCmdParam1(true, CMD_OPOBJT, pcursobj);
if (pcursitem != -1) if (pcursitem != -1)
NetSendCmdGItem(true, CMD_REQUESTAGITEM, myplr, myplr, pcursitem); NetSendCmdGItem(true, CMD_REQUESTAGITEM, MyPlayerId, MyPlayerId, pcursitem);
if (pcursmonst != -1 && !M_Talker(pcursmonst) && Monsters[pcursmonst].mtalkmsg == TEXT_NONE) if (pcursmonst != -1 && !M_Talker(pcursmonst) && Monsters[pcursmonst].mtalkmsg == TEXT_NONE)
NetSendCmdParam1(true, CMD_KNOCKBACK, pcursmonst); NetSendCmdParam1(true, CMD_KNOCKBACK, pcursmonst);
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);

82
Source/items.cpp

@ -553,7 +553,7 @@ void InitItems()
void CalcPlrItemVals(int playerId, bool loadgfx) void CalcPlrItemVals(int playerId, bool loadgfx)
{ {
auto &player = plr[playerId]; auto &player = Players[playerId];
int mind = 0; // min damage int mind = 0; // min damage
int maxd = 0; // max damage int maxd = 0; // max damage
@ -686,7 +686,7 @@ void CalcPlrItemVals(int playerId, bool loadgfx)
lrad = clamp(lrad, 2, 15); lrad = clamp(lrad, 2, 15);
if (player._pLightRad != lrad && playerId == myplr) { if (player._pLightRad != lrad && playerId == MyPlayerId) {
ChangeLightRadius(player._plid, lrad); ChangeLightRadius(player._plid, lrad);
ChangeVisionRadius(player._pvid, lrad); ChangeVisionRadius(player._pvid, lrad);
player._pLightRad = lrad; player._pLightRad = lrad;
@ -795,7 +795,7 @@ 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 == myplr && (player._pHitPoints >> 6) <= 0) { if (playerId == MyPlayerId && (player._pHitPoints >> 6) <= 0) {
SetPlayerHitPoints(playerId, 0); SetPlayerHitPoints(playerId, 0);
} }
@ -1016,17 +1016,17 @@ void CalcPlrBookVals(PlayerStruct &player)
void CalcPlrInv(int playerId, bool loadgfx) void CalcPlrInv(int playerId, bool loadgfx)
{ {
auto &player = plr[playerId]; auto &player = Players[playerId];
CalcPlrItemMin(player); CalcPlrItemMin(player);
CalcSelfItems(player); CalcSelfItems(player);
CalcPlrItemVals(playerId, loadgfx); CalcPlrItemVals(playerId, loadgfx);
CalcPlrItemMin(player); CalcPlrItemMin(player);
if (playerId == myplr) { if (playerId == MyPlayerId) {
CalcPlrBookVals(player); CalcPlrBookVals(player);
player.CalcScrolls(); player.CalcScrolls();
CalcPlrStaff(player); CalcPlrStaff(player);
if (playerId == myplr && currlevel == 0) if (playerId == MyPlayerId && currlevel == 0)
RecalcStoreStats(); RecalcStoreStats();
} }
} }
@ -1095,9 +1095,9 @@ void GetGoldSeed(int pnum, ItemStruct *h)
if (Items[ii]._iSeed == s) if (Items[ii]._iSeed == s)
doneflag = false; doneflag = false;
} }
if (pnum == myplr) { if (pnum == MyPlayerId) {
for (int i = 0; i < plr[pnum]._pNumInv; i++) { for (int i = 0; i < Players[pnum]._pNumInv; i++) {
if (plr[pnum].InvList[i]._iSeed == s) if (Players[pnum].InvList[i]._iSeed == s)
doneflag = false; doneflag = false;
} }
} }
@ -1133,7 +1133,7 @@ void SetPlrHandGoldCurs(ItemStruct *h)
void CreatePlrItems(int playerId) void CreatePlrItems(int playerId)
{ {
auto &player = plr[playerId]; auto &player = Players[playerId];
for (auto &item : player.InvBody) { for (auto &item : player.InvBody) {
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
@ -1992,7 +1992,7 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi
Items[i]._iLMaxDam = 0; Items[i]._iLMaxDam = 0;
break; break;
case IPL_FIRERESCLVL: case IPL_FIRERESCLVL:
Items[i]._iPLFR = 30 - plr[myplr]._pLevel; Items[i]._iPLFR = 30 - Players[MyPlayerId]._pLevel;
Items[i]._iPLFR = std::max<int16_t>(Items[i]._iPLFR, 0); Items[i]._iPLFR = std::max<int16_t>(Items[i]._iPLFR, 0);
break; break;
@ -2030,12 +2030,12 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi
Items[i]._iDamAcFlags |= ISPLHF_ACUNDEAD; Items[i]._iDamAcFlags |= ISPLHF_ACUNDEAD;
break; break;
case IPL_MANATOLIFE: case IPL_MANATOLIFE:
r2 = ((plr[myplr]._pMaxManaBase >> 6) * 50 / 100); r2 = ((Players[MyPlayerId]._pMaxManaBase >> 6) * 50 / 100);
Items[i]._iPLMana -= (r2 << 6); Items[i]._iPLMana -= (r2 << 6);
Items[i]._iPLHP += (r2 << 6); Items[i]._iPLHP += (r2 << 6);
break; break;
case IPL_LIFETOMANA: case IPL_LIFETOMANA:
r2 = ((plr[myplr]._pMaxHPBase >> 6) * 40 / 100); r2 = ((Players[MyPlayerId]._pMaxHPBase >> 6) * 40 / 100);
Items[i]._iPLHP -= (r2 << 6); Items[i]._iPLHP -= (r2 << 6);
Items[i]._iPLMana += (r2 << 6); Items[i]._iPLMana += (r2 << 6);
break; break;
@ -2209,7 +2209,7 @@ void GetItemBonus(int i, int minlvl, int maxlvl, bool onlygood, bool allowspells
void SetupItem(int i) void SetupItem(int i)
{ {
Items[i].SetNewAnimation(plr[myplr].pLvlLoad == 0); Items[i].SetNewAnimation(Players[MyPlayerId].pLvlLoad == 0);
Items[i]._iIdentified = false; Items[i]._iIdentified = false;
} }
@ -2985,14 +2985,14 @@ void CheckIdentify(int pnum, int cii)
ItemStruct *pi; ItemStruct *pi;
if (cii >= NUM_INVLOC) if (cii >= NUM_INVLOC)
pi = &plr[pnum].InvList[cii - NUM_INVLOC]; pi = &Players[pnum].InvList[cii - NUM_INVLOC];
else else
pi = &plr[pnum].InvBody[cii]; pi = &Players[pnum].InvBody[cii];
pi->_iIdentified = true; pi->_iIdentified = true;
CalcPlrInv(pnum, true); CalcPlrInv(pnum, true);
if (pnum == myplr) if (pnum == MyPlayerId)
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
@ -3024,7 +3024,7 @@ void DoRepair(int pnum, int cii)
{ {
ItemStruct *pi; ItemStruct *pi;
auto &player = plr[pnum]; auto &player = Players[pnum];
PlaySfxLoc(IS_REPAIR, player.position.tile); PlaySfxLoc(IS_REPAIR, player.position.tile);
@ -3037,7 +3037,7 @@ void DoRepair(int pnum, int cii)
RepairItem(pi, player._pLevel); RepairItem(pi, player._pLevel);
CalcPlrInv(pnum, true); CalcPlrInv(pnum, true);
if (pnum == myplr) if (pnum == MyPlayerId)
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
@ -3061,7 +3061,7 @@ void DoRecharge(int pnum, int cii)
{ {
ItemStruct *pi; ItemStruct *pi;
auto &player = plr[pnum]; 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 {
@ -3074,7 +3074,7 @@ void DoRecharge(int pnum, int cii)
CalcPlrInv(pnum, true); CalcPlrInv(pnum, true);
} }
if (pnum == myplr) if (pnum == MyPlayerId)
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
@ -3191,11 +3191,11 @@ void DoOil(int pnum, int cii)
{ {
if (cii < NUM_INVLOC && cii != INVLOC_HEAD && (cii <= INVLOC_AMULET || cii > INVLOC_CHEST)) if (cii < NUM_INVLOC && cii != INVLOC_HEAD && (cii <= INVLOC_AMULET || cii > INVLOC_CHEST))
return; return;
auto &player = plr[pnum]; auto &player = Players[pnum];
if (!OilItem(&player.InvBody[cii], player)) if (!OilItem(&player.InvBody[cii], player))
return; return;
CalcPlrInv(pnum, true); CalcPlrInv(pnum, true);
if (pnum == myplr) { if (pnum == MyPlayerId) {
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
} }
@ -3847,7 +3847,7 @@ void PrintItemDur(ItemStruct *x)
void UseItem(int p, item_misc_id mid, spell_id spl) void UseItem(int p, item_misc_id mid, spell_id spl)
{ {
auto &player = plr[p]; auto &player = Players[p];
switch (mid) { switch (mid) {
case IMISC_HEAL: case IMISC_HEAL:
@ -3944,7 +3944,7 @@ void UseItem(int p, item_misc_id mid, spell_id spl)
case IMISC_SCROLL: case IMISC_SCROLL:
if (spelldata[spl].sTargeted) { if (spelldata[spl].sTargeted) {
player._pTSpell = spl; player._pTSpell = spl;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
} else { } else {
ClrPlrPath(player); ClrPlrPath(player);
@ -3954,14 +3954,14 @@ void UseItem(int p, item_misc_id mid, spell_id spl)
player.destAction = ACTION_SPELL; player.destAction = ACTION_SPELL;
player.destParam1 = cursmx; player.destParam1 = cursmx;
player.destParam2 = cursmy; player.destParam2 = cursmy;
if (p == myplr && spl == SPL_NOVA) if (p == MyPlayerId && spl == SPL_NOVA)
NetSendCmdLoc(myplr, true, CMD_NOVA, { cursmx, cursmy }); NetSendCmdLoc(MyPlayerId, true, CMD_NOVA, { cursmx, cursmy });
} }
break; break;
case IMISC_SCROLLT: case IMISC_SCROLLT:
if (spelldata[spl].sTargeted) { if (spelldata[spl].sTargeted) {
player._pTSpell = spl; player._pTSpell = spl;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
} else { } else {
ClrPlrPath(player); ClrPlrPath(player);
@ -3983,7 +3983,7 @@ void UseItem(int p, item_misc_id mid, spell_id spl)
player._pManaBase += spelldata[spl].sManaCost << 6; player._pManaBase += spelldata[spl].sManaCost << 6;
player._pManaBase = std::min(player._pManaBase, player._pMaxManaBase); player._pManaBase = std::min(player._pManaBase, player._pMaxManaBase);
} }
if (p == myplr) if (p == MyPlayerId)
CalcPlrBookVals(player); CalcPlrBookVals(player);
drawmanaflag = true; drawmanaflag = true;
break; break;
@ -4001,7 +4001,7 @@ void UseItem(int p, item_misc_id mid, spell_id spl)
case IMISC_OILHARD: case IMISC_OILHARD:
case IMISC_OILIMP: case IMISC_OILIMP:
player._pOilType = mid; player._pOilType = mid;
if (p != myplr) { if (p != MyPlayerId) {
return; return;
} }
if (sbookflag) { if (sbookflag) {
@ -4020,27 +4020,27 @@ void UseItem(int p, item_misc_id mid, spell_id spl)
break; break;
case IMISC_RUNEF: case IMISC_RUNEF:
player._pTSpell = SPL_RUNEFIRE; player._pTSpell = SPL_RUNEFIRE;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
break; break;
case IMISC_RUNEL: case IMISC_RUNEL:
player._pTSpell = SPL_RUNELIGHT; player._pTSpell = SPL_RUNELIGHT;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
break; break;
case IMISC_GR_RUNEL: case IMISC_GR_RUNEL:
player._pTSpell = SPL_RUNENOVA; player._pTSpell = SPL_RUNENOVA;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
break; break;
case IMISC_GR_RUNEF: case IMISC_GR_RUNEF:
player._pTSpell = SPL_RUNEIMMOLAT; player._pTSpell = SPL_RUNEIMMOLAT;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
break; break;
case IMISC_RUNES: case IMISC_RUNES:
player._pTSpell = SPL_RUNESTONE; player._pTSpell = SPL_RUNESTONE;
if (p == myplr) if (p == MyPlayerId)
NewCursor(CURSOR_TELEPORT); NewCursor(CURSOR_TELEPORT);
break; break;
default: default:
@ -4050,7 +4050,7 @@ void UseItem(int p, item_misc_id mid, spell_id spl)
bool StoreStatOk(ItemStruct *h) bool StoreStatOk(ItemStruct *h)
{ {
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pStrength < h->_iMinStr) if (myPlayer._pStrength < h->_iMinStr)
return false; return false;
@ -4195,7 +4195,7 @@ static void SpawnOnePremium(int i, int plvl, int playerId)
bool keepGoing = false; bool keepGoing = false;
ItemStruct tempItem = Items[0]; ItemStruct tempItem = Items[0];
auto &player = plr[playerId]; auto &player = Players[playerId];
int strength = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Strength), player._pStrength); int strength = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Strength), player._pStrength);
int dexterity = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Dexterity), player._pDexterity); int dexterity = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Dexterity), player._pDexterity);
@ -4277,7 +4277,7 @@ static void SpawnOnePremium(int i, int plvl, int playerId)
void SpawnPremium(int pnum) void SpawnPremium(int pnum)
{ {
int8_t lvl = plr[pnum]._pLevel; int8_t lvl = Players[pnum]._pLevel;
int maxItems = gbIsHellfire ? SMITH_PREMIUM_ITEMS : 6; int maxItems = gbIsHellfire ? SMITH_PREMIUM_ITEMS : 6;
if (numpremium < maxItems) { if (numpremium < maxItems) {
for (int i = 0; i < maxItems; i++) { for (int i = 0; i < maxItems; i++) {
@ -4342,7 +4342,7 @@ void WitchBookLevel(int ii)
if (witchitem[ii]._iMiscId != IMISC_BOOK) if (witchitem[ii]._iMiscId != IMISC_BOOK)
return; return;
witchitem[ii]._iMinMag = spelldata[witchitem[ii]._iSpell].sMinInt; witchitem[ii]._iMinMag = spelldata[witchitem[ii]._iSpell].sMinInt;
int8_t spellLevel = plr[myplr]._pSplLvl[witchitem[ii]._iSpell]; int8_t spellLevel = Players[MyPlayerId]._pSplLvl[witchitem[ii]._iSpell];
while (spellLevel > 0) { while (spellLevel > 0) {
witchitem[ii]._iMinMag += 20 * witchitem[ii]._iMinMag / 100; witchitem[ii]._iMinMag += 20 * witchitem[ii]._iMinMag / 100;
spellLevel--; spellLevel--;
@ -4442,7 +4442,7 @@ void SpawnBoy(int lvl)
bool keepgoing = false; bool keepgoing = false;
int count = 0; int count = 0;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
HeroClass pc = myPlayer._pClass; HeroClass pc = myPlayer._pClass;
int strength = std::max(myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength), myPlayer._pStrength); int strength = std::max(myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength), myPlayer._pStrength);
@ -4562,7 +4562,7 @@ bool HealerItemOk(int i)
return AllItemsList[i].iSpell == SPL_HEALOTHER && gbIsMultiplayer; return AllItemsList[i].iSpell == SPL_HEALOTHER && gbIsMultiplayer;
if (!gbIsMultiplayer) { if (!gbIsMultiplayer) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (AllItemsList[i].iMiscId == IMISC_ELIXSTR) if (AllItemsList[i].iMiscId == IMISC_ELIXSTR)
return !gbIsHellfire || myPlayer._pBaseStr < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength); return !gbIsHellfire || myPlayer._pBaseStr < myPlayer.GetMaximumAttributeValue(CharacterAttribute::Strength);

2
Source/lighting.cpp

@ -940,7 +940,7 @@ void ToggleLighting()
} }
memcpy(dLight, dPreLight, sizeof(dLight)); memcpy(dLight, dPreLight, sizeof(dLight));
for (const auto &player : plr) { for (const auto &player : Players) {
if (player.plractive && player.plrlevel == currlevel) { if (player.plractive && player.plrlevel == currlevel) {
DoLighting(player.position.tile, player._pLightRad, -1); DoLighting(player.position.tile, player._pLightRad, -1);
} }

36
Source/loadsave.cpp

@ -324,7 +324,7 @@ static void LoadItems(LoadHelper *file, const int n, ItemStruct *pItem)
static void LoadPlayer(LoadHelper *file, int p) static void LoadPlayer(LoadHelper *file, int p)
{ {
auto &player = plr[p]; auto &player = Players[p];
player._pmode = static_cast<PLR_MODE>(file->NextLE<int32_t>()); player._pmode = static_cast<PLR_MODE>(file->NextLE<int32_t>());
@ -413,7 +413,7 @@ static void LoadPlayer(LoadHelper *file, int p)
player._pDamageMod = file->NextLE<int32_t>(); player._pDamageMod = file->NextLE<int32_t>();
player._pBaseToBlk = file->NextLE<int32_t>(); player._pBaseToBlk = file->NextLE<int32_t>();
if (player._pBaseToBlk == 0) if (player._pBaseToBlk == 0)
player._pBaseToBlk = ToBlkTbl[static_cast<std::size_t>(player._pClass)]; player._pBaseToBlk = BlockBonuses[static_cast<std::size_t>(player._pClass)];
player._pHPBase = file->NextLE<int32_t>(); player._pHPBase = file->NextLE<int32_t>();
player._pMaxHPBase = file->NextLE<int32_t>(); player._pMaxHPBase = file->NextLE<int32_t>();
player._pHitPoints = file->NextLE<int32_t>(); player._pHitPoints = file->NextLE<int32_t>();
@ -642,7 +642,7 @@ static void LoadMonster(LoadHelper *file, int i)
pMonster->leaderflag = file->NextLE<uint8_t>(); pMonster->leaderflag = file->NextLE<uint8_t>();
pMonster->packsize = file->NextLE<uint8_t>(); pMonster->packsize = file->NextLE<uint8_t>();
pMonster->mlid = file->NextLE<int8_t>(); pMonster->mlid = file->NextLE<int8_t>();
if (pMonster->mlid == plr[myplr]._plid) if (pMonster->mlid == Players[MyPlayerId]._plid)
pMonster->mlid = NO_LIGHT; // Correct incorect values in old saves pMonster->mlid = NO_LIGHT; // Correct incorect values in old saves
// Omit pointer mName; // Omit pointer mName;
@ -1000,7 +1000,7 @@ void LoadHotkeys()
if (!file.IsValid()) if (!file.IsValid())
return; return;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (auto &spellId : myPlayer._pSplHotKey) { for (auto &spellId : myPlayer._pSplHotKey) {
spellId = static_cast<spell_id>(file.NextLE<int32_t>()); spellId = static_cast<spell_id>(file.NextLE<int32_t>());
@ -1014,7 +1014,7 @@ void LoadHotkeys()
void SaveHotkeys() void SaveHotkeys()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
const size_t nHotkeyTypes = sizeof(myPlayer._pSplHotKey) / sizeof(myPlayer._pSplHotKey[0]); const size_t nHotkeyTypes = sizeof(myPlayer._pSplHotKey) / sizeof(myPlayer._pSplHotKey[0]);
const size_t nHotkeySpells = sizeof(myPlayer._pSplTHotKey) / sizeof(myPlayer._pSplTHotKey[0]); const size_t nHotkeySpells = sizeof(myPlayer._pSplTHotKey) / sizeof(myPlayer._pSplTHotKey[0]);
@ -1131,9 +1131,9 @@ void LoadGame(bool firstflag)
file.Skip(4); // Skip loading gnLevelTypeTbl file.Skip(4); // Skip loading gnLevelTypeTbl
} }
LoadPlayer(&file, myplr); LoadPlayer(&file, MyPlayerId);
sgGameInitInfo.nDifficulty = plr[myplr].pDifficulty; sgGameInitInfo.nDifficulty = Players[MyPlayerId].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;
@ -1144,12 +1144,12 @@ void LoadGame(bool firstflag)
if (gbIsHellfireSaveGame != gbIsHellfire) { if (gbIsHellfireSaveGame != gbIsHellfire) {
ConvertLevels(); ConvertLevels();
RemoveEmptyInventory(plr[myplr]); RemoveEmptyInventory(Players[MyPlayerId]);
} }
LoadGameLevel(firstflag, ENTRY_LOAD); LoadGameLevel(firstflag, ENTRY_LOAD);
SyncInitPlr(myplr); SyncInitPlr(MyPlayerId);
SyncPlrAnim(myplr); SyncPlrAnim(MyPlayerId);
ViewX = viewX; ViewX = viewX;
ViewY = viewY; ViewY = viewY;
@ -1258,7 +1258,7 @@ void LoadGame(bool firstflag)
for (int i = 0; i < giNumberOfSmithPremiumItems; i++) for (int i = 0; i < giNumberOfSmithPremiumItems; i++)
LoadPremium(&file, i); LoadPremium(&file, i);
if (gbIsHellfire && !gbIsHellfireSaveGame) if (gbIsHellfire && !gbIsHellfireSaveGame)
SpawnPremium(myplr); SpawnPremium(MyPlayerId);
AutomapActive = file.NextBool8(); AutomapActive = file.NextBool8();
AutoMapScale = file.NextBE<int32_t>(); AutoMapScale = file.NextBE<int32_t>();
@ -1385,7 +1385,7 @@ static void SaveItems(SaveHelper *file, ItemStruct *pItem, const int n)
static void SavePlayer(SaveHelper *file, int p) static void SavePlayer(SaveHelper *file, int p)
{ {
auto &player = plr[p]; 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)
@ -1915,8 +1915,8 @@ void SaveGameData()
file.WriteBE<int32_t>(gnLevelTypeTbl[i]); file.WriteBE<int32_t>(gnLevelTypeTbl[i]);
} }
plr[myplr].pDifficulty = sgGameInitInfo.nDifficulty; Players[MyPlayerId].pDifficulty = sgGameInitInfo.nDifficulty;
SavePlayer(&file, myplr); SavePlayer(&file, MyPlayerId);
for (int i = 0; i < giNumberQuests; i++) for (int i = 0; i < giNumberQuests; i++)
SaveQuest(&file, i); SaveQuest(&file, i);
@ -2034,7 +2034,7 @@ void SaveLevel()
{ {
PFileScopedArchiveWriter scopedWriter; PFileScopedArchiveWriter scopedWriter;
DoUnVision(plr[myplr].position.tile, plr[myplr]._pLightRad); // fix for vision staying on the level DoUnVision(Players[MyPlayerId].position.tile, Players[MyPlayerId]._pLightRad); // fix for vision staying on the level
if (currlevel == 0) if (currlevel == 0)
glSeedTbl[0] = AdvanceRndSeed(); glSeedTbl[0] = AdvanceRndSeed();
@ -2112,9 +2112,9 @@ void SaveLevel()
} }
if (!setlevel) if (!setlevel)
plr[myplr]._pLvlVisited[currlevel] = true; Players[MyPlayerId]._pLvlVisited[currlevel] = true;
else else
plr[myplr]._pSLvlVisited[setlvlnum] = true; Players[MyPlayerId]._pSLvlVisited[setlvlnum] = true;
} }
void LoadLevel() void LoadLevel()
@ -2208,7 +2208,7 @@ void LoadLevel()
UpdateLighting = true; UpdateLighting = true;
} }
for (auto &player : plr) { for (auto &player : Players) {
if (player.plractive && currlevel == player.plrlevel) if (player.plractive && currlevel == player.plrlevel)
Lights[player._plid]._lunflag = true; Lights[player._plid]._lunflag = true;
} }

2
Source/mainmenu.cpp

@ -104,7 +104,7 @@ bool mainmenu_select_hero_dialog(GameData *gameData)
return false; return false;
} }
pfile_read_player_from_save(gszHero, myplr); pfile_read_player_from_save(gszHero, MyPlayerId);
return true; return true;
} }

4
Source/miniwin/misc_msg.cpp

@ -48,7 +48,7 @@ void SetCursorPos(int x, int y)
// Moves the mouse to the first attribute "+" button. // Moves the mouse to the first attribute "+" button.
void FocusOnCharInfo() void FocusOnCharInfo()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (invflag || myPlayer._pStatPts <= 0) if (invflag || myPlayer._pStatPts <= 0)
return; return;
@ -283,7 +283,7 @@ bool BlurInventory()
{ {
if (pcurs >= CURSOR_FIRSTITEM) { if (pcurs >= CURSOR_FIRSTITEM) {
if (!TryDropItem()) { if (!TryDropItem()) {
plr[myplr].Say(HeroSpeech::WhereWouldIPutThis); Players[MyPlayerId].Say(HeroSpeech::WhereWouldIPutThis);
return false; return false;
} }
} }

262
Source/missiles.cpp

@ -67,10 +67,10 @@ int GenerateRndSum(int range, int iterations)
void GetDamageAmt(int i, int *mind, int *maxd) void GetDamageAmt(int i, int *mind, int *maxd)
{ {
assert(myplr >= 0 && myplr < MAX_PLRS); assert(MyPlayerId >= 0 && MyPlayerId < MAX_PLRS);
assert(i >= 0 && i < 64); assert(i >= 0 && i < 64);
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int sl = myPlayer._pSplLvl[i] + myPlayer._pISplLvlAdd; int sl = myPlayer._pSplLvl[i] + myPlayer._pISplLvlAdd;
@ -226,9 +226,9 @@ static int FindClosest(Point source, int rad)
int GetSpellLevel(int playerId, spell_id sn) int GetSpellLevel(int playerId, spell_id sn)
{ {
auto &player = plr[playerId]; auto &player = Players[playerId];
if (playerId != myplr) if (playerId != MyPlayerId)
return 1; // BUGFIX spell level will be wrong in multiplayer return 1; // BUGFIX spell level will be wrong in multiplayer
return std::max(player._pISplLvlAdd + player._pSplLvl[sn], 0); return std::max(player._pISplLvlAdd + player._pSplLvl[sn], 0);
@ -300,9 +300,9 @@ void DeleteMissile(int mi, int i)
{ {
if (missile[mi]._mitype == MIS_MANASHIELD) { if (missile[mi]._mitype == MIS_MANASHIELD) {
int src = missile[mi]._misource; int src = missile[mi]._misource;
if (src == myplr) if (src == MyPlayerId)
NetSendCmd(true, CMD_REMSHIELD); NetSendCmd(true, CMD_REMSHIELD);
plr[src].pManaShield = false; Players[src].pManaShield = false;
} }
missileavail[MAXMISSILES - nummissiles] = mi; missileavail[MAXMISSILES - nummissiles] = mi;
@ -506,7 +506,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
int hit = GenerateRnd(100); int hit = GenerateRnd(100);
int hper = 0; int hper = 0;
if (pnum != -1) { if (pnum != -1) {
const auto &player = plr[pnum]; const auto &player = Players[pnum];
if (missiledata[t].mType == 0) { if (missiledata[t].mType == 0) {
hper = player._pDexterity; hper = player._pDexterity;
hper += player._pIBonusToHit; hper += player._pIBonusToHit;
@ -555,7 +555,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
} }
if (missiledata[t].mType == 0) { if (missiledata[t].mType == 0) {
const auto &player = plr[pnum]; const auto &player = Players[pnum];
dam = player._pIBonusDamMod + dam * player._pIBonusDam / 100 + dam; dam = player._pIBonusDamMod + dam * player._pIBonusDam / 100 + dam;
if (player._pClass == HeroClass::Rogue) if (player._pClass == HeroClass::Rogue)
dam += player._pDamageMod; dam += player._pDamageMod;
@ -568,10 +568,10 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
if (resist) if (resist)
dam >>= 2; dam >>= 2;
if (pnum == myplr) if (pnum == MyPlayerId)
Monsters[m]._mhitpoints -= dam; Monsters[m]._mhitpoints -= dam;
if ((gbIsHellfire && (plr[pnum]._pIFlags & ISPL_NOHEALMON) != 0) || (!gbIsHellfire && (plr[pnum]._pIFlags & ISPL_FIRE_ARROWS) != 0)) if ((gbIsHellfire && (Players[pnum]._pIFlags & ISPL_NOHEALMON) != 0) || (!gbIsHellfire && (Players[pnum]._pIFlags & ISPL_FIRE_ARROWS) != 0))
Monsters[m]._mFlags |= MFLAG_NOHEAL; Monsters[m]._mFlags |= MFLAG_NOHEAL;
if (Monsters[m]._mhitpoints >> 6 <= 0) { if (Monsters[m]._mhitpoints >> 6 <= 0) {
@ -589,7 +589,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
M_StartHit(m, pnum, dam); M_StartHit(m, pnum, dam);
Monsters[m].Petrify(); Monsters[m].Petrify();
} else { } else {
if (missiledata[t].mType == 0 && (plr[pnum]._pIFlags & ISPL_KNOCKBACK) != 0) { if (missiledata[t].mType == 0 && (Players[pnum]._pIFlags & ISPL_KNOCKBACK) != 0) {
M_GetKnockback(m); M_GetKnockback(m);
} }
if (m > MAX_PLRS - 1) if (m > MAX_PLRS - 1)
@ -599,7 +599,7 @@ bool MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, bool
if (Monsters[m]._msquelch == 0) { if (Monsters[m]._msquelch == 0) {
Monsters[m]._msquelch = UINT8_MAX; Monsters[m]._msquelch = UINT8_MAX;
Monsters[m].position.last = plr[pnum].position.tile; Monsters[m].position.last = Players[pnum].position.tile;
} }
return true; return true;
@ -609,7 +609,7 @@ bool PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, bool s
{ {
*blocked = false; *blocked = false;
auto &player = plr[pnum]; auto &player = Players[pnum];
if (player._pHitPoints >> 6 <= 0) { if (player._pHitPoints >> 6 <= 0) {
return false; return false;
@ -728,7 +728,7 @@ bool PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, bool s
if (resper > 0) { if (resper > 0) {
dam -= dam * resper / 100; dam -= dam * resper / 100;
if (pnum == myplr) { if (pnum == MyPlayerId) {
ApplyPlrDamage(pnum, 0, 0, dam, earflag); ApplyPlrDamage(pnum, 0, 0, dam, earflag);
} }
@ -738,7 +738,7 @@ bool PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, bool s
return true; return true;
} }
if (pnum == myplr) { if (pnum == MyPlayerId) {
ApplyPlrDamage(pnum, 0, 0, dam, earflag); ApplyPlrDamage(pnum, 0, 0, dam, earflag);
} }
@ -756,8 +756,8 @@ bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, b
*blocked = false; *blocked = false;
auto &player = plr[pnum]; auto &player = Players[pnum];
auto &target = plr[p]; auto &target = Players[p];
if (target._pInvincible) { if (target._pInvincible) {
return false; return false;
@ -842,7 +842,7 @@ bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, b
dam /= 2; dam /= 2;
if (resper > 0) { if (resper > 0) {
dam -= (dam * resper) / 100; dam -= (dam * resper) / 100;
if (pnum == myplr) if (pnum == MyPlayerId)
NetSendCmdDamage(true, p, dam); NetSendCmdDamage(true, p, dam);
player.Say(HeroSpeech::ArghClang); player.Say(HeroSpeech::ArghClang);
return true; return true;
@ -852,7 +852,7 @@ bool Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, b
StartPlrBlock(p, GetDirection(target.position.tile, player.position.tile)); StartPlrBlock(p, GetDirection(target.position.tile, player.position.tile));
*blocked = true; *blocked = true;
} else { } else {
if (pnum == myplr) if (pnum == MyPlayerId)
NetSendCmdDamage(true, p, dam); NetSendCmdDamage(true, p, dam);
StartPlrHit(p, dam, false); StartPlrHit(p, dam, false);
} }
@ -1127,7 +1127,7 @@ void FreeMissiles2()
void InitMissiles() void InitMissiles()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
AutoMapShowItems = false; AutoMapShowItems = false;
myPlayer._pSpellFlags &= ~0x1; myPlayer._pSpellFlags &= ~0x1;
@ -1136,8 +1136,8 @@ void InitMissiles()
int mi = missileactive[i]; int mi = missileactive[i];
if (missile[mi]._mitype == MIS_INFRA) { if (missile[mi]._mitype == MIS_INFRA) {
int src = missile[mi]._misource; int src = missile[mi]._misource;
if (src == myplr) if (src == MyPlayerId)
CalcPlrItemVals(myplr, true); CalcPlrItemVals(MyPlayerId, true);
} }
} }
} }
@ -1148,10 +1148,10 @@ void InitMissiles()
for (int i = 0; i < nummissiles; ++i) { for (int i = 0; i < nummissiles; ++i) {
int mi = missileactive[i]; int mi = missileactive[i];
if (missile[mi]._mitype == MIS_BLODBOIL) { if (missile[mi]._mitype == MIS_BLODBOIL) {
if (missile[mi]._misource == myplr) { if (missile[mi]._misource == MyPlayerId) {
int missingHP = myPlayer._pMaxHP - myPlayer._pHitPoints; int missingHP = myPlayer._pMaxHP - myPlayer._pHitPoints;
CalcPlrItemVals(myplr, true); CalcPlrItemVals(MyPlayerId, true);
ApplyPlrDamage(myplr, 0, 1, missingHP + missile[mi]._miVar2); ApplyPlrDamage(MyPlayerId, 0, 1, missingHP + missile[mi]._miVar2);
} }
} }
} }
@ -1303,7 +1303,7 @@ void AddReflection(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /
if (missile[mi]._mispllvl != 0) if (missile[mi]._mispllvl != 0)
lvl = missile[mi]._mispllvl; lvl = missile[mi]._mispllvl;
plr[id].wReflections += lvl * plr[id]._pLevel; Players[id].wReflections += lvl * Players[id]._pLevel;
UseMana(id, SPL_REFLECT); UseMana(id, SPL_REFLECT);
} }
@ -1422,7 +1422,7 @@ void AddStealPotions(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t /*m
int8_t pnum = dPlayer[tx][ty]; int8_t pnum = dPlayer[tx][ty];
if (pnum == 0) if (pnum == 0)
continue; continue;
auto &player = plr[pnum > 0 ? pnum - 1 : -(pnum + 1)]; auto &player = Players[pnum > 0 ? pnum - 1 : -(pnum + 1)];
bool hasPlayedSFX = false; bool hasPlayedSFX = false;
for (int si = 0; si < MAXBELTITEMS; si++) { for (int si = 0; si < MAXBELTITEMS; si++) {
@ -1495,7 +1495,7 @@ void AddManaTrap(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t /*miene
if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) { if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) {
int8_t pid = dPlayer[tx][ty]; int8_t pid = dPlayer[tx][ty];
if (pid != 0) { if (pid != 0) {
auto &player = plr[(pid > 0) ? pid - 1 : -(pid + 1)]; auto &player = Players[(pid > 0) ? pid - 1 : -(pid + 1)];
player._pMana = 0; player._pMana = 0;
player._pManaBase = player._pMana + player._pMaxManaBase - player._pMaxMana; player._pManaBase = player._pMana + player._pMaxManaBase - player._pMaxMana;
@ -1515,7 +1515,7 @@ void AddSpecArrow(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t mienem
int av = 0; int av = 0;
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
auto &player = plr[id]; auto &player = Players[id];
if (player._pClass == HeroClass::Rogue) if (player._pClass == HeroClass::Rogue)
av += (player._pLevel - 1) / 4; av += (player._pLevel - 1) / 4;
@ -1542,7 +1542,7 @@ void AddWarp(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t mienemy, in
{ {
int minDistanceSq = std::numeric_limits<int>::max(); int minDistanceSq = std::numeric_limits<int>::max();
if (id >= 0) { if (id >= 0) {
src = plr[id].position.tile; src = Players[id].position.tile;
} }
Point tile = src; Point tile = src;
@ -1580,15 +1580,15 @@ void AddLightningWall(int mi, Point src, Point dst, int /*midir*/, int8_t /*mien
missile[mi]._miVar1 = src.x; missile[mi]._miVar1 = src.x;
missile[mi]._miVar2 = src.y; missile[mi]._miVar2 = src.y;
} else { } else {
missile[mi]._miVar1 = plr[id].position.tile.x; missile[mi]._miVar1 = Players[id].position.tile.x;
missile[mi]._miVar2 = plr[id].position.tile.y; missile[mi]._miVar2 = Players[id].position.tile.y;
} }
} }
void AddRuneExplosion(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/) void AddRuneExplosion(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/)
{ {
if (mienemy == TARGET_MONSTERS || mienemy == TARGET_BOTH) { if (mienemy == TARGET_MONSTERS || mienemy == TARGET_BOTH) {
int dmg = 2 * (plr[id]._pLevel + GenerateRndSum(10, 2)) + 4; int dmg = 2 * (Players[id]._pLevel + GenerateRndSum(10, 2)) + 4;
dmg = ScaleSpellEffect(dmg, missile[mi]._mispllvl); dmg = ScaleSpellEffect(dmg, missile[mi]._mispllvl);
missile[mi]._midam = dmg; missile[mi]._midam = dmg;
@ -1612,7 +1612,7 @@ void AddImmolation(int mi, Point src, Point dst, int midir, int8_t mienemy, int
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
sp += std::min(missile[mi]._mispllvl * 2, 34); sp += std::min(missile[mi]._mispllvl * 2, 34);
int dmg = 2 * (plr[id]._pLevel + GenerateRndSum(10, 2)) + 4; int dmg = 2 * (Players[id]._pLevel + GenerateRndSum(10, 2)) + 4;
missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl); missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl);
UseMana(id, SPL_FIREBALL); UseMana(id, SPL_FIREBALL);
@ -1662,15 +1662,15 @@ void AddLightningArrow(int mi, Point src, Point dst, int midir, int8_t /*mienemy
missile[mi]._miVar1 = src.x; missile[mi]._miVar1 = src.x;
missile[mi]._miVar2 = src.y; missile[mi]._miVar2 = src.y;
} else { } else {
missile[mi]._miVar1 = plr[id].position.tile.x; missile[mi]._miVar1 = Players[id].position.tile.x;
missile[mi]._miVar2 = plr[id].position.tile.y; missile[mi]._miVar2 = Players[id].position.tile.y;
} }
missile[mi]._midam <<= 6; missile[mi]._midam <<= 6;
} }
void AddMana(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddMana(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
auto &player = plr[id]; auto &player = Players[id];
int manaAmount = (GenerateRnd(10) + 1) << 6; int manaAmount = (GenerateRnd(10) + 1) << 6;
for (int i = 0; i < player._pLevel; i++) { for (int i = 0; i < player._pLevel; i++) {
@ -1696,7 +1696,7 @@ void AddMana(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*miene
void AddMagi(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddMagi(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
auto &player = plr[id]; auto &player = Players[id];
player._pMana = player._pMaxMana; player._pMana = player._pMaxMana;
player._pManaBase = player._pMaxManaBase; player._pManaBase = player._pMaxManaBase;
@ -1736,7 +1736,7 @@ void AddSearch(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t miene
AutoMapShowItems = true; AutoMapShowItems = true;
int lvl = 2; int lvl = 2;
if (id > -1) if (id > -1)
lvl = plr[id]._pLevel * 2; lvl = Players[id]._pLevel * 2;
missile[mi]._mirange = lvl + 10 * missile[mi]._mispllvl + 245; missile[mi]._mirange = lvl + 10 * missile[mi]._mispllvl + 245;
if (mienemy == TARGET_MONSTERS) if (mienemy == TARGET_MONSTERS)
UseMana(id, SPL_SEARCH); UseMana(id, SPL_SEARCH);
@ -1783,7 +1783,7 @@ void AddLArrow(int mi, Point src, Point dst, int midir, int8_t mienemy, int id,
} }
int av = 32; int av = 32;
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
auto &player = plr[id]; auto &player = Players[id];
if (player._pClass == HeroClass::Rogue) if (player._pClass == HeroClass::Rogue)
av += (player._pLevel) / 4; av += (player._pLevel) / 4;
else if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Bard) else if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Bard)
@ -1819,7 +1819,7 @@ void AddArrow(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, i
} }
int av = 32; int av = 32;
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
auto &player = plr[id]; auto &player = Players[id];
if ((player._pIFlags & ISPL_RNDARROWVEL) != 0) { if ((player._pIFlags & ISPL_RNDARROWVEL) != 0) {
av = GenerateRnd(32) + 16; av = GenerateRnd(32) + 16;
@ -1852,7 +1852,7 @@ void UpdateVileMissPos(int mi, Point dst)
int yy = j + dst.y; int yy = j + dst.y;
for (int i = -k; i <= k; i++) { for (int i = -k; i <= k; i++) {
int xx = i + dst.x; int xx = i + dst.x;
if (PosOkPlayer(myplr, { xx, yy })) { if (PosOkPlayer(MyPlayerId, { xx, yy })) {
missile[mi].position.tile = { xx, yy }; missile[mi].position.tile = { xx, yy };
return; return;
} }
@ -1901,7 +1901,7 @@ void AddRndTeleport(int mi, Point src, Point dst, int /*midir*/, int8_t mienemy,
// BUGFIX: should only run magic circle check if dObject[dx][dy] is non-zero. // BUGFIX: should only run magic circle check if dObject[dx][dy] is non-zero.
if (object[oi]._otype == OBJ_MCIRCLE1 || object[oi]._otype == OBJ_MCIRCLE2) { if (object[oi]._otype == OBJ_MCIRCLE1 || object[oi]._otype == OBJ_MCIRCLE2) {
missile[mi].position.tile = dst; missile[mi].position.tile = dst;
if (!PosOkPlayer(myplr, dst)) if (!PosOkPlayer(MyPlayerId, dst))
UpdateVileMissPos(mi, dst); UpdateVileMissPos(mi, dst);
} }
} }
@ -1997,15 +1997,15 @@ void AddLightball(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*
missile[mi]._miVar1 = src.x; missile[mi]._miVar1 = src.x;
missile[mi]._miVar2 = src.y; missile[mi]._miVar2 = src.y;
} else { } else {
missile[mi]._miVar1 = plr[id].position.tile.x; missile[mi]._miVar1 = Players[id].position.tile.x;
missile[mi]._miVar2 = plr[id].position.tile.y; missile[mi]._miVar2 = Players[id].position.tile.y;
} }
} }
void AddFirewall(int mi, Point src, Point dst, int /*midir*/, int8_t mienemy, int id, int /*dam*/) void AddFirewall(int mi, Point src, Point dst, int /*midir*/, int8_t mienemy, int id, int /*dam*/)
{ {
missile[mi]._midam = GenerateRndSum(10, 2) + 2; missile[mi]._midam = GenerateRndSum(10, 2) + 2;
missile[mi]._midam += id >= 0 ? plr[id]._pLevel : currlevel; // BUGFIX: missing parenthesis around ternary (fixed) missile[mi]._midam += id >= 0 ? Players[id]._pLevel : currlevel; // BUGFIX: missing parenthesis around ternary (fixed)
missile[mi]._midam <<= 3; missile[mi]._midam <<= 3;
UpdateMissileVel(mi, src, dst, 16); UpdateMissileVel(mi, src, dst, 16);
int i = missile[mi]._mispllvl; int i = missile[mi]._mispllvl;
@ -2015,7 +2015,7 @@ void AddFirewall(int mi, Point src, Point dst, int /*midir*/, int8_t mienemy, in
if (mienemy == TARGET_PLAYERS || id < 0) if (mienemy == TARGET_PLAYERS || id < 0)
missile[mi]._mirange += currlevel; missile[mi]._mirange += currlevel;
else else
missile[mi]._mirange += (plr[id]._pISplDur * missile[mi]._mirange) / 128; missile[mi]._mirange += (Players[id]._pISplDur * missile[mi]._mirange) / 128;
missile[mi]._mirange *= 16; missile[mi]._mirange *= 16;
missile[mi]._miVar1 = missile[mi]._mirange - missile[mi]._miAnimLen; missile[mi]._miVar1 = missile[mi]._mirange - missile[mi]._miAnimLen;
missile[mi]._miVar2 = 0; missile[mi]._miVar2 = 0;
@ -2030,7 +2030,7 @@ void AddFireball(int mi, Point src, Point dst, int midir, int8_t mienemy, int id
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
sp += std::min(missile[mi]._mispllvl * 2, 34); sp += std::min(missile[mi]._mispllvl * 2, 34);
int dmg = 2 * (plr[id]._pLevel + GenerateRndSum(10, 2)) + 4; int dmg = 2 * (Players[id]._pLevel + GenerateRndSum(10, 2)) + 4;
missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl); missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl);
UseMana(id, SPL_FIREBALL); UseMana(id, SPL_FIREBALL);
@ -2174,7 +2174,7 @@ void AddTown(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t /*mienemy*/
missile[mx]._mirange = 0; missile[mx]._mirange = 0;
} }
PutMissile(mi); PutMissile(mi);
if (id == myplr && !missile[mi]._miDelFlag && currlevel != 0) { if (id == MyPlayerId && !missile[mi]._miDelFlag && currlevel != 0) {
if (!setlevel) { if (!setlevel) {
NetSendCmdLocParam3(true, CMD_ACTIVATEPORTAL, { tx, ty }, currlevel, leveltype, 0); NetSendCmdLocParam3(true, CMD_ACTIVATEPORTAL, { tx, ty }, currlevel, leveltype, 0);
} else { } else {
@ -2187,7 +2187,7 @@ void AddFlash(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienem
{ {
if (id != -1) { if (id != -1) {
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
int dmg = GenerateRndSum(20, plr[id]._pLevel + 1) + plr[id]._pLevel + 1; int dmg = GenerateRndSum(20, Players[id]._pLevel + 1) + Players[id]._pLevel + 1;
missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl); missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl);
missile[mi]._midam += missile[mi]._midam / 2; missile[mi]._midam += missile[mi]._midam / 2;
UseMana(id, SPL_FLASH); UseMana(id, SPL_FLASH);
@ -2204,7 +2204,7 @@ void AddFlash2(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t miene
{ {
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
if (id != -1) { if (id != -1) {
int dmg = GenerateRndSum(20, plr[id]._pLevel + 1) + plr[id]._pLevel + 1; int dmg = GenerateRndSum(20, Players[id]._pLevel + 1) + Players[id]._pLevel + 1;
missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl); missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl);
missile[mi]._midam += missile[mi]._midam / 2; missile[mi]._midam += missile[mi]._midam / 2;
} else { } else {
@ -2217,17 +2217,17 @@ void AddFlash2(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t miene
void AddManashield(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/) void AddManashield(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/)
{ {
missile[mi]._mirange = 48 * plr[id]._pLevel; missile[mi]._mirange = 48 * Players[id]._pLevel;
if (mienemy == TARGET_MONSTERS) if (mienemy == TARGET_MONSTERS)
UseMana(id, SPL_MANASHIELD); UseMana(id, SPL_MANASHIELD);
if (id == myplr) if (id == MyPlayerId)
NetSendCmd(true, CMD_SETSHIELD); NetSendCmd(true, CMD_SETSHIELD);
plr[id].pManaShield = true; Players[id].pManaShield = true;
} }
void AddFiremove(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddFiremove(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
missile[mi]._midam = GenerateRnd(10) + plr[id]._pLevel + 1; missile[mi]._midam = GenerateRnd(10) + Players[id]._pLevel + 1;
UpdateMissileVel(mi, src, dst, 16); UpdateMissileVel(mi, src, dst, 16);
missile[mi]._mirange = 255; missile[mi]._mirange = 255;
missile[mi]._miVar1 = 0; missile[mi]._miVar1 = 0;
@ -2239,7 +2239,7 @@ void AddFiremove(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/
void AddGuardian(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddGuardian(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
int dmg = GenerateRnd(10) + (plr[id]._pLevel / 2) + 1; int dmg = GenerateRnd(10) + (Players[id]._pLevel / 2) + 1;
missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl); missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl);
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
@ -2268,8 +2268,8 @@ void AddGuardian(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/
if (!missile[mi]._miDelFlag) { if (!missile[mi]._miDelFlag) {
missile[mi]._misource = id; missile[mi]._misource = id;
missile[mi]._mlid = AddLight(missile[mi].position.tile, 1); missile[mi]._mlid = AddLight(missile[mi].position.tile, 1);
missile[mi]._mirange = missile[mi]._mispllvl + (plr[id]._pLevel / 2); missile[mi]._mirange = missile[mi]._mispllvl + (Players[id]._pLevel / 2);
missile[mi]._mirange += (missile[mi]._mirange * plr[id]._pISplDur) / 128; missile[mi]._mirange += (missile[mi]._mirange * Players[id]._pISplDur) / 128;
if (missile[mi]._mirange > 30) if (missile[mi]._mirange > 30)
missile[mi]._mirange = 30; missile[mi]._mirange = 30;
@ -2473,7 +2473,7 @@ void AddStone(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t /*mienemy*
missile[mi].position.tile = { tx, ty }; missile[mi].position.tile = { tx, ty };
missile[mi].position.start = missile[mi].position.tile; missile[mi].position.start = missile[mi].position.tile;
missile[mi]._mirange = missile[mi]._mispllvl + 6; missile[mi]._mirange = missile[mi]._mispllvl + 6;
missile[mi]._mirange += (missile[mi]._mirange * plr[id]._pISplDur) / 128; missile[mi]._mirange += (missile[mi]._mirange * Players[id]._pISplDur) / 128;
if (missile[mi]._mirange > 15) if (missile[mi]._mirange > 15)
missile[mi]._mirange = 15; missile[mi]._mirange = 15;
@ -2497,14 +2497,14 @@ void AddGolem(int mi, Point src, Point dst, int /*midir*/, int8_t /*mienemy*/, i
missile[mi]._miVar2 = src.y; missile[mi]._miVar2 = src.y;
missile[mi]._miVar4 = dst.x; missile[mi]._miVar4 = dst.x;
missile[mi]._miVar5 = dst.y; missile[mi]._miVar5 = dst.y;
if ((Monsters[id].position.tile.x != 1 || Monsters[id].position.tile.y != 0) && id == myplr) if ((Monsters[id].position.tile.x != 1 || Monsters[id].position.tile.y != 0) && id == MyPlayerId)
M_StartKill(id, id); M_StartKill(id, id);
UseMana(id, SPL_GOLEM); UseMana(id, SPL_GOLEM);
} }
void AddEtherealize(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/) void AddEtherealize(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/)
{ {
auto &player = plr[id]; auto &player = Players[id];
int range = 8 * player._pLevel; int range = 8 * player._pLevel;
missile[mi]._mirange = ScaleSpellEffect(range, missile[mi]._mispllvl); missile[mi]._mirange = ScaleSpellEffect(range, missile[mi]._mispllvl);
@ -2547,7 +2547,7 @@ void AddBoom(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t /*mienemy*/
void AddHeal(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddHeal(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
auto &player = plr[id]; auto &player = Players[id];
int hp = (GenerateRnd(10) + 1) << 6; int hp = (GenerateRnd(10) + 1) << 6;
for (int i = 0; i < player._pLevel; i++) { for (int i = 0; i < player._pLevel; i++) {
@ -2575,7 +2575,7 @@ void AddHealOther(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*
{ {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
UseMana(id, SPL_HEALOTHER); UseMana(id, SPL_HEALOTHER);
if (id == myplr) { if (id == MyPlayerId) {
NewCursor(CURSOR_HEALOTHER); NewCursor(CURSOR_HEALOTHER);
if (sgbControllerActive) if (sgbControllerActive)
TryIconCurs(); TryIconCurs();
@ -2588,7 +2588,7 @@ void AddElement(int mi, Point src, Point dst, int midir, int8_t /*mienemy*/, int
dst += static_cast<Direction>(midir); dst += static_cast<Direction>(midir);
} }
int dmg = 2 * (plr[id]._pLevel + GenerateRndSum(10, 2)) + 4; int dmg = 2 * (Players[id]._pLevel + GenerateRndSum(10, 2)) + 4;
missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl) / 2; missile[mi]._midam = ScaleSpellEffect(dmg, missile[mi]._mispllvl) / 2;
UpdateMissileVel(mi, src, dst, 16); UpdateMissileVel(mi, src, dst, 16);
@ -2609,7 +2609,7 @@ void AddIdentify(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*m
{ {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
UseMana(id, SPL_IDENTIFY); UseMana(id, SPL_IDENTIFY);
if (id == myplr) { if (id == MyPlayerId) {
if (sbookflag) if (sbookflag)
sbookflag = false; sbookflag = false;
if (!invflag) { if (!invflag) {
@ -2660,7 +2660,7 @@ void AddFirewallC(int mi, Point src, Point dst, int midir, int8_t /*mienemy*/, i
void AddInfra(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/) void AddInfra(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t mienemy, int id, int /*dam*/)
{ {
missile[mi]._mirange = ScaleSpellEffect(1584, missile[mi]._mispllvl); missile[mi]._mirange = ScaleSpellEffect(1584, missile[mi]._mispllvl);
missile[mi]._mirange += missile[mi]._mirange * plr[id]._pISplDur / 128; missile[mi]._mirange += missile[mi]._mirange * Players[id]._pISplDur / 128;
if (mienemy == TARGET_MONSTERS) if (mienemy == TARGET_MONSTERS)
UseMana(id, SPL_INFRA); UseMana(id, SPL_INFRA);
@ -2683,7 +2683,7 @@ void AddNova(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t mienemy, in
missile[mi]._miVar2 = dst.y; missile[mi]._miVar2 = dst.y;
if (id != -1) { if (id != -1) {
int dmg = GenerateRndSum(6, 5) + plr[id]._pLevel + 5; int dmg = GenerateRndSum(6, 5) + Players[id]._pLevel + 5;
missile[mi]._midam = ScaleSpellEffect(dmg / 2, missile[mi]._mispllvl); missile[mi]._midam = ScaleSpellEffect(dmg / 2, missile[mi]._mispllvl);
if (mienemy == TARGET_MONSTERS) if (mienemy == TARGET_MONSTERS)
@ -2697,7 +2697,7 @@ void AddNova(int mi, Point /*src*/, Point dst, int /*midir*/, int8_t mienemy, in
void AddBlodboil(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddBlodboil(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
auto &player = plr[id]; auto &player = Players[id];
if ((player._pSpellFlags & 6) != 0 || player._pHitPoints <= player._pLevel << 6) { if ((player._pSpellFlags & 6) != 0 || player._pHitPoints <= player._pLevel << 6) {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
@ -2721,7 +2721,7 @@ void AddRepair(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mie
{ {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
UseMana(id, SPL_REPAIR); UseMana(id, SPL_REPAIR);
if (id == myplr) { if (id == MyPlayerId) {
if (sbookflag) if (sbookflag)
sbookflag = false; sbookflag = false;
if (!invflag) { if (!invflag) {
@ -2737,7 +2737,7 @@ void AddRecharge(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*m
{ {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
UseMana(id, SPL_RECHARGE); UseMana(id, SPL_RECHARGE);
if (id == myplr) { if (id == MyPlayerId) {
if (sbookflag) if (sbookflag)
sbookflag = false; sbookflag = false;
if (!invflag) { if (!invflag) {
@ -2753,7 +2753,7 @@ void AddDisarm(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mie
{ {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
UseMana(id, SPL_DISARM); UseMana(id, SPL_DISARM);
if (id == myplr) { if (id == MyPlayerId) {
NewCursor(CURSOR_DISARM); NewCursor(CURSOR_DISARM);
if (sgbControllerActive) { if (sgbControllerActive) {
if (pcursobj != -1) if (pcursobj != -1)
@ -2780,7 +2780,7 @@ void AddApoca(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t /*mienemy*
missile[mi]._miVar4 = 1; missile[mi]._miVar4 = 1;
if (missile[mi]._miVar5 >= MAXDUNX) if (missile[mi]._miVar5 >= MAXDUNX)
missile[mi]._miVar5 = MAXDUNX - 1; missile[mi]._miVar5 = MAXDUNX - 1;
missile[mi]._midam = GenerateRndSum(6, plr[id]._pLevel) + plr[id]._pLevel; missile[mi]._midam = GenerateRndSum(6, Players[id]._pLevel) + Players[id]._pLevel;
missile[mi]._mirange = 255; missile[mi]._mirange = 255;
missile[mi]._miDelFlag = false; missile[mi]._miDelFlag = false;
UseMana(id, SPL_APOCA); UseMana(id, SPL_APOCA);
@ -2795,7 +2795,7 @@ void AddFlame(int mi, Point src, Point dst, int midir, int8_t mienemy, int id, i
missile[mi]._mirange = missile[mi]._miVar2 + 20; missile[mi]._mirange = missile[mi]._miVar2 + 20;
missile[mi]._mlid = AddLight(src, 1); missile[mi]._mlid = AddLight(src, 1);
if (mienemy == TARGET_MONSTERS) { if (mienemy == TARGET_MONSTERS) {
int i = GenerateRnd(plr[id]._pLevel) + GenerateRnd(2); int i = GenerateRnd(Players[id]._pLevel) + GenerateRnd(2);
missile[mi]._midam = 8 * i + 16 + ((8 * i + 16) / 2); missile[mi]._midam = 8 * i + 16 + ((8 * i + 16) / 2);
} else { } else {
missile[mi]._midam = Monsters[id].mMinDamage + GenerateRnd(Monsters[id].mMaxDamage - Monsters[id].mMinDamage + 1); missile[mi]._midam = Monsters[id].mMinDamage + GenerateRnd(Monsters[id].mMaxDamage - Monsters[id].mMinDamage + 1);
@ -2822,7 +2822,7 @@ void AddCbolt(int mi, Point src, Point dst, int midir, int8_t micaster, int id,
assert((DWORD)mi < MAXMISSILES); assert((DWORD)mi < MAXMISSILES);
missile[mi]._mirnd = GenerateRnd(15) + 1; missile[mi]._mirnd = GenerateRnd(15) + 1;
missile[mi]._midam = (micaster == 0) ? (GenerateRnd(plr[id]._pMagic / 4) + 1) : 15; missile[mi]._midam = (micaster == 0) ? (GenerateRnd(Players[id]._pMagic / 4) + 1) : 15;
if (src == dst) { if (src == dst) {
dst += static_cast<Direction>(midir); dst += static_cast<Direction>(midir);
@ -2854,14 +2854,14 @@ void AddHbolt(int mi, Point src, Point dst, int midir, int8_t /*micaster*/, int
missile[mi]._miVar1 = src.x; missile[mi]._miVar1 = src.x;
missile[mi]._miVar2 = src.y; missile[mi]._miVar2 = src.y;
missile[mi]._mlid = AddLight(src, 8); missile[mi]._mlid = AddLight(src, 8);
missile[mi]._midam = GenerateRnd(10) + plr[id]._pLevel + 9; missile[mi]._midam = GenerateRnd(10) + Players[id]._pLevel + 9;
UseMana(id, SPL_HBOLT); UseMana(id, SPL_HBOLT);
} }
void AddResurrect(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/) void AddResurrect(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t /*mienemy*/, int id, int /*dam*/)
{ {
UseMana(id, SPL_RESURRECT); UseMana(id, SPL_RESURRECT);
if (id == myplr) { if (id == MyPlayerId) {
NewCursor(CURSOR_RESURRECT); NewCursor(CURSOR_RESURRECT);
if (sgbControllerActive) if (sgbControllerActive)
TryIconCurs(); TryIconCurs();
@ -2881,7 +2881,7 @@ void AddTelekinesis(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t
{ {
missile[mi]._miDelFlag = true; missile[mi]._miDelFlag = true;
UseMana(id, SPL_TELEKINESIS); UseMana(id, SPL_TELEKINESIS);
if (id == myplr) if (id == MyPlayerId)
NewCursor(CURSOR_TELEKINESIS); NewCursor(CURSOR_TELEKINESIS);
} }
@ -2920,7 +2920,7 @@ void AddDiabApoca(int mi, Point src, Point /*dst*/, int /*midir*/, int8_t mienem
{ {
int players = gbIsMultiplayer ? MAX_PLRS : 1; int players = gbIsMultiplayer ? MAX_PLRS : 1;
for (int pnum = 0; pnum < players; pnum++) { for (int pnum = 0; pnum < players; pnum++) {
auto &player = plr[pnum]; auto &player = Players[pnum];
if (!player.plractive) if (!player.plractive)
continue; continue;
if (!LineClearMissile(src, player.position.future)) if (!LineClearMissile(src, player.position.future))
@ -2936,8 +2936,8 @@ int AddMissile(Point src, Point dst, int midir, int mitype, int8_t micaster, int
if (nummissiles >= MAXMISSILES - 1) if (nummissiles >= MAXMISSILES - 1)
return -1; return -1;
if (mitype == MIS_MANASHIELD && plr[id].pManaShield) { if (mitype == MIS_MANASHIELD && Players[id].pManaShield) {
if (currlevel != plr[id].plrlevel) if (currlevel != Players[id].plrlevel)
return -1; return -1;
for (int i = 0; i < nummissiles; i++) { for (int i = 0; i < nummissiles; i++) {
@ -3053,8 +3053,8 @@ void MI_LArrow(int i)
int mind; int mind;
int maxd; int maxd;
if (p != -1) { if (p != -1) {
mind = plr[p]._pILMinDam; mind = Players[p]._pILMinDam;
maxd = plr[p]._pILMaxDam; maxd = Players[p]._pILMaxDam;
} else { } else {
mind = GenerateRnd(10) + 1 + currlevel; mind = GenerateRnd(10) + 1 + currlevel;
maxd = GenerateRnd(10) + 1 + currlevel * 2; maxd = GenerateRnd(10) + 1 + currlevel * 2;
@ -3066,8 +3066,8 @@ void MI_LArrow(int i)
int mind; int mind;
int maxd; int maxd;
if (p != -1) { if (p != -1) {
mind = plr[p]._pIFMinDam; mind = Players[p]._pIFMinDam;
maxd = plr[p]._pIFMaxDam; maxd = Players[p]._pIFMaxDam;
} else { } else {
mind = GenerateRnd(10) + 1 + currlevel; mind = GenerateRnd(10) + 1 + currlevel;
maxd = GenerateRnd(10) + 1 + currlevel * 2; maxd = GenerateRnd(10) + 1 + currlevel * 2;
@ -3085,8 +3085,8 @@ void MI_LArrow(int i)
int maxd; int maxd;
if (p != -1) { if (p != -1) {
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
mind = plr[p]._pIMinDam; mind = Players[p]._pIMinDam;
maxd = plr[p]._pIMaxDam; maxd = Players[p]._pIMaxDam;
} else { } else {
mind = Monsters[p].mMinDamage; mind = Monsters[p].mMinDamage;
maxd = Monsters[p].mMaxDamage; maxd = Monsters[p].mMaxDamage;
@ -3139,8 +3139,8 @@ void MI_Arrow(int i)
int maxd; int maxd;
if (p != -1) { if (p != -1) {
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
mind = plr[p]._pIMinDam; mind = Players[p]._pIMinDam;
maxd = plr[p]._pIMaxDam; maxd = Players[p]._pIMaxDam;
} else { } else {
mind = Monsters[p].mMinDamage; mind = Monsters[p].mMinDamage;
maxd = Monsters[p].mMaxDamage; maxd = Monsters[p].mMaxDamage;
@ -3171,10 +3171,10 @@ void MI_Firebolt(int i)
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
switch (missile[i]._mitype) { switch (missile[i]._mitype) {
case MIS_FIREBOLT: case MIS_FIREBOLT:
d = GenerateRnd(10) + (plr[p]._pMagic / 8) + missile[i]._mispllvl + 1; d = GenerateRnd(10) + (Players[p]._pMagic / 8) + missile[i]._mispllvl + 1;
break; break;
case MIS_FLARE: case MIS_FLARE:
d = 3 * missile[i]._mispllvl - (plr[p]._pMagic / 8) + (plr[p]._pMagic / 2); d = 3 * missile[i]._mispllvl - (Players[p]._pMagic / 8) + (Players[p]._pMagic / 2);
break; break;
case MIS_BONESPIRIT: case MIS_BONESPIRIT:
d = 0; d = 0;
@ -3332,7 +3332,7 @@ static void FireballUpdate(int i, Displacement offset, bool alwaysDelete)
missile[i]._mirange--; missile[i]._mirange--;
int id = missile[i]._misource; int id = missile[i]._misource;
Point p = (missile[i]._micaster == TARGET_MONSTERS) ? plr[id].position.tile : Monsters[id].position.tile; Point p = (missile[i]._micaster == TARGET_MONSTERS) ? Players[id].position.tile : Monsters[id].position.tile;
if (missile[i]._miAnimType == MFILE_BIGEXP) { if (missile[i]._miAnimType == MFILE_BIGEXP) {
if (missile[i]._mirange == 0) { if (missile[i]._mirange == 0) {
@ -3436,7 +3436,7 @@ void MI_Rune(int i)
dir = GetDirection(missile[i].position.tile, Monsters[mid].position.tile); dir = GetDirection(missile[i].position.tile, Monsters[mid].position.tile);
} else { } else {
pid = (pid > 0) ? (pid - 1) : -(pid + 1); pid = (pid > 0) ? (pid - 1) : -(pid + 1);
dir = GetDirection(missile[i].position.tile, plr[pid].position.tile); dir = GetDirection(missile[i].position.tile, Players[pid].position.tile);
} }
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
AddUnLight(missile[i]._mlid); AddUnLight(missile[i]._mlid);
@ -3568,9 +3568,9 @@ void MI_FlashFront(int i)
{ {
int src = missile[i]._misource; int src = missile[i]._misource;
if (missile[i]._micaster == TARGET_MONSTERS && src != -1) { if (missile[i]._micaster == TARGET_MONSTERS && src != -1) {
missile[i].position.tile = plr[src].position.tile; missile[i].position.tile = Players[src].position.tile;
missile[i].position.traveled.deltaX = plr[src].position.offset.deltaX << 16; missile[i].position.traveled.deltaX = Players[src].position.offset.deltaX << 16;
missile[i].position.traveled.deltaY = plr[src].position.offset.deltaY << 16; missile[i].position.traveled.deltaY = Players[src].position.offset.deltaY << 16;
} }
missile[i]._mirange--; missile[i]._mirange--;
if (missile[i]._mirange == 0) { if (missile[i]._mirange == 0) {
@ -3578,7 +3578,7 @@ void MI_FlashFront(int i)
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
src = missile[i]._misource; src = missile[i]._misource;
if (src != -1) if (src != -1)
plr[src]._pBaseToBlk -= 50; Players[src]._pBaseToBlk -= 50;
} }
} }
PutMissile(i); PutMissile(i);
@ -3587,9 +3587,9 @@ void MI_FlashFront(int i)
void MI_Reflect(int i) void MI_Reflect(int i)
{ {
int src = missile[i]._misource; int src = missile[i]._misource;
if (src != myplr && currlevel != plr[src].plrlevel) if (src != MyPlayerId && currlevel != Players[src].plrlevel)
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
if (plr[src].wReflections <= 0) { if (Players[src].wReflections <= 0) {
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
NetSendCmd(true, CMD_REFLECT); NetSendCmd(true, CMD_REFLECT);
} }
@ -3600,7 +3600,7 @@ static void MissileRing(int i, int type)
{ {
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
int8_t src = missile[i]._micaster; int8_t src = missile[i]._micaster;
uint8_t lvl = src > 0 ? plr[src]._pLevel : currlevel; uint8_t lvl = src > 0 ? Players[src]._pLevel : currlevel;
int dmg = 16 * (GenerateRndSum(10, 2) + lvl + 2) / 2; int dmg = 16 * (GenerateRndSum(10, 2) + lvl + 2) / 2;
int k = CrawlNum[3]; int k = CrawlNum[3];
@ -3643,7 +3643,7 @@ void MI_Search(int i)
return; return;
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
PlaySfxLoc(IS_CAST7, plr[missile[i]._miVar1].position.tile); PlaySfxLoc(IS_CAST7, Players[missile[i]._miVar1].position.tile);
AutoMapShowItems = false; AutoMapShowItems = false;
} }
@ -3656,7 +3656,7 @@ bool GrowWall(int playerId, Point position, Point target, missile_id type, int s
return false; return false;
} }
AddMissile(position, position, plr[playerId]._pdir, type, TARGET_BOTH, playerId, damage, spellLevel); AddMissile(position, position, Players[playerId]._pdir, type, TARGET_BOTH, playerId, damage, spellLevel);
return true; return true;
} }
@ -3669,7 +3669,7 @@ void MI_LightningWallC(int i)
} }
int id = missile[i]._misource; int id = missile[i]._misource;
int lvl = (id > -1) ? plr[id]._pLevel : 0; int lvl = (id > -1) ? Players[id]._pLevel : 0;
int dmg = 16 * (GenerateRndSum(10, 2) + lvl + 2); int dmg = 16 * (GenerateRndSum(10, 2) + lvl + 2);
{ {
@ -3707,7 +3707,7 @@ void MI_FireNova(int i)
Direction dir = DIR_S; Direction dir = DIR_S;
mienemy_type en = TARGET_PLAYERS; mienemy_type en = TARGET_PLAYERS;
if (id != -1) { if (id != -1) {
dir = plr[id]._pdir; dir = Players[id]._pdir;
en = TARGET_MONSTERS; en = TARGET_MONSTERS;
} }
for (const auto &k : VisionCrawlTable) { for (const auto &k : VisionCrawlTable) {
@ -3735,10 +3735,10 @@ void MI_SpecArrow(int i)
Direction dir = DIR_S; Direction dir = DIR_S;
mienemy_type micaster = TARGET_PLAYERS; mienemy_type micaster = TARGET_PLAYERS;
if (id != -1) { if (id != -1) {
dir = plr[id]._pdir; dir = Players[id]._pdir;
micaster = TARGET_MONSTERS; micaster = TARGET_MONSTERS;
switch (plr[id]._pILMinDam) { switch (Players[id]._pILMinDam) {
case 0: case 0:
mitype = MIS_FIRENOVA; mitype = MIS_FIRENOVA;
break; break;
@ -3772,7 +3772,7 @@ void MI_Lightctrl(int i)
int id = missile[i]._misource; int id = missile[i]._misource;
if (id != -1) { if (id != -1) {
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
dam = (GenerateRnd(2) + GenerateRnd(plr[id]._pLevel) + 2) << 6; dam = (GenerateRnd(2) + GenerateRnd(Players[id]._pLevel) + 2) << 6;
} else { } else {
dam = 2 * (Monsters[id].mMinDamage + GenerateRnd(Monsters[id].mMaxDamage - Monsters[id].mMinDamage + 1)); dam = 2 * (Monsters[id].mMinDamage + GenerateRnd(Monsters[id].mMaxDamage - Monsters[id].mMinDamage + 1));
} }
@ -3873,10 +3873,10 @@ void MI_Town(int i)
} }
for (int p = 0; p < MAX_PLRS; p++) { for (int p = 0; p < MAX_PLRS; p++) {
auto &player = plr[p]; auto &player = Players[p];
if (player.plractive && currlevel == player.plrlevel && !player._pLvlChanging && player._pmode == PM_STAND && player.position.tile == missile[i].position.tile) { if (player.plractive && currlevel == player.plrlevel && !player._pLvlChanging && player._pmode == PM_STAND && player.position.tile == missile[i].position.tile) {
ClrPlrPath(player); ClrPlrPath(player);
if (p == myplr) { if (p == MyPlayerId) {
NetSendCmdParam1(true, CMD_WARP, missile[i]._misource); NetSendCmdParam1(true, CMD_WARP, missile[i]._misource);
player._pmode = PM_NEWLVL; player._pmode = PM_NEWLVL;
} }
@ -3894,7 +3894,7 @@ void MI_Flash(int i)
{ {
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
if (missile[i]._misource != -1) if (missile[i]._misource != -1)
plr[missile[i]._misource]._pInvincible = true; Players[missile[i]._misource]._pInvincible = true;
} }
missile[i]._mirange--; missile[i]._mirange--;
@ -3906,7 +3906,7 @@ void MI_Flash(int i)
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
if (missile[i]._misource != -1) if (missile[i]._misource != -1)
plr[missile[i]._misource]._pInvincible = false; Players[missile[i]._misource]._pInvincible = false;
} }
} }
PutMissile(i); PutMissile(i);
@ -3916,7 +3916,7 @@ void MI_Flash2(int i)
{ {
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
if (missile[i]._misource != -1) if (missile[i]._misource != -1)
plr[missile[i]._misource]._pInvincible = true; Players[missile[i]._misource]._pInvincible = true;
} }
missile[i]._mirange--; missile[i]._mirange--;
@ -3928,7 +3928,7 @@ void MI_Flash2(int i)
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
if (missile[i]._micaster == TARGET_MONSTERS) { if (missile[i]._micaster == TARGET_MONSTERS) {
if (missile[i]._misource != -1) if (missile[i]._misource != -1)
plr[missile[i]._misource]._pInvincible = false; Players[missile[i]._misource]._pInvincible = false;
} }
} }
PutMissile(i); PutMissile(i);
@ -3937,11 +3937,11 @@ void MI_Flash2(int i)
void MI_Manashield(int i) void MI_Manashield(int i)
{ {
int id = missile[i]._misource; int id = missile[i]._misource;
if (id != myplr) { if (id != MyPlayerId) {
if (currlevel != plr[id].plrlevel) if (currlevel != Players[id].plrlevel)
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
} else { } else {
if (plr[id]._pMana <= 0 || !plr[id].plractive) if (Players[id]._pMana <= 0 || !Players[id].plractive)
missile[i]._mirange = 0; missile[i]._mirange = 0;
if (missile[i]._mirange == 0) { if (missile[i]._mirange == 0) {
@ -3956,7 +3956,7 @@ void MI_Etherealize(int i)
{ {
missile[i]._mirange--; missile[i]._mirange--;
auto &player = plr[missile[i]._misource]; auto &player = Players[missile[i]._misource];
missile[i].position.tile = player.position.tile; missile[i].position.tile = player.position.tile;
missile[i].position.traveled.deltaX = player.position.offset.deltaX << 16; missile[i].position.traveled.deltaX = player.position.offset.deltaX << 16;
@ -4136,12 +4136,12 @@ void MI_Weapexp(int i)
int mind; int mind;
int maxd; int maxd;
if (missile[i]._miVar2 == 1) { if (missile[i]._miVar2 == 1) {
mind = plr[id]._pIFMinDam; mind = Players[id]._pIFMinDam;
maxd = plr[id]._pIFMaxDam; maxd = Players[id]._pIFMaxDam;
missiledata[missile[i]._mitype].mResist = MISR_FIRE; missiledata[missile[i]._mitype].mResist = MISR_FIRE;
} else { } else {
mind = plr[id]._pILMinDam; mind = Players[id]._pILMinDam;
maxd = plr[id]._pILMaxDam; maxd = Players[id]._pILMaxDam;
missiledata[missile[i]._mitype].mResist = MISR_LIGHTNING; missiledata[missile[i]._mitype].mResist = MISR_LIGHTNING;
} }
CheckMissileCol(i, mind, maxd, false, missile[i].position.tile, false); CheckMissileCol(i, mind, maxd, false, missile[i].position.tile, false);
@ -4205,7 +4205,7 @@ void MI_Teleport(int i)
} }
int id = missile[i]._misource; int id = missile[i]._misource;
auto &player = plr[id]; auto &player = Players[id];
dPlayer[player.position.tile.x][player.position.tile.y] = 0; dPlayer[player.position.tile.x][player.position.tile.y] = 0;
PlrClrTrans(player.position.tile); PlrClrTrans(player.position.tile);
@ -4219,7 +4219,7 @@ void MI_Teleport(int i)
ChangeLightXY(player._plid, player.position.tile); ChangeLightXY(player._plid, player.position.tile);
ChangeVisionXY(player._pvid, player.position.tile); ChangeVisionXY(player._pvid, player.position.tile);
} }
if (id == myplr) { if (id == MyPlayerId) {
ViewX = player.position.tile.x - ScrollInfo.tile.x; ViewX = player.position.tile.x - ScrollInfo.tile.x;
ViewY = player.position.tile.y - ScrollInfo.tile.y; ViewY = player.position.tile.y - ScrollInfo.tile.y;
} }
@ -4310,7 +4310,7 @@ void MI_Fireman(int i)
int src = missile[i]._misource; int src = missile[i]._misource;
Point b = missile[i].position.tile; Point b = missile[i].position.tile;
int enemy = Monsters[src]._menemy; int enemy = Monsters[src]._menemy;
Point c = (Monsters[src]._mFlags & MFLAG_TARGETS_MONSTER) == 0 ? plr[enemy].position.tile : Monsters[enemy].position.tile; Point c = (Monsters[src]._mFlags & MFLAG_TARGETS_MONSTER) == 0 ? Players[enemy].position.tile : Monsters[enemy].position.tile;
int j = 0; int j = 0;
if (b != a && (((missile[i]._miVar1 & 1) != 0 && a.WalkingDistance(c) >= 4) || missile[i]._miVar2 > 1) && PosOkMonst(missile[i]._misource, a)) { if (b != a && (((missile[i]._miVar1 & 1) != 0 && a.WalkingDistance(c) >= 4) || missile[i]._miVar2 > 1) && PosOkMonst(missile[i]._misource, a)) {
@ -4371,7 +4371,7 @@ void MI_FirewallC(int i)
void MI_Infra(int i) void MI_Infra(int i)
{ {
missile[i]._mirange--; missile[i]._mirange--;
plr[missile[i]._misource]._pInfraFlag = true; Players[missile[i]._misource]._pInfraFlag = true;
if (missile[i]._mirange == 0) { if (missile[i]._mirange == 0) {
missile[i]._miDelFlag = true; missile[i]._miDelFlag = true;
CalcPlrItemVals(missile[i]._misource, true); CalcPlrItemVals(missile[i]._misource, true);
@ -4392,7 +4392,7 @@ void MI_Apoca(int i)
continue; continue;
if (gbIsHellfire && !LineClearMissile(missile[i].position.tile, { k, j })) if (gbIsHellfire && !LineClearMissile(missile[i].position.tile, { k, j }))
continue; continue;
AddMissile({ k, j }, { k, j }, plr[id]._pdir, MIS_BOOM, TARGET_MONSTERS, id, missile[i]._midam, 0); AddMissile({ k, j }, { k, j }, Players[id]._pdir, MIS_BOOM, TARGET_MONSTERS, id, missile[i]._midam, 0);
exit = true; exit = true;
} }
if (!exit) { if (!exit) {
@ -4423,7 +4423,7 @@ void MI_Wave(int i)
int pn = dPiece[na.x][na.y]; int pn = dPiece[na.x][na.y];
assert((DWORD)pn <= MAXTILES); assert((DWORD)pn <= MAXTILES);
if (!nMissileTable[pn]) { if (!nMissileTable[pn]) {
Direction pdir = plr[id]._pdir; Direction pdir = Players[id]._pdir;
AddMissile(na, na + sd, pdir, MIS_FIREMOVE, TARGET_MONSTERS, id, 0, missile[i]._mispllvl); AddMissile(na, na + sd, pdir, MIS_FIREMOVE, TARGET_MONSTERS, id, 0, missile[i]._mispllvl);
na += dira; na += dira;
Point nb = src + sd + dirb; Point nb = src + sd + dirb;
@ -4462,7 +4462,7 @@ void MI_Nova(int i)
Direction dir = DIR_S; Direction dir = DIR_S;
mienemy_type en = TARGET_PLAYERS; mienemy_type en = TARGET_PLAYERS;
if (id != -1) { if (id != -1) {
dir = plr[id]._pdir; dir = Players[id]._pdir;
en = TARGET_MONSTERS; en = TARGET_MONSTERS;
} }
for (const auto &k : VisionCrawlTable) { for (const auto &k : VisionCrawlTable) {
@ -4489,7 +4489,7 @@ void MI_Blodboil(int i)
} }
int id = missile[i]._miVar1; int id = missile[i]._miVar1;
auto &player = plr[id]; auto &player = Players[id];
int hpdif = player._pMaxHP - player._pHitPoints; int hpdif = player._pMaxHP - player._pHitPoints;
@ -4646,7 +4646,7 @@ void MI_Element(int i)
int id = missile[i]._misource; int id = missile[i]._misource;
if (missile[i]._miAnimType == MFILE_BIGEXP) { if (missile[i]._miAnimType == MFILE_BIGEXP) {
Point c = missile[i].position.tile; Point c = missile[i].position.tile;
Point p = plr[id].position.tile; Point p = Players[id].position.tile;
ChangeLight(missile[i]._mlid, missile[i].position.tile, missile[i]._miAnimFrame); ChangeLight(missile[i]._mlid, missile[i].position.tile, missile[i]._miAnimFrame);
if (!CheckBlock(p, c)) if (!CheckBlock(p, c))
CheckMissileCol(i, dam, dam, true, c, true); CheckMissileCol(i, dam, dam, true, c, true);
@ -4677,7 +4677,7 @@ void MI_Element(int i)
SetMissDir(i, sd); SetMissDir(i, sd);
UpdateMissileVel(i, c, Monsters[mid].position.tile, 16); UpdateMissileVel(i, c, Monsters[mid].position.tile, 16);
} else { } else {
Direction sd = plr[id]._pdir; Direction sd = Players[id]._pdir;
SetMissDir(i, sd); SetMissDir(i, sd);
UpdateMissileVel(i, c, c + sd, 16); UpdateMissileVel(i, c, c + sd, 16);
} }
@ -4724,7 +4724,7 @@ void MI_Bonespirit(int i)
SetMissDir(i, GetDirection(c, Monsters[mid].position.tile)); SetMissDir(i, GetDirection(c, Monsters[mid].position.tile));
UpdateMissileVel(i, c, Monsters[mid].position.tile, 16); UpdateMissileVel(i, c, Monsters[mid].position.tile, 16);
} else { } else {
Direction sd = plr[id]._pdir; Direction sd = Players[id]._pdir;
SetMissDir(i, sd); SetMissDir(i, sd);
UpdateMissileVel(i, c, c + sd, 16); UpdateMissileVel(i, c, c + sd, 16);
} }

132
Source/monster.cpp

@ -627,7 +627,7 @@ void ClrAllMonsters()
monst->_mFlags = 0; monst->_mFlags = 0;
monst->_mDelFlag = false; monst->_mDelFlag = false;
monst->_menemy = GenerateRnd(gbActivePlayers); monst->_menemy = GenerateRnd(gbActivePlayers);
monst->enemyPosition = plr[monst->_menemy].position.future; monst->enemyPosition = Players[monst->_menemy].position.future;
} }
} }
@ -1309,18 +1309,18 @@ void M_Enemy(int i)
MonsterStruct *monst = &Monsters[i]; MonsterStruct *monst = &Monsters[i];
if ((monst->_mFlags & MFLAG_BERSERK) != 0 || (monst->_mFlags & MFLAG_GOLEM) == 0) { if ((monst->_mFlags & MFLAG_BERSERK) != 0 || (monst->_mFlags & MFLAG_GOLEM) == 0) {
for (int pnum = 0; pnum < MAX_PLRS; pnum++) { for (int pnum = 0; pnum < MAX_PLRS; pnum++) {
if (!plr[pnum].plractive || currlevel != plr[pnum].plrlevel || plr[pnum]._pLvlChanging if (!Players[pnum].plractive || currlevel != Players[pnum].plrlevel || Players[pnum]._pLvlChanging
|| (((plr[pnum]._pHitPoints >> 6) == 0) && gbIsMultiplayer)) || (((Players[pnum]._pHitPoints >> 6) == 0) && gbIsMultiplayer))
continue; continue;
bool sameroom = (dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[plr[pnum].position.tile.x][plr[pnum].position.tile.y]); bool sameroom = (dTransVal[monst->position.tile.x][monst->position.tile.y] == dTransVal[Players[pnum].position.tile.x][Players[pnum].position.tile.y]);
int dist = monst->position.tile.WalkingDistance(plr[pnum].position.tile); int dist = monst->position.tile.WalkingDistance(Players[pnum].position.tile);
if ((sameroom && !bestsameroom) if ((sameroom && !bestsameroom)
|| ((sameroom || !bestsameroom) && dist < bestDist) || ((sameroom || !bestsameroom) && dist < bestDist)
|| (menemy == -1)) { || (menemy == -1)) {
monst->_mFlags &= ~MFLAG_TARGETS_MONSTER; monst->_mFlags &= ~MFLAG_TARGETS_MONSTER;
menemy = pnum; menemy = pnum;
enemyx = plr[pnum].position.future.x; enemyx = Players[pnum].position.future.x;
enemyy = plr[pnum].position.future.y; enemyy = Players[pnum].position.future.y;
bestDist = dist; bestDist = dist;
bestsameroom = sameroom; bestsameroom = sameroom;
} }
@ -1587,7 +1587,7 @@ void M_StartHit(int i, int pnum, int dam)
{ {
if (pnum >= 0) if (pnum >= 0)
Monsters[i].mWhoHit |= 1 << pnum; Monsters[i].mWhoHit |= 1 << pnum;
if (pnum == myplr) { if (pnum == MyPlayerId) {
delta_monster_hp(i, Monsters[i]._mhitpoints, currlevel); delta_monster_hp(i, Monsters[i]._mhitpoints, currlevel);
NetSendCmdMonDmg(false, i, dam); NetSendCmdMonDmg(false, i, dam);
} }
@ -1595,7 +1595,7 @@ void M_StartHit(int i, int pnum, int dam)
if ((Monsters[i].MType->mtype >= MT_SNEAK && Monsters[i].MType->mtype <= MT_ILLWEAV) || dam >> 6 >= Monsters[i].mLevel + 3) { if ((Monsters[i].MType->mtype >= MT_SNEAK && Monsters[i].MType->mtype <= MT_ILLWEAV) || dam >> 6 >= Monsters[i].mLevel + 3) {
if (pnum >= 0) { if (pnum >= 0) {
Monsters[i]._menemy = pnum; Monsters[i]._menemy = pnum;
Monsters[i].enemyPosition = plr[pnum].position.future; Monsters[i].enemyPosition = Players[pnum].position.future;
Monsters[i]._mFlags &= ~MFLAG_TARGETS_MONSTER; Monsters[i]._mFlags &= ~MFLAG_TARGETS_MONSTER;
Monsters[i]._mdir = M_GetDir(i); Monsters[i]._mdir = M_GetDir(i);
} }
@ -1815,7 +1815,7 @@ void M_StartKill(int i, int pnum)
{ {
assurance((DWORD)i < MAXMONSTERS, i); assurance((DWORD)i < MAXMONSTERS, i);
if (myplr == pnum) { if (MyPlayerId == pnum) {
delta_kill_monster(i, Monsters[i].position.tile, currlevel); delta_kill_monster(i, Monsters[i].position.tile, currlevel);
if (i != pnum) { if (i != pnum) {
NetSendCmdLocParam1(false, CMD_MONSTDEATH, Monsters[i].position.tile, i); NetSendCmdLocParam1(false, CMD_MONSTDEATH, Monsters[i].position.tile, i);
@ -2016,9 +2016,9 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
M_TryM2MHit(i, pnum, hit, minDam, maxDam); M_TryM2MHit(i, pnum, hit, minDam, maxDam);
return; return;
} }
if (plr[pnum]._pHitPoints >> 6 <= 0 || plr[pnum]._pInvincible || (plr[pnum]._pSpellFlags & 1) != 0) if (Players[pnum]._pHitPoints >> 6 <= 0 || Players[pnum]._pInvincible || (Players[pnum]._pSpellFlags & 1) != 0)
return; return;
if (Monsters[i].position.tile.WalkingDistance(plr[pnum].position.tile) >= 2) if (Monsters[i].position.tile.WalkingDistance(Players[pnum].position.tile) >= 2)
return; return;
int hper = GenerateRnd(100); int hper = GenerateRnd(100);
@ -2026,15 +2026,15 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
if (debug_mode_dollar_sign || debug_mode_key_inverted_v) if (debug_mode_dollar_sign || debug_mode_key_inverted_v)
hper = 1000; hper = 1000;
#endif #endif
int ac = plr[pnum]._pIBonusAC + plr[pnum]._pIAC; int ac = Players[pnum]._pIBonusAC + Players[pnum]._pIAC;
if ((plr[pnum].pDamAcFlags & ISPLHF_ACDEMON) != 0 && Monsters[i].MData->mMonstClass == MC_DEMON) if ((Players[pnum].pDamAcFlags & ISPLHF_ACDEMON) != 0 && Monsters[i].MData->mMonstClass == MC_DEMON)
ac += 40; ac += 40;
if ((plr[pnum].pDamAcFlags & ISPLHF_ACUNDEAD) != 0 && Monsters[i].MData->mMonstClass == MC_UNDEAD) if ((Players[pnum].pDamAcFlags & ISPLHF_ACUNDEAD) != 0 && Monsters[i].MData->mMonstClass == MC_UNDEAD)
ac += 20; ac += 20;
hit += 2 * (Monsters[i].mLevel - plr[pnum]._pLevel) hit += 2 * (Monsters[i].mLevel - Players[pnum]._pLevel)
+ 30 + 30
- ac - ac
- plr[pnum]._pDexterity / 5; - Players[pnum]._pDexterity / 5;
if (hit < 15) if (hit < 15)
hit = 15; hit = 15;
if (currlevel == 14 && hit < 20) if (currlevel == 14 && hit < 20)
@ -2044,13 +2044,13 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
if (currlevel == 16 && hit < 30) if (currlevel == 16 && hit < 30)
hit = 30; hit = 30;
int blkper = 100; int blkper = 100;
if ((plr[pnum]._pmode == PM_STAND || plr[pnum]._pmode == PM_ATTACK) && plr[pnum]._pBlockFlag) { if ((Players[pnum]._pmode == PM_STAND || Players[pnum]._pmode == PM_ATTACK) && Players[pnum]._pBlockFlag) {
blkper = GenerateRnd(100); blkper = GenerateRnd(100);
} }
int blk = plr[pnum]._pDexterity int blk = Players[pnum]._pDexterity
+ plr[pnum]._pBaseToBlk + Players[pnum]._pBaseToBlk
- (Monsters[i].mLevel * 2) - (Monsters[i].mLevel * 2)
+ (plr[pnum]._pLevel * 2); + (Players[pnum]._pLevel * 2);
if (blk < 0) if (blk < 0)
blk = 0; blk = 0;
if (blk > 100) if (blk > 100)
@ -2058,12 +2058,12 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
if (hper >= hit) if (hper >= hit)
return; return;
if (blkper < blk) { if (blkper < blk) {
Direction dir = GetDirection(plr[pnum].position.tile, Monsters[i].position.tile); Direction dir = GetDirection(Players[pnum].position.tile, Monsters[i].position.tile);
StartPlrBlock(pnum, dir); StartPlrBlock(pnum, dir);
if (pnum == myplr && plr[pnum].wReflections > 0) { if (pnum == MyPlayerId && Players[pnum].wReflections > 0) {
plr[pnum].wReflections--; Players[pnum].wReflections--;
int dam = GenerateRnd((maxDam - minDam + 1) << 6) + (minDam << 6); int dam = GenerateRnd((maxDam - minDam + 1) << 6) + (minDam << 6);
dam += plr[pnum]._pIGetHit << 6; dam += Players[pnum]._pIGetHit << 6;
if (dam < 64) if (dam < 64)
dam = 64; dam = 64;
int mdam = dam * (GenerateRnd(10) + 20L) / 100; int mdam = dam * (GenerateRnd(10) + 20L) / 100;
@ -2078,7 +2078,7 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
} }
return; return;
} }
if (Monsters[i].MType->mtype == MT_YZOMBIE && pnum == myplr) { if (Monsters[i].MType->mtype == MT_YZOMBIE && pnum == MyPlayerId) {
int currentMissileId = -1; int currentMissileId = -1;
for (int j = 0; j < nummissiles; j++) { for (int j = 0; j < nummissiles; j++) {
int mi = missileactive[j]; int mi = missileactive[j];
@ -2087,30 +2087,30 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
if (missile[mi]._misource == pnum) if (missile[mi]._misource == pnum)
currentMissileId = mi; currentMissileId = mi;
} }
if (plr[pnum]._pMaxHP > 64) { if (Players[pnum]._pMaxHP > 64) {
if (plr[pnum]._pMaxHPBase > 64) { if (Players[pnum]._pMaxHPBase > 64) {
plr[pnum]._pMaxHP -= 64; Players[pnum]._pMaxHP -= 64;
if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) { if (Players[pnum]._pHitPoints > Players[pnum]._pMaxHP) {
plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; Players[pnum]._pHitPoints = Players[pnum]._pMaxHP;
if (currentMissileId >= 0) if (currentMissileId >= 0)
missile[currentMissileId]._miVar1 = plr[pnum]._pHitPoints; missile[currentMissileId]._miVar1 = Players[pnum]._pHitPoints;
} }
plr[pnum]._pMaxHPBase -= 64; Players[pnum]._pMaxHPBase -= 64;
if (plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase) { if (Players[pnum]._pHPBase > Players[pnum]._pMaxHPBase) {
plr[pnum]._pHPBase = plr[pnum]._pMaxHPBase; Players[pnum]._pHPBase = Players[pnum]._pMaxHPBase;
if (currentMissileId >= 0) if (currentMissileId >= 0)
missile[currentMissileId]._miVar2 = plr[pnum]._pHPBase; missile[currentMissileId]._miVar2 = Players[pnum]._pHPBase;
} }
} }
} }
} }
int dam = (minDam << 6) + GenerateRnd((maxDam - minDam + 1) << 6); int dam = (minDam << 6) + GenerateRnd((maxDam - minDam + 1) << 6);
dam += (plr[pnum]._pIGetHit << 6); dam += (Players[pnum]._pIGetHit << 6);
if (dam < 64) if (dam < 64)
dam = 64; dam = 64;
if (pnum == myplr) { if (pnum == MyPlayerId) {
if (plr[pnum].wReflections > 0) { if (Players[pnum].wReflections > 0) {
plr[pnum].wReflections--; Players[pnum].wReflections--;
int mdam = dam * (GenerateRnd(10) + 20L) / 100; int mdam = dam * (GenerateRnd(10) + 20L) / 100;
Monsters[i]._mhitpoints -= mdam; Monsters[i]._mhitpoints -= mdam;
dam -= mdam; dam -= mdam;
@ -2123,7 +2123,7 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
} }
ApplyPlrDamage(pnum, 0, 0, dam); ApplyPlrDamage(pnum, 0, 0, dam);
} }
if ((plr[pnum]._pIFlags & ISPL_THORNS) != 0) { if ((Players[pnum]._pIFlags & ISPL_THORNS) != 0) {
int mdam = (GenerateRnd(3) + 1) << 6; int mdam = (GenerateRnd(3) + 1) << 6;
Monsters[i]._mhitpoints -= mdam; Monsters[i]._mhitpoints -= mdam;
if (Monsters[i]._mhitpoints >> 6 <= 0) if (Monsters[i]._mhitpoints >> 6 <= 0)
@ -2133,23 +2133,23 @@ void M_TryH2HHit(int i, int pnum, int hit, int minDam, int maxDam)
} }
if ((Monsters[i]._mFlags & MFLAG_NOLIFESTEAL) == 0 && Monsters[i].MType->mtype == MT_SKING && gbIsMultiplayer) if ((Monsters[i]._mFlags & MFLAG_NOLIFESTEAL) == 0 && Monsters[i].MType->mtype == MT_SKING && gbIsMultiplayer)
Monsters[i]._mhitpoints += dam; Monsters[i]._mhitpoints += dam;
if (plr[pnum]._pHitPoints >> 6 <= 0) { if (Players[pnum]._pHitPoints >> 6 <= 0) {
if (gbIsHellfire) if (gbIsHellfire)
M_StartStand(i, Monsters[i]._mdir); M_StartStand(i, Monsters[i]._mdir);
return; return;
} }
StartPlrHit(pnum, dam, false); StartPlrHit(pnum, dam, false);
if ((Monsters[i]._mFlags & MFLAG_KNOCKBACK) != 0) { if ((Monsters[i]._mFlags & MFLAG_KNOCKBACK) != 0) {
if (plr[pnum]._pmode != PM_GOTHIT) if (Players[pnum]._pmode != PM_GOTHIT)
StartPlrHit(pnum, 0, true); StartPlrHit(pnum, 0, true);
Point newPosition = plr[pnum].position.tile + Monsters[i]._mdir; Point newPosition = Players[pnum].position.tile + Monsters[i]._mdir;
if (PosOkPlayer(pnum, newPosition)) { if (PosOkPlayer(pnum, newPosition)) {
plr[pnum].position.tile = newPosition; Players[pnum].position.tile = newPosition;
FixPlayerLocation(pnum, plr[pnum]._pdir); FixPlayerLocation(pnum, Players[pnum]._pdir);
FixPlrWalkTags(pnum); FixPlrWalkTags(pnum);
dPlayer[newPosition.x][newPosition.y] = pnum + 1; dPlayer[newPosition.x][newPosition.y] = pnum + 1;
SetPlayerOld(plr[pnum]); SetPlayerOld(Players[pnum]);
} }
} }
} }
@ -2489,7 +2489,7 @@ void DoEnding()
if (gbIsSpawn) if (gbIsSpawn)
return; return;
switch (plr[myplr]._pClass) { switch (Players[MyPlayerId]._pClass) {
case HeroClass::Sorcerer: case HeroClass::Sorcerer:
case HeroClass::Monk: case HeroClass::Monk:
play_movie("gendata\\DiabVic1.smk", false); play_movie("gendata\\DiabVic1.smk", false);
@ -2524,12 +2524,12 @@ void PrepDoEnding()
{ {
gbSoundOn = sgbSaveSoundOn; gbSoundOn = sgbSaveSoundOn;
gbRunGame = false; gbRunGame = false;
deathflag = false; MyPlayerIsDead = false;
cineflag = true; cineflag = true;
plr[myplr].pDiabloKillLevel = std::max(plr[myplr].pDiabloKillLevel, static_cast<uint8_t>(sgGameInitInfo.nDifficulty + 1)); Players[MyPlayerId].pDiabloKillLevel = std::max(Players[MyPlayerId].pDiabloKillLevel, static_cast<uint8_t>(sgGameInitInfo.nDifficulty + 1));
for (auto &player : plr) { for (auto &player : Players) {
player._pmode = PM_QUIT; player._pmode = PM_QUIT;
player._pInvincible = true; player._pInvincible = true;
if (gbIsMultiplayer) { if (gbIsMultiplayer) {
@ -3131,7 +3131,7 @@ void MAI_Sneak(int i)
if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0) if ((monst->_mFlags & MFLAG_TARGETS_MONSTER) != 0)
md = GetDirection(monst->position.tile, Monsters[monst->_menemy].position.tile); md = GetDirection(monst->position.tile, Monsters[monst->_menemy].position.tile);
else else
md = GetDirection(monst->position.tile, plr[monst->_menemy].position.last); md = GetDirection(monst->position.tile, Players[monst->_menemy].position.last);
md = opposite[md]; md = opposite[md];
if (monst->MType->mtype == MT_UNSEEN) { if (monst->MType->mtype == MT_UNSEEN) {
if (GenerateRnd(2) != 0) if (GenerateRnd(2) != 0)
@ -3792,7 +3792,7 @@ void MAI_Golum(int i)
if (Monsters[i]._pathcount > 8) if (Monsters[i]._pathcount > 8)
Monsters[i]._pathcount = 5; Monsters[i]._pathcount = 5;
bool ok = M_CallWalk(i, plr[i]._pdir); bool ok = M_CallWalk(i, Players[i]._pdir);
if (ok) if (ok)
return; return;
@ -4203,7 +4203,7 @@ void MAI_Lazurus(int i)
Direction md = M_GetDir(i); Direction md = M_GetDir(i);
if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) {
if (!gbIsMultiplayer) { if (!gbIsMultiplayer) {
if (monst->mtalkmsg == TEXT_VILE13 && monst->_mgoal == MGOAL_INQUIRING && plr[myplr].position.tile.x == 35 && plr[myplr].position.tile.y == 46) { if (monst->mtalkmsg == TEXT_VILE13 && monst->_mgoal == MGOAL_INQUIRING && Players[MyPlayerId].position.tile.x == 35 && Players[MyPlayerId].position.tile.y == 46) {
PlayInGameMovie("gendata\\fprst3.smk"); PlayInGameMovie("gendata\\fprst3.smk");
monst->_mmode = MM_TALK; monst->_mmode = MM_TALK;
quests[Q_BETRAYER]._qvar1 = 5; quests[Q_BETRAYER]._qvar1 = 5;
@ -4402,10 +4402,10 @@ void ProcessMonsters()
} else { } else {
menemy = monst->_menemy; menemy = monst->_menemy;
assurance((DWORD)menemy < MAX_PLRS, menemy); assurance((DWORD)menemy < MAX_PLRS, menemy);
monst->enemyPosition = plr[monst->_menemy].position.future; monst->enemyPosition = Players[monst->_menemy].position.future;
if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) { if ((dFlags[mx][my] & BFLAG_VISIBLE) != 0) {
monst->_msquelch = UINT8_MAX; monst->_msquelch = UINT8_MAX;
monst->position.last = plr[monst->_menemy].position.future; monst->position.last = Players[monst->_menemy].position.future;
} else if (monst->_msquelch != 0 && monst->MType->mtype != MT_DIABLO) { /// BUGFIX: change '_mAi' to 'MType->mtype' } else if (monst->_msquelch != 0 && monst->MType->mtype != MT_DIABLO) { /// BUGFIX: change '_mAi' to 'MType->mtype'
monst->_msquelch--; monst->_msquelch--;
} }
@ -4871,15 +4871,15 @@ void MissToMonst(int i, Point position)
if (monst->MType->mtype != MT_GLOOM && (monst->MType->mtype < MT_INCIN || monst->MType->mtype > MT_HELLBURN)) { if (monst->MType->mtype != MT_GLOOM && (monst->MType->mtype < MT_INCIN || monst->MType->mtype > MT_HELLBURN)) {
M_TryH2HHit(m, dPlayer[oldPosition.x][oldPosition.y] - 1, 500, monst->mMinDamage2, monst->mMaxDamage2); M_TryH2HHit(m, dPlayer[oldPosition.x][oldPosition.y] - 1, 500, monst->mMinDamage2, monst->mMaxDamage2);
if (pnum == dPlayer[oldPosition.x][oldPosition.y] - 1 && (monst->MType->mtype < MT_NSNAKE || monst->MType->mtype > MT_GSNAKE)) { if (pnum == dPlayer[oldPosition.x][oldPosition.y] - 1 && (monst->MType->mtype < MT_NSNAKE || monst->MType->mtype > MT_GSNAKE)) {
if (plr[pnum]._pmode != PM_GOTHIT && plr[pnum]._pmode != PM_DEATH) if (Players[pnum]._pmode != PM_GOTHIT && Players[pnum]._pmode != PM_DEATH)
StartPlrHit(pnum, 0, true); StartPlrHit(pnum, 0, true);
Point newPosition = oldPosition + monst->_mdir; Point newPosition = oldPosition + monst->_mdir;
if (PosOkPlayer(pnum, newPosition)) { if (PosOkPlayer(pnum, newPosition)) {
plr[pnum].position.tile = newPosition; Players[pnum].position.tile = newPosition;
FixPlayerLocation(pnum, plr[pnum]._pdir); FixPlayerLocation(pnum, Players[pnum]._pdir);
FixPlrWalkTags(pnum); FixPlrWalkTags(pnum);
dPlayer[newPosition.x][newPosition.y] = pnum + 1; dPlayer[newPosition.x][newPosition.y] = pnum + 1;
SetPlayerOld(plr[pnum]); SetPlayerOld(Players[pnum]);
} }
} }
} }
@ -5107,14 +5107,14 @@ void TalktoMonster(int i)
} }
if (QuestStatus(Q_LTBANNER) && quests[Q_LTBANNER]._qvar1 == 2) { if (QuestStatus(Q_LTBANNER) && quests[Q_LTBANNER]._qvar1 == 2) {
if (plr[pnum].TryRemoveInvItemById(IDI_BANNER)) { if (Players[pnum].TryRemoveInvItemById(IDI_BANNER)) {
quests[Q_LTBANNER]._qactive = QUEST_DONE; quests[Q_LTBANNER]._qactive = QUEST_DONE;
monst->mtalkmsg = TEXT_BANNER12; monst->mtalkmsg = TEXT_BANNER12;
monst->_mgoal = MGOAL_INQUIRING; monst->_mgoal = MGOAL_INQUIRING;
} }
} }
if (QuestStatus(Q_VEIL) && monst->mtalkmsg >= TEXT_VEIL9) { if (QuestStatus(Q_VEIL) && monst->mtalkmsg >= TEXT_VEIL9) {
if (plr[pnum].TryRemoveInvItemById(IDI_GLDNELIX)) { if (Players[pnum].TryRemoveInvItemById(IDI_GLDNELIX)) {
monst->mtalkmsg = TEXT_VEIL11; monst->mtalkmsg = TEXT_VEIL11;
monst->_mgoal = MGOAL_INQUIRING; monst->_mgoal = MGOAL_INQUIRING;
} }
@ -5130,16 +5130,16 @@ void SpawnGolum(int i, Point position, int mi)
Monsters[i].position.future = position; Monsters[i].position.future = position;
Monsters[i].position.old = position; Monsters[i].position.old = position;
Monsters[i]._pathcount = 0; Monsters[i]._pathcount = 0;
Monsters[i]._mmaxhp = 2 * (320 * missile[mi]._mispllvl + plr[i]._pMaxMana / 3); Monsters[i]._mmaxhp = 2 * (320 * missile[mi]._mispllvl + Players[i]._pMaxMana / 3);
Monsters[i]._mhitpoints = Monsters[i]._mmaxhp; Monsters[i]._mhitpoints = Monsters[i]._mmaxhp;
Monsters[i].mArmorClass = 25; Monsters[i].mArmorClass = 25;
Monsters[i].mHit = 5 * (missile[mi]._mispllvl + 8) + 2 * plr[i]._pLevel; Monsters[i].mHit = 5 * (missile[mi]._mispllvl + 8) + 2 * Players[i]._pLevel;
Monsters[i].mMinDamage = 2 * (missile[mi]._mispllvl + 4); Monsters[i].mMinDamage = 2 * (missile[mi]._mispllvl + 4);
Monsters[i].mMaxDamage = 2 * (missile[mi]._mispllvl + 8); Monsters[i].mMaxDamage = 2 * (missile[mi]._mispllvl + 8);
Monsters[i]._mFlags |= MFLAG_GOLEM; Monsters[i]._mFlags |= MFLAG_GOLEM;
M_StartSpStand(i, DIR_S); M_StartSpStand(i, DIR_S);
M_Enemy(i); M_Enemy(i);
if (i == myplr) { if (i == MyPlayerId) {
NetSendCmdGolem( NetSendCmdGolem(
Monsters[i].position.tile.x, Monsters[i].position.tile.x,
Monsters[i].position.tile.y, Monsters[i].position.tile.y,
@ -5195,7 +5195,7 @@ void decode_enemy(int m, int enemy)
if (enemy < MAX_PLRS) { if (enemy < MAX_PLRS) {
Monsters[m]._mFlags &= ~MFLAG_TARGETS_MONSTER; Monsters[m]._mFlags &= ~MFLAG_TARGETS_MONSTER;
Monsters[m]._menemy = enemy; Monsters[m]._menemy = enemy;
Monsters[m].enemyPosition = plr[enemy].position.future; Monsters[m].enemyPosition = Players[enemy].position.future;
} else { } else {
Monsters[m]._mFlags |= MFLAG_TARGETS_MONSTER; Monsters[m]._mFlags |= MFLAG_TARGETS_MONSTER;
enemy -= MAX_PLRS; enemy -= MAX_PLRS;

574
Source/msg.cpp

File diff suppressed because it is too large Load Diff

124
Source/multi.cpp

@ -113,18 +113,18 @@ byte *ReceivePacket(TBuffer *pBuf, byte *body, size_t *size)
void NetReceivePlayerData(TPkt *pkt) void NetReceivePlayerData(TPkt *pkt)
{ {
const Point target = plr[myplr].GetTargetPosition(); const Point target = Players[MyPlayerId].GetTargetPosition();
pkt->hdr.wCheck = LoadBE32("\0\0ip"); pkt->hdr.wCheck = LoadBE32("\0\0ip");
pkt->hdr.px = plr[myplr].position.tile.x; pkt->hdr.px = Players[MyPlayerId].position.tile.x;
pkt->hdr.py = plr[myplr].position.tile.y; pkt->hdr.py = Players[MyPlayerId].position.tile.y;
pkt->hdr.targx = target.x; pkt->hdr.targx = target.x;
pkt->hdr.targy = target.y; pkt->hdr.targy = target.y;
pkt->hdr.php = plr[myplr]._pHitPoints; pkt->hdr.php = Players[MyPlayerId]._pHitPoints;
pkt->hdr.pmhp = plr[myplr]._pMaxHP; pkt->hdr.pmhp = Players[MyPlayerId]._pMaxHP;
pkt->hdr.bstr = plr[myplr]._pBaseStr; pkt->hdr.bstr = Players[MyPlayerId]._pBaseStr;
pkt->hdr.bmag = plr[myplr]._pBaseMag; pkt->hdr.bmag = Players[MyPlayerId]._pBaseMag;
pkt->hdr.bdex = plr[myplr]._pBaseDex; pkt->hdr.bdex = Players[MyPlayerId]._pBaseDex;
} }
void SendPacket(int playerId, void *packet, BYTE dwSize) void SendPacket(int playerId, void *packet, BYTE dwSize)
@ -155,9 +155,9 @@ void HandleTurnUpperBit(int pnum)
break; break;
} }
if (myplr == i) { if (MyPlayerId == i) {
sgbSendDeltaTbl[pnum] = true; sgbSendDeltaTbl[pnum] = true;
} else if (myplr == pnum) { } else if (MyPlayerId == pnum) {
gbDeltaSender = i; gbDeltaSender = i;
} }
} }
@ -177,7 +177,7 @@ void ParseTurn(int pnum, uint32_t turn)
void PlayerLeftMsg(int pnum, bool left) void PlayerLeftMsg(int pnum, bool left)
{ {
if (!plr[pnum].plractive) { if (!Players[pnum].plractive) {
return; return;
} }
@ -197,11 +197,11 @@ void PlayerLeftMsg(int pnum, bool left)
pszFmt = _("Player '{:s}' dropped due to timeout"); pszFmt = _("Player '{:s}' dropped due to timeout");
break; break;
} }
EventPlrMsg(fmt::format(pszFmt, plr[pnum]._pName).c_str()); EventPlrMsg(fmt::format(pszFmt, Players[pnum]._pName).c_str());
} }
plr[pnum].plractive = false; Players[pnum].plractive = false;
plr[pnum]._pName[0] = '\0'; Players[pnum]._pName[0] = '\0';
ResetPlayerGFX(plr[pnum]); ResetPlayerGFX(Players[pnum]);
gbActivePlayers--; gbActivePlayers--;
} }
@ -279,10 +279,10 @@ void BeginTimeout()
} else if (bGroupPlayers == bGroupCount) { } else if (bGroupPlayers == bGroupCount) {
if (nLowestPlayer != nLowestActive) { if (nLowestPlayer != nLowestActive) {
gbGameDestroyed = true; gbGameDestroyed = true;
} else if (nLowestActive == myplr) { } else if (nLowestActive == MyPlayerId) {
CheckDropPlayer(); CheckDropPlayer();
} }
} else if (nLowestActive == myplr) { } else if (nLowestActive == MyPlayerId) {
CheckDropPlayer(); CheckDropPlayer();
} }
} }
@ -305,7 +305,7 @@ void ProcessTmsgs()
TPkt pkt; TPkt pkt;
while ((cnt = tmsg_get((byte *)&pkt)) != 0) { while ((cnt = tmsg_get((byte *)&pkt)) != 0) {
HandleAllPackets(myplr, (byte *)&pkt, cnt); HandleAllPackets(MyPlayerId, (byte *)&pkt, cnt);
} }
} }
@ -313,7 +313,7 @@ void SendPlayerInfo(int pnum, _cmd_id cmd)
{ {
PkPlayerStruct pkplr; PkPlayerStruct pkplr;
PackPlayer(&pkplr, plr[myplr], true); PackPlayer(&pkplr, Players[MyPlayerId], true);
dthread_send_delta(pnum, cmd, (byte *)&pkplr, sizeof(pkplr)); dthread_send_delta(pnum, cmd, (byte *)&pkplr, sizeof(pkplr));
} }
@ -354,15 +354,15 @@ void SetupLocalPositions()
} }
#endif #endif
x += plrxoff[myplr]; x += plrxoff[MyPlayerId];
y += plryoff[myplr]; y += plryoff[MyPlayerId];
plr[myplr].position.tile = { x, y }; Players[MyPlayerId].position.tile = { x, y };
plr[myplr].position.future = { x, y }; Players[MyPlayerId].position.future = { x, y };
plr[myplr].plrlevel = currlevel; Players[MyPlayerId].plrlevel = currlevel;
plr[myplr]._pLvlChanging = true; Players[MyPlayerId]._pLvlChanging = true;
plr[myplr].pLvlLoad = 0; Players[MyPlayerId].pLvlLoad = 0;
plr[myplr]._pmode = PM_NEWLVL; Players[MyPlayerId]._pmode = PM_NEWLVL;
plr[myplr].destAction = ACTION_NONE; Players[MyPlayerId].destAction = ACTION_NONE;
} }
void HandleEvents(_SNETEVENT *pEvt) void HandleEvents(_SNETEVENT *pEvt)
@ -426,7 +426,7 @@ bool InitSingle(GameData *gameData)
app_fatal("SNetCreateGame1:\n%s", SDL_GetError()); app_fatal("SNetCreateGame1:\n%s", SDL_GetError());
} }
myplr = 0; MyPlayerId = 0;
gbIsMultiplayer = false; gbIsMultiplayer = false;
return true; return true;
@ -451,10 +451,10 @@ bool InitMulti(GameData *gameData)
if ((DWORD)playerId >= MAX_PLRS) { if ((DWORD)playerId >= MAX_PLRS) {
return false; return false;
} }
myplr = playerId; MyPlayerId = playerId;
gbIsMultiplayer = true; gbIsMultiplayer = true;
pfile_read_player_from_save(gszHero, myplr); pfile_read_player_from_save(gszHero, MyPlayerId);
return true; return true;
} }
@ -565,12 +565,12 @@ bool multi_handle_delta()
sgbTimeout = false; sgbTimeout = false;
if (received) { if (received) {
if (!gbShouldValidatePackage) { if (!gbShouldValidatePackage) {
NetSendHiPri(myplr, nullptr, 0); NetSendHiPri(MyPlayerId, nullptr, 0);
gbShouldValidatePackage = false; gbShouldValidatePackage = false;
} else { } else {
gbShouldValidatePackage = false; gbShouldValidatePackage = false;
if (sgHiPriBuf.dwNextWriteOffset != 0) if (sgHiPriBuf.dwNextWriteOffset != 0)
NetSendHiPri(myplr, nullptr, 0); NetSendHiPri(MyPlayerId, nullptr, 0);
} }
} }
MonsterSeeds(); MonsterSeeds();
@ -597,36 +597,36 @@ void multi_process_network_packets()
continue; continue;
if (pkt->wLen != dwMsgSize) if (pkt->wLen != dwMsgSize)
continue; continue;
plr[dwID].position.last = { pkt->px, pkt->py }; Players[dwID].position.last = { pkt->px, pkt->py };
if (dwID != myplr) { if (dwID != MyPlayerId) {
assert(gbBufferMsgs != 2); assert(gbBufferMsgs != 2);
plr[dwID]._pHitPoints = pkt->php; Players[dwID]._pHitPoints = pkt->php;
plr[dwID]._pMaxHP = pkt->pmhp; Players[dwID]._pMaxHP = pkt->pmhp;
bool cond = gbBufferMsgs == 1; bool cond = gbBufferMsgs == 1;
plr[dwID]._pBaseStr = pkt->bstr; Players[dwID]._pBaseStr = pkt->bstr;
plr[dwID]._pBaseMag = pkt->bmag; Players[dwID]._pBaseMag = pkt->bmag;
plr[dwID]._pBaseDex = pkt->bdex; Players[dwID]._pBaseDex = pkt->bdex;
if (!cond && plr[dwID].plractive && plr[dwID]._pHitPoints != 0) { if (!cond && Players[dwID].plractive && Players[dwID]._pHitPoints != 0) {
if (currlevel == plr[dwID].plrlevel && !plr[dwID]._pLvlChanging) { if (currlevel == Players[dwID].plrlevel && !Players[dwID]._pLvlChanging) {
int dx = abs(plr[dwID].position.tile.x - pkt->px); int dx = abs(Players[dwID].position.tile.x - pkt->px);
int dy = abs(plr[dwID].position.tile.y - pkt->py); int dy = abs(Players[dwID].position.tile.y - pkt->py);
if ((dx > 3 || dy > 3) && dPlayer[pkt->px][pkt->py] == 0) { if ((dx > 3 || dy > 3) && dPlayer[pkt->px][pkt->py] == 0) {
FixPlrWalkTags(dwID); FixPlrWalkTags(dwID);
plr[dwID].position.old = plr[dwID].position.tile; Players[dwID].position.old = Players[dwID].position.tile;
FixPlrWalkTags(dwID); FixPlrWalkTags(dwID);
plr[dwID].position.tile = { pkt->px, pkt->py }; Players[dwID].position.tile = { pkt->px, pkt->py };
plr[dwID].position.future = { pkt->px, pkt->py }; Players[dwID].position.future = { pkt->px, pkt->py };
dPlayer[plr[dwID].position.tile.x][plr[dwID].position.tile.y] = dwID + 1; dPlayer[Players[dwID].position.tile.x][Players[dwID].position.tile.y] = dwID + 1;
} }
dx = abs(plr[dwID].position.future.x - plr[dwID].position.tile.x); dx = abs(Players[dwID].position.future.x - Players[dwID].position.tile.x);
dy = abs(plr[dwID].position.future.y - plr[dwID].position.tile.y); dy = abs(Players[dwID].position.future.y - Players[dwID].position.tile.y);
if (dx > 1 || dy > 1) { if (dx > 1 || dy > 1) {
plr[dwID].position.future = plr[dwID].position.tile; Players[dwID].position.future = Players[dwID].position.tile;
} }
MakePlrPath(dwID, { pkt->targx, pkt->targy }, true); MakePlrPath(dwID, { pkt->targx, pkt->targy }, true);
} else { } else {
plr[dwID].position.tile = { pkt->px, pkt->py }; Players[dwID].position.tile = { pkt->px, pkt->py };
plr[dwID].position.future = { pkt->px, pkt->py }; Players[dwID].position.future = { pkt->px, pkt->py };
} }
} }
} }
@ -638,7 +638,7 @@ void multi_process_network_packets()
void multi_send_zero_packet(int pnum, _cmd_id bCmd, byte *pbSrc, DWORD dwLen) void multi_send_zero_packet(int pnum, _cmd_id bCmd, byte *pbSrc, DWORD dwLen)
{ {
assert(pnum != myplr); assert(pnum != MyPlayerId);
assert(pbSrc); assert(pbSrc);
assert(dwLen <= 0x0ffff); assert(dwLen <= 0x0ffff);
@ -717,7 +717,7 @@ bool NetInit(bool bSinglePlayer)
memset(sgbPlayerLeftGameTbl, 0, sizeof(sgbPlayerLeftGameTbl)); memset(sgbPlayerLeftGameTbl, 0, sizeof(sgbPlayerLeftGameTbl));
memset(sgdwPlayerLeftReasonTbl, 0, sizeof(sgdwPlayerLeftReasonTbl)); memset(sgdwPlayerLeftReasonTbl, 0, sizeof(sgdwPlayerLeftReasonTbl));
memset(sgbSendDeltaTbl, 0, sizeof(sgbSendDeltaTbl)); memset(sgbSendDeltaTbl, 0, sizeof(sgbSendDeltaTbl));
for (auto &player : plr) { for (auto &player : Players) {
player.Reset(); player.Reset();
} }
memset(sgwPackPlrOffsetTbl, 0, sizeof(sgwPackPlrOffsetTbl)); memset(sgwPackPlrOffsetTbl, 0, sizeof(sgwPackPlrOffsetTbl));
@ -737,22 +737,22 @@ bool NetInit(bool bSinglePlayer)
BufferInit(&sgLoPriBuf); BufferInit(&sgLoPriBuf);
gbShouldValidatePackage = false; gbShouldValidatePackage = false;
sync_init(); sync_init();
nthread_start(sgbPlayerTurnBitTbl[myplr]); nthread_start(sgbPlayerTurnBitTbl[MyPlayerId]);
dthread_start(); dthread_start();
tmsg_start(); tmsg_start();
sgdwGameLoops = 0; sgdwGameLoops = 0;
sgbSentThisCycle = 0; sgbSentThisCycle = 0;
gbDeltaSender = myplr; gbDeltaSender = MyPlayerId;
gbSomebodyWonGameKludge = false; gbSomebodyWonGameKludge = false;
nthread_send_and_recv_turn(0, 0); nthread_send_and_recv_turn(0, 0);
SetupLocalPositions(); SetupLocalPositions();
SendPlayerInfo(-2, CMD_SEND_PLRINFO); SendPlayerInfo(-2, CMD_SEND_PLRINFO);
ResetPlayerGFX(plr[myplr]); ResetPlayerGFX(Players[MyPlayerId]);
plr[myplr].plractive = true; Players[MyPlayerId].plractive = true;
gbActivePlayers = 1; gbActivePlayers = 1;
if (!sgbPlayerTurnBitTbl[myplr] || msg_wait_resync()) if (!sgbPlayerTurnBitTbl[MyPlayerId] || msg_wait_resync())
break; break;
NetClose(); NetClose();
gbSelectProvider = false; gbSelectProvider = false;
@ -776,11 +776,11 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
{ {
const char *szEvent; const char *szEvent;
if (myplr == pnum) { if (MyPlayerId == pnum) {
return; return;
} }
assert((DWORD)pnum < MAX_PLRS); assert((DWORD)pnum < MAX_PLRS);
auto &player = plr[pnum]; auto &player = Players[pnum];
if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) { if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) {
sgwPackPlrOffsetTbl[pnum] = 0; sgwPackPlrOffsetTbl[pnum] = 0;

718
Source/objects.cpp

File diff suppressed because it is too large Load Diff

6
Source/pack.cpp

@ -195,7 +195,7 @@ static void VerifyGoldSeeds(PlayerStruct &player)
void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync) void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
{ {
auto &player = plr[pnum]; 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 };
@ -219,7 +219,7 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
player._pGold = SDL_SwapLE32(pPack->pGold); player._pGold = SDL_SwapLE32(pPack->pGold);
player._pMaxHPBase = SDL_SwapLE32(pPack->pMaxHPBase); player._pMaxHPBase = SDL_SwapLE32(pPack->pMaxHPBase);
player._pHPBase = SDL_SwapLE32(pPack->pHPBase); player._pHPBase = SDL_SwapLE32(pPack->pHPBase);
player._pBaseToBlk = ToBlkTbl[static_cast<std::size_t>(player._pClass)]; player._pBaseToBlk = BlockBonuses[static_cast<std::size_t>(player._pClass)];
if (!netSync) if (!netSync)
if ((int)(player._pHPBase & 0xFFFFFFC0) < 64) if ((int)(player._pHPBase & 0xFFFFFFC0) < 64)
player._pHPBase = 64; player._pHPBase = 64;
@ -257,7 +257,7 @@ void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)
UnPackItem(&packedItem, &player.SpdList[i], isHellfire); UnPackItem(&packedItem, &player.SpdList[i], isHellfire);
} }
if (pnum == myplr) { if (pnum == 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;
} }

26
Source/pfile.cpp

@ -266,7 +266,7 @@ const char *pfile_get_password()
} }
PFileScopedArchiveWriter::PFileScopedArchiveWriter(bool clearTables) PFileScopedArchiveWriter::PFileScopedArchiveWriter(bool clearTables)
: save_num_(GetSaveNumberFromName(plr[myplr]._pName)) : save_num_(GetSaveNumberFromName(Players[MyPlayerId]._pName))
, clear_tables_(clearTables) , clear_tables_(clearTables)
{ {
if (!OpenArchive(save_num_)) if (!OpenArchive(save_num_))
@ -286,11 +286,11 @@ void pfile_write_hero(bool writeGameData, bool clearTables)
RenameTempToPerm(); RenameTempToPerm();
} }
PkPlayerStruct pkplr; PkPlayerStruct pkplr;
PackPlayer(&pkplr, plr[myplr], !gbIsMultiplayer); PackPlayer(&pkplr, Players[MyPlayerId], !gbIsMultiplayer);
EncodeHero(&pkplr); EncodeHero(&pkplr);
if (!gbVanilla) { if (!gbVanilla) {
SaveHotkeys(); SaveHotkeys();
SaveHeroItems(plr[myplr]); SaveHeroItems(Players[MyPlayerId]);
} }
} }
@ -312,11 +312,11 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
UnPackPlayer(&pkplr, 0, false); UnPackPlayer(&pkplr, 0, false);
CloseArchive(&archive); CloseArchive(&archive);
LoadHeroItems(plr[0]); LoadHeroItems(Players[0]);
RemoveEmptyInventory(plr[0]); RemoveEmptyInventory(Players[0]);
CalcPlrInv(0, false); CalcPlrInv(0, false);
Game2UiPlayer(plr[0], &uihero, hasSaveGame); Game2UiPlayer(Players[0], &uihero, hasSaveGame);
uiAddHeroInfo(&uihero); uiAddHeroInfo(&uihero);
} }
CloseArchive(&archive); CloseArchive(&archive);
@ -353,7 +353,7 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo)
strncpy(hero_names[saveNum], heroinfo->name, PLR_NAME_LEN); strncpy(hero_names[saveNum], heroinfo->name, PLR_NAME_LEN);
hero_names[saveNum][PLR_NAME_LEN - 1] = '\0'; hero_names[saveNum][PLR_NAME_LEN - 1] = '\0';
auto &player = plr[0]; auto &player = Players[0];
CreatePlayer(0, heroinfo->heroclass); CreatePlayer(0, heroinfo->heroclass);
strncpy(player._pName, heroinfo->name, PLR_NAME_LEN); strncpy(player._pName, heroinfo->name, PLR_NAME_LEN);
player._pName[PLR_NAME_LEN - 1] = '\0'; player._pName[PLR_NAME_LEN - 1] = '\0';
@ -399,8 +399,8 @@ void pfile_read_player_from_save(char name[16], int playerId)
UnPackPlayer(&pkplr, playerId, false); UnPackPlayer(&pkplr, playerId, false);
LoadHeroItems(plr[playerId]); LoadHeroItems(Players[playerId]);
RemoveEmptyInventory(plr[playerId]); RemoveEmptyInventory(Players[playerId]);
CalcPlrInv(playerId, false); CalcPlrInv(playerId, false);
} }
@ -410,7 +410,7 @@ bool LevelFileExists()
GetPermLevelNames(szName); GetPermLevelNames(szName);
uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); uint32_t saveNum = GetSaveNumberFromName(Players[MyPlayerId]._pName);
if (!OpenArchive(saveNum)) if (!OpenArchive(saveNum))
app_fatal("%s", _("Unable to read to save file archive")); app_fatal("%s", _("Unable to read to save file archive"));
@ -429,7 +429,7 @@ void GetTempLevelNames(char *szTemp)
void GetPermLevelNames(char *szPerm) void GetPermLevelNames(char *szPerm)
{ {
uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); uint32_t saveNum = GetSaveNumberFromName(Players[MyPlayerId]._pName);
GetTempLevelNames(szPerm); GetTempLevelNames(szPerm);
if (!OpenArchive(saveNum)) if (!OpenArchive(saveNum))
app_fatal("%s", _("Unable to read to save file archive")); app_fatal("%s", _("Unable to read to save file archive"));
@ -449,7 +449,7 @@ void pfile_remove_temp_files()
if (gbIsMultiplayer) if (gbIsMultiplayer)
return; return;
uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); uint32_t saveNum = GetSaveNumberFromName(Players[MyPlayerId]._pName);
if (!OpenArchive(saveNum)) if (!OpenArchive(saveNum))
app_fatal("%s", _("Unable to write to save file archive")); app_fatal("%s", _("Unable to write to save file archive"));
mpqapi_remove_hash_entries(GetTempSaveNames); mpqapi_remove_hash_entries(GetTempSaveNames);
@ -460,7 +460,7 @@ std::unique_ptr<byte[]> pfile_read(const char *pszName, size_t *pdwLen)
{ {
HANDLE archive; HANDLE archive;
uint32_t saveNum = GetSaveNumberFromName(plr[myplr]._pName); uint32_t saveNum = GetSaveNumberFromName(Players[MyPlayerId]._pName);
archive = OpenSaveArchive(saveNum); archive = OpenSaveArchive(saveNum);
if (archive == nullptr) if (archive == nullptr)
return nullptr; return nullptr;

318
Source/player.cpp

File diff suppressed because it is too large Load Diff

8
Source/player.h

@ -434,10 +434,10 @@ struct PlayerStruct {
} }
}; };
extern int myplr; extern int MyPlayerId;
extern PlayerStruct plr[MAX_PLRS]; extern PlayerStruct Players[MAX_PLRS];
extern bool deathflag; extern bool MyPlayerIsDead;
extern int ToBlkTbl[enum_size<HeroClass>::value]; extern int BlockBonuses[enum_size<HeroClass>::value];
void LoadPlrGFX(PlayerStruct &player, player_graphic graphic); void LoadPlrGFX(PlayerStruct &player, player_graphic graphic);
void InitPlayerGFX(PlayerStruct &player); void InitPlayerGFX(PlayerStruct &player);

4
Source/plrmsg.cpp

@ -70,9 +70,9 @@ void SendPlrMsg(int pnum, const char *pszStr)
plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1); plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1);
pMsg->player = pnum; pMsg->player = pnum;
pMsg->time = SDL_GetTicks(); pMsg->time = SDL_GetTicks();
assert(strlen(plr[pnum]._pName) < PLR_NAME_LEN); assert(strlen(Players[pnum]._pName) < PLR_NAME_LEN);
assert(strlen(pszStr) < MAX_SEND_STR_LEN); assert(strlen(pszStr) < MAX_SEND_STR_LEN);
strcpy(pMsg->str, fmt::format(_(/* TRANSLATORS: Shown if player presses "v" button. {:s} is player name, {:d} is level, {:s} is location */ "{:s} (lvl {:d}): {:s}"), plr[pnum]._pName, plr[pnum]._pLevel, pszStr).c_str()); strcpy(pMsg->str, fmt::format(_(/* TRANSLATORS: Shown if player presses "v" button. {:s} is player name, {:d} is level, {:s} is location */ "{:s} (lvl {:d}): {:s}"), Players[pnum]._pName, Players[pnum]._pLevel, pszStr).c_str());
} }
void ClearPlrMsg() void ClearPlrMsg()

10
Source/portal.cpp

@ -138,7 +138,7 @@ void GetPortalLevel()
if (currlevel != 0) { if (currlevel != 0) {
setlevel = false; setlevel = false;
currlevel = 0; currlevel = 0;
plr[myplr].plrlevel = 0; Players[MyPlayerId].plrlevel = 0;
leveltype = DTYPE_TOWN; leveltype = DTYPE_TOWN;
return; return;
} }
@ -147,16 +147,16 @@ void GetPortalLevel()
setlevel = true; setlevel = true;
setlvlnum = (_setlevels)portal[portalindex].level; setlvlnum = (_setlevels)portal[portalindex].level;
currlevel = portal[portalindex].level; currlevel = portal[portalindex].level;
plr[myplr].plrlevel = setlvlnum; Players[MyPlayerId].plrlevel = setlvlnum;
leveltype = portal[portalindex].ltype; leveltype = portal[portalindex].ltype;
} else { } else {
setlevel = false; setlevel = false;
currlevel = portal[portalindex].level; currlevel = portal[portalindex].level;
plr[myplr].plrlevel = currlevel; Players[MyPlayerId].plrlevel = currlevel;
leveltype = portal[portalindex].ltype; leveltype = portal[portalindex].ltype;
} }
if (portalindex == myplr) { if (portalindex == MyPlayerId) {
NetSendCmd(true, CMD_DEACTIVATEPORTAL); NetSendCmd(true, CMD_DEACTIVATEPORTAL);
DeactivatePortal(portalindex); DeactivatePortal(portalindex);
} }
@ -171,7 +171,7 @@ void GetPortalLvlPos()
ViewX = portal[portalindex].position.x; ViewX = portal[portalindex].position.x;
ViewY = portal[portalindex].position.y; ViewY = portal[portalindex].position.y;
if (portalindex != myplr) { if (portalindex != MyPlayerId) {
ViewX++; ViewX++;
ViewY++; ViewY++;
} }

10
Source/qol/autopickup.cpp

@ -12,7 +12,7 @@ namespace {
bool HasRoomForGold() bool HasRoomForGold()
{ {
for (int idx : plr[myplr].InvGrid) { for (int idx : Players[MyPlayerId].InvGrid) {
// Secondary item cell. No need to check those as we'll go through the main item cells anyway. // Secondary item cell. No need to check those as we'll go through the main item cells anyway.
if (idx < 0) if (idx < 0)
continue; continue;
@ -22,7 +22,7 @@ bool HasRoomForGold()
return true; return true;
// Main item cell. Potentially a gold pile so check it. // Main item cell. Potentially a gold pile so check it.
auto item = plr[myplr].InvList[idx - 1]; auto item = Players[MyPlayerId].InvList[idx - 1];
if (item._itype == ITYPE_GOLD && item._ivalue < MaxGold) if (item._itype == ITYPE_GOLD && item._ivalue < MaxGold)
return true; return true;
} }
@ -37,7 +37,7 @@ void AutoGoldPickup(int pnum)
if (!sgOptions.Gameplay.bAutoGoldPickup) if (!sgOptions.Gameplay.bAutoGoldPickup)
return; return;
if (pnum != myplr) if (pnum != MyPlayerId)
return; return;
if (leveltype == DTYPE_TOWN) if (leveltype == DTYPE_TOWN)
return; return;
@ -45,8 +45,8 @@ void AutoGoldPickup(int pnum)
return; return;
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
int x = plr[pnum].position.tile.x + pathxdir[dir]; int x = Players[pnum].position.tile.x + pathxdir[dir];
int y = plr[pnum].position.tile.y + pathydir[dir]; int y = Players[pnum].position.tile.y + pathydir[dir];
if (dItem[x][y] != 0) { if (dItem[x][y] != 0) {
int itemIndex = dItem[x][y] - 1; int itemIndex = dItem[x][y] - 1;
if (Items[itemIndex]._itype == ITYPE_GOLD) { if (Items[itemIndex]._itype == ITYPE_GOLD) {

2
Source/qol/itemlabels.cpp

@ -149,7 +149,7 @@ void DrawItemNameLabels(const Surface &out)
ItemStruct &itm = Items[label.id]; ItemStruct &itm = Items[label.id];
if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width && MousePosition.y >= label.pos.y - Height + MarginY && MousePosition.y < label.pos.y + MarginY) { if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width && MousePosition.y >= label.pos.y - Height + MarginY && MousePosition.y < label.pos.y + MarginY) {
if (!gmenu_is_active() && PauseMode == 0 && !deathflag && IsMouseOverGameArea()) { if (!gmenu_is_active() && PauseMode == 0 && !MyPlayerIsDead && IsMouseOverGameArea()) {
isLabelHighlighted = true; isLabelHighlighted = true;
cursmx = itm.position.x; cursmx = itm.position.x;
cursmy = itm.position.y; cursmy = itm.position.y;

4
Source/qol/xpbar.cpp

@ -70,7 +70,7 @@ void DrawXPBar(const Surface &out)
if (!sgOptions.Gameplay.bExperienceBar) if (!sgOptions.Gameplay.bExperienceBar)
return; return;
const auto &player = plr[myplr]; const auto &player = Players[MyPlayerId];
const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155; const int backX = PANEL_LEFT + PANEL_WIDTH / 2 - 155;
const int backY = PANEL_TOP + PANEL_HEIGHT - 11; const int backY = PANEL_TOP + PANEL_HEIGHT - 11;
@ -121,7 +121,7 @@ bool CheckXPBarInfo()
if (MousePosition.x < backX || MousePosition.x >= backX + BackWidth || MousePosition.y < backY || MousePosition.y >= backY + BackHeight) if (MousePosition.x < backX || MousePosition.x >= backX + BackWidth || MousePosition.y < backY || MousePosition.y >= backY + BackHeight)
return false; return false;
const auto &player = plr[myplr]; const auto &player = Players[MyPlayerId];
const int charLevel = player._pLevel; const int charLevel = player._pLevel;

28
Source/quests.cpp

@ -215,7 +215,7 @@ void CheckQuests()
quests[Q_BETRAYER].position.y = 2 * quests[Q_BETRAYER].position.y + 16; quests[Q_BETRAYER].position.y = 2 * quests[Q_BETRAYER].position.y + 16;
int rportx = quests[Q_BETRAYER].position.x; int rportx = quests[Q_BETRAYER].position.x;
int rporty = quests[Q_BETRAYER].position.y; int rporty = quests[Q_BETRAYER].position.y;
AddMissile({ rportx, rporty }, { rportx, rporty }, 0, MIS_RPORTAL, TARGET_MONSTERS, myplr, 0, 0); AddMissile({ rportx, rporty }, { rportx, rporty }, 0, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0);
quests[Q_BETRAYER]._qvar2 = 1; quests[Q_BETRAYER]._qvar2 = 1;
if (quests[Q_BETRAYER]._qactive == QUEST_ACTIVE) { if (quests[Q_BETRAYER]._qactive == QUEST_ACTIVE) {
quests[Q_BETRAYER]._qvar1 = 3; quests[Q_BETRAYER]._qvar1 = 3;
@ -228,7 +228,7 @@ void CheckQuests()
&& quests[Q_BETRAYER]._qvar2 == 4) { && quests[Q_BETRAYER]._qvar2 == 4) {
int rportx = 35; int rportx = 35;
int rporty = 32; int rporty = 32;
AddMissile({ rportx, rporty }, { rportx, rporty }, 0, MIS_RPORTAL, TARGET_MONSTERS, myplr, 0, 0); AddMissile({ rportx, rporty }, { rportx, rporty }, 0, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0);
quests[Q_BETRAYER]._qvar2 = 3; quests[Q_BETRAYER]._qvar2 = 3;
} }
@ -239,21 +239,21 @@ void CheckQuests()
&& ActiveMonsterCount == 4 && ActiveMonsterCount == 4
&& quests[Q_PWATER]._qactive != QUEST_DONE) { && quests[Q_PWATER]._qactive != QUEST_DONE) {
quests[Q_PWATER]._qactive = QUEST_DONE; quests[Q_PWATER]._qactive = QUEST_DONE;
PlaySfxLoc(IS_QUESTDN, plr[myplr].position.tile); PlaySfxLoc(IS_QUESTDN, Players[MyPlayerId].position.tile);
LoadPalette("Levels\\L3Data\\L3pwater.pal", false); LoadPalette("Levels\\L3Data\\L3pwater.pal", false);
UpdatePWaterPalette(); UpdatePWaterPalette();
WaterDone = 32; WaterDone = 32;
} }
} else if (plr[myplr]._pmode == PM_STAND) { } else if (Players[MyPlayerId]._pmode == PM_STAND) {
for (auto &quest : quests) { for (auto &quest : quests) {
if (currlevel == quest._qlevel if (currlevel == quest._qlevel
&& quest._qslvl != 0 && quest._qslvl != 0
&& quest._qactive != QUEST_NOTAVAIL && quest._qactive != QUEST_NOTAVAIL
&& plr[myplr].position.tile == quest.position) { && Players[MyPlayerId].position.tile == quest.position) {
if (quest._qlvltype != DTYPE_NONE) { if (quest._qlvltype != DTYPE_NONE) {
setlvltype = quest._qlvltype; setlvltype = quest._qlvltype;
} }
StartNewLvl(myplr, WM_DIABSETLVL, quest._qslvl); StartNewLvl(MyPlayerId, WM_DIABSETLVL, quest._qslvl);
} }
} }
} }
@ -308,21 +308,21 @@ void CheckQuestKill(int m, bool sendmsg)
if (Monsters[m].MType->mtype == MT_SKING) { if (Monsters[m].MType->mtype == MT_SKING) {
quests[Q_SKELKING]._qactive = QUEST_DONE; quests[Q_SKELKING]._qactive = QUEST_DONE;
plr[myplr].Say(HeroSpeech::RestWellLeoricIllFindYourSon, 30); Players[MyPlayerId].Say(HeroSpeech::RestWellLeoricIllFindYourSon, 30);
if (sendmsg) if (sendmsg)
NetSendCmdQuest(true, Q_SKELKING); NetSendCmdQuest(true, Q_SKELKING);
} else if (Monsters[m].MType->mtype == MT_CLEAVER) { } else if (Monsters[m].MType->mtype == MT_CLEAVER) {
quests[Q_BUTCHER]._qactive = QUEST_DONE; quests[Q_BUTCHER]._qactive = QUEST_DONE;
plr[myplr].Say(HeroSpeech::TheSpiritsOfTheDeadAreNowAvenged, 30); Players[MyPlayerId].Say(HeroSpeech::TheSpiritsOfTheDeadAreNowAvenged, 30);
if (sendmsg) if (sendmsg)
NetSendCmdQuest(true, Q_BUTCHER); NetSendCmdQuest(true, Q_BUTCHER);
} else if (Monsters[m]._uniqtype - 1 == UMT_GARBUD) { //"Gharbad the Weak" } else if (Monsters[m]._uniqtype - 1 == UMT_GARBUD) { //"Gharbad the Weak"
quests[Q_GARBUD]._qactive = QUEST_DONE; quests[Q_GARBUD]._qactive = QUEST_DONE;
plr[myplr].Say(HeroSpeech::ImNotImpressed, 30); Players[MyPlayerId].Say(HeroSpeech::ImNotImpressed, 30);
} else if (Monsters[m]._uniqtype - 1 == UMT_ZHAR) { //"Zhar the Mad" } else if (Monsters[m]._uniqtype - 1 == UMT_ZHAR) { //"Zhar the Mad"
quests[Q_ZHAR]._qactive = QUEST_DONE; quests[Q_ZHAR]._qactive = QUEST_DONE;
plr[myplr].Say(HeroSpeech::ImSorryDidIBreakYourConcentration, 30); Players[MyPlayerId].Say(HeroSpeech::ImSorryDidIBreakYourConcentration, 30);
} else if (Monsters[m]._uniqtype - 1 == UMT_LAZURUS && gbIsMultiplayer) { //"Arch-Bishop Lazarus" } else if (Monsters[m]._uniqtype - 1 == UMT_LAZURUS && gbIsMultiplayer) { //"Arch-Bishop Lazarus"
quests[Q_BETRAYER]._qactive = QUEST_DONE; quests[Q_BETRAYER]._qactive = QUEST_DONE;
quests[Q_BETRAYER]._qvar1 = 7; quests[Q_BETRAYER]._qvar1 = 7;
@ -337,7 +337,7 @@ void CheckQuestKill(int m, bool sendmsg)
} }
} }
} }
plr[myplr].Say(HeroSpeech::YourMadnessEndsHereBetrayer, 30); Players[MyPlayerId].Say(HeroSpeech::YourMadnessEndsHereBetrayer, 30);
if (sendmsg) { if (sendmsg) {
NetSendCmdQuest(true, Q_BETRAYER); NetSendCmdQuest(true, Q_BETRAYER);
NetSendCmdQuest(true, Q_DIABLO); NetSendCmdQuest(true, Q_DIABLO);
@ -348,11 +348,11 @@ void CheckQuestKill(int m, bool sendmsg)
quests[Q_BETRAYER]._qvar1 = 7; quests[Q_BETRAYER]._qvar1 = 7;
quests[Q_BETRAYER]._qvar2 = 4; quests[Q_BETRAYER]._qvar2 = 4;
quests[Q_DIABLO]._qactive = QUEST_ACTIVE; quests[Q_DIABLO]._qactive = QUEST_ACTIVE;
AddMissile({ 35, 32 }, { 35, 32 }, 0, MIS_RPORTAL, TARGET_MONSTERS, myplr, 0, 0); AddMissile({ 35, 32 }, { 35, 32 }, 0, MIS_RPORTAL, TARGET_MONSTERS, MyPlayerId, 0, 0);
plr[myplr].Say(HeroSpeech::YourMadnessEndsHereBetrayer, 30); Players[MyPlayerId].Say(HeroSpeech::YourMadnessEndsHereBetrayer, 30);
} else if (Monsters[m]._uniqtype - 1 == UMT_WARLORD) { //"Warlord of Blood" } else if (Monsters[m]._uniqtype - 1 == UMT_WARLORD) { //"Warlord of Blood"
quests[Q_WARLORD]._qactive = QUEST_DONE; quests[Q_WARLORD]._qactive = QUEST_DONE;
plr[myplr].Say(HeroSpeech::YourReignOfPainHasEnded, 30); Players[MyPlayerId].Say(HeroSpeech::YourReignOfPainHasEnded, 30);
} }
} }

32
Source/scrollrt.cpp

@ -317,7 +317,7 @@ static void UndrawCursor(const Surface &out)
static bool ShouldShowCursor() static bool ShouldShowCursor()
{ {
return !(sgbControllerActive && !IsMovingMouseCursorWithController() && pcurs != CURSOR_TELEPORT && !invflag && (!chrflag || plr[myplr]._pStatPts <= 0)); return !(sgbControllerActive && !IsMovingMouseCursorWithController() && pcurs != CURSOR_TELEPORT && !invflag && (!chrflag || Players[MyPlayerId]._pStatPts <= 0));
} }
/** /**
@ -458,7 +458,7 @@ static void DrawMonster(const Surface &out, int x, int y, int mx, int my, int m)
trans = Monsters[m]._uniqtrans + 4; trans = Monsters[m]._uniqtrans + 4;
if (Monsters[m]._mmode == MM_STONE) if (Monsters[m]._mmode == MM_STONE)
trans = 2; trans = 2;
if (plr[myplr]._pInfraFlag && LightTableIndex > 8) if (Players[MyPlayerId]._pInfraFlag && LightTableIndex > 8)
trans = 1; trans = 1;
if (trans != 0) if (trans != 0)
Cl2DrawLightTbl(out, mx, my, cel, nCel, trans); Cl2DrawLightTbl(out, mx, my, cel, nCel, trans);
@ -471,14 +471,14 @@ static void DrawMonster(const Surface &out, int x, int y, int mx, int my, int m)
*/ */
static void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_id missileGraphicId, int x, int y, bool lighting) static void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_id missileGraphicId, int x, int y, bool lighting)
{ {
x += CalculateWidth2(plr[pnum].AnimInfo.pCelSprite->Width()) - misfiledata[missileGraphicId].mAnimWidth2[0]; x += CalculateWidth2(Players[pnum].AnimInfo.pCelSprite->Width()) - misfiledata[missileGraphicId].mAnimWidth2[0];
int width = misfiledata[missileGraphicId].mAnimWidth[0]; int width = misfiledata[missileGraphicId].mAnimWidth[0];
byte *pCelBuff = misfiledata[missileGraphicId].mAnimData[0]; byte *pCelBuff = misfiledata[missileGraphicId].mAnimData[0];
CelSprite cel { pCelBuff, width }; CelSprite cel { pCelBuff, width };
if (pnum == myplr) { if (pnum == MyPlayerId) {
Cl2Draw(out, x, y, cel, 1); Cl2Draw(out, x, y, cel, 1);
return; return;
} }
@ -501,9 +501,9 @@ static void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_i
*/ */
static void DrawPlayerIcons(const Surface &out, int pnum, int x, int y, bool lighting) static void DrawPlayerIcons(const Surface &out, int pnum, int x, int y, bool lighting)
{ {
if (plr[pnum].pManaShield) if (Players[pnum].pManaShield)
DrawPlayerIconHelper(out, pnum, MFILE_MANASHLD, x, y, lighting); DrawPlayerIconHelper(out, pnum, MFILE_MANASHLD, x, y, lighting);
if (plr[pnum].wReflections > 0) if (Players[pnum].wReflections > 0)
DrawPlayerIconHelper(out, pnum, MFILE_REFLECT, x, y + 16, lighting); DrawPlayerIconHelper(out, pnum, MFILE_REFLECT, x, y + 16, lighting);
} }
@ -521,11 +521,11 @@ static void DrawPlayerIcons(const Surface &out, int pnum, int x, int y, bool lig
*/ */
static void DrawPlayer(const Surface &out, int pnum, int x, int y, int px, int py) static void DrawPlayer(const Surface &out, int pnum, int x, int y, int px, int py)
{ {
if ((dFlags[x][y] & BFLAG_LIT) == 0 && !plr[myplr]._pInfraFlag && leveltype != DTYPE_TOWN) { if ((dFlags[x][y] & BFLAG_LIT) == 0 && !Players[MyPlayerId]._pInfraFlag && leveltype != DTYPE_TOWN) {
return; return;
} }
auto &player = plr[pnum]; auto &player = Players[pnum];
auto *pCelSprite = player.AnimInfo.pCelSprite; auto *pCelSprite = player.AnimInfo.pCelSprite;
int nCel = player.AnimInfo.GetFrameToUseForRendering(); int nCel = player.AnimInfo.GetFrameToUseForRendering();
@ -554,13 +554,13 @@ static void DrawPlayer(const Surface &out, int pnum, int x, int y, int px, int p
if (pnum == pcursplr) if (pnum == pcursplr)
Cl2DrawOutline(out, 165, px, py, *pCelSprite, nCel); Cl2DrawOutline(out, 165, px, py, *pCelSprite, nCel);
if (pnum == myplr) { if (pnum == MyPlayerId) {
Cl2Draw(out, px, py, *pCelSprite, nCel); Cl2Draw(out, px, py, *pCelSprite, nCel);
DrawPlayerIcons(out, pnum, px, py, true); DrawPlayerIcons(out, pnum, px, py, true);
return; return;
} }
if ((dFlags[x][y] & BFLAG_LIT) == 0 || (plr[myplr]._pInfraFlag && LightTableIndex > 8)) { if ((dFlags[x][y] & BFLAG_LIT) == 0 || (Players[MyPlayerId]._pInfraFlag && LightTableIndex > 8)) {
Cl2DrawLightTbl(out, px, py, *pCelSprite, nCel, 1); Cl2DrawLightTbl(out, px, py, *pCelSprite, nCel, 1);
DrawPlayerIcons(out, pnum, px, py, true); DrawPlayerIcons(out, pnum, px, py, true);
return; return;
@ -591,7 +591,7 @@ void DrawDeadPlayer(const Surface &out, int x, int y, int sx, int sy)
dFlags[x][y] &= ~BFLAG_DEAD_PLAYER; dFlags[x][y] &= ~BFLAG_DEAD_PLAYER;
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
auto &player = plr[i]; auto &player = Players[i];
if (player.plractive && player._pHitPoints == 0 && player.plrlevel == (BYTE)currlevel && player.position.tile.x == x && player.position.tile.y == y) { if (player.plractive && player._pHitPoints == 0 && player.plrlevel == (BYTE)currlevel && player.position.tile.x == x && player.position.tile.y == y) {
dFlags[x][y] |= BFLAG_DEAD_PLAYER; dFlags[x][y] |= BFLAG_DEAD_PLAYER;
int px = sx + player.position.offset.deltaX - CalculateWidth2(player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width()); int px = sx + player.position.offset.deltaX - CalculateWidth2(player.AnimInfo.pCelSprite == nullptr ? 96 : player.AnimInfo.pCelSprite->Width());
@ -784,7 +784,7 @@ static void DrawMonsterHelper(const Surface &out, int x, int y, int oy, int sx,
return; return;
} }
if ((dFlags[x][y] & BFLAG_LIT) == 0 && !plr[myplr]._pInfraFlag) if ((dFlags[x][y] & BFLAG_LIT) == 0 && !Players[MyPlayerId]._pInfraFlag)
return; return;
if (mi < 0 || mi >= MAXMONSTERS) { if (mi < 0 || mi >= MAXMONSTERS) {
@ -834,7 +834,7 @@ static void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy)
Log("draw player: tried to draw illegal player {}", p); Log("draw player: tried to draw illegal player {}", p);
return; return;
} }
auto &player = plr[p]; auto &player = Players[p];
Displacement offset = player.position.offset; Displacement offset = player.position.offset;
if (player.IsWalking()) { if (player.IsWalking()) {
@ -1270,7 +1270,7 @@ static void DrawGame(const Surface &fullOut, int x, int y)
: fullOut.subregionY(0, (gnViewportHeight + 1) / 2); : fullOut.subregionY(0, (gnViewportHeight + 1) / 2);
// Adjust by player offset and tile grid alignment // Adjust by player offset and tile grid alignment
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
Displacement offset = ScrollInfo.offset; Displacement offset = ScrollInfo.offset;
if (myPlayer.IsWalking()) if (myPlayer.IsWalking())
offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true); offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);
@ -1392,7 +1392,7 @@ void DrawView(const Surface &out, int startX, int startY)
} else if (questlog) { } else if (questlog) {
DrawQuestLog(out); DrawQuestLog(out);
} }
if (!chrflag && plr[myplr]._pStatPts != 0 && !spselflag if (!chrflag && Players[MyPlayerId]._pStatPts != 0 && !spselflag
&& (!questlog || gnScreenHeight >= SPANEL_HEIGHT + PANEL_HEIGHT + 74 || gnScreenWidth >= 4 * SPANEL_WIDTH)) { && (!questlog || gnScreenHeight >= SPANEL_HEIGHT + PANEL_HEIGHT + 74 || gnScreenWidth >= 4 * SPANEL_WIDTH)) {
DrawLevelUpIcon(out); DrawLevelUpIcon(out);
} }
@ -1414,7 +1414,7 @@ void DrawView(const Surface &out, int startX, int startY)
if (msgflag != EMSG_NONE) { if (msgflag != EMSG_NONE) {
DrawDiabloMsg(out); DrawDiabloMsg(out);
} }
if (deathflag) { if (MyPlayerIsDead) {
RedBack(out); RedBack(out);
} else if (PauseMode != 0) { } else if (PauseMode != 0) {
gmenu_draw_pause(out); gmenu_draw_pause(out);

72
Source/spells.cpp

@ -68,24 +68,24 @@ void UseMana(int id, spell_id sn)
{ {
int ma; // mana cost int ma; // mana cost
if (id == myplr) { if (id == MyPlayerId) {
switch (plr[id]._pSplType) { switch (Players[id]._pSplType) {
case RSPLTYPE_SKILL: case RSPLTYPE_SKILL:
case RSPLTYPE_INVALID: case RSPLTYPE_INVALID:
break; break;
case RSPLTYPE_SCROLL: case RSPLTYPE_SCROLL:
RemoveScroll(plr[id]); RemoveScroll(Players[id]);
break; break;
case RSPLTYPE_CHARGES: case RSPLTYPE_CHARGES:
UseStaffCharge(plr[id]); UseStaffCharge(Players[id]);
break; break;
case RSPLTYPE_SPELL: case RSPLTYPE_SPELL:
#ifdef _DEBUG #ifdef _DEBUG
if (!debug_mode_key_inverted_v) { if (!debug_mode_key_inverted_v) {
#endif #endif
ma = GetManaAmount(plr[id], sn); ma = GetManaAmount(Players[id], sn);
plr[id]._pMana -= ma; Players[id]._pMana -= ma;
plr[id]._pManaBase -= ma; Players[id]._pManaBase -= ma;
drawmanaflag = true; drawmanaflag = true;
#ifdef _DEBUG #ifdef _DEBUG
} }
@ -172,16 +172,16 @@ bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly)
return false; return false;
} }
auto &player = plr[id]; auto &player = Players[id];
return player._pMana >= GetManaAmount(player, sn); return player._pMana >= GetManaAmount(player, sn);
} }
void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl) void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl)
{ {
Direction dir = plr[id]._pdir; Direction dir = Players[id]._pdir;
if (spl == SPL_FIREWALL || spl == SPL_LIGHTWALL) { if (spl == SPL_FIREWALL || spl == SPL_LIGHTWALL) {
dir = plr[id].tempDirection; dir = Players[id].tempDirection;
} }
for (int i = 0; spelldata[spl].sMissiles[i] != MIS_NULL && i < 3; i++) { for (int i = 0; spelldata[spl].sMissiles[i] != MIS_NULL && i < 3; i++) {
@ -203,9 +203,9 @@ static void PlacePlayer(int pnum)
{ {
Point newPosition = {}; Point newPosition = {};
if (plr[pnum].plrlevel == currlevel) { if (Players[pnum].plrlevel == currlevel) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
newPosition = plr[pnum].position.tile + Displacement { plrxoff2[i], plryoff2[i] }; newPosition = Players[pnum].position.tile + Displacement { plrxoff2[i], plryoff2[i] };
if (PosOkPlayer(pnum, newPosition)) { if (PosOkPlayer(pnum, newPosition)) {
break; break;
} }
@ -217,10 +217,10 @@ static void PlacePlayer(int pnum)
int min = -1; int min = -1;
for (int max = 1; min > -50 && !done; max++, min--) { for (int max = 1; min > -50 && !done; max++, min--) {
for (int y = min; y <= max && !done; y++) { for (int y = min; y <= max && !done; y++) {
newPosition.y = plr[pnum].position.tile.y + y; newPosition.y = Players[pnum].position.tile.y + y;
for (int x = min; x <= max && !done; x++) { for (int x = min; x <= max && !done; x++) {
newPosition.x = plr[pnum].position.tile.x + x; newPosition.x = Players[pnum].position.tile.x + x;
if (PosOkPlayer(pnum, newPosition)) { if (PosOkPlayer(pnum, newPosition)) {
done = true; done = true;
@ -230,11 +230,11 @@ static void PlacePlayer(int pnum)
} }
} }
plr[pnum].position.tile = newPosition; Players[pnum].position.tile = newPosition;
dPlayer[newPosition.x][newPosition.y] = pnum + 1; dPlayer[newPosition.x][newPosition.y] = pnum + 1;
if (pnum == myplr) { if (pnum == MyPlayerId) {
ViewX = newPosition.x; ViewX = newPosition.x;
ViewY = newPosition.y; ViewY = newPosition.y;
} }
@ -250,57 +250,57 @@ void DoResurrect(int pnum, int rid)
int hp; int hp;
if ((char)rid != -1) { if ((char)rid != -1) {
AddMissile(plr[rid].position.tile, plr[rid].position.tile, 0, MIS_RESURRECTBEAM, TARGET_MONSTERS, pnum, 0, 0); AddMissile(Players[rid].position.tile, Players[rid].position.tile, 0, MIS_RESURRECTBEAM, TARGET_MONSTERS, pnum, 0, 0);
} }
if (pnum == myplr) { if (pnum == MyPlayerId) {
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
if ((char)rid != -1 && plr[rid]._pHitPoints == 0) { if ((char)rid != -1 && Players[rid]._pHitPoints == 0) {
if (rid == myplr) { if (rid == MyPlayerId) {
deathflag = false; MyPlayerIsDead = false;
gamemenu_off(); gamemenu_off();
drawhpflag = true; drawhpflag = true;
drawmanaflag = true; drawmanaflag = true;
} }
ClrPlrPath(plr[rid]); ClrPlrPath(Players[rid]);
plr[rid].destAction = ACTION_NONE; Players[rid].destAction = ACTION_NONE;
plr[rid]._pInvincible = false; Players[rid]._pInvincible = false;
PlacePlayer(rid); PlacePlayer(rid);
hp = 10 << 6; hp = 10 << 6;
if (plr[rid]._pMaxHPBase < (10 << 6)) { if (Players[rid]._pMaxHPBase < (10 << 6)) {
hp = plr[rid]._pMaxHPBase; hp = Players[rid]._pMaxHPBase;
} }
SetPlayerHitPoints(rid, hp); SetPlayerHitPoints(rid, hp);
plr[rid]._pHPBase = plr[rid]._pHitPoints + (plr[rid]._pMaxHPBase - plr[rid]._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed Players[rid]._pHPBase = Players[rid]._pHitPoints + (Players[rid]._pMaxHPBase - Players[rid]._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed
plr[rid]._pMana = 0; Players[rid]._pMana = 0;
plr[rid]._pManaBase = plr[rid]._pMana + (plr[rid]._pMaxManaBase - plr[rid]._pMaxMana); Players[rid]._pManaBase = Players[rid]._pMana + (Players[rid]._pMaxManaBase - Players[rid]._pMaxMana);
CalcPlrInv(rid, true); CalcPlrInv(rid, true);
if (plr[rid].plrlevel == currlevel) { if (Players[rid].plrlevel == currlevel) {
StartStand(rid, plr[rid]._pdir); StartStand(rid, Players[rid]._pdir);
} else { } else {
plr[rid]._pmode = PM_STAND; Players[rid]._pmode = PM_STAND;
} }
} }
} }
void DoHealOther(int pnum, uint16_t rid) void DoHealOther(int pnum, uint16_t rid)
{ {
if (pnum == myplr) { if (pnum == MyPlayerId) {
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
} }
if ((DWORD)pnum >= MAX_PLRS || rid >= MAX_PLRS) { if ((DWORD)pnum >= MAX_PLRS || rid >= MAX_PLRS) {
return; return;
} }
auto &player = plr[pnum]; auto &player = Players[pnum];
auto &target = plr[rid]; auto &target = Players[rid];
if ((target._pHitPoints >> 6) <= 0) { if ((target._pHitPoints >> 6) <= 0) {
return; return;
@ -325,7 +325,7 @@ void DoHealOther(int pnum, uint16_t rid)
target._pHitPoints = std::min(target._pHitPoints + hp, target._pMaxHP); target._pHitPoints = std::min(target._pHitPoints + hp, target._pMaxHP);
target._pHPBase = std::min(target._pHPBase + hp, target._pMaxHPBase); target._pHPBase = std::min(target._pHPBase + hp, target._pMaxHPBase);
if (rid == myplr) { if (rid == MyPlayerId) {
drawhpflag = true; drawhpflag = true;
} }
} }

120
Source/stores.cpp

@ -199,9 +199,9 @@ void PrintStoreItem(ItemStruct *x, int l, uint16_t flags)
void StoreAutoPlace() void StoreAutoPlace()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem)) { if (AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(MyPlayerId, myPlayer.HoldItem)) {
return; return;
} }
@ -262,7 +262,7 @@ void StartSmithBuy()
stextsval = 0; stextsval = 0;
/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */
strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), Players[MyPlayerId]._pGold).c_str());
AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false);
AddSLine(3); AddSLine(3);
@ -326,7 +326,7 @@ bool StartSmithPremiumBuy()
stextsval = 0; stextsval = 0;
/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */
strcpy(tempstr, fmt::format(_("I have these premium items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); strcpy(tempstr, fmt::format(_("I have these premium items for sale: Your gold: {:d}"), Players[MyPlayerId]._pGold).c_str());
AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false);
AddSLine(3); AddSLine(3);
@ -348,9 +348,9 @@ bool SmithSellOk(int i)
ItemStruct *pI; ItemStruct *pI;
if (i >= 0) { if (i >= 0) {
pI = &plr[myplr].InvList[i]; pI = &Players[MyPlayerId].InvList[i];
} else { } else {
pI = &plr[myplr].SpdList[-(i + 1)]; pI = &Players[MyPlayerId].SpdList[-(i + 1)];
} }
if (pI->isEmpty()) if (pI->isEmpty())
@ -415,7 +415,7 @@ void StartSmithSell()
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
} }
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
for (int i = 0; i < myPlayer._pNumInv; i++) { for (int i = 0; i < myPlayer._pNumInv; i++) {
if (storenumh >= 48) if (storenumh >= 48)
@ -482,7 +482,7 @@ void StartSmithSell()
bool SmithRepairOk(int i) bool SmithRepairOk(int i)
{ {
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
if (myPlayer.InvList[i].isEmpty()) if (myPlayer.InvList[i].isEmpty())
return false; return false;
@ -506,7 +506,7 @@ void StartSmithRepair()
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
auto &helmet = myPlayer.InvBody[INVLOC_HEAD]; auto &helmet = myPlayer.InvBody[INVLOC_HEAD];
if (!helmet.isEmpty() && helmet._iDurability != helmet._iMaxDur) { if (!helmet.isEmpty() && helmet._iDurability != helmet._iMaxDur) {
@ -575,7 +575,7 @@ void FillManaPlayer()
if (!sgOptions.Gameplay.bAdriaRefillsMana) if (!sgOptions.Gameplay.bAdriaRefillsMana)
return; return;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pMana != myPlayer._pMaxMana) { if (myPlayer._pMana != myPlayer._pMaxMana) {
PlaySFX(IS_CAST8); PlaySFX(IS_CAST8);
@ -637,7 +637,7 @@ void StartWitchBuy()
stextsmax = 20; stextsmax = 20;
/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */
strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), Players[MyPlayerId]._pGold).c_str());
AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false);
AddSLine(3); AddSLine(3);
@ -662,9 +662,9 @@ bool WitchSellOk(int i)
bool rv = false; bool rv = false;
if (i >= 0) if (i >= 0)
pI = &plr[myplr].InvList[i]; pI = &Players[MyPlayerId].InvList[i];
else else
pI = &plr[myplr].SpdList[-(i + 1)]; pI = &Players[MyPlayerId].SpdList[-(i + 1)];
if (pI->_itype == ITYPE_MISC) if (pI->_itype == ITYPE_MISC)
rv = true; rv = true;
@ -691,7 +691,7 @@ void StartWitchSell()
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
} }
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
for (int i = 0; i < myPlayer._pNumInv; i++) { for (int i = 0; i < myPlayer._pNumInv; i++) {
if (storenumh >= 48) if (storenumh >= 48)
@ -758,7 +758,7 @@ void StartWitchSell()
bool WitchRechargeOk(int i) bool WitchRechargeOk(int i)
{ {
const auto &item = plr[myplr].InvList[i]; const auto &item = Players[MyPlayerId].InvList[i];
if (item._itype == ITYPE_STAFF && item._iCharges != item._iMaxCharges) { if (item._itype == ITYPE_STAFF && item._iCharges != item._iMaxCharges) {
return true; return true;
@ -791,7 +791,7 @@ void StartWitchRecharge()
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
} }
const auto &myPlayer = plr[myplr]; const auto &myPlayer = Players[MyPlayerId];
const auto &leftHand = myPlayer.InvBody[INVLOC_HAND_LEFT]; const auto &leftHand = myPlayer.InvBody[INVLOC_HAND_LEFT];
if ((leftHand._itype == ITYPE_STAFF || leftHand._iMiscId == IMISC_UNIQUE) && leftHand._iCharges != leftHand._iMaxCharges) { if ((leftHand._itype == ITYPE_STAFF || leftHand._iMiscId == IMISC_UNIQUE) && leftHand._iCharges != leftHand._iMaxCharges) {
@ -860,7 +860,7 @@ void StoreConfirm()
stextscrl = false; stextscrl = false;
ClearSText(5, 23); ClearSText(5, 23);
auto &item = plr[myplr].HoldItem; auto &item = Players[MyPlayerId].HoldItem;
uint16_t iclr = item.getTextColorWithStatCheck(); uint16_t iclr = item.getTextColorWithStatCheck();
@ -942,7 +942,7 @@ void SStartBoyBuy()
stextscrl = false; stextscrl = false;
/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */
strcpy(tempstr, fmt::format(_("I have this item for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); strcpy(tempstr, fmt::format(_("I have this item for sale: Your gold: {:d}"), Players[MyPlayerId]._pGold).c_str());
AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false);
AddSLine(3); AddSLine(3);
@ -965,7 +965,7 @@ void SStartBoyBuy()
void HealPlayer() void HealPlayer()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pHitPoints != myPlayer._pMaxHP) { if (myPlayer._pHitPoints != myPlayer._pMaxHP) {
PlaySFX(IS_CAST8); PlaySFX(IS_CAST8);
@ -1019,7 +1019,7 @@ void StartHealerBuy()
stextsval = 0; stextsval = 0;
/* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */
strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), plr[myplr]._pGold).c_str()); strcpy(tempstr, fmt::format(_("I have these items for sale: Your gold: {:d}"), Players[MyPlayerId]._pGold).c_str());
AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false);
AddSLine(3); AddSLine(3);
@ -1079,7 +1079,7 @@ void StartStorytellerIdentify()
item._itype = ITYPE_NONE; item._itype = ITYPE_NONE;
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
auto &helmet = myPlayer.InvBody[INVLOC_HEAD]; auto &helmet = myPlayer.InvBody[INVLOC_HEAD];
if (IdItemOk(&helmet)) { if (IdItemOk(&helmet)) {
@ -1168,7 +1168,7 @@ void StartStorytellerIdentifyShow()
stextscrl = false; stextscrl = false;
ClearSText(5, 23); ClearSText(5, 23);
auto &item = plr[myplr].HoldItem; auto &item = Players[MyPlayerId].HoldItem;
uint16_t iclr = item.getTextColorWithStatCheck(); uint16_t iclr = item.getTextColorWithStatCheck();
@ -1294,7 +1294,7 @@ void SmithEnter()
*/ */
void SmithBuyItem() void SmithBuyItem()
{ {
auto &item = plr[myplr].HoldItem; auto &item = Players[MyPlayerId].HoldItem;
TakePlrsMoney(item._iIvalue); TakePlrsMoney(item._iIvalue);
if (item._iMagical == ITEM_QUALITY_NORMAL) if (item._iMagical == ITEM_QUALITY_NORMAL)
@ -1309,7 +1309,7 @@ void SmithBuyItem()
} }
smithitem[idx]._itype = ITYPE_NONE; smithitem[idx]._itype = ITYPE_NONE;
} }
CalcPlrInv(myplr, true); CalcPlrInv(MyPlayerId, true);
} }
void SmitBuyEnter() void SmitBuyEnter()
@ -1324,7 +1324,7 @@ void SmitBuyEnter()
stextvhold = stextsval; stextvhold = stextsval;
stextshold = STORE_SBUY; stextshold = STORE_SBUY;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
if (myPlayer._pGold < smithitem[idx]._iIvalue) { if (myPlayer._pGold < smithitem[idx]._iIvalue) {
@ -1335,7 +1335,7 @@ void SmitBuyEnter()
myPlayer.HoldItem = smithitem[idx]; myPlayer.HoldItem = smithitem[idx];
NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(MyPlayerId, myPlayer.HoldItem, false);
if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false)) if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false))
StartStore(STORE_CONFIRM); StartStore(STORE_CONFIRM);
@ -1349,7 +1349,7 @@ void SmitBuyEnter()
*/ */
void SmithBuyPItem() void SmithBuyPItem()
{ {
auto &item = plr[myplr].HoldItem; auto &item = Players[MyPlayerId].HoldItem;
TakePlrsMoney(item._iIvalue); TakePlrsMoney(item._iIvalue);
@ -1369,7 +1369,7 @@ void SmithBuyPItem()
premiumitems[xx]._itype = ITYPE_NONE; premiumitems[xx]._itype = ITYPE_NONE;
numpremium--; numpremium--;
SpawnPremium(myplr); SpawnPremium(MyPlayerId);
} }
void SmitPremiumBuyEnter() void SmitPremiumBuyEnter()
@ -1393,7 +1393,7 @@ void SmitPremiumBuyEnter()
} }
} }
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pGold < premiumitems[idx]._iIvalue) { if (myPlayer._pGold < premiumitems[idx]._iIvalue) {
StartStore(STORE_NOMONEY); StartStore(STORE_NOMONEY);
@ -1402,7 +1402,7 @@ void SmitPremiumBuyEnter()
myPlayer.HoldItem = premiumitems[idx]; myPlayer.HoldItem = premiumitems[idx];
NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(MyPlayerId, myPlayer.HoldItem, false);
if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false)) if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false))
StartStore(STORE_CONFIRM); StartStore(STORE_CONFIRM);
@ -1426,7 +1426,7 @@ bool StoreGoldFit(int idx)
if (numsqrs >= sz) if (numsqrs >= sz)
return true; return true;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
for (int8_t itemId : myPlayer.InvGrid) { for (int8_t itemId : myPlayer.InvGrid) {
if (itemId == 0) if (itemId == 0)
@ -1456,12 +1456,12 @@ bool StoreGoldFit(int idx)
*/ */
void PlaceStoreGold(int v) void PlaceStoreGold(int v)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
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(myplr, &golditem); GetGoldSeed(MyPlayerId, &golditem);
myPlayer.InvList[ii] = golditem; myPlayer.InvList[ii] = golditem;
myPlayer._pNumInv++; myPlayer._pNumInv++;
gridNum = myPlayer._pNumInv; gridNum = myPlayer._pNumInv;
@ -1477,7 +1477,7 @@ void PlaceStoreGold(int v)
*/ */
void StoreSellItem() void StoreSellItem()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = stextvhold + ((stextlhold - stextup) / 4); int idx = stextvhold + ((stextlhold - stextup) / 4);
if (storehidx[idx] >= 0) if (storehidx[idx] >= 0)
@ -1529,7 +1529,7 @@ void SmitSellEnter()
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
stextshold = STORE_SSELL; stextshold = STORE_SSELL;
stextvhold = stextsval; stextvhold = stextsval;
plr[myplr].HoldItem = storehold[idx]; Players[MyPlayerId].HoldItem = storehold[idx];
if (StoreGoldFit(idx)) if (StoreGoldFit(idx))
StartStore(STORE_CONFIRM); StartStore(STORE_CONFIRM);
@ -1542,7 +1542,7 @@ void SmitSellEnter()
*/ */
void SmithRepairItem() void SmithRepairItem()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
TakePlrsMoney(myPlayer.HoldItem._iIvalue); TakePlrsMoney(myPlayer.HoldItem._iIvalue);
@ -1580,7 +1580,7 @@ void SmitRepairEnter()
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
myPlayer.HoldItem = storehold[idx]; myPlayer.HoldItem = storehold[idx];
if (myPlayer._pGold < storehold[idx]._iIvalue) if (myPlayer._pGold < storehold[idx]._iIvalue)
@ -1620,7 +1620,7 @@ void WitchEnter()
*/ */
void WitchBuyItem() void WitchBuyItem()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = stextvhold + ((stextlhold - stextup) / 4); int idx = stextvhold + ((stextlhold - stextup) / 4);
@ -1641,7 +1641,7 @@ void WitchBuyItem()
} }
} }
CalcPlrInv(myplr, true); CalcPlrInv(MyPlayerId, true);
} }
void WitchBuyEnter() void WitchBuyEnter()
@ -1656,7 +1656,7 @@ void WitchBuyEnter()
stextvhold = stextsval; stextvhold = stextsval;
stextshold = STORE_WBUY; stextshold = STORE_WBUY;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
@ -1667,7 +1667,7 @@ void WitchBuyEnter()
myPlayer.HoldItem = witchitem[idx]; myPlayer.HoldItem = witchitem[idx];
NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(MyPlayerId, myPlayer.HoldItem, false);
if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false) || AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, false)) if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false) || AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, false))
StartStore(STORE_CONFIRM); StartStore(STORE_CONFIRM);
@ -1690,7 +1690,7 @@ void WitchSellEnter()
stextvhold = stextsval; stextvhold = stextsval;
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
plr[myplr].HoldItem = storehold[idx]; Players[MyPlayerId].HoldItem = storehold[idx];
if (StoreGoldFit(idx)) if (StoreGoldFit(idx))
StartStore(STORE_CONFIRM); StartStore(STORE_CONFIRM);
else else
@ -1702,7 +1702,7 @@ void WitchSellEnter()
*/ */
void WitchRechargeItem() void WitchRechargeItem()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
TakePlrsMoney(myPlayer.HoldItem._iIvalue); TakePlrsMoney(myPlayer.HoldItem._iIvalue);
@ -1715,7 +1715,7 @@ void WitchRechargeItem()
else else
myPlayer.InvList[i]._iCharges = myPlayer.InvList[i]._iMaxCharges; myPlayer.InvList[i]._iCharges = myPlayer.InvList[i]._iMaxCharges;
CalcPlrInv(myplr, true); CalcPlrInv(MyPlayerId, true);
} }
void WitchRechargeEnter() void WitchRechargeEnter()
@ -1730,7 +1730,7 @@ void WitchRechargeEnter()
stextlhold = stextsel; stextlhold = stextsel;
stextvhold = stextsval; stextvhold = stextsval;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
myPlayer.HoldItem = storehold[idx]; myPlayer.HoldItem = storehold[idx];
@ -1743,7 +1743,7 @@ void WitchRechargeEnter()
void BoyEnter() void BoyEnter()
{ {
if (!boyitem.isEmpty() && stextsel == 18) { if (!boyitem.isEmpty() && stextsel == 18) {
if (plr[myplr]._pGold < 50) { if (Players[MyPlayerId]._pGold < 50) {
stextshold = STORE_BOY; stextshold = STORE_BOY;
stextlhold = 18; stextlhold = 18;
stextvhold = stextsval; stextvhold = stextsval;
@ -1770,11 +1770,11 @@ void BoyEnter()
void BoyBuyItem() void BoyBuyItem()
{ {
TakePlrsMoney(plr[myplr].HoldItem._iIvalue); TakePlrsMoney(Players[MyPlayerId].HoldItem._iIvalue);
StoreAutoPlace(); StoreAutoPlace();
boyitem._itype = ITYPE_NONE; boyitem._itype = ITYPE_NONE;
stextshold = STORE_BOY; stextshold = STORE_BOY;
CalcPlrInv(myplr, true); CalcPlrInv(MyPlayerId, true);
stextlhold = 12; stextlhold = 12;
} }
@ -1783,7 +1783,7 @@ void BoyBuyItem()
*/ */
void HealerBuyItem() void HealerBuyItem()
{ {
auto &item = plr[myplr].HoldItem; auto &item = Players[MyPlayerId].HoldItem;
int idx = stextvhold + ((stextlhold - stextup) / 4); int idx = stextvhold + ((stextlhold - stextup) / 4);
if (!gbIsMultiplayer) { if (!gbIsMultiplayer) {
@ -1815,7 +1815,7 @@ void HealerBuyItem()
} }
healitem[idx]._itype = ITYPE_NONE; healitem[idx]._itype = ITYPE_NONE;
} }
CalcPlrInv(myplr, true); CalcPlrInv(MyPlayerId, true);
} }
void BoyBuyEnter() void BoyBuyEnter()
@ -1834,7 +1834,7 @@ void BoyBuyEnter()
else else
price += boyitem._iIvalue / 2; price += boyitem._iIvalue / 2;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pGold < price) { if (myPlayer._pGold < price) {
StartStore(STORE_NOMONEY); StartStore(STORE_NOMONEY);
@ -1846,7 +1846,7 @@ void BoyBuyEnter()
NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = false; bool done = false;
if (AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false)) { if (AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(MyPlayerId, myPlayer.HoldItem, false)) {
done = true; done = true;
} }
@ -1861,7 +1861,7 @@ void BoyBuyEnter()
void StorytellerIdentifyItem() void StorytellerIdentifyItem()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = storehidx[((stextlhold - stextup) / 4) + stextvhold]; int idx = storehidx[((stextlhold - stextup) / 4) + stextvhold];
if (idx < 0) { if (idx < 0) {
@ -1884,7 +1884,7 @@ void StorytellerIdentifyItem()
} }
myPlayer.HoldItem._iIdentified = true; myPlayer.HoldItem._iIdentified = true;
TakePlrsMoney(myPlayer.HoldItem._iIvalue); TakePlrsMoney(myPlayer.HoldItem._iIvalue);
CalcPlrInv(myplr, true); CalcPlrInv(MyPlayerId, true);
} }
void ConfirmEnter() void ConfirmEnter()
@ -1972,7 +1972,7 @@ void HealerBuyEnter()
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pGold < healitem[idx]._iIvalue) { if (myPlayer._pGold < healitem[idx]._iIvalue) {
StartStore(STORE_NOMONEY); StartStore(STORE_NOMONEY);
@ -1982,7 +1982,7 @@ void HealerBuyEnter()
myPlayer.HoldItem = healitem[idx]; myPlayer.HoldItem = healitem[idx];
NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(myPlayer.HoldItem._iCurs + CURSOR_FIRSTITEM);
bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(myplr, myPlayer.HoldItem, false); bool done = AutoEquipEnabled(myPlayer, myPlayer.HoldItem) && AutoEquip(MyPlayerId, myPlayer.HoldItem, false);
if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false) || AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, false)) if (done || AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, false) || AutoPlaceItemInBelt(myPlayer, myPlayer.HoldItem, false))
StartStore(STORE_CONFIRM); StartStore(STORE_CONFIRM);
@ -2024,7 +2024,7 @@ void StorytellerIdentifyEnter()
stextlhold = stextsel; stextlhold = stextsel;
stextvhold = stextsval; stextvhold = stextsval;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int idx = stextsval + ((stextsel - stextup) / 4); int idx = stextsval + ((stextsel - stextup) / 4);
myPlayer.HoldItem = storehold[idx]; myPlayer.HoldItem = storehold[idx];
@ -2214,7 +2214,7 @@ void SetupTownStores()
{ {
SetRndSeed(glSeedTbl[currlevel] * SDL_GetTicks()); SetRndSeed(glSeedTbl[currlevel] * SDL_GetTicks());
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
int l = myPlayer._pLevel / 2; int l = myPlayer._pLevel / 2;
if (!gbIsMultiplayer) { if (!gbIsMultiplayer) {
@ -2231,7 +2231,7 @@ void SetupTownStores()
SpawnWitch(l); SpawnWitch(l);
SpawnHealer(l); SpawnHealer(l);
SpawnBoy(myPlayer._pLevel); SpawnBoy(myPlayer._pLevel);
SpawnPremium(myplr); SpawnPremium(MyPlayerId);
} }
void FreeStoreMem() void FreeStoreMem()
@ -2648,7 +2648,7 @@ void StoreNext()
void TakePlrsMoney(int cost) void TakePlrsMoney(int cost)
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
myPlayer._pGold -= cost; myPlayer._pGold -= cost;

12
Source/sync.cpp

@ -23,7 +23,7 @@ void SyncOneMonster()
{ {
for (int i = 0; i < ActiveMonsterCount; i++) { for (int i = 0; i < ActiveMonsterCount; i++) {
int m = ActiveMonsters[i]; int m = ActiveMonsters[i];
sgnMonsterPriority[m] = plr[myplr].position.tile.ManhattanDistance(Monsters[m].position.tile); sgnMonsterPriority[m] = Players[MyPlayerId].position.tile.ManhattanDistance(Monsters[m].position.tile);
if (Monsters[m]._msquelch == 0) { if (Monsters[m]._msquelch == 0) {
sgnMonsterPriority[m] += 0x1000; sgnMonsterPriority[m] += 0x1000;
} else if (sgwLRU[m] != 0) { } else if (sgwLRU[m] != 0) {
@ -131,7 +131,7 @@ void SyncPlrInv(TSyncHeader *pHdr)
} }
assert(sgnSyncPInv > -1 && sgnSyncPInv < NUM_INVLOC); assert(sgnSyncPInv > -1 && sgnSyncPInv < NUM_INVLOC);
pItem = &plr[myplr].InvBody[sgnSyncPInv]; pItem = &Players[MyPlayerId].InvBody[sgnSyncPInv];
if (!pItem->isEmpty()) { if (!pItem->isEmpty()) {
pHdr->bPInvLoc = sgnSyncPInv; pHdr->bPInvLoc = sgnSyncPInv;
pHdr->wPInvIndx = pItem->IDidx; pHdr->wPInvIndx = pItem->IDidx;
@ -197,12 +197,12 @@ static void SyncMonster(int pnum, const TSyncMonster *p)
return; return;
} }
uint32_t delta = plr[myplr].position.tile.ManhattanDistance(Monsters[ndx].position.tile); uint32_t delta = Players[MyPlayerId].position.tile.ManhattanDistance(Monsters[ndx].position.tile);
if (delta > 255) { if (delta > 255) {
delta = 255; delta = 255;
} }
if (delta < p->_mdelta || (delta == p->_mdelta && pnum > myplr)) { if (delta < p->_mdelta || (delta == p->_mdelta && pnum > MyPlayerId)) {
return; return;
} }
if (Monsters[ndx].position.future.x == p->_mx && Monsters[ndx].position.future.y == p->_my) { if (Monsters[ndx].position.future.x == p->_mx && Monsters[ndx].position.future.y == p->_my) {
@ -251,7 +251,7 @@ uint32_t sync_update(int pnum, const byte *pbBuf)
if (gbBufferMsgs == 1) { if (gbBufferMsgs == 1) {
return pHdr->wLen + sizeof(*pHdr); return pHdr->wLen + sizeof(*pHdr);
} }
if (pnum == myplr) { if (pnum == MyPlayerId) {
return pHdr->wLen + sizeof(*pHdr); return pHdr->wLen + sizeof(*pHdr);
} }
@ -270,7 +270,7 @@ uint32_t sync_update(int pnum, const byte *pbBuf)
void sync_init() void sync_init()
{ {
sgnMonsters = 16 * myplr; sgnMonsters = 16 * MyPlayerId;
memset(sgwLRU, 255, sizeof(sgwLRU)); memset(sgwLRU, 255, sizeof(sgwLRU));
} }

8
Source/town.cpp

@ -168,14 +168,14 @@ void DrlgTPass3()
FillSector("Levels\\TownData\\Sector4s.DUN", 0, 0); FillSector("Levels\\TownData\\Sector4s.DUN", 0, 0);
if (gbIsSpawn || !gbIsMultiplayer) { if (gbIsSpawn || !gbIsMultiplayer) {
if (gbIsSpawn || ((plr[myplr].pTownWarps & 1) == 0 && (!gbIsHellfire || plr[myplr]._pLevel < 10))) { if (gbIsSpawn || ((Players[MyPlayerId].pTownWarps & 1) == 0 && (!gbIsHellfire || Players[MyPlayerId]._pLevel < 10))) {
FillTile(48, 20, 320); FillTile(48, 20, 320);
} }
if (gbIsSpawn || ((plr[myplr].pTownWarps & 2) == 0 && (!gbIsHellfire || plr[myplr]._pLevel < 15))) { if (gbIsSpawn || ((Players[MyPlayerId].pTownWarps & 2) == 0 && (!gbIsHellfire || Players[MyPlayerId]._pLevel < 15))) {
FillTile(16, 68, 332); FillTile(16, 68, 332);
FillTile(16, 70, 331); FillTile(16, 70, 331);
} }
if (gbIsSpawn || ((plr[myplr].pTownWarps & 4) == 0 && (!gbIsHellfire || plr[myplr]._pLevel < 20))) { if (gbIsSpawn || ((Players[MyPlayerId].pTownWarps & 4) == 0 && (!gbIsHellfire || Players[MyPlayerId]._pLevel < 20))) {
for (int x = 36; x < 46; x++) { for (int x = 36; x < 46; x++) {
FillTile(x, 78, GenerateRnd(4) + 1); FillTile(x, 78, GenerateRnd(4) + 1);
} }
@ -188,7 +188,7 @@ void DrlgTPass3()
} else { } else {
TownCloseHive(); TownCloseHive();
} }
if (quests[Q_GRAVE]._qactive == QUEST_DONE || plr[myplr]._pLvlVisited[21]) if (quests[Q_GRAVE]._qactive == QUEST_DONE || Players[MyPlayerId]._pLvlVisited[21])
TownOpenGrave(); TownOpenGrave();
else else
TownCloseGrave(); TownCloseGrave();

2
Source/towners.cpp

@ -815,7 +815,7 @@ void InitTowners()
continue; continue;
break; break;
case TOWN_GIRL: case TOWN_GIRL:
if (!gbIsHellfire || sgGameInitInfo.bTheoQuest == 0 || !plr->_pLvlVisited[17]) if (!gbIsHellfire || sgGameInitInfo.bTheoQuest == 0 || !Players->_pLvlVisited[17])
continue; continue;
break; break;
default: default:

6
Source/track.cpp

@ -29,7 +29,7 @@ void track_process()
if (cursmx < 0 || cursmx >= MAXDUNX - 1 || cursmy < 0 || cursmy >= MAXDUNY - 1) if (cursmx < 0 || cursmx >= MAXDUNX - 1 || cursmy < 0 || cursmy >= MAXDUNY - 1)
return; return;
const auto &player = plr[myplr]; const auto &player = Players[MyPlayerId];
if (player._pmode != PM_STAND && !(player.IsWalking() && player.AnimInfo.GetFrameToUseForRendering() > 6)) if (player._pmode != PM_STAND && !(player.IsWalking() && player.AnimInfo.GetFrameToUseForRendering() > 6))
return; return;
@ -42,7 +42,7 @@ void track_process()
tickMultiplier = 3; tickMultiplier = 3;
if ((int)(tick - sgdwLastWalk) >= gnTickDelay * tickMultiplier) { if ((int)(tick - sgdwLastWalk) >= gnTickDelay * tickMultiplier) {
sgdwLastWalk = tick; sgdwLastWalk = tick;
NetSendCmdLoc(myplr, true, CMD_WALKXY, { cursmx, cursmy }); NetSendCmdLoc(MyPlayerId, true, CMD_WALKXY, { cursmx, cursmy });
if (!sgbIsScrolling) if (!sgbIsScrolling)
sgbIsScrolling = true; sgbIsScrolling = true;
} }
@ -58,7 +58,7 @@ void track_repeat_walk(bool rep)
if (rep) { if (rep) {
sgbIsScrolling = false; sgbIsScrolling = false;
sgdwLastWalk = SDL_GetTicks() - gnTickDelay; sgdwLastWalk = SDL_GetTicks() - gnTickDelay;
NetSendCmdLoc(myplr, true, CMD_WALKXY, { cursmx, cursmy }); NetSendCmdLoc(MyPlayerId, true, CMD_WALKXY, { cursmx, cursmy });
} else if (sgbIsScrolling) { } else if (sgbIsScrolling) {
sgbIsScrolling = false; sgbIsScrolling = false;
} }

18
Source/trigs.cpp

@ -76,7 +76,7 @@ void InitTownTriggers()
townwarp = gbIsMultiplayer && !gbIsSpawn; townwarp = gbIsMultiplayer && !gbIsSpawn;
} }
if (!gbIsSpawn) { if (!gbIsSpawn) {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (gbIsMultiplayer || (myPlayer.pTownWarps & 1) != 0 || (gbIsHellfire && myPlayer._pLevel >= 10)) { if (gbIsMultiplayer || (myPlayer.pTownWarps & 1) != 0 || (gbIsHellfire && myPlayer._pLevel >= 10)) {
townwarps[0] = true; townwarps[0] = true;
@ -798,7 +798,7 @@ void CheckTrigForce()
void CheckTriggers() void CheckTriggers()
{ {
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
if (myPlayer._pmode != PM_STAND) if (myPlayer._pmode != PM_STAND)
return; return;
@ -811,18 +811,18 @@ void CheckTriggers()
switch (trigs[i]._tmsg) { switch (trigs[i]._tmsg) {
case WM_DIABNEXTLVL: case WM_DIABNEXTLVL:
if (gbIsSpawn && currlevel >= 2) { if (gbIsSpawn && currlevel >= 2) {
NetSendCmdLoc(myplr, true, CMD_WALKXY, { myPlayer.position.tile.x, myPlayer.position.tile.y + 1 }); NetSendCmdLoc(MyPlayerId, true, CMD_WALKXY, { myPlayer.position.tile.x, myPlayer.position.tile.y + 1 });
myPlayer.Say(HeroSpeech::NotAChance); myPlayer.Say(HeroSpeech::NotAChance);
InitDiabloMsg(EMSG_NOT_IN_SHAREWARE); InitDiabloMsg(EMSG_NOT_IN_SHAREWARE);
} else { } else {
StartNewLvl(myplr, trigs[i]._tmsg, currlevel + 1); StartNewLvl(MyPlayerId, trigs[i]._tmsg, currlevel + 1);
} }
break; break;
case WM_DIABPREVLVL: case WM_DIABPREVLVL:
StartNewLvl(myplr, trigs[i]._tmsg, currlevel - 1); StartNewLvl(MyPlayerId, trigs[i]._tmsg, currlevel - 1);
break; break;
case WM_DIABRTNLVL: case WM_DIABRTNLVL:
StartNewLvl(myplr, trigs[i]._tmsg, ReturnLvl); StartNewLvl(MyPlayerId, trigs[i]._tmsg, ReturnLvl);
break; break;
case WM_DIABTOWNWARP: case WM_DIABTOWNWARP:
if (gbIsMultiplayer) { if (gbIsMultiplayer) {
@ -852,16 +852,16 @@ void CheckTriggers()
myPlayer.Say(HeroSpeech::ICantGetThereFromHere); myPlayer.Say(HeroSpeech::ICantGetThereFromHere);
InitDiabloMsg(abortflag); InitDiabloMsg(abortflag);
NetSendCmdLoc(myplr, true, CMD_WALKXY, position); NetSendCmdLoc(MyPlayerId, true, CMD_WALKXY, position);
return; return;
} }
} }
StartNewLvl(myplr, trigs[i]._tmsg, trigs[i]._tlvl); StartNewLvl(MyPlayerId, trigs[i]._tmsg, trigs[i]._tlvl);
break; break;
case WM_DIABTWARPUP: case WM_DIABTWARPUP:
TWarpFrom = currlevel; TWarpFrom = currlevel;
StartNewLvl(myplr, trigs[i]._tmsg, 0); StartNewLvl(MyPlayerId, trigs[i]._tmsg, 0);
break; break;
default: default:
app_fatal("Unknown trigger msg"); app_fatal("Unknown trigger msg");

2
test/control_test.cpp

@ -10,7 +10,7 @@ TEST(Control, SetSpell)
pinfoflag = true; pinfoflag = true;
pSpell = SPL_FIREBOLT; pSpell = SPL_FIREBOLT;
pSplType = RSPLTYPE_CHARGES; pSplType = RSPLTYPE_CHARGES;
auto &myPlayer = plr[myplr]; auto &myPlayer = Players[MyPlayerId];
SetSpell(); SetSpell();
EXPECT_EQ(spselflag, false); EXPECT_EQ(spselflag, false);
EXPECT_EQ(myPlayer._pRSpell, SPL_FIREBOLT); EXPECT_EQ(myPlayer._pRSpell, SPL_FIREBOLT);

10
test/effects_test.cpp

@ -7,7 +7,7 @@ using namespace devilution;
TEST(Effects, calc_snd_position_center) TEST(Effects, calc_snd_position_center)
{ {
plr[myplr].position.tile = { 50, 50 }; Players[MyPlayerId].position.tile = { 50, 50 };
int plVolume = 0; int plVolume = 0;
int plPan = 0; int plPan = 0;
EXPECT_EQ(calc_snd_position({ 50, 50 }, &plVolume, &plPan), true); EXPECT_EQ(calc_snd_position({ 50, 50 }, &plVolume, &plPan), true);
@ -17,7 +17,7 @@ TEST(Effects, calc_snd_position_center)
TEST(Effects, calc_snd_position_near) TEST(Effects, calc_snd_position_near)
{ {
plr[myplr].position.tile = { 50, 50 }; Players[MyPlayerId].position.tile = { 50, 50 };
int plVolume = 0; int plVolume = 0;
int plPan = 0; int plPan = 0;
EXPECT_EQ(calc_snd_position({ 55, 50 }, &plVolume, &plPan), true); EXPECT_EQ(calc_snd_position({ 55, 50 }, &plVolume, &plPan), true);
@ -27,7 +27,7 @@ TEST(Effects, calc_snd_position_near)
TEST(Effects, calc_snd_position_out_of_range) TEST(Effects, calc_snd_position_out_of_range)
{ {
plr[myplr].position.tile = { 12, 12 }; Players[MyPlayerId].position.tile = { 12, 12 };
int plVolume = 1234; int plVolume = 1234;
int plPan = 0; int plPan = 0;
EXPECT_EQ(calc_snd_position({ 112, 112 }, &plVolume, &plPan), false); EXPECT_EQ(calc_snd_position({ 112, 112 }, &plVolume, &plPan), false);
@ -37,7 +37,7 @@ TEST(Effects, calc_snd_position_out_of_range)
TEST(Effects, calc_snd_position_extreme_right) TEST(Effects, calc_snd_position_extreme_right)
{ {
plr[myplr].position.tile = { 50, 50 }; Players[MyPlayerId].position.tile = { 50, 50 };
int plVolume = 0; int plVolume = 0;
int plPan = 0; int plPan = 0;
EXPECT_EQ(calc_snd_position({ 75, 25 }, &plVolume, &plPan), true); EXPECT_EQ(calc_snd_position({ 75, 25 }, &plVolume, &plPan), true);
@ -47,7 +47,7 @@ TEST(Effects, calc_snd_position_extreme_right)
TEST(Effects, calc_snd_position_extreme_left) TEST(Effects, calc_snd_position_extreme_left)
{ {
plr[myplr].position.tile = { 50, 50 }; Players[MyPlayerId].position.tile = { 50, 50 };
int plVolume = 0; int plVolume = 0;
int plPan = 0; int plPan = 0;
EXPECT_EQ(calc_snd_position({ 25, 75 }, &plVolume, &plPan), true); EXPECT_EQ(calc_snd_position({ 25, 75 }, &plVolume, &plPan), true);

174
test/inv_test.cpp

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

16
test/pack_test.cpp

@ -335,8 +335,8 @@ TEST(pack, UnPackItem_diablo)
gbIsMultiplayer = false; gbIsMultiplayer = false;
gbIsSpawn = false; gbIsSpawn = false;
plr[myplr]._pMaxManaBase = 125 << 6; Players[MyPlayerId]._pMaxManaBase = 125 << 6;
plr[myplr]._pMaxHPBase = 125 << 6; Players[MyPlayerId]._pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedDiabloItems) / sizeof(*PackedDiabloItems); i++) { for (size_t i = 0; i < sizeof(PackedDiabloItems) / sizeof(*PackedDiabloItems); i++) {
UnPackItem(&PackedDiabloItems[i], &id, false); UnPackItem(&PackedDiabloItems[i], &id, false);
@ -406,8 +406,8 @@ TEST(pack, UnPackItem_spawn)
gbIsMultiplayer = false; gbIsMultiplayer = false;
gbIsSpawn = true; gbIsSpawn = true;
plr[myplr]._pMaxManaBase = 125 << 6; Players[MyPlayerId]._pMaxManaBase = 125 << 6;
plr[myplr]._pMaxHPBase = 125 << 6; Players[MyPlayerId]._pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedSpawnItems) / sizeof(*PackedSpawnItems); i++) { for (size_t i = 0; i < sizeof(PackedSpawnItems) / sizeof(*PackedSpawnItems); i++) {
UnPackItem(&PackedSpawnItems[i], &id, false); UnPackItem(&PackedSpawnItems[i], &id, false);
@ -450,8 +450,8 @@ TEST(pack, UnPackItem_diablo_multiplayer)
gbIsMultiplayer = true; gbIsMultiplayer = true;
gbIsSpawn = false; gbIsSpawn = false;
plr[myplr]._pMaxManaBase = 125 << 6; Players[MyPlayerId]._pMaxManaBase = 125 << 6;
plr[myplr]._pMaxHPBase = 125 << 6; Players[MyPlayerId]._pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedDiabloMPItems) / sizeof(*PackedDiabloMPItems); i++) { for (size_t i = 0; i < sizeof(PackedDiabloMPItems) / sizeof(*PackedDiabloMPItems); i++) {
UnPackItem(&PackedDiabloMPItems[i], &id, false); UnPackItem(&PackedDiabloMPItems[i], &id, false);
@ -659,8 +659,8 @@ TEST(pack, UnPackItem_hellfire)
gbIsMultiplayer = false; gbIsMultiplayer = false;
gbIsSpawn = false; gbIsSpawn = false;
plr[myplr]._pMaxManaBase = 125 << 6; Players[MyPlayerId]._pMaxManaBase = 125 << 6;
plr[myplr]._pMaxHPBase = 125 << 6; Players[MyPlayerId]._pMaxHPBase = 125 << 6;
for (size_t i = 0; i < sizeof(PackedHellfireItems) / sizeof(*PackedHellfireItems); i++) { for (size_t i = 0; i < sizeof(PackedHellfireItems) / sizeof(*PackedHellfireItems); i++) {
UnPackItem(&PackedHellfireItems[i], &id, true); UnPackItem(&PackedHellfireItems[i], &id, true);

2
test/player_test.cpp

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

6
test/writehero_test.cpp

@ -360,15 +360,15 @@ TEST(Writehero, pfile_write_hero)
gbIsHellfireSaveGame = false; gbIsHellfireSaveGame = false;
leveltype = DTYPE_TOWN; leveltype = DTYPE_TOWN;
myplr = 0; MyPlayerId = 0;
_uiheroinfo info {}; _uiheroinfo info {};
strcpy(info.name, "TestPlayer"); strcpy(info.name, "TestPlayer");
info.heroclass = HeroClass::Rogue; info.heroclass = HeroClass::Rogue;
pfile_ui_save_create(&info); pfile_ui_save_create(&info);
PkPlayerStruct pks; PkPlayerStruct pks;
PackPlayerTest(&pks); PackPlayerTest(&pks);
UnPackPlayer(&pks, myplr, true); UnPackPlayer(&pks, MyPlayerId, true);
AssertPlayer(plr[0]); AssertPlayer(Players[0]);
pfile_write_hero(); pfile_write_hero();
std::ifstream f("multi_0.sv", std::ios::binary); std::ifstream f("multi_0.sv", std::ios::binary);

Loading…
Cancel
Save