diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2c49933f6d..bac5da4cf4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,9 +50,9 @@ set(OBJECTS_VERSION "1.0.21")
set(OBJECTS_URL "https://github.com/OpenRCT2/objects/releases/download/v${OBJECTS_VERSION}/objects.zip")
set(OBJECTS_SHA1 "c38af45d51a6e440386180feacf76c64720b6ac5")
-set(REPLAYS_VERSION "0.0.43")
+set(REPLAYS_VERSION "0.0.44")
set(REPLAYS_URL "https://github.com/OpenRCT2/replays/releases/download/v${REPLAYS_VERSION}/replays.zip")
-set(REPLAYS_SHA1 "269E4FC432A73AE9A5D601EC2A1C882F3D9BDF3C")
+set(REPLAYS_SHA1 "586F3930DE8D2C3880AAFD30ABC4D81ABC0B64A4")
option(FORCE32 "Force 32-bit build. It will add `-m32` to compiler flags.")
option(WITH_TESTS "Build tests")
diff --git a/openrct2.proj b/openrct2.proj
index 999ffe9873..369b497d2e 100644
--- a/openrct2.proj
+++ b/openrct2.proj
@@ -48,8 +48,8 @@
304d13a126c15bf2c86ff13b81a2f2cc1856ac8d
https://github.com/OpenRCT2/objects/releases/download/v1.0.21/objects.zip
c38af45d51a6e440386180feacf76c64720b6ac5
- https://github.com/OpenRCT2/replays/releases/download/v0.0.43/replays.zip
- 269E4FC432A73AE9A5D601EC2A1C882F3D9BDF3C
+ https://github.com/OpenRCT2/replays/releases/download/v0.0.44/replays.zip
+ 586F3930DE8D2C3880AAFD30ABC4D81ABC0B64A4
diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp
index 8ba15a0de6..3a95370b77 100644
--- a/src/openrct2/GameStateSnapshots.cpp
+++ b/src/openrct2/GameStateSnapshots.cpp
@@ -253,10 +253,16 @@ struct GameStateSnapshots final : public IGameStateSnapshots
COMPARE_FIELD(Peep, InteractionRideIndex);
COMPARE_FIELD(Peep, Id);
COMPARE_FIELD(Peep, PathCheckOptimisation);
- COMPARE_FIELD(Peep, PathfindGoal);
+ COMPARE_FIELD(Peep, PathfindGoal.x);
+ COMPARE_FIELD(Peep, PathfindGoal.y);
+ COMPARE_FIELD(Peep, PathfindGoal.z);
+ COMPARE_FIELD(Peep, PathfindGoal.direction);
for (int i = 0; i < 4; i++)
{
- COMPARE_FIELD(Peep, PathfindHistory[i]);
+ COMPARE_FIELD(Peep, PathfindHistory[i].x);
+ COMPARE_FIELD(Peep, PathfindHistory[i].y);
+ COMPARE_FIELD(Peep, PathfindHistory[i].z);
+ COMPARE_FIELD(Peep, PathfindHistory[i].direction);
}
COMPARE_FIELD(Peep, WalkingFrameNum);
}
diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h
index f4c9266fc5..4fdcbaf464 100644
--- a/src/openrct2/core/DataSerialiserTraits.h
+++ b/src/openrct2/core/DataSerialiserTraits.h
@@ -867,3 +867,32 @@ template<> struct DataSerializerTraits_t
stream->Write(msg, strlen(msg));
}
};
+
+template<> struct DataSerializerTraits_t
+{
+ static void encode(OpenRCT2::IStream* stream, const TileCoordsXYZD& coord)
+ {
+ stream->WriteValue(ByteSwapBE(coord.x));
+ stream->WriteValue(ByteSwapBE(coord.y));
+ stream->WriteValue(ByteSwapBE(coord.z));
+ stream->WriteValue(ByteSwapBE(coord.direction));
+ }
+
+ static void decode(OpenRCT2::IStream* stream, TileCoordsXYZD& coord)
+ {
+ auto x = ByteSwapBE(stream->ReadValue());
+ auto y = ByteSwapBE(stream->ReadValue());
+ auto z = ByteSwapBE(stream->ReadValue());
+ auto d = ByteSwapBE(stream->ReadValue());
+ coord = TileCoordsXYZD{ x, y, z, d };
+ }
+
+ static void log(OpenRCT2::IStream* stream, const TileCoordsXYZD& coord)
+ {
+ char msg[128] = {};
+ snprintf(
+ msg, sizeof(msg), "TileCoordsXYZD(x = %d, y = %d, z = %d, direction = %d)", coord.x, coord.y, coord.z,
+ coord.direction);
+ stream->Write(msg, strlen(msg));
+ }
+};
diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp
index 9bf83c9a7f..8a2f474810 100644
--- a/src/openrct2/peep/GuestPathfinding.cpp
+++ b/src/openrct2/peep/GuestPathfinding.cpp
@@ -700,8 +700,7 @@ static void peep_pathfind_heuristic_search(
/* If this is where the search started this is a search loop and the
* current search path ends here.
* Return without updating the parameters (best result so far). */
- if ((_peepPathFindHistory[0].location.x == static_cast(loc.x))
- && (_peepPathFindHistory[0].location.y == static_cast(loc.y)) && (_peepPathFindHistory[0].location.z == loc.z))
+ if (_peepPathFindHistory[0].location == loc)
{
#if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2
if (gPathFindDebug)
@@ -1076,7 +1075,7 @@ static void peep_pathfind_heuristic_search(
* already been visited by the peep while heading for this goal. */
for (auto& pathfindHistory : peep->PathfindHistory)
{
- if (pathfindHistory.x == loc.x && pathfindHistory.y == loc.y && pathfindHistory.z == loc.z)
+ if (pathfindHistory == loc)
{
if (pathfindHistory.direction == 0)
{
@@ -1103,9 +1102,7 @@ static void peep_pathfind_heuristic_search(
for (int32_t junctionNum = _peepPathFindNumJunctions + 1; junctionNum <= _peepPathFindMaxJunctions;
junctionNum++)
{
- if ((_peepPathFindHistory[junctionNum].location.x == static_cast(loc.x))
- && (_peepPathFindHistory[junctionNum].location.y == static_cast(loc.y))
- && (_peepPathFindHistory[junctionNum].location.z == loc.z))
+ if (_peepPathFindHistory[junctionNum].location == loc)
{
pathLoop = true;
break;
@@ -1144,9 +1141,7 @@ static void peep_pathfind_heuristic_search(
for (uint8_t junctInd = 0; junctInd < *endJunctions; junctInd++)
{
uint8_t histIdx = _peepPathFindMaxJunctions - junctInd;
- junctionList[junctInd].x = _peepPathFindHistory[histIdx].location.x;
- junctionList[junctInd].y = _peepPathFindHistory[histIdx].location.y;
- junctionList[junctInd].z = _peepPathFindHistory[histIdx].location.z;
+ junctionList[junctInd] = _peepPathFindHistory[histIdx].location;
directionList[junctInd] = _peepPathFindHistory[histIdx].direction;
}
}
@@ -1163,9 +1158,7 @@ static void peep_pathfind_heuristic_search(
/* This junction was NOT previously visited in the current
* search path, so add the junction to the history. */
- _peepPathFindHistory[_peepPathFindNumJunctions].location.x = static_cast(loc.x);
- _peepPathFindHistory[_peepPathFindNumJunctions].location.y = static_cast(loc.y);
- _peepPathFindHistory[_peepPathFindNumJunctions].location.z = loc.z;
+ _peepPathFindHistory[_peepPathFindNumJunctions].location = loc;
// .direction take is added below.
_peepPathFindNumJunctions--;
@@ -1334,7 +1327,7 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
permitted_edges &= 0xF;
uint8_t edges = permitted_edges;
- if (isThin && peep->PathfindGoal.x == goal.x && peep->PathfindGoal.y == goal.y && peep->PathfindGoal.z == goal.z)
+ if (isThin && peep->PathfindGoal == goal)
{
/* Use of peep->PathfindHistory[]:
* When walking to a goal, the peep PathfindHistory stores
@@ -1353,7 +1346,7 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
* directions it has not yet tried. */
for (auto& pathfindHistory : peep->PathfindHistory)
{
- if (pathfindHistory.x == loc.x && pathfindHistory.y == loc.y && pathfindHistory.z == loc.z)
+ if (pathfindHistory == loc)
{
/* Fix broken PathfindHistory[i].direction
* which have untried directions that are not
@@ -1401,16 +1394,15 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
/* If this is a new goal for the peep. Store it and reset the peep's
* PathfindHistory. */
- if (!direction_valid(peep->PathfindGoal.direction) || peep->PathfindGoal.x != goal.x || peep->PathfindGoal.y != goal.y
- || peep->PathfindGoal.z != goal.z)
+ if (!direction_valid(peep->PathfindGoal.direction) || peep->PathfindGoal != goal)
{
- peep->PathfindGoal.x = goal.x;
- peep->PathfindGoal.y = goal.y;
- peep->PathfindGoal.z = goal.z;
- peep->PathfindGoal.direction = 0;
+ peep->PathfindGoal = { goal, 0 };
// Clear pathfinding history
- std::fill(std::begin(peep->PathfindHistory), std::end(peep->PathfindHistory), rct12_xyzd8{ 0xFF, 0xFF, 0xFF, 0xFF });
+ TileCoordsXYZD nullPos;
+ nullPos.setNull();
+
+ std::fill(std::begin(peep->PathfindHistory), std::end(peep->PathfindHistory), nullPos);
#if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1
if (_pathFindDebug)
{
@@ -1466,14 +1458,17 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
_peepPathFindNumJunctions = _peepPathFindMaxJunctions;
// Initialise _peepPathFindHistory.
- std::memset(static_cast(_peepPathFindHistory), 0xFF, sizeof(_peepPathFindHistory));
+
+ for (auto& entry : _peepPathFindHistory)
+ {
+ entry.location.setNull();
+ entry.direction = INVALID_DIRECTION;
+ }
/* The pathfinding will only use elements
* 1.._peepPathFindMaxJunctions, so the starting point
* is placed in element 0 */
- _peepPathFindHistory[0].location.x = static_cast(loc.x);
- _peepPathFindHistory[0].location.y = static_cast(loc.y);
- _peepPathFindHistory[0].location.z = loc.z;
+ _peepPathFindHistory[0].location = loc;
_peepPathFindHistory[0].direction = 0xF;
uint16_t score = 0xFFFF;
@@ -1586,8 +1581,7 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
{
for (int32_t i = 0; i < 4; ++i)
{
- if (peep->PathfindHistory[i].x == loc.x && peep->PathfindHistory[i].y == loc.y
- && peep->PathfindHistory[i].z == loc.z)
+ if (peep->PathfindHistory[i] == loc)
{
/* Peep remembers this junction, so remove the
* chosen_edge from those left to try. */
@@ -1611,10 +1605,7 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
* and remember this junction. */
int32_t i = peep->PathfindGoal.direction++;
peep->PathfindGoal.direction &= 3;
- peep->PathfindHistory[i].x = static_cast(loc.x);
- peep->PathfindHistory[i].y = static_cast(loc.y);
- peep->PathfindHistory[i].z = loc.z;
- peep->PathfindHistory[i].direction = permitted_edges;
+ peep->PathfindHistory[i] = { loc, permitted_edges };
/* Remove the chosen_edge from those left to try. */
peep->PathfindHistory[i].direction &= ~(1 << chosen_edge);
/* Also remove the edge through which the peep
@@ -2312,9 +2303,7 @@ void Peep::ResetPathfindGoal()
}
#endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1
- PathfindGoal.x = 0xFF;
- PathfindGoal.y = 0xFF;
- PathfindGoal.z = 0xFF;
+ PathfindGoal.setNull();
PathfindGoal.direction = INVALID_DIRECTION;
}
diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h
index a43542e449..7b0d176ebe 100644
--- a/src/openrct2/peep/Peep.h
+++ b/src/openrct2/peep/Peep.h
@@ -612,8 +612,8 @@ struct Peep : SpriteBase
ride_id_t InteractionRideIndex;
uint32_t Id;
uint8_t PathCheckOptimisation; // see peep.checkForPath
- rct12_xyzd8 PathfindGoal;
- std::array PathfindHistory;
+ TileCoordsXYZD PathfindGoal;
+ std::array PathfindHistory;
uint8_t WalkingFrameNum;
uint32_t PeepFlags;
diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp
index 9388d6e41b..984a8d8bd6 100644
--- a/src/openrct2/rct2/S6Exporter.cpp
+++ b/src/openrct2/rct2/S6Exporter.cpp
@@ -1343,10 +1343,27 @@ void S6Exporter::ExportEntityPeep(RCT2SpritePeep* dst, const Peep* src)
dst->id = src->Id;
dst->path_check_optimisation = src->PathCheckOptimisation;
dst->peep_flags = src->PeepFlags;
- dst->pathfind_goal = src->PathfindGoal;
+ if (src->PathfindGoal.isNull())
+ {
+ dst->pathfind_goal = { 0xFF, 0xFF, 0xFF, INVALID_DIRECTION };
+ }
+ else
+ {
+ dst->pathfind_goal = { static_cast(src->PathfindGoal.x), static_cast(src->PathfindGoal.y),
+ static_cast(src->PathfindGoal.z), src->PathfindGoal.direction };
+ }
for (size_t i = 0; i < std::size(src->PathfindHistory); i++)
{
- dst->pathfind_history[i] = src->PathfindHistory[i];
+ if (src->PathfindHistory[i].isNull())
+ {
+ dst->pathfind_history[i] = { 0xFF, 0xFF, 0xFF, INVALID_DIRECTION };
+ }
+ else
+ {
+ dst->pathfind_history[i] = { static_cast(src->PathfindHistory[i].x),
+ static_cast(src->PathfindHistory[i].y),
+ static_cast(src->PathfindHistory[i].z), src->PathfindHistory[i].direction };
+ }
}
dst->no_action_frame_num = src->WalkingFrameNum;
}
diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp
index f4763855b4..ee7525c4a5 100644
--- a/src/openrct2/rct2/S6Importer.cpp
+++ b/src/openrct2/rct2/S6Importer.cpp
@@ -1365,6 +1365,10 @@ public:
void ImportEntityPeep(Peep* dst, const RCT2SpritePeep* src)
{
+ const auto isNullLocation = [](const rct12_xyzd8& pos) {
+ return pos.x == 0xFF && pos.y == 0xFF && pos.z == 0xFF && pos.direction == INVALID_DIRECTION;
+ };
+
ImportEntityCommonProperties(static_cast(dst), src);
if (is_user_string_id(src->name_string_idx))
{
@@ -1401,10 +1405,28 @@ public:
dst->Id = src->id;
dst->PathCheckOptimisation = src->path_check_optimisation;
dst->PeepFlags = src->peep_flags;
- dst->PathfindGoal = src->pathfind_goal;
+ if (isNullLocation(src->pathfind_goal))
+ {
+ dst->PathfindGoal.setNull();
+ dst->PathfindGoal.direction = INVALID_DIRECTION;
+ }
+ else
+ {
+ dst->PathfindGoal = { src->pathfind_goal.x, src->pathfind_goal.y, src->pathfind_goal.z,
+ src->pathfind_goal.direction };
+ }
for (size_t i = 0; i < std::size(src->pathfind_history); i++)
{
- dst->PathfindHistory[i] = src->pathfind_history[i];
+ if (isNullLocation(src->pathfind_history[i]))
+ {
+ dst->PathfindHistory[i].setNull();
+ dst->PathfindHistory[i].direction = INVALID_DIRECTION;
+ }
+ else
+ {
+ dst->PathfindHistory[i] = { src->pathfind_history[i].x, src->pathfind_history[i].y, src->pathfind_history[i].z,
+ src->pathfind_history[i].direction };
+ }
}
dst->WalkingFrameNum = src->no_action_frame_num;
}
diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp
index 7fd725fffa..19e5ff9952 100644
--- a/src/openrct2/world/Location.hpp
+++ b/src/openrct2/world/Location.hpp
@@ -268,6 +268,12 @@ struct CoordsXYZ : public CoordsXY
{
return ToTileStart() + CoordsXYZ{ COORDS_XY_HALF_TILE, COORDS_XY_HALF_TILE, 0 };
}
+
+ void setNull()
+ {
+ CoordsXY::setNull();
+ z = 0;
+ }
};
struct CoordsXYRangedZ : public CoordsXY
@@ -459,6 +465,12 @@ struct TileCoordsXYZ : public TileCoordsXY
}
return { x * COORDS_XY_STEP, y * COORDS_XY_STEP, z * COORDS_Z_STEP };
}
+
+ void setNull()
+ {
+ TileCoordsXY::setNull();
+ z = 0;
+ }
};
/**
@@ -615,6 +627,12 @@ struct TileCoordsXYZD : public TileCoordsXYZ
{
}
+ TileCoordsXYZD(const TileCoordsXYZ& t_, Direction d_)
+ : TileCoordsXYZ(t_)
+ , direction(d_)
+ {
+ }
+
TileCoordsXYZD(const TileCoordsXY& t_, int32_t z_, Direction d_)
: TileCoordsXYZ(t_, z_)
, direction(d_)
@@ -649,6 +667,12 @@ struct TileCoordsXYZD : public TileCoordsXYZ
}
return { x * COORDS_XY_STEP, y * COORDS_XY_STEP, z * COORDS_Z_STEP, direction };
}
+
+ void setNull()
+ {
+ TileCoordsXYZ::setNull();
+ direction = INVALID_DIRECTION;
+ }
};
/**