diff --git a/src/openrct2/actions/GameActionCompat.cpp b/src/openrct2/actions/GameActionCompat.cpp index 9af73acc63..d33c82df83 100644 --- a/src/openrct2/actions/GameActionCompat.cpp +++ b/src/openrct2/actions/GameActionCompat.cpp @@ -67,11 +67,11 @@ void ride_construct_new(RideSelection listItem) auto gameAction = RideCreateAction(listItem.Type, listItem.EntryIndex, colour1, colour2); - gameAction.SetCallback([](const GameAction* ga, const RideCreateGameActionResult* result) { + gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; - - auto ride = get_ride(result->rideIndex); + const auto rideIndex = result->GetData(); + auto ride = get_ride(rideIndex); ride_construct(ride); }); diff --git a/src/openrct2/actions/RideCreateAction.cpp b/src/openrct2/actions/RideCreateAction.cpp index bf09c66fe9..36e0341c11 100644 --- a/src/openrct2/actions/RideCreateAction.cpp +++ b/src/openrct2/actions/RideCreateAction.cpp @@ -27,16 +27,6 @@ #include -RideCreateGameActionResult::RideCreateGameActionResult() - : GameActions::Result(GameActions::Status::Ok, STR_NONE) -{ -} - -RideCreateGameActionResult::RideCreateGameActionResult(GameActions::Status error, rct_string_id message) - : GameActions::Result(error, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, message) -{ -} - RideCreateAction::RideCreateAction(int32_t rideType, ObjectEntryIndex subType, int32_t colour1, int32_t colour2) : _rideType(rideType) , _subType(subType) @@ -81,39 +71,42 @@ GameActions::Result::Ptr RideCreateAction::Query() const if (rideIndex == RIDE_ID_NULL) { // No more free slots available. - return MakeResult(GameActions::Status::NoFreeElements, STR_TOO_MANY_RIDES); + return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_TOO_MANY_RIDES); } if (_rideType >= RIDE_TYPE_COUNT) { - return MakeResult(GameActions::Status::InvalidParameters, STR_INVALID_RIDE_TYPE); + return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_INVALID_RIDE_TYPE); } int32_t rideEntryIndex = ride_get_entry_index(_rideType, _subType); if (rideEntryIndex >= MAX_RIDE_OBJECTS) { - return MakeResult(GameActions::Status::InvalidParameters, STR_INVALID_RIDE_TYPE); + return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_INVALID_RIDE_TYPE); } const auto& colourPresets = GetRideTypeDescriptor(_rideType).ColourPresets; if (_colour1 >= colourPresets.count) { - return MakeResult(GameActions::Status::InvalidParameters, STR_NONE); + return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_NONE); } rct_ride_entry* rideEntry = get_ride_entry(rideEntryIndex); if (rideEntry == nullptr) { - return MakeResult(GameActions::Status::InvalidParameters, STR_NONE); + return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_NONE); } vehicle_colour_preset_list* presetList = rideEntry->vehicle_preset_list; if ((presetList->count > 0 && presetList->count != 255) && _colour2 >= presetList->count) { - return MakeResult(GameActions::Status::InvalidParameters, STR_NONE); + return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_NONE); } - return MakeResult(); + auto res = MakeResult(); + res->SetData(ride_id_t{ rideIndex }); + + return res; } GameActions::Result::Ptr RideCreateAction::Execute() const @@ -124,16 +117,12 @@ GameActions::Result::Ptr RideCreateAction::Execute() const int32_t rideEntryIndex = ride_get_entry_index(_rideType, _subType); auto rideIndex = GetNextFreeRideId(); - res->rideIndex = rideIndex; - auto ride = GetOrAllocateRide(rideIndex); rideEntry = get_ride_entry(rideEntryIndex); if (rideEntry == nullptr) { log_warning("Invalid request for ride %u", rideIndex); - res->Error = GameActions::Status::Unknown; - res->ErrorMessage = STR_UNKNOWN_OBJECT_TYPE; - return res; + return MakeResult(GameActions::Status::Unknown, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_UNKNOWN_OBJECT_TYPE); } ride->id = rideIndex; @@ -309,6 +298,7 @@ GameActions::Result::Ptr RideCreateAction::Execute() const window_invalidate_by_class(WC_RIDE_LIST); res->Expenditure = ExpenditureType::RideConstruction; + res->SetData(ride_id_t{ rideIndex }); return res; } diff --git a/src/openrct2/actions/RideCreateAction.h b/src/openrct2/actions/RideCreateAction.h index 098a749bf4..8f3f30a116 100644 --- a/src/openrct2/actions/RideCreateAction.h +++ b/src/openrct2/actions/RideCreateAction.h @@ -11,16 +11,7 @@ #include "GameAction.h" -class RideCreateGameActionResult final : public GameActions::Result -{ -public: - RideCreateGameActionResult(); - RideCreateGameActionResult(GameActions::Status error, rct_string_id message); - - ride_id_t rideIndex = RIDE_ID_NULL; -}; - -DEFINE_GAME_ACTION(RideCreateAction, GameCommand::CreateRide, RideCreateGameActionResult) +DEFINE_GAME_ACTION(RideCreateAction, GameCommand::CreateRide, GameActions::Result) { private: ObjectEntryIndex _rideType{ OBJECT_ENTRY_INDEX_NULL }; diff --git a/src/openrct2/actions/TrackDesignAction.cpp b/src/openrct2/actions/TrackDesignAction.cpp index 8b34c92053..75e2637809 100644 --- a/src/openrct2/actions/TrackDesignAction.cpp +++ b/src/openrct2/actions/TrackDesignAction.cpp @@ -102,13 +102,12 @@ GameActions::Result::Ptr TrackDesignAction::Query() const auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0); rideCreateAction.SetFlags(GetFlags()); auto r = GameActions::ExecuteNested(&rideCreateAction); - auto rideIndex = static_cast(r.get())->rideIndex; - if (r->Error != GameActions::Status::Ok) { return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_NONE); } + const auto rideIndex = r->GetData(); auto ride = get_ride(rideIndex); if (ride == nullptr) { @@ -163,13 +162,12 @@ GameActions::Result::Ptr TrackDesignAction::Execute() const auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0); rideCreateAction.SetFlags(GetFlags()); auto r = GameActions::ExecuteNested(&rideCreateAction); - auto rideIndex = static_cast(r.get())->rideIndex; - if (r->Error != GameActions::Status::Ok) { return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_CREATE_NEW_RIDE_ATTRACTION, STR_NONE); } + const auto rideIndex = r->GetData(); auto ride = get_ride(rideIndex); if (ride == nullptr) { diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 4af87d4f7c..9da0a967f2 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1866,8 +1866,7 @@ static money32 track_design_ride_create_command(int32_t type, int32_t subType, i auto gameAction = RideCreateAction(type, subType, 0, 0); gameAction.SetFlags(flags); - auto r = GameActions::ExecuteNested(&gameAction); - const RideCreateGameActionResult* res = static_cast(r.get()); + auto res = GameActions::ExecuteNested(&gameAction); // Callee's of this function expect MONEY32_UNDEFINED in case of failure. if (res->Error != GameActions::Status::Ok) @@ -1875,7 +1874,7 @@ static money32 track_design_ride_create_command(int32_t type, int32_t subType, i return MONEY32_UNDEFINED; } - *outRideIndex = res->rideIndex; + *outRideIndex = res->GetData(); return res->Cost; } diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index c38ae2f90d..1208beeb0c 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -884,10 +884,10 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std if (action.GetType() == GameCommand::CreateRide) { - auto& rideCreateResult = static_cast(*result.get()); - if (rideCreateResult.rideIndex != RIDE_ID_NULL) + if (result->Error == GameActions::Status::Ok) { - obj.Set("ride", EnumValue(rideCreateResult.rideIndex)); + const auto rideIndex = result->GetData(); + obj.Set("ride", EnumValue(rideIndex)); } } else if (action.GetType() == GameCommand::HireNewStaffMember)