protected override void SetElementValue(ulong id, byte[] data) { switch (id) { case ElementID.BlockDuration: BlockDuration = ToULong(data); break; case ElementID.ReferencePriority: ReferencePriority = ToULong(data); break; case ElementID.ReferenceBlock: ReferenceBlock.Add(ToLong(data)); break; case ElementID.CodecState: CodecState = data; break; case ElementID.DiscardPadding: DiscardPadding = ToLong(data); break; } }
void ProcessStepMoveAwayFromDock() { SkipIfOrbitMode(); SkipIfNoGridNearby(); var _rb = ReferenceBlock; var thrusters = new List <IMyThrust>(); if (!IsObstructed(_rb.WorldMatrix.Forward)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Backward); } else if (!IsObstructed(_rb.WorldMatrix.Backward)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Forward); } else if (!IsObstructed(_rb.WorldMatrix.Left)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Right); } else if (!IsObstructed(_rb.WorldMatrix.Right)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Left); } else if (!IsObstructed(_rb.WorldMatrix.Up)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Down); } else if (!IsObstructed(_rb.WorldMatrix.Down)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Up); } else { ZeroThrustOverride(); EchoR("Ship is obstructed, waiting clearance"); throw new PutOffExecutionException(); } double currentSpeed = RemoteControl.GetShipSpeed(); double distanceFromDock = Vector3D.Distance(lastShipPosition, ReferenceBlock.GetPosition()); if (distanceFromDock < SafeDistanceFromDock && currentSpeed < 5) { thrusters.ForEach(thrust => { if (thrust.CurrentThrust > thrust.ThrustOverride) { thrust.ThrustOverride = thrust.CurrentThrust + 5000f; } thrust.ThrustOverride += 2000f; }); } else if (distanceFromDock > SafeDistanceFromDock) { processStep++; } }
public void Handle(DrillEvent e) { Action <DrillEvent> action; if (_stateBehavior.TryGetValue(_state, out action)) { action(e); } _lastTime = DateTime.Now; _lastWorldPosition = ReferenceBlock.GetPosition(); }
void ProcessStepTravelToWaypoint() { SkipIfDocked(); SkipIfStopAtWaypointDisabled(); var _rc = RemoteControl; double distanceFromWaypoint = Vector3D.Distance(currentWaypoint.Coords, ReferenceBlock.GetPosition()); if (Math.Round(_rc.GetShipSpeed(), 0) == 0 && distanceFromWaypoint < 100) { _rc.SetAutoPilotEnabled(false); // might be still enabled and we want it disabled before the next step processStep++; } informationTerminals.Text = string.Format("Arriving at {0} in {1}s", currentWaypoint.Name, Math.Round(distanceFromWaypoint / _rc.GetShipSpeed(), 0)); }
double CalculateYZAngle() { var yDirectionalVector = new Vector3D(0, 1, 0); var entityToPlanetDirectionalVector = Vector3D.Normalize(ReferenceBlock.GetPosition() - OrbitCenterPosition); var entityAngle = Math.Atan2(entityToPlanetDirectionalVector.Y, entityToPlanetDirectionalVector.Z) - Math.Atan2(yDirectionalVector.Y, yDirectionalVector.Z); if (entityAngle < 0) { entityAngle += 2 * Math.PI; } if (entityAngle > (Math.PI / 2) && entityAngle < (Math.PI * 3 / 2)) { entityAngle += Math.PI; } return(entityAngle); }
Waypoint FindNextOrbitWaypoint() { double planetRadius = OrbitRadius; var xDirectionalVector = new Vector3D(1, 0, 0); var yDirectionalVector = new Vector3D(0, 1, 0); var entityToPlanetDirectionalVector = Vector3D.Normalize(ReferenceBlock.GetPosition() - OrbitCenterPosition); var dotX = Vector3D.Dot(xDirectionalVector, entityToPlanetDirectionalVector); var dotY = Vector3D.Dot(yDirectionalVector, entityToPlanetDirectionalVector); var entityXYAngle = Math.Acos(MathHelper.Clamp(dotX, -1f, 1f)); if (dotY < 0) { entityXYAngle = 2 * Math.PI - entityXYAngle; } entityXYAngle += (Math.PI * 2) / 20; // next waypoint increment var z = 0; var x = planetRadius * Math.Cos(entityXYAngle); var y = planetRadius * Math.Sin(entityXYAngle); if (orbitYZAngle == 0) { orbitYZAngle = CalculateYZAngle(); } MatrixD xRotationMatrix = new MatrixD(1, 0, 0, 0, Math.Cos(orbitYZAngle), -Math.Sin(orbitYZAngle), 0, Math.Sin(orbitYZAngle), Math.Cos(orbitYZAngle)); var gpsCoords = new Vector3D(x, y, z); gpsCoords = Vector3D.Rotate(gpsCoords, xRotationMatrix); gpsCoords = Vector3D.Add(gpsCoords, OrbitCenterPosition); //EchoR($"GPS:NextWP:{gpsCoords.X}:{gpsCoords.Y}:{gpsCoords.Z}:#FFF17575:"); return(new Waypoint(string.Format("WP:{0:#.###}", entityXYAngle), gpsCoords, false)); }
void ProcessStepFindNextWaypoint() { if (OrbitMode) { currentWaypoint = FindNextOrbitWaypoint(); } else { if (waypoints.Count() == 0) { EchoR("No waypoint defined"); throw new PutOffExecutionException(); } if (currentWaypoint == null) { currentWaypoint = waypoints.First(); } else { double distanceFromWaypoint = Vector3D.Distance(currentWaypoint.Coords, ReferenceBlock.GetPosition()); if (distanceFromWaypoint < 100) { currentWaypoint = GetNextWaypoint(); } } } processStep++; }
void UpdateLastShipPosition() { lastShipPosition = ReferenceBlock.GetPosition(); }