Skip to content

Commit

Permalink
Planner Improvements
Browse files Browse the repository at this point in the history
Use ScaleEdit to select broad range of distances to plan (10km to 100Tm)
Improve tagging for ground station peer planning (isHome, Parent references) expected by physics calculations

Other fixes:
Prevent TechLevel<0 in all scenes
Prevent invalid band on symmetry parts when changing tech level
Clean up callback initialization
  • Loading branch information
DRVeyl authored and DRVeyl committed Jul 18, 2020
1 parent 649fd21 commit bb2d550
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
26 changes: 10 additions & 16 deletions src/RealAntennasProject/ModuleRealAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class ModuleRealAntenna : ModuleDataTransmitter, IPartCostModifier, IPart
[KSPField(guiActive = true, guiActiveEditor = true, guiName = "Peer", groupName = PAWGroupPlanner, groupDisplayName = PAWGroupPlanner)]
public string plannerTargetString = string.Empty;

[KSPField(guiActive = true, guiActiveEditor = true, guiName = "Planning Altitude (Mm)", guiUnits = " Mm", guiFormat = "N0", groupName = PAWGroupPlanner),
UI_FloatRange(maxValue = 1000, minValue = 1, stepIncrement = 1, scene = UI_Scene.All)]
[KSPField(guiActive = true, guiActiveEditor = true, guiName = "Planning Altitude", guiUnits = "m", guiFormat = "N0", groupName = PAWGroupPlanner),
UI_ScaleEdit(incrementSlide = new float[] { 1e4f, 1e6f, 1e8f, 1e10f, 1e12f }, intervals = new float[] { 1e4f, 1e6f, 1e8f, 1e10f, 1e12f, 1e14f }, sigFigs = 3, suppressEditorShipModified = true, unit = "m", useSI = true)]
public float plannerAltitude = 1;

[KSPField(guiActive = true, guiActiveEditor = true, guiName = "Transmit", groupName = PAWGroupPlanner)]
Expand Down Expand Up @@ -136,7 +136,7 @@ public override void OnStart(StartState state)
if (fr.maxValue == fr.minValue)
fr.maxValue += 0.001f;
}
if (HighLogic.LoadedSceneIsEditor && TechLevel < 0) TechLevel = maxTechLevel;
if (TechLevel < 0) TechLevel = maxTechLevel;

if (!RAAntenna.CanTarget)
{
Expand Down Expand Up @@ -235,19 +235,12 @@ private void SetupGUIs()

private void SetupUICallbacks()
{
UI_FloatRange t = Fields[nameof(TechLevel)].uiControlEditor as UI_FloatRange;
t.onFieldChanged = new Callback<BaseField, object>(OnTechLevelChange);

UI_ChooseOption op = Fields[nameof(RFBand)].uiControlEditor as UI_ChooseOption;
op.onFieldChanged = new Callback<BaseField, object>(OnRFBandChange);

UI_FloatRange fr = Fields[nameof(TxPower)].uiControlEditor as UI_FloatRange;
fr.onFieldChanged = new Callback<BaseField, object>(OnTxPowerChange);

UI_FloatRange paE = Fields[nameof(plannerAltitude)].uiControlEditor as UI_FloatRange;
UI_FloatRange paF = Fields[nameof(plannerAltitude)].uiControlFlight as UI_FloatRange;
paE.onFieldChanged = paF.onFieldChanged = new Callback<BaseField, object>(planner.OnPlanningAltitudeChange);

Fields[nameof(TechLevel)].uiControlEditor.onFieldChanged = OnTechLevelChange;
Fields[nameof(TechLevel)].uiControlEditor.onSymmetryFieldChanged = OnTechLevelChangeSymmetry;
Fields[nameof(RFBand)].uiControlEditor.onFieldChanged = OnRFBandChange;
Fields[nameof(TxPower)].uiControlEditor.onFieldChanged = OnTxPowerChange;
Fields[nameof(plannerAltitude)].uiControlEditor.onFieldChanged = planner.OnPlanningAltitudeChange;
Fields[nameof(plannerAltitude)].uiControlFlight.onFieldChanged = planner.OnPlanningAltitudeChange;
Fields[nameof(plannerActiveTxTime)].uiControlEditor.onFieldChanged += OnPlannerActiveTxTimeChanged;
}

Expand All @@ -262,6 +255,7 @@ private void OnTechLevelChange(BaseField f, object obj) // obj is the OLD va
RecalculateFields();
if (!oldBand.Equals(RFBand)) MonoUtilities.RefreshPartContextWindow(part);
}
private void OnTechLevelChangeSymmetry(BaseField f, object obj) => ConfigBandOptions();

private void ApplyGameSettings()
{
Expand Down
13 changes: 9 additions & 4 deletions src/RealAntennasProject/Planner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ internal void RecalculatePlannerFields()
RealAntenna selfAnt = new RealAntennaDigital(RAAntenna) { ParentNode = selfComm };
bool showAltitude = true;
Vector3d dir = Vector3d.up;
double furthestDistance = PlannerAltitude * 1e6;
double closestDistance = PlannerAltitude * 1e6;
double furthestDistance = PlannerAltitude;
double closestDistance = PlannerAltitude;

CelestialBody home = Planetarium.fetch.Home;
if (PlannerTarget is CelestialBody b)
{
showAltitude = (b == home);
if (RATools.HighestGainCompatibleDSNAntenna(net.Nodes, RAAntenna) is RealAntenna DSNAntenna)
{
peerComm = new RACommNode(peerObj.transform) { ParentBody = home };
peerComm = new RACommNode(peerObj.transform) { ParentBody = home, isHome = DSNAntenna.ParentNode?.isHome ?? true };
peerAnt = new RealAntennaDigital(DSNAntenna) { ParentNode = peerComm };
peerAnt.ParentNode.transform.SetPositionAndRotation(home.position + home.GetRelSurfacePosition(0, 0, 0), Quaternion.identity);
peerAnt.ParentNode.precisePosition = peerAnt.ParentNode.position;
Expand All @@ -85,7 +85,12 @@ internal void RecalculatePlannerFields()
}
} else if (PlannerTarget is RealAntenna ra)
{
peerComm = new RACommNode(peerObj.transform) { ParentVessel = ra?.Parent?.vessel };
peerComm = new RACommNode(peerObj.transform)
{
ParentVessel = (ra?.ParentNode as RACommNode)?.ParentVessel,
ParentBody = (ra?.ParentNode as RACommNode)?.ParentBody,
isHome = (ra?.ParentNode as RACommNode)?.isHome ?? false,
};
peerAnt = new RealAntennaDigital(ra) { ParentNode = peerComm };
peerAnt.ParentNode.transform.SetPositionAndRotation(home.position + (closestDistance / 2 * Vector3d.up), Quaternion.identity);
peerAnt.ParentNode.precisePosition = peerAnt.ParentNode.position;
Expand Down

0 comments on commit bb2d550

Please sign in to comment.