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

Remove code duplication for stepping

This commit is contained in:
ζeh Matt
2025-05-21 17:28:05 +03:00
parent db23e69597
commit 04c75f6f8b
4 changed files with 34 additions and 40 deletions

View File

@@ -5299,24 +5299,10 @@ void Guest::Update()
GuestUpdateThoughts(this); GuestUpdateThoughts(this);
// Walking speed logic // Walking speed logic
uint32_t stepsToTake = Energy; const auto stepsToTake = GetStepsToTake();
if (stepsToTake < 95 && State == PeepState::Queuing) const auto carryCheck = StepProgress + stepsToTake;
stepsToTake = 95;
if ((PeepFlags & PEEP_FLAGS_SLOW_WALK) && State != PeepState::Queuing)
stepsToTake /= 2;
if (IsActionWalking() && GetNextIsSloped())
{
stepsToTake /= 2;
if (State == PeepState::Queuing)
stepsToTake += stepsToTake / 2;
}
// Ensure guests make it across a level crossing in time
constexpr auto minStepsForCrossing = 55;
if (stepsToTake < minStepsForCrossing && IsOnPathBlockedByVehicle())
stepsToTake = minStepsForCrossing;
uint32_t carryCheck = StepProgress + stepsToTake;
StepProgress = carryCheck; StepProgress = carryCheck;
if (carryCheck <= 255) if (carryCheck <= 255)
{ {
UpdateEasterEggInteractions(); UpdateEasterEggInteractions();

View File

@@ -300,7 +300,7 @@ bool Peep::CheckForPath()
return false; return false;
} }
bool Peep::ShouldWaitForLevelCrossing() bool Peep::ShouldWaitForLevelCrossing() const
{ {
if (IsOnPathBlockedByVehicle()) if (IsOnPathBlockedByVehicle())
{ {
@@ -318,13 +318,13 @@ bool Peep::ShouldWaitForLevelCrossing()
return false; return false;
} }
bool Peep::IsOnLevelCrossing() bool Peep::IsOnLevelCrossing() const
{ {
auto trackElement = MapGetTrackElementAt(GetLocation()); auto trackElement = MapGetTrackElementAt(GetLocation());
return trackElement != nullptr; return trackElement != nullptr;
} }
bool Peep::IsOnPathBlockedByVehicle() bool Peep::IsOnPathBlockedByVehicle() const
{ {
auto curPos = TileCoordsXYZ(GetLocation()); auto curPos = TileCoordsXYZ(GetLocation());
return FootpathIsBlockedByVehicle(curPos); return FootpathIsBlockedByVehicle(curPos);
@@ -928,6 +928,27 @@ void Peep::UpdatePicked()
} }
} }
uint32_t Peep::GetStepsToTake() const
{
uint32_t stepsToTake = Energy;
if (stepsToTake < 95 && State == PeepState::Queuing)
stepsToTake = 95;
if ((PeepFlags & PEEP_FLAGS_SLOW_WALK) && State != PeepState::Queuing)
stepsToTake /= 2;
if (IsActionWalking() && GetNextIsSloped())
{
stepsToTake /= 2;
if (State == PeepState::Queuing)
stepsToTake += stepsToTake / 2;
}
// Ensure guests make it across a level crossing in time
constexpr auto minStepsForCrossing = 55;
if (stepsToTake < minStepsForCrossing && IsOnPathBlockedByVehicle())
stepsToTake = minStepsForCrossing;
return stepsToTake;
}
/** /**
* *
* rct2: 0x0069BF41 * rct2: 0x0069BF41

View File

@@ -399,9 +399,9 @@ public: // Peep
// TODO: Make these private again when done refactoring // TODO: Make these private again when done refactoring
public: // Peep public: // Peep
[[nodiscard]] bool CheckForPath(); [[nodiscard]] bool CheckForPath();
bool ShouldWaitForLevelCrossing(); bool ShouldWaitForLevelCrossing() const;
bool IsOnLevelCrossing(); bool IsOnLevelCrossing() const;
bool IsOnPathBlockedByVehicle(); bool IsOnPathBlockedByVehicle() const;
std::pair<uint8_t, TileElement*> PerformNextAction(); std::pair<uint8_t, TileElement*> PerformNextAction();
[[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();
@@ -411,6 +411,7 @@ protected:
void UpdateFalling(); void UpdateFalling();
void Update1(); void Update1();
void UpdatePicked(); void UpdatePicked();
uint32_t GetStepsToTake() const;
}; };
enum enum

View File

@@ -1707,24 +1707,10 @@ void Staff::Update()
} }
// Walking speed logic // Walking speed logic
uint32_t stepsToTake = Energy; const auto stepsToTake = GetStepsToTake();
if (stepsToTake < 95 && State == PeepState::Queuing) const auto carryCheck = StepProgress + stepsToTake;
stepsToTake = 95;
if ((PeepFlags & PEEP_FLAGS_SLOW_WALK) && State != PeepState::Queuing)
stepsToTake /= 2;
if (IsActionWalking() && GetNextIsSloped())
{
stepsToTake /= 2;
if (State == PeepState::Queuing)
stepsToTake += stepsToTake / 2;
}
// Ensure guests make it across a level crossing in time
constexpr auto minStepsForCrossing = 55;
if (stepsToTake < minStepsForCrossing && IsOnPathBlockedByVehicle())
stepsToTake = minStepsForCrossing;
uint32_t carryCheck = StepProgress + stepsToTake;
StepProgress = carryCheck; StepProgress = carryCheck;
if (carryCheck <= 255) if (carryCheck <= 255)
{ {
// No-op: Keep replay working for now, can be eliminate with a replay update. // No-op: Keep replay working for now, can be eliminate with a replay update.