Пример #1
0
        ///<summary>
        ///Handle messages sent to this bot.
        ///</summary>
        ///<param name="msg">the message</param>
        ///<returns>true if message was handled by this bot</returns>
        public override bool HandleMessage(Telegram msg)
        {
            //first see if the current goal accepts the message
            if (Brain.HandleMessage(msg))
                return true;

            //handle any messages not handled by the goals
            switch (msg.Msg)
            {
                case MessageTypes.TakeThatMF:
                    //just return if already dead or spawning
                    if (IsDead || IsSpawning)
                        return true;

                    //the extra info field of the telegram carries
                    //the amount of damage
                    ReduceHealth((int) msg.ExtraInfo);

                    //if this bot is now dead let the shooter know
                    if (IsDead)
                    {
                        MessageDispatcher.Instance.DispatchMsg(
                            MessageDispatcher.SEND_MSG_IMMEDIATELY,
                            ObjectId,
                            msg.Sender,
                            MessageTypes.YouGotMeYouSOB,
                            MessageDispatcher.NO_ADDITIONAL_INFO);
                    }

                    return true;

                case MessageTypes.YouGotMeYouSOB:
                    IncrementScore();

                    //the bot this bot has just killed should
                    //be removed as the target
                    TargetingSystem.ClearTarget();

                    return true;

                case MessageTypes.GunshotSound:
                    //add the source of this sound to the bot's percepts
                    SensoryMemory.UpdateWithSoundSource((BotEntity) msg.ExtraInfo);

                    return true;

                case MessageTypes.UserHasRemovedBot:
                    BotEntity removedBot = (BotEntity) msg.ExtraInfo;
                    SensoryMemory.RemoveBotFromMemory(removedBot);

                    //if the removed bot is the target, make
                    //sure the target is cleared
                    if (removedBot == TargetingSystem.Target)
                    {
                        TargetingSystem.ClearTarget();
                    }

                    return true;

                default:
                    return false;
            }
        }
Пример #2
0
        ///<summary>
        ///handle messages
        ///</summary>
        ///<param name="msg"></param>
        ///<returns></returns>
        public override bool HandleMessage(Telegram msg)
        {
            //first, pass the message down the goal hierarchy
            bool isHandled = ForwardMessageToFrontMostSubgoal(msg);

            if (isHandled)
            {
                LogUtil.WriteLineIfLogMoveToPosition(
                    LogPrefixText + LogHandleMessageText + LogStatusText +
                    LogDestinationText + _destination +
                    " Message handled by subgoal");
            }

            //if the msg was not handled, test to see if this goal can handle it
            if (!isHandled)
            {
                switch (msg.Msg)
                {
                    case MessageTypes.PathReady:
                        LogUtil.WriteLineIfLogMoveToPosition(
                            LogPrefixText + LogHandleMessageText + LogStatusText +
                            LogDestinationText + _destination +
                            " Msg: path ready");
                        //clear any existing goals
                        RemoveAllSubgoals();

                        LogUtil.WriteLineIfLogMoveToPosition(
                            LogPrefixText + LogHandleMessageText + LogStatusText +
                            LogAddSubgoalText + "FollowPath: " + PathToString());
                        AddSubgoal(
                            new FollowPath(Bot, Bot.PathPlanner.GetPath()));
                        return true; //msg handled

                    case MessageTypes.NoPathAvailable:
                        Status = StatusTypes.Failed;
                        LogUtil.WriteLineIfLogMoveToPosition(
                            LogPrefixText + LogHandleMessageText + LogStatusText +
                            LogDestinationText + _destination +
                            " Msg: no path available");
                        return true; //msg handled

                    default:
                        return false;
                }
            }

            //handled by subgoals
            return true;
        }
Пример #3
0
        ///<summary>
        ///passes the message to the goal at the front of the queue
        ///</summary>
        ///<param name="msg"></param>
        ///<returns>false if the message has not been handled</returns>
        public bool ForwardMessageToFrontMostSubgoal(Telegram msg)
        {
            if (Subgoals.Count > 0)
            {
                LogUtil.WriteLineIfVerbose(LogPrefixText + LogForwardMsgText +
                                           LogStatusText +
                                           " {" + msg.DispatchTime + ", " +
                                           msg.Sender + ", " +
                                           msg.Receiver + ", " +
                                           msg.Msg + "} --> Subgoal: " +
                                           EnumUtil.GetDescription(Subgoals.Peek().GoalType));
            }

            return Subgoals.Count > 0 && Subgoals.Peek().HandleMessage(msg);
        }
Пример #4
0
 ///<summary>
 ///Handle messages sent to this entity. Default is to not handle
 ///messages.
 ///</summary>
 ///<param name="msg">the message</param>
 ///<returns>true if message was handled by this entity</returns>
 public override bool HandleMessage(Telegram msg)
 {
     return false;
 }
Пример #5
0
 ///<summary>
 ///if a child class of Composite does not define a message handler the
 ///default behavior is to forward the message to the front-most subgoal
 ///</summary>
 ///<param name="msg"></param>
 ///<returns></returns>
 public override bool HandleMessage(Telegram msg)
 {
     return ForwardMessageToFrontMostSubgoal(msg);
 }
Пример #6
0
 ///<summary>
 ///messages that are considered the same
 ///TODO: we didn't use this ...
 ///</summary>
 ///<param name="t"></param>
 ///<returns></returns>
 public bool IsSameAs(Telegram t)
 {
     return Math.Abs(DispatchTime - t.DispatchTime) < SMALLEST_DELAY &&
            Sender == t.Sender &&
            Receiver == t.Receiver &&
            Msg == t.Msg;
 }
Пример #7
0
        ///<summary>
        ///message ordering
        ///TODO: we didn't use this ...
        ///</summary>
        ///<param name="t"></param>
        ///<returns></returns>
        public bool IsEarlierThan(Telegram t)
        {
            if (this == t)
            {
                return false;
            }

            return (DispatchTime < t.DispatchTime);
        }
Пример #8
0
 ///<summary>
 ///goals can handle messages. Many don't though, so this defines a
 ///default behavior
 ///</summary>
 ///<param name="msg"></param>
 ///<returns></returns>
 public virtual bool HandleMessage(Telegram msg)
 {
     return false;
 }
Пример #9
0
        ///<summary>
        ///Handle messages sent to this door.
        ///</summary>
        ///<param name="msg">the message</param>
        ///<returns>true if message was handled by this door</returns>
        public override bool HandleMessage(Telegram msg)
        {
            if (msg.Msg == MessageTypes.OpenSesame)
            {
                if (_status != DoorStatus.Open)
                {
                    _status = DoorStatus.Opening;
                }

                return true;
            }

            return false;
        }