/// <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); } }
/// <summary> /// Randomly selects an asteroid set. The selection is weighted by the spawn rate of /// each population; a set with a rate of 2.0 is twice as likely to be chosen as one /// with a rate of 1.0. /// </summary> /// <returns>A reference to the selected asteroid set. Shall not be null.</returns> /// /// <exception cref="InvalidOperationException">Thrown if there are no sets from /// which to choose, or if all spawn rates are zero, or if any rate is negative</exception> internal AsteroidSet drawAsteroidSet() { try { var bins = new List <Pair <AsteroidSet, double> > (); foreach (AsteroidSet x in asteroidPops) { bins.Add(new Pair <AsteroidSet, double> (x, x.getSpawnRate())); } return(RandomDist.weightedSample(bins)); } catch (ArgumentException e) { throw new InvalidOperationException( Localizer.Format("#autoLOC_CustomAsteroids_ErrorNoGroup"), 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)); } }