summaryrefslogtreecommitdiff
path: root/src/elements
diff options
context:
space:
mode:
authorCracker64 <cracker642@gmail.com>2011-01-28 23:54:50 (GMT)
committer Cracker64 <cracker642@gmail.com>2011-01-28 23:54:50 (GMT)
commitbcea95c5ca9b899be193c20760c634e2a3f5ad91 (patch)
tree7af3857d49748fb75c7c02d6ff3af38fbaa3450c /src/elements
parent60d3f0047b21c6a1b34d07f0c0ac8c3cbc708289 (diff)
downloadpowder-bcea95c5ca9b899be193c20760c634e2a3f5ad91.zip
powder-bcea95c5ca9b899be193c20760c634e2a3f5ad91.tar.gz
update to latest
Diffstat (limited to 'src/elements')
-rw-r--r--src/elements/acid.c37
-rw-r--r--src/elements/amtr.c28
-rw-r--r--src/elements/aray.c74
-rw-r--r--src/elements/bcln.c33
-rw-r--r--src/elements/bcol.c28
-rw-r--r--src/elements/bmtl.c26
-rw-r--r--src/elements/bomb.c64
-rw-r--r--src/elements/boyl.c43
-rw-r--r--src/elements/btry.c24
-rw-r--r--src/elements/c5.c24
-rw-r--r--src/elements/clne.c23
-rw-r--r--src/elements/coal.c35
-rw-r--r--src/elements/deut.c73
-rw-r--r--src/elements/dstw.c32
-rw-r--r--src/elements/firw.c66
-rw-r--r--src/elements/fog.c22
-rw-r--r--src/elements/frzw.c30
-rw-r--r--src/elements/frzz.c25
-rw-r--r--src/elements/fsep.c35
-rw-r--r--src/elements/fuse.c41
-rw-r--r--src/elements/fwrk.c51
-rw-r--r--src/elements/glas.c11
-rw-r--r--src/elements/glow.c24
-rw-r--r--src/elements/goo.c15
-rw-r--r--src/elements/hswc.c24
-rw-r--r--src/elements/ice.c23
-rw-r--r--src/elements/iron.c25
-rw-r--r--src/elements/isz.c14
-rw-r--r--src/elements/lcry.c24
-rw-r--r--src/elements/legacy.c120
-rw-r--r--src/elements/misc.c12
-rw-r--r--src/elements/mort.c6
-rw-r--r--src/elements/neut.c88
-rw-r--r--src/elements/none.c6
-rw-r--r--src/elements/nptct.c7
-rw-r--r--src/elements/pcln.c65
-rw-r--r--src/elements/phot.c43
-rw-r--r--src/elements/pipe.c122
-rw-r--r--src/elements/plnt.c57
-rw-r--r--src/elements/plut.c9
-rw-r--r--src/elements/prti.c30
-rw-r--r--src/elements/prto.c53
-rw-r--r--src/elements/pump.c39
-rw-r--r--src/elements/pyro.c111
-rw-r--r--src/elements/qrtz.c11
-rw-r--r--src/elements/rime.c26
-rw-r--r--src/elements/shld.c168
-rw-r--r--src/elements/sing.c59
-rw-r--r--src/elements/sltw.c23
-rw-r--r--src/elements/spng.c97
-rw-r--r--src/elements/sprk.c168
-rw-r--r--src/elements/stkm.c412
-rw-r--r--src/elements/stkm2.c413
-rw-r--r--src/elements/swch.c37
-rw-r--r--src/elements/thdr.c38
-rw-r--r--src/elements/thrm.c29
-rw-r--r--src/elements/uran.c10
-rw-r--r--src/elements/vine.c21
-rw-r--r--src/elements/warp.c28
-rw-r--r--src/elements/watr.c29
-rw-r--r--src/elements/wifi.c33
-rw-r--r--src/elements/wtrv.c19
-rw-r--r--src/elements/yest.c21
63 files changed, 3384 insertions, 0 deletions
diff --git a/src/elements/acid.c b/src/elements/acid.c
new file mode 100644
index 0000000..3d9f7b0
--- /dev/null
+++ b/src/elements/acid.c
@@ -0,0 +1,37 @@
+#include <element.h>
+
+int update_ACID(UPDATE_FUNC_ARGS) {
+ int r,rx,ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)!=PT_ACID)
+ {
+ if ((r&0xFF)==PT_PLEX || (r&0xFF)==PT_NITR || (r&0xFF)==PT_GUNP || (r&0xFF)==PT_RBDM || (r&0xFF)==PT_LRBD)
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ part_change_type(r>>8,x+rx,y+ry,PT_FIRE);
+ parts[i].life = 4;
+ parts[r>>8].life = 4;
+ }
+ else if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && ptypes[r&0xFF].hardness>(rand()%1000))&&parts[i].life>=50)
+ {
+ if (parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS)
+ {
+ parts[i].life--;
+ kill_part(r>>8);
+ }
+ }
+ else if (parts[i].life<=50)
+ {
+ kill_part(i);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/amtr.c b/src/elements/amtr.c
new file mode 100644
index 0000000..7c2126c
--- /dev/null
+++ b/src/elements/amtr.c
@@ -0,0 +1,28 @@
+#include <element.h>
+
+int update_AMTR(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !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_PRTI && (r&0xFF)!=PT_PRTO)
+ {
+ parts[i].life++;
+ if (parts[i].life==3)
+ {
+ kill_part(i);
+ return 1;
+ }
+ if (2>(rand()/(RAND_MAX/100)))
+ create_part(r>>8, x+rx, y+ry, PT_PHOT);
+ else
+ kill_part(r>>8);
+ pv[y/CELL][x/CELL] -= 5.0f;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/aray.c b/src/elements/aray.c
new file mode 100644
index 0000000..f323444
--- /dev/null
+++ b/src/elements/aray.c
@@ -0,0 +1,74 @@
+#include <element.h>
+
+int update_ARAY(UPDATE_FUNC_ARGS) {
+ int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, nr;
+ if (parts[i].life==0) {
+ int colored =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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SPRK) {
+ int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0;
+ int nostop = (parts[r>>8].ctype==PT_INST)?1:0;
+ for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) {
+ if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0)) {
+ break;
+ }
+ r = pmap[y+nyi+nyy][x+nxi+nxx];
+ if (!((r>>8)>=NPART)) {
+ if (!r) {
+ int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
+ if (nr!=-1) {
+ if (destroy) {
+ parts[nr].tmp = 2;
+ parts[nr].life = 2;
+ } else
+ parts[nr].ctype = colored;
+ }
+ } else if (!destroy) {
+ if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==0) {
+ if (nyy!=0 || nxx!=0) {
+ parts[r>>8].life = 1020;
+ parts[r>>8].tmp = 1;
+ if (!parts[r>>8].ctype)
+ parts[r>>8].ctype = colored;
+ }
+ docontinue = 0;
+ } else if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==1) {
+ parts[r>>8].life = 1020;
+ //docontinue = 1;
+ }
+ else if ((r&0xFF)==PT_FILT) {
+ colored = parts[r>>8].ctype;
+ } else if ((r&0xFF)!=PT_INWR && (r&0xFF)!=PT_ARAY && (r&0xFF)!=PT_WIFI && !((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
+ if (nyy!=0 || nxx!=0) {
+ create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
+ }
+ if (!(nostop && (ptypes[parts[r>>8].ctype].properties&PROP_CONDUCTS))) {
+ docontinue = 0;
+ } else {
+ docontinue = 1;
+ }
+ }
+ } else if (destroy) {
+ if ((r&0xFF)==PT_BRAY) {
+ parts[r>>8].life = 1;
+ docontinue = 1;
+ } else if ((r&0xFF)==PT_INWR || (r&0xFF)==PT_ARAY || (r&0xFF)==PT_WIFI || (r&0xFF)==PT_FILT || ((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
+ docontinue = 1;
+ } else {
+ docontinue = 0;
+ }
+ }
+ }
+ }
+ }
+ //parts[i].life = 4;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/bcln.c b/src/elements/bcln.c
new file mode 100644
index 0000000..3581fc2
--- /dev/null
+++ b/src/elements/bcln.c
@@ -0,0 +1,33 @@
+#include <element.h>
+
+int update_BCLN(UPDATE_FUNC_ARGS) {
+ if (!parts[i].life)
+ {
+ if (pv[y/CELL][x/CELL]>4.0f)
+ {
+ float advection = 0.1f;
+ parts[i].vx += advection*vx[y/CELL][x/CELL];
+ parts[i].vy += advection*vy[y/CELL][x/CELL];
+ parts[i].life = rand()%40+80;
+ }
+ }
+ if (!parts[i].ctype)
+ {
+ int rx, ry;
+ 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 &&
+ pmap[y+ry][x+rx] &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_CLNE &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_BCLN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_PCLN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_STKM &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_STKM2 &&
+ (pmap[y+ry][x+rx]&0xFF)!=0xFF)
+ parts[i].ctype = pmap[y+ry][x+rx]&0xFF;
+ }
+ else {
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
+ }
+ return 0;
+}
diff --git a/src/elements/bcol.c b/src/elements/bcol.c
new file mode 100644
index 0000000..5be50d9
--- /dev/null
+++ b/src/elements/bcol.c
@@ -0,0 +1,28 @@
+#include <element.h>
+
+int update_BCOL(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (parts[i].life<=0) {
+ create_part(i, x, y, PT_FIRE);
+ return 1;
+ } else if (parts[i].life < 100) {
+ parts[i].life--;
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
+ }
+
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
+ {
+ if (parts[i].life>100) {
+ parts[i].life = 99;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/bmtl.c b/src/elements/bmtl.c
new file mode 100644
index 0000000..a29ac7d
--- /dev/null
+++ b/src/elements/bmtl.c
@@ -0,0 +1,26 @@
+#include <element.h>
+
+int update_BMTL(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, rt;
+ if (parts[i].tmp>1) {
+ parts[i].tmp--;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ rt = parts[r>>8].type;
+ if ((rt==PT_METL || rt==PT_IRON) && 1>(rand()/(RAND_MAX/100)))
+ {
+ 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;
+ }
+ }
+ } else if (parts[i].tmp==1 && 1>rand()%1000) {
+ parts[i].tmp = 0;
+ part_change_type(i,x,y,PT_BRMT);
+ }
+ return 0;
+}
diff --git a/src/elements/bomb.c b/src/elements/bomb.c
new file mode 100644
index 0000000..59e05f8
--- /dev/null
+++ b/src/elements/bomb.c
@@ -0,0 +1,64 @@
+#include <element.h>
+
+int update_BOMB(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, nb;
+ if (parts[i].tmp==1) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)!=PT_BOMB) {
+ kill_part(i);
+ return 1;
+ }
+ }
+ } else if (parts[i].tmp==0) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN) {
+ int rad = 8;
+ int nxi;
+ int nxj;
+ pmap[y][x] = 0;
+ for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
+ for (nxi=-(rad+1); nxi<=(rad+1); nxi++)
+ if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1) {
+ nb = create_part(-1, x+nxi, y+nxj, PT_BOMB);
+ if (nb!=-1) {
+ parts[nb].tmp = 1;
+ parts[nb].life = 50;
+ parts[nb].temp = MAX_TEMP;
+ parts[nb].vx = rand()%20-10;
+ parts[nb].vy = rand()%20-10;
+ }
+ }
+ for (nxj=-rad; nxj<=rad; nxj++)
+ for (nxi=-rad; nxi<=rad; nxi++)
+ if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1)
+ if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) {
+ delete_part(x+nxi, y+nxj);
+ pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
+ nb = create_part(-1, x+nxi, y+nxj, PT_BOMB);
+ if (nb!=-1) {
+ parts[nb].tmp = 2;
+ parts[nb].life = 2;
+ parts[nb].temp = MAX_TEMP;
+ }
+ }
+ //create_parts(x, y, 9, 9, PT_BOMB);
+ //create_parts(x, y, 8, 8, PT_NONE);
+ kill_part(i);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/boyl.c b/src/elements/boyl.c
new file mode 100644
index 0000000..68e1bf6
--- /dev/null
+++ b/src/elements/boyl.c
@@ -0,0 +1,43 @@
+#include <element.h>
+
+int update_BOYL(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (pv[y/CELL][x/CELL]<(parts[i].temp/100))
+ pv[y/CELL][x/CELL] += 0.001f*((parts[i].temp/100)-pv[y/CELL][x/CELL]);
+ if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<(parts[i].temp/100))
+ pv[y/CELL+1][x/CELL] += 0.001f*((parts[i].temp/100)-pv[y/CELL+1][x/CELL]);
+ if (x+CELL<XRES)
+ {
+ pv[y/CELL][x/CELL+1] += 0.001f*((parts[i].temp/100)-pv[y/CELL][x/CELL+1]);
+ if (y+CELL<YRES)
+ pv[y/CELL+1][x/CELL+1] += 0.001f*((parts[i].temp/100)-pv[y/CELL+1][x/CELL+1]);
+ }
+ if (y-CELL>=0 && pv[y/CELL-1][x/CELL]<(parts[i].temp/100))
+ pv[y/CELL-1][x/CELL] += 0.001f*((parts[i].temp/100)-pv[y/CELL-1][x/CELL]);
+ if (x-CELL>=0)
+ {
+ pv[y/CELL][x/CELL-1] += 0.001f*((parts[i].temp/100)-pv[y/CELL][x/CELL-1]);
+ if (y-CELL>=0)
+ pv[y/CELL-1][x/CELL-1] += 0.001f*((parts[i].temp/100)-pv[y/CELL-1][x/CELL-1]);
+ }
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_WATR && 1>rand()%30)
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_FOG);
+ }
+ else if ((r&0xFF)==PT_O2 && 1>rand()%9)
+ {
+ kill_part(r>>8);
+ part_change_type(i,x,y,PT_WATR);
+ pv[y/CELL][x/CELL] += 4.0;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/btry.c b/src/elements/btry.c
new file mode 100644
index 0000000..c3a96c7
--- /dev/null
+++ b/src/elements/btry.c
@@ -0,0 +1,24 @@
+#include <element.h>
+
+int update_BTRY(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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ rt = parts[r>>8].type;
+ if (parts_avg(i,r>>8,PT_INSL) != PT_INSL)
+ {
+ if ((ptypes[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)
+ {
+ parts[r>>8].life = 4;
+ parts[r>>8].ctype = rt;
+ part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/c5.c b/src/elements/c5.c
new file mode 100644
index 0000000..000c2be
--- /dev/null
+++ b/src/elements/c5.c
@@ -0,0 +1,24 @@
+#include <element.h>
+
+int update_C5(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)!=PT_C5 && parts[r>>8].temp<100)||(r&0xFF)==PT_HFLM)
+ {
+ if (1>rand()%6)
+ {
+ part_change_type(i,x,y,PT_HFLM);
+ parts[r>>8].temp = parts[i].temp = 0;
+ parts[i].life = rand()%150+50;
+ pv[y/CELL][x/CELL] += 1.5;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/clne.c b/src/elements/clne.c
new file mode 100644
index 0000000..173bd0a
--- /dev/null
+++ b/src/elements/clne.c
@@ -0,0 +1,23 @@
+#include <element.h>
+
+int update_CLNE(UPDATE_FUNC_ARGS) {
+ if (!parts[i].ctype)
+ {
+ int rx, ry;
+ 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 &&
+ pmap[y+ry][x+rx] &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_CLNE &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_BCLN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_PCLN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_STKM &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_STKM2 &&
+ (pmap[y+ry][x+rx]&0xFF)!=0xFF)
+ parts[i].ctype = pmap[y+ry][x+rx]&0xFF;
+ }
+ else {
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
+ }
+ return 0;
+}
diff --git a/src/elements/coal.c b/src/elements/coal.c
new file mode 100644
index 0000000..3cc68e3
--- /dev/null
+++ b/src/elements/coal.c
@@ -0,0 +1,35 @@
+#include <element.h>
+
+int update_COAL(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (parts[i].life<=0) {
+ create_part(i, x, y, PT_FIRE);
+ return 1;
+ } else if (parts[i].life < 100) {
+ parts[i].life--;
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
+ }
+ if ((pv[y/CELL][x/CELL] > 4.3f)&&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) {
+ create_part(i, x, y, PT_BCOL);
+ return 1;
+ }
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
+ {
+ if (parts[i].life>100) {
+ parts[i].life = 99;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/deut.c b/src/elements/deut.c
new file mode 100644
index 0000000..2d7a1f2
--- /dev/null
+++ b/src/elements/deut.c
@@ -0,0 +1,73 @@
+#include <element.h>
+
+int update_DEUT(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, trade, np;
+ int maxlife = ((10000/(parts[i].temp + 1))-1);
+ if ((10000%((int)parts[i].temp+1))>rand()%((int)parts[i].temp+1))
+ maxlife ++;
+ if (parts[i].life < maxlife)
+ {
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r || (parts[i].life >=maxlife))
+ continue;
+ if ((r&0xFF)==PT_DEUT&&33>=rand()/(RAND_MAX/100)+1)
+ {
+ if ((parts[i].life + parts[r>>8].life + 1) <= maxlife)
+ {
+ parts[i].life += parts[r>>8].life + 1;
+ kill_part(r>>8);
+ }
+ }
+ }
+ }
+ else
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || (parts[i].life<=maxlife))
+ continue;
+ if ((bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_WALLELEC||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_EWALL||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_DESTROYALL||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_WALL||
+ bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWAIR||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWSOLID||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWGAS))
+ continue;
+ if ((!r)&&parts[i].life>=1)//if nothing then create deut
+ {
+ np = 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;
+ }
+ }
+ for ( trade = 0; trade<4; trade ++)
+ {
+ rx = rand()%5-2;
+ ry = rand()%5-2;
+ 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)
+ continue;
+ if ((r&0xFF)==PT_DEUT&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
+ {
+ int temp = parts[i].life - parts[r>>8].life;
+ if (temp ==1)
+ {
+ parts[r>>8].life ++;
+ parts[i].life --;
+ }
+ else if (temp>0)
+ {
+ parts[r>>8].life += temp/2;
+ parts[i].life -= temp/2;
+ }
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/dstw.c b/src/elements/dstw.c
new file mode 100644
index 0000000..7ce6c09
--- /dev/null
+++ b/src/elements/dstw.c
@@ -0,0 +1,32 @@
+#include <element.h>
+
+int update_DSTW(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SALT && 1>(rand()%250))
+ {
+ part_change_type(i,x,y,PT_SLTW);
+ part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
+ }
+ if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_WATR);
+ }
+ if ((r&0xFF)==PT_SLTW && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_SLTW);
+ }
+ if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (legacy_enable||parts[i].temp>12.0f) && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = 4;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/firw.c b/src/elements/firw.c
new file mode 100644
index 0000000..ae1f56d
--- /dev/null
+++ b/src/elements/firw.c
@@ -0,0 +1,66 @@
+#include <element.h>
+
+int update_FIRW(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 (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)
+ continue;
+ rt = parts[r>>8].type;
+ if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR)
+ {
+ parts[i].tmp = 1;
+ parts[i].life = rand()%50+60;
+ }
+ }
+ }
+ else if (parts[i].tmp==1) {
+ if (parts[i].life==0) {
+ parts[i].tmp=2;
+ } else {
+ float newVel = parts[i].life/25;
+ parts[i].flags = parts[i].flags&0xFFFFFFFE;
+ /* TODO:
+ if ((pmap[(int)(ly-newVel)][(int)lx]&0xFF)==PT_NONE && ly-newVel>0) {
+ parts[i].vy = -newVel;
+ ly-=newVel;
+ iy-=newVel;
+ }*/
+ parts[i].vy = -newVel;
+ }
+ }
+ else if (parts[i].tmp==2) {
+ int col = rand()%200+4;
+ 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];
+ int tmul = rand()%7;
+ create_part(-1, x+rx, y+ry, PT_FIRW);
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_FIRW) {
+ parts[r>>8].vx = (rand()%3-1)*tmul;
+ parts[r>>8].vy = (rand()%3-1)*tmul;
+ parts[r>>8].tmp = col;
+ parts[r>>8].life = rand()%100+100;
+ parts[r>>8].temp = 6000.0f;
+ }
+ }
+ pv[y/CELL][x/CELL] += 20;
+ kill_part(i);
+ return 1;
+ } else if (parts[i].tmp>=3) {
+ if (parts[i].life<=0) {
+ kill_part(i);
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/fog.c b/src/elements/fog.c
new file mode 100644
index 0000000..ff13916
--- /dev/null
+++ b/src/elements/fog.c
@@ -0,0 +1,22 @@
+#include <element.h>
+
+int update_FOG(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if (ptypes[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?
+ {
+ part_change_type(i,x,y,PT_RIME);
+ }
+ if ((r&0xFF)==PT_SPRK)
+ {
+ parts[i].life += rand()%20;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/frzw.c b/src/elements/frzw.c
new file mode 100644
index 0000000..3135357
--- /dev/null
+++ b/src/elements/frzw.c
@@ -0,0 +1,30 @@
+#include <element.h>
+
+int update_FRZW(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_WATR&&5>rand()%70)
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_FRZW);
+ }
+ }
+ if (parts[i].life==0&&13>rand()%2500)
+ {
+ 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)
+ {
+ 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);
+ }
+ return 0;
+}
diff --git a/src/elements/frzz.c b/src/elements/frzz.c
new file mode 100644
index 0000000..f995d5f
--- /dev/null
+++ b/src/elements/frzz.c
@@ -0,0 +1,25 @@
+#include <element.h>
+
+int update_FRZZ(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_WATR&&5>rand()%100)
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_FRZW);
+ parts[r>>8].life = 100;
+ parts[i].type = PT_NONE;
+ }
+
+ }
+ if (parts[i].type==PT_NONE) {
+ kill_part(i);
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/elements/fsep.c b/src/elements/fsep.c
new file mode 100644
index 0000000..6b3b376
--- /dev/null
+++ b/src/elements/fsep.c
@@ -0,0 +1,35 @@
+#include <element.h>
+
+int update_FSEP(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (parts[i].life<=0) {
+ r = create_part(i, x, y, PT_PLSM);
+ if (r!=-1)
+ parts[r].life = 50;
+ return 1;
+ } else if (parts[i].life < 40) {
+ parts[i].life--;
+ if ((rand()%10)==0) {
+ r = create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM);
+ if (r!=-1)
+ parts[r].life = 50;
+ }
+ }
+ else {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && 1>(rand()%15))
+ {
+ if (parts[i].life>40) {
+ parts[i].life = 39;
+ }
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/fuse.c b/src/elements/fuse.c
new file mode 100644
index 0000000..ad0a413
--- /dev/null
+++ b/src/elements/fuse.c
@@ -0,0 +1,41 @@
+#include <element.h>
+
+int update_FUSE(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (parts[i].life<=0) {
+ r = create_part(i, x, y, PT_PLSM);
+ if (r!=-1)
+ parts[r].life = 50;
+ return 1;
+ } else if (parts[i].life < 40) {
+ parts[i].life--;
+ if ((rand()%100)==0) {
+ r = create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM);
+ if (r!=-1)
+ parts[r].life = 50;
+ }
+ }
+ if ((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) {
+ create_part(i, x, y, PT_FSEP);
+ return 1;
+ }
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SPRK || ((parts[i].temp>=(273.15+700.0f)) && 1>(rand()%20)))
+ {
+ if (parts[i].life>40) {
+ parts[i].life = 39;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c
new file mode 100644
index 0000000..def28e4
--- /dev/null
+++ b/src/elements/fwrk.c
@@ -0,0 +1,51 @@
+#include <element.h>
+
+int update_FWRK(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, np;
+ if ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&parts[i].life==0&&!pmap[y-1][x])||parts[i].ctype==PT_DUST)
+ {
+ np = create_part(-1, x , y-1 , PT_FWRK);
+ if (np!=-1)
+ {
+ parts[r>>8].vy = rand()%8-22;
+ parts[r>>8].vx = rand()%20-rand()%20;
+ parts[r>>8].life=rand()%15+25;
+ kill_part(i);
+ return 1;
+ }
+ }
+ if (parts[i].life>=45)
+ parts[i].life=0;
+ if ((parts[i].life<3&&parts[i].life>0)||parts[i].vy>6&&parts[i].life>0)
+ {
+ int q = (rand()%255+1);
+ int w = (rand()%255+1);
+ int e = (rand()%255+1);
+ for (rx=-1; rx<2; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ if (5>=rand()%8)
+ {
+ if (!pmap[y+ry][x+rx])
+ {
+ np = create_part(-1, x+rx, y+ry , PT_DUST);
+ pv[y/CELL][x/CELL] += 2.00f*CFDS;
+ if (np!=-1)
+ {
+ parts[r>>8].vy = -(rand()%10-1);
+ parts[r>>8].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ;
+ parts[r>>8].life= rand()%37+18;
+ parts[r>>8].tmp=q;
+ parts[r>>8].flags=w;
+ parts[r>>8].ctype=e;
+ parts[r>>8].temp= rand()%20+6000;
+ }
+ }
+ }
+ }
+ kill_part(i);
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/elements/glas.c b/src/elements/glas.c
new file mode 100644
index 0000000..bc2d5ce
--- /dev/null
+++ b/src/elements/glas.c
@@ -0,0 +1,11 @@
+#include <element.h>
+
+int update_GLAS(UPDATE_FUNC_ARGS) {
+ parts[i].pavg[0] = parts[i].pavg[1];
+ parts[i].pavg[1] = pv[y/CELL][x/CELL];
+ if (parts[i].pavg[1]-parts[i].pavg[0] > 0.25f || parts[i].pavg[1]-parts[i].pavg[0] < -0.25f)
+ {
+ part_change_type(i,x,y,PT_BGLA);
+ }
+ return 0;
+}
diff --git a/src/elements/glow.c b/src/elements/glow.c
new file mode 100644
index 0000000..621e5b1
--- /dev/null
+++ b/src/elements/glow.c
@@ -0,0 +1,24 @@
+#include <element.h>
+
+int update_GLOW(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_WATR&&5>(rand()%2000))
+ {
+ parts[i].type = PT_NONE;
+ part_change_type(r>>8,x+rx,y+ry,PT_DEUT);
+ parts[r>>8].life = 10;
+ }
+ }
+ if (parts[i].type==PT_NONE) {
+ kill_part(i);
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/elements/goo.c b/src/elements/goo.c
new file mode 100644
index 0000000..0818173
--- /dev/null
+++ b/src/elements/goo.c
@@ -0,0 +1,15 @@
+#include <element.h>
+
+int update_GOO(UPDATE_FUNC_ARGS) {
+ if (!parts[i].life)
+ {
+ if (pv[y/CELL][x/CELL]>1.0f)
+ {
+ float advection = 0.1f;
+ parts[i].vx += advection*vx[y/CELL][x/CELL];
+ parts[i].vy += advection*vy[y/CELL][x/CELL];
+ parts[i].life = rand()%80+300;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/hswc.c b/src/elements/hswc.c
new file mode 100644
index 0000000..5470e2d
--- /dev/null
+++ b/src/elements/hswc.c
@@ -0,0 +1,24 @@
+#include <element.h>
+
+int update_HSWC(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (parts[i].life==10)
+ {
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_HSWC)
+ {
+ if (parts[r>>8].life<10&&parts[r>>8].life>0)
+ parts[i].life = 9;
+ else if (parts[r>>8].life==0)
+ parts[r>>8].life = 10;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/ice.c b/src/elements/ice.c
new file mode 100644
index 0000000..5b792ce
--- /dev/null
+++ b/src/elements/ice.c
@@ -0,0 +1,23 @@
+#include <element.h>
+
+int update_ICEI(UPDATE_FUNC_ARGS) { //currently used for snow as well
+ int r, rx, ry;
+ if (parts[i].ctype==PT_FRZW)
+ {
+ parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_SALT || (r&0xFF)==PT_SLTW) && 1>(rand()%1000))
+ {
+ part_change_type(i,x,y,PT_SLTW);
+ part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/iron.c b/src/elements/iron.c
new file mode 100644
index 0000000..0be1e1f
--- /dev/null
+++ b/src/elements/iron.c
@@ -0,0 +1,25 @@
+#include <element.h>
+
+int update_IRON(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((((r&0xFF) == PT_SALT && 15>(rand()/(RAND_MAX/700))) ||
+ ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/2000))) ||
+ ((r&0xFF) == PT_WATR && 5 >(rand()/(RAND_MAX/6000))) ||
+ ((r&0xFF) == PT_O2 && 2 >(rand()/(RAND_MAX/500))) ||
+ ((r&0xFF) == PT_LO2))&&
+ (!(parts[i].life))
+ )
+ {
+ part_change_type(i,x,y,PT_BMTL);
+ parts[i].tmp=(rand()/(RAND_MAX/10))+20;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/isz.c b/src/elements/isz.c
new file mode 100644
index 0000000..348b78d
--- /dev/null
+++ b/src/elements/isz.c
@@ -0,0 +1,14 @@
+#include <element.h>
+
+int update_ISZ(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ
+ float rr, rrr;
+ if (1>rand()%200 && ((int)(-4.0f*(pv[y/CELL][x/CELL])))>(rand()%1000))
+ {
+ create_part(i, x, y, PT_PHOT);
+ rr = (rand()%228+128)/127.0f;
+ rrr = (rand()%360)*3.14159f/180.0f;
+ parts[i].vx = rr*cosf(rrr);
+ parts[i].vy = rr*sinf(rrr);
+ }
+ return 0;
+}
diff --git a/src/elements/lcry.c b/src/elements/lcry.c
new file mode 100644
index 0000000..a6d442f
--- /dev/null
+++ b/src/elements/lcry.c
@@ -0,0 +1,24 @@
+#include <element.h>
+
+int update_LCRY(UPDATE_FUNC_ARGS) {
+ if (parts[i].life==10)
+ {
+ int r, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_LCRY)
+ {
+ if (parts[r>>8].life<10&&parts[r>>8].life>0)
+ parts[i].life = 9;
+ else if (parts[r>>8].life==0)
+ parts[r>>8].life = 10;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/legacy.c b/src/elements/legacy.c
new file mode 100644
index 0000000..1a345dd
--- /dev/null
+++ b/src/elements/legacy.c
@@ -0,0 +1,120 @@
+#include <element.h>
+
+// Interactions which only occur when legacy_enable is on
+int update_legacy_all(UPDATE_FUNC_ARGS) {
+ if (!legacy_enable) return 0;
+ int r, rx, ry, rt;
+ int t = parts[i].type;
+ if (t==PT_WTRV) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_DSTW||(r&0xFF)==PT_SLTW) && 1>(rand()%1000))
+ {
+ part_change_type(i,x,y,PT_WATR);
+ part_change_type(r>>8,x+rx,y+ry,PT_WATR);
+ }
+ if (((r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW) && 1>(rand()%1000))
+ {
+ part_change_type(i,x,y,PT_WATR);
+ if (1>(rand()%1000))
+ part_change_type(r>>8,x+rx,y+ry,PT_WATR);
+ }
+ }
+ }
+ else if (t==PT_WATR) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10))
+ {
+ part_change_type(i,x,y,PT_WTRV);
+ }
+ }
+ }
+ else if (t==PT_SLTW) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10))
+ {
+ part_change_type(i,x,y,PT_SALT);
+ part_change_type(r>>8,x+rx,y+ry,PT_WTRV);
+ }
+ }
+ }
+ else if (t==PT_DSTW) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10))
+ {
+ part_change_type(i,x,y,PT_WTRV);
+ }
+ }
+ }
+ else if (t==PT_ICEI) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000))
+ {
+ part_change_type(i,x,y,PT_ICEI);
+ part_change_type(r>>8,x+rx,y+ry,PT_ICEI);
+ }
+ }
+ }
+ else if (t==PT_SNOW) {
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000))
+ {
+ part_change_type(i,x,y,PT_ICEI);
+ part_change_type(r>>8,x+rx,y+ry,PT_ICEI);
+ }
+ if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 15>(rand()%1000))
+ part_change_type(i,x,y,PT_WATR);
+ }
+ }
+ if (t==PT_WTRV && pv[y/CELL][x/CELL]>4.0f)
+ part_change_type(i,x,y,PT_DSTW);
+ if (t==PT_OIL && pv[y/CELL][x/CELL]<-6.0f)
+ part_change_type(i,x,y,PT_GAS);
+ if (t==PT_GAS && pv[y/CELL][x/CELL]>6.0f)
+ part_change_type(i,x,y,PT_OIL);
+ if (t==PT_DESL && pv[y/CELL][x/CELL]>12.0f)
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = rand()%50+120;
+ }
+ return 0;
+}
diff --git a/src/elements/misc.c b/src/elements/misc.c
new file mode 100644
index 0000000..a284b3a
--- /dev/null
+++ b/src/elements/misc.c
@@ -0,0 +1,12 @@
+#include <element.h>
+
+int update_MISC(UPDATE_FUNC_ARGS) {
+ int t = parts[i].type;
+ if (t==PT_LOVE)
+ ISLOVE=1;
+ else if (t==PT_LOLZ)
+ ISLOLZ=1;
+ else if (t==PT_GRAV)
+ ISGRAV=1;
+ return 0;
+}
diff --git a/src/elements/mort.c b/src/elements/mort.c
new file mode 100644
index 0000000..d215abc
--- /dev/null
+++ b/src/elements/mort.c
@@ -0,0 +1,6 @@
+#include <element.h>
+
+int update_MORT(UPDATE_FUNC_ARGS) {
+ create_part(-1, x, y-1, PT_SMKE);
+ return 0;
+}
diff --git a/src/elements/neut.c b/src/elements/neut.c
new file mode 100644
index 0000000..aa3ddf0
--- /dev/null
+++ b/src/elements/neut.c
@@ -0,0 +1,88 @@
+#include <element.h>
+
+int update_NEUT(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ int pressureFactor = 3 + (int)pv[y/CELL][x/CELL];
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW)
+ {
+ parts[i].vx *= 0.995;
+ parts[i].vy *= 0.995;
+ }
+ if ((r&0xFF)==PT_PLUT && pressureFactor>(rand()%1000))
+ {
+ if (33>rand()%100)
+ {
+ create_part(r>>8, x+rx, y+ry, rand()%3 ? PT_LAVA : PT_URAN);
+ parts[r>>8].temp = MAX_TEMP;
+ if (parts[r>>8].type==PT_LAVA) {
+ parts[r>>8].tmp = 100;
+ parts[r>>8].ctype = PT_PLUT;
+ }
+ }
+ else
+ {
+ create_part(r>>8, x+rx, y+ry, PT_NEUT);
+ parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx;
+ parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
+ }
+ pv[y/CELL][x/CELL] += 10.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough
+ update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
+ }
+ else if ((r&0xFF)==PT_DEUT && (pressureFactor+1)>(rand()%1000))
+ {
+#ifdef SDEUT
+ create_n_parts(parts[r>>8].life, x+rx, y+ry, parts[i].vx, parts[i].vy, PT_NEUT);
+#else
+ create_part(r>>8, x+rx, y+ry, PT_NEUT);
+ parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx;
+ parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
+ if (parts[r>>8].life>0)
+ {
+ parts[r>>8].life --;
+ parts[r>>8].temp += (parts[r>>8].life*17);
+ pv[y/CELL][x/CELL] += 6.0f * CFDS;
+ }
+ else
+ kill_part(r>>8);
+#endif
+ }
+ else if ((r&0xFF)==PT_GUNP && 15>(rand()%1000))
+ part_change_type(r>>8,x+rx,y+ry,PT_DUST);
+ else if ((r&0xFF)==PT_DYST && 15>(rand()%1000))
+ part_change_type(r>>8,x+rx,y+ry,PT_YEST);
+ else if ((r&0xFF)==PT_YEST)
+ part_change_type(r>>8,x+rx,y+ry,PT_DYST);
+ else if ((r&0xFF)==PT_WATR && 15>(rand()%100))
+ part_change_type(r>>8,x+rx,y+ry,PT_DSTW);
+ else if ((r&0xFF)==PT_PLEX && 15>(rand()%1000))
+ part_change_type(r>>8,x+rx,y+ry,PT_GOO);
+ else if ((r&0xFF)==PT_NITR && 15>(rand()%1000))
+ part_change_type(r>>8,x+rx,y+ry,PT_DESL);
+ else if ((r&0xFF)==PT_PLNT && 5>(rand()%100))
+ create_part(r>>8, x+rx, y+ry, PT_WOOD);
+ else if ((r&0xFF)==PT_DESL && 15>(rand()%1000))
+ part_change_type(r>>8,x+rx,y+ry,PT_GAS);
+ else if ((r&0xFF)==PT_COAL && 5>(rand()%100))
+ create_part(r>>8, x+rx, y+ry, PT_WOOD);
+ else if ((r&0xFF)==PT_DUST && 5>(rand()%100))
+ create_part(r>>8, x+rx, y+ry, PT_FWRK);
+ else if ((r&0xFF)==PT_FWRK && 5>(rand()%100))
+ create_part(r>>8, x+rx, y+ry, PT_DUST);
+ else if ((r&0xFF)==PT_ACID && 5>(rand()%100))
+ create_part(r>>8, x+rx, y+ry, PT_ISOZ);
+ /*if(parts[r>>8].type>1 && parts[r>>8].type!=PT_NEUT && parts[r>>8].type-1!=PT_NEUT && parts[r>>8].type-1!=PT_STKM &&
+ (ptypes[parts[r>>8].type-1].menusection==SC_LIQUID||
+ ptypes[parts[r>>8].type-1].menusection==SC_EXPLOSIVE||
+ ptypes[parts[r>>8].type-1].menusection==SC_GAS||
+ ptypes[parts[r>>8].type-1].menusection==SC_POWDERS) && 15>(rand()%1000))
+ parts[r>>8].type--;*/
+ }
+ return 0;
+}
diff --git a/src/elements/none.c b/src/elements/none.c
new file mode 100644
index 0000000..7049811
--- /dev/null
+++ b/src/elements/none.c
@@ -0,0 +1,6 @@
+#include <element.h>
+
+int update_(UPDATE_FUNC_ARGS) {
+
+ return 0;
+}
diff --git a/src/elements/nptct.c b/src/elements/nptct.c
new file mode 100644
index 0000000..95d4d9a
--- /dev/null
+++ b/src/elements/nptct.c
@@ -0,0 +1,7 @@
+#include <element.h>
+
+int update_NPTCT(UPDATE_FUNC_ARGS) {
+ if (parts[i].temp>295.0f)
+ parts[i].temp -= 2.5f;
+ return 0;
+}
diff --git a/src/elements/pcln.c b/src/elements/pcln.c
new file mode 100644
index 0000000..00e5db0
--- /dev/null
+++ b/src/elements/pcln.c
@@ -0,0 +1,65 @@
+#include <element.h>
+
+int update_PCLN(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SPRK)
+ {
+ if (parts[r>>8].ctype==PT_PSCN)
+ parts[i].life = 10;
+ else if (parts[r>>8].ctype==PT_NSCN)
+ parts[i].life = 9;
+ }
+ if ((r&0xFF)==PT_PCLN)
+ {
+ if (parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
+ parts[i].life = 9;
+ else if (parts[i].life==0&&parts[r>>8].life==10)
+ parts[i].life = 10;
+ }
+ }
+ if (!parts[i].ctype)
+ 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 &&
+ pmap[y+ry][x+rx] &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_CLNE &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_PCLN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_BCLN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_SPRK &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_NSCN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_PSCN &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_STKM &&
+ (pmap[y+ry][x+rx]&0xFF)!=PT_STKM2 &&
+ (pmap[y+ry][x+rx]&0xFF)!=0xFF)
+ parts[i].ctype = pmap[y+ry][x+rx]&0xFF;
+ if (parts[i].ctype && parts[i].life==10) {
+ if (parts[i].ctype==PT_PHOT) {
+ for (rx=-1; rx<2; rx++) {
+ for (ry=-1; ry<2; ry++) {
+ int r = create_part(-1, x+rx, y+ry, parts[i].ctype);
+ if (r!=-1) {
+ parts[r].vx = rx*3;
+ parts[r].vy = ry*3;
+ }
+ }
+ }
+ }
+ else if (ptypes[parts[i].ctype].properties&PROP_LIFE) {
+ for (rx=-1; rx<2; rx++) {
+ for (ry=-1; ry<2; ry++) {
+ create_part(-1, x+rx, y+ry, parts[i].ctype);
+ }
+ }
+ } else {
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/phot.c b/src/elements/phot.c
new file mode 100644
index 0000000..7b7afc6
--- /dev/null
+++ b/src/elements/phot.c
@@ -0,0 +1,43 @@
+#include <element.h>
+
+int update_PHOT(UPDATE_FUNC_ARGS) {
+ if (1>rand()%10) update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
+ int r, rt, rx, ry;
+ float rr, rrr;
+ 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)) {
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_ISOZ && 5>(rand()%2000))
+ {
+ parts[i].vx *= 0.90;
+ parts[i].vy *= 0.90;
+ create_part(r>>8, x+rx, y+ry, PT_PHOT);
+ rrr = (rand()%360)*3.14159f/180.0f;
+ rr = (rand()%128+128)/127.0f;
+ parts[r>>8].vx = rr*cosf(rrr);
+ parts[r>>8].vy = rr*sinf(rrr);
+ pv[y/CELL][x/CELL] -= 15.0f * CFDS;
+ }
+ if ((r&0xFF)==PT_ISZS && 5>(rand()%2000))
+ {
+ parts[i].vx *= 0.90;
+ parts[i].vy *= 0.90;
+ create_part(r>>8, x+rx, y+ry, PT_PHOT);
+ rr = (rand()%228+128)/127.0f;
+ rrr = (rand()%360)*3.14159f/180.0f;
+ parts[r>>8].vx = rr*cosf(rrr);
+ parts[r>>8].vy = rr*sinf(rrr);
+ pv[y/CELL][x/CELL] -= 15.0f * CFDS;
+ }
+ }
+ r = pmap[y][x];
+ rt = r&0xFF;
+ if (rt==PT_CLNE || rt==PT_PCLN || rt==PT_BCLN) {
+ if (!parts[r>>8].ctype)
+ parts[r>>8].ctype = PT_PHOT;
+ }
+
+ return 0;
+}
diff --git a/src/elements/pipe.c b/src/elements/pipe.c
new file mode 100644
index 0000000..7d709aa
--- /dev/null
+++ b/src/elements/pipe.c
@@ -0,0 +1,122 @@
+#include <element.h>
+
+int update_PIPE(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, np, trade, q, ctype;
+ if (!parts[i].ctype && parts[i].life<=10)
+ {
+ if (parts[i].temp<272.15)
+ {
+ if (parts[i].temp>173.25&&parts[i].temp<273.15)
+ {
+ parts[i].ctype = 2;
+ parts[i].life = 0;
+ }
+ if (parts[i].temp>73.25&&parts[i].temp<=173.15)
+ {
+ parts[i].ctype = 3;
+ parts[i].life = 0;
+ }
+ if (parts[i].temp>=0&&parts[i].temp<=73.15)
+ {
+ parts[i].ctype = 4;
+ parts[i].life = 0;
+ }
+ }
+ else
+ {
+ 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>>8)>=NPART )
+ continue;
+ if (!r)
+ create_part(-1,x+rx,y+ry,PT_BRCK);
+ }
+ if (parts[i].life==1)
+ parts[i].ctype = 1;
+ }
+ }
+ if (parts[i].ctype==1)
+ {
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if (!r&&!parts[i].life)
+ parts[i].life=50;
+ }
+ if (parts[i].life==2)
+ {
+ parts[i].ctype = 2;
+ parts[i].life = 6;
+ }
+ }
+ if (parts[i].ctype>1)
+ for ( q = 0; q<3; q++)
+ for ( ctype = 2; ctype<5; ctype++)
+ {
+ if (parts[i].ctype==ctype)
+ {
+ if (parts[i].life==3)
+ {
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_PIPE&&parts[r>>8].ctype==1)
+ {
+ parts[r>>8].ctype = (((ctype)%3)+2);//reverse
+ parts[r>>8].life = 6;
+ }
+ }
+ }
+ else
+ {
+ rx = rand()%3-1;
+ ry = rand()%3-1;
+ 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)
+ continue;
+ else if (!r&&parts[i].tmp!=0)
+ {
+ np = create_part(-1,x+rx,y+ry,parts[i].tmp);
+ if (np!=-1)
+ {
+ parts[np].temp = parts[i].temp;//pipe saves temp and life now
+ parts[np].life = parts[i].flags;
+ }
+ parts[i].tmp = 0;
+ continue;
+ }
+ else if (!r)
+ continue;
+ else if (parts[i].tmp == 0 && (ptypes[r&0xFF].falldown!= 0 || ptypes[r&0xFF].state == ST_GAS))
+ {
+ parts[i].tmp = parts[r>>8].type;
+ parts[i].temp = parts[r>>8].temp;
+ parts[i].flags = parts[r>>8].life;
+ kill_part(r>>8);
+ }
+ else if ((r&0xFF)==PT_PIPE && parts[r>>8].ctype!=(((ctype)%3)+2) && parts[r>>8].tmp==0&&parts[i].tmp>0)
+ {
+ parts[r>>8].tmp = parts[i].tmp;
+ parts[r>>8].temp = parts[i].temp;
+ parts[r>>8].flags = parts[i].flags;
+ parts[i].tmp = 0;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/plnt.c b/src/elements/plnt.c
new file mode 100644
index 0000000..2ca38dd
--- /dev/null
+++ b/src/elements/plnt.c
@@ -0,0 +1,57 @@
+#include <element.h>
+
+int update_PLNT(UPDATE_FUNC_ARGS) {
+ int r, rx, ry, np;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_WATR && 1>(rand()%250))
+ {
+ np = create_part(r>>8,x+rx,y+ry,PT_PLNT);
+ if (np<0) continue;
+ parts[np].life = 0;
+ }
+ else if ((r&0xFF)==PT_LAVA && 1>(rand()%250))
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = 4;
+ }
+ else if ((r&0xFF)==PT_SMKE && (1>rand()%250))
+ {
+ kill_part(r>>8);
+ parts[i].life = rand()%60 + 60;
+ }
+ else if ((r&0xFF)==PT_WOOD && (1>rand()%20) && abs(rx+ry)<=2 && VINE_MODE)
+ {
+ int nnx = rand()%3 -1;
+ int nny = rand()%3 -1;
+ if (x+rx+nnx>=0 && y+ry+nny>0 && x+rx+nnx<XRES && y+ry+nny<YRES && (nnx || nny))
+ {
+ if ((pmap[y+ry+nny][x+rx+nnx]>>8)>=NPART||pmap[y+ry+nny][x+rx+nnx])
+ continue;
+ np = create_part(-1,x+rx+nnx,y+ry+nny,PT_VINE);
+ if (np<0) continue;
+ parts[np].temp = parts[i].temp;
+ }
+ }
+ }
+ if (parts[i].life==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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if (!r)
+ create_part(-1,x+rx,y+ry,PT_O2);
+ }
+ parts[i].life = 0;
+ }
+ return 0;
+}
diff --git a/src/elements/plut.c b/src/elements/plut.c
new file mode 100644
index 0000000..cbc9b7b
--- /dev/null
+++ b/src/elements/plut.c
@@ -0,0 +1,9 @@
+#include <element.h>
+
+int update_PLUT(UPDATE_FUNC_ARGS) {
+ if (1>rand()%100 && ((int)(5.0f*pv[y/CELL][x/CELL]))>(rand()%1000))
+ {
+ create_part(i, x, y, PT_NEUT);
+ }
+ return 0;
+}
diff --git a/src/elements/prti.c b/src/elements/prti.c
new file mode 100644
index 0000000..b25f7a3
--- /dev/null
+++ b/src/elements/prti.c
@@ -0,0 +1,30 @@
+#include <element.h>
+
+int update_PRTI(UPDATE_FUNC_ARGS) {
+ int r, nnx, rx, ry;
+ int count =0;
+ parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ count ++;
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SPRK || ((r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO && (ptypes[r&0xFF].falldown!= 0 || ptypes[r&0xFF].state == ST_GAS)))
+ for ( nnx=0; nnx<80; nnx++)
+ if (!portal[parts[i].tmp][count-1][nnx])
+ {
+ portal[parts[i].tmp][count-1][nnx] = parts[r>>8].type;
+ portaltemp[parts[i].tmp][count-1][nnx] = parts[r>>8].temp;
+ portalctype[parts[i].tmp][count-1][nnx] = parts[r>>8].ctype;
+ if ((r&0xFF)==PT_SPRK)
+ part_change_type(r>>8,x+rx,y+ry,parts[r>>8].ctype);
+ else
+ kill_part(r>>8);
+ break;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/prto.c b/src/elements/prto.c
new file mode 100644
index 0000000..2da6e00
--- /dev/null
+++ b/src/elements/prto.c
@@ -0,0 +1,53 @@
+#include <element.h>
+
+int update_PRTO(UPDATE_FUNC_ARGS) {
+ int r, nnx, rx, ry, np;
+ int count = 0;
+ parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ count ++;
+ if ((r>>8)>=NPART || r)
+ continue;
+ if (!r)
+ {
+ for ( nnx =0 ; nnx<80; nnx++)
+ {
+ int randomness = count + rand()%3-1;
+ if (randomness<1)
+ randomness=1;
+ if (randomness>8)
+ randomness=8;
+ if (portal[parts[i].tmp][randomness-1][nnx]==PT_SPRK)// TODO: make it look better
+ {
+ create_part(-1,x+1,y,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x+1,y+1,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x+1,y-1,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x,y-1,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x,y+1,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x-1,y+1,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x-1,y,portal[parts[i].tmp][randomness-1][nnx]);
+ create_part(-1,x-1,y-1,portal[parts[i].tmp][randomness-1][nnx]);
+ portal[parts[i].tmp][randomness-1][nnx] = 0;
+ portaltemp[parts[i].tmp][randomness-1][nnx] = 0;
+ break;
+ }
+ else if (portal[parts[i].tmp][randomness-1][nnx])
+ {
+ np = create_part(-1,x+rx,y+ry,portal[parts[i].tmp][randomness-1][nnx]);
+ if (np<0) continue;
+ parts[np].temp = portaltemp[parts[i].tmp][randomness-1][nnx];
+ parts[np].ctype = portalctype[parts[i].tmp][randomness-1][nnx];
+ portal[parts[i].tmp][randomness-1][nnx] = 0;
+ portaltemp[parts[i].tmp][randomness-1][nnx] = 0;
+ portalctype[parts[i].tmp][randomness-1][nnx] = 0;
+ break;
+ }
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/pump.c b/src/elements/pump.c
new file mode 100644
index 0000000..244ca8f
--- /dev/null
+++ b/src/elements/pump.c
@@ -0,0 +1,39 @@
+#include <element.h>
+
+int update_PUMP(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ if (parts[i].life==10)
+ {
+ if (parts[i].temp>=256.0+273.15)
+ parts[i].temp=256.0+273.15;
+ if (parts[i].temp<= -256.0+273.15)
+ parts[i].temp = -256.0+273.15;
+
+ if (pv[y/CELL][x/CELL]<(parts[i].temp-273.15))
+ pv[y/CELL][x/CELL] += 0.1f*((parts[i].temp-273.15)-pv[y/CELL][x/CELL]);
+ if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<(parts[i].temp-273.15))
+ pv[y/CELL+1][x/CELL] += 0.1f*((parts[i].temp-273.15)-pv[y/CELL+1][x/CELL]);
+ if (x+CELL<XRES)
+ {
+ pv[y/CELL][x/CELL+1] += 0.1f*((parts[i].temp-273.15)-pv[y/CELL][x/CELL+1]);
+ if (y+CELL<YRES)
+ pv[y/CELL+1][x/CELL+1] += 0.1f*((parts[i].temp-273.15)-pv[y/CELL+1][x/CELL+1]);
+ }
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_PUMP)
+ {
+ if (parts[r>>8].life<10&&parts[r>>8].life>0)
+ parts[i].life = 9;
+ else if (parts[r>>8].life==0)
+ parts[r>>8].life = 10;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/pyro.c b/src/elements/pyro.c
new file mode 100644
index 0000000..0fe1def
--- /dev/null
+++ b/src/elements/pyro.c
@@ -0,0 +1,111 @@
+#include <element.h>
+
+int update_PYRO(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)
+ {
+ t = PT_NBLE;
+ part_change_type(i,x,y,t);
+ parts[i].life = 0;
+ }
+ if (t==PT_FIRE && parts[i].life <=1 && parts[i].temp<625)
+ {
+ t = PT_SMKE;
+ part_change_type(i,x,y,t);
+ parts[i].life = rand()%20+250;
+ }
+ 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>>8)>=NPART || !r)
+ continue;
+ if (bmap[(y+ry)/CELL][(x+rx)/CELL] && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM)
+ continue;
+ rt = parts[r>>8].type;
+ if ((surround_space || ptypes[rt].explosive) && (t!=PT_SPRK || (rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL && rt!=PT_SWCH)) &&
+ !(t==PT_PHOT && rt==PT_INSL) &&
+ (t!=PT_LAVA || parts[i].life>0 || (rt!=PT_STNE && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SWCH && rt!=PT_INWR && rt!=PT_QRTZ))
+ && !(rt==PT_SPNG && parts[r>>8].life>0) &&
+ ptypes[rt].flammable && (ptypes[rt].flammable + (int)(pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000))
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_FIRE);
+ parts[r>>8].temp = restrict_flt(ptypes[PT_FIRE].heat + (ptypes[rt].flammable/2), MIN_TEMP, MAX_TEMP);
+ parts[r>>8].life = rand()%80+180;
+ if (ptypes[rt].explosive)
+ pv[y/CELL][x/CELL] += 0.25f * CFDS;
+ continue;
+ }
+ }
+ if (legacy_enable) update_legacy_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
+ return 0;
+}
+
+int update_legacy_PYRO(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 (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)
+ continue;
+ if (bmap[(y+ry)/CELL][(x+rx)/CELL] && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM)
+ continue;
+ rt = r&0xFF;
+ lpv = (int)pv[(y+ry)/CELL][(x+rx)/CELL];
+ if (lpv < 1) lpv = 1;
+ if (t!=PT_SPRK && ptypes[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)) &&
+ ptypes[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 = (parts[r>>8].ctype==PT_SAND)?PT_GLAS:parts[r>>8].ctype;
+ part_change_type(r>>8,x+rx,y+ry,PT_LAVA);
+ parts[r>>8].life = rand()%120+240;
+ }
+ else
+ {
+ parts[i].life = 0;
+ t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE;
+ parts[i].ctype = PT_NONE;//rt;
+ part_change_type(i,x,y,t);
+ return 1;
+ }
+ }
+ if (t!=PT_SPRK && (rt==PT_ICEI || rt==PT_SNOW))
+ {
+ parts[r>>8].type = PT_WATR;
+ if (t==PT_FIRE)
+ {
+ kill_part(i);
+ return 1;
+ }
+ if (t==PT_LAVA)
+ {
+ parts[i].life = 0;
+ t = parts[i].type = PT_STNE;
+ part_change_type(i,x,y,t);
+ }
+ }
+ if (t!=PT_SPRK && (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW))
+ {
+ kill_part(r>>8);
+ if (t==PT_FIRE)
+ {
+ kill_part(i);
+ return 1;
+ }
+ 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;
+ part_change_type(i,x,y,t);
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/qrtz.c b/src/elements/qrtz.c
new file mode 100644
index 0000000..74d8c99
--- /dev/null
+++ b/src/elements/qrtz.c
@@ -0,0 +1,11 @@
+#include <element.h>
+
+int update_QRTZ(UPDATE_FUNC_ARGS) {
+ parts[i].pavg[0] = parts[i].pavg[1];
+ parts[i].pavg[1] = pv[y/CELL][x/CELL];
+ if (parts[i].pavg[1]-parts[i].pavg[0] > 0.05*(parts[i].temp/3) || parts[i].pavg[1]-parts[i].pavg[0] < -0.05*(parts[i].temp/3))
+ {
+ part_change_type(i,x,y,PT_PQRT);
+ }
+ return 0;
+}
diff --git a/src/elements/rime.c b/src/elements/rime.c
new file mode 100644
index 0000000..e0337e5
--- /dev/null
+++ b/src/elements/rime.c
@@ -0,0 +1,26 @@
+#include <element.h>
+
+int update_RIME(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ parts[i].vx = 0;
+ parts[i].vy = 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SPRK)
+ {
+ part_change_type(i,x,y,PT_FOG);
+ parts[i].life = rand()%50 + 60;
+ }
+ else if ((r&0xFF)==PT_FOG&&parts[r>>8].life>0)
+ {
+ part_change_type(i,x,y,PT_FOG);
+ parts[i].life = parts[r>>8].life;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/shld.c b/src/elements/shld.c
new file mode 100644
index 0000000..81b9f1b
--- /dev/null
+++ b/src/elements/shld.c
@@ -0,0 +1,168 @@
+#include <element.h>
+
+int update_SHLD1(UPDATE_FUNC_ARGS) {
+ int r, nnx, nny, rx, ry;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
+ {
+ if (55>rand()%200&&parts[i].life==0)
+ {
+ part_change_type(i,x,y,PT_SHLD2);
+ parts[i].life = 7;
+ }
+ for ( nnx=-1; nnx<2; nnx++)
+ for ( nny=-1; nny<2; nny++)
+ {
+ if (!pmap[y+ry+nny][x+rx+nnx])
+ {
+ create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
+ //parts[pmap[y+ny+nny][x+nx+nnx]>>8].life=7;
+ }
+ }
+ }
+ else if ((r&0xFF)==PT_SHLD3&&4>rand()%10)
+ {
+ part_change_type(i,x,y,PT_SHLD2);
+ parts[i].life = 7;
+ }
+ }
+ return 0;
+}
+
+int update_SHLD2(UPDATE_FUNC_ARGS) {
+ int r, nnx, nny, rx, ry, np;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if (!r && parts[i].life>0)
+ create_part(-1,x+rx,y+ry,PT_SHLD1);
+ if (!r)
+ continue;
+ else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
+ {
+ if (25>rand()%200&&parts[i].life==0)
+ {
+ part_change_type(i,x,y,PT_SHLD3);
+ parts[i].life = 7;
+ }
+ for ( nnx=-1; nnx<2; nnx++)
+ for ( nny=-1; nny<2; nny++)
+ {
+ if (!pmap[y+ry+nny][x+rx+nnx])
+ {
+ np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
+ if (np<0) continue;
+ parts[np].life=7;
+ }
+ }
+ }
+ else if ((r&0xFF)==PT_SHLD4&&4>rand()%10)
+ {
+ part_change_type(i,x,y,PT_SHLD3);
+ parts[i].life = 7;
+ }
+ }
+ return 0;
+}
+
+int update_SHLD3(UPDATE_FUNC_ARGS) {
+ int r, nnx, nny, rx, ry, np;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if (!r)
+ {
+ if (1>rand()%2500)
+ {
+ np = create_part(-1,x+rx,y+ry,PT_SHLD1);
+ if (np<0) continue;
+ parts[np].life=7;
+ part_change_type(i,x,y,PT_SHLD2);
+ }
+ else
+ continue;
+
+ }
+ if ((r&0xFF)==PT_SHLD1 && parts[i].life>3)
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_SHLD2);
+ parts[r>>8].life=7;
+ }
+ else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
+ {
+ if (18>rand()%3000&&parts[i].life==0)
+ {
+ part_change_type(i,x,y,PT_SHLD4);
+ parts[i].life = 7;
+ }
+ for ( nnx=-1; nnx<2; nnx++)
+ for ( nny=-1; nny<2; nny++)
+ {
+
+ if (!pmap[y+ry+nny][x+rx+nnx])
+ {
+ np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
+ if (np<0) continue;
+ parts[np].life=7;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+int update_SHLD4(UPDATE_FUNC_ARGS) {
+ int r, nnx, nny, rx, ry, np;
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if (!r)
+ {
+ if (1>rand()%5500)
+ {
+ np = create_part(-1,x+rx,y+ry,PT_SHLD1);
+ if (np<0) continue;
+ parts[np].life=7;
+ part_change_type(i,x,y,PT_SHLD2);
+ }
+ else
+ continue;
+
+ }
+ if ((r&0xFF)==PT_SHLD2 && parts[i].life>3)
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_SHLD3);
+ parts[r>>8].life = 7;
+ }
+ else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
+ for ( nnx=-1; nnx<2; nnx++)
+ for ( nny=-1; nny<2; nny++)
+ {
+ if (!pmap[y+ry+nny][x+rx+nnx])
+ {
+ np = 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/elements/sing.c b/src/elements/sing.c
new file mode 100644
index 0000000..02f5eaf
--- /dev/null
+++ b/src/elements/sing.c
@@ -0,0 +1,59 @@
+#include <element.h>
+
+int update_SING(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ int singularity = -parts[i].life;
+
+ if (pv[y/CELL][x/CELL]<singularity)
+ pv[y/CELL][x/CELL] += 0.1f*(singularity-pv[y/CELL][x/CELL]);
+ if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<singularity)
+ pv[y/CELL+1][x/CELL] += 0.1f*(singularity-pv[y/CELL+1][x/CELL]);
+ if (x+CELL<XRES)
+ {
+ pv[y/CELL][x/CELL+1] += 0.1f*(singularity-pv[y/CELL][x/CELL+1]);
+ if (y+CELL<YRES)
+ pv[y/CELL+1][x/CELL+1] += 0.1f*(singularity-pv[y/CELL+1][x/CELL+1]);
+ }
+ if (y+CELL>0 && pv[y/CELL-1][x/CELL]<singularity)
+ pv[y/CELL-1][x/CELL] += 0.1f*(singularity-pv[y/CELL-1][x/CELL]);
+ if (x+CELL>0)
+ {
+ pv[y/CELL][x/CELL-1] += 0.1f*(singularity-pv[y/CELL][x/CELL-1]);
+ if (y+CELL>0)
+ pv[y/CELL-1][x/CELL-1] += 0.1f*(singularity-pv[y/CELL-1][x/CELL-1]);
+ }
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)!=PT_DMND&&33>=rand()/(RAND_MAX/100)+1)
+ {
+ if ((r&0xFF)==PT_SING && parts[r>>8].life >10)
+ {
+ if (parts[i].life+parts[r>>8].life > 255)
+ continue;
+ parts[i].life += parts[r>>8].life;
+ }
+ else
+ {
+ if (parts[i].life+3 > 255)
+ {
+ if (parts[r>>8].type!=PT_SING && 1>rand()%100)
+ {
+ int np;
+ np = create_part(r>>8,x+rx,y+ry,PT_SING);
+ parts[np].life = rand()%50+60;
+ }
+ continue;
+ }
+ parts[i].life += 3;
+ }
+ parts[i].temp = restrict_flt(parts[r>>8].temp+parts[i].temp, MIN_TEMP, MAX_TEMP);
+ kill_part(r>>8);
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/sltw.c b/src/elements/sltw.c
new file mode 100644
index 0000000..b6d18bb
--- /dev/null
+++ b/src/elements/sltw.c
@@ -0,0 +1,23 @@
+#include <element.h>
+
+int update_SLTW(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SALT && 1>(rand()%10000))
+ kill_part(r>>8);
+ if ((r&0xFF)==PT_PLNT&&5>(rand()%1000))
+ kill_part(r>>8);
+ if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !legacy_enable && parts[i].temp>(273.15f+12.0f) && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = 4;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/spng.c b/src/elements/spng.c
new file mode 100644
index 0000000..5bc7e95
--- /dev/null
+++ b/src/elements/spng.c
@@ -0,0 +1,97 @@
+#include <element.h>
+
+int update_SPNG(UPDATE_FUNC_ARGS) {
+ int r, trade, rx, ry, tmp;
+ if (pv[y/CELL][x/CELL]<=3&&pv[y/CELL][x/CELL]>=-3&&parts[i].temp<=374.0f)
+ {
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r || parts[i].temp>374.0f)
+ continue;
+ if ((r&0xFF)==PT_WATR&&33>=rand()/(RAND_MAX/100)+1)
+ {
+ parts[i].life++;
+ kill_part(r>>8);
+ }
+ }
+ }
+ else
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if ((bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_WALLELEC||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_EWALL||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_DESTROYALL||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_WALL||
+ bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWAIR||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWSOLID||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWGAS))
+ continue;
+ if ((!r)&&parts[i].life>=1)//if nothing then create water
+ {
+ create_part(-1,x+rx,y+ry,PT_WATR);
+ parts[i].life--;
+ }
+ }
+ for ( trade = 0; trade<9; trade ++)
+ {
+ rx = rand()%5-2;
+ ry = rand()%5-2;
+ 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)
+ continue;
+ if ((r&0xFF)==PT_SPNG&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
+ {
+ tmp = parts[i].life - parts[r>>8].life;
+ if (tmp ==1)
+ {
+ parts[r>>8].life ++;
+ parts[i].life --;
+ trade = 9;
+ }
+ else if (tmp>0)
+ {
+ parts[r>>8].life += tmp/2;
+ parts[i].life -= tmp/2;
+ trade = 9;
+ }
+ }
+ }
+ }
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_FIRE&&parts[i].life>0)
+ {
+ if (parts[i].life<=2)
+ parts[i].life --;
+ parts[i].life -= parts[i].life/3;
+ }
+ }
+ if (parts[i].temp>=374)
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART)
+ continue;
+ if ((bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_WALLELEC||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWLIQUID||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_DESTROYALL||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_WALL||bmap[(y+ry)/CELL][(x+rx)/CELL]==WL_ALLOWSOLID))
+ continue;
+ if ((!r)&&parts[i].life>=1)//if nothing then create steam
+ {
+ create_part(-1,x+rx,y+ry,PT_WTRV);
+ parts[i].life--;
+ parts[i].temp -= 40.0f;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/sprk.c b/src/elements/sprk.c
new file mode 100644
index 0000000..0f3c6c7
--- /dev/null
+++ b/src/elements/sprk.c
@@ -0,0 +1,168 @@
+#include <element.h>
+
+int update_SPRK(UPDATE_FUNC_ARGS) {
+ update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
+ int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype;
+ if (parts[i].life<=0)
+ {
+ if (ct==PT_WATR||ct==PT_SLTW||ct==PT_PSCN||ct==PT_NSCN||ct==PT_ETRD)
+ parts[i].temp = R_TEMP + 273.15f;
+ if (!ct)
+ ct = PT_METL;
+ part_change_type(i,x,y,ct);
+ parts[i].life = 4;
+ if (ct == PT_WATR)
+ parts[i].life = 64;
+ if (ct == PT_SLTW)
+ parts[i].life = 54;
+ if (ct == PT_SWCH)
+ parts[i].life = 14;
+ return 0;
+ }
+ if (ct==PT_SPRK)
+ {
+ kill_part(i);
+ return 1;
+ }
+ else if (ct==PT_ETRD&&parts[i].life==1)
+ {
+ nearp = nearest_part(i, PT_ETRD);
+ if (nearp!=-1&&parts_avg(i, nearp, PT_INSL)!=PT_INSL)
+ {
+ create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM);
+ part_change_type(i,x,y,ct);
+ ct = parts[i].ctype = PT_NONE;
+ parts[i].life = 20;
+ part_change_type(nearp,(int)(parts[nearp].x+0.5f),(int)(parts[nearp].y+0.5f),PT_SPRK);
+ parts[nearp].life = 9;
+ parts[nearp].ctype = PT_ETRD;
+ }
+ }
+ else if (ct==PT_NBLE&&parts[i].life<=1)
+ {
+ parts[i].life = rand()%150+50;
+ part_change_type(i,x,y,PT_PLSM);
+ parts[i].ctype = PT_NBLE;
+ parts[i].temp = 3500;
+ pv[y/CELL][x/CELL] += 1;
+ }
+ else if (ct==PT_IRON) {
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) ||
+ ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) ||
+ ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000))))
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_O2);
+ //parts[r>>8].tmp=(rand()/(RAND_MAX/10))+20;
+ }
+ }
+ }
+ 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>>8)>=NPART || !r)
+ continue;
+ rt = parts[r>>8].type;
+ conduct_sprk = 1;
+
+
+ pavg = parts_avg(r>>8, i,PT_INSL);
+ if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL) // make sparked SWCH turn off correctly
+ {
+ if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) {
+ parts[r>>8].life = 10;
+ }
+ if (ct==PT_NSCN) {
+ part_change_type(r>>8,x+rx,y+ry,PT_SWCH);
+ parts[r>>8].ctype = PT_NONE;
+ parts[r>>8].life = 9;
+ }
+ }
+ else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_HSWC||(rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2)))
+ {
+ if (ct==PT_PSCN) parts[r>>8].life = 10;
+ else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9;
+ }
+
+
+ // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed
+
+ if (pavg == PT_INSL) conduct_sprk = 0;
+ if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST)) conduct_sprk = 0;
+ if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH)
+ conduct_sprk = 0;
+
+
+ if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))))
+ {
+ parts[r>>8].temp = 473.0f;
+ if (rt==PT_NTCT||rt==PT_PTCT)
+ conduct_sprk = 0;
+ }
+ if (ct==PT_NTCT && !(rt==PT_PSCN || rt==PT_NTCT || (rt==PT_NSCN&&parts[i].temp>373.0f)))
+ conduct_sprk = 0;
+ if (ct==PT_PTCT && !(rt==PT_PSCN || rt==PT_PTCT || (rt==PT_NSCN&&parts[i].temp<373.0f)))
+ conduct_sprk = 0;
+ if (ct==PT_INWR && !(rt==PT_NSCN || rt==PT_INWR || rt==PT_PSCN))
+ conduct_sprk = 0;
+ if (ct==PT_NSCN && rt==PT_PSCN)
+ conduct_sprk = 0;
+ if (ct==PT_ETRD && (parts[i].life!=5||!(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN)))
+ conduct_sprk = 0;
+ if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0;
+ if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR))
+ conduct_sprk = 0;
+ if (rt==PT_QRTZ && !((ct==PT_NSCN||ct==PT_METL||ct==PT_PSCN||ct==PT_QRTZ) && (parts[r>>8].temp<173.15||pv[(y+ry)/CELL][(x+rx)/CELL]>8)))
+ conduct_sprk = 0;
+ if (rt==PT_NTCT && !(ct==PT_NSCN || ct==PT_NTCT || (ct==PT_PSCN&&parts[r>>8].temp>373.0f)))
+ conduct_sprk = 0;
+ if (rt==PT_PTCT && !(ct==PT_NSCN || ct==PT_PTCT || (ct==PT_PSCN&&parts[r>>8].temp<373.0f)))
+ conduct_sprk = 0;
+ if (rt==PT_INWR && !(ct==PT_NSCN || ct==PT_INWR || ct==PT_PSCN))
+ conduct_sprk = 0;
+ if (rt==PT_INST&&ct!=PT_PSCN)
+ conduct_sprk = 0;
+
+ if (conduct_sprk) {
+ if (ct==PT_ETRD) {
+ part_change_type(i,x,y,PT_ETRD);
+ parts[i].ctype = PT_NONE;
+ parts[i].life = 20;
+ part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ parts[r>>8].life = 4;
+ parts[r>>8].ctype = rt;
+ }
+ else if (rt==PT_WATR||rt==PT_SLTW) {
+ if (parts[r>>8].life==0 && (parts[i].life<2 || ((r>>8)<i && parts[i].life<3)))
+ {
+ part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ if (rt==PT_WATR) parts[r>>8].life = 6;
+ else parts[r>>8].life = 5;
+ parts[r>>8].ctype = rt;
+ }
+ }
+ else if (rt==PT_INST) {
+ if (parts[i].life>=3&&parts[r>>8].life==0)
+ {
+ flood_parts(x+rx,y+ry,PT_SPRK,PT_INST,-1);//spark the wire
+ }
+ }
+ else if (parts[r>>8].life==0 && (parts[i].life<3 || ((r>>8)<i && parts[i].life<4))) {
+ parts[r>>8].life = 4;
+ parts[r>>8].ctype = rt;
+ part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ if (parts[r>>8].temp+10.0f<673.0f&&!legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON))
+ parts[r>>8].temp = parts[r>>8].temp+10.0f;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/stkm.c b/src/elements/stkm.c
new file mode 100644
index 0000000..6d6b4ab
--- /dev/null
+++ b/src/elements/stkm.c
@@ -0,0 +1,412 @@
+#include <element.h>
+
+int update_SPAWN(UPDATE_FUNC_ARGS) {
+ ISSPAWN1 = 1;
+ if (death)
+ {
+ playerspawn = create_part(-1,x,y,PT_STKM);
+ isplayer = 1;
+ death = 0;
+ }
+ return 0;
+}
+
+int update_STKM(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ float pp, d;
+ float dt = 0.9;///(FPSB*FPSB); //Delta time in square
+ //Tempirature handling
+ if (parts[i].temp<243)
+ parts[i].life -= 1;
+ if ((parts[i].temp<309.6f) && (parts[i].temp>=243))
+ parts[i].temp += 1;
+
+ if (isplayer) { //Already a stickman in the simulation
+ death = 1;
+ parts[i].type = PT_NONE;
+ }
+
+ //Death
+ if (parts[i].life<1 || death || (pv[y/CELL][x/CELL]>=4.5f && player[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind...
+ {
+ for (r=-2; r<=1; r++)
+ {
+ create_part(-1, x+r, y-2, player[2]);
+ create_part(-1, x+r+1, y+2, player[2]);
+ create_part(-1, x-2, y+r+1, player[2]);
+ create_part(-1, x+2, y+r, player[2]);
+ }
+ kill_part(i); //Kill him
+ return 1;
+ }
+
+ parts[i].vy += -0.7*dt; //Head up!
+
+ //Verlet integration
+ pp = 2*player[3]-player[5]+player[19]*dt*dt;;
+ player[5] = player[3];
+ player[3] = pp;
+ pp = 2*player[4]-player[6]+player[20]*dt*dt;;
+ player[6] = player[4];
+ player[4] = pp;
+
+ pp = 2*player[7]-player[9]+player[21]*dt*dt;;
+ player[9] = player[7];
+ player[7] = pp;
+ pp = 2*player[8]-player[10]+(player[22]+1)*dt*dt;;
+ player[10] = player[8];
+ player[8] = pp;
+
+ pp = 2*player[11]-player[13]+player[23]*dt*dt;;
+ player[13] = player[11];
+ player[11] = pp;
+ pp = 2*player[12]-player[14]+player[24]*dt*dt;;
+ player[14] = player[12];
+ player[12] = pp;
+
+ pp = 2*player[15]-player[17]+player[25]*dt*dt;;
+ player[17] = player[15];
+ player[15] = pp;
+ pp = 2*player[16]-player[18]+(player[26]+1)*dt*dt;;
+ player[18] = player[16];
+ player[16] = pp;
+
+ //Setting acceleration to 0
+ player[19] = 0;
+ player[20] = 0;
+
+ player[21] = 0;
+ player[22] = 0;
+
+ player[23] = 0;
+ player[24] = 0;
+
+ player[25] = 0;
+ player[26] = 0;
+
+ //Go left
+ if (((int)(player[0])&0x01) == 0x01 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS)
+ {
+ if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID
+ && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG)
+ {
+ if (pmap[(int)(player[8]-1)][(int)(player[7])])
+ {
+ player[21] = -3;
+ player[22] = -2;
+ player[19] = -2;
+ }
+
+ if (pmap[(int)(player[16]-1)][(int)(player[15])])
+ {
+ player[25] = -3;
+ player[26] = -2;
+ player[23] = -2;
+ }
+ }
+ else
+ {
+ if (pmap[(int)(player[8]-1)][(int)(player[7])]) //It should move another way in liquids
+ {
+ player[21] = -1;
+ player[22] = -1;
+ player[19] = -1;
+ }
+
+ if (pmap[(int)(player[16]-1)][(int)(player[15])])
+ {
+ player[25] = -1;
+ player[26] = -1;
+ player[23] = -1;
+ }
+ }
+ }
+
+ //Go right
+ if (((int)(player[0])&0x02) == 0x02 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS)
+ {
+ if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID
+ && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG)
+ {
+ if (pmap[(int)(player[8]-1)][(int)(player[7])])
+ {
+ player[21] = 3;
+ player[22] = -2;
+ player[19] = 2;
+ }
+
+ if (pmap[(int)(player[16]-1)][(int)(player[15])])
+ {
+ player[25] = 3;
+ player[26] = -2;
+ player[23] = 2;
+ }
+ }
+ else
+ {
+ if (pmap[(int)(player[8]-1)][(int)(player[7])])
+ {
+ player[21] = 1;
+ player[22] = -1;
+ player[19] = 1;
+ }
+
+ if (pmap[(int)(player[16]-1)][(int)(player[15])])
+ {
+ player[25] = 1;
+ player[26] = -1;
+ player[23] = 1;
+ }
+
+ }
+ }
+
+ //Jump
+ if (((int)(player[0])&0x04) == 0x04 && (ptypes[pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF].state != ST_GAS || ptypes[pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF].state != ST_GAS))
+ {
+ if (pmap[(int)(player[8]-0.5)][(int)(player[7])] || pmap[(int)(player[16]-0.5)][(int)(player[15])])
+ {
+ parts[i].vy = -5;
+ player[22] -= 1;
+ player[26] -= 1;
+ }
+ }
+
+ //Charge detector wall if foot inside
+ if (bmap[(int)(player[8]+0.5)/CELL][(int)(player[7]+0.5)/CELL]==WL_DETECT)
+ set_emap((int)player[7]/CELL, (int)player[8]/CELL);
+ if (bmap[(int)(player[16]+0.5)/CELL][(int)(player[15]+0.5)/CELL]==WL_DETECT)
+ set_emap((int)(player[15]+0.5)/CELL, (int)(player[16]+0.5)/CELL);
+
+ //Searching for particles near head
+ 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 || (r>>8)>=NPART)
+ continue;
+ if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended.
+ {
+ player[2] = r&0xFF; //Current element
+ }
+ if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP
+ {
+ if (parts[i].life<=95)
+ parts[i].life += 5;
+ else
+ parts[i].life = 100;
+ kill_part(r>>8);
+ }
+
+ if ((r&0xFF) == PT_NEUT)
+ {
+ parts[i].life -= (102-parts[i].life)/2;
+ kill_part(r>>8);
+ }
+ if (bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN)
+ player[2] = SPC_AIR;
+ }
+
+ //Head position
+ rx = x + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01);
+ ry = y - 3*(player[1] == 0);
+
+ //Spawn
+ if (((int)(player[0])&0x08) == 0x08)
+ {
+ ry -= 2*(rand()%2)+1;
+ r = pmap[ry][rx];
+ if (!((r>>8)>=NPART))
+ {
+ if (ptypes[r&0xFF].state == ST_SOLID)
+ {
+ create_part(-1, rx, ry, PT_SPRK);
+ }
+ else
+ {
+ if (player[2] == SPC_AIR)
+ create_parts(rx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR);
+ else
+ create_part(-1, rx, ry, player[2]);
+
+ r = pmap[ry][rx];
+ if ( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR)
+ parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01);
+ if (((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT)
+ {
+ int random = abs(rand()%3-1)*3;
+ if (random==0)
+ {
+ parts[r>>8].life = 0;
+ parts[r>>8].type = PT_NONE;
+ }
+ else
+ {
+ parts[r>>8].vy = 0;
+ parts[r>>8].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random;
+ }
+ }
+
+ }
+ }
+ }
+
+ //Simulation of joints
+ d = 25/(pow((player[3]-player[7]), 2) + pow((player[4]-player[8]), 2)+25) - 0.5; //Fast distance
+ player[7] -= (player[3]-player[7])*d;
+ player[8] -= (player[4]-player[8])*d;
+ player[3] += (player[3]-player[7])*d;
+ player[4] += (player[4]-player[8])*d;
+
+ d = 25/(pow((player[11]-player[15]), 2) + pow((player[12]-player[16]), 2)+25) - 0.5;
+ player[15] -= (player[11]-player[15])*d;
+ player[16] -= (player[12]-player[16])*d;
+ player[11] += (player[11]-player[15])*d;
+ player[12] += (player[12]-player[16])*d;
+
+ d = 36/(pow((player[3]-parts[i].x), 2) + pow((player[4]-parts[i].y), 2)+36) - 0.5;
+ parts[i].vx -= (player[3]-parts[i].x)*d;
+ parts[i].vy -= (player[4]-parts[i].y)*d;
+ player[3] += (player[3]-parts[i].x)*d;
+ player[4] += (player[4]-parts[i].y)*d;
+
+ d = 36/(pow((player[11]-parts[i].x), 2) + pow((player[12]-parts[i].y), 2)+36) - 0.5;
+ parts[i].vx -= (player[11]-parts[i].x)*d;
+ parts[i].vy -= (player[12]-parts[i].y)*d;
+ player[11] += (player[11]-parts[i].x)*d;
+ player[12] += (player[12]-parts[i].y)*d;
+
+ //Side collisions checking
+ for (rx = -3; rx <= 3; rx++)
+ {
+ r = pmap[(int)(player[16]-2)][(int)(player[15]+rx)];
+ if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID)
+ player[15] -= rx;
+
+ r = pmap[(int)(player[8]-2)][(int)(player[7]+rx)];
+ if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID)
+ player[7] -= rx;
+ }
+
+ //Collision checks
+ for (ry = -2-(int)parts[i].vy; ry<=0; ry++)
+ {
+ r = pmap[(int)(player[8]+ry)][(int)(player[7]+0.5)]; //This is to make coding more pleasant :-)
+
+ //For left leg
+ if (r && (r&0xFF)!=PT_STKM)
+ {
+ if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks
+ {
+ if (parts[i].y<(player[8]-10))
+ parts[i].vy = 1*dt;
+ else
+ parts[i].vy = 0;
+ if (abs(parts[i].vx)>1)
+ parts[i].vx *= 0.5*dt;
+ }
+ else
+ {
+ if (ptypes[r&0xFF].state != ST_GAS)
+ {
+ player[8] += ry-1;
+ parts[i].vy -= 0.5*parts[i].vy*dt;
+ }
+ }
+ player[9] = player[7];
+ }
+
+ r = pmap[(int)(player[16]+ry)][(int)(player[15]+0.5)];
+
+ //For right leg
+ if (r && (r&0xFF)!=PT_STKM)
+ {
+ if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG)
+ {
+ if (parts[i].y<(player[16]-10))
+ parts[i].vy = 1*dt;
+ else
+ parts[i].vy = 0;
+ if (abs(parts[i].vx)>1)
+ parts[i].vx *= 0.5*dt;
+ }
+ else
+ {
+ if (ptypes[r&0xFF].state != ST_GAS)
+ {
+ player[16] += ry-1;
+ parts[i].vy -= 0.5*parts[i].vy*dt;
+ }
+ }
+ player[17] = player[15];
+ }
+
+ //If it falls too fast
+ if (parts[i].vy>=30)
+ {
+ parts[i].y -= (10+ry)*dt;
+ parts[i].vy = -10*dt;
+ }
+
+ }
+
+ //Keeping legs distance
+ if (pow((player[7] - player[15]), 2)<16 && pow((player[8]-player[16]), 2)<1)
+ {
+ player[21] -= 0.2;
+ player[25] += 0.2;
+ }
+
+ if (pow((player[3] - player[11]), 2)<16 && pow((player[4]-player[12]), 2)<1)
+ {
+ player[19] -= 0.2;
+ player[23] += 0.2;
+ }
+
+ //If legs touch something
+ r = pmap[(int)(player[8]+0.5)][(int)(player[7]+0.5)];
+ if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge
+ {
+ parts[i].life -= (int)(rand()/1000)+38;
+ }
+
+ if (r>0 && (r>>8)<NPART)
+ {
+ if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) //If hot or cold
+ {
+ parts[i].life -= 2;
+ player[26] -= 1;
+ }
+ }
+
+ if ((r&0xFF)==PT_ACID) //If on acid
+ parts[i].life -= 5;
+
+ if ((r&0xFF)==PT_PLUT) //If on plut
+ parts[i].life -= 1;
+
+ r = pmap[(int)(player[16]+0.5)][(int)(player[15]+0.5)];
+ if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge
+ {
+ parts[i].life -= (int)(rand()/1000)+38;
+ }
+
+ if (r>0 && (r>>8)<NPART) //If hot or cold
+ {
+ if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243)
+ {
+ parts[i].life -= 2;
+ player[22] -= 1;
+ }
+ }
+
+ if ((r&0xFF)==PT_ACID) //If on acid
+ parts[i].life -= 5;
+
+ if ((r&0xFF)==PT_PLUT) //If on plut
+ parts[i].life -= 1;
+
+ isplayer = 1;
+ return 0;
+}
diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c
new file mode 100644
index 0000000..319e388
--- /dev/null
+++ b/src/elements/stkm2.c
@@ -0,0 +1,413 @@
+#include <element.h>
+
+int update_SPAWN2(UPDATE_FUNC_ARGS) {
+ ISSPAWN2 = 1;
+ if (death2)
+ {
+ player2spawn = create_part(-1,x,y,PT_STKM2);
+ isplayer2 = 1;
+ death2 = 0;
+ }
+ return 0;
+}
+
+int update_STKM2(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ float pp, d;
+ float dt = 0.9;///(FPSB*FPSB); //Delta time in square
+ //Tempirature handling
+ if (parts[i].temp<243)
+ parts[i].life -= 1;
+ if ((parts[i].temp<309.6f) && (parts[i].temp>=243))
+ parts[i].temp += 1;
+
+ if (isplayer2) { //Already a stickman2 in the simulation
+ death2 = 1;
+ parts[i].type = PT_NONE;
+ }
+
+ //Death
+ if (parts[i].life<1 || death2 || (pv[y/CELL][x/CELL]>=4.5f && player2[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind...
+ {
+ for (r=-2; r<=1; r++)
+ {
+ create_part(-1, x+r, y-2, player2[2]);
+ create_part(-1, x+r+1, y+2, player2[2]);
+ create_part(-1, x-2, y+r+1, player2[2]);
+ create_part(-1, x+2, y+r, player2[2]);
+ }
+ kill_part(i); //Kill him
+ return 1;
+ }
+
+ parts[i].vy += -0.7*dt; //Head up!
+
+ //Verlet integration
+ pp = 2*player2[3]-player2[5]+player2[19]*dt*dt;;
+ player2[5] = player2[3];
+ player2[3] = pp;
+ pp = 2*player2[4]-player2[6]+player2[20]*dt*dt;;
+ player2[6] = player2[4];
+ player2[4] = pp;
+
+ pp = 2*player2[7]-player2[9]+player2[21]*dt*dt;;
+ player2[9] = player2[7];
+ player2[7] = pp;
+ pp = 2*player2[8]-player2[10]+(player2[22]+1)*dt*dt;;
+ player2[10] = player2[8];
+ player2[8] = pp;
+
+ pp = 2*player2[11]-player2[13]+player2[23]*dt*dt;;
+ player2[13] = player2[11];
+ player2[11] = pp;
+ pp = 2*player2[12]-player2[14]+player2[24]*dt*dt;;
+ player2[14] = player2[12];
+ player2[12] = pp;
+
+ pp = 2*player2[15]-player2[17]+player2[25]*dt*dt;;
+ player2[17] = player2[15];
+ player2[15] = pp;
+ pp = 2*player2[16]-player2[18]+(player2[26]+1)*dt*dt;;
+ player2[18] = player2[16];
+ player2[16] = pp;
+
+ //Setting acceleration to 0
+ player2[19] = 0;
+ player2[20] = 0;
+
+ player2[21] = 0;
+ player2[22] = 0;
+
+ player2[23] = 0;
+ player2[24] = 0;
+
+ player2[25] = 0;
+ player2[26] = 0;
+
+ //Go left
+ if (((int)(player2[0])&0x01) == 0x01 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS)
+ {
+ if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID
+ && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG)
+ {
+ if (pmap[(int)(player2[8]-1)][(int)(player2[7])])
+ {
+ player2[21] = -3;
+ player2[22] = -2;
+ player2[19] = -2;
+ }
+
+ if (pmap[(int)(player2[16]-1)][(int)(player2[15])])
+ {
+ player2[25] = -3;
+ player2[26] = -2;
+ player2[23] = -2;
+ }
+ }
+ else
+ {
+ if (pmap[(int)(player2[8]-1)][(int)(player2[7])]) //It should move another way in liquids
+ {
+ player2[21] = -1;
+ player2[22] = -1;
+ player2[19] = -1;
+ }
+
+ if (pmap[(int)(player2[16]-1)][(int)(player2[15])])
+ {
+ player2[25] = -1;
+ player2[26] = -1;
+ player2[23] = -1;
+ }
+ }
+ }
+
+ //Go right
+ if (((int)(player2[0])&0x02) == 0x02 && ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS)
+ {
+ if (ptypes[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID
+ && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG)
+ {
+ if (pmap[(int)(player2[8]-1)][(int)(player2[7])])
+ {
+ player2[21] = 3;
+ player2[22] = -2;
+ player2[19] = 2;
+ }
+
+ if (pmap[(int)(player2[16]-1)][(int)(player2[15])])
+ {
+ player2[25] = 3;
+ player2[26] = -2;
+ player2[23] = 2;
+ }
+ }
+ else
+ {
+ if (pmap[(int)(player2[8]-1)][(int)(player2[7])])
+ {
+ player2[21] = 1;
+ player2[22] = -1;
+ player2[19] = 1;
+ }
+
+ if (pmap[(int)(player2[16]-1)][(int)(player2[15])])
+ {
+ player2[25] = 1;
+ player2[26] = -1;
+ player2[23] = 1;
+ }
+
+ }
+ }
+
+ //Jump
+ if (((int)(player2[0])&0x04) == 0x04 && (ptypes[pmap[(int)(player2[8]-0.5)][(int)(player2[7])]&0xFF].state != ST_GAS || ptypes[pmap[(int)(player2[16]-0.5)][(int)(player2[15])]&0xFF].state != ST_GAS))
+ {
+ if (pmap[(int)(player2[8]-0.5)][(int)(player2[7])] || pmap[(int)(player2[16]-0.5)][(int)(player2[15])])
+ {
+ parts[i].vy = -5;
+ player2[22] -= 1;
+ player2[26] -= 1;
+ }
+ }
+
+ //Charge detector wall if foot inside
+ if (bmap[(int)(player2[8]+0.5)/CELL][(int)(player2[7]+0.5)/CELL]==WL_DETECT)
+ set_emap((int)player2[7]/CELL, (int)player2[8]/CELL);
+ if (bmap[(int)(player2[16]+0.5)/CELL][(int)(player2[15]+0.5)/CELL]==WL_DETECT)
+ set_emap((int)(player2[15]+0.5)/CELL, (int)(player2[16]+0.5)/CELL);
+
+ //Searching for particles near head
+ 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 || (r>>8)>=NPART)
+ continue;
+ if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended.
+ {
+ player2[2] = r&0xFF; //Current element
+ }
+ if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP
+ {
+ if (parts[i].life<=95)
+ parts[i].life += 5;
+ else
+ parts[i].life = 100;
+ kill_part(r>>8);
+ }
+
+ if ((r&0xFF) == PT_NEUT)
+ {
+ parts[i].life -= (102-parts[i].life)/2;
+ kill_part(r>>8);
+ }
+ if (bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN)
+ player2[2] = SPC_AIR;
+ }
+
+ //Head position
+ rx = x + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01);
+ ry = y - 3*(player2[1] == 0);
+
+ //Spawn
+ if (((int)(player2[0])&0x08) == 0x08)
+ {
+ ry -= 2*(rand()%2)+1;
+ r = pmap[ry][rx];
+ if (!((r>>8)>=NPART))
+ {
+ if (ptypes[r&0xFF].state == ST_SOLID)
+ {
+ create_part(-1, rx, ry, PT_SPRK);
+ }
+ else
+ {
+ if (player2[2] == SPC_AIR)
+ create_parts(rx + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR);
+ else
+ create_part(-1, rx, ry, player2[2]);
+
+ r = pmap[ry][rx];
+ if ( ((r>>8) < NPART) && (r>>8)>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR)
+ parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01);
+ if (((r>>8) < NPART) && (r>>8)>=0 && player2[2] == PT_PHOT)
+ {
+ int random = abs(rand()%3-1)*3;
+ if (random==0)
+ {
+ parts[r>>8].life = 0;
+ parts[r>>8].type = PT_NONE;
+ }
+ else
+ {
+ parts[r>>8].vy = 0;
+ parts[r>>8].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random;
+ }
+ }
+
+ }
+ }
+ }
+
+ //Simulation of joints
+ d = 25/(pow((player2[3]-player2[7]), 2) + pow((player2[4]-player2[8]), 2)+25) - 0.5; //Fast distance
+ player2[7] -= (player2[3]-player2[7])*d;
+ player2[8] -= (player2[4]-player2[8])*d;
+ player2[3] += (player2[3]-player2[7])*d;
+ player2[4] += (player2[4]-player2[8])*d;
+
+ d = 25/(pow((player2[11]-player2[15]), 2) + pow((player2[12]-player2[16]), 2)+25) - 0.5;
+ player2[15] -= (player2[11]-player2[15])*d;
+ player2[16] -= (player2[12]-player2[16])*d;
+ player2[11] += (player2[11]-player2[15])*d;
+ player2[12] += (player2[12]-player2[16])*d;
+
+ d = 36/(pow((player2[3]-parts[i].x), 2) + pow((player2[4]-parts[i].y), 2)+36) - 0.5;
+ parts[i].vx -= (player2[3]-parts[i].x)*d;
+ parts[i].vy -= (player2[4]-parts[i].y)*d;
+ player2[3] += (player2[3]-parts[i].x)*d;
+ player2[4] += (player2[4]-parts[i].y)*d;
+
+ d = 36/(pow((player2[11]-parts[i].x), 2) + pow((player2[12]-parts[i].y), 2)+36) - 0.5;
+ parts[i].vx -= (player2[11]-parts[i].x)*d;
+ parts[i].vy -= (player2[12]-parts[i].y)*d;
+ player2[11] += (player2[11]-parts[i].x)*d;
+ player2[12] += (player2[12]-parts[i].y)*d;
+
+ //Side collisions checking
+ for (rx = -3; rx <= 3; rx++)
+ {
+ r = pmap[(int)(player2[16]-2)][(int)(player2[15]+rx)];
+ if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID)
+ player2[15] -= rx;
+
+ r = pmap[(int)(player2[8]-2)][(int)(player2[7]+rx)];
+ if (r && ptypes[r&0xFF].state != ST_GAS && ptypes[r&0xFF].state != ST_LIQUID)
+ player2[7] -= rx;
+ }
+
+ //Collision checks
+ for (ry = -2-(int)parts[i].vy; ry<=0; ry++)
+ {
+ r = pmap[(int)(player2[8]+ry)][(int)(player2[7]+0.5)]; //This is to make coding more pleasant :-)
+
+ //For left leg
+ if (r && (r&0xFF)!=PT_STKM)
+ {
+ if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks
+ {
+ if (parts[i].y<(player2[8]-10))
+ parts[i].vy = 1*dt;
+ else
+ parts[i].vy = 0;
+ if (abs(parts[i].vx)>1)
+ parts[i].vx *= 0.5*dt;
+ }
+ else
+ {
+ if (ptypes[r&0xFF].state != ST_GAS)
+ {
+ player2[8] += ry-1;
+ parts[i].vy -= 0.5*parts[i].vy*dt;
+ }
+ }
+ player2[9] = player2[7];
+ }
+
+ r = pmap[(int)(player2[16]+ry)][(int)(player2[15]+0.5)];
+
+ //For right leg
+ if (r && (r&0xFF)!=PT_STKM)
+ {
+ if (ptypes[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG)
+ {
+ if (parts[i].y<(player2[16]-10))
+ parts[i].vy = 1*dt;
+ else
+ parts[i].vy = 0;
+ if (abs(parts[i].vx)>1)
+ parts[i].vx *= 0.5*dt;
+ }
+ else
+ {
+ if (ptypes[r&0xFF].state != ST_GAS)
+ {
+ player2[16] += ry-1;
+ parts[i].vy -= 0.5*parts[i].vy*dt;
+ }
+ }
+ player2[17] = player2[15];
+ }
+
+ //If it falls too fast
+ if (parts[i].vy>=30)
+ {
+ parts[i].y -= (10+ry)*dt;
+ parts[i].vy = -10*dt;
+ }
+
+ }
+
+ //Keeping legs distance
+ if (pow((player2[7] - player2[15]), 2)<16 && pow((player2[8]-player2[16]), 2)<1)
+ {
+ player2[21] -= 0.2;
+ player2[25] += 0.2;
+ }
+
+ if (pow((player2[3] - player2[11]), 2)<16 && pow((player2[4]-player2[12]), 2)<1)
+ {
+ player2[19] -= 0.2;
+ player2[23] += 0.2;
+ }
+
+ //If legs touch something
+ r = pmap[(int)(player2[8]+0.5)][(int)(player2[7]+0.5)];
+ if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge
+ {
+ parts[i].life -= (int)(rand()/1000)+38;
+ }
+
+ if (r>0 && (r>>8)<NPART)
+ {
+ if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243) //If hot or cold
+ {
+ parts[i].life -= 2;
+ player2[26] -= 1;
+ }
+ }
+
+ if ((r&0xFF)==PT_ACID) //If on acid
+ parts[i].life -= 5;
+
+ if ((r&0xFF)==PT_PLUT) //If on plut
+ parts[i].life -= 1;
+
+ r = pmap[(int)(player2[16]+0.5)][(int)(player2[15]+0.5)];
+ if ((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge
+ {
+ parts[i].life -= (int)(rand()/1000)+38;
+ }
+
+ if (r>0 && (r>>8)<NPART) //If hot or cold
+ {
+ if (parts[r>>8].temp>=323 || parts[r>>8].temp<=243)
+ {
+ parts[i].life -= 2;
+ player2[22] -= 1;
+ }
+ }
+
+ if ((r&0xFF)==PT_ACID) //If on acid
+ parts[i].life -= 5;
+
+ if ((r&0xFF)==PT_PLUT) //If on plut
+ parts[i].life -= 1;
+
+ isplayer2 = 1;
+ return 0;
+}
+
diff --git a/src/elements/swch.c b/src/elements/swch.c
new file mode 100644
index 0000000..043bf23
--- /dev/null
+++ b/src/elements/swch.c
@@ -0,0 +1,37 @@
+#include <element.h>
+
+int update_SWCH(UPDATE_FUNC_ARGS) {
+ int r, rt, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if (parts_avg(i,r>>8,PT_INSL)!=PT_INSL) {
+ rt = r&0xFF;
+ if (rt==PT_SWCH)
+ {
+ if (parts[i].life>=10&&parts[r>>8].life<10&&parts[r>>8].life>0)
+ parts[i].life = 9;
+ else if (parts[i].life==0&&parts[r>>8].life==10)
+ parts[i].life = 10;
+ }
+ else if (rt==PT_SPRK&&parts[i].life==10&&parts[r>>8].ctype!=PT_PSCN&&parts[r>>8].ctype!=PT_NSCN) {
+ part_change_type(i,x,y,PT_SPRK);
+ parts[i].ctype = PT_SWCH;
+ parts[i].life = 4;
+ }
+ }
+ }
+ if (parts[i].life==10 && (!(pmap[y-1][x-1]&0xFF) && ((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) && !(pmap[y-1][x+1]&0xFF) && ((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2)))
+ {
+ parts[i].life = 9;
+ }
+ else if (parts[i].life<=5 && (!(pmap[y-1][x-1]&0xFF) && (((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) || ((pmap[y+1][x]&0xFF)==PT_BRAY&&parts[pmap[y+1][x]>>8].tmp==2)) && !(pmap[y-1][x+1]&0xFF) && (((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2) || ((pmap[y][x-1]&0xFF)==PT_BRAY&&parts[pmap[y][x-1]>>8].tmp==2))))
+ {
+ parts[i].life = 14;
+ }
+ return 0;
+}
diff --git a/src/elements/thdr.c b/src/elements/thdr.c
new file mode 100644
index 0000000..fb90d1d
--- /dev/null
+++ b/src/elements/thdr.c
@@ -0,0 +1,38 @@
+#include <element.h>
+
+int update_THDR(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0 && !((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && parts[r>>8].ctype!=PT_SPRK)
+ {
+ parts[i].type = PT_NONE;
+ parts[r>>8].ctype = parts[r>>8].type;
+ part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ parts[r>>8].life = 4;
+ }
+ else if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT&&(r&0xFF))
+ {
+ pv[y/CELL][x/CELL] += 100.0f;
+ if (legacy_enable&&1>(rand()%200))
+ {
+ parts[i].life = rand()%50+120;
+ part_change_type(i,x,y,PT_FIRE);
+ }
+ else
+ {
+ parts[i].type = PT_NONE;
+ }
+ }
+ }
+ if (parts[i].type==PT_NONE) {
+ kill_part(i);
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/elements/thrm.c b/src/elements/thrm.c
new file mode 100644
index 0000000..838b466
--- /dev/null
+++ b/src/elements/thrm.c
@@ -0,0 +1,29 @@
+#include <element.h>
+
+int update_THRM(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_LAVA)) // TODO: could this go in update_PYRO?
+ {
+ if (1>(rand()%500)) {
+ part_change_type(i,x,y,PT_LAVA);
+ parts[i].ctype = PT_BMTL;
+ parts[i].temp = 3500.0f;
+ pv[y/CELL][x/CELL] += 50.0f;
+ } else {
+ part_change_type(i,x,y,PT_LAVA);
+ parts[i].life = 400;
+ parts[i].ctype = PT_THRM;
+ parts[i].temp = 3500.0f;
+ parts[i].tmp = 20;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/uran.c b/src/elements/uran.c
new file mode 100644
index 0000000..2b6c563
--- /dev/null
+++ b/src/elements/uran.c
@@ -0,0 +1,10 @@
+#include <element.h>
+
+int update_URAN(UPDATE_FUNC_ARGS) {
+ if (!legacy_enable && pv[y/CELL][x/CELL]>0.0f)
+ {
+ float atemp = parts[i].temp + (-MIN_TEMP);
+ parts[i].temp = restrict_flt((atemp*(1+(pv[y/CELL][x/CELL]/2000)))+MIN_TEMP, MIN_TEMP, MAX_TEMP);
+ }
+ return 0;
+}
diff --git a/src/elements/vine.c b/src/elements/vine.c
new file mode 100644
index 0000000..28b97d5
--- /dev/null
+++ b/src/elements/vine.c
@@ -0,0 +1,21 @@
+#include <element.h>
+
+int update_VINE(UPDATE_FUNC_ARGS) {
+ int r, np, rx =(rand()%3)-1, ry=(rand()%3)-1;
+ 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)
+ return 0;
+ if (1>rand()%15)
+ part_change_type(i,x,y,PT_PLNT);
+ else if (!r)
+ {
+ np = create_part(-1,x+rx,y+ry,PT_VINE);
+ if (np<0) return 0;
+ parts[np].temp = parts[i].temp;
+ part_change_type(i,x,y,PT_PLNT);
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/warp.c b/src/elements/warp.c
new file mode 100644
index 0000000..755433f
--- /dev/null
+++ b/src/elements/warp.c
@@ -0,0 +1,28 @@
+#include <element.h>
+
+int update_WARP(UPDATE_FUNC_ARGS) {
+ int trade, r, rx, ry;
+ for ( trade = 0; trade<5; trade ++)
+ {
+ rx = rand()%3-1;
+ ry = rand()%3-1;
+ 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)
+ continue;
+ if ((r&0xFF)!=PT_WARP&&(r&0xFF)!=PT_STKM&&(r&0xFF)!=PT_STKM2&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_BCLN&&(r&0xFF)!=PT_PCLN&&(10>=rand()%200))
+ {
+ parts[i].x = parts[r>>8].x;
+ parts[i].y = parts[r>>8].y;
+ parts[r>>8].x = x;
+ parts[r>>8].y = y;
+ parts[i].life += 4;
+ pmap[y][x] = r;
+ pmap[y+ry][x+rx] = (i<<8)|parts[i].type;
+ trade = 5;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/watr.c b/src/elements/watr.c
new file mode 100644
index 0000000..7c7ef64
--- /dev/null
+++ b/src/elements/watr.c
@@ -0,0 +1,29 @@
+#include <element.h>
+
+int update_WATR(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_SALT && 1>(rand()%250))
+ {
+ part_change_type(i,x,y,PT_SLTW);
+ part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
+ }
+ if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = 4;
+ }
+ if ((r&0xFF)==PT_CNCT && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_PSTE);
+ kill_part(r>>8);
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/wifi.c b/src/elements/wifi.c
new file mode 100644
index 0000000..fc5ee7f
--- /dev/null
+++ b/src/elements/wifi.c
@@ -0,0 +1,33 @@
+#include <element.h>
+
+int update_WIFI(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
+ 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))
+ {
+ r = pmap[y+ry][x+rx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if (wireless[parts[i].tmp][0])
+ {
+ if (((r&0xFF)==PT_NSCN||(r&0xFF)==PT_PSCN||(r&0xFF)==PT_INWR)&&parts[r>>8].life==0 && wireless[parts[i].tmp][0])
+ {
+ parts[r>>8].ctype = r&0xFF;
+ part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ parts[r>>8].life = 4;
+ }
+ }
+ else
+ {
+ if ((r&0xFF)==PT_SPRK && parts[r>>8].ctype!=PT_NSCN && parts[r>>8].life>=3)
+ {
+ wireless[parts[i].tmp][0] = 1;
+ wireless[parts[i].tmp][1] = 1;
+ ISWIRE = 1;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/wtrv.c b/src/elements/wtrv.c
new file mode 100644
index 0000000..7a32c94
--- /dev/null
+++ b/src/elements/wtrv.c
@@ -0,0 +1,19 @@
+#include <element.h>
+
+int update_WTRV(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !legacy_enable && parts[i].temp>(273.15f+12.0f) && 1>(rand()%500))
+ {
+ part_change_type(i,x,y,PT_FIRE);
+ parts[i].life = 4;
+ }
+ }
+ return 0;
+}
diff --git a/src/elements/yest.c b/src/elements/yest.c
new file mode 100644
index 0000000..d3f64cd
--- /dev/null
+++ b/src/elements/yest.c
@@ -0,0 +1,21 @@
+#include <element.h>
+
+int update_YEST(UPDATE_FUNC_ARGS) {
+ int r, rx, ry;
+ 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>>8)>=NPART || !r)
+ continue;
+ if ((r&0xFF)==PT_DYST && 1>(rand()%30) && !legacy_enable)
+ {
+ part_change_type(i,x,y,PT_DYST);
+ }
+ }
+ if (parts[i].temp>303&&parts[i].temp<317) {
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_YEST);
+ }
+ return 0;
+}