Skip to content

Commit

Permalink
Add support for KSPWheels in the Rover Autopilot.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonSeverinsson committed Jul 2, 2022
1 parent b6d3288 commit 3fd23a7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions MechJeb2/MechJebModuleRoverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class MechJebModuleRoverController : ComputerModule
[EditableInfoItem("#MechJeb_TractionBrakeLimit", InfoItem.Category.Rover), Persistent(pass = (int)Pass.Type)] // Traction Brake Limit
public EditableDouble tractionLimit = 75;

public List<ModuleWheelBase> wheelbases = new List<ModuleWheelBase>();
public List<(PartModule, BaseField)> wheelbases = new List<(PartModule, BaseField)>();

public override void OnStart(PartModule.StartState state)
{
Expand Down Expand Up @@ -105,7 +105,17 @@ public void OnVesselModified(Vessel v)
wheelbases.AddRange(vessel.Parts.Where(
p => p.HasModule<ModuleWheelBase>()
&& p.GetModule<ModuleWheelBase>().wheelType != WheelType.LEG
).Select(p => p.GetModule<ModuleWheelBase>()));
).Select(p => {
var pm = p.Modules.GetModule("ModuleWheelBase");
return (pm, pm.Fields["isGrounded"]);
}));
wheelbases.AddRange(vessel.Parts.Where(
p => p.Modules.Contains("KSPWheelBase") &&
p.Modules.Contains("KSPWheelRotation")
).Select(p => {
var pm = p.Modules.GetModule("KSPWheelBase");
return (pm, pm.Fields["grounded"]);
}));
}
catch (Exception) {}
}
Expand Down Expand Up @@ -146,9 +156,9 @@ public void CalculateTraction()
if (wheelbases.Count == 0) { OnVesselModified(vessel); }
traction = 0;

for (int i = 0; i < wheelbases.Count; i++)
foreach ((PartModule pm, BaseField grounded) in wheelbases)
{
if (wheelbases[i].isGrounded)
if (grounded.GetValue<bool>(pm))
{
traction += 100;
}
Expand Down

0 comments on commit 3fd23a7

Please sign in to comment.