public Program() { cockpit = GridTerminalSystem.GetBlockWithName(NAME_COCKPIT) as IMyCockpit; if (cockpit != null) { Echo("init OK"); Echo("SurfaceCount: " + cockpit.SurfaceCount); lcd = cockpit.GetSurface(0); // or 1 lcd.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE; Echo("OxygenCapacity: " + cockpit.OxygenCapacity); Echo("OxygenFilledRatio: " + cockpit.OxygenFilledRatio); // гравитация, вектор указывает на центр планеты Vector3D gravityVector = cockpit.GetNaturalGravity(); stringBuilder.Append("\ngravityVector: ").Append(gravityVector.Length()) .Append("\n X: ").Append(gravityVector.X) .Append("\n Y:").Append(gravityVector.Y) .Append("\n Z:").Append(gravityVector.Z); Echo(stringBuilder.ToString()); // масса корабля float PhysicalMass = cockpit.CalculateShipMass().PhysicalMass; Echo("PhysicalMass: " + PhysicalMass); Runtime.UpdateFrequency = UpdateFrequency.Update1; } else { Echo("init ERROR"); } }
public void Update(MyDetectedEntityInfo target, Vector3D T, Vector3D PointerPos, Vector3D PointerDir) { if (!Launched) { foreach (IMyThrust thr in thrusters) { thr.Enabled = true; thr.ThrustOverridePercentage = 1; } Launched = true; } else { counter++; if (remcon.IsFunctional && (counter > VerticalDelay)) { double currentVelocity = remcon.GetShipVelocities().LinearVelocity.Length(); Vector3D targetvector = new Vector3D(); if (LASER_GUIDED) { targetvector = ((remcon.GetPosition() - PointerPos).Dot(PointerDir) + 700) * PointerDir + PointerPos - remcon.GetPosition(); } else { targetvector = FindInterceptVector(remcon.GetPosition(), currentVelocity * INTERCEPT_COURSE, T, target.Velocity); } Vector3D trgNorm = Vector3D.Normalize(targetvector); if ((target.Position - remcon.GetPosition()).Length() < WH_ARM_DIST) { if (currentVelocity - MyVelocity < -ACCEL_DET) { foreach (IMyWarhead wh in warheads) { wh.Detonate(); } } MyVelocity = currentVelocity; } Vector3D velNorm = Vector3D.Normalize(remcon.GetShipVelocities().LinearVelocity); Vector3D CorrectionVector = Math.Max(ReflectK * trgNorm.Dot(velNorm), 1) * trgNorm - velNorm; Vector3D G = remcon.GetNaturalGravity(); if (G.LengthSquared() == 0) { CorrectionVector = Math.Max(ReflectK * trgNorm.Dot(velNorm), 1) * trgNorm - velNorm; } else { if (JAVELIN) { //trgNorm = Vector3D.Normalize(Vector3D.Reflect(-G, trgNorm)); trgNorm = Vector3D.Normalize(G.Dot(trgNorm) * trgNorm * JAVELIN_CURVE - G); } CorrectionVector = Math.Max(ReflectK * trgNorm.Dot(velNorm), 1) * trgNorm - velNorm; double A = 0; foreach (IMyThrust thr in thrusters) { A += thr.MaxEffectiveThrust; } A /= remcon.CalculateShipMass().PhysicalMass; Vector3D CorrectionNorm = Vector3D.Normalize(CorrectionVector); //CorrectionVector = CorrectionNorm * A - G; Vector3D gr = Vector3D.Reject(remcon.GetNaturalGravity(), CorrectionNorm); CorrectionVector = CorrectionNorm * Math.Sqrt(A * A + gr.LengthSquared()) - gr; } Vector3D Axis = Vector3D.Normalize(CorrectionVector).Cross(remcon.WorldMatrix.Forward); if (Axis.LengthSquared() < 0.1) { Axis += remcon.WorldMatrix.Backward * ROLL; } Axis *= GyroMult; foreach (IMyGyro gyro in gyros) { gyro.Pitch = (float)Axis.Dot(gyro.WorldMatrix.Right); gyro.Yaw = (float)Axis.Dot(gyro.WorldMatrix.Up); gyro.Roll = (float)Axis.Dot(gyro.WorldMatrix.Backward); } } else { foreach (IMyGyro gyro in gyros) { gyro.Pitch = 0; gyro.Yaw = 0; gyro.Roll = 0; } } } }