Beispiel #1
0
 protected static void PlaceDoorIfNoObject(Map map, Point pt, TileModel floor, DoorWindow door)
 {
     if (!map.HasMapObjectAt(pt))
     {
         PlaceDoor(map, pt, floor, door);
     }
 }
Beispiel #2
0
 protected static void MapObjectPlace(Map map, Point pt, MapObject mapObj)
 {
     if (!map.HasMapObjectAt(pt))
     {
         map.PlaceAt(mapObj, pt);
     }
 }
Beispiel #3
0
        public ActionShove(Actor actor, Actor target, Direction pushDir) : base(actor)
        {
            m_Target = target
#if DEBUG
                       ?? throw new ArgumentNullException(nameof(target))
#endif
            ;
            m_Direction = pushDir;
            m_To        = target.Location.Position + pushDir;
        }
Beispiel #4
0
        protected static bool PlaceDoorIfAccessible(Map map, Point pt, TileModel floor, int minAccessibility, DoorWindow door)
        {
            int num = Direction.COMPASS.Select(d => pt + d).Count(pt2 => map.IsWalkable(pt2)); // includes IsInBounds check

            if (num < minAccessibility)
            {
                return(false);
            }
            PlaceDoorIfNoObject(map, pt, floor, door);
            return(true);
        }
Beispiel #5
0
        public ActionPull(Actor actor, MapObject pullObj, Direction moveActorDir)
            : base(actor)
        {
#if DEBUG
            if (pullObj == null)
            {
                throw new ArgumentNullException(nameof(pullObj));
            }
#endif

            m_Object      = pullObj;
            m_MoveActorTo = m_Actor.Location.Position + moveActorDir;
        }
Beispiel #6
0
        public ActionPull(Actor actor, MapObject pullObj, Point moveActorTo)
            : base(actor)
        {
#if DEBUG
            if (pullObj == null)
            {
                throw new ArgumentNullException(nameof(pullObj));
            }
#endif

            m_Object      = pullObj;
            m_MoveActorTo = moveActorTo;
        }
Beispiel #7
0
        public static System.Collections.ObjectModel.ReadOnlyCollection <Point> OptimalFOV(short range)
        {
            if (OptimalFOVOffsets.TryGetValue(range, out var ret))
            {
                return(ret);                                               // TryGetValue indicated
            }
            List <Point> tmp = new List <Point>();
            // Cf. ComputeFOVFor
            double edge_of_maxrange = range + 0.5;
            Point  origin           = new Point(0, 0);
            Point  pt = new Point();

            for (pt.X = range; pt.X > 0; --pt.X)
            {
                for (pt.Y = pt.X; pt.Y >= 0; --pt.Y)
                {
                    // We want to reject points that are out of range, but still look circular in an open space
                    // the historical multipler was Math.Sqrt(.75)
                    // however, since we are in a cartesian gridspace the "radius to the edge of the square at max_range on the coordinate axis" is "radius to midpoint of square"+.5
                    if (Rules.StdDistance(in origin, in pt) > edge_of_maxrange)
                    {
                        continue;
                    }
                    // initialize all octants at once
                    tmp.Add(pt);
                    tmp.Add(-pt);
                    if (pt.X == pt.Y) // diagonal
                    {
                        tmp.Add(new Point(pt.X, -pt.Y));
                        tmp.Add(new Point(-pt.X, pt.Y));
                    }
                    else if (0 == pt.Y) // cardinal
                    {
                        tmp.Add(new Point(0, pt.X));
                        tmp.Add(new Point(0, -pt.X));
                    }
                    else // typical
                    {
                        tmp.Add(new Point(pt.X, -pt.Y));
                        tmp.Add(new Point(-pt.X, pt.Y));
                        tmp.Add(new Point(pt.Y, pt.X));
                        tmp.Add(new Point(pt.Y, -pt.X));
                        tmp.Add(new Point(-pt.Y, pt.X));
                        tmp.Add(new Point(-pt.Y, -pt.X));
                    }
                }
            }
            System.Collections.ObjectModel.ReadOnlyCollection <Point> tmp2 = new System.Collections.ObjectModel.ReadOnlyCollection <Point>(tmp);
            OptimalFOVOffsets[range] = tmp2;
            return(tmp2);
        }
Beispiel #8
0
        // dead, but typical for a map generation utility
        public Point DigUntil(Map map, TileModel model, Point startPos, Direction digDirection, Predicate <Point> stopFn)
        {
#if DEBUG
            if (null == stopFn)
            {
                throw new ArgumentNullException(nameof(stopFn));
            }
#endif
            Point p = startPos + digDirection;
            while (map.IsInBounds(p) && !stopFn(p))
            {
                map.SetTileModelAt(p.X, p.Y, model);
                p += digDirection;
            }
            return(p);
        }
Beispiel #9
0
        protected static void DoForEachTile(Rectangle rect, Map m, Action <Location> doFn)
        {
#if DEBUG
            if (null == doFn)
            {
                throw new ArgumentNullException(nameof(doFn));
            }
#endif
            Point point = new Point();
            for (point.X = rect.Left; point.X < rect.Right; ++point.X)
            {
                for (point.Y = rect.Top; point.Y < rect.Bottom; ++point.Y)
                {
                    doFn(new Location(m, point));
                }
            }
        }
Beispiel #10
0
 protected static void ClearRectangle(Map map, Rectangle rect, bool clearZones = true)
 {
     for (var left = rect.Left; left < rect.Right; ++left)
     {
         for (var top = rect.Top; top < rect.Bottom; ++top)
         {
             var pt = new Point(left, top);
             map.RemoveMapObjectAt(pt);
             map.RemoveAllItemsAt(pt);
             map.RemoveAllDecorationsAt(pt);
             if (clearZones)
             {
                 map.RemoveAllZonesAt(pt);
             }
             map.GetActorAt(pt)?.RemoveFromMap();
         }
     }
 }
Beispiel #11
0
        protected static void TileHLine(Map map, TileModel model, int left, int top, int width, Action <Tile, TileModel, Point> decoratorFn = null)
        {
#if DEBUG
            if (null == map)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (null == model)
            {
                throw new ArgumentNullException(nameof(model));
            }
#endif
            for (short x = (short)left; x < left + width; ++x)
            {
                Point     pt     = new Point(x, (short)top);
                TileModel model1 = map.GetTileModelAt(pt);
                map.SetTileModelAt(pt, model);
                decoratorFn?.Invoke(map.GetTileAt(pt), model1, pt);
            }
        }
Beispiel #12
0
        public static void MapObjectPlaceInGoodPosition(Map map, Rectangle rect, Func <Point, bool> isGoodPosFn, DiceRoller roller, Func <Point, MapObject> createFn)
        {
#if DEBUG
            if (null == createFn)
            {
                throw new ArgumentNullException(nameof(createFn));
            }
            if (null == isGoodPosFn)
            {
                throw new ArgumentNullException(nameof(isGoodPosFn));
            }
#endif
            List <Point> pointList = rect.Where(pt => isGoodPosFn(pt) && map.GetTileModelAt(pt).IsWalkable&& !map.HasMapObjectAt(pt));
            if (0 >= pointList.Count)
            {
                return;
            }
            Point pt2 = roller.Choose(pointList);
            createFn(pt2)?.PlaceAt(map, in pt2);
        }
Beispiel #13
0
        protected static void TileVLine(Map map, TileModel model, int left, int top, int height, Action <Tile, TileModel, Point> decoratorFn = null)
        {
#if DEBUG
            if (null == map)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (null == model)
            {
                throw new ArgumentNullException(nameof(model));
            }
#endif
            for (short y = (short)top; y < top + height; ++y)
            {
                Point     pt     = new Point((short)left, y);
                TileModel model1 = map.GetTileModelAt(pt);
                map.SetTileModelAt(pt, model);
                decoratorFn?.Invoke(map.GetTileAt(pt), model1, pt);
            }
        }
Beispiel #14
0
        protected static bool CheckForEachTile(Rectangle rect, Predicate <Point> predFn)
        {
#if DEBUG
            if (null == predFn)
            {
                throw new ArgumentNullException(nameof(predFn));
            }
#endif
            Point point = new Point();
            for (point.X = rect.Left; point.X < rect.Right; ++point.X)
            {
                for (point.Y = rect.Top; point.Y < rect.Bottom; ++point.Y)
                {
                    if (!predFn(point))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #15
0
        protected static bool PlaceDoorIfAccessibleAndNotAdjacent(Map map, Point pt, TileModel floor, int minAccessibility, DoorWindow door)
        {
            int num = 0;

            foreach (var point2 in pt.Adjacent()) // micro-optimized: loop combines a reject-any check with a counting operation
            {
                if (map.IsWalkable(point2))
                {
                    ++num;
                }
                if (map.GetMapObjectAt(point2) is DoorWindow)
                {
                    return(false);
                }
            }
            if (num < minAccessibility)
            {
                return(false);
            }
            PlaceDoorIfNoObject(map, pt, floor, door);
            return(true);
        }
Beispiel #16
0
        public ActionPush(Actor actor, MapObject pushObj, Direction pushDir)
            : base(actor)
        {
#if DEBUG
            if (null == pushObj)
            {
                throw new ArgumentNullException(nameof(pushObj));
            }
            if (null == pushDir)
            {
                throw new ArgumentNullException(nameof(pushDir));
            }
#endif
            m_Object    = pushObj;
            m_Direction = pushDir;
            m_To        = pushObj.Location.Position + pushDir;
#if DEBUG
            // will be ok when tactical pushing is implemented
            if (actor.Controller is Gameplay.AI.OrderableAI && m_Object.Location.Map.HasExitAt(in m_To) && m_Object.Location.Map.IsInBounds(m_To) && !m_Object.IsJumpable)
            {
                throw new InvalidOperationException("Blocking exit with push");
            }
#endif
        }
Beispiel #17
0
 protected static int CountAdjWalls(Map map, Point p)
 {
     return(map.CountAdjacentTo(p, pt => !map.GetTileModelAt(pt).IsWalkable));
 }
 static public ActionTradeWith Cast(Point pt, Actor actor, Item give, Item take)
 {
     return(Cast(new Location(actor.Location.Map, pt), actor, give, take));
 }
Beispiel #19
0
 public ActionThrowGrenade(Actor actor, Point throwPos)
     : base(actor)
 {
     m_ThrowPos = throwPos;
 }
Beispiel #20
0
 protected static void PlaceDoor(Map map, Point pt, TileModel floor, DoorWindow door)
 {
     map.SetTileModelAt(pt, floor);
     MapObjectPlace(map, pt, door);
 }