static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed, string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes, int ChunksBetweenCities, string strSpawnPoint, bool booExportSchematics, string strSelectedNPCs, string strUndergroundOres) { frmLogForm.UpdateLog("Started at " + DateTime.Now.ToLocalTime(), false, true); worldCities = new WorldCity[TotalCities]; lstCityNames.Clear(); Chunks.biomes.Clear(); RNG.SetRandomSeed(); #region create minecraft world directory from a random unused world name string strFolder = String.Empty, strWorldName = String.Empty; UserWorldName = UserWorldName.ToSafeFilename(); if (UserWorldName.Trim().Length == 0) { UserWorldName = "random"; } if (UserWorldName.ToLower().Trim() != "random") { if (Directory.Exists(UserWorldName.ToMinecraftSaveDirectory())) { 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 = strWorldName.ToMinecraftSaveDirectory(); } } if (strWorldName.Length == 0) { strWorldName = Utils.GenerateWorldName(); strFolder = strWorldName.ToMinecraftSaveDirectory(); } Directory.CreateDirectory(strFolder); frmLogForm.btnSaveLogNormal.Tag = Path.Combine(strFolder, "LogNormal.txt"); frmLogForm.btnSaveLogVerbose.Tag = Path.Combine(strFolder, "LogVerbose.txt"); frmLogForm.UpdateLog("World name: " + strWorldName, false, true); #endregion #region get handles to world, chunk manager and block manager AnvilWorld worldDest = AnvilWorld.Create(@strFolder); worldDest.Level.LevelName = "Creating. Don't open until Mace is finished."; RegionChunkManager 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 int maxFarmSize = 0; strCheckedThemes = RNG.ShuffleArray(strCheckedThemes); for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++) { if (CurrentCityID <= strCheckedThemes.GetUpperBound(0)) { worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID]; } else { worldCities[CurrentCityID].ThemeName = RNG.RandomItem(strCheckedThemes); } City.themeName = worldCities[CurrentCityID].ThemeName; worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size"); int farmSize = GetThemeLastXMLElementNumber("options", "farm_size"); maxFarmSize = Math.Max(maxFarmSize, farmSize); } #endregion GenerateCityLocations(TotalCities, ChunksBetweenCities + maxFarmSize); int intRandomCity = RNG.Next(TotalCities); for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++) { MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID, strSelectedNPCs); if (!GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z, booExportSchematics, strUndergroundOres)) { frmLogForm.UpdateLog("World generation failed/cancelled.", false, false); return; } #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 + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2), 65, ((worldCities[intRandomCity].z + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2)); break; case "Outside a random city": worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2), 65, ((worldCities[intRandomCity].z + Chunks.CITY_RELOCATION_CHUNKS) * 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 } #region weather frmLogForm.UpdateLog("Setting weather", false, true); worldDest.Level.Time = RNG.Next(24000); if (RNG.NextDouble() < 0.15) { frmLogForm.UpdateLog("Rain", false, true); worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RNG.Next(6000, 18000); if (RNG.NextDouble() < 0.25) { frmLogForm.UpdateLog("Thunder", false, true); worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #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.Hardcore = 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) { long seed = 0; if (long.TryParse(strWorldSeed, out seed)) { worldDest.Level.RandomSeed = seed; frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true); } else { worldDest.Level.RandomSeed = strWorldSeed.ToJavaHashCode(); frmLogForm.UpdateLog("Specified world seed: " + strWorldSeed, false, true); frmLogForm.UpdateLog("Specified world seed converted to a number: " + worldDest.Level.RandomSeed, false, true); } } else { worldDest.Level.RandomSeed = RNG.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 cmDest.Save(); worldDest.Save(); Chunks.SetBiomeData(@strFolder); frmLogForm.UpdateLog("\nCreated the " + strWorldName + "!", false, false); frmLogForm.UpdateLog("It'll be at the top of your MineCraft world list.", false, false); frmLogForm.UpdateLog("Finished at " + DateTime.Now.ToLocalTime(), false, true); }
public static void MakeGuardTowers(BlockManager bm, frmMace frmLogForm) { // remove wall BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 11, 64, 79, City.EdgeLength + 5, City.EdgeLength + 11, BlockInfo.Air.ID, 1); // add tower BlockShapes.MakeHollowBox(City.EdgeLength + 4, City.EdgeLength + 12, 63, 80, City.EdgeLength + 4, City.EdgeLength + 12, City.WallMaterialID, 1, City.WallMaterialData); // divide into two rooms BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 4, City.EdgeLength + 12, 2, 72, City.EdgeLength + 4, City.EdgeLength + 12, City.WallMaterialID, 1, City.WallMaterialData); BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 11, 64, 67, City.EdgeLength + 5, City.EdgeLength + 11, BlockInfo.Air.ID, 1); switch (City.OutsideLightType) { case "Fire": BlockShapes.MakeBlock(City.EdgeLength + 5, 76, City.EdgeLength + 3, BlockInfo.Netherrack.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 5, 77, City.EdgeLength + 3, BlockInfo.Fire.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 76, City.EdgeLength + 3, BlockInfo.Netherrack.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 77, City.EdgeLength + 3, BlockInfo.Fire.ID, 2, 100, -1); break; case "Torches": for (int y = 73; y <= 80; y += 7) { BlockHelper.MakeTorch(City.EdgeLength + 6, y, City.EdgeLength + 3, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.EdgeLength + 10, y, City.EdgeLength + 3, City.WallMaterialID, 2); } break; case "None": case "": break; default: Debug.Fail("Invalid switch result"); break; } if (City.HasTorchesOnWalkways) { // add torches BlockHelper.MakeTorch(City.EdgeLength + 6, 79, City.EdgeLength + 13, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.EdgeLength + 10, 79, City.EdgeLength + 13, City.WallMaterialID, 2); // add torches inside BlockHelper.MakeTorch(City.EdgeLength + 6, 77, City.EdgeLength + 11, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.EdgeLength + 10, 77, City.EdgeLength + 11, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.EdgeLength + 5, 77, City.EdgeLength + 6, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.EdgeLength + 5, 77, City.EdgeLength + 10, City.WallMaterialID, 2); } // add openings to the walls BlockShapes.MakeBlock(City.EdgeLength + 7, 73, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 9, 73, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 7, 74, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 9, 74, City.EdgeLength + 12, BlockInfo.Air.ID, 2, 100, -1); // add blocks on top of the towers BlockShapes.MakeHollowLayers(City.EdgeLength + 4, City.EdgeLength + 12, 81, 81, City.EdgeLength + 4, City.EdgeLength + 12, City.WallMaterialID, 1, City.WallMaterialData); // alternating top blocks for (int x = City.EdgeLength + 4; x <= City.EdgeLength + 12; x += 2) { for (int z = City.EdgeLength + 4; z <= City.EdgeLength + 12; z += 2) { if (x == City.EdgeLength + 4 || x == City.EdgeLength + 12 || z == City.EdgeLength + 4 || z == City.EdgeLength + 12) { BlockShapes.MakeBlock(x, 82, z, City.WallMaterialID, 1, 100, City.WallMaterialData); } } } // add central columns BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 8, City.EdgeLength + 8, 73, 82, City.EdgeLength + 8, City.EdgeLength + 8, City.WallMaterialID, 1, City.WallMaterialData); BlockHelper.MakeLadder(City.EdgeLength + 7, 73, 82, City.EdgeLength + 8, 2, City.WallMaterialID); BlockHelper.MakeLadder(City.EdgeLength + 9, 73, 82, City.EdgeLength + 8, 2, City.WallMaterialID); // add torches on the roof if (City.HasTorchesOnWalkways) { BlockShapes.MakeBlock(City.EdgeLength + 6, 81, City.EdgeLength + 6, BlockInfo.Torch.ID, 1, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 6, 81, City.EdgeLength + 10, BlockInfo.Torch.ID, 2, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 10, 81, City.EdgeLength + 10, BlockInfo.Torch.ID, 1, 100, -1); } // add cobwebs BlockShapes.MakeBlock(City.EdgeLength + 5, 79, City.EdgeLength + 5, BlockInfo.Cobweb.ID, 1, 30, -1); BlockShapes.MakeBlock(City.EdgeLength + 5, 79, City.EdgeLength + 11, BlockInfo.Cobweb.ID, 1, 30, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 79, City.EdgeLength + 5, BlockInfo.Cobweb.ID, 1, 30, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 79, City.EdgeLength + 11, BlockInfo.Cobweb.ID, 1, 30, -1); // add chests MakeGuardChest(bm, City.EdgeLength + 11, 73, City.EdgeLength + 11); MakeGuardChest(bm, City.MapLength - (City.EdgeLength + 11), 73, City.EdgeLength + 11); MakeGuardChest(bm, City.EdgeLength + 11, 73, City.MapLength - (City.EdgeLength + 11)); MakeGuardChest(bm, City.MapLength - (City.EdgeLength + 11), 73, City.MapLength - (City.EdgeLength + 11)); // add archery slots BlockShapes.MakeSolidBox(City.EdgeLength + 4, City.EdgeLength + 4, 74, 77, City.EdgeLength + 8, City.EdgeLength + 8, BlockInfo.Air.ID, 2); BlockShapes.MakeSolidBox(City.EdgeLength + 4, City.EdgeLength + 4, 76, 76, City.EdgeLength + 7, City.EdgeLength + 9, BlockInfo.Air.ID, 2); if (!City.HasWalls) { BlockHelper.MakeLadder(City.EdgeLength + 13, 64, 72, City.EdgeLength + 8, 2, City.WallMaterialID); } // include beds BlockHelper.MakeBed(City.EdgeLength + 5, City.EdgeLength + 6, 64, City.EdgeLength + 8, City.EdgeLength + 8, 2); BlockHelper.MakeBed(City.EdgeLength + 5, City.EdgeLength + 6, 64, City.EdgeLength + 10, City.EdgeLength + 10, 2); BlockHelper.MakeBed(City.EdgeLength + 11, City.EdgeLength + 10, 64, City.EdgeLength + 8, City.EdgeLength + 8, 2); // make columns to orientate torches BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 5, 64, 73, City.EdgeLength + 5, City.EdgeLength + 5, BlockInfo.Wood.ID, 2); BlockShapes.MakeSolidBox(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71, City.EdgeLength + 5, City.EdgeLength + 5, BlockInfo.Wood.ID, 2); BlockShapes.MakeSolidBox(City.EdgeLength + 5, City.EdgeLength + 5, 64, 71, City.EdgeLength + 11, City.EdgeLength + 11, BlockInfo.Wood.ID, 2); BlockShapes.MakeSolidBox(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71, City.EdgeLength + 11, City.EdgeLength + 11, BlockInfo.Wood.ID, 2); // add ladders BlockHelper.MakeLadder(City.EdgeLength + 5, 64, 73, City.EdgeLength + 6, 2, BlockInfo.Wood.ID); // make torches if (City.HasTorchesOnWalkways) { BlockHelper.MakeTorch(City.EdgeLength + 10, 66, City.EdgeLength + 5, BlockInfo.Wood.ID, 2); BlockHelper.MakeTorch(City.EdgeLength + 6, 66, City.EdgeLength + 11, BlockInfo.Wood.ID, 2); BlockHelper.MakeTorch(City.EdgeLength + 10, 66, City.EdgeLength + 11, BlockInfo.Wood.ID, 2); } // make columns for real BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 5, City.EdgeLength + 5, 64, 73, City.EdgeLength + 5, City.EdgeLength + 5, City.WallMaterialID, 2, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71, City.EdgeLength + 5, City.EdgeLength + 5, City.WallMaterialID, 2, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 5, City.EdgeLength + 5, 64, 71, City.EdgeLength + 11, City.EdgeLength + 11, City.WallMaterialID, 2, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 11, City.EdgeLength + 11, 64, 71, City.EdgeLength + 11, City.EdgeLength + 11, City.WallMaterialID, 2, City.WallMaterialData); // make cobwebs BlockShapes.MakeBlock(City.EdgeLength + 11, 67, City.EdgeLength + 8, BlockInfo.Cobweb.ID, 2, 75, -1); // make doors from the city to the guard tower BlockShapes.MakeBlock(City.EdgeLength + 11, 65, City.EdgeLength + 11, BlockInfo.GoldBlock.ID, 1, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 11, BlockInfo.GoldBlock.ID, 1, 100, -1); BlockHelper.MakeDoor(City.EdgeLength + 11, 64, City.EdgeLength + 12, BlockInfo.GoldBlock.ID, true, 2); BlockShapes.MakeBlock(City.EdgeLength + 11, 65, City.EdgeLength + 11, BlockInfo.Air.ID, 1, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 11, BlockInfo.Air.ID, 1, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 11, BlockInfo.StonePlate.ID, 1, 100, -1); BlockShapes.MakeBlock(City.EdgeLength + 11, 64, City.EdgeLength + 13, BlockInfo.StonePlate.ID, 2, 100, -1); //BlockShapes.MakeBlock(City.intFarmSize + 13, 64, City.intFarmSize + 11, BlockInfo.Stone.ID_PLATE, 1, 100, -1); // add guard tower sign BlockHelper.MakeSign(City.EdgeLength + 12, 65, City.EdgeLength + 13, "~Guard Tower~~", City.WallMaterialID, 1); BlockHelper.MakeSign(City.EdgeLength + 8, 74, City.EdgeLength + 13, "~Guard Tower~~", City.WallMaterialID, 2); // make beacon frmLogForm.UpdateLog("Creating tower addition: " + City.TowersAdditionType, true, true); switch (City.TowersAdditionType) { case "Fire beacon": BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 8, City.EdgeLength + 8, 83, 84, City.EdgeLength + 8, City.EdgeLength + 8, City.WallMaterialID, 1, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 6, City.EdgeLength + 10, 85, 85, City.EdgeLength + 6, City.EdgeLength + 10, City.WallMaterialID, 1, City.WallMaterialData); BlockShapes.MakeSolidBox(City.EdgeLength + 6, City.EdgeLength + 10, 86, 86, City.EdgeLength + 6, City.EdgeLength + 10, BlockInfo.Netherrack.ID, 1); BlockShapes.MakeSolidBox(City.EdgeLength + 6, City.EdgeLength + 10, 87, 87, City.EdgeLength + 6, City.EdgeLength + 10, BlockInfo.Fire.ID, 1); break; case "Flag": BlockShapes.MakeSolidBox(City.EdgeLength + 4, City.EdgeLength + 4, 83, 91, City.EdgeLength + 12, City.EdgeLength + 12, BlockInfo.Fence.ID, 2); BlockShapes.MakeBlock(City.EdgeLength + 4, 84, City.EdgeLength + 13, BlockInfo.Fence.ID, 2, 100, 0); BlockShapes.MakeBlock(City.EdgeLength + 4, 91, City.EdgeLength + 13, BlockInfo.Fence.ID, 2, 100, 0); int[] intColours = RNG.ShuffleArray(Enumerable.Range(0, 15).ToArray()); // select a random flag file and turn it into an array string[] strFlagLines = File.ReadAllLines(RNG.RandomItemFromArray(Directory.GetFiles("Resources", "Flag_*.txt"))); for (int x = 0; x < strFlagLines[0].Length; x++) { for (int y = 0; y < strFlagLines.GetLength(0); y++) { int WoolColourID = Convert.ToInt32(strFlagLines[y].Substring(x, 1)); BlockShapes.MakeSolidBoxWithData(City.EdgeLength + 4, City.EdgeLength + 4, 90 - y, 90 - y, City.EdgeLength + 13 + x, City.EdgeLength + 13 + x, BlockInfo.Wool.ID, 2, intColours[WoolColourID]); } } break; } }