diff --git a/CKAN/SystemHeat.netkan b/CKAN/SystemHeat.netkan new file mode 100644 index 0000000..5fb17b7 --- /dev/null +++ b/CKAN/SystemHeat.netkan @@ -0,0 +1,27 @@ +{ + "spec_version": "v1.4", + "identifier": "SystemHeat", + "name": "System Heat", + "$kref": "#/ckan/github/post-kerbin-mining-corporation/SystemHeat", + "$vref": "#/ckan/ksp-avc", + "abstract": "System Heat revamps the Core Heat system used in stock KSP to drive drills and harvesters with a new, more powerful system. This core package does not make changes to the base game - install other SystemHeat packs to change drill, converters and the like to use Systemheat", + "author": "Chris Adderley (Nertea)", + "license": "CC-BY-NC-SA-4", + "resources": { + "homepage": "https://forum.kerbalspaceprogram.com/index.php?/topic/193909", + "repository": "https://github.com/post-kerbin-mining-corporation/SystemHeat" + }, + "depends": [ + { "name": "ModuleManager" } + ], + "suggests": [ + { "name": "SystemHeatConverters" }, + { "name": "SystemHeatFissionReactors" }, + { "name": "SystemHeatFissionEngines" }, + { "name": "SystemHeatHarvesters" } + ], + "install": [ { + "find": "SystemHeat", + "install_to": "GameData" + } ] +} diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-1.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-1.cfg index 1e8f777..a61f5ae 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-1.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-1.cfg @@ -89,4 +89,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-2.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-2.cfg index d87c2ab..efd6548 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-2.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-2.cfg @@ -89,4 +89,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-3.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-3.cfg index 5ac61f1..37d99cb 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-3.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-gc-25-3.cfg @@ -89,4 +89,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-0625-1.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-0625-1.cfg index 917961a..e8e0613 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-0625-1.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-0625-1.cfg @@ -90,4 +90,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-1.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-1.cfg index 7c157b5..b0e73d2 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-1.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-1.cfg @@ -90,4 +90,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-2.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-2.cfg index 2cceebc..4a37aa0 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-2.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-125-2.cfg @@ -86,4 +86,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-25-1.cfg b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-25-1.cfg index acac6c6..4499caa 100644 --- a/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-25-1.cfg +++ b/Extras/SystemHeatFissionEngines/KerbalAtomics/ntr-sc-25-1.cfg @@ -91,4 +91,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionEngines/Squad/nuclearEngine.cfg b/Extras/SystemHeatFissionEngines/Squad/nuclearEngine.cfg index 9445c6d..149ae06 100644 --- a/Extras/SystemHeatFissionEngines/Squad/nuclearEngine.cfg +++ b/Extras/SystemHeatFissionEngines/Squad/nuclearEngine.cfg @@ -77,4 +77,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalNuclearContainers.cfg b/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalNuclearContainers.cfg new file mode 100644 index 0000000..7c55af7 --- /dev/null +++ b/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalNuclearContainers.cfg @@ -0,0 +1,34 @@ + + +@PART[nuclearfuel-0625] +{ + !MODULE[RadioactiveStorageContainer] {} + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + wasteModuleID = wasteColor + fuelModuleID = fuelColor + } +} + +@PART[nuclearfuel-125] +{ + !MODULE[RadioactiveStorageContainer] {} + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + wasteModuleID = wasteColor + fuelModuleID = fuelColor + } +} + +@PART[nuclearfuel-25] +{ + !MODULE[RadioactiveStorageContainer] {} + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + wasteModuleID = wasteColor + fuelModuleID = fuelColor + } +} \ No newline at end of file diff --git a/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalReactors.cfg b/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalReactors.cfg index 4919bc0..7b9329a 100644 --- a/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalReactors.cfg +++ b/Extras/SystemHeatFissionReactors/NearFutureElectrical/NearFutureElectricalReactors.cfg @@ -16,8 +16,7 @@ !MODULE[FissionReactor] {} !MODULE[FissionGenerator] {} !MODULE[ModuleCoreHeatNoCatchup] {} - - + !MODULE[RadioactiveStorageContainer] {} MODULE { name = ModuleSystemHeatFissionReactor @@ -36,9 +35,12 @@ // %/s/K, so with value 0.001, at 200 K over CriticalTemp, reactor takes 0.2% damage/s CoreDamageRate = 0.008 + // When repairing, amount of core damage to heal (%) + RepairAmountPerKit = 25 + CurrentPowerPercent = 100 ThrottleIncreaseRate = 1 - MinimumThrottle = 25 + MinimumThrottle = 25 // -- Electrical stuff // Power generated @@ -66,6 +68,11 @@ FlowMode = NO_FLOW } } + + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } @@ -105,6 +112,9 @@ // %/s/K, so with value 0.001, at 200 K over CriticalTemp, reactor takes 0.2% damage/s CoreDamageRate = 0.008 + // When repairing, amount of core damage to heal (%) + RepairAmountPerKit = 20 + CurrentPowerPercent = 100 ThrottleIncreaseRate = 1 MinimumThrottle = 25 @@ -137,6 +147,10 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } @@ -176,6 +190,9 @@ // %/s/K, so with value 0.001, at 200 K over CriticalTemp, reactor takes 0.2% damage/s CoreDamageRate = 0.007 + // When repairing, amount of core damage to heal (%) + RepairAmountPerKit = 15 + CurrentPowerPercent = 100 ThrottleIncreaseRate = 1 MinimumThrottle = 25 @@ -208,6 +225,10 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } // 2.5m reactor @@ -246,6 +267,9 @@ // %/s/K, so with value 0.001, at 200 K over CriticalTemp, reactor takes 0.2% damage/s CoreDamageRate = 0.006 + // When repairing, amount of core damage to heal (%) + RepairAmountPerKit = 15 + CurrentPowerPercent = 100 ThrottleIncreaseRate = 1 MinimumThrottle = 25 @@ -279,6 +303,10 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } // 3.75m reactor short @@ -317,6 +345,9 @@ // %/s/K, so with value 0.001, at 200 K over CriticalTemp, reactor takes 0.2% damage/s CoreDamageRate = 0.004 + // When repairing, amount of core damage to heal (%) + RepairAmountPerKit = 10 + CurrentPowerPercent = 100 ThrottleIncreaseRate = 1 MinimumThrottle = 25 @@ -347,6 +378,10 @@ FlowMode = NO_FLOW } } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } // 3.75m reactor @@ -385,6 +420,9 @@ // %/s/K, so with value 0.001, at 200 K over CriticalTemp, reactor takes 0.2% damage/s CoreDamageRate = 0.004 + // When repairing, amount of core damage to heal (%) + RepairAmountPerKit = 10 + CurrentPowerPercent = 100 ThrottleIncreaseRate = 1 MinimumThrottle = 25 @@ -417,4 +455,8 @@ } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/Extras/SystemHeatFissionReactors/NearFutureElectrical/PlanetaryBaseIncReactor.cfg b/Extras/SystemHeatFissionReactors/NearFutureElectrical/PlanetaryBaseIncReactor.cfg index dbd7872..d5edce5 100644 --- a/Extras/SystemHeatFissionReactors/NearFutureElectrical/PlanetaryBaseIncReactor.cfg +++ b/Extras/SystemHeatFissionReactors/NearFutureElectrical/PlanetaryBaseIncReactor.cfg @@ -64,4 +64,8 @@ FlowMode = NO_FLOW } } + MODULE + { + name = ModuleSystemHeatFissionFuelContainer + } } \ No newline at end of file diff --git a/GameData/SystemHeat/Assets/systemheat-nuclear-container-1-e.dds b/GameData/SystemHeat/Assets/systemheat-nuclear-container-1-e.dds new file mode 100644 index 0000000..24972d0 Binary files /dev/null and b/GameData/SystemHeat/Assets/systemheat-nuclear-container-1-e.dds differ diff --git a/GameData/SystemHeat/Assets/systemheat-nuclear-container-1-n.dds b/GameData/SystemHeat/Assets/systemheat-nuclear-container-1-n.dds new file mode 100644 index 0000000..3a44899 Binary files /dev/null and b/GameData/SystemHeat/Assets/systemheat-nuclear-container-1-n.dds differ diff --git a/GameData/SystemHeat/Assets/systemheat-nuclear-container-1.dds b/GameData/SystemHeat/Assets/systemheat-nuclear-container-1.dds new file mode 100644 index 0000000..fb87d1b Binary files /dev/null and b/GameData/SystemHeat/Assets/systemheat-nuclear-container-1.dds differ diff --git a/GameData/SystemHeat/Assets/systemheat-nuclear-container.mu b/GameData/SystemHeat/Assets/systemheat-nuclear-container.mu new file mode 100644 index 0000000..c08242c Binary files /dev/null and b/GameData/SystemHeat/Assets/systemheat-nuclear-container.mu differ diff --git a/GameData/SystemHeat/Localization/en-us.cfg b/GameData/SystemHeat/Localization/en-us.cfg index 72dd522..913ff0a 100644 --- a/GameData/SystemHeat/Localization/en-us.cfg +++ b/GameData/SystemHeat/Localization/en-us.cfg @@ -114,10 +114,11 @@ Localization #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_RepairReactor = Repair Reactor #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_RepairSuccess = Reactor repaired to <<1>>%! - #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreTooDamaged = Reactor core is too damaged to repair + #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreTooDamaged = Reactor is too damaged to repair #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreAlreadyRepaired = Reactor core is already at maximum field repairable integrity (<<1>>%) #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_EngineerLevelTooLow = Reactor core repair requires a Level <<1>> Engineer - #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_NotWhileRunning = Cannot repair core when running! + #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_NoKits = Reactor repair requires an EVA Repair Kit. + #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_NotWhileRunning = Cannot repair reactor when running! #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreTooHot = The reactor must be below <<1>> K to initiate repair! #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Field_CurrentSafetyOverride = Auto-Shutdown Temp @@ -149,6 +150,28 @@ Localization #LOC_SystemHeat_ModuleSystemHeatFissionEngine_PartInfo_NoPower = Generates thrust through nuclear fission. \n\nResponse Speed: <<7>>%/s\nMinimum Power: <<8>>%\nCore Life: <<1>>\n\nThermal Parameters:\n - Heat Output: <<2>> kW\n - Outlet Temperature: <<3>> K\n - Optimal Temp.: <<>> K \n - Damage Temp.: <<5>> K\n - Meltdown Temp.: <<6>> K #LOC_SystemHeat_ModuleSystemHeatFissionReactor_Action_TogglePanelAction = Toggle Reactor Panel + /// ModuleSystemHeatFissionFuelContainer + /// ================================= + + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_PartInfo = Allows EVA kerbals to collect and store nuclear fuel and waste + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_ModuleName = Nuclear Fuel Container + + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Field_Collect_Name = Collect <<1>> + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Field_Store_Name = Store <<1>> + + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_NoFuelContainer = A Nuclear Fuel Container must be equipped. + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortEngineerLevel = This transfer a Level <<1>> Engineer! + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortFromRunningConverter = Cannot transfer from a running converter! + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortToRunningConverter = Cannot transfer into a running converter! + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortFromRunningReactor = Cannot transfer from a running reactor! Seriously a bad idea! + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortToRunningReactor = Cannot transfer into a running reactor! Seriously a bad idea! + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortTooHot = This part must be below <<1>> K to transfer! + + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_Collected = Collected <<1>> <<2>> from <<3>> + #LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_Stored = Stored <<1>> <<2>> in <<3>> + + + /// ModuleSystemHeatSink /// ================================= #LOC_SystemHeat_ModuleSystemHeatSink_UIGroup_Title = Heat Sink @@ -225,5 +248,11 @@ Localization #LOC_SystemHeat_systemheat-sink-1_title = PSK-200 Heat Sink #LOC_SystemHeat_systemheat-sink-1_description = This is a hefty, heavy tank of some sciencey-sounding material that can absorb a fair bit of thermal energy before getting saturated. Useful if you really need somewhere to store some heat for a while. #LOC_SystemHeat_systemheat-sink-1_tags = systemheat + + // CARGO + // --------------- + #LOC_SystemHeat_systemheat-nuclear-container-1_title = Nuclear Fuel Cylinder + #LOC_SystemHeat_systemheat-nuclear-container-1_description = EVA part to allow Kerbals to collect nuclear materials and transfer them betwen relevant parts. + #LOC_SystemHeat_systemheat-nuclear-container-1_tags = cargo fix refuel fuel transfer nuclear waste uranium } } \ No newline at end of file diff --git a/GameData/SystemHeat/Parts/@thumbs/systemheat-nuclear-container-1_icon.png b/GameData/SystemHeat/Parts/@thumbs/systemheat-nuclear-container-1_icon.png new file mode 100644 index 0000000..f042d32 Binary files /dev/null and b/GameData/SystemHeat/Parts/@thumbs/systemheat-nuclear-container-1_icon.png differ diff --git a/GameData/SystemHeat/Parts/systemheat-nuclear-container-1.cfg b/GameData/SystemHeat/Parts/systemheat-nuclear-container-1.cfg new file mode 100644 index 0000000..ed14f31 --- /dev/null +++ b/GameData/SystemHeat/Parts/systemheat-nuclear-container-1.cfg @@ -0,0 +1,72 @@ + +PART +{ + name = systemheat-nuclear-container-1 + module = Part + author = Chris Adderley (Nertea) + MODEL + { + model= SystemHeat/Assets/systemheat-nuclear-container + } + rescaleFactor = 1 + + + TechRequired = nuclearPropulsion + entryCost = 1500 + cost = 75 + category = Cargo + subcategory = 0 + title = #LOC_SystemHeat_systemheat-nuclear-container-1_title + manufacturer = #LOC_SystemHeat_manufacturer_pkmc_title + description = #LOC_SystemHeat_systemheat-nuclear-container-1_description + attachRules = 0,0,0,0,0 + mass = 0.005 + dragModelType = default + maximum_drag = 0.1 + minimum_drag = 0.1 + angularDrag = 2 + crashTolerance = 12 + maxTemp = 1200 // = 1200 + tags = #LOC_SystemHeat_systemheat-nuclear-container-1_tags + EFFECTS + { + repair1 + { + AUDIO + { + channel = Ship + clip = Squad/Sounds/repairKit_repair1.wav + maxVolumeDistance = 150 + } + } + repair2 + { + AUDIO + { + channel = Ship + clip = Squad/Sounds/repairKit_repair2.wav + maxVolumeDistance = 150 + } + } + } + MODULE + { + name = ModuleCargoPart + stackableQuantity = 1 + packedVolume = 20 + } + RESOURCE + { + name = EnrichedUranium + amount = 0 + maxAmount = 15 + isTweakable = False + } + RESOURCE + { + name = DepletedFuel + amount = 0 + maxAmount = 15 + isTweakable = False + } +} diff --git a/GameData/SystemHeat/Plugin/SystemHeat.dll b/GameData/SystemHeat/Plugin/SystemHeat.dll index 0a3559b..c4b1ba2 100644 Binary files a/GameData/SystemHeat/Plugin/SystemHeat.dll and b/GameData/SystemHeat/Plugin/SystemHeat.dll differ diff --git a/GameData/SystemHeat/Versioning/SystemHeat.version b/GameData/SystemHeat/Versioning/SystemHeat.version index ac33d23..8fb9365 100644 --- a/GameData/SystemHeat/Versioning/SystemHeat.version +++ b/GameData/SystemHeat/Versioning/SystemHeat.version @@ -5,24 +5,24 @@ "VERSION": { "MAJOR":0, - "MINOR":2, - "PATCH":3, + "MINOR":3, + "PATCH":0, "BUILD":0 }, "KSP_VERSION": { "MAJOR":1, - "MINOR":10, - "PATCH":1 + "MINOR":11, + "PATCH":0 }, "KSP_VERSION_MIN":{ "MAJOR":1, - "MINOR":8, + "MINOR":11, "PATCH":1 }, "KSP_VERSION_MAX":{ "MAJOR":1, - "MINOR":10, + "MINOR":11, "PATCH":99 } } diff --git a/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionFuelHandler.cs b/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionFuelHandler.cs new file mode 100644 index 0000000..6ab490f --- /dev/null +++ b/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionFuelHandler.cs @@ -0,0 +1,345 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using KSP.Localization; + +namespace SystemHeat.Modules +{ + public class ModuleSystemHeatFissionFuelContainer: PartModule + { + + // Fuel that is dangerous to transfer + [KSPField(isPersistant = false)] + public string WasteResourceName = "DepletedFuel"; + + // Fuel that is safe to transfer + [KSPField(isPersistant = false)] + public string FuelResourceName = "EnrichedUranium"; + + [KSPField(isPersistant = false)] + public string RefuelCargoPartName = "systemheat-nuclear-container-1"; + + [KSPField(isPersistant = false)] + public float MaxTemperatureForRefuel = 330; + + [KSPField(isPersistant = false)] + public int EngineerLevelForRefuel = 3; + + // Color Changer for waste + [KSPField(isPersistant = false)] + public string wasteModuleID; + + // Color Changer for waste + [KSPField(isPersistant = false)] + public string fuelModuleID; + + [KSPEvent(externalToEVAOnly = true, guiActiveUnfocused = true, unfocusedRange = 3.5f, guiName = "Store Fuel")] + public void StoreFuel() + { + if (CheckEVARequirements() && CheckPartRequirements()) + { + TransferResourceFromEVA(FuelResourceName); + } + } + [KSPEvent(externalToEVAOnly = true, guiActiveUnfocused = true, unfocusedRange = 3.5f, guiName = "Store Waste")] + public void StoreWaste() + { + if (CheckEVARequirements() && CheckPartRequirements()) + { + TransferResourceFromEVA(WasteResourceName); + } + } + + [KSPEvent(externalToEVAOnly = true, guiActiveUnfocused = true, unfocusedRange = 3.5f, guiName = "Collect Fuel")] + public void CollectFuel() + { + if (CheckEVARequirements() && CheckPartRequirements()) + { + TransferResourceToEVA(FuelResourceName); + } + } + [KSPEvent(externalToEVAOnly = true, guiActiveUnfocused = true, unfocusedRange = 3.5f, guiName = "Collect Waste")] + public void CollectWaste() + { + if (CheckEVARequirements() && CheckPartRequirements()) + { + TransferResourceToEVA(WasteResourceName); + } + } + + private ModuleColorChanger wasteColorChanger; + private ModuleColorChanger fuelColorChanger; + + public override string GetInfo() + { + return Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_PartInfo"); + } + public override string GetModuleDisplayName() + { + return Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_ModuleName"); + } + + public void Start() + { + Events["StoreWaste"].guiName = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Field_Store_Name", WasteResourceName) ; + Events["StoreFuel"].guiName = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Field_Store_Name", FuelResourceName); + Events["CollectWaste"].guiName = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Field_Collect_Name", WasteResourceName); + Events["CollectFuel"].guiName = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Field_Collect_Name", FuelResourceName); + + + if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor) + { + if (fuelModuleID != "") + { + fuelColorChanger = this.GetComponents().ToList().Find(i => i.moduleID == fuelModuleID); + } + if (wasteModuleID != "") + { + wasteColorChanger = this.GetComponents().ToList().Find(i => i.moduleID == wasteModuleID); + } + } + } + + private void FixedUpdate() + { + if (HighLogic.LoadedSceneIsFlight) + { + + if (FlightGlobals.ActiveVessel.evaController != null) + { + if (FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.TotalAmountOfPartStored(RefuelCargoPartName) >= 1) + { + if (GetResourceAmount(WasteResourceName) <= 0d) + { + Events["CollectWaste"].active = false; + } + else + { + Events["CollectWaste"].active = true; + } + if (GetResourceAmount(FuelResourceName) <= 0d) + { + Events["CollectFuel"].active = false; + } + else + { + Events["CollectFuel"].active = true; + } + + if (GetResourceEVAAmount(WasteResourceName) <= 0d) + { + Events["StoreWaste"].active = false; + } + else + { + Events["StoreWaste"].active = true; + } + if (GetResourceEVAAmount(FuelResourceName) <= 0d) + { + Events["StoreFuel"].active = false; + } + else + { + Events["StoreFuel"].active = true; + } + } + else + { + Events["CollectWaste"].active = false; + Events["CollectFuel"].active = false; + Events["StoreFuel"].active = false; + Events["StoreWaste"].active = false; + } + } + } + if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor) + { + if (fuelColorChanger) + { + fuelColorChanger.SetScalar((float)(GetResourceAmount(FuelResourceName, false) / GetResourceAmount(FuelResourceName, true))); + } + if (wasteColorChanger) + { + wasteColorChanger.SetScalar((float)(GetResourceAmount(WasteResourceName, false) / GetResourceAmount(WasteResourceName, true))); + } + } + + } + + protected double GetResourceEVAAmount(string resourceName) + { + + double amt = 0d; + if (FlightGlobals.ActiveVessel.evaController != null) + { + for (int i = 0; i < FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.InventorySlots; i++) + { + if (!FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.IsSlotEmpty(i)) + { + StoredPart sPart = FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.storedParts[i]; + if (sPart.partName == RefuelCargoPartName) + { + ProtoPartResourceSnapshot res = sPart.snapshot.resources.Find(x => x.resourceName == resourceName); + amt += res.amount; + } + } + } + } + return amt; + } + protected void TransferResourceToEVA(string resourceName) + { + double availableResource = GetResourceAmount(resourceName, true); + double toRemove = 0d; + for (int i = 0; i < FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.InventorySlots; i++) + { + if (availableResource > 0d) + { + if (!FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.IsSlotEmpty(i)) + { + StoredPart sPart = FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.storedParts[i]; + if (sPart.partName == RefuelCargoPartName) + { + ProtoPartResourceSnapshot res = sPart.snapshot.resources.Find(x => x.resourceName == resourceName); + double availableSpace = res.maxAmount - res.amount; + double addable = UtilMath.Min(availableSpace, availableResource); + toRemove += addable; + + Utils.Log($"Added {addable} {resourceName} to {sPart.partName} ({availableResource} units in source, {availableSpace} space in stored part)"); + + availableResource = UtilMath.Clamp(availableResource - addable, 0, availableResource); + res.amount = UtilMath.Clamp(res.amount + addable, 0d, res.maxAmount); + } + } + } + } + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_Collected", + toRemove.ToString("F2"), + resourceName, + part.partInfo.title + ), 5.0f, ScreenMessageStyle.UPPER_CENTER));; + Utils.Log($"Removed {toRemove} {resourceName} from {part.partInfo.title}"); + part.RequestResource(resourceName, toRemove, ResourceFlowMode.NO_FLOW); + } + + protected void TransferResourceFromEVA(string resourceName) + { + double availableSpace = GetResourceAmount(resourceName, true); + double toAdd = 0d; + for (int i=0;i< FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.InventorySlots; i++) + { + if (availableSpace > 0d) + { + if (!FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.IsSlotEmpty(i)) + { + StoredPart sPart = FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.storedParts[i]; + if (sPart.partName == RefuelCargoPartName) + { + ProtoPartResourceSnapshot res = sPart.snapshot.resources.Find(x => x.resourceName == resourceName); + double availableResource = res.amount; + double addable = UtilMath.Min(availableSpace, availableResource); + toAdd += addable; + + Utils.Log($"Removed {addable} {resourceName} from {sPart.partName} ({availableResource} units in part, {availableSpace} space in target)"); + + availableSpace = UtilMath.Clamp(availableSpace - addable, 0, availableSpace); + res.amount = UtilMath.Clamp(res.amount - addable, 0d, res.maxAmount); + } + } + } + } + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_Stored", + toAdd.ToString("F2"), + resourceName, + part.partInfo.title + ), 5.0f, ScreenMessageStyle.UPPER_CENTER)); ; + Utils.Log($"Added {toAdd} {resourceName} to {part.partInfo.title}"); + part.RequestResource(resourceName, -toAdd, ResourceFlowMode.NO_FLOW); + } + /// + /// Test to see if the EVA kerbal can transfer resources + /// + /// + protected bool CheckEVARequirements() + { + if (FlightGlobals.ActiveVessel.VesselValues.RepairSkill.value < EngineerLevelForRefuel) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortEngineerLevel", EngineerLevelForRefuel.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + if (FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.TotalAmountOfPartStored(RefuelCargoPartName) < 1) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_NoFuelContainer"), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + return true; + } + + /// + /// Test to see if this part can transfter resources + /// + /// + /// + protected bool CheckPartRequirements() + { + // Some modules need to be off. + ModuleSystemHeat heat = GetComponent(); + ModuleSystemHeatConverter[] converters = GetComponents(); + ModuleSystemHeatFissionReactor reactor = GetComponent(); + ModuleSystemHeatFissionEngine engine = GetComponent(); + + // Fail if a converter is on + foreach (ModuleSystemHeatConverter converter in converters) + { + if (converter != null && converter.ModuleIsActive()) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortFromRunningConverter"), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + } + // Fail if a reactor is on + if (reactor != null && reactor.Enabled) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortFromRunningReactor"), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + //Fail if an nuclear engine is on + if (engine != null && engine.Enabled) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortFromRunningReactor"), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + + // Fail if the part is too hot + if (heat != null && heat.LoopTemperature > MaxTemperatureForRefuel) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_AbortTooHot", MaxTemperatureForRefuel.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + + return true; + } + + // Helpbers for getting a resource amount + public double GetResourceAmount(string nm) + { + if (this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id) != null) + return this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id).amount; + else + return 0.0; + } + public double GetResourceAmount(string nm, bool max) + { + if (max) + if (this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id) != null) + return this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id).maxAmount; + else + return 0.0; + + else + return GetResourceAmount(nm); + } + } +} diff --git a/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs b/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs index f0dc447..963726b 100644 --- a/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs +++ b/SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs @@ -98,7 +98,7 @@ public class ModuleSystemHeatFissionReactor : PartModule // REPAIR VARIABLES // integrity of the core [KSPField(isPersistant = true)] - public float CoreIntegrity = 100f; + public float CoreIntegrity = 50f; // Rate the core is damaged, in % per S per K [KSPField(isPersistant = false)] @@ -108,6 +108,10 @@ public class ModuleSystemHeatFissionReactor : PartModule [KSPField(isPersistant = false)] public int EngineerLevelForRepair = 5; + + [KSPField(isPersistant = false)] + public float RepairAmountPerKit = 25; + [KSPField(isPersistant = false)] public float MaxRepairPercent = 75; @@ -573,14 +577,20 @@ private void HandleResourceActivities(float timeStep) #region Repair public bool TryRepairReactor() { + if (CoreIntegrity <= MinRepairPercent) { ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreTooDamaged"), 5.0f, ScreenMessageStyle.UPPER_CENTER)); return false; } - if (!ModuleUtils.CheckEVAEngineerLevel(EngineerLevelForRepair)) + if (FlightGlobals.ActiveVessel.VesselValues.RepairSkill.value < EngineerLevelForRepair) + { + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_EngineerLevelTooLow", EngineerLevelForRepair.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + return false; + } + if (FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.TotalAmountOfPartStored("evaRepairKit") < 1) { - ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreTooDamaged", EngineerLevelForRepair.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_NoKits"), 5.0f, ScreenMessageStyle.UPPER_CENTER)); return false; } if (Enabled) @@ -594,21 +604,24 @@ public bool TryRepairReactor() ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreTooHot", MaxTempForRepair.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); return false; } - if (CoreIntegrity >= MaxRepairPercent) - { - ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreAlreadyRepaired", MaxRepairPercent.ToString("F0")), - 5.0f, ScreenMessageStyle.UPPER_CENTER)); - return false; - } + + //if (CoreIntegrity >= MaxRepairPercent) + //{ + // ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_CoreAlreadyRepaired", MaxRepairPercent.ToString("F0")), + // 5.0f, ScreenMessageStyle.UPPER_CENTER)); + // return false; + //} return true; } // Repair the reactor to max Repair percent public void DoReactorRepair() { - this.CoreIntegrity = MaxRepairPercent; + FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.RemoveNPartsFromInventory("evaRepairKit", 1, playSound: true); + + this.CoreIntegrity = Mathf.Clamp(this.CoreIntegrity + RepairAmountPerKit, 0f, 100f); ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Message_Repair_RepairSuccess", - MaxRepairPercent.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); + this.CoreIntegrity.ToString("F0")), 5.0f, ScreenMessageStyle.UPPER_CENTER)); } #endregion diff --git a/SystemHeat/SystemHeat/SystemHeat.csproj b/SystemHeat/SystemHeat/SystemHeat.csproj index cb80308..3a91eb1 100644 --- a/SystemHeat/SystemHeat/SystemHeat.csproj +++ b/SystemHeat/SystemHeat/SystemHeat.csproj @@ -87,6 +87,7 @@ + diff --git a/changelog.txt b/changelog.txt index fb3e689..7ddab31 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +v0.3.0 +------ +- Pushed to KSP 1.11 +- Improved Repair feature for fission reactors: now requires EVA repair kits. More kits needed for larger reactors +- Improved Refuel feature for fission reactors: now needs Kerbals to equip the Nuclear Fuel Container EVA part, and for them to collect fuel from containers to store in reactors +- Added Nuclear fuel container cargo part for working with fission engines/reactors + v0.2.3 ------ - Updates to Chinese localization (TerrestrisYE) diff --git a/readme.txt b/readme.txt index a8998a2..eea308b 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ ================ -SystemHeat 0.2.3 +SystemHeat 0.3.0 ================ TBW