diff --git a/Source/RP0/SpaceCenter/Projects/VesselProject.cs b/Source/RP0/SpaceCenter/Projects/VesselProject.cs index f1f6454d45a..54c98b920bf 100644 --- a/Source/RP0/SpaceCenter/Projects/VesselProject.cs +++ b/Source/RP0/SpaceCenter/Projects/VesselProject.cs @@ -1385,7 +1385,7 @@ public void MoveVesselToWarehouse() MessageSystem.Instance.AddMessage(m); } - MaintenanceHandler.Instance.ScheduleMaintenanceUpdate(); + MaintenanceHandler.Instance?.ScheduleMaintenanceUpdate(); } public void ReleaseShipNode() diff --git a/Source/RP0/SpaceCenter/SpaceCenterManagement.cs b/Source/RP0/SpaceCenter/SpaceCenterManagement.cs index 371b8219939..ea25e9820be 100644 --- a/Source/RP0/SpaceCenter/SpaceCenterManagement.cs +++ b/Source/RP0/SpaceCenter/SpaceCenterManagement.cs @@ -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) @@ -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) diff --git a/Source/RP0/UI/KCT/GUI_NewLC.cs b/Source/RP0/UI/KCT/GUI_NewLC.cs index 1f33a4bcb85..a815d445bb8 100644 --- a/Source/RP0/UI/KCT/GUI_NewLC.cs +++ b/Source/RP0/UI/KCT/GUI_NewLC.cs @@ -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) { @@ -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 { diff --git a/Source/RP0/UI/KCT/GUI_Personnel.cs b/Source/RP0/UI/KCT/GUI_Personnel.cs index 33ad28fe63c..55387d115f1 100644 --- a/Source/RP0/UI/KCT/GUI_Personnel.cs +++ b/Source/RP0/UI/KCT/GUI_Personnel.cs @@ -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; } @@ -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 { diff --git a/Source/RP0/Utilities/KCTUtilities.cs b/Source/RP0/Utilities/KCTUtilities.cs index 9892374814d..639edbcbd4c 100644 --- a/Source/RP0/Utilities/KCTUtilities.cs +++ b/Source/RP0/Utilities/KCTUtilities.cs @@ -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; } @@ -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)