示例#1
0
        public override List <Percept> Sense(RogueGame game, Actor actor)
        {
            // compute FOV
            HashSet <Point> visibleSet = LOS.ComputeFOVFor(game.Rules, actor);

            // compute percepts of other actors.
            List <Percept> list = new List <Percept>();

            // roughly estimate time for two sensing methods.
            int searchFovMethodTime        = actor.ViewRange * actor.ViewRange;
            int searchActorsListMethodTime = actor.Location.Map.CountActors;

            // choose method which seems less costly in time.
            if (searchFovMethodTime < searchActorsListMethodTime)
            {
                // FOV check : bad when few actors, good when many actors.
                foreach (Point p in visibleSet)
                {
                    Actor other = actor.Location.Map.GetActorAt(p.X, p.Y);
                    if (other != null && other != actor)
                    {
                        list.Add(new Percept(other, game.Session.WorldTime.TurnCounter, other.Location.Position));
                    }
                }
            }
            else
            {
                // Actors list check : good when few actors, bad when many actors.
                int maxRange = actor.ViewRange;
                foreach (Actor other in actor.Location.Map.Actors)
                {
                    if (other == actor)
                    {
                        continue;
                    }

                    if (game.Rules.LOSDistance(actor.Location.Position, other.Location.Position) > maxRange)
                    {
                        continue;
                    }

                    if (visibleSet.Contains(other.Location.Position))
                    {
                        list.Add(new Percept(other, game.Session.WorldTime.TurnCounter, other.Location.Position));
                    }
                }
            }

            // done.
            return(list);
        }
示例#2
0
        public override List <Percept> Sense(RogueGame game, Actor actor)
        {
            // compute FOV
            m_FOV = LOS.ComputeFOVFor(game.Rules, actor, actor.Location.Map.LocalTime, game.Session.World.Weather);
            int maxRange = game.Rules.ActorFOV(actor, actor.Location.Map.LocalTime, game.Session.World.Weather);

            // compute percepts.
            List <Percept> list = new List <Percept>();

            #region Actors
            if ((m_Filters & SensingFilter.ACTORS) != 0)
            {
                // roughly estimate time for two sensing methods.
                int searchFovMethodTime        = maxRange * maxRange;
                int searchActorsListMethodTime = actor.Location.Map.CountActors;

                // choose method which seems less costly in time.
                if (searchFovMethodTime < searchActorsListMethodTime)
                {
                    // FOV check : bad when few actors, good when many actors.
                    foreach (Point p in m_FOV)
                    {
                        Actor other = actor.Location.Map.GetActorAt(p.X, p.Y);
                        if (other != null && other != actor)
                        {
                            list.Add(new Percept(other, actor.Location.Map.LocalTime.TurnCounter, other.Location));
                        }
                    }
                }
                else
                {
                    // Actors list check : good when few actors, bad when many actors.
                    foreach (Actor other in actor.Location.Map.Actors)
                    {
                        if (other == actor)
                        {
                            continue;
                        }

                        if (game.Rules.LOSDistance(actor.Location.Position, other.Location.Position) > maxRange)
                        {
                            continue;
                        }

                        if (m_FOV.Contains(other.Location.Position))
                        {
                            list.Add(new Percept(other, actor.Location.Map.LocalTime.TurnCounter, other.Location));
                        }
                    }
                }
            }
            #endregion

            #region Items
            if ((m_Filters & SensingFilter.ITEMS) != 0)
            {
                foreach (Point p in m_FOV)
                {
                    Inventory inv = actor.Location.Map.GetItemsAt(p);
                    if (inv == null || inv.IsEmpty)
                    {
                        continue;
                    }
                    list.Add(new Percept(inv, actor.Location.Map.LocalTime.TurnCounter, new Location(actor.Location.Map, p)));
                }
            }
            #endregion

            #region Corpses
            if ((m_Filters & SensingFilter.CORPSES) != 0)
            {
                foreach (Point p in m_FOV)
                {
                    List <Corpse> corpses = actor.Location.Map.GetCorpsesAt(p.X, p.Y);
                    if (corpses != null)
                    {
                        list.Add(new Percept(corpses, actor.Location.Map.LocalTime.TurnCounter, new Location(actor.Location.Map, p)));
                    }
                }
            }
            #endregion

            // done.
            return(list);
        }