Skip to content

Commit

Permalink
Removed Generation Visibility and replaced it with Failure Rate - closes
Browse files Browse the repository at this point in the history
 #3 - also added GUI indication in Editor.
  • Loading branch information
severedsolo committed Jun 10, 2017
1 parent 5ed88fc commit 483992f
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 24 deletions.
33 changes: 26 additions & 7 deletions UPFM/Untitled Part Failure Mod/BaseFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DontRecoverMe>();
Expand All @@ -52,7 +62,11 @@ private void OnSYTrackerUpdated(IEnumerable<InventoryPart> data)
private void Initialise()
{
SYP = part.FindModuleImplementing<ModuleSYPartTracker>();
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)
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions UPFM/Untitled Part Failure Mod/BatteryFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
5 changes: 5 additions & 0 deletions UPFM/Untitled Part Failure Mod/ControlSurfaceFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UPFMSettings>().ControlSurfaceFailureModuleAllowed;
Expand Down
1 change: 1 addition & 0 deletions UPFM/Untitled Part Failure Mod/EngineFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EngineFailureModule : BaseFailureModule
protected override void Overrides()
{
maxTimeToFailure = 120;
Fields["displayChance"].guiName = "Chance of Engine Failure";
}

protected override bool FailureAllowed()
Expand Down
5 changes: 5 additions & 0 deletions UPFM/Untitled Part Failure Mod/ParachuteFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ protected override bool FailureAllowed()
return HighLogic.CurrentGame.Parameters.CustomParams<UPFMSettings>().ParachuteFailureModuleAllowed;
}

protected override void Overrides()
{
Fields["displayChance"].guiName = "Chance of Parachute Failure";
}

protected override void FailPart()
{
chute = part.FindModuleImplementing<ModuleParachute>();
Expand Down
5 changes: 5 additions & 0 deletions UPFM/Untitled Part Failure Mod/ReactionWheelFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UPFMSettings>().ReactionWheelFailureModuleAllowed;
Expand Down
4 changes: 4 additions & 0 deletions UPFM/Untitled Part Failure Mod/SolarPanelFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UPFMSettings>().SolarPanelFailureModuleAllowed;
Expand Down
5 changes: 4 additions & 1 deletion UPFM/Untitled Part Failure Mod/TankFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UPFMSettings>().TankFailureModuleAllowed;
Expand Down
4 changes: 3 additions & 1 deletion UPFM/Untitled Part Failure Mod/UPFMSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;

namespace Untitled_Part_Failure_Mod
{
Expand All @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions UPFM/Untitled Part Failure Mod/Untitled Part Failure Mod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="ScrapYard">
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\GameData\ScrapYard\ScrapYard.dll</HintPath>
<Reference Include="ScrapYard, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\GameData\ScrapYard\ScrapYard.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -49,7 +50,7 @@
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.2.2 ModDev\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program - 1.3 Playable\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -69,8 +70,8 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>"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"</PostBuildEvent>
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"</PostBuildEvent>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 483992f

Please sign in to comment.