mirror of https://github.com/OpenRCT2/OpenRCT2.git
Simplify code for Peep easter eggs
This commit is contained in:
parent
5b5aa0771e
commit
751db9f13e
|
@ -47,6 +47,7 @@
|
|||
#include "Staff.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
@ -431,11 +432,11 @@ template<> bool SpriteBase::Is<Guest>() const
|
|||
return Type == EntityType::Guest;
|
||||
}
|
||||
|
||||
bool Guest::GuestHasValidXY() const
|
||||
static bool IsValidLocation(const CoordsXYZ& coords)
|
||||
{
|
||||
if (x != LOCATION_NULL)
|
||||
if (coords.x != LOCATION_NULL)
|
||||
{
|
||||
if (map_is_location_valid({ x, y }))
|
||||
if (map_is_location_valid(coords))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -444,17 +445,23 @@ bool Guest::GuestHasValidXY() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void Guest::ApplyEasterEggToNearbyGuests(easter_egg_function easter_egg)
|
||||
template<void (Guest::*EasterEggFunc)(Guest*)> static void ApplyEasterEggToNearbyGuests(Guest* guest)
|
||||
{
|
||||
if (!GuestHasValidXY())
|
||||
const auto guestLoc = guest->GetLocation();
|
||||
if (!IsValidLocation(guestLoc))
|
||||
return;
|
||||
|
||||
for (auto* otherGuest : EntityTileList<Guest>({ x, y }))
|
||||
for (auto* otherGuest : EntityTileList<Guest>(guestLoc))
|
||||
{
|
||||
auto zDiff = std::abs(otherGuest->z - z);
|
||||
if (otherGuest == guest)
|
||||
{
|
||||
// Can not apply effect on self.
|
||||
continue;
|
||||
}
|
||||
auto zDiff = std::abs(otherGuest->z - guestLoc.z);
|
||||
if (zDiff <= 32)
|
||||
{
|
||||
(*this.*easter_egg)(otherGuest);
|
||||
std::invoke(EasterEggFunc, *guest, otherGuest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -489,8 +496,6 @@ void Guest::GivePassingPeepsPizza(Guest* passingPeep)
|
|||
|
||||
void Guest::MakePassingPeepsSick(Guest* passingPeep)
|
||||
{
|
||||
if (this == passingPeep)
|
||||
return;
|
||||
if (passingPeep->State != PeepState::Walking)
|
||||
return;
|
||||
|
||||
|
@ -505,8 +510,6 @@ void Guest::MakePassingPeepsSick(Guest* passingPeep)
|
|||
|
||||
void Guest::GivePassingPeepsIceCream(Guest* passingPeep)
|
||||
{
|
||||
if (this == passingPeep)
|
||||
return;
|
||||
if (passingPeep->HasItem(ShopItem::IceCream))
|
||||
return;
|
||||
|
||||
|
@ -522,17 +525,22 @@ void Guest::UpdateEasterEggInteractions()
|
|||
{
|
||||
if (PeepFlags & PEEP_FLAGS_PURPLE)
|
||||
{
|
||||
ApplyEasterEggToNearbyGuests(&Guest::GivePassingPeepsPurpleClothes);
|
||||
ApplyEasterEggToNearbyGuests<&Guest::GivePassingPeepsPurpleClothes>(this);
|
||||
}
|
||||
|
||||
if (PeepFlags & PEEP_FLAGS_PIZZA)
|
||||
{
|
||||
ApplyEasterEggToNearbyGuests(&Guest::GivePassingPeepsPizza);
|
||||
ApplyEasterEggToNearbyGuests<&Guest::GivePassingPeepsPizza>(this);
|
||||
}
|
||||
|
||||
if (PeepFlags & PEEP_FLAGS_CONTAGIOUS)
|
||||
{
|
||||
ApplyEasterEggToNearbyGuests(&Guest::MakePassingPeepsSick);
|
||||
ApplyEasterEggToNearbyGuests<&Guest::MakePassingPeepsSick>(this);
|
||||
}
|
||||
|
||||
if (PeepFlags & PEEP_FLAGS_ICE_CREAM)
|
||||
{
|
||||
ApplyEasterEggToNearbyGuests<&Guest::GivePassingPeepsIceCream>(this);
|
||||
}
|
||||
|
||||
if (PeepFlags & PEEP_FLAGS_JOY)
|
||||
|
@ -548,11 +556,6 @@ void Guest::UpdateEasterEggInteractions()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PeepFlags & PEEP_FLAGS_ICE_CREAM)
|
||||
{
|
||||
ApplyEasterEggToNearbyGuests(&Guest::GivePassingPeepsIceCream);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Guest::GetEasterEggNameId() const
|
||||
|
|
|
@ -816,9 +816,7 @@ private:
|
|||
void UpdateRideShopLeave();
|
||||
void loc_68F9F3();
|
||||
void loc_68FA89();
|
||||
using easter_egg_function = void (Guest::*)(Guest* otherGuest);
|
||||
int32_t CheckEasterEggName(int32_t index) const;
|
||||
void ApplyEasterEggToNearbyGuests(easter_egg_function easter_egg);
|
||||
bool GuestHasValidXY() const;
|
||||
void GivePassingPeepsPurpleClothes(Guest* passingPeep);
|
||||
void GivePassingPeepsPizza(Guest* passingPeep);
|
||||
|
|
Loading…
Reference in New Issue