From 7effa1a931e7e33d2afface5438e55ed76e3dc15 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 20 Jul 2021 22:59:25 +0200 Subject: [PATCH] Merge pull request #2433 from diasurgical/player --- Source/monster.cpp | 2 +- Source/spells.cpp | 64 ++++++++++++++++++++++-------------------- Source/sync.cpp | 70 ++++++++++++++++++++++------------------------ 3 files changed, 67 insertions(+), 69 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 223155b2d..977104b21 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -5083,7 +5083,7 @@ void TalktoMonster(MonsterStruct &monster) void SpawnGolum(int i, Point position, int mi) { - assert(i >= 0 && i < MAXMONSTERS); + assert(i >= 0 && i < MAX_PLRS); auto &player = Players[i]; auto &golem = Monsters[i]; diff --git a/Source/spells.cpp b/Source/spells.cpp index 4906024af..65067f3c3 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -253,46 +253,48 @@ void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl) */ void DoResurrect(int pnum, int rid) { - int hp; - - if ((char)rid != -1) { - AddMissile(Players[rid].position.tile, Players[rid].position.tile, 0, MIS_RESURRECTBEAM, TARGET_MONSTERS, pnum, 0, 0); - } - if (pnum == MyPlayerId) { NewCursor(CURSOR_HAND); } - if ((char)rid != -1 && Players[rid]._pHitPoints == 0) { - if (rid == MyPlayerId) { - MyPlayerIsDead = false; - gamemenu_off(); - drawhpflag = true; - drawmanaflag = true; - } + if (rid == -1) + return; - ClrPlrPath(Players[rid]); - Players[rid].destAction = ACTION_NONE; - Players[rid]._pInvincible = false; - PlacePlayer(rid); + auto &target = Players[rid]; - hp = 10 << 6; - if (Players[rid]._pMaxHPBase < (10 << 6)) { - hp = Players[rid]._pMaxHPBase; - } - SetPlayerHitPoints(rid, hp); + AddMissile(target.position.tile, target.position.tile, 0, MIS_RESURRECTBEAM, TARGET_MONSTERS, pnum, 0, 0); - Players[rid]._pHPBase = Players[rid]._pHitPoints + (Players[rid]._pMaxHPBase - Players[rid]._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed - Players[rid]._pMana = 0; - Players[rid]._pManaBase = Players[rid]._pMana + (Players[rid]._pMaxManaBase - Players[rid]._pMaxMana); + if (target._pHitPoints != 0) + return; - CalcPlrInv(rid, true); + if (rid == MyPlayerId) { + MyPlayerIsDead = false; + gamemenu_off(); + drawhpflag = true; + drawmanaflag = true; + } - if (Players[rid].plrlevel == currlevel) { - StartStand(rid, Players[rid]._pdir); - } else { - Players[rid]._pmode = PM_STAND; - } + ClrPlrPath(target); + target.destAction = ACTION_NONE; + target._pInvincible = false; + PlacePlayer(rid); + + int hp = 10 << 6; + if (target._pMaxHPBase < (10 << 6)) { + hp = target._pMaxHPBase; + } + SetPlayerHitPoints(rid, hp); + + target._pHPBase = target._pHitPoints + (target._pMaxHPBase - target._pMaxHP); // CODEFIX: does the same stuff as SetPlayerHitPoints above, can be removed + target._pMana = 0; + target._pManaBase = target._pMana + (target._pMaxManaBase - target._pMaxMana); + + CalcPlrInv(rid, true); + + if (target.plrlevel == currlevel) { + StartStand(rid, target._pdir); + } else { + target._pmode = PM_STAND; } } diff --git a/Source/sync.cpp b/Source/sync.cpp index bbac98740..493f7ec5e 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -94,54 +94,50 @@ bool SyncMonsterActive2(TSyncMonster *p) void SyncPlrInv(TSyncHeader *pHdr) { - int ii; - ItemStruct *pItem; - + pHdr->bItemI = -1; if (ActiveItemCount > 0) { if (sgnSyncItem >= ActiveItemCount) { sgnSyncItem = 0; } - ii = ActiveItems[sgnSyncItem++]; - pHdr->bItemI = ii; - pHdr->bItemX = Items[ii].position.x; - pHdr->bItemY = Items[ii].position.y; - pHdr->wItemIndx = Items[ii].IDidx; - if (Items[ii].IDidx == IDI_EAR) { - pHdr->wItemCI = (Items[ii]._iName[7] << 8) | Items[ii]._iName[8]; - pHdr->dwItemSeed = (Items[ii]._iName[9] << 24) | (Items[ii]._iName[10] << 16) | (Items[ii]._iName[11] << 8) | Items[ii]._iName[12]; - pHdr->bItemId = Items[ii]._iName[13]; - pHdr->bItemDur = Items[ii]._iName[14]; - pHdr->bItemMDur = Items[ii]._iName[15]; - pHdr->bItemCh = Items[ii]._iName[16]; - pHdr->bItemMCh = Items[ii]._iName[17]; - pHdr->wItemVal = (Items[ii]._iName[18] << 8) | ((Items[ii]._iCurs - ICURS_EAR_SORCERER) << 6) | Items[ii]._ivalue; - pHdr->dwItemBuff = (Items[ii]._iName[19] << 24) | (Items[ii]._iName[20] << 16) | (Items[ii]._iName[21] << 8) | Items[ii]._iName[22]; + pHdr->bItemI = ActiveItems[sgnSyncItem]; + sgnSyncItem++; + auto &item = Items[pHdr->bItemI]; + pHdr->bItemX = item.position.x; + pHdr->bItemY = item.position.y; + pHdr->wItemIndx = item.IDidx; + if (item.IDidx == IDI_EAR) { + pHdr->wItemCI = (item._iName[7] << 8) | item._iName[8]; + pHdr->dwItemSeed = (item._iName[9] << 24) | (item._iName[10] << 16) | (item._iName[11] << 8) | item._iName[12]; + pHdr->bItemId = item._iName[13]; + pHdr->bItemDur = item._iName[14]; + pHdr->bItemMDur = item._iName[15]; + pHdr->bItemCh = item._iName[16]; + pHdr->bItemMCh = item._iName[17]; + pHdr->wItemVal = (item._iName[18] << 8) | ((item._iCurs - ICURS_EAR_SORCERER) << 6) | item._ivalue; + pHdr->dwItemBuff = (item._iName[19] << 24) | (item._iName[20] << 16) | (item._iName[21] << 8) | item._iName[22]; } else { - pHdr->wItemCI = Items[ii]._iCreateInfo; - pHdr->dwItemSeed = Items[ii]._iSeed; - pHdr->bItemId = Items[ii]._iIdentified ? 1 : 0; - pHdr->bItemDur = Items[ii]._iDurability; - pHdr->bItemMDur = Items[ii]._iMaxDur; - pHdr->bItemCh = Items[ii]._iCharges; - pHdr->bItemMCh = Items[ii]._iMaxCharges; - if (Items[ii].IDidx == IDI_GOLD) { - pHdr->wItemVal = Items[ii]._ivalue; + pHdr->wItemCI = item._iCreateInfo; + pHdr->dwItemSeed = item._iSeed; + pHdr->bItemId = item._iIdentified ? 1 : 0; + pHdr->bItemDur = item._iDurability; + pHdr->bItemMDur = item._iMaxDur; + pHdr->bItemCh = item._iCharges; + pHdr->bItemMCh = item._iMaxCharges; + if (item.IDidx == IDI_GOLD) { + pHdr->wItemVal = item._ivalue; } } - } else { - pHdr->bItemI = -1; } + pHdr->bPInvLoc = -1; assert(sgnSyncPInv > -1 && sgnSyncPInv < NUM_INVLOC); - pItem = &Players[MyPlayerId].InvBody[sgnSyncPInv]; - if (!pItem->isEmpty()) { + const auto &item = Players[MyPlayerId].InvBody[sgnSyncPInv]; + if (!item.isEmpty()) { pHdr->bPInvLoc = sgnSyncPInv; - pHdr->wPInvIndx = pItem->IDidx; - pHdr->wPInvCI = pItem->_iCreateInfo; - pHdr->dwPInvSeed = pItem->_iSeed; - pHdr->bPInvId = pItem->_iIdentified ? 1 : 0; - } else { - pHdr->bPInvLoc = -1; + pHdr->wPInvIndx = item.IDidx; + pHdr->wPInvCI = item._iCreateInfo; + pHdr->dwPInvSeed = item._iSeed; + pHdr->bPInvId = item._iIdentified ? 1 : 0; } sgnSyncPInv++;