Skip to content

Commit

Permalink
fix: pets with MF_PET_WONT_FOLLOW flag don't follow player (#4332)
Browse files Browse the repository at this point in the history
fix: pets with MF_PET_WONT_FOLLOW flag don't follow player

THe root-cause for pets always following player regardless of
MF_PET_WONT_FOLLOW flag was found in move_scent() which caused non
fleeing creatures to gravitate towards the scent of the player, ignoring
the wont-follow flag.
  • Loading branch information
ekaratzas authored Mar 10, 2024
1 parent 32f75ac commit 6f8ef0e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,12 @@ tripoint monster::scent_move()
bestsmell = g->scent.get( pos() );
}

const scenttype_id player_scent = g->u.get_type_of_scent();
// The main purpose of scent_move() is to either move toward scents or away from scents depending on the value of the fleeing flag.
// However, if the monster is a pet who is not actively fleeing and has the WONT_FOLLOW flag, we'd rather let it stumble instead of
// vaguely follow the player's scent.
const bool ignore_player_scent = !fleeing && is_pet() && has_flag( MF_PET_WONT_FOLLOW );

tripoint next( -1, -1, posz() );
if( ( !fleeing && g->scent.get( pos() ) > smell_threshold ) ||
( fleeing && bestsmell == 0 ) ) {
Expand Down Expand Up @@ -1283,6 +1289,10 @@ tripoint monster::scent_move()
right_scent = false;
}

if( ignore_player_scent && type_scent == player_scent ) {
right_scent = false;
}

if( ( !fleeing && smell < bestsmell ) || ( fleeing && smell > bestsmell ) || !right_scent ) {
continue;
}
Expand Down

0 comments on commit 6f8ef0e

Please sign in to comment.