public static string RandomSign() { string strSignText = "*|*|*|*"; switch (rand.Next(9)) { case 0: case 1: case 2: strSignText = RandomHelper.RandomString("I will", "I can", "Will", "Can") + " " + RandomHelper.RandomString("trade", "swap", "sell") + "|" + RandomHelper.RandomString("gold", "iron", "dirt", "glass", "flowers", "cake") + "|for " + RandomHelper.RandomString("obsidian", "wood", "sand", "coal", "stone", "cookies") + "|- " + RandomHelper.RandomString("See", "Talk to") + " " + RandomHelper.RandomLetterUpper() + "." + RandomHelper.RandomLetterUpper() + "."; break; case 3: strSignText = RandomHelper.RandomString("Church", "Order") + " of the" + "|Holy " + RandomHelper.RandomString("Pickaxe", "Notch", "Herobrine", "Creeper", "Chicken", "Squid", "Pigman", "Bucket", "Sword") + "|are meeting" + "|this " + RandomHelper.RandomDay(); break; case 4: strSignText = "Lost pet|creeper. Last|seen near the|mini crater"; break; case 5: strSignText = "Israphel||Wanted dead|or alive"; break; case 6: strSignText = "Lost|Jaffa Cakes.|Please return|to Honeydew"; break; case 7: strSignText = "|Read note " + rand.Next(500, 999) + "||"; break; case 8: strSignText = "|Squids spotted|in the sewers!|"; break; } return(strSignText); }
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, 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."); }
private static string RandomSign() { string strSignText = "*|*|*|*"; int intRand; do { intRand = RandomHelper.Next(booSignUsed.GetLength(0)); } while (intRand >= 5 && booSignUsed[intRand]); booSignUsed[intRand] = true; do { switch (intRand) { case 0: case 1: strSignText = RandomHelper.RandomString("I will", "I can", "Will", "Can") + " " + RandomHelper.RandomString("trade", "swap", "sell") + " " + RandomHelper.RandomString("gold", "iron", "dirt", "glass", "flowers", "cake") + " for " + RandomHelper.RandomString("obsidian", "wood", "sand", "coal", "stone", "cookies") + "~- " + RandomHelper.RandomString("See", "Talk to") + " " + RandomHelper.RandomLetterUpper() + "." + RandomHelper.RandomLetterUpper() + "."; break; case 2: strSignText = RandomHelper.RandomString("Church", "Order") + " of the" + " Holy " + RandomHelper.RandomFileLine(Path.Combine("Resources", "ChurchNoun.txt")) + " are meeting this " + RandomHelper.RandomDay(); break; case 3: strSignText = RandomHelper.RandomString("Mrs", "Miss") + " " + RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt")) + " has lost her " + RandomHelper.RandomString("cat", "dog", "glasses", "marbles") + RandomHelper.RandomString(". Reward offered", ". Please help"); break; case 4: strSignText = RandomHelper.RandomString("Armour", "Property", "House", "Weapons", "Gold", "Bodyguard", "Pet wolf", "Books", "Tools") + " for sale~- " + RandomHelper.RandomString("See", "Talk to") + " " + RandomHelper.RandomLetterUpper() + "." + RandomHelper.RandomLetterUpper() + "."; break; case 5: strSignText = "Lost pet creeper. Last seen near the mini crater"; break; case 6: strSignText = "Israphel~~Wanted dead~or alive"; break; case 7: strSignText = "Lost Jaffa Cakes. Please return to Honeydew"; break; case 8: strSignText = "Read note " + RandomHelper.Next(500, 999); break; case 9: strSignText = "Buy one get one free on gravestones!"; break; case 10: strSignText = "Archery practice this " + RandomHelper.RandomDay() + " afternoon"; break; case 11: strSignText = "Seen a crime? Tell the nearest city guard"; break; case 12: strSignText = "New city law: No minors can be miners"; break; } } while (!IsValidSign(strSignText)); return(strSignText); }
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."); }
// 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 }
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 string RandomValueFromXMLElement(string strFilenameXML, string strParentNode, string strChildNode) { string strValues = ValueFromXMLElement(strFilenameXML, strParentNode, strChildNode); return(RandomHelper.RandomString(strValues.Split(','))); }
public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart, int x1dest, int z1dest, Building bldInsert, int y1dest) { List <Spawner> lstSpawners = new List <Spawner>(); _lstInstanceSigns.Clear(); int intRandomWoolColour = RandomHelper.Next(16); int intSourceX = 0, intSourceZ = 0; int intRotate = -1; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { intRotate = 0; } else { for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++) { for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSizeX; intCheck++) { if (CheckArea(intArea, x1dest + intCheck, z1dest - intDistance) == 1) { intRotate = 0; } else if (CheckArea(intArea, x1dest - intDistance, z1dest + intCheck) == 1) { intRotate = 1; } else if (CheckArea(intArea, x1dest + bldInsert.intSizeX + intDistance, z1dest + intCheck) == 1) { intRotate = 2; } else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSizeZ + intDistance) == 1) { intRotate = 3; } } } } if (intRotate == -1) { intRotate = RandomHelper.Next(4); } for (int x = 0; x < bldInsert.intSizeX; x++) { for (int z = 0; z < bldInsert.intSizeZ; z++) { switch (intRotate) { case 0: intSourceX = x; intSourceZ = z; break; case 1: intSourceX = (bldInsert.intSizeX - 1) - z; intSourceZ = x; break; case 2: intSourceX = z; intSourceZ = (bldInsert.intSizeZ - 1) - x; break; case 3: intSourceX = (bldInsert.intSizeX - 1) - x; intSourceZ = (bldInsert.intSizeZ - 1) - z; break; default: Debug.Fail("Invalid switch result"); break; } int intSourceEndY; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { intSourceEndY = bldInsert.intSourceStartY + 4; } else { for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--) { if (_bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY, intSourceZ + bldInsert.intSourceZ) != BlockType.AIR) { break; } } } for (int ySource = bldInsert.intSourceStartY; ySource <= intSourceEndY; ySource++) { int yDest = ySource; if (bldInsert.btThis == BuildingTypes.MineshaftSection) { yDest = y1dest + (ySource - bldInsert.intSourceStartY); } if (bldInsert.btThis == BuildingTypes.MineshaftSection || ((yDest != 64 || bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) == BlockType.AIR) && bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) != BlockType.WOOD_PLANK)) { int intBlockID = _bmSource.GetID(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); int intBlockData = _bmSource.GetData(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockID); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockData); #region import paintings // todo: test for mineshaft features foreach (EntityPainting entPainting in _AllEntityPainting) { if (entPainting.TileX == intSourceX + bldInsert.intSourceX && entPainting.TileY == ySource && entPainting.TileZ == intSourceZ + bldInsert.intSourceZ) { EntityPainting entNewPainting = (EntityPainting)entPainting.Copy(); entNewPainting.TileX = intBlockStart + x + x1dest; entNewPainting.TileY = yDest; entNewPainting.TileZ = intBlockStart + z + z1dest; entNewPainting.Position.X = entNewPainting.TileX; entNewPainting.Position.Z = entNewPainting.TileZ; entNewPainting.Direction = BlockHelper.RotatePortrait(entPainting.Direction, intRotate); ChunkRef chunkBuilding = _cmDest.GetChunkRef((intBlockStart + x + x1dest) / 16, (intBlockStart + z + z1dest) / 16); chunkBuilding.Entities.Add(entNewPainting); _cmDest.Save(); } } #endregion #region Rotation if (intRotate > 0) { switch (intBlockID) { case BlockType.PORTAL: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotatePortal(intBlockData, intRotate)); break; case BlockType.SIGN_POST: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateSignPost(intBlockData, intRotate)); break; case BlockType.STONE_BUTTON: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateButton(intBlockData, intRotate)); break; case BlockType.PUMPKIN: case BlockType.JACK_O_LANTERN: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotatePumpkin(intBlockData, intRotate)); break; case BlockType.IRON_DOOR: case BlockType.WOOD_DOOR: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateDoor(intBlockData, intRotate)); break; case BlockType.TRAPDOOR: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateTrapdoor(intBlockData, intRotate)); break; case BlockType.BED: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateBed(intBlockData, intRotate)); break; case BlockType.REDSTONE_TORCH_OFF: case BlockType.REDSTONE_TORCH_ON: case BlockType.TORCH: case BlockType.LEVER: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateTorchOrLever(intBlockData, intRotate)); break; case BlockType.WALL_SIGN: case BlockType.LADDER: case BlockType.DISPENSER: case BlockType.FURNACE: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser( intBlockData, intRotate)); break; case BlockType.COBBLESTONE_STAIRS: case BlockType.WOOD_STAIRS: bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockHelper.RotateStairs(intBlockData, intRotate)); break; // no need for a default - all other blocks are okay } } #endregion #region Handle entities switch (intBlockID) { case BlockType.SPONGE: bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.WOOL); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intRandomWoolColour); break; case BlockType.CHEST: TileEntityChest tec = (TileEntityChest)_bmSource.GetTileEntity( intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); if (_booIncludeItemsInChests) { if (tec.Items[0] != null) { if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 3) { tec = MakeHouseChest(); } if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 4) { tec = MakeTreasureChest(); } } } else { tec.Items.ClearAllItems(); } bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tec); break; case BlockType.FURNACE: case BlockType.MONSTER_SPAWNER: case BlockType.NOTE_BLOCK: bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, _bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ)); break; case BlockType.SIGN_POST: case BlockType.WALL_SIGN: #region Determine sign text int intUniqueType = 0; TileEntitySign tes = (TileEntitySign)_bmSource. GetTileEntity(intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ); string strSourceSign = tes.Text1 + " " + tes.Text2 + " " + tes.Text3 + " " + tes.Text4; switch (strSourceSign.Substring(0, 1)) { case "2": case "1": case "0": intUniqueType = Convert.ToInt32(strSourceSign.Substring(0, 1)); strSourceSign = strSourceSign.Remove(0, 1); break; default: intUniqueType = 0; break; } if (tes.Text1.ToLower() == "commentsign" || tes.Text1.ToLower() == "comment sign") { // these exist to give advice to people in the resource world. // so we just remove them from the real world bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0); } if (tes.Text1.ToLower() == "spawner" || tes.Text1.ToLower() == "gspawner") { if (!tes.Text2.ToLower().StartsWith("g") || tes.Text2.ToLower() == "[randomenemy]" || _booIncludeGhostdancerSpawners) { Spawner spawnerCurrent = new Spawner(); if (tes.Text2.ToLower() == "[randomenemy]") { if (_booIncludeGhostdancerSpawners) { spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie", "GGeist", "GGrim"); } else { spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie"); } } else { spawnerCurrent.strEntityID = tes.Text2; } if (tes.Text3.Split(' ').GetUpperBound(0) == 2) { spawnerCurrent.sy = yDest + Convert.ToInt32(tes.Text3.Split(' ')[1]); spawnerCurrent.sx = 0; spawnerCurrent.sz = 0; switch (intRotate) { case 0: spawnerCurrent.sx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text3.Split(' ')[0])); spawnerCurrent.sz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text3.Split(' ')[2])); break; case 1: spawnerCurrent.sx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text3.Split(' ')[2])); spawnerCurrent.sz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0])); break; case 2: spawnerCurrent.sx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2])); spawnerCurrent.sz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text3.Split(' ')[0])); break; case 3: spawnerCurrent.sx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0])); spawnerCurrent.sz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2])); break; } } else { spawnerCurrent.sx = intBlockStart + x + x1dest; spawnerCurrent.sy = yDest - 2; spawnerCurrent.sz = intBlockStart + z + z1dest; } if (tes.Text4.ToLower() == "no") { spawnerCurrent.booGrass = false; } else if (tes.Text4.Split(' ').GetUpperBound(0) == 2) { spawnerCurrent.gy = yDest + Convert.ToInt32(tes.Text4.Split(' ')[1]); switch (intRotate) { case 0: spawnerCurrent.gx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text4.Split(' ')[0])); spawnerCurrent.gz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text4.Split(' ')[2])); break; case 1: spawnerCurrent.gx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2])); spawnerCurrent.gz = intBlockStart + z + z1dest + (Convert.ToInt32(tes.Text4.Split(' ')[0])); break; case 2: spawnerCurrent.gx = intBlockStart + x + x1dest + (Convert.ToInt32(tes.Text4.Split(' ')[2])); spawnerCurrent.gz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0])); break; case 3: spawnerCurrent.gx = intBlockStart + x + x1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0])); spawnerCurrent.gz = intBlockStart + z + z1dest + (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2])); break; } spawnerCurrent.booGrass = true; } else { spawnerCurrent.gx = intBlockStart + x + x1dest; spawnerCurrent.gy = yDest - 1; spawnerCurrent.gz = intBlockStart + z + z1dest; spawnerCurrent.booGrass = true; } lstSpawners.Add(spawnerCurrent); } bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR); bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0); } else if (strSourceSign.Contains("[")) { string strSignText; bool booDuplicate; int intFail = 0; do { strSignText = SignText(strSourceSign); booDuplicate = false; switch (intUniqueType) { case 1: // unique by instance booDuplicate = _lstInstanceSigns.Contains(strSignText); break; case 2: // unique by city booDuplicate = _lstCitySigns.Contains(strSignText); break; } if (++intFail > 100) { Debug.WriteLine("Could not make a unique sign for " + strSourceSign); booDuplicate = false; } } while (booDuplicate); _lstCitySigns.Add(strSignText); _lstInstanceSigns.Add(strSignText); string[] strRandomSign = Utils.TextToSign(Utils.ConvertStringToSignText(strSignText)); tes.Text1 = strRandomSign[0]; tes.Text2 = strRandomSign[1]; tes.Text3 = strRandomSign[2]; tes.Text4 = strRandomSign[3]; bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes); } else { bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes); } break; #endregion // no need for a default - all the other blocks are okay } #endregion } } } } foreach (Spawner spnAdd in lstSpawners) { bmDest.SetID(spnAdd.sx, spnAdd.sy, spnAdd.sz, BlockType.MONSTER_SPAWNER); TileEntityMobSpawner tems = new TileEntityMobSpawner(); tems.EntityID = spnAdd.strEntityID; bmDest.SetTileEntity(spnAdd.sx, spnAdd.sy, spnAdd.sz, tems); if (spnAdd.booGrass) { bmDest.SetID(spnAdd.gx, spnAdd.gy, spnAdd.gz, BlockType.GRASS); } } }
private static void MakeEmblem(int intFarmSize, int intMapSize, string strCityEmblem) { if (strCityEmblem == "Random") { strCityEmblem = RandomHelper.RandomString("Cross", "England Flag", "Pride Flag", "Shield", "Yin and Yang"); } switch (strCityEmblem) { case "None": break; case "Cross": int intCrossBlock = (int)BlockType.IRON_BLOCK; switch (rand.Next(3)) { case 0: intCrossBlock = (int)BlockType.IRON_BLOCK; break; case 1: intCrossBlock = (int)BlockType.GOLD_BLOCK; break; case 2: intCrossBlock = (int)BlockType.DIAMOND_BLOCK; break; } for (int y = 64; y <= 71; y++) { BlockShapes.MakeBlock((intMapSize / 2) - 8, y, intFarmSize + 5, intCrossBlock, 2); BlockShapes.MakeBlock((intMapSize / 2) - 7, y, intFarmSize + 5, intCrossBlock, 2); } for (int x = (intMapSize / 2) - 10; x <= (intMapSize / 2) - 5; x++) { BlockShapes.MakeBlock(x, 69, intFarmSize + 5, intCrossBlock, 2); BlockShapes.MakeBlock(x, 68, intFarmSize + 5, intCrossBlock, 2); } break; case "England Flag": for (int x = (intMapSize / 2) - 11; x <= (intMapSize / 2) - 5; x++) { for (int y = 66; y <= 70; y++) { int intBlockData = (int)WoolColor.WHITE; if (y == 68 || x == (intMapSize / 2) - 8) { intBlockData = (int)WoolColor.RED; } BlockShapes.MakeBlock(x, y, intFarmSize + 5, (int)BlockType.WOOL, 2, 100, intBlockData); } } break; case "Pride Flag": for (int y = 66; y <= 71; y++) { int intWoolID = 0; switch (y) { case 71: intWoolID = (int)WoolColor.RED; break; case 70: intWoolID = (int)WoolColor.ORANGE; break; case 69: intWoolID = (int)WoolColor.YELLOW; break; case 68: intWoolID = (int)WoolColor.LIGHT_GREEN; break; case 67: intWoolID = (int)WoolColor.BLUE; break; case 66: intWoolID = (int)WoolColor.PURPLE; break; } for (int x = (intMapSize / 2) - 13; x <= (intMapSize / 2) - 5; x++) { BlockShapes.MakeBlock(x, y, intFarmSize + 5, (int)BlockType.WOOL, 2, 100, intWoolID); } } break; case "Shield": for (int x = (intMapSize / 2) - 10; x <= (intMapSize / 2) - 6; x++) { for (int y = 66; y <= 70; y++) { if (x == (intMapSize / 2) - 8 || y == 68) { BlockShapes.MakeBlock(x, y, intFarmSize + 5, (int)BlockType.GOLD_BLOCK, 2); } else if ((y >= 69 && x >= (intMapSize / 2) - 7) || (y <= 67 && x <= (intMapSize / 2) - 8)) { BlockShapes.MakeBlock(x, y, intFarmSize + 5, (int)BlockType.DIAMOND_BLOCK, 2); } else { BlockShapes.MakeBlock(x, y, intFarmSize + 5, (int)BlockType.IRON_BLOCK, 2); } } } BlockShapes.MakeBlock((intMapSize / 2) - 8, 65, intFarmSize + 5, (int)BlockType.GOLD_BLOCK, 2); BlockShapes.MakeBlock((intMapSize / 2) - 10, 66, intFarmSize + 5, (int)BlockType.AIR, 2); BlockShapes.MakeBlock((intMapSize / 2) - 6, 66, intFarmSize + 5, (int)BlockType.AIR, 2); break; case "Yin and Yang": string[] strYinYang = { " WWWB ", "WWBWBB", "WWWWBB", "WWBBBB", "WWBWBB", " WBBB " }; for (int y = 0; y <= 5; y++) { for (int z = 0; z <= 5; z++) { switch (strYinYang[y][z]) { case 'W': BlockShapes.MakeBlock(((intMapSize / 2) - 10) + z, 70 - y, intFarmSize + 5, (int)BlockType.WOOL, 2, 100, (int)WoolColor.WHITE); break; case 'B': BlockShapes.MakeBlock(((intMapSize / 2) - 10) + z, 70 - y, intFarmSize + 5, (int)BlockType.WOOL, 2, 100, (int)WoolColor.BLACK); break; } } } break; } }