From 667d38754f836f3631125d0d8d60f16566465716 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 26 Jan 2016 20:54:17 +0000 Subject: [PATCH] Start implementing handyman pathfinding --- src/peep/peep.c | 2 +- src/peep/staff.c | 85 +++++++++++++++++++++++++++++++++++++--- src/peep/staff.h | 3 +- src/ride/ride.c | 2 +- src/windows/staff_list.c | 2 +- 5 files changed, 84 insertions(+), 10 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index c52ebe9b46..41f6f81f41 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -8376,7 +8376,7 @@ static int sub_693C9E(rct_peep *peep) result = guest_path_finding(peep); } else{ - result = RCT2_CALLPROC_X(0x006BF926, x, 0, y, 0, (int)peep, 0, 0) & 0x100; + result = staff_path_finding(peep); } if (result != 0) diff --git a/src/peep/staff.c b/src/peep/staff.c index e4fe59a61e..888059d2ab 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -460,7 +460,7 @@ void staff_update_greyed_patrol_areas() } } -int staff_is_location_in_patrol_area(rct_peep *peep, int x, int y) +static int staff_is_location_in_patrol_area(rct_peep *peep, int x, int y) { // Patrol quads are stored in a bit map (8 patrol quads per byte) // Each patrol quad is 4x4 @@ -478,17 +478,52 @@ int staff_is_location_in_patrol_area(rct_peep *peep, int x, int y) * * rct2: 0x006C0905 */ -int mechanic_is_location_in_patrol(rct_peep *mechanic, int x, int y) +int staff_is_location_in_patrol(rct_peep *staff, int x, int y) { // Check if location is in the park - if (!map_is_location_owned(x, y, mechanic->z)) + if (!map_is_location_owned(x, y, staff->z)) return 0; - // Check if mechanic has patrol area - if (!(RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[mechanic->staff_id] & 2)) + // Check if staff has patrol area + if (!(RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[staff->staff_id] & 2)) return 1; - return staff_is_location_in_patrol_area(mechanic, x, y); + return staff_is_location_in_patrol_area(staff, x, y); +} + +/** + * + * rct2: 0x006C095B + * returns 0xF if not in a valid patrol area + */ +static uint8 staff_get_valid_patrol_directions(rct_peep* peep, sint16 x, sint16 y) { + uint8 directions = 0; + + if (staff_is_location_in_patrol(peep, x - 32, y)) { + directions |= (1 << 0); + } + + if (staff_is_location_in_patrol(peep, x, y + 32)) { + directions |= (1 << 1); + } + + if (staff_is_location_in_patrol(peep, x + 32, y)) { + directions |= (1 << 2); + } + + if (staff_is_location_in_patrol(peep, x, y - 32)) { + directions |= (1 << 3); + } + + if (directions == 0) { + directions = 0xF; + } + + // For backwards compatibility. + // Remove when all references to 0x00F43910 removed + RCT2_GLOBAL(0x00F43910, uint32) = directions; + + return directions; } /** @@ -521,3 +556,41 @@ bool staff_is_patrol_area_set(int staffIndex, int x, int y) int bitIndex = (x | y) & 0x1F; return gStaffPatrolAreas[peepOffset + offset] & (1 << bitIndex); } + +/** +* +* rct2: 0x006BFBA8 +*/ +static int staff_path_finding_handyman(rct_peep* peep) { + peep->var_E2++; + + RCT2_GLOBAL(0x00F43918, uint8) = 0xFF; + uint8 validDirections = staff_get_valid_patrol_directions(peep, peep->next_x, peep->next_y); + + if (peep->staff_orders & STAFF_ORDERS_SWEEPING && + ((RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) + peep->sprite_index) & 0xFFF) > 110) { + //6bfbe8 + } + //6bfd82 +} + +/** +* +* rct2: 0x006BF926 +*/ +int staff_path_finding(rct_peep* peep) { + switch (peep->staff_type) { + case STAFF_TYPE_HANDYMAN: + return RCT2_CALLPROC_X(0x006BFBA8, 0, 0, 0, 0, (int)peep, 0, 0) & 0x100; + case STAFF_TYPE_MECHANIC: + return RCT2_CALLPROC_X(0x006BFF2C, 0, 0, 0, 0, (int)peep, 0, 0) & 0x100; + case STAFF_TYPE_SECURITY: + return RCT2_CALLPROC_X(0x006C0351, 0, 0, 0, 0, (int)peep, 0, 0) & 0x100; + case STAFF_TYPE_ENTERTAINER: + return RCT2_CALLPROC_X(0x006C05AE, 0, 0, 0, 0, (int)peep, 0, 0) & 0x100; + + default: + assert(false); + return 0; + } +} diff --git a/src/peep/staff.h b/src/peep/staff.h index f223f3f30c..52baf0948c 100644 --- a/src/peep/staff.h +++ b/src/peep/staff.h @@ -62,7 +62,8 @@ void staff_reset_modes(); void update_staff_colour(uint8 staffType, uint16 color); uint16 hire_new_staff_member(uint8 staffType); void staff_update_greyed_patrol_areas(); -int mechanic_is_location_in_patrol(rct_peep *mechanic, int x, int y); +int staff_is_location_in_patrol(rct_peep *mechanic, int x, int y); +int staff_path_finding(rct_peep* peep); void staff_reset_stats(); bool staff_is_patrol_area_set(int staffIndex, int x, int y); diff --git a/src/ride/ride.c b/src/ride/ride.c index dd9409030a..a3c1648fad 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -2521,7 +2521,7 @@ rct_peep *find_closest_mechanic(int x, int y, int forInspection) } if (map_is_location_in_park(x, y)) - if (!mechanic_is_location_in_patrol(peep, x & 0xFFE0, y & 0xFFE0)) + if (!staff_is_location_in_patrol(peep, x & 0xFFE0, y & 0xFFE0)) continue; if (peep->x == (sint16)0x8000) diff --git a/src/windows/staff_list.c b/src/windows/staff_list.c index d96e8c0df1..d4f519447e 100644 --- a/src/windows/staff_list.c +++ b/src/windows/staff_list.c @@ -353,7 +353,7 @@ static void window_staff_list_tooldown(rct_window *w, int widgetIndex, int x, in if (!(gStaffModes[peep->staff_id] & 2)) { continue; } - if (!mechanic_is_location_in_patrol(peep, x, y)) { + if (!staff_is_location_in_patrol(peep, x, y)) { continue; } }