diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index ff48a855b3..2ef09a4b68 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1230,7 +1230,8 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, if (peep.type != PEEP_TYPE_STAFF) return; - if (staff_is_patrol_area_set(peep.staff_id, dest_x, dest_y)) + auto staff = peep.AsStaff(); + if (staff->IsPatrolAreaSet({ dest_x, dest_y })) { _staffPatrolAreaPaintValue = PatrolAreaValue::UNSET; } @@ -1271,7 +1272,7 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex, if (peep.type != PEEP_TYPE_STAFF) return; - bool patrolAreaValue = staff_is_patrol_area_set(peep.staff_id, dest_x, dest_y); + bool patrolAreaValue = peep.AsStaff()->IsPatrolAreaSet({ dest_x, dest_y }); if (_staffPatrolAreaPaintValue == PatrolAreaValue::SET && patrolAreaValue) return; // Since area is already the value we want, skip... if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && !patrolAreaValue) diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index fbe017b3a1..dd17572877 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -347,7 +347,7 @@ static void window_staff_list_tooldown(rct_window* w, rct_widgetindex widgetInde if (footpathCoords.isNull()) return; - bool isPatrolAreaSet = staff_is_patrol_area_set(200 + selectedPeepType, footpathCoords.x, footpathCoords.y); + bool isPatrolAreaSet = staff_is_patrol_area_set_for_type(static_cast(selectedPeepType), footpathCoords); uint16_t spriteIndex; Peep *peep, *closestPeep = nullptr; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 394d97e8f0..d405d17692 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -900,15 +900,15 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile if (!is_staff_list) { - Peep* staff = GET_PEEP(staffIndex); - if (!staff_is_patrol_area_set(staff->staff_id, x, y)) + Staff* staff = (GET_PEEP(staffIndex))->AsStaff(); + if (!staff->IsPatrolAreaSet({ x, y })) { patrolColour = COLOUR_GREY; } staffType = staff->staff_type; } - if (staff_is_patrol_area_set(200 + staffType, x, y)) + if (staff_is_patrol_area_set_for_type(static_cast(staffType), session->MapPosition)) { uint32_t imageId = 2618; int32_t patrolAreaBaseZ = tile_element->GetBaseZ(); diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index b0d52bdd15..4b3457a689 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1042,15 +1042,15 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c if (!is_staff_list) { - Peep* staff = GET_PEEP(staffIndex); - if (!staff_is_patrol_area_set(staff->staff_id, x, y)) + Staff* staff = (GET_PEEP(staffIndex))->AsStaff(); + if (!staff->IsPatrolAreaSet({ x, y })) { patrolColour = COLOUR_GREY; } staffType = staff->staff_type; } - if (staff_is_patrol_area_set(200 + staffType, x, y)) + if (staff_is_patrol_area_set_for_type(static_cast(staffType), session->MapPosition)) { assert(surfaceShape < std::size(byte_97B444)); diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 9a7e36f37e..083abac737 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -832,6 +832,7 @@ public: void UpdateStaff(uint32_t stepsToTake); void Tick128UpdateStaff(); bool IsMechanic() const; + bool IsPatrolAreaSet(CoordsXY coords) const; private: void UpdatePatrolling(); diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 5cd1eef056..86bdd06c6c 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -169,14 +169,6 @@ void staff_update_greyed_patrol_areas() } } -static bool staff_is_location_in_patrol_area(Peep* peep, int32_t x, int32_t y) -{ - // Patrol quads are stored in a bit map (8 patrol quads per byte) - // Each patrol quad is 4x4 - // Therefore there are in total 64 x 64 patrol quads in the 256 x 256 map - return staff_is_patrol_area_set(peep->staff_id, x, y); -} - /** * * rct2: 0x006C0905 @@ -191,7 +183,7 @@ bool staff_is_location_in_patrol(Peep* staff, int32_t x, int32_t y) if (!(gStaffModes[staff->staff_id] & 2)) return true; - return staff_is_location_in_patrol_area(staff, x, y); + return staff->AsStaff()->IsPatrolAreaSet({ x, y }); } bool staff_is_location_on_patrol_edge(Peep* mechanic, int32_t x, int32_t y) @@ -386,8 +378,14 @@ void staff_reset_stats() } } -bool staff_is_patrol_area_set(int32_t staffIndex, int32_t x, int32_t y) +static bool staff_is_patrol_area_set(int32_t staffIndex, int32_t x, int32_t y) { + // Patrol quads are stored in a bit map (8 patrol quads per byte). + // Each patrol quad is 4x4. + // Therefore there are in total 64 x 64 patrol quads in the 256 x 256 map. + // At the end of the array (after the slots for individual staff members), + // there are slots that save the combined patrol area for every staff type. + x = (x & 0x1F80) >> 7; y = (y & 0x1F80) >> 1; @@ -397,6 +395,16 @@ bool staff_is_patrol_area_set(int32_t staffIndex, int32_t x, int32_t y) return gStaffPatrolAreas[peepOffset + offset] & (((uint32_t)1) << bitIndex); } +bool Staff::IsPatrolAreaSet(CoordsXY coords) const +{ + return staff_is_patrol_area_set(staff_id, coords.x, coords.y); +} + +bool staff_is_patrol_area_set_for_type(STAFF_TYPE type, CoordsXY coords) +{ + return staff_is_patrol_area_set(STAFF_MAX_COUNT + type, coords.x, coords.y); +} + void staff_set_patrol_area(int32_t staffIndex, int32_t x, int32_t y, bool value) { x = (x & 0x1F80) >> 7; diff --git a/src/openrct2/peep/Staff.h b/src/openrct2/peep/Staff.h index 0684ad1565..41e848d78a 100644 --- a/src/openrct2/peep/Staff.h +++ b/src/openrct2/peep/Staff.h @@ -82,7 +82,7 @@ bool staff_is_location_on_patrol_edge(Peep* mechanic, int32_t x, int32_t y); bool staff_can_ignore_wide_flag(Peep* mechanic, int32_t x, int32_t y, uint8_t z, TileElement* path); int32_t staff_path_finding(Staff* peep); void staff_reset_stats(); -bool staff_is_patrol_area_set(int32_t staffIndex, int32_t x, int32_t y); +bool staff_is_patrol_area_set_for_type(STAFF_TYPE type, CoordsXY coords); void staff_set_patrol_area(int32_t staffIndex, int32_t x, int32_t y, bool value); void staff_toggle_patrol_area(int32_t staffIndex, int32_t x, int32_t y); colour_t staff_get_colour(uint8_t staffType);