Permalink
Browse files

change almost all the rest of the rng calls to .chance/.between

  • Loading branch information...
jacob1 committed May 5, 2018
1 parent ef2a0c2 commit 49703404bef7b43498afe8c64c9ce3c8673a14f5
Showing with 281 additions and 269 deletions.
  1. +54 −53 src/simulation/Simulation.cpp
  2. +1 −1 src/simulation/elements/AMTR.cpp
  3. +2 −2 src/simulation/elements/ANAR.cpp
  4. +6 −5 src/simulation/elements/BCLN.cpp
  5. +3 −3 src/simulation/elements/BMTL.cpp
  6. +2 −2 src/simulation/elements/BOYL.cpp
  7. +1 −1 src/simulation/elements/BREC.cpp
  8. +2 −4 src/simulation/elements/BRMT.cpp
  9. +2 −2 src/simulation/elements/C5.cpp
  10. +1 −1 src/simulation/elements/CAUS.cpp
  11. +10 −9 src/simulation/elements/CBNW.cpp
  12. +5 −4 src/simulation/elements/CLNE.cpp
  13. +1 −1 src/simulation/elements/CLST.cpp
  14. +8 −6 src/simulation/elements/CO2.cpp
  15. +1 −1 src/simulation/elements/COAL.cpp
  16. +5 −5 src/simulation/elements/DEST.cpp
  17. +5 −5 src/simulation/elements/DEUT.cpp
  18. +7 −6 src/simulation/elements/DSTW.cpp
  19. +2 −2 src/simulation/elements/ELEC.cpp
  20. +13 −13 src/simulation/elements/EMP.cpp
  21. +7 −7 src/simulation/elements/EXOT.cpp
  22. +14 −12 src/simulation/elements/Element.cpp
  23. +3 −3 src/simulation/elements/FILT.cpp
  24. +12 −9 src/simulation/elements/FIRE.cpp
  25. +7 −7 src/simulation/elements/FIRW.cpp
  26. +2 −2 src/simulation/elements/FOG.cpp
  27. +2 −2 src/simulation/elements/FRZW.cpp
  28. +1 −1 src/simulation/elements/FRZZ.cpp
  29. +3 −3 src/simulation/elements/FSEP.cpp
  30. +3 −3 src/simulation/elements/FUSE.cpp
  31. +12 −12 src/simulation/elements/FWRK.cpp
  32. +10 −9 src/simulation/elements/GEL.cpp
  33. +1 −1 src/simulation/elements/GLOW.cpp
  34. +3 −3 src/simulation/elements/GOLD.cpp
  35. +1 −1 src/simulation/elements/GOO.cpp
  36. +1 −1 src/simulation/elements/GRAV.cpp
  37. +6 −6 src/simulation/elements/H2.cpp
  38. +2 −2 src/simulation/elements/ICEI.cpp
  39. +5 −5 src/simulation/elements/IRON.cpp
  40. +3 −3 src/simulation/elements/ISOZ.cpp
  41. +3 −3 src/simulation/elements/ISZS.cpp
  42. +12 −12 src/simulation/elements/LIGH.cpp
  43. +5 −5 src/simulation/elements/MERC.cpp
  44. +4 −4 src/simulation/elements/NBLE.cpp
  45. +20 −20 src/simulation/elements/NEUT.cpp
  46. +7 −7 src/simulation/elements/O2.cpp
  47. +1 −0 src/simulation/elements/PIPE.cpp
@@ -1974,7 +1974,7 @@ int Simulation::get_wavelength_bin(int *wm)
if (wM - w0 < 5)
return wM + w0;
r = random_gen();
r = RNG::Ref().gen();
i = (r >> 1) % (wM-w0-4);
i += w0;
@@ -2098,8 +2098,8 @@ void Simulation::create_arc(int sx, int sy, int dx, int dy, int midpoints, int v
{
if(i!=midpoints)
{
xmid[i+1] += (random_gen()%variance)-voffset;
ymid[i+1] += (random_gen()%variance)-voffset;
xmid[i+1] += RNG::Ref().between(0, variance - 1) - voffset;
ymid[i+1] += RNG::Ref().between(0, variance - 1) - voffset;
}
CreateLine(xmid[i], ymid[i], xmid[i+1], ymid[i+1], type);
}
@@ -2414,9 +2414,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
e = eval_move(parts[i].type, nx, ny, &r);
/* half-silvered mirror */
if (!e && parts[i].type==PT_PHOT &&
((TYP(r)==PT_BMTL && random_gen()%2) ||
TYP(pmap[y][x])==PT_BMTL))
if (!e && parts[i].type==PT_PHOT && ((TYP(r)==PT_BMTL && RNG::Ref().chance(1, 2)) || TYP(pmap[y][x])==PT_BMTL))
e = 2;
if (!e) //if no movement
@@ -2475,7 +2473,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
switch (TYP(r))
{
case PT_GLOW:
if (!parts[ID(r)].life && random_gen()%30)
if (!parts[ID(r)].life && RNG::Ref().chance(29, 30))
{
parts[ID(r)].life = 120;
create_gain_photon(i);
@@ -2564,7 +2562,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
}
case PT_NEUT:
if (TYP(r) == PT_GLAS || TYP(r) == PT_BGLA)
if (random_gen()%10)
if (RNG::Ref().chance(9, 10))
create_cherenkov_photon(i);
break;
case PT_ELEC:
@@ -3235,7 +3233,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
parts[i].life = 75;
break;
case PT_WARP:
parts[i].life = random_gen()%95+70;
parts[i].life = RNG::Ref().between(70, 164);
break;
case PT_FUSE:
parts[i].life = 50;
@@ -3261,14 +3259,14 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
parts[i].life = 10;
break;
case PT_SING:
parts[i].life = random_gen()%50+60;
parts[i].life = RNG::Ref().between(60, 109);
break;
case PT_QRTZ:
case PT_PQRT:
parts[i].tmp2 = (random_gen()%11);
parts[i].tmp2 = RNG::Ref().between(0, 10);
break;
case PT_CLST:
parts[i].tmp = (random_gen()%7);
parts[i].tmp = RNG::Ref().between(0, 6);
break;
case PT_FSEP:
parts[i].life = 50;
@@ -3291,16 +3289,16 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
parts[i].life = 110;
break;
case PT_FIRE:
parts[i].life = random_gen()%50+120;
parts[i].life = RNG::Ref().between(120, 169);
break;
case PT_PLSM:
parts[i].life = random_gen()%150+50;
parts[i].life = RNG::Ref().between(50, 199);
break;
case PT_CFLM:
parts[i].life = random_gen()%150+50;
parts[i].life = RNG::Ref().between(50, 199);
break;
case PT_LAVA:
parts[i].life = random_gen()%120+240;
parts[i].life = RNG::Ref().between(240, 359);
break;
case PT_NBLE:
parts[i].life = 0;
@@ -3340,7 +3338,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
parts[i].pavg[1] = 250;
break;
case PT_CRMC:
parts[i].tmp2 = (random_gen() % 5);
parts[i].tmp2 = RNG::Ref().between(0, 4);
break;
case PT_ETRD:
etrd_life0_count++;
@@ -3403,7 +3401,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
}
case PT_PHOT:
{
float a = (random_gen()%8) * 0.78540f;
float a = RNG::Ref().between(0, 7) * 0.78540f;
parts[i].life = 680;
parts[i].ctype = 0x3FFFFFFF;
parts[i].vx = 3.0f*cosf(a);
@@ -3414,42 +3412,42 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
}
case PT_ELEC:
{
float a = (random_gen()%360)*3.14159f/180.0f;
float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].life = 680;
parts[i].vx = 2.0f*cosf(a);
parts[i].vy = 2.0f*sinf(a);
break;
}
case PT_NEUT:
{
float r = (random_gen()%128+128)/127.0f;
float a = (random_gen()%360)*3.14159f/180.0f;
parts[i].life = random_gen()%480+480;
float r = RNG::Ref().between(128, 255) / 127.0f;
float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].life = RNG::Ref().between(480, 959);
parts[i].vx = r*cosf(a);
parts[i].vy = r*sinf(a);
break;
}
case PT_PROT:
{
float a = (random_gen()%36)* 0.17453f;
float a = RNG::Ref().between(0, 35) * 0.17453f;
parts[i].life = 680;
parts[i].vx = 2.0f*cosf(a);
parts[i].vy = 2.0f*sinf(a);
break;
}
case PT_GRVT:
{
float a = (random_gen()%360)*3.14159f/180.0f;
parts[i].life = 250 + random_gen()%200;
float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].life = RNG::Ref().between(250, 449);
parts[i].vx = 2.0f*cosf(a);
parts[i].vy = 2.0f*sinf(a);
parts[i].tmp = 7;
break;
}
case PT_TRON:
{
int randhue = random_gen()%360;
int randomdir = random_gen()%4;
int randhue = RNG::Ref().between(0, 359);
int randomdir = RNG::Ref().between(0, 3);
parts[i].tmp = 1|(randomdir<<5)|(randhue<<7);//set as a head and a direction
parts[i].tmp2 = 4;//tail
parts[i].life = 5;
@@ -3472,13 +3470,13 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
gsize = gx*gx+gy*gy;
if (gsize<0.0016f)
{
float angle = (random_gen()%6284)*0.001f;//(in radians, between 0 and 2*pi)
float angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)
gsize = sqrtf(gsize);
// randomness in weak gravity fields (more randomness with weaker fields)
gx += cosf(angle)*(0.04f-gsize);
gy += sinf(angle)*(0.04f-gsize);
}
parts[i].tmp = (((int)(atan2f(-gy, gx)*(180.0f/M_PI)))+random_gen()%40-20+360)%360;
parts[i].tmp = (((int)(atan2f(-gy, gx)*(180.0f/M_PI))) + RNG::Ref().between(340, 380)) % 360;
parts[i].tmp2 = 4;
break;
}
@@ -3498,13 +3496,13 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
if((elements[t].Properties & TYPE_PART) && pretty_powder)
{
int colr, colg, colb;
colr = PIXR(elements[t].Colour)+sandcolour*1.3+(random_gen()%40)-20+(random_gen()%30)-15;
colg = PIXG(elements[t].Colour)+sandcolour*1.3+(random_gen()%40)-20+(random_gen()%30)-15;
colb = PIXB(elements[t].Colour)+sandcolour*1.3+(random_gen()%40)-20+(random_gen()%30)-15;
colr = PIXR(elements[t].Colour) + sandcolour * 1.3 + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15);
colg = PIXG(elements[t].Colour) + sandcolour * 1.3 + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15);
colb = PIXB(elements[t].Colour) + sandcolour * 1.3 + RNG::Ref().between(-20, 20) + RNG::Ref().between(-15, 15);
colr = colr>255 ? 255 : (colr<0 ? 0 : colr);
colg = colg>255 ? 255 : (colg<0 ? 0 : colg);
colb = colb>255 ? 255 : (colb<0 ? 0 : colb);
parts[i].dcolour = ((random_gen()%150)<<24) | (colr<<16) | (colg<<8) | colb;
parts[i].dcolour = (RNG::Ref().between(0, 149)<<24) | (colr<<16) | (colg<<8) | colb;
}
elementCount[t]++;
return i;
@@ -3541,7 +3539,7 @@ void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLO
return;
i = pfree;
lr = random_gen() % 2;
lr = RNG::Ref().between(0, 1);
if (lr) {
xx = parts[pp].x - 0.3*parts[pp].vy;
@@ -3600,7 +3598,7 @@ void Simulation::create_cherenkov_photon(int pp)//photons from NEUT going throug
pfree = parts[i].life;
if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
lr = random_gen() % 2;
lr = RNG::Ref().between(0, 1);
parts[i].type = PT_PHOT;
parts[i].ctype = 0x00000F80;
@@ -3775,11 +3773,11 @@ void Simulation::UpdateParticles(int start, int end)
{
#ifdef REALISTIC
//The magic number controls diffusion speed
parts[i].vx += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*random_gen.uniform01()-1.0f);
parts[i].vy += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*random_gen.uniform01()-1.0f);
parts[i].vx += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f);
parts[i].vy += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f);
#else
parts[i].vx += elements[t].Diffusion*(2.0f*random_gen.uniform01()-1.0f);
parts[i].vy += elements[t].Diffusion*(2.0f*random_gen.uniform01()-1.0f);
parts[i].vx += elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f);
parts[i].vy += elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f);
#endif
}
@@ -3804,7 +3802,7 @@ void Simulation::UpdateParticles(int start, int end)
if (!legacy_enable)
{
if (y-2 >= 0 && y-2 < YRES && (elements[t].Properties&TYPE_LIQUID) && (t!=PT_GEL || gel_scale>(1+random_gen()%255))) {//some heat convection for liquids
if (y-2 >= 0 && y-2 < YRES && (elements[t].Properties&TYPE_LIQUID) && (t!=PT_GEL || gel_scale > (1 + RNG::Ref().between(0, 254)))) {//some heat convection for liquids
r = pmap[y-2][x];
if (!(!r || parts[i].type != TYP(r))) {
if (parts[i].temp>parts[ID(r)].temp) {
@@ -3820,7 +3818,7 @@ void Simulation::UpdateParticles(int start, int end)
#ifdef REALISTIC
if (t&&(t!=PT_HSWC||parts[i].life==10)&&(elements[t].HeatConduct*gel_scale))
#else
if (t&&(t!=PT_HSWC||parts[i].life==10)&&(elements[t].HeatConduct*gel_scale)>(random_gen()%250))
if (t && (t!=PT_HSWC||parts[i].life==10) && RNG::Ref().chance(elements[t].HeatConduct*gel_scale, 250))
#endif
{
if (aheat_enable && !(elements[t].Properties&PROP_NOAMBHEAT))
@@ -3977,16 +3975,18 @@ void Simulation::UpdateParticles(int start, int end)
{
pt = (c_heat - platent[t])/c_Cm;
if (random_gen()%4==0) t = PT_SALT;
else t = PT_WTRV;
if (RNG::Ref().chance(1, 4))
t = PT_SALT;
else
t = PT_WTRV;
}
else
{
parts[i].temp = restrict_flt(elements[t].HighTemperature - dbt, MIN_TEMP, MAX_TEMP);
s = 0;
}
#else
if (random_gen()%4 == 0)
if (RNG::Ref().chance(1, 4))
t = PT_SALT;
else
t = PT_WTRV;
@@ -4138,14 +4138,14 @@ void Simulation::UpdateParticles(int start, int end)
goto killed;
if (t==PT_FIRE || t==PT_PLSM || t==PT_CFLM)
parts[i].life = random_gen()%50+120;
parts[i].life = RNG::Ref().between(120, 169);
if (t == PT_LAVA)
{
if (parts[i].ctype == PT_BRMT) parts[i].ctype = PT_BMTL;
else if (parts[i].ctype == PT_SAND) parts[i].ctype = PT_GLAS;
else if (parts[i].ctype == PT_BGLA) parts[i].ctype = PT_GLAS;
else if (parts[i].ctype == PT_PQRT) parts[i].ctype = PT_QRTZ;
parts[i].life = random_gen()%120+240;
parts[i].life = RNG::Ref().between(240, 359);
}
transitionOccurred = true;
}
@@ -4219,7 +4219,7 @@ void Simulation::UpdateParticles(int start, int end)
//the basic explosion, from the .explosive variable
if ((elements[t].Explosive&2) && pv[y/CELL][x/CELL]>2.5f)
{
parts[i].life = random_gen()%80+180;
parts[i].life = RNG::Ref().between(180, 259);
parts[i].temp = restrict_flt(elements[PT_FIRE].Temperature + (elements[t].Flammable/2), MIN_TEMP, MAX_TEMP);
t = PT_FIRE;
part_change_type(i,x,y,t);
@@ -4275,7 +4275,7 @@ void Simulation::UpdateParticles(int start, int end)
if (part_change_type(i,x,y,t))
goto killed;
if (t == PT_FIRE)
parts[i].life = random_gen()%50+120;
parts[i].life = RNG::Ref().between(120, 169);
transitionOccurred = true;
}
@@ -4548,7 +4548,7 @@ void Simulation::UpdateParticles(int start, int end)
continue;
// reflection
parts[i].flags |= FLAG_STAGNANT;
if (t==PT_NEUT && 100>(random_gen()%1000))
if (t==PT_NEUT && RNG::Ref().chance(1, 10))
{
kill_part(i);
continue;
@@ -4573,7 +4573,7 @@ void Simulation::UpdateParticles(int start, int end)
{
if (TYP(r) == PT_CRMC)
{
float r = (random_gen() % 101 - 50) * 0.01f, rx, ry, anrx, anry;
float r = RNG::Ref().between(-50, 50) * 0.01f, rx, ry, anrx, anry;
r = r * r * r;
rx = cosf(r); ry = sinf(r);
anrx = rx * nrx + ry * nry;
@@ -4634,7 +4634,8 @@ void Simulation::UpdateParticles(int start, int end)
}
else
{
if (water_equal_test && elements[t].Falldown == 2 && 1>= random_gen()%400)//checking stagnant is cool, but then it doesn't update when you change it later.
// Checking stagnant is cool, but then it doesn't update when you change it later.
if (water_equal_test && elements[t].Falldown == 2 && RNG::Ref().chance(1, 200))
{
if (!flood_water(x,y,i,y, parts[i].flags&FLAG_WATEREQUAL))
goto movedone;
@@ -4657,7 +4658,7 @@ void Simulation::UpdateParticles(int start, int end)
else
{
s = 1;
r = (random_gen()%2)*2-1;// position search direction (left/right first)
r = RNG::Ref().between(0, 1) * 2 - 1;// position search direction (left/right first)
if ((clear_x!=x || clear_y!=y || nt || surround_space) &&
(fabsf(parts[i].vx)>0.01f || fabsf(parts[i].vy)>0.01f))
{
@@ -5239,7 +5240,7 @@ void Simulation::BeforeSim()
}
// check for stacking and create BHOL if found
if (force_stacking_check || (random_gen()%10)==0)
if (force_stacking_check || RNG::Ref().chance(1, 10))
{
CheckStacking();
}
@@ -65,7 +65,7 @@ int Element_AMTR::update(UPDATE_FUNC_ARGS)
sim->kill_part(i);
return 1;
}
if (!(random_gen()%10))
if (RNG::Ref().chance(1, 10))
sim->create_part(ID(r), x+rx, y+ry, PT_PHOT);
else
sim->kill_part(ID(r));
@@ -58,10 +58,10 @@ int Element_ANAR::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
if (TYP(r)==PT_CFLM && !(random_gen()%4))
if (TYP(r)==PT_CFLM && RNG::Ref().chance(1, 4))
{
sim->part_change_type(i,x,y,PT_CFLM);
parts[i].life = random_gen()%150+50;
parts[i].life = RNG::Ref().between(50, 199);
parts[ID(r)].temp = parts[i].temp = 0;
sim->pv[y/CELL][x/CELL] -= 0.5;
}
Oops, something went wrong.

0 comments on commit 4970340

Please sign in to comment.