diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 546dd3d23..37d4c1c70 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -248,7 +248,7 @@ bool CanTargetMonster(const Monster &monster) return false; if (monster.isPlayerMinion()) return false; - if (monster.hitPoints >> 6 <= 0) // dead + if (monster.hasNoLife()) // dead return false; if (!IsTileLit(monster.position.tile)) // not visible diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 428e982a0..fa4cef28a 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -69,7 +69,7 @@ OptionalOwnedClxSpriteList *HalfSizeItemSpritesRed; bool IsValidMonsterForSelection(const Monster &monster) { - if (monster.hitPoints >> 6 <= 0) + if (monster.hasNoLife()) return false; if ((monster.flags & MFLAG_HIDDEN) != 0) return false; diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 2891a7a77..f4733157f 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -330,7 +330,7 @@ bool MonsterMHit(const Player &player, Monster &monster, int mindam, int maxdam, if (&player == MyPlayer) ApplyMonsterDamage(damageType, monster, dam); - if (monster.hitPoints >> 6 <= 0) { + if (monster.hasNoLife()) { M_StartKill(monster, player); } else if (resist) { monster.tag(player); @@ -723,7 +723,7 @@ bool GuardianTryFireAt(Missile &missile, Point target) const Monster &monster = Monsters[mid]; if (monster.isPlayerMinion()) return false; - if (monster.hitPoints >> 6 <= 0) + if (monster.hasNoLife()) return false; const Player &player = Players[missile._misource]; @@ -1053,7 +1053,7 @@ bool MonsterTrapHit(Monster &monster, int mindam, int maxdam, int dist, MissileI if (DebugGodMode) monster.hitPoints = 0; #endif - if (monster.hitPoints >> 6 <= 0) { + if (monster.hasNoLife()) { MonsterDeath(monster, monster.direction, true); } else if (resist) { PlayEffect(monster, MonsterSound::Hit); diff --git a/Source/monster.cpp b/Source/monster.cpp index f1ea88430..5d586cfe6 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -702,7 +702,7 @@ void UpdateEnemy(Monster &monster) Monster &otherMonster = Monsters[monsterId]; if (&otherMonster == &monster) continue; - if ((otherMonster.hitPoints >> 6) <= 0) + if (otherMonster.hasNoLife()) continue; if (otherMonster.position.tile == GolemHoldingCell) continue; @@ -1123,7 +1123,7 @@ void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind target.tag(player); } - if (target.hitPoints >> 6 <= 0) { + if (target.hasNoLife()) { StartDeathFromMonster(attacker, target); } else { MonsterHitMonster(attacker, target, dam); @@ -1143,7 +1143,7 @@ int CheckReflect(Monster &monster, Player &player, int dam) // reflects 20-30% damage const int mdam = dam * RandomIntBetween(20, 30, true) / 100; ApplyMonsterDamage(DamageType::Physical, monster, mdam); - if (monster.hitPoints >> 6 <= 0) + if (monster.hasNoLife()) M_StartKill(monster, player); else M_StartHit(monster, player, mdam); @@ -1230,7 +1230,7 @@ void MonsterAttackPlayer(Monster &monster, Player &player, int hit, int minDam, if (HasAnyOf(player._pIFlags, ItemSpecialEffect::Thorns) && monster.mode != MonsterMode::Death) { const int mdam = (GenerateRnd(3) + 1) << 6; ApplyMonsterDamage(DamageType::Physical, monster, mdam); - if (monster.hitPoints >> 6 <= 0) + if (monster.hasNoLife()) M_StartKill(monster, player); else M_StartHit(monster, player, mdam); @@ -3782,7 +3782,7 @@ void ApplyMonsterDamage(DamageType damageType, Monster &monster, int damage) monster.hitPoints -= damage; - if (monster.hitPoints >> 6 <= 0) { + if (monster.hasNoLife()) { delta_kill_monster(monster, monster.position.tile, *MyPlayer); NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, static_cast(monster.getId())); return; @@ -4139,7 +4139,7 @@ void ProcessMonsters() SetRndSeed(monster.aiSeed); monster.aiSeed = AdvanceRndSeed(); } - if (monster.hitPoints < monster.maxHitPoints && monster.hitPoints >> 6 > 0) { + if (monster.hitPoints < monster.maxHitPoints && !monster.hasNoLife()) { if (monster.level(sgGameInitInfo.nDifficulty) > 1) { monster.hitPoints += monster.level(sgGameInitInfo.nDifficulty) / 2; } else { @@ -4404,7 +4404,7 @@ void M_FallenFear(Point position) if (m == 0) continue; Monster &monster = Monsters[std::abs(m) - 1]; - if (monster.ai != MonsterAIID::Fallen || monster.hitPoints >> 6 <= 0) + if (monster.ai != MonsterAIID::Fallen || monster.hasNoLife()) continue; const int runDistance = std::max((8 - monster.data().level), 2); @@ -4908,7 +4908,7 @@ bool Monster::isPlayerMinion() const bool Monster::isPossibleToHit() const { - return hitPoints >> 6 > 0 + return !hasNoLife() && talkMsg == TEXT_NONE && (type().type != MT_ILLWEAV || goal != MonsterGoal::Retreat) && !(IsAnyOf(mode, MonsterMode::Charge, MonsterMode::Death)) diff --git a/Source/monster.h b/Source/monster.h index 1e1fb7427..6b3ef4303 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -476,6 +476,11 @@ struct Monster { // note: missing field _mAFNum * @param isMoving specifies whether the monster is moving or not (true/moving results in a negative index in dMonster) */ void occupyTile(Point tile, bool isMoving) const; + + bool hasNoLife() const + { + return hitPoints >> 6 <= 0; + } }; extern size_t LevelMonsterTypeCount; diff --git a/Source/player.cpp b/Source/player.cpp index a234a1f4d..69dc2039f 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -690,7 +690,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false) } RedrawComponent(PanelDrawComponent::Health); } - if ((monster.hitPoints >> 6) <= 0) { + if (monster.hasNoLife()) { M_StartKill(monster, player); } else { if (monster.mode != MonsterMode::Petrified && HasAnyOf(player._pIFlags, ItemSpecialEffect::Knockback)) @@ -1106,7 +1106,7 @@ void CheckNewPath(Player &player, bool pmWillBeCalled) case ACTION_RATTACKMON: case ACTION_SPELLMON: monster = &Monsters[targetId]; - if ((monster->hitPoints >> 6) <= 0) { + if (monster->hasNoLife()) { player.Stop(); return; } @@ -3110,7 +3110,7 @@ bool PosOkPlayer(const Player &player, Point position) if (dMonster[position.x][position.y] <= 0) { return false; } - if ((Monsters[dMonster[position.x][position.y] - 1].hitPoints >> 6) > 0) { + if (!Monsters[dMonster[position.x][position.y] - 1].hasNoLife()) { return false; } } diff --git a/Source/track.cpp b/Source/track.cpp index d2f9bfe17..222d71f36 100644 --- a/Source/track.cpp +++ b/Source/track.cpp @@ -38,7 +38,7 @@ void InvalidateTargets() { if (pcursmonst != -1) { const Monster &monster = Monsters[pcursmonst]; - if (monster.isInvalid || monster.hitPoints >> 6 <= 0 + if (monster.isInvalid || monster.hasNoLife() || (monster.flags & MFLAG_HIDDEN) != 0 || !IsTileLit(monster.position.tile)) { pcursmonst = -1;