private static Toil Toils_FillThingIntoConstructor(Pawn actor)
        {
            Thing carryThing = actor.jobs.curJob.GetTarget(IngredientInd).Thing;
            Building_AIPawnConstructionStation constructorThing = actor.jobs.curJob.GetTarget(ConstructorInd).Thing as Building_AIPawnConstructionStation;

            if (constructorThing == null)
            {
                return(null);
            }

            Toil toil = new Toil();

            Action action = () =>
            {
                if (actor.carryTracker.TryDropCarriedThing(constructorThing.RefillPosition, ThingPlaceMode.Direct, out carryThing, null))
                {
                    constructorThing.ReceiveThing(carryThing);
                }
            };

            toil.finishActions = new List <Action>();
            toil.finishActions.Add(action);

            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 30;

            return(toil);
        }
Esempio n. 2
0
        private static Thing FindBestThing(Pawn pawn, Thing t, out int count)
        {
            Building_AIPawnConstructionStation constructor = (t as Building_AIPawnConstructionStation);

            count = 0;

            if (constructor == null)
            {
                return(null);
            }

            int requiredSilver = constructor.SilverAmountRequired;
            int requiredSteel  = constructor.SteelAmountRequired;

            ThingDef targetDef;

            if (requiredSteel > 0)
            {
                targetDef = ThingDefOf.Steel;
                count     = requiredSteel;
            }
            else
            {
                targetDef = ThingDefOf.Silver;
                count     = requiredSilver;
            }

            Predicate <Thing> validator = delegate(Thing x)
            {
                if (x.def == targetDef)
                {
                    if (!x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false))
                    {
                        return(true);
                    }
                }

                return(false);
            };
            IntVec3 position = pawn.Position;
            Map     map      = pawn.Map;

            ThingRequest bestThingRequest = ThingRequest.ForDef(targetDef);

            PathEndMode   peMode         = PathEndMode.ClosestTouch;
            TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);

            return(GenClosest.ClosestThingReachable(position, map, bestThingRequest, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
Esempio n. 3
0
        public static Job FillJob(Pawn pawn, Thing t, bool forced = false)
        {
            Building_AIPawnConstructionStation t1 = (t as Building_AIPawnConstructionStation);

            if (t1 == null)
            {
                return(null);
            }
            int   count;
            Thing t2 = FindBestThing(pawn, t, out count);

            if (t2 == null)
            {
                return(null);
            }

            IntVec3 p3 = (t as Building_AIPawnConstructionStation).RefillPosition;
            Job     j  = new Job(DefDatabase <JobDef> .GetNamed("AIPawn_FillConstructor"), t2, t1, p3);

            j.targetQueueA = new List <LocalTargetInfo>();
            j.targetQueueA.Add(t2);
            j.count = count;
            return(j);
        }