private static int[,] AddMineshaftSections(int[,] intAreaOverview, int intDepth) { int intFail = 0; int intPlaced = 0; int intSections = 0; List <int> lstBuildings = new List <int>(); foreach (int intSection in intAreaOverview) { intSections += intSection; } do { SourceWorld.Building bldMineshaftFeature = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.MineshaftSection, intDepth); if (!bldMineshaftFeature.booUnique || !lstBuildings.Contains(bldMineshaftFeature.intID)) { structPoint spPlace = MatchPatternInArray(intAreaOverview, bldMineshaftFeature.strPattern.Split(' ')); if (spPlace.x == -1) { intFail++; } else { Debug.WriteLine("Adding " + bldMineshaftFeature.strName); int intPosX = bldMineshaftFeature.intPosX; int intPosZ = bldMineshaftFeature.intPosZ; int intSizeX = (bldMineshaftFeature.intSizeX - 1) / 6; int intSizeZ = (bldMineshaftFeature.intSizeZ - 1) / 6; if (spPlace.x >= 0) { for (int x = 0; x < intSizeX; x++) { for (int z = 0; z < intSizeZ; z++) { intAreaOverview[spPlace.x + intPosX + x, spPlace.z + intPosZ + z] = 100 + bldMineshaftFeature.intID; } } intPlaced++; if (bldMineshaftFeature.booUnique) { lstBuildings.Add(bldMineshaftFeature.intID); } } } } } while (intFail < 10 && intPlaced < intSections / 15); return(intAreaOverview); }
public static void MakeEntrances(BlockManager bm) { if (City.HasWalls) { SourceWorld.Building CurrentBuilding; CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.CityEntrance, 0); SourceWorld.InsertBuilding(bm, new int[0, 0], 0, (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2), City.EdgeLength + 5, CurrentBuilding, 0, 0); SourceWorld.InsertBuilding(bm, new int[0, 0], 0, City.EdgeLength + 5, (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2), CurrentBuilding, 0, 1); SourceWorld.InsertBuilding(bm, new int[0, 0], 0, City.MapLength - (City.EdgeLength + 4 + CurrentBuilding.intSizeX), (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2), CurrentBuilding, 0, 2); SourceWorld.InsertBuilding(bm, new int[0, 0], 0, (City.MapLength / 2) - (CurrentBuilding.intSizeX / 2), City.MapLength - (City.EdgeLength + 4 + CurrentBuilding.intSizeX), CurrentBuilding, 0, 3); } }
private static void AddBuilding(BlockManager bm, int intBuildingID) { bool booAddedBuilding = false; SourceWorld.Building bldInsert = SourceWorld.GetBuilding(intBuildingID); int intLen = bldInsert.intSizeX; bool booValid; int FailCounter = 0; do { booValid = false; int x1 = RandomHelper.Next(3, City.MapLength - (3 + intLen)); int z1 = RandomHelper.Next(3, City.MapLength - (3 + intLen)); if (!(x1 >= City.FarmLength && z1 >= City.FarmLength && x1 <= City.MapLength - City.FarmLength && z1 <= City.MapLength - City.FarmLength)) { 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 == City.MapLength / 2 && z == SpawnZ) || bm.GetID(x, 63, z) != City.GroundBlockID || bm.GetID(x, 64, z) != BlockInfo.Air.ID || bm.GetID(x, 53, z) == BlockInfo.Air.ID) { booValid = false; } } } } if (booValid) { SourceWorld.InsertBuilding(bm, new int[City.MapLength, City.MapLength], 0, x1, z1, bldInsert, 0); booAddedBuilding = true; FailCounter = 0; } else { FailCounter++; } } while (!booAddedBuilding && FailCounter <= 500); }
private static structPoint MakeBuildings(BlockManager bm, int[,] intArea, int intBlockStart, BetaWorld world) { structPoint structLocationOfMineshaftEntrance = new structPoint(); structLocationOfMineshaftEntrance.x = -1; structLocationOfMineshaftEntrance.z = -1; int intBuildings = 0; for (int x = 0; x < intArea.GetLength(0); x++) { for (int z = 0; z < intArea.GetLength(1); z++) { // hack low: this 100 to 500 stuff is all a bit hackish really, need to find a proper solution if (intArea[x, z] >= 100 && intArea[x, z] <= 500) { SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100); SourceWorld.InsertBuilding(bm, intArea, intBlockStart, x, z, CurrentBuilding, 0); if (CurrentBuilding.btThis == SourceWorld.BuildingTypes.MineshaftEntrance) { structLocationOfMineshaftEntrance.x = intBlockStart + x + (int)(CurrentBuilding.intSizeX / 2); structLocationOfMineshaftEntrance.z = intBlockStart + z + (int)(CurrentBuilding.intSizeZ / 2); if (City.HasSkyFeature) { SourceWorld.Building BalloonBuilding = SourceWorld.GetBuilding("Sky Feature"); SourceWorld.InsertBuilding(bm, new int[0, 0], intBlockStart, x + ((CurrentBuilding.intSizeX - BalloonBuilding.intSizeX) / 2), z + ((CurrentBuilding.intSizeZ - BalloonBuilding.intSizeZ) / 2), BalloonBuilding, 0); } } intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0; if (++intBuildings == NumberOfBuildingsBetweenSaves) { world.Save(); intBuildings = 0; } } } } world.Save(); return(structLocationOfMineshaftEntrance); }
private static void AddBuildings(BlockManager bm, int intFarmLength, int intMapLength) { SourceWorld.Building CurrentBuilding; List <int> lstAllFarmingBuildings = new List <int>(); int intBuildings = 0; do { do { CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.Farming, 0); } while (lstAllFarmingBuildings.Contains(CurrentBuilding.intID)); AddBuilding(bm, intFarmLength, intMapLength, CurrentBuilding.intID); if (CurrentBuilding.booUnique) { lstAllFarmingBuildings.Add(CurrentBuilding.intID); } } while (++intBuildings < Math.Max(1, (intMapLength / 16) / 2)); }
private void picMace_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { string strNames = ""; for (int x = 0; x < 50; x++) { strNames += "City of " + RandomHelper.RandomFileLine("Resources\\CityStartingWords.txt") + RandomHelper.RandomFileLine("Resources\\CityEndingWords.txt") + "\r\n"; } MessageBox.Show(strNames); } else { #if DEBUG MessageBox.Show(SourceWorld.ConvertToSignText("[the writing is hidden behind vines]")); #endif } }
private static void AddBuilding(BlockManager bm, int intFarmLength, int intMapLength, int intBuildingID) { bool booAddedBuilding = false; SourceWorld.Building bldInsert = SourceWorld.GetBuilding(intBuildingID); int intLen = bldInsert.intSizeX; bool booValid; do { booValid = false; int x1 = RandomHelper.Next(2, intMapLength - (2 + intLen)); int z1 = RandomHelper.Next(2, intMapLength - (2 + intLen)); if (!(x1 >= intFarmLength && z1 >= intFarmLength && x1 <= intMapLength - intFarmLength && z1 <= intMapLength - intFarmLength)) { 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 == intMapLength / 2 && z == intMapLength - (intFarmLength - 10)) || bm.GetID(x, 63, z) != BlockType.GRASS || bm.GetID(x, 64, z) != BlockType.AIR || bm.GetID(x, 53, z) == BlockType.AIR) { booValid = false; } } } } if (booValid) { SourceWorld.InsertBuilding(bm, new int[intMapLength, intMapLength], 0, x1, z1, bldInsert, 0); booAddedBuilding = true; } } while (!booAddedBuilding); }
// this is a simplified version of the MakeBuildings method from Buildings.cs private static void MakeBuildings(BlockManager bm, int[,] intArea, BetaWorld world) { int intBuildings = 0; for (int x = 0; x < intArea.GetLength(0); x++) { for (int z = 0; z < intArea.GetLength(1); z++) { // hack low: this 100 to 500 stuff is all a bit hackish really, need to find a proper solution if (intArea[x, z] >= 100 && intArea[x, z] <= 500) { SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100); if (CurrentBuilding.intSizeX >= 10 && RNG.NextDouble() > 0.8) { if (RNG.NextDouble() > 0.5) { MakePond(bm, 6 + x, CurrentBuilding.intSizeX, (6 - City.FarmLength) + z, CurrentBuilding.intSizeZ); } else { MakeHill(bm, 6 + x, CurrentBuilding.intSizeX, (6 - City.FarmLength) + z, CurrentBuilding.intSizeZ); } } else { SourceWorld.InsertBuilding(bm, intArea, 0, 6 + x, (6 - City.FarmLength) + z, CurrentBuilding, 0, -1); } intArea[x + CurrentBuilding.intSizeX - 2, z + CurrentBuilding.intSizeZ - 2] = 0; if (++intBuildings == NumberOfBuildingsBetweenSaves) { world.Save(); intBuildings = 0; } } } } }
private static void AddMushroomFarms(BlockManager bm, int intFarmSize, int intMapSize) { SourceWorld.Building bldMushroomFarm = SourceWorld.GetBuilding("Mushroom Farm"); int len = bldMushroomFarm.intSize; int intMushroomFarms = (intMapSize / 16) / 5; bool booValid = false; do { booValid = false; int x1 = rand.Next(2, intMapSize - (2 + len)); int z1 = rand.Next(2, intMapSize - (2 + len)); if (!(x1 >= intFarmSize && z1 >= intFarmSize && x1 <= intMapSize - intFarmSize && z1 <= intMapSize - intFarmSize)) { booValid = true; for (int x = x1 - 2; x <= x1 + len + 2 && booValid; x++) { for (int z = z1 - 2; z <= z1 + len + 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, 0, x1, z1, bldMushroomFarm); intMushroomFarms--; } } while (intMushroomFarms > 0); }
private static void MakeBuildings(int[,] intArea, int intBlockStart, BetaWorld world, int intFarmSize) { int intBuildings = 0; for (int x = 0; x < intArea.GetLength(0); x++) { for (int z = 0; z < intArea.GetLength(1); z++) { if (intArea[x, z] >= 100 && intArea[x, z] <= 500) { SourceWorld.Building CurrentBuilding = SourceWorld.GetBuilding(intArea[x, z] - 100); SourceWorld.InsertBuilding(bmDest, intBlockStart, x, z, CurrentBuilding); intArea[x + CurrentBuilding.intSize - 2, z + CurrentBuilding.intSize - 2] = 0; if (++intBuildings == 20) { world.Save(); intBuildings = 0; } } } } }
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); }
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 bool IsValidBuilding(SourceWorld.Building bldCheck, List <int> lstBuildings, int[,] intArea, int intStartX, int intStartZ, int intSizeX, int intSizeZ) { if (bldCheck.booUnique) { if (_lstAllBuildings.Contains(bldCheck.intID) || lstBuildings.Contains(bldCheck.intID)) { return(false); } else { foreach (int intID in lstBuildings) { if (SourceWorld.GetBuilding(intID).booUnique) { return(false); } } for (int x = intStartX - 8; x < intStartX + intSizeX + 8; x++) { for (int z = intStartZ - 8; z < intStartZ + intSizeZ + 8; z++) { if (x >= 0 && z >= 0 && x <= intArea.GetUpperBound(0) && z <= intArea.GetUpperBound(1)) { if (intArea[x, z] >= 100) { if (SourceWorld.GetBuilding(intArea[x, z] - 100).booUnique) { return(false); } } } } } return(true); } } else { switch (bldCheck.strFrequency) { case "very common": case "common": return(true); case "average": case "rare": case "very rare": // this exists to avoid infite loops if (RNG.NextDouble() > 0.975) { return(true); } if (lstBuildings.Contains(bldCheck.intID)) { return(false); } else { int intDistance = 0; switch (bldCheck.strFrequency) { case "average": intDistance = 12; break; case "rare": intDistance = 25; break; case "very rare": intDistance = 50; break; } for (int x = intStartX - intDistance; x < intStartX + intSizeX + intDistance; x++) { for (int z = intStartZ - intDistance; z < intStartZ + intSizeZ + intDistance; z++) { if (x >= 0 && z >= 0 && x <= intArea.GetUpperBound(0) && z <= intArea.GetUpperBound(1)) { if (intArea[x, z] - 100 == bldCheck.intID) { return(false); } } } } return(true); } // should never get here to either of these, but just in case case "exclude": Debug.WriteLine("Excluded buildings are not allowed here"); return(false); default: Debug.WriteLine("Unknown frequency type encountered"); return(false); } } }
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 (RNG.NextDouble() > 0.5) { intDistrict = intDistrict.RotateArray(RNG.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 = intDistrict.IsArraySectionAllZeros2D(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 = intFinal.RotateArray(1); } _lstAllBuildings.AddRange(lstAcceptedBuildings); _booIncludedMineshaft = true; return(intFinal); }
private static void MakeLevel(BetaWorld world, BlockManager bm, int intDepth, int intMineshaftSize, Buildings.structPoint spMineshaftEntrance) { Debug.WriteLine("----- Mineshaft Level " + intDepth + " -----"); string[] strResourceNames = Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "names").Split(','); int[] intResourceChances = Utils.StringArrayToIntArray(Utils.ValueFromXMLElement( Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "chances").Split(',')); int intTorchChance = Convert.ToInt32(Utils.ValueFromXMLElement(Path.Combine("Resources", "Mineshaft.xml"), "level" + intDepth, "torch_chance")); int[,] intAreaFull = new int[intMineshaftSize + (MULTIPLIER * 2), intMineshaftSize + (MULTIPLIER * 2)]; int intXPosOriginal = spMineshaftEntrance.x - _intBlockStartBuildings; int intZPosOriginal = spMineshaftEntrance.z - _intBlockStartBuildings; _intBlockStartBuildings -= 2; int[,] intAreaOverview = new int[(intAreaFull.GetLength(0) / MULTIPLIER), (intAreaFull.GetLength(1) / MULTIPLIER)]; int intXPos = intXPosOriginal / MULTIPLIER; int intZPos = intZPosOriginal / MULTIPLIER; intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Air; CreateRouteXPlus(intAreaOverview, intXPos + 1, intZPos, 0); CreateRouteZPlus(intAreaOverview, intXPos, intZPos + 1, 1); CreateRouteXMinus(intAreaOverview, intXPos - 1, intZPos, 2); CreateRouteZMinus(intAreaOverview, intXPos, intZPos - 1, 3); int intOffsetX = (intXPosOriginal - (intXPos * MULTIPLIER)) - 2; int intOffsetZ = (intZPosOriginal - (intZPos * MULTIPLIER)) - 2; List <structSection> lstSections = new List <structSection>(); intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Placeholder; intAreaOverview = AddMineshaftSections(intAreaOverview, intDepth); intAreaOverview[intXPos, intZPos] = (int)MineshaftBlocks.Air; for (int x = 0; x < intAreaOverview.GetLength(0); x++) { for (int z = 0; z < intAreaOverview.GetLength(1); z++) { if (intAreaOverview[x, z] >= 100) { structSection structCurrentSection = new structSection(); structCurrentSection.bldMineshaftSection = SourceWorld.GetBuilding(intAreaOverview[x, z] - 100); structCurrentSection.x = ((x * MULTIPLIER) + intOffsetX) - 1; structCurrentSection.z = ((z * MULTIPLIER) + intOffsetZ) - 1; for (int x2 = x; x2 <= x + (structCurrentSection.bldMineshaftSection.intSizeX - 1) / 7; x2++) { for (int z2 = z; z2 <= z + (structCurrentSection.bldMineshaftSection.intSizeZ - 1) / 7; z2++) { if (intAreaOverview[x2, z2] == structCurrentSection.bldMineshaftSection.intID + 100) { intAreaOverview[x2, z2] = (int)MineshaftBlocks.Structure; } } } lstSections.Add(structCurrentSection); } } } for (int x = 4; x < intAreaFull.GetLength(0) - 4; x++) { for (int z = 4; z < intAreaFull.GetLength(1) - 4; z++) { if (intAreaOverview.GetLength(0) > x / MULTIPLIER && intAreaOverview.GetLength(1) > z / MULTIPLIER) { if (intAreaFull[x + intOffsetX, z + intOffsetZ] < 4) { intAreaFull[x + intOffsetX, z + intOffsetZ] = intAreaOverview[x / MULTIPLIER, z / MULTIPLIER]; } } if ((x + 3) % 5 == 0 && (z + 3) % 5 == 0 && intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air) { if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] >= 100) { for (int x2 = 0; x2 < 5; x2++) { intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Structure; } } if (intAreaOverview[(x / MULTIPLIER) + 1, z / MULTIPLIER] == (int)MineshaftBlocks.Air) { for (int x2 = 0; x2 < 5; x2++) { if (x2 == 1 || x2 == 3) { intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.CeilingSupport; intAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.CeilingSupport; } else { intAreaFull[x + intOffsetX + 3, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Support; intAreaFull[x + intOffsetX + 2, z + intOffsetZ + x2 - 2] = (int)MineshaftBlocks.Support; } } for (int x2 = 0; x2 <= 5; x2++) { if (intAreaFull[x + intOffsetX + x2, z + intOffsetZ] == (int)MineshaftBlocks.Support) { intAreaFull[x + intOffsetX + x2, z + intOffsetZ] = (int)MineshaftBlocks.RailWithSupport; } else { intAreaFull[x + intOffsetX + x2, z + intOffsetZ] = (int)MineshaftBlocks.Rail; } } } if (intAreaOverview[x / MULTIPLIER, (z / MULTIPLIER) + 1] == (int)MineshaftBlocks.Air) { for (int z2 = 0; z2 < 5; z2++) { if (z2 == 1 || z2 == 3) { intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = (int)MineshaftBlocks.CeilingSupport; intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = (int)MineshaftBlocks.CeilingSupport; } else { intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 3] = (int)MineshaftBlocks.Support; intAreaFull[x + intOffsetX + z2 - 2, z + intOffsetZ + 2] = (int)MineshaftBlocks.Support; } } for (int z2 = 0; z2 <= 5; z2++) { if (intAreaFull[x + intOffsetX, z + intOffsetZ + z2] == (int)MineshaftBlocks.Support) { intAreaFull[x + intOffsetX, z + intOffsetZ + z2] = (int)MineshaftBlocks.RailWithSupport; } else { intAreaFull[x + intOffsetX, z + intOffsetZ + z2] = (int)MineshaftBlocks.Rail; } } } if (intAreaOverview[x / MULTIPLIER, z / MULTIPLIER] == (int)MineshaftBlocks.Air) { MakeChestAndOrTorch(intAreaOverview, intAreaFull, (x - 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX - 2, z + intOffsetZ); MakeChestAndOrTorch(intAreaOverview, intAreaFull, (x + 3) / MULTIPLIER, z / MULTIPLIER, x + intOffsetX + 2, z + intOffsetZ); MakeChestAndOrTorch(intAreaOverview, intAreaFull, x / MULTIPLIER, (z - 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ - 2); MakeChestAndOrTorch(intAreaOverview, intAreaFull, x / MULTIPLIER, (z + 3) / MULTIPLIER, x + intOffsetX, z + intOffsetZ + 2); } } } } intAreaFull[intXPosOriginal, intZPosOriginal] = (int)MineshaftBlocks.EntranceSection; int intSupportMaterial = RandomHelper.RandomNumber(BlockType.WOOD, BlockType.WOOD_PLANK, BlockType.FENCE); for (int x = 0; x < intAreaFull.GetLength(0); x++) { for (int z = 0; z < intAreaFull.GetLength(1); z++) { if (intDepth <= 4) { if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.GRAVEL) { bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockType.STONE); } } if (intDepth <= 2) { if (bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.SAND || bm.GetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings) == BlockType.SANDSTONE) { bm.SetID(x + _intBlockStartBuildings, 42 - (5 * intDepth), z + _intBlockStartBuildings, BlockType.DIRT); } } switch (intAreaFull[x, z]) { case (int)MineshaftBlocks.NaturalTerrain: break; case (int)MineshaftBlocks.Air: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } break; case (int)MineshaftBlocks.EntranceSection: case (int)MineshaftBlocks.Rail: for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 38 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.GRAVEL); } else if (y == 39 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.RAILS); } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } } break; case (int)MineshaftBlocks.RailWithSupport: for (int y = 38 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 38 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.GRAVEL); } else if (y == 39 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.RAILS); } else if (y == 40 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intSupportMaterial); } } break; case (int)MineshaftBlocks.Support: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intSupportMaterial); } break; case (int)MineshaftBlocks.ChestAndOrTorch: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 39 - (5 * intDepth) && RandomHelper.NextDouble() > 0.9) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.CHEST); MakeChestItems(bm, x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intResourceChances, strResourceNames); } else if (y == 41 - (5 * intDepth) && RandomHelper.NextDouble() < (double)intTorchChance / 100) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.TORCH); if (intAreaFull[x - 1, z] == 0) { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 1); } else if (intAreaFull[x + 1, z] == 0) { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 2); } else if (intAreaFull[x, z - 1] == 0) { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 3); } else { bm.SetData(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, 4); } } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } } break; case (int)MineshaftBlocks.CeilingSupport: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * intDepth); y++) { if (y == 41 - (5 * intDepth)) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, intSupportMaterial); } else { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } } break; case (int)MineshaftBlocks.Unused9: for (int y = 39 - (5 * intDepth); y <= 41 - (5 * (intDepth - 1)); y++) { bm.SetID(x + _intBlockStartBuildings, y, z + _intBlockStartBuildings, BlockType.AIR); } break; case (int)MineshaftBlocks.Structure: // this will be overwritten later break; default: Debug.Fail("Invalid switch result"); break; } } } foreach (structSection MineshaftSection in lstSections) { SourceWorld.InsertBuilding(bm, new int[0, 0], _intBlockStartBuildings, MineshaftSection.x, MineshaftSection.z, MineshaftSection.bldMineshaftSection, 38 - (5 * intDepth)); } world.Save(); _intBlockStartBuildings += 2; //#if DEBUG // File.WriteAllText("output_area_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaOverview)); // File.WriteAllText("output_map_" + intDepth + ".txt", Utils.TwoDimensionalArrayToString(intAreaFull)); //#endif }
public static void Generate(frmMace frmLogForm, BetaWorld worldDest, BetaChunkManager cmDest, BlockManager bmDest, int x, int z, bool booExportSchematics, string strUndergroundOres) { #region create a city name string strStart, strEnd; do { strStart = RNG.RandomFileLine(Path.Combine("Resources", City.CityNamePrefixFilename)); strEnd = RNG.RandomFileLine(Path.Combine("Resources", City.CityNameSuffixFilename)); City.Name = City.CityNamePrefix + strStart + strEnd; } while (GenerateWorld.lstCityNames.Contains(City.Name) || strStart.ToLower().Trim() == strEnd.ToLower().Trim() || (strStart + strEnd).Length > 14); GenerateWorld.lstCityNames.Add(City.Name); #endregion #region determine block sizes City.CityLength *= 16; City.FarmLength *= 16; City.EdgeLength = 8; City.MapLength = City.CityLength + (City.EdgeLength * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest); BlockHelper.SetupClass(bmDest); NoticeBoard.SetupClass(); if (!SourceWorld.SetupClass(worldDest)) { return; } #endregion #region determine random options switch (City.WallMaterialID) { case BlockType.WOOD_PLANK: case BlockType.WOOD: case BlockType.LEAVES: case BlockType.VINES: case BlockType.WOOL: case BlockType.BOOKSHELF: switch (City.OutsideLightType) { case "Fire": frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true); City.OutsideLightType = "Torches"; break; } switch (City.MoatType) { case "Fire": case "Lava": frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true); City.MoatType = "Water"; break; } break; } switch (City.PathType.ToLower().Trim()) { case "stone_raised": City.PathBlockID = BlockInfo.DoubleSlab.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = BlockInfo.Slab.ID; City.PathAlternativeBlockData = 0; City.PathExtends = 2; break; case "sandstone_raised": City.PathBlockID = BlockInfo.Sandstone.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = BlockInfo.Slab.ID; City.PathAlternativeBlockData = 1; City.PathExtends = 2; break; case "woodplanks_raised": City.PathBlockID = BlockInfo.WoodPlank.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = BlockInfo.Slab.ID; City.PathAlternativeBlockData = 2; City.PathExtends = 2; break; case "cobblestone_raised": City.PathBlockID = BlockInfo.Cobblestone.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = BlockInfo.Slab.ID; City.PathAlternativeBlockData = 3; City.PathExtends = 2; break; case "brick_raised": City.PathBlockID = BlockInfo.BrickBlock.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = BlockInfo.Slab.ID; City.PathAlternativeBlockData = 4; City.PathExtends = 2; break; case "stonebrick_raised": City.PathBlockID = BlockInfo.StoneBrick.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = BlockInfo.Slab.ID; City.PathAlternativeBlockData = 5; City.PathExtends = 2; break; case "stonebrick": City.PathBlockID = BlockInfo.StoneBrick.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = 0; City.PathAlternativeBlockData = 0; City.PathExtends = 1; break; case "sandstone": City.PathBlockID = BlockInfo.Sandstone.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = 0; City.PathAlternativeBlockData = 0; City.PathExtends = 1; break; case "stone": City.PathBlockID = BlockInfo.Stone.ID; City.PathBlockData = 0; City.PathAlternativeBlockID = 0; City.PathAlternativeBlockData = 0; City.PathExtends = 1; break; case "wood": City.PathBlockID = BlockInfo.Wood.ID; City.PathBlockData = RNG.Next(0, 2); City.PathAlternativeBlockID = 0; City.PathAlternativeBlockData = 0; City.PathExtends = 1; break; } #endregion #region make the city frmLogForm.UpdateLog("Creating the " + City.Name, false, false); frmLogForm.UpdateLog("City length in blocks: " + City.MapLength, true, true); frmLogForm.UpdateLog("Edge length in blocks: " + City.EdgeLength, true, true); frmLogForm.UpdateLog("Farm length in blocks: " + City.FarmLength, true, true); frmLogForm.UpdateLog("City position in blocks: " + ((x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + "," + ((z + Chunks.CITY_RELOCATION_CHUNKS) * 16), true, true); frmLogForm.UpdateLog("Theme: " + City.ThemeName, true, true); frmLogForm.UpdateLog("Creating underground terrain", true, false); Chunks.CreateInitialChunks(cmDest, frmLogForm, strUndergroundOres); frmLogForm.UpdateProgress(0.21); Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint(); if (City.HasWalls) { frmLogForm.UpdateLog("Creating walls", true, false); Walls.MakeWalls(worldDest, frmLogForm); } frmLogForm.UpdateProgress(0.24); if (City.HasDrawbridges) { frmLogForm.UpdateLog("Creating entrances", true, false); Entrances.MakeEntrances(bmDest); } frmLogForm.UpdateProgress(0.27); if (City.HasMoat) { frmLogForm.UpdateLog("Creating moat", true, false); Moat.MakeMoat(frmLogForm, bmDest); } frmLogForm.UpdateProgress(0.30); if (City.HasBuildings || City.HasPaths) { frmLogForm.UpdateLog("Creating paths", true, false); frmLogForm.UpdateLog("Path type: " + City.PathType, true, true); int[,] intArea = Paths.MakePaths(worldDest, bmDest); frmLogForm.UpdateProgress(0.33); if (City.HasBuildings) { frmLogForm.UpdateLog("Creating buildings", true, false); spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, frmLogForm); frmLogForm.UpdateProgress(0.36); if (City.HasMineshaft) { frmLogForm.UpdateLog("Creating mineshaft", true, false); Mineshaft.MakeMineshaft(worldDest, bmDest, spMineshaftEntrance, frmLogForm); } } } frmLogForm.UpdateProgress(0.39); if (City.HasGuardTowers) { frmLogForm.UpdateLog("Creating guard towers", true, false); GuardTowers.MakeGuardTowers(bmDest, frmLogForm); } frmLogForm.UpdateProgress(0.42); if (City.HasFarms) { frmLogForm.UpdateLog("Creating farms", true, false); Farms2.MakeFarms(worldDest, bmDest); } frmLogForm.UpdateProgress(0.45); if (City.HasFlowers) { frmLogForm.UpdateLog("Creating flowers", true, false); Flowers.MakeFlowers(worldDest, bmDest); } frmLogForm.UpdateProgress(0.46); if (!City.HasValuableBlocks) { frmLogForm.UpdateLog("Replacing valuable blocks", true, true); cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest); } frmLogForm.UpdateProgress(0.48); frmLogForm.UpdateLog("Creating rail data", true, false); Chunks.PositionRails(worldDest, bmDest); frmLogForm.UpdateProgress(0.50); frmLogForm.UpdateLog("Creating lighting data", true, false); Chunks.ResetLighting(worldDest, cmDest, frmLogForm); frmLogForm.UpdateProgress(0.95); #endregion #region export schematic if (booExportSchematics) { frmLogForm.UpdateLog("Creating schematic in world folder", true, false); AlphaBlockCollection abcExport = new AlphaBlockCollection(City.MapLength, 128, City.MapLength + City.FarmLength); for (int xBlock = 0; xBlock < City.MapLength; xBlock++) { for (int zBlock = -City.FarmLength; zBlock < City.MapLength; zBlock++) { for (int y = 0; y < 128; y++) { abcExport.SetBlock(xBlock, y, City.FarmLength + zBlock, bmDest.GetBlock(xBlock, y, zBlock)); } } } Schematic CitySchematic = new Schematic(City.MapLength, 128, City.MapLength + City.FarmLength); CitySchematic.Blocks = abcExport; CitySchematic.Export(worldDest.Path + "\\" + City.Name + ".schematic"); } #endregion #region positioning frmLogForm.UpdateLog("Creating position data", true, false); Chunks.MoveChunks(worldDest, cmDest, x, z); frmLogForm.UpdateProgress(1); #endregion }
private static int[,] FillArea(int intSizeX, int intSizeY, int intStartX, int intStartZ) { int[,] intDist = new int[intSizeX, intSizeY]; int[,] intFinal = new int[intSizeX, intSizeY]; int intWasted = intSizeX * intSizeY, intAttempts = 15, intFail = 0; do { do { SourceWorld.Building CurrentBuilding = SourceWorld.SelectRandomBuilding(); bool booFound = false; if (rand.NextDouble() > 0.5) { intDist = RotateArray(intDist, -1); } int x, z = 0; for (x = 0; x < intDist.GetLength(0) - CurrentBuilding.intSize && !booFound; x++) { for (z = 0; z < intDist.GetLength(1) - CurrentBuilding.intSize && !booFound; z++) { booFound = IsFree(intDist, 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++) { intDist[a, b] = 2; } } intDist[x + 1, z + 1] = 100 + CurrentBuilding.intID; intDist[x + CurrentBuilding.intSize - 1, z + CurrentBuilding.intSize - 1] = 100 + CurrentBuilding.intID; intFail = 0; } else { intFail++; } } while (intFail < 10); int intCurWasted = SquaresWasted(intDist); if (intCurWasted < intWasted) { intFinal = new int[intDist.GetLength(0), intDist.GetLength(1)]; Array.Copy(intDist, intFinal, intDist.Length); intWasted = intCurWasted; intAttempts = 10; } Array.Clear(intDist, 0, intDist.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = RotateArray(intFinal, 1); } return(intFinal); }
private static bool IsValidBuilding(SourceWorld.Building bldCheck, List<int> lstBuildings, int[,] intArea, int intStartX, int intStartZ, int intSizeX, int intSizeZ) { if (bldCheck.booUnique) { if (_lstAllBuildings.Contains(bldCheck.intID) || lstBuildings.Contains(bldCheck.intID)) { return false; } else { foreach (int intID in lstBuildings) { if (SourceWorld.GetBuilding(intID).booUnique) { return false; } } for (int x = intStartX - 8; x < intStartX + intSizeX + 8; x++) { for (int z = intStartZ - 8; z < intStartZ + intSizeZ + 8; z++) { if (x >= 0 && z >= 0 && x <= intArea.GetUpperBound(0) && z <= intArea.GetUpperBound(1)) { if (intArea[x, z] >= 100) { if (SourceWorld.GetBuilding(intArea[x, z] - 100).booUnique) { return false; } } } } } return true; } } else { switch (bldCheck.strFrequency) { case "very common": case "common": return true; case "average": case "rare": case "very rare": if (lstBuildings.Contains(bldCheck.intID)) { return false; } else { int intDistance = 0; switch (bldCheck.strFrequency) { case "average": intDistance = 12; break; case "rare": intDistance = 25; break; case "very rare": intDistance = 50; break; } for (int x = intStartX - intDistance; x < intStartX + intSizeX + intDistance; x++) { for (int z = intStartZ - intDistance; z < intStartZ + intSizeZ + intDistance; z++) { if (x >= 0 && z >= 0 && x <= intArea.GetUpperBound(0) && z <= intArea.GetUpperBound(1)) { if (intArea[x, z] - 100 == bldCheck.intID) { return false; } } } } return true; } // should never get here to either of these, but just in case case "exclude": Debug.WriteLine("Excluded buildings are not allowed here"); return false; default: Debug.WriteLine("Unknown frequency type encountered"); return false; } } }
public static void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings, bool booIncludePaths, bool booIncludeMineshaft, bool booIncludeItemsInChests, bool booIncludeValuableBlocks, bool booIncludeGhostdancerSpawners, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strTowerAddition, string strWallMaterial, string strCitySeed, string strWorldSeed, bool booExportSchematic) { #region seed the random number generators int intCitySeed, intWorldSeed; Random randSeeds = new Random(); if (strCitySeed.Length == 0) { intCitySeed = randSeeds.Next(); frmLogForm.UpdateLog("Random city seed: " + intCitySeed); } else { intCitySeed = JavaStringHashCode(strCitySeed); frmLogForm.UpdateLog("Random city seed: " + strCitySeed); } if (strWorldSeed.Length == 0) { intWorldSeed = randSeeds.Next(); frmLogForm.UpdateLog("Random world seed: " + intWorldSeed); } else { intWorldSeed = JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Random world seed: " + strWorldSeed); } RandomHelper.SetSeed(intCitySeed); #endregion #region create minecraft world directory from a random unused city name string strFolder = String.Empty, strCityName = String.Empty; strUserCityName = SafeFilename(strUserCityName); if (strUserCityName.ToLower().Trim().Length == 0) { strUserCityName = "random"; } if (strUserCityName.ToLower().Trim() != "random") { if (Directory.Exists(Utils.GetMinecraftSavesDirectory(strUserCityName))) { if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists."); return; } } else { strCityName = strUserCityName; strFolder = Utils.GetMinecraftSavesDirectory(strCityName); } } if (strCityName.Length == 0) { string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt")); strEnd = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt")); strCityName = "City of " + strStart + strEnd; strFolder = Utils.GetMinecraftSavesDirectory(strCityName); } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder) || (strStart + strEnd).Length > 14); } Directory.CreateDirectory(strFolder); RandomHelper.SetSeed(intCitySeed); #endregion #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); BetaChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = RandomHelper.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; default: Debug.Fail("Invalid switch result"); break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmLength = booIncludeFarms ? 32 : 8; int intMapLength = intCitySize + (intFarmLength * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapLength); BlockHelper.SetupClass(bmDest, intMapLength); if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests, booIncludeGhostdancerSpawners)) { return; } NoticeBoard.SetupClass(intCitySeed, intWorldSeed); #endregion #region determine random options // ensure selected options take priority, but don't set things on fire if (strTowerAddition == "Random") { strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag"); } if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Lava" || strMoatType == "Fire" || strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } if (strWallMaterial == "Random") { if (strMoatType == "Lava" || strMoatType == "Fire" || strOutsideLights == "Fire") { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone"); } else { strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone", "Wood Planks"); if (strWallMaterial.StartsWith("Wood")) { if (strMoatType == "Random") { strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water"); } strOutsideLights = "Torches"; } } } if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } if (strMoatType == "Random") { int intRand = RandomHelper.Next(100); if (intRand >= 90) { strMoatType = "Drop to Bedrock"; } else if (intRand >= 80) { strMoatType = "Cactus"; } else if (intRand >= 50) { strMoatType = "Lava"; } else if (intRand >= 40) { strMoatType = "Fire"; } else { strMoatType = "Water"; } } int intWallMaterial = BlockType.STONE; switch (strWallMaterial) { case "Brick": intWallMaterial = BlockType.BRICK_BLOCK; break; case "Cobblestone": intWallMaterial = BlockType.COBBLESTONE; break; case "Sandstone": intWallMaterial = BlockType.SANDSTONE; break; case "Stone": intWallMaterial = BlockType.STONE; break; case "Wood Planks": intWallMaterial = BlockType.WOOD_PLANK; break; case "Wood Logs": intWallMaterial = BlockType.WOOD; break; case "Bedrock": intWallMaterial = BlockType.BEDROCK; break; case "Mossy Cobblestone": intWallMaterial = BlockType.MOSS_STONE; break; case "Netherrack": intWallMaterial = BlockType.NETHERRACK; break; case "Glass": intWallMaterial = BlockType.GLASS; break; case "Ice": intWallMaterial = BlockType.ICE; break; case "Snow": intWallMaterial = BlockType.SNOW_BLOCK; break; case "Glowstone": intWallMaterial = BlockType.GLOWSTONE_BLOCK; break; case "Dirt": intWallMaterial = BlockType.DIRT; break; case "Obsidian": intWallMaterial = BlockType.OBSIDIAN; break; case "Jack-o-Lantern": intWallMaterial = BlockType.JACK_O_LANTERN; break; case "Soul sand": intWallMaterial = BlockType.SOUL_SAND; break; case "Gold": intWallMaterial = BlockType.GOLD_BLOCK; break; case "Diamond": intWallMaterial = BlockType.DIAMOND_BLOCK; break; default: Debug.Fail("Invalid switch result"); break; } #endregion #region make the city frmLogForm.UpdateLog("Creating underground terrain"); Chunks.CreateInitialChunks(cmDest, intMapLength / 16, frmLogForm); frmLogForm.UpdateProgress(25); Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint(); if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmLength, intMapLength, strCityEmblem, strOutsideLights, intWallMaterial); } frmLogForm.UpdateProgress(34); if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmLength, intMapLength, strCitySize, booIncludeMineshaft); frmLogForm.UpdateProgress(36); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmLength, intMapLength, booIncludePaths); frmLogForm.UpdateProgress(45); if (booIncludeMineshaft) { frmLogForm.UpdateLog("Creating mineshaft"); Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmLength, intMapLength, spMineshaftEntrance); } } } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmLength, intMapLength, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmLength, intMapLength, booIncludeMoat, booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType, strCityName); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmLength, intMapLength, booIncludeWalls, strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial); } frmLogForm.UpdateProgress(54); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmLength, intMapLength); } frmLogForm.UpdateProgress(58); if (!booIncludeValuableBlocks) { cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapLength, intWallMaterial); } frmLogForm.UpdateProgress(60); Chunks.PositionRails(worldDest, bmDest, intMapLength); frmLogForm.UpdateProgress(62); #endregion #region world settings // spawn looking at one of the city entrances if (booIncludeFarms) { SpawnPoint spLevel = new SpawnPoint(7, 11, 13); worldDest.Level.Spawn = spLevel; worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 10)); } else { worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 7)); } // spawn in the middle of the city //#if DEBUG //worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength / 2); //#endif if (strWorldSeed.Length > 0) { worldDest.Level.RandomSeed = intWorldSeed; } #if RELEASE worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endif #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2); #endif frmLogForm.UpdateLog("Creating lighting data"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapLength / 16, 2)); worldDest.Level.LevelName = strCityName; worldDest.Save(); if (booExportSchematic) { frmLogForm.UpdateLog("Creating schematic"); AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength); for (int x = 0; x < intMapLength; x++) { for (int z = 0; z < intMapLength; z++) { for (int y = 0; y < 128; y++) { abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z)); } } } Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength); CitySchematic.Blocks = abcExport; CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic"); } frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
public static void Generate(frmMace frmLogForm, BetaWorld worldDest, BetaChunkManager cmDest, BlockManager bmDest, int x, int z) { #region create a city name string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine(Path.Combine("Resources", City.CityNamePrefixFilename)); strEnd = RandomHelper.RandomFileLine(Path.Combine("Resources", City.CityNameSuffixFilename)); City.Name = "City of " + strStart + strEnd; } while (GenerateWorld.lstCityNames.Contains(City.Name) || strStart.ToLower().Trim() == strEnd.ToLower().Trim() || (strStart + strEnd).Length > 14); GenerateWorld.lstCityNames.Add(City.Name); #endregion #region determine block sizes City.CityLength *= 16; // chunk length City.FarmLength = City.HasFarms ? 32 : 8; City.MapLength = City.CityLength + (City.FarmLength * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest); BlockHelper.SetupClass(bmDest); NoticeBoard.SetupClass(); if (!SourceWorld.SetupClass(worldDest)) { return; } #endregion #region determine random options #pragma warning disable switch (City.WallMaterialID) { case BlockType.WOOD_PLANK: case BlockType.WOOD: case BlockType.LEAVES: case BlockType.VINES: case BlockType.WOOL: case BlockType.BOOKSHELF: switch (City.OutsideLightType) { case "Fire": frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true); City.OutsideLightType = "Torches"; break; } switch (City.MoatType) { case "Fire": case "Lava": frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true); City.MoatType = "Water"; break; } break; } #pragma warning restore #endregion #region make the city frmLogForm.UpdateLog("Creating the " + City.Name, false, false); frmLogForm.UpdateLog("City length in blocks: " + City.MapLength, true, true); frmLogForm.UpdateLog("City position in blocks: " + ((x + 30) * 16) + "," + ((z + 30) * 16), true, true); frmLogForm.UpdateLog("Theme: " + City.ThemeName, true, true); frmLogForm.UpdateLog("Creating underground terrain", true, false); Chunks.CreateInitialChunks(cmDest, frmLogForm); frmLogForm.UpdateProgress(0.35); Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint(); if (City.HasWalls) { frmLogForm.UpdateLog("Creating walls", true, false); Walls.MakeWalls(worldDest, frmLogForm); } frmLogForm.UpdateProgress(0.45); if (City.HasBuildings || City.HasPaths) { frmLogForm.UpdateLog("Creating paths", true, false); int[,] intArea = Paths.MakePaths(worldDest, bmDest); frmLogForm.UpdateProgress(0.50); if (City.HasBuildings) { frmLogForm.UpdateLog("Creating buildings", true, false); spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, frmLogForm); frmLogForm.UpdateProgress(0.55); if (City.HasMineshaft) { frmLogForm.UpdateLog("Creating mineshaft", true, false); Mineshaft.MakeMineshaft(worldDest, bmDest, spMineshaftEntrance, frmLogForm); } } } frmLogForm.UpdateProgress(0.60); if (City.HasMoat) { frmLogForm.UpdateLog("Creating moat", true, false); Moat.MakeMoat(frmLogForm); } frmLogForm.UpdateProgress(0.65); if (City.HasDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges", true, false); Drawbridge.MakeDrawbridges(bmDest); } frmLogForm.UpdateProgress(0.70); if (City.HasGuardTowers) { frmLogForm.UpdateLog("Creating guard towers", true, false); GuardTowers.MakeGuardTowers(bmDest, frmLogForm); } frmLogForm.UpdateProgress(0.75); if (City.HasFarms) { frmLogForm.UpdateLog("Creating farms", true, false); Farms.MakeFarms(worldDest, bmDest, frmLogForm); } frmLogForm.UpdateProgress(0.80); if (!City.HasValuableBlocks) { frmLogForm.UpdateLog("Replacing valuable blocks", true, true); cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest); } frmLogForm.UpdateProgress(0.90); frmLogForm.UpdateLog("Creating rail data", true, false); Chunks.PositionRails(worldDest, bmDest); frmLogForm.UpdateProgress(0.95); frmLogForm.UpdateLog("Creating position data", true, false); Chunks.MoveChunks(worldDest, cmDest, x, z); frmLogForm.UpdateProgress(1); #endregion }
public void Generate(frmMace frmLogForm, string strUserCityName, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard, bool booIncludeBuildings, bool booIncludePaths, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strFireBeacons, string strCitySeed, string strWorldSeed) { #region Seed the random number generators int intCitySeed, intWorldSeed; Random randSeeds = new Random(); if (strCitySeed == "") { intCitySeed = randSeeds.Next(); frmLogForm.UpdateLog("Random city seed: " + intCitySeed); } else { intCitySeed = JavaStringHashCode(strCitySeed); frmLogForm.UpdateLog("Random city seed: " + strCitySeed); } if (strWorldSeed == "") { intWorldSeed = randSeeds.Next(); frmLogForm.UpdateLog("Random world seed: " + intWorldSeed); } else { intWorldSeed = JavaStringHashCode(strWorldSeed); frmLogForm.UpdateLog("Random world seed: " + strWorldSeed); } RandomHelper.SetSeed(intCitySeed); #endregion #region create minecraft world directory from a random unused city name string strFolder = "", strCityName = ""; strUserCityName = SafeFilename(strUserCityName); if (strUserCityName.ToLower().Trim() == "") { strUserCityName = "Random"; } if (strUserCityName.ToLower().Trim() != "random") { if (Directory.Exists(Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strUserCityName + @"\")) { if (MessageBox.Show("A world called \"" + strUserCityName + "\" already exists. " + "Would you like to use a random name instead?", "World already exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { frmLogForm.UpdateLog("Cancelled, because a world with this name already exists."); return; } } else { strCityName = strUserCityName; } } if (strCityName == "") { string strStart, strEnd; do { strStart = RandomHelper.RandomFileLine("Resources\\CityAdj.txt"); strEnd = RandomHelper.RandomFileLine("Resources\\CityNoun.txt"); strCityName = "City of " + strStart + strEnd; strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\"; } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder)); } Directory.CreateDirectory(strFolder); #endregion RandomHelper.SetSeed(intCitySeed); #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); ChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = RandomHelper.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmSize = booIncludeFarms ? 32 : 16; int intMapSize = intCitySize + (intFarmSize * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapSize); BlockHelper.SetupClass(bmDest, intMapSize); SourceWorld.SetupClass(worldDest); #endregion if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } #region make the city frmLogForm.UpdateLog("Creating chunks"); Chunks.MakeChunks(cmDest, 0, intMapSize / 16, frmLogForm); frmLogForm.UpdateProgress(35); if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(38); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths); } } frmLogForm.UpdateProgress(50); if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights); } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strFireBeacons); } frmLogForm.UpdateProgress(54); if (booIncludeWalls && booIncludeNoticeboard) { frmLogForm.UpdateLog("Creating noticeboard"); NoticeBoard.MakeNoticeBoard(bmDest, intFarmSize, intMapSize, intCitySeed, intWorldSeed); } frmLogForm.UpdateProgress(55); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(58); #endregion #region world settings // spawn in a guard tower //world.Level.SpawnX = intFarmSize + 5; //world.Level.SpawnZ = intFarmSize + 5; //world.Level.SpawnY = 74; // spawn looking at one of the city entrances worldDest.Level.SpawnX = intMapSize / 2; worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10); worldDest.Level.SpawnY = 64; // spawn in the middle of the city //worldDest.Level.SpawnX = intMapSize / 2; //worldDest.Level.SpawnZ = (intMapSize / 2) - 1; //worldDest.Level.SpawnY = 64; // spawn default //world.Level.SpawnX = 0; //world.Level.SpawnY = 65; //world.Level.SpawnZ = 0; if (strWorldSeed != "") { worldDest.Level.RandomSeed = intWorldSeed; } worldDest.Level.LevelName = strCityName; worldDest.Level.Time = RandomHelper.Next(24000); if (RandomHelper.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = RandomHelper.Next(6000, 18000); if (RandomHelper.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2); #endif frmLogForm.UpdateLog("Resetting lighting"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2)); worldDest.Save(); frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
private static int[,] FillArea(int[,] intArea, int intSizeX, int intSizeZ, int intStartX, int intStartZ) { int[,] intDistrict = new int[intSizeX, intSizeZ]; int[,] intFinal = new int[intSizeX, intSizeZ]; int intWasted = intSizeX * intSizeZ, intAttempts = 15, intFail = 0; int intBonus = 0; List <int> lstBuildings = new List <int>(); List <int> lstAcceptedBuildings = new List <int>(); do { lstBuildings.Clear(); intBonus = 0; do { SourceWorld.Building CurrentBuilding; do { CurrentBuilding = SourceWorld.SelectRandomBuilding(); } while (!IsValidBuilding(CurrentBuilding, lstBuildings, intArea, intStartX, intStartZ, intSizeX, intSizeZ)); bool booFound = false; if (RandomHelper.NextDouble() > 0.5) { intDistrict = RotateArray(intDistrict, RandomHelper.Next(4)); } int x, z = 0; for (x = 0; x < intDistrict.GetLength(0) - CurrentBuilding.intSize && !booFound; x++) { for (z = 0; z < intDistrict.GetLength(1) - CurrentBuilding.intSize && !booFound; z++) { booFound = IsFree(intDistrict, x, z, x + CurrentBuilding.intSize, z + CurrentBuilding.intSize); } } x--; z--; if (booFound) { for (int a = x + 1; a <= x + CurrentBuilding.intSize - 1; a++) { for (int b = z + 1; b <= z + CurrentBuilding.intSize - 1; b++) { intDistrict[a, b] = 2; } } if (CurrentBuilding.booUnique) { // we want to include the unique buildings, // so we give a slight preference to those intBonus += 15; } lstBuildings.Add(CurrentBuilding.intID); intDistrict[x + 1, z + 1] = 100 + CurrentBuilding.intID; intDistrict[x + CurrentBuilding.intSize - 1, z + CurrentBuilding.intSize - 1] = 100 + CurrentBuilding.intID; intFail = 0; } else { intFail++; } } while (intFail < 10); int intCurWasted = SquaresWasted(intDistrict) - intBonus; if (intCurWasted < intWasted) { intFinal = new int[intDistrict.GetLength(0), intDistrict.GetLength(1)]; Array.Copy(intDistrict, intFinal, intDistrict.Length); intWasted = intCurWasted; intAttempts = 10; lstAcceptedBuildings.Clear(); lstAcceptedBuildings.AddRange(lstBuildings); } Array.Clear(intDistrict, 0, intDistrict.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = RotateArray(intFinal, 1); } lstAllBuildings.AddRange(lstAcceptedBuildings); return(intFinal); }
public void Generate(frmMace frmLogForm, bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls, bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeNoticeboard, bool booIncludeBuildings, bool booIncludePaths, string strCitySize, string strMoatType, string strCityEmblem, string strOutsideLights, string strFireBeacons) { #region create minecraft world directory from a random unused city name string strFolder = "", strCityName = ""; do { strCityName = "City of " + RandomHelper.RandomFileLine("Resources\\CityStartingWords.txt") + RandomHelper.RandomFileLine("Resources\\CityEndingWords.txt"); strFolder = Environment.GetEnvironmentVariable("APPDATA") + @"\.minecraft\saves\" + strCityName + @"\"; } while (Directory.Exists(strFolder)); Directory.CreateDirectory(strFolder); #endregion #region get handles to world, chunk manager and block manager BetaWorld worldDest = BetaWorld.Create(@strFolder); ChunkManager cmDest = worldDest.GetChunkManager(); BlockManager bmDest = worldDest.GetBlockManager(); bmDest.AutoLight = false; #endregion Random rand = new Random(); #region determine block sizes // first we set the city size by chunks int intCitySize = 12; switch (strCitySize) { case "Random": intCitySize = rand.Next(8, 16); break; case "Very small": intCitySize = 5; break; case "Small": intCitySize = 8; break; case "Medium": intCitySize = 12; break; case "Large": intCitySize = 16; break; case "Very large": intCitySize = 25; break; } // then we multiply by 16, because that's the x and z of a chunk intCitySize *= 16; int intFarmSize = booIncludeFarms ? 32 : 16; int intMapSize = intCitySize + (intFarmSize * 2); #endregion #region setup classes BlockShapes.SetupClass(bmDest, intMapSize); BlockHelper.SetupClass(bmDest, intMapSize); SourceWorld.SetupClass(); #endregion if (strOutsideLights == "Random") { strOutsideLights = RandomHelper.RandomString("Fire", "Torches"); } #region make the city frmLogForm.UpdateLog("Creating chunks"); Chunks.MakeChunks(cmDest, 0, intMapSize / 16, frmLogForm); frmLogForm.UpdateProgress(35); // todo: test excluding paths/buildings if (booIncludeBuildings || booIncludePaths) { frmLogForm.UpdateLog("Creating paths"); int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmSize, intMapSize); frmLogForm.UpdateProgress(38); if (booIncludeBuildings) { frmLogForm.UpdateLog("Creating buildings"); Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmSize, intMapSize, booIncludePaths); } } frmLogForm.UpdateProgress(50); if (booIncludeWalls) { frmLogForm.UpdateLog("Creating walls"); Walls.MakeWalls(worldDest, intFarmSize, intMapSize, strCityEmblem, strOutsideLights); } frmLogForm.UpdateProgress(51); if (booIncludeMoat) { frmLogForm.UpdateLog("Creating moat"); Moat.MakeMoat(intFarmSize, intMapSize, strMoatType, booIncludeGuardTowers); } frmLogForm.UpdateProgress(52); if (booIncludeDrawbridges) { frmLogForm.UpdateLog("Creating drawbridges"); Drawbridge.MakeDrawbridges(bmDest, intFarmSize, intMapSize, booIncludeMoat, booIncludeWalls); } frmLogForm.UpdateProgress(53); if (booIncludeGuardTowers) { frmLogForm.UpdateLog("Creating guard towers"); GuardTowers.MakeGuardTowers(bmDest, intFarmSize, intMapSize, booIncludeWalls, strOutsideLights, strFireBeacons); } frmLogForm.UpdateProgress(54); if (booIncludeWalls && booIncludeNoticeboard) { frmLogForm.UpdateLog("Creating noticeboard"); NoticeBoard.MakeNoticeBoard(bmDest, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(55); if (booIncludeFarms) { frmLogForm.UpdateLog("Creating farms"); Farms.MakeFarms(worldDest, bmDest, intFarmSize, intMapSize); } frmLogForm.UpdateProgress(58); #endregion #region world settings // spawn in a guard tower //world.Level.SpawnX = intFarmSize + 5; //world.Level.SpawnZ = intFarmSize + 5; //world.Level.SpawnY = 74; // spawn looking at one of the city entrances worldDest.Level.SpawnX = intMapSize / 2; worldDest.Level.SpawnZ = intMapSize - (intFarmSize - 10); worldDest.Level.SpawnY = 64; // spawn default //world.Level.SpawnX = 0; //world.Level.SpawnY = 65; //world.Level.SpawnZ = 0; worldDest.Level.LevelName = strCityName; worldDest.Level.Time = rand.Next(24000); if (rand.NextDouble() < 0.15) { worldDest.Level.IsRaining = true; // one-quarter to three-quarters of a day worldDest.Level.RainTime = rand.Next(6000, 18000); if (rand.NextDouble() < 0.25) { worldDest.Level.IsThundering = true; worldDest.Level.ThunderTime = worldDest.Level.RainTime; } } #endregion #if DEBUG MakeHelperChest(bmDest, worldDest.Level.SpawnX + 2, worldDest.Level.SpawnY, worldDest.Level.SpawnZ + 2); #endif frmLogForm.UpdateLog("Resetting lighting"); Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapSize / 16, 2)); worldDest.Save(); frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!"); frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list."); }
// this is a simplified version of the FillArea method from Paths.cs private static int[,] FillArea(int intSizeX, int intSizeZ) { 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>(); do { lstBuildings.Clear(); intBonus = 0; do { SourceWorld.Building CurrentBuilding; do { CurrentBuilding = SourceWorld.SelectRandomBuilding(SourceWorld.BuildingTypes.Farming, 0); } while (!IsValidBuilding(CurrentBuilding, lstBuildings)); bool booFound = false; if (RNG.NextDouble() > 0.5) { intDistrict = intDistrict.RotateArray(RNG.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 = intDistrict.IsArraySectionAllZeros2D(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) { 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; } Array.Clear(intDistrict, 0, intDistrict.Length); intAttempts--; } while (intAttempts > 0); if (intSizeX == intFinal.GetLength(1)) { intFinal = intFinal.RotateArray(1); } return(intFinal); }