static IntPoint3 GetRandomSurfaceLocation(EnvironmentObject env) { IntPoint3 p; int iter = 0; do { if (iter++ > 10000) throw new Exception(); int x = Helpers.GetRandomInt(env.Width); int y = Helpers.GetRandomInt(env.Height); int z = env.GetDepth(new IntPoint2(x, y)); p = new IntPoint3(x, y, z); } while (!EnvironmentHelpers.CanEnter(env, p)); return p; }
IntGrid2Z? FindStartLocation(EnvironmentObject env) { const int size = 3; 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; }
static void CreateWorkbenches(EnvironmentObject env) { var world = env.World; int posx = env.Width / 2 - 10; int posy = env.Height / 2 - 10; var surface = env.GetDepth(new IntPoint2(posx, posy)); var floorTile = new TileData() { TerrainID = TerrainID.NaturalFloor, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty, InteriorMaterialID = MaterialID.Undefined, }; { var p = new IntPoint3(posx, posy, surface); env.SetTileData(p, floorTile); var item = CreateItem(env, ItemID.SmithsWorkbench, MaterialID.Iron, p); item.IsInstalled = true; } posx += 4; { var p = new IntPoint3(posx, posy, surface); env.SetTileData(p, floorTile); var item = CreateItem(env, ItemID.CarpentersWorkbench, MaterialID.Oak, p); item.IsInstalled = true; } posx += 4; { var p = new IntPoint3(posx, posy, surface); env.SetTileData(p, floorTile); var item = CreateItem(env, ItemID.MasonsWorkbench, MaterialID.Iron, p); item.IsInstalled = true; } posx = env.Width / 2 - 10; posy += 4; { var p = new IntPoint3(posx, posy, surface); env.SetTileData(p, floorTile); var item = CreateItem(env, ItemID.SmelterWorkbench, MaterialID.Iron, p); item.IsInstalled = true; } posx += 4; { var p = new IntPoint3(posx, posy, surface); env.SetTileData(p, floorTile); var item = CreateItem(env, ItemID.GemcuttersWorkbench, MaterialID.Iron, p); item.IsInstalled = true; } }