fix: pets with MF_PET_WONT_FOLLOW
flag don't follow player
#4332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Purpose of change
Fixes #4331
This is a fix for the bug where pets with WONT_FOLLOW flag actually end up following the player anyway.
Describe the solution
The rootcause lied in move_scent() which makes non fleeing pets follow the scent of the player, thus ignoring the WONT_FOLLOW flag. The fix works by making monsters ignore the player's scent if the monsters:
Other than that specific corner-case, smell-based mechanics remain unaffected for monsters.
Describe alternatives you've considered
I don't think this is fixed in cdda as far as I cant tell so no fix to copy from there. I initially had a more blunt fix that simply returned from move_scent() in case it was a pet with the wont-follow flag but I think the current, more targeted, approach is far better and way less likely to introduce regressions.
Testing
Spawn cow. Befriend cow. Move a couple of tiles away. Keep spamming '.' to pass turns and notice that the cow doesn't follow you. Move a couple of tiles away and try again and so on. Assuming no threats in the near area, the cow should just stumble randomly every few turns and not follow the player.
Additional context
Checklist