From 54a058ca6c10d86fee20d4ece3351e9ae40a2f3e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 7 Apr 2020 19:43:20 +0100 Subject: [PATCH] Fix boat location import/export/update. After a refactoring to split off the boat location the import/export functions meant incorrect information could be loaded into the s6 file for boats that had not left the station. Boats that had left the station had other fields clobbered for the same reason --- src/openrct2/rct1/S4Importer.cpp | 5 +++-- src/openrct2/rct2/S6Exporter.cpp | 5 +++-- src/openrct2/rct2/S6Importer.cpp | 6 ++++-- src/openrct2/ride/Vehicle.cpp | 3 +++ src/openrct2/world/Location.hpp | 2 ++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 7513170d3c..6edb865699 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1222,14 +1222,15 @@ private: dst->TrackSubposition = src->TrackSubposition; dst->TrackLocation = { src->track_x, src->track_y, src->track_z }; dst->current_station = src->current_station; - dst->track_type = src->track_type; - if (src->boat_location.isNull() || ride->mode != RIDE_MODE_BOAT_HIRE) + if (src->boat_location.isNull() || ride->mode != RIDE_MODE_BOAT_HIRE || statusSrc != VEHICLE_STATUS_TRAVELLING_BOAT) { dst->BoatLocation.setNull(); + dst->track_type = src->track_type; } else { dst->BoatLocation = TileCoordsXY{ src->boat_location.x, src->boat_location.y }.ToCoordsXY(); + dst->track_type = 0; } dst->track_progress = src->track_progress; dst->vertical_drop_countdown = src->vertical_drop_countdown; diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index f6a08ad328..8e17cb5409 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -1017,7 +1017,7 @@ void S6Exporter::ExportSpriteVehicle(RCT2SpriteVehicle* dst, const Vehicle* src) dst->vehicle_type = src->vehicle_type; dst->colours = src->colours; dst->track_progress = src->track_progress; - if (ride != nullptr && ride->mode == RIDE_MODE_BOAT_HIRE) + if (ride != nullptr && ride->mode == RIDE_MODE_BOAT_HIRE && src->status == VEHICLE_STATUS_TRAVELLING_BOAT) { if (src->BoatLocation.isNull()) { @@ -1031,9 +1031,10 @@ void S6Exporter::ExportSpriteVehicle(RCT2SpriteVehicle* dst, const Vehicle* src) } else { + // Track direction and type are in the same field dst->track_direction = src->track_direction; + // dst->track_type = src->track_type; } - dst->track_type = src->track_type; dst->track_x = src->TrackLocation.x; dst->track_y = src->TrackLocation.y; dst->track_z = src->TrackLocation.z; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 2439e1b216..186a61ccf9 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1322,15 +1322,17 @@ public: dst->colours = src->colours; dst->track_progress = src->track_progress; dst->track_direction = src->track_direction; - if (src->boat_location.isNull() || ride.mode != RIDE_MODE_BOAT_HIRE) + if (src->boat_location.isNull() || ride.mode != RIDE_MODE_BOAT_HIRE || src->status != VEHICLE_STATUS_TRAVELLING_BOAT) { dst->BoatLocation.setNull(); + dst->track_type = src->track_type; } else { dst->BoatLocation = TileCoordsXY{ src->boat_location.x, src->boat_location.y }.ToCoordsXY(); + dst->track_type = 0; } - dst->track_type = src->track_type; + dst->TrackLocation = { src->track_x, src->track_y, src->track_z }; dst->next_vehicle_on_train = src->next_vehicle_on_train; dst->prev_vehicle_on_ride = src->prev_vehicle_on_ride; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index cd42972fd1..69d5ba2b83 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -3148,6 +3148,8 @@ static void vehicle_update_travelling_boat_hire_setup(Vehicle* vehicle) vehicle->BoatLocation = location; vehicle->var_35 = 0; + // No longer on a track so reset to 0 for import/export + vehicle->track_type = 0; vehicle->SetState(VEHICLE_STATUS_TRAVELLING_BOAT); vehicle->remaining_distance += 27924; @@ -4269,6 +4271,7 @@ static void loc_6DA9F9(Vehicle* vehicle, int32_t x, int32_t y, int32_t trackX, i if (ride != nullptr) { vehicle->track_type = (trackElement->GetTrackType() << 2) | (ride->boat_hire_return_direction & 3); + vehicle->BoatLocation.setNull(); } vehicle->track_progress = 0; diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index fd4f41a604..22aa3243e9 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -190,6 +190,7 @@ struct CoordsXY void setNull() { x = COORDS_NULL; + y = 0; } }; @@ -301,6 +302,7 @@ struct TileCoordsXY void setNull() { x = COORDS_NULL; + y = 0; } };