summaryrefslogtreecommitdiff
path: root/src/simulation/elements
diff options
context:
space:
mode:
authorcracker64 <cracker642@gmail.com>2013-02-26 23:59:37 (GMT)
committer cracker64 <cracker642@gmail.com>2013-02-26 23:59:37 (GMT)
commit8250515e97db5ace3e87c612d855f09235b73969 (patch)
treeddbc36591a9043334b2fc684722ffd334894da83 /src/simulation/elements
parente700ff29883fcc3479ad8d9fce9805fbb0d31dfa (diff)
downloadpowder-8250515e97db5ace3e87c612d855f09235b73969.zip
powder-8250515e97db5ace3e87c612d855f09235b73969.tar.gz
Lots of small optimizations and things, nothing should be functionally different.
Only gotten through a few elements, more later.
Diffstat (limited to 'src/simulation/elements')
-rw-r--r--src/simulation/elements/ACEL.cpp24
-rw-r--r--src/simulation/elements/ACID.cpp8
-rw-r--r--src/simulation/elements/AMTR.cpp8
-rw-r--r--src/simulation/elements/ANAR.cpp46
-rw-r--r--src/simulation/elements/BANG.cpp13
-rw-r--r--src/simulation/elements/BIZR.cpp4
-rw-r--r--src/simulation/elements/BIZRG.cpp83
-rw-r--r--src/simulation/elements/BIZRS.cpp83
-rw-r--r--src/simulation/elements/BMTL.cpp5
-rw-r--r--src/simulation/elements/BREC.cpp17
-rw-r--r--src/simulation/elements/BRMT.cpp17
-rw-r--r--src/simulation/elements/BTRY.cpp8
-rw-r--r--src/simulation/elements/CBNW.cpp172
-rw-r--r--src/simulation/elements/CONV.cpp10
14 files changed, 173 insertions, 325 deletions
diff --git a/src/simulation/elements/ACEL.cpp b/src/simulation/elements/ACEL.cpp
index 143e195..12f408c 100644
--- a/src/simulation/elements/ACEL.cpp
+++ b/src/simulation/elements/ACEL.cpp
@@ -60,18 +60,18 @@ int Element_ACEL::update(UPDATE_FUNC_ARGS)
{
multiplier = 1.1f;
}
- parts[i].tmp = 0;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && !(rx && ry))
- {
- r = pmap[y+ry][x+rx];
- if(!r)
- r = sim->photons[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- if(sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))
- {
+ parts[i].tmp = 0;
+ for (rx=-1; rx<2; rx++)
+ for (ry=-1; ry<2; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && !(rx && ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if(!r)
+ r = sim->photons[y+ry][x+rx];
+ if (!r)
+ continue;
+ if(sim->elements[r&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))
+ {
parts[r>>8].vx *= multiplier;
parts[r>>8].vy *= multiplier;
parts[i].tmp = 1;
diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp
index fb6cb81..6501ba0 100644
--- a/src/simulation/elements/ACID.cpp
+++ b/src/simulation/elements/ACID.cpp
@@ -102,12 +102,12 @@ int Element_ACID::update(UPDATE_FUNC_ARGS)
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{
r = pmap[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
+ if (!r)
continue;
- if ((r&0xFF)==PT_ACID&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
+ if ((r&0xFF)==PT_ACID && (parts[i].life>parts[r>>8].life) && parts[i].life>0)//diffusion
{
int temp = parts[i].life - parts[r>>8].life;
- if (temp ==1)
+ if (temp==1)
{
parts[r>>8].life ++;
parts[i].life --;
@@ -141,4 +141,4 @@ int Element_ACID::graphics(GRAPHICS_FUNC_ARGS)
}
-Element_ACID::~Element_ACID() {} \ No newline at end of file
+Element_ACID::~Element_ACID() {}
diff --git a/src/simulation/elements/AMTR.cpp b/src/simulation/elements/AMTR.cpp
index ff25bb6..8183777 100644
--- a/src/simulation/elements/AMTR.cpp
+++ b/src/simulation/elements/AMTR.cpp
@@ -49,7 +49,7 @@ Element_AMTR::Element_AMTR()
//#TPT-Directive ElementHeader Element_AMTR static int update(UPDATE_FUNC_ARGS)
int Element_AMTR::update(UPDATE_FUNC_ARGS)
{
- int r, rx, ry;
+ int r, rx, ry, rt;
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
@@ -57,7 +57,9 @@ int Element_AMTR::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
- if ((r&0xFF)!=PT_AMTR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_NONE && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_BHOL && (r&0xFF)!=PT_NBHL && (r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO)
+ rt = r&0xFF;
+ //would a table lookup be faster than 11 checks?
+ if (rt!=PT_AMTR && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PCLN && rt!=PT_NONE && rt!=PT_PHOT && rt!=PT_VOID && rt!=PT_BHOL && rt!=PT_NBHL && rt!=PT_PRTI && rt!=PT_PRTO)
{
parts[i].life++;
if (parts[i].life==4)
@@ -76,4 +78,4 @@ int Element_AMTR::update(UPDATE_FUNC_ARGS)
}
-Element_AMTR::~Element_AMTR() {} \ No newline at end of file
+Element_AMTR::~Element_AMTR() {}
diff --git a/src/simulation/elements/ANAR.cpp b/src/simulation/elements/ANAR.cpp
index f8bcd49..6dd500f 100644
--- a/src/simulation/elements/ANAR.cpp
+++ b/src/simulation/elements/ANAR.cpp
@@ -49,30 +49,30 @@ Element_ANAR::Element_ANAR()
//#TPT-Directive ElementHeader Element_ANAR static int update(UPDATE_FUNC_ARGS)
int Element_ANAR::update(UPDATE_FUNC_ARGS)
{
- int r, rx, ry;
+ int r, rx, ry;
- //if (parts[i].temp >= 0.23)
- // parts[i].temp --;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_HFLM)
- {
- if (1>rand()%22)
- {
- sim->part_change_type(i,x,y,PT_HFLM);
- parts[i].life = rand()%150+50;
- parts[r>>8].temp = parts[i].temp = 0;
- sim->pv[y/CELL][x/CELL] -= 0.5;
- }
- }
- }
- return 0;
+ //if (parts[i].temp >= 0.23)
+ // parts[i].temp --;
+ for (rx=-2; rx<3; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+ if ((r&0xFF)==PT_HFLM)
+ {
+ if (1>rand()%22)
+ {
+ sim->part_change_type(i,x,y,PT_HFLM);
+ parts[i].life = rand()%150+50;
+ parts[r>>8].temp = parts[i].temp = 0;
+ sim->pv[y/CELL][x/CELL] -= 0.5;
+ }
+ }
+ }
+ return 0;
}
-Element_ANAR::~Element_ANAR() {} \ No newline at end of file
+Element_ANAR::~Element_ANAR() {}
diff --git a/src/simulation/elements/BANG.cpp b/src/simulation/elements/BANG.cpp
index 8922e0e..9d9bfbb 100644
--- a/src/simulation/elements/BANG.cpp
+++ b/src/simulation/elements/BANG.cpp
@@ -62,11 +62,7 @@ int Element_BANG::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
- if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM)
- {
- parts[i].tmp = 1;
- }
- else if ((r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH)
+ if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH)
{
parts[i].tmp = 1;
}
@@ -86,9 +82,9 @@ int Element_BANG::update(UPDATE_FUNC_ARGS)
{
parts[i].tmp = 3;
}
- else if(parts[i].tmp>=3)
+ else
{
- float otemp = parts[i].temp-275.13f;
+ float otemp = parts[i].temp-273.15f;
//Explode!!
sim->pv[y/CELL][x/CELL] += 0.5f;
parts[i].tmp = 0;
@@ -97,14 +93,13 @@ int Element_BANG::update(UPDATE_FUNC_ARGS)
if(!(rand()%2))
{
sim->create_part(i, x, y, PT_FIRE);
- parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
}
else
{
sim->create_part(i, x, y, PT_SMKE);
parts[i].life = rand()%50+500;
- parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
}
+ parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
}
else
{
diff --git a/src/simulation/elements/BIZR.cpp b/src/simulation/elements/BIZR.cpp
index 13df996..f2327de 100644
--- a/src/simulation/elements/BIZR.cpp
+++ b/src/simulation/elements/BIZR.cpp
@@ -82,7 +82,7 @@ int Element_BIZR::update(UPDATE_FUNC_ARGS)
}
}
}
- if(((r = sim->photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT)
+ if(((r = sim->photons[y][x])&0xFF)==PT_PHOT)
{
sim->part_change_type(r>>8, x, y, PT_ELEC);
parts[r>>8].ctype = 0;
@@ -121,4 +121,4 @@ int Element_BIZR::graphics(GRAPHICS_FUNC_ARGS)
}
-Element_BIZR::~Element_BIZR() {} \ No newline at end of file
+Element_BIZR::~Element_BIZR() {}
diff --git a/src/simulation/elements/BIZRG.cpp b/src/simulation/elements/BIZRG.cpp
index 1e5f27f..48856bd 100644
--- a/src/simulation/elements/BIZRG.cpp
+++ b/src/simulation/elements/BIZRG.cpp
@@ -42,83 +42,8 @@ Element_BIZRG::Element_BIZRG()
HighTemperature = 100.0f;
HighTemperatureTransition = PT_BIZR;
- Update = &Element_BIZRG::update;
- Graphics = &Element_BIZRG::graphics;
+ Update = &Element_BIZR::update;
+ Graphics = &Element_BIZR::graphics;
}
-
-//#TPT-Directive ElementHeader Element_BIZRG static int update(UPDATE_FUNC_ARGS)
-int Element_BIZRG::update(UPDATE_FUNC_ARGS)
- {
- int r, rx, ry, nr, ng, nb, na;
- float tr, tg, tb, ta, mr, mg, mb, ma;
- float blend;
- if(parts[i].dcolour){
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_BIZR && (r&0xFF)!=PT_BIZRG && (r&0xFF)!=PT_BIZRS)
- {
- blend = 0.95f;
- tr = (parts[r>>8].dcolour>>16)&0xFF;
- tg = (parts[r>>8].dcolour>>8)&0xFF;
- tb = (parts[r>>8].dcolour)&0xFF;
- ta = (parts[r>>8].dcolour>>24)&0xFF;
-
- mr = (parts[i].dcolour>>16)&0xFF;
- mg = (parts[i].dcolour>>8)&0xFF;
- mb = (parts[i].dcolour)&0xFF;
- ma = (parts[i].dcolour>>24)&0xFF;
-
- nr = (tr*blend) + (mr*(1-blend));
- ng = (tg*blend) + (mg*(1-blend));
- nb = (tb*blend) + (mb*(1-blend));
- na = (ta*blend) + (ma*(1-blend));
-
- parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24;
- }
- }
- }
- if(((r = sim->photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT)
- {
- sim->part_change_type(r>>8, x, y, PT_ELEC);
- parts[r>>8].ctype = 0;
- }
- return 0;
-}
-
-
-//#TPT-Directive ElementHeader Element_BIZRG static int graphics(GRAPHICS_FUNC_ARGS)
-int Element_BIZRG::graphics(GRAPHICS_FUNC_ARGS)
- //BIZR, BIZRG, BIZRS
-{
- int x = 0;
- *colg = 0;
- *colb = 0;
- *colr = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *colr *= x;
- *colg *= x;
- *colb *= x;
- if(fabs(cpart->vx)+fabs(cpart->vy)>0)
- {
- *firea = 255;
- *fireg = *colg/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *fireb = *colb/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *firer = *colr/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *pixel_mode |= FIRE_ADD;
- }
- return 0;
-}
-
-
-Element_BIZRG::~Element_BIZRG() {} \ No newline at end of file
+//BIZRG update is in BIZR.cpp
+Element_BIZRG::~Element_BIZRG() {}
diff --git a/src/simulation/elements/BIZRS.cpp b/src/simulation/elements/BIZRS.cpp
index 439a723..fe2a8cf 100644
--- a/src/simulation/elements/BIZRS.cpp
+++ b/src/simulation/elements/BIZRS.cpp
@@ -42,83 +42,8 @@ Element_BIZRS::Element_BIZRS()
HighTemperature = ITH;
HighTemperatureTransition = NT;
- Update = &Element_BIZRS::update;
- Graphics = &Element_BIZRS::graphics;
+ Update = &Element_BIZR::update;
+ Graphics = &Element_BIZR::graphics;
}
-
-//#TPT-Directive ElementHeader Element_BIZRS static int update(UPDATE_FUNC_ARGS)
-int Element_BIZRS::update(UPDATE_FUNC_ARGS)
- {
- int r, rx, ry, nr, ng, nb, na;
- float tr, tg, tb, ta, mr, mg, mb, ma;
- float blend;
- if(parts[i].dcolour){
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_BIZR && (r&0xFF)!=PT_BIZRG && (r&0xFF)!=PT_BIZRS)
- {
- blend = 0.95f;
- tr = (parts[r>>8].dcolour>>16)&0xFF;
- tg = (parts[r>>8].dcolour>>8)&0xFF;
- tb = (parts[r>>8].dcolour)&0xFF;
- ta = (parts[r>>8].dcolour>>24)&0xFF;
-
- mr = (parts[i].dcolour>>16)&0xFF;
- mg = (parts[i].dcolour>>8)&0xFF;
- mb = (parts[i].dcolour)&0xFF;
- ma = (parts[i].dcolour>>24)&0xFF;
-
- nr = (tr*blend) + (mr*(1-blend));
- ng = (tg*blend) + (mg*(1-blend));
- nb = (tb*blend) + (mb*(1-blend));
- na = (ta*blend) + (ma*(1-blend));
-
- parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24;
- }
- }
- }
- if(((r = sim->photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT)
- {
- sim->part_change_type(r>>8, x, y, PT_ELEC);
- parts[r>>8].ctype = 0;
- }
- return 0;
-}
-
-
-//#TPT-Directive ElementHeader Element_BIZRS static int graphics(GRAPHICS_FUNC_ARGS)
-int Element_BIZRS::graphics(GRAPHICS_FUNC_ARGS)
- //BIZR, BIZRG, BIZRS
-{
- int x = 0;
- *colg = 0;
- *colb = 0;
- *colr = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *colr *= x;
- *colg *= x;
- *colb *= x;
- if(fabs(cpart->vx)+fabs(cpart->vy)>0)
- {
- *firea = 255;
- *fireg = *colg/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *fireb = *colb/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *firer = *colr/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *pixel_mode |= FIRE_ADD;
- }
- return 0;
-}
-
-
-Element_BIZRS::~Element_BIZRS() {} \ No newline at end of file
+//BIZRS update is in BIZR.cpp
+Element_BIZRS::~Element_BIZRS() {}
diff --git a/src/simulation/elements/BMTL.cpp b/src/simulation/elements/BMTL.cpp
index adc5289..26c086b 100644
--- a/src/simulation/elements/BMTL.cpp
+++ b/src/simulation/elements/BMTL.cpp
@@ -60,8 +60,7 @@ int Element_BMTL::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
- rt = parts[r>>8].type;
- if ((rt==PT_METL || rt==PT_IRON) && 1>(rand()/(RAND_MAX/100)))
+ if (((r&0xFF)==PT_METL || (r&0xFF)==PT_IRON) && 1>(rand()/(RAND_MAX/100)))
{
sim->part_change_type(r>>8,x+rx,y+ry,PT_BMTL);
parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100;
@@ -77,4 +76,4 @@ int Element_BMTL::update(UPDATE_FUNC_ARGS)
}
-Element_BMTL::~Element_BMTL() {} \ No newline at end of file
+Element_BMTL::~Element_BMTL() {}
diff --git a/src/simulation/elements/BREC.cpp b/src/simulation/elements/BREC.cpp
index e260a7c..f5ae4a1 100644
--- a/src/simulation/elements/BREC.cpp
+++ b/src/simulation/elements/BREC.cpp
@@ -50,13 +50,18 @@ Element_BREC::Element_BREC()
int Element_BREC::update(UPDATE_FUNC_ARGS)
{
int np;
- if (1>rand()%200 && (sim->pv[y/CELL][x/CELL] > 30.0f) && parts[i].temp>9000 && parts[i].life>0)
+ if (parts[i].life)
{
- sim->part_change_type(i, x ,y ,PT_EXOT);
- parts[i].life = 1000;
- }
- if ((sim->pv[y/CELL][x/CELL] > 10.0f) && (parts[i].life>0)) {
- parts[i].temp = parts[i].temp + (sim->pv[y/CELL][x/CELL])/8;
+ if (sim->pv[y/CELL][x/CELL]>10.0f)
+ {
+ if (parts[i].temp>9000 && sim->pv[y/CELL][x/CELL]>30.0f && 1>rand()%200)
+ {
+ sim->part_change_type(i, x ,y ,PT_EXOT);
+ parts[i].life = 1000;
+ }
+ parts[i].temp = parts[i].temp + (sim->pv[y/CELL][x/CELL])/8;
+ }
+
}
return 0;
}
diff --git a/src/simulation/elements/BRMT.cpp b/src/simulation/elements/BRMT.cpp
index 55eb243..0e36630 100644
--- a/src/simulation/elements/BRMT.cpp
+++ b/src/simulation/elements/BRMT.cpp
@@ -50,8 +50,11 @@ Element_BRMT::Element_BRMT()
int Element_BRMT::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, rt, tempFactor;
- if (parts[i].temp > (250.0f+273.15f))
+ if (parts[i].temp > 523.15f)//250.0f+273.15f
{
+ tempFactor = 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 (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
@@ -59,20 +62,14 @@ int Element_BRMT::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
- rt = parts[r>>8].type;
- tempFactor = 1000 - (((250.0f+273.15f)-parts[i].temp)*2);
- if(tempFactor < 2)
- tempFactor = 2;
- if ((rt==PT_BREC) && 1 > (rand()%tempFactor))
+ if ((r&0xFF)==PT_BREC && 1>(rand()%tempFactor))
{
if(rand()%2)
{
sim->create_part(r>>8, x+rx, y+ry, PT_THRM);
}
else
- { sim->create_part(i, x, y, PT_THRM);
- }
- return 1;
+ sim->create_part(i, x, y, PT_THRM);
//part_change_type(r>>8,x+rx,y+ry,PT_BMTL);
//parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100;
}
@@ -82,4 +79,4 @@ int Element_BRMT::update(UPDATE_FUNC_ARGS)
}
-Element_BRMT::~Element_BRMT() {} \ No newline at end of file
+Element_BRMT::~Element_BRMT() {}
diff --git a/src/simulation/elements/BTRY.cpp b/src/simulation/elements/BTRY.cpp
index efbb3d2..4f1e810 100644
--- a/src/simulation/elements/BTRY.cpp
+++ b/src/simulation/elements/BTRY.cpp
@@ -52,15 +52,15 @@ int Element_BTRY::update(UPDATE_FUNC_ARGS)
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<XRES && y+ry<YRES && (rx || ry))
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && abs(rx)+abs(ry)<4)
{
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 && abs(rx)+abs(ry) < 4)
+ 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)
{
parts[r>>8].life = 4;
parts[r>>8].ctype = rt;
@@ -72,4 +72,4 @@ int Element_BTRY::update(UPDATE_FUNC_ARGS)
}
-Element_BTRY::~Element_BTRY() {} \ No newline at end of file
+Element_BTRY::~Element_BTRY() {}
diff --git a/src/simulation/elements/CBNW.cpp b/src/simulation/elements/CBNW.cpp
index 4331750..87240d8 100644
--- a/src/simulation/elements/CBNW.cpp
+++ b/src/simulation/elements/CBNW.cpp
@@ -49,92 +49,90 @@ Element_CBNW::Element_CBNW()
//#TPT-Directive ElementHeader Element_CBNW static int update(UPDATE_FUNC_ARGS)
int Element_CBNW::update(UPDATE_FUNC_ARGS)
{
- int r, rx, ry, oldt;
- oldt = parts[i].tmp;
- if (sim->pv[y/CELL][x/CELL]<=3)
- {
- if(20>(rand()%80000))
- {
- sim->part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- sim->pv[y/CELL][x/CELL] += 0.5f;
- }
- else if(sim->pv[y/CELL][x/CELL]<=-0.5)
- {
- sim->part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- sim->pv[y/CELL][x/CELL] += 0.5f;
- }
- }
- if (parts[i].tmp>0)
- parts[i].tmp--;
- if(!(rand()%200))
- {
- parts[i].tmp2 = rand()%40;
- } else if(parts[i].tmp2!=20) {
- parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1;
- }
- if(oldt==1)
- {
- //Explode
- if(rand()%4)
- {
- sim->part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- sim->pv[y/CELL][x/CELL] += 0.2f;
- }
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((sim->elements[r&0xFF].Properties&TYPE_PART) && parts[i].tmp == 0 && 1>(rand()%250))
- {
- //Start explode
- parts[i].tmp = rand()%25;//(rand()%100)+50;
- }
- else if((sim->elements[r&0xFF].Properties&TYPE_SOLID) && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_GLAS && parts[i].tmp == 0 && (2-sim->pv[y/CELL][x/CELL])>(rand()%20000))
- {
- if(rand()%2)
- {
- sim->part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- sim->pv[y/CELL][x/CELL] += 0.2f;
- }
- }
- if ((r&0xFF)==PT_CBNW)
- {
- if(!parts[i].tmp && parts[r>>8].tmp)
- {
- parts[i].tmp = parts[r>>8].tmp;
- if((r>>8)>i) //If the other particle hasn't been life updated
- parts[i].tmp--;
- }
- else if(parts[i].tmp && !parts[r>>8].tmp)
- {
- parts[r>>8].tmp = parts[i].tmp;
- if((r>>8)>i) //If the other particle hasn't been life updated
- parts[r>>8].tmp++;
- }
- }
- if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500))
- {
- sim->part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- parts[i].ctype = PT_WATR;
- }
- if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){
- sim->kill_part(r>>8);
- if(1>(rand()%150)){
- sim->kill_part(i);
- return 1;
- }
- }
- }
- return 0;
+ int r, rx, ry;
+ if (sim->pv[y/CELL][x/CELL]<=3)
+ {
+ if(sim->pv[y/CELL][x/CELL]<=-0.5)
+ {
+ sim->part_change_type(i,x,y,PT_CO2);
+ parts[i].ctype = 5;
+ sim->pv[y/CELL][x/CELL] += 0.5f;
+ }
+ else if(1>(rand()%4000))
+ {
+ sim->part_change_type(i,x,y,PT_CO2);
+ parts[i].ctype = 5;
+ sim->pv[y/CELL][x/CELL] += 0.5f;
+ }
+ }
+ if (parts[i].tmp2!=20) {
+ parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1;
+ }
+ else if(!(rand()%200))
+ {
+ parts[i].tmp2 = rand()%40;
+ }
+
+ if(parts[i].tmp>0)
+ {
+ //Explode
+ if(parts[i].tmp==1 && rand()%4)
+ {
+ sim->part_change_type(i,x,y,PT_CO2);
+ parts[i].ctype = 5;
+ sim->pv[y/CELL][x/CELL] += 0.2f;
+ }
+ parts[i].tmp--;
+ }
+ for (rx=-2; rx<3; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+ if ((sim->elements[r&0xFF].Properties&TYPE_PART) && parts[i].tmp == 0 && 1>(rand()%250))
+ {
+ //Start explode
+ parts[i].tmp = rand()%25;//(rand()%100)+50;
+ }
+ else if((r&0xFF)!=PT_DMND && (r&0xFF)!=PT_GLAS && (sim->elements[r&0xFF].Properties&TYPE_SOLID) && parts[i].tmp == 0 && (2-sim->pv[y/CELL][x/CELL])>(rand()%40000))
+ {
+ sim->part_change_type(i,x,y,PT_CO2);
+ parts[i].ctype = 5;
+ sim->pv[y/CELL][x/CELL] += 0.2f;
+
+ }
+ if ((r&0xFF)==PT_CBNW)
+ {
+ if(!parts[i].tmp && parts[r>>8].tmp)
+ {
+ parts[i].tmp = parts[r>>8].tmp;
+ if((r>>8)>i) //If the other particle hasn't been life updated
+ parts[i].tmp--;
+ }
+ else if(parts[i].tmp && !parts[r>>8].tmp)
+ {
+ parts[r>>8].tmp = parts[i].tmp;
+ if((r>>8)>i) //If the other particle hasn't been life updated
+ parts[r>>8].tmp++;
+ }
+ }
+ if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500))
+ {
+ sim->part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = 4;
+ parts[i].ctype = PT_WATR;
+ }
+ if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){
+ sim->kill_part(r>>8);
+ if(1>(rand()%150)){
+ sim->kill_part(i);
+ return 1;
+ }
+ }
+ }
+ return 0;
}
@@ -150,4 +148,4 @@ int Element_CBNW::graphics(GRAPHICS_FUNC_ARGS)
}
-Element_CBNW::~Element_CBNW() {} \ No newline at end of file
+Element_CBNW::~Element_CBNW() {}
diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp
index 6577516..8f2f0c6 100644
--- a/src/simulation/elements/CONV.cpp
+++ b/src/simulation/elements/CONV.cpp
@@ -50,7 +50,7 @@ Element_CONV::Element_CONV()
int Element_CONV::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry;
- if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
+ if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !sim->elements[parts[i].ctype].Enabled || parts[i].ctype==PT_CONV || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
{
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
@@ -72,7 +72,9 @@ int Element_CONV::update(UPDATE_FUNC_ARGS)
}
}
}
- else if(parts[i].ctype>0 && parts[i].ctype<PT_NUM && sim->elements[parts[i].ctype].Enabled && parts[i].ctype!=PT_CONV) {
+ else
+ {
+ bool life = parts[i].ctype==PT_LIFE;
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
@@ -84,7 +86,7 @@ int Element_CONV::update(UPDATE_FUNC_ARGS)
continue;
if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=parts[i].ctype)
{
- if (parts[i].ctype==PT_LIFE) sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8));
+ if (life) sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8));
else sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype);
}
}
@@ -93,4 +95,4 @@ int Element_CONV::update(UPDATE_FUNC_ARGS)
}
-Element_CONV::~Element_CONV() {} \ No newline at end of file
+Element_CONV::~Element_CONV() {}