diff options
Diffstat (limited to 'src/simulation/Simulation.cpp')
| -rw-r--r-- | src/simulation/Simulation.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 5a40c82..17bbc9b 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -369,7 +369,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) int x1, x2, dy = (c<PT_NUM)?1:CELL; int co = c; int coord_stack_limit = XRES*YRES; - unsigned short (*coord_stack)[2] = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit); + unsigned short (*coord_stack)[2]; int coord_stack_size = 0; int created_something = 0; @@ -388,9 +388,10 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) cm = 0; } - if ((pmap[y][x]&0xFF)!=cm) + if ((pmap[y][x]&0xFF)!=cm || parts[pmap[y][x]>>8].life!=0) return 1; + coord_stack = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit); coord_stack[coord_stack_size][0] = x; coord_stack[coord_stack_size][1] = y; coord_stack_size++; @@ -404,7 +405,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) // go left as far as possible while (x1>=CELL) { - if ((pmap[y][x1-1]&0xFF)!=cm) + if ((pmap[y][x1-1]&0xFF)!=cm || parts[pmap[y][x1-1]>>8].life!=0) { break; } @@ -413,7 +414,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) // go right as far as possible while (x2<XRES-CELL) { - if ((pmap[y][x2+1]&0xFF)!=cm) + if ((pmap[y][x2+1]&0xFF)!=cm || parts[pmap[y][x2+1]>>8].life!=0) { break; } @@ -433,20 +434,23 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1+1], cm)) { // travelling vertically up, skipping a horizontal line - if ((pmap[y-2][x1]&0xFF)==cm) + if ((pmap[y-2][x1]&0xFF)==cm && !parts[pmap[y-2][x1]>>8].life) { coord_stack[coord_stack_size][0] = x1; coord_stack[coord_stack_size][1] = y-2; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) + { + free(coord_stack); return -1; + } } } else if (y>=CELL+1) { for (x=x1; x<=x2; x++) { - if ((pmap[y-1][x]&0xFF)==cm) + if ((pmap[y-1][x]&0xFF)==cm && !parts[pmap[y-1][x]>>8].life) { if (x==x1 || x==x2 || y>=YRES-CELL-1 || !PMAP_CMP_CONDUCTIVE(pmap[y+1][x], cm)) { @@ -455,7 +459,10 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) coord_stack[coord_stack_size][1] = y-1; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) + { + free(coord_stack); return -1; + } } } } @@ -466,20 +473,23 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) !PMAP_CMP_CONDUCTIVE(pmap[y+2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y+2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y+2][x1+1], cm)) { // travelling vertically down, skipping a horizontal line - if ((pmap[y+2][x1]&0xFF)==cm) + if ((pmap[y+2][x1]&0xFF)==cm && !parts[pmap[y+2][x1]>>8].life) { coord_stack[coord_stack_size][0] = x1; coord_stack[coord_stack_size][1] = y+2; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) + { + free(coord_stack); return -1; + } } } else if (y<YRES-CELL-1) { for (x=x1; x<=x2; x++) { - if ((pmap[y+1][x]&0xFF)==cm) + if ((pmap[y+1][x]&0xFF)==cm && !parts[pmap[y+1][x]>>8].life) { if (x==x1 || x==x2 || y<0 || !PMAP_CMP_CONDUCTIVE(pmap[y-1][x], cm)) { @@ -488,7 +498,10 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) coord_stack[coord_stack_size][1] = y+1; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) + { + free(coord_stack); return -1; + } } } @@ -506,7 +519,7 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) int x1, x2, dy = (c<PT_NUM)?1:CELL; int co = c; int coord_stack_limit = XRES*YRES; - unsigned short (*coord_stack)[2] = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit); + unsigned short (*coord_stack)[2]; int coord_stack_size = 0; int created_something = 0; @@ -540,6 +553,7 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )) return 1; + coord_stack = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit); coord_stack[coord_stack_size][0] = x; coord_stack[coord_stack_size][1] = y; coord_stack_size++; @@ -583,7 +597,10 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) coord_stack[coord_stack_size][1] = y-dy; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) + { + free(coord_stack); return -1; + } } if (y<YRES-CELL-dy) @@ -594,7 +611,10 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) coord_stack[coord_stack_size][1] = y+dy; coord_stack_size++; if (coord_stack_size>=coord_stack_limit) + { + free(coord_stack); return -1; + } } } while (coord_stack_size>0); free(coord_stack); |
