Refactor result passing of TrackPlaceAction

This commit is contained in:
ζeh Matt 2021-10-20 05:15:24 -07:00 committed by GitHub
parent 2d78a5efc3
commit e06f9c3ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 103 additions and 96 deletions

View File

@ -1664,8 +1664,8 @@ static void window_ride_construction_dropdown(rct_window* w, rct_widgetindex wid
_currentTrackCurve = trackPiece | RideConstructionSpecialPieceSelected; _currentTrackCurve = trackPiece | RideConstructionSpecialPieceSelected;
window_ride_construction_update_active_elements(); window_ride_construction_update_active_elements();
} }
static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, const TrackPlaceActionResult* result); static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, const GameActions::Result* result);
static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga, const TrackPlaceActionResult* result); static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga, const GameActions::Result* result);
static void CloseConstructWindowOnCompletion(Ride* ride); static void CloseConstructWindowOnCompletion(Ride* ride);
static void CloseConstructWindowOnCompletion(Ride* ride) static void CloseConstructWindowOnCompletion(Ride* ride)
@ -1687,7 +1687,7 @@ static void CloseConstructWindowOnCompletion(Ride* ride)
} }
} }
static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, const TrackPlaceActionResult* result) static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, const GameActions::Result* result)
{ {
if (result->Error != GameActions::Status::Ok) if (result->Error != GameActions::Status::Ok)
{ {
@ -1732,7 +1732,7 @@ static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, c
CloseConstructWindowOnCompletion(ride); CloseConstructWindowOnCompletion(ride);
} }
static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga, const TrackPlaceActionResult* result) static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga, const GameActions::Result* result)
{ {
if (result->Error != GameActions::Status::Ok) if (result->Error != GameActions::Status::Ok)
{ {
@ -1833,8 +1833,8 @@ static void window_ride_construction_construct(rct_window* w)
_currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_TRACK_PLACE_ACTION_QUEUED; _currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_TRACK_PLACE_ACTION_QUEUED;
} }
auto tpar = dynamic_cast<TrackPlaceActionResult*>(res.get()); const auto resultData = res->GetData<TrackPlaceActionResult>();
if (tpar != nullptr && tpar->GroundFlags & ELEMENT_IS_UNDERGROUND) if (resultData.GroundFlags & ELEMENT_IS_UNDERGROUND)
{ {
viewport_set_visibility(1); viewport_set_visibility(1);
} }

View File

@ -21,25 +21,6 @@
#include "RideSetSettingAction.h" #include "RideSetSettingAction.h"
using namespace OpenRCT2::TrackMetaData; using namespace OpenRCT2::TrackMetaData;
TrackPlaceActionResult::TrackPlaceActionResult()
: GameActions::Result(GameActions::Status::Ok, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE)
{
}
TrackPlaceActionResult::TrackPlaceActionResult(GameActions::Status error)
: GameActions::Result(error, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE)
{
}
TrackPlaceActionResult::TrackPlaceActionResult(GameActions::Status error, rct_string_id message)
: GameActions::Result(error, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, message)
{
}
TrackPlaceActionResult::TrackPlaceActionResult(GameActions::Status error, rct_string_id message, uint8_t* args)
: GameActions::Result(error, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, message, args)
{
}
TrackPlaceAction::TrackPlaceAction( TrackPlaceAction::TrackPlaceAction(
NetworkRideId_t rideIndex, int32_t trackType, const CoordsXYZD& origin, int32_t brakeSpeed, int32_t colour, NetworkRideId_t rideIndex, int32_t trackType, const CoordsXYZD& origin, int32_t brakeSpeed, int32_t colour,
@ -87,42 +68,44 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
if (ride == nullptr) if (ride == nullptr)
{ {
log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex)); log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex));
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters, STR_NONE); return MakeResult(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
} }
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr) if (rideEntry == nullptr)
{ {
log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex)); log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex));
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters, STR_NONE); return MakeResult(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
} }
if (!direction_valid(_origin.direction)) if (!direction_valid(_origin.direction))
{ {
log_warning("Invalid direction for track placement, direction = %d", _origin.direction); log_warning("Invalid direction for track placement, direction = %d", _origin.direction);
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters, STR_NONE); return MakeResult(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
} }
auto res = std::make_unique<TrackPlaceActionResult>(); auto res = MakeResult();
res->Expenditure = ExpenditureType::RideConstruction; res->Expenditure = ExpenditureType::RideConstruction;
res->Position.x = _origin.x + 16; res->Position.x = _origin.x + 16;
res->Position.y = _origin.y + 16; res->Position.y = _origin.y + 16;
res->Position.z = _origin.z; res->Position.z = _origin.z;
res->GroundFlags = 0; auto resultData = TrackPlaceActionResult{};
uint32_t rideTypeFlags = ride->GetRideTypeDescriptor().Flags; uint32_t rideTypeFlags = ride->GetRideTypeDescriptor().Flags;
if ((ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK) && _trackType == TrackElemType::EndStation) if ((ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK) && _trackType == TrackElemType::EndStation)
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Disallowed, STR_NOT_ALLOWED_TO_MODIFY_STATION); return MakeResult(
GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NOT_ALLOWED_TO_MODIFY_STATION);
} }
if (!(GetActionFlags() & GameActions::Flags::AllowWhilePaused)) if (!(GetActionFlags() & GameActions::Flags::AllowWhilePaused))
{ {
if (game_is_paused() && !gCheatsBuildInPauseMode) if (game_is_paused() && !gCheatsBuildInPauseMode)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED);
} }
} }
@ -132,16 +115,18 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
{ {
if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) if (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_ONLY_ONE_ON_RIDE_PHOTO_PER_RIDE); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_ONLY_ONE_ON_RIDE_PHOTO_PER_RIDE);
} }
} }
else if (_trackType == TrackElemType::CableLiftHill) else if (_trackType == TrackElemType::CableLiftHill)
{ {
if (ride->lifecycle_flags & RIDE_LIFECYCLE_CABLE_LIFT_HILL_COMPONENT_USED) if (ride->lifecycle_flags & RIDE_LIFECYCLE_CABLE_LIFT_HILL_COMPONENT_USED)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_ONLY_ONE_CABLE_LIFT_HILL_PER_RIDE); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_ONLY_ONE_CABLE_LIFT_HILL_PER_RIDE);
} }
} }
// Backwards steep lift hills are allowed, even on roller coasters that do not support forwards steep lift hills. // Backwards steep lift hills are allowed, even on roller coasters that do not support forwards steep lift hills.
@ -151,7 +136,9 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
const auto& ted = GetTrackElementDescriptor(_trackType); const auto& ted = GetTrackElementDescriptor(_trackType);
if (ted.Flags & TRACK_ELEM_FLAG_IS_STEEP_UP) if (ted.Flags & TRACK_ELEM_FLAG_IS_STEEP_UP)
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Disallowed, STR_TOO_STEEP_FOR_LIFT_HILL); return MakeResult(
GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_TOO_STEEP_FOR_LIFT_HILL);
} }
} }
} }
@ -168,7 +155,8 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
if (!LocationValid(tileCoords) || (!map_is_location_owned(tileCoords) && !gCheatsSandboxMode)) if (!LocationValid(tileCoords) || (!map_is_location_owned(tileCoords) && !gCheatsSandboxMode))
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Disallowed, STR_LAND_NOT_OWNED_BY_PARK); return MakeResult(
GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK);
} }
numElements++; numElements++;
} }
@ -176,7 +164,9 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
if (!CheckMapCapacity(numElements)) if (!CheckMapCapacity(numElements))
{ {
log_warning("Not enough free map elements to place track."); log_warning("Not enough free map elements to place track.");
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::NoFreeElements, STR_TILE_ELEMENT_LIMIT_REACHED); return MakeResult(
GameActions::Status::NoFreeElements, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_TILE_ELEMENT_LIMIT_REACHED);
} }
if (!gCheatsAllowTrackPlaceInvalidHeights) if (!gCheatsAllowTrackPlaceInvalidHeights)
@ -185,16 +175,18 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
{ {
if ((_origin.z & 0x0F) != 8) if ((_origin.z & 0x0F) != 8)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::InvalidParameters, STR_CONSTRUCTION_ERR_UNKNOWN); GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CONSTRUCTION_ERR_UNKNOWN);
} }
} }
else else
{ {
if ((_origin.z & 0x0F) != 0) if ((_origin.z & 0x0F) != 0)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::InvalidParameters, STR_CONSTRUCTION_ERR_UNKNOWN); GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CONSTRUCTION_ERR_UNKNOWN);
} }
} }
} }
@ -210,7 +202,8 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
if (mapLoc.z < 16) if (mapLoc.z < 16)
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters, STR_TOO_LOW); return MakeResult(
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_TOO_LOW);
} }
int32_t baseZ = floor2(mapLoc.z, COORDS_Z_STEP); int32_t baseZ = floor2(mapLoc.z, COORDS_Z_STEP);
@ -230,7 +223,8 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
if (clearanceZ > MAX_TRACK_HEIGHT) if (clearanceZ > MAX_TRACK_HEIGHT)
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters, STR_TOO_HIGH); return MakeResult(
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_TOO_HIGH);
} }
uint8_t crossingMode = (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS) uint8_t crossingMode = (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)
@ -257,19 +251,21 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
} }
uint8_t mapGroundFlags = canBuild->GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); uint8_t mapGroundFlags = canBuild->GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND);
if (res->GroundFlags != 0 && (res->GroundFlags & mapGroundFlags) == 0) if (resultData.GroundFlags != 0 && (resultData.GroundFlags & mapGroundFlags) == 0)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CANT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_GROUND); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CANT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_GROUND);
} }
res->GroundFlags = mapGroundFlags; resultData.GroundFlags = mapGroundFlags;
if (ted.Flags & TRACK_ELEM_FLAG_ONLY_ABOVE_GROUND) if (ted.Flags & TRACK_ELEM_FLAG_ONLY_ABOVE_GROUND)
{ {
if (res->GroundFlags & ELEMENT_IS_UNDERGROUND) if (resultData.GroundFlags & ELEMENT_IS_UNDERGROUND)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND);
} }
} }
@ -277,34 +273,40 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
{ // No element has this flag { // No element has this flag
if (canBuild->GroundFlags & ELEMENT_IS_UNDERWATER) if (canBuild->GroundFlags & ELEMENT_IS_UNDERWATER)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CAN_ONLY_BUILD_THIS_UNDERWATER); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CAN_ONLY_BUILD_THIS_UNDERWATER);
} }
} }
if (canBuild->GroundFlags & ELEMENT_IS_UNDERWATER && !gCheatsDisableClearanceChecks) if (canBuild->GroundFlags & ELEMENT_IS_UNDERWATER && !gCheatsDisableClearanceChecks)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_RIDE_CANT_BUILD_THIS_UNDERWATER); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_RIDE_CANT_BUILD_THIS_UNDERWATER);
} }
if ((rideTypeFlags & RIDE_TYPE_FLAG_TRACK_MUST_BE_ON_WATER) && !_trackDesignDrawingPreview) if ((rideTypeFlags & RIDE_TYPE_FLAG_TRACK_MUST_BE_ON_WATER) && !_trackDesignDrawingPreview)
{ {
auto surfaceElement = map_get_surface_element_at(mapLoc); auto surfaceElement = map_get_surface_element_at(mapLoc);
if (surfaceElement == nullptr) if (surfaceElement == nullptr)
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Unknown, STR_NONE); {
return MakeResult(GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
}
auto waterHeight = surfaceElement->GetWaterHeight(); auto waterHeight = surfaceElement->GetWaterHeight();
if (waterHeight == 0) if (waterHeight == 0)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CAN_ONLY_BUILD_THIS_ON_WATER); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CAN_ONLY_BUILD_THIS_ON_WATER);
} }
if (waterHeight != baseZ) if (waterHeight != baseZ)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CAN_ONLY_BUILD_THIS_ON_WATER); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CAN_ONLY_BUILD_THIS_ON_WATER);
} }
waterHeight -= LAND_HEIGHT_STEP; waterHeight -= LAND_HEIGHT_STEP;
if (waterHeight == surfaceElement->GetBaseZ()) if (waterHeight == surfaceElement->GetBaseZ())
@ -313,8 +315,9 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
if (slope == TILE_ELEMENT_SLOPE_W_CORNER_DN || slope == TILE_ELEMENT_SLOPE_S_CORNER_DN if (slope == TILE_ELEMENT_SLOPE_W_CORNER_DN || slope == TILE_ELEMENT_SLOPE_S_CORNER_DN
|| slope == TILE_ELEMENT_SLOPE_E_CORNER_DN || slope == TILE_ELEMENT_SLOPE_N_CORNER_DN) || slope == TILE_ELEMENT_SLOPE_E_CORNER_DN || slope == TILE_ELEMENT_SLOPE_N_CORNER_DN)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CAN_ONLY_BUILD_THIS_ON_WATER); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CAN_ONLY_BUILD_THIS_ON_WATER);
} }
} }
} }
@ -324,14 +327,17 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
{ {
if (!track_add_station_element({ mapLoc, baseZ, _origin.direction }, _rideIndex, 0, _fromTrackDesign)) if (!track_add_station_element({ mapLoc, baseZ, _origin.direction }, _rideIndex, 0, _fromTrackDesign))
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Unknown, gGameCommandErrorText); return MakeResult(
GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, gGameCommandErrorText);
} }
} }
// 6c5648 12 push // 6c5648 12 push
auto surfaceElement = map_get_surface_element_at(mapLoc); auto surfaceElement = map_get_surface_element_at(mapLoc);
if (surfaceElement == nullptr) if (surfaceElement == nullptr)
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Unknown, STR_NONE); {
return MakeResult(GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
}
if (!gCheatsDisableSupportLimits) if (!gCheatsDisableSupportLimits)
{ {
@ -353,7 +359,9 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
ride_height /= COORDS_Z_PER_TINY_Z; ride_height /= COORDS_Z_PER_TINY_Z;
if (ride_height > maxHeight && !_trackDesignDrawingPreview) if (ride_height > maxHeight && !_trackDesignDrawingPreview)
{ {
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Disallowed, STR_TOO_HIGH_FOR_SUPPORTS); return MakeResult(
GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_TOO_HIGH_FOR_SUPPORTS);
} }
} }
} }
@ -372,6 +380,8 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
price >>= 16; price >>= 16;
res->Cost = cost + ((price / 2) * 10); res->Cost = cost + ((price / 2) * 10);
res->SetData(std::move(resultData));
return res; return res;
} }
@ -381,23 +391,23 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const
if (ride == nullptr) if (ride == nullptr)
{ {
log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex)); log_warning("Invalid ride for track placement, rideIndex = %d", EnumValue(_rideIndex));
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters); return MakeResult(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
} }
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype); rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr) if (rideEntry == nullptr)
{ {
log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex)); log_warning("Invalid ride subtype for track placement, rideIndex = %d", EnumValue(_rideIndex));
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::InvalidParameters); return MakeResult(GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
} }
auto res = std::make_unique<TrackPlaceActionResult>(); auto res = MakeResult();
res->Expenditure = ExpenditureType::RideConstruction; res->Expenditure = ExpenditureType::RideConstruction;
res->Position.x = _origin.x + 16; res->Position.x = _origin.x + 16;
res->Position.y = _origin.y + 16; res->Position.y = _origin.y + 16;
res->Position.z = _origin.z; res->Position.z = _origin.z;
res->GroundFlags = 0; auto resultData = TrackPlaceActionResult{};
uint32_t rideTypeFlags = ride->GetRideTypeDescriptor().Flags; uint32_t rideTypeFlags = ride->GetRideTypeDescriptor().Flags;
@ -466,18 +476,21 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const
} }
uint8_t mapGroundFlags = canBuild->GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); uint8_t mapGroundFlags = canBuild->GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND);
if (res->GroundFlags != 0 && (res->GroundFlags & mapGroundFlags) == 0) if (resultData.GroundFlags != 0 && (resultData.GroundFlags & mapGroundFlags) == 0)
{ {
return std::make_unique<TrackPlaceActionResult>( return MakeResult(
GameActions::Status::Disallowed, STR_CANT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_GROUND); GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_CANT_BUILD_PARTLY_ABOVE_AND_PARTLY_BELOW_GROUND);
} }
res->GroundFlags = mapGroundFlags; resultData.GroundFlags = mapGroundFlags;
// 6c5648 12 push // 6c5648 12 push
auto surfaceElement = map_get_surface_element_at(mapLoc); auto surfaceElement = map_get_surface_element_at(mapLoc);
if (surfaceElement == nullptr) if (surfaceElement == nullptr)
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::Unknown, STR_NONE); {
return MakeResult(GameActions::Status::Unknown, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE);
}
int32_t supportHeight = baseZ - surfaceElement->GetBaseZ(); int32_t supportHeight = baseZ - surfaceElement->GetBaseZ();
if (supportHeight < 0) if (supportHeight < 0)
@ -552,7 +565,9 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const
if (trackElement == nullptr) if (trackElement == nullptr)
{ {
log_warning("Cannot create track element for ride = %d", EnumValue(_rideIndex)); log_warning("Cannot create track element for ride = %d", EnumValue(_rideIndex));
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::NoFreeElements); return MakeResult(
GameActions::Status::NoFreeElements, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE,
STR_TILE_ELEMENT_LIMIT_REACHED);
} }
trackElement->SetClearanceZ(clearanceZ); trackElement->SetClearanceZ(clearanceZ);
@ -659,6 +674,8 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const
price >>= 16; price >>= 16;
res->Cost = cost + ((price / 2) * 10); res->Cost = cost + ((price / 2) * 10);
res->SetData(std::move(resultData));
return res; return res;
} }

View File

@ -11,18 +11,12 @@
#include "GameAction.h" #include "GameAction.h"
class TrackPlaceActionResult final : public GameActions::Result struct TrackPlaceActionResult
{ {
public:
TrackPlaceActionResult();
TrackPlaceActionResult(GameActions::Status error);
TrackPlaceActionResult(GameActions::Status error, rct_string_id message);
TrackPlaceActionResult(GameActions::Status error, rct_string_id message, uint8_t* args);
uint8_t GroundFlags{ 0 }; uint8_t GroundFlags{ 0 };
}; };
DEFINE_GAME_ACTION(TrackPlaceAction, GameCommand::PlaceTrack, TrackPlaceActionResult) DEFINE_GAME_ACTION(TrackPlaceAction, GameCommand::PlaceTrack, GameActions::Result)
{ {
private: private:
NetworkRideId_t _rideIndex{ RIDE_ID_NULL }; NetworkRideId_t _rideIndex{ RIDE_ID_NULL };

View File

@ -51,13 +51,12 @@ money32 place_provisional_track_piece(
if (ride == nullptr) if (ride == nullptr)
return MONEY32_UNDEFINED; return MONEY32_UNDEFINED;
money32 result;
ride_construction_remove_ghosts(); ride_construction_remove_ghosts();
if (ride->type == RIDE_TYPE_MAZE) if (ride->type == RIDE_TYPE_MAZE)
{ {
int32_t flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND int32_t flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND
| GAME_COMMAND_FLAG_GHOST; // 105 | GAME_COMMAND_FLAG_GHOST; // 105
result = maze_set_track(trackPos.x, trackPos.y, trackPos.z, flags, true, 0, rideIndex, GC_SET_MAZE_TRACK_BUILD); auto result = maze_set_track(trackPos.x, trackPos.y, trackPos.z, flags, true, 0, rideIndex, GC_SET_MAZE_TRACK_BUILD);
if (result == MONEY32_UNDEFINED) if (result == MONEY32_UNDEFINED)
return result; return result;
@ -84,10 +83,8 @@ money32 place_provisional_track_piece(
trackPlaceAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); trackPlaceAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
// This command must not be sent over the network // This command must not be sent over the network
auto res = GameActions::Execute(&trackPlaceAction); auto res = GameActions::Execute(&trackPlaceAction);
auto tpar = dynamic_cast<TrackPlaceActionResult*>(res.get()); if (res->Error != GameActions::Status::Ok)
result = ((tpar == nullptr) || (res->Error == GameActions::Status::Ok)) ? res->Cost : MONEY32_UNDEFINED; return MONEY32_UNDEFINED;
if (result == MONEY32_UNDEFINED)
return result;
int16_t z_begin, z_end; int16_t z_begin, z_end;
const auto& ted = GetTrackElementDescriptor(trackType); const auto& ted = GetTrackElementDescriptor(trackType);
@ -104,10 +101,9 @@ money32 place_provisional_track_piece(
_unkF440C5 = { trackPos.x, trackPos.y, trackPos.z + z_begin, static_cast<Direction>(trackDirection) }; _unkF440C5 = { trackPos.x, trackPos.y, trackPos.z + z_begin, static_cast<Direction>(trackDirection) };
_currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_TRACK; _currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_TRACK;
if (tpar != nullptr)
{ const auto resultData = res->GetData<TrackPlaceActionResult>();
viewport_set_visibility((tpar->GroundFlags & ELEMENT_IS_UNDERGROUND) ? 1 : 3); viewport_set_visibility((resultData.GroundFlags & ELEMENT_IS_UNDERGROUND) ? 1 : 3);
}
if (_currentTrackSlopeEnd != 0) if (_currentTrackSlopeEnd != 0)
viewport_set_visibility(2); viewport_set_visibility(2);
@ -120,7 +116,7 @@ money32 place_provisional_track_piece(
virtual_floor_set_height(trackPos.z - z_begin + z_end); virtual_floor_set_height(trackPos.z - z_begin + z_end);
} }
return result; return res->Cost;
} }
static std::tuple<bool, track_type_t> window_ride_construction_update_state_get_track_element() static std::tuple<bool, track_type_t> window_ride_construction_update_state_get_track_element()