Refactor calls to staff_is_patrol_area_set()

This commit is contained in:
Michael Steenbeek 2019-12-31 10:10:40 +01:00 committed by GitHub
parent 37110f386d
commit 29922da871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 20 deletions

View File

@ -1230,7 +1230,8 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex,
if (peep.type != PEEP_TYPE_STAFF) if (peep.type != PEEP_TYPE_STAFF)
return; 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; _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) if (peep.type != PEEP_TYPE_STAFF)
return; 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) if (_staffPatrolAreaPaintValue == PatrolAreaValue::SET && patrolAreaValue)
return; // Since area is already the value we want, skip... return; // Since area is already the value we want, skip...
if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && !patrolAreaValue) if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && !patrolAreaValue)

View File

@ -347,7 +347,7 @@ static void window_staff_list_tooldown(rct_window* w, rct_widgetindex widgetInde
if (footpathCoords.isNull()) if (footpathCoords.isNull())
return; 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<STAFF_TYPE>(selectedPeepType), footpathCoords);
uint16_t spriteIndex; uint16_t spriteIndex;
Peep *peep, *closestPeep = nullptr; Peep *peep, *closestPeep = nullptr;

View File

@ -900,15 +900,15 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile
if (!is_staff_list) if (!is_staff_list)
{ {
Peep* staff = GET_PEEP(staffIndex); Staff* staff = (GET_PEEP(staffIndex))->AsStaff();
if (!staff_is_patrol_area_set(staff->staff_id, x, y)) if (!staff->IsPatrolAreaSet({ x, y }))
{ {
patrolColour = COLOUR_GREY; patrolColour = COLOUR_GREY;
} }
staffType = staff->staff_type; staffType = staff->staff_type;
} }
if (staff_is_patrol_area_set(200 + staffType, x, y)) if (staff_is_patrol_area_set_for_type(static_cast<STAFF_TYPE>(staffType), session->MapPosition))
{ {
uint32_t imageId = 2618; uint32_t imageId = 2618;
int32_t patrolAreaBaseZ = tile_element->GetBaseZ(); int32_t patrolAreaBaseZ = tile_element->GetBaseZ();

View File

@ -1042,15 +1042,15 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
if (!is_staff_list) if (!is_staff_list)
{ {
Peep* staff = GET_PEEP(staffIndex); Staff* staff = (GET_PEEP(staffIndex))->AsStaff();
if (!staff_is_patrol_area_set(staff->staff_id, x, y)) if (!staff->IsPatrolAreaSet({ x, y }))
{ {
patrolColour = COLOUR_GREY; patrolColour = COLOUR_GREY;
} }
staffType = staff->staff_type; staffType = staff->staff_type;
} }
if (staff_is_patrol_area_set(200 + staffType, x, y)) if (staff_is_patrol_area_set_for_type(static_cast<STAFF_TYPE>(staffType), session->MapPosition))
{ {
assert(surfaceShape < std::size(byte_97B444)); assert(surfaceShape < std::size(byte_97B444));

View File

@ -832,6 +832,7 @@ public:
void UpdateStaff(uint32_t stepsToTake); void UpdateStaff(uint32_t stepsToTake);
void Tick128UpdateStaff(); void Tick128UpdateStaff();
bool IsMechanic() const; bool IsMechanic() const;
bool IsPatrolAreaSet(CoordsXY coords) const;
private: private:
void UpdatePatrolling(); void UpdatePatrolling();

View File

@ -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 * 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)) if (!(gStaffModes[staff->staff_id] & 2))
return true; 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) 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; x = (x & 0x1F80) >> 7;
y = (y & 0x1F80) >> 1; 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); 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) void staff_set_patrol_area(int32_t staffIndex, int32_t x, int32_t y, bool value)
{ {
x = (x & 0x1F80) >> 7; x = (x & 0x1F80) >> 7;

View File

@ -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); 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); int32_t staff_path_finding(Staff* peep);
void staff_reset_stats(); 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_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); void staff_toggle_patrol_area(int32_t staffIndex, int32_t x, int32_t y);
colour_t staff_get_colour(uint8_t staffType); colour_t staff_get_colour(uint8_t staffType);