Browse Source

Use player by references (#4938)

pull/4900/merge
Anders Jenbo 4 years ago committed by GitHub
parent
commit
6a8fd04067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Source/control.cpp
  2. 4
      Source/controls/plrctrls.cpp
  3. 15
      Source/cursor.cpp
  4. 2
      Source/debug.cpp
  5. 6
      Source/diablo.cpp
  6. 3
      Source/engine/render/scrollrt.cpp
  7. 4
      Source/inv.cpp
  8. 36
      Source/items.cpp
  9. 2
      Source/items.h
  10. 2
      Source/loadsave.cpp
  11. 42
      Source/missiles.cpp
  12. 19
      Source/monster.cpp
  13. 179
      Source/msg.cpp
  14. 20
      Source/multi.cpp
  15. 28
      Source/objects.cpp
  16. 2
      Source/panels/spell_book.cpp
  17. 2
      Source/panels/spell_list.cpp
  18. 174
      Source/player.cpp
  19. 8
      Source/player.h
  20. 5
      Source/qol/autopickup.cpp
  21. 7
      Source/spells.cpp
  22. 2
      Source/spells.h
  23. 4
      Source/stores.cpp

4
Source/control.cpp

@ -1141,10 +1141,10 @@ void DrawTalkPan(const Surface &out)
x += 46;
int talkBtn = 0;
for (int i = 0; i < 4; i++) {
if (i == MyPlayerId)
Player &player = Players[i];
if (&player == MyPlayer)
continue;
Player &player = Players[i];
UiFlags color = player.friendlyMode ? UiFlags::ColorWhitegold : UiFlags::ColorRed;
const Point talkPanPosition = mainPanelPosition + Displacement { 172, 84 + 18 * talkBtn };
if (WhisperList[i]) {

4
Source/controls/plrctrls.cpp

@ -370,9 +370,9 @@ void CheckPlayerNearby()
return;
for (int i = 0; i < MAX_PLRS; i++) {
if (i == MyPlayerId)
continue;
const Player &player = Players[i];
if (&player == MyPlayer)
continue;
const int mx = player.position.future.x;
const int my = player.position.future.y;
if (dPlayer[mx][my] == 0

15
Source/cursor.cpp

@ -540,14 +540,16 @@ void CheckCursMove()
if (pcursmonst == -1) {
if (!flipflag && mx + 1 < MAXDUNX && dPlayer[mx + 1][my] != 0) {
int8_t bv = abs(dPlayer[mx + 1][my]) - 1;
if (bv != MyPlayerId && Players[bv]._pHitPoints != 0) {
Player &player = Players[bv];
if (&player != MyPlayer && player._pHitPoints != 0) {
cursPosition = Point { mx, my } + Displacement { 1, 0 };
pcursplr = bv;
}
}
if (flipflag && my + 1 < MAXDUNY && dPlayer[mx][my + 1] != 0) {
int8_t bv = abs(dPlayer[mx][my + 1]) - 1;
if (bv != MyPlayerId && Players[bv]._pHitPoints != 0) {
Player &player = Players[bv];
if (&player != MyPlayer && player._pHitPoints != 0) {
cursPosition = Point { mx, my } + Displacement { 0, 1 };
pcursplr = bv;
}
@ -561,7 +563,8 @@ void CheckCursMove()
}
if (TileContainsDeadPlayer({ mx, my })) {
for (int i = 0; i < MAX_PLRS; i++) {
if (Players[i].position.tile == Point { mx, my } && i != MyPlayerId) {
const Player &player = Players[i];
if (player.position.tile == Point { mx, my } && &player != MyPlayer) {
cursPosition = { mx, my };
pcursplr = i;
}
@ -572,7 +575,8 @@ void CheckCursMove()
for (int yy = -1; yy < 2; yy++) {
if (TileContainsDeadPlayer({ mx + xx, my + yy })) {
for (int i = 0; i < MAX_PLRS; i++) {
if (Players[i].position.tile.x == mx + xx && Players[i].position.tile.y == my + yy && i != MyPlayerId) {
const Player &player = Players[i];
if (player.position.tile.x == mx + xx && player.position.tile.y == my + yy && &player != MyPlayer) {
cursPosition = Point { mx, my } + Displacement { xx, yy };
pcursplr = i;
}
@ -583,7 +587,8 @@ void CheckCursMove()
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dPlayer[mx + 1][my + 1] != 0) {
int8_t bv = abs(dPlayer[mx + 1][my + 1]) - 1;
if (bv != MyPlayerId && Players[bv]._pHitPoints != 0) {
const Player &player = Players[bv];
if (&player != MyPlayer && player._pHitPoints != 0) {
cursPosition = Point { mx, my } + Displacement { 1, 1 };
pcursplr = bv;
}

2
Source/debug.cpp

@ -569,7 +569,7 @@ std::string DebugCmdChangeHealth(const string_view parameter)
int newHealth = myPlayer._pHitPoints + (change * 64);
SetPlayerHitPoints(myPlayer, newHealth);
if (newHealth <= 0)
SyncPlrKill(MyPlayerId, 0);
SyncPlrKill(myPlayer, 0);
return "Health has changed.";
}

6
Source/diablo.cpp

@ -2171,9 +2171,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
IncProgress();
bool visited = false;
int players = gbIsMultiplayer ? MAX_PLRS : 1;
for (int i = 0; i < players; i++) {
Player &player = Players[i];
for (const Player &player : Players) {
if (player.plractive)
visited = visited || player._pLvlVisited[currlevel];
}
@ -2288,7 +2286,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
for (int i = 0; i < MAX_PLRS; i++) {
Player &player = Players[i];
if (player.plractive && player.isOnActiveLevel() && (!player._pLvlChanging || i == MyPlayerId)) {
if (player.plractive && player.isOnActiveLevel() && (!player._pLvlChanging || &player == MyPlayer)) {
if (player._pHitPoints > 0) {
if (!gbIsMultiplayer)
dPlayer[player.position.tile.x][player.position.tile.y] = i + 1;

3
Source/engine/render/scrollrt.cpp

@ -578,8 +578,7 @@ void DrawDeadPlayer(const Surface &out, Point tilePosition, Point targetBufferPo
{
dFlags[tilePosition.x][tilePosition.y] &= ~DungeonFlag::DeadPlayer;
for (int i = 0; i < MAX_PLRS; i++) {
Player &player = Players[i];
for (Player &player : Players) {
if (player.plractive && player._pHitPoints == 0 && player.isOnActiveLevel() && player.position.tile == tilePosition) {
dFlags[tilePosition.x][tilePosition.y] |= DungeonFlag::DeadPlayer;
const Point playerRenderPosition { targetBufferPosition + player.position.offset };

4
Source/inv.cpp

@ -1953,7 +1953,7 @@ bool UseInvItem(int pnum, int cii)
{
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId)
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer)
return true;
if (pcurs != CURSOR_HAND)
return true;
@ -2054,7 +2054,7 @@ bool UseInvItem(int pnum, int cii)
int idata = ItemCAnimTbl[item->_iCurs];
if (item->_iMiscId == IMISC_BOOK)
PlaySFX(IS_RBOOK);
else if (pnum == MyPlayerId)
else if (&player == MyPlayer)
PlaySFX(ItemInvSnds[idata]);
UseItem(pnum, item->_iMiscId, item->_iSpell);

36
Source/items.cpp

@ -1960,13 +1960,11 @@ int RndPremiumItem(int minlvl, int maxlvl)
return RndVendorItem<PremiumItemOk>(minlvl, maxlvl);
}
void SpawnOnePremium(Item &premiumItem, int plvl, int playerId)
void SpawnOnePremium(Item &premiumItem, int plvl, Player &player)
{
int itemValue = 0;
bool keepGoing = false;
Player &player = Players[playerId];
int strength = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Strength), player._pStrength);
int dexterity = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Dexterity), player._pDexterity);
int magic = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Magic), player._pMagic);
@ -3916,7 +3914,7 @@ void UseItem(int pnum, item_misc_id mid, spell_id spl)
case IMISC_SCROLLT:
if (ControlMode == ControlTypes::KeyboardAndMouse && spelldata[spl].sTargeted) {
player._pTSpell = spl;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NewCursor(CURSOR_TELEPORT);
} else {
ClrPlrPath(player);
@ -3926,7 +3924,7 @@ void UseItem(int pnum, item_misc_id mid, spell_id spl)
player.destAction = ACTION_SPELL;
player.destParam1 = cursPosition.x;
player.destParam2 = cursPosition.y;
if (pnum == MyPlayerId && spl == SPL_NOVA)
if (&player == MyPlayer && spl == SPL_NOVA)
NetSendCmdLoc(pnum, true, CMD_NOVA, cursPosition);
}
break;
@ -3964,7 +3962,7 @@ void UseItem(int pnum, item_misc_id mid, spell_id spl)
case IMISC_OILHARD:
case IMISC_OILIMP:
player._pOilType = mid;
if (pnum != MyPlayerId) {
if (&player != MyPlayer) {
return;
}
if (sbookflag) {
@ -3983,27 +3981,27 @@ void UseItem(int pnum, item_misc_id mid, spell_id spl)
break;
case IMISC_RUNEF:
player._pTSpell = SPL_RUNEFIRE;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NewCursor(CURSOR_TELEPORT);
break;
case IMISC_RUNEL:
player._pTSpell = SPL_RUNELIGHT;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NewCursor(CURSOR_TELEPORT);
break;
case IMISC_GR_RUNEL:
player._pTSpell = SPL_RUNENOVA;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NewCursor(CURSOR_TELEPORT);
break;
case IMISC_GR_RUNEF:
player._pTSpell = SPL_RUNEIMMOLAT;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NewCursor(CURSOR_TELEPORT);
break;
case IMISC_RUNES:
player._pTSpell = SPL_RUNESTONE;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NewCursor(CURSOR_TELEPORT);
break;
default:
@ -4067,15 +4065,15 @@ void SpawnSmith(int lvl)
SortVendor(smithitem + PinnedItemCount);
}
void SpawnPremium(int pnum)
void SpawnPremium(Player &player)
{
int8_t lvl = Players[pnum]._pLevel;
int8_t lvl = player._pLevel;
int maxItems = gbIsHellfire ? SMITH_PREMIUM_ITEMS : 6;
if (numpremium < maxItems) {
for (int i = 0; i < maxItems; i++) {
if (premiumitems[i].isEmpty()) {
int plvl = premiumlevel + (gbIsHellfire ? premiumLvlAddHellfire[i] : premiumlvladd[i]);
SpawnOnePremium(premiumitems[i], plvl, pnum);
SpawnOnePremium(premiumitems[i], plvl, player);
}
}
numpremium = maxItems;
@ -4085,17 +4083,17 @@ void SpawnPremium(int pnum)
if (gbIsHellfire) {
// Discard first 3 items and shift next 10
std::move(&premiumitems[3], &premiumitems[12] + 1, &premiumitems[0]);
SpawnOnePremium(premiumitems[10], premiumlevel + premiumLvlAddHellfire[10], pnum);
SpawnOnePremium(premiumitems[10], premiumlevel + premiumLvlAddHellfire[10], player);
premiumitems[11] = premiumitems[13];
SpawnOnePremium(premiumitems[12], premiumlevel + premiumLvlAddHellfire[12], pnum);
SpawnOnePremium(premiumitems[12], premiumlevel + premiumLvlAddHellfire[12], player);
premiumitems[13] = premiumitems[14];
SpawnOnePremium(premiumitems[14], premiumlevel + premiumLvlAddHellfire[14], pnum);
SpawnOnePremium(premiumitems[14], premiumlevel + premiumLvlAddHellfire[14], player);
} else {
// Discard first 2 items and shift next 3
std::move(&premiumitems[2], &premiumitems[4] + 1, &premiumitems[0]);
SpawnOnePremium(premiumitems[3], premiumlevel + premiumlvladd[3], pnum);
SpawnOnePremium(premiumitems[3], premiumlevel + premiumlvladd[3], player);
premiumitems[4] = premiumitems[5];
SpawnOnePremium(premiumitems[5], premiumlevel + premiumlvladd[5], pnum);
SpawnOnePremium(premiumitems[5], premiumlevel + premiumlvladd[5], player);
}
}
}

2
Source/items.h

@ -504,7 +504,7 @@ void UseItem(int p, item_misc_id Mid, spell_id spl);
bool UseItemOpensHive(const Item &item, Point position);
bool UseItemOpensCrypt(const Item &item, Point position);
void SpawnSmith(int lvl);
void SpawnPremium(int pnum);
void SpawnPremium(Player &player);
void SpawnWitch(int lvl);
void SpawnBoy(int lvl);
void SpawnHealer(int lvl);

2
Source/loadsave.cpp

@ -2179,7 +2179,7 @@ void LoadGame(bool firstflag)
for (int i = 0; i < giNumberOfSmithPremiumItems; i++)
LoadPremium(file, i);
if (gbIsHellfire && !gbIsHellfireSaveGame)
SpawnPremium(MyPlayerId);
SpawnPremium(myPlayer);
AutomapActive = file.NextBool8();
AutoMapScale = file.NextBE<int32_t>();

42
Source/missiles.cpp

@ -238,7 +238,7 @@ bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, miss
if (resist)
dam >>= 2;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
monster.hitPoints -= dam;
if ((gbIsHellfire && HasAnyOf(player._pIFlags, ItemSpecialEffect::NoHealOnMonsters)) || (!gbIsHellfire && HasAnyOf(player._pIFlags, ItemSpecialEffect::FireArrows)))
@ -349,7 +349,7 @@ bool Plr2PlrMHit(const Player &player, int p, int mindam, int maxdam, int dist,
}
if (blkper < blk) {
StartPlrBlock(p, GetDirection(target.position.tile, player.position.tile));
StartPlrBlock(target, GetDirection(target.position.tile, player.position.tile));
*blocked = true;
} else {
if (&player == MyPlayer)
@ -887,7 +887,7 @@ bool PlayerMHit(int pnum, Monster *monster, int dist, int mind, int maxd, missil
{
*blocked = false;
const Player &player = Players[pnum];
Player &player = Players[pnum];
if (player._pHitPoints >> 6 <= 0) {
return false;
@ -993,14 +993,14 @@ bool PlayerMHit(int pnum, Monster *monster, int dist, int mind, int maxd, missil
dir = GetDirection(player.position.tile, monster->position.tile);
}
*blocked = true;
StartPlrBlock(pnum, dir);
StartPlrBlock(player, dir);
return true;
}
if (resper > 0) {
dam -= dam * resper / 100;
if (pnum == MyPlayerId) {
ApplyPlrDamage(pnum, 0, 0, dam, earflag);
if (&player == MyPlayer) {
ApplyPlrDamage(player, 0, 0, dam, earflag);
}
if (player._pHitPoints >> 6 > 0) {
@ -1009,8 +1009,8 @@ bool PlayerMHit(int pnum, Monster *monster, int dist, int mind, int maxd, missil
return true;
}
if (pnum == MyPlayerId) {
ApplyPlrDamage(pnum, 0, 0, dam, earflag);
if (&player == MyPlayer) {
ApplyPlrDamage(player, 0, 0, dam, earflag);
}
if (player._pHitPoints >> 6 > 0) {
@ -1049,7 +1049,7 @@ void InitMissiles()
if (missile._misource == MyPlayerId) {
int missingHP = myPlayer._pMaxHP - myPlayer._pHitPoints;
CalcPlrItemVals(myPlayer, true);
ApplyPlrDamage(MyPlayerId, 0, 1, missingHP + missile.var2);
ApplyPlrDamage(myPlayer, 0, 1, missingHP + missile.var2);
}
}
}
@ -2056,8 +2056,9 @@ void AddFlare(Missile &missile, const AddMissileParameter &parameter)
missile.var2 = missile.position.start.y;
missile._mlid = AddLight(missile.position.start, 8);
if (missile._micaster == TARGET_MONSTERS) {
UseMana(Players[missile._misource], SPL_FLARE);
ApplyPlrDamage(missile._misource, 5);
Player &player = Players[missile._misource];
UseMana(player, SPL_FLARE);
ApplyPlrDamage(player, 5);
} else if (missile._misource > 0) {
auto &monster = Monsters[missile._misource];
if (monster.type().type == MT_SUCCUBUS)
@ -2531,8 +2532,9 @@ void AddBoneSpirit(Missile &missile, const AddMissileParameter &parameter)
missile.var5 = dst.y;
missile._mlid = AddLight(missile.position.start, 8);
if (missile._micaster == TARGET_MONSTERS) {
UseMana(Players[missile._misource], SPL_BONESPIRIT);
ApplyPlrDamage(missile._misource, 6);
Player &player = Players[missile._misource];
UseMana(player, SPL_BONESPIRIT);
ApplyPlrDamage(player, 6);
}
}
@ -2545,9 +2547,7 @@ void AddRportal(Missile &missile, const AddMissileParameter & /*parameter*/)
void AddDiabApoca(Missile &missile, const AddMissileParameter & /*parameter*/)
{
int players = gbIsMultiplayer ? MAX_PLRS : 1;
for (int pnum = 0; pnum < players; pnum++) {
const Player &player = Players[pnum];
for (const Player &player : Players) {
if (!player.plractive)
continue;
if (!LineClearMissile(missile.position.start, player.position.future))
@ -3210,11 +3210,10 @@ void MI_Town(Missile &missile)
missile.var2++;
}
for (int p = 0; p < MAX_PLRS; p++) {
Player &player = Players[p];
for (Player &player : Players) {
if (player.plractive && player.isOnActiveLevel() && !player._pLvlChanging && player._pmode == PM_STAND && player.position.tile == missile.position.tile) {
ClrPlrPath(player);
if (p == MyPlayerId) {
if (&player == MyPlayer) {
NetSendCmdParam1(true, CMD_WARP, missile._misource);
player._pmode = PM_NEWLVL;
}
@ -3693,8 +3692,7 @@ void MI_Blodboil(Missile &missile)
return;
}
int id = missile._misource;
Player &player = Players[id];
Player &player = Players[missile._misource];
int hpdif = player._pMaxHP - player._pHitPoints;
@ -3710,7 +3708,7 @@ void MI_Blodboil(Missile &missile)
}
CalcPlrItemVals(player, true);
ApplyPlrDamage(id, 0, 1, hpdif);
ApplyPlrDamage(player, 0, 1, hpdif);
force_redraw = 255;
player.Say(HeroSpeech::HeavyBreathing);
}

19
Source/monster.cpp

@ -1349,15 +1349,15 @@ void MonsterAttackPlayer(int monsterId, int pnum, int hit, int minDam, int maxDa
return;
if (blkper < blk) {
Direction dir = GetDirection(player.position.tile, monster.position.tile);
StartPlrBlock(pnum, dir);
if (pnum == MyPlayerId && player.wReflections > 0) {
StartPlrBlock(player, dir);
if (&player == MyPlayer && player.wReflections > 0) {
int dam = GenerateRnd(((maxDam - minDam) << 6) + 1) + (minDam << 6);
dam = std::max(dam + (player._pIGetHit << 6), 64);
CheckReflect(monsterId, pnum, dam);
}
return;
}
if (monster.type().type == MT_YZOMBIE && pnum == MyPlayerId) {
if (monster.type().type == MT_YZOMBIE && &player == MyPlayer) {
if (player._pMaxHP > 64) {
if (player._pMaxHPBase > 64) {
player._pMaxHP -= 64;
@ -1373,10 +1373,10 @@ void MonsterAttackPlayer(int monsterId, int pnum, int hit, int minDam, int maxDa
}
int dam = (minDam << 6) + GenerateRnd(((maxDam - minDam) << 6) + 1);
dam = std::max(dam + (player._pIGetHit << 6), 64);
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
if (player.wReflections > 0)
CheckReflect(monsterId, pnum, dam);
ApplyPlrDamage(pnum, 0, 0, dam);
ApplyPlrDamage(player, 0, 0, dam);
}
// Reflect can also kill a monster, so make sure the monster is still alive
@ -3949,13 +3949,14 @@ void M_StartHit(Monster &monster, int dam)
void M_StartHit(Monster &monster, int pnum, int dam)
{
monster.whoHit |= 1 << pnum;
if (pnum == MyPlayerId) {
Player &player = Players[pnum];
if (&player == MyPlayer) {
delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), dam);
}
if (IsAnyOf(monster.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= monster.level + 3) {
monster.enemy = pnum;
monster.enemyPosition = Players[pnum].position.future;
monster.enemyPosition = player.position.future;
monster.flags &= ~MFLAG_TARGETS_MONSTER;
monster.direction = GetMonsterDirection(monster);
}
@ -3972,7 +3973,7 @@ void StartMonsterDeath(Monster &monster, int pnum, bool sendmsg)
void M_StartKill(int monsterId, int pnum)
{
assert(monsterId >= 0 && monsterId < MaxMonsters);
auto &monster = Monsters[monsterId];
Monster &monster = Monsters[monsterId];
if (pnum == MyPlayerId) {
delta_kill_monster(monsterId, monster.position.tile, *MyPlayer);
@ -4806,7 +4807,7 @@ void SpawnGolem(int id, Point position, Missile &missile)
golem.flags |= MFLAG_GOLEM;
StartSpecialStand(golem, Direction::South);
UpdateEnemy(golem);
if (id == MyPlayerId) {
if (&player == MyPlayer) {
NetSendCmdGolem(
golem.position.tile.x,
golem.position.tile.y,

179
Source/msg.cpp

@ -639,22 +639,21 @@ void DeltaPutItem(const TCmdPItem &message, Point position, const Player &player
bool IOwnLevel(const Player &player)
{
int i;
for (i = 0; i < MAX_PLRS; i++) {
if (!Players[i].plractive)
for (const Player &other : Players) {
if (!other.plractive)
continue;
if (Players[i]._pLvlChanging)
if (other._pLvlChanging)
continue;
if (Players[i].plrlevel != player.plrlevel)
if (other.plrlevel != player.plrlevel)
continue;
if (Players[i].plrIsOnSetLevel != player.plrIsOnSetLevel)
if (other.plrIsOnSetLevel != player.plrIsOnSetLevel)
continue;
if (i == MyPlayerId && gbBufferMsgs != 0)
if (&other == MyPlayer && gbBufferMsgs != 0)
continue;
break;
return &other == MyPlayer;
}
return i == MyPlayerId;
return false;
}
void DeltaOpenPortal(int pnum, Point position, uint8_t bLevel, dungeon_type bLType, bool bSetLvl)
@ -999,7 +998,7 @@ DWORD OnPutItem(const TCmd *pCmd, int pnum)
Player &player = Players[pnum];
if (player.isOnActiveLevel()) {
int ii;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
ii = InvPutItem(player, position, ItemLimbo);
else
ii = SyncPutItem(player, position, message.wIndx, message.wCI, message.dwSeed, message.bId, message.bDur, message.bMDur, message.bCh, message.bMCh, message.wValue, message.dwBuff, message.wToHit, message.wMaxDam, message.bMinStr, message.bMinMag, message.bMinDex, message.bAC);
@ -1055,7 +1054,7 @@ DWORD OnRespawnItem(const TCmd *pCmd, int pnum)
} else if (IsPItemValid(message)) {
const Point position { message.x, message.y };
Player &player = Players[pnum];
if (player.isOnActiveLevel() && pnum != MyPlayerId) {
if (player.isOnActiveLevel() && &player != MyPlayer) {
SyncPutItem(player, position, message.wIndx, message.wCI, message.dwSeed, message.bId, message.bDur, message.bMDur, message.bCh, message.bMCh, message.wValue, message.dwBuff, message.wToHit, message.wMaxDam, message.bMinStr, message.bMinMag, message.bMinDex, message.bAC);
}
PutItemRecord(message.dwSeed, message.wCI, message.wIndx);
@ -1541,13 +1540,15 @@ DWORD OnMonstDeath(const TCmd *pCmd, int pnum)
const auto &message = *reinterpret_cast<const TCmdLocParam1 *>(pCmd);
const Point position { message.x, message.y };
if (gbBufferMsgs == 1)
SendPacket(pnum, &message, sizeof(message));
else if (pnum != MyPlayerId && InDungeonBounds(position) && message.wParam1 < MaxMonsters) {
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (player.isOnActiveLevel())
M_SyncStartKill(message.wParam1, position, pnum);
delta_kill_monster(message.wParam1, position, player);
if (&player != MyPlayer && InDungeonBounds(position) && message.wParam1 < MaxMonsters) {
if (player.isOnActiveLevel())
M_SyncStartKill(message.wParam1, position, pnum);
delta_kill_monster(message.wParam1, position, player);
}
} else {
SendPacket(pnum, &message, sizeof(message));
}
return sizeof(message);
@ -1558,13 +1559,15 @@ DWORD OnKillGolem(const TCmd *pCmd, int pnum)
const auto &message = *reinterpret_cast<const TCmdLoc *>(pCmd);
const Point position { message.x, message.y };
if (gbBufferMsgs == 1)
SendPacket(pnum, &message, sizeof(message));
else if (pnum != MyPlayerId && InDungeonBounds(position)) {
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (player.isOnActiveLevel())
M_SyncStartKill(pnum, position, pnum);
delta_kill_monster(pnum, position, player);
if (&player != MyPlayer && InDungeonBounds(position)) {
if (player.isOnActiveLevel())
M_SyncStartKill(pnum, position, pnum);
delta_kill_monster(pnum, position, player);
}
} else {
SendPacket(pnum, &message, sizeof(message));
}
return sizeof(message);
@ -1578,17 +1581,18 @@ DWORD OnAwakeGolem(const TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) {
SendPacket(pnum, &message, sizeof(message));
} else if (InDungeonBounds(position)) {
if (!Players[pnum].isOnActiveLevel()) {
Player &player = Players[pnum];
if (!player.isOnActiveLevel()) {
DeltaSyncGolem(message, pnum, message._currlevel);
} else if (pnum != MyPlayerId) {
} else if (&player != MyPlayer) {
// Check if this player already has an active golem
for (auto &missile : Missiles) {
if (missile._mitype == MIS_GOLEM && missile._misource == pnum) {
if (missile._mitype == MIS_GOLEM && &Players[missile._misource] == &player) {
return sizeof(message);
}
}
AddMissile(Players[pnum].position.tile, position, message._mdir, MIS_GOLEM, TARGET_MONSTERS, pnum, 0, 1);
AddMissile(player.position.tile, position, message._mdir, MIS_GOLEM, TARGET_MONSTERS, pnum, 0, 1);
}
}
@ -1599,20 +1603,22 @@ DWORD OnMonstDamage(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdMonDamage *>(pCmd);
if (gbBufferMsgs == 1) {
SendPacket(pnum, &message, sizeof(message));
} else if (pnum != MyPlayerId) {
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (player.isOnActiveLevel() && message.wMon < MaxMonsters) {
auto &monster = Monsters[message.wMon];
monster.whoHit |= 1 << pnum;
if (monster.hitPoints > 0) {
monster.hitPoints -= message.dwDam;
if ((monster.hitPoints >> 6) < 1)
monster.hitPoints = 1 << 6;
delta_monster_hp(monster, player);
if (&player != MyPlayer) {
if (player.isOnActiveLevel() && message.wMon < MaxMonsters) {
auto &monster = Monsters[message.wMon];
monster.whoHit |= 1 << pnum;
if (monster.hitPoints > 0) {
monster.hitPoints -= message.dwDam;
if ((monster.hitPoints >> 6) < 1)
monster.hitPoints = 1 << 6;
delta_monster_hp(monster, player);
}
}
}
} else {
SendPacket(pnum, &message, sizeof(message));
}
return sizeof(message);
@ -1622,12 +1628,15 @@ DWORD OnPlayerDeath(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdParam1 *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (&player != MyPlayer)
StartPlayerKill(player, message.wParam1);
else
CheckUpdatePlayer(pnum);
} else {
SendPacket(pnum, &message, sizeof(message));
else if (pnum != MyPlayerId)
StartPlayerKill(pnum, message.wParam1);
else
CheckUpdatePlayer(pnum);
}
return sizeof(message);
}
@ -1636,9 +1645,10 @@ DWORD OnPlayerDamage(const TCmd *pCmd, Player &player)
{
const auto &message = *reinterpret_cast<const TCmdDamage *>(pCmd);
if (message.bPlr == MyPlayerId && leveltype != DTYPE_TOWN && gbBufferMsgs != 1) {
if (player.isOnActiveLevel() && message.dwDam <= 192000 && Players[message.bPlr]._pHitPoints >> 6 > 0) {
ApplyPlrDamage(message.bPlr, 0, 0, message.dwDam, 1);
Player &target = Players[message.bPlr];
if (&target == MyPlayer && leveltype != DTYPE_TOWN && gbBufferMsgs != 1) {
if (player.isOnActiveLevel() && message.dwDam <= 192000 && target._pHitPoints >> 6 > 0) {
ApplyPlrDamage(target, 0, 0, message.dwDam, 1);
}
}
@ -1738,7 +1748,7 @@ DWORD OnChangePlayerItems(const TCmd *pCmd, int pnum)
if (gbBufferMsgs == 1) {
SendPacket(pnum, &message, sizeof(message));
} else if (pnum != MyPlayerId && message.wIndx <= IDI_LAST) {
} else if (&player != MyPlayer && message.wIndx <= IDI_LAST) {
CheckInvSwap(player, bodyLocation, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff);
}
@ -1751,10 +1761,13 @@ DWORD OnDeletePlayerItems(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdDelItem *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (&player != MyPlayer && message.bLoc < NUM_INVLOC)
inv_update_rem_item(player, static_cast<inv_body_loc>(message.bLoc));
} else {
SendPacket(pnum, &message, sizeof(message));
else if (pnum != MyPlayerId && message.bLoc < NUM_INVLOC)
inv_update_rem_item(Players[pnum], static_cast<inv_body_loc>(message.bLoc));
}
return sizeof(message);
}
@ -1763,10 +1776,13 @@ DWORD OnPlayerLevel(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdParam1 *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (message.wParam1 <= MaxCharacterLevel && &player != MyPlayer)
player._pLevel = static_cast<int8_t>(message.wParam1);
} else {
SendPacket(pnum, &message, sizeof(message));
else if (message.wParam1 <= MaxCharacterLevel && pnum != MyPlayerId)
Players[pnum]._pLevel = static_cast<int8_t>(message.wParam1);
}
return sizeof(message);
}
@ -1793,7 +1809,7 @@ DWORD OnSpawnItem(const TCmd *pCmd, int pnum)
} else if (IsPItemValid(message)) {
Player &player = Players[pnum];
Point position = { message.x, message.y };
if (player.isOnActiveLevel() && pnum != MyPlayerId) {
if (player.isOnActiveLevel() && &player != MyPlayer) {
SyncDropItem(position, message.wIndx, message.wCI, message.dwSeed, message.bId, message.bDur, message.bMDur, message.bCh, message.bMCh, message.wValue, message.dwBuff, message.wToHit, message.wMaxDam, message.bMinStr, message.bMinMag, message.bMinDex, message.bAC);
}
PutItemRecord(message.dwSeed, message.wCI, message.wIndx);
@ -1841,7 +1857,7 @@ DWORD OnPlayerJoinLevel(const TCmd *pCmd, int pnum)
EventPlrMsg(fmt::format(fmt::runtime(_("Player '{:s}' (level {:d}) just joined the game")), player._pName, player._pLevel));
}
if (player.plractive && pnum != MyPlayerId) {
if (player.plractive && &player != MyPlayer) {
player.position.tile = position;
if (isSetLevel)
player.setLevel(static_cast<_setlevels>(playerLevel));
@ -1860,7 +1876,7 @@ DWORD OnPlayerJoinLevel(const TCmd *pCmd, int pnum)
dFlags[player.position.tile.x][player.position.tile.y] |= DungeonFlag::DeadPlayer;
}
player._pvid = AddVision(player.position.tile, player._pLightRad, pnum == MyPlayerId);
player._pvid = AddVision(player.position.tile, player._pLightRad, &player == MyPlayer);
}
}
@ -1880,13 +1896,14 @@ DWORD OnActivatePortal(const TCmd *pCmd, int pnum)
auto dungeonType = static_cast<dungeon_type>(message.wParam2);
ActivatePortal(pnum, position, level, dungeonType, isSetLevel);
if (pnum != MyPlayerId) {
Player &player = Players[pnum];
if (&player != MyPlayer) {
if (leveltype == DTYPE_TOWN) {
AddInTownPortal(pnum);
} else if (Players[pnum].isOnActiveLevel()) {
} else if (player.isOnActiveLevel()) {
bool addPortal = true;
for (auto &missile : Missiles) {
if (missile._mitype == MIS_TOWN && missile._misource == pnum) {
if (missile._mitype == MIS_TOWN && &Players[missile._misource] == &player) {
addPortal = false;
break;
}
@ -1937,10 +1954,13 @@ DWORD OnSetStrength(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdParam1 *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs == 1) {
Player &player = Players[pnum];
if (message.wParam1 <= 750 && &player != MyPlayer)
SetPlrStr(player, message.wParam1);
} else {
SendPacket(pnum, &message, sizeof(message));
else if (message.wParam1 <= 750 && pnum != MyPlayerId)
SetPlrStr(Players[pnum], message.wParam1);
}
return sizeof(message);
}
@ -1949,10 +1969,13 @@ DWORD OnSetDexterity(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdParam1 *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (message.wParam1 <= 750 && &player != MyPlayer)
SetPlrDex(player, message.wParam1);
} else {
SendPacket(pnum, &message, sizeof(message));
else if (message.wParam1 <= 750 && pnum != MyPlayerId)
SetPlrDex(Players[pnum], message.wParam1);
}
return sizeof(message);
}
@ -1961,10 +1984,13 @@ DWORD OnSetMagic(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdParam1 *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (message.wParam1 <= 750 && &player != MyPlayer)
SetPlrMag(player, message.wParam1);
} else {
SendPacket(pnum, &message, sizeof(message));
else if (message.wParam1 <= 750 && pnum != MyPlayerId)
SetPlrMag(Players[pnum], message.wParam1);
}
return sizeof(message);
}
@ -1973,10 +1999,13 @@ DWORD OnSetVitality(const TCmd *pCmd, int pnum)
{
const auto &message = *reinterpret_cast<const TCmdParam1 *>(pCmd);
if (gbBufferMsgs == 1)
if (gbBufferMsgs != 1) {
Player &player = Players[pnum];
if (message.wParam1 <= 750 && &player != MyPlayer)
SetPlrVit(player, message.wParam1);
} else {
SendPacket(pnum, &message, sizeof(message));
else if (message.wParam1 <= 750 && pnum != MyPlayerId)
SetPlrVit(Players[pnum], message.wParam1);
}
return sizeof(message);
}
@ -2351,9 +2380,9 @@ void DeltaSaveLevel()
if (!gbIsMultiplayer)
return;
for (int i = 0; i < MAX_PLRS; i++) {
if (i != MyPlayerId)
ResetPlayerGFX(Players[i]);
for (Player &player : Players) {
if (&player != MyPlayer)
ResetPlayerGFX(player);
}
uint8_t localLevel;
if (setlevel) {

20
Source/multi.cpp

@ -151,13 +151,14 @@ bool IsNetPlayerValid(const Player &player)
void CheckPlayerInfoTimeouts()
{
for (int i = 0; i < MAX_PLRS; i++) {
if (i == MyPlayerId) {
Player &player = Players[i];
if (&player == MyPlayer) {
continue;
}
Uint32 &timerStart = playerInfoTimers[i];
bool isPlayerConnected = (player_state[i] & PS_CONNECTED) != 0;
bool isPlayerValid = isPlayerConnected && IsNetPlayerValid(Players[i]);
bool isPlayerValid = isPlayerConnected && IsNetPlayerValid(player);
if (isPlayerConnected && !isPlayerValid && timerStart == 0) {
timerStart = SDL_GetTicks();
}
@ -228,15 +229,12 @@ void ParseTurn(int pnum, uint32_t turn)
void PlayerLeftMsg(int pnum, bool left)
{
if (pnum == MyPlayerId) {
return;
}
Player &player = Players[pnum];
if (!player.plractive) {
if (&player == MyPlayer)
return;
if (!player.plractive)
return;
}
FixPlrWalkTags(player);
RemovePortalMissile(pnum);
@ -783,11 +781,11 @@ void recv_plrinfo(int pnum, const TCmdPlrInfoHdr &header, bool recv)
{
static PlayerPack PackedPlayerBuffer[MAX_PLRS];
if (pnum == MyPlayerId) {
return;
}
assert(pnum >= 0 && pnum < MAX_PLRS);
Player &player = Players[pnum];
if (&player == MyPlayer) {
return;
}
auto &packedPlayer = PackedPlayerBuffer[pnum];
if (sgwPackPlrOffsetTbl[pnum] != header.wOffset) {

28
Source/objects.cpp

@ -1522,7 +1522,7 @@ void UpdateBurningCrossDamage(Object &cross)
if (myPlayer.position.tile != cross.position + Displacement { 0, -1 })
return;
ApplyPlrDamage(MyPlayerId, 0, 0, damage[leveltype - 1]);
ApplyPlrDamage(myPlayer, 0, 0, damage[leveltype - 1]);
if (myPlayer._pHitPoints >> 6 > 0) {
myPlayer.Say(HeroSpeech::Argh);
}
@ -2350,8 +2350,8 @@ void OperateChest(int pnum, int i, bool sendmsg)
CreateRndUseful(Objects[i].position, sendmsg);
}
}
const Player &player = Players[pnum];
if (Objects[i].IsTrappedChest()) {
const Player &player = Players[pnum];
Direction mdir = GetDirection(Objects[i].position, player.position.tile);
missile_id mtype;
switch (Objects[i]._oVar4) {
@ -2379,7 +2379,7 @@ void OperateChest(int pnum, int i, bool sendmsg)
AddMissile(Objects[i].position, player.position.tile, mdir, mtype, TARGET_PLAYERS, -1, 0, 0);
Objects[i]._oTrapFlag = false;
}
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NetSendCmdParam2(false, CMD_PLROPOBJ, pnum, i);
}
@ -3521,7 +3521,7 @@ bool OperateFountains(int pnum, int i)
bool applied = false;
switch (Objects[i]._otype) {
case OBJ_BLOODFTN:
if (pnum != MyPlayerId)
if (&player != MyPlayer)
return false;
if (player._pHitPoints < player._pMaxHP) {
@ -3537,7 +3537,7 @@ bool OperateFountains(int pnum, int i)
PlaySfxLoc(LS_FOUNTAIN, Objects[i].position);
break;
case OBJ_PURIFYINGFTN:
if (pnum != MyPlayerId)
if (&player != MyPlayer)
return false;
if (player._pMana < player._pMaxMana) {
@ -3569,7 +3569,7 @@ bool OperateFountains(int pnum, int i)
0,
2 * leveltype);
applied = true;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NetSendCmdParam1(false, CMD_OPERATEOBJ, i);
break;
case OBJ_TEARFTN: {
@ -3577,7 +3577,7 @@ bool OperateFountains(int pnum, int i)
break;
PlaySfxLoc(LS_FOUNTAIN, Objects[i].position);
Objects[i]._oSelFlag = 0;
if (pnum != MyPlayerId)
if (&player != MyPlayer)
return false;
unsigned randomValue = (Objects[i]._oRndSeed >> 16) % 12;
@ -3606,7 +3606,7 @@ bool OperateFountains(int pnum, int i)
CheckStats(player);
applied = true;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NetSendCmdParam1(false, CMD_OPERATEOBJ, i);
} break;
default:
@ -4809,8 +4809,8 @@ int ItemMiscIdIdx(item_misc_id imiscid)
void OperateObject(int pnum, int i, bool teleFlag)
{
bool sendmsg = pnum == MyPlayerId;
const Player &player = Players[pnum];
bool sendmsg = &player == MyPlayer;
switch (Objects[i]._otype) {
case OBJ_L1LDOOR:
case OBJ_L1RDOOR:
@ -5034,28 +5034,28 @@ void DeltaSyncOpObject(int cmd, int i)
void SyncOpObject(int pnum, int cmd, int i)
{
bool sendmsg = pnum == MyPlayerId;
const Player &player = Players[pnum];
bool sendmsg = &player == MyPlayer;
switch (Objects[i]._otype) {
case OBJ_L1LDOOR:
case OBJ_L1RDOOR:
if (pnum != MyPlayerId)
if (!sendmsg)
SyncOpL1Door(cmd, i);
break;
case OBJ_L2LDOOR:
case OBJ_L2RDOOR:
if (pnum != MyPlayerId)
if (!sendmsg)
SyncOpL2Door(cmd, i);
break;
case OBJ_L3LDOOR:
case OBJ_L3RDOOR:
if (pnum != MyPlayerId)
if (!sendmsg)
SyncOpL3Door(cmd, i);
break;
case OBJ_L5LDOOR:
case OBJ_L5RDOOR:
if (pnum != MyPlayerId)
if (!sendmsg)
SyncOpL5Door(cmd, i);
break;
case OBJ_LEVER:

2
Source/panels/spell_book.cpp

@ -63,7 +63,7 @@ spell_type GetSBookTrans(spell_id ii, bool townok)
st = RSPLTYPE_SKILL;
}
if (st == RSPLTYPE_SPELL) {
if (CheckSpell(MyPlayerId, ii, st, true) != SpellCheckResult::Success) {
if (CheckSpell(*MyPlayer, ii, st, true) != SpellCheckResult::Success) {
st = RSPLTYPE_INVALID;
}
if (player.GetSpellLevel(ii) == 0) {

2
Source/panels/spell_list.cpp

@ -110,7 +110,7 @@ void DrawSpell(const Surface &out)
if (st == RSPLTYPE_SPELL) {
int tlvl = myPlayer.GetSpellLevel(spl);
if (CheckSpell(MyPlayerId, spl, st, true) != SpellCheckResult::Success)
if (CheckSpell(*MyPlayer, spl, st, true) != SpellCheckResult::Success)
st = RSPLTYPE_INVALID;
if (tlvl <= 0)
st = RSPLTYPE_INVALID;

174
Source/player.cpp

@ -330,7 +330,7 @@ void HandleWalkMode(int pnum, Displacement vel, Direction dir)
// The player's tile position after finishing this movement action
player.position.future = player.position.tile + dirModeParams.tileAdd;
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
ScrollViewPort(player, dirModeParams.scrollDir);
}
@ -361,8 +361,8 @@ void StartWalk(int pnum, Displacement vel, Direction dir, bool pmWillBeCalled)
{
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -431,15 +431,10 @@ void ChangeOffset(Player &player)
PmChangeLightOff(player);
}
void StartAttack(int pnum, Direction d)
void StartAttack(Player &player, Direction d)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal(StrCat("StartAttack: illegal player ", pnum));
}
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -463,15 +458,10 @@ void StartAttack(int pnum, Direction d)
SetPlayerOld(player);
}
void StartRangeAttack(int pnum, Direction d, WorldTileCoord cx, WorldTileCoord cy)
void StartRangeAttack(Player &player, Direction d, WorldTileCoord cx, WorldTileCoord cy)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal(StrCat("StartRangeAttack: illegal player ", pnum));
}
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -505,14 +495,10 @@ player_graphic GetPlayerGraphicForSpell(spell_id spellId)
}
}
void StartSpell(int pnum, Direction d, WorldTileCoord cx, WorldTileCoord cy)
void StartSpell(Player &player, Direction d, WorldTileCoord cx, WorldTileCoord cy)
{
if ((DWORD)pnum >= MAX_PLRS)
app_fatal(StrCat("StartSpell: illegal player ", pnum));
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -690,7 +676,7 @@ bool DoWalk(int pnum, int variant)
}
// Update the "camera" tile position
if (pnum == MyPlayerId && ScrollInfo._sdir != ScrollDirection::None) {
if (&player == MyPlayer && ScrollInfo._sdir != ScrollDirection::None) {
ViewPosition = Point { 0, 0 } + (player.position.tile - ScrollInfo.tile);
}
@ -906,11 +892,11 @@ bool PlrHitMonst(int pnum, int monsterId, bool adjacentDamage = false)
if (adjacentDamage)
dam >>= 2;
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
if (HasAnyOf(player.pDamAcFlags, ItemSpecialEffectHf::Peril)) {
dam2 += player._pIGetHit << 6;
if (dam2 >= 0) {
ApplyPlrDamage(pnum, 0, 1, dam2);
ApplyPlrDamage(player, 0, 1, dam2);
}
dam *= 2;
}
@ -1016,7 +1002,7 @@ bool PlrHitPlr(Player &attacker, int8_t p)
if (blk < blkper) {
Direction dir = GetDirection(target.position.tile, attacker.position.tile);
StartPlrBlock(p, dir);
StartPlrBlock(target, dir);
return true;
}
@ -1491,7 +1477,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
Direction d;
if (player.walkpath[0] != WALK_NONE) {
if (player._pmode == PM_STAND) {
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
if (player.destAction == ACTION_ATTACKMON || player.destAction == ACTION_ATTACKPLR) {
if (player.destAction == ACTION_ATTACKMON) {
x = abs(player.position.future.x - monster->position.future.x);
@ -1508,7 +1494,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if (player.destAction == ACTION_ATTACKMON && monster->talkMsg != TEXT_NONE && monster->talkMsg != TEXT_VILE14) {
TalktoMonster(*monster);
} else {
StartAttack(pnum, d);
StartAttack(player, d);
}
player.destAction = ACTION_NONE;
}
@ -1573,7 +1559,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
switch (player.destAction) {
case ACTION_ATTACK:
d = GetDirection(player.position.tile, { player.destParam1, player.destParam2 });
StartAttack(pnum, d);
StartAttack(player, d);
break;
case ACTION_ATTACKMON:
x = abs(player.position.tile.x - monster->position.future.x);
@ -1583,7 +1569,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if (monster->talkMsg != TEXT_NONE && monster->talkMsg != TEXT_VILE14) {
TalktoMonster(*monster);
} else {
StartAttack(pnum, d);
StartAttack(player, d);
}
}
break;
@ -1592,50 +1578,50 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
y = abs(player.position.tile.y - target->position.future.y);
if (x <= 1 && y <= 1) {
d = GetDirection(player.position.future, target->position.future);
StartAttack(pnum, d);
StartAttack(player, d);
}
break;
case ACTION_RATTACK:
d = GetDirection(player.position.tile, { player.destParam1, player.destParam2 });
StartRangeAttack(pnum, d, player.destParam1, player.destParam2);
StartRangeAttack(player, d, player.destParam1, player.destParam2);
break;
case ACTION_RATTACKMON:
d = GetDirection(player.position.future, monster->position.future);
if (monster->talkMsg != TEXT_NONE && monster->talkMsg != TEXT_VILE14) {
TalktoMonster(*monster);
} else {
StartRangeAttack(pnum, d, monster->position.future.x, monster->position.future.y);
StartRangeAttack(player, d, monster->position.future.x, monster->position.future.y);
}
break;
case ACTION_RATTACKPLR:
d = GetDirection(player.position.future, target->position.future);
StartRangeAttack(pnum, d, target->position.future.x, target->position.future.y);
StartRangeAttack(player, d, target->position.future.x, target->position.future.y);
break;
case ACTION_SPELL:
d = GetDirection(player.position.tile, { player.destParam1, player.destParam2 });
StartSpell(pnum, d, player.destParam1, player.destParam2);
StartSpell(player, d, player.destParam1, player.destParam2);
player.spellLevel = player.destParam3;
break;
case ACTION_SPELLWALL:
StartSpell(pnum, static_cast<Direction>(player.destParam3), player.destParam1, player.destParam2);
StartSpell(player, static_cast<Direction>(player.destParam3), player.destParam1, player.destParam2);
player.tempDirection = static_cast<Direction>(player.destParam3);
player.spellLevel = player.destParam4;
break;
case ACTION_SPELLMON:
d = GetDirection(player.position.tile, monster->position.future);
StartSpell(pnum, d, monster->position.future.x, monster->position.future.y);
StartSpell(player, d, monster->position.future.x, monster->position.future.y);
player.spellLevel = player.destParam2;
break;
case ACTION_SPELLPLR:
d = GetDirection(player.position.tile, target->position.future);
StartSpell(pnum, d, target->position.future.x, target->position.future.y);
StartSpell(player, d, target->position.future.x, target->position.future.y);
player.spellLevel = player.destParam2;
break;
case ACTION_OPERATE:
if (IsPlayerAdjacentToObject(player, *object)) {
if (object->_oBreak == 1) {
d = GetDirection(player.position.tile, object->position);
StartAttack(pnum, d);
StartAttack(player, d);
} else {
OperateObject(pnum, targetId, false);
}
@ -1645,7 +1631,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if (IsPlayerAdjacentToObject(player, *object)) {
if (object->_oBreak == 1) {
d = GetDirection(player.position.tile, object->position);
StartAttack(pnum, d);
StartAttack(player, d);
} else {
TryDisarm(player, *object);
OperateObject(pnum, targetId, false);
@ -1658,7 +1644,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
}
break;
case ACTION_PICKUPITEM:
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
x = abs(player.position.tile.x - item->position.x);
y = abs(player.position.tile.y - item->position.y);
if (x <= 1 && y <= 1 && pcurs == CURSOR_HAND && !item->_iRequest) {
@ -1668,7 +1654,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
}
break;
case ACTION_PICKUPAITEM:
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
x = abs(player.position.tile.x - item->position.x);
y = abs(player.position.tile.y - item->position.y);
if (x <= 1 && y <= 1 && pcurs == CURSOR_HAND) {
@ -1677,7 +1663,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
}
break;
case ACTION_TALK:
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
TalkToTowner(player, player.destParam1);
}
break;
@ -1694,14 +1680,14 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if (player._pmode == PM_ATTACK && player.AnimInfo.currentFrame >= player._pAFNum) {
if (player.destAction == ACTION_ATTACK) {
d = GetDirection(player.position.future, { player.destParam1, player.destParam2 });
StartAttack(pnum, d);
StartAttack(player, d);
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_ATTACKMON) {
x = abs(player.position.tile.x - monster->position.future.x);
y = abs(player.position.tile.y - monster->position.future.y);
if (x <= 1 && y <= 1) {
d = GetDirection(player.position.future, monster->position.future);
StartAttack(pnum, d);
StartAttack(player, d);
}
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_ATTACKPLR) {
@ -1709,14 +1695,14 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
y = abs(player.position.tile.y - target->position.future.y);
if (x <= 1 && y <= 1) {
d = GetDirection(player.position.future, target->position.future);
StartAttack(pnum, d);
StartAttack(player, d);
}
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_OPERATE) {
if (IsPlayerAdjacentToObject(player, *object)) {
if (object->_oBreak == 1) {
d = GetDirection(player.position.tile, object->position);
StartAttack(pnum, d);
StartAttack(player, d);
}
}
}
@ -1725,15 +1711,15 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if (player._pmode == PM_RATTACK && player.AnimInfo.currentFrame >= player._pAFNum) {
if (player.destAction == ACTION_RATTACK) {
d = GetDirection(player.position.tile, { player.destParam1, player.destParam2 });
StartRangeAttack(pnum, d, player.destParam1, player.destParam2);
StartRangeAttack(player, d, player.destParam1, player.destParam2);
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_RATTACKMON) {
d = GetDirection(player.position.tile, monster->position.future);
StartRangeAttack(pnum, d, monster->position.future.x, monster->position.future.y);
StartRangeAttack(player, d, monster->position.future.x, monster->position.future.y);
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_RATTACKPLR) {
d = GetDirection(player.position.tile, target->position.future);
StartRangeAttack(pnum, d, target->position.future.x, target->position.future.y);
StartRangeAttack(player, d, target->position.future.x, target->position.future.y);
player.destAction = ACTION_NONE;
}
}
@ -1741,15 +1727,15 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
if (player._pmode == PM_SPELL && player.AnimInfo.currentFrame >= player._pSFNum) {
if (player.destAction == ACTION_SPELL) {
d = GetDirection(player.position.tile, { player.destParam1, player.destParam2 });
StartSpell(pnum, d, player.destParam1, player.destParam2);
StartSpell(player, d, player.destParam1, player.destParam2);
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_SPELLMON) {
d = GetDirection(player.position.tile, monster->position.future);
StartSpell(pnum, d, monster->position.future.x, monster->position.future.y);
StartSpell(player, d, monster->position.future.x, monster->position.future.y);
player.destAction = ACTION_NONE;
} else if (player.destAction == ACTION_SPELLPLR) {
d = GetDirection(player.position.tile, target->position.future);
StartSpell(pnum, d, target->position.future.x, target->position.future.y);
StartSpell(player, d, target->position.future.x, target->position.future.y);
player.destAction = ACTION_NONE;
}
}
@ -2098,20 +2084,20 @@ void Player::UpdatePreviewCelSprite(_cmd_id cmdId, Point point, uint16_t wParam1
break;
}
case _cmd_id::CMD_RATTACKPID: {
auto &targetPlayer = Players[wParam1];
Player &targetPlayer = Players[wParam1];
dir = GetDirection(position.future, targetPlayer.position.future);
graphic = player_graphic::Attack;
break;
}
case _cmd_id::CMD_SPELLPID:
case _cmd_id::CMD_TSPELLPID: {
auto &targetPlayer = Players[wParam1];
Player &targetPlayer = Players[wParam1];
dir = GetDirection(position.future, targetPlayer.position.future);
graphic = GetPlayerGraphicForSpell(static_cast<spell_id>(wParam2));
break;
}
case _cmd_id::CMD_ATTACKPID: {
auto &targetPlayer = Players[wParam1];
Player &targetPlayer = Players[wParam1];
point = targetPlayer.position.future;
minimalWalkDistance = 2;
dir = GetDirection(position.future, targetPlayer.position.future);
@ -2904,8 +2890,8 @@ void StartStand(int pnum, Direction dir)
}
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -2917,15 +2903,10 @@ void StartStand(int pnum, Direction dir)
SetPlayerOld(player);
}
void StartPlrBlock(int pnum, Direction dir)
void StartPlrBlock(Player &player, Direction dir)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal(StrCat("StartPlrBlock: illegal player ", pnum));
}
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -2959,8 +2940,8 @@ void StartPlrHit(int pnum, int dam, bool forcehit)
}
Player &player = Players[pnum];
if (player._pInvincible && player._pHitPoints == 0 && pnum == MyPlayerId) {
SyncPlrKill(pnum, -1);
if (player._pInvincible && player._pHitPoints == 0 && &player == MyPlayer) {
SyncPlrKill(player, -1);
return;
}
@ -3004,18 +2985,13 @@ void StartPlrHit(int pnum, int dam, bool forcehit)
__attribute__((no_sanitize("shift-base")))
#endif
void
StartPlayerKill(int pnum, int earflag)
StartPlayerKill(Player &player, int earflag)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal(StrCat("StartPlayerKill: illegal player ", pnum));
}
Player &player = Players[pnum];
if (player._pHitPoints <= 0 && player._pmode == PM_DEATH) {
return;
}
if (MyPlayerId == pnum) {
if (&player == MyPlayer) {
NetSendCmdParam1(true, CMD_PLRDEAD, earflag);
}
@ -3039,7 +3015,7 @@ StartPlayerKill(int pnum, int earflag)
player._pInvincible = true;
SetPlayerHitPoints(player, 0);
if (pnum != MyPlayerId && earflag == 0 && !diablolevel) {
if (&player != MyPlayer && earflag == 0 && !diablolevel) {
for (auto &item : player.InvBody) {
item.clear();
}
@ -3052,7 +3028,7 @@ StartPlayerKill(int pnum, int earflag)
dFlags[player.position.tile.x][player.position.tile.y] |= DungeonFlag::DeadPlayer;
SetPlayerOld(player);
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
drawhpflag = true;
if (!player.HoldItem.isEmpty()) {
@ -3124,17 +3100,15 @@ void StripTopGold(Player &player)
player._pGold = CalculateGold(player);
}
void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int earflag /*= 0*/)
void ApplyPlrDamage(Player &player, int dam, int minHP /*= 0*/, int frac /*= 0*/, int earflag /*= 0*/)
{
Player &player = Players[pnum];
int totalDamage = (dam << 6) + frac;
if (totalDamage > 0 && player.pManaShield) {
int8_t manaShieldLevel = player._pSplLvl[SPL_MANASHIELD];
if (manaShieldLevel > 0) {
totalDamage += totalDamage / -player.GetManaShieldDamageReduction();
}
if (pnum == MyPlayerId)
if (&player == MyPlayer)
drawmanaflag = true;
if (player._pMana >= totalDamage) {
player._pMana -= totalDamage;
@ -3147,7 +3121,7 @@ void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int
}
player._pMana = 0;
player._pManaBase = player._pMaxManaBase - player._pMaxMana;
if (pnum == MyPlayerId)
if (&player == MyPlayer)
NetSendCmd(true, CMD_REMSHIELD);
}
}
@ -3167,21 +3141,19 @@ void ApplyPlrDamage(int pnum, int dam, int minHP /*= 0*/, int frac /*= 0*/, int
SetPlayerHitPoints(player, minHitPoints);
}
if (player._pHitPoints >> 6 <= 0) {
SyncPlrKill(pnum, earflag);
SyncPlrKill(player, earflag);
}
}
void SyncPlrKill(int pnum, int earflag)
void SyncPlrKill(Player &player, int earflag)
{
Player &player = Players[pnum];
if (player._pHitPoints <= 0 && leveltype == DTYPE_TOWN) {
SetPlayerHitPoints(player, 64);
return;
}
SetPlayerHitPoints(player, 0);
StartPlayerKill(pnum, earflag);
StartPlayerKill(player, earflag);
}
void RemovePlrMissiles(const Player &player)
@ -3241,7 +3213,7 @@ StartNewLvl(int pnum, interface_mode fom, int lvl)
app_fatal("StartNewLvl");
}
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
player._pmode = PM_NEWLVL;
player._pInvincible = true;
PostMessage(fom, 0, 0);
@ -3269,7 +3241,7 @@ void RestartTownLvl(int pnum)
CalcPlrInv(player, false);
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
player._pmode = PM_NEWLVL;
player._pInvincible = true;
PostMessage(WM_DIABRETOWN, 0, 0);
@ -3293,7 +3265,7 @@ void StartWarpLvl(int pnum, int pidx)
}
}
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
SetCurrentPortal(pidx);
player._pmode = PM_NEWLVL;
player._pInvincible = true;
@ -3338,16 +3310,16 @@ void ProcessPlayers()
for (int pnum = 0; pnum < MAX_PLRS; pnum++) {
Player &player = Players[pnum];
if (player.plractive && player.isOnActiveLevel() && (pnum == MyPlayerId || !player._pLvlChanging)) {
if (player.plractive && player.isOnActiveLevel() && (&player == MyPlayer || !player._pLvlChanging)) {
CheckCheatStats(player);
if (!PlrDeathModeOK(player) && (player._pHitPoints >> 6) <= 0) {
SyncPlrKill(pnum, -1);
SyncPlrKill(player, -1);
}
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
if (HasAnyOf(player._pIFlags, ItemSpecialEffect::DrainLife) && leveltype != DTYPE_TOWN) {
ApplyPlrDamage(pnum, 0, 0, 4);
ApplyPlrDamage(player, 0, 0, 4);
}
if (HasAnyOf(player._pIFlags, ItemSpecialEffect::NoMana) && player._pManaBase > 0) {
player._pManaBase -= player._pMana;
@ -3511,7 +3483,7 @@ void CheckPlrSpell(bool isShiftHeld, spell_id spellID, spell_type spellType)
switch (spellType) {
case RSPLTYPE_SKILL:
case RSPLTYPE_SPELL:
spellcheck = CheckSpell(MyPlayerId, spellID, spellType, false);
spellcheck = CheckSpell(*MyPlayer, spellID, spellType, false);
addflag = spellcheck == SpellCheckResult::Success;
break;
case RSPLTYPE_SCROLL:
@ -3640,7 +3612,7 @@ void SyncInitPlrPos(int pnum)
player.position.tile = position;
dPlayer[position.x][position.y] = pnum + 1;
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
player.position.future = position;
ViewPosition = position;
}
@ -3655,7 +3627,7 @@ void SyncInitPlr(int pnum)
SetPlrAnims(player);
SyncInitPlrPos(pnum);
if (pnum != MyPlayerId)
if (&player != MyPlayer)
player._plid = NO_LIGHT;
}

8
Source/player.h

@ -764,7 +764,7 @@ void NextPlrLevel(Player &player);
#endif
void AddPlrExperience(Player &player, int lvl, int exp);
void AddPlrMonstExper(int lvl, int exp, char pmask);
void ApplyPlrDamage(int pnum, int dam, int minHP = 0, int frac = 0, int earflag = 0);
void ApplyPlrDamage(Player &player, int dam, int minHP = 0, int frac = 0, int earflag = 0);
void InitPlayer(Player &player, bool FirstTime);
void InitMultiView();
void PlrClrTrans(Point position);
@ -772,15 +772,15 @@ void PlrDoTrans(Point position);
void SetPlayerOld(Player &player);
void FixPlayerLocation(Player &player, Direction bDir);
void StartStand(int pnum, Direction dir);
void StartPlrBlock(int pnum, Direction dir);
void StartPlrBlock(Player &player, Direction dir);
void FixPlrWalkTags(const Player &player);
void StartPlrHit(int pnum, int dam, bool forcehit);
void StartPlayerKill(int pnum, int earflag);
void StartPlayerKill(Player &player, int earflag);
/**
* @brief Strip the top off gold piles that are larger than MaxGold
*/
void StripTopGold(Player &player);
void SyncPlrKill(int pnum, int earflag);
void SyncPlrKill(Player &player, int earflag);
void RemovePlrMissiles(const Player &player);
void StartNewLvl(int pnum, interface_mode fom, int lvl);
void RestartTownLvl(int pnum);

5
Source/qol/autopickup.cpp

@ -75,13 +75,14 @@ bool DoPickup(Item item)
void AutoPickup(int pnum)
{
if (pnum != MyPlayerId)
const Player &player = Players[pnum];
if (&player != MyPlayer)
return;
if (leveltype == DTYPE_TOWN && !*sgOptions.Gameplay.autoPickupInTown)
return;
for (auto pathDir : PathDirs) {
Point tile = Players[pnum].position.tile + pathDir;
Point tile = player.position.tile + pathDir;
if (dItem[tile.x][tile.y] != 0) {
int itemIndex = dItem[tile.x][tile.y] - 1;
auto &item = Items[itemIndex];

7
Source/spells.cpp

@ -100,7 +100,7 @@ void PlacePlayer(int pnum)
dPlayer[newPosition.x][newPosition.y] = pnum + 1;
if (pnum == MyPlayerId) {
if (&player == MyPlayer) {
ViewPosition = newPosition;
}
}
@ -208,7 +208,7 @@ void EnsureValidReadiedSpell(Player &player)
}
}
SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly)
SpellCheckResult CheckSpell(const Player &player, spell_id sn, spell_type st, bool manaonly)
{
#ifdef _DEBUG
if (DebugGodMode)
@ -223,7 +223,6 @@ SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly)
return SpellCheckResult::Success;
}
const Player &player = Players[id];
if (player.GetSpellLevel(sn) <= 0) {
return SpellCheckResult::Fail_Level0;
}
@ -271,7 +270,7 @@ void DoResurrect(int pnum, uint16_t rid)
if (target._pHitPoints != 0)
return;
if (rid == MyPlayerId) {
if (&target == MyPlayer) {
MyPlayerIsDead = false;
gamemenu_off();
drawhpflag = true;

2
Source/spells.h

@ -21,7 +21,7 @@ bool IsWallSpell(spell_id spl);
bool TargetsMonster(spell_id id);
int GetManaAmount(const Player &player, spell_id sn);
void UseMana(Player &player, spell_id sn);
SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly);
SpellCheckResult CheckSpell(const Player &player, spell_id sn, spell_type st, bool manaonly);
/**
* @brief Ensures the player's current readied spell is a valid selection for the character. If the current selection is

4
Source/stores.cpp

@ -1465,7 +1465,7 @@ void SmithBuyPItem(Item &item)
premiumitems[xx].clear();
numpremium--;
SpawnPremium(MyPlayerId);
SpawnPremium(*MyPlayer);
}
void SmithPremiumBuyEnter()
@ -2244,7 +2244,7 @@ void SetupTownStores()
SpawnWitch(l);
SpawnHealer(l);
SpawnBoy(myPlayer._pLevel);
SpawnPremium(MyPlayerId);
SpawnPremium(myPlayer);
}
void FreeStoreMem()

Loading…
Cancel
Save