Пример #1
0
 /// <summary>
 /// Randomly selects an asteroid class. The selection is weighted by the proportions passed
 /// to the method.
 /// </summary>
 ///
 /// <param name="typeRatios">The proportions in which to select the types.</param>
 /// <returns>The selected asteroid class. Shall not be null.</returns>
 ///
 /// <exception cref="InvalidOperationException">Thrown if there are no types from
 /// which to choose, or if all proportions are zero, or if any proportion is
 /// negative.</exception>
 internal static string drawAsteroidType <Dummy> (Proportions <Dummy> typeRatios)
 {
     try {
         return(RandomDist.weightedSample(typeRatios.asPairList()));
     } catch (ArgumentException e) {
         throw new InvalidOperationException(
                   Localizer.Format("#autoLOC_CustomAsteroids_ErrorNoClass2"), e);
     }
 }
 public UntrackedObjectClass drawAsteroidSize()
 {
     if (sizeRatios != null)
     {
         string sizeName = RandomDist.weightedSample(sizeRatios.asPairList());
         if (Enum.TryParse(sizeName, true, out UntrackedObjectClass size))
         {
             return(size);
         }
         else
         {
             Util.errorToPlayerLoc("#autoLOC_CustomAsteroids_ErrorNoSize", sizeName, name);
             Debug.LogError($"[CustomAsteroids]: Invalid asteroid size {sizeName} in group {name}.");
             return(UntrackedObjectClass.C);
         }
     }
     else
     {
         // Stock asteroids appear to be hardcoded to be from size A to E, even though there are more classes now
         return((UntrackedObjectClass)(int)
                (stockSizeCurve.Evaluate((float)RandomDist.drawUniform(0, 1)) * 5));
     }
 }