mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Refactor PerformNextAction, we don't need a wrapper
This commit is contained in:
@@ -1281,8 +1281,7 @@ void Guest::UpdateSitting()
|
|||||||
return;
|
return;
|
||||||
// 691541
|
// 691541
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -5425,8 +5424,7 @@ void Guest::UpdateWalking()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -5660,8 +5658,7 @@ void Guest::UpdateQueuing()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t pathingResult;
|
PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!IsActionInterruptable())
|
if (!IsActionInterruptable())
|
||||||
return;
|
return;
|
||||||
if (AnimationGroup == PeepAnimationGroup::Normal)
|
if (AnimationGroup == PeepAnimationGroup::Normal)
|
||||||
@@ -5739,8 +5736,7 @@ void Guest::UpdateEnteringPark()
|
|||||||
{
|
{
|
||||||
if (Var37 != 1)
|
if (Var37 != 1)
|
||||||
{
|
{
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if ((pathingResult & PATHING_OUTSIDE_PARK))
|
if ((pathingResult & PATHING_OUTSIDE_PARK))
|
||||||
{
|
{
|
||||||
DecrementGuestsHeadingForPark();
|
DecrementGuestsHeadingForPark();
|
||||||
@@ -5771,8 +5767,7 @@ void Guest::UpdateLeavingPark()
|
|||||||
{
|
{
|
||||||
if (Var37 != 0)
|
if (Var37 != 0)
|
||||||
{
|
{
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_OUTSIDE_PARK))
|
if (!(pathingResult & PATHING_OUTSIDE_PARK))
|
||||||
return;
|
return;
|
||||||
PeepEntityRemove(this);
|
PeepEntityRemove(this);
|
||||||
@@ -5795,8 +5790,7 @@ void Guest::UpdateLeavingPark()
|
|||||||
auto* windowMgr = Ui::GetWindowManager();
|
auto* windowMgr = Ui::GetWindowManager();
|
||||||
windowMgr->InvalidateByClass(WindowClass::GuestList);
|
windowMgr->InvalidateByClass(WindowClass::GuestList);
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_OUTSIDE_PARK))
|
if (!(pathingResult & PATHING_OUTSIDE_PARK))
|
||||||
return;
|
return;
|
||||||
Remove();
|
Remove();
|
||||||
@@ -5812,8 +5806,8 @@ void Guest::UpdateWatching()
|
|||||||
{
|
{
|
||||||
if (!CheckForPath())
|
if (!CheckForPath())
|
||||||
return;
|
return;
|
||||||
uint8_t pathingResult;
|
|
||||||
PerformNextAction(pathingResult);
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -5909,8 +5903,7 @@ void Guest::UpdateUsingBin()
|
|||||||
if (!CheckForPath())
|
if (!CheckForPath())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (pathingResult & PATHING_DESTINATION_REACHED)
|
if (pathingResult & PATHING_DESTINATION_REACHED)
|
||||||
{
|
{
|
||||||
UsingBinSubState = PeepUsingBinSubState::GoingBack;
|
UsingBinSubState = PeepUsingBinSubState::GoingBack;
|
||||||
|
|||||||
@@ -2442,19 +2442,15 @@ static bool PeepInteractWithShop(Peep* peep, const CoordsXYE& coords)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peep::PerformNextAction(uint8_t& pathing_result)
|
|
||||||
{
|
|
||||||
TileElement* tmpTile;
|
|
||||||
PerformNextAction(pathing_result, tmpTile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* rct2: 0x00693C9E
|
* 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;
|
PeepActionType previousAction = Action;
|
||||||
|
|
||||||
if (Action == PeepActionType::Idle)
|
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 (State == PeepState::Queuing && guest != nullptr)
|
||||||
{
|
{
|
||||||
if (guest->UpdateQueuePosition(previousAction))
|
if (guest->UpdateQueuePosition(previousAction))
|
||||||
return;
|
{
|
||||||
|
return { pathingResult, tileResult };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<CoordsXY> loc;
|
std::optional<CoordsXY> loc;
|
||||||
if (loc = UpdateAction(); !loc.has_value())
|
if (loc = UpdateAction(); !loc.has_value())
|
||||||
{
|
{
|
||||||
pathing_result |= PATHING_DESTINATION_REACHED;
|
pathingResult |= PATHING_DESTINATION_REACHED;
|
||||||
uint8_t result = 0;
|
uint8_t result = 0;
|
||||||
|
|
||||||
if (guest != nullptr)
|
if (guest != nullptr)
|
||||||
@@ -2484,10 +2482,10 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
|
|
||||||
if (loc = UpdateAction(); !loc.has_value())
|
if (loc = UpdateAction(); !loc.has_value())
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto newLoc = *loc;
|
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);
|
int16_t height = GetZOnSlope(newLoc.x, newLoc.y);
|
||||||
MoveTo({ newLoc.x, newLoc.y, height });
|
MoveTo({ newLoc.x, newLoc.y, height });
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MapIsEdge(newLoc))
|
if (MapIsEdge(newLoc))
|
||||||
{
|
{
|
||||||
if (guest != nullptr && guest->OutsideOfPark)
|
if (guest != nullptr && guest->OutsideOfPark)
|
||||||
{
|
{
|
||||||
pathing_result |= PATHING_OUTSIDE_PARK;
|
pathingResult |= PATHING_OUTSIDE_PARK;
|
||||||
}
|
}
|
||||||
PeepReturnToCentreOfTile(this);
|
PeepReturnToCentreOfTile(this);
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
TileElement* tileElement = MapGetFirstElementAt(newLoc);
|
TileElement* tileElement = MapGetFirstElementAt(newLoc);
|
||||||
if (tileElement == nullptr)
|
if (tileElement == nullptr)
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
|
|
||||||
int16_t base_z = std::max(0, (z / 8) - 2);
|
int16_t base_z = std::max(0, (z / 8) - 2);
|
||||||
int16_t top_z = (z / 8) + 1;
|
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)
|
if (tileElement->GetType() == TileElementType::Path)
|
||||||
{
|
{
|
||||||
PeepInteractWithPath(this, { newLoc, tileElement });
|
PeepInteractWithPath(this, { newLoc, tileElement });
|
||||||
tile_result = tileElement;
|
tileResult = tileElement;
|
||||||
return;
|
|
||||||
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tileElement->GetType() == TileElementType::Track)
|
if (tileElement->GetType() == TileElementType::Track)
|
||||||
{
|
{
|
||||||
if (PeepInteractWithShop(this, { newLoc, tileElement }))
|
if (PeepInteractWithShop(this, { newLoc, tileElement }))
|
||||||
{
|
{
|
||||||
tile_result = tileElement;
|
tileResult = tileElement;
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tileElement->GetType() == TileElementType::Entrance)
|
else if (tileElement->GetType() == TileElementType::Entrance)
|
||||||
{
|
{
|
||||||
if (PeepInteractWithEntrance(this, { newLoc, tileElement }, pathing_result))
|
if (PeepInteractWithEntrance(this, { newLoc, tileElement }, pathingResult))
|
||||||
{
|
{
|
||||||
tile_result = tileElement;
|
tileResult = tileElement;
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!(tileElement++)->IsLastForTile());
|
} while (!(tileElement++)->IsLastForTile());
|
||||||
@@ -2564,21 +2564,21 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
|
|||||||
if (!MapIsLocationInPark(newLoc))
|
if (!MapIsLocationInPark(newLoc))
|
||||||
{
|
{
|
||||||
PeepReturnToCentreOfTile(this);
|
PeepReturnToCentreOfTile(this);
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto surfaceElement = MapGetSurfaceElementAt(newLoc);
|
auto surfaceElement = MapGetSurfaceElementAt(newLoc);
|
||||||
if (surfaceElement == nullptr)
|
if (surfaceElement == nullptr)
|
||||||
{
|
{
|
||||||
PeepReturnToCentreOfTile(this);
|
PeepReturnToCentreOfTile(this);
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t water_height = surfaceElement->GetWaterHeight();
|
int16_t water_height = surfaceElement->GetWaterHeight();
|
||||||
if (water_height > 0)
|
if (water_height > 0)
|
||||||
{
|
{
|
||||||
PeepReturnToCentreOfTile(this);
|
PeepReturnToCentreOfTile(this);
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* staff = As<Staff>();
|
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))
|
if (!((staff->StaffOrders & STAFF_ORDERS_MOWING) && staff->StaffMowingTimeout >= 12))
|
||||||
{
|
{
|
||||||
PeepReturnToCentreOfTile(staff);
|
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);
|
height = GetZOnSlope(newLoc.x, newLoc.y);
|
||||||
MoveTo({ newLoc.x, newLoc.y, height });
|
MoveTo({ newLoc.x, newLoc.y, height });
|
||||||
return;
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PeepReturnToCentreOfTile(this);
|
PeepReturnToCentreOfTile(this);
|
||||||
|
return { pathingResult, tileResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
constexpr uint8_t kPeepMinEnergy = 32;
|
constexpr uint8_t kPeepMinEnergy = 32;
|
||||||
constexpr uint8_t kPeepMaxEnergy = 128;
|
constexpr uint8_t kPeepMaxEnergy = 128;
|
||||||
@@ -402,8 +403,7 @@ public: // Peep
|
|||||||
bool ShouldWaitForLevelCrossing();
|
bool ShouldWaitForLevelCrossing();
|
||||||
bool IsOnLevelCrossing();
|
bool IsOnLevelCrossing();
|
||||||
bool IsOnPathBlockedByVehicle();
|
bool IsOnPathBlockedByVehicle();
|
||||||
void PerformNextAction(uint8_t& pathing_result);
|
std::pair<uint8_t, TileElement*> PerformNextAction();
|
||||||
void PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result);
|
|
||||||
[[nodiscard]] int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y);
|
[[nodiscard]] int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y);
|
||||||
void SwitchNextAnimationType();
|
void SwitchNextAnimationType();
|
||||||
[[nodiscard]] PeepAnimationType GetAnimationType();
|
[[nodiscard]] PeepAnimationType GetAnimationType();
|
||||||
|
|||||||
@@ -1053,8 +1053,7 @@ void Staff::UpdateWatering()
|
|||||||
if (!CheckForPath())
|
if (!CheckForPath())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1117,8 +1116,7 @@ void Staff::UpdateEmptyingBin()
|
|||||||
if (!CheckForPath())
|
if (!CheckForPath())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1273,10 +1271,7 @@ void Staff::UpdateHeadingToInspect()
|
|||||||
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
|
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, rideEntranceExitElement] = PerformNextAction();
|
||||||
TileElement* rideEntranceExitElement;
|
|
||||||
PerformNextAction(pathingResult, rideEntranceExitElement);
|
|
||||||
|
|
||||||
if (!(pathingResult & PATHING_RIDE_EXIT) && !(pathingResult & PATHING_RIDE_ENTRANCE))
|
if (!(pathingResult & PATHING_RIDE_EXIT) && !(pathingResult & PATHING_RIDE_ENTRANCE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -1381,10 +1376,7 @@ void Staff::UpdateAnswering()
|
|||||||
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
|
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, rideEntranceExitElement] = PerformNextAction();
|
||||||
TileElement* rideEntranceExitElement;
|
|
||||||
PerformNextAction(pathingResult, rideEntranceExitElement);
|
|
||||||
|
|
||||||
if (!(pathingResult & PATHING_RIDE_EXIT) && !(pathingResult & PATHING_RIDE_ENTRANCE))
|
if (!(pathingResult & PATHING_RIDE_EXIT) && !(pathingResult & PATHING_RIDE_ENTRANCE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -1719,8 +1711,7 @@ void Staff::UpdatePatrolling()
|
|||||||
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
|
if (ShouldWaitForLevelCrossing() && !IsMechanicHeadingToFixRideBlockingPath())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t pathingResult;
|
const auto [pathingResult, _] = PerformNextAction();
|
||||||
PerformNextAction(pathingResult);
|
|
||||||
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
if (!(pathingResult & PATHING_DESTINATION_REACHED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -108,8 +108,7 @@ protected:
|
|||||||
int step = 0;
|
int step = 0;
|
||||||
while (!(*pos == goal) && step < expectedSteps)
|
while (!(*pos == goal) && step < expectedSteps)
|
||||||
{
|
{
|
||||||
uint8_t pathingResult = 0;
|
peep->PerformNextAction();
|
||||||
peep->PerformNextAction(pathingResult);
|
|
||||||
++step;
|
++step;
|
||||||
|
|
||||||
*pos = TileCoordsXYZ(peep->GetLocation());
|
*pos = TileCoordsXYZ(peep->GetLocation());
|
||||||
|
|||||||
Reference in New Issue
Block a user