public static bool TryFindNewRandomSitePartFor(SiteCoreDef core, IEnumerable <SitePartDef> existingSiteParts, IEnumerable <SitePartDef> possibleSiteParts, Faction faction, out SitePartDef sitePart, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null) { if (faction != null) { if ((from x in possibleSiteParts where x == null || SiteMakerHelper.FactionCanOwn(x, faction, disallowAlliedFactions, extraFactionValidator) select x).TryRandomElement(out sitePart)) { return(true); } } else { SiteMakerHelper.possibleFactions.Clear(); SiteMakerHelper.possibleFactions.Add(null); SiteMakerHelper.possibleFactions.AddRange(Find.FactionManager.AllFactionsListForReading); if ((from x in possibleSiteParts where x == null || SiteMakerHelper.possibleFactions.Any((Faction fac) => SiteMakerHelper.FactionCanOwn(core, existingSiteParts, fac, disallowAlliedFactions, extraFactionValidator) && SiteMakerHelper.FactionCanOwn(x, fac, disallowAlliedFactions, extraFactionValidator)) select x).TryRandomElement(out sitePart)) { SiteMakerHelper.possibleFactions.Clear(); return(true); } SiteMakerHelper.possibleFactions.Clear(); } sitePart = null; return(false); }
public static bool TryFindRandomFactionFor(SiteCoreDef core, IEnumerable <SitePartDef> parts, out Faction faction, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null) { if (SiteMakerHelper.FactionCanOwn(core, parts, null, disallowAlliedFactions, extraFactionValidator)) { faction = null; return(true); } if ((from x in Find.FactionManager.AllFactionsListForReading where SiteMakerHelper.FactionCanOwn(core, parts, x, disallowAlliedFactions, extraFactionValidator) select x).TryRandomElement(out faction)) { return(true); } faction = null; return(false); }
public static bool FactionCanOwn(SiteCoreDef core, IEnumerable <SitePartDef> parts, Faction faction, bool disallowAlliedFactions, Predicate <Faction> extraFactionValidator) { if (!SiteMakerHelper.FactionCanOwn(core, faction, disallowAlliedFactions, extraFactionValidator)) { return(false); } if (parts != null) { foreach (SitePartDef part in parts) { if (!SiteMakerHelper.FactionCanOwn(part, faction, disallowAlliedFactions, extraFactionValidator)) { return(false); } } } return(true); }
public static bool FactionCanOwn(SiteCoreDef core, IEnumerable <SitePartDef> parts, Faction faction, bool disallowNonHostileFactions, Predicate <Faction> extraFactionValidator) { bool result; if (!SiteMakerHelper.FactionCanOwn(core, faction, disallowNonHostileFactions, extraFactionValidator)) { result = false; } else { if (parts != null) { foreach (SitePartDef siteDefBase in parts) { if (!SiteMakerHelper.FactionCanOwn(siteDefBase, faction, disallowNonHostileFactions, extraFactionValidator)) { return(false); } } } result = true; } return(result); }