private void CleanupCurrentJob(JobCondition condition, bool releaseReservations,
                                bool cancelBusyStancesSoft = true)
 {
     if (debugLog)
     {
         DebugLogEvent(string.Concat("CleanupCurrentJob ", curJob == null ? "null" : curJob.def.ToString(),
                                     " condition ", condition));
     }
     if (curJob == null)
     {
         return;
     }
     curDriver.ended = true;
     curDriver.Cleanup(condition);
     curDriver = null;
     curJob    = null;
     //if (releaseReservations)
     //{
     //    this.caravan.ClearReservations(false);
     //}
     //if (cancelBusyStancesSoft)
     //{
     //    this.caravan.stances.CancelBusyStanceSoft();
     //}
     //if (!this.caravan.Destroyed && this.caravan.carryTracker != null && this.caravan.carryTracker.CarriedThing != null)
     //{
     //    Thing thing;
     //    this.caravan.carryTracker.TryDropCarriedThing(this.caravan.Position, ThingPlaceMode.Near, out thing, null);
     //}
 }
Esempio n. 2
0
 //private void CleanupCurrentJob(JobCondition condition, bool releaseReservations, bool cancelBusyStancesSoft = true)
 private void CleanupCurrentJob(JobCondition condition)
 {
     DebugLogEvent($"CleanupCurrentJob {curJob?.def.ToString() ?? "null"} condition {condition}");
     if (curJob == null)
     {
         return;
     }
     curDriver.ended = true;
     curDriver.Cleanup(condition);
     curDriver = null;
     curJob    = null;
     //if (releaseReservations)
     //{
     //    caravan.ClearReservations(false);
     //}
     //if (cancelBusyStancesSoft)
     //{
     //    caravan.stances.CancelBusyStanceSoft();
     //}
     //if (!caravan.Destroyed && caravan.carryTracker != null && caravan.carryTracker.CarriedThing != null)
     //{
     //    Thing thing;
     //    caravan.carryTracker.TryDropCarriedThing(caravan.Position, ThingPlaceMode.Near, out thing, null);
     //}
 }
 public void StartJob(CaravanJob newJob, JobCondition lastJobEndCondition = JobCondition.None,
                      ThinkNode jobGiver     = null, bool resumeCurJobAfterwards = false, bool cancelBusyStances = true,
                      ThinkTreeDef thinkTree = null, JobTag?tag = null)
 {
     //Log.Message("JecsTools :: CaravanJobTracker :: JobTracker StartJob :: " + newJob.def.label);
     if (!Find.TickManager.Paused || lastJobGivenAtFrame == RealTime.frameCount)
     {
         jobsGivenThisTick++;
         jobsGivenThisTickTextual = jobsGivenThisTickTextual + "(" + newJob + ") ";
     }
     lastJobGivenAtFrame = RealTime.frameCount;
     if (jobsGivenThisTick > 10)
     {
         var text = jobsGivenThisTickTextual;
         jobsGivenThisTick        = 0;
         jobsGivenThisTickTextual = string.Empty;
         StartErrorRecoverJob(string.Concat(caravan, " started 10 jobs in one tick. newJob=", newJob,
                                            " jobGiver=", jobGiver, " jobList=", text));
         return;
     }
     if (debugLog)
     {
         DebugLogEvent(string.Concat("StartJob [", newJob, "] lastJobEndCondition=", lastJobEndCondition,
                                     ", jobGiver=", jobGiver, ", cancelBusyStances=", cancelBusyStances));
     }
     if (curJob != null)
     {
         if (lastJobEndCondition == JobCondition.None)
         {
             Log.Warning(string.Concat(caravan, " starting job ", newJob, " while already having job ", curJob,
                                       " without a specific job end condition."));
             lastJobEndCondition = JobCondition.InterruptForced;
         }
         if (resumeCurJobAfterwards && curJob.def.suspendable)
         {
             jobQueue.EnqueueFirst(curJob, null);
             if (debugLog)
             {
                 DebugLogEvent("   JobQueue EnqueueFirst curJob: " + curJob);
             }
         }
         CleanupCurrentJob(lastJobEndCondition, !resumeCurJobAfterwards, cancelBusyStances);
     }
     if (newJob == null)
     {
         Log.Warning(caravan + " tried to start doing a null job.");
         return;
     }
     newJob.startTick = Find.TickManager.TicksGame;
     if (newJob.playerForced)
     {
         newJob.ignoreForbidden    = true;
         newJob.ignoreDesignations = true;
     }
     curJob    = newJob;
     curDriver = curJob.MakeDriver(caravan);
     curDriver.Notify_Starting();
     curDriver.SetupToils();
     curDriver.ReadyForNextToil();
 }
Esempio n. 4
0
 public bool TryTakeOrderedJob(CaravanJob job, JobTag tag = JobTag.Misc)
 {
     DebugLogEvent("TakeOrderedJob " + job);
     job.playerForced = true;
     if (curJob != null && curJob.JobIsSameAs(job))
     {
         return(true);
     }
     caravan.pather.StopDead();
     //caravan.Map.CaravanDestinationManager.UnreserveAllFor(caravan);
     //if (job.def == CaravanJobDefOf.Goto)
     //{
     //    //caravan.Map.CaravanDestinationManager.ReserveDestinationFor(caravan, job.targetA.Cell);
     //}
     DebugLogEvent("    Queueing job");
     jobQueue.Clear();
     jobQueue.EnqueueFirst(job, tag);
     if (IsCurrentJobPlayerInterruptible())
     {
         if (curJob != null)
         {
             curDriver.EndJobWith(JobCondition.InterruptForced);
         }
         else
         {
             CheckForJobOverride();
         }
     }
     return(true);
 }
Esempio n. 5
0
        public string ReportStringProcessed(string str)
        {
            CaravanJob curJob = this.CurJob;

            if (curJob.targetA.HasThing)
            {
                str = str.Replace("TargetA", curJob.targetA.Thing.LabelShort);
            }
            else
            {
                str = str.Replace("TargetA", "AreaLower".Translate());
            }
            if (curJob.targetB.HasThing)
            {
                str = str.Replace("TargetB", curJob.targetB.Thing.LabelShort);
            }
            else
            {
                str = str.Replace("TargetB", "AreaLower".Translate());
            }
            if (curJob.targetC.HasThing)
            {
                str = str.Replace("TargetC", curJob.targetC.Thing.LabelShort);
            }
            else
            {
                str = str.Replace("TargetC", "AreaLower".Translate());
            }
            return(str);
        }
Esempio n. 6
0
        public void EndCurrentJob(JobCondition condition, bool startNewJob = true)
        {
            if (this.debugLog)
            {
                this.DebugLogEvent(string.Concat(new object[]
                {
                    "EndCurrentJob ",
                    (this.curJob == null) ? "null" : this.curJob.ToString(),
                    " condition=",
                    condition,
                    " curToil=",
                    (this.curDriver == null) ? "null_driver" : this.curDriver.CurToilIndex.ToString()
                }));
            }
            CaravanJob job = this.curJob;

            this.CleanupCurrentJob(condition, true, true);
            if (startNewJob)
            {
                if (condition == JobCondition.ErroredPather || condition == JobCondition.Errored)
                {
                    //this.StartJob(new CaravanJob(JobDefOf.Wait, 250, false), JobCondition.None, null, false, true, null, null);
                    return;
                }
                if (condition == JobCondition.Succeeded && job != null && !this.caravan.pather.Moving) //&& job.def != JobDefOf.WaitMaintainPosture )
                {
                    //this.StartJob(new CaravanJob(JobDefOf.WaitMaintainPosture, 1, false), JobCondition.None, null, false, false, null, null);
                }
                else
                {
                    this.TryFindAndStartJob();
                }
            }
        }
 public bool TryTakeOrderedJobPrioritizedWork(CaravanJob job, WorkGiver giver, IntVec3 cell)
 {
     if (TryTakeOrderedJob(job, giver.def.tagToGive))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
 public bool TryTakeOrderedJobPrioritizedWork(CaravanJob job, WorkGiver giver, IntVec3 cell)
 {
     if (this.TryTakeOrderedJob(job, giver.def.tagToGive))
     {
         //this.caravan.mindState.lastGivenWorkType = giver.def.workType;
         //if (giver.def.prioritizeSustains)
         //{
         //    this.caravan.mindState.priorityWork.Set(cell, giver.def.workType);
         //}
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
        private void TryFindAndStartJob()
        {
            //if (this.caravan.thinker == null)
            //{
            //    Log.ErrorOnce(this.caravan + " did TryFindAndStartJob but had no thinker.", 8573261);
            //    return;
            //}
            if (this.curJob != null)
            {
                Log.Warning(this.caravan + " doing TryFindAndStartJob while still having job " + this.curJob);
            }
            if (this.debugLog)
            {
                this.DebugLogEvent("TryFindAndStartJob");
            }
            if (!this.CanDoAnyJob())
            {
                if (this.debugLog)
                {
                    this.DebugLogEvent("   CanDoAnyJob is false. Clearing queue and returning");
                }
                if (this.jobQueue != null)
                {
                    this.jobQueue.Clear();
                }
                return;
            }
            //ThinkTreeDef thinkTreeDef;
            //ThinkResult result = this.DetermineNextJob(out thinkTreeDef);
            //if (result.IsValid)
            //{
            //    this.CheckLeaveJoinableLordBecauseJobIssued(result);
            //    ThinkNode sourceNode = result.SourceNode;
            //    ThinkTreeDef thinkTree = thinkTreeDef;
            //    this.StartJob(result.Job, JobCondition.None, sourceNode, false, false, thinkTree, result.Tag);
            //}

            //ThinkTreeDef thinkTreeDef;
            //Log.Message("JecsTools :: CaravanJobTracker :: JobTracker TryFindStartNextJob");
            CaravanJob result = this.DetermineNextJob();

            if (result != null && result.CanBeginNow(caravan))
            {
                Log.Message("JecsTools :: CaravanJobTracker :: JobTracker StartJob :: " + result.def.label);
                this.StartJob(result, JobCondition.None, null, false, false, null, null);
            }
        }
Esempio n. 10
0
 public bool JobIsSameAs(CaravanJob other)
 {
     return(other != null && def == other.def && !(targetA != other.targetA) && !(targetB != other.targetB) &&
            verbToUse == other.verbToUse && !(targetC != other.targetC) && commTarget == other.commTarget &&
            bill == other.bill);
 }
Esempio n. 11
0
 public QueuedCaravanJob(CaravanJob job, JobTag?tag)
 {
     this.job = job;
     this.tag = tag;
 }
Esempio n. 12
0
 public void EnqueueLast(CaravanJob j, JobTag?tag = null)
 {
     this.jobs.Add(new QueuedCaravanJob(j, tag));
 }
Esempio n. 13
0
 public void EnqueueFirst(CaravanJob j, JobTag?tag = null)
 {
     this.jobs.Insert(0, new QueuedCaravanJob(j, tag));
 }
Esempio n. 14
0
 public void DriverTick()
 {
     try
     {
         this.ticksLeftThisToil--;
         this.debugTicksSpentThisToil++;
         if (this.CurToil == null)
         {
             //if (!this.caravan.stances.FullBodyBusy || this.CanStartNextToilInBusyStance)
             //{
             this.ReadyForNextToil();
             //}
         }
         else if (!this.CheckCurrentToilEndOrFail())
         {
             if (this.curToilCompleteMode == ToilCompleteMode.Delay)
             {
                 if (this.ticksLeftThisToil <= 0)
                 {
                     this.ReadyForNextToil();
                     return;
                 }
             }
             else if (this.curToilCompleteMode == ToilCompleteMode.FinishedBusy) //&& !this.caravan.stances.FullBodyBusy)
             {
                 this.ReadyForNextToil();
                 return;
             }
             if (this.wantBeginNextToil)
             {
                 this.TryActuallyStartNextToil();
             }
             else if (this.curToilCompleteMode == ToilCompleteMode.Instant && this.debugTicksSpentThisToil > 300)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     this.caravan,
                     " had to be broken from frozen state. He was doing job ",
                     this.CurJob,
                     ", toilindex=",
                     this.curToilIndex
                 }));
                 this.ReadyForNextToil();
             }
             else
             {
                 CaravanJob curJob = this.CurJob;
                 if (this.CurToil.preTickActions != null)
                 {
                     CaravanToil curToil = this.CurToil;
                     for (int i = 0; i < curToil.preTickActions.Count; i++)
                     {
                         curToil.preTickActions[i]();
                         if (this.CurJob != curJob)
                         {
                             return;
                         }
                         if (this.CurToil != curToil || this.wantBeginNextToil)
                         {
                             return;
                         }
                     }
                 }
                 if (this.CurToil.tickAction != null)
                 {
                     this.CurToil.tickAction();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Find.World.GetComponent <CaravanJobGiver>().Tracker(caravan).StartErrorRecoverJob(string.Concat(new object[]
         {
             "Exception in Tick (pawn=",
             this.caravan,
             ", job=",
             this.CurJob,
             ", CurToil=",
             this.curToilIndex,
             "): ",
             ex
         }));
     }
 }