forked from rosebudai/OpenRCT2-Web
Move Track game actions to GameActions namespace
This commit is contained in:
1 parent
afdee8852a
commit
86a001875e
13 files changed
+1419
-1440
No files matched your search
@@ -2318,7 +2318,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
return;
|
||||
}
|
||||
|
||||
auto trackPlaceAction = TrackPlaceAction(
|
||||
auto trackPlaceAction = GameActions::TrackPlaceAction(
|
||||
rideIndex, trackType, currentRide->type, { trackPos, static_cast<uint8_t>(trackDirection) }, properties & 0xFF,
|
||||
(properties >> 8) & 0x0F, (properties >> 12) & 0x0F, liftHillAndAlternativeState, false);
|
||||
if (_rideConstructionState == RideConstructionState::Back)
|
||||
@@ -2353,7 +2353,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
_currentTrackSelectionFlags.set(TrackSelectionFlag::trackPlaceActionQueued);
|
||||
}
|
||||
|
||||
const auto resultData = res.GetData<TrackPlaceActionResult>();
|
||||
const auto resultData = res.GetData<GameActions::TrackPlaceActionResult>();
|
||||
if (resultData.GroundFlags & ELEMENT_IS_UNDERGROUND)
|
||||
{
|
||||
ViewportSetVisibility(ViewportVisibility::UndergroundViewOn);
|
||||
@@ -2448,7 +2448,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
_gotoStartPlacementMode = true;
|
||||
}
|
||||
|
||||
auto trackRemoveAction = TrackRemoveAction(
|
||||
auto trackRemoveAction = GameActions::TrackRemoveAction(
|
||||
_currentTrackPieceType, 0,
|
||||
{ _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z, currentDirection });
|
||||
|
||||
@@ -2567,7 +2567,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
&tileElement, {})
|
||||
!= std::nullopt)
|
||||
{
|
||||
auto trackSetBrakeSpeed = TrackSetBrakeSpeedAction(
|
||||
auto trackSetBrakeSpeed = GameActions::TrackSetBrakeSpeedAction(
|
||||
_currentTrackBegin, tileElement->AsTrack()->GetTrackType(), brakesSpeed);
|
||||
trackSetBrakeSpeed.SetCallback([](const GameAction* ga, const GameActions::Result* result) {
|
||||
WindowRideConstructionUpdateActiveElements();
|
||||
@@ -4777,7 +4777,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
return result.Cost;
|
||||
}
|
||||
|
||||
auto trackPlaceAction = TrackPlaceAction(
|
||||
auto trackPlaceAction = GameActions::TrackPlaceAction(
|
||||
rideIndex, trackType, ride->type, { trackPos, static_cast<uint8_t>(trackDirection) }, 0, 0, 0,
|
||||
liftHillAndAlternativeState, false);
|
||||
trackPlaceAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
|
||||
@@ -4802,7 +4802,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
_unkF440C5 = { trackPos.x, trackPos.y, trackPos.z + zBegin, static_cast<Direction>(trackDirection) };
|
||||
_currentTrackSelectionFlags.set(TrackSelectionFlag::track);
|
||||
|
||||
const auto resultData = res.GetData<TrackPlaceActionResult>();
|
||||
const auto resultData = res.GetData<GameActions::TrackPlaceActionResult>();
|
||||
const auto visiblity = (resultData.GroundFlags & ELEMENT_IS_UNDERGROUND) ? ViewportVisibility::UndergroundViewOn
|
||||
: ViewportVisibility::UndergroundViewOff;
|
||||
ViewportSetVisibility(visiblity);
|
||||
@@ -5167,7 +5167,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
auto trackType = next_track.element->AsTrack()->GetTrackType();
|
||||
int32_t trackSequence = next_track.element->AsTrack()->GetSequenceIndex();
|
||||
auto trackRemoveAction = TrackRemoveAction{
|
||||
auto trackRemoveAction = GameActions::TrackRemoveAction{
|
||||
trackType, trackSequence, { next_track.x, next_track.y, z, static_cast<Direction>(direction) }
|
||||
};
|
||||
trackRemoveAction.SetFlags(
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
if (res.Error == GameActions::Status::Ok)
|
||||
{
|
||||
// Valid location found. Place the ghost at the location.
|
||||
auto tdAction = TrackDesignAction(trackLoc, *_trackDesign);
|
||||
auto tdAction = GameActions::TrackDesignAction(trackLoc, *_trackDesign);
|
||||
tdAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
|
||||
tdAction.SetCallback([&](const GameAction*, const GameActions::Result* result) {
|
||||
if (result->Error == GameActions::Status::Ok)
|
||||
@@ -282,7 +282,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
return;
|
||||
}
|
||||
|
||||
auto tdAction = TrackDesignAction({ trackLoc, _currentTrackPieceDirection }, *_trackDesign);
|
||||
auto tdAction = GameActions::TrackDesignAction({ trackLoc, _currentTrackPieceDirection }, *_trackDesign);
|
||||
tdAction.SetCallback([&](const GameAction*, const GameActions::Result* result) {
|
||||
if (result->Error != GameActions::Status::Ok)
|
||||
{
|
||||
@@ -378,7 +378,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
if (_hasPlacementGhost)
|
||||
{
|
||||
auto tdAction = TrackDesignAction({ _placementGhostLoc }, *_trackDesign);
|
||||
auto tdAction = GameActions::TrackDesignAction({ _placementGhostLoc }, *_trackDesign);
|
||||
tdAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
|
||||
auto res = GameActions::Execute(&tdAction);
|
||||
if (res.Error != GameActions::Status::Ok)
|
||||
@@ -703,7 +703,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
GameActions::Result res;
|
||||
for (int32_t i = 0; i < 7; i++, loc.z += kCoordsZStep)
|
||||
{
|
||||
auto tdAction = TrackDesignAction(
|
||||
auto tdAction = GameActions::TrackDesignAction(
|
||||
CoordsXYZD{ loc.x, loc.y, loc.z, _currentTrackPieceDirection }, *_trackDesign);
|
||||
tdAction.SetFlags(newFlags);
|
||||
res = GameActions::Query(&tdAction);
|
||||
|
||||
@@ -225,7 +225,7 @@ money64 RideDemolishAction::DemolishTracks() const
|
||||
|
||||
if (type != TrackElemType::Maze)
|
||||
{
|
||||
auto trackRemoveAction = TrackRemoveAction(type, trackElement->GetSequenceIndex(), location);
|
||||
auto trackRemoveAction = GameActions::TrackRemoveAction(type, trackElement->GetSequenceIndex(), location);
|
||||
trackRemoveAction.SetFlags(GAME_COMMAND_FLAG_NO_SPEND);
|
||||
|
||||
auto removRes = GameActions::ExecuteNested(&trackRemoveAction);
|
||||
|
||||
@@ -25,253 +25,251 @@
|
||||
#include "RideSetSettingAction.h"
|
||||
#include "RideSetVehicleAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
TrackDesignAction::TrackDesignAction(const CoordsXYZD& location, const TrackDesign& td)
|
||||
: _loc(location)
|
||||
, _td(td)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void TrackDesignAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(_loc);
|
||||
// TODO visit the track design (it has a lot of sub fields)
|
||||
}
|
||||
|
||||
uint16_t TrackDesignAction::GetActionFlags() const
|
||||
{
|
||||
return GameActionBase::GetActionFlags();
|
||||
}
|
||||
|
||||
void TrackDesignAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc);
|
||||
_td.Serialise(stream);
|
||||
}
|
||||
|
||||
GameActions::Result TrackDesignAction::Query() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
TrackDesignAction::TrackDesignAction(const CoordsXYZD& location, const TrackDesign& td)
|
||||
: _loc(location)
|
||||
, _td(td)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
auto& gameState = getGameState();
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.trackAndVehicle.vehicleObject);
|
||||
if (entryIndex == kObjectEntryIndexNull)
|
||||
void TrackDesignAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
// Force a fallback if the entry is not invented yet a track design of it is selected,
|
||||
// which can happen in select-by-track-type mode
|
||||
if (!RideEntryIsInvented(entryIndex) && !gameState.cheats.ignoreResearchStatus)
|
||||
visitor.Visit(_loc);
|
||||
// TODO visit the track design (it has a lot of sub fields)
|
||||
}
|
||||
|
||||
uint16_t TrackDesignAction::GetActionFlags() const
|
||||
{
|
||||
return GameActionBase::GetActionFlags();
|
||||
}
|
||||
|
||||
void TrackDesignAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_loc);
|
||||
_td.Serialise(stream);
|
||||
}
|
||||
|
||||
Result TrackDesignAction::Query() const
|
||||
{
|
||||
auto res = Result();
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
{
|
||||
entryIndex = kObjectEntryIndexNull;
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
}
|
||||
|
||||
// Colours do not matter as will be overwritten
|
||||
auto rideCreateAction = RideCreateAction(_td.trackAndVehicle.rtdIndex, entryIndex, 0, 0, gameState.lastEntranceStyle);
|
||||
rideCreateAction.SetFlags(GetFlags());
|
||||
auto r = GameActions::ExecuteNested(&rideCreateAction);
|
||||
if (r.Error != GameActions::Status::Ok)
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, kStringIdNone);
|
||||
}
|
||||
|
||||
const auto rideIndex = r.GetData<RideId>();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
LOG_ERROR("Ride not found for rideIndex %d", rideIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
|
||||
bool placeScenery = true;
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (GetFlags() & GAME_COMMAND_FLAG_GHOST)
|
||||
flags |= GAME_COMMAND_FLAG_GHOST;
|
||||
if (GetFlags() & GAME_COMMAND_FLAG_REPLAY)
|
||||
flags |= GAME_COMMAND_FLAG_REPLAY;
|
||||
|
||||
auto queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
if (_trackDesignPlaceStateSceneryUnavailable)
|
||||
{
|
||||
placeScenery = false;
|
||||
queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
}
|
||||
|
||||
auto gameAction = RideDemolishAction(ride->id, RideModifyType::demolish);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
|
||||
GameActions::ExecuteNested(&gameAction);
|
||||
|
||||
if (queryRes.Error != GameActions::Status::Ok)
|
||||
{
|
||||
res.Error = queryRes.Error;
|
||||
res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
res.ErrorMessage = queryRes.ErrorMessage;
|
||||
res.ErrorMessageArgs = queryRes.ErrorMessageArgs;
|
||||
return res;
|
||||
}
|
||||
|
||||
res.Cost = queryRes.Cost;
|
||||
res.SetData(RideId{ RideId::GetNull() });
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
GameActions::Result TrackDesignAction::Execute() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
auto& gameState = getGameState();
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.trackAndVehicle.vehicleObject);
|
||||
if (entryIndex != kObjectEntryIndexNull)
|
||||
{
|
||||
// Force a fallback if the entry is not invented yet a track design using it is selected.
|
||||
// This can happen on rides with multiple vehicles where some have been invented and some haven’t.
|
||||
if (!RideEntryIsInvented(entryIndex) && !gameState.cheats.ignoreResearchStatus)
|
||||
auto& gameState = getGameState();
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.trackAndVehicle.vehicleObject);
|
||||
if (entryIndex == kObjectEntryIndexNull)
|
||||
{
|
||||
entryIndex = kObjectEntryIndexNull;
|
||||
// Force a fallback if the entry is not invented yet a track design of it is selected,
|
||||
// which can happen in select-by-track-type mode
|
||||
if (!RideEntryIsInvented(entryIndex) && !gameState.cheats.ignoreResearchStatus)
|
||||
{
|
||||
entryIndex = kObjectEntryIndexNull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Colours do not matter as will be overwritten
|
||||
auto rideCreateAction = RideCreateAction(_td.trackAndVehicle.rtdIndex, entryIndex, 0, 0, gameState.lastEntranceStyle);
|
||||
rideCreateAction.SetFlags(GetFlags());
|
||||
auto r = GameActions::ExecuteNested(&rideCreateAction);
|
||||
if (r.Error != GameActions::Status::Ok)
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, kStringIdNone);
|
||||
}
|
||||
// Colours do not matter as will be overwritten
|
||||
auto rideCreateAction = RideCreateAction(_td.trackAndVehicle.rtdIndex, entryIndex, 0, 0, gameState.lastEntranceStyle);
|
||||
rideCreateAction.SetFlags(GetFlags());
|
||||
auto r = ExecuteNested(&rideCreateAction);
|
||||
if (r.Error != Status::Ok)
|
||||
{
|
||||
return Result(Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, kStringIdNone);
|
||||
}
|
||||
|
||||
const auto rideIndex = r.GetData<RideId>();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
LOG_ERROR("Ride not found for rideIndex %d", rideIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
const auto rideIndex = r.GetData<RideId>();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
LOG_ERROR("Ride not found for rideIndex %d", rideIndex);
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Query first, this is required again to determine if scenery is available.
|
||||
uint32_t flags = GetFlags() & ~GAME_COMMAND_FLAG_APPLY;
|
||||
bool placeScenery = true;
|
||||
|
||||
bool placeScenery = true;
|
||||
uint32_t flags = 0;
|
||||
if (GetFlags() & GAME_COMMAND_FLAG_GHOST)
|
||||
flags |= GAME_COMMAND_FLAG_GHOST;
|
||||
if (GetFlags() & GAME_COMMAND_FLAG_REPLAY)
|
||||
flags |= GAME_COMMAND_FLAG_REPLAY;
|
||||
|
||||
auto queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
if (_trackDesignPlaceStateSceneryUnavailable)
|
||||
{
|
||||
placeScenery = false;
|
||||
queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
}
|
||||
auto queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
if (_trackDesignPlaceStateSceneryUnavailable)
|
||||
{
|
||||
placeScenery = false;
|
||||
queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
}
|
||||
|
||||
if (queryRes.Error != GameActions::Status::Ok)
|
||||
{
|
||||
auto gameAction = RideDemolishAction(ride->id, RideModifyType::demolish);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
GameActions::ExecuteNested(&gameAction);
|
||||
|
||||
res.Error = queryRes.Error;
|
||||
res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
res.ErrorMessage = queryRes.ErrorMessage;
|
||||
res.ErrorMessageArgs = queryRes.ErrorMessageArgs;
|
||||
ExecuteNested(&gameAction);
|
||||
|
||||
if (queryRes.Error != Status::Ok)
|
||||
{
|
||||
res.Error = queryRes.Error;
|
||||
res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
res.ErrorMessage = queryRes.ErrorMessage;
|
||||
res.ErrorMessageArgs = queryRes.ErrorMessageArgs;
|
||||
return res;
|
||||
}
|
||||
|
||||
res.Cost = queryRes.Cost;
|
||||
res.SetData(RideId{ RideId::GetNull() });
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// Execute.
|
||||
flags |= GAME_COMMAND_FLAG_APPLY;
|
||||
|
||||
auto execRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
if (execRes.Error != GameActions::Status::Ok)
|
||||
Result TrackDesignAction::Execute() const
|
||||
{
|
||||
auto gameAction = RideDemolishAction(ride->id, RideModifyType::demolish);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
GameActions::ExecuteNested(&gameAction);
|
||||
auto res = Result();
|
||||
res.Position.x = _loc.x + 16;
|
||||
res.Position.y = _loc.y + 16;
|
||||
res.Position.z = _loc.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
res.Error = execRes.Error;
|
||||
res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
res.ErrorMessage = execRes.ErrorMessage;
|
||||
res.ErrorMessageArgs = execRes.ErrorMessageArgs;
|
||||
auto& gameState = getGameState();
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.trackAndVehicle.vehicleObject);
|
||||
if (entryIndex != kObjectEntryIndexNull)
|
||||
{
|
||||
// Force a fallback if the entry is not invented yet a track design using it is selected.
|
||||
// This can happen on rides with multiple vehicles where some have been invented and some haven’t.
|
||||
if (!RideEntryIsInvented(entryIndex) && !gameState.cheats.ignoreResearchStatus)
|
||||
{
|
||||
entryIndex = kObjectEntryIndexNull;
|
||||
}
|
||||
}
|
||||
|
||||
// Colours do not matter as will be overwritten
|
||||
auto rideCreateAction = RideCreateAction(_td.trackAndVehicle.rtdIndex, entryIndex, 0, 0, gameState.lastEntranceStyle);
|
||||
rideCreateAction.SetFlags(GetFlags());
|
||||
auto r = ExecuteNested(&rideCreateAction);
|
||||
if (r.Error != Status::Ok)
|
||||
{
|
||||
return Result(Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, kStringIdNone);
|
||||
}
|
||||
|
||||
const auto rideIndex = r.GetData<RideId>();
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
LOG_ERROR("Ride not found for rideIndex %d", rideIndex);
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Query first, this is required again to determine if scenery is available.
|
||||
uint32_t flags = GetFlags() & ~GAME_COMMAND_FLAG_APPLY;
|
||||
|
||||
bool placeScenery = true;
|
||||
|
||||
auto queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
if (_trackDesignPlaceStateSceneryUnavailable)
|
||||
{
|
||||
placeScenery = false;
|
||||
queryRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
}
|
||||
|
||||
if (queryRes.Error != Status::Ok)
|
||||
{
|
||||
auto gameAction = RideDemolishAction(ride->id, RideModifyType::demolish);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
ExecuteNested(&gameAction);
|
||||
|
||||
res.Error = queryRes.Error;
|
||||
res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
res.ErrorMessage = queryRes.ErrorMessage;
|
||||
res.ErrorMessageArgs = queryRes.ErrorMessageArgs;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// Execute.
|
||||
flags |= GAME_COMMAND_FLAG_APPLY;
|
||||
|
||||
auto execRes = TrackDesignPlace(_td, flags, placeScenery, *ride, _loc);
|
||||
if (execRes.Error != Status::Ok)
|
||||
{
|
||||
auto gameAction = RideDemolishAction(ride->id, RideModifyType::demolish);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
ExecuteNested(&gameAction);
|
||||
|
||||
res.Error = execRes.Error;
|
||||
res.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
res.ErrorMessage = execRes.ErrorMessage;
|
||||
res.ErrorMessageArgs = execRes.ErrorMessageArgs;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
if (entryIndex != kObjectEntryIndexNull)
|
||||
{
|
||||
auto colour = RideGetUnusedPresetVehicleColour(entryIndex);
|
||||
auto rideSetVehicleAction = RideSetVehicleAction(ride->id, RideSetVehicleType::RideEntry, entryIndex, colour);
|
||||
ExecuteNested(&rideSetVehicleAction);
|
||||
}
|
||||
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::Mode, static_cast<uint8_t>(_td.operation.rideMode), flags);
|
||||
auto rideSetVehicleAction2 = RideSetVehicleAction(
|
||||
ride->id, RideSetVehicleType::NumTrains, _td.trackAndVehicle.numberOfTrains);
|
||||
ExecuteNested(&rideSetVehicleAction2);
|
||||
|
||||
auto rideSetVehicleAction3 = RideSetVehicleAction(
|
||||
ride->id, RideSetVehicleType::NumCarsPerTrain, _td.trackAndVehicle.numberOfCarsPerTrain);
|
||||
ExecuteNested(&rideSetVehicleAction3);
|
||||
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::Departure, _td.operation.departFlags, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::MinWaitingTime, _td.operation.minWaitingTime, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::MaxWaitingTime, _td.operation.maxWaitingTime, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::Operation, _td.operation.operationSetting, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::LiftHillSpeed, _td.operation.liftHillSpeed, flags);
|
||||
|
||||
auto numCircuits = std::max<uint8_t>(1, _td.operation.numCircuits);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::NumCircuits, numCircuits, flags);
|
||||
|
||||
uint8_t defaultInspectionInterval = Config::Get().general.DefaultInspectionInterval;
|
||||
if (defaultInspectionInterval <= RIDE_INSPECTION_NEVER)
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::InspectionInterval, defaultInspectionInterval, flags);
|
||||
|
||||
ride->lifecycleFlags |= RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN;
|
||||
ride->vehicleColourSettings = _td.appearance.vehicleColourSettings;
|
||||
|
||||
ride->entranceStyle = objManager.GetLoadedObjectEntryIndex(_td.appearance.stationObjectIdentifier);
|
||||
if (ride->entranceStyle == kObjectEntryIndexNull)
|
||||
{
|
||||
ride->entranceStyle = gameState.lastEntranceStyle;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < std::min(std::size(ride->trackColours), std::size(_td.appearance.trackColours)); i++)
|
||||
{
|
||||
ride->trackColours[i] = _td.appearance.trackColours[i];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < Limits::kMaxVehicleColours; i++)
|
||||
{
|
||||
ride->vehicleColours[i] = _td.appearance.vehicleColours[i];
|
||||
}
|
||||
|
||||
for (int32_t count = 1; count == 1 || r.Error != Status::Ok; ++count)
|
||||
{
|
||||
auto name = count == 1 ? _td.gameStateData.name : (_td.gameStateData.name + " " + std::to_string(count));
|
||||
auto gameAction = RideSetNameAction(ride->id, name);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
r = ExecuteNested(&gameAction);
|
||||
}
|
||||
res.Cost = execRes.Cost;
|
||||
res.SetData(RideId{ ride->id });
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
if (entryIndex != kObjectEntryIndexNull)
|
||||
{
|
||||
auto colour = RideGetUnusedPresetVehicleColour(entryIndex);
|
||||
auto rideSetVehicleAction = RideSetVehicleAction(ride->id, RideSetVehicleType::RideEntry, entryIndex, colour);
|
||||
GameActions::ExecuteNested(&rideSetVehicleAction);
|
||||
}
|
||||
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::Mode, static_cast<uint8_t>(_td.operation.rideMode), flags);
|
||||
auto rideSetVehicleAction2 = RideSetVehicleAction(
|
||||
ride->id, RideSetVehicleType::NumTrains, _td.trackAndVehicle.numberOfTrains);
|
||||
GameActions::ExecuteNested(&rideSetVehicleAction2);
|
||||
|
||||
auto rideSetVehicleAction3 = RideSetVehicleAction(
|
||||
ride->id, RideSetVehicleType::NumCarsPerTrain, _td.trackAndVehicle.numberOfCarsPerTrain);
|
||||
GameActions::ExecuteNested(&rideSetVehicleAction3);
|
||||
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::Departure, _td.operation.departFlags, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::MinWaitingTime, _td.operation.minWaitingTime, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::MaxWaitingTime, _td.operation.maxWaitingTime, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::Operation, _td.operation.operationSetting, flags);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::LiftHillSpeed, _td.operation.liftHillSpeed, flags);
|
||||
|
||||
auto numCircuits = std::max<uint8_t>(1, _td.operation.numCircuits);
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::NumCircuits, numCircuits, flags);
|
||||
|
||||
uint8_t defaultInspectionInterval = Config::Get().general.DefaultInspectionInterval;
|
||||
if (defaultInspectionInterval <= RIDE_INSPECTION_NEVER)
|
||||
SetOperatingSettingNested(ride->id, RideSetSetting::InspectionInterval, defaultInspectionInterval, flags);
|
||||
|
||||
ride->lifecycleFlags |= RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN;
|
||||
ride->vehicleColourSettings = _td.appearance.vehicleColourSettings;
|
||||
|
||||
ride->entranceStyle = objManager.GetLoadedObjectEntryIndex(_td.appearance.stationObjectIdentifier);
|
||||
if (ride->entranceStyle == kObjectEntryIndexNull)
|
||||
{
|
||||
ride->entranceStyle = gameState.lastEntranceStyle;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < std::min(std::size(ride->trackColours), std::size(_td.appearance.trackColours)); i++)
|
||||
{
|
||||
ride->trackColours[i] = _td.appearance.trackColours[i];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < Limits::kMaxVehicleColours; i++)
|
||||
{
|
||||
ride->vehicleColours[i] = _td.appearance.vehicleColours[i];
|
||||
}
|
||||
|
||||
for (int32_t count = 1; count == 1 || r.Error != GameActions::Status::Ok; ++count)
|
||||
{
|
||||
auto name = count == 1 ? _td.gameStateData.name : (_td.gameStateData.name + " " + std::to_string(count));
|
||||
auto gameAction = RideSetNameAction(ride->id, name);
|
||||
gameAction.SetFlags(GetFlags());
|
||||
r = GameActions::ExecuteNested(&gameAction);
|
||||
}
|
||||
res.Cost = execRes.Cost;
|
||||
res.SetData(RideId{ ride->id });
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -12,22 +12,25 @@
|
||||
#include "../ride/TrackDesign.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
class TrackDesignAction final : public GameActionBase<GameCommand::PlaceTrackDesign>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
TrackDesign _td;
|
||||
class TrackDesignAction final : public GameActionBase<GameCommand::PlaceTrackDesign>
|
||||
{
|
||||
private:
|
||||
CoordsXYZD _loc;
|
||||
TrackDesign _td;
|
||||
|
||||
public:
|
||||
TrackDesignAction() = default;
|
||||
TrackDesignAction(const CoordsXYZD& location, const TrackDesign& td);
|
||||
public:
|
||||
TrackDesignAction() = default;
|
||||
TrackDesignAction(const CoordsXYZD& location, const TrackDesign& td);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
};
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,40 +12,41 @@
|
||||
#include "../ride/RideConstruction.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
struct TrackPlaceActionResult
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
uint8_t GroundFlags{ 0 };
|
||||
};
|
||||
struct TrackPlaceActionResult
|
||||
{
|
||||
uint8_t GroundFlags{ 0 };
|
||||
};
|
||||
|
||||
class TrackPlaceAction final : public GameActionBase<GameCommand::PlaceTrack>
|
||||
{
|
||||
private:
|
||||
RideId _rideIndex{ RideId::GetNull() };
|
||||
OpenRCT2::TrackElemType _trackType{};
|
||||
ride_type_t _rideType{};
|
||||
CoordsXYZD _origin;
|
||||
int32_t _brakeSpeed{};
|
||||
int32_t _colour{};
|
||||
int32_t _seatRotation{};
|
||||
SelectedLiftAndInverted _trackPlaceFlags{};
|
||||
bool _fromTrackDesign{};
|
||||
class TrackPlaceAction final : public GameActionBase<GameCommand::PlaceTrack>
|
||||
{
|
||||
private:
|
||||
RideId _rideIndex{ RideId::GetNull() };
|
||||
TrackElemType _trackType{};
|
||||
ride_type_t _rideType{};
|
||||
CoordsXYZD _origin;
|
||||
int32_t _brakeSpeed{};
|
||||
int32_t _colour{};
|
||||
int32_t _seatRotation{};
|
||||
SelectedLiftAndInverted _trackPlaceFlags{};
|
||||
bool _fromTrackDesign{};
|
||||
|
||||
public:
|
||||
TrackPlaceAction() = default;
|
||||
TrackPlaceAction(
|
||||
RideId rideIndex, OpenRCT2::TrackElemType trackType, ride_type_t rideType, const CoordsXYZD& origin, int32_t brakeSpeed,
|
||||
int32_t colour, int32_t seatRotation, SelectedLiftAndInverted liftHillAndAlternativeState, bool fromTrackDesign);
|
||||
public:
|
||||
TrackPlaceAction() = default;
|
||||
TrackPlaceAction(
|
||||
RideId rideIndex, TrackElemType trackType, ride_type_t rideType, const CoordsXYZD& origin, int32_t brakeSpeed,
|
||||
int32_t colour, int32_t seatRotation, SelectedLiftAndInverted liftHillAndAlternativeState, bool fromTrackDesign);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override final;
|
||||
uint16_t GetActionFlags() const override final;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
GameActions::Result Query() const override;
|
||||
GameActions::Result Execute() const override;
|
||||
|
||||
private:
|
||||
bool CheckMapCapacity(int16_t numTiles) const;
|
||||
};
|
||||
private:
|
||||
bool CheckMapCapacity(int16_t numTiles) const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -21,186 +21,88 @@
|
||||
#include "../world/tile_element/TrackElement.h"
|
||||
#include "RideSetSettingAction.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::TrackMetaData;
|
||||
|
||||
TrackRemoveAction::TrackRemoveAction(OpenRCT2::TrackElemType trackType, int32_t sequence, const CoordsXYZD& origin)
|
||||
: _trackType(trackType)
|
||||
, _sequence(sequence)
|
||||
, _origin(origin)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
_origin.direction &= 3;
|
||||
}
|
||||
using namespace OpenRCT2::TrackMetaData;
|
||||
|
||||
void TrackRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(_origin);
|
||||
visitor.Visit("trackType", _trackType);
|
||||
visitor.Visit("sequence", _sequence);
|
||||
}
|
||||
|
||||
uint16_t TrackRemoveAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags();
|
||||
}
|
||||
|
||||
static OpenRCT2::TrackElemType normaliseTrackType(OpenRCT2::TrackElemType trackType)
|
||||
{
|
||||
switch (trackType)
|
||||
TrackRemoveAction::TrackRemoveAction(TrackElemType trackType, int32_t sequence, const CoordsXYZD& origin)
|
||||
: _trackType(trackType)
|
||||
, _sequence(sequence)
|
||||
, _origin(origin)
|
||||
{
|
||||
case TrackElemType::BeginStation:
|
||||
case TrackElemType::MiddleStation:
|
||||
return TrackElemType::EndStation;
|
||||
default:
|
||||
return trackType;
|
||||
}
|
||||
}
|
||||
|
||||
void TrackRemoveAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_trackType) << DS_TAG(_sequence) << DS_TAG(_origin);
|
||||
}
|
||||
|
||||
GameActions::Result TrackRemoveAction::Query() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Position.x = _origin.x + 16;
|
||||
res.Position.y = _origin.y + 16;
|
||||
res.Position.z = _origin.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
auto comparableTrackType = normaliseTrackType(_trackType);
|
||||
|
||||
bool found = false;
|
||||
bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
TileElement* tileElement = MapGetFirstElementAt(_origin);
|
||||
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetBaseZ() != _origin.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Track)
|
||||
continue;
|
||||
|
||||
if ((tileElement->GetDirection()) != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != _sequence)
|
||||
continue;
|
||||
|
||||
if (tileElement->IsGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
auto tileTrackType = normaliseTrackType(tileElement->AsTrack()->GetTrackType());
|
||||
|
||||
if (tileTrackType != comparableTrackType)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
|
||||
if (!found)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", _origin.x, _origin.y, _origin.z,
|
||||
_origin.direction, _sequence);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
_origin.direction &= 3;
|
||||
}
|
||||
|
||||
if (tileElement->AsTrack()->IsIndestructible())
|
||||
void TrackRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS,
|
||||
STR_YOU_ARE_NOT_ALLOWED_TO_REMOVE_THIS_SECTION);
|
||||
visitor.Visit(_origin);
|
||||
visitor.Visit("trackType", _trackType);
|
||||
visitor.Visit("sequence", _sequence);
|
||||
}
|
||||
|
||||
RideId rideIndex = tileElement->AsTrack()->GetRideIndex();
|
||||
const auto trackType = tileElement->AsTrack()->GetTrackType();
|
||||
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
uint16_t TrackRemoveAction::GetActionFlags() const
|
||||
{
|
||||
LOG_ERROR("Ride not found for rideIndex %d.", rideIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_RIDE_NOT_FOUND);
|
||||
return GameAction::GetActionFlags();
|
||||
}
|
||||
|
||||
if (ride->type >= RIDE_TYPE_COUNT)
|
||||
static TrackElemType normaliseTrackType(TrackElemType trackType)
|
||||
{
|
||||
LOG_ERROR("Ride type not found. ride type = %d.", ride->type);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
auto sequenceIndex = tileElement->AsTrack()->GetSequenceIndex();
|
||||
if (sequenceIndex >= ted.numSequences)
|
||||
{
|
||||
LOG_ERROR("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_BLOCK_NOT_FOUND);
|
||||
}
|
||||
const auto& currentTrackBlock = ted.sequences[sequenceIndex].clearance;
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ currentTrackBlock.x, currentTrackBlock.y }.Rotate(startLoc.direction),
|
||||
currentTrackBlock.z };
|
||||
startLoc.x -= rotatedTrack.x;
|
||||
startLoc.y -= rotatedTrack.y;
|
||||
startLoc.z -= rotatedTrack.z;
|
||||
res.Position.x = startLoc.x;
|
||||
res.Position.y = startLoc.y;
|
||||
res.Position.z = startLoc.z;
|
||||
|
||||
money64 supportCosts = 0;
|
||||
|
||||
for (uint8_t i = 0; i < ted.numSequences; i++)
|
||||
{
|
||||
const auto& trackBlock = ted.sequences[i].clearance;
|
||||
rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock.x, trackBlock.y }.Rotate(startLoc.direction), trackBlock.z };
|
||||
auto mapLoc = CoordsXYZ{ startLoc.x, startLoc.y, startLoc.z } + rotatedTrack;
|
||||
|
||||
if (!LocationValid(mapLoc))
|
||||
switch (trackType)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
case TrackElemType::BeginStation:
|
||||
case TrackElemType::MiddleStation:
|
||||
return TrackElemType::EndStation;
|
||||
default:
|
||||
return trackType;
|
||||
}
|
||||
MapInvalidateTileFull(mapLoc);
|
||||
}
|
||||
|
||||
void TrackRemoveAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_trackType) << DS_TAG(_sequence) << DS_TAG(_origin);
|
||||
}
|
||||
|
||||
Result TrackRemoveAction::Query() const
|
||||
{
|
||||
auto res = Result();
|
||||
res.Position.x = _origin.x + 16;
|
||||
res.Position.y = _origin.y + 16;
|
||||
res.Position.z = _origin.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
auto comparableTrackType = normaliseTrackType(_trackType);
|
||||
|
||||
bool found = false;
|
||||
bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
TileElement* tileElement = MapGetFirstElementAt(_origin);
|
||||
|
||||
found = false;
|
||||
tileElement = MapGetFirstElementAt(mapLoc);
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetBaseZ() != mapLoc.z)
|
||||
if (tileElement->GetBaseZ() != _origin.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Track)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetDirection() != _origin.direction)
|
||||
if ((tileElement->GetDirection()) != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != i)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetTrackType() != trackType)
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != _sequence)
|
||||
continue;
|
||||
|
||||
if (tileElement->IsGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
auto tileTrackType = normaliseTrackType(tileElement->AsTrack()->GetTrackType());
|
||||
|
||||
if (tileTrackType != comparableTrackType)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
@@ -208,175 +110,183 @@ GameActions::Result TrackRemoveAction::Query() const
|
||||
if (!found)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", mapLoc.x, mapLoc.y, mapLoc.z,
|
||||
_origin.direction, i);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", _origin.x, _origin.y, _origin.z,
|
||||
_origin.direction, _sequence);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int32_t entranceDirections = ted.sequences[0].flags;
|
||||
if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0))
|
||||
if (tileElement->AsTrack()->IsIndestructible())
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement({ mapLoc, _origin.direction }, rideIndex, 0);
|
||||
if (!removeElementResult.Successful)
|
||||
return Result(
|
||||
Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_YOU_ARE_NOT_ALLOWED_TO_REMOVE_THIS_SECTION);
|
||||
}
|
||||
|
||||
RideId rideIndex = tileElement->AsTrack()->GetRideIndex();
|
||||
const auto trackType = tileElement->AsTrack()->GetTrackType();
|
||||
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
LOG_ERROR("Ride not found for rideIndex %d.", rideIndex);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (ride->type >= RIDE_TYPE_COUNT)
|
||||
{
|
||||
LOG_ERROR("Ride type not found. ride type = %d.", ride->type);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_VALUE_OUT_OF_RANGE);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
auto sequenceIndex = tileElement->AsTrack()->GetSequenceIndex();
|
||||
if (sequenceIndex >= ted.numSequences)
|
||||
{
|
||||
LOG_ERROR("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_BLOCK_NOT_FOUND);
|
||||
}
|
||||
const auto& currentTrackBlock = ted.sequences[sequenceIndex].clearance;
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
auto rotatedTrack = CoordsXYZ{ CoordsXY{ currentTrackBlock.x, currentTrackBlock.y }.Rotate(startLoc.direction),
|
||||
currentTrackBlock.z };
|
||||
startLoc.x -= rotatedTrack.x;
|
||||
startLoc.y -= rotatedTrack.y;
|
||||
startLoc.z -= rotatedTrack.z;
|
||||
res.Position.x = startLoc.x;
|
||||
res.Position.y = startLoc.y;
|
||||
res.Position.z = startLoc.z;
|
||||
|
||||
money64 supportCosts = 0;
|
||||
|
||||
for (uint8_t i = 0; i < ted.numSequences; i++)
|
||||
{
|
||||
const auto& trackBlock = ted.sequences[i].clearance;
|
||||
rotatedTrack = CoordsXYZ{ CoordsXY{ trackBlock.x, trackBlock.y }.Rotate(startLoc.direction), trackBlock.z };
|
||||
auto mapLoc = CoordsXYZ{ startLoc.x, startLoc.y, startLoc.z } + rotatedTrack;
|
||||
|
||||
if (!LocationValid(mapLoc))
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, removeElementResult.Message);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
MapInvalidateTileFull(mapLoc);
|
||||
|
||||
found = false;
|
||||
tileElement = MapGetFirstElementAt(mapLoc);
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetBaseZ() != mapLoc.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Track)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetDirection() != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != i)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetTrackType() != trackType)
|
||||
continue;
|
||||
|
||||
if (tileElement->IsGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
|
||||
if (!found)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", mapLoc.x, mapLoc.y, mapLoc.z,
|
||||
_origin.direction, i);
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int32_t entranceDirections = ted.sequences[0].flags;
|
||||
if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement({ mapLoc, _origin.direction }, rideIndex, 0);
|
||||
if (!removeElementResult.Successful)
|
||||
{
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, removeElementResult.Message);
|
||||
}
|
||||
}
|
||||
|
||||
auto* surfaceElement = MapGetSurfaceElementAt(mapLoc);
|
||||
if (surfaceElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Surface Element not found. x = %d, y = %d", mapLoc.x, mapLoc.y);
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int16_t _support_height = tileElement->BaseHeight - surfaceElement->BaseHeight;
|
||||
if (_support_height < 0)
|
||||
{
|
||||
_support_height = 10;
|
||||
}
|
||||
|
||||
supportCosts += (_support_height / 2) * ride->getRideTypeDescriptor().BuildCosts.SupportPrice;
|
||||
}
|
||||
|
||||
auto* surfaceElement = MapGetSurfaceElementAt(mapLoc);
|
||||
if (surfaceElement == nullptr)
|
||||
money64 price = ride->getRideTypeDescriptor().BuildCosts.TrackPrice;
|
||||
price *= ted.priceModifier;
|
||||
price >>= 16;
|
||||
price = supportCosts + price;
|
||||
if (ride->lifecycleFlags & RIDE_LIFECYCLE_EVER_BEEN_OPENED)
|
||||
{
|
||||
LOG_ERROR("Surface Element not found. x = %d, y = %d", mapLoc.x, mapLoc.y);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
|
||||
// 70% modifier for opened rides
|
||||
price = (price * 45875) / 65536;
|
||||
}
|
||||
|
||||
int16_t _support_height = tileElement->BaseHeight - surfaceElement->BaseHeight;
|
||||
if (_support_height < 0)
|
||||
{
|
||||
_support_height = 10;
|
||||
}
|
||||
|
||||
supportCosts += (_support_height / 2) * ride->getRideTypeDescriptor().BuildCosts.SupportPrice;
|
||||
res.Cost = -price;
|
||||
return res;
|
||||
}
|
||||
|
||||
money64 price = ride->getRideTypeDescriptor().BuildCosts.TrackPrice;
|
||||
price *= ted.priceModifier;
|
||||
price >>= 16;
|
||||
price = supportCosts + price;
|
||||
if (ride->lifecycleFlags & RIDE_LIFECYCLE_EVER_BEEN_OPENED)
|
||||
Result TrackRemoveAction::Execute() const
|
||||
{
|
||||
// 70% modifier for opened rides
|
||||
price = (price * 45875) / 65536;
|
||||
}
|
||||
auto res = Result();
|
||||
res.Position.x = _origin.x + 16;
|
||||
res.Position.y = _origin.y + 16;
|
||||
res.Position.z = _origin.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
res.Cost = -price;
|
||||
return res;
|
||||
}
|
||||
auto comparableTrackType = normaliseTrackType(_trackType);
|
||||
|
||||
GameActions::Result TrackRemoveAction::Execute() const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
res.Position.x = _origin.x + 16;
|
||||
res.Position.y = _origin.y + 16;
|
||||
res.Position.z = _origin.z;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
bool found = false;
|
||||
bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
TileElement* tileElement = MapGetFirstElementAt(_origin);
|
||||
|
||||
auto comparableTrackType = normaliseTrackType(_trackType);
|
||||
|
||||
bool found = false;
|
||||
bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
|
||||
TileElement* tileElement = MapGetFirstElementAt(_origin);
|
||||
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetBaseZ() != _origin.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Track)
|
||||
continue;
|
||||
|
||||
if ((tileElement->GetDirection()) != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != _sequence)
|
||||
continue;
|
||||
|
||||
if (tileElement->IsGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
auto tileTrackType = normaliseTrackType(tileElement->AsTrack()->GetTrackType());
|
||||
|
||||
if (tileTrackType != comparableTrackType)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
|
||||
if (!found)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", _origin.x, _origin.y, _origin.z,
|
||||
_origin.direction, _sequence);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
RideId rideIndex = tileElement->AsTrack()->GetRideIndex();
|
||||
const auto trackType = tileElement->AsTrack()->GetTrackType();
|
||||
bool isLiftHill = tileElement->AsTrack()->HasChain();
|
||||
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
LOG_ERROR("Ride not found. ride index = %d.", rideIndex);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
auto sequenceIndex = tileElement->AsTrack()->GetSequenceIndex();
|
||||
if (sequenceIndex >= ted.numSequences)
|
||||
{
|
||||
LOG_ERROR("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_BLOCK_NOT_FOUND);
|
||||
}
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
const auto& currentTrackBlock = ted.sequences[sequenceIndex].clearance;
|
||||
auto rotatedTrackLoc = CoordsXYZ{ CoordsXY{ currentTrackBlock.x, currentTrackBlock.y }.Rotate(startLoc.direction),
|
||||
currentTrackBlock.z };
|
||||
startLoc.x -= rotatedTrackLoc.x;
|
||||
startLoc.y -= rotatedTrackLoc.y;
|
||||
startLoc.z -= rotatedTrackLoc.z;
|
||||
res.Position.x = startLoc.x;
|
||||
res.Position.y = startLoc.y;
|
||||
res.Position.z = startLoc.z;
|
||||
|
||||
money64 supportCosts = 0;
|
||||
|
||||
for (uint8_t i = 0; i < ted.numSequences; i++)
|
||||
{
|
||||
const auto& trackBlock = ted.sequences[i].clearance;
|
||||
|
||||
rotatedTrackLoc = CoordsXYZ{ CoordsXY{ trackBlock.x, trackBlock.y }.Rotate(startLoc.direction), trackBlock.z };
|
||||
auto mapLoc = CoordsXYZ{ startLoc.x, startLoc.y, startLoc.z } + rotatedTrackLoc;
|
||||
|
||||
MapInvalidateTileFull(mapLoc);
|
||||
|
||||
found = false;
|
||||
tileElement = MapGetFirstElementAt(mapLoc);
|
||||
do
|
||||
{
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetBaseZ() != mapLoc.z)
|
||||
if (tileElement->GetBaseZ() != _origin.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Track)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetDirection() != _origin.direction)
|
||||
if ((tileElement->GetDirection()) != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != i)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetTrackType() != trackType)
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != _sequence)
|
||||
continue;
|
||||
|
||||
if (tileElement->IsGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
auto tileTrackType = normaliseTrackType(tileElement->AsTrack()->GetTrackType());
|
||||
|
||||
if (tileTrackType != comparableTrackType)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
@@ -384,131 +294,208 @@ GameActions::Result TrackRemoveAction::Execute() const
|
||||
if (!found)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", mapLoc.x, mapLoc.y, mapLoc.z,
|
||||
_origin.direction, i);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", _origin.x, _origin.y, _origin.z,
|
||||
_origin.direction, _sequence);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int32_t entranceDirections = ted.sequences[0].flags;
|
||||
if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0))
|
||||
RideId rideIndex = tileElement->AsTrack()->GetRideIndex();
|
||||
const auto trackType = tileElement->AsTrack()->GetTrackType();
|
||||
bool isLiftHill = tileElement->AsTrack()->HasChain();
|
||||
|
||||
auto ride = GetRide(rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement({ mapLoc, _origin.direction }, rideIndex, 0);
|
||||
if (!removeElementResult.Successful)
|
||||
LOG_ERROR("Ride not found. ride index = %d.", rideIndex);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_RIDE_NOT_FOUND);
|
||||
}
|
||||
const auto& ted = GetTrackElementDescriptor(trackType);
|
||||
auto sequenceIndex = tileElement->AsTrack()->GetSequenceIndex();
|
||||
if (sequenceIndex >= ted.numSequences)
|
||||
{
|
||||
LOG_ERROR("Track block %d not found for track type %d.", sequenceIndex, trackType);
|
||||
return Result(Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_BLOCK_NOT_FOUND);
|
||||
}
|
||||
|
||||
auto startLoc = _origin;
|
||||
startLoc.direction = tileElement->GetDirection();
|
||||
|
||||
const auto& currentTrackBlock = ted.sequences[sequenceIndex].clearance;
|
||||
auto rotatedTrackLoc = CoordsXYZ{ CoordsXY{ currentTrackBlock.x, currentTrackBlock.y }.Rotate(startLoc.direction),
|
||||
currentTrackBlock.z };
|
||||
startLoc.x -= rotatedTrackLoc.x;
|
||||
startLoc.y -= rotatedTrackLoc.y;
|
||||
startLoc.z -= rotatedTrackLoc.z;
|
||||
res.Position.x = startLoc.x;
|
||||
res.Position.y = startLoc.y;
|
||||
res.Position.z = startLoc.z;
|
||||
|
||||
money64 supportCosts = 0;
|
||||
|
||||
for (uint8_t i = 0; i < ted.numSequences; i++)
|
||||
{
|
||||
const auto& trackBlock = ted.sequences[i].clearance;
|
||||
|
||||
rotatedTrackLoc = CoordsXYZ{ CoordsXY{ trackBlock.x, trackBlock.y }.Rotate(startLoc.direction), trackBlock.z };
|
||||
auto mapLoc = CoordsXYZ{ startLoc.x, startLoc.y, startLoc.z } + rotatedTrackLoc;
|
||||
|
||||
MapInvalidateTileFull(mapLoc);
|
||||
|
||||
found = false;
|
||||
tileElement = MapGetFirstElementAt(mapLoc);
|
||||
do
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, removeElementResult.Message);
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
||||
if (tileElement->GetBaseZ() != mapLoc.z)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetType() != TileElementType::Track)
|
||||
continue;
|
||||
|
||||
if (tileElement->GetDirection() != _origin.direction)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetSequenceIndex() != i)
|
||||
continue;
|
||||
|
||||
if (tileElement->AsTrack()->GetTrackType() != trackType)
|
||||
continue;
|
||||
|
||||
if (tileElement->IsGhost() != isGhost)
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
break;
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
|
||||
if (!found)
|
||||
{
|
||||
LOG_ERROR(
|
||||
"Track Element not found. x = %d, y = %d, z = %d, d = %d, seq = %d.", mapLoc.x, mapLoc.y, mapLoc.z,
|
||||
_origin.direction, i);
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_TRACK_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int32_t entranceDirections = ted.sequences[0].flags;
|
||||
if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN && (tileElement->AsTrack()->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement({ mapLoc, _origin.direction }, rideIndex, 0);
|
||||
if (!removeElementResult.Successful)
|
||||
{
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, removeElementResult.Message);
|
||||
}
|
||||
}
|
||||
|
||||
auto* surfaceElement = MapGetSurfaceElementAt(mapLoc);
|
||||
if (surfaceElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Surface Element not found. x = %d, y = %d", mapLoc.x, mapLoc.y);
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int16_t _support_height = tileElement->BaseHeight - surfaceElement->BaseHeight;
|
||||
if (_support_height < 0)
|
||||
{
|
||||
_support_height = 10;
|
||||
}
|
||||
|
||||
supportCosts += (_support_height / 2) * ride->getRideTypeDescriptor().BuildCosts.SupportPrice;
|
||||
|
||||
// If the removed tile is a station modify station properties.
|
||||
// Don't do this if the ride is simulating and the tile is a ghost to prevent desyncs.
|
||||
if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN
|
||||
&& (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) || (GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN))
|
||||
&& (tileElement->AsTrack()->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement(
|
||||
{ mapLoc, _origin.direction }, rideIndex, GAME_COMMAND_FLAG_APPLY);
|
||||
if (!removeElementResult.Successful)
|
||||
{
|
||||
return Result(Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, removeElementResult.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (ride->getRideTypeDescriptor().HasFlag(RtdFlag::trackMustBeOnWater))
|
||||
{
|
||||
surfaceElement->SetHasTrackThatNeedsWater(false);
|
||||
}
|
||||
|
||||
InvalidateTestResults(*ride);
|
||||
FootpathQueueChainReset();
|
||||
if (!getGameState().cheats.disableClearanceChecks || !(tileElement->IsGhost()))
|
||||
{
|
||||
FootpathRemoveEdgesAt(mapLoc, tileElement);
|
||||
}
|
||||
TileElementRemove(tileElement);
|
||||
ride->validateStations();
|
||||
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
{
|
||||
ride->updateMaxVehicles();
|
||||
}
|
||||
}
|
||||
|
||||
auto* surfaceElement = MapGetSurfaceElementAt(mapLoc);
|
||||
if (surfaceElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Surface Element not found. x = %d, y = %d", mapLoc.x, mapLoc.y);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
int16_t _support_height = tileElement->BaseHeight - surfaceElement->BaseHeight;
|
||||
if (_support_height < 0)
|
||||
{
|
||||
_support_height = 10;
|
||||
}
|
||||
|
||||
supportCosts += (_support_height / 2) * ride->getRideTypeDescriptor().BuildCosts.SupportPrice;
|
||||
|
||||
// If the removed tile is a station modify station properties.
|
||||
// Don't do this if the ride is simulating and the tile is a ghost to prevent desyncs.
|
||||
if (entranceDirections & TRACK_SEQUENCE_FLAG_ORIGIN
|
||||
&& (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) || (GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN))
|
||||
&& (tileElement->AsTrack()->GetSequenceIndex() == 0))
|
||||
{
|
||||
const auto removeElementResult = TrackRemoveStationElement(
|
||||
{ mapLoc, _origin.direction }, rideIndex, GAME_COMMAND_FLAG_APPLY);
|
||||
if (!removeElementResult.Successful)
|
||||
{
|
||||
return GameActions::Result(
|
||||
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_REMOVE_THIS, removeElementResult.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (ride->getRideTypeDescriptor().HasFlag(RtdFlag::trackMustBeOnWater))
|
||||
{
|
||||
surfaceElement->SetHasTrackThatNeedsWater(false);
|
||||
}
|
||||
|
||||
InvalidateTestResults(*ride);
|
||||
FootpathQueueChainReset();
|
||||
if (!getGameState().cheats.disableClearanceChecks || !(tileElement->IsGhost()))
|
||||
{
|
||||
FootpathRemoveEdgesAt(mapLoc, tileElement);
|
||||
}
|
||||
TileElementRemove(tileElement);
|
||||
ride->validateStations();
|
||||
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
{
|
||||
ride->updateMaxVehicles();
|
||||
}
|
||||
}
|
||||
|
||||
if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST))
|
||||
{
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackElemType::OnRidePhoto:
|
||||
ride->lifecycleFlags &= ~RIDE_LIFECYCLE_ON_RIDE_PHOTO;
|
||||
break;
|
||||
case TrackElemType::CableLiftHill:
|
||||
ride->lifecycleFlags &= ~RIDE_LIFECYCLE_CABLE_LIFT_HILL_COMPONENT_USED;
|
||||
break;
|
||||
case TrackElemType::BlockBrakes:
|
||||
case TrackElemType::DiagBlockBrakes:
|
||||
ride->numBlockBrakes--;
|
||||
if (ride->numBlockBrakes == 0)
|
||||
{
|
||||
ride->windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_OPERATING;
|
||||
RideMode newMode = RideMode::continuousCircuit;
|
||||
if (ride->mode == RideMode::poweredLaunchBlockSectioned)
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackElemType::OnRidePhoto:
|
||||
ride->lifecycleFlags &= ~RIDE_LIFECYCLE_ON_RIDE_PHOTO;
|
||||
break;
|
||||
case TrackElemType::CableLiftHill:
|
||||
ride->lifecycleFlags &= ~RIDE_LIFECYCLE_CABLE_LIFT_HILL_COMPONENT_USED;
|
||||
break;
|
||||
case TrackElemType::BlockBrakes:
|
||||
case TrackElemType::DiagBlockBrakes:
|
||||
ride->numBlockBrakes--;
|
||||
if (ride->numBlockBrakes == 0)
|
||||
{
|
||||
newMode = RideMode::poweredLaunch;
|
||||
ride->windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_OPERATING;
|
||||
RideMode newMode = RideMode::continuousCircuit;
|
||||
if (ride->mode == RideMode::poweredLaunchBlockSectioned)
|
||||
{
|
||||
newMode = RideMode::poweredLaunch;
|
||||
}
|
||||
|
||||
auto rideSetSetting = RideSetSettingAction(
|
||||
ride->id, RideSetSetting::Mode, static_cast<uint8_t>(newMode));
|
||||
ExecuteNested(&rideSetSetting);
|
||||
}
|
||||
|
||||
auto rideSetSetting = RideSetSettingAction(ride->id, RideSetSetting::Mode, static_cast<uint8_t>(newMode));
|
||||
GameActions::ExecuteNested(&rideSetSetting);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackElemType::Up25ToFlat:
|
||||
case TrackElemType::Up60ToFlat:
|
||||
case TrackElemType::DiagUp25ToFlat:
|
||||
case TrackElemType::DiagUp60ToFlat:
|
||||
if (!isLiftHill)
|
||||
break;
|
||||
[[fallthrough]];
|
||||
case TrackElemType::CableLiftHill:
|
||||
ride->numBlockBrakes--;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (trackType)
|
||||
{
|
||||
case TrackElemType::Up25ToFlat:
|
||||
case TrackElemType::Up60ToFlat:
|
||||
case TrackElemType::DiagUp25ToFlat:
|
||||
case TrackElemType::DiagUp60ToFlat:
|
||||
if (!isLiftHill)
|
||||
break;
|
||||
[[fallthrough]];
|
||||
case TrackElemType::CableLiftHill:
|
||||
ride->numBlockBrakes--;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
money64 price = ride->getRideTypeDescriptor().BuildCosts.TrackPrice;
|
||||
price *= ted.priceModifier;
|
||||
price >>= 16;
|
||||
price = supportCosts + price;
|
||||
if (ride->lifecycleFlags & RIDE_LIFECYCLE_EVER_BEEN_OPENED)
|
||||
{
|
||||
// 70% modifier for opened rides
|
||||
price = (price * 45875) / 65536;
|
||||
}
|
||||
money64 price = ride->getRideTypeDescriptor().BuildCosts.TrackPrice;
|
||||
price *= ted.priceModifier;
|
||||
price >>= 16;
|
||||
price = supportCosts + price;
|
||||
if (ride->lifecycleFlags & RIDE_LIFECYCLE_EVER_BEEN_OPENED)
|
||||
{
|
||||
// 70% modifier for opened rides
|
||||
price = (price * 45875) / 65536;
|
||||
}
|
||||
|
||||
res.Cost = -price;
|
||||
return res;
|
||||
}
|
||||
res.Cost = -price;
|
||||
return res;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -11,22 +11,25 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
class TrackRemoveAction final : public GameActionBase<GameCommand::RemoveTrack>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
OpenRCT2::TrackElemType _trackType{};
|
||||
int32_t _sequence{};
|
||||
CoordsXYZD _origin;
|
||||
class TrackRemoveAction final : public GameActionBase<GameCommand::RemoveTrack>
|
||||
{
|
||||
private:
|
||||
TrackElemType _trackType{};
|
||||
int32_t _sequence{};
|
||||
CoordsXYZD _origin;
|
||||
|
||||
public:
|
||||
TrackRemoveAction() = default;
|
||||
TrackRemoveAction(OpenRCT2::TrackElemType trackType, int32_t sequence, const CoordsXYZD& origin);
|
||||
public:
|
||||
TrackRemoveAction() = default;
|
||||
TrackRemoveAction(TrackElemType trackType, int32_t sequence, const CoordsXYZD& origin);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override final;
|
||||
uint16_t GetActionFlags() const override final;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
};
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -14,76 +14,77 @@
|
||||
#include "../ride/RideConstruction.h"
|
||||
#include "../world/tile_element/TrackElement.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
TrackSetBrakeSpeedAction::TrackSetBrakeSpeedAction(const CoordsXYZ& loc, OpenRCT2::TrackElemType trackType, uint8_t brakeSpeed)
|
||||
: _loc(loc)
|
||||
, _trackType(trackType)
|
||||
, _brakeSpeed(brakeSpeed)
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
}
|
||||
|
||||
void TrackSetBrakeSpeedAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
visitor.Visit(_loc);
|
||||
visitor.Visit("trackType", _trackType);
|
||||
visitor.Visit("brakeSpeed", _brakeSpeed);
|
||||
}
|
||||
|
||||
uint16_t TrackSetBrakeSpeedAction::GetActionFlags() const
|
||||
{
|
||||
return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
void TrackSetBrakeSpeedAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
stream << DS_TAG(_loc) << DS_TAG(_trackType) << DS_TAG(_brakeSpeed);
|
||||
}
|
||||
|
||||
GameActions::Result TrackSetBrakeSpeedAction::Query() const
|
||||
{
|
||||
return QueryExecute(false);
|
||||
}
|
||||
|
||||
GameActions::Result TrackSetBrakeSpeedAction::Execute() const
|
||||
{
|
||||
return QueryExecute(true);
|
||||
}
|
||||
|
||||
GameActions::Result TrackSetBrakeSpeedAction::QueryExecute(bool isExecuting) const
|
||||
{
|
||||
auto res = GameActions::Result();
|
||||
|
||||
res.Position = _loc;
|
||||
res.Position.x += 16;
|
||||
res.Position.y += 16;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
TrackSetBrakeSpeedAction::TrackSetBrakeSpeedAction(
|
||||
const CoordsXYZ& loc, OpenRCT2::TrackElemType trackType, uint8_t brakeSpeed)
|
||||
: _loc(loc)
|
||||
, _trackType(trackType)
|
||||
, _brakeSpeed(brakeSpeed)
|
||||
{
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_CHANGE_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
TileElement* tileElement = MapGetTrackElementAtOfType(_loc, _trackType);
|
||||
if (tileElement == nullptr)
|
||||
void TrackSetBrakeSpeedAction::AcceptParameters(GameActionParameterVisitor& visitor)
|
||||
{
|
||||
LOG_ERROR("Track element of type %u not found at x = %d, y = %d, z = %d", _trackType, _loc.x, _loc.y, _loc.z);
|
||||
return GameActions::Result(
|
||||
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
|
||||
visitor.Visit(_loc);
|
||||
visitor.Visit("trackType", _trackType);
|
||||
visitor.Visit("brakeSpeed", _brakeSpeed);
|
||||
}
|
||||
|
||||
if (_brakeSpeed > kMaximumTrackSpeed)
|
||||
uint16_t TrackSetBrakeSpeedAction::GetActionFlags() const
|
||||
{
|
||||
LOG_WARNING("Invalid speed for track, speed = %d", _brakeSpeed);
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_SPEED_TOO_HIGH, kStringIdNone);
|
||||
return GameAction::GetActionFlags() | Flags::AllowWhilePaused;
|
||||
}
|
||||
|
||||
if (isExecuting)
|
||||
void TrackSetBrakeSpeedAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GetTrackElementOriginAndApplyChanges(
|
||||
{ _loc, tileElement->GetDirection() }, tileElement->AsTrack()->GetTrackType(), _brakeSpeed, nullptr,
|
||||
{ TrackElementSetFlag::brakeBoosterSpeed });
|
||||
GameAction::Serialise(stream);
|
||||
stream << DS_TAG(_loc) << DS_TAG(_trackType) << DS_TAG(_brakeSpeed);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Result TrackSetBrakeSpeedAction::Query() const
|
||||
{
|
||||
return QueryExecute(false);
|
||||
}
|
||||
|
||||
Result TrackSetBrakeSpeedAction::Execute() const
|
||||
{
|
||||
return QueryExecute(true);
|
||||
}
|
||||
|
||||
Result TrackSetBrakeSpeedAction::QueryExecute(bool isExecuting) const
|
||||
{
|
||||
auto res = Result();
|
||||
|
||||
res.Position = _loc;
|
||||
res.Position.x += 16;
|
||||
res.Position.y += 16;
|
||||
res.Expenditure = ExpenditureType::rideConstruction;
|
||||
|
||||
if (!LocationValid(_loc))
|
||||
{
|
||||
return Result(Status::InvalidParameters, STR_CANT_CHANGE_THIS, STR_OFF_EDGE_OF_MAP);
|
||||
}
|
||||
|
||||
TileElement* tileElement = MapGetTrackElementAtOfType(_loc, _trackType);
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
LOG_ERROR("Track element of type %u not found at x = %d, y = %d, z = %d", _trackType, _loc.x, _loc.y, _loc.z);
|
||||
return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_TILE_ELEMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (_brakeSpeed > kMaximumTrackSpeed)
|
||||
{
|
||||
LOG_WARNING("Invalid speed for track, speed = %d", _brakeSpeed);
|
||||
return Result(Status::InvalidParameters, STR_SPEED_TOO_HIGH, kStringIdNone);
|
||||
}
|
||||
|
||||
if (isExecuting)
|
||||
{
|
||||
GetTrackElementOriginAndApplyChanges(
|
||||
{ _loc, tileElement->GetDirection() }, tileElement->AsTrack()->GetTrackType(), _brakeSpeed, nullptr,
|
||||
{ TrackElementSetFlag::brakeBoosterSpeed });
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -11,25 +11,28 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
class TrackSetBrakeSpeedAction final : public GameActionBase<GameCommand::SetBrakesSpeed>
|
||||
namespace OpenRCT2::GameActions
|
||||
{
|
||||
private:
|
||||
CoordsXYZ _loc;
|
||||
OpenRCT2::TrackElemType _trackType{};
|
||||
uint8_t _brakeSpeed{};
|
||||
class TrackSetBrakeSpeedAction final : public GameActionBase<GameCommand::SetBrakesSpeed>
|
||||
{
|
||||
private:
|
||||
CoordsXYZ _loc;
|
||||
TrackElemType _trackType{};
|
||||
uint8_t _brakeSpeed{};
|
||||
|
||||
public:
|
||||
TrackSetBrakeSpeedAction() = default;
|
||||
TrackSetBrakeSpeedAction(const CoordsXYZ& loc, OpenRCT2::TrackElemType trackType, uint8_t brakeSpeed);
|
||||
public:
|
||||
TrackSetBrakeSpeedAction() = default;
|
||||
TrackSetBrakeSpeedAction(const CoordsXYZ& loc, OpenRCT2::TrackElemType trackType, uint8_t brakeSpeed);
|
||||
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
void AcceptParameters(GameActionParameterVisitor& visitor) override;
|
||||
|
||||
uint16_t GetActionFlags() const override final;
|
||||
uint16_t GetActionFlags() const override final;
|
||||
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
OpenRCT2::GameActions::Result Query() const override;
|
||||
OpenRCT2::GameActions::Result Execute() const override;
|
||||
void Serialise(DataSerialiser& stream) override;
|
||||
Result Query() const override;
|
||||
Result Execute() const override;
|
||||
|
||||
private:
|
||||
OpenRCT2::GameActions::Result QueryExecute(bool isExecuting) const;
|
||||
};
|
||||
private:
|
||||
Result QueryExecute(bool isExecuting) const;
|
||||
};
|
||||
} // namespace OpenRCT2::GameActions
|
||||
@@ -1122,7 +1122,7 @@ money64 RideGetRefundPrice(const Ride& ride)
|
||||
|
||||
do
|
||||
{
|
||||
auto trackRemoveAction = TrackRemoveAction(
|
||||
auto trackRemoveAction = GameActions::TrackRemoveAction(
|
||||
trackElement.element->AsTrack()->GetTrackType(), trackElement.element->AsTrack()->GetSequenceIndex(),
|
||||
{ trackElement.x, trackElement.y, trackElement.element->GetBaseZ(), direction });
|
||||
trackRemoveAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED);
|
||||
|
||||
@@ -1582,7 +1582,7 @@ static GameActions::Result TrackDesignPlaceRide(
|
||||
{
|
||||
const TrackCoordinates* trackCoordinates = &ted.coordinates;
|
||||
int32_t tempZ = newCoords.z - trackCoordinates->zBegin + ted.sequences[0].clearance.z;
|
||||
auto trackRemoveAction = TrackRemoveAction(
|
||||
auto trackRemoveAction = GameActions::TrackRemoveAction(
|
||||
trackType, 0, { newCoords, tempZ, static_cast<Direction>(rotation & 3) });
|
||||
trackRemoveAction.SetFlags(
|
||||
GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST
|
||||
@@ -1631,7 +1631,7 @@ static GameActions::Result TrackDesignPlaceRide(
|
||||
flags |= GAME_COMMAND_FLAG_REPLAY;
|
||||
}
|
||||
|
||||
auto trackPlaceAction = TrackPlaceAction(
|
||||
auto trackPlaceAction = GameActions::TrackPlaceAction(
|
||||
ride.id, trackType, ride.type, { newCoords, tempZ, static_cast<uint8_t>(rotation) },
|
||||
track.brakeBoosterSpeed, track.colourScheme, track.seatRotation, liftHillAndAlternativeState, true);
|
||||
trackPlaceAction.SetFlags(flags);
|
||||
|
||||
Reference in new issue
Block a user