예제 #1
0
 public static bool StartJob(Pawn_JobTracker __instance,
                             Job newJob,
                             JobCondition lastJobEndCondition = JobCondition.None,
                             ThinkNode jobGiver          = null,
                             bool resumeCurJobAfterwards = false,
                             bool cancelBusyStances      = true,
                             ThinkTreeDef thinkTree      = null,
                             JobTag?tag                 = null,
                             bool fromQueue             = false,
                             bool canReturnCurJobToPool = false)
 {
     __instance.startingNewJob = true;
     try
     {
         if (!fromQueue && (!Find.TickManager.Paused || __instance.lastJobGivenAtFrame == RealTime.frameCount))
         {
             ++__instance.jobsGivenThisTick;
             if (Prefs.DevMode)
             {
                 __instance.jobsGivenThisTickTextual = __instance.jobsGivenThisTickTextual + "(" + newJob.ToString() + ") ";
             }
         }
         __instance.lastJobGivenAtFrame = RealTime.frameCount;
         if (__instance.jobsGivenThisTick > 10)
         {
             string givenThisTickTextual = __instance.jobsGivenThisTickTextual;
             __instance.jobsGivenThisTick        = 0;
             __instance.jobsGivenThisTickTextual = "";
             __instance.startingNewJob           = false;
             __instance.pawn.ClearReservationsForJob(newJob);
             JobUtility.TryStartErrorRecoverJob(__instance.pawn, __instance.pawn.ToStringSafe <Pawn>() + " started 10 jobs in one tick. newJob=" + newJob.ToStringSafe <Job>() + " jobGiver=" + jobGiver.ToStringSafe <ThinkNode>() + " jobList=" + givenThisTickTextual);
         }
         else
         {
             if (__instance.debugLog)
             {
                 __instance.DebugLogEvent("StartJob [" + (object)newJob + "] lastJobEndCondition=" + (object)lastJobEndCondition + ", jobGiver=" + (object)jobGiver + ", cancelBusyStances=" + cancelBusyStances.ToString());
             }
             Pawn_StanceTracker stances = __instance.pawn.stances;             //changed
             if (cancelBusyStances && stances != null && stances.FullBodyBusy) //changed
             {
                 stances.CancelBusyStanceHard();
             }
             if (__instance.curJob != null)
             {
                 if (lastJobEndCondition == JobCondition.None)
                 {
                     Log.Warning(__instance.pawn.ToString() + " starting job " + (object)newJob + " from JobGiver " + (object)newJob.jobGiver + " while already having job " + (object)__instance.curJob + " without a specific job end condition.");
                     lastJobEndCondition = JobCondition.InterruptForced;
                 }
                 if (resumeCurJobAfterwards && __instance.curJob.def.suspendable)
                 {
                     __instance.jobQueue.EnqueueFirst(__instance.curJob);
                     if (__instance.debugLog)
                     {
                         __instance.DebugLogEvent("   JobQueue EnqueueFirst curJob: " + (object)__instance.curJob);
                     }
                     __instance.CleanupCurrentJob(lastJobEndCondition, false, cancelBusyStances);
                 }
                 else
                 {
                     __instance.CleanupCurrentJob(lastJobEndCondition, true, cancelBusyStances, canReturnCurJobToPool);
                 }
             }
             if (newJob == null)
             {
                 Log.Warning(__instance.pawn.ToString() + " tried to start doing a null job.");
             }
             else
             {
                 newJob.startTick = Find.TickManager.TicksGame;
                 if (__instance.pawn.Drafted || newJob.playerForced)
                 {
                     newJob.ignoreForbidden    = true;
                     newJob.ignoreDesignations = true;
                 }
                 __instance.curJob = newJob;
                 __instance.curJob.jobGiverThinkTree = thinkTree;
                 __instance.curJob.jobGiver          = jobGiver;
                 JobDriver cDriver = __instance.curJob.MakeDriver(__instance.pawn); //changed
                 __instance.curDriver = cDriver;                                    //changed
                 bool flag = fromQueue;
                 if (__instance.curDriver.TryMakePreToilReservations(!flag))
                 {
                     Job newJob1 = __instance.TryOpportunisticJob(newJob);
                     if (newJob1 != null)
                     {
                         __instance.jobQueue.EnqueueFirst(newJob);
                         __instance.curJob    = (Job)null;
                         __instance.curDriver = (JobDriver)null;
                         __instance.StartJob(newJob1);
                     }
                     else
                     {
                         if (tag.HasValue)
                         {
                             __instance.pawn.mindState.lastJobTag = tag.Value;
                         }
                         cDriver.SetInitialPosture(); //changed
                         cDriver.Notify_Starting();   //changed
                         cDriver.SetupToils();        //changed
                         cDriver.ReadyForNextToil();  //changed
                     }
                 }
                 else if (flag)
                 {
                     __instance.EndCurrentJob(JobCondition.QueuedNoLongerValid);
                 }
                 else
                 {
                     Log.Warning("TryMakePreToilReservations() returned false for a non-queued job right after StartJob(). This should have been checked before. curJob=" + __instance.curJob.ToStringSafe <Job>());
                     __instance.EndCurrentJob(JobCondition.Errored);
                 }
             }
         }
     }
     finally
     {
         __instance.startingNewJob = false;
     }
     return(false);
 }