Exemplo n.º 1
0
        public float GetRandomisation(Part p)
        {
            ModuleSYPartTracker SYP = p.FindModuleImplementing <ModuleSYPartTracker>();

            if (SYP == null)
            {
                return(0);
            }
            float f = 0;

            if (randomisation.TryGetValue(SYP.ID, out f))
            {
                return(f);
            }
            int builds;

            if (HighLogic.LoadedSceneIsEditor)
            {
                builds = ScrapYardWrapper.GetBuildCount(p, ScrapYardWrapper.TrackType.NEW) + 1;
            }
            else
            {
                builds = ScrapYardWrapper.GetBuildCount(p, ScrapYardWrapper.TrackType.NEW);
            }
            int randomFactor = 8;

            if (builds > 0)
            {
                randomFactor = 8 / builds;
            }
            if (randomFactor > 1)
            {
                f = (Randomiser.instance.RandomInteger(1, randomFactor) / 100.0f);
            }
            float threshold = HighLogic.CurrentGame.Parameters.CustomParams <UPFMSettings>().safetyThreshold / 100.0f;

            if (f > threshold)
            {
                f = threshold - 0.01f;
            }
            if (!float.IsNaN(f))
            {
                randomisation.Add(SYP.ID, f);
#if DEBUG
                Debug.Log("[UPFM]: Applied Random Factor of " + f + " to part " + SYP.ID);
#endif
            }
            return(f);
        }
Exemplo n.º 2
0
 //This keeps track of which generation the part is.
 //If its been seen before it will be in the dictionary, so we can just return that (rather than having to guess by builds and times recovered)
 //Otherwise we can assume it's a new part and the "current" build count should be correct.
 public int GetGeneration(uint id, Part p)
 {
     if (generations.TryGetValue(id, out int i))
     {
         return(i);
     }
     if (HighLogic.LoadedSceneIsEditor)
     {
         i = ScrapYardWrapper.GetBuildCount(p, ScrapYardWrapper.TrackType.NEW) + 1;
     }
     else
     {
         i = ScrapYardWrapper.GetBuildCount(p, ScrapYardWrapper.TrackType.NEW);
     }
     generations.Add(id, i);
     return(i);
 }
Exemplo n.º 3
0
        public void Initialise()
        {
            SYP   = part.FindModuleImplementing <ModuleSYPartTracker>();
            ready = SYP.ID != "";
            if (!ready)
            {
                return;
            }
            randomisation = UPFMUtils.instance.GetRandomisation(part);
            if (hasFailed)
            {
                UPFM.Events["RepairChecks"].active    = true;
                UPFM.Events["ToggleHighlight"].active = true;
            }
            else
            {
                if (FailCheck(true) && !HighLogic.LoadedSceneIsEditor && launched)
                {
                    double timeToFailure = (maxTimeToFailure * (1 - chanceOfFailure)) * Randomiser.instance.NextDouble();
                    failureTime = Planetarium.GetUniversalTime() + timeToFailure;
                    willFail    = true;
                    Debug.Log("[UPFM]: " + SYP.ID + " " + ClassName + " will attempt to fail in " + timeToFailure + " seconds");
#if !DEBUG
                    Debug.Log("[UPFM]: Chance of Failure was " + displayChance + "% (Generation " + ScrapYardWrapper.GetBuildCount(part, ScrapYardWrapper.TrackType.NEW) + ")");
#endif
                }
            }
            displayChance = (int)(chanceOfFailure * 100);
            float safetyCalc = 1.0f - ((float)displayChance / HighLogic.CurrentGame.Parameters.CustomParams <UPFMSettings>().safetyThreshold);
            if (safetyCalc > 0.95)
            {
                safetyRating = 5;
            }
            else if (safetyCalc > 0.9)
            {
                safetyRating = 4;
            }
            else if (safetyCalc > 0.8)
            {
                safetyRating = 3;
            }
            else if (safetyCalc > 0.7)
            {
                safetyRating = 2;
            }
            else
            {
                safetyRating = 1;
            }
            if (displayChance > HighLogic.CurrentGame.Parameters.CustomParams <UPFMSettings>().safetyThreshold)
            {
                safetyRating = 0;
            }
            if (chanceOfFailure == 0.01f)
            {
                displayChance = 1;
            }
            if (UPFMUtils.instance != null && hasFailed)
            {
                if (!UPFMUtils.instance.brokenParts.ContainsKey(part))
                {
                    UPFMUtils.instance.brokenParts.Add(part, displayChance);
                }
            }
        }