diff --git a/src/RealAntennasProject/Network/RACommNetNetwork.cs b/src/RealAntennasProject/Network/RACommNetNetwork.cs index 5d8ae77..a31d54e 100644 --- a/src/RealAntennasProject/Network/RACommNetNetwork.cs +++ b/src/RealAntennasProject/Network/RACommNetNetwork.cs @@ -57,7 +57,7 @@ protected virtual void Start() ResetNetwork(); } - protected new void ResetNetwork() + internal new void ResetNetwork() { Debug.Log($"{ModTag} ResetNetwork()"); diff --git a/src/RealAntennasProject/RACommNetScenario.cs b/src/RealAntennasProject/RACommNetScenario.cs index a685568..f0201c2 100644 --- a/src/RealAntennasProject/RACommNetScenario.cs +++ b/src/RealAntennasProject/RACommNetScenario.cs @@ -1,7 +1,9 @@ using CommNet; +using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; +using Upgradeables; namespace RealAntennas { @@ -40,6 +42,7 @@ protected override void Start() ApplyGameSettings(); GameEvents.OnGameSettingsApplied.Add(ApplyGameSettings); + GameEvents.OnKSCFacilityUpgraded.Add(OnKSCFacilityUpgraded); } else StartCoroutine(NotifyDisabled()); } @@ -94,6 +97,7 @@ public void OnDestroy() if (Network) Destroy(Network); if (UI) Destroy(UI); GameEvents.OnGameSettingsApplied.Remove(ApplyGameSettings); + GameEvents.OnKSCFacilityUpgraded.Remove(OnKSCFacilityUpgraded); } public void RebuildHomes() @@ -114,6 +118,23 @@ private void ApplyGameSettings() debugWalkInterval = HighLogic.CurrentGame.Parameters.CustomParams().debugWalkInterval; } + private void OnKSCFacilityUpgraded(UpgradeableFacility facility, int lvl) + { + string tsFacId = ScenarioUpgradeableFacilities.SlashSanitize(nameof(SpaceCenterFacility.TrackingStation)); + if (string.Equals(facility.id, tsFacId, StringComparison.OrdinalIgnoreCase)) + { + ApplyTSLevelChange(); + } + } + + private void ApplyTSLevelChange() + { + Debug.LogFormat($"{ModTag} Applying TS level change"); + float fTSLvl = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation); + GroundStationTechLevel = Mathf.RoundToInt(MaxTL * (HighLogic.CurrentGame.Mode == Game.Modes.CAREER ? fTSLvl : 1)); + Network.ResetNetwork(); + } + private void Initialize() { if (!staticInit && GameDatabase.Instance.GetConfigNode("RealAntennas/RealAntennasCommNetParams/RealAntennasCommNetParams") is ConfigNode RAParamNode)