Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix RemoteTech steering again #1809

Merged
merged 4 commits into from
Sep 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/kOS/Module/kOSVesselModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class kOSVesselModule : VesselModule
private bool initialized = false;
private Vessel parentVessel;
private bool hasRemoteTech = false;
/// <summary>How often to re-attempt the remote tech hook, expressed as a number of physics updates</summary>
private const int RemoteTechRehookPeriod = 25;
private int counterRemoteTechRefresh = RemoteTechRehookPeriod - 2; // make sure it starts out ready to trigger soon

public Guid ID
{
Expand Down Expand Up @@ -46,16 +49,16 @@ public Guid ID
/// </summary>
public override void OnAwake()
{
if (kOS.Safe.Utilities.SafeHouse.Logger != null)
if (SafeHouse.Logger != null)
{
kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose("kOSVesselModule Awake()!");
SafeHouse.Logger.SuperVerbose("kOSVesselModule Awake()!");
parentVessel = GetComponent<Vessel>();
if (parentVessel != null)
{
allInstances[ID] = this;
AddDefaultParameters();
}
kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Awake() finished on {0} ({1})", parentVessel.name, ID));
SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Awake() finished on {0} ({1})", parentVessel.vesselName, ID));
}
}

Expand All @@ -66,7 +69,7 @@ public override void OnAwake()
/// </summary>
public void Start()
{
kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Start()! On {0} ({1})", parentVessel.name, ID));
SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Start()! On {0} ({1})", parentVessel.vesselName, ID));
HarvestParts();
HookEvents();
initialized = true;
Expand All @@ -78,9 +81,9 @@ public void Start()
/// </summary>
public void OnDestroy()
{
if (kOS.Safe.Utilities.SafeHouse.Logger != null)
if (SafeHouse.Logger != null)
{
kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose("kOSVesselModule OnDestroy()!");
SafeHouse.Logger.SuperVerbose("kOSVesselModule OnDestroy()!");
UnHookEvents();
ClearParts();
if (parentVessel != null && allInstances.ContainsKey(ID))
Expand Down Expand Up @@ -260,6 +263,14 @@ private void CheckSwapEvents()
HookRemoteTechPilot();
}
}
if (hasRemoteTech)
{
if (++counterRemoteTechRefresh > RemoteTechRehookPeriod)
{
counterRemoteTechRefresh = 0;
HookRemoteTechPilot();
}
}
}

private void HookRemoteTechPilot()
Expand All @@ -271,6 +282,7 @@ private void HookRemoteTechPilot()
private void UnHookRemoteTechPilot()
{
RemoteTechHook.Instance.RemoveSanctionedPilot(parentVessel.id, HandleRemoteTechSanctionedPilot);
counterRemoteTechRefresh = RemoteTechRehookPeriod - 2; // make sure it starts out ready to trigger soon
}

private void HookStockPilot()
Expand Down Expand Up @@ -345,7 +357,7 @@ public IFlightControlParameter GetFlightControlParameter(string name)
{
name = name.ToLower();
if (!flightControlParameters.ContainsKey(name))
throw new Exception(string.Format("kOSVesselModule on {0} does not contain a parameter named {1}", parentVessel.name, name));
throw new Exception(string.Format("kOSVesselModule on {0} does not contain a parameter named {1}", parentVessel.vesselName, name));
return flightControlParameters[name];
}

Expand Down