Ejemplo n.º 1
0
    /// <summary>
    /// Recomputes a new route in the itinerary from a certain point.
    /// </summary>
    /// <param name="stationsNearby">List os stations nearby (null by default).</param>
    private void RedoRouteFromCurrentPosition(StationController[] stationsNearby = null)
    {
        UpdateInfoBalloon();

        navAgent.enabled = false;
        ResetStopIndex();

        if (stationsNearby != null)
        {
            routing = new FlashPedestriansRouting(routing.destination,
                                                  flashInformer.FindBestItinerary(this.transform.position, routing.destination, stationsNearby, profile.travelPreference));
        }
        else
        {
            //In this case, the pedestrian will find the nearby stations from its point
            routing = new FlashPedestriansRouting(routing.destination,
                                                  flashInformer.FindBestItinerary(this.transform.position, routing.destination, StationsNearCurrentPosition(), profile.travelPreference));
        }

        if (routing != null)
        {
            if (routing.itinerary != null)
            {
                stations = routing.itinerary.WayPoints;
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Generates a group of pedestrians inside the Unity scene. The position will be set
    /// randomly in a radious around the spawner.
    /// </summary>
    private void SpawnGroupOfPedestrians()
    {
        if (!pedGlobalParameters.flashPedestriansPaused || spawningInitialBatch)
        {
            // Create a new pedestrian profile
            FlashPedestriansProfile profile = new FlashPedestriansProfile(pedGlobalParameters.averageSpeed + Random.Range(-0.5f, 0.5f),
                                                                          true /*future use*/, true /*future use*/, Random.Range(0.0f, 1.0f), false /*future use*/,
                                                                          Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), pedGlobalParameters.sumoCarAwarenessEnabled,
                                                                          //percOfPedWillingToTakeTransport
                                                                          (Random.value < pedGlobalParameters.percOfPedWillingToChangeDestination) ? TravelPreference.time : TravelPreference.noPublicTransport);

            //Find a destination
            FlashPedestriansDestination destination = null;
            int     destinationIndex    = 0;
            float[] priorityPercentages = GetPrioritiesOfAllDestinations();
            float   rand = Random.Range(0.0f, 0.99f);
            for (int i = 0; i < priorityPercentages.Length; i++)
            {
                if (rand < priorityPercentages[i])
                {
                    destination = destinations[i];

                    //Get one of the destination points within the destination choosen
                    destinationIndex = Random.Range(0, destination.numberOfdestinations);

                    break;
                }
            }
            if (destination == null)
            {
                Debug.LogWarning("No destination could be found with the list of priorities, avoiding spawning...");
                return;
            }

            //Find a new random spawning point inside the radious defined
            Vector3 spawningPoint = spawningPoints[Random.Range(0, numberOfSpawningPoints)];

            //Vector3 spawningPoint = this.transform.position
            //   + new Vector3(Random.Range(-spawningArea, spawningArea),
            //   0f, Random.Range(-spawningArea, spawningArea));

            //Find the best itinerary using the travel preferences in the pedestrian profile.
            Itinerary itinerary = flashInformer.FindBestItinerary(spawningPoint, destination, stationsNearThisSpawner, profile.travelPreference, destinationIndex);

            if (showDebugInfo)
            {
                Debug.Log(itinerary.Print());
            }

            //Calculate number of pedestrians to spawn in this iteration
            int pedToSpawn = Random.Range(minPedestriansPerSpawningIteration, maxPedestriansPerSpawningIteration);

            //Spawn pedestrians
            for (int i = 0; i < pedToSpawn; i++)
            {
                SpawnPedestrian(spawningPoint, profile, destination, itinerary, destinationIndex);
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Generates a group of pedestrians inside the Unity scene. The position will be set
    /// randomly in a radious around the spawner.
    /// </summary>
    private void SpawnGroupOfPedestrians()
    {
        if (!pedGlobalParameters.flashPedestriansPaused)
        {
            // Create a new pedestrian profile
            FlashPedestriansProfile profile = new FlashPedestriansProfile(pedGlobalParameters.averageSpeed + Random.Range(-0.5f, 0.5f),
                                                                          true /*future use*/, true /*future use*/, Random.Range(0.0f, 1.0f), false /*future use*/, Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), pedGlobalParameters.sumoCarAwarenessEnabled, TravelPreference.time);

            //Find a destination
            FlashPedestriansDestination destination = null;
            float[] priorityPercentages             = getPrioritiesOfAllDestinations();
            float   rand = Random.Range(0.0f, 0.99f);
            for (int i = 0; i < priorityPercentages.Length; i++)
            {
                if (rand < priorityPercentages[i])
                {
                    destination = destinationPoints[i];
                    break;
                }
            }
            if (destination == null)
            {
                Debug.LogWarning("No destination could be found with the list of priorities, avoiding spawning...");
                return;
            }

            //Find a new random spawning point inside the radious defined
            Vector3 spawningPoint = this.transform.position
                                    + new Vector3(Random.Range(-spawningArea, spawningArea), 0.0f, Random.Range(-spawningArea, spawningArea));

            //Move the spawning point to the closest point in the walkable navmesh (is this an expensive operation?)
            //NavMeshHit hit;
            //if (NavMesh.SamplePosition(spawningPoint, out hit, 1000.0f, 1 << NavMesh.GetAreaFromName("footway")))
            //    spawningPoint = hit.position;

            //Find the best itinerary using the travel preferences in the pedestrian profile.
            Itinerary itinerary = flashInformer.FindBestItinerary(spawningPoint, destination, stationsNearThisSpawner, profile.travelPreference);

            //Calculate number of pedestrians to spawn in this iteration
            int pedToSpawn = Random.Range(minPedestriansPerSpawningIteration, maxPedestriansPerSpawningIteration);

            //Spawn pedestrians
            for (int i = 0; i < pedToSpawn; i++)
            {
                SpawnPedestrian(spawningPoint, profile, destination, itinerary);
            }
        }
    }