Example #1
0
        public override Activity Tick(Actor self)
        {
            // Refuse to take off if it would land immediately again.
            if (aircraft.ForceLanding)
            {
                Cancel(self);
                return(NextActivity);
            }

            if (!target.IsValidFor(self))
            {
                return(NextActivity);
            }

            // If all valid weapons have depleted their ammo and RearmBuilding is defined, return to RearmBuilding to reload and then resume the activity
            if (!autoReloads && aircraft.Info.RearmBuildings.Any() && attackPlane.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
            {
                return(ActivityUtils.SequenceActivities(new ReturnToBase(self, aircraft.Info.AbortOnResupply), this));
            }

            if (attackPlane != null)
            {
                attackPlane.DoAttack(self, target);
            }

            if (ChildActivity == null)
            {
                if (IsCanceled)
                {
                    return(NextActivity);
                }

                // TODO: This should fire each weapon at its maximum range
                if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Where(Exts.IsTraitEnabled).Select(a => a.Weapon.MinRange).Min()))
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }
                else
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }

                // HACK: This needs to be done in this round-about way because TakeOff doesn't behave as expected when it doesn't have a NextActivity.
                if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraft.Info.MinAirborneAltitude)
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new TakeOff(self), ChildActivity);
                }
            }

            ActivityUtils.RunActivity(self, ChildActivity);

            return(this);
        }
Example #2
0
        public override Activity Tick(Actor self)
        {
            // Refuse to take off if it would land immediately again.
            if (aircraft.ForceLanding)
            {
                Cancel(self);
                return(NextActivity);
            }

            if (!target.IsValidFor(self))
            {
                return(NextActivity);
            }

            // TODO: This should check whether there is ammo left that is actually suitable for the target
            if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
            {
                return(ActivityUtils.SequenceActivities(new ReturnToBase(self, aircraft.Info.AbortOnResupply), this));
            }

            if (attackPlane != null)
            {
                attackPlane.DoAttack(self, target);
            }

            if (ChildActivity == null)
            {
                if (IsCanceled)
                {
                    return(NextActivity);
                }

                // TODO: This should fire each weapon at its maximum range
                if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Where(Exts.IsTraitEnabled).Select(a => a.Weapon.MinRange).Min()))
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }
                else
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }

                // HACK: This needs to be done in this round-about way because TakeOff doesn't behave as expected when it doesn't have a NextActivity.
                if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraft.Info.MinAirborneAltitude)
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new TakeOff(self), ChildActivity);
                }
            }

            ActivityUtils.RunActivity(self, ChildActivity);

            return(this);
        }
Example #3
0
        public override Activity Tick(Actor self)
        {
            if (aircraft.ForceLanding)
            {
                Cancel(self);
                return(NextActivity);
            }

            if (!target.IsValidFor(self))
            {
                return(NextActivity);
            }


            if (!autoReloads && aircraft.Info.RearmBuildings.Any() &&
                attackPlane.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
            {
                return(ActivityUtils.SequenceActivities(new ReturnToBase(self, aircraft.Info.AbortOnResupply), this));
            }

            if (attackPlane != null)
            {
                attackPlane.DoAttack(self, target);
            }

            if (ChildActivity == null)
            {
                if (IsCanceled)
                {
                    return(NextActivity);
                }

                if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Where(Exts.IsTraitEnabled).Select(a => a.Weapon.MinRange).Min()))
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }
                else
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }

                if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraft.Info.MinAirborneAltitude)
                {
                    ChildActivity = ActivityUtils.SequenceActivities(new TakeOff(self), ChildActivity);
                }
            }

            ActivityUtils.RunActivity(self, ChildActivity);

            return(this);
        }
Example #4
0
        public override Activity Tick(Actor self)
        {
            if (!target.IsValidFor(self))
            {
                return(NextActivity);
            }

            // TODO: This should check whether there is ammo left that is actually suitable for the target
            if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
            {
                //var master = self.Trait<Spawned>().Master;
                //var tgt = Target.FromActor(master);
                //// We let the spawned to move closer then Enter.
                //// If we just let it enter, it "slides on the ground", targetable by ground units.
                //return ActivityUtils.SequenceActivities(new Fly(self, tgt, new WDist(1024*3), new WDist(1024*5)), new EnterSpawner(self, master, EnterBehaviour.Exit));
                self.Trait <Spawned>().EnterSpawner(self);
            }

            if (attackPlane != null)
            {
                attackPlane.DoAttack(self, target);
            }

            if (inner == null)
            {
                if (IsCanceled)
                {
                    return(NextActivity);
                }

                // TODO: This should fire each weapon at its maximum range
                if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min()))
                {
                    inner = ActivityUtils.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }
                else
                {
                    inner = ActivityUtils.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }

                // HACK: This needs to be done in this round-about way because TakeOff doesn't behave as expected when it doesn't have a NextActivity.
                if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraft.Info.MinAirborneAltitude)
                {
                    inner = ActivityUtils.SequenceActivities(new SpawnedTakeOff(self), inner);
                }
            }

            inner = ActivityUtils.RunActivity(self, inner);

            return(this);
        }
Example #5
0
        public override Activity Tick(Actor self)
        {
            if (!target.IsValidFor(self))
            {
                return(NextActivity);
            }

            // Move to the next activity only if all ammo pools are depleted and none reload automatically
            // TODO: This should check whether there is ammo left that is actually suitable for the target
            if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
            {
                return(NextActivity);
            }

            if (attackPlane != null)
            {
                attackPlane.DoAttack(self, target);
            }

            if (inner == null)
            {
                if (IsCanceled)
                {
                    return(NextActivity);
                }

                // TODO: This should fire each weapon at its maximum range
                if (target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min()))
                {
                    inner = Util.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }
                else
                {
                    inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
                }
            }

            inner = Util.RunActivity(self, inner);

            return(this);
        }