diff --git a/src/simulation/ElementDefs.h b/src/simulation/ElementDefs.h index b134611fd..320214d4c 100644 --- a/src/simulation/ElementDefs.h +++ b/src/simulation/ElementDefs.h @@ -54,8 +54,6 @@ constexpr auto FLAG_PHOTDECO = UINT32_C(0x00000008); // compatibility with #define CTYPEDRAW_FUNC_ARGS Simulation *sim, int i, int t, int v #define CTYPEDRAW_FUNC_SUBCALL_ARGS sim, i, t, v -constexpr bool BOUNDS_CHECK = true; - constexpr int OLD_PT_WIND = 147; // Change this to change the amount of bits used to store type in pmap (and a few elements such as PIPE and CRAY) diff --git a/src/simulation/elements/ACEL.cpp b/src/simulation/elements/ACEL.cpp index 042408633..b0c9a4cb9 100644 --- a/src/simulation/elements/ACEL.cpp +++ b/src/simulation/elements/ACEL.cpp @@ -49,7 +49,6 @@ void Element::Element_ACEL() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; float multiplier; if (parts[i].life!=0) { @@ -61,11 +60,13 @@ static int update(UPDATE_FUNC_ARGS) multiplier = 1.1f; } parts[i].tmp = 0; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (!rx != !ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (!rx != !ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if(!r) r = sim->photons[y+ry][x+rx]; if (!r) @@ -77,6 +78,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].tmp = 1; } } + } + } return 0; } diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp index 050ebf4c3..7baa317e8 100644 --- a/src/simulation/elements/ACID.cpp +++ b/src/simulation/elements/ACID.cpp @@ -52,12 +52,13 @@ void Element::Element_ACID() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, trade; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; int rt = TYP(r); @@ -108,13 +109,15 @@ static int update(UPDATE_FUNC_ARGS) } } } - for (trade = 0; trade<2; trade++) + } + } + for (auto trade = 0; trade<2; trade++) { - rx = sim->rng.between(-2, 2); - ry = sim->rng.between(-2, 2); - if (BOUNDS_CHECK && (rx || ry)) + auto rx = sim->rng.between(-2, 2); + auto ry = sim->rng.between(-2, 2); + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r) == PT_ACID && (parts[i].life > parts[ID(r)].life) && parts[i].life>0)//diffusion diff --git a/src/simulation/elements/AMTR.cpp b/src/simulation/elements/AMTR.cpp index bb4648358..f9e28fffd 100644 --- a/src/simulation/elements/AMTR.cpp +++ b/src/simulation/elements/AMTR.cpp @@ -49,15 +49,16 @@ void Element::Element_AMTR() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (rt!=PT_AMTR && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PCLN && rt!=PT_VOID && rt!=PT_BHOL && rt!=PT_NBHL && rt!=PT_PRTI && rt!=PT_PRTO) { parts[i].life++; @@ -73,6 +74,8 @@ static int update(UPDATE_FUNC_ARGS) sim->pv[y/CELL][x/CELL] -= 2.0f; } } + } + } return 0; } diff --git a/src/simulation/elements/ANAR.cpp b/src/simulation/elements/ANAR.cpp index 969038926..d932fe2f8 100644 --- a/src/simulation/elements/ANAR.cpp +++ b/src/simulation/elements/ANAR.cpp @@ -48,15 +48,13 @@ void Element::Element_ANAR() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - - //if (parts[i].temp >= 0.23) - // parts[i].temp --; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_CFLM && sim->rng.chance(1, 4)) @@ -67,5 +65,7 @@ static int update(UPDATE_FUNC_ARGS) sim->pv[y/CELL][x/CELL] -= 0.5; } } + } + } return 0; } diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index a7558d3df..7784adefc 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -53,7 +53,7 @@ static int update(UPDATE_FUNC_ARGS) { for (int ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (!r) diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp index 0f3c82592..bae8f7079 100644 --- a/src/simulation/elements/BANG.cpp +++ b/src/simulation/elements/BANG.cpp @@ -47,17 +47,19 @@ void Element::Element_BANG() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if(parts[i].tmp==0) { if(parts[i].temp>=673.0f) parts[i].tmp = 1; else - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_FIRE || TYP(r)==PT_PLSM || TYP(r)==PT_SPRK || TYP(r)==PT_LIGH) @@ -65,7 +67,9 @@ static int update(UPDATE_FUNC_ARGS) parts[i].tmp = 1; } } - + } + } + } } else if(parts[i].tmp==1) { diff --git a/src/simulation/elements/BCLN.cpp b/src/simulation/elements/BCLN.cpp index 2a1135b49..aebb675b9 100644 --- a/src/simulation/elements/BCLN.cpp +++ b/src/simulation/elements/BCLN.cpp @@ -60,27 +60,27 @@ static int update(UPDATE_FUNC_ARGS) } if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled) { - int r, rx, ry, rt; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + auto r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + auto rt = TYP(r); + if (rt!=PT_CLNE && rt!=PT_PCLN && + rt!=PT_BCLN && rt!=PT_STKM && + rt!=PT_PBCN && rt!=PT_STKM2 && + rtphotons[y+ry][x+rx]; - if (!r) - r = pmap[y+ry][x+rx]; - if (!r) - continue; - rt = TYP(r); - if (rt!=PT_CLNE && rt!=PT_PCLN && - rt!=PT_BCLN && rt!=PT_STKM && - rt!=PT_PBCN && rt!=PT_STKM2 && - rt>16)&0xFF); - tg = float((parts[ID(r)].dcolour>>8)&0xFF); - tb = float((parts[ID(r)].dcolour)&0xFF); - ta = float((parts[ID(r)].dcolour>>24)&0xFF); + auto tr = float((parts[ID(r)].dcolour>>16)&0xFF); + auto tg = float((parts[ID(r)].dcolour>>8)&0xFF); + auto tb = float((parts[ID(r)].dcolour)&0xFF); + auto ta = float((parts[ID(r)].dcolour>>24)&0xFF); - mr = float((parts[i].dcolour>>16)&0xFF); - mg = float((parts[i].dcolour>>8)&0xFF); - mb = float((parts[i].dcolour)&0xFF); - ma = float((parts[i].dcolour>>24)&0xFF); + auto mr = float((parts[i].dcolour>>16)&0xFF); + auto mg = float((parts[i].dcolour>>8)&0xFF); + auto mb = float((parts[i].dcolour)&0xFF); + auto ma = float((parts[i].dcolour>>24)&0xFF); - nr = int((tr*BLEND) + (mr*(1 - BLEND))); - ng = int((tg*BLEND) + (mg*(1 - BLEND))); - nb = int((tb*BLEND) + (mb*(1 - BLEND))); - na = int((ta*BLEND) + (ma*(1 - BLEND))); + auto nr = int((tr*BLEND) + (mr*(1 - BLEND))); + auto ng = int((tg*BLEND) + (mg*(1 - BLEND))); + auto nb = int((tb*BLEND) + (mb*(1 - BLEND))); + auto na = int((ta*BLEND) + (ma*(1 - BLEND))); parts[ID(r)].dcolour = nr<<16 | ng<<8 | nb | na<<24; } } + } + } } return 0; } diff --git a/src/simulation/elements/BMTL.cpp b/src/simulation/elements/BMTL.cpp index 2e00b8c25..230dd3e10 100644 --- a/src/simulation/elements/BMTL.cpp +++ b/src/simulation/elements/BMTL.cpp @@ -47,15 +47,16 @@ void Element::Element_BMTL() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].tmp>1) { parts[i].tmp--; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if ((TYP(r)==PT_METL || TYP(r)==PT_IRON) && sim->rng.chance(1, 100)) @@ -64,6 +65,8 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].tmp = (parts[i].tmp<=7) ? parts[i].tmp=1 : parts[i].tmp - sim->rng.between(0, 4); } } + } + } } else if (parts[i].tmp==1 && sim->rng.chance(1, 1000)) { diff --git a/src/simulation/elements/BOMB.cpp b/src/simulation/elements/BOMB.cpp index d530067b7..5410f96c8 100644 --- a/src/simulation/elements/BOMB.cpp +++ b/src/simulation/elements/BOMB.cpp @@ -50,23 +50,24 @@ void Element::Element_BOMB() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt, nb; - - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (rt!=PT_BOMB && rt!=PT_EMBR && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PCLN && rt!=PT_BCLN && rt!=PT_VIBR) { int rad = 8, nt; - int nxi, nxj; sim->kill_part(i); - for (nxj=-rad; nxj<=rad; nxj++) - for (nxi=-rad; nxi<=rad; nxi++) + for (auto nxj=-rad; nxj<=rad; nxj++) + { + for (auto nxi=-rad; nxi<=rad; nxi++) + { if ((pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2))<=1) { int ynxj = y + nxj, xnxi = x + nxi; @@ -80,7 +81,7 @@ static int update(UPDATE_FUNC_ARGS) if (nt) sim->kill_part(ID(pmap[ynxj][xnxi])); sim->pv[(ynxj)/CELL][(xnxi)/CELL] += 0.1f; - nb = sim->create_part(-3, xnxi, ynxj, PT_EMBR); + auto nb = sim->create_part(-3, xnxi, ynxj, PT_EMBR); if (nb!=-1) { parts[nb].tmp = 2; @@ -89,11 +90,15 @@ static int update(UPDATE_FUNC_ARGS) } } } - for (nxj=-(rad+1); nxj<=(rad+1); nxj++) - for (nxi=-(rad+1); nxi<=(rad+1); nxi++) + } + } + for (auto nxj=-(rad+1); nxj<=(rad+1); nxj++) + { + for (auto nxi=-(rad+1); nxi<=(rad+1); nxi++) + { if ((pow((float)nxi,2))/(pow((float)(rad+1),2))+(pow((float)nxj,2))/(pow((float)(rad+1),2))<=1 && !TYP(pmap[y+nxj][x+nxi])) { - nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR); + auto nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR); if (nb!=-1) { parts[nb].tmp = 0; @@ -103,9 +108,13 @@ static int update(UPDATE_FUNC_ARGS) parts[nb].vy = float(sim->rng.between(-20, 20)); } } + } + } return 1; } } + } + } return 0; } diff --git a/src/simulation/elements/BOYL.cpp b/src/simulation/elements/BOYL.cpp index 8adabe4cf..385474809 100644 --- a/src/simulation/elements/BOYL.cpp +++ b/src/simulation/elements/BOYL.cpp @@ -48,7 +48,6 @@ void Element::Element_BOYL() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; float limit = parts[i].temp / 100; if (sim->pv[y / CELL][x / CELL] < limit) sim->pv[y / CELL][x / CELL] += 0.001f*(limit - sim->pv[y / CELL][x / CELL]); @@ -62,11 +61,13 @@ static int update(UPDATE_FUNC_ARGS) sim->pv[y / CELL][x / CELL - 1] += 0.001f*(limit - sim->pv[y / CELL][x / CELL - 1]); sim->pv[y / CELL - 1][x / CELL - 1] += 0.001f*(limit - sim->pv[y / CELL - 1][x / CELL - 1]); - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_WATR) @@ -84,5 +85,7 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/BRMT.cpp b/src/simulation/elements/BRMT.cpp index 19143a6f7..793830ecf 100644 --- a/src/simulation/elements/BRMT.cpp +++ b/src/simulation/elements/BRMT.cpp @@ -47,17 +47,18 @@ void Element::Element_BRMT() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, tempFactor; if (parts[i].temp > 523.15f)//250.0f+273.15f { - tempFactor = int(1000 - ((523.15f-parts[i].temp)*2)); + auto tempFactor = int(1000 - ((523.15f-parts[i].temp)*2)); if(tempFactor < 2) tempFactor = 2; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_BREC && sim->rng.chance(1, tempFactor)) @@ -70,6 +71,8 @@ static int update(UPDATE_FUNC_ARGS) sim->create_part(i, x, y, PT_THRM); } } + } + } } return 0; } diff --git a/src/simulation/elements/BTRY.cpp b/src/simulation/elements/BTRY.cpp index b007e1231..2f5dd934a 100644 --- a/src/simulation/elements/BTRY.cpp +++ b/src/simulation/elements/BTRY.cpp @@ -47,15 +47,16 @@ void Element::Element_BTRY() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry) && abs(rx)+abs(ry)<4) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if ((rx || ry) && abs(rx)+abs(ry)<4) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (sim->parts_avg(i,ID(r),PT_INSL) != PT_INSL) { if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) @@ -66,5 +67,7 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/C5.cpp b/src/simulation/elements/C5.cpp index 2f9e278ba..3b164a953 100644 --- a/src/simulation/elements/C5.cpp +++ b/src/simulation/elements/C5.cpp @@ -49,12 +49,13 @@ void Element::Element_C5() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) 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) @@ -68,13 +69,15 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } if (parts[i].ctype && !parts[i].life) { float vx = ((parts[i].tmp << 16) >> 16) / 255.0f; float vy = (parts[i].tmp >> 16) / 255.0f; float dx = ((parts[i].tmp2 << 16) >> 16) / 255.0f; float dy = (parts[i].tmp2 >> 16) / 255.0f; - r = sim->create_part(-3, x, y, PT_PHOT); + auto r = sim->create_part(-3, x, y, PT_PHOT); if (r != -1) { parts[r].ctype = parts[i].ctype; diff --git a/src/simulation/elements/CAUS.cpp b/src/simulation/elements/CAUS.cpp index efa94055e..afa318dee 100644 --- a/src/simulation/elements/CAUS.cpp +++ b/src/simulation/elements/CAUS.cpp @@ -50,8 +50,10 @@ void Element::Element_CAUS() static int update(UPDATE_FUNC_ARGS) { for (int rx = -2; rx <= 2; rx++) + { for (int ry = -2; ry <= 2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (!r) @@ -86,5 +88,7 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/CBNW.cpp b/src/simulation/elements/CBNW.cpp index 83e9bfa48..274364677 100644 --- a/src/simulation/elements/CBNW.cpp +++ b/src/simulation/elements/CBNW.cpp @@ -50,7 +50,6 @@ void Element::Element_CBNW() static int 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 || sim->rng.chance(1, 4000)) @@ -79,11 +78,13 @@ static int update(UPDATE_FUNC_ARGS) } parts[i].tmp--; } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if ((sim->elements[TYP(r)].Properties&TYPE_PART) && parts[i].tmp == 0 && sim->rng.chance(1, 83)) @@ -133,6 +134,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/CLNE.cpp b/src/simulation/elements/CLNE.cpp index 06c4e9844..72caac538 100644 --- a/src/simulation/elements/CLNE.cpp +++ b/src/simulation/elements/CLNE.cpp @@ -51,27 +51,27 @@ static int update(UPDATE_FUNC_ARGS) { if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled) { - int r, rx, ry, rt; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + auto r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + auto rt = TYP(r); + if (rt!=PT_CLNE && rt!=PT_PCLN && + rt!=PT_BCLN && rt!=PT_STKM && + rt!=PT_PBCN && rt!=PT_STKM2 && + rtphotons[y+ry][x+rx]; - if (!r) - r = pmap[y+ry][x+rx]; - if (!r) - continue; - rt = TYP(r); - if (rt!=PT_CLNE && rt!=PT_PCLN && - rt!=PT_BCLN && rt!=PT_STKM && - rt!=PT_PBCN && rt!=PT_STKM2 && - rtrng.chance(1, 2000)) @@ -86,6 +87,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f) { if (sim->rng.chance(1, 5)) diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp index 292fc49ab..d82b39de9 100644 --- a/src/simulation/elements/CONV.cpp +++ b/src/simulation/elements/CONV.cpp @@ -49,39 +49,41 @@ void Element::Element_CONV() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; int ctype = TYP(parts[i].ctype); if (ctype<=0 || ctype>=PT_NUM || !sim->elements[ctype].Enabled || ctype==PT_CONV) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + auto r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + int rt = TYP(r); + if (rt != PT_CLNE && rt != PT_PCLN && + rt != PT_BCLN && rt != PT_STKM && + rt != PT_PBCN && rt != PT_STKM2 && + rt != PT_CONV && rt < PT_NUM) { - r = sim->photons[y+ry][x+rx]; - if (!r) - r = pmap[y+ry][x+rx]; - if (!r) - continue; - int rt = TYP(r); - if (rt != PT_CLNE && rt != PT_PCLN && - rt != PT_BCLN && rt != PT_STKM && - rt != PT_PBCN && rt != PT_STKM2 && - rt != PT_CONV && rt < PT_NUM) - { - parts[i].ctype = rt; - if (rt == PT_LIFE) - parts[i].ctype |= PMAPID(parts[ID(r)].ctype); - } + parts[i].ctype = rt; + if (rt == PT_LIFE) + parts[i].ctype |= PMAPID(parts[ID(r)].ctype); } + } + } } else { int restrictElement = sim->IsElement(parts[i].tmp) ? parts[i].tmp : 0; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { if (x+rx>=0 && y+ry>=0 && x+rxphotons[y+ry][x+rx]; + auto r = sim->photons[y+ry][x+rx]; if (!r || (restrictElement && ((TYP(r) == restrictElement) == (parts[i].tmp2 == 1)))) r = pmap[y+ry][x+rx]; if (!r || (restrictElement && ((TYP(r) == restrictElement) == (parts[i].tmp2 == 1)))) @@ -91,6 +93,8 @@ static int update(UPDATE_FUNC_ARGS) sim->create_part(ID(r), x+rx, y+ry, TYP(parts[i].ctype), ID(parts[i].ctype)); } } + } + } } return 0; } diff --git a/src/simulation/elements/CRAY.cpp b/src/simulation/elements/CRAY.cpp index e68f9b31b..4e3d68d2e 100644 --- a/src/simulation/elements/CRAY.cpp +++ b/src/simulation/elements/CRAY.cpp @@ -56,26 +56,29 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].ctype<=0 || !sim->elements[TYP(parts[i].ctype)].Enabled) { for (int rx = -1; rx <= 1; rx++) + { for (int ry = -1; ry <= 1; ry++) - if (BOUNDS_CHECK) + { + int r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (TYP(r)!=PT_CRAY && TYP(r)!=PT_PSCN && TYP(r)!=PT_INST && TYP(r)!=PT_METL && TYP(r)!=PT_SPRK && TYP(r)photons[y+ry][x+rx]; - if (!r) - r = pmap[y+ry][x+rx]; - if (!r) - continue; - if (TYP(r)!=PT_CRAY && TYP(r)!=PT_PSCN && TYP(r)!=PT_INST && TYP(r)!=PT_METL && TYP(r)!=PT_SPRK && TYP(r) 100 ? 100 : (parts[i].life < 0 ? 0 : parts[i].life)) / 100.0f); } parts[i].tmp = 0; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry) && !(rx && ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if ((rx || ry) && !(rx && ry)) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) r = sim->photons[y+ry][x+rx]; if (!r) @@ -72,6 +73,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].tmp = 1; } } + } + } return 0; } diff --git a/src/simulation/elements/DEUT.cpp b/src/simulation/elements/DEUT.cpp index 969488d57..83c639328 100644 --- a/src/simulation/elements/DEUT.cpp +++ b/src/simulation/elements/DEUT.cpp @@ -53,7 +53,6 @@ void Element::Element_DEUT() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, trade, np; float gravtot = fabs(sim->gravy[(y/CELL)*XCELLS+(x/CELL)])+fabs(sim->gravx[(y/CELL)*XCELLS+(x/CELL)]); // Prevent division by 0 float temp = std::max(1.0f, (parts[i].temp + 1)); @@ -65,11 +64,13 @@ static int update(UPDATE_FUNC_ARGS) maxlife = maxlife*int(5.0f - 8.0f/(gravtot+2.0f)); if (parts[i].life < maxlife) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r || (parts[i].life >=maxlife)) continue; if (TYP(r)==PT_DEUT&& sim->rng.chance(1, 3)) @@ -83,33 +84,41 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } else - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { //Leave if there is nothing to do if (parts[i].life <= maxlife) goto trade; - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if ((!r)&&parts[i].life>=1)//if nothing then create deut { - np = sim->create_part(-1,x+rx,y+ry,PT_DEUT); + auto np = sim->create_part(-1,x+rx,y+ry,PT_DEUT); if (np<0) continue; parts[i].life--; parts[np].temp = parts[i].temp; parts[np].life = 0; } } + } + } + } trade: - for ( trade = 0; trade<4; trade ++) + for (auto trade = 0; trade<4; trade ++) { - rx = sim->rng.between(-2, 2); - ry = sim->rng.between(-2, 2); - if (BOUNDS_CHECK && (rx || ry)) + auto rx = sim->rng.between(-2, 2); + auto ry = sim->rng.between(-2, 2); + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_DEUT&&(parts[i].life>parts[ID(r)].life)&&parts[i].life>0)//diffusion diff --git a/src/simulation/elements/DLAY.cpp b/src/simulation/elements/DLAY.cpp index 2f280f7fb..bbc14ad0b 100644 --- a/src/simulation/elements/DLAY.cpp +++ b/src/simulation/elements/DLAY.cpp @@ -50,17 +50,18 @@ void Element::Element_DLAY() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, oldl; - oldl = parts[i].life; + auto oldl = parts[i].life; if (parts[i].life>0) parts[i].life--; if (parts[i].temp<= 1.0f+273.15f) parts[i].temp = 1.0f+273.15f; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r || sim->parts_avg(ID(r), i,PT_INSL)==PT_INSL) continue; if (TYP(r)==PT_SPRK && parts[i].life==0 && parts[ID(r)].life>0 && parts[ID(r)].life<4 && parts[ID(r)].ctype==PT_PSCN) @@ -90,7 +91,8 @@ static int update(UPDATE_FUNC_ARGS) sim->create_part(-1, x+rx, y+ry, PT_SPRK); } } - //} + } + } return 0; } diff --git a/src/simulation/elements/DMG.cpp b/src/simulation/elements/DMG.cpp index 37c29e186..0067555ad 100644 --- a/src/simulation/elements/DMG.cpp +++ b/src/simulation/elements/DMG.cpp @@ -50,39 +50,40 @@ void Element::Element_DMG() static int update(UPDATE_FUNC_ARGS) { - int r, rr, rx, ry, nxi, nxj, t, dist; int rad = 25; - float angle, fx, fy; - - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)!=PT_DMG && TYP(r)!=PT_EMBR && TYP(r)!=PT_DMND && TYP(r)!=PT_CLNE && TYP(r)!=PT_PCLN && TYP(r)!=PT_BCLN) { sim->kill_part(i); - for (nxj=-rad; nxj<=rad; nxj++) - for (nxi=-rad; nxi<=rad; nxi++) + for (auto nxj=-rad; nxj<=rad; nxj++) + { + for (auto nxi=-rad; nxi<=rad; nxi++) + { if (x+nxi>=0 && y+nxj>=0 && x+nxivx[(y+nxj)/CELL][(x+nxi)/CELL] += fx; sim->vy[(y+nxj)/CELL][(x+nxi)/CELL] += fy; sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 1.0f; - t = TYP(rr); + auto t = TYP(rr); if (t && sim->elements[t].HighPressureTransition>-1 && sim->elements[t].HighPressureTransitionpart_change_type(ID(rr), x+nxi, y+nxj, sim->elements[t].HighPressureTransition); else if (t == PT_BMTL) @@ -103,9 +104,13 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 1; } } + } + } return 0; } diff --git a/src/simulation/elements/DRAY.cpp b/src/simulation/elements/DRAY.cpp index 78db8e0f6..7a939639a 100644 --- a/src/simulation/elements/DRAY.cpp +++ b/src/simulation/elements/DRAY.cpp @@ -68,7 +68,7 @@ static int update(UPDATE_FUNC_ARGS) { for (int ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3) //spark found, start creating diff --git a/src/simulation/elements/DSTW.cpp b/src/simulation/elements/DSTW.cpp index b5d8d4b41..5565bf53b 100644 --- a/src/simulation/elements/DSTW.cpp +++ b/src/simulation/elements/DSTW.cpp @@ -48,12 +48,13 @@ void Element::Element_DSTW() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; switch (TYP(r)) { case PT_SALT: @@ -97,5 +98,7 @@ static int update(UPDATE_FUNC_ARGS) continue; } } + } + } return 0; } diff --git a/src/simulation/elements/DTEC.cpp b/src/simulation/elements/DTEC.cpp index 5f0f382cc..911bd2dde 100644 --- a/src/simulation/elements/DTEC.cpp +++ b/src/simulation/elements/DTEC.cpp @@ -51,19 +51,21 @@ void Element::Element_DTEC() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt, rd = parts[i].tmp2; + int rd = parts[i].tmp2; if (rd > 25) parts[i].tmp2 = rd = 25; if (parts[i].life) { parts[i].life = 0; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (sim->parts_avg(i,ID(r),PT_INSL) != PT_INSL) { if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) @@ -74,14 +76,18 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } bool setFilt = false; int photonWl = 0; - for (rx=-rd; rx=0 && y+ry>=0 && x+rxphotons[y+ry][x+rx]; if(!r) @@ -94,14 +100,18 @@ static int update(UPDATE_FUNC_ARGS) photonWl = parts[ID(r)].ctype; } } + } + } if (setFilt) { int nx, ny; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx=-1; rx<2; rx++) + { + for (auto ry=-1; ry<2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; nx = x+rx; @@ -116,6 +126,8 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[ny][nx]; } } + } + } } return 0; } diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp index 3c9ce1825..9874019e9 100644 --- a/src/simulation/elements/ELEC.cpp +++ b/src/simulation/elements/ELEC.cpp @@ -52,77 +52,82 @@ void Element::Element_ELEC() static int update(UPDATE_FUNC_ARGS) { - int r, rt, rx, ry, nb, rrx, rry; - for (rx=-2; rx<=2; rx++) - for (ry=-2; ry<=2; ry++) - if (BOUNDS_CHECK) { - r = pmap[y+ry][x+rx]; - if (!r) - r = sim->photons[y+ry][x+rx]; - if (!r) - continue; - rt = TYP(r); - switch (rt) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + auto r = pmap[y+ry][x+rx]; + if (!r) + r = sim->photons[y+ry][x+rx]; + if (!r) + continue; + auto rt = TYP(r); + switch (rt) + { + case PT_GLAS: + for (auto rrx=-1; rrx<=1; rrx++) { - case PT_GLAS: - for (rrx=-1; rrx<=1; rrx++) - for (rry=-1; rry<=1; rry++) - if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrxcreate_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR); - if (nb!=-1) { - parts[nb].tmp = 0; - parts[nb].life = 50; - parts[nb].temp = parts[i].temp*0.8f; - parts[nb].vx = float(sim->rng.between(-10, 10)); - parts[nb].vy = float(sim->rng.between(-10, 10)); - } - } - sim->kill_part(i); - return 1; - case PT_LCRY: - parts[ID(r)].tmp2 = sim->rng.between(5, 9); - break; - case PT_WATR: - case PT_DSTW: - case PT_SLTW: - case PT_CBNW: - if (sim->rng.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); - sim->kill_part(i); - return 1; - case PT_PROT: // this is the correct reaction, not NEUT, but leaving NEUT in anyway - if (parts[ID(r)].tmp2 & 0x1) - break; - case PT_NEUT: - sim->part_change_type(ID(r), x+rx, y+ry, PT_H2); - parts[ID(r)].life = 0; - parts[ID(r)].ctype = 0; - sim->kill_part(i); - break; - case PT_DEUT: - if(parts[ID(r)].life < 6000) - parts[ID(r)].life += 1; - parts[ID(r)].temp = 0; - sim->kill_part(i); - return 1; - case PT_EXOT: - parts[ID(r)].tmp2 += 5; - parts[ID(r)].life = 1000; - break; - case PT_NONE: //seems to speed up ELEC even if it isn't used - break; - default: - if ((sim->elements[rt].Properties & PROP_CONDUCTS) && (rt!=PT_NBLE||parts[i].temp<2273.15)) + for (auto rry=-1; rry<=1; rry++) { - sim->create_part(-1, x+rx, y+ry, PT_SPRK); - sim->kill_part(i); - return 1; + if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrxcreate_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR); + if (nb!=-1) { + parts[nb].tmp = 0; + parts[nb].life = 50; + parts[nb].temp = parts[i].temp*0.8f; + parts[nb].vx = float(sim->rng.between(-10, 10)); + parts[nb].vy = float(sim->rng.between(-10, 10)); + } + } } - break; } + sim->kill_part(i); + return 1; + case PT_LCRY: + parts[ID(r)].tmp2 = sim->rng.between(5, 9); + break; + case PT_WATR: + case PT_DSTW: + case PT_SLTW: + case PT_CBNW: + if (sim->rng.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); + sim->kill_part(i); + return 1; + case PT_PROT: // this is the correct reaction, not NEUT, but leaving NEUT in anyway + if (parts[ID(r)].tmp2 & 0x1) + break; + case PT_NEUT: + sim->part_change_type(ID(r), x+rx, y+ry, PT_H2); + parts[ID(r)].life = 0; + parts[ID(r)].ctype = 0; + sim->kill_part(i); + break; + case PT_DEUT: + if(parts[ID(r)].life < 6000) + parts[ID(r)].life += 1; + parts[ID(r)].temp = 0; + sim->kill_part(i); + return 1; + case PT_EXOT: + parts[ID(r)].tmp2 += 5; + parts[ID(r)].life = 1000; + break; + case PT_NONE: //seems to speed up ELEC even if it isn't used + break; + default: + if ((sim->elements[rt].Properties & PROP_CONDUCTS) && (rt!=PT_NBLE||parts[i].temp<2273.15)) + { + sim->create_part(-1, x+rx, y+ry, PT_SPRK); + sim->kill_part(i); + return 1; + } + break; } + } + } return 0; } diff --git a/src/simulation/elements/EMBR.cpp b/src/simulation/elements/EMBR.cpp index 8c0802f04..c94a1ad5d 100644 --- a/src/simulation/elements/EMBR.cpp +++ b/src/simulation/elements/EMBR.cpp @@ -52,12 +52,13 @@ void Element::Element_EMBR() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if ((sim->elements[TYP(r)].Properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(sim->elements[TYP(r)].Properties & PROP_SPARKSETTLE)) @@ -66,6 +67,8 @@ static int update(UPDATE_FUNC_ARGS) return 1; } } + } + } return 0; } diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index f8ff425dc..c4d630f3e 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -53,15 +53,16 @@ void Element::Element_EXOT() static int update(UPDATE_FUNC_ARGS) { - int r, rt, rx, ry, trade, tym; - for (rx=-2; rx<=2; rx++) - for (ry=-2; ry<=2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (rt == PT_WARP) { if (parts[ID(r)].tmp2>2000 && sim->rng.chance(1, 100)) @@ -107,6 +108,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } parts[i].tmp--; parts[i].tmp2--; @@ -136,18 +139,18 @@ static int update(UPDATE_FUNC_ARGS) } if (parts[i].tmp2 > 100) { - for (trade = 0; trade < 9; trade++) + for (auto trade = 0; trade < 9; trade++) { - rx = sim->rng.between(-2, 2); - ry = sim->rng.between(-2, 2); - if (BOUNDS_CHECK && (rx || ry)) + auto rx = sim->rng.between(-2, 2); + auto ry = sim->rng.between(-2, 2); + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_EXOT && (parts[i].tmp2 > parts[ID(r)].tmp2) && parts[ID(r)].tmp2 >= 0) //diffusion { - tym = parts[i].tmp2 - parts[ID(r)].tmp2; + auto tym = parts[i].tmp2 - parts[ID(r)].tmp2; if (tym == 1) { parts[ID(r)].tmp2++; diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index b3df41eac..658e3aada 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -54,7 +54,7 @@ void Element::Element_FIRE() int Element_FIRE_update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt, t = parts[i].type; + int t = parts[i].type; switch (t) { case PT_PLSM: @@ -141,14 +141,16 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) default: break; } - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); //THRM burning if (rt==PT_THRM && (t==PT_FIRE || t==PT_PLSM || t==PT_LAVA)) @@ -273,6 +275,8 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) sim->pv[y/CELL][x/CELL] += 0.25f * CFDS; } } + } + } if (sim->legacy_enable && t!=PT_SPRK) // SPRK has no legacy reactions updateLegacy(UPDATE_FUNC_SUBCALL_ARGS); return 0; @@ -280,19 +284,21 @@ int Element_FIRE_update(UPDATE_FUNC_ARGS) static int updateLegacy(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt, lpv, t = parts[i].type; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + int t = parts[i].type; + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (sim->bmap[(y+ry)/CELL][(x+rx)/CELL] && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM) continue; - rt = TYP(r); + auto rt = TYP(r); - lpv = (int)sim->pv[(y+ry)/CELL][(x+rx)/CELL]; + auto 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) @@ -348,6 +354,8 @@ static int updateLegacy(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp index e635cd819..8510a9f25 100644 --- a/src/simulation/elements/FIRW.cpp +++ b/src/simulation/elements/FIRW.cpp @@ -49,16 +49,18 @@ void Element::Element_FIRW() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt, np; - if (parts[i].tmp<=0) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + if (parts[i].tmp<=0) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR) { float gx, gy, multiplier; @@ -77,6 +79,8 @@ static int update(UPDATE_FUNC_ARGS) return 0; } } + } + } } else if (parts[i].tmp==1) { if (parts[i].life<=0) { @@ -90,7 +94,7 @@ static int update(UPDATE_FUNC_ARGS) unsigned col = Renderer::firwTableAt(sim->rng.between(0, 199)).Pack(); for (int n=0; n<40; n++) { - np = sim->create_part(-3, x, y, PT_EMBR); + auto np = sim->create_part(-3, x, y, PT_EMBR); if (np>-1) { auto magnitude = sim->rng.between(40, 99) * 0.05f; diff --git a/src/simulation/elements/FOG.cpp b/src/simulation/elements/FOG.cpp index 7cc87d951..19765bdcd 100644 --- a/src/simulation/elements/FOG.cpp +++ b/src/simulation/elements/FOG.cpp @@ -48,12 +48,13 @@ void Element::Element_FOG() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if ((sim->elements[TYP(r)].Properties&TYPE_SOLID) && sim->rng.chance(1, 10) && parts[i].life==0 && !(TYP(r)==PT_CLNE || TYP(r)==PT_PCLN)) // TODO: should this also exclude BCLN? @@ -65,5 +66,7 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life += sim->rng.between(0, 19); } } + } + } return 0; } diff --git a/src/simulation/elements/FRAY.cpp b/src/simulation/elements/FRAY.cpp index f4dfc8a78..286e28755 100644 --- a/src/simulation/elements/FRAY.cpp +++ b/src/simulation/elements/FRAY.cpp @@ -53,17 +53,21 @@ static int update(UPDATE_FUNC_ARGS) curlen = parts[i].tmp; else curlen = 10; - int r, nxx, nyy, len, nxi, nyi, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - if (TYP(r)==PT_SPRK) { - for (nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1, len = 0; ; nyy+=nyi, nxx+=nxi, len++) { - if (!(x+nxi+nxx= 0 && y+nyi+nyy >= 0) || len>curlen) { + if (TYP(r)==PT_SPRK) + { + for (auto nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1, len = 0; ; nyy+=nyi, nxx+=nxi, len++) + { + if (!(x+nxi+nxx= 0 && y+nyi+nyy >= 0) || len>curlen) + { break; } r = pmap[y+nyi+nyy][x+nxi+nxx]; @@ -76,5 +80,7 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp index e6f543841..ba0f3074b 100644 --- a/src/simulation/elements/FRZW.cpp +++ b/src/simulation/elements/FRZW.cpp @@ -50,12 +50,13 @@ void Element::Element_FRZW() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_WATR && sim->rng.chance(1, 14)) @@ -63,6 +64,8 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW); } } + } + } if ((parts[i].life==0 && sim->rng.chance(1, 192)) || sim->rng.chance(100-parts[i].life, 50000)) { sim->part_change_type(i,x,y,PT_ICEI); diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp index 00fa61b6d..796532cdf 100644 --- a/src/simulation/elements/FRZZ.cpp +++ b/src/simulation/elements/FRZZ.cpp @@ -48,12 +48,13 @@ void Element::Element_FRZZ() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_WATR && sim->rng.chance(1, 20)) @@ -64,5 +65,7 @@ static int update(UPDATE_FUNC_ARGS) return 1; } } + } + } return 0; } diff --git a/src/simulation/elements/FSEP.cpp b/src/simulation/elements/FSEP.cpp index e117c01d6..79798713b 100644 --- a/src/simulation/elements/FSEP.cpp +++ b/src/simulation/elements/FSEP.cpp @@ -49,9 +49,8 @@ void Element::Element_FSEP() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life<=0) { - r = sim->create_part(i, x, y, PT_PLSM); + auto r = sim->create_part(i, x, y, PT_PLSM); if (r!=-1) parts[r].life = 50; return 1; @@ -59,17 +58,19 @@ static int update(UPDATE_FUNC_ARGS) else if (parts[i].life < 40) { parts[i].life--; if (sim->rng.chance(1, 10)) { - r = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_PLSM); + auto r = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_PLSM); if (r>-1) parts[r].life = 50; } } else { - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto 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 && sim->rng.chance(1, 15)) @@ -77,6 +78,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 39; } } + } + } } return 0; } diff --git a/src/simulation/elements/FUSE.cpp b/src/simulation/elements/FUSE.cpp index 6a29db774..0c3a61ca1 100644 --- a/src/simulation/elements/FUSE.cpp +++ b/src/simulation/elements/FUSE.cpp @@ -50,9 +50,8 @@ void Element::Element_FUSE() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life<=0) { - r = sim->create_part(i, x, y, PT_PLSM); + auto r = sim->create_part(i, x, y, PT_PLSM); if (r>-1) parts[r].life = 50; return 1; @@ -60,7 +59,7 @@ static int update(UPDATE_FUNC_ARGS) else if (parts[i].life < 40) { parts[i].life--; if (sim->rng.chance(1, 100)) { - r = sim->create_part(-1, x + sim->rng.chance(-1, 1), y + sim->rng.chance(-1, 1), PT_PLSM); + auto r = sim->create_part(-1, x + sim->rng.chance(-1, 1), y + sim->rng.chance(-1, 1), PT_PLSM); if (r>-1) parts[r].life = 50; } @@ -74,11 +73,13 @@ static int update(UPDATE_FUNC_ARGS) else if (parts[i].tmp<40) parts[i].tmp--; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPRK || (parts[i].temp>=(273.15+700.0f) && sim->rng.chance(1, 20))) @@ -87,5 +88,7 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 39; } } + } + } return 0; } diff --git a/src/simulation/elements/GBMB.cpp b/src/simulation/elements/GBMB.cpp index 0bf40f5d5..2036dc053 100644 --- a/src/simulation/elements/GBMB.cpp +++ b/src/simulation/elements/GBMB.cpp @@ -50,26 +50,24 @@ void Element::Element_GBMB() static int update(UPDATE_FUNC_ARGS) { - int rx,ry,r; if (parts[i].life<=0) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK) + auto r = pmap[y+ry][x+rx]; + if(!r) + continue; + if(TYP(r)!=PT_BOMB && TYP(r)!=PT_GBMB && + TYP(r)!=PT_CLNE && TYP(r)!=PT_PCLN && + TYP(r)!=PT_DMND) { - r = pmap[y+ry][x+rx]; - if(!r) - continue; - if(TYP(r)!=PT_BOMB && TYP(r)!=PT_GBMB && - TYP(r)!=PT_CLNE && TYP(r)!=PT_PCLN && - TYP(r)!=PT_DMND) - { - parts[i].life=60; - break; - } + parts[i].life=60; + break; } } + } } if (parts[i].life>20) sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] = 20; diff --git a/src/simulation/elements/GEL.cpp b/src/simulation/elements/GEL.cpp index 262790a4b..7da0abfbe 100644 --- a/src/simulation/elements/GEL.cpp +++ b/src/simulation/elements/GEL.cpp @@ -50,22 +50,22 @@ void Element::Element_GEL() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; - bool gel; 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)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - gel=false; - r = pmap[y+ry][x+rx]; + auto gel=false; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); //Desaturation switch (rt) { @@ -150,6 +150,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/GLOW.cpp b/src/simulation/elements/GLOW.cpp index 5972755e0..7df7367c4 100644 --- a/src/simulation/elements/GLOW.cpp +++ b/src/simulation/elements/GLOW.cpp @@ -50,12 +50,13 @@ void Element::Element_GLOW() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_WATR && sim->rng.chance(1, 400)) @@ -66,6 +67,8 @@ static int update(UPDATE_FUNC_ARGS) return 1; } } + } + } int ctype = int(sim->pv[y/CELL][x/CELL]*16); if (ctype < 0) ctype = 0; diff --git a/src/simulation/elements/GOLD.cpp b/src/simulation/elements/GOLD.cpp index e58843d0c..cab7bfa63 100644 --- a/src/simulation/elements/GOLD.cpp +++ b/src/simulation/elements/GOLD.cpp @@ -51,17 +51,17 @@ void Element::Element_GOLD() static int update(UPDATE_FUNC_ARGS) { - int rx, ry, r, rndstore; static int checkCoordsX[] = { -4, 4, 0, 0 }; static int checkCoordsY[] = { 0, 0, -4, 4 }; //Find nearby rusted iron (BMTL with tmp 1+) - for(int j = 0; j < 8; j++){ - rndstore = sim->rng.gen(); - rx = (rndstore % 9)-4; + for(int j = 0; j < 8; j++) + { + auto rndstore = sim->rng.gen(); + auto rx = (rndstore % 9)-4; rndstore >>= 4; - ry = (rndstore % 9)-4; - if ((!rx != !ry) && BOUNDS_CHECK) { - r = pmap[y+ry][x+rx]; + auto ry = (rndstore % 9)-4; + if ((!rx != !ry)) { + auto r = pmap[y+ry][x+rx]; if(!r) continue; if(TYP(r)==PT_BMTL && parts[ID(r)].tmp) { @@ -73,18 +73,17 @@ static int update(UPDATE_FUNC_ARGS) //Find sparks if(!parts[i].life) { - for(int j = 0; j < 4; j++){ - rx = checkCoordsX[j]; - ry = checkCoordsY[j]; - if (BOUNDS_CHECK) { - r = pmap[y+ry][x+rx]; - if(!r) continue; - if(TYP(r)==PT_SPRK && parts[ID(r)].life && parts[ID(r)].life<4) - { - sim->part_change_type(i, x, y, PT_SPRK); - parts[i].life = 4; - parts[i].ctype = PT_GOLD; - } + for(int j = 0; j < 4; j++) + { + auto rx = checkCoordsX[j]; + auto ry = checkCoordsY[j]; + auto r = pmap[y+ry][x+rx]; + if(!r) continue; + if(TYP(r)==PT_SPRK && parts[ID(r)].life && parts[ID(r)].life<4) + { + sim->part_change_type(i, x, y, PT_SPRK); + parts[i].life = 4; + parts[i].ctype = PT_GOLD; } } } diff --git a/src/simulation/elements/GPMP.cpp b/src/simulation/elements/GPMP.cpp index d9386749b..d624c7347 100644 --- a/src/simulation/elements/GPMP.cpp +++ b/src/simulation/elements/GPMP.cpp @@ -51,7 +51,6 @@ void Element::Element_GPMP() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life!=10) { if (parts[i].life>0) @@ -65,11 +64,13 @@ static int update(UPDATE_FUNC_ARGS) parts[i].temp = -256.0f+273.15f; sim->gravmap[(y/CELL)*XCELLS+(x/CELL)] = 0.2f*(parts[i].temp-273.15); - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_GPMP) @@ -80,6 +81,8 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].life = 10; } } + } + } } return 0; } diff --git a/src/simulation/elements/H2.cpp b/src/simulation/elements/H2.cpp index 2b959c5f3..ccb0ae299 100644 --- a/src/simulation/elements/H2.cpp +++ b/src/simulation/elements/H2.cpp @@ -47,15 +47,16 @@ void Element::Element_H2() static int update(UPDATE_FUNC_ARGS) { - int r,rx,ry,rt; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (sim->pv[y/CELL][x/CELL] > 8.0f && rt == PT_DESL) // This will not work. DESL turns to fire above 5.0 pressure { sim->part_change_type(ID(r),x+rx,y+ry,PT_WATR); @@ -90,6 +91,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } if (parts[i].temp > 2273.15 && sim->pv[y/CELL][x/CELL] > 50.0f) { if (sim->rng.chance(1, 5)) @@ -115,7 +118,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].temp = temp; parts[j].tmp = 0x1; } - rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.between(-1, 1), rt = TYP(pmap[ry][rx]); + auto rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.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); diff --git a/src/simulation/elements/HSWC.cpp b/src/simulation/elements/HSWC.cpp index 8e6fba41f..0f34069cc 100644 --- a/src/simulation/elements/HSWC.cpp +++ b/src/simulation/elements/HSWC.cpp @@ -49,7 +49,6 @@ void Element::Element_HSWC() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life!=10) { if (parts[i].life>0) @@ -58,11 +57,13 @@ static int update(UPDATE_FUNC_ARGS) else { bool deserializeTemp = parts[i].tmp == 1; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) r = sim->photons[y+ry][x+rx]; if (!r) @@ -84,6 +85,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } return 0; } diff --git a/src/simulation/elements/ICEI.cpp b/src/simulation/elements/ICEI.cpp index 8621adf38..3f93528df 100644 --- a/src/simulation/elements/ICEI.cpp +++ b/src/simulation/elements/ICEI.cpp @@ -50,16 +50,17 @@ void Element::Element_ICEI() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].ctype==PT_FRZW)//get colder if it is from FRZW { parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP); } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SALT || TYP(r)==PT_SLTW) @@ -77,5 +78,7 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].ctype = PT_FRZW; } } + } + } return 0; } diff --git a/src/simulation/elements/IGNT.cpp b/src/simulation/elements/IGNT.cpp index b52369e2b..7b568fccf 100644 --- a/src/simulation/elements/IGNT.cpp +++ b/src/simulation/elements/IGNT.cpp @@ -49,22 +49,25 @@ void Element::Element_IGNT() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; if(parts[i].tmp==0) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if (rt==PT_FIRE || rt==PT_PLSM || rt==PT_SPRK || rt==PT_LIGH || (rt==PT_IGNT && parts[ID(r)].life==1)) { parts[i].tmp = 1; } } + } + } } else if(parts[i].life > 0) { diff --git a/src/simulation/elements/IRON.cpp b/src/simulation/elements/IRON.cpp index b68a71618..3d01e022f 100644 --- a/src/simulation/elements/IRON.cpp +++ b/src/simulation/elements/IRON.cpp @@ -47,14 +47,15 @@ void Element::Element_IRON() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life) return 0; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; switch (TYP(r)) { case PT_SALT: @@ -79,6 +80,8 @@ static int update(UPDATE_FUNC_ARGS) break; } } + } + } return 0; succ: sim->part_change_type(i,x,y,PT_BMTL); diff --git a/src/simulation/elements/LCRY.cpp b/src/simulation/elements/LCRY.cpp index fa5708290..7c0b5d6d6 100644 --- a/src/simulation/elements/LCRY.cpp +++ b/src/simulation/elements/LCRY.cpp @@ -49,7 +49,7 @@ void Element::Element_LCRY() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, check, setto; + int check, setto; switch (parts[i].tmp) { case 1: @@ -85,11 +85,13 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 0; return 0; } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_LCRY && parts[ID(r)].tmp == check) @@ -97,6 +99,8 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].tmp = setto; } } + } + } return 0; } diff --git a/src/simulation/elements/LDTC.cpp b/src/simulation/elements/LDTC.cpp index f4ad432ee..0020cc8ad 100644 --- a/src/simulation/elements/LDTC.cpp +++ b/src/simulation/elements/LDTC.cpp @@ -96,7 +96,7 @@ static int update(UPDATE_FUNC_ARGS) { for (int ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (!r) diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index 4869cc4b6..92380b43e 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -67,9 +67,7 @@ static int update(UPDATE_FUNC_ARGS) * * tmp - angle of lighting, measured in degrees counterclockwise from the positive x direction */ - int r,rx,ry,rt, multipler, powderful; - float angle, angle2=-1; - powderful = int(parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER); + auto powderful = int(parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER); //Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS); if (sim->aheat_enable) { @@ -81,14 +79,16 @@ static int update(UPDATE_FUNC_ARGS) sim->hv[y/CELL][x/CELL] = MAX_TEMP; } - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if ((surround_space || sim->elements[rt].Explosive) && (rt!=PT_SPNG || parts[ID(r)].life==0) && sim->elements[rt].Flammable && sim->rng.chance(sim->elements[rt].Flammable + int(sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f), 1000)) @@ -152,6 +152,8 @@ static int update(UPDATE_FUNC_ARGS) sim->pv[y/CELL][x/CELL] += powderful/400; if (sim->elements[TYP(r)].HeatConduct) parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful/1.3, MIN_TEMP, MAX_TEMP); } + } + } // Deferred branch or bend; or in removal countdown stage if (parts[i].tmp2 == 1 || parts[i].tmp2 == 3 || (parts[i].tmp2 >= 6 && parts[i].tmp2 <= 8)) { @@ -167,14 +169,14 @@ static int update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } - angle = float((parts[i].tmp + sim->rng.between(-30, 30)) % 360); - multipler = int(parts[i].life * 1.5) + sim->rng.between(0, parts[i].life); - rx=int(cos(angle*TPT_PI_FLT/180)*multipler); - ry=int(-sin(angle*TPT_PI_FLT/180)*multipler); + auto angle = float((parts[i].tmp + sim->rng.between(-30, 30)) % 360); + auto multipler = int(parts[i].life * 1.5) + sim->rng.between(0, parts[i].life); + auto rx=int(cos(angle*TPT_PI_FLT/180)*multipler); + auto ry=int(-sin(angle*TPT_PI_FLT/180)*multipler); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle), parts[i].tmp2, i); if (parts[i].tmp2 == 2)// && pNear == -1) { - angle2 = float(((int)angle + sim->rng.between(-100, 100)) % 360); + auto angle2 = float(((int)angle + sim->rng.between(-100, 100)) % 360); rx=int(cos(angle2*TPT_PI_FLT/180)*multipler); ry=int(-sin(angle2*TPT_PI_FLT/180)*multipler); create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle2), parts[i].tmp2, i); diff --git a/src/simulation/elements/LITH.cpp b/src/simulation/elements/LITH.cpp index e25ce10aa..4ace0e832 100644 --- a/src/simulation/elements/LITH.cpp +++ b/src/simulation/elements/LITH.cpp @@ -80,7 +80,7 @@ static int update(UPDATE_FUNC_ARGS) { for (int ry = -2; ry <= 2; ++ry) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int neighborData = pmap[y + ry][x + rx]; if (!neighborData) @@ -198,7 +198,7 @@ static int update(UPDATE_FUNC_ARGS) { int rx = sim->rng.between(-3, 3); int ry = sim->rng.between(-3, 3); - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int neighborData = pmap[y + ry][x + rx]; if (TYP(neighborData) != PT_LITH) diff --git a/src/simulation/elements/LSNS.cpp b/src/simulation/elements/LSNS.cpp index 6521ba8f4..a70f4a22e 100644 --- a/src/simulation/elements/LSNS.cpp +++ b/src/simulation/elements/LSNS.cpp @@ -56,8 +56,10 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].life = 0; for (int rx = -2; rx <= 2; rx++) + { for (int ry = -2; ry <= 2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r) @@ -74,14 +76,17 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r), x + rx, y + ry, PT_SPRK); } } - } + } + } } bool doSerialization = false; bool doDeserialization = false; int life = 0; for (int rx = -rd; rx < rd + 1; rx++) + { for (int ry = -rd; ry < rd + 1; ry++) + { if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) { int r = pmap[y + ry][x + rx]; @@ -120,10 +125,14 @@ static int update(UPDATE_FUNC_ARGS) break; } } + } + } for (int rx = -1; rx <= 1; rx++) + { for (int ry = -1; ry <= 1; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r) @@ -152,6 +161,8 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].life = life - 0x10000000; } } + } + } return 0; } diff --git a/src/simulation/elements/MERC.cpp b/src/simulation/elements/MERC.cpp index b7d5e79a8..756bca1cf 100644 --- a/src/simulation/elements/MERC.cpp +++ b/src/simulation/elements/MERC.cpp @@ -49,7 +49,6 @@ void Element::Element_MERC() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, trade, np; // Max number of particles that can be condensed into one const int absorbScale = 10000; // Obscure division by 0 fix @@ -70,11 +69,13 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].tmp < maxtmp) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r || (parts[i].tmp >=maxtmp)) continue; if (TYP(r)==PT_MERC&& sim->rng.chance(1, 3)) @@ -86,18 +87,23 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } else - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (parts[i].tmp<=maxtmp) continue; if ((!r)&&parts[i].tmp>=1)//if nothing then create MERC { - np = sim->create_part(-1,x+rx,y+ry,PT_MERC); + auto np = sim->create_part(-1,x+rx,y+ry,PT_MERC); if (np<0) continue; parts[i].tmp--; parts[np].temp = parts[i].temp; @@ -105,13 +111,16 @@ static int update(UPDATE_FUNC_ARGS) parts[np].dcolour = parts[i].dcolour; } } - for ( trade = 0; trade<4; trade ++) + } + } + } + for (auto trade = 0; trade<4; trade ++) { - rx = sim->rng.between(-2, 2); - ry = sim->rng.between(-2, 2); - if (BOUNDS_CHECK && (rx || ry)) + auto rx = sim->rng.between(-2, 2); + auto ry = sim->rng.between(-2, 2); + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_MERC&&(parts[i].tmp>parts[ID(r)].tmp)&&parts[i].tmp>0)//diffusion diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index 2e1289603..bfd0c146a 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -54,121 +54,121 @@ void Element::Element_NEUT() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; unsigned int pressureFactor = 3 + (int)sim->pv[y/CELL][x/CELL]; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK) + for (int rx = -1; rx <= 1; rx++) + { + for (int ry = -1; ry <= 1; ry++) + { + auto r = pmap[y+ry][x+rx]; + switch (TYP(r)) { - r = pmap[y+ry][x+rx]; - switch (TYP(r)) + case PT_WATR: + if (sim->rng.chance(3, 20)) + sim->part_change_type(ID(r),x+rx,y+ry,PT_DSTW); + case PT_ICEI: + case PT_SNOW: + parts[i].vx *= 0.995f; + parts[i].vy *= 0.995f; + break; + case PT_PLUT: + if (sim->rng.chance(pressureFactor, 1000)) { - case PT_WATR: - if (sim->rng.chance(3, 20)) - sim->part_change_type(ID(r),x+rx,y+ry,PT_DSTW); - case PT_ICEI: - case PT_SNOW: - parts[i].vx *= 0.995f; - parts[i].vy *= 0.995f; - break; - case PT_PLUT: - if (sim->rng.chance(pressureFactor, 1000)) + if (sim->rng.chance(1, 3)) { - if (sim->rng.chance(1, 3)) - { - sim->create_part(ID(r), x+rx, y+ry, sim->rng.chance(2, 3) ? PT_LAVA : PT_URAN); - parts[ID(r)].temp = MAX_TEMP; - if (parts[ID(r)].type==PT_LAVA) { - parts[ID(r)].tmp = 100; - parts[ID(r)].ctype = PT_PLUT; - } + sim->create_part(ID(r), x+rx, y+ry, sim->rng.chance(2, 3) ? PT_LAVA : PT_URAN); + parts[ID(r)].temp = MAX_TEMP; + if (parts[ID(r)].type==PT_LAVA) { + parts[ID(r)].tmp = 100; + parts[ID(r)].ctype = PT_PLUT; } - else - { - sim->create_part(ID(r), x+rx, y+ry, PT_NEUT); - parts[ID(r)].vx = 0.25f*parts[ID(r)].vx + parts[i].vx; - parts[ID(r)].vy = 0.25f*parts[ID(r)].vy + parts[i].vy; - } - sim->pv[y/CELL][x/CELL] += 10.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough - Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS); } - break; - case PT_DEUT: - if (sim->rng.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)); - } - break; - case PT_GUNP: - if (sim->rng.chance(3, 200)) - sim->part_change_type(ID(r),x+rx,y+ry,PT_DUST); - break; - case PT_DYST: - if (sim->rng.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 (sim->rng.chance(3, 200)) - sim->part_change_type(ID(r),x+rx,y+ry,PT_GOO); - break; - case PT_NITR: - if (sim->rng.chance(3, 200)) - sim->part_change_type(ID(r),x+rx,y+ry,PT_DESL); - break; - case PT_PLNT: - if (sim->rng.chance(1, 20)) - sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); - break; - case PT_DESL: - case PT_OIL: - if (sim->rng.chance(3, 200)) - sim->part_change_type(ID(r),x+rx,y+ry,PT_GAS); - break; - case PT_COAL: - if (sim->rng.chance(1, 20)) - sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); - break; - case PT_BCOL: - if (sim->rng.chance(1, 20)) - sim->create_part(ID(r), x+rx, y+ry, PT_SAWD); - break; - case PT_DUST: - if (sim->rng.chance(1, 20)) - sim->part_change_type(ID(r), x+rx, y+ry, PT_FWRK); - break; - case PT_FWRK: - if (sim->rng.chance(1, 20)) - parts[ID(r)].ctype = PT_DUST; - break; - case PT_ACID: - if (sim->rng.chance(1, 20)) - sim->create_part(ID(r), x+rx, y+ry, PT_ISOZ); - break; - case PT_TTAN: - if (sim->rng.chance(1, 20)) - { - sim->kill_part(i); - return 1; - } - break; - case PT_EXOT: - if (sim->rng.chance(1, 20)) - parts[ID(r)].life = 1500; - break; - case PT_RFRG: - if (sim->rng.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); - break; - default: - break; + { + sim->create_part(ID(r), x+rx, y+ry, PT_NEUT); + parts[ID(r)].vx = 0.25f*parts[ID(r)].vx + parts[i].vx; + parts[ID(r)].vy = 0.25f*parts[ID(r)].vy + parts[i].vy; + } + sim->pv[y/CELL][x/CELL] += 10.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough + Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS); } + break; + case PT_DEUT: + if (sim->rng.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)); + } + break; + case PT_GUNP: + if (sim->rng.chance(3, 200)) + sim->part_change_type(ID(r),x+rx,y+ry,PT_DUST); + break; + case PT_DYST: + if (sim->rng.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 (sim->rng.chance(3, 200)) + sim->part_change_type(ID(r),x+rx,y+ry,PT_GOO); + break; + case PT_NITR: + if (sim->rng.chance(3, 200)) + sim->part_change_type(ID(r),x+rx,y+ry,PT_DESL); + break; + case PT_PLNT: + if (sim->rng.chance(1, 20)) + sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); + break; + case PT_DESL: + case PT_OIL: + if (sim->rng.chance(3, 200)) + sim->part_change_type(ID(r),x+rx,y+ry,PT_GAS); + break; + case PT_COAL: + if (sim->rng.chance(1, 20)) + sim->create_part(ID(r), x+rx, y+ry, PT_WOOD); + break; + case PT_BCOL: + if (sim->rng.chance(1, 20)) + sim->create_part(ID(r), x+rx, y+ry, PT_SAWD); + break; + case PT_DUST: + if (sim->rng.chance(1, 20)) + sim->part_change_type(ID(r), x+rx, y+ry, PT_FWRK); + break; + case PT_FWRK: + if (sim->rng.chance(1, 20)) + parts[ID(r)].ctype = PT_DUST; + break; + case PT_ACID: + if (sim->rng.chance(1, 20)) + sim->create_part(ID(r), x+rx, y+ry, PT_ISOZ); + break; + case PT_TTAN: + if (sim->rng.chance(1, 20)) + { + sim->kill_part(i); + return 1; + } + break; + case PT_EXOT: + if (sim->rng.chance(1, 20)) + parts[ID(r)].life = 1500; + break; + case PT_RFRG: + if (sim->rng.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); + break; + default: + break; } + } + } return 0; } diff --git a/src/simulation/elements/O2.cpp b/src/simulation/elements/O2.cpp index 62a362bdc..bba9c936f 100644 --- a/src/simulation/elements/O2.cpp +++ b/src/simulation/elements/O2.cpp @@ -47,12 +47,13 @@ void Element::Element_O2() static int update(UPDATE_FUNC_ARGS) { - int r,rx,ry; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; @@ -74,6 +75,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].tmp |= 2; } } + } + } if (parts[i].temp > 9973.15 && sim->pv[y/CELL][x/CELL] > 250.0f) { int gravPos = ((y/CELL)*XCELLS)+(x/CELL); @@ -95,7 +98,7 @@ static int update(UPDATE_FUNC_ARGS) parts[j].temp = MAX_TEMP; parts[j].tmp = 0x1; } - rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.between(-1, 1), r = TYP(pmap[ry][rx]); + auto rx = x + sim->rng.between(-1, 1), ry = y + sim->rng.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/PBCN.cpp b/src/simulation/elements/PBCN.cpp index 3ef66a158..e2b678d52 100644 --- a/src/simulation/elements/PBCN.cpp +++ b/src/simulation/elements/PBCN.cpp @@ -54,7 +54,6 @@ constexpr float ADVECTION = 0.1f; static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; if (!parts[i].tmp2 && sim->pv[y/CELL][x/CELL]>4.0f) parts[i].tmp2 = sim->rng.between(80, 119); if (parts[i].tmp2) @@ -68,27 +67,30 @@ static int update(UPDATE_FUNC_ARGS) } } if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled) - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + auto r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + auto rt = TYP(r); + if (rt!=PT_CLNE && rt!=PT_PCLN && + rt!=PT_BCLN && rt!=PT_SPRK && + rt!=PT_NSCN && rt!=PT_PSCN && + rt!=PT_STKM && rt!=PT_STKM2 && + rt!=PT_PBCN && rtphotons[y+ry][x+rx]; - if (!r) - r = pmap[y+ry][x+rx]; - if (!r) - continue; - rt = TYP(r); - if (rt!=PT_CLNE && rt!=PT_PCLN && - rt!=PT_BCLN && rt!=PT_SPRK && - rt!=PT_NSCN && rt!=PT_PSCN && - rt!=PT_STKM && rt!=PT_STKM2 && - rt!=PT_PBCN && rt0) @@ -96,11 +98,13 @@ static int update(UPDATE_FUNC_ARGS) } else { - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_PBCN) @@ -111,11 +115,15 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].life = 10; } } + } + } if (parts[i].ctype>0 && parts[i].ctypeelements[parts[i].ctype].Enabled) { if (parts[i].ctype==PT_PHOT) {//create photons a different way - for (rx=-1; rx<2; rx++) - for (ry = -1; ry < 2; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { if (rx || ry) { int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT); @@ -130,12 +138,19 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } else if (parts[i].ctype==PT_LIFE)//create life a different way - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); - + } + } + } else if (parts[i].ctype!=PT_LIGH || sim->rng.chance(1, 30)) { int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), TYP(parts[i].ctype)); diff --git a/src/simulation/elements/PCLN.cpp b/src/simulation/elements/PCLN.cpp index 2b4e9363c..79eaa8ef6 100644 --- a/src/simulation/elements/PCLN.cpp +++ b/src/simulation/elements/PCLN.cpp @@ -52,14 +52,15 @@ void Element::Element_PCLN() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; if (parts[i].life>0 && parts[i].life!=10) parts[i].life--; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPRK) @@ -80,33 +81,40 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 10; } } + } + } if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled) - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + auto r = sim->photons[y+ry][x+rx]; + if (!r) + r = pmap[y+ry][x+rx]; + if (!r) + continue; + auto rt = TYP(r); + if (rt!=PT_CLNE && rt!=PT_PCLN && + rt!=PT_BCLN && rt!=PT_SPRK && + rt!=PT_NSCN && rt!=PT_PSCN && + rt!=PT_STKM && rt!=PT_STKM2 && + rt!=PT_PBCN && rtphotons[y+ry][x+rx]; - if (!r) - r = pmap[y+ry][x+rx]; - if (!r) - continue; - rt = TYP(r); - if (rt!=PT_CLNE && rt!=PT_PCLN && - rt!=PT_BCLN && rt!=PT_SPRK && - rt!=PT_NSCN && rt!=PT_PSCN && - rt!=PT_STKM && rt!=PT_STKM2 && - rt!=PT_PBCN && rt0 && parts[i].ctypeelements[parts[i].ctype].Enabled && parts[i].life==10) { if (parts[i].ctype==PT_PHOT) {//create photons a different way - for (rx=-1; rx<2; rx++) - for (ry = -1; ry < 2; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { if (rx || ry) { int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT); @@ -121,12 +129,19 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } else if (parts[i].ctype==PT_LIFE)//create life a different way - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); - + } + } + } else if (parts[i].ctype != PT_LIGH || sim->rng.chance(1, 30)) { int np = sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), TYP(parts[i].ctype)); diff --git a/src/simulation/elements/PHOT.cpp b/src/simulation/elements/PHOT.cpp index d5cbb8a98..56432a48b 100644 --- a/src/simulation/elements/PHOT.cpp +++ b/src/simulation/elements/PHOT.cpp @@ -56,8 +56,6 @@ void Element::Element_PHOT() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - float rr, rrr; if (!(parts[i].ctype&0x3FFFFFFF)) { sim->kill_part(i); return 1; @@ -65,54 +63,57 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].temp > 506) if (sim->rng.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) { - r = pmap[y+ry][x+rx]; - if (!r) - continue; - if (TYP(r)==PT_ISOZ || TYP(r)==PT_ISZS) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + auto r = pmap[y+ry][x+rx]; + if (!r) + continue; + if (TYP(r)==PT_ISOZ || TYP(r)==PT_ISZS) + { + if (sim->rng.chance(1, 400)) { - if (sim->rng.chance(1, 400)) - { - parts[i].vx *= 0.90f; - parts[i].vy *= 0.90f; - sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); - rrr = sim->rng.between(0, 359) * 3.14159f / 180.0f; - if (TYP(r) == PT_ISOZ) - rr = sim->rng.between(128, 255) / 127.0f; - else - rr = sim->rng.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; - } - } - else if((TYP(r) == PT_QRTZ || TYP(r) == PT_PQRT) && !ry && !rx)//if on QRTZ - { - float a = sim->rng.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 << sim->rng.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 = sim->rng.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; - parts[i].vx = vx; - parts[i].vy = vy; - } - else if (TYP(r) == PT_FILT && parts[ID(r)].tmp==9) - { - parts[i].vx += ((float)sim->rng.between(-500, 500))/1000.0f; - parts[i].vy += ((float)sim->rng.between(-500, 500))/1000.0f; + parts[i].vx *= 0.90f; + parts[i].vy *= 0.90f; + sim->create_part(ID(r), x+rx, y+ry, PT_PHOT); + auto rrr = sim->rng.between(0, 359) * 3.14159f / 180.0f; + int rr; + if (TYP(r) == PT_ISOZ) + rr = sim->rng.between(128, 255) / 127.0f; + else + rr = sim->rng.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; } } + else if((TYP(r) == PT_QRTZ || TYP(r) == PT_PQRT) && !ry && !rx)//if on QRTZ + { + float a = sim->rng.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 << sim->rng.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 = sim->rng.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; + parts[i].vx = vx; + parts[i].vy = vy; + } + else if (TYP(r) == PT_FILT && parts[ID(r)].tmp==9) + { + parts[i].vx += ((float)sim->rng.between(-500, 500))/1000.0f; + parts[i].vy += ((float)sim->rng.between(-500, 500))/1000.0f; + } + } + } return 0; } diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 4e6446814..c39961f00 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -123,8 +123,6 @@ static unsigned int nextColor(unsigned int flags) int Element_PIPE_update(UPDATE_FUNC_ARGS) { - int r, rx, ry, np; - int rnd, rndstore; if (parts[i].ctype && !sim->elements[TYP(parts[i].ctype)].Enabled) parts[i].ctype = 0; if (parts[i].tmp & PPIP_TMPFLAG_TRIGGERS) @@ -144,13 +142,13 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) } if (pause_changed) { - int rx, ry, r; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (TYP(r) == PT_BRCK) { if (parts[i].tmp & PPIP_TMPFLAG_PAUSED) @@ -160,6 +158,7 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) } } } + } } if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_REVERSE) @@ -188,12 +187,14 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) int neighborcount = 0; int count = 0; // make automatic pipe pattern - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { count++; - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r) != PT_PIPE && TYP(r) != PT_PPIP) @@ -224,6 +225,8 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) lastneighbor = ID(r); } } + } + } if (neighborcount == 1) parts[lastneighbor].tmp |= 0x100; } @@ -240,50 +243,47 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) if (nt)//there is something besides PIPE around current particle { - rndstore = sim->rng.gen(); - rnd = rndstore&7; - //rndstore = rndstore>>3; - rx = Element_PIPE_offsets[rnd].X; - ry = Element_PIPE_offsets[rnd].Y; - if (BOUNDS_CHECK) + auto rndstore = sim->rng.gen(); + auto rnd = rndstore&7; + auto rx = Element_PIPE_offsets[rnd].X; + auto ry = Element_PIPE_offsets[rnd].Y; + auto r = pmap[y+ry][x+rx]; + if(!r) + r = sim->photons[y+ry][x+rx]; + if (surround_space && !r && TYP(parts[i].ctype)) //creating at end { - r = pmap[y+ry][x+rx]; - if(!r) - r = sim->photons[y+ry][x+rx]; - if (surround_space && !r && TYP(parts[i].ctype)) //creating at end + auto np = sim->create_part(-1, x+rx, y+ry, TYP(parts[i].ctype)); + if (np!=-1) { - np = sim->create_part(-1, x+rx, y+ry, TYP(parts[i].ctype)); - if (np!=-1) - { - Element_PIPE_transfer_pipe_to_part(sim, parts+i, parts+np, false); - } - } - //try eating particle at entrance - else if (!TYP(parts[i].ctype) && (sim->elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) - { - if (TYP(r)==PT_SOAP) - Element_SOAP_detach(sim, ID(r)); - transfer_part_to_pipe(parts+(ID(r)), parts+i); - sim->kill_part(ID(r)); - } - else if (!TYP(parts[i].ctype) && TYP(r)==PT_STOR && sim->IsElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) - { - // STOR stores properties in the same places as PIPE does - transfer_pipe_to_pipe(parts+(ID(r)), parts+i, true); + Element_PIPE_transfer_pipe_to_part(sim, parts+i, parts+np, false); } } + //try eating particle at entrance + else if (!TYP(parts[i].ctype) && (sim->elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + { + if (TYP(r)==PT_SOAP) + Element_SOAP_detach(sim, ID(r)); + transfer_part_to_pipe(parts+(ID(r)), parts+i); + sim->kill_part(ID(r)); + } + else if (!TYP(parts[i].ctype) && TYP(r)==PT_STOR && sim->IsElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + { + // STOR stores properties in the same places as PIPE does + transfer_pipe_to_pipe(parts+(ID(r)), parts+i, true); + } } } } else if (!(parts[i].tmp&(PFLAG_COLORS|PFLAG_INITIALIZING)) && parts[i].life<=10) { // make a border - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) { // BRCK border @@ -293,6 +293,7 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) } } } + } if (parts[i].life <= 1) parts[i].tmp |= PFLAG_INITIALIZING; } @@ -301,25 +302,33 @@ int Element_PIPE_update(UPDATE_FUNC_ARGS) { if (!parts[i].life) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { if (!pmap[y+ry][x+rx] && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_ALLOWAIR && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_WALL && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_WALLELEC && (sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_EWALL || sim->emap[(y+ry)/CELL][(x+rx)/CELL])) parts[i].life=50; } + } + } } else if (parts[i].life==5)//check for beginning of pipe single pixel { int issingle = 1; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && parts[i].life) issingle = 0; } + } + } if (issingle) parts[i].tmp |= 0x100; } @@ -467,60 +476,56 @@ static void transfer_pipe_to_pipe(Particle *src, Particle *dest, bool STOR) static void pushParticle(Simulation * sim, int i, int count, int original) { - int rndstore, rnd, rx, ry, r, x, y, np, q; unsigned int notctype = nextColor(sim->parts[i].tmp); if (!TYP(sim->parts[i].ctype) || count >= 2)//don't push if there is nothing there, max speed of 2 per frame return; - x = (int)(sim->parts[i].x+0.5f); - y = (int)(sim->parts[i].y+0.5f); + auto x = (int)(sim->parts[i].x+0.5f); + auto y = (int)(sim->parts[i].y+0.5f); if( !(sim->parts[i].tmp&0x200) ) { //normal random push - rndstore = sim->rng.gen(); + auto rndstore = sim->rng.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 + for (auto q=0; q<3; q++)//try to push 3 times { - rnd = rndstore&7; + auto rnd = rndstore&7; rndstore = rndstore>>3; - rx = Element_PIPE_offsets[rnd].X; - ry = Element_PIPE_offsets[rnd].Y; - if (BOUNDS_CHECK) + auto rx = Element_PIPE_offsets[rnd].X; + auto ry = Element_PIPE_offsets[rnd].Y; + auto r = sim->pmap[y+ry][x+rx]; + if (!r) + continue; + else if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && (sim->parts[ID(r)].tmp&PFLAG_COLORS) != notctype && !TYP(sim->parts[ID(r)].ctype)) { - r = sim->pmap[y+ry][x+rx]; - if (!r) - continue; - else if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && (sim->parts[ID(r)].tmp&PFLAG_COLORS) != notctype && !TYP(sim->parts[ID(r)].ctype)) - { - transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r)), false); - if (ID(r) > original) - sim->parts[ID(r)].flags |= PFLAG_NORMALSPEED;//skip particle push, normalizes speed - count++; - pushParticle(sim, ID(r),count,original); - } - else if (TYP(r) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase - { - int portaltmp = sim->parts[ID(r)].tmp; - if (portaltmp >= CHANNELS) - portaltmp = CHANNELS-1; - else if (portaltmp < 0) - portaltmp = 0; - for (int nnx = 0; nnx < 80; nnx++) - if (!sim->portalp[portaltmp][count][nnx].type) - { - Element_PIPE_transfer_pipe_to_part(sim, sim->parts+i, &(sim->portalp[portaltmp][count][nnx]), false); - count++; - break; - } - } + transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r)), false); + if (ID(r) > original) + sim->parts[ID(r)].flags |= PFLAG_NORMALSPEED;//skip particle push, normalizes speed + count++; + pushParticle(sim, ID(r),count,original); + } + else if (TYP(r) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase + { + int portaltmp = sim->parts[ID(r)].tmp; + if (portaltmp >= CHANNELS) + portaltmp = CHANNELS-1; + else if (portaltmp < 0) + portaltmp = 0; + for (int nnx = 0; nnx < 80; nnx++) + if (!sim->portalp[portaltmp][count][nnx].type) + { + Element_PIPE_transfer_pipe_to_part(sim, sim->parts+i, &(sim->portalp[portaltmp][count][nnx]), false); + count++; + break; + } } } } else //predefined 1 pixel thick pipe movement { int coords = 7 - ((sim->parts[i].tmp>>10)&7); - r = sim->pmap[y+ Element_PIPE_offsets[coords].Y][x+ Element_PIPE_offsets[coords].X]; + auto r = sim->pmap[y+ Element_PIPE_offsets[coords].Y][x+ Element_PIPE_offsets[coords].X]; if ((TYP(r)==PT_PIPE || TYP(r) == PT_PPIP) && (sim->parts[ID(r)].tmp&PFLAG_COLORS) != notctype && !TYP(sim->parts[ID(r)].ctype)) { transfer_pipe_to_pipe(sim->parts+i, sim->parts+(ID(r)), false); @@ -546,9 +551,9 @@ static void pushParticle(Simulation * sim, int i, int count, int original) } else if (!r) //Move particles out of pipe automatically, much faster at ends { - rx = Element_PIPE_offsets[coords].X; - ry = Element_PIPE_offsets[coords].Y; - np = sim->create_part(-1,x+rx,y+ry,TYP(sim->parts[i].ctype)); + auto rx = Element_PIPE_offsets[coords].X; + auto ry = Element_PIPE_offsets[coords].Y; + auto np = sim->create_part(-1,x+rx,y+ry,TYP(sim->parts[i].ctype)); if (np!=-1) { Element_PIPE_transfer_pipe_to_part(sim, sim->parts+i, sim->parts+np, false); diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp index abf9da4aa..f5f92cc62 100644 --- a/src/simulation/elements/PLNT.cpp +++ b/src/simulation/elements/PLNT.cpp @@ -51,18 +51,19 @@ void Element::Element_PLNT() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, np, rndstore; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; switch (TYP(r)) { case PT_WATR: if (sim->rng.chance(1, 50)) { - np = sim->create_part(ID(r),x+rx,y+ry,PT_PLNT); + auto np = sim->create_part(ID(r),x+rx,y+ry,PT_PLNT); if (np<0) continue; parts[np].life = 0; } @@ -83,20 +84,22 @@ static int update(UPDATE_FUNC_ARGS) } break; case PT_WOOD: - rndstore = sim->rng.gen(); - if (surround_space && !(rndstore%4) && parts[i].tmp==1) { - rndstore >>= 3; - int nnx = (rndstore%3) -1; - rndstore >>= 2; - int nny = (rndstore%3) -1; - if (nnx || nny) + auto rndstore = sim->rng.gen(); + if (surround_space && !(rndstore%4) && parts[i].tmp==1) { - if (pmap[y+ry+nny][x+rx+nnx]) - continue; - np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_VINE); - if (np<0) continue; - parts[np].temp = parts[i].temp; + rndstore >>= 3; + int nnx = (rndstore%3) -1; + rndstore >>= 2; + int nny = (rndstore%3) -1; + if (nnx || nny) + { + if (pmap[y+ry+nny][x+rx+nnx]) + continue; + auto np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_VINE); + if (np<0) continue; + parts[np].temp = parts[i].temp; + } } } break; @@ -104,16 +107,22 @@ static int update(UPDATE_FUNC_ARGS) continue; } } + } + } if (parts[i].life==2) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) sim->create_part(-1,x+rx,y+ry,PT_O2); } + } + } parts[i].life = 0; } if (parts[i].temp > 350 && parts[i].temp > parts[i].tmp2) diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp index 519457791..c0675eed5 100644 --- a/src/simulation/elements/PRTI.cpp +++ b/src/simulation/elements/PRTI.cpp @@ -71,7 +71,7 @@ static int update(UPDATE_FUNC_ARGS) { int rx = sim->portal_rx[count]; int ry = sim->portal_ry[count]; - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (!r || TYP(r) == PT_STOR) diff --git a/src/simulation/elements/PRTO.cpp b/src/simulation/elements/PRTO.cpp index a701aa2fa..bf9b1e485 100644 --- a/src/simulation/elements/PRTO.cpp +++ b/src/simulation/elements/PRTO.cpp @@ -48,105 +48,107 @@ void Element::Element_PRTO() } /*these are the count values of where the particle gets stored, depending on where it came from - 0 1 2 - 7 . 3 - 6 5 4 - PRTO does (count+4)%8, so that it will come out at the opposite place to where it came in - PRTO does +/-1 to the count, so it doesn't jam as easily + 0 1 2 + 7 . 3 + 6 5 4 + PRTO does (count+4)%8, so that it will come out at the opposite place to where it came in + PRTO does +/-1 to the count, so it doesn't jam as easily */ static int update(UPDATE_FUNC_ARGS) { - int r, nnx, rx, ry, np, fe = 0; - int count = 0; + int fe = 0; parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; else if (parts[i].tmp<0) parts[i].tmp = 0; - for (count=0; count<8; count++) + for (auto count=0; count<8; count++) { - rx = sim->portal_rx[count]; - ry = sim->portal_ry[count]; - if (BOUNDS_CHECK && (rx || ry)) + auto rx = sim->portal_rx[count]; + auto ry = sim->portal_ry[count]; + if (rx || ry) + { + auto r = pmap[y+ry][x+rx]; + if (!r) { - r = pmap[y+ry][x+rx]; - if (!r) + fe = 1; + for (auto nnx =0 ; nnx<80; nnx++) { - fe = 1; - for ( nnx =0 ; nnx<80; nnx++) + int randomness = (count + sim->rng.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 { - int randomness = (count + sim->rng.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); + sim->create_part(-1,x+1,y+1,PT_SPRK); + sim->create_part(-1,x+1,y-1,PT_SPRK); + sim->create_part(-1,x,y-1,PT_SPRK); + sim->create_part(-1,x,y+1,PT_SPRK); + sim->create_part(-1,x-1,y+1,PT_SPRK); + sim->create_part(-1,x-1,y,PT_SPRK); + sim->create_part(-1,x-1,y-1,PT_SPRK); + memset(&sim->portalp[parts[i].tmp][randomness][nnx], 0, sizeof(Particle)); + break; + } + else if (sim->portalp[parts[i].tmp][randomness][nnx].type) + { + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM) + sim->player.spwn = 0; + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2) + sim->player2.spwn = 0; + if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH) { - sim->create_part(-1,x+1,y,PT_SPRK); - sim->create_part(-1,x+1,y+1,PT_SPRK); - sim->create_part(-1,x+1,y-1,PT_SPRK); - sim->create_part(-1,x,y-1,PT_SPRK); - sim->create_part(-1,x,y+1,PT_SPRK); - sim->create_part(-1,x-1,y+1,PT_SPRK); - sim->create_part(-1,x-1,y,PT_SPRK); - sim->create_part(-1,x-1,y-1,PT_SPRK); - memset(&sim->portalp[parts[i].tmp][randomness][nnx], 0, sizeof(Particle)); - break; + sim->fighcount--; + sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 0; } - else if (sim->portalp[parts[i].tmp][randomness][nnx].type) + auto np = sim->create_part(-1, x+rx, y+ry, sim->portalp[parts[i].tmp][randomness][nnx].type); + if (np<0) { if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM) - sim->player.spwn = 0; + sim->player.spwn = 1; if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2) - sim->player2.spwn = 0; + sim->player2.spwn = 1; if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH) { - sim->fighcount--; - sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 0; - } - np = sim->create_part(-1, x+rx, y+ry, sim->portalp[parts[i].tmp][randomness][nnx].type); - if (np<0) - { - if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM) - sim->player.spwn = 1; - if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2) - sim->player2.spwn = 1; - if (sim->portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH) - { - sim->fighcount++; - sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1; - } - continue; - } - if (parts[np].type==PT_FIGH) - { - // Release the fighters[] element allocated by create_part, the one reserved when the fighter went into the portal will be used - sim->fighters[(unsigned char)parts[np].tmp].spwn = 0; + sim->fighcount++; sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1; } - if (sim->portalp[parts[i].tmp][randomness][nnx].vx == 0.0f && sim->portalp[parts[i].tmp][randomness][nnx].vy == 0.0f) - { - // particles that have passed from PIPE into PRTI have lost their velocity, so use the velocity of the newly created particle if the particle in the portal has no velocity - float tmp_vx = parts[np].vx; - float tmp_vy = parts[np].vy; - parts[np] = sim->portalp[parts[i].tmp][randomness][nnx]; - parts[np].vx = tmp_vx; - parts[np].vy = tmp_vy; - } - else - parts[np] = sim->portalp[parts[i].tmp][randomness][nnx]; - parts[np].x = float(x+rx); - parts[np].y = float(y+ry); - memset(&sim->portalp[parts[i].tmp][randomness][nnx], 0, sizeof(Particle)); - break; + continue; } + if (parts[np].type==PT_FIGH) + { + // Release the fighters[] element allocated by create_part, the one reserved when the fighter went into the portal will be used + sim->fighters[(unsigned char)parts[np].tmp].spwn = 0; + sim->fighters[(unsigned char)sim->portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1; + } + if (sim->portalp[parts[i].tmp][randomness][nnx].vx == 0.0f && sim->portalp[parts[i].tmp][randomness][nnx].vy == 0.0f) + { + // particles that have passed from PIPE into PRTI have lost their velocity, so use the velocity of the newly created particle if the particle in the portal has no velocity + float tmp_vx = parts[np].vx; + float tmp_vy = parts[np].vy; + parts[np] = sim->portalp[parts[i].tmp][randomness][nnx]; + parts[np].vx = tmp_vx; + parts[np].vy = tmp_vy; + } + else + parts[np] = sim->portalp[parts[i].tmp][randomness][nnx]; + parts[np].x = float(x+rx); + parts[np].y = float(y+ry); + memset(&sim->portalp[parts[i].tmp][randomness][nnx], 0, sizeof(Particle)); + break; } } } + } } - if (fe) { + 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 = sim->rng.gen(); if (!sim->parts[i].ctype) parts[i].ctype = sim->rng.gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); - for (r = 0; r < 4; r++) { - if (orbd[r]<254) { + for (auto r = 0; r < 4; r++) + { + if (orbd[r]<254) + { orbd[r] += 16; if (orbd[r]>254) { orbd[r] = 0; @@ -157,15 +159,17 @@ static int update(UPDATE_FUNC_ARGS) orbl[r] += 1; orbl[r] = orbl[r]%255; } - //orbl[r] += 1; - //orbl[r] = orbl[r]%255; - } else { + } + else + { orbd[r] = 0; orbl[r] = sim->rng.between(0, 254); } } sim->orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); - } else { + } + else + { parts[i].life = 0; parts[i].ctype = 0; } diff --git a/src/simulation/elements/PSNS.cpp b/src/simulation/elements/PSNS.cpp index 2f92afa99..3d893f287 100644 --- a/src/simulation/elements/PSNS.cpp +++ b/src/simulation/elements/PSNS.cpp @@ -48,19 +48,20 @@ void Element::Element_PSNS() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; if ((parts[i].tmp == 0 && sim->pv[y/CELL][x/CELL] > parts[i].temp-273.15f) || (parts[i].tmp == 2 && sim->pv[y/CELL][x/CELL] < parts[i].temp-273.15f)) { - for (rx = -2; rx <= 2; rx++) - for (ry = -2; ry <= 2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (sim->parts_avg(i,ID(r),PT_INSL) != PT_INSL) { - rt = TYP(r); + auto rt = TYP(r); if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) { parts[ID(r)].life = 4; @@ -69,6 +70,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } if (parts[i].tmp == 1) { @@ -76,16 +79,17 @@ static int update(UPDATE_FUNC_ARGS) float photonWl = sim->pv[y / CELL][x / CELL]; if (setFilt) { - int nx, ny; - for (rx = -1; rx <= 1; rx++) - for (ry = -1; ry <= 1; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y + ry][x + rx]; + auto r = pmap[y + ry][x + rx]; if (!r) continue; - nx = x + rx; - ny = y + ry; + auto nx = x + rx; + auto ny = y + ry; while (TYP(r) == PT_FILT) { parts[ID(r)].ctype = 0x10000000 + int(round(photonWl) - MIN_PRESSURE); @@ -96,6 +100,8 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[ny][nx]; } } + } + } } } return 0; diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index 225ade2f6..63efb4811 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -83,14 +83,16 @@ static int update(UPDATE_FUNC_ARGS) int maxSize = parts[i].tmp ? parts[i].tmp : DEFAULT_LIMIT; int armLimit = parts[i].tmp2 ? parts[i].tmp2 : DEFAULT_ARM_LIMIT; int state = 0; - int r, nxx, nyy, nxi, nyi, rx, ry; int directionX = 0, directionY = 0; - if (state == PISTON_INACTIVE) { - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry) && (!rx || !ry)) + if (state == PISTON_INACTIVE) + { + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if ((rx || ry) && (!rx || !ry)) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPRK && parts[ID(r)].life==3) { @@ -100,13 +102,18 @@ static int update(UPDATE_FUNC_ARGS) state = PISTON_RETRACT; } } + } + } } - if(state == PISTON_EXTEND || state == PISTON_RETRACT) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry) && (!rx || !ry)) + if (state == PISTON_EXTEND || state == PISTON_RETRACT) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if ((rx || ry) && (!rx || !ry)) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r) == PT_PSTN && !parts[ID(r)].life) @@ -119,7 +126,9 @@ static int update(UPDATE_FUNC_ARGS) int armCount = 0; directionX = rx; directionY = ry; - for (nxx = 0, nyy = 0, nxi = directionX, nyi = directionY; ; nyy += nyi, nxx += nxi) { + auto nxi = directionX, nyi = directionY; + for (auto nxx = 0, nyy = 0; ; nyy += nyi, nxx += nxi) + { if (!(x+nxx= 0 && y+nyy >= 0)) { break; } @@ -190,7 +199,8 @@ static int update(UPDATE_FUNC_ARGS) return 0; } } - + } + } } return 0; } diff --git a/src/simulation/elements/PTNM.cpp b/src/simulation/elements/PTNM.cpp index 045d4a14a..1593b124f 100644 --- a/src/simulation/elements/PTNM.cpp +++ b/src/simulation/elements/PTNM.cpp @@ -54,7 +54,7 @@ static void wtrv_reactions(int wtrv1_id, UPDATE_FUNC_ARGS) { for (int ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r || ID(r) == wtrv1_id) @@ -79,7 +79,7 @@ static void hygn_reactions(int hygn1_id, UPDATE_FUNC_ARGS) { for (int ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r || ID(r) == hygn1_id) @@ -167,7 +167,7 @@ static int update(UPDATE_FUNC_ARGS) { for (int ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r) diff --git a/src/simulation/elements/PUMP.cpp b/src/simulation/elements/PUMP.cpp index c1dda5ab2..a885970af 100644 --- a/src/simulation/elements/PUMP.cpp +++ b/src/simulation/elements/PUMP.cpp @@ -52,7 +52,6 @@ void Element::Element_PUMP() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life != 10) { if (parts[i].life>0) @@ -65,8 +64,9 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].temp <= MIN_PRESSURE+273.15f) parts[i].temp = MIN_PRESSURE+273.15f; - for (rx = -1; rx <= 1; rx++) - for (ry = -1; ry <= 1; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) { if (parts[i].tmp != 1) { @@ -86,11 +86,14 @@ static int update(UPDATE_FUNC_ARGS) } } } - for (rx = -2; rx <= 2; rx++) - for (ry = -2; ry <= 2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + } + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r) == PT_PUMP) @@ -101,6 +104,8 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].life = 10; } } + } + } } return 0; } diff --git a/src/simulation/elements/PVOD.cpp b/src/simulation/elements/PVOD.cpp index 98f039d81..213de466b 100644 --- a/src/simulation/elements/PVOD.cpp +++ b/src/simulation/elements/PVOD.cpp @@ -49,14 +49,15 @@ void Element::Element_PVOD() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].life>0 && parts[i].life!=10) parts[i].life--; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPRK) @@ -77,6 +78,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 10; } } + } + } return 0; } diff --git a/src/simulation/elements/QRTZ.cpp b/src/simulation/elements/QRTZ.cpp index 5acf98545..76f778eae 100644 --- a/src/simulation/elements/QRTZ.cpp +++ b/src/simulation/elements/QRTZ.cpp @@ -51,7 +51,7 @@ void Element::Element_QRTZ() int Element_QRTZ_update(UPDATE_FUNC_ARGS) { - int r, tmp, trade, rx, ry, np, t = parts[i].type; + int t = parts[i].type; if (t == PT_QRTZ) { auto press = int(sim->pv[y/CELL][x/CELL] * 64); @@ -67,11 +67,14 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) parts[i].life = 5; // absorb SLTW if (parts[i].tmp != -1) - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; else if (TYP(r)==PT_SLTW && sim->rng.chance(1, 500)) @@ -80,26 +83,28 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) parts[i].tmp++; } } + } + } + } // grow and diffuse if (parts[i].tmp > 0 && (parts[i].vx*parts[i].vx + parts[i].vy*parts[i].vy)<0.2f && parts[i].life<=0) { bool stopgrow = false; - int rnd, sry, srx; - for (trade = 0; trade < 9; trade++) + for (auto trade = 0; trade < 9; trade++) { - rnd = sim->rng.gen() % 0x3FF; - rx = (rnd%5)-2; - srx = (rnd%3)-1; + auto rnd = sim->rng.gen() % 0x3FF; + auto rx = (rnd%5)-2; + auto srx = (rnd%3)-1; rnd >>= 3; - ry = (rnd%5)-2; - sry = (rnd%3)-1; - if (BOUNDS_CHECK && (rx || ry)) + auto ry = (rnd%5)-2; + auto sry = (rnd%3)-1; + if (rx || ry) { if (!stopgrow)//try to grow { if (!pmap[y+sry][x+srx] && parts[i].tmp!=0) { - np = sim->create_part(-1,x+srx,y+sry,PT_QRTZ); + auto np = sim->create_part(-1,x+srx,y+sry,PT_QRTZ); if (np>-1) { parts[np].temp = parts[i].temp; @@ -127,12 +132,12 @@ int Element_QRTZ_update(UPDATE_FUNC_ARGS) } } //diffusion - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; else if (TYP(r)==PT_QRTZ && (parts[i].tmp>parts[ID(r)].tmp) && parts[ID(r)].tmp>=0) { - tmp = parts[i].tmp - parts[ID(r)].tmp; + auto tmp = parts[i].tmp - parts[ID(r)].tmp; if (tmp ==1) { parts[ID(r)].tmp++; diff --git a/src/simulation/elements/RIME.cpp b/src/simulation/elements/RIME.cpp index 1884db1ec..e59cb0a8d 100644 --- a/src/simulation/elements/RIME.cpp +++ b/src/simulation/elements/RIME.cpp @@ -48,12 +48,13 @@ void Element::Element_RIME() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPRK) @@ -67,5 +68,7 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = parts[ID(r)].life; } } + } + } return 0; } diff --git a/src/simulation/elements/SHLD1.cpp b/src/simulation/elements/SHLD1.cpp index 056fd1233..d45bf55eb 100644 --- a/src/simulation/elements/SHLD1.cpp +++ b/src/simulation/elements/SHLD1.cpp @@ -47,12 +47,13 @@ void Element::Element_SHLD1() static int update(UPDATE_FUNC_ARGS) { - int r, nnx, nny, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; else if (TYP(r)==PT_SPRK&&parts[i].life==0) @@ -62,8 +63,9 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(i,x,y,PT_SHLD2); parts[i].life = 7; } - for ( nnx=-1; nnx<2; nnx++) - for ( nny=-1; nny<2; nny++) + for (auto nnx = -1; nnx <= 1; nnx++) + { + for (auto nny = -1; nny <= 1; nny++) { if (!pmap[y+ry+nny][x+rx+nnx]) { @@ -71,6 +73,7 @@ static int update(UPDATE_FUNC_ARGS) //parts[ID(pmap[y+ny+nny][x+nx+nnx])].life=7; } } + } } else if (TYP(r) == PT_SHLD3 && sim->rng.chance(2, 5)) { @@ -78,5 +81,7 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 7; } } + } + } return 0; } diff --git a/src/simulation/elements/SHLD2.cpp b/src/simulation/elements/SHLD2.cpp index e1492507c..2baa6a663 100644 --- a/src/simulation/elements/SHLD2.cpp +++ b/src/simulation/elements/SHLD2.cpp @@ -47,12 +47,13 @@ void Element::Element_SHLD2() static int update(UPDATE_FUNC_ARGS) { - int r, nnx, nny, rx, ry, np; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) { if (parts[i].life>0) @@ -66,16 +67,18 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(i,x,y,PT_SHLD3); parts[i].life = 7; } - for ( nnx=-1; nnx<2; nnx++) - for ( nny=-1; nny<2; nny++) + for (auto nnx = -1; nnx <= 1; nnx++) + { + for (auto nny = -1; nny <= 1; nny++) { if (!pmap[y+ry+nny][x+rx+nnx]) { - np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + auto np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); if (np<0) continue; parts[np].life=7; } } + } } else if (TYP(r) == PT_SHLD4 && sim->rng.chance(2, 5)) { @@ -83,5 +86,7 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 7; } } + } + } return 0; } diff --git a/src/simulation/elements/SHLD3.cpp b/src/simulation/elements/SHLD3.cpp index d41ea4fec..134e4908a 100644 --- a/src/simulation/elements/SHLD3.cpp +++ b/src/simulation/elements/SHLD3.cpp @@ -47,17 +47,18 @@ void Element::Element_SHLD3() static int update(UPDATE_FUNC_ARGS) { - int r, nnx, nny, rx, ry, np; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) { if (sim->rng.chance(1, 2500)) { - np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); + auto np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); if (np<0) continue; parts[np].life=7; sim->part_change_type(i,x,y,PT_SHLD2); @@ -76,18 +77,22 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(i,x,y,PT_SHLD4); parts[i].life = 7; } - for ( nnx=-1; nnx<2; nnx++) - for ( nny=-1; nny<2; nny++) + for (auto nnx = -1; nnx <= 1; nnx++) + { + for (auto nny = -1; nny <= 1; nny++) { if (!pmap[y+ry+nny][x+rx+nnx]) { - np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + auto np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); if (np<0) continue; parts[np].life=7; } } + } } } + } + } return 0; } diff --git a/src/simulation/elements/SHLD4.cpp b/src/simulation/elements/SHLD4.cpp index 3169db74f..bb9be1850 100644 --- a/src/simulation/elements/SHLD4.cpp +++ b/src/simulation/elements/SHLD4.cpp @@ -47,17 +47,18 @@ void Element::Element_SHLD4() static int update(UPDATE_FUNC_ARGS) { - int r, nnx, nny, rx, ry, np; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) { if (sim->rng.chance(1, 5500)) { - np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); + auto np = sim->create_part(-1,x+rx,y+ry,PT_SHLD1); if (np<0) continue; parts[np].life=7; sim->part_change_type(i,x,y,PT_SHLD2); @@ -71,16 +72,22 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].life = 7; } else if (TYP(r)==PT_SPRK&&parts[i].life==0) - for ( nnx=-1; nnx<2; nnx++) - for ( nny=-1; nny<2; nny++) + { + for (auto nnx = -1; nnx <= 1; nnx++) + { + for (auto nny = -1; nny <= 1; nny++) { if (!pmap[y+ry+nny][x+rx+nnx]) { - np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); + auto np = sim->create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1); if (np<0) continue; parts[np].life=7; } } + } + } } + } + } return 0; } diff --git a/src/simulation/elements/SING.cpp b/src/simulation/elements/SING.cpp index 378527a69..fb80c51a7 100644 --- a/src/simulation/elements/SING.cpp +++ b/src/simulation/elements/SING.cpp @@ -49,9 +49,7 @@ void Element::Element_SING() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, cry, crx, spawncount; int singularity = -parts[i].life; - float angle, v; if (sim->pv[y/CELL][x/CELL]pv[y/CELL][x/CELL] += 0.1f*(singularity-sim->pv[y/CELL][x/CELL]); @@ -67,16 +65,18 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].life<1) { //Pop! - for (rx=-1; rx<2; rx++) { - crx = (x/CELL)+rx; - for (ry=-1; ry<2; ry++) { - cry = (y/CELL)+ry; + for (auto rx = -1; rx <= 1; rx++) + { + auto crx = (x/CELL)+rx; + for (auto ry = -1; ry <= 1; ry++) + { + auto cry = (y/CELL)+ry; if (cry >= 0 && crx >= 0 && crx < XCELLS && cry < YCELLS) { sim->pv[cry][crx] += (float)parts[i].tmp; } } } - spawncount = std::abs(parts[i].tmp); + auto spawncount = std::abs(parts[i].tmp); spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*TPT_PI_FLT); for (int j = 0;j < spawncount; j++) { @@ -96,8 +96,8 @@ static int update(UPDATE_FUNC_ARGS) if (nb!=-1) { parts[nb].life = sim->rng.between(0, 299); parts[nb].temp = MAX_TEMP/2; - angle = sim->rng.uniform01()*2.0f*TPT_PI_FLT; - v = sim->rng.uniform01()*5.0f; + auto angle = sim->rng.uniform01()*2.0f*TPT_PI_FLT; + auto v = sim->rng.uniform01()*5.0f; parts[nb].vx = v*cosf(angle); parts[nb].vy = v*sinf(angle); } @@ -107,11 +107,13 @@ static int update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)!=PT_DMND&& sim->rng.chance(1, 3)) @@ -141,6 +143,8 @@ static int update(UPDATE_FUNC_ARGS) sim->kill_part(ID(r)); } } + } + } return 0; } diff --git a/src/simulation/elements/SLTW.cpp b/src/simulation/elements/SLTW.cpp index 420e781a6..2a3805f23 100644 --- a/src/simulation/elements/SLTW.cpp +++ b/src/simulation/elements/SLTW.cpp @@ -47,12 +47,13 @@ void Element::Element_SLTW() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; switch (TYP(r)) { case PT_SALT: @@ -89,5 +90,7 @@ static int update(UPDATE_FUNC_ARGS) continue; } } + } + } return 0; } diff --git a/src/simulation/elements/SNOW.cpp b/src/simulation/elements/SNOW.cpp index 9745397fe..e729db65c 100644 --- a/src/simulation/elements/SNOW.cpp +++ b/src/simulation/elements/SNOW.cpp @@ -49,16 +49,17 @@ void Element::Element_SNOW() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; if (parts[i].ctype==PT_FRZW)//get colder if it is from FRZW { parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP); } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if ((TYP(r)==PT_SALT || TYP(r)==PT_SLTW) && sim->rng.chance(1, 333)) @@ -67,5 +68,7 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_SLTW); } } + } + } return 0; } diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp index e950a646d..1c335c540 100644 --- a/src/simulation/elements/SOAP.cpp +++ b/src/simulation/elements/SOAP.cpp @@ -95,9 +95,6 @@ constexpr float BLEND = 0.85f; static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, nr, ng, nb, na; - float tr, tg, tb, ta; - //0x01 - bubble on/off //0x02 - first mate yes/no //0x04 - "back" mate yes/no @@ -143,25 +140,32 @@ static int update(UPDATE_FUNC_ARGS) } if(!(parts[i].ctype&2)) { - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if ((parts[ID(r)].type == PT_SOAP) && (parts[ID(r)].ctype&1) && !(parts[ID(r)].ctype&4)) attach(parts, i, ID(r)); } + } + } } else { if (parts[i].life<=0) - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r && !sim->bmap[(y+ry)/CELL][(x+rx)/CELL]) continue; if (parts[i].temp>FREEZING) @@ -198,6 +202,9 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } + } } if(parts[i].ctype&2) { @@ -235,26 +242,30 @@ static int update(UPDATE_FUNC_ARGS) parts[i].life = 10; } } - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)!=PT_SOAP) { - tr = float((parts[ID(r)].dcolour>>16)&0xFF); - tg = float((parts[ID(r)].dcolour>>8)&0xFF); - tb = float((parts[ID(r)].dcolour)&0xFF); - ta = float((parts[ID(r)].dcolour>>24)&0xFF); - nr = int(tr*BLEND); - ng = int(tg*BLEND); - nb = int(tb*BLEND); - na = int(ta*BLEND); + auto tr = float((parts[ID(r)].dcolour>>16)&0xFF); + auto tg = float((parts[ID(r)].dcolour>>8)&0xFF); + auto tb = float((parts[ID(r)].dcolour)&0xFF); + auto ta = float((parts[ID(r)].dcolour>>24)&0xFF); + auto nr = int(tr*BLEND); + auto ng = int(tg*BLEND); + auto nb = int(tb*BLEND); + auto na = int(ta*BLEND); parts[ID(r)].dcolour = nr<<16 | ng<<8 | nb | na<<24; } } + } + } return 0; } diff --git a/src/simulation/elements/SPNG.cpp b/src/simulation/elements/SPNG.cpp index 3dcc4aa83..6523dc60d 100644 --- a/src/simulation/elements/SPNG.cpp +++ b/src/simulation/elements/SPNG.cpp @@ -49,16 +49,17 @@ void Element::Element_SPNG() static int update(UPDATE_FUNC_ARGS) { - int r, trade, rx, ry, tmp, np; int limit = 50; if (parts[i].lifepv[y/CELL][x/CELL]<=3&&sim->pv[y/CELL][x/CELL]>=-3&&parts[i].temp<=374.0f) { int absorbChanceDenom = parts[i].life*10000/limit + 500; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; switch (TYP(r)) { case PT_WATR: @@ -98,31 +99,39 @@ static int update(UPDATE_FUNC_ARGS) continue; } } + } + } } else - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if ((!r)&&parts[i].life>=1)//if nothing then create water { - np = sim->create_part(-1,x+rx,y+ry,PT_WATR); + auto np = sim->create_part(-1,x+rx,y+ry,PT_WATR); if (np>-1) parts[i].life--; } } - for ( trade = 0; trade<9; trade ++) + } + } + } + for (auto trade = 0; trade<9; trade ++) { - rx = sim->rng.between(-2, 2); - ry = sim->rng.between(-2, 2); - if (BOUNDS_CHECK && (rx || ry)) + auto rx = sim->rng.between(-2, 2); + auto ry = sim->rng.between(-2, 2); + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPNG&&(parts[i].life>parts[ID(r)].life)&&parts[i].life>0)//diffusion { - tmp = parts[i].life - parts[ID(r)].life; + auto tmp = parts[i].life - parts[ID(r)].life; if (tmp ==1) { parts[ID(r)].life ++; @@ -138,14 +147,16 @@ static int update(UPDATE_FUNC_ARGS) } } } - tmp = 0; + auto tmp = 0; if (parts[i].life>0) { - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_FIRE) @@ -157,20 +168,25 @@ static int update(UPDATE_FUNC_ARGS) parts[ID(r)].life--; } } + } + } } if (tmp && parts[i].life>3) parts[i].life -= parts[i].life/3; if (tmp>1) tmp = tmp/2; if (tmp || parts[i].temp>=374) - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if ((!r)&&parts[i].life>=1)//if nothing then create steam { - np = sim->create_part(-1,x+rx,y+ry,PT_WTRV); + auto np = sim->create_part(-1,x+rx,y+ry,PT_WTRV); if (np>-1) { parts[np].temp = parts[i].temp; @@ -180,6 +196,9 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } + } if (tmp>0) { if (parts[i].life>tmp) diff --git a/src/simulation/elements/SPRK.cpp b/src/simulation/elements/SPRK.cpp index c24c6a17e..4b43a5869 100644 --- a/src/simulation/elements/SPRK.cpp +++ b/src/simulation/elements/SPRK.cpp @@ -52,7 +52,7 @@ void Element::Element_SPRK() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, nearp, pavg, ct = parts[i].ctype, sender, receiver; + int ct = parts[i].ctype; Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS); if (parts[i].life<=0) @@ -88,7 +88,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].life==1) { int Element_ETRD_nearestSparkablePart(Simulation *sim, int targetId); - nearp = Element_ETRD_nearestSparkablePart(sim, i); + auto nearp = Element_ETRD_nearestSparkablePart(sim, i); if (nearp!=-1 && sim->parts_avg(i, nearp, PT_INSL)!=PT_INSL) { sim->CreateLine(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), PT_PLSM); @@ -116,11 +116,13 @@ static int update(UPDATE_FUNC_ARGS) case PT_TESC: if (parts[i].tmp>300) parts[i].tmp=300; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (r) continue; if (parts[i].tmp>4 && sim->rng.chance(1, parts[i].tmp*parts[i].tmp/20+6)) @@ -145,13 +147,17 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } break; case PT_IRON: - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_DSTW || TYP(r)==PT_SLTW || TYP(r)==PT_WATR) @@ -163,6 +169,8 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_H2); } } + } + } break; case PT_TUNG: if(parts[i].temp < 3595.0){ @@ -171,16 +179,18 @@ static int update(UPDATE_FUNC_ARGS) default: break; } - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - receiver = TYP(r); - sender = ct; - pavg = sim->parts_avg(ID(r), i,PT_INSL); + auto receiver = TYP(r); + auto sender = ct; + auto pavg = sim->parts_avg(ID(r), i,PT_INSL); //receiver is the element SPRK is trying to conduct to //sender is the element the SPRK is on //First, some checks usually for (de)activation of elements @@ -363,6 +373,8 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_SPRK); } } + } + } return 0; } diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index 1ef590ed5..d0af46772 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -53,16 +53,17 @@ void Element::Element_STOR() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, np, rx1, ry1; if (!sim->IsElementOrNone(parts[i].tmp)) parts[i].tmp = 0; if(parts[i].life && !parts[i].tmp) parts[i].life--; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if ((ID(r))>=NPART || !r) continue; if (!parts[i].tmp && !parts[i].life && TYP(r)!=PT_STOR && !(sim->elements[TYP(r)].Properties&TYPE_SOLID) && (!parts[i].ctype || TYP(r)==parts[i].ctype)) @@ -78,9 +79,11 @@ static int update(UPDATE_FUNC_ARGS) } if(parts[i].tmp && TYP(r)==PT_SPRK && parts[ID(r)].ctype==PT_PSCN && parts[ID(r)].life>0 && parts[ID(r)].life<4) { - for(ry1 = 1; ry1 >= -1; ry1--){ - for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscillate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1) - np = sim->create_part(-1,x+rx1,y+ry1,TYP(parts[i].tmp)); + for(auto ry1 = 1; ry1 >= -1; ry1--) + { + for(auto rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1) // Oscillate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1) + { + auto np = sim->create_part(-1,x+rx1,y+ry1,TYP(parts[i].tmp)); if (np!=-1) { parts[np].temp = parts[i].temp; @@ -95,6 +98,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/SWCH.cpp b/src/simulation/elements/SWCH.cpp index 1050ce7aa..c41525b28 100644 --- a/src/simulation/elements/SWCH.cpp +++ b/src/simulation/elements/SWCH.cpp @@ -54,18 +54,20 @@ static bool isRedBRAY(UPDATE_FUNC_ARGS, int xc, int yc) static int update(UPDATE_FUNC_ARGS) { - int r, rt, rx, ry; if (parts[i].life>0 && parts[i].life!=10) parts[i].life--; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - if (sim->parts_avg(i,ID(r),PT_INSL)!=PT_INSL) { - rt = TYP(r); + if (sim->parts_avg(i,ID(r),PT_INSL)!=PT_INSL) + { + auto rt = TYP(r); if (rt==PT_SWCH) { if (parts[i].life>=10&&parts[ID(r)].life<10&&parts[ID(r)].life>0) @@ -83,6 +85,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } //turn SWCH on/off from two red BRAYS. There must be one either above or below, and one either left or right to work, and it can't come from the side, it must be a diagonal beam if (!TYP(pmap[y-1][x-1]) && !TYP(pmap[y-1][x+1]) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y-1) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y+1)) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x+1, y) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x-1, y))) { diff --git a/src/simulation/elements/THDR.cpp b/src/simulation/elements/THDR.cpp index b420d6185..c22e7a474 100644 --- a/src/simulation/elements/THDR.cpp +++ b/src/simulation/elements/THDR.cpp @@ -50,16 +50,17 @@ void Element::Element_THDR() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rt; bool kill=false; - for (rx=-2; rx<3; rx++) - for (ry=-2; ry<3; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -2; rx <= 2; rx++) + { + for (auto ry = -2; ry <= 2; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; - rt = TYP(r); + auto rt = TYP(r); if ((sim->elements[TYP(r)].Properties&PROP_CONDUCTS) && parts[ID(r)].life==0 && !(rt==PT_WATR||rt==PT_SLTW) && parts[ID(r)].ctype!=PT_SPRK) { parts[ID(r)].ctype = parts[ID(r)].type; @@ -79,6 +80,8 @@ static int update(UPDATE_FUNC_ARGS) kill=true; } } + } + } if (kill) { sim->kill_part(i); return 1; diff --git a/src/simulation/elements/TSNS.cpp b/src/simulation/elements/TSNS.cpp index 4f84ed540..7da107e06 100644 --- a/src/simulation/elements/TSNS.cpp +++ b/src/simulation/elements/TSNS.cpp @@ -56,8 +56,10 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].life = 0; for (int rx = -2; rx <= 2; rx++) + { for (int ry = -2; ry <= 2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (!r) @@ -75,6 +77,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } bool setFilt = false; int photonWl = 0; @@ -99,16 +103,17 @@ static int update(UPDATE_FUNC_ARGS) } if (setFilt) { - int nx, ny; for (int rx = -1; rx <= 1; rx++) + { for (int ry = -1; ry <= 1; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y+ry][x+rx]; if (!r) continue; - nx = x + rx; - ny = y + ry; + auto nx = x + rx; + auto ny = y + ry; while (TYP(r) == PT_FILT) { parts[ID(r)].ctype = 0x10000000 + photonWl; @@ -119,6 +124,8 @@ static int update(UPDATE_FUNC_ARGS) r = pmap[ny][nx]; } } + } + } } return 0; } diff --git a/src/simulation/elements/TTAN.cpp b/src/simulation/elements/TTAN.cpp index 8fe4e4159..e1892d6ca 100644 --- a/src/simulation/elements/TTAN.cpp +++ b/src/simulation/elements/TTAN.cpp @@ -56,12 +56,16 @@ static int update(UPDATE_FUNC_ARGS) else if (nt <= 6) { for (int rx = -1; rx <= 1; rx++) + { for (int ry = -1; ry <= 1; ry++) - if ((!rx != !ry) && BOUNDS_CHECK) + { + if (!rx != !ry) { if (TYP(pmap[y+ry][x+rx]) == PT_TTAN) ttan++; } + } + } } if (ttan >= 2) diff --git a/src/simulation/elements/TUNG.cpp b/src/simulation/elements/TUNG.cpp index 29317aaa0..086359a1d 100644 --- a/src/simulation/elements/TUNG.cpp +++ b/src/simulation/elements/TUNG.cpp @@ -57,17 +57,20 @@ static int update(UPDATE_FUNC_ARGS) if(parts[i].temp > 2400.0) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if(TYP(r) == PT_O2) { splode = true; } } + } + } } if((parts[i].temp > MELTING_POINT && sim->rng.chance(1, 20)) || splode) { diff --git a/src/simulation/elements/VIBR.cpp b/src/simulation/elements/VIBR.cpp index 083352446..fbb6a6c96 100644 --- a/src/simulation/elements/VIBR.cpp +++ b/src/simulation/elements/VIBR.cpp @@ -50,8 +50,7 @@ void Element::Element_VIBR() int Element_VIBR_update(UPDATE_FUNC_ARGS) { - int r, rx, ry, rndstore = 0; - int trade, transfer; + int rndstore = 0; if (!parts[i].life) //if not exploding { //Heat absorption code @@ -86,10 +85,10 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) rndstore = sim->rng.gen(); if (parts[i].life < 300) { - rx = rndstore%3-1; - ry = (rndstore>>2)%3-1; + auto rx = rndstore%3-1; + auto ry = (rndstore>>2)%3-1; rndstore = rndstore >> 4; - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (TYP(r) && TYP(r) != PT_BREC && (sim->elements[TYP(r)].Properties&PROP_CONDUCTS) && !parts[ID(r)].life) { parts[ID(r)].life = 4; @@ -100,16 +99,13 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) //Release all heat if (parts[i].life < 500) { - rx = rndstore%7-3; - ry = (rndstore>>3)%7-3; - if(BOUNDS_CHECK) + auto rx = rndstore%7-3; + auto ry = (rndstore>>3)%7-3; + auto r = pmap[y+ry][x+rx]; + if (TYP(r) && TYP(r)!=PT_VIBR && TYP(r)!=PT_BVBR && sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||parts[ID(r)].life==10)) { - r = pmap[y+ry][x+rx]; - if (TYP(r) && TYP(r)!=PT_VIBR && TYP(r)!=PT_BVBR && sim->elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||parts[ID(r)].life==10)) - { - parts[ID(r)].temp += parts[i].tmp*3; - parts[i].tmp = 0; - } + parts[ID(r)].temp += parts[i].tmp*3; + parts[i].tmp = 0; } } //Explosion code @@ -145,11 +141,13 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) } } //Neighbor check loop - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (parts[i].life) @@ -187,22 +185,24 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) sim->pv[y/CELL][x/CELL] -= 1; } } - for (trade = 0; trade < 9; trade++) + } + } + for (auto trade = 0; trade < 9; trade++) { if (!(trade%2)) rndstore = sim->rng.gen(); - rx = rndstore%7-3; + auto rx = rndstore%7-3; rndstore >>= 3; - ry = rndstore%7-3; + auto ry = rndstore%7-3; rndstore >>= 3; - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (TYP(r) != PT_VIBR && TYP(r) != PT_BVBR) continue; if (parts[i].tmp > parts[ID(r)].tmp) { - transfer = parts[i].tmp - parts[ID(r)].tmp; + auto transfer = parts[i].tmp - parts[ID(r)].tmp; parts[ID(r)].tmp += transfer/2; parts[i].tmp -= transfer/2; break; diff --git a/src/simulation/elements/VINE.cpp b/src/simulation/elements/VINE.cpp index 68048c14a..857ecc8d8 100644 --- a/src/simulation/elements/VINE.cpp +++ b/src/simulation/elements/VINE.cpp @@ -52,19 +52,19 @@ void Element::Element_VINE() static int update(UPDATE_FUNC_ARGS) { - int r, np, rx, ry, rndstore = sim->rng.gen(); - rx = (rndstore % 3) - 1; + int rndstore = sim->rng.gen(); + auto rx = (rndstore % 3) - 1; rndstore >>= 2; - ry = (rndstore % 3) - 1; + auto ry = (rndstore % 3) - 1; rndstore >>= 2; - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!(rndstore % 15)) sim->part_change_type(i, x, y, PT_PLNT); else if (!r) { - np = sim->create_part(-1,x+rx,y+ry,PT_VINE); + auto np = sim->create_part(-1,x+rx,y+ry,PT_VINE); if (np<0) return 0; parts[np].temp = parts[i].temp; sim->part_change_type(i,x,y,PT_PLNT); diff --git a/src/simulation/elements/VIRS.cpp b/src/simulation/elements/VIRS.cpp index 4c01f0838..bd185d225 100644 --- a/src/simulation/elements/VIRS.cpp +++ b/src/simulation/elements/VIRS.cpp @@ -55,7 +55,7 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) { //tmp3 measures how many frames until it is cured (0 if still actively spreading and not being cured) //tmp4 measures how many frames until it dies - int r, rx, ry, rndstore = sim->rng.gen(); + int rndstore = sim->rng.gen(); if (parts[i].tmp3) { parts[i].tmp3 -= (rndstore & 0x1) ? 0:1; @@ -81,12 +81,13 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) rndstore >>= 3; } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; @@ -142,6 +143,7 @@ int Element_VIRS_update(UPDATE_FUNC_ARGS) else if (!rx && !ry) rndstore = sim->rng.gen(); } + } return 0; } diff --git a/src/simulation/elements/VSNS.cpp b/src/simulation/elements/VSNS.cpp index f4b8eccd5..2b54de686 100644 --- a/src/simulation/elements/VSNS.cpp +++ b/src/simulation/elements/VSNS.cpp @@ -56,8 +56,10 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].life = 0; for (int rx = -2; rx <= 2; rx++) + { for (int ry = -2; ry <= 2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r) @@ -73,6 +75,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } } bool doSerialization = false; bool doDeserialization = false; @@ -126,8 +130,10 @@ static int update(UPDATE_FUNC_ARGS) } for (int rx = -1; rx <= 1; rx++) + { for (int ry = -1; ry <= 1; ry++) - if (BOUNDS_CHECK && (rx || ry)) + { + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r) @@ -166,6 +172,8 @@ static int update(UPDATE_FUNC_ARGS) } } } + } + } return 0; } diff --git a/src/simulation/elements/WARP.cpp b/src/simulation/elements/WARP.cpp index 311566ce7..623f9fb6d 100644 --- a/src/simulation/elements/WARP.cpp +++ b/src/simulation/elements/WARP.cpp @@ -62,7 +62,7 @@ static int update(UPDATE_FUNC_ARGS) { int rx = sim->rng.between(-1, 1); int ry = sim->rng.between(-1, 1); - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { int r = pmap[y + ry][x + rx]; if (!r) diff --git a/src/simulation/elements/WATR.cpp b/src/simulation/elements/WATR.cpp index 1ed233189..2e82c5e06 100644 --- a/src/simulation/elements/WATR.cpp +++ b/src/simulation/elements/WATR.cpp @@ -48,12 +48,13 @@ void Element::Element_WATR() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SALT && sim->rng.chance(1, 50)) @@ -90,5 +91,7 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_STNE); } } + } + } return 0; } diff --git a/src/simulation/elements/WIFI.cpp b/src/simulation/elements/WIFI.cpp index 55f692a46..6caffe140 100644 --- a/src/simulation/elements/WIFI.cpp +++ b/src/simulation/elements/WIFI.cpp @@ -49,15 +49,16 @@ void Element::Element_WIFI() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; else if (parts[i].tmp<0) parts[i].tmp = 0; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; // wireless[][0] - whether channel is active on this frame @@ -77,6 +78,8 @@ static int update(UPDATE_FUNC_ARGS) sim->ISWIRE = 2; } } + } + } return 0; } diff --git a/src/simulation/elements/WIRE.cpp b/src/simulation/elements/WIRE.cpp index 4d2653150..94b5b5e46 100644 --- a/src/simulation/elements/WIRE.cpp +++ b/src/simulation/elements/WIRE.cpp @@ -49,7 +49,7 @@ void Element::Element_WIRE() static int update(UPDATE_FUNC_ARGS) { - int r,rx,ry,count=0; + int count=0; /* 0: wire 1: spark head @@ -67,12 +67,13 @@ static int update(UPDATE_FUNC_ARGS) { parts[i].ctype=0; } - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) { - if (BOUNDS_CHECK && (rx || ry)) + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_SPRK && parts[ID(r)].life==3 && parts[ID(r)].ctype==PT_PSCN) @@ -86,6 +87,7 @@ static int update(UPDATE_FUNC_ARGS) count++; } } + } if (count==1 || count==2) parts[i].ctype=1; return 0; diff --git a/src/simulation/elements/WTRV.cpp b/src/simulation/elements/WTRV.cpp index 94df68002..3461db707 100644 --- a/src/simulation/elements/WTRV.cpp +++ b/src/simulation/elements/WTRV.cpp @@ -48,12 +48,13 @@ void Element::Element_WTRV() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto 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) && sim->rng.chance(1, 100)) @@ -63,6 +64,8 @@ static int update(UPDATE_FUNC_ARGS) parts[i].ctype = PT_WATR; } } + } + } if(parts[i].temp>1273&&parts[i].ctype==PT_FIRE) parts[i].temp-=parts[i].temp/1000; return 0; diff --git a/src/simulation/elements/YEST.cpp b/src/simulation/elements/YEST.cpp index c6bf2e53a..662fd3e82 100644 --- a/src/simulation/elements/YEST.cpp +++ b/src/simulation/elements/YEST.cpp @@ -47,12 +47,13 @@ void Element::Element_YEST() static int update(UPDATE_FUNC_ARGS) { - int r, rx, ry; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) - if (BOUNDS_CHECK && (rx || ry)) + for (auto rx = -1; rx <= 1; rx++) + { + for (auto ry = -1; ry <= 1; ry++) + { + if (rx || ry) { - r = pmap[y+ry][x+rx]; + auto r = pmap[y+ry][x+rx]; if (!r) continue; if (TYP(r)==PT_DYST && sim->rng.chance(1, 6) && !sim->legacy_enable) @@ -60,6 +61,8 @@ static int update(UPDATE_FUNC_ARGS) sim->part_change_type(i,x,y,PT_DYST); } } + } + } if (parts[i].temp > 303 && parts[i].temp < 317) { sim->create_part(-1, x + sim->rng.between(-1, 1), y + sim->rng.between(-1, 1), PT_YEST); }