Skip to content

Commit 8d4ef7f

Browse files
Peppie84Warren Seymour
authored andcommitted
Division by Zero on a ManeuverCommand - fixes RemoteTechnologiesGroup#65
The Maneuver is now on hold until you ativate the engine. A short message will be displayed: http://peppie23.imgur.com/all/
1 parent 25f98bd commit 8d4ef7f

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

src/RemoteTech2/FlightComputer/Commands/ManeuverCommand.cs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ public class ManeuverCommand : AbstractCommand
1212
public double OriginalDelta { get; set; }
1313
public double RemainingTime { get; set; }
1414
public double RemainingDelta { get; set; }
15+
public bool EngineActivated { get; set; }
1516
public override int Priority { get { return 0; } }
1617

1718
public override string Description
1819
{
1920
get
2021
{
2122
if (RemainingTime > 0 || RemainingDelta > 0)
22-
return "Executing maneuver: " + RemainingDelta.ToString("F2") + "m/s" + Environment.NewLine +
23-
"Remaining duration: " + RTUtil.FormatDuration(RemainingTime) + Environment.NewLine + base.Description;
23+
{
24+
string flightInfo = "Executing maneuver: " + RemainingDelta.ToString("F2") +
25+
"m/s" + Environment.NewLine + "Remaining duration: ";
26+
27+
if (EngineActivated)
28+
{
29+
flightInfo += RTUtil.FormatDuration(RemainingTime);
30+
}
31+
else
32+
flightInfo += "-:-";
33+
34+
return flightInfo + Environment.NewLine + base.Description;
35+
}
2436
else
2537
return "Execute planned maneuver" + Environment.NewLine + base.Description;
2638
}
@@ -32,7 +44,17 @@ public override bool Pop(FlightComputer f)
3244
if (burn != null) f.Remove(burn);
3345
OriginalDelta = Node.DeltaV.magnitude;
3446
RemainingDelta = Node.GetBurnVector(f.Vessel.orbit).magnitude;
35-
RemainingTime = RemainingDelta / (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass());
47+
EngineActivated = true;
48+
double thrustToMass = (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass());
49+
50+
if (thrustToMass != 0.0)
51+
RemainingTime = RemainingDelta / thrustToMass;
52+
else
53+
{
54+
EngineActivated = false;
55+
RTUtil.ScreenMessage("[Flight Computer]: No Engine to proceed the maneuver.");
56+
}
57+
3658
return true;
3759
}
3860

@@ -44,9 +66,19 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
4466
var up = (f.SignalProcessor.Body.position - f.SignalProcessor.Position).normalized;
4567
var orientation = Quaternion.LookRotation(forward, up);
4668
FlightCore.HoldOrientation(fcs, f, orientation);
69+
70+
double thrustToMass = (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass());
71+
72+
if (thrustToMass == 0.0)
73+
{
74+
EngineActivated = false;
75+
return false;
76+
}
77+
78+
EngineActivated = true;
4779
fcs.mainThrottle = 1.0f;
48-
RemainingTime -= TimeWarp.deltaTime;
49-
RemainingDelta -= (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass()) * TimeWarp.deltaTime;
80+
RemainingTime = RemainingDelta / thrustToMass;
81+
RemainingDelta -= thrustToMass * TimeWarp.deltaTime;
5082
return false;
5183
}
5284
f.Enqueue(AttitudeCommand.Off(), true, true, true);

0 commit comments

Comments
 (0)