1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-20 22:33:02 +01:00

Refactor PerformNextAction, we don't need a wrapper

This commit is contained in:
ζeh Matt
2025-03-20 18:48:26 +02:00
parent bd4db4a91b
commit cac21504cd
5 changed files with 46 additions and 62 deletions

View File

@@ -1281,8 +1281,7 @@ void Guest::UpdateSitting()
return;
// 691541
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_DESTINATION_REACHED))
return;
@@ -5425,8 +5424,7 @@ void Guest::UpdateWalking()
return;
}
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_DESTINATION_REACHED))
return;
@@ -5660,8 +5658,7 @@ void Guest::UpdateQueuing()
return;
}
uint8_t pathingResult;
PerformNextAction(pathingResult);
PerformNextAction();
if (!IsActionInterruptable())
return;
if (AnimationGroup == PeepAnimationGroup::Normal)
@@ -5739,8 +5736,7 @@ void Guest::UpdateEnteringPark()
{
if (Var37 != 1)
{
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if ((pathingResult & PATHING_OUTSIDE_PARK))
{
DecrementGuestsHeadingForPark();
@@ -5771,8 +5767,7 @@ void Guest::UpdateLeavingPark()
{
if (Var37 != 0)
{
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_OUTSIDE_PARK))
return;
PeepEntityRemove(this);
@@ -5795,8 +5790,7 @@ void Guest::UpdateLeavingPark()
auto* windowMgr = Ui::GetWindowManager();
windowMgr->InvalidateByClass(WindowClass::GuestList);
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_OUTSIDE_PARK))
return;
Remove();
@@ -5812,8 +5806,8 @@ void Guest::UpdateWatching()
{
if (!CheckForPath())
return;
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_DESTINATION_REACHED))
return;
@@ -5909,8 +5903,7 @@ void Guest::UpdateUsingBin()
if (!CheckForPath())
return;
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (pathingResult & PATHING_DESTINATION_REACHED)
{
UsingBinSubState = PeepUsingBinSubState::GoingBack;

View File

@@ -2442,19 +2442,15 @@ static bool PeepInteractWithShop(Peep* peep, const CoordsXYE& coords)
return true;
}
void Peep::PerformNextAction(uint8_t& pathing_result)
{
TileElement* tmpTile;
PerformNextAction(pathing_result, tmpTile);
}
/**
*
* rct2: 0x00693C9E
*/
void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
std::pair<uint8_t, TileElement*> Peep::PerformNextAction()
{
pathing_result = 0;
uint8_t pathingResult = 0;
TileElement* tileResult = nullptr;
PeepActionType previousAction = Action;
if (Action == PeepActionType::Idle)
@@ -2464,13 +2460,15 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
if (State == PeepState::Queuing && guest != nullptr)
{
if (guest->UpdateQueuePosition(previousAction))
return;
{
return { pathingResult, tileResult };
}
}
std::optional<CoordsXY> loc;
if (loc = UpdateAction(); !loc.has_value())
{
pathing_result |= PATHING_DESTINATION_REACHED;
pathingResult |= PATHING_DESTINATION_REACHED;
uint8_t result = 0;
if (guest != nullptr)
@@ -2484,10 +2482,10 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
}
if (result != 0)
return;
return { pathingResult, tileResult };
if (loc = UpdateAction(); !loc.has_value())
return;
return { pathingResult, tileResult };
}
auto newLoc = *loc;
@@ -2496,22 +2494,23 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
{
int16_t height = GetZOnSlope(newLoc.x, newLoc.y);
MoveTo({ newLoc.x, newLoc.y, height });
return;
return { pathingResult, tileResult };
}
if (MapIsEdge(newLoc))
{
if (guest != nullptr && guest->OutsideOfPark)
{
pathing_result |= PATHING_OUTSIDE_PARK;
pathingResult |= PATHING_OUTSIDE_PARK;
}
PeepReturnToCentreOfTile(this);
return;
return { pathingResult, tileResult };
}
TileElement* tileElement = MapGetFirstElementAt(newLoc);
if (tileElement == nullptr)
return;
return { pathingResult, tileResult };
int16_t base_z = std::max(0, (z / 8) - 2);
int16_t top_z = (z / 8) + 1;
@@ -2527,24 +2526,25 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
if (tileElement->GetType() == TileElementType::Path)
{
PeepInteractWithPath(this, { newLoc, tileElement });
tile_result = tileElement;
return;
tileResult = tileElement;
return { pathingResult, tileResult };
}
if (tileElement->GetType() == TileElementType::Track)
{
if (PeepInteractWithShop(this, { newLoc, tileElement }))
{
tile_result = tileElement;
return;
tileResult = tileElement;
return { pathingResult, tileResult };
}
}
else if (tileElement->GetType() == TileElementType::Entrance)
{
if (PeepInteractWithEntrance(this, { newLoc, tileElement }, pathing_result))
if (PeepInteractWithEntrance(this, { newLoc, tileElement }, pathingResult))
{
tile_result = tileElement;
return;
tileResult = tileElement;
return { pathingResult, tileResult };
}
}
} while (!(tileElement++)->IsLastForTile());
@@ -2564,21 +2564,21 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
if (!MapIsLocationInPark(newLoc))
{
PeepReturnToCentreOfTile(this);
return;
return { pathingResult, tileResult };
}
auto surfaceElement = MapGetSurfaceElementAt(newLoc);
if (surfaceElement == nullptr)
{
PeepReturnToCentreOfTile(this);
return;
return { pathingResult, tileResult };
}
int16_t water_height = surfaceElement->GetWaterHeight();
if (water_height > 0)
{
PeepReturnToCentreOfTile(this);
return;
return { pathingResult, tileResult };
}
auto* staff = As<Staff>();
@@ -2588,7 +2588,7 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
if (!((staff->StaffOrders & STAFF_ORDERS_MOWING) && staff->StaffMowingTimeout >= 12))
{
PeepReturnToCentreOfTile(staff);
return;
return { pathingResult, tileResult };
}
}
@@ -2598,11 +2598,12 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
height = GetZOnSlope(newLoc.x, newLoc.y);
MoveTo({ newLoc.x, newLoc.y, height });
return;
return { pathingResult, tileResult };
}
}
PeepReturnToCentreOfTile(this);
return { pathingResult, tileResult };
}
/**

View File

@@ -20,6 +20,7 @@
#include <optional>
#include <string>
#include <string_view>
#include <utility>
constexpr uint8_t kPeepMinEnergy = 32;
constexpr uint8_t kPeepMaxEnergy = 128;
@@ -402,8 +403,7 @@ public: // Peep
bool ShouldWaitForLevelCrossing();
bool IsOnLevelCrossing();
bool IsOnPathBlockedByVehicle();
void PerformNextAction(uint8_t& pathing_result);
void PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result);
std::pair<uint8_t, TileElement*> PerformNextAction();
[[nodiscard]] int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y);
void SwitchNextAnimationType();
[[nodiscard]] PeepAnimationType GetAnimationType();

View File

@@ -1053,8 +1053,7 @@ void Staff::UpdateWatering()
if (!CheckForPath())
return;
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_DESTINATION_REACHED))
return;
@@ -1117,8 +1116,7 @@ void Staff::UpdateEmptyingBin()
if (!CheckForPath())
return;
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_DESTINATION_REACHED))
return;
@@ -1273,10 +1271,7 @@ void Staff::UpdateHeadingToInspect()
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
return;
uint8_t pathingResult;
TileElement* rideEntranceExitElement;
PerformNextAction(pathingResult, rideEntranceExitElement);
const auto [pathingResult, rideEntranceExitElement] = PerformNextAction();
if (!(pathingResult & PATHING_RIDE_EXIT) && !(pathingResult & PATHING_RIDE_ENTRANCE))
{
return;
@@ -1381,10 +1376,7 @@ void Staff::UpdateAnswering()
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
return;
uint8_t pathingResult;
TileElement* rideEntranceExitElement;
PerformNextAction(pathingResult, rideEntranceExitElement);
const auto [pathingResult, rideEntranceExitElement] = PerformNextAction();
if (!(pathingResult & PATHING_RIDE_EXIT) && !(pathingResult & PATHING_RIDE_ENTRANCE))
{
return;
@@ -1719,8 +1711,7 @@ void Staff::UpdatePatrolling()
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
return;
uint8_t pathingResult;
PerformNextAction(pathingResult);
const auto [pathingResult, _] = PerformNextAction();
if (!(pathingResult & PATHING_DESTINATION_REACHED))
return;

View File

@@ -108,8 +108,7 @@ protected:
int step = 0;
while (!(*pos == goal) && step < expectedSteps)
{
uint8_t pathingResult = 0;
peep->PerformNextAction(pathingResult);
peep->PerformNextAction();
++step;
*pos = TileCoordsXYZ(peep->GetLocation());