protected static void ItemsDrop(Map map, Rectangle rect, Predicate <Point> isGoodPositionFn, Func <Point, Item> createFn) { #if DEBUG if (null == createFn) { throw new ArgumentNullException(nameof(createFn)); } #endif rect.DoForEach(pt => createFn(pt)?.DropAt(map, pt), isGoodPositionFn); }
public Zone(string name, Rectangle bounds) { #if DEBUG if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } #endif m_Name = name; m_Bounds = bounds; }
protected static void MapObjectFill(Map map, Rectangle rect, Func <Point, MapObject> createFn) { #if DEBUG if (null == createFn) { throw new ArgumentNullException(nameof(createFn)); } #endif rect.DoForEach(pt => { createFn(pt)?.PlaceAt(map, in pt); // XXX RNG potentially involved }, pt => !map.HasMapObjectAt(pt)); }
static public Rectangle Edge(this Rectangle src, XCOMlike dir_code) { switch (dir_code) { case XCOMlike.N: return(new Rectangle(src.Left, src.Top, src.Width, 1)); case XCOMlike.S: return(new Rectangle(src.Left, src.Bottom - 1, src.Width, 1)); case XCOMlike.W: return(new Rectangle(src.Left, src.Top, 1, src.Height)); case XCOMlike.E: return(new Rectangle(src.Right - 1, src.Top, 1, src.Height)); default: throw new InvalidOperationException("direction code out of range"); } }
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)); } } }
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(); } } }
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); }
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); }
public List <Percept_ <AIScent> > Sense(Actor actor) { #if DEBUG if (OdorScent.MIN_STRENGTH > actor.SmellThreshold) { throw new ArgumentOutOfRangeException(nameof(actor), OdorScent.MIN_STRENGTH.ToString() + " > actor.SmellThreshold"); } #endif m_List.Clear(); int num = actor.SmellThreshold; // floors at 1 Rectangle survey = new Rectangle(actor.Location.Position + Direction.NW, 3, 3); Map map = actor.Location.Map; int turnCounter = map.LocalTime.TurnCounter; survey.DoForEach(pt => { var scentAt = map.GetScentByOdorAt(m_OdorToSmell, in pt); // XXX 0 is the no-scent value if (scentAt >= num) { m_List.Add(new Percept_ <AIScent>(new AIScent(scentAt), turnCounter, new Location(map, pt))); } }); return(m_List); }
static public Point Anchor(this Rectangle src, XCOMlike dir_code) // Tk/Tcl anchor point for aligning a rectangle { switch (dir_code) { case XCOMlike.N: return(new Point(src.Width / 2 + src.Left, src.Top)); case XCOMlike.NE: return(new Point(src.Right - 1, src.Top)); case XCOMlike.E: return(new Point(src.Right - 1, src.Height / 2 + src.Top)); case XCOMlike.SE: return(new Point(src.Right - 1, src.Bottom - 1)); case XCOMlike.S: return(new Point(src.Width / 2 + src.Left, src.Bottom - 1)); case XCOMlike.SW: return(new Point(src.Left, src.Bottom - 1)); case XCOMlike.W: return(new Point(src.Left, src.Height / 2 + src.Top)); case XCOMlike.NW: return(new Point(src.Left, src.Top)); default: throw new InvalidOperationException("direction code out of range"); } }
// 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); }
protected static void TileFill(Map map, TileModel model, Rectangle rect, Action <Tile, TileModel, int, int> decoratorFn = null) { TileFill(map, model, rect.Left, rect.Top, rect.Width, rect.Height, decoratorFn); }
protected static void TileFill(Map map, TileModel model, Rectangle rect, bool inside) { TileFill(map, model, rect.Left, rect.Top, rect.Width, rect.Height, inside); }
protected static void TileRectangle(Map map, TileModel model, Rectangle rect) { TileRectangle(map, model, rect.Left, rect.Top, rect.Width, rect.Height); }
public Point Choose(Rectangle r) // \todo evaluate stack-based version { return(new Point(Roll(r.Left, r.Right), Roll(r.Top, r.Bottom))); }