/// <summary> /// Generates vessel parts and resources appropriate for the chosen set. /// </summary> /// /// <param name="group">The set to which the asteroid belongs.</param> /// <returns>An array of ConfigNodes storing the asteroid's parts. The first element MUST /// be the root part.</returns> /// /// <exception cref="System.InvalidOperationException">Thrown if <c>group</c> cannot /// generate valid parts. The program state will be unchanged in the event of an /// exception.</exception> /// <exception cref="System.NullReferenceException">Thrown if <c>group</c> is /// null.</exception> private ConfigNode [] makeAsteroidParts(AsteroidSet group) { // The same "seed" that shows up in ProceduralAsteroid? uint seed = (uint)rng.Next(); string part = group.drawAsteroidType(); try { ConfigNode potato = ProtoVessel.CreatePartNode(part, seed); return(new [] { potato }); } catch (Exception e) { // Really? That's what CreatePartNode throws? throw new InvalidOperationException( Localizer.Format("#autoLOC_CustomAsteroids_ErrorTypeBadPart", part), e); } }
/// <summary> /// Uses criteria similar to ScenarioDiscoverableObjects to decide whether to create an /// asteroid. /// </summary> protected override void checkSpawn() { if (areAsteroidsTrackable() && AsteroidManager.spawnRate() > 0.0 && countUntrackedAsteroids() < rng.Next(SPAWN_GROUP_MIN_LIMIT, SPAWN_GROUP_MAX_LIMIT)) { if (rng.NextDouble() < 1.0 / (1.0 + SPAWN_ODDS_AGAINST)) { spawnAsteroid(); } else { Debug.Log("[StockalikeSpawner]: " + Localizer.Format("#autoLOC_CustomAsteroids_LogSpawnStock", SPAWN_ODDS_AGAINST)); } } }
/// <summary> /// Returns <c>+1</c> or <c>-1</c> with equal probability. Does not throw exceptions. /// </summary> /// <returns>The value <c>+1</c> or <c>-1</c>.</returns> internal static double drawSign() { return(rng.Next(2) == 0 ? -1.0 : +1.0); }