Beispiel #1
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                return(NextActivity);
            }
            if (!isCalculated)
            {
                Calculate(self);
            }
            if (dest == null)
            {
                var rearmBuildings = self.Info.Traits.Get <PlaneInfo>().RearmBuildings;
                var nearestAfld    = self.World.ActorsWithTrait <Reservable>()
                                     .Where(a => a.Actor.Owner == self.Owner && rearmBuildings.Contains(a.Actor.Info.Name))
                                     .Select(a => a.Actor)
                                     .ClosestTo(self.CenterLocation);

                self.CancelActivity();
                return(Util.SequenceActivities(Fly.ToCell(nearestAfld.Location), new FlyCircle()));
            }

            return(Util.SequenceActivities(
                       Fly.ToPx(w1),
                       Fly.ToPx(w2),
                       Fly.ToPx(w3),
                       new Land(Target.FromActor(dest)),
                       NextActivity));
        }
Beispiel #2
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled || self.IsDead())
            {
                return(NextActivity);
            }

            if (!isCalculated)
            {
                Calculate(self);
            }

            if (dest == null)
            {
                var nearestAfld = ChooseAirfield(self, false);

                self.CancelActivity();
                if (nearestAfld != null)
                {
                    return(Util.SequenceActivities(Fly.ToCell(nearestAfld.Location), new FlyCircle()));
                }
                else
                {
                    return(new FlyCircle());
                }
            }

            return(Util.SequenceActivities(
                       Fly.ToPos(w1),
                       Fly.ToPos(w2),
                       Fly.ToPos(w3),
                       new Land(Target.FromActor(dest)),
                       NextActivity));
        }
Beispiel #3
0
        public override Activity Tick(Actor self)
        {
            if (!target.IsValidFor(self))
            {
                Cancel(self);
            }

            if (IsCanceled)
            {
                return(NextActivity);
            }

            var plane = self.Trait <Plane>();
            var d     = target.CenterPosition - self.CenterPosition;

            // The next move would overshoot, so just set the final position
            var move = plane.FlyStep(plane.Facing);

            if (d.HorizontalLengthSquared < move.HorizontalLengthSquared)
            {
                plane.SetPosition(self, target.CenterPosition);
                return(NextActivity);
            }

            var desiredFacing = Util.GetFacing(d, plane.Facing);

            Fly.FlyToward(self, plane, desiredFacing, WRange.Zero);

            return(this);
        }
Beispiel #4
0
        public override Activity Tick(Actor self)
        {
            if (!Target.IsValid)
            {
                Cancel(self);
            }
            var limitedAmmo = self.TraitOrDefault <LimitedAmmo>();

            if (limitedAmmo != null && !limitedAmmo.HasAmmo())
            {
                Cancel(self);
            }

            var attack = self.TraitOrDefault <AttackPlane>();

            if (attack != null)
            {
                attack.DoAttack(self, Target);
            }

            if (inner == null)
            {
                if (IsCanceled)
                {
                    return(NextActivity);
                }
                inner = Util.SequenceActivities(
                    Fly.ToPx(Target.CenterLocation),
                    new FlyTimed(50));
            }
            inner = Util.RunActivity(self, inner);

            return(this);
        }
Beispiel #5
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled || !self.World.Map.IsInMap(self.Location))
            {
                return(NextActivity);
            }

            var plane = self.Trait <Plane>();

            Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);
            return(this);
        }
Beispiel #6
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Move")
            {
                UnReserve();

                var target = self.World.ClampToWorld(order.TargetLocation);
                self.SetTargetLine(Target.FromCell(target), Color.Green);
                self.CancelActivity();
                self.QueueActivity(Fly.ToCell(target));
                self.QueueActivity(new FlyCircle());
            }

            else if (order.OrderString == "Enter")
            {
                if (Reservable.IsReserved(order.TargetActor))
                {
                    return;
                }

                UnReserve();

                self.SetTargetLine(Target.FromOrder(order), Color.Green);

                self.CancelActivity();
                self.QueueActivity(new ReturnToBase(self, order.TargetActor));
                self.QueueActivity(new ResupplyAircraft());
            }
            else if (order.OrderString == "Stop")
            {
                UnReserve();
                self.CancelActivity();
            }
            else if (order.OrderString == "ReturnToBase")
            {
                var airfield = ReturnToBase.ChooseAirfield(self);
                if (airfield == null)
                {
                    return;
                }

                UnReserve();
                self.CancelActivity();
                self.SetTargetLine(Target.FromActor(airfield), Color.Green);
                self.QueueActivity(new ReturnToBase(self, airfield));
                self.QueueActivity(new ResupplyAircraft());
            }
            else
            {
                // Game.Debug("Unreserve due to unhandled order: {0}".F(order.OrderString));
                UnReserve();
            }
        }
Beispiel #7
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled || remainingTicks-- == 0)
            {
                return(NextActivity);
            }

            var plane = self.Trait <Plane>();

            Fly.FlyToward(self, plane, plane.Facing, plane.Info.CruiseAltitude);

            return(this);
        }
Beispiel #8
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                return(NextActivity);
            }

            var plane = self.Trait <Plane>();

            // We can't possibly turn this fast
            var desiredFacing = plane.Facing + 64;

            Fly.FlyToward(self, plane, desiredFacing, plane.Info.CruiseAltitude);

            return(this);
        }
Beispiel #9
0
        public void TickIdle(Actor self)
        {
            // We're on the ground, let's stay there.
            if (self.CenterPosition.Z == 0)
            {
                return;
            }

            var airfield = ReturnToBase.ChooseAirfield(self, true);

            if (airfield != null)
            {
                self.QueueActivity(new ReturnToBase(self, airfield));
                self.QueueActivity(new ResupplyAircraft());
            }
            else
            {
                // nowhere to land, pick something friendly and circle over it.

                // i'd prefer something we own
                var someBuilding = self.World.ActorsWithTrait <Building>()
                                   .Select(a => a.Actor)
                                   .FirstOrDefault(a => a.Owner == self.Owner);

                // failing that, something unlikely to shoot at us
                if (someBuilding == null)
                {
                    someBuilding = self.World.ActorsWithTrait <Building>()
                                   .Select(a => a.Actor)
                                   .FirstOrDefault(a => self.Owner.Stances[a.Owner] == Stance.Ally);
                }

                if (someBuilding == null)
                {
                    // ... going down the garden to eat worms ...
                    self.QueueActivity(new FlyOffMap());
                    self.QueueActivity(new RemoveSelf());
                    return;
                }

                self.QueueActivity(Fly.ToCell(someBuilding.Location));
                self.QueueActivity(new FlyCircle());
            }
        }
Beispiel #10
0
 public Activity MoveWithinRange(Target target, WRange range)
 {
     return(Fly.ToPos(target.CenterPosition));
 }
Beispiel #11
0
 public Activity MoveTo(CPos cell, Actor ignoredActor)
 {
     return(Fly.ToCell(cell));
 }
Beispiel #12
0
 public Activity MoveTo(CPos cell, int nearEnough)
 {
     return(Fly.ToCell(cell));
 }