1515
1616#include <element.h>
1717
18- int tempParts [128 ];
18+ int tempParts [XRES ];
1919
2020#define PISTON_INACTIVE 0x00
2121#define PISTON_RETRACT 0x01
@@ -27,22 +27,22 @@ int tempParts[128];
2727int CanMoveStack (int stackX , int stackY , int directionX , int directionY , int maxSize , int amount , int retract , int block )
2828{
2929 int posX , posY , r , spaces = 0 , currentPos = 0 ;
30- if (amount = = 0 )
30+ if (amount < = 0 )
3131 return 0 ;
32- for (posX = stackX , posY = stackY ; currentPos < maxSize + amount ; posX += directionX , posY += directionY ) {
32+ for (posX = stackX , posY = stackY ; currentPos < maxSize + amount && currentPos < XRES - 1 ; posX += directionX , posY += directionY ) {
3333 if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0 )) {
3434 break ;
3535 }
3636 r = pmap [posY ][posX ];
3737 if (IsWallBlocking (posX , posY , 0 ) || (block && (r & 0xFF ) == block ))
38- break ;
38+ return spaces ;
3939 if (!r ) {
4040 spaces ++ ;
4141 tempParts [currentPos ++ ] = -1 ;
4242 if (spaces >= amount )
4343 break ;
4444 } else {
45- if (spaces < maxSize && !retract )
45+ if (spaces < maxSize && currentPos < maxSize && ( !retract || (( r & 0xFF ) == PT_FRME ) && posX == stackX && posY == stackY ) )
4646 tempParts [currentPos ++ ] = r >>8 ;
4747 else
4848 return spaces ;
@@ -71,7 +71,7 @@ int MoveStack(int stackX, int stackY, int directionX, int directionY, int maxSiz
7171 posY = stackY + (c * newY );
7272 posX = stackX + (c * newX );
7373 if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && (pmap [posY ][posX ]& 0xFF ) == PT_FRME ) {
74- int val = CanMoveStack (posX + realDirectionX , posY + realDirectionY , realDirectionX , realDirectionY , maxSize , amount , retract , block );
74+ int val = CanMoveStack (posX , posY , realDirectionX , realDirectionY , maxSize , amount , retract , block );
7575 if (val < amount )
7676 amount = val ;
7777 } else {
@@ -83,7 +83,7 @@ int MoveStack(int stackX, int stackY, int directionX, int directionY, int maxSiz
8383 posY = stackY - (c * newY );
8484 posX = stackX - (c * newX );
8585 if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && (pmap [posY ][posX ]& 0xFF ) == PT_FRME ) {
86- int val = CanMoveStack (posX + realDirectionX , posY + realDirectionY , realDirectionX , realDirectionY , maxSize , amount , retract , block );
86+ int val = CanMoveStack (posX , posY , realDirectionX , realDirectionY , maxSize , amount , retract , block );
8787 if (val < amount )
8888 amount = val ;
8989 } else {
@@ -116,7 +116,7 @@ int MoveStack(int stackX, int stackY, int directionX, int directionY, int maxSiz
116116 if (!callDepth )
117117 for (j = 1 ; j <= amount ; j ++ )
118118 kill_part (pmap [stackY + (directionY * - j )][stackX + (directionX * - j )]>>8 );
119- for (posX = stackX , posY = stackY ; currentPos < maxSize ; posX += directionX , posY += directionY ) {
119+ for (posX = stackX , posY = stackY ; currentPos < maxSize && currentPos < XRES - 1 ; posX += directionX , posY += directionY ) {
120120 if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0 )) {
121121 break ;
122122 }
@@ -297,4 +297,4 @@ int graphics_FRME(GRAPHICS_FUNC_ARGS)
297297 * colb += 30 ;
298298 }
299299 return 0 ;
300- }
300+ }
0 commit comments