summaryrefslogtreecommitdiff
path: root/src/elements/deut.c
diff options
context:
space:
mode:
authorjacksonmj <jacksonmj@jacksonmj.none>2011-01-07 16:18:22 (GMT)
committer jacksonmj <jacksonmj@jacksonmj.none>2011-01-07 16:18:22 (GMT)
commitf3ded5f08c0bbb3523a0ab2ee6e07538fabd79c2 (patch)
tree804bfff0e558daf780b4330db417e93e2ef695a2 /src/elements/deut.c
parentb661418d7ecd44960f0e24eb7abd79cfc5eb5f0e (diff)
downloadpowder-f3ded5f08c0bbb3523a0ab2ee6e07538fabd79c2.zip
powder-f3ded5f08c0bbb3523a0ab2ee6e07538fabd79c2.tar.gz
More function pointers.
Diffstat (limited to 'src/elements/deut.c')
-rw-r--r--src/elements/deut.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/elements/deut.c b/src/elements/deut.c
new file mode 100644
index 0000000..dc96173
--- /dev/null
+++ b/src/elements/deut.c
@@ -0,0 +1,72 @@
+#include <powder.h>
+
+int update_DEUT(UPDATE_FUNC_ARGS) {
+ int r, trade;
+ 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 (nx=-1; nx<2; nx++)
+ for (ny=-1; ny<2; ny++)
+ if (x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ {
+ r = pmap[y+ny][x+nx];
+ if ((r>>8)>=NPART || !r || (parts[i].life >=maxlife))
+ continue;
+ if (parts[r>>8].type==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;
+ parts[r>>8].type=PT_NONE;
+ }
+ }
+ }
+ }
+ else
+ for (nx=-1; nx<2; nx++)
+ for (ny=-1; ny<2; ny++)
+ if (x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ {
+ r = pmap[y+ny][x+nx];
+ if ((r>>8)>=NPART || (parts[i].life<=maxlife))
+ continue;
+ if ((bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_WALLELEC||bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_EWALL||bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_DESTROYALL||bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_WALL||
+ bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_ALLOWAIR||bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_ALLOWSOLID||bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_ALLOWGAS))
+ continue;
+ if ((!r)&&parts[i].life>=1)//if nothing then create deut
+ {
+ create_part(-1,x+nx,y+ny,PT_DEUT);
+ parts[i].life--;
+ parts[pmap[y+ny][x+nx]>>8].temp = parts[i].temp;
+ parts[pmap[y+ny][x+nx]>>8].life = 0;
+ }
+ }
+ for ( trade = 0; trade<4; trade ++)
+ {
+ nx = rand()%5-2;
+ ny = rand()%5-2;
+ if (x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ {
+ r = pmap[y+ny][x+nx];
+ if ((r>>8)>=NPART || !r)
+ continue;
+ if (parts[r>>8].type==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;
+}