Esempio n. 1
0
 /// <summary>
 /// Check a rumour about a station out of bikes that comes from another pedestrian.
 /// </summary>
 /// <param name="rumour">Bike station that is out of bikes.</param>
 public void CheckNoBikesRumour(BikeStationScript stationOutOfBikes)
 {
     if (takingABike && targetedBikeStation.Equals(stationOutOfBikes))
     {
         // Arrives at the bike station
         takingABike = false;
         FSM.SetBool("OnBikeStation", true);
     }
 }
 /// <summary>
 /// Registers a bike station in the informer.
 /// </summary>
 /// <param name="bikeStation">Transform of the bike station.</param>
 internal void RegisterBikeStationPosition(BikeStationScript bikeStation)
 {
     if (bikeStations.ContainsKey(bikeStation.GetHashCode()))
     {
         bikeStations[bikeStation.GetHashCode()] = bikeStation;
     }
     else
     {
         bikeStations.Add(bikeStation.GetHashCode(), bikeStation);
     }
 }
Esempio n. 3
0
    /// <summary>
    /// Spreads around the rumour that there are no more bikes on a certain bike station.
    /// </summary>
    /// <param name="targetedBikeStation">Bike station that is out of bikes.</param>
    internal void SpreadNoBikesRumour(BikeStationScript targetedBikeStation)
    {
        Collider[] pedestriansAffected = Physics.OverlapSphere(this.transform.position, flashInformer.globalParam.radiusOfSpreadingRumours, LayerMask.GetMask("Pedestrian"));

        foreach (var p in pedestriansAffected)
        {
            if (p.transform == this.transform)
            {
                continue;
            }

            p.SendMessage("CheckNoBikesRumour", targetedBikeStation, SendMessageOptions.DontRequireReceiver);
        }
    }
    /// <summary>
    /// Attempts to find the closest bike station within a certain radious of a given point.
    /// </summary>
    /// <param name="point">Point of interest.</param>
    /// <param name="radius">Radious around the point to check bike stations.</param>
    /// <returns>The transform of the closest bike station or null if any was found.</returns>
    internal BikeStationScript FindBikeStationNearby(Vector3 point)
    {
        BikeStationScript closestBikeStation = null;
        float             currentDistance    = float.MaxValue;

        foreach (KeyValuePair <int, BikeStationScript> K in bikeStations)
        {
            float newDistance = Vector3.Distance(K.Value.transform.position, point);
            if (newDistance < currentDistance && Vector3.Distance(K.Value.transform.position, point) < K.Value.bikeRadius && K.Value.capacityNumber > 0)
            {
                closestBikeStation = K.Value;
                currentDistance    = newDistance;
            }
        }

        return(closestBikeStation);
    }
Esempio n. 5
0
    /// <summary>
    /// Update method.
    /// </summary>
    void Update()
    {
        // Check if the flash pedestrian is paused
        if (globalParam != null)
        {
            if (globalParam.flashPedestriansPaused && !isPause)
            {
                navAgent.speed = 0;
                isPause        = true;
            }
            else if (!globalParam.flashPedestriansPaused && isPause)
            {
                navAgent.speed = profile.speed;

                if (goingBikingToDestination)
                {
                    navAgent.speed += 3;
                }

                isPause = false;
            }
        }

        if (!isPause)
        {
            // Check the weather and update pedestrian behaviour accordingly
            if (currentWeather != flashInformer.globalParam.currentWeatherCondition)
            {
                ChangePedestrianBehaviourOnWeather(flashInformer.globalParam.currentWeatherCondition);
            }

            // If going to station, check if pedestrian has arrived to station
            if (goingToStation && Vector3.Distance(this.transform.position, nextPoint.position) < 4.0f)
            {
                // Arrives at the station
                goingToStation = false;
                FSM.SetBool("OnStation", true);
            }

            // If going to destination, check if pedestrian has arrived to destination
            if (goingToDestination && Vector3.Distance(transform.position, routing.destination.transform.position) < 4.0f)
            {
                // Arrives at the destination
                goingToDestination = false;
                FSM.SetBool("OnDestination", true);
            }

            // If going to take a bike, check if pedestrian has arrived to bike station
            if (takingABike && Vector3.Distance(this.transform.position, targetedBikeStation.transform.position) < 4.0f)
            {
                // Arrives at the bike station
                takingABike = false;
                FSM.SetBool("OnBikeStation", true);
            }

            // If going to take a bike an arrived and there is no bike station there, bike station has moved
            if (takingABike && (navAgent.remainingDistance < 3.0f || navAgent.isPathStale))
            {
                navAgent.ResetPath();
                navAgent.SetDestination(targetedBikeStation.transform.position);
            }

            // If going to destination biking, check if pedestrian has arrived to destination
            if (goingBikingToDestination && Vector3.Distance(this.transform.position, routing.destination.transform.position) < 4.0f)
            {
                // Arrives at the destination
                goingBikingToDestination = false;
                FSM.SetBool("OnDestination", true);
            }

            // If car awareness is active and pedestrian is walking or cycling, check if it is on a road
            if (profile.carAwareness && (goingToStation || goingToDestination || takingABike || goingBikingToDestination))
            {
                if (carAwarenessTimer > carAwarenessFrequency)
                {
                    UnityEngine.AI.NavMeshHit navHit;
                    if (navAgent.enabled && navAgent.hasPath && !navAgent.SamplePathPosition(-1, 2.0f, out navHit))
                    {
                        if ((navHit.mask & roadMask) != 0)
                        {
                            // Send message to the cars around
                            InformVehiclesAround();
                        }
                    }

                    carAwarenessTimer = 0.0f;
                }

                carAwarenessTimer += Time.deltaTime;
            }

            // If bikes are enabled, check if there are bike stations around
            if (flashInformer.globalParam.bikesEnabled && (!takingABike || !goingBikingToDestination))
            {
                // If the pedestrian is willing to take a bike, it will look for bike stations nearby.
                if ((goingToStation || goingToDestination) && bikeAwarenessTimer > bikeAwarenessFrequency &&
                    profile.chanceOfTakingABike + flashInformer.globalParam.percOfPedTakingBikes * profile.weatherFactorOnTakingBikes > 1.0f)
                {
                    targetedBikeStation = flashInformer.FindBikeStationNearby(this.transform.position);

                    if (targetedBikeStation != null && targetedBikeStation.capacityNumber > 0)
                    {
                        navAgent.enabled = false;
                        GoToBikeStation();
                    }

                    bikeAwarenessTimer = 0.0f;
                }

                bikeAwarenessTimer += Time.deltaTime;
            }
        }
    }