コード例 #1
0
ファイル: Plane.cs プロジェクト: wenzeslaus/OpenRA
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Move")
            {
                var cell     = self.World.Map.Clamp(order.TargetLocation);
                var explored = self.Owner.Shroud.IsExplored(cell);

                if (!explored && !Info.MoveIntoShroud)
                {
                    return;
                }

                UnReserve();

                var target = Target.FromCell(self.World, cell);
                self.SetTargetLine(target, Color.Green);
                self.CancelActivity();
                self.QueueActivity(new Fly(self, target));
                self.QueueActivity(new FlyCircle(self));
            }
            else if (order.OrderString == "Enter")
            {
                if (Reservable.IsReserved(order.TargetActor))
                {
                    return;
                }

                UnReserve();

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

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

                UnReserve();
                self.CancelActivity();
                self.SetTargetLine(Target.FromActor(airfield), Color.Green);
                self.QueueActivity(new ReturnToBase(self, airfield));
                self.QueueActivity(new ResupplyAircraft(self));
            }
            else
            {
                // Game.Debug("Unreserve due to unhandled order: {0}".F(order.OrderString));
                UnReserve();
            }
        }
コード例 #2
0
        void IResolveOrder.ResolveOrder(Actor self, Order order)
        {
            if (IsTraitDisabled)
            {
                return;
            }

            if (order.OrderString == "Move")
            {
                var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
                if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
                {
                    return;
                }

                var target = Target.FromCell(self.World, cell);

                self.SetTargetLine(target, Color.Green);
            }
            else if (order.OrderString == "Enter")
            {
                // Enter and Repair orders are only valid for own/allied actors,
                // which are guaranteed to never be frozen.
                if (order.Target.Type != TargetType.Actor)
                {
                    return;
                }

                var targetActor = order.Target.Actor;

                // We only want to set a target line if the order will (most likely) succeed
                if (Reservable.IsAvailableFor(targetActor, self))
                {
                    self.SetTargetLine(Target.FromActor(targetActor), Color.Green);
                }
            }

            var currentTransform = self.CurrentActivity as Transform;
            var transform        = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused);

            if (transform == null && currentTransform == null)
            {
                return;
            }

            // Manually manage the inner activity queue
            var activity = currentTransform ?? transform.GetTransformActivity(self);

            if (!order.Queued && activity.NextActivity != null)
            {
                activity.NextActivity.Cancel(self);
            }

            activity.Queue(self, new IssueOrderAfterTransform(order.OrderString, order.Target));

            if (currentTransform == null)
            {
                self.QueueActivity(order.Queued, activity);
            }
        }
コード例 #3
0
ファイル: Production.cs プロジェクト: JustSomeDev1/OpenRA
        public virtual bool Produce(Actor self, ActorInfo producee, string productionType, TypeDictionary inits, int refundableValue)
        {
            if (IsTraitDisabled || IsTraitPaused || Reservable.IsReserved(self))
            {
                return(false);
            }

            // Pick a spawn/exit point pair
            var exit = SelectExit(self, producee, productionType);

            if (exit != null || self.OccupiesSpace == null || !producee.HasTraitInfo <IOccupySpaceInfo>())
            {
                DoProduction(self, producee, exit?.Info, productionType, inits);
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public virtual bool Produce(Actor self, ActorInfo producee, string factionVariant)
        {
            if (Reservable.IsReserved(self) || (building != null && building.Locked))
            {
                return(false);
            }

            // Pick a spawn/exit point pair
            var exit = self.Info.TraitInfos <ExitInfo>().Shuffle(self.World.SharedRandom)
                       .FirstOrDefault(e => CanUseExit(self, producee, e));

            if (exit != null || self.OccupiesSpace == null)
            {
                DoProduction(self, producee, exit, factionVariant);
                return(true);
            }

            return(false);
        }
コード例 #5
0
        public virtual bool Produce(Actor self, ActorInfo producee, string raceVariant)
        {
            if (Reservable.IsReserved(self))
            {
                return(false);
            }

            // pick a spawn/exit point pair
            var exit = self.Info.Traits.WithInterface <ExitInfo>().Shuffle(self.World.SharedRandom)
                       .FirstOrDefault(e => CanUseExit(self, producee, e));

            if (exit != null)
            {
                DoProduction(self, producee, exit, raceVariant);
                return(true);
            }

            return(false);
        }
        public virtual bool Produce(Actor self, ActorInfo producee, string productionType, TypeDictionary inits)
        {
            if (IsTraitDisabled || IsTraitPaused || Reservable.IsReserved(self) || (building != null && building.Locked))
            {
                return(false);
            }

            // Pick a spawn/exit point pair
            var exit = SelectExit(self, producee, productionType);

            if (exit != null || self.OccupiesSpace == null)
            {
                DoProduction(self, producee, exit, productionType, inits);

                return(true);
            }

            return(false);
        }
コード例 #7
0
ファイル: Aircraft.cs プロジェクト: alexeik/openRA.Engine.Hg
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Move")
            {
                var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
                if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
                {
                    return;
                }

                if (!order.Queued)
                {
                    UnReserve();
                }

                var target = Target.FromCell(self.World, cell);

                self.SetTargetLine(target, Color.Green);

                if (!Info.CanHover)
                {
                    self.QueueActivity(order.Queued, new Fly(self, target));
                }
                else
                {
                    self.QueueActivity(order.Queued, new HeliFlyAndLandWhenIdle(self, target, Info));
                }
            }
            else if (order.OrderString == "Enter" || order.OrderString == "Repair")
            {
                // Enter and Repair orders are only valid for own/allied actors,
                // which are guaranteed to never be frozen.
                if (order.Target.Type != TargetType.Actor)
                {
                    return;
                }

                if (!order.Queued)
                {
                    UnReserve();
                }

                var targetActor = order.Target.Actor;

                // We only want to set a target line if the order will (most likely) succeed
                if (Reservable.IsAvailableFor(targetActor, self))
                {
                    self.SetTargetLine(Target.FromActor(targetActor), Color.Green);
                }

                self.QueueActivity(order.Queued, new ReturnToBase(self, Info.AbortOnResupply, targetActor));
            }
            else if (order.OrderString == "Stop")
            {
                self.CancelActivity();

                // HACK: If the player accidentally pressed 'Stop', we don't want this to cancel reservation.
                // If unreserving is actually desired despite an actor below, it should be triggered from OnBecomingIdle.
                if (GetActorBelow() != null)
                {
                    return;
                }

                UnReserve();
            }
            else if (order.OrderString == "ReturnToBase" && rearmable != null && rearmable.Info.RearmActors.Any())
            {
                // Don't restart activity every time deploy hotkey is triggered
                if (self.CurrentActivity is ReturnToBase || GetActorBelow() != null)
                {
                    return;
                }

                if (!order.Queued)
                {
                    UnReserve();
                }

                // Aircraft with TakeOffOnResupply would immediately take off again, so there's no point in forcing them to land
                // on a resupplier. For aircraft without it, it makes more sense to land than to idle above a free resupplier, though.
                self.QueueActivity(order.Queued, new ReturnToBase(self, Info.AbortOnResupply, null, !Info.TakeOffOnResupply));
            }
            else if (order.OrderString == "Scatter")
            {
                Nudge(self);
            }
        }
コード例 #8
0
ファイル: Aircraft.cs プロジェクト: zhangolove/OpenRA
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Move")
            {
                var cell = self.World.Map.Clamp(order.TargetLocation);

                if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
                {
                    return;
                }

                if (!order.Queued)
                {
                    UnReserve();
                }

                var target = Target.FromCell(self.World, cell);

                self.SetTargetLine(target, Color.Green);

                if (IsPlane)
                {
                    self.QueueActivity(order.Queued, new FlyAndContinueWithCirclesWhenIdle(self, target));
                }
                else
                {
                    self.QueueActivity(order.Queued, new HeliFlyAndLandWhenIdle(self, target, Info));
                }
            }
            else if (order.OrderString == "Enter")
            {
                if (!order.Queued)
                {
                    UnReserve();
                }

                if (Reservable.IsReserved(order.TargetActor))
                {
                    if (IsPlane)
                    {
                        self.QueueActivity(new ReturnToBase(self));
                    }
                    else
                    {
                        self.QueueActivity(new HeliReturnToBase(self));
                    }
                }
                else
                {
                    self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green);

                    if (IsPlane)
                    {
                        self.QueueActivity(order.Queued, Util.SequenceActivities(
                                               new ReturnToBase(self, order.TargetActor),
                                               new ResupplyAircraft(self)));
                    }
                    else
                    {
                        var res = order.TargetActor.TraitOrDefault <Reservable>();
                        if (res != null)
                        {
                            Reservation = res.Reserve(order.TargetActor, self, this);
                        }

                        Action enter = () =>
                        {
                            var exit   = order.TargetActor.Info.TraitInfos <ExitInfo>().FirstOrDefault();
                            var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;

                            self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
                            self.QueueActivity(new Turn(self, Info.InitialFacing));
                            self.QueueActivity(new HeliLand(self, false));
                            self.QueueActivity(new ResupplyAircraft(self));
                            self.QueueActivity(new TakeOff(self));
                        };

                        self.QueueActivity(order.Queued, new CallFunc(enter));
                    }
                }
            }
            else if (order.OrderString == "Stop")
            {
                self.CancelActivity();
                if (GetActorBelow() != null)
                {
                    self.QueueActivity(new ResupplyAircraft(self));
                    return;
                }

                UnReserve();

                // TODO: Implement INotifyBecomingIdle instead
                if (!IsPlane && Info.LandWhenIdle)
                {
                    if (Info.TurnToLand)
                    {
                        self.QueueActivity(new Turn(self, Info.InitialFacing));
                    }

                    self.QueueActivity(new HeliLand(self, true));
                }
            }
            else if (order.OrderString == "ReturnToBase")
            {
                UnReserve();
                self.CancelActivity();
                if (IsPlane)
                {
                    self.QueueActivity(new ReturnToBase(self));
                }
                else
                {
                    self.QueueActivity(new HeliReturnToBase(self));
                }

                self.QueueActivity(new ResupplyAircraft(self));
            }
            else
            {
                UnReserve();
            }
        }
コード例 #9
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Move")
            {
                var cell = self.World.Map.Clamp(order.TargetLocation);

                if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
                {
                    return;
                }

                if (!order.Queued)
                {
                    UnReserve();
                }

                var target = Target.FromCell(self.World, cell);

                self.SetTargetLine(target, Color.Green);

                if (!Info.CanHover)
                {
                    self.QueueActivity(order.Queued, new FlyAndContinueWithCirclesWhenIdle(self, target));
                }
                else
                {
                    self.QueueActivity(order.Queued, new HeliFlyAndLandWhenIdle(self, target, Info));
                }
            }
            else if (order.OrderString == "Enter")
            {
                // Enter orders are only valid for own/allied actors,
                // which are guaranteed to never be frozen.
                if (order.Target.Type != TargetType.Actor)
                {
                    return;
                }

                if (!order.Queued)
                {
                    UnReserve();
                }

                var targetActor = order.Target.Actor;
                if (Reservable.IsReserved(targetActor))
                {
                    if (!Info.CanHover)
                    {
                        self.QueueActivity(new ReturnToBase(self, Info.AbortOnResupply));
                    }
                    else
                    {
                        self.QueueActivity(new HeliReturnToBase(self, Info.AbortOnResupply));
                    }
                }
                else
                {
                    self.SetTargetLine(Target.FromActor(targetActor), Color.Green);

                    if (!Info.CanHover && !Info.VTOL)
                    {
                        self.QueueActivity(order.Queued, ActivityUtils.SequenceActivities(
                                               new ReturnToBase(self, Info.AbortOnResupply, targetActor),
                                               new ResupplyAircraft(self)));
                    }
                    else
                    {
                        MakeReservation(targetActor);

                        Action enter = () =>
                        {
                            var exit   = targetActor.FirstExitOrDefault(null);
                            var offset = exit != null ? exit.Info.SpawnOffset : WVec.Zero;

                            self.QueueActivity(new HeliFly(self, Target.FromPos(targetActor.CenterPosition + offset)));
                            if (Info.TurnToDock)
                            {
                                self.QueueActivity(new Turn(self, Info.InitialFacing));
                            }

                            self.QueueActivity(new HeliLand(self, false));
                            self.QueueActivity(new ResupplyAircraft(self));
                        };

                        self.QueueActivity(order.Queued, new CallFunc(enter));
                    }
                }
            }
            else if (order.OrderString == "Stop")
            {
                self.CancelActivity();
                if (GetActorBelow() != null)
                {
                    self.QueueActivity(new ResupplyAircraft(self));
                    return;
                }

                UnReserve();

                // TODO: Implement INotifyBecomingIdle instead
                if (Info.VTOL && Info.LandWhenIdle)
                {
                    if (Info.TurnToLand)
                    {
                        self.QueueActivity(new Turn(self, Info.InitialFacing));
                    }

                    self.QueueActivity(new HeliLand(self, true));
                }
            }
            else if (order.OrderString == "ReturnToBase" && rearmableInfo != null && rearmableInfo.RearmActors.Any())
            {
                UnReserve();
                self.CancelActivity();
                if (!Info.CanHover)
                {
                    self.QueueActivity(new ReturnToBase(self, Info.AbortOnResupply, null, false));
                }
                else
                {
                    self.QueueActivity(new HeliReturnToBase(self, Info.AbortOnResupply, null, false));
                }
            }
        }
コード例 #10
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (Reservation != null)
            {
                Reservation.Dispose();
                Reservation = null;
            }

            if (order.OrderString == "Move")
            {
                var cell     = self.World.Map.Clamp(order.TargetLocation);
                var explored = self.Owner.Shroud.IsExplored(cell);

                if (!explored && !Info.MoveIntoShroud)
                {
                    return;
                }

                var target = Target.FromCell(self.World, cell);

                self.SetTargetLine(target, Color.Green);
                self.CancelActivity();
                self.QueueActivity(new HeliFly(self, target));

                if (Info.LandWhenIdle)
                {
                    if (Info.TurnToLand)
                    {
                        self.QueueActivity(new Turn(self, Info.InitialFacing));
                    }

                    self.QueueActivity(new HeliLand(self, true));
                }
            }

            if (order.OrderString == "Enter")
            {
                if (Reservable.IsReserved(order.TargetActor))
                {
                    self.CancelActivity();
                    self.QueueActivity(new HeliReturn(self));
                }
                else
                {
                    var res = order.TargetActor.TraitOrDefault <Reservable>();
                    if (res != null)
                    {
                        Reservation = res.Reserve(order.TargetActor, self, this);
                    }

                    var exit   = order.TargetActor.Info.Traits.WithInterface <ExitInfo>().FirstOrDefault();
                    var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;

                    self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green);

                    self.CancelActivity();
                    self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
                    self.QueueActivity(new Turn(self, Info.InitialFacing));
                    self.QueueActivity(new HeliLand(self, false));
                    self.QueueActivity(new ResupplyAircraft(self));
                    self.QueueActivity(new TakeOff(self));
                }
            }

            if (order.OrderString == "ReturnToBase")
            {
                self.CancelActivity();
                self.QueueActivity(new HeliReturn(self));
            }

            if (order.OrderString == "Stop")
            {
                self.CancelActivity();

                if (Info.LandWhenIdle)
                {
                    if (Info.TurnToLand)
                    {
                        self.QueueActivity(new Turn(self, Info.InitialFacing));
                    }

                    self.QueueActivity(new HeliLand(self, true));
                }
            }
        }