Exemplo n.º 1
0
        public override bool Tick(Actor self)
        {
            var result = base.Tick(self);

            if (!abortByCancel && shouldCancel)
            {
                shouldCancel = false;
            }

            if (!result)
            {
                return(false);
            }

            if (shouldCancel)
            {
                return(true);
            }

            var tanker = (Tanker)Dockable;

            if (tanker.Current == tanker.Maximum)
            {
                if (!tanker.IsValidPowerStation(tanker.PowerStation))
                {
                    tanker.AssignNearestPowerStation();
                }

                if (tanker.PowerStation == null)
                {
                    return(true);
                }

                DockActor    = tanker.PowerStation;
                Dock         = DockActor.Trait <Dock>();
                DockingState = DockingState.Approaching;
            }
            else
            {
                if (!tanker.IsValidDrillrig(tanker.Drillrig))
                {
                    tanker.AssignNearestDrillrig();
                }

                if (tanker.Drillrig == null)
                {
                    return(true);
                }

                DockActor    = tanker.Drillrig;
                Dock         = DockActor.Trait <Dock>();
                DockingState = DockingState.Approaching;
            }

            return(false);
        }
Exemplo n.º 2
0
        public override bool Tick(Actor self)
        {
            if (!shouldCancel && (DockActor == null || DockActor.IsDead || !DockActor.IsInWorld || Dock.GetDockAction(DockableActor) == null))
            {
                shouldCancel = true;
            }

            if (ChildActivity != null)
            {
                if (shouldCancel)
                {
                    ChildActivity.Cancel(self);
                }

                if (ChildActivity != null)
                {
                    ChildActivity.Tick(self);
                }
            }

            switch (DockingState)
            {
            case DockingState.Approaching:
                if (shouldCancel)
                {
                    DockingState = DockingState.Undocked;
                    break;
                }

                // TODO does not null when target reached...?
                if (ChildActivity != null)
                {
                    break;
                }

                var distance = (DockableActor.CenterPosition - DockActor.CenterPosition).Length;

                if (distance > WDist.FromCells(Dock.Info.QueueDistance).Length)
                {
                    QueueChild(new Move(DockableActor, Target.FromActor(DockActor), WDist.FromCells(Dock.Info.QueueDistance)));
                }
                else
                {
                    DockingState = DockingState.Waiting;
                    Dock.Add(DockableActor);
                }

                break;

            case DockingState.Waiting:
                if (shouldCancel)
                {
                    DockingState = DockingState.Undocked;
                    Dock.Remove(DockableActor);
                }

                break;

            case DockingState.Docking:
                if (ChildActivity == null)
                {
                    if (shouldCancel)
                    {
                        DockingState = DockingState.Undocked;
                        Dock.Remove(DockableActor);
                    }
                    else
                    {
                        DockingState = DockingState.Docked;
                        Dock.OnDock();
                    }
                }

                break;

            case DockingState.Docked:
                if (shouldCancel)
                {
                    StartUndocking();
                }

                break;

            case DockingState.Undocking:
                if (ChildActivity == null)
                {
                    DockingState = DockingState.Undocked;
                    Dock.Remove(DockableActor);

                    if (!DockActor.IsDead && DockActor.IsInWorld)
                    {
                        var rallyPoint = DockActor.TraitOrDefault <RallyPoint>();
                        if (rallyPoint != null && rallyPoint.Path.Any())
                        {
                            DockableActor.QueueActivity(new Move(DockableActor, rallyPoint.Path.First()));
                        }
                    }
                }

                break;

            case DockingState.Undocked:
                break;
            }

            return(DockingState == DockingState.Undocked && ChildActivity == null);
        }
Exemplo n.º 3
0
        public override bool Tick(Actor self)
        {
            if ((DockActor.IsDead || !DockActor.IsInWorld || Dock.IsTraitDisabled) && !IsCanceling)
            {
                Cancel(self, true);
            }

            switch (DockingState)
            {
            case DockingState.Approaching:
                if (State == ActivityState.Canceling)
                {
                    return(true);
                }

                if (ChildActivity != null)
                {
                    break;
                }

                var distance = WDist.FromCells(Dock.Info.QueueDistance);

                if ((dockableActor.CenterPosition - DockActor.CenterPosition).Length > distance.Length)
                {
                    QueueChild(new Move(dockableActor, Target.FromActor(DockActor), distance));
                }
                else
                {
                    DockingState = DockingState.Waiting;
                    Dock.Add(dockableActor);
                }

                break;

            case DockingState.Waiting:
                if (State == ActivityState.Canceling)
                {
                    Dock.Remove(dockableActor);
                    return(true);
                }

                break;

            case DockingState.PrepareDocking:
                if (State == ActivityState.Canceling)
                {
                    Dock.Remove(dockableActor);
                    return(true);
                }

                if (ChildActivity != null)
                {
                    break;
                }

                var target = DockActor.World.Map.CellContaining(DockActor.CenterPosition + Dock.Info.Position + Dock.Info.DragOffset);

                if (dockableActor.Location != target)
                {
                    QueueChild(new Move(dockableActor, target));
                }
                else
                {
                    DockingState = DockingState.Docking;

                    QueueChild(new Turn(dockableActor, Dock.Info.Angle));
                    initialPosition = dockableActor.CenterPosition;
                    QueueChild(new Drag(dockableActor, dockableActor.CenterPosition, DockActor.CenterPosition + Dock.Info.Position, Dock.Info.DragLength));
                }

                break;

            case DockingState.Docking:
                if (State == ActivityState.Canceling)
                {
                    StartUndocking();
                    return(false);
                }

                if (ChildActivity == null)
                {
                    DockingState = DockingState.Docked;
                    Dock.OnDock();
                }

                break;

            case DockingState.Docked:
                if (State == ActivityState.Canceling)
                {
                    StartUndocking();
                    return(false);
                }

                break;

            case DockingState.Undocking:
                if (ChildActivity == null)
                {
                    DockingState = DockingState.None;
                    Dock.Remove(dockableActor);

                    if (!DockActor.IsDead && DockActor.IsInWorld)
                    {
                        var rallyPoint = DockActor.TraitOrDefault <RallyPoint>();
                        if (rallyPoint != null && rallyPoint.Path.Any())
                        {
                            foreach (var cell in rallyPoint.Path)
                            {
                                dockableActor.QueueActivity(new Move(dockableActor, cell));
                            }
                        }
                    }
                }

                break;

            case DockingState.None:
                return(true);
            }

            return(false);
        }