private static void AddBuilding(BlockManager bm, int intFarmSize, int intMapSize, string strBuildingName) { SourceWorld.Building bldInsert = SourceWorld.GetBuilding(strBuildingName); int intLen = bldInsert.intSize; int intBuildingsToAdd = Math.Max(1, (intMapSize / 16) / 6); bool booValid; do { booValid = false; int x1 = RandomHelper.Next(2, intMapSize - (2 + intLen)); int z1 = RandomHelper.Next(2, intMapSize - (2 + intLen)); if (!(x1 >= intFarmSize && z1 >= intFarmSize && x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize)) { booValid = true; for (int x = x1 - 2; x <= x1 + intLen + 2 && booValid; x++) { for (int z = z1 - 2; z <= z1 + intLen + 2 && booValid; z++) { // make sure it doesn't overlap with the spawn point or another farm if ((x == intMapSize / 2 && z == intMapSize - (intFarmSize - 10)) || bm.GetID(x, 63, z) != (int)BlockType.GRASS || bm.GetID(x, 64, z) != (int)BlockType.AIR || bm.GetID(x, 53, z) == (int)BlockType.AIR) { booValid = false; } } } } if (booValid) { SourceWorld.InsertBuilding(bm, new int[intMapSize, intMapSize], 0, x1, z1, bldInsert); intBuildingsToAdd--; } } while (intBuildingsToAdd > 0); }
private static TileEntityChest MakeTreasureChest() { TileEntityChest tec = new TileEntityChest(); for (int intItems = RandomHelper.Next(5, 7); intItems >= 2; intItems--) { tec.Items[intItems] = BlockHelper.MakeItem(RandomHelper.RandomNumber( ItemInfo.GoldenApple.ID, ItemInfo.GoldIngot.ID, ItemInfo.Diamond.ID, ItemInfo.GoldMusicDisc.ID, ItemInfo.GreenMusicDisc.ID, ItemInfo.IronIngot.ID, ItemInfo.Saddle.ID, ItemInfo.Compass.ID, ItemInfo.Clock.ID, ItemInfo.Cake.ID, ItemInfo.Cookie.ID ), 1); } tec.Items[0] = BlockHelper.MakeItem(ItemInfo.GetRandomItem().ID, 1); tec.Items[1] = BlockHelper.MakeItem(ItemInfo.GetRandomItem().ID, 1); return(tec); }
private static void MakeGuardChest(BlockManager bm, int x, int y, int z, bool booIncludeItemsInChests) { TileEntityChest tec = new TileEntityChest(); if (booIncludeItemsInChests) { for (int a = 0; a < 5; a++) { tec.Items[a] = BlockHelper.MakeItem(RandomHelper.RandomNumber(ItemInfo.IronSword.ID, ItemInfo.WoodenSword.ID, ItemInfo.StoneSword.ID), 1); } tec.Items[6] = BlockHelper.MakeItem(ItemInfo.Bow.ID, 1); tec.Items[7] = BlockHelper.MakeItem(ItemInfo.Arrow.ID, 64); int intArmourStartID = RandomHelper.RandomNumber(ItemInfo.LeatherCap.ID, ItemInfo.ChainHelmet.ID, ItemInfo.IronHelmet.ID); for (int a = 9; a < 18; a++) { tec.Items[a] = BlockHelper.MakeItem(intArmourStartID + RandomHelper.Next(4), 1); // random armour } } bm.SetID(x, y, z, (int)BlockType.CHEST); bm.SetTileEntity(x, y, z, tec); }
private static int[, ,] AddResources(int[, ,] intEnlargedArea, int Y, frmMace frmLogForm) { int X, Z; int intResources = (int)(City.MapLength * Y * City.MapLength * 0.005); frmLogForm.UpdateLog("Adding resource patches: " + intResources, true, true); do { X = RandomHelper.Next(1, intEnlargedArea.GetLength(0) - 1); Y = RandomHelper.Next(1, intEnlargedArea.GetLength(1) - 1); Z = RandomHelper.Next(1, intEnlargedArea.GetLength(2) - 1); if (intEnlargedArea[X, Y, Z] == BlockInfo.Stone.ID) { double dblDepth = (double)Y / intEnlargedArea.GetLength(1); // this increases ore frequency as we get lower if (dblDepth < RandomHelper.NextDouble() * 1.5) { intEnlargedArea[X, Y, Z] = SelectRandomResource(dblDepth); intResources--; } } } while (intResources > 0); return(intEnlargedArea); }
private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ) { int[,] intDistrict = new int[intSizeX, intSizeZ]; int[,] intFinal = new int[intSizeX, intSizeZ]; int intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0; int intBonus = 0; List <int> lstBuildings = new List <int>(); List <int> lstAcceptedBuildings = new List <int>(); do { lstBuildings.Clear(); intBonus = 0; do { SourceWorld.Building CurrentBuilding; do { CurrentBuilding = SourceWorld.SelectRandomBuilding(); } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea, intStartX, intStartZ, intSizeX, intSizeZ)); bool booFound = false; if (RandomHelper.NextDouble() > 0.5) { intDistrict = RotateArray(intDistrict, RandomHelper.Next(4)); } int x, z = 0; for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSize && !booFound; x++) { for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSize && !booFound; z++) { booFound = IsFree(intDistrict, x, z, x + CurrentBuilding.intSize, z + CurrentBuilding.intSize); } } x--; z--; if (booFound) { for (int a = x + 1; a <= x + CurrentBuilding.intSize - 1; a++) { for (int b = z + 1; b <= z + CurrentBuilding.intSize - 1; b++) { intDistrict[a, b] = 2; } } if (CurrentBuilding.booUnique) { // we want to include the unique buildings, // so we give a slight preference to those intBonus += 15; } lstBuildings.Add(CurrentBuilding.intID); intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID; intDistrict[x + CurrentBuilding.intSize - 1, z + CurrentBuilding.intSize - 1] = 100 + CurrentBuilding.intID; intFail = 0; } else { intFail++; } } while (intFail < 10); int intCurWasted = SquaresWasted(intDistrict) - intBonus; if (intCurWasted < intWasted) { intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)]; Array.Copy(intDistrict, intFinal, intDistrict.Length); intWasted = intCurWasted; intAttempts = 10; lstAcceptedBuildings.Clear(); lstAcceptedBuildings.AddRange(lstBuildings); } Array.Clear(intDistrict, 0, intDistrict.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = RotateArray(intFinal, 1); } lstAllBuildings.AddRange(lstAcceptedBuildings); return(intFinal); }
private static int[,] CheckAgainstNeighbours(int[,] intArea, int intMin, int intRandMin, int intRandMax, int intSet, int intTimes, bool booCheckDown) { int[,] intOriginal = new int[intArea.GetLength(0), intArea.GetLength(1)]; for (int intTime = 1; intTime <= intTimes; intTime++) { Array.Copy(intArea, intOriginal, intArea.Length); for (int a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (int b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { if (booCheckDown) { if (Utils.SumOfNeighbours2D(intOriginal, a, b) < intMin + RandomHelper.Next(intRandMin, intRandMax)) { intArea[a, b] = intSet; } } else { if (Utils.SumOfNeighbours2D(intOriginal, a, b) >= intMin + RandomHelper.Next(intRandMin, intRandMax)) { intArea[a, b] = intSet; } } } } } return(intArea); }
public static int[] ShuffleArray(int[] intArray) { return(intArray.OrderBy(a => RandomHelper.Next()).ToArray()); }
public void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings, bool booIncludePaths, bool booIncludeMineshaft, bool booIncludeItemsInChests, bool booIncludeValuableBlocks, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strTowerAddition, string strWallMaterial, string strCitySeed, string strWorldSeed) { #region seed the random number generators int intCitySeed, intWorldSeed; Random randSeeds = new Random(); if (strCitySeed == "") { intCitySeed = randSeeds.Next(); frmLogForm.UpdateLog("Random city seed: " + intCitySeed); } else { intCitySeed = JavaStringHashCode(strCitySeed); frmLogForm.UpdateLog("Random city seed: " + strCitySeed); } if (strWorldSeed == "") { intWorldSeed = randSeeds.Next(); frmLogForm.UpdateLog("Random world seed: " + intWorldSeed); } else { intWorldSeed = JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Random world seed: " + strWorldSeed); } RandomHelper.SetSeed(intCitySeed); #endregion #region create minecraft world directory from a random unused city name string strFolder = "", strCityName = ""; strUserCityName = SafeFilename(strUserCityName); if (strUserCityName.ToLower().Trim() == "") { strUserCityName = "Random"; } if (strUserCityName.ToLower().Trim() != "random") { if (Directory.Exists(Utils.GetMinecraftSavesDir(strUserCityName))) { if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists."); return; } } else { strCityName = strUserCityName; strFolder = Utils.GetMinecraftSavesDir(strCityName); } } if (strCityName == "") { string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt")); strEnd = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt")); strCityName = "City of " + strStart + strEnd; strFolder = Utils.GetMinecraftSavesDir(strCityName); } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder)); } Directory.CreateDirectory(strFolder); RandomHelper.SetSeed(intCitySeed); #endregion #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); ChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = RandomHelper.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmSize = booIncludeFarms ? 32 : 16; int intMapSize = intCitySize + (intFarmSize * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapSize); BlockHelper.SetupClass(bmDest, intMapSize); if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests)) { return; } NoticeBoard.SetupClass(intCitySeed, intWorldSeed); #endregion #region determine random options // ensure selected options take priority, but don't set things on fire if (strTowerAddition == "Random") { strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag"); } if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Lava" || strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } if (strWallMaterial == "Random") { if (strMoatType == "Lava" || strOutsideLights == "Fire") { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone"); } else { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone", "Wood Planks"); if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } } } if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } if (strMoatType == "Random") { int intRand = RandomHelper.Next(100); if (intRand >= 90) { strMoatType = "Drop to Bedrock"; } else if (intRand >= 80) { strMoatType = "Cactus"; } else if (intRand >= 50) { strMoatType = "Lava"; } else { strMoatType = "Water"; } } int intWallMaterial = (int)BlockType.STONE; switch (strWallMaterial) { case "Brick": intWallMaterial = (int)BlockType.BRICK_BLOCK; break; case "Cobblestone": intWallMaterial = (int)BlockType.COBBLESTONE; break; case "Sandstone": intWallMaterial = (int)BlockType.SANDSTONE; break; case "Stone": intWallMaterial = (int)BlockType.STONE; break; case "Wood Planks": intWallMaterial = (int)BlockType.WOOD_PLANK; break; case "Wood Logs": intWallMaterial = (int)BlockType.WOOD; break; case "Bedrock": intWallMaterial = (int)BlockType.BEDROCK; break; case "Glass": intWallMaterial = (int)BlockType.GLASS; break; case "Dirt": intWallMaterial = (int)BlockType.DIRT; break; case "Obsidian": intWallMaterial = (int)BlockType.OBSIDIAN; break; } #endregion #region make the city frmLogForm.UpdateLog("Creating underground terrain"); Chunks.MakeChunks(cmDest, intMapSize / 16, frmLogForm); frmLogForm.UpdateProgress(25); if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(34); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths); } } frmLogForm.UpdateProgress(43); if (booIncludeMineshaft) { frmLogForm.UpdateLog("Creating mineshaft"); Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(49); } if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights, intWallMaterial); } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial); } frmLogForm.UpdateProgress(54); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(58); if (!booIncludeValuableBlocks) { cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapSize); } frmLogForm.UpdateProgress(62); #endregion #region world settings // spawn in a guard tower //worldDest.Level.SpawnX = intFarmSize + 5; //worldDest.Level.SpawnZ = intFarmSize + 5; //worldDest.Level.SpawnY = 82; // spawn looking at one of the city entrances worldDest.Level.SpawnX = intMapSize / 2; worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10); worldDest.Level.SpawnY = 64; // spawn in the middle of the city //worldDest.Level.SpawnX = intMapSize / 2; //worldDest.Level.SpawnZ = (intMapSize / 2) - 1; //worldDest.Level.SpawnY = 64; // spawn default //world.Level.SpawnX = 0; //world.Level.SpawnY = 65; //world.Level.SpawnZ = 0; if (strWorldSeed != "") { worldDest.Level.RandomSeed = intWorldSeed; } worldDest.Level.LevelName = strCityName; #if RELEASE worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endif #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2); #endif frmLogForm.UpdateLog("Resetting lighting"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2)); worldDest.Save(); frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
private static TileEntityChest MakeHouseChest() { TileEntityChest tec = new TileEntityChest(); for (int intItems = RandomHelper.Next(4, 8); intItems >= 0; intItems--) { switch (RandomHelper.Next(0, 17)) { case 0: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Apple.ID, 1); break; case 1: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Book.ID, 1); break; case 2: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Bowl.ID, 1); break; case 3: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Bread.ID, 1); break; case 4: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Cake.ID, 1); break; case 5: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Clock.ID, 1); break; case 6: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Compass.ID, 1); break; case 7: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Cookie.ID, 1); break; case 8: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Diamond.ID, 1); break; case 9: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Egg.ID, 1); break; case 10: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Feather.ID, 1); break; case 11: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.FishingRod.ID, 1); break; case 12: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.GoldMusicDisc.ID, 1); break; case 13: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.GreenMusicDisc.ID, 1); break; case 14: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Paper.ID, 1); break; case 15: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.Saddle.ID, 1); break; case 16: tec.Items[intItems] = BlockHelper.MakeItem(ItemInfo.String.ID, 1); break; } } return(tec); }
public static int RandomItemFromArray(int[] intNumbers) { return(intNumbers[RandomHelper.Next(intNumbers.Length)]); }
public static char RandomLetterLower() { return((char)((short)'a' + RandomHelper.Next(26))); }
public static string RandomString(params string[] strStrings) { return(strStrings[RandomHelper.Next(strStrings.Length)]); }
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 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); } } }
public static void MakeGuardTowers(BlockManager bm, int intFarmLength, int intMapLength, bool booIncludeWalls, string strOutsideLights, string strTowerAddition, bool booIncludeItemsInChests, int intWallMaterial) { // remove wall BlockShapes.MakeSolidBox(intFarmLength + 5, intFarmLength + 11, 64, 79, intFarmLength + 5, intFarmLength + 11, BlockType.AIR, 1); // add tower BlockShapes.MakeHollowBox(intFarmLength + 4, intFarmLength + 12, 63, 80, intFarmLength + 4, intFarmLength + 12, intWallMaterial, 1, -1); // divide into two rooms BlockShapes.MakeSolidBox(intFarmLength + 4, intFarmLength + 12, 2, 72, intFarmLength + 4, intFarmLength + 12, intWallMaterial, 1); BlockShapes.MakeSolidBox(intFarmLength + 5, intFarmLength + 11, 64, 67, intFarmLength + 5, intFarmLength + 11, BlockType.AIR, 1); switch (strOutsideLights) { case "Fire": BlockShapes.MakeBlock(intFarmLength + 5, 76, intFarmLength + 3, BlockType.NETHERRACK, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 5, 77, intFarmLength + 3, BlockType.FIRE, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 11, 76, intFarmLength + 3, BlockType.NETHERRACK, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 11, 77, intFarmLength + 3, BlockType.FIRE, 2, 100, -1); break; case "Torches": for (int y = 73; y <= 80; y += 7) { BlockHelper.MakeTorch(intFarmLength + 6, y, intFarmLength + 3, intWallMaterial, 2); BlockHelper.MakeTorch(intFarmLength + 10, y, intFarmLength + 3, intWallMaterial, 2); } break; case "None": break; default: Debug.Fail("Invalid switch result"); break; } // add torches BlockHelper.MakeTorch(intFarmLength + 6, 79, intFarmLength + 13, intWallMaterial, 2); BlockHelper.MakeTorch(intFarmLength + 10, 79, intFarmLength + 13, intWallMaterial, 2); // add torches inside BlockHelper.MakeTorch(intFarmLength + 6, 77, intFarmLength + 11, intWallMaterial, 2); BlockHelper.MakeTorch(intFarmLength + 10, 77, intFarmLength + 11, intWallMaterial, 2); BlockHelper.MakeTorch(intFarmLength + 5, 77, intFarmLength + 6, intWallMaterial, 2); BlockHelper.MakeTorch(intFarmLength + 5, 77, intFarmLength + 10, intWallMaterial, 2); // add openings to the walls BlockShapes.MakeBlock(intFarmLength + 7, 73, intFarmLength + 12, BlockType.AIR, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 9, 73, intFarmLength + 12, BlockType.AIR, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 7, 74, intFarmLength + 12, BlockType.AIR, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 9, 74, intFarmLength + 12, BlockType.AIR, 2, 100, -1); // add blocks on top of the towers BlockShapes.MakeHollowLayers(intFarmLength + 4, intFarmLength + 12, 81, 81, intFarmLength + 4, intFarmLength + 12, intWallMaterial, 1, -1); // alternating top blocks for (int x = intFarmLength + 4; x <= intFarmLength + 12; x += 2) { for (int z = intFarmLength + 4; z <= intFarmLength + 12; z += 2) { if (x == intFarmLength + 4 || x == intFarmLength + 12 || z == intFarmLength + 4 || z == intFarmLength + 12) { BlockShapes.MakeBlock(x, 82, z, intWallMaterial, 1, 100, -1); } } } // add central columns BlockShapes.MakeSolidBox(intFarmLength + 8, intFarmLength + 8, 73, 82, intFarmLength + 8, intFarmLength + 8, intWallMaterial, 1); BlockHelper.MakeLadder(intFarmLength + 7, 73, 82, intFarmLength + 8, 2, intWallMaterial); BlockHelper.MakeLadder(intFarmLength + 9, 73, 82, intFarmLength + 8, 2, intWallMaterial); // add torches on the roof BlockShapes.MakeBlock(intFarmLength + 6, 81, intFarmLength + 6, BlockType.TORCH, 1, 100, -1); BlockShapes.MakeBlock(intFarmLength + 6, 81, intFarmLength + 10, BlockType.TORCH, 2, 100, -1); BlockShapes.MakeBlock(intFarmLength + 10, 81, intFarmLength + 10, BlockType.TORCH, 1, 100, -1); // add cobwebs BlockShapes.MakeBlock(intFarmLength + 5, 79, intFarmLength + 5, BlockType.COBWEB, 1, 30, -1); BlockShapes.MakeBlock(intFarmLength + 5, 79, intFarmLength + 11, BlockType.COBWEB, 1, 30, -1); BlockShapes.MakeBlock(intFarmLength + 11, 79, intFarmLength + 5, BlockType.COBWEB, 1, 30, -1); BlockShapes.MakeBlock(intFarmLength + 11, 79, intFarmLength + 11, BlockType.COBWEB, 1, 30, -1); // add chests MakeGuardChest(bm, intFarmLength + 11, 73, intFarmLength + 11, booIncludeItemsInChests); MakeGuardChest(bm, intMapLength - (intFarmLength + 11), 73, intFarmLength + 11, booIncludeItemsInChests); MakeGuardChest(bm, intFarmLength + 11, 73, intMapLength - (intFarmLength + 11), booIncludeItemsInChests); MakeGuardChest(bm, intMapLength - (intFarmLength + 11), 73, intMapLength - (intFarmLength + 11), booIncludeItemsInChests); // add archery slots BlockShapes.MakeSolidBox(intFarmLength + 4, intFarmLength + 4, 74, 77, intFarmLength + 8, intFarmLength + 8, BlockType.AIR, 2); BlockShapes.MakeSolidBox(intFarmLength + 4, intFarmLength + 4, 76, 76, intFarmLength + 7, intFarmLength + 9, BlockType.AIR, 2); if (!booIncludeWalls) { BlockHelper.MakeLadder(intFarmLength + 13, 64, 72, intFarmLength + 8, 2, intWallMaterial); } // include beds BlockHelper.MakeBed(intFarmLength + 5, intFarmLength + 6, 64, intFarmLength + 8, intFarmLength + 8, 2); BlockHelper.MakeBed(intFarmLength + 5, intFarmLength + 6, 64, intFarmLength + 10, intFarmLength + 10, 2); BlockHelper.MakeBed(intFarmLength + 11, intFarmLength + 10, 64, intFarmLength + 8, intFarmLength + 8, 2); // make columns to orientate torches BlockShapes.MakeSolidBox(intFarmLength + 5, intFarmLength + 5, 64, 73, intFarmLength + 5, intFarmLength + 5, BlockType.WOOD, 2); BlockShapes.MakeSolidBox(intFarmLength + 11, intFarmLength + 11, 64, 71, intFarmLength + 5, intFarmLength + 5, BlockType.WOOD, 2); BlockShapes.MakeSolidBox(intFarmLength + 5, intFarmLength + 5, 64, 71, intFarmLength + 11, intFarmLength + 11, BlockType.WOOD, 2); BlockShapes.MakeSolidBox(intFarmLength + 11, intFarmLength + 11, 64, 71, intFarmLength + 11, intFarmLength + 11, BlockType.WOOD, 2); // add ladders BlockHelper.MakeLadder(intFarmLength + 5, 64, 73, intFarmLength + 6, 2, BlockType.WOOD); // make torches BlockHelper.MakeTorch(intFarmLength + 10, 66, intFarmLength + 5, BlockType.WOOD, 2); BlockHelper.MakeTorch(intFarmLength + 6, 66, intFarmLength + 11, BlockType.WOOD, 2); BlockHelper.MakeTorch(intFarmLength + 10, 66, intFarmLength + 11, BlockType.WOOD, 2); // make columns for real BlockShapes.MakeSolidBox(intFarmLength + 5, intFarmLength + 5, 64, 73, intFarmLength + 5, intFarmLength + 5, intWallMaterial, 2); BlockShapes.MakeSolidBox(intFarmLength + 11, intFarmLength + 11, 64, 71, intFarmLength + 5, intFarmLength + 5, intWallMaterial, 2); BlockShapes.MakeSolidBox(intFarmLength + 5, intFarmLength + 5, 64, 71, intFarmLength + 11, intFarmLength + 11, intWallMaterial, 2); BlockShapes.MakeSolidBox(intFarmLength + 11, intFarmLength + 11, 64, 71, intFarmLength + 11, intFarmLength + 11, intWallMaterial, 2); // make cobwebs BlockShapes.MakeBlock(intFarmLength + 11, 67, intFarmLength + 8, BlockType.COBWEB, 2, 75, -1); // make doors from the city to the guard tower BlockShapes.MakeBlock(intFarmLength + 11, 65, intFarmLength + 11, BlockType.GOLD_BLOCK, 1, 100, -1); BlockShapes.MakeBlock(intFarmLength + 11, 64, intFarmLength + 11, BlockType.GOLD_BLOCK, 1, 100, -1); BlockHelper.MakeDoor(intFarmLength + 11, 64, intFarmLength + 12, BlockType.GOLD_BLOCK, true, 2); BlockShapes.MakeBlock(intFarmLength + 11, 65, intFarmLength + 11, BlockType.AIR, 1, 100, -1); BlockShapes.MakeBlock(intFarmLength + 11, 64, intFarmLength + 11, BlockType.AIR, 1, 100, -1); BlockShapes.MakeBlock(intFarmLength + 11, 64, intFarmLength + 11, BlockType.STONE_PLATE, 1, 100, -1); BlockShapes.MakeBlock(intFarmLength + 11, 64, intFarmLength + 13, BlockType.STONE_PLATE, 2, 100, -1); //BlockShapes.MakeBlock(intFarmLength + 13, 64, intFarmLength + 11, BlockType.STONE_PLATE, 1, 100, -1); // add guard tower sign BlockHelper.MakeSign(intFarmLength + 12, 65, intFarmLength + 13, "~Guard Tower~~", intWallMaterial, 1); BlockHelper.MakeSign(intFarmLength + 8, 74, intFarmLength + 13, "~Guard Tower~~", intWallMaterial, 2); // make beacon switch (strTowerAddition) { case "Fire beacon": BlockShapes.MakeSolidBox(intFarmLength + 8, intFarmLength + 8, 83, 84, intFarmLength + 8, intFarmLength + 8, intWallMaterial, 1); BlockShapes.MakeSolidBox(intFarmLength + 6, intFarmLength + 10, 85, 85, intFarmLength + 6, intFarmLength + 10, intWallMaterial, 1); BlockShapes.MakeSolidBox(intFarmLength + 6, intFarmLength + 10, 86, 86, intFarmLength + 6, intFarmLength + 10, BlockType.NETHERRACK, 1); BlockShapes.MakeSolidBox(intFarmLength + 6, intFarmLength + 10, 87, 87, intFarmLength + 6, intFarmLength + 10, BlockType.FIRE, 1); break; case "Flag": BlockShapes.MakeSolidBox(intFarmLength + 4, intFarmLength + 4, 83, 91, intFarmLength + 12, intFarmLength + 12, BlockType.FENCE, 2); BlockShapes.MakeBlock(intFarmLength + 4, 84, intFarmLength + 13, BlockType.FENCE, 2, 100, 0); BlockShapes.MakeBlock(intFarmLength + 4, 91, intFarmLength + 13, BlockType.FENCE, 2, 100, 0); int[] intColours = Utils.ShuffleArray(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); switch (RandomHelper.Next(7)) { case 0: //2vert BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 13, intFarmLength + 17, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 18, intFarmLength + 22, BlockType.WOOL, 2, intColours[1]); break; case 1: //3vert BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 13, intFarmLength + 15, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 16, intFarmLength + 18, BlockType.WOOL, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 19, intFarmLength + 21, BlockType.WOOL, 2, intColours[2]); break; case 2: //4vert BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 13, intFarmLength + 14, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 15, intFarmLength + 16, BlockType.WOOL, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 17, intFarmLength + 18, BlockType.WOOL, 2, intColours[2]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 19, intFarmLength + 20, BlockType.WOOL, 2, intColours[3]); break; case 3: //2horiz BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 87, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 88, 90, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[1]); break; case 4: //3horiz BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 86, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 87, 88, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 89, 90, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[2]); break; case 5: //quarters BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 87, intFarmLength + 13, intFarmLength + 17, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 87, intFarmLength + 18, intFarmLength + 22, BlockType.WOOL, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 88, 90, intFarmLength + 13, intFarmLength + 17, BlockType.WOOL, 2, intColours[2]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 88, 90, intFarmLength + 18, intFarmLength + 22, BlockType.WOOL, 2, intColours[3]); break; case 6: //cross BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 87, 88, intFarmLength + 13, intFarmLength + 22, BlockType.WOOL, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(intFarmLength + 4, intFarmLength + 4, 85, 90, intFarmLength + 17, intFarmLength + 18, BlockType.WOOL, 2, intColours[1]); break; default: Debug.Fail("Invalid switch result"); break; } break; } }
public static void MakeGuardTowers(BlockManager bm, frmMace frmLogForm) { // remove wall BlockShapes.MakeSolidBox(City.FarmLength + 5, City.FarmLength + 11, 64, 79, City.FarmLength + 5, City.FarmLength + 11, BlockInfo.Air.ID, 1); // add tower BlockShapes.MakeHollowBox(City.FarmLength + 4, City.FarmLength + 12, 63, 80, City.FarmLength + 4, City.FarmLength + 12, City.WallMaterialID, 1, City.WallMaterialData); // divide into two rooms BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 12, 2, 72, City.FarmLength + 4, City.FarmLength + 12, City.WallMaterialID, 1, City.WallMaterialData); BlockShapes.MakeSolidBox(City.FarmLength + 5, City.FarmLength + 11, 64, 67, City.FarmLength + 5, City.FarmLength + 11, BlockInfo.Air.ID, 1); switch (City.OutsideLightType) { case "Fire": BlockShapes.MakeBlock(City.FarmLength + 5, 76, City.FarmLength + 3, BlockInfo.Netherrack.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 5, 77, City.FarmLength + 3, BlockInfo.Fire.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 76, City.FarmLength + 3, BlockInfo.Netherrack.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 77, City.FarmLength + 3, BlockInfo.Fire.ID, 2, 100, -1); break; case "Torches": for (int y = 73; y <= 80; y += 7) { BlockHelper.MakeTorch(City.FarmLength + 6, y, City.FarmLength + 3, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.FarmLength + 10, y, City.FarmLength + 3, City.WallMaterialID, 2); } break; case "None": break; default: Debug.Fail("Invalid switch result"); break; } // add torches BlockHelper.MakeTorch(City.FarmLength + 6, 79, City.FarmLength + 13, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.FarmLength + 10, 79, City.FarmLength + 13, City.WallMaterialID, 2); // add torches inside BlockHelper.MakeTorch(City.FarmLength + 6, 77, City.FarmLength + 11, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.FarmLength + 10, 77, City.FarmLength + 11, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.FarmLength + 5, 77, City.FarmLength + 6, City.WallMaterialID, 2); BlockHelper.MakeTorch(City.FarmLength + 5, 77, City.FarmLength + 10, City.WallMaterialID, 2); // add openings to the walls BlockShapes.MakeBlock(City.FarmLength + 7, 73, City.FarmLength + 12, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 9, 73, City.FarmLength + 12, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 7, 74, City.FarmLength + 12, BlockInfo.Air.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 9, 74, City.FarmLength + 12, BlockInfo.Air.ID, 2, 100, -1); // add blocks on top of the towers BlockShapes.MakeHollowLayers(City.FarmLength + 4, City.FarmLength + 12, 81, 81, City.FarmLength + 4, City.FarmLength + 12, City.WallMaterialID, 1, City.WallMaterialData); // alternating top blocks for (int x = City.FarmLength + 4; x <= City.FarmLength + 12; x += 2) { for (int z = City.FarmLength + 4; z <= City.FarmLength + 12; z += 2) { if (x == City.FarmLength + 4 || x == City.FarmLength + 12 || z == City.FarmLength + 4 || z == City.FarmLength + 12) { BlockShapes.MakeBlock(x, 82, z, City.WallMaterialID, 1, 100, City.WallMaterialData); } } } // add central columns BlockShapes.MakeSolidBoxWithData(City.FarmLength + 8, City.FarmLength + 8, 73, 82, City.FarmLength + 8, City.FarmLength + 8, City.WallMaterialID, 1, City.WallMaterialData); BlockHelper.MakeLadder(City.FarmLength + 7, 73, 82, City.FarmLength + 8, 2, City.WallMaterialID); BlockHelper.MakeLadder(City.FarmLength + 9, 73, 82, City.FarmLength + 8, 2, City.WallMaterialID); // add torches on the roof BlockShapes.MakeBlock(City.FarmLength + 6, 81, City.FarmLength + 6, BlockInfo.Torch.ID, 1, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 6, 81, City.FarmLength + 10, BlockInfo.Torch.ID, 2, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 10, 81, City.FarmLength + 10, BlockInfo.Torch.ID, 1, 100, -1); // add cobwebs BlockShapes.MakeBlock(City.FarmLength + 5, 79, City.FarmLength + 5, BlockInfo.Cobweb.ID, 1, 30, -1); BlockShapes.MakeBlock(City.FarmLength + 5, 79, City.FarmLength + 11, BlockInfo.Cobweb.ID, 1, 30, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 79, City.FarmLength + 5, BlockInfo.Cobweb.ID, 1, 30, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 79, City.FarmLength + 11, BlockInfo.Cobweb.ID, 1, 30, -1); // add chests MakeGuardChest(bm, City.FarmLength + 11, 73, City.FarmLength + 11); MakeGuardChest(bm, City.MapLength - (City.FarmLength + 11), 73, City.FarmLength + 11); MakeGuardChest(bm, City.FarmLength + 11, 73, City.MapLength - (City.FarmLength + 11)); MakeGuardChest(bm, City.MapLength - (City.FarmLength + 11), 73, City.MapLength - (City.FarmLength + 11)); // add archery slots BlockShapes.MakeSolidBox(City.FarmLength + 4, City.FarmLength + 4, 74, 77, City.FarmLength + 8, City.FarmLength + 8, BlockInfo.Air.ID, 2); BlockShapes.MakeSolidBox(City.FarmLength + 4, City.FarmLength + 4, 76, 76, City.FarmLength + 7, City.FarmLength + 9, BlockInfo.Air.ID, 2); if (!City.HasWalls) { BlockHelper.MakeLadder(City.FarmLength + 13, 64, 72, City.FarmLength + 8, 2, City.WallMaterialID); } // include beds BlockHelper.MakeBed(City.FarmLength + 5, City.FarmLength + 6, 64, City.FarmLength + 8, City.FarmLength + 8, 2); BlockHelper.MakeBed(City.FarmLength + 5, City.FarmLength + 6, 64, City.FarmLength + 10, City.FarmLength + 10, 2); BlockHelper.MakeBed(City.FarmLength + 11, City.FarmLength + 10, 64, City.FarmLength + 8, City.FarmLength + 8, 2); // make columns to orientate torches BlockShapes.MakeSolidBox(City.FarmLength + 5, City.FarmLength + 5, 64, 73, City.FarmLength + 5, City.FarmLength + 5, BlockInfo.Wood.ID, 2); BlockShapes.MakeSolidBox(City.FarmLength + 11, City.FarmLength + 11, 64, 71, City.FarmLength + 5, City.FarmLength + 5, BlockInfo.Wood.ID, 2); BlockShapes.MakeSolidBox(City.FarmLength + 5, City.FarmLength + 5, 64, 71, City.FarmLength + 11, City.FarmLength + 11, BlockInfo.Wood.ID, 2); BlockShapes.MakeSolidBox(City.FarmLength + 11, City.FarmLength + 11, 64, 71, City.FarmLength + 11, City.FarmLength + 11, BlockInfo.Wood.ID, 2); // add ladders BlockHelper.MakeLadder(City.FarmLength + 5, 64, 73, City.FarmLength + 6, 2, BlockInfo.Wood.ID); // make torches BlockHelper.MakeTorch(City.FarmLength + 10, 66, City.FarmLength + 5, BlockInfo.Wood.ID, 2); BlockHelper.MakeTorch(City.FarmLength + 6, 66, City.FarmLength + 11, BlockInfo.Wood.ID, 2); BlockHelper.MakeTorch(City.FarmLength + 10, 66, City.FarmLength + 11, BlockInfo.Wood.ID, 2); // make columns for real BlockShapes.MakeSolidBoxWithData(City.FarmLength + 5, City.FarmLength + 5, 64, 73, City.FarmLength + 5, City.FarmLength + 5, City.WallMaterialID, 2, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 11, City.FarmLength + 11, 64, 71, City.FarmLength + 5, City.FarmLength + 5, City.WallMaterialID, 2, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 5, City.FarmLength + 5, 64, 71, City.FarmLength + 11, City.FarmLength + 11, City.WallMaterialID, 2, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 11, City.FarmLength + 11, 64, 71, City.FarmLength + 11, City.FarmLength + 11, City.WallMaterialID, 2, City.WallMaterialData); // make cobwebs BlockShapes.MakeBlock(City.FarmLength + 11, 67, City.FarmLength + 8, BlockInfo.Cobweb.ID, 2, 75, -1); // make doors from the city to the guard tower BlockShapes.MakeBlock(City.FarmLength + 11, 65, City.FarmLength + 11, BlockInfo.GoldBlock.ID, 1, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 64, City.FarmLength + 11, BlockInfo.GoldBlock.ID, 1, 100, -1); BlockHelper.MakeDoor(City.FarmLength + 11, 64, City.FarmLength + 12, BlockInfo.GoldBlock.ID, true, 2); BlockShapes.MakeBlock(City.FarmLength + 11, 65, City.FarmLength + 11, BlockInfo.Air.ID, 1, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 64, City.FarmLength + 11, BlockInfo.Air.ID, 1, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 64, City.FarmLength + 11, BlockInfo.StonePlate.ID, 1, 100, -1); BlockShapes.MakeBlock(City.FarmLength + 11, 64, City.FarmLength + 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.FarmLength + 12, 65, City.FarmLength + 13, "~Guard Tower~~", City.WallMaterialID, 1); BlockHelper.MakeSign(City.FarmLength + 8, 74, City.FarmLength + 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.FarmLength + 8, City.FarmLength + 8, 83, 84, City.FarmLength + 8, City.FarmLength + 8, City.WallMaterialID, 1, City.WallMaterialData); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 6, City.FarmLength + 10, 85, 85, City.FarmLength + 6, City.FarmLength + 10, City.WallMaterialID, 1, City.WallMaterialData); BlockShapes.MakeSolidBox(City.FarmLength + 6, City.FarmLength + 10, 86, 86, City.FarmLength + 6, City.FarmLength + 10, BlockInfo.Netherrack.ID, 1); BlockShapes.MakeSolidBox(City.FarmLength + 6, City.FarmLength + 10, 87, 87, City.FarmLength + 6, City.FarmLength + 10, BlockInfo.Fire.ID, 1); break; case "Flag": BlockShapes.MakeSolidBox(City.FarmLength + 4, City.FarmLength + 4, 83, 91, City.FarmLength + 12, City.FarmLength + 12, BlockInfo.Fence.ID, 2); BlockShapes.MakeBlock(City.FarmLength + 4, 84, City.FarmLength + 13, BlockInfo.Fence.ID, 2, 100, 0); BlockShapes.MakeBlock(City.FarmLength + 4, 91, City.FarmLength + 13, BlockInfo.Fence.ID, 2, 100, 0); int[] intColours = RandomHelper.ShuffleArray(Enumerable.Range(0, 15).ToArray()); switch (RandomHelper.Next(8)) { case 0: //2vert BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 13, City.FarmLength + 17, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 18, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[1]); break; case 1: //3vert BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 13, City.FarmLength + 15, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 16, City.FarmLength + 18, BlockInfo.Wool.ID, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 19, City.FarmLength + 21, BlockInfo.Wool.ID, 2, intColours[2]); break; case 2: //4vert BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 13, City.FarmLength + 14, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 15, City.FarmLength + 16, BlockInfo.Wool.ID, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 17, City.FarmLength + 18, BlockInfo.Wool.ID, 2, intColours[2]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 19, City.FarmLength + 20, BlockInfo.Wool.ID, 2, intColours[3]); break; case 3: //2horiz BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 87, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 88, 90, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[1]); break; case 4: //3horiz BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 86, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 87, 88, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 89, 90, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[2]); break; case 5: //quarters BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 87, City.FarmLength + 13, City.FarmLength + 17, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 87, City.FarmLength + 18, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 88, 90, City.FarmLength + 13, City.FarmLength + 17, BlockInfo.Wool.ID, 2, intColours[2]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 88, 90, City.FarmLength + 18, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[3]); break; case 6: //cross BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 87, 88, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 17, City.FarmLength + 18, BlockInfo.Wool.ID, 2, intColours[1]); break; default: // inside "circle" BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 85, 90, City.FarmLength + 13, City.FarmLength + 22, BlockInfo.Wool.ID, 2, intColours[0]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 86, 89, City.FarmLength + 17, City.FarmLength + 18, BlockInfo.Wool.ID, 2, intColours[1]); BlockShapes.MakeSolidBoxWithData(City.FarmLength + 4, City.FarmLength + 4, 87, 88, City.FarmLength + 16, City.FarmLength + 19, BlockInfo.Wool.ID, 2, intColours[1]); break; } break; } }
private static void SplitArea(BlockManager bm, int[,] intArea, int x1, int z1, int x2, int z2) { for (int x = x1; x <= x2; x++) { for (int y = z1; y <= z2; y++) { if (x == x1 || x == x2 || y == z1 || y == z2) { if (intArea[x, y] < 500) { intArea[x, y] = 1; } } } } bool booPossibleToSplit = true; bool booSplitByX = false; if (Math.Abs(x1 - x2) > 50 && Math.Abs(z1 - z2) > 50) { booSplitByX = RandomHelper.NextDouble() > 0.5; } else if (Math.Abs(x1 - x2) > 50) { booSplitByX = true; } else if (Math.Abs(z1 - z2) <= 50) { booPossibleToSplit = false; } if (booPossibleToSplit) { if (booSplitByX) { int intSplitPoint = RandomHelper.Next(x1 + 20, x2 - 20); SplitArea(bm, intArea, x1, z1, intSplitPoint, z2); SplitArea(bm, intArea, intSplitPoint, z1, x2, z2); intStreet++; MakeStreetSign(bm, intSplitPoint - 1, z1 + 1, intSplitPoint - 1, z2 - 1); } else { int intSplitPoint = RandomHelper.Next(z1 + 20, z2 - 20); SplitArea(bm, intArea, x1, z1, x2, intSplitPoint); SplitArea(bm, intArea, x1, intSplitPoint, x2, z2); intStreet++; MakeStreetSign(bm, x1 + 1, intSplitPoint - 1, x2 - 1, intSplitPoint - 1); } } else { int[,] intDistrict = FillArea(intArea, (x2 - x1), (z2 - z1), x1, z1); for (int x = 0; x < intDistrict.GetUpperBound(0) - 1; x++) { for (int y = 0; y < intDistrict.GetUpperBound(1) - 1; y++) { intArea[x1 + x + 1, z1 + y + 1] = intDistrict[x + 1, y + 1]; } } } }
public static string[] ShuffleArray(string[] strArray) { return(strArray.OrderBy(a => RandomHelper.Next()).ToArray()); }
// 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 static void MakeMoat(int intFarmSize, int intMapSize, string strMoatType, bool booIncludeGuardTowers) { 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"; } } switch (strMoatType) { case "Drop to Bedrock": for (int a = intFarmSize - 1; a <= intFarmSize + 5; a++) { BlockShapes.MakeHollowLayers(a, intMapSize - a, 2, 63, a, intMapSize - a, (int)BlockType.AIR, 0, -1); } break; case "Cactus": for (int a = intFarmSize - 1; a <= intFarmSize + 5; a++) { BlockShapes.MakeHollowLayers(a, intMapSize - a, 59, 63, a, intMapSize - a, (int)BlockType.AIR, 0, -1); BlockShapes.MakeHollowLayers(a, intMapSize - a, 58, 58, a, intMapSize - a, (int)BlockType.SAND, 0, -1); } for (int a = intFarmSize + 1; a <= intMapSize / 2; a += 2) { BlockShapes.MakeBlock(a, 59, intFarmSize + 1, (int)BlockType.CACTUS, 2, 100, -1); BlockShapes.MakeBlock(a, 59, intFarmSize + 3, (int)BlockType.CACTUS, 2, 100, -1); BlockShapes.MakeBlock(a, 60, intFarmSize + 1, (int)BlockType.CACTUS, 2, 50, -1); BlockShapes.MakeBlock(a, 60, intFarmSize + 3, (int)BlockType.CACTUS, 2, 50, -1); } for (int a = intFarmSize; a <= intMapSize / 2; a += 2) { BlockShapes.MakeBlock(a, 59, intFarmSize, (int)BlockType.CACTUS, 2, 100, -1); BlockShapes.MakeBlock(a, 59, intFarmSize + 2, (int)BlockType.CACTUS, 2, 100, -1); BlockShapes.MakeBlock(a, 59, intFarmSize + 4, (int)BlockType.CACTUS, 2, 100, -1); BlockShapes.MakeBlock(a, 60, intFarmSize, (int)BlockType.CACTUS, 2, 50, -1); BlockShapes.MakeBlock(a, 60, intFarmSize + 2, (int)BlockType.CACTUS, 2, 50, -1); BlockShapes.MakeBlock(a, 60, intFarmSize + 4, (int)BlockType.CACTUS, 2, 50, -1); } if (booIncludeGuardTowers) { for (int a = intFarmSize + 3; a <= intFarmSize + 13; a += 2) { BlockShapes.MakeBlock(a, 59, intFarmSize + 3, (int)BlockType.AIR, 2, 100, -1); BlockShapes.MakeBlock(a, 60, intFarmSize + 3, (int)BlockType.AIR, 2, 100, -1); } } break; case "Lava": for (int a = intFarmSize - 1; a <= intFarmSize + 5; a++) { BlockShapes.MakeHollowLayers(a, intMapSize - a, 62, 63, a, intMapSize - a, (int)BlockType.AIR, 0, -1); } for (int a = intFarmSize - 1; a <= intFarmSize + 5; a++) { BlockShapes.MakeHollowLayers(a, intMapSize - a, 59, 61, a, intMapSize - a, (int)BlockType.LAVA, 0, -1); } break; case "Water": for (int a = intFarmSize - 1; a <= intFarmSize + 5; a++) { BlockShapes.MakeHollowLayers(a, intMapSize - a, 59, 63, a, intMapSize - a, (int)BlockType.WATER, 0, -1); } break; } }
public static int RandomNumber(params int[] intNumbers) { return(intNumbers[RandomHelper.Next(intNumbers.Length)]); }
public static void MakeFarms(BetaWorld world, BlockManager bm, frmMace frmLogForm) { if (City.HasFarms) { frmLogForm.UpdateLog("Creating farm buildings", true, true); AddBuildings(bm); frmLogForm.UpdateLog("Creating farms and outside features", true, true); int intFail = 0; int intFarms = 0; while (intFail <= 500) { int xlen = RandomHelper.Next(8, 26); int x1 = RandomHelper.Next(5, City.MapLength - (5 + xlen)); int zlen = RandomHelper.Next(8, 26); int z1 = RandomHelper.Next(5, City.MapLength - (5 + zlen)); if (!(x1 >= City.FarmLength && z1 >= City.FarmLength && x1 <= City.MapLength - City.FarmLength && z1 <= City.MapLength - City.FarmLength)) { bool booValid = true; for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++) { for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++) { // make sure it doesn't overlap with the spawn point or another farm if ((x == City.MapLength / 2 && z == SpawnZ) || bm.GetID(x, 63, z) != City.GroundBlockID || bm.GetID(x, 64, z) != BlockInfo.Air.ID) { booValid = false; intFail++; } } } if (booValid) { // first there is a 25% chance of a hill or pond // if not, for large farms, there is a 50% chance it'll be an orchard // if not, 33% are cactus, 33% are wheat and 33% are sugarcane FarmTypes curFarm; int intFarmType = RandomHelper.Next(100); if (xlen >= 10 && zlen >= 10 && intFarmType > 75) { if (RandomHelper.NextDouble() > 0.5) { curFarm = FarmTypes.Pond; MakePond(bm, x1, xlen, z1, zlen, false); } else { curFarm = FarmTypes.Hill; MakeHill(bm, x1, xlen, z1, zlen, false); } } else { intFarmType = RandomHelper.Next(100); if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50) { curFarm = FarmTypes.Orchard; xlen = ((int)((xlen - 1) / 5) * 5) + 1; zlen = ((int)((zlen - 1) / 5) * 5) + 1; } else { intFarmType = RandomHelper.Next(3); if (intFarmType == 2) { curFarm = FarmTypes.Cactus; } else if (intFarmType == 1) { curFarm = FarmTypes.Wheat; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } else { curFarm = FarmTypes.SugarCane; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } } } int intWallMaterial = RandomHelper.NextDouble() > 0.5 ? BlockInfo.Fence.ID : BlockInfo.Leaves.ID; switch (curFarm) { case FarmTypes.Hill: case FarmTypes.Pond: intWallMaterial = 0; break; case FarmTypes.SugarCane: case FarmTypes.Mushroom: if (RandomHelper.NextDouble() > 0.5) { intWallMaterial = 0; } break; case FarmTypes.Wheat: intWallMaterial = BlockInfo.Leaves.ID; break; // no need for default - the other types don't need anything here } #pragma warning disable switch (intWallMaterial) { case BlockType.FENCE: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, BlockInfo.Fence.ID, 0, -1); break; case BlockType.LEAVES: // the saplings will all disappear if one of them is broken. // so we put wood beneath them to stop that happening BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen, BlockInfo.Wood.ID, 0, -1); BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, BlockInfo.Leaves.ID, 0, RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE, (int)LeafType.BIRCH)); break; case 0: // no wall break; default: Debug.Fail("Invalid switch result"); break; } #pragma warning restore switch (curFarm) { case FarmTypes.Orchard: int intSaplingType = RandomHelper.RandomNumber(SaplingBirchDataID, SaplingOakDataID, SaplingSpruceDataID); for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5) { for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5) { BlockShapes.MakeBlock(x, 63, z, City.GroundBlockID, City.GroundBlockData); BlockShapes.MakeBlock(x, 64, z, BlockInfo.Sapling.ID, intSaplingType); } } break; case FarmTypes.Cactus: int intAttempts = 0; do { int xCactus = RandomHelper.Next(x1 + 1, x1 + xlen); int zCactus = RandomHelper.Next(z1 + 1, z1 + zlen); bool booValidFarm = true; for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++) { for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++) { if (bm.GetID(xCheck, 64, zCheck) != BlockInfo.Air.ID) { booValidFarm = false; } } } if (booValidFarm) { bm.SetID(xCactus, 64, zCactus, BlockInfo.Cactus.ID); if (RandomHelper.NextDouble() > 0.5) { bm.SetID(xCactus, 65, zCactus, BlockInfo.Cactus.ID); } } }while (++intAttempts < 100); break; case FarmTypes.Wheat: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, BlockInfo.Glass.ID, 0, -1); BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, BlockInfo.Glass.ID, 0); break; // no need for a default, because there's nothing to do for the other farms } for (int x = x1 + 1; x <= x1 + xlen - 1; x++) { for (int z = z1 + 1; z <= z1 + zlen - 1; z++) { switch (curFarm) { case FarmTypes.Cactus: bm.SetID(x, 63, z, BlockInfo.Sand.ID); break; case FarmTypes.Wheat: if (z == z1 + 1) { bm.SetID(x, 63, z, BlockInfo.DoubleSlab.ID); } else if (x % 2 == 0) { BlockShapes.MakeBlock(x, 63, z, BlockInfo.Farmland.ID, 1); bm.SetID(x, 64, z, BlockInfo.Crops.ID); } else { bm.SetID(x, 63, z, BlockInfo.StationaryWater.ID); } break; case FarmTypes.SugarCane: if (z != z1 + 1) { if (x % 2 == 0) { bm.SetID(x, 64, z, BlockInfo.SugarCane.ID); if (RandomHelper.Next(100) > 50) { bm.SetID(x, 65, z, BlockInfo.SugarCane.ID); } } else { bm.SetID(x, 63, z, BlockInfo.StationaryWater.ID); } } break; // no need for a default, because there's nothing to do for the other farms } } } int intDoorPosition = x1 + RandomHelper.Next(1, xlen - 1); if (curFarm == FarmTypes.Wheat) { bm.SetID(intDoorPosition, 63, z1, BlockInfo.DoubleSlab.ID); } if (intWallMaterial != 0) { if (curFarm == FarmTypes.Wheat || intWallMaterial == BlockInfo.Leaves.ID) { BlockShapes.MakeBlock(intDoorPosition, 64, z1, BlockInfo.WoodDoor.ID, 4); BlockShapes.MakeBlock(intDoorPosition, 65, z1, BlockInfo.WoodDoor.ID, 4 + (int)DoorState.TOPHALF); } else { bm.SetID(intDoorPosition, 64, z1, BlockInfo.FenceGate.ID); bm.SetData(intDoorPosition, 64, z1, 0); } } intFail = 0; if (++intFarms > 10) { world.Save(); intFarms = 0; } } } } MakeMiniPondsAndHills(world, bm); } if (City.HasFlowers) { MakeFlowers(world, bm); } }
public static string RandomItemFromArray(string[] strStrings) { return(strStrings[RandomHelper.Next(strStrings.Length)]); }
private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ, bool booUniqueBonus) { int[,] intDistrict = new int[intSizeX, intSizeZ]; int[,] intFinal = new int[intSizeX, intSizeZ]; int intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0; int intBonus = 0; List <int> lstBuildings = new List <int>(); List <int> lstAcceptedBuildings = new List <int>(); bool booAreaNeedsMineshaft = false; do { lstBuildings.Clear(); intBonus = 0; if (!_booIncludedMineshaft) { booAreaNeedsMineshaft = true; } do { SourceWorld.Building CurrentBuilding; if (booAreaNeedsMineshaft) { CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.MineshaftEntrance, 0); // mineshaft is always the first building, so therefore it will always be possible to place it booAreaNeedsMineshaft = false; } else { do { CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.City, 0); } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea, intStartX, intStartZ, intSizeX, intSizeZ)); } bool booFound = false; if (RandomHelper.NextDouble() > 0.5) { intDistrict = Utils.RotateArray(intDistrict, RandomHelper.Next(4)); } int x, z = 0; for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSizeX && !booFound; x++) { for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSizeZ && !booFound; z++) { booFound = Utils.IsArraySectionAllZeros2D(intDistrict, x, z, x + CurrentBuilding.intSizeX, z + CurrentBuilding.intSizeZ); } } x--; z--; if (booFound) { for (int a = x + 1; a <= x + CurrentBuilding.intSizeX - 1; a++) { for (int b = z + 1; b <= z + CurrentBuilding.intSizeZ - 1; b++) { intDistrict[a, b] = 2; } } if (CurrentBuilding.booUnique && booUniqueBonus) { // we want to include the unique buildings, // so we give a slight preference to those intBonus += 15; } lstBuildings.Add(CurrentBuilding.intID); intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID; intDistrict[x + CurrentBuilding.intSizeX - 1, z + CurrentBuilding.intSizeZ - 1] = 100 + CurrentBuilding.intID; intFail = 0; } else { intFail++; } } while (intFail < 10); int intCurWasted = Utils.ZerosInArray2D(intDistrict) - intBonus; if (intCurWasted < intWasted) { intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)]; Array.Copy(intDistrict, intFinal, intDistrict.Length); intWasted = intCurWasted; intAttempts = 10; lstAcceptedBuildings.Clear(); lstAcceptedBuildings.AddRange(lstBuildings); } Array.Clear(intDistrict, 0, intDistrict.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = Utils.RotateArray(intFinal, 1); } _lstAllBuildings.AddRange(lstAcceptedBuildings); _booIncludedMineshaft = true; return(intFinal); }
public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart, int x1dest, int z1dest, Building bldInsert) { lstInstanceSigns.Clear(); int intHighestSourceY = 0; int intSourceX = 0, intSourceZ = 0; int intRotate = -1; for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++) { for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSize; 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.intSize + intDistance, z1dest + intCheck) == 1) { intRotate = 2; } else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSize + intDistance) == 1) { intRotate = 3; } } } if (intRotate == -1) { intRotate = RandomHelper.Next(4); } for (int x = 0; x < bldInsert.intSize; x++) { for (int z = 0; z < bldInsert.intSize; z++) { switch (intRotate) { case 0: intSourceX = x; intSourceZ = z; break; case 1: intSourceX = (bldInsert.intSize - 1) - z; intSourceZ = x; break; case 2: intSourceX = z; intSourceZ = (bldInsert.intSize - 1) - x; break; case 3: intSourceX = (bldInsert.intSize - 1) - x; intSourceZ = (bldInsert.intSize - 1) - z; break; } int intSourceEndY; for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--) { if (bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY, intSourceZ + bldInsert.intSourceZ) != (int)BlockType.AIR) { break; } } if (intSourceEndY > intHighestSourceY) { intHighestSourceY = intSourceEndY; } for (int y = bldInsert.intSourceStartY; y <= intSourceEndY; y++) { if (y != 64 || bmDest.GetID(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest) == (int)BlockType.AIR) { int intBlockID = bmSource.GetID(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); int intBlockData = bmSource.GetData(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); bmDest.SetID(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, intBlockID); bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, intBlockData); foreach (EntityPainting entPainting in AllEntityPainting) { if (entPainting.TileX == intSourceX + bldInsert.intSourceX && entPainting.TileY == y && entPainting.TileZ == intSourceZ + bldInsert.intSourceZ) { EntityPainting entNewPainting = (EntityPainting)entPainting.Copy(); entNewPainting.TileX = intBlockStart + x + x1dest; entNewPainting.TileY = y; 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(); } } #region Rotation if (intRotate > 0) { switch (intBlockID) { case (int)BlockType.SIGN_POST: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateSignPost(intBlockData, intRotate)); break; case (int)BlockType.STONE_BUTTON: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateButton(intBlockData, intRotate)); break; case (int)BlockType.PUMPKIN: case (int)BlockType.JACK_O_LANTERN: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotatePumpkin(intBlockData, intRotate)); break; case (int)BlockType.IRON_DOOR: case (int)BlockType.WOOD_DOOR: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateDoor(intBlockData, intRotate)); break; case (int)BlockType.TRAPDOOR: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateTrapdoor(intBlockData, intRotate)); break; case (int)BlockType.BED: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateBed(intBlockData, intRotate)); break; case (int)BlockType.REDSTONE_TORCH_OFF: case (int)BlockType.REDSTONE_TORCH_ON: case (int)BlockType.TORCH: case (int)BlockType.LEVER: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateTorchOrLever(intBlockData, intRotate)); break; case (int)BlockType.WALL_SIGN: case (int)BlockType.LADDER: case (int)BlockType.DISPENSER: case (int)BlockType.FURNACE: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser(intBlockData, intRotate)); break; case (int)BlockType.COBBLESTONE_STAIRS: case (int)BlockType.WOOD_STAIRS: bmDest.SetData(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, BlockHelper.RotateStairs(intBlockData, intRotate)); break; } } #endregion #region Handle entities switch (intBlockID) { case (int)BlockType.CHEST: TileEntityChest tec = (TileEntityChest)bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ); if (tec.Items[0] != null) { if (tec.Items[0].ID == ItemInfo.Paper.ID && tec.Items[0].Count == 3) { tec = MakeHouseChest(); } } bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, tec); break; case (int)BlockType.FURNACE: case (int)BlockType.MONSTER_SPAWNER: case (int)BlockType.NOTE_BLOCK: case (int)BlockType.JUKEBOX: case (int)BlockType.TRAPDOOR: bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, y, intSourceZ + bldInsert.intSourceZ)); break; case (int)BlockType.SIGN_POST: case (int)BlockType.WALL_SIGN: #region Determine sign text int intUniqueType = 0; TileEntitySign tes = (TileEntitySign)bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, y, 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 (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; } intFail++; 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 = BlockHelper.TextToSign(ConvertToSignText(strSignText)); tes.Text1 = strRandomSign[0]; tes.Text2 = strRandomSign[1]; tes.Text3 = strRandomSign[2]; tes.Text4 = strRandomSign[3]; } bmDest.SetTileEntity(intBlockStart + x + x1dest, y, intBlockStart + z + z1dest, tes); break; #endregion } #endregion } } } } }
public static void MakeFarms(BetaWorld world, BlockManager bm, int intFarmSize, int intMapSize) { AddMushroomFarms(bm, intFarmSize, intMapSize); int intFail = 0; int intFarms = 0; while (intFail <= 500) { int xlen = RandomHelper.Next(8, 26); int x1 = RandomHelper.Next(4, intMapSize - (4 + xlen)); int zlen = RandomHelper.Next(8, 26); int z1 = RandomHelper.Next(4, intMapSize - (4 + zlen)); if (!(x1 >= intFarmSize && z1 >= intFarmSize && x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize)) { bool booValid = true; for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++) { for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++) { // make sure it doesn't overlap with the spawn point or another farm if ((x == intMapSize / 2 && z == intMapSize - (intFarmSize - 10)) || bm.GetID(x, 63, z) != (int)BlockType.GRASS || bm.GetID(x, 64, z) != (int)BlockType.AIR) { booValid = false; intFail++; } } } if (booValid) { // first there is a 25% chance of a hill or pond // if not, for large farms, there is a 50% chance it'll be an orchard // if not, 25% are cactus, 50% are wheat and 25% are sugarcane FarmTypes curFarm; int intFarmType = RandomHelper.Next(100); if (xlen >= 10 && zlen >= 10 && intFarmType > 75) { if (RandomHelper.NextDouble() > 0.5) { curFarm = FarmTypes.Pond; MakePond(bm, x1, xlen, z1, zlen, false); } else { curFarm = FarmTypes.Hill; MakeHill(bm, x1, xlen, z1, zlen, false); } } else { intFarmType = RandomHelper.Next(100); if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50) { curFarm = FarmTypes.Orchard; xlen = ((int)((xlen - 1) / 5) * 5) + 1; zlen = ((int)((zlen - 1) / 5) * 5) + 1; } else { intFarmType = RandomHelper.Next(100); if (intFarmType > 75) { curFarm = FarmTypes.Cactus; } else if (intFarmType > 25) { curFarm = FarmTypes.Wheat; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } else { curFarm = FarmTypes.SugarCane; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } } } int intWallMaterial = RandomHelper.NextDouble() > 0.5 ? (int)BlockType.FENCE : (int)BlockType.LEAVES; switch (curFarm) { case FarmTypes.Hill: case FarmTypes.Pond: intWallMaterial = 0; break; case FarmTypes.SugarCane: case FarmTypes.Mushroom: if (RandomHelper.NextDouble() > 0.5) { intWallMaterial = 0; } break; case FarmTypes.Wheat: intWallMaterial = (int)BlockType.LEAVES; break; } switch (intWallMaterial) { case (int)BlockType.FENCE: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, (int)BlockType.FENCE, 0, -1); break; case (int)BlockType.LEAVES: // the saplings will all disappear if one of them is broken. // so we put wood beneath them to stop that happening BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen, (int)BlockType.WOOD, 0, -1); BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, (int)BlockType.LEAVES, 0, RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE, (int)LeafType.BIRCH)); break; } switch (curFarm) { case FarmTypes.Orchard: int intSaplingType = RandomHelper.RandomNumber(BlockHelper.SaplingBirch, BlockHelper.SaplingOak, BlockHelper.SaplingSpruce); for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5) { for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5) { bm.SetID(x, 63, z, (int)BlockType.GRASS); bm.SetID(x, 64, z, (int)BlockType.SAPLING); bm.SetData(x, 64, z, intSaplingType); } } break; case FarmTypes.Cactus: int intAttempts = 0; do { int xCactus = RandomHelper.Next(x1 + 1, x1 + xlen), zCactus = RandomHelper.Next(z1 + 1, z1 + zlen); bool booValidFarm = true; for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++) { for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++) { if (bm.GetID(xCheck, 64, zCheck) != (int)BlockType.AIR) { booValidFarm = false; } } } if (booValidFarm) { bm.SetID(xCactus, 64, zCactus, (int)BlockType.CACTUS); if (RandomHelper.NextDouble() > 0.5) { bm.SetID(xCactus, 65, zCactus, (int)BlockType.CACTUS); } } intAttempts++; }while (intAttempts < 100); break; case FarmTypes.Wheat: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, (int)BlockType.GLASS, 0, -1); BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, (int)BlockType.GLASS, 0); break; } for (int x = x1 + 1; x <= x1 + xlen - 1; x++) { for (int z = z1 + 1; z <= z1 + zlen - 1; z++) { switch (curFarm) { case FarmTypes.Cactus: bm.SetID(x, 63, z, (int)BlockType.SAND); break; case FarmTypes.Wheat: if (z == z1 + 1) { bm.SetID(x, 63, z, (int)BlockType.DOUBLE_SLAB); } else if (x % 2 == 0) { bm.SetID(x, 63, z, (int)BlockType.FARMLAND); bm.SetData(x, 63, z, 1); bm.SetID(x, 64, z, (int)BlockType.CROPS); } else { bm.SetID(x, 63, z, (int)BlockType.STATIONARY_WATER); } break; case FarmTypes.SugarCane: if (z != z1 + 1) { if (x % 2 == 0) { bm.SetID(x, 64, z, (int)BlockType.SUGAR_CANE); if (RandomHelper.Next(100) > 50) { bm.SetID(x, 65, z, (int)BlockType.SUGAR_CANE); } } else { bm.SetID(x, 63, z, (int)BlockType.STATIONARY_WATER); } } break; } } } int d = RandomHelper.Next(x1 + 1, x1 + xlen - 1); if (curFarm == FarmTypes.Wheat) { bm.SetID(d, 63, z1, (int)BlockType.DOUBLE_SLAB); } if (intWallMaterial != 0) { bm.SetID(d, 64, z1, (int)BlockType.WOOD_DOOR); bm.SetData(d, 64, z1, 4); bm.SetID(d, 65, z1, (int)BlockType.WOOD_DOOR); bm.SetData(d, 65, z1, 4 + (int)DoorState.TOPHALF); } intFail = 0; intFarms++; if (intFarms % 10 == 0) { world.Save(); } } } } MakeMiniPondsAndHills(world, bm, intFarmSize, intMapSize); MakeFlowers(bm, intFarmSize, intMapSize); }
private static 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 static void MakeFarms(BetaWorld world, BlockManager bm, int intFarmLength, int intMapLength) { AddBuildings(bm, intFarmLength, intMapLength); int intFail = 0; int intFarms = 0; while (intFail <= 500) { int xlen = RandomHelper.Next(8, 26); int x1 = RandomHelper.Next(4, intMapLength - (4 + xlen)); int zlen = RandomHelper.Next(8, 26); int z1 = RandomHelper.Next(4, intMapLength - (4 + zlen)); if (!(x1 >= intFarmLength && z1 >= intFarmLength && x1 <= intMapLength - intFarmLength && z1 <= intMapLength - intFarmLength)) { bool booValid = true; for (int x = x1 - 2; x <= x1 + xlen + 2 && booValid; x++) { for (int z = z1 - 2; z <= z1 + zlen + 2 && booValid; z++) { // make sure it doesn't overlap with the spawn point or another farm if ((x == intMapLength / 2 && z == intMapLength - (intFarmLength - 10)) || bm.GetID(x, 63, z) != BlockType.GRASS || bm.GetID(x, 64, z) != BlockType.AIR) { booValid = false; intFail++; } } } if (booValid) { // first there is a 25% chance of a hill or pond // if not, for large farms, there is a 50% chance it'll be an orchard // if not, 33% are cactus, 33% are wheat and 33% are sugarcane FarmTypes curFarm; int intFarmType = RandomHelper.Next(100); if (xlen >= 10 && zlen >= 10 && intFarmType > 75) { if (RandomHelper.NextDouble() > 0.5) { curFarm = FarmTypes.Pond; MakePond(bm, x1, xlen, z1, zlen, false); } else { curFarm = FarmTypes.Hill; MakeHill(bm, x1, xlen, z1, zlen, false); } } else { intFarmType = RandomHelper.Next(100); if (((xlen >= 11 && zlen >= 16) || (xlen >= 16 && zlen >= 11)) && intFarmType > 50) { curFarm = FarmTypes.Orchard; xlen = ((int)((xlen - 1) / 5) * 5) + 1; zlen = ((int)((zlen - 1) / 5) * 5) + 1; } else { intFarmType = RandomHelper.Next(3); if (intFarmType == 2) { curFarm = FarmTypes.Cactus; } else if (intFarmType == 1) { curFarm = FarmTypes.Wheat; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } else { curFarm = FarmTypes.SugarCane; xlen += (xlen % 2) - 1; zlen += (zlen % 2) - 1; } } } int intWallMaterial = RandomHelper.NextDouble() > 0.5 ? BlockType.FENCE : BlockType.LEAVES; switch (curFarm) { case FarmTypes.Hill: case FarmTypes.Pond: intWallMaterial = 0; break; case FarmTypes.SugarCane: case FarmTypes.Mushroom: if (RandomHelper.NextDouble() > 0.5) { intWallMaterial = 0; } break; case FarmTypes.Wheat: intWallMaterial = BlockType.LEAVES; break; // no need for default - the other types don't need anything here } switch (intWallMaterial) { case BlockType.FENCE: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 64, z1, z1 + zlen, BlockType.FENCE, 0, -1); break; case BlockType.LEAVES: // the saplings will all disappear if one of them is broken. // so we put wood beneath them to stop that happening BlockShapes.MakeHollowLayers(x1, x1 + xlen, 63, 63, z1, z1 + zlen, BlockType.WOOD, 0, -1); BlockShapes.MakeHollowLayers(x1, x1 + xlen, 64, 65, z1, z1 + zlen, BlockType.LEAVES, 0, RandomHelper.RandomNumber((int)LeafType.OAK, (int)LeafType.SPRUCE, (int)LeafType.BIRCH)); break; case 0: // no wall break; default: Debug.Fail("Invalid switch result"); break; } switch (curFarm) { case FarmTypes.Orchard: int intSaplingType = RandomHelper.RandomNumber(SaplingBirchDataID, SaplingOakDataID, SaplingSpruceDataID); for (int x = x1 + 3; x <= x1 + xlen - 3; x += 5) { for (int z = z1 + 3; z <= z1 + zlen - 3; z += 5) { bm.SetID(x, 63, z, BlockType.GRASS); BlockShapes.MakeBlock(x, 64, z, BlockType.SAPLING, intSaplingType); } } break; case FarmTypes.Cactus: int intAttempts = 0; do { int xCactus = RandomHelper.Next(x1 + 1, x1 + xlen); int zCactus = RandomHelper.Next(z1 + 1, z1 + zlen); bool booValidFarm = true; for (int xCheck = xCactus - 1; xCheck <= xCactus + 1 && booValidFarm; xCheck++) { for (int zCheck = zCactus - 1; zCheck <= zCactus + 1 && booValidFarm; zCheck++) { if (bm.GetID(xCheck, 64, zCheck) != BlockType.AIR) { booValidFarm = false; } } } if (booValidFarm) { bm.SetID(xCactus, 64, zCactus, BlockType.CACTUS); if (RandomHelper.NextDouble() > 0.5) { bm.SetID(xCactus, 65, zCactus, BlockType.CACTUS); } } }while (++intAttempts < 100); break; case FarmTypes.Wheat: BlockShapes.MakeHollowLayers(x1, x1 + xlen, 66, 66, z1, z1 + zlen, BlockType.GLASS, 0, -1); BlockShapes.MakeSolidBox(x1 + 1, x1 + xlen - 1, 67, 67, z1 + 1, z1 + zlen - 1, BlockType.GLASS, 0); break; // no need for a default, because there's nothing to do for the other farms } for (int x = x1 + 1; x <= x1 + xlen - 1; x++) { for (int z = z1 + 1; z <= z1 + zlen - 1; z++) { switch (curFarm) { case FarmTypes.Cactus: bm.SetID(x, 63, z, BlockType.SAND); break; case FarmTypes.Wheat: if (z == z1 + 1) { bm.SetID(x, 63, z, BlockType.DOUBLE_SLAB); } else if (x % 2 == 0) { BlockShapes.MakeBlock(x, 63, z, BlockType.FARMLAND, 1); bm.SetID(x, 64, z, BlockType.CROPS); } else { bm.SetID(x, 63, z, BlockType.STATIONARY_WATER); } break; case FarmTypes.SugarCane: if (z != z1 + 1) { if (x % 2 == 0) { bm.SetID(x, 64, z, BlockType.SUGAR_CANE); if (RandomHelper.Next(100) > 50) { bm.SetID(x, 65, z, BlockType.SUGAR_CANE); } } else { bm.SetID(x, 63, z, BlockType.STATIONARY_WATER); } } break; // no need for a default, because there's nothing to do for the other farms } } } int intDoorPosition = x1 + RandomHelper.Next(1, xlen - 1); if (curFarm == FarmTypes.Wheat) { bm.SetID(intDoorPosition, 63, z1, BlockType.DOUBLE_SLAB); } if (intWallMaterial != 0) { BlockShapes.MakeBlock(intDoorPosition, 64, z1, BlockType.WOOD_DOOR, 4); BlockShapes.MakeBlock(intDoorPosition, 65, z1, BlockType.WOOD_DOOR, 4 + (int)DoorState.TOPHALF); } intFail = 0; if (++intFarms > 10) { world.Save(); intFarms = 0; } } } } MakeMiniPondsAndHills(world, bm, intFarmLength, intMapLength); MakeFlowers(bm, intFarmLength, intMapLength); }
public static void 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."); }
private static void MakeHill(BlockManager bm, int x, int xlen, int z, int zlen, bool booMini) { int[,] intArea = new int[xlen, zlen]; int a, b; int c = 0, d = 0, clen = -1, dlen = -1; if (!booMini) { c = RandomHelper.Next(1, intArea.GetUpperBound(0) - 7); d = RandomHelper.Next(1, intArea.GetUpperBound(1) - 7); clen = RandomHelper.Next(3, 7); dlen = RandomHelper.Next(3, 7); } for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { if (a < c || a > c + clen || b < d || b > d + dlen) { intArea[a, b] = 1; } } } intArea = CheckAgainstNeighbours(intArea, 0, 0, 7, 0, RandomHelper.Next(7, 11), true); intArea = CheckAgainstNeighbours(intArea, 6, 0, 3, 2, 1, false); intArea = CheckAgainstNeighbours(intArea, 14, 0, 3, 3, 1, false); for (a = 1; a <= intArea.GetUpperBound(0) - 1; a++) { for (b = 1; b <= intArea.GetUpperBound(1) - 1; b++) { for (int y = 1; y <= intArea[a, b]; y++) { if (y == intArea[a, b]) { bm.SetID(x + a, y + 63, z + b, BlockType.GRASS); switch (RandomHelper.Next(0, 10)) { case 0: bm.SetID(x + a, y + 64, z + b, BlockType.RED_ROSE); break; case 1: bm.SetID(x + a, y + 64, z + b, BlockType.YELLOW_FLOWER); break; case 2: case 3: bm.SetID(x + a, y + 64, z + b, BlockType.TALL_GRASS); bm.SetData(x + a, y + 64, z + b, RandomHelper.Next(1, 3)); break; // we want to skip the other numbers, so there's no need for a default } } else { bm.SetID(x + a, y + 63, z + b, BlockType.DIRT); } } } } }