From e1cdec438e6966e09b3bfe77b44adb20e24093ef Mon Sep 17 00:00:00 2001 From: obligaron Date: Sun, 16 Apr 2023 23:15:50 +0200 Subject: [PATCH] When player position desyncs ensure position.old is also updated --- Source/multi.cpp | 2 ++ Source/player.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/Source/multi.cpp b/Source/multi.cpp index 3022c600d..a0bb6debf 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -657,6 +657,7 @@ void multi_process_network_packets() player.position.future = syncPosition; if (player.isWalking()) player.position.temp = syncPosition; + SetPlayerOld(player); dPlayer[player.position.tile.x][player.position.tile.y] = playerId + 1; } if (player.position.future.WalkingDistance(player.position.tile) > 1) { @@ -668,6 +669,7 @@ void multi_process_network_packets() } else { player.position.tile = syncPosition; player.position.future = syncPosition; + SetPlayerOld(player); } } } diff --git a/Source/player.cpp b/Source/player.cpp index 04302f4f1..770ab5d85 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -2588,6 +2588,7 @@ void InitPlayer(Player &player, bool firstTime) } player.position.future = player.position.tile; + SetPlayerOld(player); player.walkpath[0] = WALK_NONE; player.destAction = ACTION_NONE; @@ -2701,6 +2702,16 @@ void FixPlrWalkTags(const Player &player) dPlayer[searchTile.x][searchTile.y] = 0; } } + +#ifdef _DEBUG + // Checks that FixPlrWalkTags really removes player from all dPlayer tiles + // FixPlrWalkTags could fail if player.position.old is not updated correctly + for (int y = 0; y < MAXDUNY; y++) { + for (int x = 0; x < MAXDUNX; x++) { + assert(PlayerAtPosition({ x, y }) != &player); + } + } +#endif } void StartPlrHit(Player &player, int dam, bool forcehit)