public static Stockpile CreateStockpile(EnvironmentObject environment, IntGrid2Z area) { var stockpile = new Stockpile(environment, area); environment.AddAreaElement(stockpile); return(stockpile); }
public void SetContext(EnvironmentObject env, IntGrid2Z area) { this.Environment = env; this.Area = area; areaTextBox.Text = String.Format("{0},{1} {2}x{3}", area.X, area.Y, area.Columns, area.Rows); }
public Stockpile(EnvironmentObject environment, IntGrid2Z area) { this.Environment = environment; this.Area = area; m_jobs = new List <StoreToStockpileJob>(); }
public Stockpile(EnvironmentObject environment, IntGrid2Z area) { this.Environment = environment; this.Area = area; m_jobs = new List<StoreToStockpileJob>(); }
IntGrid2Z?FindStartLocation(EnvironmentObject env) { const int size = 2; var center = env.StartLocation; foreach (var p in IntVector2.SquareSpiral(center.ToIntVector2(), env.Width / 2)) { if (env.Size.Plane.Contains(p) == false) { continue; } var z = env.GetSurfaceLevel(p); var r = new IntGrid2Z(p.X - size, p.Y - size, size * 2, size * 2, z); if (TestStartArea(env, r)) { return(r); } } return(null); }
public Map(int width, int height, int depth) { this.Grid = new AStarMapTile[depth, height, width]; this.Bounds = new IntGrid3(0, 0, 0, width, height, depth); for (int y = 0; y < 350; ++y) { SetBlocked(new IntVector3(5, y, 0), true); } for (int y = 2; y < 22; ++y) { SetBlocked(new IntVector3(14, y, 0), true); } for (int y = 6; y < 11; ++y) { SetWeight(new IntVector3(10, y, 0), 40); } for (int y = 6; y < 18; ++y) { SetBlocked(new IntVector3(3, y, 1), true); } for (int y = 6; y < 11; ++y) { SetWeight(new IntVector3(5, y, 1), 40); } SetStairs(new IntVector3(10, 10, 0), Stairs.Up); SetStairs(new IntVector3(10, 10, 1), Stairs.Down); SetStairs(new IntVector3(15, 12, 0), Stairs.Up); SetStairs(new IntVector3(15, 12, 1), Stairs.Down); var r = new Random(4); var bounds = new IntGrid2Z(16, 0, 30, 30, 0); foreach (var p in bounds.Range()) { var v = r.Next(100); if (v < 30) { SetBlocked(p, true); } else if (v < 60) { SetWeight(p, v); } } }
public static IEnumerable<ILivingObject> FindEnemies(IEnvironmentObject env, IntPoint3 location, int range, LivingCategory categories) { int maxSide = 2 * range + 1; var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z); return env.GetContents(rect) .OfType<ILivingObject>() .Where(o => (o.LivingCategory & categories) != 0) .OrderBy(o => (location - o.Location).Length); }
public static IEnumerable <ILivingObject> FindEnemies(IEnvironmentObject env, IntVector3 location, int range, LivingCategory categories) { int maxSide = 2 * range + 1; var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z); return(env.GetContents(rect) .OfType <ILivingObject>() .Where(o => (o.LivingCategory & categories) != 0) .OrderBy(o => (location - o.Location).Length)); }
public void AddConstructJob(ConstructMode mode, IntGrid2Z area, IItemFilter userItemFilter) { var locations = area.Range().Where(p => m_environment.Contains(p)); ITerrainFilter filter; IItemFilter coreItemFilter; switch (mode) { case ConstructMode.Floor: filter = WorkHelpers.ConstructFloorTerrainFilter; coreItemFilter = WorkHelpers.ConstructFloorItemFilter; break; case ConstructMode.Pavement: filter = WorkHelpers.ConstructPavementTerrainFilter; coreItemFilter = WorkHelpers.ConstructPavementItemFilter; break; case ConstructMode.Wall: filter = WorkHelpers.ConstructWallTerrainFilter; coreItemFilter = WorkHelpers.ConstructWallItemFilter; break; default: throw new Exception(); } IItemFilter itemFilter; if (userItemFilter != null) { itemFilter = new AndItemFilter(coreItemFilter, userItemFilter); } else { itemFilter = coreItemFilter; } locations = locations.Where(p => filter.Match(m_environment.GetTileData(p))); foreach (var l in locations) { var data = new ConstructJobData() { Mode = mode, Location = l, ItemFilter = itemFilter, }; m_jobDataList.Add(data); } }
public static ILivingObject FindNearestEnemy(IEnvironmentObject env, IntVector3 location, int range, LivingCategory categories) { int maxSide = 2 * range + 1; var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z); return env.GetContents(rect) .OfType<ILivingObject>() .Where(o => (o.LivingCategory & categories) != 0) .OrderBy(o => (location - o.Location).Length) .FirstOrDefault(); }
public CleanAreaJob(IJobObserver parent, EnvironmentObject env, IntGrid2Z area) : base(parent) { m_environment = env; m_area = area; m_map = new Dictionary<IntPoint3, IJob>(); foreach (var p in m_area.Range()) m_map[p] = null; m_environment.World.TickStarting += World_TickStarting; }
public static void CreateWater(EnvironmentObject env, IntGrid2Z area) { for (int x = area.X1; x <= area.X2; ++x) { for (int y = area.Y1; y <= area.Y2; ++y) { var p = new IntVector3(x, y, area.Z); ClearTile(env, p); env.SetWaterLevel(p, TileData.MaxWaterLevel); } } }
public void RemoveArea(IntGrid2Z area) { var rm = m_jobDataList.Where(d => area.Contains(d.Location)).ToArray(); foreach (var d in rm) { if (d.Job != null) { d.Job.Abort(); } m_jobDataList.Remove(d); } }
public void AddConstructJob(ConstructMode mode, IntGrid2Z area, IItemFilter userItemFilter) { var locations = area.Range().Where(p => m_environment.Contains(p)); ITerrainFilter filter; IItemFilter coreItemFilter; switch (mode) { case ConstructMode.Floor: filter = WorkHelpers.ConstructFloorTerrainFilter; coreItemFilter = WorkHelpers.ConstructFloorItemFilter; break; case ConstructMode.Pavement: filter = WorkHelpers.ConstructPavementTerrainFilter; coreItemFilter = WorkHelpers.ConstructPavementItemFilter; break; case ConstructMode.Wall: filter = WorkHelpers.ConstructWallTerrainFilter; coreItemFilter = WorkHelpers.ConstructWallItemFilter; break; default: throw new Exception(); } IItemFilter itemFilter; if (userItemFilter != null) itemFilter = new AndItemFilter(coreItemFilter, userItemFilter); else itemFilter = coreItemFilter; locations = locations.Where(p => filter.Match(m_environment.GetTileData(p))); foreach (var l in locations) { var data = new ConstructJobData() { Mode = mode, Location = l, ItemFilter = itemFilter, }; m_jobDataList.Add(data); } }
public CleanAreaJob(IJobObserver parent, EnvironmentObject env, IntGrid2Z area) : base(parent) { m_environment = env; m_area = area; m_map = new Dictionary <IntVector3, IJob>(); foreach (var p in m_area.Range()) { m_map[p] = null; } m_environment.World.TickStarted += World_TickStarting; }
public static void CreateWalls(EnvironmentObject env, IntGrid2Z area) { for (int x = area.X1; x <= area.X2; ++x) { for (int y = area.Y1; y <= area.Y2; ++y) { if (y != area.Y1 && y != area.Y2 && x != area.X1 && x != area.X2) { continue; } var p = new IntVector3(x, y, area.Z); env.SetTileData(p, TileData.GetNaturalWall(MaterialID.Granite)); } } }
bool TestStartArea(EnvironmentObject env, IntGrid2Z r) { foreach (var p in r.Range()) { var td = env.GetTileData(p); if (td.IsWalkable) { continue; } else { return(false); } } return(true); }
static IntPoint3? GetRandomRoomLoc(EnvironmentObject env, ref IntGrid2Z grid) { int x = grid.X + Helpers.GetRandomInt(grid.Columns); int y = grid.Y + Helpers.GetRandomInt(grid.Rows); foreach (var p in IntPoint2.SquareSpiral(new IntPoint2(x, y), Math.Max(grid.Columns, grid.Rows))) { if (env.Size.Plane.Contains(p) == false) continue; var p3 = new IntPoint3(p, grid.Z); if (EnvironmentHelpers.CanEnter(env, p3) == false) continue; return p3; } return null; }
public Map(int width, int height, int depth) { this.Grid = new AStarMapTile[depth, height, width]; this.Bounds = new IntGrid3(0, 0, 0, width, height, depth); for (int y = 0; y < 350; ++y) SetBlocked(new IntVector3(5, y, 0), true); for (int y = 2; y < 22; ++y) SetBlocked(new IntVector3(14, y, 0), true); for (int y = 6; y < 11; ++y) SetWeight(new IntVector3(10, y, 0), 40); for (int y = 6; y < 18; ++y) SetBlocked(new IntVector3(3, y, 1), true); for (int y = 6; y < 11; ++y) SetWeight(new IntVector3(5, y, 1), 40); SetStairs(new IntVector3(10, 10, 0), Stairs.Up); SetStairs(new IntVector3(10, 10, 1), Stairs.Down); SetStairs(new IntVector3(15, 12, 0), Stairs.Up); SetStairs(new IntVector3(15, 12, 1), Stairs.Down); var r = new Random(4); var bounds = new IntGrid2Z(16, 0, 30, 30, 0); foreach (var p in bounds.Range()) { var v = r.Next(100); if (v < 30) SetBlocked(p, true); else if (v < 60) SetWeight(p, v); } }
static IntVector3?GetRandomRoomLoc(EnvironmentObject env, ref IntGrid2Z grid) { int x = grid.X + Helpers.GetRandomInt(grid.Columns); int y = grid.Y + Helpers.GetRandomInt(grid.Rows); foreach (var p in IntVector2.SquareSpiral(new IntVector2(x, y), Math.Max(grid.Columns, grid.Rows))) { if (env.Size.Plane.Contains(p) == false) { continue; } var p3 = new IntVector3(p, grid.Z); if (env.CanEnter(p3) == false) { continue; } return(p3); } return(null); }
void CreateMonsters() { foreach (var kvp in m_rooms) { int z = kvp.Key; var rooms = kvp.Value; for (int i = 0; i < 10; ++i) { var room = new IntGrid2Z(rooms[Helpers.GetRandomInt(rooms.Length)], z); var pn = GetRandomRoomLoc(m_env, ref room); if (pn.HasValue == false) { continue; } var p = pn.Value; var living = CreateRandomLiving(z); living.MoveToMustSucceed(m_env, p); } } }
void CreateMonsters() { foreach (var kvp in m_rooms) { int z = kvp.Key; var rooms = kvp.Value; for (int i = 0; i < 10; ++i) { var room = new IntGrid2Z(rooms[Helpers.GetRandomInt(rooms.Length)], z); var pn = GetRandomRoomLoc(m_env, ref room); if (pn.HasValue == false) continue; var p = pn.Value; var living = CreateRandomLiving(z); living.MoveTo(m_env, p); } } }
public void RemoveArea(IntGrid2Z area) { var rm = m_jobDataList.Where(d => area.Contains(d.Location)).ToArray(); foreach (var d in rm) { if (d.Job != null) d.Job.Abort(); m_jobDataList.Remove(d); } }
public IEnumerable<IMovableObject> GetContents(IntGrid2Z rect) { return m_objectMap.Where(kvp => rect.Contains(kvp.Key)).SelectMany(kvp => kvp.Value); }
public IEnumerable <IMovableObject> GetContents(IntGrid2Z rect) { var obs = m_contentArray[rect.Z]; return(obs.Where(o => rect.Contains(o.Location))); }
public void Add(IntGrid2Z rect) { m_region.Add(rect); }
public IEnumerable<IMovableObject> GetContents(IntGrid2Z rect) { var obs = m_contentArray[rect.Z]; return obs.Where(o => rect.Contains(o.Location)); }
public static Stockpile CreateStockpile(EnvironmentObject environment, IntGrid2Z area) { var stockpile = new Stockpile(environment, area); environment.AddAreaElement(stockpile); return stockpile; }
bool TestStartArea(EnvironmentObject env, IntGrid2Z r) { foreach (var p in r.Range()) { var td = env.GetTileData(p); if (td.IsWalkable) continue; else return false; } return true; }
public void Add(IntGrid2Z rect) { Add(new IntGrid3(rect)); }
IntGrid2Z? FindStartLocation(EnvironmentObject env) { const int size = 2; var center = env.StartLocation; foreach (var p in IntPoint2.SquareSpiral(center.ToIntPoint(), env.Width / 2)) { if (env.Size.Plane.Contains(p) == false) continue; var z = env.GetDepth(p); var r = new IntGrid2Z(p.X - size, p.Y - size, size * 2, size * 2, z); if (TestStartArea(env, r)) return r; } return null; }
IntGrid2Z? FindStartLocation(EnvironmentObject env, IntVector3 pos) { const int size = 3; var center = pos; foreach (var p in IntVector2.SquareSpiral(center.ToIntVector2(), env.Width / 2)) { if (env.Size.Plane.Contains(p) == false) continue; var z = env.GetSurfaceLevel(p); var r = new IntGrid2Z(p.X - size, p.Y - size, size * 2, size * 2, z); if (TestStartArea(env, r)) return r; } return null; }
public static void CreateWalls(EnvironmentObject env, IntGrid2Z area) { for (int x = area.X1; x <= area.X2; ++x) { for (int y = area.Y1; y <= area.Y2; ++y) { if (y != area.Y1 && y != area.Y2 && x != area.X1 && x != area.X2) continue; var p = new IntVector3(x, y, area.Z); env.SetTileData(p, TileData.GetNaturalWall(MaterialID.Granite)); } } }
public IEnumerable <IMovableObject> GetContents(IntGrid2Z rect) { return(m_objectMap.Where(kvp => rect.Contains(kvp.Key)).SelectMany(kvp => kvp.Value)); }
bool TestStartArea(EnvironmentObject env, IntGrid2Z r) { foreach (var p in r.Range()) { var terrainID = env.GetTerrainID(p); var interiorID = env.GetInteriorID(p); if (terrainID == TerrainID.NaturalFloor) continue; else return false; } return true; }