Skip to content

Commit

Permalink
Merge pull request OpenRCT2#21244 from pfroud/add-error-strings
Browse files Browse the repository at this point in the history
Add error strings to reduce how many `GameActions::Result`s have `STR_NONE, STR_NONE`
  • Loading branch information
ZehMatt authored Jan 29, 2024
2 parents 89094ca + a382e4b commit fc1b580
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 94 deletions.
16 changes: 16 additions & 0 deletions data/language/en-GB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3699,6 +3699,22 @@ STR_6593 :Remove park fences
STR_6594 :Tile Inspector: Toggle wall slope
STR_6595 :{WINDOW_COLOUR_2}Author: {BLACK}{STRING}
STR_6596 :{WINDOW_COLOUR_2}Authors: {BLACK}{STRING}
STR_6597 :Invalid parameter
STR_6598 :Value out of range
STR_6599 :Ghost element not found
STR_6600 :Balloon not found
STR_6601 :Staff not found
STR_6602 :Ride not found
STR_6603 :Ride object entry not found
STR_6604 :Player not found
STR_6605 :Entrance element not found
STR_6606 :Surface element not found
STR_6607 :Tile element not found
STR_6608 :Track element not found
STR_6609 :Track block not found
STR_6610 :Path element not found
STR_6611 :Wall element not found
STR_6612 :Banner element not found

#############
# Scenarios #
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/BalloonPressAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ GameActions::Result BalloonPressAction::Query() const
if (balloon == nullptr)
{
LOG_ERROR("Tried getting invalid sprite for balloon: %u", _spriteIndex);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND);
}
return GameActions::Result();
}
Expand All @@ -51,7 +52,8 @@ GameActions::Result BalloonPressAction::Execute() const
if (balloon == nullptr)
{
LOG_ERROR("Tried getting invalid sprite for balloon: %u", _spriteIndex);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND);
}

balloon->Press();
Expand Down
13 changes: 8 additions & 5 deletions src/openrct2/actions/CheatSetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ GameActions::Result CheatSetAction::Query() const
{
if (static_cast<uint32_t>(_cheatType) >= static_cast<uint32_t>(CheatType::Count))
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

ParametersRange validRange = GetParameterRange(static_cast<CheatType>(_cheatType.id));

if (_param1 < validRange.first.first || _param1 > validRange.first.second)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
if (_param2 < validRange.second.first || _param2 > validRange.second.second)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

return GameActions::Result();
Expand Down Expand Up @@ -257,9 +260,9 @@ GameActions::Result CheatSetAction::Execute() const
default:
{
LOG_ERROR("Unabled cheat: %d", _cheatType.id);
GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
break;
}

if (NetworkGetMode() == NETWORK_MODE_NONE)
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/GameSetSpeedAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ GameActions::Result GameSetSpeedAction::Query() const
if (!IsValidSpeed(_speed))
{
LOG_WARNING("Invalid game command for speed %u", _speed);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

return res;
Expand All @@ -53,7 +54,8 @@ GameActions::Result GameSetSpeedAction::Execute() const
if (!IsValidSpeed(_speed))
{
LOG_WARNING("Invalid game command for speed %u", _speed);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

gGameSpeed = _speed;
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/LandSetHeightAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ GameActions::Result LandSetHeightAction::Query() const

auto* surfaceElement = MapGetSurfaceElementAt(_coords);
if (surfaceElement == nullptr)
return GameActions::Result(GameActions::Status::Unknown, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);

// We need to check if there is _currently_ a level crossing on the tile.
// For that, we need the old height, so we can't use the _height variable.
Expand Down Expand Up @@ -165,7 +166,8 @@ GameActions::Result LandSetHeightAction::Execute() const

auto* surfaceElement = MapGetSurfaceElementAt(_coords);
if (surfaceElement == nullptr)
return GameActions::Result(GameActions::Status::Unknown, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);

cost += GetSurfaceHeightChangeCost(surfaceElement);
SetSurfaceHeight(reinterpret_cast<TileElement*>(surfaceElement));
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/LandSetRightsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ GameActions::Result LandSetRightsAction::MapBuyLandRightsForTile(const CoordsXY&
if (surfaceElement == nullptr)
{
LOG_ERROR("Could not find surface. x = %d, y = %d", loc.x, loc.y);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_SURFACE_ELEMENT_NOT_FOUND);
}

auto res = GameActions::Result();
Expand Down Expand Up @@ -203,6 +204,7 @@ GameActions::Result LandSetRightsAction::MapBuyLandRightsForTile(const CoordsXY&
}
default:
LOG_WARNING("Tried calling set land rights with an incorrect setting. setting = %u", _setting);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
}
3 changes: 2 additions & 1 deletion src/openrct2/actions/ParkSetDateAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ GameActions::Result ParkSetDateAction::Query() const
{
if (_year < 0 || _year >= MAX_YEAR || _month < 0 || _month >= MONTH_COUNT || _day < 0 || _day >= 31)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

return GameActions::Result();
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/actions/ParkSetEntranceFeeAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ GameActions::Result ParkSetEntranceFeeAction::Query() const
}
if (_fee < 0.00_GBP || _fee > MAX_ENTRANCE_FEE)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
return GameActions::Result();
}
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/ParkSetParameterAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ GameActions::Result ParkSetParameterAction::Query() const
{
if (_parameter >= ParkParameter::Count)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

auto res = GameActions::Result();
Expand Down Expand Up @@ -76,7 +77,8 @@ GameActions::Result ParkSetParameterAction::Execute() const
WindowInvalidateByClass(WindowClass::Ride);
break;
default:
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

auto res = GameActions::Result();
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/actions/ParkSetResearchFundingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ GameActions::Result ParkSetResearchFundingAction::Query() const
{
if (_fundingAmount >= RESEARCH_FUNDING_COUNT)
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
return GameActions::Result();
}
Expand Down
20 changes: 12 additions & 8 deletions src/openrct2/actions/RideEntranceExitRemoveAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GameActions::Result RideEntranceExitRemoveAction::Query() const
if (ride == nullptr)
{
LOG_WARNING("Invalid ride id %u for entrance/exit removal", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

if (ride->status != RideStatus::Closed && ride->status != RideStatus::Simulating)
Expand All @@ -94,14 +94,16 @@ GameActions::Result RideEntranceExitRemoveAction::Query() const
// If we are trying to remove a ghost and the element we found is real, return an error, but don't log a warning
if (entranceElement != nullptr && (GetFlags() & GAME_COMMAND_FLAG_GHOST) && !(entranceElement->IsGhost()))
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_GHOST_ELEMENT_NOT_FOUND);
}
else if (entranceElement == nullptr)
{
LOG_WARNING(
"Track Element not found. x = %d, y = %d, ride = %u, station = %u", _loc.x, _loc.y, _rideIndex.ToUnderlying(),
"Entrance element not found. x = %d, y = %d, ride = %u, station = %u", _loc.x, _loc.y, _rideIndex.ToUnderlying(),
_stationNum.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ENTRANCE_ELEMENT_NOT_FOUND);
}

return GameActions::Result();
Expand All @@ -113,7 +115,7 @@ GameActions::Result RideEntranceExitRemoveAction::Execute() const
if (ride == nullptr)
{
LOG_WARNING("Invalid ride id %u for entrance/exit removal", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

const bool isGhost = GetFlags() & GAME_COMMAND_FLAG_GHOST;
Expand All @@ -130,14 +132,16 @@ GameActions::Result RideEntranceExitRemoveAction::Execute() const
// If we are trying to remove a ghost and the element we found is real, return an error, but don't log a warning
if (entranceElement != nullptr && isGhost && !(entranceElement->IsGhost()))
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_GHOST_ELEMENT_NOT_FOUND);
}
else if (entranceElement == nullptr)
{
LOG_WARNING(
"Track Element not found. x = %d, y = %d, ride = %u, station = %d", _loc.x, _loc.y, _rideIndex.ToUnderlying(),
"Entrance element not found. x = %d, y = %d, ride = %u, station = %d", _loc.x, _loc.y, _rideIndex.ToUnderlying(),
_stationNum);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ENTRANCE_ELEMENT_NOT_FOUND);
}

auto res = GameActions::Result();
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/actions/RideFreezeRatingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ GameActions::Result RideFreezeRatingAction::Query() const
if (ride == nullptr)
{
LOG_WARNING("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

if (_value <= 0)
{
LOG_WARNING("Rating value must be positive", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

return GameActions::Result();
Expand Down
13 changes: 8 additions & 5 deletions src/openrct2/actions/RideSetAppearanceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ GameActions::Result RideSetAppearanceAction::Query() const
if (ride == nullptr)
{
LOG_WARNING("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

switch (_type)
Expand All @@ -65,7 +65,8 @@ GameActions::Result RideSetAppearanceAction::Query() const
if (_index >= std::size(ride->track_colour))
{
LOG_WARNING("Invalid game command, index %d out of bounds", _index);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
break;
case RideSetAppearanceType::VehicleColourBody:
Expand All @@ -74,7 +75,8 @@ GameActions::Result RideSetAppearanceAction::Query() const
if (_index >= std::size(ride->vehicle_colours))
{
LOG_WARNING("Invalid game command, index %d out of bounds", _index);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
break;
case RideSetAppearanceType::VehicleColourScheme:
Expand All @@ -83,7 +85,8 @@ GameActions::Result RideSetAppearanceAction::Query() const
break;
default:
LOG_WARNING("Invalid game command, type %d not recognised", _type);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

return GameActions::Result();
Expand All @@ -95,7 +98,7 @@ GameActions::Result RideSetAppearanceAction::Execute() const
if (ride == nullptr)
{
LOG_WARNING("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

switch (_type)
Expand Down
10 changes: 6 additions & 4 deletions src/openrct2/actions/RideSetPriceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ GameActions::Result RideSetPriceAction::Query() const
if (ride == nullptr)
{
LOG_WARNING("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

const auto* rideEntry = GetRideEntryByIndex(ride->subtype);
if (rideEntry == nullptr)
{
LOG_WARNING("Invalid game command for ride %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_OBJECT_ENTRY_NOT_FOUND);
}

return res;
Expand All @@ -77,14 +78,15 @@ GameActions::Result RideSetPriceAction::Execute() const
if (ride == nullptr)
{
LOG_WARNING("Invalid game command, ride_id = %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_NOT_FOUND);
}

const auto* rideEntry = GetRideEntryByIndex(ride->subtype);
if (rideEntry == nullptr)
{
LOG_WARNING("Invalid game command for ride %u", _rideIndex.ToUnderlying());
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_OBJECT_ENTRY_NOT_FOUND);
}

if (!ride->overall_view.IsNull())
Expand Down
6 changes: 4 additions & 2 deletions src/openrct2/actions/ScenarioSetSettingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ GameActions::Result ScenarioSetSettingAction::Query() const
if (_setting >= ScenarioSetSetting::Count)
{
LOG_ERROR("Invalid setting: %u", _setting);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

return GameActions::Result();
Expand Down Expand Up @@ -264,7 +265,8 @@ GameActions::Result ScenarioSetSettingAction::Execute() const
}
default:
LOG_ERROR("Invalid setting: %u", _setting);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}
WindowInvalidateByClass(WindowClass::EditorScenarioOptions);
return GameActions::Result();
Expand Down
7 changes: 4 additions & 3 deletions src/openrct2/actions/StaffFireAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ GameActions::Result StaffFireAction::Query() const
if (_spriteId.ToUnderlying() >= MAX_ENTITIES || _spriteId.IsNull())
{
LOG_ERROR("Invalid spriteId. spriteId = %u", _spriteId);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE);
}

auto staff = TryGetEntity<Staff>(_spriteId);
if (staff == nullptr)
{
LOG_ERROR("Invalid spriteId. spriteId = %u", _spriteId);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND);
}

if (staff->State == PeepState::Fixing)
Expand All @@ -67,7 +68,7 @@ GameActions::Result StaffFireAction::Execute() const
if (staff == nullptr)
{
LOG_ERROR("Invalid spriteId. spriteId = %u", _spriteId);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND);
}
WindowCloseByClass(WindowClass::FirePrompt);
PeepEntityRemove(staff);
Expand Down
Loading

0 comments on commit fc1b580

Please sign in to comment.