예제 #1
0
        protected override bool Satisfied(Pawn pawn)
        {
            if (pawn.IsPrisoner)
            {
                //show tutorials
                Tutorials.Introduction();
                Tutorials.Management();

                IntVec3 c;

                var need = pawn.needs.TryGetNeed <Need_Motivation>();
                if (need == null)
                {
                    if (!pawn.guest.PrisonerIsSecure || RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
                    {
                        return(false);
                    }
                    else if (PrisonLaborUtility.LaborEnabled(pawn))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                // Prisoner will escape if get ready to run.
                // If he can run he will start ticking impatient, once complete he will get ready.
                if (!pawn.guest.PrisonerIsSecure ||
                    RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
                {
                    need.CanEscape = true;
                    if (need.ReadyToRun)
                    {
                        return(false);
                    }
                }
                else
                {
                    need.CanEscape = false;
                }


                if (PrisonLaborUtility.LaborEnabled(pawn))
                {
                    return(true);
                }

                need.Enabled = false;
            }
            return(false);
        }
예제 #2
0
 public static void Save()
 {
     Tutorials.UpdateTutorialFlags();
     try
     {
         var xDocument = new XDocument();
         var content   = DirectXmlSaver.XElementFromObject(data, typeof(PrisonLaborPrefsData));
         xDocument.Add(content);
         xDocument.Save(prefsFilePath);
     }
     catch (Exception ex)
     {
         GenUI.ErrorDialog("ProblemSavingFile".Translate(prefsFilePath, ex.ToString()));
         Log.Error("Exception saving prefs: " + ex);
     }
 }
예제 #3
0
        public override void NeedInterval()
        {
            CurLevel += LazinessRate;

            if (CurLevel == MaxLevel)
            {
                NeedToBeInspired = false;
            }
            if (CurLevel <= NeedInspirationLevel && !NeedToBeInspired)
            {
                NeedToBeInspired = true;
            }
            if (CurLevel <= LazyLevel && !IsLazy && delta <= 0)
            {
                IsLazy = true;
                Tutorials.Motivation();
            }
            else if (IsLazy && delta > 0)
            {
                IsLazy = false;
            }

            ImpatientTick();
        }
예제 #4
0
 public static void ResetTutorials()
 {
     data.tutorials_flags = TutorialFlag.None;
     Tutorials.Reset();
 }
예제 #5
0
 public static void Apply()
 {
     data.Apply();
     WorkSettings.DataString = AllowedWorkTypes;
     Tutorials.Apply();
 }
        public override Job JobOnCell(Pawn pawn, IntVec3 c)
        {
            //if (!pawn.IsPrisoner)
            //    return null;
            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!GenPlant.GrowthSeasonNow(c, pawn.Map))
            {
                return(null);
            }
            if (wantedPlantDef == null)
            {
                wantedPlantDef = CalculateWantedPlantDef(c, pawn.Map);
                if (wantedPlantDef == null)
                {
                    return(null);
                }
            }
            var thingList = c.GetThingList(pawn.Map);

            for (var i = 0; i < thingList.Count; i++)
            {
                var thing = thingList[i];
                if (thing.def == wantedPlantDef)
                {
                    return(null);
                }
                if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction)
                {
                    return(null);
                }
            }
            var plant = c.GetPlant(pawn.Map);

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (!pawn.CanReserve(plant, 1, -1, null, false) || plant.IsForbidden(pawn))
                {
                    return(null);
                }
                return(new Job(JobDefOf.CutPlant, plant));
            }
            var thing2 = GenPlant.AdjacentSowBlocker(wantedPlantDef, c, pawn.Map);

            if (thing2 != null)
            {
                var plant2 = thing2 as Plant;
                if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn))
                {
                    var plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                    if (plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def)
                    {
                        return(new Job(JobDefOf.CutPlant, plant2));
                    }
                }
                return(null);
            }
            if (wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Growing).Level < wantedPlantDef.plant.sowMinSkill)
            {
                return(null);
            }
            if (pawn.IsPrisoner && wantedPlantDef.plant.sowMinSkill > 6 && !PrisonLaborPrefs.AdvancedGrowing)
            {
                Tutorials.Growing();
                return(null);
            }
            var j = 0;

            while (j < thingList.Count)
            {
                var thing3 = thingList[j];
                if (thing3.def.BlockPlanting)
                {
                    if (!pawn.CanReserve(thing3, 1, -1, null, false))
                    {
                        return(null);
                    }
                    if (thing3.def.category == ThingCategory.Plant)
                    {
                        if (!thing3.IsForbidden(pawn))
                        {
                            return(new Job(JobDefOf.CutPlant, thing3));
                        }
                        return(null);
                    }
                    if (thing3.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                    }
                    return(null);
                }
                j++;
            }
            if (!wantedPlantDef.CanEverPlantAt(c, pawn.Map) || !GenPlant.GrowthSeasonNow(c, pawn.Map) ||
                !pawn.CanReserve(c, 1, -1, null, false))
            {
                return(null);
            }
            return(new Job(JobDefOf.Sow, c)
            {
                plantDefToSow = wantedPlantDef
            });
        }
예제 #7
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            var need = pawn.needs.TryGetNeed <Need_Motivation>();

            if (pawn.timetable == null)
            {
                PrisonLaborUtility.InitWorkSettings(pawn);
            }
            if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
            {
                return(ThinkResult.NoJob);
            }
            //Check medical assistance, fed, and rest if not override
            if (!PrisonLaborUtility.WorkTime(pawn))
            {
                Tutorials.Timetable();
                if (need != null)
                {
                    need.Enabled = false;
                }
                return(ThinkResult.NoJob);
            }
            //Check motivation
            if (PrisonLaborPrefs.EnableMotivationMechanics && (need == null || need.IsLazy))
            {
                return(ThinkResult.NoJob);
            }
            //Work prisoners will do
            PrisonLaborUtility.InitWorkSettings(pawn);
            var workList = pawn.workSettings.WorkGiversInOrderNormal;

            //TODO check this
            //workList.RemoveAll(workGiver => workGiver.def.defName == "GrowerSow");
            if (need != null)
            {
                need.Enabled = false;
            }

            var num        = -999;
            var targetInfo = TargetInfo.Invalid;
            WorkGiver_Scanner workGiver_Scanner = null;

            for (var j = 0; j < workList.Count; j++)
            {
                var workGiver = workList[j];
                if (workGiver.def.priorityInType != num && targetInfo.IsValid)
                {
                    break;
                }
                if (PawnCanUseWorkGiver(pawn, workGiver))
                {
                    try
                    {
                        var job2 = workGiver.NonScanJob(pawn);
                        if (job2 != null)
                        {
                            if (need != null)
                            {
                                need.Enabled = true;
                            }
                            return(new ThinkResult(job2, this, workList[j].def.tagToGive));
                        }
                        var scanner = workGiver as WorkGiver_Scanner;
                        if (scanner != null)
                        {
                            if (workGiver.def.scanThings)
                            {
                                Predicate <Thing> predicate = t =>
                                                              !t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t, false);
                                var   enumerable = scanner.PotentialWorkThingsGlobal(pawn);
                                Thing thing;
                                if (scanner.Prioritized)
                                {
                                    var enumerable2 = enumerable;
                                    if (enumerable2 == null)
                                    {
                                        enumerable2 =
                                            pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest);
                                    }
                                    var validator = predicate;
                                    thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map,
                                                                                     enumerable2, scanner.PathEndMode,
                                                                                     TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f,
                                                                                     validator, x => scanner.GetPriority(pawn, x));
                                }
                                else
                                {
                                    var validator         = predicate;
                                    var forceGlobalSearch = enumerable != null;
                                    thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map,
                                                                             scanner.PotentialWorkThingRequest, scanner.PathEndMode,
                                                                             TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f,
                                                                             validator, enumerable, 0, scanner.LocalRegionsToScanFirst, forceGlobalSearch,
                                                                             RegionType.Set_Passable, false);
                                }
                                if (thing != null)
                                {
                                    targetInfo        = thing;
                                    workGiver_Scanner = scanner;
                                }
                            }
                            if (workGiver.def.scanCells)
                            {
                                var position    = pawn.Position;
                                var num2        = 99999f;
                                var num3        = -3.40282347E+38f;
                                var prioritized = scanner.Prioritized;
                                foreach (var current in scanner.PotentialWorkCellsGlobal(pawn))
                                {
                                    var   flag = false;
                                    float num4 = (current - position).LengthHorizontalSquared;
                                    if (prioritized)
                                    {
                                        if (!current.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, current))
                                        {
                                            var priority = scanner.GetPriority(pawn, current);
                                            if (priority > num3 || priority == num3 && num4 < num2)
                                            {
                                                flag = true;
                                                num3 = priority;
                                            }
                                        }
                                    }
                                    else if (num4 < num2 && !current.IsForbidden(pawn) &&
                                             scanner.HasJobOnCell(pawn, current))
                                    {
                                        flag = true;
                                    }
                                    if (flag)
                                    {
                                        targetInfo        = new TargetInfo(current, pawn.Map, false);
                                        workGiver_Scanner = scanner;
                                        num2 = num4;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Concat(pawn, " threw exception in WorkGiver ", workGiver.def.defName, ": ",
                                                ex.ToString()));
                    }
                    finally
                    {
                    }
                    if (targetInfo.IsValid)
                    {
                        pawn.mindState.lastGivenWorkType = workGiver.def.workType;
                        Job job3;
                        if (targetInfo.HasThing)
                        {
                            job3 = workGiver_Scanner.JobOnThing(pawn, targetInfo.Thing, false);
                        }
                        else
                        {
                            job3 = workGiver_Scanner.JobOnCell(pawn, targetInfo.Cell);
                        }
                        if (job3 != null)
                        {
                            if (need != null)
                            {
                                need.Enabled = true;
                            }
                            return(new ThinkResult(job3, this, workList[j].def.tagToGive));
                        }
                        Log.ErrorOnce(
                            string.Concat(workGiver_Scanner, " provided target ", targetInfo,
                                          " but yielded no actual job for pawn ", pawn,
                                          ". The CanGiveJob and JobOnX methods may not be synchronized."), 6112651);
                    }
                    num = workGiver.def.priorityInType;
                }
            }
            return(ThinkResult.NoJob);
        }
예제 #8
0
 public static void Apply()
 {
     data.Apply();
     PrisonLaborUtility.AllowedWorkTypesData = AllowedWorkTypes;
     Tutorials.Apply();
 }