static public DockIntel IGCUnpack(object data) { var unpacked = (MyTuple <MyTuple <MatrixD, float, float, Vector3D, double, Vector3D>, MyTuple <long, int, int, string>, MyTuple <long, string> >)data; var di = new DockIntel(); di.IGCUnpackInto(unpacked); return(di); }
public void Reset(TimeSpan canonicalTime) { Status = TaskStatus.Incomplete; StartTime = canonicalTime; ExpectedVelocity = AutopilotSubsystem.Controller.GetShipVelocities().LinearVelocity; Drift = ExpectedVelocity + (DockingSubsystem.Connector.Status == MyShipConnectorStatus.Connected ? (DockingSubsystem.Connector.OtherConnector.WorldMatrix.Forward) : (DockingSubsystem.Connector.WorldMatrix.Backward)) * 30; ExpectedPosition = DockingSubsystem.Connector.WorldMatrix.Translation; WaitTask.Status = TaskStatus.Incomplete; dock = null; // cleared = false; }
void AutoHomeCrafts(TimeSpan localTime) { FriendlyShipScratchpad.Clear(); DockIntelScratchpad.Clear(); var intelItems = IntelProvider.GetFleetIntelligences(localTime); foreach (var kvp in intelItems) { if (kvp.Key.Item1 == IntelItemType.Friendly) { var friendly = (FriendlyShipIntel)kvp.Value; if (friendly.HomeID == -1 && !string.IsNullOrEmpty(friendly.CommandChannelTag)) { FriendlyShipScratchpad.Add(friendly); } } else if (kvp.Key.Item1 == IntelItemType.Dock) { var dock = (DockIntel)kvp.Value; if (dock.OwnerID == -1) { DockIntelScratchpad.Add(dock); } } } if (FriendlyShipScratchpad.Count == 0) { return; } foreach (var craft in FriendlyShipScratchpad) { DockIntel targetDock = null; foreach (var dock in DockIntelScratchpad) { if (DockIntel.TagsMatch(craft.HangarTags, dock.Tags)) { targetDock = dock; break; } } if (targetDock != null) { IntelProvider.ReportCommand(craft, TaskType.SetHome, MyTuple.Create(IntelItemType.Dock, targetDock.ID), localTime); DockIntelScratchpad.Remove(targetDock); } } }
public override void Do(Dictionary <MyTuple <IntelItemType, long>, IFleetIntelligence> IntelItems, TimeSpan canonicalTime, Profiler profiler) { if (!IntelItems.ContainsKey(IntelKey)) { Aborted = true; TaskQueue.Clear(); return; } DockIntel dock = (DockIntel)IntelItems[IntelKey]; Vector3D dockPosition = dock.GetPositionFromCanonicalTime(canonicalTime); Vector3 approachPoint = dock.WorldMatrix.Forward * dock.UndockFar + dockPosition; Vector3 entryPoint = dock.WorldMatrix.Forward * (dock.UndockNear + (DockSize == MyCubeSize.Large ? 1.25f : 0.5f) + 1) + dockPosition; Vector3 closePoint = dock.WorldMatrix.Forward * (dock.UndockNear + (DockSize == MyCubeSize.Large ? 1f : 0.25f)) + dockPosition; Vector3 dockDirection = dock.WorldMatrix.Backward; Vector3D dockToMeDir = Program.Me.WorldMatrix.Translation - dockPosition; double dockToMeDist = dockToMeDir.Length(); ApproachEntrance.Destination.Direction = dockDirection; if (dockToMeDist < 250 && dockToMeDist > 150) { EnterHoldingPattern.Destination.Position = Vector3D.Zero; } else { dockToMeDir.Normalize(); Vector3 holdPoint = dockToMeDir * 200 + dockPosition; EnterHoldingPattern.Destination.Position = holdPoint; EnterHoldingPattern.Destination.Velocity = dock.GetVelocity(); } ApproachEntrance.Destination.Direction = dockDirection; ApproachEntrance.Destination.Position = approachPoint; ApproachEntrance.Destination.Velocity = dock.GetVelocity(); ApproachDock.Destination.Direction = dockDirection; ApproachDock.Destination.Position = entryPoint; ApproachDock.Destination.Velocity = dock.GetVelocity(); FinalAdjustToDock.Destination.Direction = dockDirection; FinalAdjustToDock.Destination.Position = closePoint; FinalAdjustToDock.Destination.Velocity = dock.GetVelocity(); if (Indicator != null && dock.IndicatorDir != Vector3D.Zero) { //Matrix.CreateWorld(Connector.WorldMatrix.Translation, Connector.WorldMatrix.Forward, Indicator.WorldMatrix.Forward); var tDir = Vector3D.TransformNormal(Vector3D.TransformNormal(dock.IndicatorDir, MatrixD.Transpose(MatrixD.CreateFromDir(Connector.WorldMatrix.Forward, Indicator.WorldMatrix.Forward))), Connector.WorldMatrix); ApproachEntrance.Destination.DirectionUp = tDir; ApproachDock.Destination.DirectionUp = tDir; FinalAdjustToDock.Destination.DirectionUp = tDir; } if (TaskQueue.Count < 6) { Program.IGC.SendBroadcastMessage(dock.HangarChannelTag, MyTuple.Create(Program.Me.CubeGrid.EntityId, dock.ID, (int)HangarRequest.RequestDock)); Program.IGC.SendBroadcastMessage(dock.HangarChannelTag, MyTuple.Create(Program.Me.CubeGrid.EntityId, dock.ID, (int)HangarRequest.Reserve)); if (dock.OwnerID == Program.Me.CubeGrid.EntityId && (dock.Status & HangarStatus.Docking) != 0) { WaitForClearance.Status = TaskStatus.Complete; } } if (TaskQueue.Count == 4 && (ApproachEntrance.Autopilot.Reference.GetPosition() - approachPoint).LengthSquared() < 1) { TaskQueue.Dequeue(); } if (TaskQueue.Count == 3 && (ApproachDock.Autopilot.Reference.GetPosition() - entryPoint).LengthSquared() < 0.5) { TaskQueue.Dequeue(); } if (TaskQueue.Count < 3) { if (DockTask.DockingSubsystem.Connector.Status == MyShipConnectorStatus.Connectable) { FinalAdjustToDock.Autopilot.Clear(); DockTask.Do(IntelItems, canonicalTime, profiler); TaskQueue.Clear(); } } base.Do(IntelItems, canonicalTime, profiler); }