public static Toil ExtractNextTargetFromQueue(TargetIndex ind, bool failIfCountFromQueueTooBig = true)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (targetQueue.NullOrEmpty <LocalTargetInfo>())
                {
                    return;
                }
                if (failIfCountFromQueueTooBig && !curJob.countQueue.NullOrEmpty <int>() && targetQueue[0].HasThing && curJob.countQueue[0] > targetQueue[0].Thing.stackCount)
                {
                    actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                    return;
                }
                curJob.SetTarget(ind, targetQueue[0]);
                targetQueue.RemoveAt(0);
                if (!curJob.countQueue.NullOrEmpty <int>())
                {
                    curJob.count = curJob.countQueue[0];
                    curJob.countQueue.RemoveAt(0);
                }
            };
            return(toil);
        }
Beispiel #2
0
        private static Toil JumpToCollectNextIntoHandsForBill(Toil gotoGetTargetToil, TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
                    return;
                }
                if (actor.carryTracker.Full)
                {
                    return;
                }
                Job curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (targetQueue.NullOrEmpty <LocalTargetInfo>())
                {
                    return;
                }
                for (int i = 0; i < targetQueue.Count; i++)
                {
                    if (GenAI.CanUseItemForWork(actor, targetQueue[i].Thing))
                    {
                        if (targetQueue[i].Thing.CanStackWith(actor.carryTracker.CarriedThing))
                        {
                            if ((float)(actor.Position - targetQueue[i].Thing.Position).LengthHorizontalSquared <= 64f)
                            {
                                int num  = (actor.carryTracker.CarriedThing != null) ? actor.carryTracker.CarriedThing.stackCount : 0;
                                int num2 = curJob.countQueue[i];
                                num2 = Mathf.Min(num2, targetQueue[i].Thing.def.stackLimit - num);
                                num2 = Mathf.Min(num2, actor.carryTracker.AvailableStackSpace(targetQueue[i].Thing.def));
                                if (num2 > 0)
                                {
                                    curJob.count = num2;
                                    curJob.SetTarget(ind, targetQueue[i].Thing);
                                    List <int> countQueue;
                                    int        index;
                                    (countQueue = curJob.countQueue)[index = i] = countQueue[index] - num2;
                                    if (curJob.countQueue[i] <= 0)
                                    {
                                        curJob.countQueue.RemoveAt(i);
                                        targetQueue.RemoveAt(i);
                                    }
                                    actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                                    return;
                                }
                            }
                        }
                    }
                }
            };
            return(toil);
        }
        private static Toil JumpToCollectNextIntoHandsForBill(Toil gotoGetTargetToil, TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
                }
                else if (!actor.carryTracker.Full)
                {
                    Job curJob = actor.jobs.curJob;
                    List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                    if (!targetQueue.NullOrEmpty())
                    {
                        int num = 0;
                        int a;
                        while (true)
                        {
                            if (num < targetQueue.Count)
                            {
                                if (GenAI.CanUseItemForWork(actor, targetQueue[num].Thing) && targetQueue[num].Thing.CanStackWith(actor.carryTracker.CarriedThing) && !((float)(actor.Position - targetQueue[num].Thing.Position).LengthHorizontalSquared > 64.0))
                                {
                                    int num2 = (actor.carryTracker.CarriedThing != null) ? actor.carryTracker.CarriedThing.stackCount : 0;
                                    a = curJob.countQueue[num];
                                    a = Mathf.Min(a, targetQueue[num].Thing.def.stackLimit - num2);
                                    a = Mathf.Min(a, actor.carryTracker.AvailableStackSpace(targetQueue[num].Thing.def));
                                    if (a > 0)
                                    {
                                        break;
                                    }
                                }
                                num++;
                                continue;
                            }
                            return;
                        }
                        curJob.count = a;
                        curJob.SetTarget(ind, targetQueue[num].Thing);
                        List <int> countQueue;
                        int        index;
                        (countQueue = curJob.countQueue)[index = num] = countQueue[index] - a;
                        if (curJob.countQueue[num] <= 0)
                        {
                            curJob.countQueue.RemoveAt(num);
                            targetQueue.RemoveAt(num);
                        }
                        actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                    }
                }
            };
            return(toil);
        }
        public static Toil ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex ind, Func <Thing, bool> validator = null)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                targetQueue.RemoveAll((LocalTargetInfo ta) => !ta.HasThing || !ta.Thing.Spawned || ta.Thing.IsForbidden(actor) || (validator != null && !validator(ta.Thing)));
            };
            return(toil);
        }
Beispiel #5
0
 public static T EndOnNoTargetInQueue <T>(this T f, TargetIndex ind, JobCondition endCondition = JobCondition.Incompletable) where T : IJobEndable
 {
     f.AddEndCondition(delegate
     {
         Pawn actor = f.GetActor();
         Job curJob = actor.jobs.curJob;
         List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
         if (targetQueue.NullOrEmpty())
         {
             return(endCondition);
         }
         return(JobCondition.Ongoing);
     });
     return(f);
 }
Beispiel #6
0
        public static Toil JumpIfHaveTargetInQueue(TargetIndex ind, Toil jumpToil)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (!targetQueue.NullOrEmpty())
                {
                    actor.jobs.curDriver.JumpToToil(jumpToil);
                }
            };
            return(toil);
        }
Beispiel #7
0
        public static Toil ClearQueue(TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (!targetQueue.NullOrEmpty())
                {
                    targetQueue.Clear();
                }
            };
            return(toil);
        }
        private static Toil JumpToCollectNextIntoHandsForBill(Toil gotoGetTargetToil, TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error(string.Concat("JumpToAlsoCollectTargetInQueue run on ", actor, " who is not carrying something."));
                }
                else if (!actor.carryTracker.Full)
                {
                    Job curJob = actor.jobs.curJob;
                    List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                    if (!targetQueue.NullOrEmpty())
                    {
                        for (int i = 0; i < targetQueue.Count; i++)
                        {
                            if (GenAI.CanUseItemForWork(actor, targetQueue[i].Thing) && targetQueue[i].Thing.CanStackWith(actor.carryTracker.CarriedThing) && !((float)(actor.Position - targetQueue[i].Thing.Position).LengthHorizontalSquared > 64f))
                            {
                                int num = ((actor.carryTracker.CarriedThing != null) ? actor.carryTracker.CarriedThing.stackCount : 0);
                                int a   = curJob.countQueue[i];
                                a = Mathf.Min(a, targetQueue[i].Thing.def.stackLimit - num);
                                a = Mathf.Min(a, actor.carryTracker.AvailableStackSpace(targetQueue[i].Thing.def));
                                if (a > 0)
                                {
                                    curJob.count = a;
                                    curJob.SetTarget(ind, targetQueue[i].Thing);
                                    curJob.countQueue[i] -= a;
                                    if (curJob.countQueue[i] <= 0)
                                    {
                                        curJob.countQueue.RemoveAt(i);
                                        targetQueue.RemoveAt(i);
                                    }
                                    actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            return(toil);
        }
Beispiel #9
0
        public static Toil JumpIfAlsoCollectingNextTargetInQueue(Toil gotoGetTargetToil, TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (targetQueue.NullOrEmpty <LocalTargetInfo>())
                {
                    return;
                }
                if (curJob.count <= 0)
                {
                    return;
                }
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.", false);
                    return;
                }
                if (actor.carryTracker.AvailableStackSpace(actor.carryTracker.CarriedThing.def) <= 0)
                {
                    return;
                }
                for (int i = 0; i < targetQueue.Count; i++)
                {
                    if (!GenAI.CanUseItemForWork(actor, targetQueue[i].Thing))
                    {
                        actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        return;
                    }
                    if (targetQueue[i].Thing.def == actor.carryTracker.CarriedThing.def)
                    {
                        curJob.SetTarget(ind, targetQueue[i].Thing);
                        targetQueue.RemoveAt(i);
                        actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                        break;
                    }
                }
            };
            return(toil);
        }
Beispiel #10
0
        public static Toil JumpIfAlsoCollectingNextTargetInQueue(Toil gotoGetTargetToil, TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                if (!targetQueue.NullOrEmpty() && curJob.count > 0)
                {
                    if (actor.carryTracker.CarriedThing == null)
                    {
                        Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
                    }
                    else if (actor.carryTracker.AvailableStackSpace(actor.carryTracker.CarriedThing.def) > 0)
                    {
                        int num = 0;
                        while (true)
                        {
                            if (num < targetQueue.Count)
                            {
                                if (GenAI.CanUseItemForWork(actor, targetQueue[num].Thing))
                                {
                                    if (targetQueue[num].Thing.def != actor.carryTracker.CarriedThing.def)
                                    {
                                        num++;
                                        continue;
                                    }
                                    break;
                                }
                                actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                            }
                            return;
                        }
                        curJob.SetTarget(ind, targetQueue[num].Thing);
                        targetQueue.RemoveAt(num);
                        actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                    }
                }
            };
            return(toil);
        }
            internal void <> m__0()
            {
                Pawn actor  = this.toil.actor;
                Job  curJob = actor.jobs.curJob;
                List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(this.ind);

                if (targetQueue.NullOrEmpty <LocalTargetInfo>())
                {
                    return;
                }
                if (this.failIfCountFromQueueTooBig && !curJob.countQueue.NullOrEmpty <int>() && targetQueue[0].HasThing && curJob.countQueue[0] > targetQueue[0].Thing.stackCount)
                {
                    actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                    return;
                }
                curJob.SetTarget(this.ind, targetQueue[0]);
                targetQueue.RemoveAt(0);
                if (!curJob.countQueue.NullOrEmpty <int>())
                {
                    curJob.count = curJob.countQueue[0];
                    curJob.countQueue.RemoveAt(0);
                }
            }
        public static Toil MoveCurrentTargetIntoQueue(TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Job             curJob = toil.actor.CurJob;
                LocalTargetInfo target = curJob.GetTarget(ind);
                if (target.IsValid)
                {
                    List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                    if (targetQueue == null)
                    {
                        curJob.AddQueuedTarget(ind, target);
                    }
                    else
                    {
                        targetQueue.Insert(0, target);
                    }
                    curJob.SetTarget(ind, null);
                }
            };
            return(toil);
        }
Beispiel #13
0
        public static Toil StartCarryThing(TargetIndex haulableInd, bool putRemainderInQueue = false, bool subtractNumTakenFromJobCount = false, bool failIfStackCountLessThanJobCount = false)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(haulableInd).Thing;
                if (!ErrorCheckForCarry(actor, thing))
                {
                    if (curJob.count == 0)
                    {
                        throw new Exception("StartCarryThing job had count = " + curJob.count + ". Job: " + curJob);
                    }
                    int num = actor.carryTracker.AvailableStackSpace(thing.def);
                    if (num == 0)
                    {
                        throw new Exception(string.Concat("StartCarryThing got availableStackSpace ", num, " for haulTarg ", thing, ". Job: ", curJob));
                    }
                    if (failIfStackCountLessThanJobCount && thing.stackCount < curJob.count)
                    {
                        actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                    }
                    else
                    {
                        int num2 = Mathf.Min(curJob.count, num, thing.stackCount);
                        if (num2 <= 0)
                        {
                            throw new Exception("StartCarryThing desiredNumToTake = " + num2);
                        }
                        int stackCount = thing.stackCount;
                        int num3       = actor.carryTracker.TryStartCarry(thing, num2);
                        if (num3 == 0)
                        {
                            actor.jobs.EndCurrentJob(JobCondition.Incompletable);
                        }
                        if (num3 < stackCount)
                        {
                            int num4 = curJob.count - num3;
                            if (putRemainderInQueue && num4 > 0)
                            {
                                curJob.GetTargetQueue(haulableInd).Insert(0, thing);
                                if (curJob.countQueue == null)
                                {
                                    curJob.countQueue = new List <int>();
                                }
                                curJob.countQueue.Insert(0, num4);
                            }
                            else if (actor.Map.reservationManager.ReservedBy(thing, actor, curJob))
                            {
                                actor.Map.reservationManager.Release(thing, actor, curJob);
                            }
                        }
                        if (subtractNumTakenFromJobCount)
                        {
                            curJob.count -= num3;
                        }
                        curJob.SetTarget(haulableInd, actor.carryTracker.CarriedThing);
                        actor.records.Increment(RecordDefOf.ThingsHauled);
                    }
                }
            };
            return(toil);
        }
        // Token: 0x0600001E RID: 30 RVA: 0x00003530 File Offset: 0x00001730
        private static Toil JumpToCollectNextIntoHandsForBill(Toil gotoGetTargetToil, TargetIndex ind)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor = toil.actor;
                bool flag  = actor.carryTracker.CarriedThing == null;
                if (flag)
                {
                    string str  = "JumpToAlsoCollectTargetInQueue run on ";
                    Pawn   pawn = actor;
                    Log.Error(str + ((pawn != null) ? pawn.ToString() : null) + " who is not carrying something.", false);
                }
                else
                {
                    bool full = actor.carryTracker.Full;
                    if (!full)
                    {
                        Job curJob = actor.jobs.curJob;
                        List <LocalTargetInfo> targetQueue = curJob.GetTargetQueue(ind);
                        bool flag2 = targetQueue.NullOrEmpty <LocalTargetInfo>();
                        if (!flag2)
                        {
                            for (int i = 0; i < targetQueue.Count; i++)
                            {
                                bool flag3 = GenAI.CanUseItemForWork(actor, targetQueue[i].Thing);
                                if (flag3)
                                {
                                    bool flag4 = targetQueue[i].Thing.CanStackWith(actor.carryTracker.CarriedThing);
                                    if (flag4)
                                    {
                                        bool flag5 = (float)(actor.Position - targetQueue[i].Thing.Position).LengthHorizontalSquared <= 64f;
                                        if (flag5)
                                        {
                                            int num  = (actor.carryTracker.CarriedThing != null) ? actor.carryTracker.CarriedThing.stackCount : 0;
                                            int num2 = curJob.countQueue[i];
                                            num2 = Mathf.Min(num2, targetQueue[i].Thing.def.stackLimit - num);
                                            num2 = Mathf.Min(num2, actor.carryTracker.AvailableStackSpace(targetQueue[i].Thing.def));
                                            bool flag6 = num2 > 0;
                                            if (flag6)
                                            {
                                                curJob.count = num2;
                                                curJob.SetTarget(ind, targetQueue[i].Thing);
                                                List <int> countQueue;
                                                int        index;
                                                (countQueue = curJob.countQueue)[index = i] = countQueue[index] - num2;
                                                bool flag7 = curJob.countQueue[i] <= 0;
                                                if (flag7)
                                                {
                                                    curJob.countQueue.RemoveAt(i);
                                                    targetQueue.RemoveAt(i);
                                                }
                                                actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            return(toil);
        }
Beispiel #15
0
        private static Toil JumpToCollectNextIntoHandsForBill(Toil gotoGetTargetToil, TargetIndex ind)
        {
            const float MaxDist = 8;

            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn actor = toil.actor;

                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error("JumpToAlsoCollectTargetInQueue run on " + actor + " who is not carrying something.");
                    return;
                }

                //Early-out
                if (actor.carryTracker.Full)
                {
                    return;
                }

                Job curJob      = actor.jobs.curJob;
                var targetQueue = curJob.GetTargetQueue(ind);

                if (targetQueue.NullOrEmpty())
                {
                    return;
                }

                //Find an item in the queue matching what you're carrying
                for (int i = 0; i < targetQueue.Count; i++)
                {
                    //Can't use item - skip
                    if (!GenAI.CanUseItemForWork(actor, targetQueue[i].Thing))
                    {
                        continue;
                    }

                    //Cannot stack with thing in hands - skip
                    if (!targetQueue[i].Thing.CanStackWith(actor.carryTracker.CarriedThing))
                    {
                        continue;
                    }

                    //Too far away - skip
                    if ((actor.Position - targetQueue[i].Thing.Position).LengthHorizontalSquared > MaxDist * MaxDist)
                    {
                        continue;
                    }

                    //Determine num in hands
                    int numInHands = (actor.carryTracker.CarriedThing == null) ? 0 : actor.carryTracker.CarriedThing.stackCount;

                    //Determine num to take
                    int numToTake = curJob.countQueue[i];
                    numToTake = Mathf.Min(numToTake, targetQueue[i].Thing.def.stackLimit - numInHands);
                    numToTake = Mathf.Min(numToTake, actor.carryTracker.AvailableStackSpace(targetQueue[i].Thing.def));

                    //Won't take any - skip
                    if (numToTake <= 0)
                    {
                        continue;
                    }

                    //Set me to go get it
                    curJob.count = numToTake;
                    curJob.SetTarget(ind, targetQueue[i].Thing);

                    //Remove the amount to take from the num to bring list
                    //Remove from queue if I'm going to take all
                    curJob.countQueue[i] -= numToTake;
                    if (curJob.countQueue[i] <= 0)
                    {
                        curJob.countQueue.RemoveAt(i);
                        targetQueue.RemoveAt(i);
                    }

                    //Jump to toil
                    actor.jobs.curDriver.JumpToToil(gotoGetTargetToil);
                    return;
                }
            };

            return(toil);
        }
Beispiel #16
0
            internal void <> m__0()
            {
                Pawn  actor  = this.toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(this.haulableInd).Thing;

                if (Toils_Haul.ErrorCheckForCarry(actor, thing))
                {
                    return;
                }
                if (curJob.count == 0)
                {
                    throw new Exception(string.Concat(new object[]
                    {
                        "StartCarryThing job had count = ",
                        curJob.count,
                        ". Job: ",
                        curJob
                    }));
                }
                int num = actor.carryTracker.AvailableStackSpace(thing.def);

                if (num == 0)
                {
                    throw new Exception(string.Concat(new object[]
                    {
                        "StartCarryThing got availableStackSpace ",
                        num,
                        " for haulTarg ",
                        thing,
                        ". Job: ",
                        curJob
                    }));
                }
                if (this.failIfStackCountLessThanJobCount && thing.stackCount < curJob.count)
                {
                    actor.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                    return;
                }
                int num2 = Mathf.Min(new int[]
                {
                    curJob.count,
                    num,
                    thing.stackCount
                });

                if (num2 <= 0)
                {
                    throw new Exception("StartCarryThing desiredNumToTake = " + num2);
                }
                int stackCount = thing.stackCount;
                int num3       = actor.carryTracker.TryStartCarry(thing, num2, true);

                if (num3 == 0)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                if (num3 < stackCount)
                {
                    int num4 = curJob.count - num3;
                    if (this.putRemainderInQueue && num4 > 0)
                    {
                        curJob.GetTargetQueue(this.haulableInd).Insert(0, thing);
                        if (curJob.countQueue == null)
                        {
                            curJob.countQueue = new List <int>();
                        }
                        curJob.countQueue.Insert(0, num4);
                    }
                    else if (actor.Map.reservationManager.ReservedBy(thing, actor, curJob))
                    {
                        actor.Map.reservationManager.Release(thing, actor, curJob);
                    }
                }
                if (this.subtractNumTakenFromJobCount)
                {
                    curJob.count -= num3;
                }
                curJob.SetTarget(this.haulableInd, actor.carryTracker.CarriedThing);
                actor.records.Increment(RecordDefOf.ThingsHauled);
            }