From 44a8665f6f9f6cb8cba67a5a1acd2f09b446ed73 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 2 May 2018 23:53:15 -0400 Subject: [PATCH] update rng functions in a lot of element files to use .between/.chance conversion is still very incomplete --- src/common/tpt-rand.cpp | 11 +++++++++-- src/common/tpt-rand.h | 3 ++- src/simulation/elements/ACID.cpp | 4 ++-- src/simulation/elements/BANG.cpp | 6 +++--- src/simulation/elements/IGNT.cpp | 2 +- src/simulation/elements/PBCN.cpp | 6 +++--- src/simulation/elements/PCLN.cpp | 4 ++-- src/simulation/elements/PHOT.cpp | 21 +++++++++++---------- src/simulation/elements/PIPE.cpp | 4 ++-- src/simulation/elements/PLNT.cpp | 10 +++++----- src/simulation/elements/PLUT.cpp | 2 +- src/simulation/elements/POLO.cpp | 4 ++-- src/simulation/elements/PROT.cpp | 6 +++--- src/simulation/elements/PRTI.cpp | 12 ++++++------ src/simulation/elements/PRTO.cpp | 10 +++++----- src/simulation/elements/QRTZ.cpp | 8 ++++---- src/simulation/elements/RIME.cpp | 2 +- src/simulation/elements/RPEL.cpp | 4 ++-- src/simulation/elements/SHLD1.cpp | 4 ++-- src/simulation/elements/SHLD2.cpp | 4 ++-- src/simulation/elements/SHLD3.cpp | 4 ++-- src/simulation/elements/SHLD4.cpp | 2 +- src/simulation/elements/SING.cpp | 14 +++++++------- src/simulation/elements/SLTW.cpp | 9 +++++---- src/simulation/elements/SNOW.cpp | 2 +- src/simulation/elements/SPNG.cpp | 14 +++++++------- src/simulation/elements/SPRK.cpp | 14 +++++++------- src/simulation/elements/STKM.cpp | 14 +++++++------- src/simulation/elements/THDR.cpp | 4 ++-- src/simulation/elements/TRON.cpp | 4 ++-- src/simulation/elements/TUNG.cpp | 14 +++++++------- src/simulation/elements/VIBR.cpp | 12 ++++++------ src/simulation/elements/VINE.cpp | 2 +- src/simulation/elements/VIRS.cpp | 6 +++--- src/simulation/elements/WARP.cpp | 10 +++++----- src/simulation/elements/WATR.cpp | 19 ++++++++----------- src/simulation/elements/WTRV.cpp | 2 +- src/simulation/elements/YEST.cpp | 2 +- 38 files changed, 141 insertions(+), 134 deletions(-) diff --git a/src/common/tpt-rand.cpp b/src/common/tpt-rand.cpp index 7b2ddcbd1..c93a88ae7 100644 --- a/src/common/tpt-rand.cpp +++ b/src/common/tpt-rand.cpp @@ -22,6 +22,11 @@ uint64_t RNG::next() return result; } +unsigned int RNG::gen() +{ + return next() & 0x7FFFFFFF; +} + unsigned int RNG::operator()() { return next()&0xFFFFFFFF; @@ -33,9 +38,11 @@ int RNG::between(int lower, int upper) return static_cast(r % (upper - lower + 1)) + lower; } -bool RNG::chance(float chance) +bool RNG::chance(int nominator, unsigned int denominator) { - return uniform01() < chance; + if (nominator < 0) + return false; + return next() % denominator < static_cast(nominator); } float RNG::uniform01() diff --git a/src/common/tpt-rand.h b/src/common/tpt-rand.h index 198ce45bf..3bd0aa402 100644 --- a/src/common/tpt-rand.h +++ b/src/common/tpt-rand.h @@ -11,8 +11,9 @@ private: uint64_t next(); public: unsigned int operator()(); + unsigned int gen(); int between(int lower, int upper); - bool chance(float chance); + bool chance(int nominator, unsigned int denominator); float uniform01(); RNG(); diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp index c374ea779..ecb2daf87 100644 --- a/src/simulation/elements/ACID.cpp +++ b/src/simulation/elements/ACID.cpp @@ -69,14 +69,14 @@ int Element_ACID::update(UPDATE_FUNC_ARGS) } else if (rt == PT_WTRV) { - if (RNG::Ref().chance(1/250.0f)) + if (RNG::Ref().chance(1, 250)) { sim->part_change_type(i, x, y, PT_CAUS); parts[i].life = RNG::Ref().between(25, 74); sim->kill_part(ID(r)); } } - else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && RNG::Ref().chance(sim->elements[rt].Hardness/1000.0)) + else if (rt != PT_CLNE && rt != PT_PCLN && parts[i].life >= 50 && RNG::Ref().chance(sim->elements[rt].Hardness, 1000.0)) { if (sim->parts_avg(i, ID(r),PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid { diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp index dc51ca625..ab471e987 100644 --- a/src/simulation/elements/BANG.cpp +++ b/src/simulation/elements/BANG.cpp @@ -87,9 +87,9 @@ int Element_BANG::update(UPDATE_FUNC_ARGS) //Explode!! sim->pv[y/CELL][x/CELL] += 0.5f; parts[i].tmp = 0; - if (RNG::Ref().chance(1.0/3)) + if (RNG::Ref().chance(1, 3)) { - if (RNG::Ref().chance(1.0/2)) + if (RNG::Ref().chance(1, 2)) { sim->create_part(i, x, y, PT_FIRE); } @@ -102,7 +102,7 @@ int Element_BANG::update(UPDATE_FUNC_ARGS) } else { - if (RNG::Ref().chance(1.0/15)) + if (RNG::Ref().chance(1, 15)) { sim->create_part(i, x, y, PT_EMBR); parts[i].tmp = 0; diff --git a/src/simulation/elements/IGNT.cpp b/src/simulation/elements/IGNT.cpp index 384f96681..652d9049c 100644 --- a/src/simulation/elements/IGNT.cpp +++ b/src/simulation/elements/IGNT.cpp @@ -66,7 +66,7 @@ int Element_IGNT::update(UPDATE_FUNC_ARGS) } else if(parts[i].life > 0) { - if (RNG::Ref().chance(2.0/3)) + if (RNG::Ref().chance(2, 3)) { int nb = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), PT_EMBR); if (nb!=-1) { diff --git a/src/simulation/elements/PBCN.cpp b/src/simulation/elements/PBCN.cpp index fbb2e5273..adc55fc73 100644 --- a/src/simulation/elements/PBCN.cpp +++ b/src/simulation/elements/PBCN.cpp @@ -52,7 +52,7 @@ int Element_PBCN::update(UPDATE_FUNC_ARGS) { int r, rx, ry, rt; if (!parts[i].tmp2 && sim->pv[y/CELL][x/CELL]>4.0f) - parts[i].tmp2 = random_gen()%40+80; + parts[i].tmp2 = RNG::Ref().between(80, 119); if (parts[i].tmp2) { parts[i].vx += ADVECTION*sim->vx[y/CELL][x/CELL]; @@ -132,9 +132,9 @@ int Element_PBCN::update(UPDATE_FUNC_ARGS) for (ry=-1; ry<2; ry++) sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); - else if (parts[i].ctype!=PT_LIGH || !(random_gen()%30)) + 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>-1) { 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/PCLN.cpp b/src/simulation/elements/PCLN.cpp index c4e967d24..908dec34a 100644 --- a/src/simulation/elements/PCLN.cpp +++ b/src/simulation/elements/PCLN.cpp @@ -123,9 +123,9 @@ int Element_PCLN::update(UPDATE_FUNC_ARGS) for (ry=-1; ry<2; ry++) sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); - else if (parts[i].ctype!=PT_LIGH || (random_gen()%30)==0) + 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/PHOT.cpp b/src/simulation/elements/PHOT.cpp index 26e51192f..d3a7034ed 100644 --- a/src/simulation/elements/PHOT.cpp +++ b/src/simulation/elements/PHOT.cpp @@ -55,7 +55,8 @@ int Element_PHOT::update(UPDATE_FUNC_ARGS) return 1; } if (parts[i].temp > 506) - if (!(random_gen()%10)) Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); + if (RNG::Ref().chance(1, 10)) + Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (BOUNDS_CHECK) { @@ -64,16 +65,16 @@ int Element_PHOT::update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_ISOZ || TYP(r)==PT_ISZS) { - if (!(random_gen()%400)) + if (RNG::Ref().chance(1, 400)) { parts[i].vx *= 0.90; parts[i].vy *= 0.90; sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); - rrr = (random_gen()%360)*3.14159f/180.0f; + rrr = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; if (TYP(r) == PT_ISOZ) - rr = (random_gen()%128+128)/127.0f; + rr = RNG::Ref().between(128, 255) / 127.0f; else - rr = (random_gen()%228+128)/127.0f; + rr = RNG::Ref().between(128, 355) / 127.0f; parts[ID(r)].vx = rr*cosf(rrr); parts[ID(r)].vy = rr*sinf(rrr); sim->pv[y/CELL][x/CELL] -= 15.0f * CFDS; @@ -81,17 +82,17 @@ int Element_PHOT::update(UPDATE_FUNC_ARGS) } else if((TYP(r) == PT_QRTZ || TYP(r) == PT_PQRT) && !ry && !rx)//if on QRTZ { - float a = (random_gen()%360)*3.14159f/180.0f; + float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; parts[i].vx = 3.0f*cosf(a); parts[i].vy = 3.0f*sinf(a); if(parts[i].ctype == 0x3FFFFFFF) - parts[i].ctype = 0x1F<<(random_gen()%26); + parts[i].ctype = 0x1F << RNG::Ref().between(0, 25); if (parts[i].life) parts[i].life++; //Delay death } else if(TYP(r) == PT_BGLA && !ry && !rx)//if on BGLA { - float a = (random_gen()%101 - 50) * 0.001f; + float a = RNG::Ref().between(-50, 50) * 0.001f; float rx = cosf(a), ry = sinf(a), vx, vy; vx = rx * parts[i].vx + ry * parts[i].vy; vy = rx * parts[i].vy - ry * parts[i].vx; @@ -100,8 +101,8 @@ int Element_PHOT::update(UPDATE_FUNC_ARGS) } else if (TYP(r) == PT_FILT && parts[ID(r)].tmp==9) { - parts[i].vx += ((float)(random_gen()%1000-500))/1000.0f; - parts[i].vy += ((float)(random_gen()%1000-500))/1000.0f; + parts[i].vx += ((float)RNG::Ref().between(-500, 500))/1000.0f; + parts[i].vy += ((float)RNG::Ref().between(-500, 500))/1000.0f; } } return 0; diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 83964bbf3..a303bf3ce 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -191,7 +191,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS) if (nt)//there is something besides PIPE around current particle { - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); rnd = rndstore&7; //rndstore = rndstore>>3; rx = pos_1_rx[rnd]; @@ -433,7 +433,7 @@ void Element_PIPE::pushParticle(Simulation * sim, int i, int count, int original if( !(sim->parts[i].tmp&0x200) ) { //normal random push - rndstore = random_gen(); + 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 for (q=0; q<3; q++)//try to push 3 times diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp index 4d87510e0..d74a72689 100644 --- a/src/simulation/elements/PLNT.cpp +++ b/src/simulation/elements/PLNT.cpp @@ -60,7 +60,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS) switch (TYP(r)) { case PT_WATR: - if (!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) { np = sim->create_part(ID(r),x+rx,y+ry,PT_PLNT); if (np<0) continue; @@ -68,7 +68,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS) } break; case PT_LAVA: - if (!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -76,14 +76,14 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS) break; case PT_SMKE: case PT_CO2: - if (!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) { sim->kill_part(ID(r)); - parts[i].life = random_gen()%60 + 60; + parts[i].life = RNG::Ref().between(60, 119); } break; case PT_WOOD: - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); if (surround_space && !(rndstore%4) && parts[i].tmp==1) { rndstore >>= 3; diff --git a/src/simulation/elements/PLUT.cpp b/src/simulation/elements/PLUT.cpp index 57ea9c5ca..4f88bc13c 100644 --- a/src/simulation/elements/PLUT.cpp +++ b/src/simulation/elements/PLUT.cpp @@ -48,7 +48,7 @@ Element_PLUT::Element_PLUT() //#TPT-Directive ElementHeader Element_PLUT static int update(UPDATE_FUNC_ARGS) int Element_PLUT::update(UPDATE_FUNC_ARGS) { - if (!(random_gen()%100) && (5.0f*sim->pv[y/CELL][x/CELL]) > (random_gen()%1000)) + if (RNG::Ref().chance(1, 100) && RNG::Ref().chance(5.0f*sim->pv[y/CELL][x/CELL], 1000)) { sim->create_part(i, x, y, PT_NEUT); } diff --git a/src/simulation/elements/POLO.cpp b/src/simulation/elements/POLO.cpp index f88cc67d4..491ce9add 100644 --- a/src/simulation/elements/POLO.cpp +++ b/src/simulation/elements/POLO.cpp @@ -55,7 +55,7 @@ int Element_POLO::update(UPDATE_FUNC_ARGS) int r = sim->photons[y][x]; if (parts[i].tmp < LIMIT && !parts[i].life) { - if (!(random_gen()%10000) && !parts[i].tmp) + if (RNG::Ref().chance(1, 10000) && !parts[i].tmp) { int s = sim->create_part(-3, x, y, PT_NEUT); if (s >= 0) @@ -68,7 +68,7 @@ int Element_POLO::update(UPDATE_FUNC_ARGS) } } - if (r && !(random_gen()%100)) + if (r && RNG::Ref().chance(1, 100)) { int s = sim->create_part(-3, x, y, PT_NEUT); if (s >= 0) diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index 34576da71..af99b3883 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -68,7 +68,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) break; } case PT_DEUT: - if ((-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100)) > (int)(random_gen() % 200)) + if (RNG::Ref().chance(-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100), 200)) { DeutImplosion(sim, parts[uID].life, x, y, restrict_flt(parts[uID].temp + parts[uID].life * 500, MIN_TEMP, MAX_TEMP), PT_PROT); sim->kill_part(uID); @@ -76,7 +76,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) break; case PT_LCRY: //Powered LCRY reaction: PROT->PHOT - if (parts[uID].life > 5 && !(random_gen() % 10)) + if (parts[uID].life > 5 && RNG::Ref().chance(1, 10)) { sim->part_change_type(i, x, y, PT_PHOT); parts[i].life *= 2; @@ -143,7 +143,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) element = PT_CO2; else element = PT_NBLE; - newID = sim->create_part(-1, x+random_gen()%3-1, y+random_gen()%3-1, element); + newID = sim->create_part(-1, x + RNG::Ref().between(-1, 1), y + RNG::Ref().between(-1, 1), element); if (newID >= 0) parts[newID].temp = restrict_flt(100.0f*parts[i].tmp, MIN_TEMP, MAX_TEMP); sim->kill_part(i); diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp index 9cdbd7e49..d1dab4274 100644 --- a/src/simulation/elements/PRTI.cpp +++ b/src/simulation/elements/PRTI.cpp @@ -116,22 +116,22 @@ int Element_PRTI::update(UPDATE_FUNC_ARGS) if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!sim->parts[i].life) parts[i].life = random_gen(); - if (!sim->parts[i].ctype) parts[i].ctype = random_gen(); + if (!sim->parts[i].life) parts[i].life = RNG::Ref().gen(); + if (!sim->parts[i].ctype) parts[i].ctype = RNG::Ref().gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (int r = 0; r < 4; r++) { if (orbd[r]>1) { orbd[r] -= 12; if (orbd[r]<1) { - orbd[r] = (random_gen()%128)+128; - orbl[r] = random_gen()%255; + orbd[r] = RNG::Ref().between(128, 255); + orbl[r] = RNG::Ref().between(0, 254); } else { orbl[r] += 2; orbl[r] = orbl[r]%255; } } else { - orbd[r] = (random_gen()%128)+128; - orbl[r] = random_gen()%255; + orbd[r] = RNG::Ref().between(128, 255); + orbl[r] = RNG::Ref().between(0, 254); } } sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); diff --git a/src/simulation/elements/PRTO.cpp b/src/simulation/elements/PRTO.cpp index ad2c92a40..f126c28cc 100644 --- a/src/simulation/elements/PRTO.cpp +++ b/src/simulation/elements/PRTO.cpp @@ -73,7 +73,7 @@ int Element_PRTO::update(UPDATE_FUNC_ARGS) fe = 1; for ( nnx =0 ; nnx<80; nnx++) { - int randomness = (count + random_gen()%3-1 + 4)%8;//add -1,0,or 1 to count + int randomness = (count + RNG::Ref().between(-1, 1) + 4) % 8;//add -1,0,or 1 to count if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_SPRK)// TODO: make it look better, spark creation { sim->create_part(-1,x+1,y,PT_SPRK); @@ -141,15 +141,15 @@ int Element_PRTO::update(UPDATE_FUNC_ARGS) if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!sim->parts[i].life) parts[i].life = random_gen(); - if (!sim->parts[i].ctype) parts[i].ctype = random_gen(); + if (!sim->parts[i].life) parts[i].life = RNG::Ref().gen(); + if (!sim->parts[i].ctype) parts[i].ctype = RNG::Ref().gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (r = 0; r < 4; r++) { if (orbd[r]<254) { orbd[r] += 16; if (orbd[r]>254) { orbd[r] = 0; - orbl[r] = random_gen()%255; + orbl[r] = RNG::Ref().between(0, 254); } else { @@ -160,7 +160,7 @@ int Element_PRTO::update(UPDATE_FUNC_ARGS) //orbl[r] = orbl[r]%255; } else { orbd[r] = 0; - orbl[r] = random_gen()%255; + orbl[r] = RNG::Ref().between(0, 254); } } sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); diff --git a/src/simulation/elements/QRTZ.cpp b/src/simulation/elements/QRTZ.cpp index 7737250b7..ca25acd50 100644 --- a/src/simulation/elements/QRTZ.cpp +++ b/src/simulation/elements/QRTZ.cpp @@ -70,7 +70,7 @@ int Element_QRTZ::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - else if (TYP(r)==PT_SLTW && !(random_gen()%500)) + else if (TYP(r)==PT_SLTW && RNG::Ref().chance(1, 500)) { sim->kill_part(ID(r)); parts[i].tmp++; @@ -83,7 +83,7 @@ int Element_QRTZ::update(UPDATE_FUNC_ARGS) int rnd, sry, srx; for (trade = 0; trade < 9; trade++) { - rnd = random_gen()%0x3FF; + rnd = RNG::Ref().gen() % 0x3FF; rx = (rnd%5)-2; srx = (rnd%3)-1; rnd >>= 3; @@ -106,11 +106,11 @@ int Element_QRTZ::update(UPDATE_FUNC_ARGS) // If PQRT is stationary and has started growing particles of QRTZ, the PQRT is basically part of a new QRTZ crystal. So turn it back into QRTZ so that it behaves more like part of the crystal. sim->part_change_type(i,x,y,PT_QRTZ); } - if (random_gen()%2) + if (RNG::Ref().chance(1, 2)) { parts[np].tmp=-1;//dead qrtz } - else if (!parts[i].tmp && !(random_gen()%15)) + else if (!parts[i].tmp && RNG::Ref().chance(1, 15)) { parts[i].tmp=-1; } diff --git a/src/simulation/elements/RIME.cpp b/src/simulation/elements/RIME.cpp index 9c34891ae..1769e4ee9 100644 --- a/src/simulation/elements/RIME.cpp +++ b/src/simulation/elements/RIME.cpp @@ -58,7 +58,7 @@ int Element_RIME::update(UPDATE_FUNC_ARGS) if (TYP(r)==PT_SPRK) { sim->part_change_type(i,x,y,PT_FOG); - parts[i].life = random_gen()%50 + 60; + parts[i].life = RNG::Ref().between(60, 119); } else if (TYP(r)==PT_FOG&&parts[ID(r)].life>0) { diff --git a/src/simulation/elements/RPEL.cpp b/src/simulation/elements/RPEL.cpp index 8c5b9ab89..1822cb196 100644 --- a/src/simulation/elements/RPEL.cpp +++ b/src/simulation/elements/RPEL.cpp @@ -50,8 +50,8 @@ int Element_RPEL::update(UPDATE_FUNC_ARGS) int r, rx, ry, ri; for(ri = 0; ri <= 10; ri++) { - rx = (random_gen()%21)-10; - ry = (random_gen()%21)-10; + rx = RNG::Ref().between(-10, 10); + ry = RNG::Ref().between(-10, 10); if (x+rx >= 0 && x+rx < XRES && y+ry >= 0 && y+ry < YRES && (rx || ry)) { r = pmap[y+ry][x+rx]; diff --git a/src/simulation/elements/SHLD1.cpp b/src/simulation/elements/SHLD1.cpp index 5c10c1e8f..34be83ead 100644 --- a/src/simulation/elements/SHLD1.cpp +++ b/src/simulation/elements/SHLD1.cpp @@ -57,7 +57,7 @@ int Element_SHLD1::update(UPDATE_FUNC_ARGS) continue; else if (TYP(r)==PT_SPRK&&parts[i].life==0) { - if (11>random_gen()%40) + if (RNG::Ref().chance(11, 40)) { sim->part_change_type(i,x,y,PT_SHLD2); parts[i].life = 7; @@ -72,7 +72,7 @@ int Element_SHLD1::update(UPDATE_FUNC_ARGS) } } } - else if (TYP(r)==PT_SHLD3&&2>random_gen()%5) + else if (TYP(r) == PT_SHLD3 && RNG::Ref().chance(2, 5)) { sim->part_change_type(i,x,y,PT_SHLD2); parts[i].life = 7; diff --git a/src/simulation/elements/SHLD2.cpp b/src/simulation/elements/SHLD2.cpp index 8f1bab520..551aff0f1 100644 --- a/src/simulation/elements/SHLD2.cpp +++ b/src/simulation/elements/SHLD2.cpp @@ -61,7 +61,7 @@ int Element_SHLD2::update(UPDATE_FUNC_ARGS) } else if (TYP(r)==PT_SPRK&&parts[i].life==0) { - if (!(random_gen()%8)) + if (RNG::Ref().chance(1, 8)) { sim->part_change_type(i,x,y,PT_SHLD3); parts[i].life = 7; @@ -77,7 +77,7 @@ int Element_SHLD2::update(UPDATE_FUNC_ARGS) } } } - else if (TYP(r)==PT_SHLD4&&2>random_gen()%5) + else if (TYP(r) == PT_SHLD4 && RNG::Ref().chance(2, 5)) { sim->part_change_type(i,x,y,PT_SHLD3); parts[i].life = 7; diff --git a/src/simulation/elements/SHLD3.cpp b/src/simulation/elements/SHLD3.cpp index 67f80e5ff..ba96d95bc 100644 --- a/src/simulation/elements/SHLD3.cpp +++ b/src/simulation/elements/SHLD3.cpp @@ -55,7 +55,7 @@ int Element_SHLD3::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) { - if (!(random_gen()%2500)) + if (RNG::Ref().chance(1, 2500)) { np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); if (np<0) continue; @@ -71,7 +71,7 @@ int Element_SHLD3::update(UPDATE_FUNC_ARGS) } else if (TYP(r)==PT_SPRK&&parts[i].life==0) { - if (3>random_gen()%500) + if (RNG::Ref().chance(3, 500)) { sim->part_change_type(i,x,y,PT_SHLD4); parts[i].life = 7; diff --git a/src/simulation/elements/SHLD4.cpp b/src/simulation/elements/SHLD4.cpp index 238a8dc28..6be508ea4 100644 --- a/src/simulation/elements/SHLD4.cpp +++ b/src/simulation/elements/SHLD4.cpp @@ -55,7 +55,7 @@ int Element_SHLD4::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) { - if (!(random_gen()%5500)) + if (RNG::Ref().chance(1, 5500)) { np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); if (np<0) continue; diff --git a/src/simulation/elements/SING.cpp b/src/simulation/elements/SING.cpp index 8b120946c..51cf628ed 100644 --- a/src/simulation/elements/SING.cpp +++ b/src/simulation/elements/SING.cpp @@ -78,7 +78,7 @@ int Element_SING::update(UPDATE_FUNC_ARGS) spawncount = (spawncount>255) ? 3019 : std::pow((double)(spawncount/8), 2)*M_PI; for (int j = 0;j < spawncount; j++) { - switch(random_gen()%3) + switch (RNG::Ref().gen() % 3) { case 0: nb = sim->create_part(-3, x, y, PT_PHOT); @@ -91,10 +91,10 @@ int Element_SING::update(UPDATE_FUNC_ARGS) break; } if (nb!=-1) { - parts[nb].life = (random_gen()%300); + parts[nb].life = RNG::Ref().between(0, 299); parts[nb].temp = MAX_TEMP/2; - angle = random_gen.uniform01()*2.0f*M_PI; - v = random_gen.uniform01()*5.0f; + angle = RNG::Ref().uniform01()*2.0f*M_PI; + v = RNG::Ref().uniform01()*5.0f; parts[nb].vx = v*cosf(angle); parts[nb].vy = v*sinf(angle); } @@ -111,7 +111,7 @@ int Element_SING::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)!=PT_DMND&& !(random_gen()%3)) + if (TYP(r)!=PT_DMND&& RNG::Ref().chance(1, 3)) { if (TYP(r)==PT_SING && parts[ID(r)].life >10) { @@ -123,11 +123,11 @@ int Element_SING::update(UPDATE_FUNC_ARGS) { if (parts[i].life+3 > 255) { - if (parts[ID(r)].type!=PT_SING && !(random_gen()%100)) + if (parts[ID(r)].type!=PT_SING && RNG::Ref().chance(1, 1000)) { int np; np = sim->create_part(ID(r),x+rx,y+ry,PT_SING); - parts[np].life = random_gen()%50+60; + parts[np].life = RNG::Ref().between(60, 109); } continue; } diff --git a/src/simulation/elements/SLTW.cpp b/src/simulation/elements/SLTW.cpp index b56c2e374..0a011fa33 100644 --- a/src/simulation/elements/SLTW.cpp +++ b/src/simulation/elements/SLTW.cpp @@ -56,16 +56,16 @@ int Element_SLTW::update(UPDATE_FUNC_ARGS) switch TYP(r) { case PT_SALT: - if (!(random_gen()%2000)) + if (RNG::Ref().chance(1, 2000)) sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); break; case PT_PLNT: - if (!(random_gen()%40)) + if (RNG::Ref().chance(1, 40)) sim->kill_part(ID(r)); break; case PT_RBDM: case PT_LRBD: - if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(random_gen()%100)) + if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && RNG::Ref().chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; @@ -76,7 +76,8 @@ int Element_SLTW::update(UPDATE_FUNC_ARGS) if (parts[ID(r)].ctype!=PT_WATR) { 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/SNOW.cpp b/src/simulation/elements/SNOW.cpp index 40f7f4bef..c0c7a4fe9 100644 --- a/src/simulation/elements/SNOW.cpp +++ b/src/simulation/elements/SNOW.cpp @@ -60,7 +60,7 @@ int Element_SNOW::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_SALT || TYP(r)==PT_SLTW) && !(random_gen()%333)) + if ((TYP(r)==PT_SALT || TYP(r)==PT_SLTW) && RNG::Ref().chance(1, 333)) { sim->part_change_type(i,x,y,PT_SLTW); sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); diff --git a/src/simulation/elements/SPNG.cpp b/src/simulation/elements/SPNG.cpp index 21f1645b3..9616ce9f6 100644 --- a/src/simulation/elements/SPNG.cpp +++ b/src/simulation/elements/SPNG.cpp @@ -63,31 +63,31 @@ int Element_SPNG::update(UPDATE_FUNC_ARGS) case PT_WATR: case PT_DSTW: case PT_FRZW: - if (parts[i].liferandom_gen()%absorbChanceDenom) + if (parts[i].lifekill_part(ID(r)); } break; case PT_SLTW: - if (parts[i].liferandom_gen()%absorbChanceDenom) + if (parts[i].lifekill_part(ID(r)); else sim->part_change_type(ID(r), x+rx, y+ry, PT_SALT); } break; case PT_CBNW: - if (parts[i].liferandom_gen()%absorbChanceDenom) + if (parts[i].lifepart_change_type(ID(r), x+rx, y+ry, PT_CO2); } break; case PT_PSTE: - if (parts[i].liferandom_gen()%absorbChanceDenom) + if (parts[i].lifecreate_part(ID(r), x+rx, y+ry, PT_CLST); @@ -112,8 +112,8 @@ int Element_SPNG::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]; diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index b3d984916..dd8b979b7 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -99,7 +99,7 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) case PT_NBLE: if (parts[i].life<=1 && !(parts[i].tmp&0x1)) { - parts[i].life = random_gen()%150+50; + parts[i].life = RNG::Ref().between(50, 199); sim->part_change_type(i,x,y,PT_PLSM); parts[i].ctype = PT_NBLE; if (parts[i].temp > 5273.15) @@ -118,12 +118,12 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (r) continue; - if (parts[i].tmp>4 && random_gen()%(parts[i].tmp*parts[i].tmp/20+6)==0) + if (parts[i].tmp>4 && RNG::Ref().chance(1, parts[i].tmp*parts[i].tmp/20+6)) { int p = sim->create_part(-1, x+rx*2, y+ry*2, PT_LIGH); if (p!=-1) { - parts[p].life=random_gen()%(2+parts[i].tmp/15)+parts[i].tmp/7; + parts[p].life = RNG::Ref().between(0, 2+parts[i].tmp/15) + parts[i].tmp/7; if (parts[i].life>60) parts[i].life=60; parts[p].temp=parts[p].life*parts[i].tmp/2.5; @@ -151,17 +151,17 @@ int Element_SPRK::update(UPDATE_FUNC_ARGS) continue; if (TYP(r)==PT_DSTW || TYP(r)==PT_SLTW || TYP(r)==PT_WATR) { - int rnd = random_gen()%100; - if (!rnd) + int rndstore = RNG::Ref().gen()%100; + if (!rndstore) sim->part_change_type(ID(r),x+rx,y+ry,PT_O2); - else if (3>rnd) + else if (3 > rndstore) sim->part_change_type(ID(r),x+rx,y+ry,PT_H2); } } break; case PT_TUNG: if(parts[i].temp < 3595.0){ - parts[i].temp += (random_gen()%20)-4; + parts[i].temp += RNG::Ref().between(-4, 15); } default: break; diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index b8b9766f5..2f30396d5 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -403,7 +403,7 @@ int Element_STKM::run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { //Spawn if (((int)(playerp->comm)&0x08) == 0x08) { - ry -= 2*(random_gen()%2)+1; + ry -= 2 * RNG::Ref().between(0, 1) + 1; r = pmap[ry][rx]; if (sim->elements[TYP(r)].Properties&TYPE_SOLID) { @@ -439,7 +439,7 @@ int Element_STKM::run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { { if (playerp->elem == PT_PHOT) { - int random = abs((int)(random_gen()%3-1))*3; + int random = abs((RNG::Ref().between(-1, 1)))*3; if (random==0) { sim->kill_part(np); @@ -460,7 +460,7 @@ int Element_STKM::run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { if (gvx!=0 || gvy!=0) angle = atan2(gvx, gvy)*180.0f/M_PI; else - angle = random_gen()%360; + angle = RNG::Ref().between(0, 359); if (((int)playerp->pcomm)&0x01) angle += 180; if (angle>360) @@ -468,9 +468,9 @@ int Element_STKM::run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) { if (angle<0) angle+=360; parts[np].tmp = angle; - parts[np].life=random_gen()%(2+power/15)+power/7; - parts[np].temp=parts[np].life*power/2.5; - parts[np].tmp2=1; + parts[np].life = RNG::Ref().between(0, 2+power/15) + power/7; + parts[np].temp = parts[np].life*power/2.5; + parts[np].tmp2 = 1; } else if (!playerp->fan) { @@ -592,7 +592,7 @@ void Element_STKM::STKM_interact(Simulation *sim, playerst *playerp, int i, int { if (TYP(r)==PT_SPRK && playerp->elem!=PT_LIGH) //If on charge { - sim->parts[i].life -= random_gen.between(32, 52); + sim->parts[i].life -= RNG::Ref().between(32, 52); } if (sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||sim->parts[ID(r)].life==10) && ((playerp->elem!=PT_LIGH && sim->parts[ID(r)].temp>=323) || sim->parts[ID(r)].temp<=243) && (!playerp->rocketBoots || TYP(r)!=PT_PLSM)) diff --git a/src/simulation/elements/THDR.cpp b/src/simulation/elements/THDR.cpp index 562697c76..9d61ba672 100644 --- a/src/simulation/elements/THDR.cpp +++ b/src/simulation/elements/THDR.cpp @@ -68,9 +68,9 @@ int Element_THDR::update(UPDATE_FUNC_ARGS) else if (rt!=PT_CLNE&&rt!=PT_THDR&&rt!=PT_SPRK&&rt!=PT_DMND&&rt!=PT_FIRE) { sim->pv[y/CELL][x/CELL] += 100.0f; - if (sim->legacy_enable&&1>(random_gen()%200)) + if (sim->legacy_enable && RNG::Ref().chance(1, 200)) { - parts[i].life = random_gen()%50+120; + parts[i].life = RNG::Ref().between(120, 169); sim->part_change_type(i,x,y,PT_FIRE); } else diff --git a/src/simulation/elements/TRON.cpp b/src/simulation/elements/TRON.cpp index 8a576fc92..a381e2915 100644 --- a/src/simulation/elements/TRON.cpp +++ b/src/simulation/elements/TRON.cpp @@ -102,7 +102,7 @@ int Element_TRON::update(UPDATE_FUNC_ARGS) int originaldir = direction; //random turn - int random = random_gen()%340; + int random = RNG::Ref().between(0, 339); if ((random==1 || random==3) && !(parts[i].tmp & TRON_NORANDOM)) { //randomly turn left(3) or right(1) @@ -126,7 +126,7 @@ int Element_TRON::update(UPDATE_FUNC_ARGS) } else { - seconddir = (direction + ((random_gen()%2)*2)+1)% 4; + seconddir = (direction + (RNG::Ref().between(0, 1)*2)+1)% 4; lastdir = (seconddir + 2)%4; } seconddircheck = trymovetron(sim,x,y,seconddir,i,parts[i].tmp2); diff --git a/src/simulation/elements/TUNG.cpp b/src/simulation/elements/TUNG.cpp index 211889bfe..8cf743361 100644 --- a/src/simulation/elements/TUNG.cpp +++ b/src/simulation/elements/TUNG.cpp @@ -66,16 +66,16 @@ int Element_TUNG::update(UPDATE_FUNC_ARGS) } } } - if((parts[i].temp > MELTING_POINT && !(random_gen()%20)) || splode) + if((parts[i].temp > MELTING_POINT && RNG::Ref().chance(1, 20)) || splode) { - if(!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) { sim->pv[y/CELL][x/CELL] += 50.0f; } - else if(!(random_gen()%100)) + else if (RNG::Ref().chance(1, 100)) { sim->part_change_type(i, x, y, PT_FIRE); - parts[i].life = random_gen()%500; + parts[i].life = RNG::Ref().between(0, 499); return 1; } else @@ -86,10 +86,10 @@ int Element_TUNG::update(UPDATE_FUNC_ARGS) } if(splode) { - parts[i].temp = restrict_flt(MELTING_POINT + (random_gen()%600) + 200, MIN_TEMP, MAX_TEMP); + parts[i].temp = restrict_flt(MELTING_POINT + RNG::Ref().between(200, 799), MIN_TEMP, MAX_TEMP); } - parts[i].vx += (random_gen()%100)-50; - parts[i].vy += (random_gen()%100)-50; + parts[i].vx += RNG::Ref().between(-50, 50); + parts[i].vy += RNG::Ref().between(-50, 50); return 1; } parts[i].pavg[0] = parts[i].pavg[1]; diff --git a/src/simulation/elements/VIBR.cpp b/src/simulation/elements/VIBR.cpp index 43c5060c8..3072a7977 100644 --- a/src/simulation/elements/VIBR.cpp +++ b/src/simulation/elements/VIBR.cpp @@ -80,7 +80,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) { else //if it is exploding { //Release sparks before explode - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); if (parts[i].life < 300) { rx = rndstore%3-1; @@ -114,7 +114,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) { { if (!parts[i].tmp2) { - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); int index = sim->create_part(-3,x+((rndstore>>4)&3)-1,y+((rndstore>>6)&3)-1,PT_ELEC); if (index != -1) parts[index].temp = 7000; @@ -122,7 +122,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) { if (index != -1) parts[index].temp = 7000; int rx = ((rndstore>>12)&3)-1; - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); index = sim->create_part(-1,x+rx-1,y+rndstore%3-1,PT_BREC); if (index != -1) parts[index].temp = 7000; @@ -156,7 +156,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) { { if (!parts[ID(r)].life) parts[ID(r)].tmp += 45; - else if (parts[i].tmp2 && parts[i].life > 75 && random_gen()%2) + else if (parts[i].tmp2 && parts[i].life > 75 && RNG::Ref().chance(1, 2)) { parts[ID(r)].tmp2 = 1; parts[i].tmp = 0; @@ -171,7 +171,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) { else { //Melts into EXOT - if (TYP(r) == PT_EXOT && !(random_gen()%25)) + if (TYP(r) == PT_EXOT && RNG::Ref().chance(1, 25)) { sim->part_change_type(i, x, y, PT_EXOT); return 1; @@ -187,7 +187,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) { for (trade = 0; trade < 9; trade++) { if (!(trade%2)) - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); rx = rndstore%7-3; rndstore >>= 3; ry = rndstore%7-3; diff --git a/src/simulation/elements/VINE.cpp b/src/simulation/elements/VINE.cpp index 7b62627a5..0d726bc6c 100644 --- a/src/simulation/elements/VINE.cpp +++ b/src/simulation/elements/VINE.cpp @@ -49,7 +49,7 @@ Element_VINE::Element_VINE() //#TPT-Directive ElementHeader Element_VINE static int update(UPDATE_FUNC_ARGS) int Element_VINE::update(UPDATE_FUNC_ARGS) { - int r, np, rx, ry, rndstore = random_gen()&0x7FFFFFFF; + int r, np, rx, ry, rndstore = RNG::Ref().gen(); rx = (rndstore % 3) - 1; rndstore >>= 2; ry = (rndstore % 3) - 1; diff --git a/src/simulation/elements/VIRS.cpp b/src/simulation/elements/VIRS.cpp index 906fa62df..3b40e0a2b 100644 --- a/src/simulation/elements/VIRS.cpp +++ b/src/simulation/elements/VIRS.cpp @@ -50,7 +50,7 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS) { //pavg[0] measures how many frames until it is cured (0 if still actively spreading and not being cured) //pavg[1] measures how many frames until it dies - int r, rx, ry, rndstore = random_gen(); + int r, rx, ry, rndstore = RNG::Ref().gen(); if (parts[i].pavg[0]) { parts[i].pavg[0] -= (rndstore & 0x1) ? 0:1; @@ -101,7 +101,7 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS) } else if (TYP(r) == PT_PLSM) { - if (surround_space && 10 + sim->pv[(y+ry)/CELL][(x+rx)/CELL] > (random_gen()%100)) + if (surround_space && RNG::Ref().chance(10 + sim->pv[(y+ry)/CELL][(x+rx)/CELL], 100)) { sim->create_part(i, x, y, PT_PLSM); return 1; @@ -135,7 +135,7 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS) } //reset rndstore only once, halfway through else if (!rx && !ry) - rndstore = random_gen(); + rndstore = RNG::Ref().gen(); } return 0; } diff --git a/src/simulation/elements/WARP.cpp b/src/simulation/elements/WARP.cpp index 4f88de4fb..097c7d8e0 100644 --- a/src/simulation/elements/WARP.cpp +++ b/src/simulation/elements/WARP.cpp @@ -53,13 +53,13 @@ int Element_WARP::update(UPDATE_FUNC_ARGS) { parts[i].temp = 10000; sim->pv[y/CELL][x/CELL] += (parts[i].tmp2/5000) * CFDS; - if (!(random_gen()%50)) + if (RNG::Ref().chance(1, 50)) sim->create_part(-3, x, y, PT_ELEC); } for ( trade = 0; trade<5; trade ++) { - rx = random_gen()%3-1; - ry = random_gen()%3-1; + rx = RNG::Ref().between(-1, 1); + ry = RNG::Ref().between(-1, 1); if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; @@ -71,8 +71,8 @@ int Element_WARP::update(UPDATE_FUNC_ARGS) parts[i].y = parts[ID(r)].y; parts[ID(r)].x = x; parts[ID(r)].y = y; - parts[ID(r)].vx = (random_gen()%4)-1.5; - parts[ID(r)].vy = (random_gen()%4)-2; + parts[ID(r)].vx = RNG::Ref().chance(-2, 1) + 0.5f; + parts[ID(r)].vy = RNG::Ref().between(-2, 1); parts[i].life += 4; pmap[y][x] = r; pmap[y+ry][x+rx] = PMAP(i, parts[i].type); diff --git a/src/simulation/elements/WATR.cpp b/src/simulation/elements/WATR.cpp index 0188fd8d4..868632c46 100644 --- a/src/simulation/elements/WATR.cpp +++ b/src/simulation/elements/WATR.cpp @@ -55,35 +55,32 @@ int Element_WATR::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_SALT && !(random_gen()%50)) + if (TYP(r)==PT_SALT && RNG::Ref().chance(1, 50)) { sim->part_change_type(i,x,y,PT_SLTW); // on average, convert 3 WATR 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); } - else if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(random_gen()%100)) + else if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && RNG::Ref().chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; parts[i].ctype = PT_WATR; } - 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)); - if(!(random_gen()%30)){ + if (RNG::Ref().chance(1, 30)) + { sim->kill_part(i); return 1; } } - else if (TYP(r)==PT_SLTW && !(random_gen()%2000)) + else if (TYP(r)==PT_SLTW && RNG::Ref().chance(1, 2000)) { sim->part_change_type(i,x,y,PT_SLTW); } - /*if (TYP(r)==PT_CNCT && !(random_gen()%100)) Concrete+Water to paste, not very popular - { - part_change_type(i,x,y,PT_PSTE); - sim.kill_part(ID(r)); - }*/ } return 0; } diff --git a/src/simulation/elements/WTRV.cpp b/src/simulation/elements/WTRV.cpp index 382cd4086..8cb029b90 100644 --- a/src/simulation/elements/WTRV.cpp +++ b/src/simulation/elements/WTRV.cpp @@ -55,7 +55,7 @@ int Element_WTRV::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && !(random_gen()%100)) + if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && RNG::Ref().chance(1, 100)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; diff --git a/src/simulation/elements/YEST.cpp b/src/simulation/elements/YEST.cpp index 6b2cf4369..a2f963ffc 100644 --- a/src/simulation/elements/YEST.cpp +++ b/src/simulation/elements/YEST.cpp @@ -55,7 +55,7 @@ int Element_YEST::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_DYST && RNG::Ref().chance(1.0/6) && !sim->legacy_enable) + if (TYP(r)==PT_DYST && RNG::Ref().chance(1, 6) && !sim->legacy_enable) { sim->part_change_type(i,x,y,PT_DYST); }