Allow limited arm size from tmp2

This commit is contained in:
Simon Robertshaw 2013-01-26 19:44:05 +00:00
parent 03fde95719
commit 486d26e40b

View File

@ -52,11 +52,12 @@ int Element_PSTN::tempParts[128];
//#TPT-Directive ElementHeader Element_PSTN static int tempPartAmount[128]; //#TPT-Directive ElementHeader Element_PSTN static int tempPartAmount[128];
int Element_PSTN::tempPartAmount[128]; int Element_PSTN::tempPartAmount[128];
#define PISTON_INACTIVE 0x00 #define PISTON_INACTIVE 0x00
#define PISTON_RETRACT 0x01 #define PISTON_RETRACT 0x01
#define PISTON_EXTEND 0x02 #define PISTON_EXTEND 0x02
#define MAX_FRAME 0x0F #define MAX_FRAME 0x0F
#define DEFAULT_LIMIT 0x1F #define DEFAULT_LIMIT 0x1F
#define DEFAULT_ARM_LIMIT 0xFF
//#TPT-Directive ElementHeader Element_PSTN static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_PSTN static int update(UPDATE_FUNC_ARGS)
int Element_PSTN::update(UPDATE_FUNC_ARGS) int Element_PSTN::update(UPDATE_FUNC_ARGS)
@ -64,7 +65,8 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS)
if(parts[i].ctype) if(parts[i].ctype)
return 0; return 0;
int maxSize = parts[i].tmp ? parts[i].tmp : DEFAULT_LIMIT; int maxSize = parts[i].tmp ? parts[i].tmp : DEFAULT_LIMIT;
int state = parts[i].tmp2; int armLimit = parts[i].tmp2 ? parts[i].tmp2 : DEFAULT_ARM_LIMIT;
int state = 0;
int r, nxx, nyy, nxi, nyi, rx, ry; int r, nxx, nyy, nxi, nyi, rx, ry;
int directionX = 0, directionY = 0; int directionX = 0, directionY = 0;
if (parts[i].life==0 && state == PISTON_INACTIVE) { if (parts[i].life==0 && state == PISTON_INACTIVE) {
@ -91,7 +93,7 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((r&0xFF) == PT_PSTN && parts[r>>8].tmp2 == PISTON_INACTIVE) { if ((r&0xFF) == PT_PSTN) {
directionX = rx; directionX = rx;
directionY = ry; directionY = ry;
{ {
@ -119,13 +121,17 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS)
} }
if(foundEnd) { if(foundEnd) {
if(state == PISTON_EXTEND) { if(state == PISTON_EXTEND) {
newSpace = MoveStack(sim, pistonEndX, pistonEndY, directionX, directionY, maxSize, pistonCount, false); if(armCount+pistonCount > armLimit)
if(newSpace) { pistonCount = armLimit-armCount;
//Create new piston section if(pistonCount > 0) {
for(int j = 0; j < newSpace; j++) { newSpace = MoveStack(sim, pistonEndX, pistonEndY, directionX, directionY, maxSize, pistonCount, false);
int nr = sim->create_part(-3, pistonEndX+(nxi*j), pistonEndY+(nyi*j), PT_PSTN); if(newSpace) {
if (nr!=-1) { //Create new piston section
parts[nr].ctype = 1; for(int j = 0; j < newSpace; j++) {
int nr = sim->create_part(-3, pistonEndX+(nxi*j), pistonEndY+(nyi*j), PT_PSTN);
if (nr!=-1) {
parts[nr].ctype = 1;
}
} }
} }
} }