forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispersion.cpp
53 lines (48 loc) · 1.32 KB
/
dispersion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "dispersion.h"
#include "rng.h"
double dispersion_sources::roll() const
{
// The roll "latches" for a given instance of a dispersion source.
double this_roll = 0.0;
if( prev_roll < 0.0 ) {
for( const double &source : linear_sources ) {
this_roll += rng_float( 0.0, source );
}
for( const double &source : normal_sources ) {
this_roll += rng_normal( source );
}
for( const double &source : multipliers ) {
this_roll *= source;
}
prev_roll = this_roll;
} else {
this_roll = prev_roll;
}
for( const double &source : spread_sources ) {
// Normal distribution centered on 0, but flip negatives to positive.
double sample = rng_normal( -source, source );
this_roll += sample >= 0 ? sample : -sample;
}
return this_roll;
}
double dispersion_sources::max() const
{
double sum = 0.0;
for( const double &source : linear_sources ) {
sum += source;
}
for( const double &source : normal_sources ) {
sum += source;
}
for( const double &source : multipliers ) {
sum *= source;
}
for( const double &spread : spread_sources ) {
sum += spread;
}
return sum;
}
double dispersion_sources::avg() const
{
return max() / 2.0;
}