/// <summary> /// Create a column with a given depth of floor surface with empty blocks above /// </summary> /// <param name="bm">the BlockManger for the world</param> /// <param name="posX">The X coordinate of the column</param> /// <param name="posY">The Y coordinate where the floor surface ends and air begins</param> /// <param name="posZ">The Z coordinate of the column</param> private static void MakeOpenSurface(BlockManager bm, Int32 posX, Int32 posY, Int32 posZ) { for (Int32 yi = posY - 5; yi < posY; yi++) { bm.SetID(posX, yi, posZ, BlockType.OBSIDIAN); } for (Int32 yi = posY; yi < 256; yi++) { bm.SetID(posX, yi, posZ, BlockType.AIR); } }
private static void AddFlowersToBlock(BlockManager bmDest, int x, int z) { switch (RandomHelper.Next(4)) { case 0: bmDest.SetID(x, 64, z, BlockType.RED_ROSE); break; case 1: bmDest.SetID(x, 64, z, BlockType.YELLOW_FLOWER); break; case 2: case 3: BlockShapes.MakeBlock(x, 64, z, BlockType.TALL_GRASS, RandomHelper.Next(1, 3)); break; default: Debug.Fail("Invalid switch result"); break; } }
public static void MakeMineshaft(BetaWorld world, BlockManager bm, int intFarmLength, int intMapLength, Buildings.structPoint spMineshaftEntrance) { _intBlockStartBuildings = intFarmLength + 13; int intMineshaftSize = (1 + intMapLength) - (_intBlockStartBuildings * 2); if (intMineshaftSize % 5 > 0) { intMineshaftSize += 5 - (intMineshaftSize % 5); } _intBlockStartBuildings -= 2; for (int intLevel = 1; intLevel <= 7; intLevel++) { MakeLevel(world, bm, intLevel, intMineshaftSize, spMineshaftEntrance); } int intBlockToReplace = bm.GetID(spMineshaftEntrance.x, 63, spMineshaftEntrance.z + 1); BlockShapes.MakeSolidBox(spMineshaftEntrance.x, spMineshaftEntrance.x, 3, 63, spMineshaftEntrance.z + 1, spMineshaftEntrance.z + 1, BlockType.WOOD, 0); BlockHelper.MakeLadder(spMineshaftEntrance.x, 4, 63, spMineshaftEntrance.z, 0, BlockType.WOOD); BlockShapes.MakeSolidBox(spMineshaftEntrance.x, spMineshaftEntrance.x, 3, 63, spMineshaftEntrance.z + 1, spMineshaftEntrance.z + 1, BlockType.STONE, 0); bm.SetID(spMineshaftEntrance.x, 63, spMineshaftEntrance.z + 1, intBlockToReplace); }
private static void MakeHill(BlockManager bm, int x, int xlen, int z, int zlen, bool booMini) { int[,] intArea = new int[xlen, zlen]; int a, b; int c = 0, d = 0, clen = -1, dlen = -1; if (!booMini) { c = RandomHelper.Next(1, intArea.GetUpperBound(0) - 7); d = RandomHelper.Next(1, intArea.GetUpperBound(1) - 7); clen = RandomHelper.Next(3, 7); dlen = RandomHelper.Next(3, 7); } for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { if (a < c || a > c + clen || b < d || b > d + dlen) { intArea[a, b] = 1; } } } intArea = CheckAgainstNeighbours(intArea, 0, 0, 7, 0, RandomHelper.Next(7, 11), true); intArea = CheckAgainstNeighbours(intArea, 6, 0, 3, 2, 1, false); intArea = CheckAgainstNeighbours(intArea, 14, 0, 3, 3, 1, false); for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { for (int y = 1; y <= intArea[a, b]; y++) { if (y == intArea[a, b]) { bm.SetID(x + a, y + 63, z + b, BlockType.GRASS); switch (RandomHelper.Next(0, 10)) { case 0: bm.SetID(x + a, y + 64, z + b, BlockType.RED_ROSE); break; case 1: bm.SetID(x + a, y + 64, z + b, BlockType.YELLOW_FLOWER); break; case 2: case 3: bm.SetID(x + a, y + 64, z + b, BlockType.TALL_GRASS); bm.SetData(x + a, y + 64, z + b, RandomHelper.Next(1, 3)); break; // we want to skip the other numbers, so there's no need for a default } } else { bm.SetID(x + a, y + 63, z + b, BlockType.DIRT); } } } } }
private static void MakeFlowers(BlockManager bm, int intFarmLength, int intMapLength) { for (int x = 0; x <= intMapLength; x++) { for (int z = 0; z <= intMapLength; z++) { if (x <= intFarmLength || z <= intFarmLength || x >= intMapLength - intFarmLength || z >= intMapLength - intFarmLength) { bool booFree = true; for (int xCheck = x - 1; xCheck <= x + 1 && booFree; xCheck++) { for (int zCheck = z - 1; zCheck <= z + 1 && booFree; zCheck++) { booFree = bm.GetID(xCheck, 63, zCheck) == BlockType.GRASS && bm.GetID(xCheck, 64, zCheck) == BlockType.AIR; } } if (booFree && RandomHelper.NextDouble() > 0.90) { switch (RandomHelper.Next(4)) { case 0: bm.SetID(x, 64, z, BlockType.RED_ROSE); break; case 1: bm.SetID(x, 64, z, BlockType.YELLOW_FLOWER); break; case 2: case 3: bm.SetID(x, 64, z, BlockType.TALL_GRASS); bm.SetData(x, 64, z, RandomHelper.Next(1, 3)); break; default: Debug.Fail("Invalid switch result"); break; } } } } } }
private static void JoinPathsToRoad(BlockManager bmDest, int intMapLength, int intFarmLength) { int intBlockStart = intFarmLength + 13; int intPlotBlocksLength = (1 + intMapLength) - (intBlockStart * 2); for (int a = 0; a <= intPlotBlocksLength; a++) { for (int b = -2; b <= 2; b+=4) { if (bmDest.GetID(intBlockStart + a, 63, intBlockStart + (intPlotBlocksLength / 2) + (int)(b * 1.5)) == BlockType.DOUBLE_SLAB && bmDest.GetID(intBlockStart + a, 63, intBlockStart + (intPlotBlocksLength / 2) + (int)(b / 2)) == BlockType.DOUBLE_SLAB && bmDest.GetID(intBlockStart + a, 63, intBlockStart + (intPlotBlocksLength / 2) + b) == BlockType.GRASS && bmDest.GetID(intBlockStart + a, 64, intBlockStart + (intPlotBlocksLength / 2) + b) == BlockType.AIR) { bmDest.SetID(intBlockStart + a, 63, intBlockStart + (intPlotBlocksLength / 2) + b, BlockType.DOUBLE_SLAB); } if (bmDest.GetID(intBlockStart + (intPlotBlocksLength / 2) + (int)(b * 1.5), 63, intBlockStart + a) == BlockType.DOUBLE_SLAB && bmDest.GetID(intBlockStart + (intPlotBlocksLength / 2) + (int)(b / 2), 63, intBlockStart + a) == BlockType.DOUBLE_SLAB && bmDest.GetID(intBlockStart + (intPlotBlocksLength / 2) + b, 63, intBlockStart + a) == BlockType.GRASS && bmDest.GetID(intBlockStart + (intPlotBlocksLength / 2) + b, 64, intBlockStart + a) == BlockType.AIR) { bmDest.SetID(intBlockStart + (intPlotBlocksLength / 2) + b, 63, intBlockStart + a, BlockType.DOUBLE_SLAB); } } } }
private static void MakeStreetSign(BlockManager bm, int x1, int z1, int x2, int z2) { x1 += _intBlockStart; z1 += _intBlockStart; x2 += _intBlockStart; z2 += _intBlockStart; bm.SetID(x1, 64, z1, BlockType.FENCE); bm.SetID(x1, 65, z1, BlockType.WOOD_PLANK); bm.SetID(x1, 66, z1, BlockType.TORCH); bm.SetID(x2, 64, z2, BlockType.FENCE); bm.SetID(x2, 65, z2, BlockType.WOOD_PLANK); bm.SetID(x2, 66, z2, BlockType.TORCH); if (z1 == z2) { x1--; x2++; } else { z1--; z2++; } string strStreetName, strStreetType; do { strStreetName = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt")); strStreetType = RandomHelper.RandomFileLine(Path.Combine("Resources", "RoadTypes.txt")); } while (_lstStreetsUsed.Contains(strStreetName + " " + strStreetType)); _lstStreetsUsed.Add(strStreetName + " " + strStreetType); BlockHelper.MakeSign(x1, 65, z1, "~" + strStreetName + "~" + strStreetType + "~", BlockType.WOOD_PLANK, 0); BlockHelper.MakeSign(x2, 65, z2, "~" + strStreetName + "~" + strStreetType + "~", BlockType.WOOD_PLANK, 0); }
public void LinkRooms (BlockManager bm, int x1, int y1, int z1, int x2, int y2, int z2) { int xx = originx + (cellxlen + wallxwidth) * x1; int yy = originy + (cellylen + wallywidth) * y1; int zz = originz + (cellzlen + wallzwidth) * z1; if (x1 != x2) { xx = originx + (cellxlen + wallxwidth) * Math.Max(x1, x2); for (int xi = 0; xi < wallxwidth; xi++) { int zc = zz + wallzwidth + (cellzlen / 2); int yb = yy + wallywidth; bm.SetID(xx + xi, yb, zc - 1, (int)BlockType.AIR); bm.SetID(xx + xi, yb, zc, (int)BlockType.AIR); bm.SetID(xx + xi, yb, zc + 1, (int)BlockType.AIR); bm.SetID(xx + xi, yb + 1, zc - 1, (int)BlockType.AIR); bm.SetID(xx + xi, yb + 1, zc, (int)BlockType.AIR); bm.SetID(xx + xi, yb + 1, zc + 1, (int)BlockType.AIR); bm.SetID(xx + xi, yb + 2, zc, (int)BlockType.AIR); } } else if (z1 != z2) { zz = originz + (cellzlen + wallzwidth) * Math.Max(z1, z2); for (int zi = 0; zi < wallxwidth; zi++) { int xc = xx + wallxwidth + (cellxlen / 2); int yb = yy + wallywidth; bm.SetID(xc - 1, yb, zz + zi, (int)BlockType.AIR); bm.SetID(xc, yb, zz + zi, (int)BlockType.AIR); bm.SetID(xc + 1, yb, zz + zi, (int)BlockType.AIR); bm.SetID(xc - 1, yb + 1, zz + zi, (int)BlockType.AIR); bm.SetID(xc, yb + 1, zz + zi, (int)BlockType.AIR); bm.SetID(xc + 1, yb + 1, zz + zi, (int)BlockType.AIR); bm.SetID(xc, yb + 2, zz + zi, (int)BlockType.AIR); } } else if (y1 != y2) { yy = originy + (cellylen + wallywidth) * Math.Max(y1, y2); for (int yi = 0 - cellylen + 1; yi < wallywidth + 1; yi++) { int xc = xx + wallxwidth + (cellxlen / 2); int zc = zz + wallzwidth + (cellzlen / 2); bm.SetID(xc, yy + yi, zc, (int)BlockType.BEDROCK); bm.SetID(xc - 1, yy + yi, zc, (int)BlockType.LADDER); bm.SetData(xc - 1, yy + yi, zc, 4); bm.SetID(xc + 1, yy + yi, zc, (int)BlockType.LADDER); bm.SetData(xc + 1, yy + yi, zc, 5); bm.SetID(xc, yy + yi, zc - 1, (int)BlockType.LADDER); bm.SetData(xc, yy + yi, zc - 1, 2); bm.SetID(xc, yy + yi, zc + 1, (int)BlockType.LADDER); bm.SetData(xc, yy + yi, zc + 1, 3); } } }
private static void MakeHelperChest(BlockManager bm, int x, int y, int z) { TileEntityChest tec = new TileEntityChest(); tec.Items[0] = BlockHelper.MakeItem(ItemInfo.DiamondSword.ID, 1); tec.Items[1] = BlockHelper.MakeItem(ItemInfo.DiamondPickaxe.ID, 1); tec.Items[2] = BlockHelper.MakeItem(ItemInfo.DiamondShovel.ID, 1); tec.Items[3] = BlockHelper.MakeItem(ItemInfo.DiamondAxe.ID, 1); tec.Items[4] = BlockHelper.MakeItem(BlockType.LADDER, 64); tec.Items[5] = BlockHelper.MakeItem(BlockType.DIRT, 64); tec.Items[6] = BlockHelper.MakeItem(BlockType.SAND, 64); tec.Items[7] = BlockHelper.MakeItem(BlockType.CRAFTING_TABLE, 64); tec.Items[8] = BlockHelper.MakeItem(BlockType.FURNACE, 64); tec.Items[9] = BlockHelper.MakeItem(ItemInfo.Bread.ID, 64); tec.Items[10] = BlockHelper.MakeItem(BlockType.TORCH, 64); tec.Items[11] = BlockHelper.MakeItem(BlockType.STONE, 64); tec.Items[12] = BlockHelper.MakeItem(BlockType.CHEST, 64); tec.Items[13] = BlockHelper.MakeItem(BlockType.GLASS, 64); tec.Items[14] = BlockHelper.MakeItem(BlockType.WOOD, 64); tec.Items[15] = BlockHelper.MakeItem(ItemInfo.Cookie.ID, 64); tec.Items[16] = BlockHelper.MakeItem(ItemInfo.RedstoneDust.ID, 64); tec.Items[17] = BlockHelper.MakeItem(BlockType.IRON_BLOCK, 64); tec.Items[18] = BlockHelper.MakeItem(BlockType.DIAMOND_BLOCK, 64); tec.Items[19] = BlockHelper.MakeItem(BlockType.GOLD_BLOCK, 64); bm.SetID(x, y, z, BlockType.CHEST); bm.SetTileEntity(x, y, z, tec); }
private void SetToRoadBlock(int X, int Z, BlockManager bm) { //Average the 7x7 block surrounding the thing we are going to sample. int average = 0; for (int xx = -3; xx <= 3; ++xx) { for (int zz = -3; zz <= 3; ++zz) { average += bm.GetHeight (X + xx, Z + zz) - 1; } } average /= 49; //Set the block below the average to dirt, at the average to cobble, and everything above to air for (int y = average; y < bm.GetHeight(X, Z); ++y) { bm.SetID (X, y, Z, BlockInfo.Air.ID); } bm.SetID (X, average, Z, BlockInfo.Cobblestone.ID); bm.SetID (X, average - 1, Z, BlockInfo.Dirt.ID); }
public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart, int x1dest, int z1dest, Building bldInsert, int y1dest) { List<Spawner> lstSpawners = new List<Spawner>(); _lstInstanceSigns.Clear(); int intRandomWoolColour = RandomHelper.Next(16); int intSourceX = 0, intSourceZ = 0; int intRotate = -1; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { intRotate = 0; } else { for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++) { for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSizeX; intCheck++) { if (CheckArea(intArea, x1dest + intCheck, z1dest - intDistance) == 1) { intRotate = 0; } else if (CheckArea(intArea, x1dest - intDistance, z1dest + intCheck) == 1) { intRotate = 1; } else if (CheckArea(intArea, x1dest + bldInsert.intSizeX + intDistance, z1dest + intCheck) == 1) { intRotate = 2; } else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSizeZ + intDistance) == 1) { intRotate = 3; } } } } if (intRotate == -1) { intRotate = RandomHelper.Next(4); } for (int x = 0; x < bldInsert.intSizeX; x++) { for (int z = 0; z < bldInsert.intSizeZ; z++) { switch (intRotate) { case 0: intSourceX = x; intSourceZ = z; break; case 1: intSourceX = (bldInsert.intSizeX - 1) - z; intSourceZ = x; break; case 2: intSourceX = z; intSourceZ = (bldInsert.intSizeZ - 1) - x; break; case 3: intSourceX = (bldInsert.intSizeX - 1) - x; intSourceZ = (bldInsert.intSizeZ - 1) - z; break; default: Debug.Fail("Invalid switch result"); break; } int intSourceEndY; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { intSourceEndY = bldInsert.intSourceStartY + 4; } else { for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--) { if (_bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY, intSourceZ + bldInsert.intSourceZ) != BlockType.AIR) { break; } } } for (int ySource = bldInsert.intSourceStartY; ySource <= intSourceEndY; ySource++) { int yDest = ySource; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { yDest = y1dest + (ySource - bldInsert.intSourceStartY); } if (bldInsert.btThis == BuildingTypes.MineshaftSection || ((yDest != 64 || bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) == BlockType.AIR) && bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) != BlockType.WOOD_PLANK)) { int intBlockID = _bmSource.GetID(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); int intBlockData = _bmSource.GetData(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockID); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockData); #region import paintings // todo: test for mineshaft features foreach (EntityPainting entPainting in _AllEntityPainting) { if (entPainting.TileX == intSourceX + bldInsert.intSourceX && entPainting.TileY == ySource && entPainting.TileZ == intSourceZ + bldInsert.intSourceZ) { EntityPainting entNewPainting = (EntityPainting)entPainting.Copy(); entNewPainting.TileX = intBlockStart + x + x1dest; entNewPainting.TileY = yDest; entNewPainting.TileZ = intBlockStart + z + z1dest; entNewPainting.Position.X = entNewPainting.TileX; entNewPainting.Position.Z = entNewPainting.TileZ; entNewPainting.Direction = BlockHelper.RotatePortrait(entPainting.Direction, intRotate); ChunkRef chunkBuilding = _cmDest.GetChunkRef((intBlockStart + x + x1dest) / 16, (intBlockStart + z + z1dest) / 16); chunkBuilding.Entities.Add(entNewPainting); _cmDest.Save(); } } #endregion #region Rotation if (intRotate > 0) { switch (intBlockID) { case BlockType.PORTAL: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotatePortal(intBlockData, intRotate)); break; case BlockType.SIGN_POST: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateSignPost(intBlockData, intRotate)); break; case BlockType.STONE_BUTTON: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateButton(intBlockData, intRotate)); break; case BlockType.PUMPKIN: case BlockType.JACK_O_LANTERN: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotatePumpkin(intBlockData, intRotate)); break; case BlockType.IRON_DOOR: case BlockType.WOOD_DOOR: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateDoor(intBlockData, intRotate)); break; case BlockType.TRAPDOOR: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateTrapdoor(intBlockData, intRotate)); break; case BlockType.BED: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateBed(intBlockData, intRotate)); break; case BlockType.REDSTONE_TORCH_OFF: case BlockType.REDSTONE_TORCH_ON: case BlockType.TORCH: case BlockType.LEVER: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateTorchOrLever(intBlockData, intRotate)); break; case BlockType.WALL_SIGN: case BlockType.LADDER: case BlockType.DISPENSER: case BlockType.FURNACE: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser( intBlockData, intRotate)); break; case BlockType.COBBLESTONE_STAIRS: case BlockType.WOOD_STAIRS: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateStairs(intBlockData, intRotate)); break; // no need for a default - all other blocks are okay } } #endregion #region Handle entities switch (intBlockID) { case BlockType.SPONGE: bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.WOOL); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intRandomWoolColour); break; case BlockType.CHEST: TileEntityChest tec = (TileEntityChest)_bmSource.GetTileEntity( intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); if (_booIncludeItemsInChests) { if (tec.Items[0] != null) { if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 3) { tec = MakeHouseChest(); } if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 4) { tec = MakeTreasureChest(); } } } else { tec.Items.ClearAllItems(); } bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tec); break; case BlockType.FURNACE: case BlockType.MONSTER_SPAWNER: case BlockType.NOTE_BLOCK: bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, _bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ)); break; case BlockType.SIGN_POST: case BlockType.WALL_SIGN: #region Determine sign text int intUniqueType = 0; TileEntitySign tes = (TileEntitySign)_bmSource. GetTileEntity(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); string strSourceSign = tes.Text1 + " " + tes.Text2 + " " + tes.Text3 + " " + tes.Text4; switch (strSourceSign.Substring(0, 1)) { case "2": case "1": case "0": intUniqueType = Convert.ToInt32(strSourceSign.Substring(0, 1)); strSourceSign = strSourceSign.Remove(0, 1); break; default: intUniqueType = 0; break; } if (tes.Text1.ToLower() == "commentsign" || tes.Text1.ToLower() == "comment sign") { // these exist to give advice to people in the resource world. // so we just remove them from the real world bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0); } if (tes.Text1.ToLower() == "spawner" || tes.Text1.ToLower() == "gspawner") { if (!tes.Text2.ToLower().StartsWith("g") || tes.Text2.ToLower() == "[randomenemy]" || _booIncludeGhostdancerSpawners) { Spawner spawnerCurrent = new Spawner(); if (tes.Text2.ToLower() == "[randomenemy]") { if (_booIncludeGhostdancerSpawners) { spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie", "GGeist", "GGrim"); } else { spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie"); } } else { spawnerCurrent.strEntityID = tes.Text2; } if (tes.Text3.Split(' ').GetUpperBound(0) == 2) { spawnerCurrent.sy = yDest + Convert.ToInt32(tes.Text3.Split(' ')[1]); spawnerCurrent.sx = 0; spawnerCurrent.sz = 0; switch (intRotate) { case 0: spawnerCurrent.sx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text3.Split(' ')[0])); spawnerCurrent.sz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text3.Split(' ')[2])); break; case 1: spawnerCurrent.sx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text3.Split(' ')[2])); spawnerCurrent.sz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0])); break; case 2: spawnerCurrent.sx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2])); spawnerCurrent.sz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text3.Split(' ')[0])); break; case 3: spawnerCurrent.sx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0])); spawnerCurrent.sz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2])); break; } } else { spawnerCurrent.sx = intBlockStart + x + x1dest; spawnerCurrent.sy = yDest - 2; spawnerCurrent.sz = intBlockStart + z + z1dest; } if (tes.Text4.ToLower() == "no") { spawnerCurrent.booGrass = false; } else if (tes.Text4.Split(' ').GetUpperBound(0) == 2) { spawnerCurrent.gy = yDest + Convert.ToInt32(tes.Text4.Split(' ')[1]); switch (intRotate) { case 0: spawnerCurrent.gx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text4.Split(' ')[0])); spawnerCurrent.gz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text4.Split(' ')[2])); break; case 1: spawnerCurrent.gx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2])); spawnerCurrent.gz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text4.Split(' ')[0])); break; case 2: spawnerCurrent.gx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text4.Split(' ')[2])); spawnerCurrent.gz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0])); break; case 3: spawnerCurrent.gx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0])); spawnerCurrent.gz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2])); break; } spawnerCurrent.booGrass = true; } else { spawnerCurrent.gx = intBlockStart + x + x1dest; spawnerCurrent.gy = yDest - 1; spawnerCurrent.gz = intBlockStart + z + z1dest; spawnerCurrent.booGrass = true; } lstSpawners.Add(spawnerCurrent); } bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0); } else if (strSourceSign.Contains("[")) { string strSignText; bool booDuplicate; int intFail = 0; do { strSignText = SignText(strSourceSign); booDuplicate = false; switch (intUniqueType) { case 1: // unique by instance booDuplicate = _lstInstanceSigns.Contains(strSignText); break; case 2: // unique by city booDuplicate = _lstCitySigns.Contains(strSignText); break; } if (++intFail > 100) { Debug.WriteLine("Could not make a unique sign for " + strSourceSign); booDuplicate = false; } } while (booDuplicate); _lstCitySigns.Add(strSignText); _lstInstanceSigns.Add(strSignText); string[] strRandomSign = Utils.TextToSign(Utils.ConvertStringToSignText(strSignText)); tes.Text1 = strRandomSign[0]; tes.Text2 = strRandomSign[1]; tes.Text3 = strRandomSign[2]; tes.Text4 = strRandomSign[3]; bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes); } else { bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes); } break; #endregion // no need for a default - all the other blocks are okay } #endregion } } } } foreach (Spawner spnAdd in lstSpawners) { bmDest.SetID(spnAdd.sx, spnAdd.sy, spnAdd.sz, BlockType.MONSTER_SPAWNER); TileEntityMobSpawner tems = new TileEntityMobSpawner(); tems.EntityID = spnAdd.strEntityID; bmDest.SetTileEntity(spnAdd.sx, spnAdd.sy, spnAdd.sz, tems); if (spnAdd.booGrass) { bmDest.SetID(spnAdd.gx, spnAdd.gy, spnAdd.gz, BlockType.GRASS); } } }
private static void MakeGuardChest(BlockManager bm, int x, int y, int z, bool booIncludeItemsInChests) { TileEntityChest tec = new TileEntityChest(); if (booIncludeItemsInChests) { for (int a = 0; a < 5; a++) { tec.Items[a] = BlockHelper.MakeItem(RandomHelper.RandomNumber(ItemInfo.IronSword.ID, ItemInfo.WoodenSword.ID, ItemInfo.StoneSword.ID), 1); } tec.Items[6] = BlockHelper.MakeItem(ItemInfo.Bow.ID, 1); tec.Items[7] = BlockHelper.MakeItem(ItemInfo.Arrow.ID, 64); int intArmourStartID = RandomHelper.RandomNumber(ItemInfo.LeatherCap.ID, ItemInfo.ChainHelmet.ID, ItemInfo.IronHelmet.ID); for (int a = 9; a < 18; a++) { // random armour tec.Items[a] = BlockHelper.MakeItem(intArmourStartID + RandomHelper.Next(4), 1); } } bm.SetID(x, y, z, BlockType.CHEST); bm.SetTileEntity(x, y, z, tec); }
private static void MakeLevel(BetaWorld world, BlockManager bm, int intDepth, int intMineshaftSize, Buildings.structPoint spMineshaftEntrance) { Debug.WriteLine("----- Mineshaft Level " + intDepth + " -----"); string[] strResourceNames = Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "names").Split(','); int[] intResourceChances = Utils.StringArrayToIntArray(Utils.ValueFromXMLElement( Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "chances").Split(',')); int intTorchChance = Convert.ToInt32(Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "torch_chance")); int[,] intAreaFull = new int[intMineshaftSize + (MULTIPLIER * 2), intMineshaftSize + (MULTIPLIER * 2)]; int intXPosOriginal = spMineshaftEntrance.x - _intBlockStartBuildings; int intZPosOriginal = spMineshaftEntrance.z - _intBlockStartBuildings; _intBlockStartBuildings -= 2; int[,] intAreaOverview = new int[(intAreaFull.GetLength(0) / MULTIPLIER), (intAreaFull.GetLength(1) / MULTIPLIER)]; int intXPos = intXPosOriginal / MULTIPLIER; int intZPos = intZPosOriginal / MULTIPLIER; intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Air; CreateRouteXPlus(intAreaOverview, intXPos + 1, intZPos, 0); CreateRouteZPlus(intAreaOverview, intXPos, intZPos + 1, 1); CreateRouteXMinus(intAreaOverview, intXPos - 1, intZPos, 2); CreateRouteZMinus(intAreaOverview, intXPos, intZPos - 1, 3); int intOffsetX = (intXPosOriginal - (intXPos * MULTIPLIER)) - 2; int intOffsetZ = (intZPosOriginal - (intZPos * MULTIPLIER)) - 2; List<structSection> lstSections = new List<structSection>(); intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Placeholder; intAreaOverview = AddMineshaftSections(intAreaOverview, intDepth); intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Air; for (int x = 0; x < intAreaOverview.GetLength(0); x++) { for (int z = 0; z < intAreaOverview.GetLength(1); z++) { if (intAreaOverview[x, z] >= 100) { structSection structCurrentSection = new structSection(); structCurrentSection.bldMineshaftSection = SourceWorld.GetBuilding(intAreaOverview[x, z] - 100); structCurrentSection.x = ((x * MULTIPLIER) + intOffsetX) - 1; structCurrentSection.z = ((z * MULTIPLIER) + intOffsetZ) - 1; for (int x2 = x; x2 <= x + (structCurrentSection.bldMineshaftSection.intSizeX - 1) / 7; x2++) { for (int z2 = z; z2 <= z + (structCurrentSection.bldMineshaftSection.intSizeZ - 1) / 7; z2++) { if (intAreaOverview[x2, z2] == structCurrentSection.bldMineshaftSection.intID + 100) { intAreaOverview[x2, z2] = (int)MineshaftBlocks.Structure; } } } lstSections.Add(structCurrentSection); } } } for (int x = 4; x < intAreaFull.GetLength(0) - 4; x++) { for (int z = 4; z < intAreaFull.GetLength(1) - 4; z++) { if (intAreaOverview.GetLength(0) > x / MULTIPLIER && intAreaOverview.GetLength(1) > z / MULTIPLIER) { if (intAreaFull[x + intOffsetX, z + intOffsetZ] < 4) { intAreaFull[x + intOffsetX, z + intOffsetZ] = intAreaOverview[x / MULTIPLIER, z / MULTIPLIER]; } } if ((x + 3) % 5 == 0 && (z + 3) % 5 == 0 && intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air) { if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] >= 100) { for (int x2 = 0; x2 < 5; x2++) { intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Structure; } } if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] == (int)MineshaftBlocks.Air) { for (int x2 = 0; x2 < 5; x2++) { if (x2 == 1 || x2 == 3) { intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.CeilingSupport; intAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.CeilingSupport; } else { intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Support; intAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Support; } } for (int x2 = 0; x2 <= 5; x2++) { if (intAreaFull[x + intOffsetX + x2, z + intOffsetZ] == (int)MineshaftBlocks.Support) { intAreaFull[x + intOffsetX + x2, z + intOffsetZ] = (int)MineshaftBlocks.RailWithSupport; } else { intAreaFull[x + intOffsetX + x2, z + intOffsetZ] = (int)MineshaftBlocks.Rail; } } } if (intAreaOverview[x / MULTIPLIER, (z / MULTIPLIER) + 1] == (int)MineshaftBlocks.Air) { for (int z2 = 0; z2 < 5; z2++) { if (z2 == 1 || z2 == 3) { intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = (int)MineshaftBlocks.CeilingSupport; intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = (int)MineshaftBlocks.CeilingSupport; } else { intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = (int)MineshaftBlocks.Support; intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = (int)MineshaftBlocks.Support; } } for (int z2 = 0; z2 <= 5; z2++) { if (intAreaFull[x + intOffsetX, z + intOffsetZ + z2] == (int)MineshaftBlocks.Support) { intAreaFull[x + intOffsetX, z + intOffsetZ + z2] = (int)MineshaftBlocks.RailWithSupport; } else { intAreaFull[x + intOffsetX, z + intOffsetZ + z2] = (int)MineshaftBlocks.Rail; } } } if (intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air) { MakeChestAndOrTorch(intAreaOverview, intAreaFull, (x - 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX - 2, z + intOffsetZ); MakeChestAndOrTorch(intAreaOverview, intAreaFull, (x + 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX + 2, z + intOffsetZ); MakeChestAndOrTorch(intAreaOverview, intAreaFull, x / MULTIPLIER, (z - 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ - 2); MakeChestAndOrTorch(intAreaOverview, intAreaFull, x / MULTIPLIER, (z + 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ + 2); } } } } intAreaFull[intXPosOriginal, intZPosOriginal] = (int)MineshaftBlocks.EntranceSection; int intSupportMaterial = RandomHelper.RandomNumber(BlockType.WOOD, BlockType.WOOD_PLANK, BlockType.FENCE); for (int x = 0; x < intAreaFull.GetLength(0); x++) { for (int z = 0; z < intAreaFull.GetLength(1); z++) { if (intDepth <= 4) { if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.GRAVEL) { bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockType.STONE); } } if (intDepth <= 2) { if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.SAND || bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.SANDSTONE) { bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockType.DIRT); } } switch(intAreaFull[x, z]) { case (int)MineshaftBlocks.NaturalTerrain: break; case (int)MineshaftBlocks.Air: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } break; case (int)MineshaftBlocks.EntranceSection: case (int)MineshaftBlocks.Rail: for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 38 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.GRAVEL); } else if (y == 39 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.RAILS); } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } } break; case (int)MineshaftBlocks.RailWithSupport: for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 38 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.GRAVEL); } else if (y == 39 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.RAILS); } else if (y == 40 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intSupportMaterial); } } break; case (int)MineshaftBlocks.Support: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intSupportMaterial); } break; case (int)MineshaftBlocks.ChestAndOrTorch: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 39 - (5 * intDepth) && RandomHelper.NextDouble() > 0.9) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.CHEST); MakeChestItems(bm, x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intResourceChances, strResourceNames); } else if (y == 41 - (5 * intDepth) && RandomHelper.NextDouble() < (double)intTorchChance / 100) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.TORCH); if (intAreaFull[x - 1, z] == 0) { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 1); } else if (intAreaFull[x + 1, z] == 0) { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 2); } else if (intAreaFull[x, z - 1] == 0) { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 3); } else { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 4); } } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } } break; case (int)MineshaftBlocks.CeilingSupport: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 41 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intSupportMaterial); } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } } break; case (int)MineshaftBlocks.Unused9: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * (intDepth - 1)); y++) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } break; case (int)MineshaftBlocks.Structure: // this will be overwritten later break; default: Debug.Fail("Invalid switch result"); break; } } } foreach (structSection MineshaftSection in lstSections) { SourceWorld.InsertBuilding(bm, new int[0, 0], _intBlockStartBuildings, MineshaftSection.x, MineshaftSection.z, MineshaftSection.bldMineshaftSection, 38 - (5 * intDepth)); } world.Save(); _intBlockStartBuildings += 2; //#if DEBUG // File.WriteAllText("output_area_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaOverview)); // File.WriteAllText("output_map_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaFull)); //#endif }
private void BuildHouse(int X, int Z, int AverageHeight, BlockManager bm) { for (int x = 0; x < _fp.X; ++x) { for (int z = 0; z < _fp.Z; ++z) { if (x == 0 || x == _fp.X - 1 || z == 0 || z == _fp.Z - 1) { //Walls. for (int y = AverageHeight; y < AverageHeight + 4; ++y) { //Walls should be wood. if (y != AverageHeight + 2) bm.SetID (x + X, y, z + Z, BlockInfo.Wood.ID); else bm.SetID (x + X, y, z + Z, BlockInfo.Glass.ID); } } else { //Floor is wooden planks. bm.SetID (x + X, AverageHeight, z + Z, BlockInfo.WoodPlank.ID); } //Roof. int peak = (int) (x * (x - _fp.X - 1) + z * (z - _fp.Z - 1)); if (_o == Orientation.NORTH || _o == Orientation.SOUTH) { //Absolute value function. Graph makes the peak of the roof. //peak = (Abs ((int)((x - 0.5) - _fp.X / 2.0)) * -1) + 7; //Make the stairs face the right direction. bm.SetData (x + X, AverageHeight + peak, z + Z, ((x > _fp.X / 2.0) ? 0x1 : 0x0)); } else { //Absolute value function. Graph makes the peak of the roof. //peak = (Abs ((int)((z - 0.5) - _fp.X / 2.0)) * -1) + 7; //Make the stairs face the right direction. bm.SetData (x + X, AverageHeight + peak, z + Z, ((z + 0.5 > _fp.Z / 2.0) ? 0x3 : 0x2)); } bm.SetID (x + X, AverageHeight + peak, z + Z, BlockInfo.WoodStairs.ID); if (x == 0 || x == _fp.X - 1 || z == 0 || z == _fp.Z - 1) { //If it is is the sides, fill up to the house height. for (int y = AverageHeight + 4; y < AverageHeight + peak; ++y) { bm.SetID (x + X, y, z + Z, BlockInfo.Wood.ID); } } } } }
public static void MakeFarms(BetaWorld world, BlockManager bm, int intFarmLength, int intMapLength) { AddBuildings(bm, intFarmLength, intMapLength); int intFail = 0; int intFarms = 0; while (intFail <= 500) { int xlen = RandomHelper.Next(8, 26); int x1 = RandomHelper.Next(4, intMapLength - (4 + xlen)); int zlen = RandomHelper.Next(8, 26); int z1 = RandomHelper.Next(4, intMapLength - (4 + zlen)); if (!(x1 >= intFarmLength && z1 >= intFarmLength && x1 <= intMapLength - intFarmLength && z1 <= intMapLength - intFarmLength)) { bool booValid = true; for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++) { for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++) { // make sure it doesn't overlap with the spawn point or another farm if ((x == intMapLength / 2 && z == intMapLength - (intFarmLength - 10)) || bm.GetID(x, 63, z) != BlockType.GRASS || bm.GetID(x, 64, z) != BlockType.AIR) { booValid = false; intFail++; } } } if (booValid) { // first there is a 25% chance of a hill or pond // if not, for large farms, there is a 50% chance it'll be an orchard // if not, 33% are cactus, 33% are wheat and 33% are sugarcane FarmTypes curFarm; int intFarmType = RandomHelper.Next(100); if (xlen >= 10 && zlen >= 10 && intFarmType > 75) { if (RandomHelper.NextDouble() > 0.5) { curFarm = FarmTypes.Pond; MakePond(bm, x1, xlen, z1, zlen, false); } else { curFarm = FarmTypes.Hill; MakeHill(bm, x1, xlen, z1, zlen, false); } } else { intFarmType = RandomHelper.Next(100); if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50) { curFarm = FarmTypes.Orchard; xlen = ((int)((xlen - 1) / 5) * 5) + 1; zlen = ((int)((zlen - 1) / 5) * 5) + 1; } else { intFarmType = RandomHelper.Next(3); if (intFarmType == 2) { curFarm = FarmTypes.Cactus; } else if (intFarmType == 1) { curFarm = FarmTypes.Wheat; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } else { curFarm = FarmTypes.SugarCane; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } } } int intWallMaterial = RandomHelper.NextDouble() > 0.5 ? BlockType.FENCE : BlockType.LEAVES; switch (curFarm) { case FarmTypes.Hill: case FarmTypes.Pond: intWallMaterial = 0; break; case FarmTypes.SugarCane: case FarmTypes.Mushroom: if (RandomHelper.NextDouble() > 0.5) { intWallMaterial = 0; } break; case FarmTypes.Wheat: intWallMaterial = BlockType.LEAVES; break; // no need for default - the other types don't need anything here } switch (intWallMaterial) { case BlockType.FENCE: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, BlockType.FENCE, 0, -1); break; case BlockType.LEAVES: // the saplings will all disappear if one of them is broken. // so we put wood beneath them to stop that happening BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen, BlockType.WOOD, 0, -1); BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, BlockType.LEAVES, 0, RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE, (int)LeafType.BIRCH)); break; case 0: // no wall break; default: Debug.Fail("Invalid switch result"); break; } switch (curFarm) { case FarmTypes.Orchard: int intSaplingType = RandomHelper.RandomNumber(SaplingBirchDataID, SaplingOakDataID, SaplingSpruceDataID); for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5) { for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5) { bm.SetID(x, 63, z, BlockType.GRASS); BlockShapes.MakeBlock(x, 64, z, BlockType.SAPLING, intSaplingType); } } break; case FarmTypes.Cactus: int intAttempts = 0; do { int xCactus = RandomHelper.Next(x1 + 1, x1 + xlen); int zCactus = RandomHelper.Next(z1 + 1, z1 + zlen); bool booValidFarm = true; for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++) { for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++) { if (bm.GetID(xCheck, 64, zCheck) != BlockType.AIR) { booValidFarm = false; } } } if (booValidFarm) { bm.SetID(xCactus, 64, zCactus, BlockType.CACTUS); if (RandomHelper.NextDouble() > 0.5) { bm.SetID(xCactus, 65, zCactus, BlockType.CACTUS); } } } while (++intAttempts < 100); break; case FarmTypes.Wheat: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, BlockType.GLASS, 0, -1); BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, BlockType.GLASS, 0); break; // no need for a default, because there's nothing to do for the other farms } for (int x = x1 + 1; x <= x1 + xlen - 1; x++) { for (int z = z1 + 1; z <= z1 + zlen - 1; z++) { switch (curFarm) { case FarmTypes.Cactus: bm.SetID(x, 63, z, BlockType.SAND); break; case FarmTypes.Wheat: if (z == z1 + 1) { bm.SetID(x, 63, z, BlockType.DOUBLE_SLAB); } else if (x % 2 == 0) { BlockShapes.MakeBlock(x, 63, z, BlockType.FARMLAND, 1); bm.SetID(x, 64, z, BlockType.CROPS); } else { bm.SetID(x, 63, z, BlockType.STATIONARY_WATER); } break; case FarmTypes.SugarCane: if (z != z1 + 1) { if (x % 2 == 0) { bm.SetID(x, 64, z, BlockType.SUGAR_CANE); if (RandomHelper.Next(100) > 50) { bm.SetID(x, 65, z, BlockType.SUGAR_CANE); } } else { bm.SetID(x, 63, z, BlockType.STATIONARY_WATER); } } break; // no need for a default, because there's nothing to do for the other farms } } } int intDoorPosition = x1 + RandomHelper.Next(1, xlen - 1); if (curFarm == FarmTypes.Wheat) { bm.SetID(intDoorPosition, 63, z1, BlockType.DOUBLE_SLAB); } if (intWallMaterial != 0) { BlockShapes.MakeBlock(intDoorPosition, 64, z1, BlockType.WOOD_DOOR, 4); BlockShapes.MakeBlock(intDoorPosition, 65, z1, BlockType.WOOD_DOOR, 4 + (int)DoorState.TOPHALF); } intFail = 0; if (++intFarms > 10) { world.Save(); intFarms = 0; } } } } MakeMiniPondsAndHills(world, bm, intFarmLength, intMapLength); MakeFlowers(bm, intFarmLength, intMapLength); }
private static void MakePond(BlockManager bm, int x, int xlen, int z, int zlen, bool booSmallPond) { int[,] intArea = new int[xlen, zlen]; int a, b; int c = 0, d = 0, clen = -1, dlen = -1; if (!booSmallPond) { c = RandomHelper.Next(1, intArea.GetUpperBound(0) - 7); d = RandomHelper.Next(1, intArea.GetUpperBound(1) - 7); clen = RandomHelper.Next(3, 7); dlen = RandomHelper.Next(3, 7); } for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { if (a < c || a > c + clen || b < d || b > d + dlen) { intArea[a, b] = 1; } } } intArea = CheckAgainstNeighbours(intArea, 0, 0, 7, 0, RandomHelper.Next(3, 6), true); intArea = CheckAgainstNeighbours(intArea, 6, 0, 2, 2, 1, false); intArea = CheckAgainstNeighbours(intArea, 14, 0, 3, 3, 1, false); bool booLava = (!booSmallPond && RandomHelper.NextDouble() < 0.15); for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { if (intArea[a, b] == 1) { bm.SetID(x + a, 64, z + b, BlockType.TALL_GRASS); bm.SetData(x + a, 64, z + b, RandomHelper.Next(1, 3)); } else { for (int y = 2; y <= intArea[a, b]; y++) { if (booLava) { bm.SetID(x + a, 65 - y, z + b, BlockType.STATIONARY_LAVA); } else { bm.SetID(x + a, 65 - y, z + b, BlockType.STATIONARY_WATER); } } } } } }
private static void MakeStreetLight(BlockManager bm, StreetLights slCurrent, int x1, int z1, int x2, int z2) { if (bm.GetID(x1, 63, z1) == BlockType.GRASS && bm.GetID(x1, 64, z1) == BlockType.AIR && bm.GetID(x1, 65, z1) == BlockType.AIR) { switch (slCurrent) { case StreetLights.Glowstone: bm.SetID(x1, 64, z1, BlockType.FENCE); bm.SetID(x1, 65, z1, BlockType.FENCE); bm.SetID(x1, 66, z1, BlockType.FENCE); bm.SetID(x1, 67, z1, BlockType.FENCE); bm.SetID(x1, 68, z1, BlockType.FENCE); bm.SetID(x2, 68, z2, BlockType.FENCE); bm.SetID(x2, 67, z2, BlockType.GLOWSTONE_BLOCK); break; case StreetLights.Torches: bm.SetID(x1, 64, z1, BlockType.FENCE); bm.SetID(x1, 65, z1, BlockType.FENCE); bm.SetID(x1, 66, z1, BlockType.FENCE); bm.SetID(x1, 67, z1, BlockType.FENCE); bm.SetID(x1, 68, z1, BlockType.FENCE); bm.SetID(x2, 68, z2, BlockType.FENCE); bm.SetID(x2, 67, z2, BlockType.WOOD_PLANK); if (z1 == z2) { BlockHelper.MakeTorch(x2, 67, z2 - 1, BlockType.WOOD_PLANK, 0); BlockHelper.MakeTorch(x2, 67, z2 + 1, BlockType.WOOD_PLANK, 0); } else { BlockHelper.MakeTorch(x2 - 1, 67, z2, BlockType.WOOD_PLANK, 0); BlockHelper.MakeTorch(x2 + 1, 67, z2, BlockType.WOOD_PLANK, 0); } break; } } }
public void BuildRoom (BlockManager bm, int x, int y, int z) { int ox = originx + (cellxlen + wallxwidth) * x; int oy = originy + (cellylen + wallywidth) * y; int oz = originz + (cellzlen + wallzwidth) * z; // Hollow out room for (int xi = 0; xi < cellxlen; xi++) { int xx = ox + wallxwidth + xi; for (int zi = 0; zi < cellzlen; zi++) { int zz = oz + wallzwidth + zi; for (int yi = 0; yi < cellylen; yi++) { int yy = oy + wallywidth + yi; bm.SetID(xx, yy, zz, (int)BlockType.AIR); } } } // Build walls for (int xi = 0; xi < cellxlen + 2 * wallxwidth; xi++) { for (int zi = 0; zi < cellzlen + 2 * wallzwidth; zi++) { for (int yi = 0; yi < wallywidth; yi++) { bm.SetID(ox + xi, oy + yi, oz + zi, (int)BlockType.BEDROCK); bm.SetID(ox + xi, oy + yi + cellylen + wallywidth, oz + zi, (int)BlockType.BEDROCK); } } } for (int xi = 0; xi < cellxlen + 2 * wallxwidth; xi++) { for (int zi = 0; zi < wallzwidth; zi++) { for (int yi = 0; yi < cellylen + 2 * wallywidth; yi++) { bm.SetID(ox + xi, oy + yi, oz + zi, (int)BlockType.BEDROCK); bm.SetID(ox + xi, oy + yi, oz + zi + cellzlen + wallzwidth, (int)BlockType.BEDROCK); } } } for (int xi = 0; xi < wallxwidth; xi++) { for (int zi = 0; zi < cellzlen + 2 * wallzwidth; zi++) { for (int yi = 0; yi < cellylen + 2 * wallywidth; yi++) { bm.SetID(ox + xi, oy + yi, oz + zi, (int)BlockType.BEDROCK); bm.SetID(ox + xi + cellxlen + wallxwidth, oy + yi, oz + zi, (int)BlockType.BEDROCK); } } } // Torchlight bm.SetID(ox + wallxwidth, oy + wallywidth + 2, oz + wallzwidth + 1, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth, oy + wallywidth + 2, oz + wallzwidth + cellzlen - 2, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth + cellxlen - 1, oy + wallywidth + 2, oz + wallzwidth + 1, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth + cellxlen - 1, oy + wallywidth + 2, oz + wallzwidth + cellzlen - 2, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth + 1, oy + wallywidth + 2, oz + wallzwidth, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth + cellxlen - 2, oy + wallywidth + 2, oz + wallzwidth, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth + 1, oy + wallywidth + 2, oz + wallzwidth + cellzlen - 1, (int)BlockType.TORCH); bm.SetID(ox + wallxwidth + cellxlen - 2, oy + wallywidth + 2, oz + wallzwidth + cellzlen - 1, (int)BlockType.TORCH); }
private static void RemovePaths(BlockManager bmDest, int[,] intArea, int intBlockStart) { for (int x = 0; x < intArea.GetLength(0); x++) { for (int z = 0; z < intArea.GetLength(1); z++) { if (intArea[x, z] == 1) { bmDest.SetID(intBlockStart + x, 63, intBlockStart + z, BlockType.GRASS); } } } }
public void AddPrize (BlockManager bm, int x, int y, int z) { int ox = originx + (cellxlen + wallxwidth) * x + wallxwidth; int oy = originy + (cellylen + wallywidth) * y + wallywidth; int oz = originz + (cellzlen + wallzwidth) * z + wallzwidth; Random rand = new Random(); for (int xi = 0; xi < cellxlen; xi++) { for (int zi = 0; zi < cellzlen; zi++) { if (rand.NextDouble() < 0.1) { bm.SetID(ox + xi, oy, oz + zi, (int)BlockType.DIAMOND_BLOCK); } } } }
private static void MakePaths(BetaWorld world, BlockManager bm, int[,] intArea, int intMapLength) { for (int x = 0; x < intArea.GetLength(0); x++) { for (int z = 0; z < intArea.GetLength(1); z++) { if (intArea[x, z] == 1) { if (Math.Abs(x - (intArea.GetLength(0) / 2)) == 2 && Math.Abs(z - (intArea.GetLength(1) / 2)) == 2) { // don't need these } else if (Math.Abs(x - (intArea.GetLength(0) / 2)) == 2 || Math.Abs(z - (intArea.GetLength(1) / 2)) == 2) { if (MultipleNeighbouringPaths(intArea, x, z)) { bm.SetID(_intBlockStart + x, 63, _intBlockStart + z, BlockType.DOUBLE_SLAB); } } else { bm.SetID(_intBlockStart + x, 63, _intBlockStart + z, BlockType.DOUBLE_SLAB); } } } if (x % 20 == 0) { world.Save(); } } }