Skip to content

Commit da2a3b3

Browse files
committed
PartModule for RPM display info
1 parent b7bdc15 commit da2a3b3

File tree

9 files changed

+138
-45
lines changed

9 files changed

+138
-45
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

GameData/KerbalScienceFoundation/NavInstruments/Runways/custom.rwy

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Runway
2222
shortID = KSC2
2323
hdg = 90
2424
body = Kerbin
25-
altMSL = 1500
25+
altMSL = 425
2626
gsLatitude = 20.5829
2727
gsLongitude = -146.5116
2828
locLatitude = 20.5829

KSP Navigation/NavUtilLib/GlobalVariables.cs

+52-44
Original file line numberDiff line numberDiff line change
@@ -127,50 +127,58 @@ public static bool isINSMode() {
127127

128128
public static void updateNavigationData()
129129
{
130-
131-
selectedGlideSlope = gsList[gsIdx];
132-
selectedRwy = rwyList[rwyIdx];
133-
134-
//Since there seems to be no callback methods to determine whether waypoint has been set or changed, we have to refresh INS data on every update
135-
NavWaypoint navpoint = FinePrint.WaypointManager.navWaypoint;
136-
if (FinePrint.WaypointManager.navIsActive() && (navpoint != null)) {
137-
//Trying to find the FinePrint waypoint that navigation is set for:
138-
Waypoint waypoint = null;
139-
140-
foreach (Waypoint wp in FinePrint.WaypointManager.Instance().Waypoints) {
141-
if (navpoint.latitude == wp.latitude && navpoint.longitude == wp.longitude) {
142-
waypoint = wp;
143-
break;
144-
}
145-
}
146-
if (waypoint != null) {
147-
//If waypoint is fine then generate fake target runway every time
148-
Runway insTarget = new Runway();
149-
insTarget.isINSTarget = true;
150-
insTarget.ident = waypoint.name;
151-
insTarget.hdg = selectedRwy != null ? selectedRwy.hdg : 0;
152-
insTarget.altMSL = (float)(waypoint.height + waypoint.altitude);
153-
insTarget.locLatitude = (float)navpoint.latitude;
154-
insTarget.locLongitude = (float)navpoint.longitude;
155-
insTarget.gsLatitude = (float)navpoint.latitude;
156-
insTarget.gsLongitude = (float)navpoint.longitude;
157-
selectedRwy = insTarget;
158-
}
159-
}
160-
161-
currentVessel = FlightGlobals.ActiveVessel;
162-
163-
bearing = NavUtilLib.Utils.CalcBearingToBeacon(currentVessel, selectedRwy);
164-
dme = NavUtilLib.Utils.CalcDistanceToBeacon(currentVessel, selectedRwy);
165-
elevationAngle = NavUtilLib.Utils.CalcElevationAngle(currentVessel, selectedRwy);
166-
//locDeviation = NavUtilLib.Utils.CalcLocalizerDeviation(bearing, selectedRwy);
167-
locDeviation = (float)NavUtilLib.Utils.CalcLocalizerDeviation(currentVessel, selectedRwy);
168-
gsDeviation = NavUtilLib.Utils.CalcGlideslopeDeviation(elevationAngle, selectedGlideSlope);
169-
170-
//
171-
runwayHeading = (float)NavUtilLib.Utils.CalcProjectedRunwayHeading(currentVessel, selectedRwy);
172-
173-
SetLastNavUpdateUT();
130+
//see if information is current
131+
if (GetLastNavUpdateUT() != Planetarium.GetUniversalTime())
132+
{
133+
134+
selectedGlideSlope = gsList[gsIdx];
135+
selectedRwy = rwyList[rwyIdx];
136+
137+
//Since there seems to be no callback methods to determine whether waypoint has been set or changed, we have to refresh INS data on every update
138+
NavWaypoint navpoint = FinePrint.WaypointManager.navWaypoint;
139+
if (FinePrint.WaypointManager.navIsActive() && (navpoint != null))
140+
{
141+
//Trying to find the FinePrint waypoint that navigation is set for:
142+
Waypoint waypoint = null;
143+
144+
foreach (Waypoint wp in FinePrint.WaypointManager.Instance().Waypoints)
145+
{
146+
if (navpoint.latitude == wp.latitude && navpoint.longitude == wp.longitude)
147+
{
148+
waypoint = wp;
149+
break;
150+
}
151+
}
152+
if (waypoint != null)
153+
{
154+
//If waypoint is fine then generate fake target runway every time
155+
Runway insTarget = new Runway();
156+
insTarget.isINSTarget = true;
157+
insTarget.ident = waypoint.name;
158+
insTarget.hdg = selectedRwy != null ? selectedRwy.hdg : 0;
159+
insTarget.altMSL = (float)(waypoint.height + waypoint.altitude);
160+
insTarget.locLatitude = (float)navpoint.latitude;
161+
insTarget.locLongitude = (float)navpoint.longitude;
162+
insTarget.gsLatitude = (float)navpoint.latitude;
163+
insTarget.gsLongitude = (float)navpoint.longitude;
164+
selectedRwy = insTarget;
165+
}
166+
}
167+
168+
currentVessel = FlightGlobals.ActiveVessel;
169+
170+
bearing = NavUtilLib.Utils.CalcBearingToBeacon(currentVessel, selectedRwy);
171+
dme = NavUtilLib.Utils.CalcDistanceToBeacon(currentVessel, selectedRwy);
172+
elevationAngle = NavUtilLib.Utils.CalcElevationAngle(currentVessel, selectedRwy);
173+
//locDeviation = NavUtilLib.Utils.CalcLocalizerDeviation(bearing, selectedRwy);
174+
locDeviation = (float)NavUtilLib.Utils.CalcLocalizerDeviation(currentVessel, selectedRwy);
175+
gsDeviation = NavUtilLib.Utils.CalcGlideslopeDeviation(elevationAngle, selectedGlideSlope);
176+
177+
//
178+
runwayHeading = (float)NavUtilLib.Utils.CalcProjectedRunwayHeading(currentVessel, selectedRwy);
179+
180+
SetLastNavUpdateUT();
181+
}
174182
}
175183
}
176184

KSP Navigation/RPM/InfoPartModule.cs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using KSP;
6+
using UnityEngine;
7+
using NavUtilLib.GlobalVariables;
8+
using NavUtilLib;
9+
10+
namespace NavUtilRPM
11+
{
12+
class ModuleNavUtilsInfo : PartModule
13+
{
14+
new public void OnAwake()
15+
{
16+
if (NavUtilLib.GlobalVariables.Settings.enableDebugging)
17+
Debug.Log("NavUtils: ModuleNavUtilsInfo.OnAwake()");
18+
19+
20+
//load settings from config
21+
NavUtilLib.ConfigLoader.LoadSettings(NavUtilLib.GlobalVariables.Settings.settingsFileURL);
22+
23+
24+
//load navigation data
25+
if (!NavUtilLib.GlobalVariables.Settings.navAidsIsLoaded)
26+
NavUtilLib.GlobalVariables.Settings.loadNavAids();
27+
}
28+
29+
//public void OnUpdate()
30+
//{
31+
// ;
32+
//}
33+
34+
//selectedGlideSlope, bearing, dme, elevationAngle, locDeviation, gsDeviation, runwayHeading
35+
public object NavInfo(string s)
36+
{
37+
if (NavUtilLib.GlobalVariables.Settings.enableDebugging)
38+
Debug.Log("NavUtils: ModuleNavUtilsInfo.NavInfo() " + s);
39+
40+
FlightData.updateNavigationData();
41+
42+
s = s.ToUpper();
43+
44+
switch (s)
45+
{
46+
case "SELECTEDGLIDESLOPE":
47+
return FlightData.selectedGlideSlope;
48+
49+
case "BEARING":
50+
return FlightData.bearing;
51+
52+
case "DME":
53+
return FlightData.dme;
54+
55+
case "ELEVATIONANGLE":
56+
return FlightData.elevationAngle;
57+
58+
case "LOCALIZERDEVIATION":
59+
return FlightData.locDeviation;
60+
61+
case "GLIDESLOPEDEVIATION":
62+
return FlightData.gsDeviation;
63+
64+
case "RUNWAYHEADING":
65+
return FlightData.runwayHeading;
66+
67+
case "SELECTEDRUNWAYALT":
68+
return FlightData.selectedRwy.altMSL;
69+
70+
case "SELECTEDRUNWAYIDENT":
71+
return FlightData.selectedRwy.ident;
72+
73+
case "SELECTEDRUNWAYLAT":
74+
return FlightData.selectedRwy.locLatitude;
75+
76+
case "SELECTEDRUNWAYLON":
77+
return FlightData.selectedRwy.locLongitude;
78+
79+
default:
80+
return null;
81+
}
82+
}
83+
}
84+
}

KSP Navigation/RPM/NavUtilRPM.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
</Reference>
4242
</ItemGroup>
4343
<ItemGroup>
44+
<Compile Include="InfoPartModule.cs" />
4445
<Compile Include="Instruments.cs" />
4546
<Compile Include="Properties\AssemblyInfo.cs" />
4647
</ItemGroup>

0 commit comments

Comments
 (0)