From 35b2aa4947a370eb74fe26a46b36a97961c1ed50 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 24 Jun 2021 02:04:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8FUnfold=20a=20few=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/multi.cpp | 24 +++++++------- Source/player.cpp | 15 ++++----- Source/spells.cpp | 79 +++++++++++++++++++++-------------------------- Source/spells.h | 2 +- 4 files changed, 57 insertions(+), 63 deletions(-) diff --git a/Source/multi.cpp b/Source/multi.cpp index cf84a8eba..b5fc4f40f 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -832,7 +832,6 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) return; } assert((DWORD)pnum < MAX_PLRS); - auto &player = plr[pnum]; if (sgwPackPlrOffsetTbl[pnum] != p->wOffset) { @@ -872,17 +871,20 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) SyncInitPlr(pnum); - if (player.plrlevel == currlevel) { - if (player._pHitPoints >> 6 > 0) { - StartStand(pnum, DIR_S); - } else { - player._pgfxnum = 0; - player._pmode = PM_DEATH; - NewPlrAnim(player, player_graphic::Death, DIR_S, player._pDFrames, 1); - player.AnimInfo.CurrentFrame = player.AnimInfo.NumberOfFrames - 1; - dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER; - } + if (player.plrlevel != currlevel) { + return; } + + if (player._pHitPoints >> 6 > 0) { + StartStand(pnum, DIR_S); + return; + } + + player._pgfxnum = 0; + player._pmode = PM_DEATH; + NewPlrAnim(player, player_graphic::Death, DIR_S, player._pDFrames, 1); + player.AnimInfo.CurrentFrame = player.AnimInfo.NumberOfFrames - 1; + dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER; } } // namespace devilution diff --git a/Source/player.cpp b/Source/player.cpp index 83f0dd184..1743360c7 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -692,13 +692,14 @@ void InitPlayerGFX(PlayerStruct &player) if (player._pHitPoints >> 6 == 0) { player._pgfxnum = 0; LoadPlrGFX(player, player_graphic::Death); - } else { - for (size_t i = 0; i < enum_size::value; i++) { - auto graphic = static_cast(i); - if (graphic == player_graphic::Death) - continue; - LoadPlrGFX(player, graphic); - } + return; + } + + for (size_t i = 0; i < enum_size::value; i++) { + auto graphic = static_cast(i); + if (graphic == player_graphic::Death) + continue; + LoadPlrGFX(player, graphic); } } diff --git a/Source/spells.cpp b/Source/spells.cpp index 770268b34..3546e4d54 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -154,29 +154,26 @@ void EnsureValidReadiedSpell(PlayerStruct &player) bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly) { - bool result; - #ifdef _DEBUG if (debug_mode_key_inverted_v) return true; #endif - result = true; if (!manaonly && pcurs != CURSOR_HAND) { - result = false; - } else { - if (st != RSPLTYPE_SKILL) { - if (GetSpellLevel(id, sn) <= 0) { - result = false; - } else { - auto &player = plr[id]; + return false; + } - return player._pMana >= GetManaAmount(player, sn); - } - } + if (st == RSPLTYPE_SKILL) { + return true; } - return result; + if (GetSpellLevel(id, sn) <= 0) { + return false; + } + + auto &player = plr[id]; + + return player._pMana >= GetManaAmount(player, sn); } void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl) @@ -294,48 +291,42 @@ void DoResurrect(int pnum, int rid) } } -void DoHealOther(int pnum, int rid) +void DoHealOther(int pnum, uint16_t rid) { - int i, j, hp; - if (pnum == myplr) { NewCursor(CURSOR_HAND); } + if ((DWORD)pnum >= MAX_PLRS || rid >= MAX_PLRS) { + return; + } auto &player = plr[pnum]; auto &target = plr[rid]; - if ((char)rid != -1 && (target._pHitPoints >> 6) > 0) { - hp = (GenerateRnd(10) + 1) << 6; - - for (i = 0; i < player._pLevel; i++) { - hp += (GenerateRnd(4) + 1) << 6; - } - - for (j = 0; j < GetSpellLevel(pnum, SPL_HEALOTHER); ++j) { - hp += (GenerateRnd(6) + 1) << 6; - } - - if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) { - hp *= 2; - } else if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Bard) { - hp += hp / 2; - } else if (player._pClass == HeroClass::Monk) { - hp *= 3; - } - - target._pHitPoints += hp; + if ((target._pHitPoints >> 6) <= 0) { + return; + } - if (target._pHitPoints > target._pMaxHP) { - target._pHitPoints = target._pMaxHP; - } + int hp = (GenerateRnd(10) + 1) << 6; + for (int i = 0; i < player._pLevel; i++) { + hp += (GenerateRnd(4) + 1) << 6; + } + for (int i = 0; i < GetSpellLevel(pnum, SPL_HEALOTHER); i++) { + hp += (GenerateRnd(6) + 1) << 6; + } - target._pHPBase += hp; + if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) { + hp *= 2; + } else if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Bard) { + hp += hp / 2; + } else if (player._pClass == HeroClass::Monk) { + hp *= 3; + } - if (target._pHPBase > target._pMaxHPBase) { - target._pHPBase = target._pMaxHPBase; - } + target._pHitPoints = std::min(target._pHitPoints + hp, target._pMaxHP); + target._pHPBase = std::min(target._pHPBase + hp, target._pMaxHPBase); + if (rid == myplr) { drawhpflag = true; } } diff --git a/Source/spells.h b/Source/spells.h index 46730931b..92185f36a 100644 --- a/Source/spells.h +++ b/Source/spells.h @@ -15,7 +15,7 @@ bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly); void EnsureValidReadiedSpell(PlayerStruct &player); void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl); void DoResurrect(int pnum, int rid); -void DoHealOther(int pnum, int rid); +void DoHealOther(int pnum, uint16_t rid); int GetSpellBookLevel(spell_id s); int GetSpellStaffLevel(spell_id s);