예제 #1
0
        private Building_ResearchBench FindBenchFulfillingMostRequirements(ThingDef requiredResearchBench, List <ThingDef> requiredFacilities)
        {
            tmpAllBuildings.Clear();
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                tmpAllBuildings.AddRange(maps[i].listerBuildings.allBuildingsColonist);
            }
            float num = 0f;
            Building_ResearchBench building_ResearchBench = null;

            for (int j = 0; j < tmpAllBuildings.Count; j++)
            {
                Building_ResearchBench building_ResearchBench2 = tmpAllBuildings[j] as Building_ResearchBench;
                if (building_ResearchBench2 != null && (requiredResearchBench == null || building_ResearchBench2.def == requiredResearchBench))
                {
                    float researchBenchRequirementsScore = GetResearchBenchRequirementsScore(building_ResearchBench2, requiredFacilities);
                    if (building_ResearchBench == null || researchBenchRequirementsScore > num)
                    {
                        num = researchBenchRequirementsScore;
                        building_ResearchBench = building_ResearchBench2;
                    }
                }
            }
            tmpAllBuildings.Clear();
            return(building_ResearchBench);
        }
예제 #2
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            ResearchProjectDef currentProj = Find.ResearchManager.currentProj;

            if (currentProj == null)
            {
                return(false);
            }
            Building_ResearchBench building_ResearchBench = t as Building_ResearchBench;

            if (building_ResearchBench == null)
            {
                return(false);
            }
            if (!currentProj.CanBeResearchedAt(building_ResearchBench, false))
            {
                return(false);
            }
            LocalTargetInfo target = t;

            if (!pawn.CanReserve(target, 1, -1, null, forced))
            {
                return(false);
            }
            return(true);
        }
        private float DrawResearchBenchRequirements(ResearchProjectDef project, Rect rect)
        {
            float xMin = rect.xMin;
            float yMin = rect.yMin;

            if (project.requiredResearchBuilding != null)
            {
                bool       present = false;
                List <Map> maps    = Find.Maps;
                for (int i = 0; i < maps.Count; i++)
                {
                    if (maps[i].listerBuildings.allBuildingsColonist.Find((Building x) => x.def == project.requiredResearchBuilding) != null)
                    {
                        present = true;
                        break;
                    }
                }
                Widgets.LabelCacheHeight(ref rect, "RequiredResearchBench".Translate() + ":");
                rect.xMin += 6f;
                rect.yMin += rect.height;
                SetPrerequisiteStatusColor(present, project);
                rect.height = Text.CalcHeight(project.requiredResearchBuilding.LabelCap, rect.width - 24f - 6f);
                Widgets.HyperlinkWithIcon(rect, new Dialog_InfoCard.Hyperlink(project.requiredResearchBuilding));
                rect.yMin += rect.height + 4f;
                GUI.color  = Color.white;
                rect.xMin  = xMin;
            }
            if (!project.requiredResearchFacilities.NullOrEmpty())
            {
                Widgets.LabelCacheHeight(ref rect, "RequiredResearchBenchFacilities".Translate() + ":");
                rect.yMin += rect.height;
                Building_ResearchBench   building_ResearchBench = FindBenchFulfillingMostRequirements(project.requiredResearchBuilding, project.requiredResearchFacilities);
                CompAffectedByFacilities bestMatchingBench      = null;
                if (building_ResearchBench != null)
                {
                    bestMatchingBench = building_ResearchBench.TryGetComp <CompAffectedByFacilities>();
                }
                rect.xMin += 6f;
                for (int j = 0; j < project.requiredResearchFacilities.Count; j++)
                {
                    DrawResearchBenchFacilityRequirement(project.requiredResearchFacilities[j], bestMatchingBench, project, ref rect);
                    rect.yMin += rect.height;
                }
                rect.yMin += 4f;
            }
            GUI.color = Color.white;
            rect.xMin = xMin;
            return(rect.yMin - yMin);
        }
        private float DrawResearchBenchRequirements(ResearchProjectDef project, Rect rect)
        {
            float yMin = rect.yMin;

            if (project.requiredResearchBuilding != null)
            {
                bool       present = false;
                List <Map> maps    = Find.Maps;
                int        num     = 0;
                while (num < maps.Count)
                {
                    if (maps[num].listerBuildings.allBuildingsColonist.Find((Building x) => x.def == project.requiredResearchBuilding) == null)
                    {
                        num++;
                        continue;
                    }
                    present = true;
                    break;
                }
                Widgets.LabelCacheHeight(ref rect, "RequiredResearchBench".Translate() + ":", true, false);
                rect.yMin += rect.height;
                this.SetPrerequisiteStatusColor(present, project);
                Widgets.LabelCacheHeight(ref rect, "  " + project.requiredResearchBuilding.LabelCap, true, false);
                rect.yMin += rect.height;
                GUI.color  = Color.white;
            }
            if (!project.requiredResearchFacilities.NullOrEmpty())
            {
                Widgets.LabelCacheHeight(ref rect, "RequiredResearchBenchFacilities".Translate() + ":", true, false);
                rect.yMin += rect.height;
                Building_ResearchBench   building_ResearchBench = this.FindBenchFulfillingMostRequirements(project.requiredResearchBuilding, project.requiredResearchFacilities);
                CompAffectedByFacilities bestMatchingBench      = null;
                if (building_ResearchBench != null)
                {
                    bestMatchingBench = building_ResearchBench.TryGetComp <CompAffectedByFacilities>();
                }
                for (int i = 0; i < project.requiredResearchFacilities.Count; i++)
                {
                    this.DrawResearchBenchFacilityRequirement(project.requiredResearchFacilities[i], bestMatchingBench, project, ref rect);
                    rect.yMin += 15f;
                }
            }
            GUI.color = Color.white;
            return(rect.yMin - yMin);
        }
예제 #5
0
        private float GetResearchBenchRequirementsScore(Building_ResearchBench bench, List <ThingDef> requiredFacilities)
        {
            float num = 0f;

            for (int i = 0; i < requiredFacilities.Count; i++)
            {
                CompAffectedByFacilities benchComp = bench.GetComp <CompAffectedByFacilities>();
                if (benchComp != null)
                {
                    List <Thing> linkedFacilitiesListForReading = benchComp.LinkedFacilitiesListForReading;
                    if (linkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacilities[i] && benchComp.IsFacilityActive(x)) != null)
                    {
                        num += 1f;
                    }
                    else if (linkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacilities[i]) != null)
                    {
                        num += 0.6f;
                    }
                }
            }
            return(num);
        }