-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Player snaps back if teleport fails #72887
base: master
Are you sure you want to change the base?
Conversation
If this explanation is too messy to be understood, let me know and I'll make a new attempt. |
Fair.
Do you want to PR this onto my branch? I'm not super-enthused about working with our coordinates systems and that way you can get full authorship for the commit. |
Sorry, I don't know how to hook up to others' PRs, and I don't care about credits (beyond people pounding their chests and bragging about things they've not actually done). Thus, here's the code:
plus: I've done some basic testing, moving to different submaps within the starting overmap tile and verifying I ended up in the corresponding location in the target overmap tile (that didn't work previously). I also spawned a breather and tried to teleport into it. That caused an infinite loop where, for whatever reason, the code tried to teleport the PC back to the tile it was on already. I blocked that with the check for the destination being the same as the source location at the top (which makes sense anyway). Can't say it's great fun trying to juggle the various coordinate systems and manually adjust between their projections. Edit: Come to think about it, I don't think the recursion is needed. The PC is already at the start location when the teleporting failed, and my sanity check causes the recursion call to bail out immediately without actually doing anything, and my character remained at the start location (I didn't check what happens when I try to move, etc. afterwards). |
A ping comment, in case this was put in the "I'm busy right now, I'll deal with it later" pile. |
The pile gets cleaned up, eventually! |
0551b5d
to
c37d0d4
Compare
Co-authored-by: PatrikLundell <[email protected]>
I ran this last push locally and it seemed to be all that was needed. Here's to hoping it works on CI as well. |
tests/water_movement_test.cpp
Outdated
@@ -144,7 +144,7 @@ TEST_CASE( "avatar_diving", "[diving]" ) | |||
|
|||
// Put us back at 0. We shouldn't have to do this but other tests are | |||
// making assumptions about what z-level they're on. | |||
g->vertical_shift( 0 ); | |||
dummy.setpos( test_origin ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue comes from this change. game::vertical_shift
sets abs_sub
on the map
object. And apparently Creature::setpos
does not, so the map still thinks it's at z-level -1 when the avatar moves in subsequent tests, which sets the avatar z-level to -1 when game::update_map
is called.
7ac03d8
to
ed4a75d
Compare
ed4a75d
to
f2f86d5
Compare
@@ -261,8 +261,14 @@ struct swim_scenario { | |||
static int swimming_steps( avatar &swimmer ) | |||
{ | |||
map &here = get_map(); | |||
// This shouldn't work. | |||
CAPTURE( swimmer.pos() ); | |||
avatar_action::move( swimmer, here, swimmer.pos() + tripoint_west ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avatar_action::move() wants an offset, not a coordinate, so you should provide just tripoint_west as the third argument.
No idea why it's ending up at z= -2 though?
@@ -272,10 +278,10 @@ static int swimming_steps( avatar &swimmer ) | |||
while( swimmer.get_stamina() > 0 && !swimmer.has_effect( effect_winded ) && steps < STOP_STEPS ) { | |||
if( steps % 2 == 0 ) { | |||
REQUIRE( swimmer.pos() == left ); | |||
REQUIRE( avatar_action::move( swimmer, here, tripoint_east ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this wants an offset like tripoint_east, not a coordinate like left.
Summary
Bugfixes "Additional code safety if player's long-range teleport fails"
Purpose of change
Describe the solution
Check the teleport succeeded by comparing the player's actual coordinates before to after. If they are the same, the teleport has failed somehow. Run map update again to shift all the coordinates back. Re-run the function to make sure we safely unload and then reload the map.
Describe alternatives you've considered
Testing
Video depicts an attempted teleport to a modified art_gallery which is packed with every square containing a monster.
2024-05-19.08-04-28.mp4
Additional context