Exemple #1
0
        private void init_SewersThing(BaseTownGenerator tgen)
        {
#if DEBUG
            if (null != TheSewersThing)
            {
                throw new InvalidOperationException("only call UniqueActors::init_SewersThing once");
            }
#endif
            Map        map    = tgen.RandomDistrictInCity().SewersMap;
            Actor      named  = GameActors.SewersThing.CreateNamed(GameFactions.TheUndeads, "The Sewers Thing", 0);
            DiceRoller roller = new DiceRoller(map.Seed);
            if (!MapGenerator.ActorPlace(roller, map, named))
            {
                throw new InvalidOperationException("could not spawn unique The Sewers Thing");
            }
            Zone zoneByPartialName = map.GetZoneByPartialName("Sewers Maintenance");
            if (zoneByPartialName != null)
            {
                MapGenerator.MapObjectPlaceInGoodPosition(map, zoneByPartialName.Bounds, pt => {
                    return(map.IsWalkable(pt) && !map.HasActorAt(in pt) && !map.HasItemsAt(pt) && !map.HasExitAt(in pt));
                }, roller, pt => BaseMapGenerator.MakeObjBoard(GameImages.OBJ_BOARD, new string[] {
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);
        }
Exemple #3
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 #4
0
 public static bool ActorPlace(DiceRoller roller, Map map, Actor actor, Predicate <Point> goodPositionFn = null)
 {
     return(ActorPlace(roller, map, actor, map.Rect, goodPositionFn));
 }
        public void MapObjectPlaceInGoodPosition(Map map, int left, int top, int width, int height, Func <Point, bool> isGoodPosFn, DiceRoller roller, Func <Point, MapObject> createFn)
        {
            // find all good positions.
            List <Point> goodList = null;

            Point p = new Point();

            for (int x = left; x < left + width; x++)
            {
                p.X = x;
                for (int y = top; y < top + height; y++)
                {
                    p.Y = y;

                    if (isGoodPosFn(p) && map.GetMapObjectAt(x, y) == null)
                    {
                        if (goodList == null)
                        {
                            goodList = new List <Point>();
                        }
                        goodList.Add(p);
                    }
                }
            }

            // pick a good position at random and put the object there.
            if (goodList == null)
            {
                return;
            }
            int       iValid = roller.Roll(0, goodList.Count);
            MapObject mapObj = createFn(goodList[iValid]);

            if (mapObj != null)
            {
                map.PlaceMapObjectAt(mapObj, goodList[iValid]);
            }
        }
 public void MapObjectPlaceInGoodPosition(Map map, Rectangle rect, Func <Point, bool> isGoodPosFn, DiceRoller roller, Func <Point, MapObject> createFn)
 {
     MapObjectPlaceInGoodPosition(map, rect.Left, rect.Top, rect.Width, rect.Height, isGoodPosFn, roller, createFn);
 }
 public bool ActorPlace(DiceRoller roller, int maxTries, Map map, Actor actor, Predicate <Point> goodPositionFn)
 {
     return(ActorPlace(roller, maxTries, map, actor, 0, 0, map.Width, map.Height, goodPositionFn));
 }
 public bool ActorPlace(DiceRoller roller, int maxTries, Map map, Actor actor, int left, int top, int width, int height)
 {
     return(ActorPlace(roller, maxTries, map, actor, left, top, width, height, null));
 }
 public bool ActorPlace(DiceRoller roller, int maxTries, Map map, Actor actor)
 {
     return(ActorPlace(roller, maxTries, map, actor, null));
 }