summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-04-03 00:37:41 (GMT)
committer Simon <simon@hardwired.org.uk>2011-04-04 15:12:52 (GMT)
commit4d80abc399b0694eb602487058d7b5865f9b4eae (patch)
treec323e57cf0c46ce9d62bde8ef47ac4e31f8f2262 /src
parent63089242a54f54fa4a199ba20697ddc5486df94e (diff)
downloadpowder-4d80abc399b0694eb602487058d7b5865f9b4eae.zip
powder-4d80abc399b0694eb602487058d7b5865f9b4eae.tar.gz
Fix neutrons crash
Also fix neutrons causing unwanted movement of parts[0]
Diffstat (limited to 'src')
-rw-r--r--src/powder.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/powder.c b/src/powder.c
index b178318..4ae5bca 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -237,7 +237,7 @@ int try_move(int i, int x, int y, int nx, int ny)
return 0;
}
- if ((pmap[ny][nx]&0xFF)==PT_CNCT)//why is this here
+ if ((pmap[ny][nx]&0xFF)==PT_CNCT)//stops CNCT being displaced by other particles
return 0;
if (parts[i].type==PT_CNCT && y<ny && (pmap[y+1][x]&0xFF)==PT_CNCT)//check below CNCT for another CNCT
return 0;
@@ -262,14 +262,20 @@ int try_move(int i, int x, int y, int nx, int ny)
if (parts[i].type==PT_NEUT) {
// target material is NEUTPENETRATE, meaning it gets moved around when neutron passes
unsigned s = pmap[y][x];
+ if ((s>>8)>=NPART) return 0;
if ((s&0xFF) && (s&0xFF)<PT_NUM && !(ptypes[s&0xFF].properties&PROP_NEUTPENETRATE))
- return 1; // if the element currently underneath neutron isn't NEUTPENETRATE, don't move it around
- if ((pmap[ny][nx]>>8)==e) pmap[ny][nx] = (s&~(0xFF))|parts[s>>8].type;
+ return 1; // if the element currently underneath neutron isn't NEUTPENETRATE, don't move anything except the neutron
+ // if nothing is currently underneath neutron, only move target particle
+ if (s)
+ {
+ pmap[ny][nx] = (s&~(0xFF))|parts[s>>8].type;
+ parts[s>>8].x = nx;
+ parts[s>>8].y = ny;
+ }
+ else pmap[ny][nx] = 0;
parts[e].x = x;
parts[e].y = y;
pmap[y][x] = (e<<8)|parts[e].type;
- parts[s>>8].x = nx;
- parts[s>>8].y = ny;
return 1;
}