Skip to content
Merged
Show file tree
Hide file tree
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
135 changes: 135 additions & 0 deletions Source/MASFlightComputerProxy2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4022,6 +4022,141 @@ public double ToggleRCSTranslate()
return 1.0;
}
}

/// <returns>1 if any RCS thrusters are configured to allow pitch control, 0 otherwise.</returns>
public double GetRCSPitchEnabled()
{
return (vc.anyRcsPitch) ? 1.0 : 0.0;
}

/// <returns>1 if any RCS thrusters are configured to allow yaw control, 0 otherwise.</returns>
public double GetRCSYawEnabled()
{
return (vc.anyRcsYaw) ? 1.0 : 0.0;
}

/// <returns>1 if any RCS thrusters are configured to allow roll control, 0 otherwise.</returns>
public double GetRCSRollEnabled()
{
return (vc.anyRcsRoll) ? 1.0 : 0.0;
}

/// <summary>
/// Enable or disable RCS pitch control.
/// </summary>
/// <param name="active">Whether RCS should be used for pitch.</param>
/// <returns>The number of RCS modules updated.</returns>
public double SetRCSPitchEnabled(bool active)
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enablePitch = active;
}

return vc.moduleRcs.Length;
}

/// <summary>
/// Enable or disable RCS yaw control.
/// </summary>
/// <param name="active">Whether RCS should be used for yaw.</param>
/// <returns>The number of RCS modules updated.</returns>
public double SetRCSYawEnabled(bool active)
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enableYaw = active;
}

return vc.moduleRcs.Length;
}

/// <summary>
/// Enable or disable RCS roll control.
/// </summary>
/// <param name="active">Whether RCS should be used for roll.</param>
/// <returns>The number of RCS modules updated.</returns>
public double SetRCSRollEnabled(bool active)
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enableRoll = active;
}

return vc.moduleRcs.Length;
}

/// <summary>
/// Toggle RCS pitch control.
/// </summary>
/// <returns>1 if pitch is now on, 0 otherwise.</returns>
public double ToggleRCSPitch()
{
if (vc.anyRcsPitch)
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enablePitch = false;
}
return 0.0;
}
else
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enablePitch = true;
}
return 1.0;
}
}

/// <summary>
/// Toggle RCS yaw control.
/// </summary>
/// <returns>1 if yaw is now on, 0 otherwise.</returns>
public double ToggleRCSYaw()
{
if (vc.anyRcsYaw)
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enableYaw = false;
}
return 0.0;
}
else
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enableYaw = true;
}
return 1.0;
}
}

/// <summary>
/// Toggle RCS roll control.
/// </summary>
/// <returns>1 if roll is now on, 0 otherwise.</returns>
public double ToggleRCSRoll()
{
if (vc.anyRcsRoll)
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enableRoll = false;
}
return 0.0;
}
else
{
for (int i = vc.moduleRcs.Length - 1; i >= 0; --i)
{
vc.moduleRcs[i].enableRoll = true;
}
return 1.0;
}
}
#endregion RCS

/// <summary>
Expand Down
39 changes: 23 additions & 16 deletions Source/MASVesselComputerModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ private void UpdateProceduralFairing()
internal bool anyRcsFiring = false;
internal bool anyRcsRotate = false;
internal bool anyRcsTranslate = false;
internal bool anyRcsPitch = false;
internal bool anyRcsYaw = false;
internal bool anyRcsRoll = false;
internal float rcsWeightedThrustLimit;
internal float rcsActiveThrustPercent;
private void UpdateRcs()
Expand All @@ -836,50 +839,54 @@ private void UpdateRcs()
anyRcsFiring = false;
anyRcsRotate = false;
anyRcsTranslate = false;
anyRcsPitch = false;
anyRcsYaw = false;
anyRcsRoll = false;
float netThrust = 0.0f;
rcsWeightedThrustLimit = 0.0f;
rcsActiveThrustPercent = 0.0f;
float numActiveThrusters = 0.0f;

for (int i = moduleRcs.Length - 1; i >= 0; --i)
{
if (moduleRcs[i].rcsEnabled == false)
var rcsModule = moduleRcs[i];

if (rcsModule.rcsEnabled == false)
{
anyRcsDisabled = true;
}
else
{
if (moduleRcs[i].enableX || moduleRcs[i].enableY || moduleRcs[i].enableZ)
anyRcsTranslate = anyRcsTranslate || rcsModule.enableX || rcsModule.enableY || rcsModule.enableZ;
anyRcsPitch = anyRcsPitch || rcsModule.enablePitch;
anyRcsYaw = anyRcsYaw || rcsModule.enableYaw;
anyRcsRoll = anyRcsRoll || rcsModule.enableRoll;

if (rcsModule.rcs_active)
{
anyRcsTranslate = true;
}
if (moduleRcs[i].enableRoll || moduleRcs[i].enableYaw || moduleRcs[i].enablePitch)
{
anyRcsRotate = true;
}
if (moduleRcs[i].rcs_active)
{
for (int q = 0; q < moduleRcs[i].thrustForces.Length; ++q)
for (int q = 0; q < rcsModule.thrustForces.Length; ++q)
{
if (moduleRcs[i].thrustForces[q] > 0.0f)
if (rcsModule.thrustForces[q] > 0.0f)
{
rcsActiveThrustPercent += moduleRcs[i].thrustForces[q] / moduleRcs[i].thrusterPower;
rcsActiveThrustPercent += rcsModule.thrustForces[q] / rcsModule.thrusterPower;
numActiveThrusters += 1.0f;
anyRcsFiring = true;
}
}
}
netThrust += moduleRcs[i].thrusterPower;
rcsWeightedThrustLimit += moduleRcs[i].thrusterPower * moduleRcs[i].thrustPercentage;
netThrust += rcsModule.thrusterPower;
rcsWeightedThrustLimit += rcsModule.thrusterPower * rcsModule.thrustPercentage;

List<PartResourceDefinition> propellants = moduleRcs[i].GetConsumedResources();
List<PartResourceDefinition> propellants = rcsModule.GetConsumedResources();
for (int res = propellants.Count - 1; res >= 0; --res)
{
MarkActiveRcsPropellant(propellants[res].id);
}
}
}

anyRcsRotate = anyRcsPitch || anyRcsYaw || anyRcsRoll;

if (numActiveThrusters > 0.0f)
{
rcsActiveThrustPercent /= numActiveThrusters;
Expand Down
Loading