diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 2906b678ea..93239263fa 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -1022,8 +1022,7 @@ void Guest::TryGetUpFromSitting() // Set destination to the centre of the tile. auto destination = GetLocation().ToTileCentre(); - SetDestination(destination); - DestinationTolerance = 5; + SetDestination(destination, 5); UpdateCurrentActionSpriteType(); } @@ -1077,8 +1076,7 @@ void Guest::UpdateSitting() // Set destination to the centre of the tile auto destination = GetLocation().ToTileCentre(); - SetDestination(destination); - DestinationTolerance = 5; + SetDestination(destination, 5); UpdateCurrentActionSpriteType(); return; } @@ -2294,9 +2292,7 @@ void Guest::GoToRideEntrance(Ride* ride) location.x += x_shift; location.y += y_shift; - SetDestination(location); - DestinationTolerance = 2; - + SetDestination(location, 2); SetState(PeepState::EnteringRide); RideSubState = PeepRideSubState::InEntrance; @@ -3302,8 +3298,7 @@ static void peep_update_ride_leave_entrance_maze(Guest* peep, Ride* ride, Coords entrance_loc.x += _MazeEntranceStart[direction / 4].x; entrance_loc.y += _MazeEntranceStart[direction / 4].y; - peep->SetDestination(entrance_loc); - peep->DestinationTolerance = 3; + peep->SetDestination(entrance_loc, 3); ride->cur_num_customers++; peep->OnEnterRide(peep->CurrentRide); @@ -3498,8 +3493,7 @@ void Guest::UpdateRideAdvanceThroughEntrance() if (vehicle_type->flags & VEHICLE_ENTRY_FLAG_DODGEM_CAR_PLACEMENT) { - SetDestination(vehicle->GetLocation()); - DestinationTolerance = 15; + SetDestination(vehicle->GetLocation(), 15); RideSubState = PeepRideSubState::ApproachVehicle; return; } @@ -3580,8 +3574,7 @@ static void peep_go_to_ride_exit(Peep* peep, Ride* ride, int16_t x, int16_t y, i x -= x_shift; y -= y_shift; - peep->SetDestination({ x, y }); - peep->DestinationTolerance = 2; + peep->SetDestination({ x, y }, 2); peep->sprite_direction = exit_direction * 8; peep->RideSubState = PeepRideSubState::ApproachExit; @@ -3660,9 +3653,7 @@ static void peep_update_ride_no_free_vehicle_rejoin_queue(Peep* peep, Ride* ride x += 16 - DirectionOffsets[entranceLocation.direction].x * 20; y += 16 - DirectionOffsets[entranceLocation.direction].y * 20; - peep->SetDestination({ x, y }); - peep->DestinationTolerance = 2; - + peep->SetDestination({ x, y }, 2); peep->SetState(PeepState::QueuingFront); peep->RideSubState = PeepRideSubState::AtEntrance; @@ -4054,8 +4045,7 @@ void Guest::UpdateRideLeaveVehicle() waypointLoc.x += vehicleEntry->peep_loading_waypoints[Var37 / 4][1].x; waypointLoc.y += vehicleEntry->peep_loading_waypoints[Var37 / 4][1].y; - SetDestination(waypointLoc); - DestinationTolerance = 2; + SetDestination(waypointLoc, 2); RideSubState = PeepRideSubState::ApproachExitWaypoints; } @@ -4100,8 +4090,7 @@ static void peep_update_ride_prepare_for_exit(Peep* peep) x -= x_shift; y -= y_shift; - peep->SetDestination({ x, y }); - peep->DestinationTolerance = 2; + peep->SetDestination({ x, y }, 2); peep->RideSubState = PeepRideSubState::InExit; } @@ -4789,8 +4778,7 @@ void Guest::UpdateRideShopInteract() { RideSubState = PeepRideSubState::LeaveShop; - SetDestination({ tileCenterX, tileCenterY }); - DestinationTolerance = 3; + SetDestination({ tileCenterX, tileCenterY }, 3); HappinessTarget = std::min(HappinessTarget + 30, PEEP_MAX_HAPPINESS); Happiness = HappinessTarget; } @@ -4816,8 +4804,7 @@ void Guest::UpdateRideShopInteract() RideSubState = PeepRideSubState::LeaveShop; - SetDestination({ tileCenterX, tileCenterY }); - DestinationTolerance = 3; + SetDestination({ tileCenterX, tileCenterY }, 3); HappinessTarget = std::min(HappinessTarget + 30, PEEP_MAX_HAPPINESS); Happiness = HappinessTarget; @@ -5225,8 +5212,7 @@ void Guest::UpdateWalking() int32_t destX = (x & 0xFFE0) + _WatchingPositionOffsets[Var37 & 0x1F].x; int32_t destY = (y & 0xFFE0) + _WatchingPositionOffsets[Var37 & 0x1F].y; - SetDestination({ destX, destY }); - DestinationTolerance = 3; + SetDestination({ destX, destY }, 3); if (CurrentSeat & 1) { @@ -5521,8 +5507,7 @@ void Guest::UpdateWatching() // Send peep to the centre of current tile. auto destination = GetLocation().ToTileCentre(); - SetDestination(destination); - DestinationTolerance = 5; + SetDestination(destination, 5); UpdateCurrentActionSpriteType(); } } @@ -5752,8 +5737,7 @@ bool Guest::UpdateWalkingFindBench() int32_t benchX = (x & 0xFFE0) + BenchUseOffsets[Var37 & 0x7].x; int32_t benchY = (y & 0xFFE0) + BenchUseOffsets[Var37 & 0x7].y; - SetDestination({ benchX, benchY }); - DestinationTolerance = 3; + SetDestination({ benchX, benchY }, 3); return true; } @@ -5831,8 +5815,7 @@ bool Guest::UpdateWalkingFindBin() int32_t binX = (peep->x & 0xFFE0) + BinUseOffsets[peep->Var37 & 0x3].x; int32_t binY = (peep->y & 0xFFE0) + BinUseOffsets[peep->Var37 & 0x3].y; - peep->SetDestination({ binX, binY }); - peep->DestinationTolerance = 3; + peep->SetDestination({ binX, binY }, 3); return true; } diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 3beb05b532..0c3f238c37 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -167,8 +167,7 @@ static int32_t peep_move_one_tile(Direction direction, Peep* peep) newTile.y += offset; } } - peep->SetDestination(newTile); - peep->DestinationTolerance = 2; + peep->SetDestination(newTile, 2); return 0; } diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 417d126c4f..8e46b4c5bb 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1029,8 +1029,7 @@ void Peep::Update1() SetState(PeepState::Patrolling); } - SetDestination(GetLocation()); - DestinationTolerance = 10; + SetDestination(GetLocation(), 10); PeepDirection = sprite_direction >> 3; } @@ -2288,8 +2287,7 @@ static void peep_return_to_centre_of_tile(Peep* peep) { peep->PeepDirection = direction_reverse(peep->PeepDirection); auto destination = peep->GetLocation().ToTileCentre(); - peep->SetDestination(destination); - peep->DestinationTolerance = 5; + peep->SetDestination(destination, 5); } /** @@ -2455,8 +2453,7 @@ static bool peep_interact_with_entrance(Peep* peep, const CoordsXYE& coords, uin } auto destination = peep->GetDestination() + CoordsDirectionDelta[peep->PeepDirection]; - peep->SetDestination(destination); - peep->DestinationTolerance = 9; + peep->SetDestination(destination, 9); peep->MoveTo({ coords, peep->z }); peep->SetState(PeepState::LeavingPark); @@ -2594,8 +2591,7 @@ static bool peep_interact_with_entrance(Peep* peep, const CoordsXYE& coords, uin peep->Var37 = 1; auto destination = peep->GetDestination(); destination += CoordsDirectionDelta[peep->PeepDirection]; - peep->SetDestination(destination); - peep->DestinationTolerance = 7; + peep->SetDestination(destination, 7); peep->MoveTo({ coords, peep->z }); } return true; @@ -2935,9 +2931,7 @@ static bool peep_interact_with_shop(Peep* peep, const CoordsXYE& coords) } auto coordsCentre = coords.ToTileCentre(); - peep->SetDestination(coordsCentre); - peep->DestinationTolerance = 3; - + peep->SetDestination(coordsCentre, 3); peep->CurrentRide = rideIndex; peep->SetState(PeepState::EnteringRide); peep->RideSubState = PeepRideSubState::ApproachShop; @@ -3388,6 +3382,12 @@ void Peep::SetDestination(const CoordsXY& coords) DestinationY = static_cast(coords.y); } +void Peep::SetDestination(const CoordsXY& coords, int32_t tolerance) +{ + SetDestination(coords); + DestinationTolerance = tolerance; +} + CoordsXY Peep::GetDestination() const { return CoordsXY{ static_cast(DestinationX), static_cast(DestinationY) }; diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 877d783fab..01aec10408 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -767,6 +767,7 @@ public: // Peep bool HasItem(ShopItem peepItem) const; void SetDestination(const CoordsXY& coords); + void SetDestination(const CoordsXY& coords, int32_t tolerance); CoordsXY GetDestination() const; // TODO: Make these private again when done refactoring diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 44a6155a7b..a01b91fc21 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -653,8 +653,7 @@ bool Staff::DoHandymanPathFinding() } PeepDirection = newDirection; - SetDestination(chosenTile + CoordsXY{ 16, 16 }); - DestinationTolerance = 3; + SetDestination(chosenTile + CoordsXY{ 16, 16 }, 3); if (State == PeepState::Queuing) { DestinationTolerance = (scenario_rand() & 7) + 2; @@ -871,8 +870,8 @@ bool Staff::DoMechanicPathFinding() } PeepDirection = newDirection; - SetDestination(chosenTile + CoordsXY{ 16, 16 }); - DestinationTolerance = (scenario_rand() & 7) + 2; + auto tolerance = (scenario_rand() & 7) + 2; + SetDestination(chosenTile + CoordsXY{ 16, 16 }, tolerance); return false; } @@ -949,8 +948,8 @@ bool Staff::DoMiscPathFinding() } PeepDirection = newDirection; - SetDestination(chosenTile + CoordsXY{ 16, 16 }); - DestinationTolerance = (scenario_rand() & 7) + 2; + auto tolerance = (scenario_rand() & 7) + 2; + SetDestination(chosenTile + CoordsXY{ 16, 16 }, tolerance); return false; } @@ -1446,8 +1445,7 @@ void Staff::UpdateHeadingToInspect() int32_t destX = NextLoc.x + 16 + DirectionOffsets[PeepDirection].x * 53; int32_t destY = NextLoc.y + 16 + DirectionOffsets[PeepDirection].y * 53; - SetDestination({ destX, destY }); - DestinationTolerance = 2; + SetDestination({ destX, destY }, 2); sprite_direction = PeepDirection << 3; z = rideEntranceExitElement->base_height * 4; @@ -1556,8 +1554,7 @@ void Staff::UpdateAnswering() int32_t destX = NextLoc.x + 16 + DirectionOffsets[PeepDirection].x * 53; int32_t destY = NextLoc.y + 16 + DirectionOffsets[PeepDirection].y * 53; - SetDestination({ destX, destY }); - DestinationTolerance = 2; + SetDestination({ destX, destY }, 2); sprite_direction = PeepDirection << 3; z = rideEntranceExitElement->base_height * 4; @@ -1651,8 +1648,7 @@ bool Staff::UpdatePatrollingFindWatering() SubState = 0; auto destination = _WateringUseOffsets[chosen_position] + GetLocation().ToTileStart(); - SetDestination(destination); - DestinationTolerance = 3; + SetDestination(destination, 3); return true; } while (!(tile_element++)->IsLastForTile()); @@ -1720,8 +1716,7 @@ bool Staff::UpdatePatrollingFindBin() SubState = 0; auto destination = BinUseOffsets[chosen_position] + GetLocation().ToTileStart(); - SetDestination(destination); - DestinationTolerance = 3; + SetDestination(destination, 3); return true; } @@ -1750,8 +1745,7 @@ bool Staff::UpdatePatrollingFindGrass() // Original code used .y for both x and y. Changed to .x to make more sense (both x and y are 28) auto destination = _MowingWaypoints[0] + NextLoc; - SetDestination(destination); - DestinationTolerance = 3; + SetDestination(destination, 3); return true; } } @@ -1777,8 +1771,7 @@ bool Staff::UpdatePatrollingFindSweeping() SetState(PeepState::Sweeping); Var37 = 0; - SetDestination(litter->GetLocation()); - DestinationTolerance = 5; + SetDestination(litter->GetLocation(), 5); return true; } @@ -2162,8 +2155,7 @@ bool Staff::UpdateFixingMoveToBrokenDownVehicle(bool firstRun, const Ride* ride) CoordsXY offset = DirectionOffsets[PeepDirection]; auto destination = (offset * -12) + vehicle->GetLocation(); - SetDestination(destination); - DestinationTolerance = 2; + SetDestination(destination, 2); } if (auto loc = UpdateAction()) @@ -2313,8 +2305,7 @@ bool Staff::UpdateFixingMoveToStationEnd(bool firstRun, const Ride* ride) stationPos.y = GetDestination().y; } - SetDestination(stationPos); - DestinationTolerance = 2; + SetDestination(stationPos, 2); } if (auto loc = UpdateAction()) @@ -2420,8 +2411,7 @@ bool Staff::UpdateFixingMoveToStationStart(bool firstRun, const Ride* ride) destination.y = GetDestination().y; } - SetDestination(destination); - DestinationTolerance = 2; + SetDestination(destination, 2); } if (auto loc = UpdateAction()) @@ -2534,8 +2524,7 @@ bool Staff::UpdateFixingMoveToStationExit(bool firstRun, const Ride* ride) stationPosition.x += stationPlatformDirection.x * 20; stationPosition.y += stationPlatformDirection.y * 20; - SetDestination(stationPosition); - DestinationTolerance = 2; + SetDestination(stationPosition, 2); } if (auto loc = UpdateAction()) @@ -2618,8 +2607,7 @@ bool Staff::UpdateFixingLeaveByEntranceExit(bool firstRun, const Ride* ride) exitPosition.x -= ebx_direction.x * 19; exitPosition.y -= ebx_direction.y * 19; - SetDestination(exitPosition); - DestinationTolerance = 2; + SetDestination(exitPosition, 2); } int16_t xy_distance; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index f78fba8cd5..2fe6083bba 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -429,8 +429,7 @@ void footpath_interrupt_peeps(const CoordsXYZ& footpathPos) { auto destination = location.ToTileCentre(); peep->SetState(PeepState::Walking); - peep->SetDestination(destination); - peep->DestinationTolerance = 5; + peep->SetDestination(destination, 5); peep->UpdateCurrentActionSpriteType(); } } diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index f750dce3a7..6254f8e179 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -723,8 +723,7 @@ Peep* Park::GenerateGuest() // Get the centre point of the tile the peep is on auto destination = peep->GetLocation().ToTileCentre(); - peep->SetDestination(destination); - peep->DestinationTolerance = 5; + peep->SetDestination(destination, 5); peep->PeepDirection = direction; peep->Var37 = 0; peep->State = PeepState::EnteringPark; diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index ddce62f7d9..974f5c6136 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -97,8 +97,7 @@ protected: // destination will be picked, to try and get the peep towards the overall pathfinding goal. peep->PeepDirection = moveDir; auto destination = CoordsDirectionDelta[moveDir] + peep->GetLocation(); - peep->SetDestination(destination); - peep->DestinationTolerance = 2; + peep->SetDestination(destination, 2); // Repeatedly step the peep, until they reach the target position or until the expected number of steps have // elapsed. Each step, check that the tile they are standing on is not marked as forbidden in the test data