Beispiel #1
0
        public FlyAttack(Actor self, AttackSource source, Target target, bool forceAttack, Color?targetLineColor)
        {
            this.source          = source;
            this.target          = target;
            this.forceAttack     = forceAttack;
            this.targetLineColor = targetLineColor;

            aircraft       = self.Trait <Aircraft>();
            attackAircraft = self.Trait <AttackAircraft>();
            rearmable      = self.TraitOrDefault <Rearmable>();

            strafeDistance = attackAircraft.Info.StrafeRunLength;

            // The target may become hidden between the initial order request and the first tick (e.g. if queued)
            // Moving to any position (even if quite stale) is still better than immediately giving up
            if ((target.Type == TargetType.Actor && target.Actor.CanBeViewedByPlayer(self.Owner)) ||
                target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
            {
                lastVisibleTarget       = Target.FromPos(target.CenterPosition);
                lastVisibleMaximumRange = attackAircraft.GetMaximumRangeVersusTarget(target);

                if (target.Type == TargetType.Actor)
                {
                    lastVisibleOwner       = target.Actor.Owner;
                    lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes();
                }
                else if (target.Type == TargetType.FrozenActor)
                {
                    lastVisibleOwner       = target.FrozenActor.Owner;
                    lastVisibleTargetTypes = target.FrozenActor.TargetTypes;
                }
            }
        }
Beispiel #2
0
        public Resupply(Actor self, Actor host, WDist closeEnough)
        {
            this.host        = Target.FromActor(host);
            this.closeEnough = closeEnough;
            allRepairsUnits  = host.TraitsImplementing <RepairsUnits>().ToArray();
            health           = self.TraitOrDefault <IHealth>();
            repairable       = self.TraitOrDefault <Repairable>();
            repairableNear   = self.TraitOrDefault <RepairableNear>();
            rearmable        = self.TraitOrDefault <Rearmable>();
            notifyResupplies = host.TraitsImplementing <INotifyResupply>().ToArray();

            var cannotRepairAtHost = health == null || health.DamageState == DamageState.Undamaged ||
                                     !allRepairsUnits.Any() ||
                                     ((repairable == null || !repairable.Info.RepairActors.Contains(host.Info.Name)) &&
                                      (repairableNear == null || !repairableNear.Info.RepairActors.Contains(host.Info.Name)));

            if (!cannotRepairAtHost)
            {
                activeResupplyTypes |= ResupplyType.Repair;
            }

            var cannotRearmAtHost = rearmable == null || !rearmable.Info.RearmActors.Contains(host.Info.Name) || rearmable.RearmableAmmoPools.All(p => p.FullAmmo());

            if (!cannotRearmAtHost)
            {
                activeResupplyTypes |= ResupplyType.Rearm;
            }
        }
Beispiel #3
0
 public ReturnToBase(Actor self, Actor dest = null, bool alwaysLand = false)
 {
     this.dest       = dest;
     this.alwaysLand = alwaysLand;
     aircraft        = self.Trait <Aircraft>();
     repairableInfo  = self.Info.TraitInfoOrDefault <RepairableInfo>();
     rearmable       = self.TraitOrDefault <Rearmable>();
 }
Beispiel #4
0
 public FlyAttack(Actor self, Target target)
 {
     this.target    = target;
     aircraft       = self.Trait <Aircraft>();
     attackAircraft = self.Trait <AttackAircraft>();
     rearmable      = self.TraitOrDefault <Rearmable>();
     ticksUntilTurn = attackAircraft.AttackAircraftInfo.AttackTurnDelay;
 }
Beispiel #5
0
 public HeliAttack(Actor self, Target target, bool attackOnlyVisibleTargets = true)
 {
     Target         = target;
     aircraft       = self.Trait <Aircraft>();
     attackAircraft = self.Trait <AttackAircraft>();
     this.attackOnlyVisibleTargets = attackOnlyVisibleTargets;
     rearmable = self.TraitOrDefault <Rearmable>();
 }
Beispiel #6
0
 public ReturnToBase(Actor self, bool abortOnResupply, Actor dest = null, bool alwaysLand = true)
 {
     this.dest            = dest;
     this.alwaysLand      = alwaysLand;
     this.abortOnResupply = abortOnResupply;
     aircraft             = self.Trait <Aircraft>();
     repairableInfo       = self.Info.TraitInfoOrDefault <RepairableInfo>();
     rearmable            = self.TraitOrDefault <Rearmable>();
 }
Beispiel #7
0
 protected virtual void Created(Actor self)
 {
     repairable       = self.TraitOrDefault <Repairable>();
     rearmable        = self.TraitOrDefault <Rearmable>();
     conditionManager = self.TraitOrDefault <ConditionManager>();
     speedModifiers   = self.TraitsImplementing <ISpeedModifier>().ToArray().Select(sm => sm.GetSpeedModifier());
     cachedPosition   = self.CenterPosition;
     notifyMoving     = self.TraitsImplementing <INotifyMoving>().ToArray();
 }
Beispiel #8
0
        protected static bool ReloadsAutomatically(IEnumerable <AmmoPool> ammoPools, Rearmable rearmable)
        {
            if (rearmable == null)
            {
                return(true);
            }

            foreach (var ap in ammoPools)
            {
                if (!rearmable.Info.AmmoPools.Contains(ap.Info.Name))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #9
0
        public Resupply(Actor self, Actor host, WDist closeEnough, bool stayOnResupplier = false)
        {
            this.host             = Target.FromActor(host);
            this.closeEnough      = closeEnough;
            this.stayOnResupplier = stayOnResupplier;
            allRepairsUnits       = host.TraitsImplementing <RepairsUnits>().ToArray();
            health                = self.TraitOrDefault <IHealth>();
            repairable            = self.TraitOrDefault <Repairable>();
            repairableNear        = self.TraitOrDefault <RepairableNear>();
            rearmable             = self.TraitOrDefault <Rearmable>();
            notifyResupplies      = host.TraitsImplementing <INotifyResupply>().ToArray();
            notifyBeingResupplied = self.TraitsImplementing <INotifyBeingResupplied>().ToArray();
            transportCallers      = self.TraitsImplementing <ICallForTransport>().ToArray();
            move            = self.Trait <IMove>();
            aircraft        = move as Aircraft;
            moveInfo        = self.Info.TraitInfo <IMoveInfo>();
            playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();

            var valued = self.Info.TraitInfoOrDefault <ValuedInfo>();

            unitCost = valued != null ? valued.Cost : 0;

            var cannotRepairAtHost = health == null || health.DamageState == DamageState.Undamaged ||
                                     !allRepairsUnits.Any() ||
                                     ((repairable == null || !repairable.Info.RepairActors.Contains(host.Info.Name)) &&
                                      (repairableNear == null || !repairableNear.Info.RepairActors.Contains(host.Info.Name)));

            if (!cannotRepairAtHost)
            {
                activeResupplyTypes |= ResupplyType.Repair;

                // HACK: Reservable logic can't handle repairs, so force a take-off if resupply included repairs.
                // TODO: Make reservation logic or future docking logic properly handle this.
                wasRepaired = true;
            }

            var cannotRearmAtHost = rearmable == null || !rearmable.Info.RearmActors.Contains(host.Info.Name) || rearmable.RearmableAmmoPools.All(p => p.HasFullAmmo);

            if (!cannotRearmAtHost)
            {
                activeResupplyTypes |= ResupplyType.Rearm;
            }
        }
Beispiel #10
0
 public Rearm(Actor self, Actor host, WDist closeEnough)
 {
     this.host        = Target.FromActor(host);
     this.closeEnough = closeEnough;
     rearmable        = self.Trait <Rearmable>();
 }