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

This commit is contained in:
jacob1 2018-05-05 11:56:17 -04:00
parent ef2a0c2c81
commit 49703404be
47 changed files with 281 additions and 269 deletions

View File

@ -1974,7 +1974,7 @@ int Simulation::get_wavelength_bin(int *wm)
if (wM - w0 < 5) if (wM - w0 < 5)
return wM + w0; return wM + w0;
r = random_gen(); r = RNG::Ref().gen();
i = (r >> 1) % (wM-w0-4); i = (r >> 1) % (wM-w0-4);
i += w0; 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) if(i!=midpoints)
{ {
xmid[i+1] += (random_gen()%variance)-voffset; xmid[i+1] += RNG::Ref().between(0, variance - 1) - voffset;
ymid[i+1] += (random_gen()%variance)-voffset; ymid[i+1] += RNG::Ref().between(0, variance - 1) - voffset;
} }
CreateLine(xmid[i], ymid[i], xmid[i+1], ymid[i+1], type); 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); e = eval_move(parts[i].type, nx, ny, &r);
/* half-silvered mirror */ /* half-silvered mirror */
if (!e && parts[i].type==PT_PHOT && if (!e && parts[i].type==PT_PHOT && ((TYP(r)==PT_BMTL && RNG::Ref().chance(1, 2)) || TYP(pmap[y][x])==PT_BMTL))
((TYP(r)==PT_BMTL && random_gen()%2) ||
TYP(pmap[y][x])==PT_BMTL))
e = 2; e = 2;
if (!e) //if no movement 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)) switch (TYP(r))
{ {
case PT_GLOW: 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; parts[ID(r)].life = 120;
create_gain_photon(i); 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: case PT_NEUT:
if (TYP(r) == PT_GLAS || TYP(r) == PT_BGLA) if (TYP(r) == PT_GLAS || TYP(r) == PT_BGLA)
if (random_gen()%10) if (RNG::Ref().chance(9, 10))
create_cherenkov_photon(i); create_cherenkov_photon(i);
break; break;
case PT_ELEC: 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; parts[i].life = 75;
break; break;
case PT_WARP: case PT_WARP:
parts[i].life = random_gen()%95+70; parts[i].life = RNG::Ref().between(70, 164);
break; break;
case PT_FUSE: case PT_FUSE:
parts[i].life = 50; 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; parts[i].life = 10;
break; break;
case PT_SING: case PT_SING:
parts[i].life = random_gen()%50+60; parts[i].life = RNG::Ref().between(60, 109);
break; break;
case PT_QRTZ: case PT_QRTZ:
case PT_PQRT: case PT_PQRT:
parts[i].tmp2 = (random_gen()%11); parts[i].tmp2 = RNG::Ref().between(0, 10);
break; break;
case PT_CLST: case PT_CLST:
parts[i].tmp = (random_gen()%7); parts[i].tmp = RNG::Ref().between(0, 6);
break; break;
case PT_FSEP: case PT_FSEP:
parts[i].life = 50; 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; parts[i].life = 110;
break; break;
case PT_FIRE: case PT_FIRE:
parts[i].life = random_gen()%50+120; parts[i].life = RNG::Ref().between(120, 169);
break; break;
case PT_PLSM: case PT_PLSM:
parts[i].life = random_gen()%150+50; parts[i].life = RNG::Ref().between(50, 199);
break; break;
case PT_CFLM: case PT_CFLM:
parts[i].life = random_gen()%150+50; parts[i].life = RNG::Ref().between(50, 199);
break; break;
case PT_LAVA: case PT_LAVA:
parts[i].life = random_gen()%120+240; parts[i].life = RNG::Ref().between(240, 359);
break; break;
case PT_NBLE: case PT_NBLE:
parts[i].life = 0; 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; parts[i].pavg[1] = 250;
break; break;
case PT_CRMC: case PT_CRMC:
parts[i].tmp2 = (random_gen() % 5); parts[i].tmp2 = RNG::Ref().between(0, 4);
break; break;
case PT_ETRD: case PT_ETRD:
etrd_life0_count++; etrd_life0_count++;
@ -3403,7 +3401,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
} }
case PT_PHOT: 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].life = 680;
parts[i].ctype = 0x3FFFFFFF; parts[i].ctype = 0x3FFFFFFF;
parts[i].vx = 3.0f*cosf(a); parts[i].vx = 3.0f*cosf(a);
@ -3414,7 +3412,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
} }
case PT_ELEC: 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].life = 680;
parts[i].vx = 2.0f*cosf(a); parts[i].vx = 2.0f*cosf(a);
parts[i].vy = 2.0f*sinf(a); parts[i].vy = 2.0f*sinf(a);
@ -3422,16 +3420,16 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
} }
case PT_NEUT: case PT_NEUT:
{ {
float r = (random_gen()%128+128)/127.0f; float r = RNG::Ref().between(128, 255) / 127.0f;
float a = (random_gen()%360)*3.14159f/180.0f; float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].life = random_gen()%480+480; parts[i].life = RNG::Ref().between(480, 959);
parts[i].vx = r*cosf(a); parts[i].vx = r*cosf(a);
parts[i].vy = r*sinf(a); parts[i].vy = r*sinf(a);
break; break;
} }
case PT_PROT: 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].life = 680;
parts[i].vx = 2.0f*cosf(a); parts[i].vx = 2.0f*cosf(a);
parts[i].vy = 2.0f*sinf(a); parts[i].vy = 2.0f*sinf(a);
@ -3439,8 +3437,8 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
} }
case PT_GRVT: case PT_GRVT:
{ {
float a = (random_gen()%360)*3.14159f/180.0f; float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].life = 250 + random_gen()%200; parts[i].life = RNG::Ref().between(250, 449);
parts[i].vx = 2.0f*cosf(a); parts[i].vx = 2.0f*cosf(a);
parts[i].vy = 2.0f*sinf(a); parts[i].vy = 2.0f*sinf(a);
parts[i].tmp = 7; parts[i].tmp = 7;
@ -3448,8 +3446,8 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
} }
case PT_TRON: case PT_TRON:
{ {
int randhue = random_gen()%360; int randhue = RNG::Ref().between(0, 359);
int randomdir = random_gen()%4; int randomdir = RNG::Ref().between(0, 3);
parts[i].tmp = 1|(randomdir<<5)|(randhue<<7);//set as a head and a direction parts[i].tmp = 1|(randomdir<<5)|(randhue<<7);//set as a head and a direction
parts[i].tmp2 = 4;//tail parts[i].tmp2 = 4;//tail
parts[i].life = 5; 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; gsize = gx*gx+gy*gy;
if (gsize<0.0016f) 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); gsize = sqrtf(gsize);
// randomness in weak gravity fields (more randomness with weaker fields) // randomness in weak gravity fields (more randomness with weaker fields)
gx += cosf(angle)*(0.04f-gsize); gx += cosf(angle)*(0.04f-gsize);
gy += sinf(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; parts[i].tmp2 = 4;
break; 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) if((elements[t].Properties & TYPE_PART) && pretty_powder)
{ {
int colr, colg, colb; int colr, colg, colb;
colr = PIXR(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+(random_gen()%40)-20+(random_gen()%30)-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+(random_gen()%40)-20+(random_gen()%30)-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); colr = colr>255 ? 255 : (colr<0 ? 0 : colr);
colg = colg>255 ? 255 : (colg<0 ? 0 : colg); colg = colg>255 ? 255 : (colg<0 ? 0 : colg);
colb = colb>255 ? 255 : (colb<0 ? 0 : colb); 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]++; elementCount[t]++;
return i; return i;
@ -3541,7 +3539,7 @@ void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLO
return; return;
i = pfree; i = pfree;
lr = random_gen() % 2; lr = RNG::Ref().between(0, 1);
if (lr) { if (lr) {
xx = parts[pp].x - 0.3*parts[pp].vy; 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; pfree = parts[i].life;
if (i>parts_lastActiveIndex) parts_lastActiveIndex = i; if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
lr = random_gen() % 2; lr = RNG::Ref().between(0, 1);
parts[i].type = PT_PHOT; parts[i].type = PT_PHOT;
parts[i].ctype = 0x00000F80; parts[i].ctype = 0x00000F80;
@ -3775,11 +3773,11 @@ void Simulation::UpdateParticles(int start, int end)
{ {
#ifdef REALISTIC #ifdef REALISTIC
//The magic number controls diffusion speed //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].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*random_gen.uniform01()-1.0f); parts[i].vy += 0.05*sqrtf(parts[i].temp)*elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f);
#else #else
parts[i].vx += 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*random_gen.uniform01()-1.0f); parts[i].vy += elements[t].Diffusion*(2.0f*RNG::Ref().uniform01()-1.0f);
#endif #endif
} }
@ -3804,7 +3802,7 @@ void Simulation::UpdateParticles(int start, int end)
if (!legacy_enable) 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]; r = pmap[y-2][x];
if (!(!r || parts[i].type != TYP(r))) { if (!(!r || parts[i].type != TYP(r))) {
if (parts[i].temp>parts[ID(r)].temp) { if (parts[i].temp>parts[ID(r)].temp) {
@ -3820,7 +3818,7 @@ void Simulation::UpdateParticles(int start, int end)
#ifdef REALISTIC #ifdef REALISTIC
if (t&&(t!=PT_HSWC||parts[i].life==10)&&(elements[t].HeatConduct*gel_scale)) if (t&&(t!=PT_HSWC||parts[i].life==10)&&(elements[t].HeatConduct*gel_scale))
#else #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 #endif
{ {
if (aheat_enable && !(elements[t].Properties&PROP_NOAMBHEAT)) if (aheat_enable && !(elements[t].Properties&PROP_NOAMBHEAT))
@ -3977,8 +3975,10 @@ void Simulation::UpdateParticles(int start, int end)
{ {
pt = (c_heat - platent[t])/c_Cm; pt = (c_heat - platent[t])/c_Cm;
if (random_gen()%4==0) t = PT_SALT; if (RNG::Ref().chance(1, 4))
else t = PT_WTRV; t = PT_SALT;
else
t = PT_WTRV;
} }
else else
{ {
@ -3986,7 +3986,7 @@ void Simulation::UpdateParticles(int start, int end)
s = 0; s = 0;
} }
#else #else
if (random_gen()%4 == 0) if (RNG::Ref().chance(1, 4))
t = PT_SALT; t = PT_SALT;
else else
t = PT_WTRV; t = PT_WTRV;
@ -4138,14 +4138,14 @@ void Simulation::UpdateParticles(int start, int end)
goto killed; goto killed;
if (t==PT_FIRE || t==PT_PLSM || t==PT_CFLM) 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 (t == PT_LAVA)
{ {
if (parts[i].ctype == PT_BRMT) parts[i].ctype = PT_BMTL; 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_SAND) parts[i].ctype = PT_GLAS;
else if (parts[i].ctype == PT_BGLA) 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; 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; transitionOccurred = true;
} }
@ -4219,7 +4219,7 @@ void Simulation::UpdateParticles(int start, int end)
//the basic explosion, from the .explosive variable //the basic explosion, from the .explosive variable
if ((elements[t].Explosive&2) && pv[y/CELL][x/CELL]>2.5f) 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); parts[i].temp = restrict_flt(elements[PT_FIRE].Temperature + (elements[t].Flammable/2), MIN_TEMP, MAX_TEMP);
t = PT_FIRE; t = PT_FIRE;
part_change_type(i,x,y,t); 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)) if (part_change_type(i,x,y,t))
goto killed; goto killed;
if (t == PT_FIRE) if (t == PT_FIRE)
parts[i].life = random_gen()%50+120; parts[i].life = RNG::Ref().between(120, 169);
transitionOccurred = true; transitionOccurred = true;
} }
@ -4548,7 +4548,7 @@ killed:
continue; continue;
// reflection // reflection
parts[i].flags |= FLAG_STAGNANT; 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); kill_part(i);
continue; continue;
@ -4573,7 +4573,7 @@ killed:
{ {
if (TYP(r) == PT_CRMC) 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; r = r * r * r;
rx = cosf(r); ry = sinf(r); rx = cosf(r); ry = sinf(r);
anrx = rx * nrx + ry * nry; anrx = rx * nrx + ry * nry;
@ -4634,7 +4634,8 @@ killed:
} }
else 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)) if (!flood_water(x,y,i,y, parts[i].flags&FLAG_WATEREQUAL))
goto movedone; goto movedone;
@ -4657,7 +4658,7 @@ killed:
else else
{ {
s = 1; 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) && if ((clear_x!=x || clear_y!=y || nt || surround_space) &&
(fabsf(parts[i].vx)>0.01f || fabsf(parts[i].vy)>0.01f)) (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 // 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(); CheckStacking();
} }

View File

@ -65,7 +65,7 @@ int Element_AMTR::update(UPDATE_FUNC_ARGS)
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
} }
if (!(random_gen()%10)) if (RNG::Ref().chance(1, 10))
sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); sim->create_part(ID(r), x+rx, y+ry, PT_PHOT);
else else
sim->kill_part(ID(r)); sim->kill_part(ID(r));

View File

@ -58,10 +58,10 @@ int Element_ANAR::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; 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); 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; parts[ID(r)].temp = parts[i].temp = 0;
sim->pv[y/CELL][x/CELL] -= 0.5; sim->pv[y/CELL][x/CELL] -= 0.5;
} }

View File

@ -50,7 +50,7 @@ Element_BCLN::Element_BCLN()
int Element_BCLN::update(UPDATE_FUNC_ARGS) int Element_BCLN::update(UPDATE_FUNC_ARGS)
{ {
if (!parts[i].life && sim->pv[y/CELL][x/CELL]>4.0f) if (!parts[i].life && sim->pv[y/CELL][x/CELL]>4.0f)
parts[i].life = random_gen()%40+80; parts[i].life = RNG::Ref().between(80, 119);
if (parts[i].life) if (parts[i].life)
{ {
parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL];
@ -80,11 +80,12 @@ int Element_BCLN::update(UPDATE_FUNC_ARGS)
} }
} }
} }
else { else
if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_LIFE, parts[i].tmp); {
else if (parts[i].ctype!=PT_LIGH || (random_gen()%30)==0) if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_LIFE, parts[i].tmp);
else if (parts[i].ctype!=PT_LIGH || RNG::Ref().chance(1, 30))
{ {
int np = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, TYP(parts[i].ctype)); int np = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), TYP(parts[i].ctype));
if (np>=0) if (np>=0)
{ {
if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)

View File

@ -58,14 +58,14 @@ int Element_BMTL::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_METL || TYP(r)==PT_IRON) && !(random_gen()%100)) if ((TYP(r)==PT_METL || TYP(r)==PT_IRON) && RNG::Ref().chance(1, 100))
{ {
sim->part_change_type(ID(r),x+rx,y+ry,PT_BMTL); sim->part_change_type(ID(r),x+rx,y+ry,PT_BMTL);
parts[ID(r)].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(random_gen()%5);//random_gen()/(RAND_MAX/300)+100; parts[ID(r)].tmp = (parts[i].tmp<=7) ? parts[i].tmp=1 : parts[i].tmp - RNG::Ref().between(0, 4);
} }
} }
} }
else if (parts[i].tmp==1 && !(random_gen()%1000)) else if (parts[i].tmp==1 && RNG::Ref().chance(1, 1000))
{ {
parts[i].tmp = 0; parts[i].tmp = 0;
sim->part_change_type(i,x,y,PT_BRMT); sim->part_change_type(i,x,y,PT_BRMT);

View File

@ -70,12 +70,12 @@ int Element_BOYL::update(UPDATE_FUNC_ARGS)
continue; continue;
if (TYP(r)==PT_WATR) if (TYP(r)==PT_WATR)
{ {
if (!(random_gen()%30)) if (RNG::Ref().chance(1, 30))
sim->part_change_type(ID(r),x+rx,y+ry,PT_FOG); sim->part_change_type(ID(r),x+rx,y+ry,PT_FOG);
} }
else if (TYP(r)==PT_O2) else if (TYP(r)==PT_O2)
{ {
if (!(random_gen()%9)) if (RNG::Ref().chance(1, 9))
{ {
sim->kill_part(ID(r)); sim->kill_part(ID(r));
sim->part_change_type(i,x,y,PT_WATR); sim->part_change_type(i,x,y,PT_WATR);

View File

@ -51,7 +51,7 @@ int Element_BREC::update(UPDATE_FUNC_ARGS)
{ {
if (sim->pv[y/CELL][x/CELL]>10.0f) if (sim->pv[y/CELL][x/CELL]>10.0f)
{ {
if (parts[i].temp>9000 && sim->pv[y/CELL][x/CELL]>30.0f && !(random_gen()%200)) if (parts[i].temp>9000 && sim->pv[y/CELL][x/CELL]>30.0f && RNG::Ref().chance(1, 200))
{ {
sim->part_change_type(i, x ,y ,PT_EXOT); sim->part_change_type(i, x ,y ,PT_EXOT);
parts[i].life = 1000; parts[i].life = 1000;

View File

@ -60,16 +60,14 @@ int Element_BRMT::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if (TYP(r)==PT_BREC && !(random_gen()%tempFactor)) if (TYP(r)==PT_BREC && RNG::Ref().chance(1, tempFactor))
{ {
if(random_gen()%2) if (RNG::Ref().chance(1, 2))
{ {
sim->create_part(ID(r), x+rx, y+ry, PT_THRM); sim->create_part(ID(r), x+rx, y+ry, PT_THRM);
} }
else else
sim->create_part(i, x, y, PT_THRM); sim->create_part(i, x, y, PT_THRM);
//part_change_type(ID(r),x+rx,y+ry,PT_BMTL);
//parts[ID(r)].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(random_gen()%5);//random_gen()/(RAND_MAX/300)+100;
} }
} }
} }

View File

@ -58,11 +58,11 @@ int Element_C5::update(UPDATE_FUNC_ARGS)
continue; continue;
if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||parts[ID(r)].life==10)) || TYP(r)==PT_CFLM) if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||parts[ID(r)].life==10)) || TYP(r)==PT_CFLM)
{ {
if (!(random_gen()%6)) if (RNG::Ref().chance(1, 6))
{ {
sim->part_change_type(i,x,y,PT_CFLM); sim->part_change_type(i,x,y,PT_CFLM);
parts[ID(r)].temp = parts[i].temp = 0; parts[ID(r)].temp = parts[i].temp = 0;
parts[i].life = random_gen()%150+50; parts[i].life = RNG::Ref().between(50, 199);
sim->pv[y/CELL][x/CELL] += 1.5; sim->pv[y/CELL][x/CELL] += 1.5;
} }
} }

View File

@ -64,7 +64,7 @@ int Element_CAUS::update(UPDATE_FUNC_ARGS)
} }
else if (TYP(r) != PT_ACID && TYP(r) != PT_CAUS && TYP(r) != PT_RFRG && TYP(r) != PT_RFGL) else if (TYP(r) != PT_ACID && TYP(r) != PT_CAUS && TYP(r) != PT_RFRG && TYP(r) != PT_RFGL)
{ {
if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && (unsigned int)sim->elements[TYP(r)].Hardness > (random_gen()%1000)) && parts[i].life >= 50) if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && RNG::Ref().chance(sim->elements[TYP(r)].Hardness, 1000)) && parts[i].life >= 50)
{ {
// GLAS protects stuff from acid // GLAS protects stuff from acid
if (sim->parts_avg(i, ID(r),PT_GLAS) != PT_GLAS) if (sim->parts_avg(i, ID(r),PT_GLAS) != PT_GLAS)

View File

@ -51,7 +51,7 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
int r, rx, ry; int r, rx, ry;
if (sim->pv[y/CELL][x/CELL]<=3) if (sim->pv[y/CELL][x/CELL]<=3)
{ {
if (sim->pv[y/CELL][x/CELL] <= -0.5 || !(random_gen()%4000)) if (sim->pv[y/CELL][x/CELL] <= -0.5 || RNG::Ref().chance(1, 4000))
{ {
sim->part_change_type(i,x,y,PT_CO2); sim->part_change_type(i,x,y,PT_CO2);
parts[i].ctype = 5; parts[i].ctype = 5;
@ -61,15 +61,15 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
if (parts[i].tmp2!=20) { if (parts[i].tmp2!=20) {
parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1; parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1;
} }
else if(!(random_gen()%200)) else if (RNG::Ref().chance(1, 200))
{ {
parts[i].tmp2 = random_gen()%40; parts[i].tmp2 = RNG::Ref().between(0, 39);
} }
if(parts[i].tmp>0) if(parts[i].tmp>0)
{ {
//Explode //Explode
if(parts[i].tmp==1 && random_gen()%4) if(parts[i].tmp==1 && RNG::Ref().chance(3, 4))
{ {
sim->part_change_type(i,x,y,PT_CO2); sim->part_change_type(i,x,y,PT_CO2);
parts[i].ctype = 5; parts[i].ctype = 5;
@ -84,12 +84,12 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((sim->elements[TYP(r)].Properties&TYPE_PART) && parts[i].tmp == 0 && !(random_gen()%83)) if ((sim->elements[TYP(r)].Properties&TYPE_PART) && parts[i].tmp == 0 && RNG::Ref().chance(1, 83))
{ {
//Start explode //Start explode
parts[i].tmp = random_gen()%25;//(random_gen()%100)+50; parts[i].tmp = RNG::Ref().between(0, 24);
} }
else if((sim->elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && (2-sim->pv[y/CELL][x/CELL])>(random_gen()%6667)) else if((sim->elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && RNG::Ref().chance(2 - sim->pv[y/CELL][x/CELL], 6667))
{ {
sim->part_change_type(i,x,y,PT_CO2); sim->part_change_type(i,x,y,PT_CO2);
parts[i].ctype = 5; parts[i].ctype = 5;
@ -115,7 +115,7 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
} }
else if (TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) else if (TYP(r)==PT_RBDM||TYP(r)==PT_LRBD)
{ {
if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(random_gen()%166)) if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && RNG::Ref().chance(1, 166))
{ {
sim->part_change_type(i,x,y,PT_FIRE); sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4; parts[i].life = 4;
@ -124,7 +124,8 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
} }
else if (TYP(r)==PT_FIRE && parts[ID(r)].ctype!=PT_WATR){ else if (TYP(r)==PT_FIRE && parts[ID(r)].ctype!=PT_WATR){
sim->kill_part(ID(r)); sim->kill_part(ID(r));
if(!(random_gen()%50)){ if (RNG::Ref().chance(1, 50))
{
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
} }

View File

@ -71,11 +71,12 @@ int Element_CLNE::update(UPDATE_FUNC_ARGS)
} }
} }
} }
else { else
if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_LIFE, parts[i].tmp); {
else if (parts[i].ctype!=PT_LIGH || (random_gen()%30)==0) if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x + RNG::Ref().chance(-1, 1), y + RNG::Ref().chance(-1, 1), PT_LIFE, parts[i].tmp);
else if (parts[i].ctype!=PT_LIGH || RNG::Ref().chance(1, 30))
{ {
int np = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, TYP(parts[i].ctype)); int np = sim->create_part(-1, x + RNG::Ref().chance(-1, 1), y + RNG::Ref().chance(-1, 1), TYP(parts[i].ctype));
if (np>=0) if (np>=0)
{ {
if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && sim->elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)

View File

@ -59,7 +59,7 @@ int Element_CLST::update(UPDATE_FUNC_ARGS)
continue; continue;
if (TYP(r)==PT_WATR) if (TYP(r)==PT_WATR)
{ {
if (!(random_gen()%1500)) if (RNG::Ref().chance(1, 1500))
{ {
sim->create_part(i, x, y, PT_PSTS); sim->create_part(i, x, y, PT_PSTS);
sim->kill_part(ID(r)); sim->kill_part(ID(r));

View File

@ -55,21 +55,23 @@ int Element_CO2::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
{ {
if (parts[i].ctype==5 && !(random_gen()%2000)) if (parts[i].ctype==5 && RNG::Ref().chance(1, 2000))
{ {
if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0) if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0)
parts[i].ctype = 0; parts[i].ctype = 0;
} }
continue; continue;
} }
if (TYP(r)==PT_FIRE){ if (TYP(r)==PT_FIRE)
{
sim->kill_part(ID(r)); sim->kill_part(ID(r));
if(!(random_gen()%30)){ if (RNG::Ref().chance(1, 30))
{
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
} }
} }
else if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && !(random_gen()%50)) else if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(1, 50))
{ {
sim->part_change_type(ID(r), x+rx, y+ry, PT_CBNW); sim->part_change_type(ID(r), x+rx, y+ry, PT_CBNW);
if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet
@ -86,14 +88,14 @@ int Element_CO2::update(UPDATE_FUNC_ARGS)
} }
if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f) if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f)
{ {
if (!(random_gen()%5)) if (RNG::Ref().chance(1, 5))
{ {
int j; int j;
sim->create_part(i,x,y,PT_O2); sim->create_part(i,x,y,PT_O2);
j = sim->create_part(-3,x,y,PT_NEUT); j = sim->create_part(-3,x,y,PT_NEUT);
if (j != -1) if (j != -1)
parts[j].temp = MAX_TEMP; parts[j].temp = MAX_TEMP;
if (!(random_gen()%50)) if (RNG::Ref().chance(1, 50))
{ {
j = sim->create_part(-3,x,y,PT_ELEC); j = sim->create_part(-3,x,y,PT_ELEC);
if (j != -1) if (j != -1)

View File

@ -54,7 +54,7 @@ int Element_COAL::update(UPDATE_FUNC_ARGS)
return 1; return 1;
} else if (parts[i].life < 100) { } else if (parts[i].life < 100) {
parts[i].life--; parts[i].life--;
sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_FIRE); sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_FIRE);
} }
if (parts[i].type == PT_COAL) if (parts[i].type == PT_COAL)
{ {

View File

@ -48,8 +48,8 @@ Element_DEST::Element_DEST()
//#TPT-Directive ElementHeader Element_DEST static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_DEST static int update(UPDATE_FUNC_ARGS)
int Element_DEST::update(UPDATE_FUNC_ARGS) int Element_DEST::update(UPDATE_FUNC_ARGS)
{ {
int rx = random_gen()%5-2; int rx = RNG::Ref().between(-2, 2);
int ry = random_gen()%5-2; int ry = RNG::Ref().between(-2, 2);
int r = pmap[y+ry][x+rx]; int r = pmap[y+ry][x+rx];
if (!r) if (!r)
return 0; return 0;
@ -59,13 +59,13 @@ int Element_DEST::update(UPDATE_FUNC_ARGS)
if (parts[i].life<=0 || parts[i].life>37) if (parts[i].life<=0 || parts[i].life>37)
{ {
parts[i].life=30+random_gen()%20; parts[i].life = RNG::Ref().between(30, 59);
sim->pv[y/CELL][x/CELL]+=60.0f; sim->pv[y/CELL][x/CELL]+=60.0f;
} }
if (rt == PT_PLUT || rt == PT_DEUT) if (rt == PT_PLUT || rt == PT_DEUT)
{ {
sim->pv[y/CELL][x/CELL]+=20.0f; sim->pv[y/CELL][x/CELL]+=20.0f;
if (random_gen()%2) if (RNG::Ref().chance(1, 2))
{ {
sim->create_part(ID(r), x+rx, y+ry, PT_NEUT); sim->create_part(ID(r), x+rx, y+ry, PT_NEUT);
parts[ID(r)].temp = MAX_TEMP; parts[ID(r)].temp = MAX_TEMP;
@ -77,7 +77,7 @@ int Element_DEST::update(UPDATE_FUNC_ARGS)
{ {
sim->create_part(ID(r), x+rx, y+ry, PT_PLSM); sim->create_part(ID(r), x+rx, y+ry, PT_PLSM);
} }
else if (!(random_gen()%3)) else if (RNG::Ref().chance(1, 3))
{ {
sim->kill_part(ID(r)); sim->kill_part(ID(r));
parts[i].life -= 4*((sim->elements[rt].Properties&TYPE_SOLID)?3:1); parts[i].life -= 4*((sim->elements[rt].Properties&TYPE_SOLID)?3:1);

View File

@ -51,8 +51,8 @@ int Element_DEUT::update(UPDATE_FUNC_ARGS)
int r, rx, ry, trade, np; int r, rx, ry, trade, np;
float gravtot = fabs(sim->gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(sim->gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]); float gravtot = fabs(sim->gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(sim->gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
int maxlife = ((10000/(parts[i].temp + 1))-1); int maxlife = ((10000/(parts[i].temp + 1))-1);
if ((10000%((int)parts[i].temp + 1))>random_gen()%((int)parts[i].temp + 1)) if (RNG::Ref().chance(10000 % static_cast<int>(parts[i].temp + 1), static_cast<int>(parts[i].temp + 1)))
maxlife ++; maxlife++;
// Compress when Newtonian gravity is applied // Compress when Newtonian gravity is applied
// multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf
maxlife = maxlife*(5.0f - 8.0f/(gravtot+2.0f)); maxlife = maxlife*(5.0f - 8.0f/(gravtot+2.0f));
@ -65,7 +65,7 @@ int Element_DEUT::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r || (parts[i].life >=maxlife)) if (!r || (parts[i].life >=maxlife))
continue; continue;
if (TYP(r)==PT_DEUT&& !(random_gen()%3)) if (TYP(r)==PT_DEUT&& RNG::Ref().chance(1, 3))
{ {
// If neighbour life+1 fits in the free capacity for this particle, absorb neighbour // If neighbour life+1 fits in the free capacity for this particle, absorb neighbour
// Condition is written in this way so that large neighbour life values don't cause integer overflow // Condition is written in this way so that large neighbour life values don't cause integer overflow
@ -98,8 +98,8 @@ int Element_DEUT::update(UPDATE_FUNC_ARGS)
trade: trade:
for ( trade = 0; trade<4; trade ++) for ( trade = 0; trade<4; trade ++)
{ {
rx = random_gen()%5-2; rx = RNG::Ref().between(-2, 2);
ry = random_gen()%5-2; ry = RNG::Ref().between(-2, 2);
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];

View File

@ -56,29 +56,29 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
switch (TYP(r)) switch (TYP(r))
{ {
case PT_SALT: case PT_SALT:
if (!(random_gen()%50)) if (RNG::Ref().chance(1, 50))
{ {
sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(i,x,y,PT_SLTW);
// on average, convert 3 DSTW to SLTW before SALT turns into SLTW // on average, convert 3 DSTW to SLTW before SALT turns into SLTW
if (!(random_gen()%3)) if (RNG::Ref().chance(1, 3))
sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW);
} }
break; break;
case PT_SLTW: case PT_SLTW:
if (!(random_gen()%2000)) if (RNG::Ref().chance(1, 2000))
{ {
sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(i,x,y,PT_SLTW);
break; break;
} }
case PT_WATR: case PT_WATR:
if (!(random_gen()%100)) if (RNG::Ref().chance(1, 100))
{ {
sim->part_change_type(i,x,y,PT_WATR); sim->part_change_type(i,x,y,PT_WATR);
} }
break; break;
case PT_RBDM: case PT_RBDM:
case PT_LRBD: case PT_LRBD:
if ((sim->legacy_enable||parts[i].temp>12.0f) && !(random_gen()%100)) if ((sim->legacy_enable||parts[i].temp>12.0f) && RNG::Ref().chance(1, 100))
{ {
sim->part_change_type(i,x,y,PT_FIRE); sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4; parts[i].life = 4;
@ -86,7 +86,8 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
break; break;
case PT_FIRE: case PT_FIRE:
sim->kill_part(ID(r)); sim->kill_part(ID(r));
if(!(random_gen()%30)){ if (RNG::Ref().chance(1, 30))
{
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
} }

View File

@ -76,13 +76,13 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS)
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
case PT_LCRY: case PT_LCRY:
parts[ID(r)].tmp2 = 5+random_gen()%5; parts[ID(r)].tmp2 = RNG::Ref().between(5, 9);
break; break;
case PT_WATR: case PT_WATR:
case PT_DSTW: case PT_DSTW:
case PT_SLTW: case PT_SLTW:
case PT_CBNW: case PT_CBNW:
if(!(random_gen()%3)) if (RNG::Ref().chance(1, 3))
sim->create_part(ID(r), x+rx, y+ry, PT_O2); sim->create_part(ID(r), x+rx, y+ry, PT_O2);
else else
sim->create_part(ID(r), x+rx, y+ry, PT_H2); sim->create_part(ID(r), x+rx, y+ry, PT_H2);

View File

@ -67,7 +67,7 @@ public:
} }
void apply(Simulation *sim, Particle &p) void apply(Simulation *sim, Particle &p)
{ {
p.temp = restrict_flt(p.temp+getDelta(random_gen.uniform01()), MIN_TEMP, MAX_TEMP); p.temp = restrict_flt(p.temp+getDelta(RNG::Ref().uniform01()), MIN_TEMP, MAX_TEMP);
} }
}; };
@ -120,9 +120,9 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount)
{ {
is_elec = true; is_elec = true;
temp_center.apply(sim, parts[r]); temp_center.apply(sim, parts[r]);
if (random_gen.uniform01() < prob_changeCenter) if (RNG::Ref().uniform01() < prob_changeCenter)
{ {
if (random_gen()%5 < 2) if (RNG::Ref().chance(2, 5))
sim->part_change_type(r, rx, ry, PT_BREC); sim->part_change_type(r, rx, ry, PT_BREC);
else else
sim->part_change_type(r, rx, ry, PT_NTCT); sim->part_change_type(r, rx, ry, PT_NTCT);
@ -145,10 +145,10 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount)
{ {
case PT_METL: case PT_METL:
temp_metal.apply(sim, parts[n]); temp_metal.apply(sim, parts[n]);
if (random_gen.uniform01() < prob_breakMETL) if (RNG::Ref().uniform01() < prob_breakMETL)
{ {
sim->part_change_type(n, rx+nx, ry+ny, PT_BMTL); sim->part_change_type(n, rx+nx, ry+ny, PT_BMTL);
if (random_gen.uniform01() < prob_breakMETLMore) if (RNG::Ref().uniform01() < prob_breakMETLMore)
{ {
sim->part_change_type(n, rx+nx, ry+ny, PT_BRMT); sim->part_change_type(n, rx+nx, ry+ny, PT_BRMT);
parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP);
@ -157,19 +157,19 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount)
break; break;
case PT_BMTL: case PT_BMTL:
temp_metal.apply(sim, parts[n]); temp_metal.apply(sim, parts[n]);
if (random_gen.uniform01() < prob_breakBMTL) if (RNG::Ref().uniform01() < prob_breakBMTL)
{ {
sim->part_change_type(n, rx+nx, ry+ny, PT_BRMT); sim->part_change_type(n, rx+nx, ry+ny, PT_BRMT);
parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP);
} }
break; break;
case PT_WIFI: case PT_WIFI:
if (random_gen.uniform01() < prob_randWIFI) if (RNG::Ref().uniform01() < prob_randWIFI)
{ {
// Randomize channel // Randomize channel
parts[n].temp = random_gen()%MAX_TEMP; parts[n].temp = RNG::Ref().between(0, MAX_TEMP-1);
} }
if (random_gen.uniform01() < prob_breakWIFI) if (RNG::Ref().uniform01() < prob_breakWIFI)
{ {
sim->create_part(n, rx+nx, ry+ny, PT_BREC); sim->create_part(n, rx+nx, ry+ny, PT_BREC);
parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP);
@ -182,22 +182,22 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount)
switch (ntype) switch (ntype)
{ {
case PT_SWCH: case PT_SWCH:
if (random_gen.uniform01() < prob_breakSWCH) if (RNG::Ref().uniform01() < prob_breakSWCH)
sim->part_change_type(n, rx+nx, ry+ny, PT_BREC); sim->part_change_type(n, rx+nx, ry+ny, PT_BREC);
temp_SWCH.apply(sim, parts[n]); temp_SWCH.apply(sim, parts[n]);
break; break;
case PT_ARAY: case PT_ARAY:
if (random_gen.uniform01() < prob_breakARAY) if (RNG::Ref().uniform01() < prob_breakARAY)
{ {
sim->create_part(n, rx+nx, ry+ny, PT_BREC); sim->create_part(n, rx+nx, ry+ny, PT_BREC);
parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP);
} }
break; break;
case PT_DLAY: case PT_DLAY:
if (random_gen.uniform01() < prob_randDLAY) if (RNG::Ref().uniform01() < prob_randDLAY)
{ {
// Randomize delay // Randomize delay
parts[n].temp = (random_gen()%256) + 273.15f; parts[n].temp = RNG::Ref().between(0, 255) + 273.15f;
} }
break; break;
default: default:

View File

@ -59,7 +59,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS)
rt = TYP(r); rt = TYP(r);
if (rt == PT_WARP) if (rt == PT_WARP)
{ {
if (parts[ID(r)].tmp2>2000 && !(random_gen()%100)) if (parts[ID(r)].tmp2>2000 && RNG::Ref().chance(1, 100))
{ {
parts[i].tmp2 += 100; parts[i].tmp2 += 100;
} }
@ -68,7 +68,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS)
{ {
if (parts[ID(r)].ctype == PT_PROT) if (parts[ID(r)].ctype == PT_PROT)
parts[i].ctype = PT_PROT; parts[i].ctype = PT_PROT;
if (parts[ID(r)].life == 1500 && !(random_gen()%1000)) if (parts[ID(r)].life == 1500 && RNG::Ref().chance(1, 1000))
parts[i].life = 1500; parts[i].life = 1500;
} }
else if (rt == PT_LAVA) else if (rt == PT_LAVA)
@ -76,7 +76,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS)
//turn molten TTAN or molten GOLD to molten VIBR //turn molten TTAN or molten GOLD to molten VIBR
if (parts[ID(r)].ctype == PT_TTAN || parts[ID(r)].ctype == PT_GOLD) if (parts[ID(r)].ctype == PT_TTAN || parts[ID(r)].ctype == PT_GOLD)
{ {
if (!(random_gen()%10)) if (RNG::Ref().chance(1, 10))
{ {
parts[ID(r)].ctype = PT_VIBR; parts[ID(r)].ctype = PT_VIBR;
sim->kill_part(i); sim->kill_part(i);
@ -86,7 +86,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS)
//molten VIBR will kill the leftover EXOT though, so the VIBR isn't killed later //molten VIBR will kill the leftover EXOT though, so the VIBR isn't killed later
else if (parts[ID(r)].ctype == PT_VIBR) else if (parts[ID(r)].ctype == PT_VIBR)
{ {
if (!(random_gen()%1000)) if (RNG::Ref().chance(1, 1000))
{ {
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
@ -131,8 +131,8 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS)
{ {
for (trade = 0; trade < 9; trade++) for (trade = 0; trade < 9; trade++)
{ {
rx = random_gen()%5-2; rx = RNG::Ref().between(-2, 2);
ry = random_gen()%5-2; ry = RNG::Ref().between(-2, 2);
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
@ -186,7 +186,7 @@ int Element_EXOT::graphics(GRAPHICS_FUNC_ARGS)
int c = cpart->tmp2; int c = cpart->tmp2;
if (cpart->life < 1001) if (cpart->life < 1001)
{ {
if ((cpart->tmp2 - 1) > (int)(random_gen()%1000)) if (RNG::Ref().chance(cpart->tmp2 - 1, 1000))
{ {
float frequency = 0.04045; float frequency = 0.04045;
*colr = (sin(frequency*c + 4) * 127 + 150); *colr = (sin(frequency*c + 4) * 127 + 150);

View File

@ -99,15 +99,15 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_WATR||TYP(r)==PT_DSTW||TYP(r)==PT_SLTW) && 1>(random_gen()%1000)) if ((TYP(r)==PT_WATR||TYP(r)==PT_DSTW||TYP(r)==PT_SLTW) && RNG::Ref().chance(1, 1000))
{ {
sim->part_change_type(i,x,y,PT_WATR); sim->part_change_type(i,x,y,PT_WATR);
sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR); sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR);
} }
if ((TYP(r)==PT_ICEI || TYP(r)==PT_SNOW) && 1>(random_gen()%1000)) if ((TYP(r)==PT_ICEI || TYP(r)==PT_SNOW) && RNG::Ref().chance(1, 1000))
{ {
sim->part_change_type(i,x,y,PT_WATR); sim->part_change_type(i,x,y,PT_WATR);
if (1>(random_gen()%1000)) if (RNG::Ref().chance(1, 1000))
sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR); sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR);
} }
} }
@ -121,7 +121,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && 1>(random_gen()%10)) if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && RNG::Ref().chance(1, 10))
{ {
sim->part_change_type(i,x,y,PT_WTRV); sim->part_change_type(i,x,y,PT_WTRV);
} }
@ -136,10 +136,12 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && 1>(random_gen()%10)) if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && RNG::Ref().chance(1, 10))
{ {
if (random_gen()%4==0) sim->part_change_type(i,x,y,PT_SALT); if (RNG::Ref().chance(1, 4))
else sim->part_change_type(i,x,y,PT_WTRV); sim->part_change_type(i,x,y,PT_SALT);
else
sim->part_change_type(i,x,y,PT_WTRV);
} }
} }
} }
@ -152,7 +154,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && 1>(random_gen()%10)) if ((TYP(r)==PT_FIRE || TYP(r)==PT_LAVA) && RNG::Ref().chance(1, 10))
{ {
sim->part_change_type(i,x,y,PT_WTRV); sim->part_change_type(i,x,y,PT_WTRV);
} }
@ -166,7 +168,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && 1>(random_gen()%1000)) if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(1, 1000))
{ {
sim->part_change_type(i,x,y,PT_ICEI); sim->part_change_type(i,x,y,PT_ICEI);
sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI); sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI);
@ -181,12 +183,12 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && 1>(random_gen()%1000)) if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(1, 1000))
{ {
sim->part_change_type(i,x,y,PT_ICEI); sim->part_change_type(i,x,y,PT_ICEI);
sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI); sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI);
} }
if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && 15>(random_gen()%1000)) if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && RNG::Ref().chance(3, 200))
sim->part_change_type(i,x,y,PT_WATR); sim->part_change_type(i,x,y,PT_WATR);
} }
} }
@ -199,7 +201,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) {
if (t==PT_DESL && sim->pv[y/CELL][x/CELL]>12.0f) if (t==PT_DESL && sim->pv[y/CELL][x/CELL]>12.0f)
{ {
sim->part_change_type(i,x,y,PT_FIRE); sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = random_gen()%50+120; parts[i].life = RNG::Ref().between(120, 169);
} }
return 0; return 0;
} }

View File

@ -108,9 +108,9 @@ int Element_FILT::interactWavelengths(Particle* cpart, int origWl)
return (~origWl) & mask; // Invert colours return (~origWl) & mask; // Invert colours
case 9: case 9:
{ {
int t1 = (origWl & 0x0000FF)+(random_gen()%5)-2; int t1 = (origWl & 0x0000FF) + RNG::Ref().between(-2, 2);
int t2 = ((origWl & 0x00FF00)>>8)+(random_gen()%5)-2; int t2 = ((origWl & 0x00FF00)>>8) + RNG::Ref().between(-2, 2);
int t3 = ((origWl & 0xFF0000)>>16)+(random_gen()%5)-2; int t3 = ((origWl & 0xFF0000)>>16) + RNG::Ref().between(-2, 2);
return (origWl & 0xFF000000) | (t3<<16) | (t2<<8) | t1; return (origWl & 0xFF000000) | (t3<<16) | (t2<<8) | t1;
} }
case 10: case 10:

View File

@ -79,7 +79,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS)
else if (parts[i].temp<625) else if (parts[i].temp<625)
{ {
sim->part_change_type(i,x,y,PT_SMKE); sim->part_change_type(i,x,y,PT_SMKE);
parts[i].life = random_gen()%20+250; parts[i].life = RNG::Ref().between(250, 269);
} }
} }
break; break;
@ -98,7 +98,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS)
//THRM burning //THRM burning
if (rt==PT_THRM && (t==PT_FIRE || t==PT_PLSM || t==PT_LAVA)) if (rt==PT_THRM && (t==PT_FIRE || t==PT_PLSM || t==PT_LAVA))
{ {
if (!(random_gen()%500)) { if (RNG::Ref().chance(1, 500)) {
sim->part_change_type(ID(r),x+rx,y+ry,PT_LAVA); sim->part_change_type(ID(r),x+rx,y+ry,PT_LAVA);
parts[ID(r)].ctype = PT_BMTL; parts[ID(r)].ctype = PT_BMTL;
parts[ID(r)].temp = 3500.0f; parts[ID(r)].temp = 3500.0f;
@ -117,13 +117,13 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS)
{ {
if ((t==PT_FIRE || t==PT_PLSM)) if ((t==PT_FIRE || t==PT_PLSM))
{ {
if (parts[ID(r)].life>100 && !(random_gen()%500)) { if (parts[ID(r)].life>100 && RNG::Ref().chance(1, 500)) {
parts[ID(r)].life = 99; parts[ID(r)].life = 99;
} }
} }
else if (t==PT_LAVA) else if (t==PT_LAVA)
{ {
if (parts[i].ctype == PT_IRON && !(random_gen()%500)) { if (parts[i].ctype == PT_IRON && RNG::Ref().chance(1, 500)) {
parts[i].ctype = PT_METL; parts[i].ctype = PT_METL;
sim->kill_part(ID(r)); sim->kill_part(ID(r));
} }
@ -144,7 +144,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS)
} }
else if (rt == PT_HEAC && parts[i].ctype == PT_HEAC) else if (rt == PT_HEAC && parts[i].ctype == PT_HEAC)
{ {
if (parts[ID(r)].temp > sim->elements[PT_HEAC].HighTemperature && random_gen()%200) if (parts[ID(r)].temp > sim->elements[PT_HEAC].HighTemperature)
{ {
sim->part_change_type(ID(r), x+rx, y+ry, PT_LAVA); sim->part_change_type(ID(r), x+rx, y+ry, PT_LAVA);
parts[ID(r)].ctype = PT_HEAC; parts[ID(r)].ctype = PT_HEAC;
@ -153,7 +153,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS)
} }
if ((surround_space || sim->elements[rt].Explosive) && if ((surround_space || sim->elements[rt].Explosive) &&
sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f)) > (random_gen()%1000) && sim->elements[rt].Flammable && RNG::Ref().chance(sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f), 1000) &&
//exceptions, t is the thing causing the spark and rt is what's burning //exceptions, t is the thing causing the spark and rt is what's burning
(t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && rt != PT_INSL)) && (t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && rt != PT_INSL)) &&
(t != PT_PHOT || rt != PT_INSL) && (t != PT_PHOT || rt != PT_INSL) &&
@ -161,7 +161,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS)
{ {
sim->part_change_type(ID(r), x+rx, y+ry, PT_FIRE); sim->part_change_type(ID(r), x+rx, y+ry, PT_FIRE);
parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP);
parts[ID(r)].life = random_gen()%80+180; parts[ID(r)].life = RNG::Ref().between(180, 259);
parts[ID(r)].tmp = parts[ID(r)].ctype = 0; parts[ID(r)].tmp = parts[ID(r)].ctype = 0;
if (sim->elements[rt].Explosive) if (sim->elements[rt].Explosive)
sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; sim->pv[y/CELL][x/CELL] += 0.25f * CFDS;
@ -188,7 +188,10 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) {
lpv = (int)sim->pv[(y+ry)/CELL][(x+rx)/CELL]; lpv = (int)sim->pv[(y+ry)/CELL][(x+rx)/CELL];
if (lpv < 1) lpv = 1; if (lpv < 1) lpv = 1;
if (sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) && (unsigned int)sim->elements[rt].Meltable*lpv>(random_gen()%1000)) if (sim->elements[rt].Meltable &&
((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK)
&& ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR))
&& RNG::Ref().chance(sim->elements[rt].Meltable*lpv, 1000))
{ {
if (t!=PT_LAVA || parts[i].life>0) if (t!=PT_LAVA || parts[i].life>0)
{ {
@ -199,7 +202,7 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) {
else else
parts[ID(r)].ctype = rt; parts[ID(r)].ctype = rt;
sim->part_change_type(ID(r),x+rx,y+ry,PT_LAVA); sim->part_change_type(ID(r),x+rx,y+ry,PT_LAVA);
parts[ID(r)].life = random_gen()%120+240; parts[ID(r)].life = RNG::Ref().between(240, 359);
} }
else else
{ {

View File

@ -68,12 +68,12 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS)
sim->GetGravityField(x, y, sim->elements[PT_FIRW].Gravity, 1.0f, gx, gy); sim->GetGravityField(x, y, sim->elements[PT_FIRW].Gravity, 1.0f, gx, gy);
if (gx*gx+gy*gy < 0.001f) if (gx*gx+gy*gy < 0.001f)
{ {
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)
gx += sinf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; gx += sinf(angle)*sim->elements[PT_FIRW].Gravity*0.5f;
gy += cosf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; gy += cosf(angle)*sim->elements[PT_FIRW].Gravity*0.5f;
} }
parts[i].tmp = 1; parts[i].tmp = 1;
parts[i].life = random_gen()%10+20; parts[i].life = RNG::Ref().between(20, 29);
multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy); multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy);
parts[i].vx -= gx*multiplier; parts[i].vx -= gx*multiplier;
parts[i].vy -= gy*multiplier; parts[i].vy -= gy*multiplier;
@ -91,7 +91,7 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS)
else //if (parts[i].tmp>=2) else //if (parts[i].tmp>=2)
{ {
float angle, magnitude; float angle, magnitude;
int caddress = (random_gen()%200)*3; int caddress = RNG::Ref().between(0, 199) * 3;
int n; int n;
unsigned col = (((firw_data[caddress]))<<16) | (((firw_data[caddress+1]))<<8) | ((firw_data[caddress+2])); unsigned col = (((firw_data[caddress]))<<16) | (((firw_data[caddress+1]))<<8) | ((firw_data[caddress+2]));
for (n=0; n<40; n++) for (n=0; n<40; n++)
@ -99,14 +99,14 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS)
np = sim->create_part(-3, x, y, PT_EMBR); np = sim->create_part(-3, x, y, PT_EMBR);
if (np>-1) if (np>-1)
{ {
magnitude = ((random_gen()%60)+40)*0.05f; magnitude = RNG::Ref().between(40, 99) * 0.05f;
angle = (random_gen()%6284)*0.001f;//(in radians, between 0 and 2*pi) angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)
parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude;
parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude;
parts[np].ctype = col; parts[np].ctype = col;
parts[np].tmp = 1; parts[np].tmp = 1;
parts[np].life = random_gen()%40+70; parts[np].life = RNG::Ref().between(70, 109);
parts[np].temp = (random_gen()%500)+5750.0f; parts[np].temp = RNG::Ref().between(5750, 6249);
parts[np].dcolour = parts[i].dcolour; parts[np].dcolour = parts[i].dcolour;
} }
} }

View File

@ -55,13 +55,13 @@ int Element_FOG::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((sim->elements[TYP(r)].Properties&TYPE_SOLID) && !(random_gen()%10) && parts[i].life==0 && !(TYP(r)==PT_CLNE || TYP(r)==PT_PCLN)) // TODO: should this also exclude BCLN? if ((sim->elements[TYP(r)].Properties&TYPE_SOLID) && RNG::Ref().chance(1, 10) && parts[i].life==0 && !(TYP(r)==PT_CLNE || TYP(r)==PT_PCLN)) // TODO: should this also exclude BCLN?
{ {
sim->part_change_type(i,x,y,PT_RIME); sim->part_change_type(i,x,y,PT_RIME);
} }
if (TYP(r)==PT_SPRK) if (TYP(r)==PT_SPRK)
{ {
parts[i].life += random_gen()%20; parts[i].life += RNG::Ref().between(0, 19);
} }
} }
return 0; return 0;

View File

@ -55,12 +55,12 @@ int Element_FRZW::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if (TYP(r)==PT_WATR && !(random_gen()%14)) if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 14))
{ {
sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW); sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW);
} }
} }
if ((parts[i].life==0 && !(random_gen()%192)) || (100-(parts[i].life)) > (int)(random_gen()%50000)) if ((parts[i].life==0 && RNG::Ref().chance(1, 192)) || RNG::Ref().chance(100-parts[i].life, 50000))
{ {
sim->part_change_type(i,x,y,PT_ICEI); sim->part_change_type(i,x,y,PT_ICEI);
parts[i].ctype=PT_FRZW; parts[i].ctype=PT_FRZW;

View File

@ -55,7 +55,7 @@ int Element_FRZZ::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if (TYP(r)==PT_WATR && !(random_gen()%20)) if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 20))
{ {
sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW); sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW);
parts[ID(r)].life = 100; parts[ID(r)].life = 100;

View File

@ -56,8 +56,8 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS)
} }
else if (parts[i].life < 40) { else if (parts[i].life < 40) {
parts[i].life--; parts[i].life--;
if (!(random_gen()%10)) { if (RNG::Ref().chance(1, 10)) {
r = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_PLSM); r = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_PLSM);
if (r>-1) if (r>-1)
parts[r].life = 50; parts[r].life = 50;
} }
@ -70,7 +70,7 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && parts[i].life>40 && !(random_gen()%15)) if ((TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && parts[i].life>40 && RNG::Ref().chance(1, 15))
{ {
parts[i].life = 39; parts[i].life = 39;
} }

View File

@ -56,8 +56,8 @@ int Element_FUSE::update(UPDATE_FUNC_ARGS)
} }
else if (parts[i].life < 40) { else if (parts[i].life < 40) {
parts[i].life--; parts[i].life--;
if (!(random_gen()%100)) { if (RNG::Ref().chance(1, 100)) {
r = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_PLSM); r = sim->create_part(-1, x + RNG::Ref().chance(-1, 1), y + RNG::Ref().chance(-1, 1), PT_PLSM);
if (r>-1) if (r>-1)
parts[r].life = 50; parts[r].life = 50;
} }
@ -78,7 +78,7 @@ int Element_FUSE::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if (TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+700.0f) && !(random_gen()%20))) if (TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+700.0f) && RNG::Ref().chance(1, 20)))
{ {
if (parts[i].life > 40) if (parts[i].life > 40)
parts[i].life = 39; parts[i].life = 39;

View File

@ -49,14 +49,14 @@ Element_FWRK::Element_FWRK()
//#TPT-Directive ElementHeader Element_FWRK static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_FWRK static int update(UPDATE_FUNC_ARGS)
int Element_FWRK::update(UPDATE_FUNC_ARGS) int Element_FWRK::update(UPDATE_FUNC_ARGS)
{ {
if (parts[i].life == 0 && ((surround_space && parts[i].temp>400 && (9+parts[i].temp/40)>random_gen()%100000) || parts[i].ctype == PT_DUST)) if (parts[i].life == 0 && ((surround_space && parts[i].temp>400 && RNG::Ref().chance(9+parts[i].temp/40, 100000)) || parts[i].ctype == PT_DUST))
{ {
float gx, gy, multiplier, gmax; float gx, gy, multiplier, gmax;
int randTmp; int randTmp;
sim->GetGravityField(x, y, sim->elements[PT_FWRK].Gravity, 1.0f, gx, gy); sim->GetGravityField(x, y, sim->elements[PT_FWRK].Gravity, 1.0f, gx, gy);
if (gx*gx+gy*gy < 0.001f) if (gx*gx+gy*gy < 0.001f)
{ {
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)
gx += sinf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; gx += sinf(angle)*sim->elements[PT_FWRK].Gravity*0.5f;
gy += cosf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; gy += cosf(angle)*sim->elements[PT_FWRK].Gravity*0.5f;
} }
@ -66,15 +66,15 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS)
multiplier = 15.0f/sqrtf(gx*gx+gy*gy); multiplier = 15.0f/sqrtf(gx*gx+gy*gy);
//Some variation in speed parallel to gravity direction //Some variation in speed parallel to gravity direction
randTmp = (random_gen()%200)-100; randTmp = RNG::Ref().between(-100, 100);
gx += gx*randTmp*0.002f; gx += gx*randTmp*0.002f;
gy += gy*randTmp*0.002f; gy += gy*randTmp*0.002f;
//and a bit more variation in speed perpendicular to gravity direction //and a bit more variation in speed perpendicular to gravity direction
randTmp = (random_gen()%200)-100; randTmp = RNG::Ref().between(-100, 100);
gx += -gy*randTmp*0.005f; gx += -gy*randTmp*0.005f;
gy += gx*randTmp*0.005f; gy += gx*randTmp*0.005f;
parts[i].life=random_gen()%10+18; parts[i].life = RNG::Ref().between(18, 27);
parts[i].ctype=0; parts[i].ctype=0;
parts[i].vx -= gx*multiplier; parts[i].vx -= gx*multiplier;
parts[i].vy -= gy*multiplier; parts[i].vy -= gy*multiplier;
@ -83,9 +83,9 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS)
} }
if (parts[i].life<3&&parts[i].life>0) if (parts[i].life<3&&parts[i].life>0)
{ {
int r = (random_gen()%245+11); int r = RNG::Ref().between(11, 255);
int g = (random_gen()%245+11); int g = RNG::Ref().between(11, 255);
int b = (random_gen()%245+11); int b = RNG::Ref().between(11, 255);
int n; int n;
float angle, magnitude; float angle, magnitude;
unsigned col = (r<<16) | (g<<8) | b; unsigned col = (r<<16) | (g<<8) | b;
@ -94,14 +94,14 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS)
int np = sim->create_part(-3, x, y, PT_EMBR); int np = sim->create_part(-3, x, y, PT_EMBR);
if (np>-1) if (np>-1)
{ {
magnitude = ((random_gen()%60)+40)*0.05f; magnitude = RNG::Ref().between(40, 99) * 0.05f;
angle = (random_gen()%6284)*0.001f;//(in radians, between 0 and 2*pi) angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)
parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude; parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude;
parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude;
parts[np].ctype = col; parts[np].ctype = col;
parts[np].tmp = 1; parts[np].tmp = 1;
parts[np].life = random_gen()%40+70; parts[np].life = RNG::Ref().between(70, 109);
parts[np].temp = (random_gen()%500)+5750.0f; parts[np].temp = RNG::Ref().between(5750, 6249);
parts[np].dcolour = parts[i].dcolour; parts[np].dcolour = parts[i].dcolour;
} }
} }

View File

@ -50,10 +50,11 @@ int Element_GEL::update(UPDATE_FUNC_ARGS)
{ {
int r, rx, ry, rt; int r, rx, ry, rt;
bool gel; bool gel;
int absorbChanceDenom; if (parts[i].tmp > 100)
if (parts[i].tmp>100) parts[i].tmp = 100; parts[i].tmp = 100;
if (parts[i].tmp<0) parts[i].tmp = 0; if (parts[i].tmp < 0)
absorbChanceDenom = parts[i].tmp*10 + 500; parts[i].tmp = 0;
int absorbChanceDenom = parts[i].tmp * 10 + 500;
for (rx=-2; rx<3; rx++) for (rx=-2; rx<3; rx++)
for (ry=-2; ry<3; ry++) for (ry=-2; ry<3; ry++)
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
@ -69,31 +70,31 @@ int Element_GEL::update(UPDATE_FUNC_ARGS)
case PT_WATR: case PT_WATR:
case PT_DSTW: case PT_DSTW:
case PT_FRZW: case PT_FRZW:
if (parts[i].tmp<100 && 500>random_gen()%absorbChanceDenom) if (parts[i].tmp<100 && RNG::Ref().chance(500, absorbChanceDenom))
{ {
parts[i].tmp++; parts[i].tmp++;
sim->kill_part(ID(r)); sim->kill_part(ID(r));
} }
break; break;
case PT_PSTE: case PT_PSTE:
if (parts[i].tmp<100 && 20>random_gen()%absorbChanceDenom) if (parts[i].tmp<100 && RNG::Ref().chance(20, absorbChanceDenom))
{ {
parts[i].tmp++; parts[i].tmp++;
sim->create_part(ID(r), x+rx, y+ry, PT_CLST); sim->create_part(ID(r), x+rx, y+ry, PT_CLST);
} }
break; break;
case PT_SLTW: case PT_SLTW:
if (parts[i].tmp<100 && 50>random_gen()%absorbChanceDenom) if (parts[i].tmp<100 && RNG::Ref().chance(50, absorbChanceDenom))
{ {
parts[i].tmp++; parts[i].tmp++;
if (random_gen()%4) if (RNG::Ref().chance(3, 4))
sim->kill_part(ID(r)); sim->kill_part(ID(r));
else else
sim->part_change_type(ID(r), x+rx, y+ry, PT_SALT); sim->part_change_type(ID(r), x+rx, y+ry, PT_SALT);
} }
break; break;
case PT_CBNW: case PT_CBNW:
if (parts[i].tmp<100 && 100>random_gen()%absorbChanceDenom) if (parts[i].tmp < 100 && RNG::Ref().chance(100, absorbChanceDenom))
{ {
parts[i].tmp++; parts[i].tmp++;
sim->part_change_type(ID(r), x+rx, y+ry, PT_CO2); sim->part_change_type(ID(r), x+rx, y+ry, PT_CO2);

View File

@ -56,7 +56,7 @@ int Element_GLOW::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if (TYP(r)==PT_WATR && !(random_gen()%400)) if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 400))
{ {
sim->kill_part(i); sim->kill_part(i);
sim->part_change_type(ID(r),x+rx,y+ry,PT_DEUT); sim->part_change_type(ID(r),x+rx,y+ry,PT_DEUT);

View File

@ -55,7 +55,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS)
static int checkCoordsY[] = { 0, 0, -4, 4 }; static int checkCoordsY[] = { 0, 0, -4, 4 };
//Find nearby rusted iron (BMTL with tmp 1+) //Find nearby rusted iron (BMTL with tmp 1+)
for(int j = 0; j < 8; j++){ for(int j = 0; j < 8; j++){
rndstore = random_gen(); rndstore = RNG::Ref().gen();
rx = (rndstore % 9)-4; rx = (rndstore % 9)-4;
rndstore >>= 4; rndstore >>= 4;
ry = (rndstore % 9)-4; ry = (rndstore % 9)-4;
@ -89,7 +89,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS)
} }
if (TYP(sim->photons[y][x]) == PT_NEUT) if (TYP(sim->photons[y][x]) == PT_NEUT)
{ {
if (!(random_gen()%7)) if (RNG::Ref().chance(1, 7))
{ {
sim->kill_part(ID(sim->photons[y][x])); sim->kill_part(ID(sim->photons[y][x]));
} }
@ -100,7 +100,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS)
//#TPT-Directive ElementHeader Element_GOLD static int graphics(GRAPHICS_FUNC_ARGS) //#TPT-Directive ElementHeader Element_GOLD static int graphics(GRAPHICS_FUNC_ARGS)
int Element_GOLD::graphics(GRAPHICS_FUNC_ARGS) int Element_GOLD::graphics(GRAPHICS_FUNC_ARGS)
{ {
int rndstore = random_gen(); int rndstore = RNG::Ref().gen();
*colr += (rndstore % 10) - 5; *colr += (rndstore % 10) - 5;
rndstore >>= 4; rndstore >>= 4;
*colg += (rndstore % 10)- 5; *colg += (rndstore % 10)- 5;

View File

@ -51,7 +51,7 @@ Element_GOO::Element_GOO()
int Element_GOO::update(UPDATE_FUNC_ARGS) int Element_GOO::update(UPDATE_FUNC_ARGS)
{ {
if (!parts[i].life && sim->pv[y/CELL][x/CELL]>1.0f) if (!parts[i].life && sim->pv[y/CELL][x/CELL]>1.0f)
parts[i].life = random_gen()%80+300; parts[i].life = RNG::Ref().between(300, 379);
if (parts[i].life) if (parts[i].life)
{ {
parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL];

View File

@ -50,7 +50,7 @@ Element_GRAV::Element_GRAV()
//#TPT-Directive ElementHeader Element_GRAV static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_GRAV static int update(UPDATE_FUNC_ARGS)
int Element_GRAV::update(UPDATE_FUNC_ARGS) int Element_GRAV::update(UPDATE_FUNC_ARGS)
{ {
if (parts[i].vx*parts[i].vx + parts[i].vy*parts[i].vy >= 0.1f && (random_gen() % 512) == 0) if (parts[i].vx*parts[i].vx + parts[i].vy*parts[i].vy >= 0.1f && RNG::Ref().chance(1, 512))
{ {
if (!parts[i].life) if (!parts[i].life)
parts[i].life = 48; parts[i].life = 48;

View File

@ -77,14 +77,14 @@ int Element_H2::update(UPDATE_FUNC_ARGS)
parts[ID(r)].temp=2473.15f; parts[ID(r)].temp=2473.15f;
parts[ID(r)].tmp |= 1; parts[ID(r)].tmp |= 1;
sim->create_part(i,x,y,PT_FIRE); sim->create_part(i,x,y,PT_FIRE);
parts[i].temp+=(random_gen()%100); parts[i].temp += RNG::Ref().between(0, 99);
parts[i].tmp |= 1; parts[i].tmp |= 1;
return 1; return 1;
} }
else if ((rt==PT_PLSM && !(parts[ID(r)].tmp&4)) || (rt==PT_LAVA && parts[ID(r)].ctype != PT_BMTL)) else if ((rt==PT_PLSM && !(parts[ID(r)].tmp&4)) || (rt==PT_LAVA && parts[ID(r)].ctype != PT_BMTL))
{ {
sim->create_part(i,x,y,PT_FIRE); sim->create_part(i,x,y,PT_FIRE);
parts[i].temp+=(random_gen()%100); parts[i].temp += RNG::Ref().between(0, 99);
parts[i].tmp |= 1; parts[i].tmp |= 1;
return 1; return 1;
} }
@ -92,7 +92,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS)
} }
if (parts[i].temp > 2273.15 && sim->pv[y/CELL][x/CELL] > 50.0f) if (parts[i].temp > 2273.15 && sim->pv[y/CELL][x/CELL] > 50.0f)
{ {
if (!(random_gen()%5)) if (RNG::Ref().chance(1, 5))
{ {
int j; int j;
float temp = parts[i].temp; float temp = parts[i].temp;
@ -102,7 +102,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS)
j = sim->create_part(-3,x,y,PT_NEUT); j = sim->create_part(-3,x,y,PT_NEUT);
if (j>-1) if (j>-1)
parts[j].temp = temp; parts[j].temp = temp;
if (!(random_gen()%10)) if (RNG::Ref().chance(1, 10))
{ {
j = sim->create_part(-3,x,y,PT_ELEC); j = sim->create_part(-3,x,y,PT_ELEC);
if (j>-1) if (j>-1)
@ -115,7 +115,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS)
parts[j].temp = temp; parts[j].temp = temp;
parts[j].tmp = 0x1; parts[j].tmp = 0x1;
} }
rx = x+random_gen()%3-1, ry = y+random_gen()%3-1, rt = TYP(pmap[ry][rx]); rx = x + RNG::Ref().between(-1, 1), ry = y + RNG::Ref().between(-1, 1), rt = TYP(pmap[ry][rx]);
if (sim->can_move[PT_PLSM][rt] || rt == PT_H2) if (sim->can_move[PT_PLSM][rt] || rt == PT_H2)
{ {
j = sim->create_part(-3,rx,ry,PT_PLSM); j = sim->create_part(-3,rx,ry,PT_PLSM);
@ -125,7 +125,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS)
parts[j].tmp |= 4; parts[j].tmp |= 4;
} }
} }
parts[i].temp = temp+750+random_gen()%500; parts[i].temp = temp + RNG::Ref().between(750, 1249);
sim->pv[y/CELL][x/CELL] += 30; sim->pv[y/CELL][x/CELL] += 30;
return 1; return 1;
} }

View File

@ -61,14 +61,14 @@ int Element_ICEI::update(UPDATE_FUNC_ARGS)
continue; continue;
if (TYP(r)==PT_SALT || TYP(r)==PT_SLTW) if (TYP(r)==PT_SALT || TYP(r)==PT_SLTW)
{ {
if (parts[i].temp > sim->elements[PT_SLTW].LowTemperature && !(random_gen()%200)) if (parts[i].temp > sim->elements[PT_SLTW].LowTemperature && RNG::Ref().chance(1, 200))
{ {
sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(i,x,y,PT_SLTW);
sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW);
return 0; return 0;
} }
} }
else if ((TYP(r)==PT_FRZZ) && !(random_gen()%200)) else if ((TYP(r)==PT_FRZZ) && RNG::Ref().chance(1, 200))
{ {
sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI); sim->part_change_type(ID(r),x+rx,y+ry,PT_ICEI);
parts[ID(r)].ctype = PT_FRZW; parts[ID(r)].ctype = PT_FRZW;

View File

@ -58,19 +58,19 @@ int Element_IRON::update(UPDATE_FUNC_ARGS)
switch TYP(r) switch TYP(r)
{ {
case PT_SALT: case PT_SALT:
if (!(random_gen()%47)) if (RNG::Ref().chance(1, 47))
goto succ; goto succ;
break; break;
case PT_SLTW: case PT_SLTW:
if (!(random_gen()%67)) if (RNG::Ref().chance(1, 67))
goto succ; goto succ;
break; break;
case PT_WATR: case PT_WATR:
if (!(random_gen()%1200)) if (RNG::Ref().chance(1, 1200))
goto succ; goto succ;
break; break;
case PT_O2: case PT_O2:
if (!(random_gen()%250)) if (RNG::Ref().chance(1, 250))
goto succ; goto succ;
break; break;
case PT_LO2: case PT_LO2:
@ -82,7 +82,7 @@ int Element_IRON::update(UPDATE_FUNC_ARGS)
return 0; return 0;
succ: succ:
sim->part_change_type(i,x,y,PT_BMTL); sim->part_change_type(i,x,y,PT_BMTL);
parts[i].tmp=(random_gen()%10)+20; parts[i].tmp = RNG::Ref().between(20, 29);
return 0; return 0;
} }

View File

@ -48,11 +48,11 @@ Element_ISOZ::Element_ISOZ()
int Element_ISOZ::update(UPDATE_FUNC_ARGS) int Element_ISOZ::update(UPDATE_FUNC_ARGS)
{ // for both ISZS and ISOZ { // for both ISZS and ISOZ
float rr, rrr; float rr, rrr;
if (!(random_gen()%200) && (-4.0f*(sim->pv[y/CELL][x/CELL])) > (random_gen()%1000)) if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(-4.0f * sim->pv[y/CELL][x/CELL], 1000))
{ {
sim->create_part(i, x, y, PT_PHOT); sim->create_part(i, x, y, PT_PHOT);
rr = (random_gen()%228+128)/127.0f; rr = RNG::Ref().between(128, 355) / 127.0f;
rrr = (random_gen()%360)*3.14159f/180.0f; rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].vx = rr*cosf(rrr); parts[i].vx = rr*cosf(rrr);
parts[i].vy = rr*sinf(rrr); parts[i].vy = rr*sinf(rrr);
} }

View File

@ -48,11 +48,11 @@ Element_ISZS::Element_ISZS()
int Element_ISZS::update(UPDATE_FUNC_ARGS) int Element_ISZS::update(UPDATE_FUNC_ARGS)
{ // for both ISZS and ISOZ { // for both ISZS and ISOZ
float rr, rrr; float rr, rrr;
if (!(random_gen()%200) && (-4.0f*(sim->pv[y/CELL][x/CELL])) > (random_gen()%1000)) if (RNG::Ref().chance(1, 200) && RNG::Ref().chance(-4.0f * sim->pv[y/CELL][x/CELL], 1000))
{ {
sim->create_part(i, x, y, PT_PHOT); sim->create_part(i, x, y, PT_PHOT);
rr = (random_gen()%228+128)/127.0f; rr = RNG::Ref().between(128, 355) / 127.0f;
rrr = (random_gen()%360)*3.14159f/180.0f; rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f;
parts[i].vx = rr*cosf(rrr); parts[i].vx = rr*cosf(rrr);
parts[i].vy = rr*sinf(rrr); parts[i].vy = rr*sinf(rrr);
} }

View File

@ -91,11 +91,11 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS)
rt = TYP(r); rt = TYP(r);
if ((surround_space || sim->elements[rt].Explosive) && if ((surround_space || sim->elements[rt].Explosive) &&
(rt!=PT_SPNG || parts[ID(r)].life==0) && (rt!=PT_SPNG || parts[ID(r)].life==0) &&
sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f)) > (random_gen()%1000)) sim->elements[rt].Flammable && (sim->elements[rt].Flammable + RNG::Ref().chance(sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f, 1000)))
{ {
sim->part_change_type(ID(r),x+rx,y+ry,PT_FIRE); sim->part_change_type(ID(r),x+rx,y+ry,PT_FIRE);
parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP);
parts[ID(r)].life = random_gen()%80+180; parts[ID(r)].life = RNG::Ref().between(180, 259);
parts[ID(r)].tmp = parts[ID(r)].ctype = 0; parts[ID(r)].tmp = parts[ID(r)].ctype = 0;
if (sim->elements[rt].Explosive) if (sim->elements[rt].Explosive)
sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; sim->pv[y/CELL][x/CELL] += 0.25f * CFDS;
@ -115,12 +115,12 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS)
case PT_PLUT: case PT_PLUT:
parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful, MIN_TEMP, MAX_TEMP); parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful, MIN_TEMP, MAX_TEMP);
sim->pv[y/CELL][x/CELL] +=powderful/35; sim->pv[y/CELL][x/CELL] +=powderful/35;
if (!(random_gen()%3)) if (RNG::Ref().chance(1, 3))
{ {
sim->part_change_type(ID(r),x+rx,y+ry,PT_NEUT); sim->part_change_type(ID(r),x+rx,y+ry,PT_NEUT);
parts[ID(r)].life = random_gen()%480+480; parts[ID(r)].life = RNG::Ref().between(480, 959);
parts[ID(r)].vx=random_gen()%10-5; parts[ID(r)].vx = RNG::Ref().between(-5, 5);
parts[ID(r)].vy=random_gen()%10-5; parts[ID(r)].vy = RNG::Ref().between(-5, 5);
} }
break; break;
case PT_COAL: case PT_COAL:
@ -208,15 +208,15 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS)
}*/ }*/
//if (parts[i].tmp2==1/* || near!=-1*/) //if (parts[i].tmp2==1/* || near!=-1*/)
//angle=0;//parts[i].tmp-30+random_gen()%60; //angle=0;//parts[i].tmp + RNG::Ref().between(-30, 30);
angle = (parts[i].tmp-30+random_gen()%60)%360; angle = (parts[i].tmp + RNG::Ref().between(-30, 30)) % 360;
multipler=parts[i].life*1.5+random_gen()%((int)(parts[i].life+1)); multipler = parts[i].life * 1.5 + RNG::Ref().between(0, parts[i].life);
rx=cos(angle*M_PI/180)*multipler; rx=cos(angle*M_PI/180)*multipler;
ry=-sin(angle*M_PI/180)*multipler; ry=-sin(angle*M_PI/180)*multipler;
create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, parts[i].tmp2); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, parts[i].tmp2);
if (parts[i].tmp2==2)// && pNear==-1) if (parts[i].tmp2==2)// && pNear==-1)
{ {
angle2= ((int)angle+100-random_gen()%200)%360; angle2 = ((int)angle + RNG::Ref().between(-100, 100)) % 360;
rx=cos(angle2*M_PI/180)*multipler; rx=cos(angle2*M_PI/180)*multipler;
ry=-sin(angle2*M_PI/180)*multipler; ry=-sin(angle2*M_PI/180)*multipler;
create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, parts[i].tmp2); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, parts[i].tmp2);
@ -278,8 +278,8 @@ bool Element_LIGH::create_LIGH(Simulation * sim, int x, int y, int c, int temp,
sim->parts[p].tmp = tmp; sim->parts[p].tmp = tmp;
if (last) if (last)
{ {
sim->parts[p].tmp2=1+((int)(random_gen()%200) > tmp2*tmp2/10+60); sim->parts[p].tmp2 = 1 + (RNG::Ref().between(0, 199) > tmp2*tmp2/10+60);
sim->parts[p].life=(int)(life/1.5-random_gen()%2); sim->parts[p].life = (int)(life/1.5 - RNG::Ref().between(0, 1));
} }
else else
{ {

View File

@ -53,8 +53,8 @@ int Element_MERC::update(UPDATE_FUNC_ARGS)
// Obscure division by 0 fix // Obscure division by 0 fix
if (parts[i].temp + 1 == 0) if (parts[i].temp + 1 == 0)
parts[i].temp = 0; parts[i].temp = 0;
int maxtmp = ((absorbScale/(parts[i].temp + 1))-1); int maxtmp = (absorbScale/(parts[i].temp + 1))-1;
if ((absorbScale%((int)parts[i].temp+1))>random_gen()%((int)parts[i].temp+1)) if (RNG::Ref().chance(absorbScale%((int)parts[i].temp+1), parts[i].temp+1))
maxtmp ++; maxtmp ++;
if (parts[i].tmp < 0) if (parts[i].tmp < 0)
@ -75,7 +75,7 @@ int Element_MERC::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r || (parts[i].tmp >=maxtmp)) if (!r || (parts[i].tmp >=maxtmp))
continue; continue;
if (TYP(r)==PT_MERC&& !(random_gen()%3)) if (TYP(r)==PT_MERC&& RNG::Ref().chance(1, 3))
{ {
if ((parts[i].tmp + parts[ID(r)].tmp + 1) <= maxtmp) if ((parts[i].tmp + parts[ID(r)].tmp + 1) <= maxtmp)
{ {
@ -105,8 +105,8 @@ int Element_MERC::update(UPDATE_FUNC_ARGS)
} }
for ( trade = 0; trade<4; trade ++) for ( trade = 0; trade<4; trade ++)
{ {
rx = random_gen()%5-2; rx = RNG::Ref().between(-2, 2);
ry = random_gen()%5-2; ry = RNG::Ref().between(-2, 2);
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];

View File

@ -51,7 +51,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS)
if (parts[i].temp > 5273.15 && sim->pv[y/CELL][x/CELL] > 100.0f) if (parts[i].temp > 5273.15 && sim->pv[y/CELL][x/CELL] > 100.0f)
{ {
parts[i].tmp |= 0x1; parts[i].tmp |= 0x1;
if (!(random_gen()%5)) if (RNG::Ref().chance(1, 5))
{ {
int j; int j;
float temp = parts[i].temp; float temp = parts[i].temp;
@ -60,7 +60,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS)
j = sim->create_part(-3,x,y,PT_NEUT); j = sim->create_part(-3,x,y,PT_NEUT);
if (j != -1) if (j != -1)
parts[j].temp = temp; parts[j].temp = temp;
if (!(random_gen()%25)) if (RNG::Ref().chance(1, 25))
{ {
j = sim->create_part(-3,x,y,PT_ELEC); j = sim->create_part(-3,x,y,PT_ELEC);
if (j != -1) if (j != -1)
@ -73,7 +73,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS)
parts[j].temp = temp; parts[j].temp = temp;
parts[j].tmp = 0x1; parts[j].tmp = 0x1;
} }
int rx = x+random_gen()%3-1, ry = y+random_gen()%3-1, rt = TYP(pmap[ry][rx]); int rx = x + RNG::Ref().between(-1, 1), ry = y + RNG::Ref().between(-1, 1), rt = TYP(pmap[ry][rx]);
if (sim->can_move[PT_PLSM][rt] || rt == PT_NBLE) if (sim->can_move[PT_PLSM][rt] || rt == PT_NBLE)
{ {
j = sim->create_part(-3,rx,ry,PT_PLSM); j = sim->create_part(-3,rx,ry,PT_PLSM);
@ -83,7 +83,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS)
parts[j].tmp |= 4; parts[j].tmp |= 4;
} }
} }
parts[i].temp = temp+1750+random_gen()%500; parts[i].temp = temp + 1750 + RNG::Ref().between(0, 499);
sim->pv[y/CELL][x/CELL] += 50; sim->pv[y/CELL][x/CELL] += 50;
} }
} }

View File

@ -58,7 +58,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
switch (TYP(r)) switch (TYP(r))
{ {
case PT_WATR: case PT_WATR:
if (3>(random_gen()%20)) if (RNG::Ref().chance(3, 20))
sim->part_change_type(ID(r),x+rx,y+ry,PT_DSTW); sim->part_change_type(ID(r),x+rx,y+ry,PT_DSTW);
case PT_ICEI: case PT_ICEI:
case PT_SNOW: case PT_SNOW:
@ -66,11 +66,11 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
parts[i].vy *= 0.995; parts[i].vy *= 0.995;
break; break;
case PT_PLUT: case PT_PLUT:
if (pressureFactor > (random_gen()%1000)) if (RNG::Ref().chance(pressureFactor, 1000))
{ {
if (!(random_gen()%3)) if (RNG::Ref().chance(1, 3))
{ {
sim->create_part(ID(r), x+rx, y+ry, random_gen()%3 ? PT_LAVA : PT_URAN); sim->create_part(ID(r), x+rx, y+ry, RNG::Ref().chance(1, 3) ? PT_LAVA : PT_URAN);
parts[ID(r)].temp = MAX_TEMP; parts[ID(r)].temp = MAX_TEMP;
if (parts[ID(r)].type==PT_LAVA) { if (parts[ID(r)].type==PT_LAVA) {
parts[ID(r)].tmp = 100; parts[ID(r)].tmp = 100;
@ -89,7 +89,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
break; break;
#ifdef SDEUT #ifdef SDEUT
case PT_DEUT: case PT_DEUT:
if ((pressureFactor+1+(parts[ID(r)].life/100))>(random_gen()%1000)) if (RNG::Ref().chance(pressureFactor + 1 + (parts[ID(r)].life/100), 1000))
{ {
DeutExplosion(sim, parts[ID(r)].life, x+rx, y+ry, restrict_flt(parts[ID(r)].temp + parts[ID(r)].life*500.0f, MIN_TEMP, MAX_TEMP), PT_NEUT); DeutExplosion(sim, parts[ID(r)].life, x+rx, y+ry, restrict_flt(parts[ID(r)].temp + parts[ID(r)].life*500.0f, MIN_TEMP, MAX_TEMP), PT_NEUT);
sim->kill_part(ID(r)); sim->kill_part(ID(r));
@ -97,7 +97,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
break; break;
#else #else
case PT_DEUT: case PT_DEUT:
if ((pressureFactor+1)>(random_gen()%1000)) if (RNG::Ref().chance(pressureFactor+1, 1000))
{ {
create_part(ID(r), x+rx, y+ry, PT_NEUT); create_part(ID(r), x+rx, y+ry, PT_NEUT);
parts[ID(r)].vx = 0.25f*parts[ID(r)].vx + parts[i].vx; parts[ID(r)].vx = 0.25f*parts[ID(r)].vx + parts[i].vx;
@ -110,66 +110,66 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS)
break; break;
#endif #endif
case PT_GUNP: case PT_GUNP:
if (3>(random_gen()%200)) if (RNG::Ref().chance(3, 200))
sim->part_change_type(ID(r),x+rx,y+ry,PT_DUST); sim->part_change_type(ID(r),x+rx,y+ry,PT_DUST);
break; break;
case PT_DYST: case PT_DYST:
if (3>(random_gen()%200)) if (RNG::Ref().chance(3, 200))
sim->part_change_type(ID(r),x+rx,y+ry,PT_YEST); sim->part_change_type(ID(r),x+rx,y+ry,PT_YEST);
break; break;
case PT_YEST: case PT_YEST:
sim->part_change_type(ID(r),x+rx,y+ry,PT_DYST); sim->part_change_type(ID(r),x+rx,y+ry,PT_DYST);
break; break;
case PT_PLEX: case PT_PLEX:
if (3>(random_gen()%200)) if (RNG::Ref().chance(3, 200))
sim->part_change_type(ID(r),x+rx,y+ry,PT_GOO); sim->part_change_type(ID(r),x+rx,y+ry,PT_GOO);
break; break;
case PT_NITR: case PT_NITR:
if (3>(random_gen()%200)) if (RNG::Ref().chance(3, 200))
sim->part_change_type(ID(r),x+rx,y+ry,PT_DESL); sim->part_change_type(ID(r),x+rx,y+ry,PT_DESL);
break; break;
case PT_PLNT: case PT_PLNT:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); sim->create_part(ID(r), x+rx, y+ry, PT_WOOD);
break; break;
case PT_DESL: case PT_DESL:
case PT_OIL: case PT_OIL:
if (3>(random_gen()%200)) if (RNG::Ref().chance(3, 200))
sim->part_change_type(ID(r),x+rx,y+ry,PT_GAS); sim->part_change_type(ID(r),x+rx,y+ry,PT_GAS);
break; break;
case PT_COAL: case PT_COAL:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); sim->create_part(ID(r), x+rx, y+ry, PT_WOOD);
break; break;
case PT_BCOL: case PT_BCOL:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
sim->create_part(ID(r), x+rx, y+ry, PT_SAWD); sim->create_part(ID(r), x+rx, y+ry, PT_SAWD);
break; break;
case PT_DUST: case PT_DUST:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
sim->part_change_type(ID(r), x+rx, y+ry, PT_FWRK); sim->part_change_type(ID(r), x+rx, y+ry, PT_FWRK);
break; break;
case PT_FWRK: case PT_FWRK:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
parts[ID(r)].ctype = PT_DUST; parts[ID(r)].ctype = PT_DUST;
break; break;
case PT_ACID: case PT_ACID:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
sim->create_part(ID(r), x+rx, y+ry, PT_ISOZ); sim->create_part(ID(r), x+rx, y+ry, PT_ISOZ);
break; break;
case PT_TTAN: case PT_TTAN:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
{ {
sim->kill_part(i); sim->kill_part(i);
return 1; return 1;
} }
break; break;
case PT_EXOT: case PT_EXOT:
if (!(random_gen()%20)) if (RNG::Ref().chance(1, 20))
parts[ID(r)].life = 1500; parts[ID(r)].life = 1500;
break; break;
case PT_RFRG: case PT_RFRG:
if (random_gen()%2) if (RNG::Ref().chance(1, 2))
sim->create_part(ID(r), x+rx, y+ry, PT_GAS); sim->create_part(ID(r), x+rx, y+ry, PT_GAS);
else else
sim->create_part(ID(r), x+rx, y+ry, PT_CAUS); sim->create_part(ID(r), x+rx, y+ry, PT_CAUS);

View File

@ -58,19 +58,19 @@ int Element_O2::update(UPDATE_FUNC_ARGS)
if (TYP(r)==PT_FIRE) if (TYP(r)==PT_FIRE)
{ {
parts[ID(r)].temp+=(random_gen()%100); parts[ID(r)].temp += RNG::Ref().between(0, 99);
if(parts[ID(r)].tmp&0x01) if (parts[ID(r)].tmp & 0x01)
parts[ID(r)].temp=3473; parts[ID(r)].temp = 3473;
parts[ID(r)].tmp |= 2; parts[ID(r)].tmp |= 2;
sim->create_part(i,x,y,PT_FIRE); sim->create_part(i,x,y,PT_FIRE);
parts[i].temp+=(random_gen()%100); parts[i].temp += RNG::Ref().between(0, 99);
parts[i].tmp |= 2; parts[i].tmp |= 2;
} }
else if (TYP(r)==PT_PLSM && !(parts[ID(r)].tmp&4)) else if (TYP(r)==PT_PLSM && !(parts[ID(r)].tmp&4))
{ {
sim->create_part(i,x,y,PT_FIRE); sim->create_part(i,x,y,PT_FIRE);
parts[i].temp+=(random_gen()%100); parts[i].temp += RNG::Ref().between(0, 99);
parts[i].tmp |= 2; parts[i].tmp |= 2;
} }
} }
@ -81,7 +81,7 @@ int Element_O2::update(UPDATE_FUNC_ARGS)
float gravy = sim->gravy[gravPos]; float gravy = sim->gravy[gravPos];
if (gravx*gravx + gravy*gravy > 400) if (gravx*gravx + gravy*gravy > 400)
{ {
if (!(random_gen()%5)) if (RNG::Ref().chance(1, 5))
{ {
int j; int j;
sim->create_part(i,x,y,PT_BRMT); sim->create_part(i,x,y,PT_BRMT);
@ -95,7 +95,7 @@ int Element_O2::update(UPDATE_FUNC_ARGS)
parts[j].temp = MAX_TEMP; parts[j].temp = MAX_TEMP;
parts[j].tmp = 0x1; parts[j].tmp = 0x1;
} }
rx = x+random_gen()%3-1, ry = y+random_gen()%3-1, r = TYP(pmap[ry][rx]); rx = x + RNG::Ref().between(-1, 1), ry = y + RNG::Ref().between(-1, 1), r = TYP(pmap[ry][rx]);
if (sim->can_move[PT_PLSM][r] || r == PT_O2) if (sim->can_move[PT_PLSM][r] || r == PT_O2)
{ {
j = sim->create_part(-3,rx,ry,PT_PLSM); j = sim->create_part(-3,rx,ry,PT_PLSM);

View File

@ -464,6 +464,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original
rndstore = RNG::Ref().gen(); rndstore = RNG::Ref().gen();
// RAND_MAX is at least 32767 on all platforms i.e. pow(8,5)-1 // RAND_MAX is at least 32767 on all platforms i.e. pow(8,5)-1
// so can go 5 cycles without regenerating rndstore // so can go 5 cycles without regenerating rndstore
// (although now we use our own randomizer so maybe should reevaluate all the rndstore usages in every element)
for (q=0; q<3; q++)//try to push 3 times for (q=0; q<3; q++)//try to push 3 times
{ {
rnd = rndstore&7; rnd = rndstore&7;