Skip to content

Commit

Permalink
Merge pull request #451 from sswelm/patch-1
Browse files Browse the repository at this point in the history
Calculate shield rating with correct exponential function
  • Loading branch information
SirMortimer committed Jul 1, 2019
2 parents 9fdf146 + 7c41fdc commit ec400b5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Added mod support for CME prediction accuracy that influences the probability that you get an advanced warning, and its accuracy (Sir Mortimer)
* Configs for SoundingRockets (Arthur, Breach Candy)
* Fixed DMOS experiment restriction to plantary space. This breaks some DMOS contracts that require experiments in solar orbit (Sir Mortimer)
* Improved shielding efficiency calculation (Free Thinker)

## v3.0.2 for all versions of KSP from 1.4.0 to 1.7.x

Expand Down
7 changes: 4 additions & 3 deletions src/Kerbalism/Modules/Habitat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,12 @@ public static double Humidity(Vessel v)
return ResourceCache.Info(v, "MoistAtmosphere").level + 0.6;
}

// return shielding factor in a vessel
/// <summary>
/// Return vessel shielding factor.
/// </summary>
public static double Shielding(Vessel v)
{
// the shielding factor is simply the level of shielding, scaled by the 'shielding efficiency' setting
return ResourceCache.Info(v, "Shielding").level * PreferencesStorm.Instance.shieldingEfficiency;
return Radiation.ShieldingEfficiency(ResourceCache.Info(v, "Shielding").level);
}

// return living space factor in a vessel
Expand Down
15 changes: 15 additions & 0 deletions src/Kerbalism/Radiation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,21 @@ static CelestialBody Interesting_body()
: null;
}

/// <summary>
/// Calculate radiation shielding efficiency. Parameter shielding should be in range [0..1]
/// <para>
/// If you have a thickness which stops a known amount of radiation of a known and constant
/// type, then if you have a new thickness, you can calculate how much it stops by:
/// </para>
/// Stoppage = 1 - ((1 - AmountStoppedByKnownThickness)^(NewThickness / KnownThickness))
/// <para>
/// source : http://www.projectrho.com/public_html/rocket/radiation.php#id--Radiation_Shielding--Shielding--Shield_Rating
/// </para>
/// </summary>
public static double ShieldingEfficiency(double shielding)
{
return 1 - Math.Pow(1 - PreferencesStorm.Instance.shieldingEfficiency, Lib.Clamp(shielding, 0.0, 1.0));
}

static Dictionary<string, RadiationModel> models = new Dictionary<string, RadiationModel>(16);
static Dictionary<string, RadiationBody> bodies = new Dictionary<string, RadiationBody>(32);
Expand Down
5 changes: 4 additions & 1 deletion src/Kerbalism/UI/Planner/VesselAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ void Analyze_radiation(List<Part> parts, ResourceSimulator sim)
// calculate shielding factor
double amount = sim.Resource("Shielding").amount;
double capacity = sim.Resource("Shielding").capacity;
shielding = (capacity > double.Epsilon ? amount / capacity : 1.0) * PreferencesStorm.Instance.shieldingEfficiency;

shielding = capacity > double.Epsilon
? Radiation.ShieldingEfficiency(amount / capacity)
: PreferencesStorm.Instance.shieldingEfficiency;
}

void Analyze_reliability(List<Part> parts)
Expand Down

0 comments on commit ec400b5

Please sign in to comment.