Skip to content

Commit

Permalink
Fixed Failure Degeneration Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
severedsolo committed Jun 13, 2017
1 parent 7f837ad commit 56f5bfc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions UPFM/Untitled Part Failure Mod/BaseFailureModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Untitled_Part_Failure_Mod
{
Expand All @@ -14,7 +15,6 @@ class BaseFailureModule : PartModule
public bool hasFailed = false;
public float expectedLifetime = 2;
ModuleSYPartTracker SYP;
[KSPField(isPersistant = true, guiActive = false)]
public float chanceOfFailure = 0.5f;
[KSPField(isPersistant = true, guiActive = true, guiName = "BaseFailure" ,guiActiveEditor = true, guiUnits = "%")]
public int displayChance = 0;
Expand Down Expand Up @@ -74,12 +74,12 @@ private void Initialise()
return;
}
if(part != null) Debug.Log("[UPFM]: " + part.name + " has initialised");
if (FailCheck(true) && !HighLogic.LoadedSceneIsEditor)
{
failureTime = Planetarium.GetUniversalTime() + (maxTimeToFailure*UnityEngine.Random.value);
willFail = true;
Debug.Log("[UPFM]: " + part.name + " will attempt to fail at " + failureTime);
}
if (FailCheck(true) && !HighLogic.LoadedSceneIsEditor)
{
failureTime = Planetarium.GetUniversalTime() + (maxTimeToFailure * UnityEngine.Random.value);
willFail = true;
Debug.Log("[UPFM]: " + part.name + " will attempt to fail at " + failureTime);
}
displayChance = (int)(chanceOfFailure * 100);
}
public void SetFailedHighlight()
Expand Down Expand Up @@ -118,7 +118,6 @@ bool FailCheck(bool recalcChance)
{
chanceOfFailure = chanceOfFailure / generation;
if (SYP.TimesRecovered > 0) chanceOfFailure = chanceOfFailure * ((SYP.TimesRecovered / expectedLifetime));

}
if(part != null) Debug.Log("[UPFM]: Chances of "+part.name+" failing calculated to be " + chanceOfFailure * 100 + "%");
if (UnityEngine.Random.value < chanceOfFailure) return true;
Expand Down

0 comments on commit 56f5bfc

Please sign in to comment.