// Attempt to send a message to a particular agent; called by the preceding two methods -- don't call this from your own agents private static void SendMessage(Agent agent, Telegram telegram) { if (!agent.HandleMessage(telegram)) { Printer.PrintMessageData("Message: " + telegram.messageType.ToString() + " not handled"); } }
// This message is used by agents to dispatch messages to other agents -- use this from your own agents public static void DispatchMessage(double delay, int sender, int receiver, MessageType messageType, Object extra = null) { Agent sendingAgent = AgentManager.GetAgent(sender); Agent receivingAgent = AgentManager.GetAgent(receiver); Telegram telegram = new Telegram(0, sender, receiver, messageType); if (extra != null) telegram.extraInfo = extra; if (delay <= 0.0f) { //Printer.PrintMessageData("Instant telegram dispatched by " + sender + " for " + receiver + " message is " + messageType.ToString()); SendMessage(receivingAgent, telegram); } else { telegram.DispatchTime = (int)gameTime.TotalGameTime.Ticks + delay; telegramQueue.Add(telegram); //Printer.PrintMessageData("Delayed telegram from " + sender + " recorded at time " + gameTime.TotalGameTime.Ticks); } }
// This method is invoked when the agent receives a message public override bool HandleMessage(Telegram telegram) { return stateMachine.HandleMessage(telegram); }
public abstract bool HandleMessage(Telegram telegram);