Esempio n. 1
0
        public static Thing findAmmo(Pawn pawn, AERIALSYSTEM aeriel)
        {
            StorageSettings   allowed   = pawn.IsColonist ? aeriel.gun.TryGetComp <AERIALChangeableProjectile>().allowedShellsSettings : null;
            Predicate <Thing> validator = (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t, 10, 1, null, false) && (allowed == null || allowed.AllowedToAccept(t));

            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Shell), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 40f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
Esempio n. 2
0
        private static bool GunNeedsLoading(Building b)
        {
            AERIALSYSTEM building_TurretGun = b as AERIALSYSTEM;

            if (building_TurretGun == null)
            {
                return(false);
            }
            AERIALChangeableProjectile compChangeableProjectile = building_TurretGun.gun.TryGetComp <AERIALChangeableProjectile>();

            return(compChangeableProjectile != null && !(compChangeableProjectile.loadedShells.Count >= compChangeableProjectile.Props.maxShellCount));
        }
Esempio n. 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            Toil aerialGogo   = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);
            Toil loadIfNeeded = new Toil();

            loadIfNeeded.initAction = delegate()
            {
                Pawn         actor              = loadIfNeeded.actor;
                Building     building           = (Building)actor.CurJob.targetA.Thing;
                AERIALSYSTEM building_TurretGun = building as AERIALSYSTEM;
                if (!GunNeedsLoading(building))
                {
                    //this.JumpToToil(gotoTurret);
                    return;
                }
                Thing thing = findAmmo(pawn, building_TurretGun);
                if (thing == null)
                {
                    if (actor.Faction == Faction.OfPlayer)
                    {
                        Messages.Message("MessageOutOfNearbyShellsFor".Translate(actor.LabelShort, building_TurretGun.Label, actor.Named("PAWN"), building_TurretGun.Named("GUN")).CapitalizeFirst(), building_TurretGun, MessageTypeDefOf.NegativeEvent, true);
                    }
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true, true);
                }
                actor.CurJob.targetB = thing;
                actor.CurJob.count   = 1;
            };
            yield return(loadIfNeeded);

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 10, 1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Pawn actor = loadIfNeeded.actor;
                    AERIALSYSTEM building_TurretGun = ((Building)actor.CurJob.targetA.Thing) as AERIALSYSTEM;

                    building_TurretGun.gun.TryGetComp <AERIALChangeableProjectile>().NewLoadShell(actor.CurJob.targetB.Thing.def, 1);
                    actor.carryTracker.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
            });
            //yield return gotoTurret;
        }