Browse Source

HitMonster() cleanup (#5147)

pull/5154/head
Stephen C. Wills 4 years ago committed by GitHub
parent
commit
e364b7488c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Source/missiles.cpp
  2. 76
      Source/monster.cpp
  3. 1
      Source/monster.h
  4. 2
      Source/msg.cpp

1
Source/missiles.cpp

@ -887,6 +887,7 @@ bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, missile_id
} else if (resist) { } else if (resist) {
PlayEffect(monster, 1); PlayEffect(monster, 1);
} else if (monster.type().type != MT_GOLEM) { } else if (monster.type().type != MT_GOLEM) {
PlayEffect(monster, 1);
M_StartHit(monster, dam); M_StartHit(monster, dam);
} }
return true; return true;

76
Source/monster.cpp

@ -1033,47 +1033,17 @@ void Teleport(Monster &monster)
} }
} }
void HitMonster(Monster &monster, int dam)
{
delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), dam);
PlayEffect(monster, 1);
if (IsAnyOf(monster.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= monster.level + 3) {
if (monster.type().type == MT_BLINK) {
Teleport(monster);
} else if (IsAnyOf(monster.type().type, MT_NSCAV, MT_BSCAV, MT_WSCAV, MT_YSCAV, MT_GRAVEDIG)) {
monster.goal = MonsterGoal::Normal;
monster.goalVar1 = 0;
monster.goalVar2 = 0;
}
if (monster.mode != MonsterMode::Petrified) {
StartMonsterGotHit(monster);
}
}
}
void MonsterHitMonster(Monster &attacker, Monster &target, int dam) void MonsterHitMonster(Monster &attacker, Monster &target, int dam)
{ {
if (attacker.isPlayerMinion())
target.whoHit |= 1 << attacker.getId(); // really the id the player who controls this golem
if (IsAnyOf(target.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= target.level + 3) { if (IsAnyOf(target.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= target.level + 3) {
target.direction = Opposite(attacker.direction); target.direction = Opposite(attacker.direction);
} }
HitMonster(target, dam); M_StartHit(target, dam);
} }
void StartDeathFromMonster(Monster &attacker, Monster &target) void StartDeathFromMonster(Monster &attacker, Monster &target)
{ {
delta_kill_monster(target, target.position.tile, *MyPlayer);
NetSendCmdLocParam1(false, CMD_MONSTDEATH, target.position.tile, target.getId());
if (attacker.isPlayerMinion())
target.whoHit |= 1 << attacker.getId(); // really the id the player who controls this golem
Direction md = GetDirection(target.position.tile, attacker.position.tile); Direction md = GetDirection(target.position.tile, attacker.position.tile);
MonsterDeath(target, md, true); MonsterDeath(target, md, true);
@ -1194,6 +1164,21 @@ bool MonsterWalk(Monster &monster, MonsterMode variant)
return isAnimationEnd; return isAnimationEnd;
} }
void ApplyMonsterDamage(Monster &monster, int damage)
{
monster.hitPoints -= damage;
if (monster.hitPoints >> 6 <= 0) {
delta_kill_monster(monster, monster.position.tile, *MyPlayer);
NetSendCmdLocParam1(false, CMD_MONSTDEATH, monster.position.tile, monster.getId());
return;
}
delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), damage);
PlayEffect(monster, 1);
}
void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind, int maxd) void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind, int maxd)
{ {
if (!target.isPossibleToHit()) if (!target.isPossibleToHit())
@ -1208,7 +1193,14 @@ void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind
return; return;
int dam = (mind + GenerateRnd(maxd - mind + 1)) << 6; int dam = (mind + GenerateRnd(maxd - mind + 1)) << 6;
target.hitPoints -= dam; ApplyMonsterDamage(target, dam);
if (attacker.isPlayerMinion()) {
int playerId = attacker.getId();
const Player &player = Players[playerId];
target.tag(player);
}
if (target.hitPoints >> 6 <= 0) { if (target.hitPoints >> 6 <= 0) {
StartDeathFromMonster(attacker, target); StartDeathFromMonster(attacker, target);
} else { } else {
@ -3748,13 +3740,10 @@ void M_GetKnockback(Monster &monster)
void M_StartHit(Monster &monster, int dam) void M_StartHit(Monster &monster, int dam)
{ {
PlayEffect(monster, 1);
if (IsAnyOf(monster.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= monster.level + 3) { if (IsAnyOf(monster.type().type, MT_SNEAK, MT_STALKER, MT_UNSEEN, MT_ILLWEAV) || dam >> 6 >= monster.level + 3) {
if (monster.type().type == MT_BLINK) { if (monster.type().type == MT_BLINK) {
Teleport(monster); Teleport(monster);
} else if (IsAnyOf(monster.type().type, MT_NSCAV, MT_BSCAV, MT_WSCAV, MT_YSCAV) } else if (IsAnyOf(monster.type().type, MT_NSCAV, MT_BSCAV, MT_WSCAV, MT_YSCAV, MT_GRAVEDIG)) {
|| monster.type().type == MT_GRAVEDIG) {
monster.goal = MonsterGoal::Normal; monster.goal = MonsterGoal::Normal;
monster.goalVar1 = 0; monster.goalVar1 = 0;
monster.goalVar2 = 0; monster.goalVar2 = 0;
@ -3767,7 +3756,7 @@ void M_StartHit(Monster &monster, int dam)
void M_StartHit(Monster &monster, const Player &player, int dam) void M_StartHit(Monster &monster, const Player &player, int dam)
{ {
monster.whoHit |= 1 << player.getId(); monster.tag(player);
if (&player == MyPlayer) { if (&player == MyPlayer) {
delta_monster_hp(monster, *MyPlayer); delta_monster_hp(monster, *MyPlayer);
NetSendCmdMonDmg(false, monster.getId(), dam); NetSendCmdMonDmg(false, monster.getId(), dam);
@ -3779,6 +3768,7 @@ void M_StartHit(Monster &monster, const Player &player, int dam)
monster.direction = GetMonsterDirection(monster); monster.direction = GetMonsterDirection(monster);
} }
PlayEffect(monster, 1);
M_StartHit(monster, dam); M_StartHit(monster, dam);
} }
@ -3819,7 +3809,7 @@ void MonsterDeath(Monster &monster, Direction md, bool sendmsg)
void StartMonsterDeath(Monster &monster, const Player &player, bool sendmsg) void StartMonsterDeath(Monster &monster, const Player &player, bool sendmsg)
{ {
monster.whoHit |= 1 << player.getId(); monster.tag(player);
Direction md = GetDirection(monster.position.tile, player.position.tile); Direction md = GetDirection(monster.position.tile, player.position.tile);
MonsterDeath(monster, md, sendmsg); MonsterDeath(monster, md, sendmsg);
} }
@ -4452,9 +4442,10 @@ void MissToMonst(Missile &missile, Point position)
monster.position.tile = position; monster.position.tile = position;
M_StartStand(monster, monster.direction); M_StartStand(monster, monster.direction);
if ((monster.flags & MFLAG_TARGETS_MONSTER) == 0) if ((monster.flags & MFLAG_TARGETS_MONSTER) == 0)
M_StartHit(monster, 0); PlayEffect(monster, 1);
else else
HitMonster(monster, 0); ApplyMonsterDamage(monster, 0);
M_StartHit(monster, 0);
if (monster.type().type == MT_GLOOM) if (monster.type().type == MT_GLOOM)
return; return;
@ -4764,6 +4755,11 @@ bool Monster::isPossibleToHit() const
|| (IsAnyOf(type().type, MT_COUNSLR, MT_MAGISTR, MT_CABALIST, MT_ADVOCATE) && goal != MonsterGoal::Normal)); || (IsAnyOf(type().type, MT_COUNSLR, MT_MAGISTR, MT_CABALIST, MT_ADVOCATE) && goal != MonsterGoal::Normal));
} }
void Monster::tag(const Player &tagger)
{
whoHit |= 1 << tagger.getId();
}
bool Monster::tryLiftGargoyle() bool Monster::tryLiftGargoyle()
{ {
if (ai == AI_GARG && (flags & MFLAG_ALLOW_SPECIAL) != 0) { if (ai == AI_GARG && (flags & MFLAG_ALLOW_SPECIAL) != 0) {

1
Source/monster.h

@ -345,6 +345,7 @@ struct Monster { // note: missing field _mAFNum
[[nodiscard]] bool isPlayerMinion() const; [[nodiscard]] bool isPlayerMinion() const;
bool isPossibleToHit() const; bool isPossibleToHit() const;
void tag(const Player &tagger);
[[nodiscard]] bool isUnique() const [[nodiscard]] bool isUnique() const
{ {

2
Source/msg.cpp

@ -1591,7 +1591,7 @@ size_t OnMonstDamage(const TCmd *pCmd, int pnum)
if (&player != MyPlayer) { if (&player != MyPlayer) {
if (player.isOnActiveLevel() && message.wMon < MaxMonsters) { if (player.isOnActiveLevel() && message.wMon < MaxMonsters) {
auto &monster = Monsters[message.wMon]; auto &monster = Monsters[message.wMon];
monster.whoHit |= 1 << pnum; monster.tag(player);
if (monster.hitPoints > 0) { if (monster.hitPoints > 0) {
monster.hitPoints -= message.dwDam; monster.hitPoints -= message.dwDam;
if ((monster.hitPoints >> 6) < 1) if ((monster.hitPoints >> 6) < 1)

Loading…
Cancel
Save