mirror of https://github.com/OpenRCT2/OpenRCT2.git
Implement TrackSetBrakeSpeedAction
This commit is contained in:
parent
f4526dd2ae
commit
7fbf11ac79
|
@ -20,6 +20,7 @@
|
||||||
#include <openrct2/actions/RideEntranceExitPlaceAction.hpp>
|
#include <openrct2/actions/RideEntranceExitPlaceAction.hpp>
|
||||||
#include <openrct2/actions/TrackPlaceAction.hpp>
|
#include <openrct2/actions/TrackPlaceAction.hpp>
|
||||||
#include <openrct2/actions/TrackRemoveAction.hpp>
|
#include <openrct2/actions/TrackRemoveAction.hpp>
|
||||||
|
#include <openrct2/actions/TrackSetBrakeSpeedAction.hpp>
|
||||||
#include <openrct2/audio/audio.h>
|
#include <openrct2/audio/audio.h>
|
||||||
#include <openrct2/config/Config.h>
|
#include <openrct2/config/Config.h>
|
||||||
#include <openrct2/localisation/Localisation.h>
|
#include <openrct2/localisation/Localisation.h>
|
||||||
|
@ -3458,9 +3459,13 @@ static void ride_construction_set_brakes_speed(int32_t brakesSpeed)
|
||||||
z = _currentTrackBegin.z;
|
z = _currentTrackBegin.z;
|
||||||
if (!sub_6C683D(&x, &y, &z, _currentTrackPieceDirection & 3, _currentTrackPieceType, 0, &tileElement, 0))
|
if (!sub_6C683D(&x, &y, &z, _currentTrackPieceDirection & 3, _currentTrackPieceType, 0, &tileElement, 0))
|
||||||
{
|
{
|
||||||
game_do_command(
|
auto trackSetBrakeSpeed = TrackSetBrakeSpeedAction(
|
||||||
_currentTrackBegin.x, GAME_COMMAND_FLAG_APPLY | ((brakesSpeed) << 8), _currentTrackBegin.y,
|
{ _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z }, tileElement->AsTrack()->GetTrackType(),
|
||||||
tileElement->AsTrack()->GetTrackType(), GAME_COMMAND_SET_BRAKES_SPEED, _currentTrackBegin.z, 0);
|
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();
|
window_ride_construction_update_active_elements();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "TrackRemoveAction.hpp"
|
#include "TrackRemoveAction.hpp"
|
||||||
#include "WallRemoveAction.hpp"
|
#include "WallRemoveAction.hpp"
|
||||||
#include "WaterSetHeightAction.hpp"
|
#include "WaterSetHeightAction.hpp"
|
||||||
|
#include "TrackSetBrakeSpeedAction.hpp"
|
||||||
|
|
||||||
namespace GameActions
|
namespace GameActions
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* 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 "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;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue