Exemple #1
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);
        }
Exemple #2
0
        // Formerly Las Vegas algorithm.
        protected static bool ActorPlace(DiceRoller roller, Map map, Actor actor, Rectangle rect, Predicate <Point> goodPositionFn = null)
        {
#if DEBUG
            if (null == map)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (null == actor)
            {
                throw new ArgumentNullException(nameof(actor));
            }
#endif
            List <Point> valid_spawn = rect.Where(pt => map.IsWalkableFor(pt, actor) && (goodPositionFn == null || goodPositionFn(pt)));
            if (0 >= valid_spawn.Count)
            {
                return(false);
            }
            map.PlaceAt(actor, roller.Choose(valid_spawn));
            if (Session.Get.Police.IsEnemy(actor))
            {
                Session.Get.Police.Threats.RecordSpawn(actor, map, valid_spawn);
            }
            return(true);
        }