void SpawnTraveler(int start, int end, TravelPreference preference = TravelPreference.time) { var itinerary = routingController.GetItinerary(start, end, preference); int index = Mathf.FloorToInt(UnityEngine.Random.Range(0, spawnPoints.Count)); //if (itinerary == null) // return; GameObject newTraveler = TravelerController.CreateGameObject(itinerary); newTraveler.transform.SetParent(travelers.transform); newTraveler.transform.position = RandomSpawnPoint(spawnPoints[index]); //Debug.Log(itinerary); }
/// <summary> /// Bubble algorithm to find the best itinerary between the stations given and the stations close to the destination point. /// </summary> /// <param name="startingPoint">Point in the map where the pedestrian starts.</param> /// <param name="destination">Final destination of the pedestrian.</param> /// <param name="stationsNearby">Stations nearby considered by the pedestrian.</param> /// <param name="travelPreference">Travel preferences of the pedestrian.</param> /// <param name="destIndex">Index of the destination point within the destination object.</param> /// <returns>An Itinerary object with the best itinerary for the pedestrian (empty itinerary if anything better than walking has been found).</returns> public Itinerary FindBestItinerary(Vector3 startingPoint, FlashPedestriansDestination destination, StationController[] stationsNearby, TravelPreference travelPreference, int destIndex = 0) { Itinerary bestItineraryFound = new Itinerary(new List <StationController>()); // Return an empty itinerary if no public transport is the travel preference if (travelPreference == TravelPreference.noPublicTransport) { return(bestItineraryFound); } // The default travel time taken into account is the possibility of walking all the way float bestTravelTime = Vector3.Distance(startingPoint, destination.destinationTransform[destIndex].position) * secondsPerMeter; for (int i = 0; i < stationsNearby.Length; i++) { for (int j = 0; j < destination.stationsNearThisDestination[destIndex].Length; j++) { Itinerary nextItinerary = routingController.GetItinerary( stationsNearby[i], destination.stationsNearThisDestination[destIndex][j].GetComponent <StationController>(), travelPreference); if (nextItinerary != null) { // Check the total travel time considering walking times form the starting point to the first station and from th last station to the destination float timeWalkingToFirstStation = Vector3.Distance(startingPoint, nextItinerary.FirstStop.transform.position) * secondsPerMeter; float timeWalkingFromLastStation = Vector3.Distance(nextItinerary.LastStop.transform.position, destination.transform.position) * secondsPerMeter; float travelTime = nextItinerary.GetTotalTravelTime() + timeWalkingToFirstStation + timeWalkingFromLastStation; if (travelTime < bestTravelTime) { bestTravelTime = travelTime; bestItineraryFound = nextItinerary; } } } } if (bestItineraryFound == null) { Debug.Log("No itinerary found"); } return(bestItineraryFound); }