From 27e3e1251837f5d64e835068d5f5bd5b67b95921 Mon Sep 17 00:00:00 2001 From: cracker64 Date: Wed, 27 Feb 2013 00:11:23 -0500 Subject: [PATCH] Small optimizations number 2. --- src/simulation/elements/CLST.cpp | 8 +-- src/simulation/elements/CO2.cpp | 35 ++++++----- src/simulation/elements/DEST.cpp | 26 +++----- src/simulation/elements/DLAY.cpp | 57 ++++++++--------- src/simulation/elements/DMG.cpp | 2 +- src/simulation/elements/DSTW.cpp | 25 ++++---- src/simulation/elements/DTEC.cpp | 4 +- src/simulation/elements/ELEC.cpp | 26 ++++---- src/simulation/elements/EMP.cpp | 45 ++++++------- src/simulation/elements/EXOT.cpp | 34 +++++----- src/simulation/elements/FIGH.cpp | 105 ++++++++++++++----------------- src/simulation/elements/FIRE.cpp | 36 +++++------ src/simulation/elements/FIRW.cpp | 6 +- src/simulation/elements/FOG.cpp | 4 +- src/simulation/elements/FRZW.cpp | 12 +--- src/simulation/elements/FRZZ.cpp | 11 ++-- src/simulation/elements/FSEP.cpp | 17 +++-- src/simulation/elements/FUSE.cpp | 24 +++---- src/simulation/elements/FWRK.cpp | 6 +- 19 files changed, 211 insertions(+), 272 deletions(-) diff --git a/src/simulation/elements/CLST.cpp b/src/simulation/elements/CLST.cpp index ab62acb10..5a9d79f6a 100644 --- a/src/simulation/elements/CLST.cpp +++ b/src/simulation/elements/CLST.cpp @@ -72,11 +72,11 @@ int Element_CLST::update(UPDATE_FUNC_ARGS) { if(parts[i].temp <195) cxy = 0.05; - if(parts[i].temp >= 195 && parts[i].temp <295) + else if(parts[i].temp >= 195 && parts[i].temp <295) cxy = 0.015; - if(parts[i].temp >= 295 && parts[i].temp <350) + else if(parts[i].temp >= 295 && parts[i].temp <350) cxy = 0.01; - if(parts[i].temp >= 350) + else cxy = 0.005; parts[i].vx += cxy*rx; parts[i].vy += cxy*ry;//These two can be set not to calculate over 350 later. They do virtually nothing over 0.005. @@ -98,4 +98,4 @@ int Element_CLST::graphics(GRAPHICS_FUNC_ARGS) } -Element_CLST::~Element_CLST() {} \ No newline at end of file +Element_CLST::~Element_CLST() {} diff --git a/src/simulation/elements/CO2.cpp b/src/simulation/elements/CO2.cpp index 49614fbad..c4e6a9ae8 100644 --- a/src/simulation/elements/CO2.cpp +++ b/src/simulation/elements/CO2.cpp @@ -55,47 +55,48 @@ int Element_CO2::update(UPDATE_FUNC_ARGS) if (x+rx>=0 && y+ry>0 && x+rx(rand()%40000)) - { - if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0) - parts[i].ctype = 0; - } - if ((r>>8)>=NPART || !r) + if (!r) continue; if ((r&0xFF)==PT_FIRE){ sim->kill_part(r>>8); - if(1>(rand()%150)){ - sim->kill_part(i); - return 1; - } + if(!(rand()%150)){ + sim->kill_part(i); + return 1; + } } - if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%250)) + if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && !(rand()%250)) { sim->part_change_type(r>>8, x+rx, y+ry, PT_CBNW); if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet sim->create_part(i, x, y, PT_WATR); else + { sim->kill_part(i); + return 1; + } } } + if (parts[i].ctype==5 && !(rand()%83)) + { + if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0) + parts[i].ctype = 0; + } if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f) { - if (rand()%5 < 1) + if (!(rand()%5)) { int j; sim->create_part(i,x,y,PT_O2); - j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) - parts[j].temp = 15000; + parts[j].temp = MAX_TEMP; if (!(rand()%50)) { j = sim->create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) - parts[j].temp = 15000; + parts[j].temp = MAX_TEMP; } - - parts[i].temp = 15000; + parts[i].temp = MAX_TEMP; sim->pv[y/CELL][x/CELL] += 100; } } diff --git a/src/simulation/elements/DEST.cpp b/src/simulation/elements/DEST.cpp index a4f789154..303633155 100644 --- a/src/simulation/elements/DEST.cpp +++ b/src/simulation/elements/DEST.cpp @@ -60,19 +60,15 @@ int Element_DEST::update(UPDATE_FUNC_ARGS) if (parts[i].life<=0 || parts[i].life>37) { parts[i].life=30+rand()%20; - parts[i].temp+=20000; sim->pv[y/CELL][x/CELL]+=60.0f; } - parts[i].temp+=10000; if ((r&0xFF)==PT_PLUT || (r&0xFF)==PT_DEUT) { sim->pv[y/CELL][x/CELL]+=20.0f; - parts[i].temp+=18000; - if (rand()%2==0) + if (rand()%2) { - float orig_temp = parts[r>>8].temp; sim->create_part(r>>8, x+rx, y+ry, PT_NEUT); - parts[r>>8].temp = restrict_flt(orig_temp+40000.0f, MIN_TEMP, MAX_TEMP); + parts[r>>8].temp = MAX_TEMP; sim->pv[y/CELL][x/CELL] += 10.0f; parts[i].life-=4; } @@ -81,23 +77,17 @@ int Element_DEST::update(UPDATE_FUNC_ARGS) { sim->create_part(r>>8, x+rx, y+ry, PT_PLSM); } - else if (rand()%3==0) + else if (!rand()%3) { sim->kill_part(r>>8); parts[i].life -= 4*((sim->elements[r&0xFF].Properties&TYPE_SOLID)?3:1); if (parts[i].life<=0) parts[i].life=1; - parts[i].temp+=10000; } - else - { - if (sim->elements[r&0xFF].HeatConduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+10000.0f, MIN_TEMP, MAX_TEMP); - } - topv=sim->pv[y/CELL][x/CELL]/9+parts[r>>8].temp/900; - if (topv>40.0f) - topv=40.0f; - sim->pv[y/CELL][x/CELL]+=40.0f+topv; - parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP); + else if (sim->elements[r&0xFF].HeatConduct) + parts[r>>8].temp = MAX_TEMP; + parts[i].temp=MAX_TEMP; + sim->pv[y/CELL][x/CELL]+=80.0f; return 0; } @@ -118,4 +108,4 @@ int Element_DEST::graphics(GRAPHICS_FUNC_ARGS) } -Element_DEST::~Element_DEST() {} \ No newline at end of file +Element_DEST::~Element_DEST() {} diff --git a/src/simulation/elements/DLAY.cpp b/src/simulation/elements/DLAY.cpp index e69c2020c..1bce99925 100644 --- a/src/simulation/elements/DLAY.cpp +++ b/src/simulation/elements/DLAY.cpp @@ -53,44 +53,39 @@ int Element_DLAY::update(UPDATE_FUNC_ARGS) oldl = parts[i].life; if (parts[i].life>0) parts[i].life--; - //if (parts[i].life==1) - //{ - if (parts[i].temp>=MAX_TEMP+273.15f) - parts[i].temp = MAX_TEMP+273.15f; 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 (x+rx>=0 && y+ry>0 && x+rx=0 && y+ry>0 && x+rxparts_avg(r>>8, i,PT_INSL)==PT_INSL) + continue; + if ((r&0xFF)==PT_SPRK && parts[i].life==0 && parts[r>>8].life>0 && parts[r>>8].life<4 && parts[r>>8].ctype==PT_PSCN) { - r = pmap[y+ry][x+rx]; - if (!r || sim->parts_avg(r>>8, i,PT_INSL)==PT_INSL) - continue; - if ((r&0xFF)==PT_SPRK && parts[i].life==0 && parts[r>>8].life>0 && parts[r>>8].life<4 && parts[r>>8].ctype==PT_PSCN) + parts[i].life = (int)(parts[i].temp-273.15); + } + else if ((r&0xFF)==PT_DLAY) + { + if(!parts[i].life && parts[r>>8].life) { - parts[i].life = (int)(parts[i].temp-273.15); + parts[i].life = parts[r>>8].life; + if((r>>8)>i) //If the other particle hasn't been life updated + parts[i].life--; } - else if ((r&0xFF)==PT_DLAY) + else if(parts[i].life && !parts[r>>8].life) { - if(!parts[i].life && parts[r>>8].life) - { - parts[i].life = parts[r>>8].life; - if((r>>8)>i) //If the other particle hasn't been life updated - parts[i].life--; - } - else if(parts[i].life && !parts[r>>8].life) - { - parts[r>>8].life = parts[i].life; - if((r>>8)>i) //If the other particle hasn't been life updated - parts[r>>8].life++; - } - } - else if((r&0xFF)==PT_NSCN && oldl==1) - { - sim->create_part(-1, x+rx, y+ry, PT_SPRK); + parts[r>>8].life = parts[i].life; + if((r>>8)>i) //If the other particle hasn't been life updated + parts[r>>8].life++; } } + else if((r&0xFF)==PT_NSCN && oldl==1) + { + sim->create_part(-1, x+rx, y+ry, PT_SPRK); + } + } //} return 0; } @@ -108,4 +103,4 @@ int Element_DLAY::graphics(GRAPHICS_FUNC_ARGS) } -Element_DLAY::~Element_DLAY() {} \ No newline at end of file +Element_DLAY::~Element_DLAY() {} diff --git a/src/simulation/elements/DMG.cpp b/src/simulation/elements/DMG.cpp index 9c19199d3..b89db1cfe 100644 --- a/src/simulation/elements/DMG.cpp +++ b/src/simulation/elements/DMG.cpp @@ -85,7 +85,7 @@ int Element_DMG::update(UPDATE_FUNC_ARGS) sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 1.0f; - t = parts[rr>>8].type; + t = rr&0xFF; if(t && sim->elements[t].HighPressureTransition>-1 && sim->elements[t].HighPressureTransitionpart_change_type(rr>>8, x+nxi, y+nxj, sim->elements[t].HighPressureTransition); else if(t == PT_BMTL) diff --git a/src/simulation/elements/DSTW.cpp b/src/simulation/elements/DSTW.cpp index 8b1610781..970dbb20a 100644 --- a/src/simulation/elements/DSTW.cpp +++ b/src/simulation/elements/DSTW.cpp @@ -49,7 +49,7 @@ Element_DSTW::Element_DSTW() //#TPT-Directive ElementHeader Element_DSTW static int update(UPDATE_FUNC_ARGS) int Element_DSTW::update(UPDATE_FUNC_ARGS) { - int r, rx, ry; + int r, rx, ry, rt; for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) if (x+rx>=0 && y+ry>0 && x+rx(rand()%250)) + rt = r&0xFF; + if (rt==PT_SALT && !(rand()%250)) { sim->part_change_type(i,x,y,PT_SLTW); // on average, convert 3 DSTW to SLTW before SALT turns into SLTW - if (rand()%3==0) + if (!rand()%3) sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW); } - if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && 1>(rand()%500)) + if ((rt==PT_WATR||rt==PT_SLTW) && !(rand()%500)) { sim->part_change_type(i,x,y,PT_WATR); } - if ((r&0xFF)==PT_SLTW && 1>(rand()%10000)) + if (rt==PT_SLTW && !(rand()%10000)) { sim->part_change_type(i,x,y,PT_SLTW); } - if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>12.0f) && 1>(rand()%500)) + if ((rt==PT_RBDM||rt==PT_LRBD) && (sim->legacy_enable||parts[i].temp>12.0f) && !(rand()%500)) { sim->part_change_type(i,x,y,PT_FIRE); parts[i].life = 4; } - if ((r&0xFF)==PT_FIRE){ + if (rt==PT_FIRE){ sim->kill_part(r>>8); - if(1>(rand()%150)){ - sim->kill_part(i); - return 1; - } + if(!(rand()%150)){ + sim->kill_part(i); + return 1; + } } } return 0; } -Element_DSTW::~Element_DSTW() {} \ No newline at end of file +Element_DSTW::~Element_DSTW() {} diff --git a/src/simulation/elements/DTEC.cpp b/src/simulation/elements/DTEC.cpp index 3fec02345..5d0c68e4d 100644 --- a/src/simulation/elements/DTEC.cpp +++ b/src/simulation/elements/DTEC.cpp @@ -61,7 +61,7 @@ int Element_DTEC::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - rt = parts[r>>8].type; + rt = r&0xFF; if (sim->parts_avg(i,r>>8,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[r>>8].life==0) @@ -82,7 +82,7 @@ int Element_DTEC::update(UPDATE_FUNC_ARGS) r = sim->photons[y+ry][x+rx]; if(!r) continue; - if (parts[r>>8].type == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[r>>8].ctype || !parts[i].tmp)) + if ((r&0xFF) == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[r>>8].ctype || !parts[i].tmp)) parts[i].life = 1; } return 0; diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp index c602da889..307c6ad50 100644 --- a/src/simulation/elements/ELEC.cpp +++ b/src/simulation/elements/ELEC.cpp @@ -53,7 +53,7 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS) float rr, rrr; parts[i].pavg[0] = x; parts[i].pavg[1] = y; - if(pmap[y][x]==PT_GLOW) + if(pmap[y][x]==PT_GLOW)//move into movement code { sim->part_change_type(i, x, y, PT_PHOT); } @@ -65,7 +65,8 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS) r = sim->photons[y+ry][x+rx]; if (!r) continue; - if ((r&0xFF)==PT_GLAS) + rt = r&0xFF; + if (rt==PT_GLAS) { for (rrx=-1; rrx<=1; rrx++) { @@ -95,30 +96,25 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } - if ((r&0xFF)==PT_LCRY) + if (rt==PT_LCRY) { parts[r>>8].tmp2 = 5+rand()%5; } - if ((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW || (r&0xFF)==PT_CBNW) + if (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW || rt==PT_CBNW) { - if(rand()create_part(r>>8, x+rx, y+ry, PT_O2); - return 1; - } else - { sim->create_part(r>>8, x+rx, y+ry, PT_H2); - return 1; - } + return 1; } - if ((r&0xFF)==PT_NEUT && !pmap[y+ry][x+rx]) + if (rt==PT_NEUT) { sim->part_change_type(r>>8, x+rx, y+ry, PT_H2); parts[r>>8].life = 0; parts[r>>8].ctype = 0; } - if ((r&0xFF)==PT_DEUT) + if (rt==PT_DEUT) { if(parts[r>>8].life < 6000) parts[r>>8].life += 1; @@ -126,12 +122,12 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } - if ((r&0xFF)==PT_EXOT) + if (rt==PT_EXOT) { parts[r>>8].tmp2 += 5; parts[r>>8].life = 1000; } - if ((sim->elements[r&0xFF].Properties & PROP_CONDUCTS) && ((r&0xFF)!=PT_NBLE||parts[i].temp<2273.15)) + 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); diff --git a/src/simulation/elements/EMP.cpp b/src/simulation/elements/EMP.cpp index e21f69c95..a09ad2625 100644 --- a/src/simulation/elements/EMP.cpp +++ b/src/simulation/elements/EMP.cpp @@ -60,13 +60,10 @@ int Element_EMP::update(UPDATE_FUNC_ARGS) if (!r) continue; if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4) - { - ok=1; - break; - } + goto ok; } - if (!ok) - return 0; + return 0; + ok: parts[i].life=220; sim->emp_decor += 3; if (sim->emp_decor > 40) @@ -83,11 +80,11 @@ int Element_EMP::update(UPDATE_FUNC_ARGS) parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH) { is_elec=1; - if (sim->elements[parts[r].type].HeatConduct && rand()%100==0) + if (sim->elements[parts[r].type].HeatConduct && !(rand()%100)) parts[r].temp = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP); - if (rand()%80==0) + if (!(rand()%80)) sim->part_change_type(r, rx, ry, PT_BREC); - else if (rand()%120==0) + else if (!(rand()%120)) sim->part_change_type(r, rx, ry, PT_NTCT); } @@ -98,55 +95,49 @@ int Element_EMP::update(UPDATE_FUNC_ARGS) n = pmap[ry+ny][rx+nx]; if (!n) continue; - /*if ((n&0xFF)==PT_BTRY && rand()%60==0) - { - part_change_type(n>>8, rx+nx, ry+ny, PT_PLSM); - parts[n>>8].life=rand()%100+70; - parts[n>>8].temp+=3000; - }*/ - + nt = n&0xFF; //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor //So not affected by spark on metl, watr etc if (is_elec) { - if (((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0) + if ((nt==PT_METL || nt==PT_BMTL) && !(rand()%280)) { parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP); } - if ((n&0xFF)==PT_BMTL && rand()%160==0) + if (nt==PT_BMTL && !(rand()%160)) { - sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);//TODO: Redundant, was this meant to be BRMT or something? + sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BRMT); parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); } - if ((n&0xFF)==PT_METL && rand()%300==0) + if (nt==PT_METL && !(rand()%300)) { sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL); } - if ((n&0xFF)==PT_WIFI && rand()%8==0) + if (nt==PT_WIFI && !(rand()%8)) { //Randomise channel parts[n>>8].temp = rand()%MAX_TEMP; } - if ((n&0xFF)==PT_WIFI && rand()%16==0) + if (nt==PT_WIFI && !(rand()%16)) { sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC); parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); } } - if ((n&0xFF)==PT_SWCH && rand()%100==0) + if (nt==PT_SWCH && !(rand()%100)) { sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BREC); } - if ((n&0xFF)==PT_SWCH && rand()%100==0) + if (nt==PT_SWCH && !(rand()%100)) { parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP); } - if ((n&0xFF)==PT_ARAY && rand()%60==0) + if (nt==PT_ARAY && !(rand()%60)) { sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC); parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP); } - if (t==PT_DLAY && rand()%70==0) + if (nt==PT_DLAY && !(rand()%70)) { //Randomise delay parts[n>>8].temp = (rand()%256) + 273.15f; @@ -180,4 +171,4 @@ int Element_EMP::graphics(GRAPHICS_FUNC_ARGS) } -Element_EMP::~Element_EMP() {} \ No newline at end of file +Element_EMP::~Element_EMP() {} diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index 03eca2f13..8cf0161f5 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -48,42 +48,36 @@ Element_EXOT::Element_EXOT() //#TPT-Directive ElementHeader Element_EXOT static int update(UPDATE_FUNC_ARGS) int Element_EXOT::update(UPDATE_FUNC_ARGS) { - int r, rt, rx, ry, nb, rrx, rry, trade, tym, t; - t = parts[i].type; + int r, rt, rx, ry, nb, rrx, rry, trade, tym; for (rx=-2; rx<=2; rx++) for (ry=-2; ry<=2; ry++) - if (x+rx>=0 && y+ry>=0 && x+rx=0 && y+ry>=0 && x+rx>8].tmp2>2000) - if (1>rand()%100) - { - parts[i].tmp2 += 100; - } + if (parts[r>>8].tmp2>2000 && !(rand()%100)) + { + parts[i].tmp2 += 100; + } } - else if ((r&0xFF) == PT_EXOT && parts[r>>8].life == 1500 && 1>rand()%1000) + else if (rt == PT_EXOT && parts[r>>8].life == 1500 && !(rand()%1000)) parts[i].life = 1500; - else if ((r&0xFF) == PT_LAVA) + else if (rt == PT_LAVA) { - if (parts[r>>8].ctype == PT_TTAN && 1>rand()%10) + if (parts[r>>8].ctype == PT_TTAN && !(rand()%10)) { parts[r>>8].ctype = PT_VIBR; sim->kill_part(i); return 1; } - /*else if (parts[r>>8].ctype == PT_VIBR && 1>rand()%1000) - { - sim->kill_part(i); - return 1; - }*/ } if ((parts[i].tmp>245) && (parts[i].life>1000)) - if ((r&0xFF)!=PT_EXOT && (r&0xFF)!=PT_BREC && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_NBHL && (r&0xFF)!=PT_WARP && (r&0xFF)!=PT_NEUT) + if (rt!=PT_EXOT && rt!=PT_BREC && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PRTI && rt!=PT_PRTO && rt!=PT_PCLN && rt!=PT_PHOT && rt!=PT_VOID && rt!=PT_NBHL && rt!=PT_WARP && rt!=PT_NEUT) { - sim->create_part(i, x, y, parts[r>>8].type); + sim->create_part(i, x, y, rt); return 0; } } @@ -121,7 +115,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS) { r = pmap[y+ry][x+rx]; if (!r) continue; - if ((r&0xFF)==t && (parts[i].tmp2>parts[r>>8].tmp2) && parts[r>>8].tmp2>=0 )//diffusion + if ((r&0xFF)==PT_EXOT && (parts[i].tmp2>parts[r>>8].tmp2) && parts[r>>8].tmp2>=0 )//diffusion { tym = parts[i].tmp2 - parts[r>>8].tmp2; if (tym ==1) diff --git a/src/simulation/elements/FIGH.cpp b/src/simulation/elements/FIGH.cpp index 66be5bdaf..e1072f2bf 100644 --- a/src/simulation/elements/FIGH.cpp +++ b/src/simulation/elements/FIGH.cpp @@ -48,7 +48,6 @@ Element_FIGH::Element_FIGH() //#TPT-Directive ElementHeader Element_FIGH static int update(UPDATE_FUNC_ARGS) int Element_FIGH::update(UPDATE_FUNC_ARGS) - { playerst* figh = &sim->fighters[(unsigned char)parts[i].tmp]; @@ -57,78 +56,68 @@ int Element_FIGH::update(UPDATE_FUNC_ARGS) parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man //Set target cords - if (sim->player.spwn && sim->player2.spwn) + if (sim->player2.spwn) { - if ((pow((float)sim->player.legs[2]-x, 2) + pow((float)sim->player.legs[3]-y, 2))<= - (pow((float)sim->player2.legs[2]-x, 2) + pow((float)sim->player2.legs[3]-y, 2))) - { - tarx = (unsigned int)sim->player.legs[2]; - tary = (unsigned int)sim->player.legs[3]; - } - else - { - tarx = (unsigned int)sim->player2.legs[2]; - tary = (unsigned int)sim->player2.legs[3]; - } - parts[i].tmp2 = 1; - } - else - { - if (sim->player.spwn) + if (sim->player.spwn && (pow((float)sim->player.legs[2]-x, 2) + pow((float)sim->player.legs[3]-y, 2))<= + (pow((float)sim->player2.legs[2]-x, 2) + pow((float)sim->player2.legs[3]-y, 2))) { tarx = (unsigned int)sim->player.legs[2]; tary = (unsigned int)sim->player.legs[3]; - parts[i].tmp2 = 1; } - if (sim->player2.spwn) + else { tarx = (unsigned int)sim->player2.legs[2]; tary = (unsigned int)sim->player2.legs[3]; - parts[i].tmp2 = 1; } + parts[i].tmp2 = 1; + } + else if (sim->player.spwn) + { + tarx = (unsigned int)sim->player.legs[2]; + tary = (unsigned int)sim->player.legs[3]; + parts[i].tmp2 = 1; } switch (parts[i].tmp2) { - case 1: - if ((pow(float(tarx-x), 2) + pow(float(tary-y), 2))<600) - { - if (figh->elem == PT_LIGH || figh->elem == PT_NEUT - || sim->elements[figh->elem].Properties&(PROP_DEADLY|PROP_RADIOACTIVE) - || sim->elements[figh->elem].Temperature>=323 || sim->elements[figh->elem].Temperature<=243) - figh->comm = (int)figh->comm | 0x08; - } + case 1: + if ((pow(float(tarx-x), 2) + pow(float(tary-y), 2))<600) + { + if (figh->elem == PT_LIGH || figh->elem == PT_NEUT + || sim->elements[figh->elem].Properties&(PROP_DEADLY|PROP_RADIOACTIVE) + || sim->elements[figh->elem].Temperature>=323 || sim->elements[figh->elem].Temperature<=243) + figh->comm = (int)figh->comm | 0x08; + } + else if (tarxeval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+6, NULL) + && sim->eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+3, NULL))) + figh->comm = 0x01; else - if (tarxeval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+6, NULL) - && sim->eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+3, NULL))) - figh->comm = 0x01; - else - figh->comm = 0x02; + figh->comm = 0x02; - if (!sim->eval_move(PT_FIGH, figh->legs[4]-4, figh->legs[5]-1, NULL) - || !sim->eval_move(PT_FIGH, figh->legs[12]-4, figh->legs[13]-1, NULL) - || sim->eval_move(PT_FIGH, 2*figh->legs[4]-figh->legs[6], figh->legs[5]+5, NULL)) - figh->comm = (int)figh->comm | 0x04; - } - else - { - if (!(sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+6, NULL) - && sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+3, NULL))) - figh->comm = 0x02; - else - figh->comm = 0x01; + if (!sim->eval_move(PT_FIGH, figh->legs[4]-4, figh->legs[5]-1, NULL) + || !sim->eval_move(PT_FIGH, figh->legs[12]-4, figh->legs[13]-1, NULL) + || sim->eval_move(PT_FIGH, 2*figh->legs[4]-figh->legs[6], figh->legs[5]+5, NULL)) + figh->comm = (int)figh->comm | 0x04; + } + else + { + if (!(sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+6, NULL) + && sim->eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+3, NULL))) + figh->comm = 0x02; + else + figh->comm = 0x01; - if (!sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) - || !sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) - || sim->eval_move(PT_FIGH, 2*figh->legs[12]-figh->legs[14], figh->legs[13]+5, NULL)) - figh->comm = (int)figh->comm | 0x04; - } - break; - default: - figh->comm = 0; - break; + if (!sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) + || !sim->eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL) + || sim->eval_move(PT_FIGH, 2*figh->legs[12]-figh->legs[14], figh->legs[13]+5, NULL)) + figh->comm = (int)figh->comm | 0x04; + } + break; + default: + figh->comm = 0; + break; } figh->pcomm = figh->comm; @@ -137,4 +126,4 @@ int Element_FIGH::update(UPDATE_FUNC_ARGS) return 0; } -Element_FIGH::~Element_FIGH() {} \ No newline at end of file +Element_FIGH::~Element_FIGH() {} diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index f9313fa97..9a9334fda 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -50,32 +50,28 @@ Element_FIRE::Element_FIRE() int Element_FIRE::update(UPDATE_FUNC_ARGS) { int r, rx, ry, rt, t = parts[i].type; - if (t==PT_PLSM&&parts[i].ctype == PT_NBLE&&parts[i].life <=1) + if (t==PT_PLSM && parts[i].ctype == PT_NBLE && parts[i].life <=1) { - t = PT_NBLE; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,PT_NBLE); parts[i].life = 0; } - if(t==PT_FIRE && parts[i].life <=1) + if (t==PT_FIRE && parts[i].life <=1) { if ((parts[i].tmp&0x3) == 3){ - t = PT_DSTW; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,PT_DSTW); parts[i].life = 0; parts[i].ctype = PT_FIRE; } else if (parts[i].temp<625) { - t = PT_SMKE; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,PT_SMKE); parts[i].life = rand()%20+250; } } - if(t==PT_PLSM && parts[i].life <=1) + if (t==PT_PLSM && parts[i].life <=1) { if ((parts[i].tmp&0x3) == 3){ - t = PT_DSTW; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,PT_DSTW); parts[i].life = 0; parts[i].ctype = PT_FIRE; } @@ -89,7 +85,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) continue; if (sim->bmap[(y+ry)/CELL][(x+rx)/CELL] && sim->bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM) continue; - rt = parts[r>>8].type; + rt = r&0xFF; if ((surround_space || sim->elements[rt].Explosive) && (t!=PT_SPRK || (rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL)) && (t!=PT_PHOT || rt!=PT_INSL) && @@ -123,12 +119,11 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { rt = r&0xFF; lpv = (int)sim->pv[(y+ry)/CELL][(x+rx)/CELL]; if (lpv < 1) lpv = 1; - if (t!=PT_SPRK && sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) && - sim->elements[rt].Meltable*lpv>(rand()%1000)) + if (t!=PT_SPRK && sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) &&sim->elements[rt].Meltable*lpv>(rand()%1000)) { if (t!=PT_LAVA || parts[i].life>0) { - parts[r>>8].ctype = (rt==PT_BRMT)?PT_BMTL:parts[r>>8].type; + parts[r>>8].ctype = (rt==PT_BRMT)?PT_BMTL:(r&0xFF); parts[r>>8].ctype = (parts[r>>8].ctype==PT_SAND)?PT_GLAS:parts[r>>8].ctype; sim->part_change_type(r>>8,x+rx,y+ry,PT_LAVA); parts[r>>8].life = rand()%120+240; @@ -136,9 +131,8 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { else { parts[i].life = 0; - t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE; parts[i].ctype = PT_NONE;//rt; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,(parts[i].ctype)?parts[i].ctype:PT_STNE); return 1; } } @@ -153,8 +147,7 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { if (t==PT_LAVA) { parts[i].life = 0; - t = parts[i].type = PT_STNE; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,PT_STNE); } } if (t!=PT_SPRK && (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW)) @@ -168,9 +161,8 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { if (t==PT_LAVA) { parts[i].life = 0; - t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE; parts[i].ctype = PT_NONE; - sim->part_change_type(i,x,y,t); + sim->part_change_type(i,x,y,(parts[i].ctype)?parts[i].ctype:PT_STNE); } } } @@ -198,4 +190,4 @@ int Element_FIRE::graphics(GRAPHICS_FUNC_ARGS) return 0; } -Element_FIRE::~Element_FIRE() {} \ No newline at end of file +Element_FIRE::~Element_FIRE() {} diff --git a/src/simulation/elements/FIRW.cpp b/src/simulation/elements/FIRW.cpp index bc047df21..3863c94c8 100644 --- a/src/simulation/elements/FIRW.cpp +++ b/src/simulation/elements/FIRW.cpp @@ -62,7 +62,7 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - rt = parts[r>>8].type; + rt = r&0xFF; if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR) { float gx, gy, multiplier; @@ -89,7 +89,7 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS) parts[i].flags &= ~FLAG_STAGNANT; } } - else if (parts[i].tmp>=2) + else //if (parts[i].tmp>=2) { float angle, magnitude; int caddress = (rand()%200)*3; @@ -131,4 +131,4 @@ int Element_FIRW::graphics(GRAPHICS_FUNC_ARGS) } -Element_FIRW::~Element_FIRW() {} \ No newline at end of file +Element_FIRW::~Element_FIRW() {} diff --git a/src/simulation/elements/FOG.cpp b/src/simulation/elements/FOG.cpp index 9cfbe62f0..e2aae3c72 100644 --- a/src/simulation/elements/FOG.cpp +++ b/src/simulation/elements/FOG.cpp @@ -57,7 +57,7 @@ int Element_FOG::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (sim->elements[r&0xFF].State==ST_SOLID&&5>=rand()%50&&parts[i].life==0&&!((r&0xFF)==PT_CLNE||(r&0xFF)==PT_PCLN)) // TODO: should this also exclude BCLN? + if (sim->elements[r&0xFF].State==ST_SOLID && !(rand()%10) && parts[i].life==0 && !((r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN)) // TODO: should this also exclude BCLN? { sim->part_change_type(i,x,y,PT_RIME); } @@ -70,4 +70,4 @@ int Element_FOG::update(UPDATE_FUNC_ARGS) } -Element_FOG::~Element_FOG() {} \ No newline at end of file +Element_FOG::~Element_FOG() {} diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp index 5bdbb2129..b48cd6f97 100644 --- a/src/simulation/elements/FRZW.cpp +++ b/src/simulation/elements/FRZW.cpp @@ -57,18 +57,12 @@ int Element_FRZW::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((r&0xFF)==PT_WATR&&5>rand()%70) + if ((r&0xFF)==PT_WATR && !(rand()%14)) { sim->part_change_type(r>>8,x+rx,y+ry,PT_FRZW); } } - if (parts[i].life==0&&13>rand()%2500) - { - sim->part_change_type(i,x,y,PT_ICEI); - parts[i].ctype=PT_FRZW; - parts[i].temp = restrict_flt(parts[i].temp-200.0f, MIN_TEMP, MAX_TEMP); - } - else if ((100-(parts[i].life))>rand()%50000) + if ((parts[i].life==0 && !(rand()%192)) || (100-(parts[i].life))>rand()%50000 ) { sim->part_change_type(i,x,y,PT_ICEI); parts[i].ctype=PT_FRZW; @@ -78,4 +72,4 @@ int Element_FRZW::update(UPDATE_FUNC_ARGS) } -Element_FRZW::~Element_FRZW() {} \ No newline at end of file +Element_FRZW::~Element_FRZW() {} diff --git a/src/simulation/elements/FRZZ.cpp b/src/simulation/elements/FRZZ.cpp index 47a5c0f41..106766db5 100644 --- a/src/simulation/elements/FRZZ.cpp +++ b/src/simulation/elements/FRZZ.cpp @@ -57,20 +57,17 @@ int Element_FRZZ::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if ((r&0xFF)==PT_WATR&&5>rand()%100) + if ((r&0xFF)==PT_WATR && !(rand()%20)) { sim->part_change_type(r>>8,x+rx,y+ry,PT_FRZW); parts[r>>8].life = 100; - parts[i].type = PT_NONE; + sim->kill_part(i); + return 1; } } - if (parts[i].type==PT_NONE) { - sim->kill_part(i); - return 1; - } return 0; } -Element_FRZZ::~Element_FRZZ() {} \ No newline at end of file +Element_FRZZ::~Element_FRZZ() {} diff --git a/src/simulation/elements/FSEP.cpp b/src/simulation/elements/FSEP.cpp index 52e4a6713..132e0def2 100644 --- a/src/simulation/elements/FSEP.cpp +++ b/src/simulation/elements/FSEP.cpp @@ -55,11 +55,12 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS) if (r!=-1) parts[r].life = 50; return 1; - } else if (parts[i].life < 40) { + } + else if (parts[i].life < 40) { parts[i].life--; - if ((rand()%10)==0) { - r = sim->create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM); - if (r!=-1) + if (!(rand()%10)) { + r = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_PLSM); + if (r>-1) parts[r].life = 50; } } @@ -71,11 +72,9 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (!r) continue; - if (((r&0xFF)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && 1>(rand()%15)) + if (((r&0xFF)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && parts[i].life>40 && !(rand()%15)) { - if (parts[i].life>40) { - parts[i].life = 39; - } + parts[i].life = 39; } } } @@ -83,4 +82,4 @@ int Element_FSEP::update(UPDATE_FUNC_ARGS) } -Element_FSEP::~Element_FSEP() {} \ No newline at end of file +Element_FSEP::~Element_FSEP() {} diff --git a/src/simulation/elements/FUSE.cpp b/src/simulation/elements/FUSE.cpp index 946e86b72..5e9c95d05 100644 --- a/src/simulation/elements/FUSE.cpp +++ b/src/simulation/elements/FUSE.cpp @@ -52,25 +52,26 @@ int Element_FUSE::update(UPDATE_FUNC_ARGS) int r, rx, ry; if (parts[i].life<=0) { r = sim->create_part(i, x, y, PT_PLSM); - if (r!=-1) + if (r>-1) parts[r].life = 50; return 1; } else if (parts[i].life < 40) { parts[i].life--; - if ((rand()%100)==0) { - r = sim->create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM); - if (r!=-1) + if (!(rand()%100)) { + r = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_PLSM); + if (r>-1) parts[r].life = 50; } } - if ((sim->pv[y/CELL][x/CELL] > 2.7f)&&parts[i].tmp>40) + if ((sim->pv[y/CELL][x/CELL] > 2.7f) && parts[i].tmp>40) parts[i].tmp=39; - else if (parts[i].tmp<40&&parts[i].tmp>0) - parts[i].tmp--; else if (parts[i].tmp<=0) { sim->create_part(i, x, y, PT_FSEP); return 1; } + else if (parts[i].tmp<40) + parts[i].tmp--; + for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) if (x+rx>=0 && y+ry>0 && x+rx=(273.15+700.0f)) && 1>(rand()%20))) + if ((r&0xFF)==PT_SPRK || ((parts[i].temp>=(273.15+700.0f)) && parts[i].life>40 && !(rand()%20))) { - if (parts[i].life>40) { - parts[i].life = 39; - } + parts[i].life = 39; + } } return 0; } -Element_FUSE::~Element_FUSE() {} \ No newline at end of file +Element_FUSE::~Element_FUSE() {} diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp index f05db69dd..a16fbc6d9 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -83,8 +83,6 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS) return 0; } } - if (parts[i].life>=45) - parts[i].life=0; if (parts[i].life<3&&parts[i].life>0) { int r = (rand()%245+11); @@ -113,8 +111,10 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS) sim->kill_part(i); return 1; } + if (parts[i].life>=45) + parts[i].life=0; return 0; } -Element_FWRK::~Element_FWRK() {} \ No newline at end of file +Element_FWRK::~Element_FWRK() {}