diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 9e11e4bee9..388c903d83 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -3458,9 +3459,13 @@ static void ride_construction_set_brakes_speed(int32_t brakesSpeed) z = _currentTrackBegin.z; if (!sub_6C683D(&x, &y, &z, _currentTrackPieceDirection & 3, _currentTrackPieceType, 0, &tileElement, 0)) { - game_do_command( - _currentTrackBegin.x, GAME_COMMAND_FLAG_APPLY | ((brakesSpeed) << 8), _currentTrackBegin.y, - tileElement->AsTrack()->GetTrackType(), GAME_COMMAND_SET_BRAKES_SPEED, _currentTrackBegin.z, 0); + auto trackSetBrakeSpeed = TrackSetBrakeSpeedAction( + { _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z }, tileElement->AsTrack()->GetTrackType(), + brakesSpeed); + trackSetBrakeSpeed.SetCallback( + [](const GameAction* ga, const GameActionResult* result) { window_ride_construction_update_active_elements(); }); + GameActions::Execute(&trackSetBrakeSpeed); + return; } window_ride_construction_update_active_elements(); } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 9ed6cf73e2..7048190972 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -1289,7 +1289,7 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { game_command_smooth_land, nullptr, nullptr, - game_command_set_brakes_speed, + nullptr, game_command_hire_new_staff_member, game_command_set_staff_patrol, game_command_fire_staff_member, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 99a8cb3d83..c017f1f139 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -45,9 +45,9 @@ enum GAME_COMMAND GAME_COMMAND_RAISE_LAND, // GA GAME_COMMAND_LOWER_LAND, // GA GAME_COMMAND_EDIT_LAND_SMOOTH, - GAME_COMMAND_RAISE_WATER, // GA - GAME_COMMAND_LOWER_WATER, // GA - GAME_COMMAND_SET_BRAKES_SPEED, + GAME_COMMAND_RAISE_WATER, // GA + GAME_COMMAND_LOWER_WATER, // GA + GAME_COMMAND_SET_BRAKES_SPEED, // GA GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, GAME_COMMAND_SET_STAFF_PATROL, GAME_COMMAND_FIRE_STAFF_MEMBER, diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index d87adb6b4d..6406055f8d 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -52,6 +52,7 @@ #include "StaffSetOrdersAction.hpp" #include "TrackPlaceAction.hpp" #include "TrackRemoveAction.hpp" +#include "TrackSetBrakeSpeedAction.hpp" #include "WallRemoveAction.hpp" #include "WaterLowerAction.hpp" #include "WaterRaiseAction.hpp" @@ -103,6 +104,7 @@ namespace GameActions Register(); Register(); Register(); + Register(); Register(); Register(); Register(); diff --git a/src/openrct2/actions/TrackSetBrakeSpeedAction.hpp b/src/openrct2/actions/TrackSetBrakeSpeedAction.hpp new file mode 100644 index 0000000000..c3b60556f8 --- /dev/null +++ b/src/openrct2/actions/TrackSetBrakeSpeedAction.hpp @@ -0,0 +1,75 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../management/Finance.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(TrackSetBrakeSpeedAction, GAME_COMMAND_SET_BRAKES_SPEED, GameActionResult) +{ +private: + CoordsXYZ _loc; + uint8_t _trackType; + uint8_t _brakeSpeed; + +public: + TrackSetBrakeSpeedAction() = default; + TrackSetBrakeSpeedAction(CoordsXYZ loc, uint8_t trackType, uint8_t brakeSpeed) + : _loc(loc) + , _trackType(trackType) + , _brakeSpeed(brakeSpeed) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + stream << DS_TAG(_loc) << DS_TAG(_trackType) << DS_TAG(_brakeSpeed); + } + + GameActionResult::Ptr Query() const override + { + return QueryExecute(false); + } + + GameActionResult::Ptr Execute() const override + { + return QueryExecute(true); + } + +private: + GameActionResult::Ptr QueryExecute(bool isExecuting) const + { + auto res = MakeResult(); + + res->Position = _loc; + res->Position.x += 16; + res->Position.y += 16; + res->ExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; + + TileElement* tileElement = map_get_track_element_at_of_type(_loc.x / 32, _loc.y / 32, _loc.z / 8, _trackType); + if (tileElement == nullptr) + { + log_warning("Invalid game command for setting brakes speed. x = %d, y = %d", _loc.x, _loc.y); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + if (isExecuting == true) + { + tileElement->AsTrack()->SetBrakeBoosterSpeed(_brakeSpeed); + } + return res; + } +}; diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index b5421f73e5..1c7b64f6ee 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -1264,55 +1264,6 @@ void game_command_remove_track( *edx & 0xFF, (*edx >> 8) & 0xFF, *eax & 0xFFFF, *ecx & 0xFFFF, *edi & 0xFFFF, (*ebx >> 8) & 0xFF, *ebx & 0xFF); } -/** - * - * rct2: 0x006C5AE9 - */ -void game_command_set_brakes_speed( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, int32_t* edi, - [[maybe_unused]] int32_t* ebp) -{ - int32_t x = (*eax & 0xFFFF); - int32_t y = (*ecx & 0xFFFF); - int32_t z = (*edi & 0xFFFF); - int32_t trackType = (*edx & 0xFF); - int32_t brakesSpeed = ((*ebx >> 8) & 0xFF); - - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; - gCommandPosition.x = x + 16; - gCommandPosition.y = y + 16; - gCommandPosition.z = z; - - if (*ebx & GAME_COMMAND_FLAG_APPLY) - { - *ebx = 0; - return; - } - - TileElement* tileElement = map_get_first_element_at(x >> 5, y >> 5); - if (tileElement == nullptr) - { - log_warning("Invalid game command for setting brakes speed. x = %d, y = %d", x, y); - *ebx = MONEY32_UNDEFINED; - return; - } - do - { - if (tileElement->base_height * 8 != z) - continue; - if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) - continue; - if (tileElement->AsTrack()->GetTrackType() != trackType) - continue; - - tileElement->AsTrack()->SetBrakeBoosterSpeed(brakesSpeed); - - break; - } while (!(tileElement++)->IsLastForTile()); - - *ebx = 0; -} - void track_circuit_iterator_begin(track_circuit_iterator* it, CoordsXYE first) { it->last = first; diff --git a/src/openrct2/ride/Track.h b/src/openrct2/ride/Track.h index ef6bb84501..8f194f6955 100644 --- a/src/openrct2/ride/Track.h +++ b/src/openrct2/ride/Track.h @@ -557,7 +557,5 @@ money32 maze_set_track( uint16_t x, uint16_t y, uint16_t z, uint8_t flags, bool initialPlacement, uint8_t direction, ride_id_t rideIndex, uint8_t mode); -void game_command_set_brakes_speed( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); bool track_element_is_booster(uint8_t rideType, uint8_t trackType); bool track_element_has_speed_setting(uint8_t trackType);