1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Merge pull request #8852 'track_set_brake_speed'

This commit is contained in:
duncanspumpkin
2019-03-15 19:46:19 +00:00
7 changed files with 89 additions and 58 deletions

View File

@@ -20,6 +20,7 @@
#include <openrct2/actions/RideEntranceExitPlaceAction.hpp>
#include <openrct2/actions/TrackPlaceAction.hpp>
#include <openrct2/actions/TrackRemoveAction.hpp>
#include <openrct2/actions/TrackSetBrakeSpeedAction.hpp>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/localisation/Localisation.h>
@@ -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();
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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<LandSetHeightAction>();
Register<TrackPlaceAction>();
Register<TrackRemoveAction>();
Register<TrackSetBrakeSpeedAction>();
Register<ClearAction>();
Register<PauseToggleAction>();
Register<LoadOrQuitAction>();

View File

@@ -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;
}
};

View File

@@ -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;

View File

@@ -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);