diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 6dada3246a..985a68e87b 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -417,43 +417,10 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) xy_distance = x_delta + y_delta; + // We're taking an easier route if we're just walking if (IsActionWalking()) { - if (xy_distance <= DestinationTolerance) - { - return std::nullopt; - } - int32_t nextDirection = 0; - if (x_delta < y_delta) - { - nextDirection = 8; - if (differenceLoc.y >= 0) - { - nextDirection = 24; - } - } - else - { - nextDirection = 16; - if (differenceLoc.x >= 0) - { - nextDirection = 0; - } - } - - Orientation = nextDirection; - CoordsXY loc = { x, y }; - loc += word_981D7C[nextDirection / 8]; - - WalkingFrameNum++; - const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType); - if (WalkingFrameNum >= peepAnimation.frame_offsets.size()) - { - WalkingFrameNum = 0; - } - ActionSpriteImageOffset = peepAnimation.frame_offsets[WalkingFrameNum]; - - return loc; + return UpdateWalkingAction(differenceLoc, xy_distance); } const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType); @@ -469,14 +436,67 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) } ActionSpriteImageOffset = peepAnimation.frame_offsets[ActionFrame]; + // Should we throw up, and are we at the frame where sick appears? auto* guest = As(); - // If not throwing up and not at the frame where sick appears. - if (Action != PeepActionType::ThrowUp || ActionFrame != 15 || guest == nullptr) + if (Action == PeepActionType::ThrowUp && ActionFrame == 15 && guest != nullptr) { - return { { x, y } }; + ThrowUp(); } - // We are throwing up + return { { x, y } }; +} + +std::optional Peep::UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance) +{ + if (!IsActionWalking()) + { + return std::nullopt; + } + + if (xy_distance <= DestinationTolerance) + { + return std::nullopt; + } + + int32_t x_delta = abs(differenceLoc.x); + int32_t y_delta = abs(differenceLoc.y); + + int32_t nextDirection = 0; + if (x_delta < y_delta) + { + nextDirection = 8; + if (differenceLoc.y >= 0) + { + nextDirection = 24; + } + } + else + { + nextDirection = 16; + if (differenceLoc.x >= 0) + { + nextDirection = 0; + } + } + + Orientation = nextDirection; + CoordsXY loc = { x, y }; + loc += word_981D7C[nextDirection / 8]; + + WalkingFrameNum++; + const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType); + if (WalkingFrameNum >= peepAnimation.frame_offsets.size()) + { + WalkingFrameNum = 0; + } + ActionSpriteImageOffset = peepAnimation.frame_offsets[WalkingFrameNum]; + + return loc; +} + +void Peep::ThrowUp() +{ + auto* guest = As(); guest->Hunger /= 2; guest->NauseaTarget /= 2; @@ -498,8 +518,6 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) }; auto soundId = coughs[ScenarioRand() & 3]; OpenRCT2::Audio::Play3D(soundId, curLoc); - - return { { x, y } }; } /** diff --git a/src/openrct2/entity/Peep.h b/src/openrct2/entity/Peep.h index fd05a68841..109493088c 100644 --- a/src/openrct2/entity/Peep.h +++ b/src/openrct2/entity/Peep.h @@ -376,6 +376,8 @@ public: // Peep void Update(); std::optional UpdateAction(int16_t& xy_distance); std::optional UpdateAction(); + std::optional UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance); + void ThrowUp(); void SetState(PeepState new_state); void Remove(); void UpdateCurrentActionSpriteType();