fix: move tamed pet to proper faction set in creature_tracker layer #4285
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.
Purpose of change
The reason for this PR is me hitting the following error message in the debug build as explained in the respective task when trying to tame a pet: "ERROR: the chicken tried to find faction player which wasn't loaded in game::monmove"
Fixes #4284
Describe the solution
Digging into it, it seems that once the animal gets tamed with food, it's never moved to the 'player' faction set of
Creature_tracker::monster_faction_map_
and then we hit the error inmonster::plan()
inmonmove.cpp
.What this change does is move the existing code that 'makes the animal a pet' into a new method,
monster::make_pet()
, akin to similar functions in that class. It also introduces a helper function in creature_tracker layer that allows us to notify that layer that there has been a change in the faction that this monster belongs to.In the new method of
Creature_tracker::update_faction()
layer we remove the monster from existing sets inmonster_faction_map_
and we use the existing internal helper functionadd_to_faction_map()
to properly add the pet in the appropriate set.Describe alternatives you've considered
Looked into CDDA repo but the creature_tracker layer has been majorly overhauled/rewritten. Porting a fix from there didn't seem like the way to go.
Testing
Follow repro steps. Spawn dog/chickens. Try to tame them. Notice we don't hit this error anymore.
Additional context
Checklist