diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 22f43c708..391a81dfa 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.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,7 +3412,7 @@ 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); @@ -3422,16 +3420,16 @@ int Simulation::create_part(int p, int x, int y, int t, int v) } 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); @@ -3439,8 +3437,8 @@ int Simulation::create_part(int p, int x, int y, int t, int v) } 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; @@ -3448,8 +3446,8 @@ int Simulation::create_part(int p, int x, int y, int t, int v) } 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,8 +3975,10 @@ 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 { @@ -3986,7 +3986,7 @@ void Simulation::UpdateParticles(int start, int end) 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 @@ killed: 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 @@ killed: { 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 @@ killed: } 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 @@ killed: 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(); } diff --git a/src/simulation/elements/AMTR.cpp b/src/simulation/elements/AMTR.cpp index 35c5d3a70..afa87a068 100644 --- a/src/simulation/elements/AMTR.cpp +++ b/src/simulation/elements/AMTR.cpp @@ -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)); diff --git a/src/simulation/elements/ANAR.cpp b/src/simulation/elements/ANAR.cpp index d288d9ac6..354c324c8 100644 --- a/src/simulation/elements/ANAR.cpp +++ b/src/simulation/elements/ANAR.cpp @@ -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; } diff --git a/src/simulation/elements/BCLN.cpp b/src/simulation/elements/BCLN.cpp index 18bfbf4cf..c4bacaeff 100644 --- a/src/simulation/elements/BCLN.cpp +++ b/src/simulation/elements/BCLN.cpp @@ -50,7 +50,7 @@ Element_BCLN::Element_BCLN() int Element_BCLN::update(UPDATE_FUNC_ARGS) { 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) { parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; @@ -80,11 +80,12 @@ int Element_BCLN::update(UPDATE_FUNC_ARGS) } } } - 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) + else + { + 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 (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/BMTL.cpp b/src/simulation/elements/BMTL.cpp index 16a3af5c1..258de6b5f 100644 --- a/src/simulation/elements/BMTL.cpp +++ b/src/simulation/elements/BMTL.cpp @@ -58,14 +58,14 @@ int Element_BMTL::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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); - 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; sim->part_change_type(i,x,y,PT_BRMT); diff --git a/src/simulation/elements/BOYL.cpp b/src/simulation/elements/BOYL.cpp index e1d439a52..f73f634a5 100644 --- a/src/simulation/elements/BOYL.cpp +++ b/src/simulation/elements/BOYL.cpp @@ -70,12 +70,12 @@ int Element_BOYL::update(UPDATE_FUNC_ARGS) continue; 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); } else if (TYP(r)==PT_O2) { - if (!(random_gen()%9)) + if (RNG::Ref().chance(1, 9)) { sim->kill_part(ID(r)); sim->part_change_type(i,x,y,PT_WATR); diff --git a/src/simulation/elements/BREC.cpp b/src/simulation/elements/BREC.cpp index 58616ee8e..13e9cb4e6 100644 --- a/src/simulation/elements/BREC.cpp +++ b/src/simulation/elements/BREC.cpp @@ -51,7 +51,7 @@ int Element_BREC::update(UPDATE_FUNC_ARGS) { 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); parts[i].life = 1000; diff --git a/src/simulation/elements/BRMT.cpp b/src/simulation/elements/BRMT.cpp index d2c021ac5..672781a5f 100644 --- a/src/simulation/elements/BRMT.cpp +++ b/src/simulation/elements/BRMT.cpp @@ -60,16 +60,14 @@ int Element_BRMT::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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); } else 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; } } } diff --git a/src/simulation/elements/C5.cpp b/src/simulation/elements/C5.cpp index f67a1b0fd..495f0424e 100644 --- a/src/simulation/elements/C5.cpp +++ b/src/simulation/elements/C5.cpp @@ -58,11 +58,11 @@ int Element_C5::update(UPDATE_FUNC_ARGS) 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 (!(random_gen()%6)) + if (RNG::Ref().chance(1, 6)) { sim->part_change_type(i,x,y,PT_CFLM); 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; } } diff --git a/src/simulation/elements/CAUS.cpp b/src/simulation/elements/CAUS.cpp index b952f2188..6d655537d 100644 --- a/src/simulation/elements/CAUS.cpp +++ b/src/simulation/elements/CAUS.cpp @@ -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) { - 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 if (sim->parts_avg(i, ID(r),PT_GLAS) != PT_GLAS) diff --git a/src/simulation/elements/CBNW.cpp b/src/simulation/elements/CBNW.cpp index 9df626930..5b37f6db6 100644 --- a/src/simulation/elements/CBNW.cpp +++ b/src/simulation/elements/CBNW.cpp @@ -51,7 +51,7 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS) int r, rx, ry; 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); parts[i].ctype = 5; @@ -61,15 +61,15 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS) if (parts[i].tmp2!=20) { 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) { //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); parts[i].ctype = 5; @@ -84,12 +84,12 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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 - 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); 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) { - 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); 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){ sim->kill_part(ID(r)); - if(!(random_gen()%50)){ + if (RNG::Ref().chance(1, 50)) + { sim->kill_part(i); return 1; } diff --git a/src/simulation/elements/CLNE.cpp b/src/simulation/elements/CLNE.cpp index dca6b5fff..8b4183e84 100644 --- a/src/simulation/elements/CLNE.cpp +++ b/src/simulation/elements/CLNE.cpp @@ -71,11 +71,12 @@ int Element_CLNE::update(UPDATE_FUNC_ARGS) } } } - 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) + else + { + 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 (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/CLST.cpp b/src/simulation/elements/CLST.cpp index 89d6568ea..da4582799 100644 --- a/src/simulation/elements/CLST.cpp +++ b/src/simulation/elements/CLST.cpp @@ -59,7 +59,7 @@ int Element_CLST::update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_WATR) { - if (!(random_gen()%1500)) + if (RNG::Ref().chance(1, 1500)) { sim->create_part(i, x, y, PT_PSTS); sim->kill_part(ID(r)); diff --git a/src/simulation/elements/CO2.cpp b/src/simulation/elements/CO2.cpp index 54ed9fa19..ca3e89766 100644 --- a/src/simulation/elements/CO2.cpp +++ b/src/simulation/elements/CO2.cpp @@ -55,21 +55,23 @@ int Element_CO2::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; 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) parts[i].ctype = 0; } continue; } - if (TYP(r)==PT_FIRE){ + if (TYP(r)==PT_FIRE) + { sim->kill_part(ID(r)); - if(!(random_gen()%30)){ + if (RNG::Ref().chance(1, 30)) + { sim->kill_part(i); 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); 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 (!(random_gen()%5)) + if (RNG::Ref().chance(1, 5)) { int j; sim->create_part(i,x,y,PT_O2); j = sim->create_part(-3,x,y,PT_NEUT); if (j != -1) parts[j].temp = MAX_TEMP; - if (!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) { j = sim->create_part(-3,x,y,PT_ELEC); if (j != -1) diff --git a/src/simulation/elements/COAL.cpp b/src/simulation/elements/COAL.cpp index 30e1f5cb5..01c6eaad0 100644 --- a/src/simulation/elements/COAL.cpp +++ b/src/simulation/elements/COAL.cpp @@ -54,7 +54,7 @@ int Element_COAL::update(UPDATE_FUNC_ARGS) return 1; } else if (parts[i].life < 100) { 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) { diff --git a/src/simulation/elements/DEST.cpp b/src/simulation/elements/DEST.cpp index e9da9bdf3..42124c752 100644 --- a/src/simulation/elements/DEST.cpp +++ b/src/simulation/elements/DEST.cpp @@ -48,8 +48,8 @@ Element_DEST::Element_DEST() //#TPT-Directive ElementHeader Element_DEST static int update(UPDATE_FUNC_ARGS) int Element_DEST::update(UPDATE_FUNC_ARGS) { - int rx = random_gen()%5-2; - int ry = random_gen()%5-2; + int rx = RNG::Ref().between(-2, 2); + int ry = RNG::Ref().between(-2, 2); int r = pmap[y+ry][x+rx]; if (!r) return 0; @@ -59,13 +59,13 @@ int Element_DEST::update(UPDATE_FUNC_ARGS) 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; } if (rt == PT_PLUT || rt == PT_DEUT) { 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); 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); } - else if (!(random_gen()%3)) + else if (RNG::Ref().chance(1, 3)) { sim->kill_part(ID(r)); parts[i].life -= 4*((sim->elements[rt].Properties&TYPE_SOLID)?3:1); diff --git a/src/simulation/elements/DEUT.cpp b/src/simulation/elements/DEUT.cpp index c8551a22e..7b2795643 100644 --- a/src/simulation/elements/DEUT.cpp +++ b/src/simulation/elements/DEUT.cpp @@ -51,8 +51,8 @@ int Element_DEUT::update(UPDATE_FUNC_ARGS) 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)]); int maxlife = ((10000/(parts[i].temp + 1))-1); - if ((10000%((int)parts[i].temp + 1))>random_gen()%((int)parts[i].temp + 1)) - maxlife ++; + if (RNG::Ref().chance(10000 % static_cast(parts[i].temp + 1), static_cast(parts[i].temp + 1))) + maxlife++; // Compress when Newtonian gravity is applied // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf 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]; if (!r || (parts[i].life >=maxlife)) 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 // 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: for ( trade = 0; trade<4; trade ++) { - rx = random_gen()%5-2; - ry = random_gen()%5-2; + rx = RNG::Ref().between(-2, 2); + ry = RNG::Ref().between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/DSTW.cpp b/src/simulation/elements/DSTW.cpp index 465e81528..e9c379d57 100644 --- a/src/simulation/elements/DSTW.cpp +++ b/src/simulation/elements/DSTW.cpp @@ -56,29 +56,29 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_SALT: - if (!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) { sim->part_change_type(i,x,y,PT_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); } break; case PT_SLTW: - if (!(random_gen()%2000)) + if (RNG::Ref().chance(1, 2000)) { sim->part_change_type(i,x,y,PT_SLTW); break; } case PT_WATR: - if (!(random_gen()%100)) + if (RNG::Ref().chance(1, 100)) { sim->part_change_type(i,x,y,PT_WATR); } break; case PT_RBDM: 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); parts[i].life = 4; @@ -86,7 +86,8 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS) break; case PT_FIRE: sim->kill_part(ID(r)); - if(!(random_gen()%30)){ + if (RNG::Ref().chance(1, 30)) + { sim->kill_part(i); return 1; } diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp index 7340ad28a..9bde3df16 100644 --- a/src/simulation/elements/ELEC.cpp +++ b/src/simulation/elements/ELEC.cpp @@ -76,13 +76,13 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; case PT_LCRY: - parts[ID(r)].tmp2 = 5+random_gen()%5; + parts[ID(r)].tmp2 = RNG::Ref().between(5, 9); break; case PT_WATR: case PT_DSTW: case PT_SLTW: case PT_CBNW: - if(!(random_gen()%3)) + if (RNG::Ref().chance(1, 3)) sim->create_part(ID(r), x+rx, y+ry, PT_O2); else sim->create_part(ID(r), x+rx, y+ry, PT_H2); diff --git a/src/simulation/elements/EMP.cpp b/src/simulation/elements/EMP.cpp index 4e7f6f8a4..4ab6d57cb 100644 --- a/src/simulation/elements/EMP.cpp +++ b/src/simulation/elements/EMP.cpp @@ -67,7 +67,7 @@ public: } 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; 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); else sim->part_change_type(r, rx, ry, PT_NTCT); @@ -145,10 +145,10 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount) { case PT_METL: 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); - if (random_gen.uniform01() < prob_breakMETLMore) + if (RNG::Ref().uniform01() < prob_breakMETLMore) { 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); @@ -157,19 +157,19 @@ int Element_EMP::Trigger(Simulation *sim, int triggerCount) break; case PT_BMTL: 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); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); } break; case PT_WIFI: - if (random_gen.uniform01() < prob_randWIFI) + if (RNG::Ref().uniform01() < prob_randWIFI) { // 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); 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) { 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); temp_SWCH.apply(sim, parts[n]); break; 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); parts[n].temp = restrict_flt(parts[n].temp+1000.0f, MIN_TEMP, MAX_TEMP); } break; case PT_DLAY: - if (random_gen.uniform01() < prob_randDLAY) + if (RNG::Ref().uniform01() < prob_randDLAY) { // Randomize delay - parts[n].temp = (random_gen()%256) + 273.15f; + parts[n].temp = RNG::Ref().between(0, 255) + 273.15f; } break; default: diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index 5eb61ee0a..c489c3b7b 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -59,7 +59,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS) rt = TYP(r); 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; } @@ -68,7 +68,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS) { if (parts[ID(r)].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; } 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 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; 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 else if (parts[ID(r)].ctype == PT_VIBR) { - if (!(random_gen()%1000)) + if (RNG::Ref().chance(1, 1000)) { sim->kill_part(i); return 1; @@ -131,8 +131,8 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS) { for (trade = 0; trade < 9; trade++) { - rx = random_gen()%5-2; - ry = random_gen()%5-2; + rx = RNG::Ref().between(-2, 2); + ry = RNG::Ref().between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; @@ -186,7 +186,7 @@ int Element_EXOT::graphics(GRAPHICS_FUNC_ARGS) int c = cpart->tmp2; if (cpart->life < 1001) { - if ((cpart->tmp2 - 1) > (int)(random_gen()%1000)) + if (RNG::Ref().chance(cpart->tmp2 - 1, 1000)) { float frequency = 0.04045; *colr = (sin(frequency*c + 4) * 127 + 150); diff --git a/src/simulation/elements/Element.cpp b/src/simulation/elements/Element.cpp index 7d620f7f3..155ec55df 100644 --- a/src/simulation/elements/Element.cpp +++ b/src/simulation/elements/Element.cpp @@ -99,15 +99,15 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) 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(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); - if (1>(random_gen()%1000)) + if (RNG::Ref().chance(1, 1000)) 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]; if (!r) 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); } @@ -136,10 +136,12 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) 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); - else sim->part_change_type(i,x,y,PT_WTRV); + if (RNG::Ref().chance(1, 4)) + 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]; if (!r) 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); } @@ -166,7 +168,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) 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(ID(r),x+rx,y+ry,PT_ICEI); @@ -181,12 +183,12 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) 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(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); } } @@ -199,7 +201,7 @@ int Element::legacyUpdate(UPDATE_FUNC_ARGS) { if (t==PT_DESL && sim->pv[y/CELL][x/CELL]>12.0f) { 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; } diff --git a/src/simulation/elements/FILT.cpp b/src/simulation/elements/FILT.cpp index 6fdd0ef8f..65025da33 100644 --- a/src/simulation/elements/FILT.cpp +++ b/src/simulation/elements/FILT.cpp @@ -108,9 +108,9 @@ int Element_FILT::interactWavelengths(Particle* cpart, int origWl) return (~origWl) & mask; // Invert colours case 9: { - int t1 = (origWl & 0x0000FF)+(random_gen()%5)-2; - int t2 = ((origWl & 0x00FF00)>>8)+(random_gen()%5)-2; - int t3 = ((origWl & 0xFF0000)>>16)+(random_gen()%5)-2; + int t1 = (origWl & 0x0000FF) + RNG::Ref().between(-2, 2); + int t2 = ((origWl & 0x00FF00)>>8) + RNG::Ref().between(-2, 2); + int t3 = ((origWl & 0xFF0000)>>16) + RNG::Ref().between(-2, 2); return (origWl & 0xFF000000) | (t3<<16) | (t2<<8) | t1; } case 10: diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index ee1dc0d97..b666cbe32 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -79,7 +79,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) else if (parts[i].temp<625) { 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; @@ -98,7 +98,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) //THRM burning 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); parts[ID(r)].ctype = PT_BMTL; 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 (parts[ID(r)].life>100 && !(random_gen()%500)) { + if (parts[ID(r)].life>100 && RNG::Ref().chance(1, 500)) { parts[ID(r)].life = 99; } } 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; 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) { - 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); parts[ID(r)].ctype = PT_HEAC; @@ -153,7 +153,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) } 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 (t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && 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); 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; if (sim->elements[rt].Explosive) 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]; 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) { @@ -199,7 +202,7 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { else parts[ID(r)].ctype = rt; 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 { diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp index a35855ed5..63bc60cb5 100644 --- a/src/simulation/elements/FIRW.cpp +++ b/src/simulation/elements/FIRW.cpp @@ -68,12 +68,12 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) sim->GetGravityField(x, y, sim->elements[PT_FIRW].Gravity, 1.0f, gx, gy); 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; gy += cosf(angle)*sim->elements[PT_FIRW].Gravity*0.5f; } 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); parts[i].vx -= gx*multiplier; parts[i].vy -= gy*multiplier; @@ -91,7 +91,7 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) else //if (parts[i].tmp>=2) { float angle, magnitude; - int caddress = (random_gen()%200)*3; + int caddress = RNG::Ref().between(0, 199) * 3; int n; unsigned col = (((firw_data[caddress]))<<16) | (((firw_data[caddress+1]))<<8) | ((firw_data[caddress+2])); 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); if (np>-1) { - magnitude = ((random_gen()%60)+40)*0.05f; - angle = (random_gen()%6284)*0.001f;//(in radians, between 0 and 2*pi) + magnitude = RNG::Ref().between(40, 99) * 0.05f; + 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].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].ctype = col; parts[np].tmp = 1; - parts[np].life = random_gen()%40+70; - parts[np].temp = (random_gen()%500)+5750.0f; + parts[np].life = RNG::Ref().between(70, 109); + parts[np].temp = RNG::Ref().between(5750, 6249); parts[np].dcolour = parts[i].dcolour; } } diff --git a/src/simulation/elements/FOG.cpp b/src/simulation/elements/FOG.cpp index 358529168..2458b40df 100644 --- a/src/simulation/elements/FOG.cpp +++ b/src/simulation/elements/FOG.cpp @@ -55,13 +55,13 @@ int Element_FOG::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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); } if (TYP(r)==PT_SPRK) { - parts[i].life += random_gen()%20; + parts[i].life += RNG::Ref().between(0, 19); } } return 0; diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp index b63e7e38d..e6da0bfd1 100644 --- a/src/simulation/elements/FRZW.cpp +++ b/src/simulation/elements/FRZW.cpp @@ -55,12 +55,12 @@ int Element_FRZW::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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); } } - 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); parts[i].ctype=PT_FRZW; diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp index e561755bd..6140534ab 100644 --- a/src/simulation/elements/FRZZ.cpp +++ b/src/simulation/elements/FRZZ.cpp @@ -55,7 +55,7 @@ int Element_FRZZ::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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); parts[ID(r)].life = 100; diff --git a/src/simulation/elements/FSEP.cpp b/src/simulation/elements/FSEP.cpp index 63fc71e8a..22a3225dc 100644 --- a/src/simulation/elements/FSEP.cpp +++ b/src/simulation/elements/FSEP.cpp @@ -56,8 +56,8 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS) } else if (parts[i].life < 40) { parts[i].life--; - if (!(random_gen()%10)) { - r = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_PLSM); + if (RNG::Ref().chance(1, 10)) { + r = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_PLSM); if (r>-1) parts[r].life = 50; } @@ -70,7 +70,7 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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; } diff --git a/src/simulation/elements/FUSE.cpp b/src/simulation/elements/FUSE.cpp index db6d56195..573603652 100644 --- a/src/simulation/elements/FUSE.cpp +++ b/src/simulation/elements/FUSE.cpp @@ -56,8 +56,8 @@ int Element_FUSE::update(UPDATE_FUNC_ARGS) } else if (parts[i].life < 40) { parts[i].life--; - if (!(random_gen()%100)) { - r = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, PT_PLSM); + if (RNG::Ref().chance(1, 100)) { + r = sim->create_part(-1, x + RNG::Ref().chance(-1, 1), y + RNG::Ref().chance(-1, 1), PT_PLSM); if (r>-1) parts[r].life = 50; } @@ -78,7 +78,7 @@ int Element_FUSE::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) 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) parts[i].life = 39; diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp index 8a22ccf6e..d3beb141e 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -49,14 +49,14 @@ Element_FWRK::Element_FWRK() //#TPT-Directive ElementHeader Element_FWRK static int 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; int randTmp; sim->GetGravityField(x, y, sim->elements[PT_FWRK].Gravity, 1.0f, gx, gy); 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; 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); //Some variation in speed parallel to gravity direction - randTmp = (random_gen()%200)-100; + randTmp = RNG::Ref().between(-100, 100); gx += gx*randTmp*0.002f; gy += gy*randTmp*0.002f; //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; 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].vx -= gx*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) { - int r = (random_gen()%245+11); - int g = (random_gen()%245+11); - int b = (random_gen()%245+11); + int r = RNG::Ref().between(11, 255); + int g = RNG::Ref().between(11, 255); + int b = RNG::Ref().between(11, 255); int n; float angle, magnitude; 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); if (np>-1) { - magnitude = ((random_gen()%60)+40)*0.05f; - angle = (random_gen()%6284)*0.001f;//(in radians, between 0 and 2*pi) + magnitude = RNG::Ref().between(40, 99) * 0.05f; + 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].vy = parts[i].vy*0.5f + sinf(angle)*magnitude; parts[np].ctype = col; parts[np].tmp = 1; - parts[np].life = random_gen()%40+70; - parts[np].temp = (random_gen()%500)+5750.0f; + parts[np].life = RNG::Ref().between(70, 109); + parts[np].temp = RNG::Ref().between(5750, 6249); parts[np].dcolour = parts[i].dcolour; } } diff --git a/src/simulation/elements/GEL.cpp b/src/simulation/elements/GEL.cpp index dd90708fb..d10ecc058 100644 --- a/src/simulation/elements/GEL.cpp +++ b/src/simulation/elements/GEL.cpp @@ -50,10 +50,11 @@ int Element_GEL::update(UPDATE_FUNC_ARGS) { int r, rx, ry, rt; bool gel; - int absorbChanceDenom; - if (parts[i].tmp>100) parts[i].tmp = 100; - if (parts[i].tmp<0) parts[i].tmp = 0; - absorbChanceDenom = parts[i].tmp*10 + 500; + if (parts[i].tmp > 100) + parts[i].tmp = 100; + if (parts[i].tmp < 0) + parts[i].tmp = 0; + int absorbChanceDenom = parts[i].tmp * 10 + 500; for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) if (BOUNDS_CHECK && (rx || ry)) @@ -69,31 +70,31 @@ int Element_GEL::update(UPDATE_FUNC_ARGS) case PT_WATR: case PT_DSTW: 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++; sim->kill_part(ID(r)); } break; 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++; sim->create_part(ID(r), x+rx, y+ry, PT_CLST); } break; 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++; - if (random_gen()%4) + if (RNG::Ref().chance(3, 4)) sim->kill_part(ID(r)); else sim->part_change_type(ID(r), x+rx, y+ry, PT_SALT); } break; 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++; sim->part_change_type(ID(r), x+rx, y+ry, PT_CO2); diff --git a/src/simulation/elements/GLOW.cpp b/src/simulation/elements/GLOW.cpp index b80acf9fa..39a9053a8 100644 --- a/src/simulation/elements/GLOW.cpp +++ b/src/simulation/elements/GLOW.cpp @@ -56,7 +56,7 @@ int Element_GLOW::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_WATR && !(random_gen()%400)) + if (TYP(r)==PT_WATR && RNG::Ref().chance(1, 400)) { sim->kill_part(i); sim->part_change_type(ID(r),x+rx,y+ry,PT_DEUT); diff --git a/src/simulation/elements/GOLD.cpp b/src/simulation/elements/GOLD.cpp index 1ec03198c..2ffb3af75 100644 --- a/src/simulation/elements/GOLD.cpp +++ b/src/simulation/elements/GOLD.cpp @@ -55,7 +55,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS) static int checkCoordsY[] = { 0, 0, -4, 4 }; //Find nearby rusted iron (BMTL with tmp 1+) for(int j = 0; j < 8; j++){ - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); rx = (rndstore % 9)-4; rndstore >>= 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 (!(random_gen()%7)) + if (RNG::Ref().chance(1, 7)) { 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) int Element_GOLD::graphics(GRAPHICS_FUNC_ARGS) { - int rndstore = random_gen(); + int rndstore = RNG::Ref().gen(); *colr += (rndstore % 10) - 5; rndstore >>= 4; *colg += (rndstore % 10)- 5; diff --git a/src/simulation/elements/GOO.cpp b/src/simulation/elements/GOO.cpp index e0b9c8012..c32f7da82 100644 --- a/src/simulation/elements/GOO.cpp +++ b/src/simulation/elements/GOO.cpp @@ -51,7 +51,7 @@ Element_GOO::Element_GOO() int Element_GOO::update(UPDATE_FUNC_ARGS) { 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) { parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; diff --git a/src/simulation/elements/GRAV.cpp b/src/simulation/elements/GRAV.cpp index c5d874731..b4e394ffb 100644 --- a/src/simulation/elements/GRAV.cpp +++ b/src/simulation/elements/GRAV.cpp @@ -50,7 +50,7 @@ Element_GRAV::Element_GRAV() //#TPT-Directive ElementHeader Element_GRAV static int 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) parts[i].life = 48; diff --git a/src/simulation/elements/H2.cpp b/src/simulation/elements/H2.cpp index 83fd39f2c..2ea5b157a 100644 --- a/src/simulation/elements/H2.cpp +++ b/src/simulation/elements/H2.cpp @@ -77,14 +77,14 @@ int Element_H2::update(UPDATE_FUNC_ARGS) parts[ID(r)].temp=2473.15f; parts[ID(r)].tmp |= 1; 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; return 1; } 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); - parts[i].temp+=(random_gen()%100); + parts[i].temp += RNG::Ref().between(0, 99); parts[i].tmp |= 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 (!(random_gen()%5)) + if (RNG::Ref().chance(1, 5)) { int j; 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); if (j>-1) parts[j].temp = temp; - if (!(random_gen()%10)) + if (RNG::Ref().chance(1, 10)) { j = sim->create_part(-3,x,y,PT_ELEC); if (j>-1) @@ -115,7 +115,7 @@ int Element_H2::update(UPDATE_FUNC_ARGS) parts[j].temp = temp; 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) { 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[i].temp = temp+750+random_gen()%500; + parts[i].temp = temp + RNG::Ref().between(750, 1249); sim->pv[y/CELL][x/CELL] += 30; return 1; } diff --git a/src/simulation/elements/ICEI.cpp b/src/simulation/elements/ICEI.cpp index 1c07fe882..78e9f9b5b 100644 --- a/src/simulation/elements/ICEI.cpp +++ b/src/simulation/elements/ICEI.cpp @@ -61,14 +61,14 @@ int Element_ICEI::update(UPDATE_FUNC_ARGS) continue; 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(ID(r),x+rx,y+ry,PT_SLTW); 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); parts[ID(r)].ctype = PT_FRZW; diff --git a/src/simulation/elements/IRON.cpp b/src/simulation/elements/IRON.cpp index 9901d0c3f..8ee1ac09a 100644 --- a/src/simulation/elements/IRON.cpp +++ b/src/simulation/elements/IRON.cpp @@ -58,19 +58,19 @@ int Element_IRON::update(UPDATE_FUNC_ARGS) switch TYP(r) { case PT_SALT: - if (!(random_gen()%47)) + if (RNG::Ref().chance(1, 47)) goto succ; break; case PT_SLTW: - if (!(random_gen()%67)) + if (RNG::Ref().chance(1, 67)) goto succ; break; case PT_WATR: - if (!(random_gen()%1200)) + if (RNG::Ref().chance(1, 1200)) goto succ; break; case PT_O2: - if (!(random_gen()%250)) + if (RNG::Ref().chance(1, 250)) goto succ; break; case PT_LO2: @@ -82,7 +82,7 @@ int Element_IRON::update(UPDATE_FUNC_ARGS) return 0; succ: 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; } diff --git a/src/simulation/elements/ISOZ.cpp b/src/simulation/elements/ISOZ.cpp index 4766755cb..c3ea9b6c3 100644 --- a/src/simulation/elements/ISOZ.cpp +++ b/src/simulation/elements/ISOZ.cpp @@ -48,11 +48,11 @@ Element_ISOZ::Element_ISOZ() int Element_ISOZ::update(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ 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); - rr = (random_gen()%228+128)/127.0f; - rrr = (random_gen()%360)*3.14159f/180.0f; + rr = RNG::Ref().between(128, 355) / 127.0f; + rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; parts[i].vx = rr*cosf(rrr); parts[i].vy = rr*sinf(rrr); } diff --git a/src/simulation/elements/ISZS.cpp b/src/simulation/elements/ISZS.cpp index 97cf468ae..ddce97448 100644 --- a/src/simulation/elements/ISZS.cpp +++ b/src/simulation/elements/ISZS.cpp @@ -48,11 +48,11 @@ Element_ISZS::Element_ISZS() int Element_ISZS::update(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ 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); - rr = (random_gen()%228+128)/127.0f; - rrr = (random_gen()%360)*3.14159f/180.0f; + rr = RNG::Ref().between(128, 355) / 127.0f; + rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; parts[i].vx = rr*cosf(rrr); parts[i].vy = rr*sinf(rrr); } diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index 50fa57c1d..00610d819 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -91,11 +91,11 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS) rt = TYP(r); if ((surround_space || sim->elements[rt].Explosive) && (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); 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; if (sim->elements[rt].Explosive) sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; @@ -115,12 +115,12 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS) case PT_PLUT: parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful, MIN_TEMP, MAX_TEMP); 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); - parts[ID(r)].life = random_gen()%480+480; - parts[ID(r)].vx=random_gen()%10-5; - parts[ID(r)].vy=random_gen()%10-5; + parts[ID(r)].life = RNG::Ref().between(480, 959); + parts[ID(r)].vx = RNG::Ref().between(-5, 5); + parts[ID(r)].vy = RNG::Ref().between(-5, 5); } break; case PT_COAL: @@ -208,15 +208,15 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS) }*/ //if (parts[i].tmp2==1/* || near!=-1*/) - //angle=0;//parts[i].tmp-30+random_gen()%60; - angle = (parts[i].tmp-30+random_gen()%60)%360; - multipler=parts[i].life*1.5+random_gen()%((int)(parts[i].life+1)); + //angle=0;//parts[i].tmp + RNG::Ref().between(-30, 30); + angle = (parts[i].tmp + RNG::Ref().between(-30, 30)) % 360; + multipler = parts[i].life * 1.5 + RNG::Ref().between(0, parts[i].life); rx=cos(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); 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; 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); @@ -278,8 +278,8 @@ bool Element_LIGH::create_LIGH(Simulation * sim, int x, int y, int c, int temp, sim->parts[p].tmp = tmp; if (last) { - sim->parts[p].tmp2=1+((int)(random_gen()%200) > tmp2*tmp2/10+60); - sim->parts[p].life=(int)(life/1.5-random_gen()%2); + sim->parts[p].tmp2 = 1 + (RNG::Ref().between(0, 199) > tmp2*tmp2/10+60); + sim->parts[p].life = (int)(life/1.5 - RNG::Ref().between(0, 1)); } else { diff --git a/src/simulation/elements/MERC.cpp b/src/simulation/elements/MERC.cpp index 365bbb24f..3dc29ed02 100644 --- a/src/simulation/elements/MERC.cpp +++ b/src/simulation/elements/MERC.cpp @@ -53,8 +53,8 @@ int Element_MERC::update(UPDATE_FUNC_ARGS) // Obscure division by 0 fix if (parts[i].temp + 1 == 0) parts[i].temp = 0; - int maxtmp = ((absorbScale/(parts[i].temp + 1))-1); - if ((absorbScale%((int)parts[i].temp+1))>random_gen()%((int)parts[i].temp+1)) + int maxtmp = (absorbScale/(parts[i].temp + 1))-1; + if (RNG::Ref().chance(absorbScale%((int)parts[i].temp+1), parts[i].temp+1)) maxtmp ++; if (parts[i].tmp < 0) @@ -75,7 +75,7 @@ int Element_MERC::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r || (parts[i].tmp >=maxtmp)) 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) { @@ -105,8 +105,8 @@ int Element_MERC::update(UPDATE_FUNC_ARGS) } for ( trade = 0; trade<4; trade ++) { - rx = random_gen()%5-2; - ry = random_gen()%5-2; + rx = RNG::Ref().between(-2, 2); + ry = RNG::Ref().between(-2, 2); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/NBLE.cpp b/src/simulation/elements/NBLE.cpp index 097250777..9041d0e99 100644 --- a/src/simulation/elements/NBLE.cpp +++ b/src/simulation/elements/NBLE.cpp @@ -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) { parts[i].tmp |= 0x1; - if (!(random_gen()%5)) + if (RNG::Ref().chance(1, 5)) { int j; 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); if (j != -1) parts[j].temp = temp; - if (!(random_gen()%25)) + if (RNG::Ref().chance(1, 25)) { j = sim->create_part(-3,x,y,PT_ELEC); if (j != -1) @@ -73,7 +73,7 @@ int Element_NBLE::update(UPDATE_FUNC_ARGS) parts[j].temp = temp; 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) { 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[i].temp = temp+1750+random_gen()%500; + parts[i].temp = temp + 1750 + RNG::Ref().between(0, 499); sim->pv[y/CELL][x/CELL] += 50; } } diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index 3351b913f..5f975e86b 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -58,7 +58,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS) switch (TYP(r)) { 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); case PT_ICEI: case PT_SNOW: @@ -66,11 +66,11 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS) parts[i].vy *= 0.995; break; 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; if (parts[ID(r)].type==PT_LAVA) { parts[ID(r)].tmp = 100; @@ -89,7 +89,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS) break; #ifdef SDEUT 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); sim->kill_part(ID(r)); @@ -97,7 +97,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS) break; #else 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); 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; #endif 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); break; 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); break; case PT_YEST: sim->part_change_type(ID(r),x+rx,y+ry,PT_DYST); break; 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); break; 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); break; case PT_PLNT: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); break; case PT_DESL: 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); break; case PT_COAL: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); break; case PT_BCOL: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_SAWD); break; 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); break; case PT_FWRK: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) parts[ID(r)].ctype = PT_DUST; break; case PT_ACID: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) sim->create_part(ID(r), x+rx, y+ry, PT_ISOZ); break; case PT_TTAN: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) { sim->kill_part(i); return 1; } break; case PT_EXOT: - if (!(random_gen()%20)) + if (RNG::Ref().chance(1, 20)) parts[ID(r)].life = 1500; break; case PT_RFRG: - if (random_gen()%2) + if (RNG::Ref().chance(1, 2)) sim->create_part(ID(r), x+rx, y+ry, PT_GAS); else sim->create_part(ID(r), x+rx, y+ry, PT_CAUS); diff --git a/src/simulation/elements/O2.cpp b/src/simulation/elements/O2.cpp index 35974632b..2622e72c1 100644 --- a/src/simulation/elements/O2.cpp +++ b/src/simulation/elements/O2.cpp @@ -58,19 +58,19 @@ int Element_O2::update(UPDATE_FUNC_ARGS) if (TYP(r)==PT_FIRE) { - parts[ID(r)].temp+=(random_gen()%100); - if(parts[ID(r)].tmp&0x01) - parts[ID(r)].temp=3473; + parts[ID(r)].temp += RNG::Ref().between(0, 99); + if (parts[ID(r)].tmp & 0x01) + parts[ID(r)].temp = 3473; parts[ID(r)].tmp |= 2; 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; } else if (TYP(r)==PT_PLSM && !(parts[ID(r)].tmp&4)) { 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; } } @@ -81,7 +81,7 @@ int Element_O2::update(UPDATE_FUNC_ARGS) float gravy = sim->gravy[gravPos]; if (gravx*gravx + gravy*gravy > 400) { - if (!(random_gen()%5)) + if (RNG::Ref().chance(1, 5)) { int j; 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].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) { j = sim->create_part(-3,rx,ry,PT_PLSM); diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index d800d625c..17544b874 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -464,6 +464,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original rndstore = RNG::Ref().gen(); // RAND_MAX is at least 32767 on all platforms i.e. pow(8,5)-1 // 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 { rnd = rndstore&7;