diff --git a/src/openrct2/rct1.h b/src/openrct2/rct1.h index f2875119ff..259591200f 100644 --- a/src/openrct2/rct1.h +++ b/src/openrct2/rct1.h @@ -82,7 +82,7 @@ typedef struct rct1_ride { uint8 max_waiting_time; uint8 operation_option; uint8 boat_hire_return_direction; - uint16 boat_hire_return_position; + rct_xy8 boat_hire_return_position; uint8 data_logging_index; uint8 special_track_elements; uint16 unk_86; diff --git a/src/openrct2/ride/ride.c b/src/openrct2/ride/ride.c index 4bceeb4c47..28872a1e65 100644 --- a/src/openrct2/ride/ride.c +++ b/src/openrct2/ride/ride.c @@ -4341,7 +4341,8 @@ static void ride_set_boat_hire_return_point(rct_ride *ride, rct_xy_element *star trackType = returnTrackElement->properties.track.type; int elementReturnDirection = TrackCoordinates[trackType].rotation_begin; ride->boat_hire_return_direction = (returnTrackElement->type + elementReturnDirection) & 3; - ride->boat_hire_return_position = (returnX >> 5) | ((returnY >> 5) << 8); + ride->boat_hire_return_position.x = returnX >> 5; + ride->boat_hire_return_position.y = returnY >> 5; } /** diff --git a/src/openrct2/ride/ride.h b/src/openrct2/ride/ride.h index bb648fecdf..217883c154 100644 --- a/src/openrct2/ride/ride.h +++ b/src/openrct2/ride/ride.h @@ -183,8 +183,9 @@ typedef struct rct_ride { uint8 speed; // 0x0D0 uint8 rotations; // 0x0D0 }; + uint8 boat_hire_return_direction; // 0x0D1 - uint16 boat_hire_return_position; // 0x0D2 + rct_xy8 boat_hire_return_position; // 0x0D2 uint8 measurement_index; // 0x0D4 // bits 0 through 4 are the number of helix sections // bit 5: spinning tunnel, water splash, or rapids diff --git a/src/openrct2/ride/vehicle.c b/src/openrct2/ride/vehicle.c index f398c33ec2..35c1ac4319 100644 --- a/src/openrct2/ride/vehicle.c +++ b/src/openrct2/ride/vehicle.c @@ -58,7 +58,7 @@ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); static void vehicle_update_travelling_boat(rct_vehicle* vehicle); static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle); -static void sub_6DA280(rct_vehicle *vehicle); +static void vehicle_update_boat_location(rct_vehicle *vehicle); static bool vehicle_is_boat_on_water(rct_vehicle *vehicle, int x, int y); static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); @@ -3832,7 +3832,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) vehicle->var_34 = bl; x += y; if (x <= 12) { - sub_6DA280(vehicle); + vehicle_update_boat_location(vehicle); } if (!(vehicle->var_35 & (1 << 0))) { @@ -3863,7 +3863,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) vehicle->remaining_distance = 0; if (vehicle->sprite_direction == vehicle->var_34) { vehicle->sprite_direction ^= (1 << 4); - sub_6DA280(vehicle); + vehicle_update_boat_location(vehicle); vehicle->sprite_direction ^= (1 << 4); } break; @@ -3881,7 +3881,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) do_loc_6DAA97 = true; } else { uint16 xy = (((dx >> 5) << 8) | (bx >> 5)); - if (xy != ride->boat_hire_return_position) { + if (xy != ride->boat_hire_return_position.xy) { do_loc_6DAA97 = true; } } @@ -3890,7 +3890,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) if (do_loc_6DAA97) { vehicle->remaining_distance = 0; if (vehicle->sprite_direction == vehicle->var_34) { - sub_6DA280(vehicle); + vehicle_update_boat_location(vehicle); } break; } @@ -3988,16 +3988,18 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) * * rct2: 0x006DA280 */ -static void sub_6DA280(rct_vehicle *vehicle) +static void vehicle_update_boat_location(rct_vehicle *vehicle) { - rct_ride* ride = get_ride(vehicle->ride); + rct_ride *ride = get_ride(vehicle->ride); + rct_xy8 returnPosition = ride->boat_hire_return_position; + uint8 returnDirection = ride->boat_hire_return_direction & 3; rct_xy8 location = { - .x = (vehicle->x + TileDirectionDelta[ride->boat_hire_return_direction & 3].x) / 32, - .y = (vehicle->y + TileDirectionDelta[ride->boat_hire_return_direction & 3].y) / 32 + .x = (vehicle->x + TileDirectionDelta[returnDirection].x) / 32, + .y = (vehicle->y + TileDirectionDelta[returnDirection].y) / 32 }; - if (*((uint16*)&location) == ride->boat_hire_return_position) { + if (location.xy == returnPosition.xy) { vehicle->sub_state = 1; vehicle->boat_location = location; return; @@ -4007,21 +4009,22 @@ static void sub_6DA280(rct_vehicle *vehicle) uint8 curDirection = ((vehicle->sprite_direction + 19) >> 3) & 3; uint8 randDirection = scenario_rand() & 3; - rct_ride_entry* rideEntry = get_ride_entry(vehicle->ride_subtype); - if (scenario_rand() & 1 && (!(rideEntry->flags & RIDE_ENTRY_FLAG_7) || vehicle->lost_time_out > 1920)) { - location = *((rct_xy8*)&ride->boat_hire_return_position); - rct_xy16 destLocation = { - .x = location.x * 32 - TileDirectionDelta[ride->boat_hire_return_direction & 3].x + 16, - .y = location.y * 32 - TileDirectionDelta[ride->boat_hire_return_direction & 3].y + 16 - }; + rct_ride_entry *rideEntry = get_ride_entry(vehicle->ride_subtype); + if (!(rideEntry->flags & RIDE_ENTRY_FLAG_7) || vehicle->lost_time_out > 1920) { + if (scenario_rand() & 1) { + rct_xy16 destLocation = { + .x = returnPosition.x * 32 - TileDirectionDelta[returnDirection].x + 16, + .y = returnPosition.y * 32 - TileDirectionDelta[returnDirection].y + 16 + }; - destLocation.x -= vehicle->x; - destLocation.y -= vehicle->y; + destLocation.x -= vehicle->x; + destLocation.y -= vehicle->y; - if (abs(destLocation.x) <= abs(destLocation.y)) { - randDirection = destLocation.y < 0 ? 3 : 1; - } else { - randDirection = destLocation.x < 0 ? 0 : 2; + if (abs(destLocation.x) <= abs(destLocation.y)) { + randDirection = destLocation.y < 0 ? 3 : 1; + } else { + randDirection = destLocation.x < 0 ? 0 : 2; + } } }