summaryrefslogtreecommitdiff
path: root/src/elements/pipe.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/pipe.c
parent855281295fbc23366e8b84d7c8e55816d6f47a87 (diff)
downloadpowder-54f9f872b9e4d5a0086d6de104e84d43b125c349.zip
powder-54f9f872b9e4d5a0086d6de104e84d43b125c349.tar.gz
Finish update function cleanup
Diffstat (limited to 'src/elements/pipe.c')
-rw-r--r--src/elements/pipe.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/elements/pipe.c b/src/elements/pipe.c
index 8c66057..93eec4e 100644
--- a/src/elements/pipe.c
+++ b/src/elements/pipe.c
@@ -1,7 +1,7 @@
#include <powder.h>
int update_PIPE(UPDATE_FUNC_ARGS) {
- int r, trade, q, ctype;
+ int r, rx, ry, np, trade, q, ctype;
if (!parts[i].ctype && parts[i].life<=10)
{
if (parts[i].temp<272.15)
@@ -24,15 +24,15 @@ int update_PIPE(UPDATE_FUNC_ARGS) {
}
else
{
- for (nx=-2; nx<3; nx++)
- for (ny=-2; ny<3; ny++)
- if (x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ 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+ny][x+nx];
+ r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART )
continue;
if (!r)
- create_part(-1,x+nx,y+ny,PT_BRCK);
+ create_part(-1,x+rx,y+ry,PT_BRCK);
}
if (parts[i].life==1)
parts[i].ctype = 1;
@@ -40,11 +40,11 @@ int update_PIPE(UPDATE_FUNC_ARGS) {
}
if (parts[i].ctype==1)
{
- 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)
continue;
if (!r&&!parts[i].life)
@@ -64,14 +64,14 @@ int update_PIPE(UPDATE_FUNC_ARGS) {
{
if (parts[i].life==3)
{
- 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)
continue;
- if (parts[r>>8].type==PT_PIPE&&parts[r>>8].ctype==1)
+ if ((r&0xFF)==PT_PIPE&&parts[r>>8].ctype==1)
{
parts[r>>8].ctype = (((ctype)%3)+2);//reverse
parts[r>>8].life = 6;
@@ -80,33 +80,34 @@ int update_PIPE(UPDATE_FUNC_ARGS) {
}
else
{
- nx = rand()%3-1;
- ny = rand()%3-1;
- if (x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ 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+ny][x+nx];
+ r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART)
continue;
else if (!r&&parts[i].tmp!=0)
{
- if (create_part(-1,x+nx,y+ny,parts[i].tmp))
+ np = create_part(-1,x+rx,y+ry,parts[i].tmp);
+ if (np!=-1)
{
- parts[pmap[y+ny][x+nx]>>8].temp = parts[i].temp;//pipe saves temp and life now
- parts[pmap[y+ny][x+nx]>>8].life = parts[i].flags;
+ 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[parts[r>>8].type].falldown!= 0 || pstates[parts[r>>8].type].state == ST_GAS))
+ else if (parts[i].tmp == 0 && (ptypes[r&0xFF].falldown!= 0 || pstates[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;
- parts[r>>8].type = PT_NONE;
+ kill_part(r>>8);
}
- else if (parts[r>>8].type==PT_PIPE && parts[r>>8].ctype!=(((ctype)%3)+2) && parts[r>>8].tmp==0&&parts[i].tmp>0)
+ 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;