public static IEnumerable <Blueprint_Build> PlaceBlueprints(LordToilData_SiegeCustom data, Map map, Faction placeFaction) { customParams = FactionDefExtension.Get(placeFaction.def).siegeParameterSetDef; NonPublicFields.SiegeBlueprintPlacer_center.SetValue(null, data.siegeCenter); NonPublicFields.SiegeBlueprintPlacer_faction.SetValue(null, placeFaction); // Cover if (customParams.coverDef != null) { var coverBlueprints = PlaceCoverBlueprints(map).ToList(); for (int i = 0; i < coverBlueprints.Count; i++) { yield return(coverBlueprints[i]); } } // Artillery if (!customParams.artilleryBuildingTags.NullOrEmpty()) { var artilleryBlueprints = PlaceArtilleryBlueprints(data, map).ToList(); for (int i = 0; i < artilleryBlueprints.Count; i++) { yield return(artilleryBlueprints[i]); } } }
private static IEnumerable <Blueprint_Build> PlaceArtilleryBlueprints(LordToilData_SiegeCustom data, Map map) { IEnumerable <ThingDef> artyDefs = customParams.artilleryDefs; // No tag matches if (!artyDefs.Any()) { Log.Error($"Could not find any artillery ThingDefs matching the following tags: {customParams.artilleryBuildingTags.ToStringSafeEnumerable()}"); yield break; } float points = data.blueprintPoints; // Generate blueprints int numArtillery = Mathf.RoundToInt(points / customParams.lowestArtilleryBlueprintPoints); numArtillery = Mathf.Clamp(numArtillery, customParams.artilleryCountRange.min, customParams.artilleryCountRange.max); int i = 0; while (points > 0 && i < numArtillery) { artyDefs = artyDefs.Where(t => ThingDefExtension.Get(t).siegeBlueprintPoints <= points); if (!artyDefs.Any()) { yield break; } var rot = Rot4.Random; var artyDef = artyDefs.RandomElementByWeight(t => ThingDefExtension.Get(t).siegeBlueprintPoints); var artySpot = NonPublicMethods.SiegeBlueprintPlacer_FindArtySpot(artyDef, rot, map); if (!artySpot.IsValid) { yield break; } yield return(GenConstruct.PlaceBlueprintForBuild(artyDef, artySpot, map, rot, (Faction)NonPublicFields.SiegeBlueprintPlacer_faction.GetValue(null), GenStuff.DefaultStuffFor(artyDef))); if (data.artilleryCounts.ContainsKey(artyDef)) { data.artilleryCounts[artyDef]++; } else { data.artilleryCounts.Add(artyDef, 1); } points -= ThingDefExtension.Get(artyDef).siegeBlueprintPoints; i++; } yield break; }
public LordToil_SiegeCustom(IntVec3 siegeCenter, float blueprintPoints) { data = new LordToilData_SiegeCustom(); Data.siegeCenter = siegeCenter; Data.blueprintPoints = blueprintPoints; }