update_mapgen: rotation fixes to solve the teleporting NPC issue #35534
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.
Summary
SUMMARY: Bugfixes "update_mapgen: rotation fixes to solve the teleporting NPC issue"
Purpose of change
Fixes #35430
NPCs teleport to the upper left corner to the reality bubble when an
update_mapgen
function needs to rotate their overmap tile.While investigating that issue, I noticed that basecamps built in rotated fire stations or evac shelters didn't rotate after setting up the camp, which kept the NPC in place but meant that the upgrades were applied to the wrong part of the map.
Fix both issues.
Describe the solution
For the base camp issue, create a new rotational overmap tile ID for basecamps and set the overmap tile ID to that new ID including the rotation information. Further
update_mapgen
calls will continue to rotate the map properly to put the updates in the correct relative position.map::rotate()
usesnpc::spawn_at_precise()
to move NPCs during rotation, but this explicitly clips the NPC's position to upper left of the reality bubble. Pass asetpos_safe
bool torotate()
whenrotate()
is called from anupdate_mapgen
function, and usenpc::setpos()
instead ofnpc::spawn_at_precise()
so that position isn't clipped.npc::setpos()
explicitly can't be called during normal mapgen, so this split is required.Describe alternatives you've considered
I hate CDDA's co-ordinate systems. Fixing them to be type safe isn't feasible.
Testing
Started a new game and went to an east facing refugee center. Performed the first two Old Guard rep missions, the second of which calls
update_mapgen
to place some NPCs, and verified that the other NPCs were not teleported away.Started a fire station faction camp in a west facing faction camp, and verified that the companion NPC wasn't teleported away and that the kitchen upgrade spawned in the kitchen correctly.