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 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 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 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 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); }
// 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 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); }
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 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 }