1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-18 21:43:48 +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);
// Walking speed logic
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;
uint32_t carryCheck = StepProgress + stepsToTake;
const auto stepsToTake = GetStepsToTake();
const auto carryCheck = StepProgress + stepsToTake;
StepProgress = carryCheck;
if (carryCheck <= 255)
{
UpdateEasterEggInteractions();

View File

@@ -300,7 +300,7 @@ bool Peep::CheckForPath()
return false;
}
bool Peep::ShouldWaitForLevelCrossing()
bool Peep::ShouldWaitForLevelCrossing() const
{
if (IsOnPathBlockedByVehicle())
{
@@ -318,13 +318,13 @@ bool Peep::ShouldWaitForLevelCrossing()
return false;
}
bool Peep::IsOnLevelCrossing()
bool Peep::IsOnLevelCrossing() const
{
auto trackElement = MapGetTrackElementAt(GetLocation());
return trackElement != nullptr;
}
bool Peep::IsOnPathBlockedByVehicle()
bool Peep::IsOnPathBlockedByVehicle() const
{
auto curPos = TileCoordsXYZ(GetLocation());
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

View File

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

View File

@@ -1707,24 +1707,10 @@ void Staff::Update()
}
// Walking speed logic
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;
uint32_t carryCheck = StepProgress + stepsToTake;
const auto stepsToTake = GetStepsToTake();
const auto carryCheck = StepProgress + stepsToTake;
StepProgress = carryCheck;
if (carryCheck <= 255)
{
// No-op: Keep replay working for now, can be eliminate with a replay update.