diff --git a/Changelog.txt b/Changelog.txt index d67c6bf..f1e5bc3 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -87,5 +87,11 @@ Thanks to @jamesErvin for updates to the English localization Added DockingCamera support for the AdvancedMicroSatWedge +4.0.0.7 + Fixed drag cube for the ACDSmall, ACD1500, ACDLarge decoupler + Added Mass to USSolarSwitch + Added display of mass & cost of USSolarSwitch to PAW + Fixed IndexOutOfRange exception for microsats, due to no _PanelMasses specified (was added for embedded panels) + TODO Update all language files for missing fields \ No newline at end of file diff --git a/GameData/UniversalStorage2/Parts/Control/ACD1500.cfg b/GameData/UniversalStorage2/Parts/Control/ACD1500.cfg index b2eb4ed..7b7a6e2 100644 --- a/GameData/UniversalStorage2/Parts/Control/ACD1500.cfg +++ b/GameData/UniversalStorage2/Parts/Control/ACD1500.cfg @@ -216,7 +216,7 @@ PART minimum_drag = 0.2 DRAG_CUBE { - Default, 0.1988,0.7448,0.8757, 0.1988,0.7448,0.8757, 1.217,0.9952,0.1299, 1.217,0.9952,0.1299, 0.1988,0.7442,0.8871, 0.1988,0.7442,0.8871, 0,0,0, 1.25,0.16,1.25 + cube =Default, 0.1988,0.7448,0.8757, 0.1988,0.7448,0.8757, 1.217,0.9952,0.1299, 1.217,0.9952,0.1299, 0.1988,0.7442,0.8871, 0.1988,0.7442,0.8871, 0,0,0, 1.25,0.16,1.25 } // Model call diff --git a/GameData/UniversalStorage2/Parts/Control/ACDLarge.cfg b/GameData/UniversalStorage2/Parts/Control/ACDLarge.cfg index 49079fe..3f42e0d 100644 --- a/GameData/UniversalStorage2/Parts/Control/ACDLarge.cfg +++ b/GameData/UniversalStorage2/Parts/Control/ACDLarge.cfg @@ -218,7 +218,7 @@ PART minimum_drag = 0.2 DRAG_CUBE { - Default, 0.7952,0.745,1.652, 0.7952,0.745,1.652, 4.87,0.9796,0.1611, 4.87,0.9796,0.1611, 0.7952,0.7447,1.673, 0.7952,0.7447,1.673, 0,0,0, 2.5,0.32,2.5 + cube = Default, 0.7952,0.745,1.652, 0.7952,0.745,1.652, 4.87,0.9796,0.1611, 4.87,0.9796,0.1611, 0.7952,0.7447,1.673, 0.7952,0.7447,1.673, 0,0,0, 2.5,0.32,2.5 } // Model call diff --git a/GameData/UniversalStorage2/Parts/Control/ACDSmall.cfg b/GameData/UniversalStorage2/Parts/Control/ACDSmall.cfg index 6938458..6db1491 100644 --- a/GameData/UniversalStorage2/Parts/Control/ACDSmall.cfg +++ b/GameData/UniversalStorage2/Parts/Control/ACDSmall.cfg @@ -207,9 +207,8 @@ PART minimum_drag = 0.2 DRAG_CUBE { - Default, 0.1988,0.7448,0.8757, 0.1988,0.7448,0.8757, 1.217,0.9952,0.1299, 1.217,0.9952,0.1299, 0.1988,0.7442,0.8871, 0.1988,0.7442,0.8871, 0,0,0, 1.25,0.16,1.25 + cube = Default, 0.1988,0.7448,0.8757, 0.1988,0.7448,0.8757, 1.217,0.9952,0.1299, 1.217,0.9952,0.1299, 0.1988,0.7442,0.8871, 0.1988,0.7442,0.8871, 0,0,0, 1.25,0.16,1.25 } - // Model call MODEL { diff --git a/GameData/UniversalStorage2/Parts/Science/CargoStorageWedge.cfg b/GameData/UniversalStorage2/Parts/Science/CargoStorageWedge.cfg index fd552bd..4183404 100644 --- a/GameData/UniversalStorage2/Parts/Science/CargoStorageWedge.cfg +++ b/GameData/UniversalStorage2/Parts/Science/CargoStorageWedge.cfg @@ -75,7 +75,7 @@ PART DRAG_CUBE { - cube = Default, 0.5829,0.8344,0.2631, 0.5829,0.8872,0.3984, 0.2528,0.9224,0.3678, 0.2528,0.9225,0.3678, 0.335,0.845,0.4124, 0.335,0.8448,0.416, -0.02687,-0.02047,-1.49E-08, 0.439,0.8193,0.7224 + cube = Default, 0.5829,0.8344,0.2631, 0.5829,0.8872,0.3984, 0.2528,0.9224,0.3678, 0.2528,0.9225,0.3678, 0.335,0.845,0.4124, 0.335,0.8448,0.416, -0.02687,-0.02047,-1.49E-08, 0.439,0.8193,0.7224 } // Model call diff --git a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud0625.cfg b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud0625.cfg index b95a4cc..120c5ce 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud0625.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud0625.cfg @@ -308,13 +308,14 @@ PART MODULE { name = USSolarSwitch - //SwitchID = 0 + SwitchID = 0 secondaryTransformName = sunCatcher solarMeshTransformName = Solar resourceName = ElectricCharge chargeRate = 1.4 toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 300 + AddedPanelMass = 0.010;0 DebugMode = false } diff --git a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250.cfg b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250.cfg index 0d447b6..416a6e8 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250.cfg @@ -256,6 +256,7 @@ PART chargeRate = 4;4 toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 900;900 + AddedPanelMass = 0.010;0.020;0 DebugMode = false } /- diff --git a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250Soyuz.cfg b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250Soyuz.cfg index f7929ce..0e476d6 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250Soyuz.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1250Soyuz.cfg @@ -288,6 +288,7 @@ PART chargeRate = 1;2;3;4 toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 225;450;675;900 + AddedPanelMass = 0.010;0.020;0.030;0.040;0 DebugMode = false } /- diff --git a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1500.cfg b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1500.cfg index bcab557..b6645d1 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1500.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1500.cfg @@ -233,8 +233,9 @@ PART solarMeshTransformName = Solar resourceName = ElectricCharge chargeRate = 4;4 - toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel + //toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 900;900 + AddedPanelMass = 0.010;0.020;0.030;0.040;0 DebugMode = false } /- diff --git a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1875.cfg b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1875.cfg index e4b5615..a4c229d 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1875.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/AdaptorShroud1875.cfg @@ -259,6 +259,7 @@ PART chargeRate = 7 toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 1800 + AddedPanelMass = 0.010;0 DebugMode = false } diff --git a/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud1500.cfg b/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud1500.cfg index d4ec41f..8e99dcb 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud1500.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud1500.cfg @@ -443,8 +443,10 @@ PART chargeRate = 1;2;3;4;0 toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 225;450;675;900;0 + AddedPanelMass = 0.010;0.020;0.030;0.040;0 DebugMode = false } + /- } diff --git a/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud250.cfg b/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud250.cfg index f1c89f8..93b9863 100644 --- a/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud250.cfg +++ b/GameData/UniversalStorage2/Parts/Shrouds/CylindricalShroud250.cfg @@ -363,6 +363,7 @@ PART chargeRate = 1;2;3;4;0 toggleSolarPanelEventGUIName = #autoLOC_US_ToggleSolarPanel AddedCost = 188;376;564;752;0 + AddedPanelMass = 0.010;0.020;0.030;0.040;0 DebugMode = false } diff --git a/GameData/UniversalStorage2/UniversalStorage2.version b/GameData/UniversalStorage2/UniversalStorage2.version index ed879ac..b8c911f 100644 --- a/GameData/UniversalStorage2/UniversalStorage2.version +++ b/GameData/UniversalStorage2/UniversalStorage2.version @@ -7,7 +7,7 @@ "MAJOR": 4, "MINOR": 0, "PATCH": 0, - "BUILD": 5 + "BUILD": 6 }, "KSP_VERSION": { "MAJOR": 1, diff --git a/USSourceDev/UniversalStorage/AssemblyVersion.cs b/USSourceDev/UniversalStorage/AssemblyVersion.cs index 2952d3a..43a4020 100644 --- a/USSourceDev/UniversalStorage/AssemblyVersion.cs +++ b/USSourceDev/UniversalStorage/AssemblyVersion.cs @@ -10,6 +10,6 @@ using System.Reflection; - [assembly: AssemblyVersion("4.0.0.5")] - [assembly: AssemblyFileVersion("4.0.0.5")] - [assembly: AssemblyInformationalVersion("v4.0.0.5")] \ No newline at end of file + [assembly: AssemblyVersion("4.0.0.6")] + [assembly: AssemblyFileVersion("4.0.0.6")] + [assembly: AssemblyInformationalVersion("v4.0.0.6")] \ No newline at end of file diff --git a/USSourceDev/UniversalStorage/SwitchModules/USCostSwitch.cs b/USSourceDev/UniversalStorage/SwitchModules/USCostSwitch.cs index a3158a4..7811b11 100644 --- a/USSourceDev/UniversalStorage/SwitchModules/USCostSwitch.cs +++ b/USSourceDev/UniversalStorage/SwitchModules/USCostSwitch.cs @@ -26,6 +26,7 @@ public class USCostSwitch : USBaseSwitch, IPartCostModifier private string _localizedDryCostString = "Part Cost"; + private USSolarSwitch solarSwitchModule = null; public override void OnAwake() { base.OnAwake(); @@ -35,7 +36,7 @@ public override void OnAwake() if (onFuelRequestCost != null) onFuelRequestCost.Add(onFuelSwitchRequest); - _localizedDryCostString = Localizer.Format(DisplayCostName); + //_localizedDryCostString = Localizer.Format(DisplayCostName); Fields["AddedCostValue"].guiName = _localizedDryCostString; } @@ -48,7 +49,7 @@ public override void OnStart(StartState state) return; _partCostModifiers = part.FindModulesImplementing(); - + solarSwitchModule = part.FindModuleImplementing(); for (int i = _partCostModifiers.Count - 1; i >= 0; i--) { if (_partCostModifiers[i] == (IPartCostModifier)this) @@ -116,7 +117,10 @@ private void onFuelSwitchRequest(int index, Part p, USFuelSwitch fuel) if (_Costs.Length > CurrentSelection) cost = (float)_Costs[CurrentSelection]; - fuel.setMeshCost(cost); + fuel.setMeshCost(cost); + + AddedCostValue = AddedCostValue = part.partInfo.cost + cost; + UpdateSolarCost(); } private float UpdateCost() @@ -132,18 +136,30 @@ private float UpdateCost() { otherCosts += _partCostModifiers[i].GetModuleCost(0, ModifierStagingSituation.CURRENT); } - + + USdebugMessages.USStaticLog("USCostSwitch.GetModuleMass, CurrentSelection: " + CurrentSelection); AddedCostValue = part.partInfo.cost + cost + otherCosts; + return cost; } + private void UpdateSolarCost() + { + if (solarSwitchModule!=null) + { + AddedCostValue += solarSwitchModule.GetModuleCost(0, ModifierStagingSituation.CURRENT); + USdebugMessages.USStaticLog("USCostSwitch.GetModuleMass, solarSwitchModuleCost: " + solarSwitchModule.GetModuleCost(0, ModifierStagingSituation.CURRENT)); + } + } public float GetModuleCost(float defaultCost, ModifierStagingSituation sit) { if (!_updateCost) return 0; - return UpdateCost(); + var m = UpdateCost(); + UpdateSolarCost(); + return m; } public ModifierChangeWhen GetModuleCostChangeWhen() diff --git a/USSourceDev/UniversalStorage/SwitchModules/USFuelSwitch.cs b/USSourceDev/UniversalStorage/SwitchModules/USFuelSwitch.cs index 1cbd0cb..9fe7cbb 100644 --- a/USSourceDev/UniversalStorage/SwitchModules/USFuelSwitch.cs +++ b/USSourceDev/UniversalStorage/SwitchModules/USFuelSwitch.cs @@ -6,10 +6,10 @@ namespace UniversalStorage2 { public class USFuelSwitch : PartModule, IPartCostModifier, IPartMassModifier - { - [KSPField] - public string SwitchID = string.Empty; - [KSPField] + { + [KSPField] + public string SwitchID = string.Empty; + [KSPField] public string resourceNames = "ElectricCharge;ElectricCharge|LiquidFuel,Oxidizer;LiquidFuel,Oxidizer|MonoPropellant;MonoPropellant|Structural;Structural"; [KSPField] public string resourceAmounts = "100;100|75,25;75,25|200;200|0;0"; @@ -21,9 +21,9 @@ public class USFuelSwitch : PartModule, IPartCostModifier, IPartMassModifier public string tankCost = "0;0|0;0|0;0|0;0"; [KSPField] public bool displayCurrentTankCost = true; - [KSPField] - public bool displayCurrentTankDryMass = true; - [KSPField] + [KSPField] + public bool displayCurrentTankDryMass = true; + [KSPField] public bool availableInFlight = false; [KSPField] public bool availableInEditor = false; @@ -39,22 +39,23 @@ public class USFuelSwitch : PartModule, IPartCostModifier, IPartMassModifier public bool configLoaded = false; [KSPField] public bool DebugMode = false; - [KSPField] - public string DisplayCostName = "#autoLOC_US_DryCost"; - [KSPField] - public string DisplayMassName = "#autoLOC_US_DryMass"; - [KSPField] - public string ModuleDisplayName = "#autoLOC_US_FuelSwitch"; - [KSPField(guiActive = false, guiActiveEditor = true, guiName = "Dry cost")] + [KSPField] + public string DisplayCostName = "#autoLOC_US_DryCost"; + [KSPField] + public string DisplayMassName = "#autoLOC_US_DryMass"; + [KSPField] + public string ModuleDisplayName = "#autoLOC_US_FuelSwitch"; + + [KSPField(guiActive = false, guiActiveEditor = true, guiName = "Dry cost")] public float addedCost = 0f; [KSPField(guiActive = false, guiActiveEditor = true, guiName = "Dry mass")] public float dryMassInfo = 0f; private List>> tankList; - private int[] _SwitchIndices; + private int[] _SwitchIndices; - private float meshCost = 0; + private float meshCost = 0; private float meshMass = 0; private List> weightList; @@ -65,35 +66,39 @@ public class USFuelSwitch : PartModule, IPartCostModifier, IPartMassModifier UIPartActionWindow tweakableUI; private USdebugMessages debug; - - private EventData onUSFuelSwitch; - private EventData onFuelRequestMass; - private EventData onFuelRequestCost; - private string _localizedDryCostString = "Dry Cost"; - private string _localizedDryMassString = "Dry Mass"; + private EventData onUSFuelSwitch; + private EventData onFuelRequestMass; + private EventData onFuelRequestCost; - public override void OnStart(PartModule.StartState state) - { - if (String.IsNullOrEmpty(SwitchID)) - return; + private string _localizedDryCostString = "Dry Cost"; + private string _localizedDryMassString = "Dry Mass"; - _SwitchIndices = USTools.parseIntegers(SwitchID).ToArray(); + private USSolarSwitch solarSwitchModule = null; - onFuelRequestCost = GameEvents.FindEvent>("onFuelRequestCost"); - onFuelRequestMass = GameEvents.FindEvent>("onFuelRequestMass"); - onUSFuelSwitch = GameEvents.FindEvent>("onUSFuelSwitch"); + public override void OnStart(PartModule.StartState state) + { + if (String.IsNullOrEmpty(SwitchID)) + return; + + _SwitchIndices = USTools.parseIntegers(SwitchID).ToArray(); + + onFuelRequestCost = GameEvents.FindEvent>("onFuelRequestCost"); + onFuelRequestMass = GameEvents.FindEvent>("onFuelRequestMass"); + onUSFuelSwitch = GameEvents.FindEvent>("onUSFuelSwitch"); + + solarSwitchModule = part.FindModuleImplementing(); - _localizedDryCostString = Localizer.Format(DisplayCostName); - _localizedDryMassString = Localizer.Format(DisplayMassName); + _localizedDryCostString = Localizer.Format(DisplayCostName); + _localizedDryMassString = Localizer.Format(DisplayMassName); - Fields["addedCost"].guiName = _localizedDryCostString; - Fields["dryMassInfo"].guiName = _localizedDryMassString; + Fields["addedCost"].guiName = _localizedDryCostString; + Fields["dryMassInfo"].guiName = _localizedDryMassString; - if (onUSFuelSwitch != null) - onUSFuelSwitch.Add(OnFuelSwitch); - - initializeData(); + if (onUSFuelSwitch != null) + onUSFuelSwitch.Add(OnFuelSwitch); + + initializeData(); if (selectedTankModeOne == -1 || selectedTankModeTwo == -1) { @@ -102,8 +107,8 @@ public override void OnStart(PartModule.StartState state) assignResourcesToPart(false); } - onFuelRequestMass.Fire(_SwitchIndices[0], part, this); - onFuelRequestCost.Fire(_SwitchIndices[0], part, this); + onFuelRequestMass.Fire(_SwitchIndices[0], part, this); + onFuelRequestCost.Fire(_SwitchIndices[0], part, this); } public override void OnAwake() @@ -112,19 +117,19 @@ public override void OnAwake() initializeData(); } - private void OnDestroy() - { - if (onUSFuelSwitch != null) - onUSFuelSwitch.Remove(OnFuelSwitch); - } + private void OnDestroy() + { + if (onUSFuelSwitch != null) + onUSFuelSwitch.Remove(OnFuelSwitch); + } - public override void OnLoad(ConfigNode node) + public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (!configLoaded) initializeData(); - + configLoaded = true; } @@ -146,59 +151,59 @@ public override string GetInfo() return base.GetInfo(); } - public override string GetModuleDisplayName() - { - return Localizer.Format(ModuleDisplayName); - } + public override string GetModuleDisplayName() + { + return Localizer.Format(ModuleDisplayName); + } - private void initializeData() - { - if (!initialized) - { - debug = new USdebugMessages(DebugMode, "USFuelSwitch"); + private void initializeData() + { + if (!initialized) + { + debug = new USdebugMessages(DebugMode, "USFuelSwitch"); - setupTankList(); + setupTankList(); - weightList = new List>(); + weightList = new List>(); - string[] weights = tankMass.Split('|'); + string[] weights = tankMass.Split('|'); - for (int i = 0; i < weights.Length; i++) - { - weightList.Add(USTools.parseDoubles(weights[i])); - } + for (int i = 0; i < weights.Length; i++) + { + weightList.Add(USTools.parseDoubles(weights[i])); + } - tankCostList = new List>(); + tankCostList = new List>(); - string[] costs = tankCost.Split('|'); + string[] costs = tankCost.Split('|'); - for (int i = 0; i < costs.Length; i++) - { - tankCostList.Add(USTools.parseDoubles(costs[i])); - } + for (int i = 0; i < costs.Length; i++) + { + tankCostList.Add(USTools.parseDoubles(costs[i])); + } - if (HighLogic.LoadedSceneIsFlight) - hasLaunched = true; + if (HighLogic.LoadedSceneIsFlight) + hasLaunched = true; - Events["nextTankSetupEvent"].guiActive = availableInFlight; - Events["nextTankSetupEvent"].guiActiveEditor = availableInEditor; - Events["previousTankSetupEvent"].guiActive = availableInFlight; - Events["previousTankSetupEvent"].guiActiveEditor = availableInEditor; - Events["nextModeEvent"].guiActive = availableInFlight; - Events["nextModeEvent"].guiActiveEditor = availableInEditor; - Events["previousModeEvent"].guiActive = availableInFlight; - Events["previousModeEvent"].guiActiveEditor = availableInEditor; + Events["nextTankSetupEvent"].guiActive = availableInFlight; + Events["nextTankSetupEvent"].guiActiveEditor = availableInEditor; + Events["previousTankSetupEvent"].guiActive = availableInFlight; + Events["previousTankSetupEvent"].guiActiveEditor = availableInEditor; + Events["nextModeEvent"].guiActive = availableInFlight; + Events["nextModeEvent"].guiActiveEditor = availableInEditor; + Events["previousModeEvent"].guiActive = availableInFlight; + Events["previousModeEvent"].guiActiveEditor = availableInEditor; - if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.Mode == Game.Modes.CAREER) - Fields["addedCost"].guiActiveEditor = displayCurrentTankCost; + if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.Mode == Game.Modes.CAREER) + Fields["addedCost"].guiActiveEditor = displayCurrentTankCost; - Fields["dryMassInfo"].guiActiveEditor = displayCurrentTankDryMass; + Fields["dryMassInfo"].guiActiveEditor = displayCurrentTankDryMass; - initialized = true; - } - } + initialized = true; + } + } - [KSPEvent(guiActive=true, guiActiveEditor = true, guiName = "#autoLOC_US_NextTankModeSetup")] + [KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "#autoLOC_US_NextTankModeSetup")] public void nextModeEvent() { selectedTankModeTwo++; @@ -242,55 +247,55 @@ public void previousTankSetupEvent() assignResourcesToPart(true); } - private void OnFuelSwitch(int index, int selection, bool modeOne, Part p) - { - if (p != part) - return; - - for (int i = _SwitchIndices.Length - 1; i >= 0; i--) - { - if (_SwitchIndices[i] == index) - { - if (modeOne) - { - selectedTankModeOne = selection; - - if (onFuelRequestCost != null) - onFuelRequestCost.Fire(index, part, this); - - if (onFuelRequestMass != null) - onFuelRequestMass.Fire(index, part, this); - - assignResourcesToPart(true); - } - else - { - selectedTankModeTwo = selection; - - if (onFuelRequestCost != null) - onFuelRequestCost.Fire(index, part, this); - - if (onFuelRequestMass != null) - onFuelRequestMass.Fire(index, part, this); - - assignResourcesToPart(true); - } - - break; - } - } - } - - public void setMeshCost(float cost) - { - meshCost = cost; - } - - public void setMeshMass(float mass) - { - meshMass = mass; - } - + private void OnFuelSwitch(int index, int selection, bool modeOne, Part p) + { + if (p != part) + return; + + for (int i = _SwitchIndices.Length - 1; i >= 0; i--) + { + if (_SwitchIndices[i] == index) + { + if (modeOne) + { + selectedTankModeOne = selection; + + if (onFuelRequestCost != null) + onFuelRequestCost.Fire(index, part, this); + + if (onFuelRequestMass != null) + onFuelRequestMass.Fire(index, part, this); + + assignResourcesToPart(true); + } + else + { + selectedTankModeTwo = selection; + + if (onFuelRequestCost != null) + onFuelRequestCost.Fire(index, part, this); + + if (onFuelRequestMass != null) + onFuelRequestMass.Fire(index, part, this); + + assignResourcesToPart(true); + } + + break; + } + } + } + + public void setMeshCost(float cost) + { + meshCost = cost; + } + + public void setMeshMass(float mass) + { + meshMass = mass; + } + private void assignResourcesToPart(bool calledByPlayer) { // destroying a resource messes up the gui in editor, but not in flight. @@ -318,7 +323,7 @@ private void assignResourcesToPart(bool calledByPlayer) if (tweakableUI != null) tweakableUI.displayDirty = true; else - debug.debugMessage("no UI to refresh"); + debug.debugMessage("no UI to refresh"); } private void setupTankInPart(Part currentPart, bool calledByPlayer) @@ -328,15 +333,15 @@ private void setupTankInPart(Part currentPart, bool calledByPlayer) for (int i = 0; i < tankList.Count; i++) { - if (DebugMode) - debug.debugMessage(string.Format("Tank Mode: {0} - Selection: {1}", i, selectedTankModeTwo)); + if (DebugMode) + debug.debugMessage(string.Format("Tank Mode: {0} - Selection: {1}", i, selectedTankModeTwo)); - if (selectedTankModeTwo == i) + if (selectedTankModeTwo == i) { for (int j = 0; j < tankList[i].Count; j++) { - if (DebugMode) - debug.debugMessage(string.Format("Tank: {0} - Selection: {1}", j, selectedTankModeOne)); + if (DebugMode) + debug.debugMessage(string.Format("Tank: {0} - Selection: {1}", j, selectedTankModeOne)); if (selectedTankModeOne == j) { @@ -354,10 +359,10 @@ private void setupTankInPart(Part currentPart, bool calledByPlayer) else newResourceNode.AddValue("amount", res.amount); - if (DebugMode) - debug.debugMessage(string.Format("Switch to new resource: {0} - Amount: {1:N2} - Max: {2:N2}", res.name, res.amount, res.maxAmount)); + if (DebugMode) + debug.debugMessage(string.Format("Switch to new resource: {0} - Amount: {1:N2} - Max: {2:N2}", res.name, res.amount, res.maxAmount)); - currentPart.AddResource(newResourceNode); + currentPart.AddResource(newResourceNode); } } } @@ -423,7 +428,7 @@ private void setupTankList() resourceList.Add(resourceTankAmounts); initialResourceList.Add(initResourceTankAmounts); } - + // Then find the kinds of resources each tank holds, and fill them with the amounts found previously, or the amount they held last (values kept in save persistence/craft) string[] modeArray = resourceNames.Split('|'); @@ -512,6 +517,10 @@ private float getDryCost(float fullCost) cost -= def.unitCost * (float)res.maxAmount; } + if (solarSwitchModule) + { + cost += solarSwitchModule.GetModuleCost(0, ModifierStagingSituation.CURRENT); + } return cost; } @@ -530,8 +539,15 @@ private float updateWeight(Part currentPart) float newMass = mass + meshMass; + if (solarSwitchModule!=null) + { + newMass += solarSwitchModule.GetModuleMass(0, ModifierStagingSituation.CURRENT); + } + + dryMassInfo = currentPart.partInfo.partPrefab.mass + newMass; + return newMass; } diff --git a/USSourceDev/UniversalStorage/SwitchModules/USMassSwitch.cs b/USSourceDev/UniversalStorage/SwitchModules/USMassSwitch.cs index e86fa7d..e53e862 100644 --- a/USSourceDev/UniversalStorage/SwitchModules/USMassSwitch.cs +++ b/USSourceDev/UniversalStorage/SwitchModules/USMassSwitch.cs @@ -22,6 +22,7 @@ public class USMassSwitch : USBaseSwitch, IPartMassModifier private bool _updateMass = true; private string _localizedDryMassString = "Part Mass"; + private USSolarSwitch solarSwitchModule = null; public override void OnAwake() { @@ -45,8 +46,9 @@ public override void OnStart(StartState state) return; _Masses = USTools.parseDoubles(AddedMass).ToArray(); - - Fields["DryMassInfo"].guiActiveEditor = DisplayCurrentModeMass; + + Fields["DryMassInfo"].guiActiveEditor = DisplayCurrentModeMass; + solarSwitchModule = part.FindModuleImplementing(); } private void OnDestroy() @@ -103,6 +105,10 @@ private void onFuelSwitchRequest(int index, Part p, USFuelSwitch fuel) mass = (float)_Masses[CurrentSelection]; fuel.setMeshMass(mass); + + DryMassInfo = DryMassInfo = part.partInfo.cost + mass; + UpdateSolarMass(); + } private float UpdateWeight(Part currentPart) @@ -116,13 +122,24 @@ private float UpdateWeight(Part currentPart) return mass; } - + + private void UpdateSolarMass() + { + if (solarSwitchModule != null) + { + DryMassInfo += solarSwitchModule.GetModuleMass(0, ModifierStagingSituation.CURRENT); + USdebugMessages.USStaticLog("USCostSwitch.GetModuleMass, solarSwitchModuleCost: " + solarSwitchModule.GetModuleCost(0, ModifierStagingSituation.CURRENT)); + } + } + public float GetModuleMass(float defaultMass, ModifierStagingSituation sit) { if (!_updateMass) return 0; - return UpdateWeight(part); + var m = UpdateWeight(part); + UpdateSolarMass(); + return m; } public ModifierChangeWhen GetModuleMassChangeWhen() diff --git a/USSourceDev/UniversalStorage/SwitchModules/USSolarSwitch.cs b/USSourceDev/UniversalStorage/SwitchModules/USSolarSwitch.cs index 4326bf9..f51aba5 100644 --- a/USSourceDev/UniversalStorage/SwitchModules/USSolarSwitch.cs +++ b/USSourceDev/UniversalStorage/SwitchModules/USSolarSwitch.cs @@ -4,12 +4,16 @@ namespace UniversalStorage2 { - public class USSolarSwitch : USBaseSwitch, IPartCostModifier + public class USSolarSwitch : USBaseSwitch, IPartCostModifier, IPartMassModifier { [KSPField] public string AddedCost = string.Empty; + [KSPField] + public string AddedPanelMass = string.Empty; + [KSPField] public bool DisplayCurrentModeCost = false; + [KSPField(guiActive = false, guiActiveEditor = false, guiName = "#autoLOC_US_SolarPanelCostField")] public float AddedCostValue = 0f; [KSPField] @@ -26,6 +30,14 @@ public class USSolarSwitch : USBaseSwitch, IPartCostModifier public float SunExposure; [KSPField(guiUnits = " ", guiFormat = "F3", guiActive = true, guiActiveEditor = false, guiName = "#autoLOC_6001421")] public float EnergyFlow; + + + [KSPField(guiUnits = " ", guiFormat = "F0", guiActive = false, guiActiveEditor = false, guiName = "Solar Cell Cost")] + public float SolarCellCost = 0; + [KSPField(guiUnits = " ", guiFormat = "F3", guiActive = false, guiActiveEditor = false, guiName = "Solar Cell Mass")] + public float SolarCellMass = 0; + + [KSPField(isPersistant = true)] public int CurrentSelection = 0; [KSPField(isPersistant = true)] @@ -40,6 +52,8 @@ public class USSolarSwitch : USBaseSwitch, IPartCostModifier [KSPField] public bool SolarPanelsLocked = false; + private double[] _PanelMasses; + private Shader _DebugLineShader; private Transform[] _sunCatchers; @@ -77,6 +91,10 @@ public class USSolarSwitch : USBaseSwitch, IPartCostModifier private string _localizedRetractedString = "Retracted"; private string _localizedUnavailableString = "Unavailable"; + private EventData onFuelRequestMass; + private EventData onFuelRequestCost; + private USFuelSwitch usFuelSwitch; + private bool _started; public void DeploySolarPanels(bool isOn) @@ -96,7 +114,20 @@ public void DeploySolarPanels(bool isOn) public override void OnStart(StartState state) { base.OnStart(state); + if (String.IsNullOrEmpty(SwitchID)) + return; + + _SwitchIndices = USTools.parseIntegers(SwitchID).ToArray(); + + _PanelMasses = USTools.parseDoubles(AddedPanelMass).ToArray(); + if (_PanelMasses != null && _PanelMasses.Length > 0) + { + string m = ""; + for (int i = 0; i < _PanelMasses.Length; i++) + m += _PanelMasses[i].ToString() + ", "; + USdebugMessages.USStaticLog("USSolarSwitch.OnStart, _PanelMasses: " + m); + } _localizedSunlightString = Localizer.Format("#autoLOC_235418"); _localizedUnderwaterString = Localizer.Format("#autoLOC_235468"); _localizedActiveString = Localizer.Format("#autoLOC_900336"); @@ -143,6 +174,11 @@ public override void OnStart(StartState state) SolarPanels = IsActive ? _localizedActiveString : _localizedInactiveString; else SolarPanels = (IsDeployed || IsFixed)? "" : _localizedRetractedString; + + onFuelRequestCost = GameEvents.FindEvent>("onFuelRequestCost"); + onFuelRequestMass = GameEvents.FindEvent>("onFuelRequestMass"); + usFuelSwitch = this.part.FindModuleImplementing(); + } public override void OnStartFinished(StartState state) @@ -195,6 +231,9 @@ private void toggleSolarPanels() IsActive = !IsActive; + Fields["SolarCellCost"].guiActiveEditor = IsActive; + Fields["SolarCellMass"].guiActiveEditor = IsActive; + if (_solarMeshes != null) { for (int i = _solarMeshes.Length - 1; i >= 0; i--) @@ -212,6 +251,13 @@ private void toggleSolarPanels() SolarPanels = IsActive ? _localizedActiveString : _localizedInactiveString; GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); + + if (onFuelRequestCost != null) + onFuelRequestCost.Fire(0, part, usFuelSwitch); + + if (onFuelRequestMass != null) + onFuelRequestMass.Fire(0, part, usFuelSwitch); + } private void Update() @@ -502,6 +548,7 @@ private void DrawDebugLines(Transform[] sources, float length, Color c) public float GetModuleCost(float defaultCost, ModifierStagingSituation sit) { + SolarCellCost = 0; if (SolarPanelsLocked || !IsActive) return 0; @@ -511,7 +558,7 @@ public float GetModuleCost(float defaultCost, ModifierStagingSituation sit) cost = _Costs[CurrentSelection]; AddedCostValue = cost; - + SolarCellCost = cost; return cost; } @@ -519,5 +566,25 @@ public ModifierChangeWhen GetModuleCostChangeWhen() { return ModifierChangeWhen.CONSTANTLY; } + + public ModifierChangeWhen GetModuleMassChangeWhen() + { + return ModifierChangeWhen.CONSTANTLY; + } + + public float GetModuleMass(float defaultMass, ModifierStagingSituation sit) + { + //USdebugMessages.USStaticLog("USSolarSwitch.GetModuleMass, IsActive: " + IsActive + ", CurrentSelection: " + CurrentSelection); + SolarCellMass = 0; + if (!IsActive) + { + return 0; + } + + if (_PanelMasses != null && _PanelMasses.Length >= CurrentSelection) + SolarCellMass = (float)_PanelMasses[CurrentSelection]; + USdebugMessages.USStaticLog("USSolarSwitch.GetModuleMass, SolarCellMass: " + SolarCellMass); + return SolarCellMass; + } } } diff --git a/USSourceDev/UniversalStorage/Utilities/USTools.cs b/USSourceDev/UniversalStorage/Utilities/USTools.cs index 2dab2a0..84850e2 100644 --- a/USSourceDev/UniversalStorage/Utilities/USTools.cs +++ b/USSourceDev/UniversalStorage/Utilities/USTools.cs @@ -43,6 +43,8 @@ public static List parseIntegers(string stringOfInts, char sep = ';') public static List parseDoubles(string stringOfDoubles, char sep = ';') { + if (stringOfDoubles == "") + return null; List list = new List(); string[] array = stringOfDoubles.Trim().Split(sep); for (int i = 0; i < array.Length; i++) diff --git a/UniversalStorage2.version b/UniversalStorage2.version index b8c911f..fd975e0 100644 --- a/UniversalStorage2.version +++ b/UniversalStorage2.version @@ -7,7 +7,7 @@ "MAJOR": 4, "MINOR": 0, "PATCH": 0, - "BUILD": 6 + "BUILD": 7 }, "KSP_VERSION": { "MAJOR": 1,