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); }