mirror of https://github.com/OpenRCT2/OpenRCT2.git
Peep: split off UpdateWalkingAction, ThrowUp from UpdateAction
This commit is contained in:
parent
d35d08e86a
commit
f5f31496db
|
@ -417,43 +417,10 @@ std::optional<CoordsXY> 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<CoordsXY> 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<Guest>();
|
||||
// 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<CoordsXY> 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>();
|
||||
guest->Hunger /= 2;
|
||||
guest->NauseaTarget /= 2;
|
||||
|
||||
|
@ -498,8 +518,6 @@ std::optional<CoordsXY> Peep::UpdateAction(int16_t& xy_distance)
|
|||
};
|
||||
auto soundId = coughs[ScenarioRand() & 3];
|
||||
OpenRCT2::Audio::Play3D(soundId, curLoc);
|
||||
|
||||
return { { x, y } };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -376,6 +376,8 @@ public: // Peep
|
|||
void Update();
|
||||
std::optional<CoordsXY> UpdateAction(int16_t& xy_distance);
|
||||
std::optional<CoordsXY> UpdateAction();
|
||||
std::optional<CoordsXY> UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance);
|
||||
void ThrowUp();
|
||||
void SetState(PeepState new_state);
|
||||
void Remove();
|
||||
void UpdateCurrentActionSpriteType();
|
||||
|
|
Loading…
Reference in New Issue