예제 #1
0
 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);
 }
예제 #2
0
파일: SiteMaker.cs 프로젝트: potsh/RimWorld
 public static Site TryMakeSite(SiteCoreDef core, IEnumerable <SitePartDef> siteParts, int tile, bool disallowNonHostileFactions = true, Predicate <Faction> extraFactionValidator = null, bool ifHostileThenMustRemainHostile = true, float?threatPoints = default(float?))
 {
     if (!SiteMakerHelper.TryFindRandomFactionFor(core, siteParts, out Faction faction, disallowNonHostileFactions, extraFactionValidator))
     {
         return(null);
     }
     return(MakeSite(core, siteParts, tile, faction, ifHostileThenMustRemainHostile, threatPoints));
 }
예제 #3
0
파일: SiteMaker.cs 프로젝트: potsh/RimWorld
 public static Site TryMakeSite_SingleSitePart(SiteCoreDef core, string singleSitePartTag, int tile, Faction faction = null, bool disallowNonHostileFactions = true, Predicate <Faction> extraFactionValidator = null, bool ifHostileThenMustRemainHostile = true, float?threatPoints = default(float?))
 {
     if (!SiteMakerHelper.TryFindSiteParams_SingleSitePart(core, singleSitePartTag, out SitePartDef sitePart, out faction, faction, disallowNonHostileFactions, extraFactionValidator))
     {
         return(null);
     }
     return(MakeSite(core, sitePart, tile, faction, ifHostileThenMustRemainHostile, threatPoints));
 }
예제 #4
0
        public static bool TryFindSiteParams_SingleSitePart(SiteCoreDef core, string singleSitePartTag, out SitePartDef sitePart, out Faction faction, Faction factionToUse = null, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null)
        {
            IEnumerable <SitePartDef> singleSitePartCandidates = (singleSitePartTag == null) ? null : (from x in DefDatabase <SitePartDef> .AllDefsListForReading
                                                                                                       where x.tags.Contains(singleSitePartTag)
                                                                                                       select x);

            return(SiteMakerHelper.TryFindSiteParams_SingleSitePart(core, singleSitePartCandidates, out sitePart, out faction, factionToUse, disallowAlliedFactions, extraFactionValidator));
        }
예제 #5
0
 public static Site TryMakeSite_MultipleSiteParts(List <string> sitePartsTags, int tile, Faction faction = null, bool disallowNonHostileFactions = true, Predicate <Faction> extraFactionValidator = null, bool ifHostileThenMustRemainHostile = true, float?threatPoints = null)
 {
     if (!SiteMakerHelper.TryFindSiteParams_MultipleSiteParts(sitePartsTags, out var siteParts, out faction, faction, disallowNonHostileFactions, extraFactionValidator))
     {
         return(null);
     }
     return(MakeSite(siteParts, tile, faction, ifHostileThenMustRemainHostile, threatPoints));
 }
예제 #6
0
 public static Site TryMakeSite_SingleSitePart(IEnumerable <SitePartDef> singleSitePartCandidates, int tile, Faction faction = null, bool disallowNonHostileFactions = true, Predicate <Faction> extraFactionValidator = null, bool ifHostileThenMustRemainHostile = true, float?threatPoints = null)
 {
     if (!SiteMakerHelper.TryFindSiteParams_SingleSitePart(singleSitePartCandidates, out var sitePart, out faction, faction, disallowNonHostileFactions, extraFactionValidator))
     {
         return(null);
     }
     return(MakeSite(sitePart, tile, faction, ifHostileThenMustRemainHostile, threatPoints));
 }
예제 #7
0
        public static Site TryMakeSite(SiteCoreDef core, IEnumerable <SitePartDef> siteParts, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null)
        {
            Faction faction = default(Faction);

            if (!SiteMakerHelper.TryFindRandomFactionFor(core, siteParts, out faction, disallowAlliedFactions, extraFactionValidator))
            {
                return(null);
            }
            return(SiteMaker.MakeSite(core, siteParts, faction));
        }
예제 #8
0
        public static Site TryMakeSite_SingleSitePart(SiteCoreDef core, string singleSitePartTag, Faction faction = null, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null)
        {
            SitePartDef sitePart = default(SitePartDef);

            if (!SiteMakerHelper.TryFindSiteParams_SingleSitePart(core, singleSitePartTag, out sitePart, out faction, faction, disallowAlliedFactions, extraFactionValidator))
            {
                return(null);
            }
            return(SiteMaker.MakeSite(core, sitePart, faction));
        }
예제 #9
0
        public static Site MakeSite(IEnumerable <SitePartDef> siteParts, int tile, Faction faction, bool ifHostileThenMustRemainHostile = true, float?threatPoints = null)
        {
            float num = threatPoints ?? StorytellerUtility.DefaultSiteThreatPointsNow();

            SiteMakerHelper.GenerateDefaultParams(num, tile, faction, siteParts, out var sitePartDefsWithParams);
            Site site = MakeSite(sitePartDefsWithParams, tile, faction, ifHostileThenMustRemainHostile);

            site.desiredThreatPoints = num;
            return(site);
        }
예제 #10
0
        public static Site TryMakeSite_SingleSitePart(SiteCoreDef core, IEnumerable <SitePartDef> singleSitePartCandidates, Faction faction = null, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null)
        {
            SitePartDef sitePart;

            if (!SiteMakerHelper.TryFindSiteParams_SingleSitePart(core, singleSitePartCandidates, out sitePart, out faction, faction, disallowAlliedFactions, extraFactionValidator))
            {
                return(null);
            }
            return(SiteMaker.MakeSite(core, sitePart, faction));
        }
예제 #11
0
        public static Site TryMakeSite(SiteCoreDef core, IEnumerable <SitePartDef> siteParts, bool disallowNonHostileFactions = true, Predicate <Faction> extraFactionValidator = null, bool ifHostileThenMustRemainHostile = true)
        {
            Faction faction;
            Site    result;

            if (!SiteMakerHelper.TryFindRandomFactionFor(core, siteParts, out faction, disallowNonHostileFactions, extraFactionValidator))
            {
                result = null;
            }
            else
            {
                result = SiteMaker.MakeSite(core, siteParts, faction, ifHostileThenMustRemainHostile);
            }
            return(result);
        }
예제 #12
0
        public static Site TryMakeSite_SingleSitePart(SiteCoreDef core, string singleSitePartTag, Faction faction = null, bool disallowNonHostileFactions = true, Predicate <Faction> extraFactionValidator = null, bool ifHostileThenMustRemainHostile = true)
        {
            SitePartDef sitePart;
            Site        result;

            if (!SiteMakerHelper.TryFindSiteParams_SingleSitePart(core, singleSitePartTag, out sitePart, out faction, faction, disallowNonHostileFactions, extraFactionValidator))
            {
                result = null;
            }
            else
            {
                result = SiteMaker.MakeSite(core, sitePart, faction, ifHostileThenMustRemainHostile);
            }
            return(result);
        }
예제 #13
0
 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);
 }
예제 #15
0
 public static bool TryFindSiteParams_SingleSitePart(SiteCoreDef core, IEnumerable <SitePartDef> singleSitePartCandidates, out SitePartDef sitePart, out Faction faction, Faction factionToUse = null, bool disallowAlliedFactions = true, Predicate <Faction> extraFactionValidator = null)
 {
     faction = factionToUse;
     if (singleSitePartCandidates != null)
     {
         if (!SiteMakerHelper.TryFindNewRandomSitePartFor(core, null, singleSitePartCandidates, faction, out sitePart, disallowAlliedFactions, extraFactionValidator))
         {
             return(false);
         }
     }
     else
     {
         sitePart = null;
     }
     if (faction == null)
     {
         IEnumerable <SitePartDef> parts = (sitePart == null) ? null : Gen.YieldSingle <SitePartDef>(sitePart);
         if (!SiteMakerHelper.TryFindRandomFactionFor(core, parts, out faction, disallowAlliedFactions, extraFactionValidator))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #16
0
        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);
        }