Skip to content

Commit e045569

Browse files
committed
Career mode compatibility (fixes #4)
1 parent 6f920a4 commit e045569

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

GameData/PlanningNode/Localization/en-us.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ Localization
22
{
33
en-us
44
{
5-
PlanningNode_mainTitle = Planning Node
6-
PlanningNode_mainTooltip = Plan maneuver nodes from your parent body
7-
PlanningNode_viewOnlyTooltip = Switch to a vessel to create planning nodes
5+
PlanningNode_mainTitle = Planning Node
6+
PlanningNode_mainTooltip = Plan maneuver nodes from your parent body
7+
PlanningNode_viewOnlyTooltip = Switch to a vessel to create planning nodes
8+
PlanningNode_unlockBothTooltip = Upgrade your tracking station and mission control to access planning nodes
9+
PlanningNode_unlockStationTooltip = Upgrade your tracking station to access planning nodes
10+
PlanningNode_unlockMisConTooltip = Upgrade your mission control to access planning nodes
811

912
PlanningNode_editorTitle = Planning Node v<<1>>.<<2>>.<<3>>
1013

GameData/PlanningNode/Localization/zh-cn.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ Localization
22
{
33
zh-cn
44
{
5-
PlanningNode_mainTitle = 深空变轨计划
6-
PlanningNode_mainTooltip = 在你目前环绕的母星的轨道上,策划一个机动点!
7-
PlanningNode_viewOnlyTooltip = 切换到某一载具来策划机动点。
5+
PlanningNode_mainTitle = 深空变轨计划
6+
PlanningNode_mainTooltip = 在你目前环绕的母星的轨道上,策划一个机动点!
7+
PlanningNode_viewOnlyTooltip = 切换到某一载具来策划机动点。
8+
PlanningNode_unlockBothTooltip = 升级追踪站和任务中心来解锁深空机动点
9+
PlanningNode_unlockStationTooltip = 升级追踪站来解锁深空机动点
10+
PlanningNode_unlockMisConTooltip = 升级任务中心来解锁深空机动点
811

912
PlanningNode_editorTitle = 深空变轨计划 v<<1>>.<<2>>.<<3>>
1013

GameData/PlanningNode/PlanningNode-Changelog.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ KERBALCHANGELOG
1010
version = 0.1.4
1111
versionName = Sharpening the Axe
1212
versionKSP = 1.11
13+
CHANGE
14+
{
15+
change = Require mission control and tracking station upgrades in career mode
16+
type = Fix
17+
}
1318
}
1419
VERSION
1520
{

Source/PlanningNodeAddonBase.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,18 @@ private void AddLauncher()
104104
launcher?.Disable(true);
105105
}
106106

107+
string lockReason;
108+
if (!unlocked(out lockReason)) {
109+
launcher?.Disable(true);
110+
}
111+
107112
launcher?.gameObject?.SetTooltip(
108113
"PlanningNode_mainTitle",
109114
launcher.IsEnabled
110115
? "PlanningNode_mainTooltip"
111-
: "PlanningNode_viewOnlyTooltip"
116+
: string.IsNullOrEmpty(lockReason)
117+
? "PlanningNode_viewOnlyTooltip"
118+
: lockReason
112119
);
113120
}
114121
}
@@ -121,6 +128,40 @@ private void RemoveLauncher()
121128
}
122129
}
123130

131+
/// <summary>
132+
/// Check whether the mod should be available for use in the current save.
133+
/// We need patched conics and flight planning.
134+
/// </summary>
135+
/// <param name="reason">User friendly explanation of why we're not available</param>
136+
/// <returns>
137+
/// true if unlocked, false if locked
138+
/// </returns>
139+
private static bool unlocked(out string reason)
140+
{
141+
if (ScenarioUpgradeableFacilities.Instance == null) {
142+
reason = "";
143+
return true;
144+
}
145+
var gVars = GameVariables.Instance;
146+
var stationLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation);
147+
var stationOK = gVars.GetOrbitDisplayMode(stationLevel) == GameVariables.OrbitDisplayMode.PatchedConics;
148+
var missionLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.MissionControl);
149+
var missionOK = gVars.UnlockedFlightPlanning(missionLevel);
150+
if (!stationOK) {
151+
reason = !missionOK ? "PlanningNode_unlockBothTooltip"
152+
: "PlanningNode_unlockStationTooltip";
153+
return false;
154+
} else {
155+
if (!missionOK) {
156+
reason = "PlanningNode_unlockMisConTooltip";
157+
return false;
158+
} else {
159+
reason = "";
160+
return true;
161+
}
162+
}
163+
}
164+
124165
/// <summary>
125166
/// This is called when they click our toolbar button
126167
/// </summary>

Source/PlanningNodeAddonFlight.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ private void OnManeuverNodeSelected()
8686

8787
private ManeuverNode OpenManeuver(Vessel v)
8888
{
89-
var nodes = v.patchedConicSolver.maneuverNodes;
90-
for (int i = 0; i < nodes.Count; ++i) {
89+
var nodes = v.patchedConicSolver?.maneuverNodes;
90+
for (int i = 0; i < (nodes?.Count ?? 0); ++i) {
9191
ManeuverNode nd = nodes[i];
9292
if (nd.attachedGizmo != null) {
9393
return nd;
@@ -107,7 +107,7 @@ private void OnAutoTimeClick()
107107
if (newTime.HasValue) {
108108
nd.attachedGizmo.orbitsAdded += (int)Math.Round((newTime.Value - nd.UT) / renderer.vessel.orbit.period);
109109
nd.UT = newTime.Value;
110-
renderer.vessel.patchedConicSolver.UpdateFlightPlan();
110+
renderer.vessel.patchedConicSolver?.UpdateFlightPlan();
111111
}
112112
}
113113
nd.attachedGizmo?.SetMouseOverGizmo(true);

0 commit comments

Comments
 (0)