public void Generate(frmMace frmLogForm, 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) { #region create minecraft world directory from a random unused city name string strFolder = "", strCityName = ""; do { strCityName = "City of " + RandomHelper.RandomFileLine("Resources\\CityStartingWords.txt") + RandomHelper.RandomFileLine("Resources\\CityEndingWords.txt"); strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\"; } while (Directory.Exists(strFolder)); Directory.CreateDirectory(strFolder); #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 Random rand = new Random(); #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = rand.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(); #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); // todo: test excluding paths/buildings 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); } 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 default //world.Level.SpawnX = 0; //world.Level.SpawnY = 65; //world.Level.SpawnZ = 0; worldDest.Level.LevelName = strCityName; worldDest.Level.Time = rand.Next(24000); if (rand.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = rand.Next(6000, 18000); if (rand.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."); }
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."); }
public void Generate(frmMace frmLogForm, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard, bool booIncludeBuildings, bool booIncludeSewers, string strCitySize, string strMoatLiquid) { string strFolder, strCityName; do { strCityName = "City of " + RandomHelper.RandomFileLine("CityStartingWords.txt") + RandomHelper.RandomFileLine("CityEndingWords.txt"); strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\"; } while (Directory.Exists(strFolder)); Directory.CreateDirectory(strFolder); BetaWorld world = BetaWorld.Create(@strFolder); int intFarmSize = 28; if (!booIncludeFarms) { intFarmSize = 2; } int intPlotSize = 12; int intPlots = 15; Random rand = new Random(); switch (strCitySize) { case "Random": intPlots = rand.Next(10, 20); break; case "Very small": intPlots = 6; break; case "Small": intPlots = 10; break; case "Medium": intPlots = 15; break; case "Large": intPlots = 20; break; case "Very large": intPlots = 23; break; default: Debug.Assert(false); break; } int intMapSize = (intPlots * intPlotSize) + (intFarmSize * 2); ChunkManager cm = world.GetChunkManager(); frmLogForm.UpdateLog("Creating chunks"); Chunks.MakeChunks(cm, -1, 2 + (intMapSize / 16), frmLogForm); frmLogForm.UpdateProgress(34); BlockManager bm = world.GetBlockManager(); bm.AutoLight = false; BlockShapes.SetupClass(bm, intMapSize); BlockHelper.SetupClass(bm, intMapSize); bool[,] booSewerEntrances; if (booIncludeSewers) { frmLogForm.UpdateLog("Creating sewers"); booSewerEntrances = Sewers.MakeSewers(intFarmSize, intMapSize, intPlotSize); } else { booSewerEntrances = new bool[2 + ((intMapSize - ((intFarmSize + 16) * 2)) / intPlotSize), 2 + ((intMapSize - ((intFarmSize + 16) * 2)) / intPlotSize)]; } frmLogForm.UpdateProgress(35); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating plots"); Plots.MakeBuildings(bm, booSewerEntrances, intFarmSize, intMapSize, intPlotSize); } frmLogForm.UpdateProgress(36); if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(intFarmSize, intMapSize); } frmLogForm.UpdateProgress(37); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmSize, intMapSize, strMoatLiquid); } frmLogForm.UpdateProgress(38); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bm, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls); } frmLogForm.UpdateProgress(39); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bm, intFarmSize, intMapSize, booIncludeWalls); } frmLogForm.UpdateProgress(40); if (booIncludeWalls && booIncludeNoticeboard) { frmLogForm.UpdateLog("Creating noticeboard"); NoticeBoard.MakeNoticeBoard(bm, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(41); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(bm, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(42); world.Level.LevelName = strCityName; // 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 world.Level.SpawnX = intMapSize / 2; world.Level.SpawnZ = intMapSize - 21; world.Level.SpawnY = 64; if (rand.NextDouble() < 0.1) { world.Level.IsRaining = true; if (rand.NextDouble() < 0.25) { world.Level.IsThundering = true; } } //MakeHelperChest(bm, world.Level.SpawnX + 2, world.Level.SpawnY, world.Level.SpawnZ + 2); frmLogForm.UpdateLog("Resetting lighting"); Chunks.ResetLighting(cm, frmLogForm, (int)Math.Pow(3 + (intMapSize / 16), 2)); world.Save(); 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 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."); }
public static void Generate(frmMace frmLogForm, BetaWorld worldDest, BetaChunkManager cmDest, BlockManager bmDest, int x, int z) { #region create a city name string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine(Path.Combine("Resources", City.CityNamePrefixFilename)); strEnd = RandomHelper.RandomFileLine(Path.Combine("Resources", City.CityNameSuffixFilename)); City.Name = "City of " + strStart + strEnd; } while (GenerateWorld.lstCityNames.Contains(City.Name) || strStart.ToLower().Trim() == strEnd.ToLower().Trim() || (strStart + strEnd).Length > 14); GenerateWorld.lstCityNames.Add(City.Name); #endregion #region determine block sizes City.CityLength *= 16; // chunk length City.FarmLength = City.HasFarms ? 32 : 8; City.MapLength = City.CityLength + (City.FarmLength * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest); BlockHelper.SetupClass(bmDest); NoticeBoard.SetupClass(); if (!SourceWorld.SetupClass(worldDest)) { return; } #endregion #region determine random options #pragma warning disable switch (City.WallMaterialID) { case BlockType.WOOD_PLANK: case BlockType.WOOD: case BlockType.LEAVES: case BlockType.VINES: case BlockType.WOOL: case BlockType.BOOKSHELF: switch (City.OutsideLightType) { case "Fire": frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true); City.OutsideLightType = "Torches"; break; } switch (City.MoatType) { case "Fire": case "Lava": frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true); City.MoatType = "Water"; break; } break; } #pragma warning restore #endregion #region make the city frmLogForm.UpdateLog("Creating the " + City.Name, false, false); frmLogForm.UpdateLog("City length in blocks: " + City.MapLength, true, true); frmLogForm.UpdateLog("City position in blocks: " + ((x + 30) * 16) + "," + ((z + 30) * 16), true, true); frmLogForm.UpdateLog("Theme: " + City.ThemeName, true, true); frmLogForm.UpdateLog("Creating underground terrain", true, false); Chunks.CreateInitialChunks(cmDest, frmLogForm); frmLogForm.UpdateProgress(0.35); Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint(); if (City.HasWalls) { frmLogForm.UpdateLog("Creating walls", true, false); Walls.MakeWalls(worldDest, frmLogForm); } frmLogForm.UpdateProgress(0.45); if (City.HasBuildings || City.HasPaths) { frmLogForm.UpdateLog("Creating paths", true, false); int[,] intArea = Paths.MakePaths(worldDest, bmDest); frmLogForm.UpdateProgress(0.50); if (City.HasBuildings) { frmLogForm.UpdateLog("Creating buildings", true, false); spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, frmLogForm); frmLogForm.UpdateProgress(0.55); if (City.HasMineshaft) { frmLogForm.UpdateLog("Creating mineshaft", true, false); Mineshaft.MakeMineshaft(worldDest, bmDest, spMineshaftEntrance, frmLogForm); } } } frmLogForm.UpdateProgress(0.60); if (City.HasMoat) { frmLogForm.UpdateLog("Creating moat", true, false); Moat.MakeMoat(frmLogForm); } frmLogForm.UpdateProgress(0.65); if (City.HasDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges", true, false); Drawbridge.MakeDrawbridges(bmDest); } frmLogForm.UpdateProgress(0.70); if (City.HasGuardTowers) { frmLogForm.UpdateLog("Creating guard towers", true, false); GuardTowers.MakeGuardTowers(bmDest, frmLogForm); } frmLogForm.UpdateProgress(0.75); if (City.HasFarms) { frmLogForm.UpdateLog("Creating farms", true, false); Farms.MakeFarms(worldDest, bmDest, frmLogForm); } frmLogForm.UpdateProgress(0.80); if (!City.HasValuableBlocks) { frmLogForm.UpdateLog("Replacing valuable blocks", true, true); cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest); } frmLogForm.UpdateProgress(0.90); frmLogForm.UpdateLog("Creating rail data", true, false); Chunks.PositionRails(worldDest, bmDest); frmLogForm.UpdateProgress(0.95); frmLogForm.UpdateLog("Creating position data", true, false); Chunks.MoveChunks(worldDest, cmDest, x, z); frmLogForm.UpdateProgress(1); #endregion }