Skip to content

Commit

Permalink
Decipher P_NewChaseDir
Browse files Browse the repository at this point in the history
  • Loading branch information
kraflab committed Apr 8, 2021
1 parent 3fd92ea commit a86d862
Showing 1 changed file with 45 additions and 34 deletions.
79 changes: 45 additions & 34 deletions prboom2/src/p_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,47 +674,58 @@ static void P_NewChaseDir(mobj_t *actor)
actor->strafecount = 0;

if (mbf_features) {
if (actor->floorz - actor->dropoffz > FRACUNIT*24 &&
actor->z <= actor->floorz &&
!(actor->flags & (MF_DROPOFF|MF_FLOAT)) &&
!comp[comp_dropoff] &&
P_AvoidDropoff(actor)) /* Move away from dropoff */
{
P_DoNewChaseDir(actor, dropoff_deltax, dropoff_deltay);
if (
actor->floorz - actor->dropoffz > FRACUNIT*24 &&
actor->z <= actor->floorz &&
!(actor->flags & (MF_DROPOFF|MF_FLOAT)) &&
!comp[comp_dropoff] &&
P_AvoidDropoff(actor)
) /* Move away from dropoff */
{
P_DoNewChaseDir(actor, dropoff_deltax, dropoff_deltay);

// If moving away from dropoff, set movecount to 1 so that
// small steps are taken to get monster away from dropoff.
// If moving away from dropoff, set movecount to 1 so that
// small steps are taken to get monster away from dropoff.

actor->movecount = 1;
return;
}
actor->movecount = 1;
return;
}
else
{
fixed_t dist = P_AproxDistance(deltax, deltay);
{
fixed_t dist = P_AproxDistance(deltax, deltay);

// Move away from friends when too close, except
// in certain situations (e.g. a crowded lift)
// Move away from friends when too close, except
// in certain situations (e.g. a crowded lift)

if (actor->flags & target->flags & MF_FRIEND &&
distfriend << FRACBITS > dist &&
!P_IsOnLift(target) && !P_IsUnderDamage(actor))
{
deltax = -deltax, deltay = -deltay;
} else
if (target->health > 0 && (actor->flags ^ target->flags) & MF_FRIEND)
{ // Live enemy target
if (monster_backing &&
actor->info->missilestate && actor->type != MT_SKULL &&
((!target->info->missilestate && dist < MELEERANGE*2) ||
(target->player && dist < MELEERANGE*3 &&
(target->player->readyweapon == wp_fist ||
target->player->readyweapon == wp_chainsaw))))
{ // Back away from melee attacker
actor->strafecount = P_Random(pr_enemystrafe) & 15;
deltax = -deltax, deltay = -deltay;
}
if (actor->flags & target->flags & MF_FRIEND &&
distfriend << FRACBITS > dist &&
!P_IsOnLift(target) && !P_IsUnderDamage(actor))
{
deltax = -deltax, deltay = -deltay;
}
else if (target->health > 0 && (actor->flags ^ target->flags) & MF_FRIEND)
{ // Live enemy target
if (
monster_backing &&
actor->info->missilestate &&
actor->type != MT_SKULL &&
(
(!target->info->missilestate && dist < MELEERANGE*2) ||
(
target->player && dist < MELEERANGE*3 &&
(
target->player->readyweapon == wp_fist ||
target->player->readyweapon == wp_chainsaw
)
)
)
)
{ // Back away from melee attacker
actor->strafecount = P_Random(pr_enemystrafe) & 15;
deltax = -deltax, deltay = -deltay;
}
}
}
}

P_DoNewChaseDir(actor, deltax, deltay);
Expand Down

0 comments on commit a86d862

Please sign in to comment.