Skip to content

Commit

Permalink
Fix #734 on the issue of throttle not delayed
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed Aug 11, 2017
1 parent 626b8c5 commit 16acae7
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/RemoteTech/FlightComputer/FlightComputer.cs
Expand Up @@ -360,11 +360,25 @@ private void Enqueue(FlightCtrlState fs)
var dfs = new DelayedFlightCtrlState(fs);
dfs.TimeStamp += Delay;

if(StockAutopilotCommand.IsAutoPilotEngaged(this)) // remove the delay if the autopilot is engaged
dfs.TimeStamp -= Delay;
if (StockAutopilotCommand.IsAutoPilotEngaged(this)) // remove the delay if the autopilot is engaged
{
var autopilotfs = new DelayedFlightCtrlState(fs); // make copy of FS and apply no delay

_flightCtrlQueue.Enqueue(dfs);
//nullify autopilot inputs in the delayed fs
dfs.State.roll = 0f;
dfs.State.rollTrim = 0f;
dfs.State.pitch = 0f;
dfs.State.pitchTrim = 0f;
dfs.State.yaw = 0f;
dfs.State.yawTrim = 0f;

//nullify throttle
autopilotfs.State.mainThrottle = 0f;

_flightCtrlQueue.Enqueue(autopilotfs);
}

_flightCtrlQueue.Enqueue(dfs);
}

/// <summary>Remove a <see cref="FlightCtrlState"/> from the flight control queue.</summary>
Expand All @@ -373,20 +387,22 @@ private void Enqueue(FlightCtrlState fs)
private void PopFlightCtrl(FlightCtrlState fcs, ISatellite sat)
{
var delayed = new FlightCtrlState();
delayed.mainThrottle = fcs.mainThrottle;
float maxThrottle = 0f;

while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
{
delayed = _flightCtrlQueue.Dequeue().State;
maxThrottle = Math.Max(maxThrottle, delayed.mainThrottle);
}
delayed.mainThrottle = maxThrottle;

if (!KeepThrottleNoConnect && !InputAllowed) // enforce the rule of shutting throttle down on connection loss
{
delayed.mainThrottle = 0f;
}
else if (KeepThrottleNoConnect && LockedThrottleNoConnect) // when connection is lost with the disabled rule of shutting throttle down, throttle is locked
{
delayed.mainThrottle = LockedThrottlePositionNoConnect;
}

while (_flightCtrlQueue.Count > 0 && _flightCtrlQueue.Peek().TimeStamp <= RTUtil.GameTime)
{
delayed = _flightCtrlQueue.Dequeue().State;
delayed.mainThrottle = LockedThrottlePositionNoConnect;
}

fcs.CopyFrom(delayed);
Expand Down Expand Up @@ -465,7 +481,7 @@ private void OnFlyByWirePre(FlightCtrlState fcs)

if (!satellite.HasLocalControl)
{
if (InputAllowed)
if (InputAllowed) // working connection
{
LockedThrottleNoConnect = false;
}
Expand Down

0 comments on commit 16acae7

Please sign in to comment.