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

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

            var pos       = self.CenterPosition;
            var targetPos = attackHeli.GetTargetPosition(pos, target);

            if (attackOnlyVisibleTargets && target.Type == TargetT.Actor && canHidenUnderFog && !target.Actor.CanBeViewedByPlayer(self.Owner))
            {
                var newTarget = Target.FromCell(self.World, self.World.Map.CellContaining(targetPos));

                Cancel(self);
                self.SetTargetLine(newTarget, Color.Green);
                return(new HeliFly(self, newTarget));
            }

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

            var dist = targetPos - pos;

            //Can rotate facing while ascending
            var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing;

            helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed);

            if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
            {
                return(this);
            }

            //Fly towards the target
            if (!target.IsInRange(pos, attackHeli.GetMaximumRangeVersusTarget(target)))
            {
                helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing));
            }

            //Fly backwards from the target

            if (target.IsInRange(pos, attackHeli.GetMinimumRangeVersusTarget(target)))
            {
                //Facing 0 doesn't work with the following position change
                var facing = 1;
                if (desiredFacing != 0)
                {
                    facing = desiredFacing;
                }
                else if (helicopter.Facing != 0)
                {
                    facing = helicopter.Facing;
                }
                helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing));
            }

            attackHeli.DoAttack(self, target);

            return(this);
        }
Exemple #2
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled || !target.IsValidFor(self))
            {
                return(NextActivity);
            }

            if (attackOnlyVisibleTargets && target.Type == TargetType.Actor && canHideUnderFog &&
                !self.Owner.CanTargetActor(target.Actor))
            {
                var newTarget = Target.FromCell(self.World, self.World.Map.CellContaining(target.CenterPosition));

                Cancel(self);
                self.SetTargetLine(newTarget, Color.Green);
                return(new HeliFly(self, newTarget));
            }

            // If any AmmoPool is depleted and no weapon is valid against target, return to helipad to reload and then resume the activity
            if (ammoPools.Any(x => !x.Info.SelfReloads && !x.HasAmmo()) && !attackHeli.HasAnyValidWeapons(target))
            {
                return(ActivityUtils.SequenceActivities(new HeliReturnToBase(self, helicopter.Info.AbortOnResupply), this));
            }

            var dist = target.CenterPosition - self.CenterPosition;

            // Can rotate facing while ascending
            var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing;

            helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed);

            if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
            {
                return(this);
            }

            // Fly towards the target
            if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRangeVersusTarget(target)))
            {
                helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing));
            }

            // Fly backwards from the target
            if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRangeVersusTarget(target)))
            {
                // Facing 0 doesn't work with the following position change
                var facing = 1;
                if (desiredFacing != 0)
                {
                    facing = desiredFacing;
                }
                else if (helicopter.Facing != 0)
                {
                    facing = helicopter.Facing;
                }
                helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing));
            }

            attackHeli.DoAttack(self, target);

            return(this);
        }