From 2a086608a778bf51727df2116802d533d4c37139 Mon Sep 17 00:00:00 2001 From: Efstratios Karatzas Date: Sat, 9 Mar 2024 23:19:48 -0800 Subject: [PATCH] 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. --- src/monmove.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/monmove.cpp b/src/monmove.cpp index e0d64eded8b4..d57eb6bbc39c 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -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 ) ) { @@ -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; }