From e128a78b91e1c64d7639c162daac8bbe14ca4715 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 28 Feb 2019 16:27:19 +0000 Subject: [PATCH] Fix formating and other issues Refactor as per comments. Simplified some of the code as well Use constants --- src/openrct2-ui/windows/RideConstruction.cpp | 5 +- src/openrct2/ReplayManager.cpp | 4 +- .../actions/RideEntranceExitPlaceAction.hpp | 75 +++---------------- src/openrct2/core/DataSerialiserTraits.h | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/world/Entrance.h | 2 + 6 files changed, 19 insertions(+), 71 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index f419e4976c..9e11e4bee9 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3941,8 +3941,7 @@ static void ride_construction_tooldown_entrance_exit(int32_t screenX, int32_t sc auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction( { _unkF44188.x, _unkF44188.y }, direction_reverse(gRideEntranceExitPlaceDirection), gRideEntranceExitPlaceRideIndex, - gRideEntranceExitPlaceStationIndex, - gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT); + gRideEntranceExitPlaceStationIndex, gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT); rideEntranceExitPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) { if (result->Error != GA_ERROR::OK) @@ -3956,7 +3955,7 @@ static void ride_construction_tooldown_entrance_exit(int32_t screenX, int32_t sc tool_cancel(); if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_NO_TRACK)) { - window_close_by_class(WC_RIDE_CONSTRUCTION); + window_close_by_class(WC_RIDE_CONSTRUCTION); } } else diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index 462360df6c..a15298b2e6 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -506,12 +506,12 @@ namespace OpenRCT2 } case GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT: { - CoordsXY loc = {command.eax & 0xFFFF, command.ecx & 0xFFFF}; + CoordsXY loc = { (int32_t)(command.eax & 0xFFFF), (int32_t)(command.ecx & 0xFFFF) }; Direction direction = (command.ebx >> 8) & 0xFF; ride_id_t rideId = command.edx & 0xFF; uint8_t stationNum = command.edi & 0xFF; bool isExit = ((command.edx >> 8) & 0xFF) != 0; - result.action = std::make_unique(loc,direction,rideId,stationNum,isExit); + result.action = std::make_unique(loc, direction, rideId, stationNum, isExit); result.action->SetFlags(command.ebx & 0xFF); break; } diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp index 94dfc87eee..8ef9533354 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.hpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.hpp @@ -10,11 +10,11 @@ #pragma once #include "../actions/RideEntranceExitRemoveAction.hpp" +#include "../management/Finance.h" #include "../ride/Ride.h" #include "../ride/Station.h" #include "../world/Entrance.h" #include "../world/MapAnimation.h" -#include "../management/Finance.h" #include "../world/Sprite.h" #include "GameAction.h" @@ -92,44 +92,13 @@ public: ride_clear_for_construction(ride); ride_remove_peeps(ride); - bool requiresRemove = false; - LocationXY16 removeCoord = { 0, 0 }; + const auto location = _isExit ? ride_get_exit_location(ride, _stationNum) + : ride_get_entrance_location(ride, _stationNum); - if (_isExit) - { - const auto exit = ride_get_exit_location(ride, _stationNum); - if (!exit.isNull()) - { - if (GetFlags() & GAME_COMMAND_FLAG_GHOST) - { - return MakeResult(GA_ERROR::DISALLOWED, errorTitle); - } - - removeCoord.x = exit.x * 32; - removeCoord.y = exit.y * 32; - requiresRemove = true; - } - } - else - { - const auto entrance = ride_get_entrance_location(ride, _stationNum); - if (!entrance.isNull()) - { - if (GetFlags() & GAME_COMMAND_FLAG_GHOST) - { - return MakeResult(GA_ERROR::DISALLOWED, errorTitle); - } - - removeCoord.x = entrance.x * 32; - removeCoord.y = entrance.y * 32; - requiresRemove = true; - } - } - - if (requiresRemove) + if (!location.isNull()) { auto rideEntranceExitRemove = RideEntranceExitRemoveAction( - { removeCoord.x, removeCoord.y }, _rideIndex, _stationNum, _isExit); + { location.x * 32, location.y * 32 }, _rideIndex, _stationNum, _isExit); rideEntranceExitRemove.SetFlags(GetFlags()); auto result = GameActions::QueryNested(&rideEntranceExitRemove); @@ -161,7 +130,7 @@ public: return MakeResult(GA_ERROR::DISALLOWED, errorTitle, STR_RIDE_CANT_BUILD_THIS_UNDERWATER); } - if (z / 8 > 244) + if (z / 8 > MaxRideEntranceOrExitHeight) { return MakeResult(GA_ERROR::DISALLOWED, errorTitle, STR_TOO_HIGH); } @@ -190,34 +159,12 @@ public: ride_clear_for_construction(ride); ride_remove_peeps(ride); - bool requiresRemove = false; - LocationXY16 removeCoord = { 0, 0 }; - - if (_isExit) - { - const auto exit = ride_get_exit_location(ride, _stationNum); - if (!exit.isNull()) - { - removeCoord.x = exit.x * 32; - removeCoord.y = exit.y * 32; - requiresRemove = true; - } - } - else - { - const auto entrance = ride_get_entrance_location(ride, _stationNum); - if (!entrance.isNull()) - { - removeCoord.x = entrance.x * 32; - removeCoord.y = entrance.y * 32; - requiresRemove = true; - } - } - - if (requiresRemove) + const auto location = _isExit ? ride_get_exit_location(ride, _stationNum) + : ride_get_entrance_location(ride, _stationNum); + if (!location.isNull()) { auto rideEntranceExitRemove = RideEntranceExitRemoveAction( - { removeCoord.x, removeCoord.y }, _rideIndex, _stationNum, _isExit); + { location.x * 32, location.y * 32 }, _rideIndex, _stationNum, _isExit); rideEntranceExitRemove.SetFlags(GetFlags()); auto result = GameActions::ExecuteNested(&rideEntranceExitRemove); @@ -324,7 +271,7 @@ public: return MakeResult(GA_ERROR::DISALLOWED, errorTitle, STR_RIDE_CANT_BUILD_THIS_UNDERWATER); } - if (baseZ > 244) + if (baseZ > MaxRideEntranceOrExitHeight) { return MakeResult(GA_ERROR::DISALLOWED, errorTitle, STR_TOO_HIGH); } diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index da80b1190a..e415f18bab 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -333,7 +333,7 @@ template<> struct DataSerializerTraits { auto x = ByteSwapBE(stream->ReadValue()); auto y = ByteSwapBE(stream->ReadValue()); - coords = CoordsXY{x, y}; + coords = CoordsXY{ x, y }; } static void log(IStream* stream, const CoordsXY& coords) { diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index ef69064c0b..049c03e316 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1218,7 +1218,7 @@ static int32_t track_design_place_maze(rct_track_td6* td6, int16_t x, int16_t y, if (_trackDesignPlaceOperation == PTD_OPERATION_1) { - auto res = RideEntranceExitPlaceAction::TrackPlaceQuery({mapCoord.x, mapCoord.y, z}, false); + auto res = RideEntranceExitPlaceAction::TrackPlaceQuery({ mapCoord.x, mapCoord.y, z }, false); cost = res->Error == GA_ERROR::OK ? res->Cost : MONEY32_UNDEFINED; } else diff --git a/src/openrct2/world/Entrance.h b/src/openrct2/world/Entrance.h index eff7bd5f35..740791b3f6 100644 --- a/src/openrct2/world/Entrance.h +++ b/src/openrct2/world/Entrance.h @@ -37,6 +37,8 @@ extern uint8_t gParkEntranceGhostDirection; #define MAX_PARK_ENTRANCES 4 +constexpr int32_t MaxRideEntranceOrExitHeight = 244; + extern std::vector gParkEntrances; extern CoordsXYZD gRideEntranceExitGhostPosition;