public static bool BuildingPresent(ResearchProjectDef research)
        {
            // try get from cache
            bool result;

            if (_buildingPresentCache.TryGetValue(research, out result))
            {
                return(result);
            }

            // do the work manually
            if (research.requiredResearchBuilding == null)
            {
                result = true;
            }
            else
            {
                result = Find.Maps.SelectMany(map => map.listerBuildings.allBuildingsColonist)
                         .OfType <Building_ResearchBench>()
                         .Any(b => research.CanBeResearchedAt(b, true));
            }

            if (result)
            {
                result = research.GetPrerequisitesRecursive().All(BuildingPresent);
            }

            // update cache
            _buildingPresentCache.Add(research, result);
            return(result);
        }
Exemple #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);
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            ResearchProjectDef currentProj = Find.ResearchManager.currentProj;

            if (currentProj == null)
            {
                return(false);
            }

            // --- new code ---
            if (!Find.ResearchManager.currentProj.HasModExtension <ForbiddenResearchExtension>() && t.def.defName == "Cults_OccultResearchBench")
            {
                return(false);
            }
            // --- -------- ---

            Building_ResearchBench building_ResearchBench = t as Building_ResearchBench;

            if (building_ResearchBench == null)
            {
                return(false);
            }
            if (!currentProj.CanBeResearchedAt(building_ResearchBench, ignoreResearchBenchPowerStatus: false))
            {
                return(false);
            }
            if (!pawn.CanReserve(t, 1, -1, null, forced))
            {
                return(false);
            }
            return(true);
        }
        private bool IsLocked(ResearchProjectDef research)
        {
            if (research.requiredResearchBuilding != null || !research.requiredResearchFacilities.NullOrEmpty())
            {
                if (ResearchPalMod.allResearchBenches.NullOrEmpty())
                {
                    return(true);
                }

                foreach (var bench in ResearchPalMod.allResearchBenches)
                {
                    if (research.CanBeResearchedAt(bench, false))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        private void ResolveNonOccultProjects()
        {
            //First, declare our variables.
            ResearchProjectDef currentProject = Find.ResearchManager.currentProj;
            Pawn interactingPawn = InteractingPawn;

            if (currentProject == null)
            {
                return;
            }

            if (interactingPawn == null)
            {
                return;
            }
            if (Find.World.GetComponent <WorldComponent_GlobalCultTracker>().cultResearch == null)
            {
                return;
            }
            //Are we using this for the correct project type?
            this.SetForbidden(false);
            if (IsThisCultistResearch(currentProject))
            {
                return;
            }
            this.SetForbidden(true);
            //Uh oh.
            //Let's try and find another research station to research this at.
            Building_ResearchBench bench = null;

            foreach (Building bld in Map.listerBuildings.allBuildingsColonist)
            {
                if (bld != this && bld.def != this.def)
                {
                    if (bld is Building_ResearchBench)
                    {
                        bench = bld as Building_ResearchBench;
                    }
                }
            }

            //No building found? Cancel the research projects.
            if (bench == null)
            {
                CancelResearch("Cannot use the grimoire to research standard research projects.");
                return;
            }

            //We found a research bench! Can we send the researcher there?
            if (!currentProject.CanBeResearchedAt(bench, false))
            {
                CancelResearch("Cannot research this project at the forbidden center.");
            }
            if (!interactingPawn.CanReach(bench, Verse.AI.PathEndMode.ClosestTouch, Danger.Deadly))
            {
                CancelResearch("Cannot research this project at the forbidden center.");
            }
            if (!interactingPawn.CanReserve(bench)) //Map.reservationManager.IsReserved(bench, Faction.OfPlayer))
            {
                this.SetForbidden(true);
                interactingPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                return;
            }

            //Okay, assign a job over there instead of here.
            Job J = new Job(JobDefOf.Research, bench);

            Map.reservationManager.ReleaseAllClaimedBy(interactingPawn);
            interactingPawn.jobs.TryTakeOrderedJob(J);
            //interactingpawn.CurJob.EndCurrentJob(JobCondition.InterruptForced);
        }