Example #1
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            IBillGiver billGiver = thing as IBillGiver;

            if (billGiver != null && ThingIsUsableBillGiver(thing) && billGiver.BillStack.AnyShouldDoNow && billGiver.UsableForBillsAfterFueling())
            {
                LocalTargetInfo target = thing;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations) && !thing.IsBurning() && !thing.IsForbidden(pawn))
                {
                    CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>();
                    if (compRefuelable != null && !compRefuelable.HasFuel)
                    {
                        if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced))
                        {
                            return(null);
                        }
                        return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced));
                    }
                    billGiver.BillStack.RemoveIncompletableBills();
                    return(StartOrResumeBillJob(pawn, billGiver));
                }
            }
            return(null);
        }
 public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     if (CanRefuelThing(t))
     {
         return(RefuelWorkGiverUtility.CanRefuel(pawn, t, forced));
     }
     return(false);
 }
Example #3
0
        public static bool CanRefuel(Pawn pawn, Thing t, bool forced = false)
        {
            CompRefuelable compRefuelable = t.TryGetComp <CompRefuelable>();
            bool           result;

            if (compRefuelable == null || compRefuelable.IsFull)
            {
                result = false;
            }
            else
            {
                bool flag = !forced;
                if (flag && !compRefuelable.ShouldAutoRefuelNow)
                {
                    result = false;
                }
                else
                {
                    if (!t.IsForbidden(pawn))
                    {
                        LocalTargetInfo target = t;
                        if (pawn.CanReserve(target, 1, -1, null, forced))
                        {
                            if (t.Faction != pawn.Faction)
                            {
                                return(false);
                            }
                            if (RefuelWorkGiverUtility.FindBestFuel(pawn, t) == null)
                            {
                                ThingFilter fuelFilter = t.TryGetComp <CompRefuelable>().Props.fuelFilter;
                                JobFailReason.Is("NoFuelToRefuel".Translate(new object[]
                                {
                                    fuelFilter.Summary
                                }), null);
                                return(false);
                            }
                            if (t.TryGetComp <CompRefuelable>().Props.atomicFueling)
                            {
                                if (RefuelWorkGiverUtility.FindAllFuel(pawn, t) == null)
                                {
                                    ThingFilter fuelFilter2 = t.TryGetComp <CompRefuelable>().Props.fuelFilter;
                                    JobFailReason.Is("NoFuelToRefuel".Translate(new object[]
                                    {
                                        fuelFilter2.Summary
                                    }), null);
                                    return(false);
                                }
                            }
                            return(true);
                        }
                    }
                    result = false;
                }
            }
            return(result);
        }
Example #4
0
        public static List <Thing> FindEnoughAmmo(Pawn pawn, IntVec3 rootCell, CompReloadable comp, bool forceReload)
        {
            if (comp == null)
            {
                return(null);
            }
            IntRange desiredQuantity = new IntRange(comp.MinAmmoNeeded(forceReload), comp.MaxAmmoNeeded(forceReload));

            return(RefuelWorkGiverUtility.FindEnoughReservableThings(pawn, rootCell, desiredQuantity, (Thing t) => t.def == comp.AmmoDef));
        }
        public static Job RefuelJob(Pawn pawn, Thing t, bool forced = false, JobDef customRefuelJob = null, JobDef customAtomicRefuelJob = null)
        {
            if (!t.TryGetComp <CompRefuelable>().Props.atomicFueling)
            {
                Thing t2 = RefuelWorkGiverUtility.FindBestFuel(pawn, t);
                return(new Job(customRefuelJob ?? JobDefOf.Refuel, t, t2));
            }
            List <Thing> source = RefuelWorkGiverUtility.FindAllFuel(pawn, t);
            Job          job    = new Job(customAtomicRefuelJob ?? JobDefOf.RefuelAtomic, t);

            job.targetQueueB = (from f in source
                                select new LocalTargetInfo(f)).ToList <LocalTargetInfo>();
            return(job);
        }
Example #6
0
        public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false)
        {
            IBillGiver billGiver = thing as IBillGiver;

            if (billGiver == null || !ThingIsUsableBillGiver(thing) || !billGiver.BillStack.AnyShouldDoNow || !billGiver.UsableForBillsAfterFueling() || !pawn.CanReserve(thing, 1, -1, null, forced) || thing.IsBurning() || thing.IsForbidden(pawn))
            {
                return(null);
            }
            CompRefuelable compRefuelable = thing.TryGetComp <CompRefuelable>();

            if (compRefuelable != null && !compRefuelable.HasFuel)
            {
                if (!RefuelWorkGiverUtility.CanRefuel(pawn, thing, forced))
                {
                    return(null);
                }
                return(RefuelWorkGiverUtility.RefuelJob(pawn, thing, forced));
            }
            billGiver.BillStack.RemoveIncompletableBills();
            return(StartOrResumeBillJob(pawn, billGiver));
        }
 public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     return(RefuelWorkGiverUtility.RefuelJob(pawn, t, forced, this.JobStandard, this.JobAtomic));
 }