/// <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> /// Cancels the next upcoming metro in the schedule. /// </summary> public void CancelNextMetro() { ModeInfo mInfo = null; foreach (ModeInfo m in listOfMetros) { if (m.GetTimeOfArrival() > Time.time && !m.GetStatus().Equals(Status.OUT_OF_SCHEDULE)) { m.SetStatus(Status.OUT_OF_SCHEDULE); mInfo = m; break; } } if (notificatePedestriansSuscribed) { //Notifies about the cancellation to those pedestrians that are suscribed to the ModeDB. UnityEngine.Debug.Log("Broadcasting this message: " + mInfo.ToString()); pedestrians.BroadcastMessage("NewMessagefromModeDBReceived", new Tuple <ModeInfo, int>(mInfo, 2)); } }
/// <summary> /// Introduces a delay in all the buses of the schedule. /// </summary> /// <param name="delay">Float containing the amount of delay in seconds.</param> public void DelayBuses(float delay) { foreach (ModeInfo m in listOfBuses) { if (!m.GetStatus().Equals(Status.OUT_OF_SCHEDULE)) { m.DelayMode(delay); m.SetStatus(Status.DELAYED); } } if (notificatePedestriansSuscribed) { //Notifies about the delay to those pedestrians that are suscribed to the ModeDB. ModeInfo mInfo = GetNextBusInfo(); if (mInfo != null) { UnityEngine.Debug.Log("Broadcasting this message: " + mInfo.ToString()); pedestrians.BroadcastMessage("NewMessagefromModeDBReceived", new Tuple <ModeInfo, int>(mInfo, 1)); } } }