//Call this every frame to make sure the target transform stays up to date public void Update(VesselWrapper VSL) { if (target != null) { UpdateCoordinates(VSL.Body); } if (TargetInfo.targetType != ProtoTargetInfo.Type.Null && HighLogic.LoadedSceneIsFlight) { target = TargetInfo.FindTarget(); if (target == null) { TargetInfo.targetType = ProtoTargetInfo.Type.Null; Name += " last location"; } else { UpdateCoordinates(VSL.Body); } } else { if (go == null) { go = new GameObject(); } go.transform.position = VSL.Body.GetWorldSurfacePosition(Pos.Lat, Pos.Lon, VSL.Body.TerrainAltitude(Pos.Lat, Pos.Lon)); } AbsRadius = Radius * VSL.Geometry.R; }
public virtual void InitTorque(VesselWrapper VSL, float ratio_factor) { wThrustLever = wThrustPos - VSL.Physics.wCoM; thrustDirection = VSL.refT.InverseTransformDirection(wThrustDir); specificTorque = VSL.refT.InverseTransformDirection(Vector3.Cross(wThrustLever, wThrustDir)); torqueRatio = Mathf.Pow(Mathf.Clamp01(1 - Mathf.Abs(Vector3.Dot(wThrustLever.normalized, wThrustDir))), ratio_factor); }
public static bool AvoidStatic(VesselWrapper vsl, Vector3d dir, float dist, Vector3d dV, out Vector3d maneuver) { maneuver = Vector3d.zero; var dVn = dV.normalized; var cosA = Mathf.Clamp(Vector3.Dot(dir, dVn), -1, 1); if (cosA <= 0) { return(false); } var sinA = Mathf.Sqrt(1 - cosA * cosA); var vdist = dist * cosA; var min_separation = dist * sinA; if (min_separation > vsl.Geometry.D || min_separation > vsl.Geometry.R && vdist < min_separation) { return(false); } maneuver = (dVn * cosA - dir).normalized; var vTime = dist * cosA / dV.magnitude; if (vTime > SafeTime(vsl, dVn)) { return(false); } maneuver *= (vsl.Geometry.D - min_separation) / Math.Sqrt(vTime); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="ThrottleControlledAvionics.AtmoSim"/> class. /// </summary> /// <param name="body">Planetary body.</param> /// <param name="vsl">VesselWrapper.</param> public AtmoSim(CelestialBody body, VesselWrapper vsl) { Body = body; VSL = vsl; //0.0005 converts dynamic pressure to kPa and divides area by 2: Drag = dP * Cd * S/2. Cd = 0.0005 * Globals.Instance.ORB.DragK * PhysicsGlobals.DragCubeMultiplier * PhysicsGlobals.DragMultiplier; }
public bool BeforeDestination(VesselWrapper VSL, Vector3d vel) { return(Valid && (VSL.Info.Destination.IsZero() || Vector3.Dot(RelPosition(VSL.Physics.wCoM + VSL.Info.Destination), VSL.Info.Destination) < 0 || Vector3.Dot(vel, VSL.Info.Destination) < 0)); }
protected override bool Action(VesselWrapper VSL) { VSL.CFG.BlockThrottle = true; VSL.CFG.VF.XOffIfOn(VFlight.AltitudeControl); VSL.CFG.VerticalCutoff = Value; return(false); }
public LandingTrajectory(VesselWrapper vsl, Vector3d dV, double startUT, WayPoint target, double target_altitude = 0, bool with_brake = true) : base(vsl, dV, startUT, target) { TargetAltitude = target_altitude; update(with_brake); }
protected override bool Action(VesselWrapper VSL) { VSL.CFG.BlockThrottle = true; VSL.CFG.VF.XOnIfNot(VFlight.AltitudeControl); VSL.CFG.DesiredAltitude = Value; return(false); }
public RendezvousTrajectory(VesselWrapper vsl, Vector3d dV, double startUT, WayPoint target, double transfer_time = -1) : base(vsl, dV, startUT, target) { TransferTime = transfer_time; TargetOrbit = Target.GetOrbit(); update(); }
protected override bool Evaluate(VesselWrapper VSL) { var ret = false; switch (Operator) { case CompareOperator.GT: ret = VesselValue(VSL) > Value; break; case CompareOperator.EQ: ret = Mathf.Abs(VesselValue(VSL) - Value) < Error; break; case CompareOperator.LS: ret = VesselValue(VSL) < Value; break; } if (ret) { if (WaitTimer.TimePassed) { WaitTimer.Reset(); return(true); } } else { WaitTimer.Reset(); } return(false); }
public static Sweep Cast(VesselWrapper vsl, Vector3 dir, float angle, float dist) { var s = new Sweep(vsl); s.Cast(dir, angle, dist); return(s); }
public static float BrakingNodeCorrection(float V0, VesselWrapper VSL) { float ttb; var offset = BrakingOffset(V0, VSL, out ttb); return(offset - ttb / 2); }
protected override bool Action(VesselWrapper VSL) { var nv = Vector3d.zero; switch (mode) { case Mode.Forward: nv = VSL.OnPlanetParams.Heading; break; case Mode.Backward: nv = -VSL.OnPlanetParams.Heading; break; case Mode.Right: nv = Vector3.ProjectOnPlane(VSL.refT.right, VSL.Physics.Up).normalized; break; case Mode.Left: nv = -Vector3.ProjectOnPlane(VSL.refT.right, VSL.Physics.Up).normalized; break; case Mode.Bearing: nv = VSL.Physics.Direction(Bearing); break; case Mode.Off: VSL.CFG.HF.XOff(); return(false); } VSL.CFG.HF.XOn(HFlight.CruiseControl); VSL.HorizontalSpeed.SetNeeded(nv * Value); return(false); }
public EnginesStats(EnginesDB engines, VesselWrapper vsl) : base(vsl) { engines.SortByRole(); TorqueInfo = new TorqueInfo(VSL); for (int i = 0, count = engines.Count; i < count; i++) { var e = engines[i]; e.InitState(); e.InitTorque(VSL, EngineOptimizer.C.TorqueRatioFactor); e.UpdateCurrentTorque(1); } engines.OptimizeForZeroTorque(VSL.Physics.MoI); for (int i = 0, count = engines.Count; i < count; i++) { var e = engines[i]; var throttle = e.Role == TCARole.MANUAL ? e.limit : e.thrustLimit; if (throttle > 0) { if (e.Role != TCARole.MANEUVER) { var thrust = e.nominalCurrentThrust(throttle); MaxThrust += e.wThrustDir * thrust; MaxDefThrust += e.defThrustDir * thrust; MaxMassFlow += e.MaxFuelFlow * throttle; } if (e.isSteering) { TorqueLimits.Add(e.specificTorque * e.nominalCurrentThrust(throttle)); } } } TorqueInfo.Update(TorqueLimits.Max + VSL.Torque.NoEngines.Torque); }
void init() { if (!TCA_Active) { return; } updateCFG(); VSL = new VesselWrapper(this); EnableTCA(VSL.Engines.All.Count > 0 || VSL.Engines.RCS.Count > 0 || VSL.Torque.Wheels.Count > 0); if (!TCA_Active) { VSL = null; return; } VSL.Init(); TCAModulesDatabase.InitModules(this); VSL.ConnectAutopilotOutput();//should follow module initialization vessel.OnPreAutopilotUpdate += OnPreAutopilotUpdate; vessel.OnPostAutopilotUpdate += OnPostAutopilotUpdate; TCAGui.Reinitialize(this); StartCoroutine(updateUnpackDistance()); Actions["onActionUpdate"].active = true; Actions["ToggleTCA"].actionGroup = CFG.ActionGroup; CFG.Resume(this); }
public void OnActivated(VesselWrapper VSL) { if (Level && VSL.OnPlanet) { VSL.CFG.HF.OnIfNot(HFlight.Level); } Activated = false; }
public static void AddNodeRaw(VesselWrapper VSL, Vector3d NodeV, double UT) { var node = VSL.vessel.patchedConicSolver.AddManeuverNode(UT); node.DeltaV = NodeV; VSL.vessel.patchedConicSolver.UpdateFlightPlan(); // VSL.Log("AddNodeRaw: {} : {}", UT, node.DeltaV);//debug }
public static void AddNode(VesselWrapper VSL, Vector3d dV, double UT) { var node = VSL.vessel.patchedConicSolver.AddManeuverNode(UT); node.DeltaV = Orbital2NodeDeltaV(node.patch, dV, UT); VSL.vessel.patchedConicSolver.UpdateFlightPlan(); // VSL.Log("AddNode: {} : {}", UT, node.DeltaV);//debug }
protected override bool Action(VesselWrapper VSL) { if (!VSL.HasTarget) { Message("No Target"); return(false); } VSL.CFG.Nav.XOn(Navigation.FollowTarget); return(false); }
protected override bool Action(VesselWrapper VSL) { if (!VSL.HasTarget) { Message("No Target"); return(false); } VSL.CFG.Nav.XOnIfNot(Navigation.GoToTarget); return(VSL.CFG.Nav[Navigation.GoToTarget]); }
protected override bool Action(VesselWrapper VSL) { if (!VSL.HasTarget) { Message("No Target"); return(false); } VSL.CFG.AP1.XOnIfNot(Autopilot1.MatchVelNear); return(VSL.CFG.AP1[Autopilot1.MatchVelNear]); }
public void Copy(Sweep s) { VSL = s.VSL; L = s.L; C = s.C; R = s.R; Obstacle = s.Obstacle; Altitude = s.Altitude; Maneuver = s.Maneuver; Valid = s.Valid; }
protected override bool Action(VesselWrapper VSL) { if (!VSL.HasTarget) { Message("No Target"); return(false); } VSL.CFG.AP2.XOnIfNot(Autopilot2.Rendezvous); return(VSL.CFG.AP2[Autopilot2.Rendezvous]); }
protected override bool Action(VesselWrapper VSL) { if (!VSL.HasManeuverNode) { Message("No Maneuver Node"); return(false); } VSL.CFG.AP1.XOnIfNot(Autopilot1.Maneuver); return(VSL.CFG.AP1[Autopilot1.Maneuver]); }
public bool ConditionsMet(VesselWrapper VSL) { var ret = Conditions.Count == 0; for (int i = 0, count = Conditions.Count; i < count; i++) { ret |= Conditions[i].True(VSL); } return(ret); }
protected override bool Action(VesselWrapper VSL) { var THR = VSL.TCA.GetModule <ThrottleControl>(); if (THR != null) { THR.Throttle = Value / 100; } return(false); }
protected override bool Action(VesselWrapper VSL) { if (VSL.vessel != null) { foreach (KSPActionGroup g in Enum.GetValues(typeof(KSPActionGroup))) { VSL.vessel.ActionGroups.SetGroup(g, group_is_set(g)); } } return(false); }
public static void AddNode(VesselWrapper VSL, Vector3d dV, double UT) { var node = VSL.vessel.patchedConicSolver.AddManeuverNode(UT); var norm = node.patch.GetOrbitNormal().normalized; var prograde = node.patch.getOrbitalVelocityAtUT(UT).normalized; var radial = Vector3d.Cross(prograde, norm).normalized; node.DeltaV = new Vector3d(Vector3d.Dot(dV, radial), Vector3d.Dot(dV, norm), Vector3d.Dot(dV, prograde)); VSL.vessel.patchedConicSolver.UpdateFlightPlan(); }
public void OnActivated(VesselWrapper VSL) { if (Level && VSL.OnPlanet) { VSL.CFG.HF.OnIfNot(HFlight.Level); } if (SmartEngines != 0) { VSL.CFG.UseSmartEngines = SmartEngines > 0; } Activated = false; }
protected override bool Action(VesselWrapper VSL) { if (attitude.Equals(Attitude.None)) { VSL.CFG.AT.XOff(); } else { VSL.CFG.AT.XOnIfNot(attitude); } return(false); }