diff --git a/UPFM/Untitled Part Failure Mod/BaseFailureModule.cs b/UPFM/Untitled Part Failure Mod/BaseFailureModule.cs index 82da771..bd7cf41 100644 --- a/UPFM/Untitled Part Failure Mod/BaseFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/BaseFailureModule.cs @@ -9,29 +9,39 @@ namespace Untitled_Part_Failure_Mod class BaseFailureModule : PartModule { UnityEngine.Random r = new UnityEngine.Random(); - [KSPField(isPersistant = true, guiActive = false)] public bool willFail = false; [KSPField(isPersistant = true, guiActive = false)] public bool hasFailed = false; public float expectedLifetime = 2; ModuleSYPartTracker SYP; - float chanceOfFailure = 0.5f; - [KSPField(isPersistant = true, guiActive = true, guiName = "Generation")] + [KSPField(isPersistant = true, guiActive = false)] + public float chanceOfFailure = 0.5f; + [KSPField(isPersistant = true, guiActive = true, guiName = "BaseFailure" ,guiActiveEditor = true, guiUnits = "%")] + public int displayChance = 0; + [KSPField(isPersistant = true, guiActive = false)] public int generation = 0; [KSPField(isPersistant = true, guiActive = false)] double failureTime = 0; public double maxTimeToFailure = 1800; - private void Start() { - if (HighLogic.LoadedSceneIsEditor) return; Overrides(); - part.AddModule("DontRecoverMe"); + if(!HighLogic.LoadedSceneIsEditor) part.AddModule("DontRecoverMe"); ScrapYardEvents.OnSYTrackerUpdated.Add(OnSYTrackerUpdated); + ScrapYardEvents.OnSYInventoryAppliedToVessel.Add(OnSYInventoryAppliedToVessel); Initialise(); GameEvents.onLaunch.Add(onLaunch); } + private void OnSYInventoryAppliedToVessel() + { + Debug.Log("[UPFM]: ScrayYard Inventory Applied. Recalculating failure chance"); + willFail = false; + generation = 0; + chanceOfFailure = 0.5f; + Initialise(); + } + private void onLaunch(EventReport data) { PartModule dontRecover = part.FindModuleImplementing(); @@ -52,7 +62,11 @@ private void OnSYTrackerUpdated(IEnumerable data) private void Initialise() { SYP = part.FindModuleImplementing(); - if (generation == 0) generation = (ScrapYardWrapper.GetBuildCount(part, ScrapYardWrapper.TrackType.NEW) - SYP.TimesRecovered); + if (generation == 0) + { + generation = (ScrapYardWrapper.GetBuildCount(part, ScrapYardWrapper.TrackType.NEW) - SYP.TimesRecovered); + if (HighLogic.LoadedSceneIsEditor) generation++; + } if (generation < 1) generation = 1; if (hasFailed) { @@ -66,6 +80,7 @@ private void Initialise() willFail = true; Debug.Log("[UPFM]: " + part.name + " will attempt to fail at " + failureTime); } + displayChance = (int)(chanceOfFailure * 100); } public void SetFailedHighlight() { @@ -109,7 +124,11 @@ bool FailCheck(bool recalcChance) if (UnityEngine.Random.value < chanceOfFailure) return true; return false; } + [KSPEvent(active = true, guiActiveUnfocused = false, unfocusedRange = 5.0f, externalToEVAOnly = true, guiName = "Trash Part ")] + public void TrashPart() + { + } [KSPEvent(active = false, guiActiveUnfocused = true, unfocusedRange = 5.0f, externalToEVAOnly = true, guiName = "Repair ")] public void RepairChecks() { diff --git a/UPFM/Untitled Part Failure Mod/BatteryFailureModule.cs b/UPFM/Untitled Part Failure Mod/BatteryFailureModule.cs index 25c78ec..979c49e 100644 --- a/UPFM/Untitled Part Failure Mod/BatteryFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/BatteryFailureModule.cs @@ -11,6 +11,10 @@ class BatteryFailureModule : BaseFailureModule PartResource battery; bool message; + protected override void Overrides() + { + Fields["displayChance"].guiName = "Chance of Battery Failure"; + } protected override void FailPart() { battery = part.Resources["ElectricCharge"]; diff --git a/UPFM/Untitled Part Failure Mod/ControlSurfaceFailureModule.cs b/UPFM/Untitled Part Failure Mod/ControlSurfaceFailureModule.cs index 09250c0..851ebe5 100644 --- a/UPFM/Untitled Part Failure Mod/ControlSurfaceFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/ControlSurfaceFailureModule.cs @@ -13,6 +13,11 @@ class ControlSurfaceFailureModule : BaseFailureModule [KSPField(isPersistant = true, guiActive = false)] bool message; + protected override void Overrides() + { + Fields["displayChance"].guiName = "Chance of COntrol Surface Failure"; + } + protected override bool FailureAllowed() { return HighLogic.CurrentGame.Parameters.CustomParams().ControlSurfaceFailureModuleAllowed; diff --git a/UPFM/Untitled Part Failure Mod/EngineFailureModule.cs b/UPFM/Untitled Part Failure Mod/EngineFailureModule.cs index 84a5639..62b9015 100644 --- a/UPFM/Untitled Part Failure Mod/EngineFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/EngineFailureModule.cs @@ -19,6 +19,7 @@ class EngineFailureModule : BaseFailureModule protected override void Overrides() { maxTimeToFailure = 120; + Fields["displayChance"].guiName = "Chance of Engine Failure"; } protected override bool FailureAllowed() diff --git a/UPFM/Untitled Part Failure Mod/ParachuteFailureModule.cs b/UPFM/Untitled Part Failure Mod/ParachuteFailureModule.cs index fedfc25..ece3e35 100644 --- a/UPFM/Untitled Part Failure Mod/ParachuteFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/ParachuteFailureModule.cs @@ -16,6 +16,11 @@ protected override bool FailureAllowed() return HighLogic.CurrentGame.Parameters.CustomParams().ParachuteFailureModuleAllowed; } + protected override void Overrides() + { + Fields["displayChance"].guiName = "Chance of Parachute Failure"; + } + protected override void FailPart() { chute = part.FindModuleImplementing(); diff --git a/UPFM/Untitled Part Failure Mod/ReactionWheelFailureModule.cs b/UPFM/Untitled Part Failure Mod/ReactionWheelFailureModule.cs index a35dee5..f055865 100644 --- a/UPFM/Untitled Part Failure Mod/ReactionWheelFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/ReactionWheelFailureModule.cs @@ -11,6 +11,11 @@ class ReactionWheelFailureModule : BaseFailureModule ModuleReactionWheel rw; bool message = false; + protected override void Overrides() + { + Fields["displayChance"].guiName = "Chance of Reaction Wheel Failure"; + } + protected override bool FailureAllowed() { return HighLogic.CurrentGame.Parameters.CustomParams().ReactionWheelFailureModuleAllowed; diff --git a/UPFM/Untitled Part Failure Mod/SolarPanelFailureModule.cs b/UPFM/Untitled Part Failure Mod/SolarPanelFailureModule.cs index bf8f0bb..d6e810b 100644 --- a/UPFM/Untitled Part Failure Mod/SolarPanelFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/SolarPanelFailureModule.cs @@ -10,6 +10,10 @@ class SolarPanelFailureModule : BaseFailureModule { ModuleDeployableSolarPanel panel; bool originallyRetractable; + protected override void Overrides() + { + Fields["displayChance"].guiName = "Chance of Solar Panel Failure"; + } protected override bool FailureAllowed() { return HighLogic.CurrentGame.Parameters.CustomParams().SolarPanelFailureModuleAllowed; diff --git a/UPFM/Untitled Part Failure Mod/TankFailureModule.cs b/UPFM/Untitled Part Failure Mod/TankFailureModule.cs index 2c57f9c..511aff4 100644 --- a/UPFM/Untitled Part Failure Mod/TankFailureModule.cs +++ b/UPFM/Untitled Part Failure Mod/TankFailureModule.cs @@ -13,7 +13,10 @@ class TankFailureModule : BaseFailureModule [KSPField(isPersistant = true, guiActive = false)] public string leakingName = "None"; private string savedFile; - + protected override void Overrides() + { + Fields["displayChance"].guiName = "Chance of Resource Tank Failure"; + } protected override bool FailureAllowed() { return HighLogic.CurrentGame.Parameters.CustomParams().TankFailureModuleAllowed; diff --git a/UPFM/Untitled Part Failure Mod/UPFMSettings.cs b/UPFM/Untitled Part Failure Mod/UPFMSettings.cs index f1d5177..70a3881 100644 --- a/UPFM/Untitled Part Failure Mod/UPFMSettings.cs +++ b/UPFM/Untitled Part Failure Mod/UPFMSettings.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; namespace Untitled_Part_Failure_Mod { @@ -7,6 +8,7 @@ class UPFMSettings : GameParameters.CustomParameterNode public override string Title { get { return "UPFM Options"; } } public override GameParameters.GameMode GameMode { get { return GameParameters.GameMode.ANY; } } public override string Section { get { return "Allowed Failures"; } } + public override string DisplaySection { get { return Section; } } public override int SectionOrder { get { return 1; } } public override bool HasPresets { get { return false; } } public bool autoPersistance = true; diff --git a/UPFM/Untitled Part Failure Mod/Untitled Part Failure Mod.csproj b/UPFM/Untitled Part Failure Mod/Untitled Part Failure Mod.csproj index 8c24b66..0fc370d 100644 --- a/UPFM/Untitled Part Failure Mod/Untitled Part Failure Mod.csproj +++ b/UPFM/Untitled Part Failure Mod/Untitled Part Failure Mod.csproj @@ -32,14 +32,15 @@ False - F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\KSP_x64_Data\Managed\Assembly-CSharp.dll + F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\KSP_x64_Data\Managed\Assembly-CSharp.dll False - F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll + F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll - - F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\GameData\ScrapYard\ScrapYard.dll + + False + F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\GameData\ScrapYard\ScrapYard.dll @@ -49,7 +50,7 @@ False - F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\KSP_x64_Data\Managed\UnityEngine.dll + F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\KSP_x64_Data\Managed\UnityEngine.dll @@ -69,8 +70,8 @@ "D:\OneDrive\Documents\pdb2mdb\pdb2mdb.exe" "$(TargetFileName)" -xcopy /Y "$(TargetPath)" "F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\GameData\UntitledFailures" -xcopy /Y "$(TargetDir)$(TargetName).pdb" "F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\GameData\UntitledFailures" -xcopy /Y "$(TargetDir)$(TargetName).dll.mdb" "F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\GameData\UntitledFailures" +xcopy /Y "$(TargetPath)" "F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 ModDev\GameData\UntitledFailures" +xcopy /Y "$(TargetDir)$(TargetName).pdb" "F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 ModDev\GameData\UntitledFailures" +xcopy /Y "$(TargetDir)$(TargetName).dll.mdb" "F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 ModDev\GameData\UntitledFailures" \ No newline at end of file diff --git a/UPFM/Untitled Part Failure Mod/bin/Release/GameData/UntitledFailures/UPFM.version b/UPFM/Untitled Part Failure Mod/bin/Release/GameData/UntitledFailures/UPFM.version index bf026d2..f917825 100644 --- a/UPFM/Untitled Part Failure Mod/bin/Release/GameData/UntitledFailures/UPFM.version +++ b/UPFM/Untitled Part Failure Mod/bin/Release/GameData/UntitledFailures/UPFM.version @@ -10,26 +10,26 @@ "VERSION" : { "MAJOR" : 0, - "MINOR" : 3, + "MINOR" : 4, "PATCH" : 0, "BUILD" : 0 }, "KSP_VERSION" : { "MAJOR" : 1, - "MINOR" : 2, - "PATCH" : 2 + "MINOR" : 3, + "PATCH" : 0 }, "KSP_VERSION_MIN" : { "MAJOR" : 1, - "MINOR" : 2, - "PATCH" : 2 + "MINOR" : 3, + "PATCH" : 0 }, "KSP_VERSION_MAX" : { "MAJOR" : 1, - "MINOR" : 2, - "PATCH" : 2 + "MINOR" : 3, + "PATCH" : 0 } }