コード例 #1
0
    /// <summary>
    /// Auxiliar method used from ModeDB through BroadcastMessage. Handles the reception of new ModeDB information in the pedestrian knowledge.
    /// </summary>
    /// <param name="information">Tuple containing the ModeInfo object and an integer indicating the mode.</param>
    public void NewMessagefromModeDBReceived(Tuple <ModeInfo, int> information)
    {
        if (tellMeWhatYouAreDoing)
        {
            Debug.Log("Got a message!");
        }

        if (suscribedToModeDB && information.Item2 == mode)
        {
            ModeInfo mInfo = information.Item1;

            foreach (var m in currentModeInfoKnowledge)
            {
                if (mInfo.GetId().Equals(m.GetId()) && !mInfo.Equals(m) && mInfo.GetTimeCreated() > m.GetTimeCreated())
                {
                    if (tellMeWhatYouAreDoing)
                    {
                        Debug.Log("Message received from mode db: " + mInfo.ToString());
                    }

                    //Copy mode (not referencing!)
                    currentModeInfoKnowledge[m.index] = new ModeInfo(mInfo.GetId(), mInfo.GetTimeOfArrival());
                    currentModeInfoKnowledge[m.index].SetStatus(mInfo.GetStatus());
                    currentModeInfoKnowledge[m.index].index = m.index;
                }
            }

            RumourInfo rInfo = new RumourInfo("rumour" + mInfo.GetId(), mInfo, 1.0f);
            rumour = new Tuple <RumourInfo, int>(rInfo, information.Item2);

            InvokeRepeating("SpreadRumour", 1, 1.0f + Random.Range(0.0f, 1.0f));

            newKnowledgeToBeCheckedbyController = true;
        }
    }
コード例 #2
0
    /// <summary>
    /// Auxiliar method used from ModeDB through BroadcastMessage. Handles the reception of a new rumour in the pedestrian knowledge.
    /// </summary>
    /// <param name="information">Tuple containing the RumourInfo object and an integer indicating the mode.</param>
    public void NewRumourReceived(Tuple <RumourInfo, int> information)
    {
        if (information.Item2 == mode)
        {
            RumourInfo newRumour = information.Item1;

            if (!newRumour.GetId().Equals(rumour.Item1.GetId()) &&
                rumourSusceptibility > Random.Range(0.0f, 1.0f) &&
                newRumour.GetCredibility() > Random.Range(0.0f, 1.0f))
            {
                ModeInfo mInfo = (ModeInfo)newRumour.GetRumour();

                foreach (var m in currentModeInfoKnowledge)
                {
                    if (mInfo.GetId().Equals(m.GetId()) && !mInfo.Equals(m) && mInfo.GetTimeCreated() > m.GetTimeCreated())
                    {
                        //Copy mode (not referencing!)
                        currentModeInfoKnowledge[m.index] = new ModeInfo(mInfo.GetId(), mInfo.GetTimeOfArrival());
                        currentModeInfoKnowledge[m.index].SetStatus(mInfo.GetStatus());
                        currentModeInfoKnowledge[m.index].index = m.index;
                    }
                }

                // Spread message around
                float rumourCredibility = newRumour.GetCredibility() - 0.1f;

                if (rumourCredibility > 0.0f)
                {
                    RumourInfo rInfo = new RumourInfo(newRumour.GetId(), newRumour.GetRumour(), rumourCredibility);
                    rumour = new Tuple <RumourInfo, int>(rInfo, information.Item2);
                    InvokeRepeating("SpreadRumour", 1, 1.0f + Random.Range(0.0f, 1.0f));
                }

                newKnowledgeToBeCheckedbyController = true;
            }
        }
    }
コード例 #3
0
    /// <summary>
    /// Implements the behaviour when the finite state machine exits a certain state.
    /// </summary>
    /// <param name="stateName">Name of the state that the FSM is exiting.</param>
    public void onStateExit(string stateName)
    {
        switch (stateName)
        {
        case "Bus":
        case "Metro":
        {
            if (CurrentState == "End")
            {
                //Reads ModeDB information at the station
                knowledge.UpdateKnowledgeFromModeDB();

                //Takes the next available mode
                ModeInfo m = knowledge.NextAvailableMode();

                // Decide if the pedestrian takes the next mode or leaves the station
                if (m != null)
                {
                    //Check if there is a mode available soon
                    bool modeAvailableSoon = IsModeAvailableSoon();
                    animator.SetBool("modeAvailableSoon", modeAvailableSoon);

                    if (tellMeWhatYouAreDoing)
                    {
                        Debug.Log("My decision to stay at the station: " + modeAvailableSoon);
                    }

                    //If there is no mode available soon, spread the rumour around
                    if (!modeAvailableSoon)
                    {
                        RumourInfo rInfo = new RumourInfo("rumour" + m.GetId(), m, 1.0f);
                        knowledge.rumour = new Tuple <RumourInfo, int>(rInfo, knowledge.mode);
                        knowledge.InvokeRepeating("SpreadRumour", 1, 1.0f + Random.Range(0.0f, 1.0f));
                    }
                    else
                    {
                        this.transform.FindChild("bike").gameObject.SetActive(false);

                        //Stay at the station, put in pedestrian cache for reuse
                        pedestrianCache.Enqueue(this.gameObject);

                        //Send the pedestrian model away from the end point
                        steering.SendToLimbo();
                    }
                }
                else
                {
                    if (tellMeWhatYouAreDoing)
                    {
                        Debug.Log("I lost the last mode...");
                    }

                    //I lost the last mode! Go to the library then...
                    animator.SetBool("modeAvailableSoon", false);
                }
            }
            break;
        }

        case "Walk":
        case "ToBikeStation":     // added by furkan
        case "Bicycle":
        {
            this.transform.FindChild("bike").gameObject.SetActive(false);

            //Stay there, put in pedestrian cache for reuse
            pedestrianCache.Enqueue(this.gameObject);

            //Send the pedestrian model away from the end point
            steering.SendToLimbo();

            break;
        }

        case "End":
        {
            //It is not the end of the trip for this pedestrian
            animator.SetBool("endReached", false);
            break;
        }

        default:
        {
            //Do nothing
            break;
        }
        }
    }