public static IEnumerable <ThingDef> GetAllowedThingDefs(ThingSetMakerParams parms)
        {
            TechLevel techLevel           = parms.techLevel ?? TechLevel.Undefined;
            IEnumerable <ThingDef> source = parms.filter.AllowedThingDefs;

            if (techLevel != 0)
            {
                source = source.Where((ThingDef x) => (int)x.techLevel <= (int)techLevel);
            }
            RoyalTitleDef highestTitle = null;

            if (parms.makingFaction != null && parms.makingFaction.def.HasRoyalTitles)
            {
                foreach (Pawn allMapsCaravansAndTravelingTransportPods_Alive_Colonist in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists)
                {
                    RoyalTitleDef royalTitleDef = ((allMapsCaravansAndTravelingTransportPods_Alive_Colonist.royalty != null) ? allMapsCaravansAndTravelingTransportPods_Alive_Colonist.royalty.GetCurrentTitle(parms.makingFaction) : null);
                    if (royalTitleDef != null && (highestTitle == null || royalTitleDef.seniority > highestTitle.seniority))
                    {
                        highestTitle = royalTitleDef;
                    }
                }
            }
            source = source.Where(delegate(ThingDef x)
            {
                CompProperties_Techprint compProperties = x.GetCompProperties <CompProperties_Techprint>();
                if (compProperties != null)
                {
                    if (parms.makingFaction != null && !compProperties.project.heldByFactionCategoryTags.Contains(parms.makingFaction.def.categoryTag))
                    {
                        return(false);
                    }
                    if (compProperties.project.IsFinished || compProperties.project.TechprintRequirementMet)
                    {
                        return(false);
                    }
                }
                if (parms.makingFaction != null && parms.makingFaction.def.HasRoyalTitles)
                {
                    RoyalTitleDef minTitleToUse = ThingRequiringRoyalPermissionUtility.GetMinTitleToUse(x, parms.makingFaction);
                    if (minTitleToUse != null && (highestTitle == null || highestTitle.seniority < minTitleToUse.seniority))
                    {
                        return(false);
                    }
                }
                return(true);
            });
            return(source.Where((ThingDef x) => CanGenerate(x) && (!parms.maxThingMarketValue.HasValue || x.BaseMarketValue <= parms.maxThingMarketValue) && (parms.validator == null || parms.validator(x))));
        }
Exemple #2
0
 public static IEnumerable <ResearchProjectDef> GetResearchProjectsNeedingTechprintsNow(Faction faction, List <ThingDef> alreadyGeneratedTechprints = null, float maxMarketValue = float.MaxValue)
 {
     return(DefDatabase <ResearchProjectDef> .AllDefsListForReading.Where(delegate(ResearchProjectDef p)
     {
         if (p.TechprintCount == 0)
         {
             return false;
         }
         if (p.IsFinished || p.TechprintRequirementMet)
         {
             return false;
         }
         if (faction != null && (p.heldByFactionCategoryTags == null || !p.heldByFactionCategoryTags.Contains(faction.def.categoryTag)))
         {
             return false;
         }
         if (maxMarketValue != float.MaxValue && p.Techprint.BaseMarketValue > maxMarketValue)
         {
             return false;
         }
         if (alreadyGeneratedTechprints != null)
         {
             CompProperties_Techprint compProperties = p.Techprint.GetCompProperties <CompProperties_Techprint>();
             if (compProperties != null)
             {
                 int num = compProperties.project.TechprintCount - compProperties.project.TechprintsApplied;
                 int num2 = 0;
                 for (int i = 0; i < alreadyGeneratedTechprints.Count; i++)
                 {
                     if (alreadyGeneratedTechprints[i] == p.Techprint)
                     {
                         num2++;
                     }
                 }
                 if (num2 >= num)
                 {
                     return false;
                 }
             }
         }
         return true;
     }));
 }