Skip to content

Commit 66f5f26

Browse files
1 parent b02eafe commit 66f5f26

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/RemoteTech/FlightComputer/Commands/ManeuverCommand.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ public override string Description
4646

4747
public override bool Pop(FlightComputer f)
4848
{
49+
if(f.Vessel.patchedConicSolver == null)
50+
{
51+
f.Vessel.AttachPatchedConicsSolver();
52+
f.Vessel.patchedConicSolver.Update();
53+
}
54+
4955
// check if the stored node is still valid
50-
if (f.Vessel.patchedConicSolver.maneuverNodes.IndexOf(this.Node) < 0)
56+
if (f.Vessel.patchedConicSolver.maneuverNodes.FindIndex(x => x.UT == this.Node.UT && x.DeltaV == this.Node.DeltaV) < 0)//IndexOf() is bad comparer
5157
{
5258
RTUtil.ScreenMessage("[Flight Computer]: No maneuver node found.");
5359
return false;
5460
}
5561

62+
if (this.Node.solver == null) // need to repair (due to the scenario of 2 vessels within phyical range)
63+
this.Node = f.Vessel.patchedConicSolver.maneuverNodes.Find(x => x.UT == this.Node.UT && x.DeltaV == this.Node.DeltaV);
64+
5665
var burn = f.ActiveCommands.FirstOrDefault(c => c is BurnCommand);
5766
if (burn != null) {
5867
f.Remove (burn);
@@ -92,7 +101,7 @@ private void AbortManeuver(FlightComputer computer)
92101
RTUtil.ScreenMessage("[Flight Computer]: Maneuver node removed");
93102
if (computer.Vessel.patchedConicSolver != null)
94103
{
95-
Node.RemoveSelf();
104+
this.Node.RemoveSelf();
96105
}
97106

98107
// Flight Computer mode after execution based on settings
@@ -246,13 +255,22 @@ public static ManeuverCommand WithNode(int nodeIndex, FlightComputer f)
246255
/// <returns>true - loaded successfull</returns>
247256
public override bool Load(ConfigNode n, FlightComputer fc)
248257
{
258+
//Additional notes: Load() is never called when cold-launching KSP and resuming flight.
249259
if(base.Load(n,fc))
250260
{
251261
if(n.HasValue("NodeIndex"))
252262
{
253263
this.NodeIndex = int.Parse(n.GetValue("NodeIndex"));
254-
RTLog.Notify("Trying to get Maneuver {0}", this.NodeIndex);
255-
if (this.NodeIndex >= 0)
264+
265+
if (fc.Vessel.patchedConicSolver == null)
266+
{
267+
fc.Vessel.AttachPatchedConicsSolver();
268+
fc.Vessel.patchedConicSolver.Update();
269+
}
270+
271+
RTLog.Notify("Trying to get Maneuver {0} in the list of {1} maneuver nodes", this.NodeIndex, fc.Vessel.patchedConicSolver.maneuverNodes.Count);
272+
273+
if (this.NodeIndex >= 0 && fc.Vessel.patchedConicSolver.maneuverNodes.Count > 0)
256274
{
257275
// Set the ManeuverNode into this command
258276
this.Node = fc.Vessel.patchedConicSolver.maneuverNodes[this.NodeIndex];
@@ -271,8 +289,14 @@ public override bool Load(ConfigNode n, FlightComputer fc)
271289
/// </summary>
272290
public override void Save(ConfigNode n, FlightComputer fc)
273291
{
292+
if (fc.Vessel.patchedConicSolver == null)
293+
{
294+
fc.Vessel.AttachPatchedConicsSolver();
295+
fc.Vessel.patchedConicSolver.Update();
296+
}
297+
274298
// search the node on the List
275-
this.NodeIndex = fc.Vessel.patchedConicSolver.maneuverNodes.IndexOf(this.Node);
299+
this.NodeIndex = fc.Vessel.patchedConicSolver.maneuverNodes.FindIndex(x => x.UT == this.Node.UT && x.DeltaV == this.Node.DeltaV);
276300

277301
// only save this command if we are on the maneuverNode list
278302
if (this.NodeIndex >= 0)

src/RemoteTech/FlightComputer/FlightCore.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public static void HoldAttitude(FlightCtrlState fs, FlightComputer f, ReferenceF
3737

3838
case ReferenceFrame.Maneuver:
3939
ignoreRoll = true;
40+
41+
if (f.Vessel.patchedConicSolver == null)//scenario: two vessels within physical range with FC attitude hold cmds. Unloaded one doesn't have solver instance
42+
{
43+
f.Vessel.AttachPatchedConicsSolver();
44+
f.Vessel.patchedConicSolver.Update();
45+
}
46+
4047
if (f.Vessel.patchedConicSolver.maneuverNodes.Count != 0)
4148
{
4249
forward = f.Vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(v.orbit);

0 commit comments

Comments
 (0)