summaryrefslogtreecommitdiff
path: root/src/elements/deut.c
diff options
context:
space:
mode:
authorjacksonmj <jacksonmj@jacksonmj.none>2011-01-10 14:41:03 (GMT)
committer jacksonmj <jacksonmj@jacksonmj.none>2011-01-10 14:41:03 (GMT)
commit54f9f872b9e4d5a0086d6de104e84d43b125c349 (patch)
treeb567fb9d3710acbce22f8193bfe2585bb2988bed /src/elements/deut.c
parent855281295fbc23366e8b84d7c8e55816d6f47a87 (diff)
downloadpowder-54f9f872b9e4d5a0086d6de104e84d43b125c349.zip
powder-54f9f872b9e4d5a0086d6de104e84d43b125c349.tar.gz
Finish update function cleanup
Diffstat (limited to 'src/elements/deut.c')
-rw-r--r--src/elements/deut.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/elements/deut.c b/src/elements/deut.c
index dc96173..640d84a 100644
--- a/src/elements/deut.c
+++ b/src/elements/deut.c
@@ -1,58 +1,59 @@
#include <powder.h>
int update_DEUT(UPDATE_FUNC_ARGS) {
- int r, trade;
+ 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 (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))
+ 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+ny][x+nx];
+ r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART || !r || (parts[i].life >=maxlife))
continue;
- if (parts[r>>8].type==PT_DEUT&&33>=rand()/(RAND_MAX/100)+1)
+ 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;
- parts[r>>8].type=PT_NONE;
+ kill_part(r>>8);
}
}
}
}
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))
+ 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+ny][x+nx];
+ r = pmap[y+ry][x+rx];
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))
+ 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
{
- create_part(-1,x+nx,y+ny,PT_DEUT);
+ np = create_part(-1,x+rx,y+ry,PT_DEUT);
+ if (np<0) continue;
parts[i].life--;
- parts[pmap[y+ny][x+nx]>>8].temp = parts[i].temp;
- parts[pmap[y+ny][x+nx]>>8].life = 0;
+ parts[np].temp = parts[i].temp;
+ parts[np].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))
+ 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+ny][x+nx];
+ r = pmap[y+ry][x+rx];
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
+ 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)