Remove AsGuest and AsStaff duplicated functions

This commit is contained in:
Duncan authored and GitHub committed 2021-02-21 13:23:31 +01:00
1 parent 3f8386e122
commit 2b26e423e4
11 files changed
+33 -53

No files matched your search

+1 -1
View File
@@ -4130,7 +4130,7 @@ static void window_ride_maintenance_paint(rct_window* w, rct_drawpixelinfo* dpi)
for (auto peep : EntityList<Staff>(EntityListId::Peep))
{
if (peep->AssignedStaffType == StaffType::Mechanic)
if (peep->IsMechanic())
{
stringId = STR_CALLING_MECHANIC;
break;
+1 -1
View File
@@ -571,7 +571,7 @@ private:
{
continue;
}
if (!peep->AsStaff()->IsLocationInPatrol(footpathCoords))
if (!peep->IsLocationInPatrol(footpathCoords))
{
continue;
}
+1 -1
View File
@@ -211,7 +211,7 @@ GameActions::Result::Ptr StaffHireNewAction::QueryExecute(bool execute) const
}
// Staff uses this
newPeep->AsStaff()->SetHireDate(gDateMonthsElapsed);
newPeep->As<Staff>()->SetHireDate(gDateMonthsElapsed);
newPeep->PathfindGoal.x = 0xFF;
newPeep->PathfindGoal.y = 0xFF;
newPeep->PathfindGoal.z = 0xFF;
+4 -8
View File
@@ -254,16 +254,12 @@ void Guest::ApplyEasterEggToNearbyGuests(easter_egg_function easter_egg)
if (!GuestHasValidXY())
return;
for (auto otherPeep : EntityTileList<Peep>({ x, y }))
for (auto* otherGuest : EntityTileList<Guest>({ x, y }))
{
auto otherGuest = otherPeep->AsGuest();
if (otherGuest)
auto zDiff = std::abs(otherGuest->z - z);
if (zDiff <= 32)
{
auto zDiff = std::abs(otherPeep->z - z);
if (zDiff <= 32)
{
(*this.*easter_egg)(otherGuest);
}
(*this.*easter_egg)(otherGuest);
}
}
}
+6 -5
View File
@@ -712,9 +712,10 @@ static void peep_pathfind_heuristic_search(
}
bool nextInPatrolArea = inPatrolArea;
if (peep->AssignedPeepType == PeepType::Staff && peep->AssignedStaffType == StaffType::Mechanic)
auto* staff = peep->As<Staff>();
if (staff != nullptr && staff->IsMechanic())
{
nextInPatrolArea = peep->AsStaff()->IsLocationInPatrol(loc.ToCoordsXY());
nextInPatrolArea = staff->IsLocationInPatrol(loc.ToCoordsXY());
if (inPatrolArea && !nextInPatrolArea)
{
/* The mechanic will leave his patrol area by taking
@@ -823,7 +824,6 @@ static void peep_pathfind_heuristic_search(
if (tileElement->AsPath()->IsWide())
{
/* Check if staff can ignore this wide flag. */
const Staff* staff = peep->As<Staff>();
if (staff == nullptr || !staff->CanIgnoreWideFlag(loc.ToCoordsXYZ(), tileElement))
{
searchResult = PATH_SEARCH_WIDE;
@@ -1497,12 +1497,13 @@ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep)
uint8_t endDirectionList[16] = { 0 };
bool inPatrolArea = false;
if (peep->AssignedPeepType == PeepType::Staff && peep->AssignedStaffType == StaffType::Mechanic)
auto* staff = peep->As<Staff>();
if (staff != nullptr && staff->IsMechanic())
{
/* Mechanics are the only staff type that
* pathfind to a destination. Determine if the
* mechanic is in their patrol area. */
inPatrolArea = peep->AsStaff()->IsLocationInPatrol(peep->NextLoc);
inPatrolArea = staff->IsLocationInPatrol(peep->NextLoc);
}
#if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2
+14 -24
View File
@@ -321,16 +321,6 @@ template<> bool SpriteBase::Is<Peep>() const
return sprite_identifier == SpriteIdentifier::Peep;
}
Guest* Peep::AsGuest()
{
return AssignedPeepType == PeepType::Guest ? static_cast<Guest*>(this) : nullptr;
}
Staff* Peep::AsStaff()
{
return AssignedPeepType == PeepType::Staff ? static_cast<Staff*>(this) : nullptr;
}
uint8_t Peep::GetNextDirection() const
{
return NextFlags & PEEP_NEXT_FLAG_DIRECTION_MASK;
@@ -457,14 +447,14 @@ void peep_update_all()
*/
static void peep_128_tick_update(Peep* peep, int32_t index)
{
auto guest = peep->AsGuest();
auto* guest = peep->As<Guest>();
if (guest != nullptr)
{
guest->Tick128UpdateGuest(index);
}
else
{
auto staff = peep->AsStaff();
auto* staff = peep->As<Staff>();
if (staff != nullptr)
{
staff->Tick128UpdateStaff();
@@ -744,7 +734,7 @@ void peep_window_state_update(Peep* peep)
void Peep::Pickup()
{
auto guest = AsGuest();
auto* guest = As<Guest>();
if (guest != nullptr)
{
guest->RemoveFromRide();
@@ -839,7 +829,7 @@ std::unique_ptr<GameActions::Result> Peep::Place(const TileCoordsXYZ& location,
*/
void peep_sprite_remove(Peep* peep)
{
auto guest = peep->AsGuest();
auto* guest = peep->As<Guest>();
if (guest != nullptr)
{
guest->RemoveFromRide();
@@ -953,7 +943,7 @@ void Peep::UpdateFalling()
// Looks like we are drowning!
MoveTo({ x, y, height });
auto guest = AsGuest();
auto* guest = As<Guest>();
if (guest != nullptr)
{
// Drop balloon if held
@@ -1149,7 +1139,7 @@ void Peep::Update()
StepProgress = carryCheck;
if (carryCheck <= 255)
{
auto guest = AsGuest();
auto* guest = As<Guest>();
if (guest != nullptr)
{
guest->UpdateEasterEggInteractions();
@@ -1174,14 +1164,14 @@ void Peep::Update()
break;
default:
{
auto guest = AsGuest();
auto* guest = As<Guest>();
if (guest != nullptr)
{
guest->UpdateGuest();
}
else
{
auto staff = AsStaff();
auto* staff = As<Staff>();
if (staff != nullptr)
{
staff->UpdateStaff(stepsToTake);
@@ -2340,7 +2330,7 @@ static bool peep_interact_with_entrance(Peep* peep, const CoordsXYE& coords, uin
if (ride == nullptr)
return false;
auto guest = peep->AsGuest();
auto* guest = peep->As<Guest>();
if (guest == nullptr)
{
// Default staff behaviour attempting to enter a
@@ -2413,7 +2403,7 @@ static bool peep_interact_with_entrance(Peep* peep, const CoordsXYE& coords, uin
else
{
// PARK_ENTRANCE
auto guest = peep->AsGuest();
auto* guest = peep->As<Guest>();
if (guest == nullptr)
{
// Staff cannot leave the park, so go back.
@@ -2771,7 +2761,7 @@ static void peep_interact_with_path(Peep* peep, const CoordsXYE& coords)
}
}
auto guest = peep->AsGuest();
auto* guest = peep->As<Guest>();
if (guest != nullptr && tile_element->AsPath()->IsQueue())
{
auto rideIndex = tile_element->AsPath()->GetRideIndex();
@@ -2879,7 +2869,7 @@ static bool peep_interact_with_shop(Peep* peep, const CoordsXYE& coords)
if (ride == nullptr || !ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP))
return false;
auto guest = peep->AsGuest();
auto* guest = peep->As<Guest>();
if (guest == nullptr)
{
peep_return_to_centre_of_tile(peep);
@@ -3000,14 +2990,14 @@ void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
pathing_result |= PATHING_DESTINATION_REACHED;
uint8_t result = 0;
auto guest = AsGuest();
auto* guest = As<Guest>();
if (guest != nullptr)
{
result = guest_path_finding(guest);
}
else
{
auto staff = AsStaff();
auto* staff = As<Staff>();
result = staff->DoPathFinding();
}
-3
View File
@@ -728,9 +728,6 @@ struct Peep : SpriteBase
uint64_t ItemFlags;
public: // Peep
Guest* AsGuest();
Staff* AsStaff();
void Update();
std::optional<CoordsXY> UpdateAction(int16_t& xy_distance);
std::optional<CoordsXY> UpdateAction();
+1 -3
View File
@@ -1820,9 +1820,7 @@ void Staff::Tick128UpdateStaff()
bool Staff::IsMechanic() const
{
return (
sprite_identifier == SpriteIdentifier::Peep && AssignedPeepType == PeepType::Staff
&& AssignedStaffType == StaffType::Mechanic);
return AssignedStaffType == StaffType::Mechanic;
}
void Staff::UpdateStaff(uint32_t stepsToTake)
+2 -2
View File
@@ -2730,7 +2730,7 @@ Peep* find_closest_mechanic(const CoordsXY& entrancePosition, int32_t forInspect
for (auto peep : EntityList<Staff>(EntityListId::Peep))
{
if (peep->AssignedStaffType != StaffType::Mechanic)
if (!peep->IsMechanic())
continue;
if (!forInspection)
@@ -2754,7 +2754,7 @@ Peep* find_closest_mechanic(const CoordsXY& entrancePosition, int32_t forInspect
auto location = entrancePosition.ToTileStart();
if (map_is_location_in_park(location))
if (!peep->AsStaff()->IsLocationInPatrol(location))
if (!peep->IsLocationInPatrol(location))
continue;
if (peep->x == LOCATION_NULL)
+1 -3
View File
@@ -280,11 +280,9 @@ static void ride_race_init_vehicle_speeds(Ride* ride)
if (vehicle->num_peeps != 0)
{
auto peep = GetEntity<Peep>(vehicle->peep[0]);
auto* guest = GetEntity<Guest>(vehicle->peep[0]);
// Easter egg names should only work on guests
Guest* guest = peep->AsGuest();
if (guest != nullptr)
{
switch (guest->GetEasterEggNameId())
+2 -2
View File
@@ -834,7 +834,7 @@ namespace OpenRCT2::Scripting
auto peep = GetPeep();
if (peep != nullptr)
{
return peep->AsGuest();
return peep->As<Guest>();
}
return nullptr;
}
@@ -1123,7 +1123,7 @@ namespace OpenRCT2::Scripting
auto peep = GetPeep();
if (peep != nullptr)
{
return peep->AsStaff();
return peep->As<Staff>();
}
return nullptr;
}