diff --git a/src/openrct2/actions/StaffHireNewAction.cpp b/src/openrct2/actions/StaffHireNewAction.cpp index ef580fe771..10a979c03c 100644 --- a/src/openrct2/actions/StaffHireNewAction.cpp +++ b/src/openrct2/actions/StaffHireNewAction.cpp @@ -26,6 +26,8 @@ #include "../world/Entrance.h" #include "../world/Park.h" +#include + /* rct2: 0x009929FC */ static constexpr const PeepSpriteType spriteTypes[] = { PeepSpriteType::Handyman, @@ -142,25 +144,20 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const newPeep->StaffOrders = _staffOrders; // We search for the first available Id for a given staff type - uint32_t newStaffId = 0; - for (;;) + std::set usedStaffIds; + + for (auto searchPeep : EntityList()) { - bool found = false; - ++newStaffId; - for (auto searchPeep : EntityList()) - { - if (static_cast(searchPeep->AssignedStaffType) != _staffType) - continue; + if (static_cast(searchPeep->AssignedStaffType) != _staffType) + continue; - if (searchPeep->PeepId == newStaffId) - { - found = true; - break; - } - } + usedStaffIds.insert(searchPeep->PeepId); + } - if (!found) - break; + uint32_t newStaffId = 1; + while (usedStaffIds.find(newStaffId) != usedStaffIds.end()) + { + newStaffId++; } newPeep->PeepId = newStaffId;