Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
add action group for resource discharge
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Apr 15, 2017
1 parent c078c66 commit e376c17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Binary file modified GameData/RW Saturatable/SaturatableRW.dll
Binary file not shown.
31 changes: 19 additions & 12 deletions SaturatableRW/RWSaturatable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand All @@ -12,7 +12,7 @@ public class RWSaturatable : PartModule
* This is not and is never intended to be a realistic representation of how reaction wheels work. That would involve simulating
* effects such as gyroscopic stabilisation and precession that are not dependent only on the internal state of the part and current
* command inputs, but the rate of rotation of the vessel and would require applying forces without using the input system
*
*
* Instead, a reaction wheel is simulated as an arbitrary object in a fixed orientation in space. Momentum is
* attributed to and decayed from these objects based on vessel alignment with their arbitrary axes. This system allows for
* a reasonable approximation of RW effects on control input but there are very noticeable inconsistencies with a realistic
Expand Down Expand Up @@ -49,9 +49,10 @@ public class RWSaturatable : PartModule
/// Maximum momentum storable on an axis
/// </summary>
public float saturationLimit;

// Storing module torque for reference since this module overrides the base values to take effect
public float maxRollTorque;

public float maxPitchTorque;
public float maxYawTorque;

Expand Down Expand Up @@ -97,6 +98,7 @@ public class RWSaturatable : PartModule

public List<ResourceConsumer> dischargeResources;
public MomentumDischargeThruster dummyRCS;

public class ResourceConsumer
{
public int ID { get; set; }
Expand All @@ -109,6 +111,7 @@ public ResourceConsumer(int id, double rate, ResourceFlowMode flowMode)
FlowMode = flowMode;
}
}

/// <summary>
/// if false, resource consumption is disallowed
/// </summary>
Expand All @@ -134,6 +137,12 @@ public void ToggleWindow()
Window.Instance.showWindow = !Window.Instance.showWindow;
}

[KSPAction(actionGroup = KSPActionGroup.None, advancedTweakable = true, guiName = "Toggle Discharge", isPersistent = true, requireFullControl = true)]
public void ToggleDischarge()
{
bConsumeResource = !bConsumeResource;
}

public void OnDestroy()
{
if (!HighLogic.LoadedSceneIsFlight || Window.Instance == null || Window.Instance.Vessels == null)
Expand All @@ -160,13 +169,11 @@ public void Start()
break;
}
}

wheelRef = part.Modules.GetModule<ModuleReactionWheel>();

// Float curve initialisation



maxRollTorque = wheelRef.RollTorque;
maxPitchTorque = wheelRef.PitchTorque;
maxYawTorque = wheelRef.YawTorque;
Expand All @@ -177,12 +184,12 @@ public void Start()
// remember reference torque values

LoadConfig();

StartCoroutine(registerWheel());
}
}

IEnumerator registerWheel()
private IEnumerator registerWheel()
{
yield return null;

Expand All @@ -206,7 +213,7 @@ IEnumerator registerWheel()

for (int i = 0; i < 10; i++)
yield return null;

if (!Window.Instance.Vessels.ContainsKey(vessel.vesselName))
Window.Instance.Vessels.Add(vessel.vesselName, new VesselInfo(vessel, wheelRef.State == ModuleReactionWheel.WheelState.Active));

Expand Down Expand Up @@ -282,7 +289,7 @@ public void FixedUpdate()
updateTorque();
}

Vector3 lastRemovedMoment;
private Vector3 lastRemovedMoment;
private void useResourcesToRecover()
{
if (!bConsumeResource || !canForceDischarge)
Expand Down Expand Up @@ -411,7 +418,7 @@ private float decayMoment(float moment, Vector3 refAxis)
private float calcAvailableTorque(Vector3 refAxis, float maxAxisTorque)
{
Vector3 torqueVec = new Vector3(Vector3.Dot(refAxis, Planetarium.forward), Vector3.Dot(refAxis, Planetarium.up), Vector3.Dot(refAxis, Planetarium.right));

// Smallest ratio is the scaling factor so set them huge as a default
float ratiox = 1000000, ratioy = 1000000, ratioz = 1000000;
if (torqueVec.x != 0)
Expand All @@ -435,4 +442,4 @@ private float pctSaturation(float current, float limit)
return 0;
}
}
}
}

0 comments on commit e376c17

Please sign in to comment.