Пример #1
0
        public void DispatchDelayedMessages()
        {
            //this procedure is being called each update

            //first get current time
            double CurrentTime = Clock.Instance().GetCurrentTime();

            //check whether we need to dispatch messages or not
            bool notNull = !(PriorityQ.begin().Msg == -1 && PriorityQ.begin().Receiver == -1 &&
                             PriorityQ.begin().Sender == -1);

            while ((PriorityQ.begin().DispatchTime < CurrentTime) &&
                   (PriorityQ.begin().DispatchTime > 0) && notNull)
            {
                Telegram telegram = PriorityQ.begin();

                //find the recipient
                BaseGameEntity pReceiver = EntityManager.Instance().GetEntityFromID(telegram.Receiver);

                //send the telegram to recipient
                Discharge(pReceiver, telegram);

                //and remove it from the queque
                PriorityQ.Remove(PriorityQ.begin());
            }
        }
Пример #2
0
        public BaseGameEntity GetEntityFromID(int id)
        {
            BaseGameEntity answer = null;

            foreach (BaseGameEntity entity in m_EntityMap)
            {
                if (entity.ID == id)
                {
                    answer = entity;
                    break;
                }
            }

            return(answer);
        }
Пример #3
0
        //the procedure isbeing used for adding new messages in queque
        public void DispatchMessage(double delay, int sender, int receiver, int msg, AdditionalInfo additionalInfo)
        {
            Telegram telegram;

            //receiver
            BaseGameEntity pReceiver = EntityManager.Instance().GetEntityFromID(receiver);

            //create telegram
            if (additionalInfo == null)
            {
                telegram = new Telegram(0, sender, receiver, msg);
            }
            else
            {
                telegram = new Telegram(0, sender, receiver, msg, additionalInfo);
            }

            if (delay <= 0)
            {
                if ((EntityManager.Instance().GetEntityFromID(sender).GetType().ToString() == "AI1_The_West_World_Project.MacWorker") ||
                    (EntityManager.Instance().GetEntityFromID(receiver).GetType().ToString() == "AI1_The_West_World_Project.MacWorker"))
                {
                    Debugger.Instance().WriteLine(String.Format("\nThe message {0} from {1} to {2} was sent immediately", (message_type_mac)msg,
                                                                EntityManager.Instance().GetNameOfEntity(sender), EntityManager.Instance().GetNameOfEntity(receiver)));
                }
                else
                {
                    Debugger.Instance().WriteLine(String.Format("\nThe message {0} from {1} to {2} was sent immediately", (message_type)msg,
                                                                EntityManager.Instance().GetNameOfEntity(sender), EntityManager.Instance().GetNameOfEntity(receiver)));
                }

                Discharge(pReceiver, telegram);
            }
            else
            {
                double CurrentTime = Clock.Instance().GetCurrentTime();

                telegram.DispatchTime = CurrentTime + delay;

                PriorityQ.Add(telegram);

                Debugger.Instance().WriteLine(String.Format("\nThe delayed message {0} from {1} to {2} was sent. It will be discharged in {3} s", (message_type)msg,
                                                            EntityManager.Instance().GetNameOfEntity(sender), EntityManager.Instance().GetNameOfEntity(receiver),
                                                            delay));
            }
        }
Пример #4
0
 private void Discharge(BaseGameEntity pReceiver, Telegram msg)
 {
     pReceiver.HandleMessage(msg);
 }
Пример #5
0
 public void RemoveEntity(BaseGameEntity pEntity)
 {
     m_EntityMap.Remove(pEntity);
 }
Пример #6
0
 public void RegisterEntity(BaseGameEntity NewEntity)
 {
     m_EntityMap.Add(NewEntity);
 }