/// <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; } }
/// <summary> /// Compares the current knowledge of the pedestrian with ModeDB and updates the information. Takes also the next available mode from the ModeDB. /// </summary> public void UpdateKnowledgeFromModeDB() { if (mode == 1) { foreach (var m in currentModeInfoKnowledge) { ModeInfo modefromDB = mdb.GetBusInfoWithId(m.GetId()); if (modefromDB != null && !modefromDB.Equals(mdb)) { //Copy mode (not referencing!) currentModeInfoKnowledge[m.index] = new ModeInfo(modefromDB.GetId(), modefromDB.GetTimeOfArrival()); currentModeInfoKnowledge[m.index].SetStatus(modefromDB.GetStatus()); currentModeInfoKnowledge[m.index].index = m.index; } } } else { foreach (var m in currentModeInfoKnowledge) { ModeInfo modefromDB = mdb.GetMetroInfoWithId(m.GetId()); if (modefromDB != null && !modefromDB.Equals(mdb)) { //Copy mode (not referencing!) currentModeInfoKnowledge[m.index] = new ModeInfo(modefromDB.GetId(), modefromDB.GetTimeOfArrival()); currentModeInfoKnowledge[m.index].SetStatus(modefromDB.GetStatus()); currentModeInfoKnowledge[m.index].index = m.index; } } } GetNextModeFromDB(); }
/// <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; } } }