Skip to content

Commit

Permalink
Fix various space center management issues in sandbox mode
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jan 11, 2025
1 parent 34995bb commit 3de6aa4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Source/RP0/SpaceCenter/Projects/VesselProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ public void MoveVesselToWarehouse()
MessageSystem.Instance.AddMessage(m);
}

MaintenanceHandler.Instance.ScheduleMaintenanceUpdate();
MaintenanceHandler.Instance?.ScheduleMaintenanceUpdate();
}

public void ReleaseShipNode()
Expand Down
8 changes: 8 additions & 0 deletions Source/RP0/SpaceCenter/SpaceCenterManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ public void FixedUpdate()
UpdateTechYearMults();
_lastYearMultUpdateUT = UT;
}

if (MaintenanceHandler.Instance == null)
{
// Normally handled through MaintenanceHandler but that doesn't exist outside career mode
ProgressBuildTime(UTDiff);
}
}

if (HighLogic.LoadedSceneIsFlight && IsSimulatedFlight)
Expand Down Expand Up @@ -953,6 +959,8 @@ public double GetBudgetDelta(double deltaTime)
{
// note NetUpkeepPerDay is negative or 0.

if (MaintenanceHandler.Instance == null) return 0;

double averageSubsidyPerDay = CurrencyUtils.Funds(TransactionReasonsRP0.Subsidy, MaintenanceHandler.GetAverageSubsidyForPeriod(deltaTime)) * (1d / 365.25d);
double fundDelta = Math.Min(0d, MaintenanceHandler.Instance.UpkeepPerDayForDisplay + averageSubsidyPerDay) * deltaTime * (1d / 86400d)
+ GetConstructionCostOverTime(deltaTime) + GetReconRolloutCostOverTime(deltaTime)
Expand Down
9 changes: 7 additions & 2 deletions Source/RP0/UI/KCT/GUI_NewLC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public static void DrawNewLCWindow(int windowID)
GUILayout.Label(new GUIContent(sBuildTime, "At 100% work rate"), GetLabelRightAlignStyle());
GUILayout.EndHorizontal();

double projectedMaintenance = MaintenanceHandler.Instance.ComputeDailyMaintenanceCost(totalCostForMaintenance, isHangar ? FacilityMaintenanceType.Hangar : FacilityMaintenanceType.LC);
double projectedMaintenance = MaintenanceHandler.Instance?.ComputeDailyMaintenanceCost(totalCostForMaintenance, isHangar ? FacilityMaintenanceType.Hangar : FacilityMaintenanceType.LC) ?? 0;

if (projectedMaintenance > 0d)
{
Expand Down Expand Up @@ -580,7 +580,12 @@ private static void ProcessNewLC(bool isModify, double curPadCost, double totalC
if (isModify)
activeLC.Modify(_newLCData, Guid.NewGuid());
else
SpaceCenterManagement.Instance.ActiveSC.LaunchComplexes.Add(new LaunchComplex(_newLCData, SpaceCenterManagement.Instance.ActiveSC));
{
SpaceCenterManagement.Instance.ActiveSC.LaunchComplexes.Add(new LaunchComplex(_newLCData, SpaceCenterManagement.Instance.ActiveSC)
{
IsOperational = true
});
}
}
else
{
Expand Down
34 changes: 19 additions & 15 deletions Source/RP0/UI/KCT/GUI_Personnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,24 @@ private static void DrawPersonnelWindow(int windowID)
GUILayout.Label(SpaceCenterManagement.Instance.Applicants.ToString("N0"), GetLabelRightAlignStyle());
GUILayout.EndHorizontal();

double salaryE = -CurrencyUtils.Funds(TransactionReasonsRP0.SalaryEngineers, -MaintenanceHandler.Instance.IntegrationSalaryPerDay * 365.25d);
GUILayout.BeginHorizontal();
GUILayout.Label("Total Engineers:", GUILayout.Width(120));
GUILayout.Label(SpaceCenterManagement.Instance.TotalEngineers.ToString("N0"), GetLabelRightAlignStyle(), GUILayout.Width(60));
GUILayout.Label("Salary and Facilities:", GetLabelRightAlignStyle(), GUILayout.Width(150));
GUILayout.Label($"√{salaryE:N0}", GetLabelRightAlignStyle());
GUILayout.EndHorizontal();
if (MaintenanceHandler.Instance != null)
{
double salaryE = -CurrencyUtils.Funds(TransactionReasonsRP0.SalaryEngineers, -MaintenanceHandler.Instance.IntegrationSalaryPerDay * 365.25d);
GUILayout.BeginHorizontal();
GUILayout.Label("Total Engineers:", GUILayout.Width(120));
GUILayout.Label(SpaceCenterManagement.Instance.TotalEngineers.ToString("N0"), GetLabelRightAlignStyle(), GUILayout.Width(60));
GUILayout.Label("Salary and Facilities:", GetLabelRightAlignStyle(), GUILayout.Width(150));
GUILayout.Label($"√{salaryE:N0}", GetLabelRightAlignStyle());
GUILayout.EndHorizontal();

double salaryR = -CurrencyUtils.Funds(TransactionReasonsRP0.SalaryResearchers, -MaintenanceHandler.Instance.ResearchSalaryPerDay * 365.25d);
GUILayout.BeginHorizontal();
GUILayout.Label("Total Researchers:", GUILayout.Width(120));
GUILayout.Label(SpaceCenterManagement.Instance.Researchers.ToString("N0"), GetLabelRightAlignStyle(), GUILayout.Width(60));
GUILayout.Label("Salary and Facilities:", GetLabelRightAlignStyle(), GUILayout.Width(150));
GUILayout.Label($"√{salaryR:N0}", GetLabelRightAlignStyle());
GUILayout.EndHorizontal();
double salaryR = -CurrencyUtils.Funds(TransactionReasonsRP0.SalaryResearchers, -MaintenanceHandler.Instance.ResearchSalaryPerDay * 365.25d);
GUILayout.BeginHorizontal();
GUILayout.Label("Total Researchers:", GUILayout.Width(120));
GUILayout.Label(SpaceCenterManagement.Instance.Researchers.ToString("N0"), GetLabelRightAlignStyle(), GUILayout.Width(60));
GUILayout.Label("Salary and Facilities:", GetLabelRightAlignStyle(), GUILayout.Width(150));
GUILayout.Label($"√{salaryR:N0}", GetLabelRightAlignStyle());
GUILayout.EndHorizontal();
}

GUILayout.BeginHorizontal();
if (GUILayout.Button("Engineers")) { _personnelWindowHolder = 0; _personnelPosition.height = 1; }
Expand Down Expand Up @@ -468,7 +471,8 @@ private static string GetAssignText(bool add, LaunchComplex currentLC, out int m
if (add)
{
signChar = "+";
limit = Math.Min(currentLC.KSC.UnassignedEngineers, currentLC.MaxEngineers - currentLC.Engineers);
int unassigned = KSPUtils.CurrentGameIsCareer() ? currentLC.KSC.UnassignedEngineers : int.MaxValue;
limit = Math.Min(unassigned, currentLC.MaxEngineers - currentLC.Engineers);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Source/RP0/Utilities/KCTUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ public static void ChangeEngineers(LaunchComplex currentLC, int delta)
{
currentLC.Engineers += delta;
SCMEvents.OnPersonnelChange.Fire();
MaintenanceHandler.Instance.ScheduleMaintenanceUpdate();
MaintenanceHandler.Instance?.ScheduleMaintenanceUpdate();
currentLC.RecalculateBuildRates();
KCT_GUI.BuildRateForDisplay = null;
}
Expand All @@ -1365,7 +1365,7 @@ public static void ChangeEngineers(LCSpaceCenter ksc, int delta)
{
ksc.Engineers += delta;
SCMEvents.OnPersonnelChange.Fire();
MaintenanceHandler.Instance.ScheduleMaintenanceUpdate();
MaintenanceHandler.Instance?.ScheduleMaintenanceUpdate();
}

public static void ChangeResearchers(int delta)
Expand Down

0 comments on commit 3de6aa4

Please sign in to comment.