Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_mapgen: rotation fixes to solve the teleporting NPC issue #35534

Merged
merged 2 commits into from
Nov 18, 2019

Conversation

mlangsdorf
Copy link
Contributor

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() uses npc::spawn_at_precise() to move NPCs during rotation, but this explicitly clips the NPC's position to upper left of the reality bubble. Pass a setpos_safe bool to rotate() when rotate() is called from an update_mapgen function, and use npc::setpos() instead of npc::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.

Now that basecamps can be built in places that aren't fields, the
basecamp overmap terrain id needs to include rotational data so that
update_mapgen will correctly place upgrades on fire stations and evac
shelters that are rotated.
@mlangsdorf mlangsdorf added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Map / Mapgen Overmap, Mapgen, Map extras, Map display NPC / Factions NPCs, AI, Speech, Factions, Ownership Player Faction Base / Camp All about the player faction base/camp/site labels Nov 15, 2019
src/mapgen.cpp Outdated Show resolved Hide resolved
Fixes CleverRaven#35430

When a tinymap is rotated during update_mapgen, the NPCs would be moved
via spawn_at_precise, which would clip their position to 0-11,0-11,
effectively teleporting them to the upper left of the reality bubble.

Rework rotate() to include a variable as to whether the rotation is
setpos() safe, and use setpos() to relocate NPCs because that doesn't
clip the position and teleport the NPCs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Map / Mapgen Overmap, Mapgen, Map extras, Map display NPC / Factions NPCs, AI, Speech, Factions, Ownership Player Faction Base / Camp All about the player faction base/camp/site
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refugee Center NPC's Teleport After Handing in Quest
3 participants