Exemplo n.º 1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Job result;

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                result = null;
            }
            else
            {
                Lord  lord  = pawn.GetLord();
                Thing thing = GatherItemsForCaravanUtility.FindThingToHaul(pawn, lord);
                if (thing == null)
                {
                    result = null;
                }
                else
                {
                    result = new Job(JobDefOf.PrepareCaravan_GatherItems, thing)
                    {
                        lord = lord
                    };
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public static Thing FindThingToHaul(Pawn p, Lord lord)
        {
            GatherItemsForCaravanUtility.neededItems.Clear();
            List <TransferableOneWay> transferables = ((LordJob_FormAndSendCaravan)lord.LordJob).transferables;

            for (int i = 0; i < transferables.Count; i++)
            {
                TransferableOneWay transferableOneWay = transferables[i];
                if (GatherItemsForCaravanUtility.CountLeftToTransfer(p, transferableOneWay, lord) > 0)
                {
                    for (int j = 0; j < transferableOneWay.things.Count; j++)
                    {
                        GatherItemsForCaravanUtility.neededItems.Add(transferableOneWay.things[j]);
                    }
                }
            }
            if (!GatherItemsForCaravanUtility.neededItems.Any())
            {
                return(null);
            }
            Thing result = GenClosest.ClosestThingReachable(p.Position, p.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.Touch, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing x) => GatherItemsForCaravanUtility.neededItems.Contains(x) && p.CanReserve(x, 1, -1, null, false), null, 0, -1, false, RegionType.Set_Passable, false);

            GatherItemsForCaravanUtility.neededItems.Clear();
            return(result);
        }
Exemplo n.º 3
0
 public static int CountLeftToTransfer(Pawn pawn, TransferableOneWay transferable, Lord lord)
 {
     if (transferable.CountToTransfer > 0 && transferable.HasAnyThing)
     {
         return(Mathf.Max(transferable.CountToTransfer - GatherItemsForCaravanUtility.TransferableCountHauledByOthers(pawn, transferable, lord), 0));
     }
     return(0);
 }
        public static int CountLeftToTransfer(Pawn pawn, TransferableOneWay transferable, Lord lord)
        {
            int result;

            if (transferable.CountToTransfer <= 0 || !transferable.HasAnyThing)
            {
                result = 0;
            }
            else
            {
                result = Mathf.Max(transferable.CountToTransfer - GatherItemsForCaravanUtility.TransferableCountHauledByOthers(pawn, transferable, lord), 0);
            }
            return(result);
        }
        private void <DetermineNumToHaul> m__0()
        {
            int num = GatherItemsForCaravanUtility.CountLeftToTransfer(this.pawn, this.Transferable, this.job.lord);

            if (this.pawn.carryTracker.CarriedThing != null)
            {
                num -= this.pawn.carryTracker.CarriedThing.stackCount;
            }
            if (num <= 0)
            {
                this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded, true);
            }
            else
            {
                this.job.count = num;
            }
        }
Exemplo n.º 6
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                return(null);
            }
            Lord  lord  = pawn.GetLord();
            Thing thing = GatherItemsForCaravanUtility.FindThingToHaul(pawn, lord);

            if (thing == null)
            {
                return(null);
            }
            Job job = new Job(JobDefOf.PrepareCaravan_GatherItems, thing);

            job.lord = lord;
            return(job);
        }
        public override Job NonScanJob(Pawn pawn)
        {
            List <Lord> lords = pawn.Map.lordManager.lords;

            for (int i = 0; i < lords.Count; i++)
            {
                LordJob_FormAndSendCaravan lordJob_FormAndSendCaravan = lords[i].LordJob as LordJob_FormAndSendCaravan;
                if (lordJob_FormAndSendCaravan != null && lordJob_FormAndSendCaravan.GatheringItemsNow)
                {
                    Thing thing = GatherItemsForCaravanUtility.FindThingToHaul(pawn, lords[i]);
                    if (thing != null && this.AnyReachableCarrierOrColonist(pawn, lords[i]))
                    {
                        Job job = new Job(JobDefOf.PrepareCaravan_GatherItems, thing);
                        job.lord = lords[i];
                        return(job);
                    }
                }
            }
            return(null);
        }
 private Toil DetermineNumToHaul()
 {
     return(new Toil
     {
         initAction = delegate()
         {
             int num = GatherItemsForCaravanUtility.CountLeftToTransfer(this.pawn, this.Transferable, this.job.lord);
             if (this.pawn.carryTracker.CarriedThing != null)
             {
                 num -= this.pawn.carryTracker.CarriedThing.stackCount;
             }
             if (num <= 0)
             {
                 this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded, true);
             }
             else
             {
                 this.job.count = num;
             }
         },
         defaultCompleteMode = ToilCompleteMode.Instant,
         atomicWithPrevious = true
     });
 }
        private Toil DetermineNumToHaul()
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                int num = GatherItemsForCaravanUtility.CountLeftToTransfer(pawn, Transferable, job.lord);
                if (pawn.carryTracker.CarriedThing != null)
                {
                    num -= pawn.carryTracker.CarriedThing.stackCount;
                }
                if (num <= 0)
                {
                    pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                }
                else
                {
                    job.count = num;
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            toil.atomicWithPrevious  = true;
            return(toil);
        }