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); }
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); }
public static structPoint MakeInsideCity(BlockManager bm, BetaWorld worldDest, int[,] intArea, frmMace frmLogForm) { int intBlockStart = City.EdgeLength + 13; structPoint spMineshaftEntrance = MakeBuildings(bm, intArea, intBlockStart, worldDest); worldDest.Save(); if (City.HasPaths) { JoinPathsToRoad(bm); } else { RemovePaths(bm, intArea, intBlockStart); } frmLogForm.UpdateLog("Creating street lights: " + City.StreetLightType, true, true); MakeStreetLights(bm); return(spMineshaftEntrance); }
public static structPoint MakeInsideCity(BlockManager bm, BetaWorld worldDest, int[,] intArea, int intFarmLength, int intMapLength, bool booIncludePaths) { int intBlockStart = intFarmLength + 13; structPoint spMineshaftEntrance = MakeBuildings(bm, intArea, intBlockStart, worldDest, intFarmLength); worldDest.Save(); if (!booIncludePaths) { RemovePaths(bm, intArea, intBlockStart); } else { JoinPathsToRoad(bm, intMapLength, intFarmLength); } MakeStreetLights(bm, intMapLength, intFarmLength); MakeFlowers(bm, worldDest, intFarmLength, intMapLength); return(spMineshaftEntrance); }
private static structPoint MatchPatternInArray(int[,] intArray, string[] strPattern) { List <structPoint> lstPoints = new List <structPoint>(); for (int x = 0; x <= intArray.GetUpperBound(0) - strPattern[0].Length; x++) { for (int z = 0; z <= intArray.GetUpperBound(1) - strPattern[0].Length; z++) { bool booMatches = true; for (int xCheck = 0; xCheck < strPattern[0].Length && booMatches; xCheck++) { for (int zCheck = 0; zCheck < strPattern[0].Length && booMatches; zCheck++) { booMatches = intArray[x + xCheck, z + zCheck] <= 1 && (strPattern[zCheck][(strPattern[0].Length - 1) - xCheck].ToString() == "?" || intArray[x + xCheck, z + zCheck].ToString() == "" + strPattern[zCheck][(strPattern[0].Length - 1) - xCheck]); } } if (booMatches) { structPoint pntFoundPattern = new structPoint(); pntFoundPattern.x = x; pntFoundPattern.z = z; lstPoints.Add(pntFoundPattern); } } } if (lstPoints.Count == 0) { structPoint pntNoPattern = new structPoint(); pntNoPattern.x = -1; pntNoPattern.z = -1; return(pntNoPattern); } else { return(lstPoints[RandomHelper.Next(lstPoints.Count)]); } }
private static structPoint MakeBuildings(BlockManager bmDest, int[,] intArea, int intBlockStart, BetaWorld world, int intFarmLength) { 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: 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(bmDest, 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); SourceWorld.Building BalloonBuilding = SourceWorld.GetBuilding("Sky Feature"); SourceWorld.InsertBuilding(bmDest, 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 structPoint MatchPatternInArray(int[,] intArray, string[] strPattern) { List<structPoint> lstPoints = new List<structPoint>(); for (int x = 0; x <= intArray.GetUpperBound(0) - strPattern[0].Length; x++) { for (int z = 0; z <= intArray.GetUpperBound(1) - strPattern[0].Length; z++) { bool booMatches = true; for (int xCheck = 0; xCheck < strPattern[0].Length && booMatches; xCheck++) { for (int zCheck = 0; zCheck < strPattern[0].Length && booMatches; zCheck++) { booMatches = intArray[x + xCheck, z + zCheck] <= 1 && (strPattern[zCheck][(strPattern[0].Length - 1) - xCheck].ToString() == "?" || intArray[x + xCheck, z + zCheck].ToString() == "" + strPattern[zCheck][(strPattern[0].Length - 1) - xCheck]); } } if (booMatches) { structPoint pntFoundPattern = new structPoint(); pntFoundPattern.x = x; pntFoundPattern.z = z; lstPoints.Add(pntFoundPattern); } } } if (lstPoints.Count == 0) { structPoint pntNoPattern = new structPoint(); pntNoPattern.x = -1; pntNoPattern.z = -1; return pntNoPattern; } else { return lstPoints[RandomHelper.Next(lstPoints.Count)]; } }