Browse Source

Add Monster hasNoLife helper (#8304)

pull/8318/head
Eric Robinson 3 months ago committed by GitHub
parent
commit
e5e6804e49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      Source/controls/plrctrls.cpp
  2. 2
      Source/cursor.cpp
  3. 6
      Source/missiles.cpp
  4. 16
      Source/monster.cpp
  5. 5
      Source/monster.h
  6. 6
      Source/player.cpp
  7. 2
      Source/track.cpp

2
Source/controls/plrctrls.cpp

@ -248,7 +248,7 @@ bool CanTargetMonster(const Monster &monster)
return false; return false;
if (monster.isPlayerMinion()) if (monster.isPlayerMinion())
return false; return false;
if (monster.hitPoints >> 6 <= 0) // dead if (monster.hasNoLife()) // dead
return false; return false;
if (!IsTileLit(monster.position.tile)) // not visible if (!IsTileLit(monster.position.tile)) // not visible

2
Source/cursor.cpp

@ -69,7 +69,7 @@ OptionalOwnedClxSpriteList *HalfSizeItemSpritesRed;
bool IsValidMonsterForSelection(const Monster &monster) bool IsValidMonsterForSelection(const Monster &monster)
{ {
if (monster.hitPoints >> 6 <= 0) if (monster.hasNoLife())
return false; return false;
if ((monster.flags & MFLAG_HIDDEN) != 0) if ((monster.flags & MFLAG_HIDDEN) != 0)
return false; return false;

6
Source/missiles.cpp

@ -330,7 +330,7 @@ bool MonsterMHit(const Player &player, Monster &monster, int mindam, int maxdam,
if (&player == MyPlayer) if (&player == MyPlayer)
ApplyMonsterDamage(damageType, monster, dam); ApplyMonsterDamage(damageType, monster, dam);
if (monster.hitPoints >> 6 <= 0) { if (monster.hasNoLife()) {
M_StartKill(monster, player); M_StartKill(monster, player);
} else if (resist) { } else if (resist) {
monster.tag(player); monster.tag(player);
@ -723,7 +723,7 @@ bool GuardianTryFireAt(Missile &missile, Point target)
const Monster &monster = Monsters[mid]; const Monster &monster = Monsters[mid];
if (monster.isPlayerMinion()) if (monster.isPlayerMinion())
return false; return false;
if (monster.hitPoints >> 6 <= 0) if (monster.hasNoLife())
return false; return false;
const Player &player = Players[missile._misource]; const Player &player = Players[missile._misource];
@ -1053,7 +1053,7 @@ bool MonsterTrapHit(Monster &monster, int mindam, int maxdam, int dist, MissileI
if (DebugGodMode) if (DebugGodMode)
monster.hitPoints = 0; monster.hitPoints = 0;
#endif #endif
if (monster.hitPoints >> 6 <= 0) { if (monster.hasNoLife()) {
MonsterDeath(monster, monster.direction, true); MonsterDeath(monster, monster.direction, true);
} else if (resist) { } else if (resist) {
PlayEffect(monster, MonsterSound::Hit); PlayEffect(monster, MonsterSound::Hit);

16
Source/monster.cpp

@ -702,7 +702,7 @@ void UpdateEnemy(Monster &monster)
Monster &otherMonster = Monsters[monsterId]; Monster &otherMonster = Monsters[monsterId];
if (&otherMonster == &monster) if (&otherMonster == &monster)
continue; continue;
if ((otherMonster.hitPoints >> 6) <= 0) if (otherMonster.hasNoLife())
continue; continue;
if (otherMonster.position.tile == GolemHoldingCell) if (otherMonster.position.tile == GolemHoldingCell)
continue; continue;
@ -1123,7 +1123,7 @@ void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind
target.tag(player); target.tag(player);
} }
if (target.hitPoints >> 6 <= 0) { if (target.hasNoLife()) {
StartDeathFromMonster(attacker, target); StartDeathFromMonster(attacker, target);
} else { } else {
MonsterHitMonster(attacker, target, dam); MonsterHitMonster(attacker, target, dam);
@ -1143,7 +1143,7 @@ int CheckReflect(Monster &monster, Player &player, int dam)
// reflects 20-30% damage // reflects 20-30% damage
const int mdam = dam * RandomIntBetween(20, 30, true) / 100; const int mdam = dam * RandomIntBetween(20, 30, true) / 100;
ApplyMonsterDamage(DamageType::Physical, monster, mdam); ApplyMonsterDamage(DamageType::Physical, monster, mdam);
if (monster.hitPoints >> 6 <= 0) if (monster.hasNoLife())
M_StartKill(monster, player); M_StartKill(monster, player);
else else
M_StartHit(monster, player, mdam); 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) { if (HasAnyOf(player._pIFlags, ItemSpecialEffect::Thorns) && monster.mode != MonsterMode::Death) {
const int mdam = (GenerateRnd(3) + 1) << 6; const int mdam = (GenerateRnd(3) + 1) << 6;
ApplyMonsterDamage(DamageType::Physical, monster, mdam); ApplyMonsterDamage(DamageType::Physical, monster, mdam);
if (monster.hitPoints >> 6 <= 0) if (monster.hasNoLife())
M_StartKill(monster, player); M_StartKill(monster, player);
else else
M_StartHit(monster, player, mdam); M_StartHit(monster, player, mdam);
@ -3782,7 +3782,7 @@ void ApplyMonsterDamage(DamageType damageType, Monster &monster, int damage)
monster.hitPoints -= damage; monster.hitPoints -= damage;
if (monster.hitPoints >> 6 <= 0) { if (monster.hasNoLife()) {
delta_kill_monster(monster, monster.position.tile, *MyPlayer); delta_kill_monster(monster, monster.position.tile, *MyPlayer);
NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, static_cast<uint16_t>(monster.getId())); NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, static_cast<uint16_t>(monster.getId()));
return; return;
@ -4139,7 +4139,7 @@ void ProcessMonsters()
SetRndSeed(monster.aiSeed); SetRndSeed(monster.aiSeed);
monster.aiSeed = AdvanceRndSeed(); 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) { if (monster.level(sgGameInitInfo.nDifficulty) > 1) {
monster.hitPoints += monster.level(sgGameInitInfo.nDifficulty) / 2; monster.hitPoints += monster.level(sgGameInitInfo.nDifficulty) / 2;
} else { } else {
@ -4404,7 +4404,7 @@ void M_FallenFear(Point position)
if (m == 0) if (m == 0)
continue; continue;
Monster &monster = Monsters[std::abs(m) - 1]; Monster &monster = Monsters[std::abs(m) - 1];
if (monster.ai != MonsterAIID::Fallen || monster.hitPoints >> 6 <= 0) if (monster.ai != MonsterAIID::Fallen || monster.hasNoLife())
continue; continue;
const int runDistance = std::max((8 - monster.data().level), 2); const int runDistance = std::max((8 - monster.data().level), 2);
@ -4908,7 +4908,7 @@ bool Monster::isPlayerMinion() const
bool Monster::isPossibleToHit() const bool Monster::isPossibleToHit() const
{ {
return hitPoints >> 6 > 0 return !hasNoLife()
&& talkMsg == TEXT_NONE && talkMsg == TEXT_NONE
&& (type().type != MT_ILLWEAV || goal != MonsterGoal::Retreat) && (type().type != MT_ILLWEAV || goal != MonsterGoal::Retreat)
&& !(IsAnyOf(mode, MonsterMode::Charge, MonsterMode::Death)) && !(IsAnyOf(mode, MonsterMode::Charge, MonsterMode::Death))

5
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) * @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; void occupyTile(Point tile, bool isMoving) const;
bool hasNoLife() const
{
return hitPoints >> 6 <= 0;
}
}; };
extern size_t LevelMonsterTypeCount; extern size_t LevelMonsterTypeCount;

6
Source/player.cpp

@ -690,7 +690,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false)
} }
RedrawComponent(PanelDrawComponent::Health); RedrawComponent(PanelDrawComponent::Health);
} }
if ((monster.hitPoints >> 6) <= 0) { if (monster.hasNoLife()) {
M_StartKill(monster, player); M_StartKill(monster, player);
} else { } else {
if (monster.mode != MonsterMode::Petrified && HasAnyOf(player._pIFlags, ItemSpecialEffect::Knockback)) 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_RATTACKMON:
case ACTION_SPELLMON: case ACTION_SPELLMON:
monster = &Monsters[targetId]; monster = &Monsters[targetId];
if ((monster->hitPoints >> 6) <= 0) { if (monster->hasNoLife()) {
player.Stop(); player.Stop();
return; return;
} }
@ -3110,7 +3110,7 @@ bool PosOkPlayer(const Player &player, Point position)
if (dMonster[position.x][position.y] <= 0) { if (dMonster[position.x][position.y] <= 0) {
return false; return false;
} }
if ((Monsters[dMonster[position.x][position.y] - 1].hitPoints >> 6) > 0) { if (!Monsters[dMonster[position.x][position.y] - 1].hasNoLife()) {
return false; return false;
} }
} }

2
Source/track.cpp

@ -38,7 +38,7 @@ void InvalidateTargets()
{ {
if (pcursmonst != -1) { if (pcursmonst != -1) {
const Monster &monster = Monsters[pcursmonst]; const Monster &monster = Monsters[pcursmonst];
if (monster.isInvalid || monster.hitPoints >> 6 <= 0 if (monster.isInvalid || monster.hasNoLife()
|| (monster.flags & MFLAG_HIDDEN) != 0 || (monster.flags & MFLAG_HIDDEN) != 0
|| !IsTileLit(monster.position.tile)) { || !IsTileLit(monster.position.tile)) {
pcursmonst = -1; pcursmonst = -1;

Loading…
Cancel
Save