static void DrawRect(EnvironmentObjectBuilder env, IntRectZ area, TileData data) { foreach (var p in area.Range()) { if ((p.Y != area.Y1 && p.Y != area.Y2 - 1) && (p.X != area.X1 && p.X != area.X2 - 1)) continue; env.SetTileData(p, data); } }
public void InitializeWorld(World world) { var envBuilder = new EnvironmentObjectBuilder(new IntSize3(64, 64, 4), VisibilityMode.AllVisible); TileData td; int surfaceLevel = 2; td = new TileData() { TerrainID = TerrainID.NaturalWall, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty }; FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 0), td); FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 1), td); td = new TileData() { TerrainID = TerrainID.NaturalFloor, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty }; FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 2), td); td = new TileData() { TerrainID = TerrainID.Empty, InteriorID = InteriorID.Empty }; FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 3), td); td = new TileData() { TerrainID = TerrainID.NaturalWall, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty }; DrawRect(envBuilder, new IntRectZ(envBuilder.Bounds.Plane, 2), td); var env = envBuilder.Create(world); env.HomeLocation = new IntPoint3(envBuilder.Width / 2, 4, surfaceLevel); /* Add Monsters */ CreateSheep(env, surfaceLevel); { var builder = new LivingObjectBuilder(LivingID.Wolf); var wolf = builder.Create(env.World); var ai = new Dwarrowdelf.AI.CarnivoreAI(wolf); wolf.SetAI(ai); wolf.MoveTo(env, GetRandomSurfaceLocation(env, surfaceLevel)); } { var builder = new LivingObjectBuilder(LivingID.Dragon); var dragon = builder.Create(env.World); var ai = new Dwarrowdelf.AI.MonsterAI(dragon); dragon.SetAI(ai); dragon.MoveTo(env, GetRandomSurfaceLocation(env, surfaceLevel)); } }
IntVector3 GetTileColor(TileData td) { byte r, g, b; if (td.WaterLevel > 0) { r = g = 0; b = 255; return new IntVector3(r, g, b); } switch (td.ID) { case TileID.Undefined: r = g = b = 0; break; case TileID.Empty: r = 0; g = 0; b = 0; break; default: { var mat = td.MaterialID; var matInfo = Materials.GetMaterial(mat); var rgb = matInfo.Color.ToGameColorRGB(); r = (byte)(rgb.R / 2); g = (byte)(rgb.G / 2); b = (byte)(rgb.B / 2); } break; } return new IntVector3(r, g, b); }
static void FillVolume(EnvironmentObjectBuilder env, IntBox volume, TileData data) { foreach (var p in volume.Range()) env.SetTileData(p, data); }
static void SetArea(EnvironmentObject env, IntGrid3 area, TileData data) { foreach (var p in area.Range()) env.SetTileData(p, data); }
public bool Match(TileData td) { return Match(td.TerrainID, td.InteriorID); }
void SetTileData(IntVector3 p, TileData td) { m_data.SetTileData(p, td); }
static void HandleTree(VertexList<SceneryVertex> sceneryVertexList, TileData td, ref IntVector3 pos) { SymbolID symbol; Color color; switch (td.ID) { case TileID.Tree: switch (td.MaterialID) { case MaterialID.Fir: symbol = SymbolID.ConiferousTree; break; case MaterialID.Pine: symbol = SymbolID.ConiferousTree2; break; case MaterialID.Birch: symbol = SymbolID.DeciduousTree; break; case MaterialID.Oak: symbol = SymbolID.DeciduousTree2; break; default: throw new Exception(); } break; case TileID.Sapling: switch (td.MaterialID) { case MaterialID.Fir: symbol = SymbolID.ConiferousSapling; break; case MaterialID.Pine: symbol = SymbolID.ConiferousSapling2; break; case MaterialID.Birch: symbol = SymbolID.DeciduousSapling; break; case MaterialID.Oak: symbol = SymbolID.DeciduousSapling2; break; default: throw new Exception(); } break; case TileID.DeadTree: symbol = SymbolID.DeadTree; break; default: throw new Exception(); } color = Color.ForestGreen; sceneryVertexList.Add(new SceneryVertex(pos.ToVector3(), Color.LightGreen, (uint)symbol)); }
void CreateBaseGrid() { int width = m_size.Width; int height = m_size.Height; int depth = m_size.Depth; var rockMaterials = Materials.GetMaterials(MaterialCategory.Rock).ToArray(); var layers = new MaterialID[20]; { int rep = 0; MaterialID mat = MaterialID.Undefined; for (int z = 0; z < layers.Length; ++z) { if (rep == 0) { rep = m_random.Next(4) + 1; mat = rockMaterials[m_random.Next(rockMaterials.Length - 1)].ID; } layers[z] = mat; rep--; } } double xk = (GetRandomDouble() * 2 - 1) * 0.01; double yk = (GetRandomDouble() * 2 - 1) * 0.01; m_rockLayerSlant = new Tuple<double, double>(xk, yk); Parallel.For(0, height, y => { for (int x = 0; x < width; ++x) { int surface = m_data.GetHeight(x, y); for (int z = 0; z < depth; ++z) { var p = new IntPoint3(x, y, z); var td = new TileData(); if (z < surface) { td.TerrainID = TerrainID.NaturalWall; int _z = (int)Math.Round(z + x * xk + y * yk); _z = _z % layers.Length; if (_z < 0) _z += layers.Length; td.TerrainMaterialID = layers[_z]; } else if (z == surface) { td.TerrainID = TerrainID.NaturalFloor; td.TerrainMaterialID = GetTileData(new IntPoint3(x, y, z - 1)).TerrainMaterialID; } else { td.TerrainID = TerrainID.Empty; td.TerrainMaterialID = MaterialID.Undefined; } td.InteriorID = InteriorID.Empty; td.InteriorMaterialID = MaterialID.Undefined; SetTileData(p, td); } } }); }
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; } }
void SetTileData(IntPoint3 p, TileData td) { m_data.SetTileData(p, td); }
public bool Match(TileData td) { // ZZZ: todo //return Match(td.TerrainID, td.InteriorID); return false; }
void CreateBaseGrid() { int width = m_size.Width; int height = m_size.Height; int depth = m_size.Depth; Parallel.For(0, height, y => { for (int x = 0; x < width; ++x) { int surface = m_data.GetHeight(x, y); for (int z = 0; z < depth; ++z) { var p = new IntPoint3(x, y, z); var td = new TileData(); if (z < surface) { td.TerrainID = TerrainID.NaturalWall; td.TerrainMaterialID = MaterialID.Granite; } else if (z == surface) { td.TerrainID = TerrainID.NaturalFloor; td.TerrainMaterialID = MaterialID.Granite; } else { td.TerrainID = TerrainID.Empty; td.TerrainMaterialID = MaterialID.Undefined; } td.InteriorID = InteriorID.Empty; td.InteriorMaterialID = MaterialID.Undefined; SetTileData(p, td); } } }); }
void CreateDungeonLevel(BSPTree bsp, int z) { var root = new IntGrid2(0, 0, m_size.Width, m_size.Height); CreateNodes(bsp, root, 0); var td = new TileData(); td.TerrainID = TerrainID.NaturalFloor; td.TerrainMaterialID = MaterialID.Granite; td.InteriorID = InteriorID.Empty; td.InteriorMaterialID = MaterialID.Undefined; int leafs = MyMath.Pow2(bsp.Depth - 1); var rooms = new List<IntGrid2>(); // Shrink the full sized leaf nodes for rooms for (int l = 0; l < leafs; ++l) { int i = bsp.Length - l - 1; var n = bsp[i]; var grid = n.Grid; var xm = GetRandomDouble(0.2, 0.5); var ym = GetRandomDouble(0.2, 0.5); int columns = (int)((grid.Columns - 1) * xm); int rows = (int)((grid.Rows - 1) * ym); int x = m_random.Next(grid.Columns - columns) + grid.X; int y = m_random.Next(grid.Rows - rows) + grid.Y; n.Grid = new IntGrid2(x, y, columns, rows); bsp[i] = n; rooms.Add(n.Grid); } m_rooms[z] = rooms.ToArray(); for (int l = 0; l < leafs; ++l) { int i = bsp.Length - l - 1; var grid = bsp[i].Grid; foreach (var p2 in grid.Range()) { var p = new IntPoint3(p2, z); var _td = GetTileData(p); if (_td.TerrainID == td.TerrainID) Debugger.Break(); SetTileData(p, td); } } Connect(bsp, 0, true, z); }
void CreateCorridor(IntPoint2 from, IntPoint2 to, int z, bool horiz) { var td = new TileData(); td.TerrainID = TerrainID.NaturalFloor; td.TerrainMaterialID = MaterialID.Granite; td.InteriorID = InteriorID.Empty; td.InteriorMaterialID = MaterialID.Undefined; if (horiz) { int yinc = from.Y < to.Y ? 1 : -1; int middle = from.Y + (to.Y - from.Y) / 2; for (int y = from.Y; y != middle; y += yinc) SetTileData(new IntPoint3(from.X, y, z), td); int x1 = Math.Min(from.X, to.X); int x2 = Math.Max(from.X, to.X); for (int x = x1; x <= x2; ++x) SetTileData(new IntPoint3(x, middle, z), td); for (int y = middle; y != to.Y; y += yinc) SetTileData(new IntPoint3(to.X, y, z), td); } else { int xinc = from.X < to.X ? 1 : -1; int middle = from.X + (to.X - from.X) / 2; for (int x = from.X; x != middle; x += xinc) SetTileData(new IntPoint3(x, from.Y, z), td); int y1 = Math.Min(from.Y, to.Y); int y2 = Math.Max(from.Y, to.Y); for (int y = y1; y <= y2; ++y) SetTileData(new IntPoint3(middle, y, z), td); for (int x = middle; x != to.X; x += xinc) SetTileData(new IntPoint3(x, to.Y, z), td); } }
public bool Match(TileData td) { // ZZZ: todo //return Match(td.TerrainID, td.InteriorID); return(false); }