예제 #1
0
        public override bool HandleMessage(Msg message)
        {
            switch (message.MessageType)
            {
                case Constants.Messages.ActorSeen:
                    Actor seen = (Actor)message.Data;
                    if (seen is HumanCitizen)
                    {
                        CitizenBaseStats cs = (CitizenBaseStats)seen.Statistics;

                        //Is this the closest target?  if so, attack
                        if (Stats.Target == null) {
                            Stats.Target = seen;
                        } else if (Stats.Target != null && ((Stats.Target.Statistics as CitizenBaseStats).LocationVec.Subtract(Stats.LocationVec).LengthSquared() > cs.LocationVec.Subtract(Stats.LocationVec).LengthSquared())) {
                            Stats.Target = seen;
                        }
                        if (ParentActor.Intention.Primary.CurrentAction

                    }
                    return true;

                default:
                    return false;
            }
        }
예제 #2
0
 public static void DispatchMessage(Msg msg)
 {
     if (msg.DispatchTime <= 0)
     {
         Dispatch(msg);
     }
     else
     {
         AddMessage(msg);
     }
 }
예제 #3
0
 public bool HandleMessage(Msg message)
 {
     bool rtrn = false;
     foreach (Behavior b in behaviors)
     {
         if (b.CurrentAction.HandleMessage(message)) rtrn = true;
     }
     if (!rtrn)
     {
         return GlobalState.HandleMessage(message);
     }
     else
     {
         return true;
     }
 }
예제 #4
0
 public bool HandleMessage(Msg message)
 {
     return Intention.HandleMessage(message);
 }
        public void CheckVision()
        {
            //Get the list of actors in nearby grid squares.
            //Check for 100% cover or inside a building
            //Do a distance squared check to find actors within the vision radius
            //Do an angle check for any actors outside of the vision range
            //Compare the current list of what actors are in sight
            //  to the list of ones it sees now.  If the status changes, send a message

            WorkingActorList.Clear();
            List<Actor> PotentialActorsInSight = Area.Grid.ActorsInRange(VisionDistance, (ParentActor.Locomotion as CitizenLocomotion).CurrentGridPoint);
            bool vis = true;
            double VDSquared = Convert.ToDouble(VisionDistance * VisionDistance);
            Msg m;
            foreach (var visAct in ActorsInSight)
            {
                vis = true;
                if ((visAct.Statistics as CitizenStats).Cover > 0) vis = Utilities.RTFWeighted(100 - (visAct.Statistics as CitizenStats).Cover);
                if (vis && (Stats.LocationVec.Subtract((visAct.Statistics as CitizenStats).LocationVec).LengthSquared() < VDSquared)) vis = false;
                if (vis && (LookDirection.AngleTo((visAct.Statistics as CitizenStats).LocationVec) > VisionAngle)) vis = false;
                if (vis)
                {
                    ActorsInSight.Add(visAct);
                    WorkingActorList.Add(visAct);
                    m = new Msg(ParentActor ,ParentActor, Constants.Messages.ActorSeen, 0f, visAct);
                    MessageDispatcher.DispatchMessage(m);
                }

            }

            for (int i = ActorsInSight.Count()-1; i >=0; i--)
            {
                if (!WorkingActorList.Contains(ActorsInSight[i])) {
                    m = new Msg(ParentActor, ParentActor, Constants.Messages.ActorNoLongerSeen, 0f, ActorsInSight[i]);
                    ActorsInSight.RemoveAt(i);
                }
            }
        }
 public override bool HandleMessage(Msg msg)
 {
     return false;
 }
        public void GenerateSound(string Sound, int Intensity)
        {
            //Get a list of actors in the nearby grid squares
            //If the actor is in a building, cut the intensity by half
            //Intensity varies inversely to the distance away
            //if the modified intensity (squared) is bigger than the distance squared then
            //Send messages to those actors.
            List<Actor> PotentiallyAudibleActors = Area.Grid.ActorsInRange(ListenDistance, (ParentActor.Locomotion as CitizenLocomotion).CurrentGridPoint);
            int tempInt;
            double dist;
            Msg m;
            foreach (var PAA in PotentiallyAudibleActors)
            {
                tempInt = Intensity;
                if ((PAA.Statistics as CitizenBaseStats).InBuilding != Stats.InBuilding) tempInt /= 2;
                if (tempInt >= 1) {
                    dist = ((PAA.Statistics as CitizenBaseStats).LocationVec.Subtract(Stats.LocationVec)).Length();
                    tempInt = tempInt - (int)dist;
                    if (tempInt > 0)
                    {
                        m = new Msg(ParentActor, PAA, Constants.Messages.SoundHeard, 0f, tempInt);
                        MessageDispatcher.DispatchMessage(m);
                    }

                }

            }
        }
예제 #8
0
 private static void Dispatch(Msg msg)
 {
     msg.Receiver.HandleMessage(msg);
 }
예제 #9
0
 private static void AddMessage(Msg msg)
 {
     MessageQueue.Add(msg);
     MessageQueue = MessageQueue.OrderBy(s => s.DispatchTime).ToList();
 }
 public virtual bool HandleMessage(Msg message)
 {
     return false;
 }