Пример #1
0
        public static Toil CheckForGetOpportunityDuplicate(Toil getHaulTargetToil, TargetIndex haulableInd, TargetIndex storeCellInd, bool takeFromValidStorage = false, Predicate <Thing> extraValidator = null)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                if (actor.carryTracker.CarriedThing.def.stackLimit != 1 && !actor.carryTracker.Full && curJob.count > 0)
                {
                    Thing             thing     = null;
                    Predicate <Thing> validator = delegate(Thing t)
                    {
                        if (!t.Spawned)
                        {
                            return(false);
                        }
                        if (t.def != actor.carryTracker.CarriedThing.def)
                        {
                            return(false);
                        }
                        if (!t.CanStackWith(actor.carryTracker.CarriedThing))
                        {
                            return(false);
                        }
                        if (t.IsForbidden(actor))
                        {
                            return(false);
                        }
                        if (!takeFromValidStorage && t.IsInValidStorage())
                        {
                            return(false);
                        }
                        if (storeCellInd != 0 && !curJob.GetTarget(storeCellInd).Cell.IsValidStorageFor(actor.Map, t))
                        {
                            return(false);
                        }
                        if (!actor.CanReserve(t, 1, -1, null, false))
                        {
                            return(false);
                        }
                        if (extraValidator != null && !extraValidator(t))
                        {
                            return(false);
                        }
                        return(true);
                    };
                    thing = GenClosest.ClosestThingReachable(actor.Position, actor.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableAlways), PathEndMode.ClosestTouch, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), 8f, validator, null, 0, -1, false, RegionType.Set_Passable, false);
                    if (thing != null)
                    {
                        curJob.SetTarget(haulableInd, thing);
                        actor.jobs.curDriver.JumpToToil(getHaulTargetToil);
                    }
                }
            };
            return(toil);
        }
Пример #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 SetTargetToIngredientPlaceCell(TargetIndex billGiverInd, TargetIndex carryItemInd, TargetIndex cellTargetInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn       actor     = toil.actor;
                Job        curJob    = actor.jobs.curJob;
                Thing      thing     = curJob.GetTarget(carryItemInd).Thing;
                IBillGiver billGiver = curJob.GetTarget(billGiverInd).Thing as IBillGiver;
                IntVec3    c         = IntVec3.Invalid;
                foreach (IntVec3 item in Toils_JobTransforms.IngredientPlaceCellsInOrder(billGiver))
                {
                    if (!c.IsValid)
                    {
                        c = item;
                    }
                    bool         flag = false;
                    List <Thing> list = actor.Map.thingGrid.ThingsListAt(item);
                    int          num  = 0;
                    while (num < list.Count)
                    {
                        if (list[num].def.category != ThingCategory.Item || (list[num].def == thing.def && list[num].stackCount != list[num].def.stackLimit))
                        {
                            num++;
                            continue;
                        }
                        flag = true;
                        break;
                    }
                    if (!flag)
                    {
                        curJob.SetTarget(cellTargetInd, item);
                        return;
                    }
                }
                curJob.SetTarget(cellTargetInd, c);
            };
            return(toil);
        }
        // Token: 0x0600002D RID: 45 RVA: 0x0000384C File Offset: 0x00001A4C
        public static Toil MakeUnfinishedThingIfNeeded()
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                bool flag   = !curJob.RecipeDef.UsesUnfinishedThing;
                if (!flag)
                {
                    bool flag2 = curJob.GetTarget(TargetIndex.B).Thing is UnfinishedThing;
                    if (!flag2)
                    {
                        List <Thing> list  = Toils_WPRecipe.CalculateIngredients(curJob, actor);
                        string       str   = "ingredient list in toil_wprecipe";
                        List <Thing> list2 = list;
                        Log.Message(str + ((list2 != null) ? list2.ToString() : null), false);
                        Thing thing = Toils_WPRecipe.CalculateDominantIngredient(curJob, list);
                        for (int i = 0; i < list.Count; i++)
                        {
                            Thing  thing2 = list[i];
                            string str2   = "ingredient in toil_wprecipe";
                            Thing  thing3 = list[i];
                            Log.Message(str2 + ((thing3 != null) ? thing3.ToString() : null), false);
                            actor.Map.designationManager.RemoveAllDesignationsOn(thing2, false);
                            bool spawned = thing2.Spawned;
                            if (spawned)
                            {
                                thing2.DeSpawn(DestroyMode.Vanish);
                            }
                        }
                        ThingDef        stuff           = (!curJob.RecipeDef.unfinishedThingDef.MadeFromStuff) ? null : thing.def;
                        UnfinishedThing unfinishedThing = (UnfinishedThing)ThingMaker.MakeThing(curJob.RecipeDef.unfinishedThingDef, stuff);
                        unfinishedThing.Creator     = actor;
                        unfinishedThing.BoundBill   = (Bill_ProductionWithUft)curJob.bill;
                        unfinishedThing.ingredients = list;
                        CompColorable compColorable = unfinishedThing.TryGetComp <CompColorable>();
                        bool          flag3         = compColorable != null;
                        if (flag3)
                        {
                            compColorable.Color = thing.DrawColor;
                        }
                        GenSpawn.Spawn(unfinishedThing, curJob.GetTarget(TargetIndex.A).Cell, actor.Map, WipeMode.Vanish);
                        curJob.SetTarget(TargetIndex.B, unfinishedThing);
                        actor.Reserve(unfinishedThing, curJob, 1, -1, null, true);
                    }
                }
            };
            return(toil);
        }
Пример #6
0
        public static Toil SetTargetToIngredientPlaceCell(TargetIndex billGiverInd, TargetIndex carryItemInd, TargetIndex cellTargetInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn       actor     = toil.actor;
                Job        curJob    = actor.jobs.curJob;
                Thing      thing     = curJob.GetTarget(carryItemInd).Thing;
                IBillGiver billGiver = curJob.GetTarget(billGiverInd).Thing as IBillGiver;
                IntVec3    c         = IntVec3.Invalid;
                foreach (IntVec3 current in Toils_JobTransforms.IngredientPlaceCellsInOrder(billGiver))
                {
                    if (!c.IsValid)
                    {
                        c = current;
                    }
                    bool         flag = false;
                    List <Thing> list = actor.Map.thingGrid.ThingsListAt(current);
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].def.category == ThingCategory.Item && (list[i].def != thing.def || list[i].stackCount == list[i].def.stackLimit))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        curJob.SetTarget(cellTargetInd, current);
                        return;
                    }
                }
                curJob.SetTarget(cellTargetInd, c);
            };
            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);
        }
Пример #8
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);
        }
Пример #9
0
        public static Toil MakeUnfinishedThingIfNeeded()
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                if (!curJob.RecipeDef.UsesUnfinishedThing)
                {
                    return;
                }
                if (curJob.GetTarget(TargetIndex.B).Thing is UnfinishedThing)
                {
                    return;
                }
                List <Thing> list  = Toils_Recipe.CalculateIngredients(curJob, actor);
                Thing        thing = Toils_Recipe.CalculateDominantIngredient(curJob, list);
                for (int i = 0; i < list.Count; i++)
                {
                    Thing thing2 = list[i];
                    actor.Map.designationManager.RemoveAllDesignationsOn(thing2, false);
                    if (thing2.Spawned)
                    {
                        thing2.DeSpawn(DestroyMode.Vanish);
                    }
                }
                ThingDef        stuff           = (!curJob.RecipeDef.unfinishedThingDef.MadeFromStuff) ? null : thing.def;
                UnfinishedThing unfinishedThing = (UnfinishedThing)ThingMaker.MakeThing(curJob.RecipeDef.unfinishedThingDef, stuff);
                unfinishedThing.Creator     = actor;
                unfinishedThing.BoundBill   = (Bill_ProductionWithUft)curJob.bill;
                unfinishedThing.ingredients = list;
                CompColorable compColorable = unfinishedThing.TryGetComp <CompColorable>();
                if (compColorable != null)
                {
                    compColorable.Color = thing.DrawColor;
                }
                GenSpawn.Spawn(unfinishedThing, curJob.GetTarget(TargetIndex.A).Cell, actor.Map, WipeMode.Vanish);
                curJob.SetTarget(TargetIndex.B, unfinishedThing);
                actor.Reserve(unfinishedThing, curJob, 1, -1, null, true);
            };
            return(toil);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #16
0
        public static Toil MakeUnfinishedThingIfNeeded()
        {
            Toil toil = new Toil();

            toil.initAction = () =>
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;

                //Recipe doesn't use unfinished things
                if (!curJob.RecipeDef.UsesUnfinishedThing)
                {
                    return;
                }

                //Already working on an unfinished thing
                if (curJob.GetTarget(JobDriver_DoBill.IngredientInd).Thing is UnfinishedThing)
                {
                    return;
                }

                //Create the unfinished thing
                var   ingredients        = CalculateIngredients(curJob, actor);
                Thing dominantIngredient = CalculateDominantIngredient(curJob, ingredients);

                //Despawn ingredients. They will be saved inside the UFT
                //because these ingredients can come back out if the UFT is canceled
                for (int i = 0; i < ingredients.Count; i++)
                {
                    var ingredient = ingredients[i];
                    actor.Map.designationManager.RemoveAllDesignationsOn(ingredient);
                    if (ingredient.Spawned)
                    {
                        ingredient.DeSpawn();
                    }
                }

                //Store the dominant ingredient as the UnfinishedThing's stuff
                ThingDef stuff = curJob.RecipeDef.unfinishedThingDef.MadeFromStuff
                                        ? dominantIngredient.def
                                        : null;

                //Make the UFT and set its data
                UnfinishedThing uft = (UnfinishedThing)ThingMaker.MakeThing(curJob.RecipeDef.unfinishedThingDef, stuff);
                uft.Creator     = actor;
                uft.BoundBill   = (Bill_ProductionWithUft)curJob.bill;
                uft.ingredients = ingredients;
                CompColorable cc = uft.TryGetComp <CompColorable>();
                if (cc != null)
                {
                    cc.Color = dominantIngredient.DrawColor;
                }

                //Spawn the UFT
                GenSpawn.Spawn(uft, curJob.GetTarget(JobDriver_DoBill.BillGiverInd).Cell, actor.Map);

                //Set the job to use the unfinished thing as its only ingredient
                curJob.SetTarget(JobDriver_DoBill.IngredientInd, uft);

                //Reserve the unfinished thing
                actor.Reserve(uft, curJob);
            };
            return(toil);
        }
Пример #17
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);
            }