private static int[, ,] AddResources(int[, ,] intEnlargedArea, int Y, frmMace frmLogForm) { int X, Z; int intResources = (int)(City.MapLength * Y * City.MapLength * 0.005); frmLogForm.UpdateLog("Adding resource patches: " + intResources, true, true); do { X = RandomHelper.Next(1, intEnlargedArea.GetLength(0) - 1); Y = RandomHelper.Next(1, intEnlargedArea.GetLength(1) - 1); Z = RandomHelper.Next(1, intEnlargedArea.GetLength(2) - 1); if (intEnlargedArea[X, Y, Z] == BlockInfo.Stone.ID) { double dblDepth = (double)Y / intEnlargedArea.GetLength(1); // this increases ore frequency as we get lower if (dblDepth < RandomHelper.NextDouble() * 1.5) { intEnlargedArea[X, Y, Z] = SelectRandomResource(dblDepth); intResources--; } } } while (intResources > 0); return(intEnlargedArea); }
public static void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings, bool booIncludePaths, bool booIncludeMineshaft, bool booIncludeItemsInChests, bool booIncludeValuableBlocks, bool booIncludeGhostdancerSpawners, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strTowerAddition, string strWallMaterial, string strCitySeed, string strWorldSeed, bool booExportSchematic) { #region seed the random number generators int intCitySeed, intWorldSeed; Random randSeeds = new Random(); if (strCitySeed.Length == 0) { intCitySeed = randSeeds.Next(); frmLogForm.UpdateLog("Random city seed: " + intCitySeed); } else { intCitySeed = JavaStringHashCode(strCitySeed); frmLogForm.UpdateLog("Random city seed: " + strCitySeed); } if (strWorldSeed.Length == 0) { intWorldSeed = randSeeds.Next(); frmLogForm.UpdateLog("Random world seed: " + intWorldSeed); } else { intWorldSeed = JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Random world seed: " + strWorldSeed); } RandomHelper.SetSeed(intCitySeed); #endregion #region create minecraft world directory from a random unused city name string strFolder = String.Empty, strCityName = String.Empty; strUserCityName = SafeFilename(strUserCityName); if (strUserCityName.ToLower().Trim().Length == 0) { strUserCityName = "random"; } if (strUserCityName.ToLower().Trim() != "random") { if (Directory.Exists(Utils.GetMinecraftSavesDirectory(strUserCityName))) { if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists."); return; } } else { strCityName = strUserCityName; strFolder = Utils.GetMinecraftSavesDirectory(strCityName); } } if (strCityName.Length == 0) { string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt")); strEnd = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt")); strCityName = "City of " + strStart + strEnd; strFolder = Utils.GetMinecraftSavesDirectory(strCityName); } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder) || (strStart + strEnd).Length > 14); } Directory.CreateDirectory(strFolder); RandomHelper.SetSeed(intCitySeed); #endregion #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); BetaChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = RandomHelper.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; default: Debug.Fail("Invalid switch result"); break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmLength = booIncludeFarms ? 32 : 8; int intMapLength = intCitySize + (intFarmLength * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapLength); BlockHelper.SetupClass(bmDest, intMapLength); if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests, booIncludeGhostdancerSpawners)) { return; } NoticeBoard.SetupClass(intCitySeed, intWorldSeed); #endregion #region determine random options // ensure selected options take priority, but don't set things on fire if (strTowerAddition == "Random") { strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag"); } if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Lava" || strMoatType == "Fire" || strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } if (strWallMaterial == "Random") { if (strMoatType == "Lava" || strMoatType == "Fire" || strOutsideLights == "Fire") { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone"); } else { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone", "Wood Planks"); if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } } } if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } if (strMoatType == "Random") { int intRand = RandomHelper.Next(100); if (intRand >= 90) { strMoatType = "Drop to Bedrock"; } else if (intRand >= 80) { strMoatType = "Cactus"; } else if (intRand >= 50) { strMoatType = "Lava"; } else if (intRand >= 40) { strMoatType = "Fire"; } else { strMoatType = "Water"; } } int intWallMaterial = BlockType.STONE; switch (strWallMaterial) { case "Brick": intWallMaterial = BlockType.BRICK_BLOCK; break; case "Cobblestone": intWallMaterial = BlockType.COBBLESTONE; break; case "Sandstone": intWallMaterial = BlockType.SANDSTONE; break; case "Stone": intWallMaterial = BlockType.STONE; break; case "Wood Planks": intWallMaterial = BlockType.WOOD_PLANK; break; case "Wood Logs": intWallMaterial = BlockType.WOOD; break; case "Bedrock": intWallMaterial = BlockType.BEDROCK; break; case "Mossy Cobblestone": intWallMaterial = BlockType.MOSS_STONE; break; case "Netherrack": intWallMaterial = BlockType.NETHERRACK; break; case "Glass": intWallMaterial = BlockType.GLASS; break; case "Ice": intWallMaterial = BlockType.ICE; break; case "Snow": intWallMaterial = BlockType.SNOW_BLOCK; break; case "Glowstone": intWallMaterial = BlockType.GLOWSTONE_BLOCK; break; case "Dirt": intWallMaterial = BlockType.DIRT; break; case "Obsidian": intWallMaterial = BlockType.OBSIDIAN; break; case "Jack-o-Lantern": intWallMaterial = BlockType.JACK_O_LANTERN; break; case "Soul sand": intWallMaterial = BlockType.SOUL_SAND; break; case "Gold": intWallMaterial = BlockType.GOLD_BLOCK; break; case "Diamond": intWallMaterial = BlockType.DIAMOND_BLOCK; break; default: Debug.Fail("Invalid switch result"); break; } #endregion #region make the city frmLogForm.UpdateLog("Creating underground terrain"); Chunks.CreateInitialChunks(cmDest, intMapLength / 16, frmLogForm); frmLogForm.UpdateProgress(25); Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint(); if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmLength, intMapLength, strCityEmblem, strOutsideLights, intWallMaterial); } frmLogForm.UpdateProgress(34); if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmLength, intMapLength, strCitySize, booIncludeMineshaft); frmLogForm.UpdateProgress(36); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmLength, intMapLength, booIncludePaths); frmLogForm.UpdateProgress(45); if (booIncludeMineshaft) { frmLogForm.UpdateLog("Creating mineshaft"); Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmLength, intMapLength, spMineshaftEntrance); } } } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmLength, intMapLength, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmLength, intMapLength, booIncludeMoat, booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType, strCityName); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmLength, intMapLength, booIncludeWalls, strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial); } frmLogForm.UpdateProgress(54); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmLength, intMapLength); } frmLogForm.UpdateProgress(58); if (!booIncludeValuableBlocks) { cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapLength, intWallMaterial); } frmLogForm.UpdateProgress(60); Chunks.PositionRails(worldDest, bmDest, intMapLength); frmLogForm.UpdateProgress(62); #endregion #region world settings // spawn looking at one of the city entrances if (booIncludeFarms) { SpawnPoint spLevel = new SpawnPoint(7, 11, 13); worldDest.Level.Spawn = spLevel; worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 10)); } else { worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 7)); } // spawn in the middle of the city //#if DEBUG //worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength / 2); //#endif if (strWorldSeed.Length > 0) { worldDest.Level.RandomSeed = intWorldSeed; } #if RELEASE worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endif #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2); #endif frmLogForm.UpdateLog("Creating lighting data"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapLength / 16, 2)); worldDest.Level.LevelName = strCityName; worldDest.Save(); if (booExportSchematic) { frmLogForm.UpdateLog("Creating schematic"); AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength); for (int x = 0; x < intMapLength; x++) { for (int z = 0; z < intMapLength; z++) { for (int y = 0; y < 128; y++) { abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z)); } } } Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength); CitySchematic.Blocks = abcExport; CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic"); } frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
public void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings, bool booIncludePaths, bool booIncludeMineshaft, bool booIncludeItemsInChests, bool booIncludeValuableBlocks, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strTowerAddition, string strWallMaterial, string strCitySeed, string strWorldSeed) { #region seed the random number generators int intCitySeed, intWorldSeed; Random randSeeds = new Random(); if (strCitySeed == "") { intCitySeed = randSeeds.Next(); frmLogForm.UpdateLog("Random city seed: " + intCitySeed); } else { intCitySeed = JavaStringHashCode(strCitySeed); frmLogForm.UpdateLog("Random city seed: " + strCitySeed); } if (strWorldSeed == "") { intWorldSeed = randSeeds.Next(); frmLogForm.UpdateLog("Random world seed: " + intWorldSeed); } else { intWorldSeed = JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Random world seed: " + strWorldSeed); } RandomHelper.SetSeed(intCitySeed); #endregion #region create minecraft world directory from a random unused city name string strFolder = "", strCityName = ""; strUserCityName = SafeFilename(strUserCityName); if (strUserCityName.ToLower().Trim() == "") { strUserCityName = "Random"; } if (strUserCityName.ToLower().Trim() != "random") { if (Directory.Exists(Utils.GetMinecraftSavesDir(strUserCityName))) { if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists."); return; } } else { strCityName = strUserCityName; strFolder = Utils.GetMinecraftSavesDir(strCityName); } } if (strCityName == "") { string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt")); strEnd = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt")); strCityName = "City of " + strStart + strEnd; strFolder = Utils.GetMinecraftSavesDir(strCityName); } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder)); } Directory.CreateDirectory(strFolder); RandomHelper.SetSeed(intCitySeed); #endregion #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); ChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = RandomHelper.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmSize = booIncludeFarms ? 32 : 16; int intMapSize = intCitySize + (intFarmSize * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapSize); BlockHelper.SetupClass(bmDest, intMapSize); if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests)) { return; } NoticeBoard.SetupClass(intCitySeed, intWorldSeed); #endregion #region determine random options // ensure selected options take priority, but don't set things on fire if (strTowerAddition == "Random") { strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag"); } if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Lava" || strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } if (strWallMaterial == "Random") { if (strMoatType == "Lava" || strOutsideLights == "Fire") { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone"); } else { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone", "Wood Planks"); if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } } } if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } if (strMoatType == "Random") { int intRand = RandomHelper.Next(100); if (intRand >= 90) { strMoatType = "Drop to Bedrock"; } else if (intRand >= 80) { strMoatType = "Cactus"; } else if (intRand >= 50) { strMoatType = "Lava"; } else { strMoatType = "Water"; } } int intWallMaterial = (int)BlockType.STONE; switch (strWallMaterial) { case "Brick": intWallMaterial = (int)BlockType.BRICK_BLOCK; break; case "Cobblestone": intWallMaterial = (int)BlockType.COBBLESTONE; break; case "Sandstone": intWallMaterial = (int)BlockType.SANDSTONE; break; case "Stone": intWallMaterial = (int)BlockType.STONE; break; case "Wood Planks": intWallMaterial = (int)BlockType.WOOD_PLANK; break; case "Wood Logs": intWallMaterial = (int)BlockType.WOOD; break; case "Bedrock": intWallMaterial = (int)BlockType.BEDROCK; break; case "Glass": intWallMaterial = (int)BlockType.GLASS; break; case "Dirt": intWallMaterial = (int)BlockType.DIRT; break; case "Obsidian": intWallMaterial = (int)BlockType.OBSIDIAN; break; } #endregion #region make the city frmLogForm.UpdateLog("Creating underground terrain"); Chunks.MakeChunks(cmDest, intMapSize / 16, frmLogForm); frmLogForm.UpdateProgress(25); if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(34); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths); } } frmLogForm.UpdateProgress(43); if (booIncludeMineshaft) { frmLogForm.UpdateLog("Creating mineshaft"); Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(49); } if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights, intWallMaterial); } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial); } frmLogForm.UpdateProgress(54); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(58); if (!booIncludeValuableBlocks) { cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapSize); } frmLogForm.UpdateProgress(62); #endregion #region world settings // spawn in a guard tower //worldDest.Level.SpawnX = intFarmSize + 5; //worldDest.Level.SpawnZ = intFarmSize + 5; //worldDest.Level.SpawnY = 82; // spawn looking at one of the city entrances worldDest.Level.SpawnX = intMapSize / 2; worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10); worldDest.Level.SpawnY = 64; // spawn in the middle of the city //worldDest.Level.SpawnX = intMapSize / 2; //worldDest.Level.SpawnZ = (intMapSize / 2) - 1; //worldDest.Level.SpawnY = 64; // spawn default //world.Level.SpawnX = 0; //world.Level.SpawnY = 65; //world.Level.SpawnZ = 0; if (strWorldSeed != "") { worldDest.Level.RandomSeed = intWorldSeed; } worldDest.Level.LevelName = strCityName; #if RELEASE worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endif #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2); #endif frmLogForm.UpdateLog("Resetting lighting"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2)); worldDest.Save(); frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
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 }
// todo low: long code is long static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed, string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes, int ChunksBetweenCities, string strSpawnPoint) { worldCities = new WorldCity[TotalCities]; lstCityNames.Clear(); RandomHelper.SetRandomSeed(); #region create minecraft world directory from a random unused city name string strFolder = String.Empty, strWorldName = String.Empty; UserWorldName = Utils.SafeFilename(UserWorldName); if (UserWorldName.Trim().Length == 0) { UserWorldName = "random"; } if (UserWorldName.ToLower().Trim() != "random") { if (Directory.Exists(Utils.GetMinecraftSavesDirectory(UserWorldName))) { if (MessageBox.Show("A world called \"" + UserWorldName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.", false, false); return; } } else { strWorldName = UserWorldName; strFolder = Utils.GetMinecraftSavesDirectory(strWorldName); } } if (strWorldName.Length == 0) { strWorldName = Utils.GenerateWorldName(); strFolder = Utils.GetMinecraftSavesDirectory(strWorldName); } Directory.CreateDirectory(strFolder); frmLogForm.UpdateLog("World name: " + strWorldName, false, true); #endregion #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); worldDest.Level.LevelName = "Creating. Don't open until Mace is finished."; BetaChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region Determine themes // "how does this work, robson?" // well, I'm glad you asked! // we keep selecting a random unused checked theme, until they've all been used once. // after that, all other cities will have a random checked theme strCheckedThemes = RandomHelper.ShuffleArray(strCheckedThemes); for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++) { if (CurrentCityID <= strCheckedThemes.GetUpperBound(0)) { worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID]; } else { worldCities[CurrentCityID].ThemeName = RandomHelper.RandomString(strCheckedThemes); } Debug.WriteLine(worldCities[CurrentCityID].ThemeName); City.ThemeName = worldCities[CurrentCityID].ThemeName; worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size"); } #endregion GenerateCityLocations(TotalCities, ChunksBetweenCities); int intRandomCity = RandomHelper.Next(TotalCities); for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++) { MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID); GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z); #region set spawn point if (City.ID == intRandomCity) { switch (strSpawnPoint) { case "Away from the cities": worldDest.Level.Spawn = new SpawnPoint(0, 65, 0); break; case "Inside a random city": worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2), 65, ((worldCities[intRandomCity].z + 30) * 16) + (City.MapLength / 2)); break; case "Outside a random city": if (City.HasFarms) { worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2), 65, ((worldCities[intRandomCity].z + 30) * 16) + 20); } else { worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2), 65, ((worldCities[intRandomCity].z + 30) * 16) + 2); } break; default: Debug.Fail("invalid spawn point"); break; } frmLogForm.UpdateLog("Spawn point set to " + worldDest.Level.Spawn.X + "," + worldDest.Level.Spawn.Y + "," + worldDest.Level.Spawn.Z, false, true); } #endregion } City.ID = TotalCities; frmLogForm.UpdateProgress(0); #region weather #if RELEASE frmLogForm.UpdateLog("Setting weather", false, true); worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.2) { frmLogForm.UpdateLog("Rain", false, true); worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { frmLogForm.UpdateLog("Thunder", false, true); worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endif #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2); #endif #region lighting frmLogForm.UpdateLog("\nCreating world lighting data", false, false); Chunks.ResetLighting(worldDest, cmDest, frmLogForm); frmLogForm.UpdateProgress(0.95); #endregion #region world details worldDest.Level.LevelName = strWorldName; frmLogForm.UpdateLog("Setting world type: " + strWorldType, false, true); switch (strWorldType.ToLower()) { case "creative": worldDest.Level.GameType = GameType.CREATIVE; break; case "survival": worldDest.Level.GameType = GameType.SURVIVAL; break; case "hardcore": worldDest.Level.GameType = GameType.SURVIVAL; worldDest.Level.UseHardcoreMode = true; break; default: Debug.Fail("Invalidate world type selected."); break; } frmLogForm.UpdateLog("World map features: " + booWorldMapFeatures.ToString(), false, true); worldDest.Level.UseMapFeatures = booWorldMapFeatures; if (strWorldSeed != String.Empty) { worldDest.Level.RandomSeed = Utils.JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true); } else { worldDest.Level.RandomSeed = RandomHelper.Next(); frmLogForm.UpdateLog("Random world seed: " + worldDest.Level.RandomSeed, false, true); } worldDest.Level.LastPlayed = (DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000; frmLogForm.UpdateLog("World time: " + worldDest.Level.LastPlayed, false, true); #endregion worldDest.Save(); frmLogForm.UpdateProgress(1); frmLogForm.UpdateLog("\nCreated the " + strWorldName + "!", false, false); frmLogForm.UpdateLog("It'll be at the top of your MineCraft world list.", false, false); // todo low: export schematic #region export schematic //if (booExportSchematic) //{ // frmLogForm.UpdateLog("Creating schematic"); // AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength); // for (int x = 0; x < intMapLength; x++) // { // for (int z = 0; z < intMapLength; z++) // { // for (int y = 0; y < 128; y++) // { // abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z)); // } // } // } // Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength); // CitySchematic.Blocks = abcExport; // CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic"); //} #endregion }
private static void MakeLevel(BetaWorld world, BlockManager bm, int intDepth, int intMineshaftSize) { strResourceNames = ValueFromXMLElement(Path.Combine("Resources", "MineshaftChests.xml"), "level" + intDepth, "names").Split(','); intResourceChances = StringArrayToIntArray( ValueFromXMLElement(Path.Combine("Resources", "MineshaftChests.xml"), "level" + intDepth, "chances").Split(',')); int intTorchChance = Convert.ToInt32(ValueFromXMLElement(Path.Combine("Resources", "MineshaftChests.xml"), "level" + intDepth, "torch_chance")); int[,] intMap = new int[intMineshaftSize, intMineshaftSize]; int intXPosOriginal = intMap.GetLength(0) / 2; int intZPosOriginal = intMap.GetLength(1) / 2; int[,] intArea = new int[intMap.GetLength(0) / MULTIPLIER, intMap.GetLength(1) / MULTIPLIER]; int intXPos = intXPosOriginal / MULTIPLIER; int intZPos = intZPosOriginal / MULTIPLIER; intArea[intXPos, intZPos] = 1; CreateRouteXPlus(intArea, intXPos + 1, intZPos, 0); CreateRouteZPlus(intArea, intXPos, intZPos + 1, 1); CreateRouteXMinus(intArea, intXPos - 1, intZPos, 2); CreateRouteZMinus(intArea, intXPos, intZPos - 1, 3); int intOffsetX = (intXPosOriginal - (intXPos * MULTIPLIER)) - 2; int intOffsetZ = (intZPosOriginal - (intZPos * MULTIPLIER)) - 2; int intGhostX = 0, intGhostZ = 0; bool booGhost = false; if (intDepth == 7) { for (int x = 1; x < intArea.GetLength(0) - 1 && !booGhost; x++) { for (int z = 1; z < intArea.GetLength(1) - 1 && !booGhost; z++) { if (intArea[x, z] == 1 && intArea[x + 1, z] == 0 && intArea[x - 1, z] == 0 && intArea[x, z + 1] == 0) { intArea[x, z] = 9; intGhostX = (x * MULTIPLIER) + intOffsetX; intGhostZ = (z * MULTIPLIER) + intOffsetZ; booGhost = true; } } } } for (int x = 4; x < intMap.GetLength(0) - 4; x++) { for (int z = 4; z < intMap.GetLength(1) - 4; z++) { if (intArea.GetLength(0) > x / MULTIPLIER && intArea.GetLength(1) > z / MULTIPLIER) { if (intMap[x + intOffsetX, z + intOffsetZ] < 4) { intMap[x + intOffsetX, z + intOffsetZ] = intArea[x / MULTIPLIER, z / MULTIPLIER]; } } if ((x + 3) % 5 == 0 && (z + 3) % 5 == 0 && intArea[x / MULTIPLIER, z / MULTIPLIER] == 1) { if (intArea[(x / MULTIPLIER) + 1, z / MULTIPLIER] == 1) { for (int x2 = 0; x2 < 5; x2++) { if (x2 == 1 || x2 == 3) { intMap[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = 8; intMap[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = 8; } else { intMap[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = 5; intMap[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = 5; } } for (int x2 = 0; x2 <= 5; x2++) { if (intMap[x + intOffsetX + x2, z + intOffsetZ] == 5) { intMap[x + intOffsetX + x2, z + intOffsetZ] = 4; } else { intMap[x + intOffsetX + x2, z + intOffsetZ] = 7; } } } if (intArea[x / MULTIPLIER, (z / MULTIPLIER) + 1] == 1) { for (int z2 = 0; z2 < 5; z2++) { if (z2 == 1 || z2 == 3) { intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = 8; intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = 8; } else { intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = 5; intMap[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = 5; } } for (int z2 = 0; z2 <= 5; z2++) { if (intMap[x + intOffsetX, z + intOffsetZ + z2] == 5) { intMap[x + intOffsetX, z + intOffsetZ + z2] = 4; } else { intMap[x + intOffsetX, z + intOffsetZ + z2] = 7; } } } if (intArea[x / MULTIPLIER, z / MULTIPLIER] == 1) { MakeChestAndOrTorch(intArea, intMap, (x - 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX - 2, z + intOffsetZ); MakeChestAndOrTorch(intArea, intMap, (x + 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX + 2, z + intOffsetZ); MakeChestAndOrTorch(intArea, intMap, x / MULTIPLIER, (z - 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ - 2); MakeChestAndOrTorch(intArea, intMap, x / MULTIPLIER, (z + 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ + 2); } } } } intMap[intXPosOriginal, intZPosOriginal] = 3; int intSupportMaterial = RandomHelper.RandomNumber((int)BlockType.WOOD, (int)BlockType.WOOD_PLANK, (int)BlockType.FENCE); intSupportMaterial = (int)BlockType.WOOD_PLANK; for (int x = 0; x < intMap.GetLength(0); x++) { for (int z = 0; z < intMap.GetLength(1); z++) { switch (intMap[x, z]) { case 0: break; case 1: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR); } break; case 9: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * (intDepth - 1)); y++) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR); } break; case 2: break; case 4: for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 38 - (5 * intDepth)) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.GRAVEL); } else if (y == 39 - (5 * intDepth)) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.RAILS); } else if (y == 40 - (5 * intDepth)) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR); } else { bm.SetID(x + intBlockStart, y, z + intBlockStart, intSupportMaterial); } } break; case 5: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { bm.SetID(x + intBlockStart, y, z + intBlockStart, intSupportMaterial); } break; case 6: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 39 - (5 * intDepth) && RandomHelper.NextDouble() > 0.9) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.CHEST); MakeChestItems(bm, x + intBlockStart, y, z + intBlockStart); } else if (y == 41 - (5 * intDepth) && RandomHelper.NextDouble() < (double)intTorchChance / 100) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.TORCH); if (intMap[x - 1, z] == 0) { bm.SetData(x + intBlockStart, y, z + intBlockStart, 1); } else if (intMap[x + 1, z] == 0) { bm.SetData(x + intBlockStart, y, z + intBlockStart, 2); } else if (intMap[x, z - 1] == 0) { bm.SetData(x + intBlockStart, y, z + intBlockStart, 3); } else { bm.SetData(x + intBlockStart, y, z + intBlockStart, 4); } } else { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR); } } break; case 7: case 3: for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 38 - (5 * intDepth)) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.GRAVEL); } else if (y == 39 - (5 * intDepth)) { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.RAILS); } else { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR); } } break; case 8: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 41 - (5 * intDepth)) { bm.SetID(x + intBlockStart, y, z + intBlockStart, intSupportMaterial); } else { bm.SetID(x + intBlockStart, y, z + intBlockStart, (int)BlockType.AIR); } } break; } } } for (int x = 0; x < intMap.GetLength(0); x++) { for (int z = 0; z < intMap.GetLength(1); z++) { switch (intMap[x, z]) { case 3: case 4: case 7: BlockHelper.MakeRail(x + intBlockStart, 39 - (5 * intDepth), z + intBlockStart); break; } } } if (booGhost) { BlockShapes.MakeSolidBox(intBlockStart + intGhostX - 1, intBlockStart + intGhostX + 5, 39 - (5 * intDepth), 46 - (5 * intDepth), intBlockStart + intGhostZ - 1, intBlockStart + intGhostZ + 5, (int)BlockType.AIR, 0); for (int x = intBlockStart + intGhostX; x <= intBlockStart + intGhostX + 4; x++) { for (int y = 39 - (5 * intDepth); y <= 44 - (5 * intDepth); y++) { for (int z = intBlockStart + intGhostZ + 3; z <= intBlockStart + intGhostZ + 4; z++) { bm.SetID(x, y, z, (int)BlockType.WOOL); bm.SetData(x, y, z, (int)WoolColor.WHITE); } } } bm.SetID(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.TORCH); bm.SetID(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)BlockType.TORCH); bm.SetID(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.TORCH); bm.SetID(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)BlockType.TORCH); bm.SetData(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)TorchOrientation.FLOOR); bm.SetData(intBlockStart + intGhostX + 0, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)TorchOrientation.FLOOR); bm.SetData(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)TorchOrientation.FLOOR); bm.SetData(intBlockStart + intGhostX + 4, 44 - (5 * intDepth), intBlockStart + intGhostZ + 4, (int)TorchOrientation.FLOOR); bm.SetID(intBlockStart + intGhostX + 1, 43 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.OBSIDIAN); bm.SetID(intBlockStart + intGhostX + 3, 43 - (5 * intDepth), intBlockStart + intGhostZ + 3, (int)BlockType.OBSIDIAN); bm.SetID(intBlockStart + intGhostX + 1, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)BlockType.TORCH); bm.SetData(intBlockStart + intGhostX + 1, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)TorchOrientation.FLOOR); bm.SetID(intBlockStart + intGhostX + 2, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)BlockType.SIGN_POST); bm.SetData(intBlockStart + intGhostX + 2, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)SignPostOrientation.EAST); BlockHelper.MakeSignPost(intBlockStart + intGhostX + 2, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, "Ghostdancer:|Victim of the|Creeper Rush|of '09"); bm.SetID(intBlockStart + intGhostX + 3, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)BlockType.TORCH); bm.SetData(intBlockStart + intGhostX + 3, 39 - (5 * intDepth), intBlockStart + intGhostZ + 2, (int)TorchOrientation.FLOOR); } world.Save(); //File.WriteAllText("c:\\output.txt", TwoDimensionalArrayToString(intMap)); }
public void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard, bool booIncludeBuildings, bool booIncludePaths, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strFireBeacons, string strCitySeed, string strWorldSeed) { #region Seed the random number generators int intCitySeed, intWorldSeed; Random randSeeds = new Random(); if (strCitySeed == "") { intCitySeed = randSeeds.Next(); frmLogForm.UpdateLog("Random city seed: " + intCitySeed); } else { intCitySeed = JavaStringHashCode(strCitySeed); frmLogForm.UpdateLog("Random city seed: " + strCitySeed); } if (strWorldSeed == "") { intWorldSeed = randSeeds.Next(); frmLogForm.UpdateLog("Random world seed: " + intWorldSeed); } else { intWorldSeed = JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Random world seed: " + strWorldSeed); } RandomHelper.SetSeed(intCitySeed); #endregion #region create minecraft world directory from a random unused city name string strFolder = "", strCityName = ""; strUserCityName = SafeFilename(strUserCityName); if (strUserCityName.ToLower().Trim() == "") { strUserCityName = "Random"; } if (strUserCityName.ToLower().Trim() != "random") { if (Directory.Exists(Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strUserCityName + @"\")) { if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists."); return; } } else { strCityName = strUserCityName; } } if (strCityName == "") { string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine("Resources\\CityAdj.txt"); strEnd = RandomHelper.RandomFileLine("Resources\\CityNoun.txt"); strCityName = "City of " + strStart + strEnd; strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\"; } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder)); } Directory.CreateDirectory(strFolder); #endregion RandomHelper.SetSeed(intCitySeed); #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); ChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = RandomHelper.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmSize = booIncludeFarms ? 32 : 16; int intMapSize = intCitySize + (intFarmSize * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapSize); BlockHelper.SetupClass(bmDest, intMapSize); SourceWorld.SetupClass(worldDest); #endregion if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } #region make the city frmLogForm.UpdateLog("Creating chunks"); Chunks.MakeChunks(cmDest, 0, intMapSize / 16, frmLogForm); frmLogForm.UpdateProgress(35); if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(38); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths); } } frmLogForm.UpdateProgress(50); if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights); } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strFireBeacons); } frmLogForm.UpdateProgress(54); if (booIncludeWalls && booIncludeNoticeboard) { frmLogForm.UpdateLog("Creating noticeboard"); NoticeBoard.MakeNoticeBoard(bmDest, intFarmSize, intMapSize, intCitySeed, intWorldSeed); } frmLogForm.UpdateProgress(55); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(58); #endregion #region world settings // spawn in a guard tower //world.Level.SpawnX = intFarmSize + 5; //world.Level.SpawnZ = intFarmSize + 5; //world.Level.SpawnY = 74; // spawn looking at one of the city entrances worldDest.Level.SpawnX = intMapSize / 2; worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10); worldDest.Level.SpawnY = 64; // spawn in the middle of the city //worldDest.Level.SpawnX = intMapSize / 2; //worldDest.Level.SpawnZ = (intMapSize / 2) - 1; //worldDest.Level.SpawnY = 64; // spawn default //world.Level.SpawnX = 0; //world.Level.SpawnY = 65; //world.Level.SpawnZ = 0; if (strWorldSeed != "") { worldDest.Level.RandomSeed = intWorldSeed; } worldDest.Level.LevelName = strCityName; worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2); #endif frmLogForm.UpdateLog("Resetting lighting"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2)); worldDest.Save(); frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ) { int[,] intDistrict = new int[intSizeX, intSizeZ]; int[,] intFinal = new int[intSizeX, intSizeZ]; int intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0; int intBonus = 0; List <int> lstBuildings = new List <int>(); List <int> lstAcceptedBuildings = new List <int>(); do { lstBuildings.Clear(); intBonus = 0; do { SourceWorld.Building CurrentBuilding; do { CurrentBuilding = SourceWorld.SelectRandomBuilding(); } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea, intStartX, intStartZ, intSizeX, intSizeZ)); bool booFound = false; if (RandomHelper.NextDouble() > 0.5) { intDistrict = RotateArray(intDistrict, RandomHelper.Next(4)); } int x, z = 0; for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSize && !booFound; x++) { for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSize && !booFound; z++) { booFound = IsFree(intDistrict, x, z, x + CurrentBuilding.intSize, z + CurrentBuilding.intSize); } } x--; z--; if (booFound) { for (int a = x + 1; a <= x + CurrentBuilding.intSize - 1; a++) { for (int b = z + 1; b <= z + CurrentBuilding.intSize - 1; b++) { intDistrict[a, b] = 2; } } if (CurrentBuilding.booUnique) { // we want to include the unique buildings, // so we give a slight preference to those intBonus += 15; } lstBuildings.Add(CurrentBuilding.intID); intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID; intDistrict[x + CurrentBuilding.intSize - 1, z + CurrentBuilding.intSize - 1] = 100 + CurrentBuilding.intID; intFail = 0; } else { intFail++; } } while (intFail < 10); int intCurWasted = SquaresWasted(intDistrict) - intBonus; if (intCurWasted < intWasted) { intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)]; Array.Copy(intDistrict, intFinal, intDistrict.Length); intWasted = intCurWasted; intAttempts = 10; lstAcceptedBuildings.Clear(); lstAcceptedBuildings.AddRange(lstBuildings); } Array.Clear(intDistrict, 0, intDistrict.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = RotateArray(intFinal, 1); } lstAllBuildings.AddRange(lstAcceptedBuildings); return(intFinal); }
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); }
public static void MakeFarms(BetaWorld world, BlockManager bm, int intFarmSize, int intMapSize) { AddMushroomFarms(bm, intFarmSize, intMapSize); int intFail = 0; int intFarms = 0; while (intFail <= 500) { int xlen = RandomHelper.Next(8, 26); int x1 = RandomHelper.Next(4, intMapSize - (4 + xlen)); int zlen = RandomHelper.Next(8, 26); int z1 = RandomHelper.Next(4, intMapSize - (4 + zlen)); if (!(x1 >= intFarmSize && z1 >= intFarmSize && x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize)) { 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 == intMapSize / 2 && z == intMapSize - (intFarmSize - 10)) || bm.GetID(x, 63, z) != (int)BlockType.GRASS || bm.GetID(x, 64, z) != (int)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, 25% are cactus, 50% are wheat and 25% 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(100); if (intFarmType > 75) { curFarm = FarmTypes.Cactus; } else if (intFarmType > 25) { 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 ? (int)BlockType.FENCE : (int)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 = (int)BlockType.LEAVES; break; } switch (intWallMaterial) { case (int)BlockType.FENCE: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, (int)BlockType.FENCE, 0, -1); break; case (int)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, (int)BlockType.WOOD, 0, -1); BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, (int)BlockType.LEAVES, 0, RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE, (int)LeafType.BIRCH)); break; } switch (curFarm) { case FarmTypes.Orchard: int intSaplingType = RandomHelper.RandomNumber(BlockHelper.SaplingBirch, BlockHelper.SaplingOak, BlockHelper.SaplingSpruce); 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, (int)BlockType.GRASS); bm.SetID(x, 64, z, (int)BlockType.SAPLING); bm.SetData(x, 64, z, intSaplingType); } } break; case FarmTypes.Cactus: int intAttempts = 0; do { int xCactus = RandomHelper.Next(x1 + 1, x1 + xlen), 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) != (int)BlockType.AIR) { booValidFarm = false; } } } if (booValidFarm) { bm.SetID(xCactus, 64, zCactus, (int)BlockType.CACTUS); if (RandomHelper.NextDouble() > 0.5) { bm.SetID(xCactus, 65, zCactus, (int)BlockType.CACTUS); } } intAttempts++; }while (intAttempts < 100); break; case FarmTypes.Wheat: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, (int)BlockType.GLASS, 0, -1); BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, (int)BlockType.GLASS, 0); break; } 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, (int)BlockType.SAND); break; case FarmTypes.Wheat: if (z == z1 + 1) { bm.SetID(x, 63, z, (int)BlockType.DOUBLE_SLAB); } else if (x % 2 == 0) { bm.SetID(x, 63, z, (int)BlockType.FARMLAND); bm.SetData(x, 63, z, 1); bm.SetID(x, 64, z, (int)BlockType.CROPS); } else { bm.SetID(x, 63, z, (int)BlockType.STATIONARY_WATER); } break; case FarmTypes.SugarCane: if (z != z1 + 1) { if (x % 2 == 0) { bm.SetID(x, 64, z, (int)BlockType.SUGAR_CANE); if (RandomHelper.Next(100) > 50) { bm.SetID(x, 65, z, (int)BlockType.SUGAR_CANE); } } else { bm.SetID(x, 63, z, (int)BlockType.STATIONARY_WATER); } } break; } } } int d = RandomHelper.Next(x1 + 1, x1 + xlen - 1); if (curFarm == FarmTypes.Wheat) { bm.SetID(d, 63, z1, (int)BlockType.DOUBLE_SLAB); } if (intWallMaterial != 0) { bm.SetID(d, 64, z1, (int)BlockType.WOOD_DOOR); bm.SetData(d, 64, z1, 4); bm.SetID(d, 65, z1, (int)BlockType.WOOD_DOOR); bm.SetData(d, 65, z1, 4 + (int)DoorState.TOPHALF); } intFail = 0; intFarms++; if (intFarms % 10 == 0) { world.Save(); } } } } MakeMiniPondsAndHills(world, bm, intFarmSize, intMapSize); MakeFlowers(bm, intFarmSize, intMapSize); }
private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ, bool booUniqueBonus) { int[,] intDistrict = new int[intSizeX, intSizeZ]; int[,] intFinal = new int[intSizeX, intSizeZ]; int intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0; int intBonus = 0; List <int> lstBuildings = new List <int>(); List <int> lstAcceptedBuildings = new List <int>(); bool booAreaNeedsMineshaft = false; do { lstBuildings.Clear(); intBonus = 0; if (!_booIncludedMineshaft) { booAreaNeedsMineshaft = true; } do { SourceWorld.Building CurrentBuilding; if (booAreaNeedsMineshaft) { CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.MineshaftEntrance, 0); // mineshaft is always the first building, so therefore it will always be possible to place it booAreaNeedsMineshaft = false; } else { do { CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.City, 0); } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea, intStartX, intStartZ, intSizeX, intSizeZ)); } bool booFound = false; if (RandomHelper.NextDouble() > 0.5) { intDistrict = Utils.RotateArray(intDistrict, RandomHelper.Next(4)); } int x, z = 0; for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSizeX && !booFound; x++) { for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSizeZ && !booFound; z++) { booFound = Utils.IsArraySectionAllZeros2D(intDistrict, x, z, x + CurrentBuilding.intSizeX, z + CurrentBuilding.intSizeZ); } } x--; z--; if (booFound) { for (int a = x + 1; a <= x + CurrentBuilding.intSizeX - 1; a++) { for (int b = z + 1; b <= z + CurrentBuilding.intSizeZ - 1; b++) { intDistrict[a, b] = 2; } } if (CurrentBuilding.booUnique && booUniqueBonus) { // we want to include the unique buildings, // so we give a slight preference to those intBonus += 15; } lstBuildings.Add(CurrentBuilding.intID); intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID; intDistrict[x + CurrentBuilding.intSizeX - 1, z + CurrentBuilding.intSizeZ - 1] = 100 + CurrentBuilding.intID; intFail = 0; } else { intFail++; } } while (intFail < 10); int intCurWasted = Utils.ZerosInArray2D(intDistrict) - intBonus; if (intCurWasted < intWasted) { intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)]; Array.Copy(intDistrict, intFinal, intDistrict.Length); intWasted = intCurWasted; intAttempts = 10; lstAcceptedBuildings.Clear(); lstAcceptedBuildings.AddRange(lstBuildings); } Array.Clear(intDistrict, 0, intDistrict.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = Utils.RotateArray(intFinal, 1); } _lstAllBuildings.AddRange(lstAcceptedBuildings); _booIncludedMineshaft = true; return(intFinal); }
public static void MakeFarms(BetaWorld world, BlockManager bm, frmMace frmLogForm) { if (City.HasFarms) { frmLogForm.UpdateLog("Creating farm buildings", true, true); AddBuildings(bm); frmLogForm.UpdateLog("Creating farms and outside features", true, true); int intFail = 0; int intFarms = 0; while (intFail <= 500) { int xlen = RandomHelper.Next(8, 26); int x1 = RandomHelper.Next(5, City.MapLength - (5 + xlen)); int zlen = RandomHelper.Next(8, 26); int z1 = RandomHelper.Next(5, City.MapLength - (5 + zlen)); if (!(x1 >= City.FarmLength && z1 >= City.FarmLength && x1 <= City.MapLength - City.FarmLength && z1 <= City.MapLength - City.FarmLength)) { 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 == City.MapLength / 2 && z == SpawnZ) || bm.GetID(x, 63, z) != City.GroundBlockID || bm.GetID(x, 64, z) != BlockInfo.Air.ID) { 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 ? BlockInfo.Fence.ID : BlockInfo.Leaves.ID; 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 = BlockInfo.Leaves.ID; break; // no need for default - the other types don't need anything here } #pragma warning disable switch (intWallMaterial) { case BlockType.FENCE: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, BlockInfo.Fence.ID, 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, BlockInfo.Wood.ID, 0, -1); BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, BlockInfo.Leaves.ID, 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; } #pragma warning restore 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) { BlockShapes.MakeBlock(x, 63, z, City.GroundBlockID, City.GroundBlockData); BlockShapes.MakeBlock(x, 64, z, BlockInfo.Sapling.ID, 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) != BlockInfo.Air.ID) { booValidFarm = false; } } } if (booValidFarm) { bm.SetID(xCactus, 64, zCactus, BlockInfo.Cactus.ID); if (RandomHelper.NextDouble() > 0.5) { bm.SetID(xCactus, 65, zCactus, BlockInfo.Cactus.ID); } } }while (++intAttempts < 100); break; case FarmTypes.Wheat: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, BlockInfo.Glass.ID, 0, -1); BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, BlockInfo.Glass.ID, 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, BlockInfo.Sand.ID); break; case FarmTypes.Wheat: if (z == z1 + 1) { bm.SetID(x, 63, z, BlockInfo.DoubleSlab.ID); } else if (x % 2 == 0) { BlockShapes.MakeBlock(x, 63, z, BlockInfo.Farmland.ID, 1); bm.SetID(x, 64, z, BlockInfo.Crops.ID); } else { bm.SetID(x, 63, z, BlockInfo.StationaryWater.ID); } break; case FarmTypes.SugarCane: if (z != z1 + 1) { if (x % 2 == 0) { bm.SetID(x, 64, z, BlockInfo.SugarCane.ID); if (RandomHelper.Next(100) > 50) { bm.SetID(x, 65, z, BlockInfo.SugarCane.ID); } } else { bm.SetID(x, 63, z, BlockInfo.StationaryWater.ID); } } 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, BlockInfo.DoubleSlab.ID); } if (intWallMaterial != 0) { if (curFarm == FarmTypes.Wheat || intWallMaterial == BlockInfo.Leaves.ID) { BlockShapes.MakeBlock(intDoorPosition, 64, z1, BlockInfo.WoodDoor.ID, 4); BlockShapes.MakeBlock(intDoorPosition, 65, z1, BlockInfo.WoodDoor.ID, 4 + (int)DoorState.TOPHALF); } else { bm.SetID(intDoorPosition, 64, z1, BlockInfo.FenceGate.ID); bm.SetData(intDoorPosition, 64, z1, 0); } } intFail = 0; if (++intFarms > 10) { world.Save(); intFarms = 0; } } } } MakeMiniPondsAndHills(world, bm); } if (City.HasFlowers) { MakeFlowers(world, bm); } }
private static void SplitArea(BlockManager bm, int[,] intArea, int x1, int z1, int x2, int z2) { for (int x = x1; x <= x2; x++) { for (int y = z1; y <= z2; y++) { if (x == x1 || x == x2 || y == z1 || y == z2) { if (intArea[x, y] < 500) { intArea[x, y] = 1; } } } } bool booPossibleToSplit = true; bool booSplitByX = false; if (Math.Abs(x1 - x2) > 50 && Math.Abs(z1 - z2) > 50) { booSplitByX = RandomHelper.NextDouble() > 0.5; } else if (Math.Abs(x1 - x2) > 50) { booSplitByX = true; } else if (Math.Abs(z1 - z2) <= 50) { booPossibleToSplit = false; } if (booPossibleToSplit) { if (booSplitByX) { int intSplitPoint = RandomHelper.Next(x1 + 20, x2 - 20); SplitArea(bm, intArea, x1, z1, intSplitPoint, z2); SplitArea(bm, intArea, intSplitPoint, z1, x2, z2); intStreet++; MakeStreetSign(bm, intSplitPoint - 1, z1 + 1, intSplitPoint - 1, z2 - 1); } else { int intSplitPoint = RandomHelper.Next(z1 + 20, z2 - 20); SplitArea(bm, intArea, x1, z1, x2, intSplitPoint); SplitArea(bm, intArea, x1, intSplitPoint, x2, z2); intStreet++; MakeStreetSign(bm, x1 + 1, intSplitPoint - 1, x2 - 1, intSplitPoint - 1); } } else { int[,] intDistrict = FillArea(intArea, (x2 - x1), (z2 - z1), x1, z1); for (int x = 0; x < intDistrict.GetUpperBound(0) - 1; x++) { for (int y = 0; y < intDistrict.GetUpperBound(1) - 1; y++) { intArea[x1 + x + 1, z1 + y + 1] = intDistrict[x + 1, y + 1]; } } } }
public static void MakeMoat(frmMace frmLogForm) { frmLogForm.UpdateLog("Moat type: " + City.MoatType, true, true); switch (City.MoatType) { case "Drop to Bedrock": for (int a = City.FarmLength - 1; a <= City.FarmLength + 5; a++) { BlockShapes.MakeHollowLayers(a, City.MapLength - a, 2, 63, a, City.MapLength - a, BlockInfo.Air.ID, 0, -1); } break; case "Cactus": for (int a = City.FarmLength - 1; a <= City.FarmLength + 5; a++) { BlockShapes.MakeHollowLayers(a, City.MapLength - a, 63, 63, a, City.MapLength - a, BlockInfo.Sand.ID, 0, -1); } for (int a = City.FarmLength + 1; a <= City.MapLength / 2; a += 2) { if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 64, City.FarmLength + 1, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 65, City.FarmLength + 1, BlockInfo.Cactus.ID, 2, 50, -1); } if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 64, City.FarmLength + 3, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 65, City.FarmLength + 3, BlockInfo.Cactus.ID, 2, 50, -1); } } for (int a = City.FarmLength; a <= City.MapLength / 2; a += 2) { if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 64, City.FarmLength, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 65, City.FarmLength, BlockInfo.Cactus.ID, 2, 50, -1); } if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 64, City.FarmLength + 2, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 65, City.FarmLength + 2, BlockInfo.Cactus.ID, 2, 50, -1); } if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 64, City.FarmLength + 4, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 65, City.FarmLength + 4, BlockInfo.Cactus.ID, 2, 50, -1); } } if (City.HasGuardTowers) { for (int a = City.FarmLength + 3; a <= City.FarmLength + 13; a += 2) { BlockShapes.MakeBlock(a, 64, City.FarmLength + 3, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 65, City.FarmLength + 3, BlockInfo.Air.ID, 2, 100, -1); } } break; case "Low Cactus": for (int a = City.FarmLength - 1; a <= City.FarmLength + 5; a++) { BlockShapes.MakeHollowLayers(a, City.MapLength - a, 59, 63, a, City.MapLength - a, BlockInfo.Air.ID, 0, -1); BlockShapes.MakeHollowLayers(a, City.MapLength - a, 58, 58, a, City.MapLength - a, BlockInfo.Sand.ID, 0, -1); } for (int a = City.FarmLength + 1; a <= City.MapLength / 2; a += 2) { if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 59, City.FarmLength + 1, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 60, City.FarmLength + 1, BlockInfo.Cactus.ID, 2, 50, -1); } if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 59, City.FarmLength + 3, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 60, City.FarmLength + 3, BlockInfo.Cactus.ID, 2, 50, -1); } } for (int a = City.FarmLength; a <= City.MapLength / 2; a += 2) { if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 59, City.FarmLength, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 60, City.FarmLength, BlockInfo.Cactus.ID, 2, 50, -1); } if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 59, City.FarmLength + 2, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 60, City.FarmLength + 2, BlockInfo.Cactus.ID, 2, 50, -1); } if (RandomHelper.NextDouble() > 0.5) { BlockShapes.MakeBlock(a, 59, City.FarmLength + 4, BlockInfo.Cactus.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 60, City.FarmLength + 4, BlockInfo.Cactus.ID, 2, 50, -1); } } if (City.HasGuardTowers) { for (int a = City.FarmLength + 3; a <= City.FarmLength + 13; a += 2) { BlockShapes.MakeBlock(a, 59, City.FarmLength + 3, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(a, 60, City.FarmLength + 3, BlockInfo.Air.ID, 2, 100, -1); } } break; case "Lava": for (int a = City.FarmLength - 1; a <= City.FarmLength + 5; a++) { BlockShapes.MakeHollowLayers(a, City.MapLength - a, 55, 56, a, City.MapLength - a, BlockInfo.Lava.ID, 0, -1); BlockShapes.MakeHollowLayers(a, City.MapLength - a, 57, 63, a, City.MapLength - a, BlockInfo.Air.ID, 0, -1); } break; case "Fire": for (int a = City.FarmLength - 1; a <= City.FarmLength + 5; a++) { BlockShapes.MakeHollowLayers(a, City.MapLength - a, 56, 56, a, City.MapLength - a, BlockInfo.Netherrack.ID, 0, -1); BlockShapes.MakeHollowLayers(a, City.MapLength - a, 57, 57, a, City.MapLength - a, BlockInfo.Fire.ID, 0, -1); BlockShapes.MakeHollowLayers(a, City.MapLength - a, 58, 63, a, City.MapLength - a, BlockInfo.Air.ID, 0, -1); } break; case "Water": for (int a = City.FarmLength - 1; a <= City.FarmLength + 5; a++) { BlockShapes.MakeHollowLayers(a, City.MapLength - a, 59, 63, a, City.MapLength - a, BlockInfo.Water.ID, 0, -1); } break; default: Debug.Fail("Invalid switch result"); break; } }