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:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user