From 20d8eff7f526aa91997ec09266374d14775607ef Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 22 Feb 2013 16:50:33 -0500 Subject: [PATCH] remove uneeded PSTN check, fix PSTN not retracting sometimes, fix PSTN bug where is wouldn't properly tell the difference between PSTN and PSTN arms --- src/simulation/elements/PSTN.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index 6496483a4..da67f76fd 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -94,6 +94,7 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) if (!r) continue; if ((r&0xFF) == PT_PSTN) { + bool movedPiston = false; directionX = rx; directionY = ry; { @@ -102,7 +103,7 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) int pistonCount = 0; int newSpace = 0; int armCount = 0; - for (nxx = 0, nyy = 0, nxi = directionX, nyi = directionY; pistonCount < maxSize; nyy += nyi, nxx += nxi) { + for (nxx = 0, nyy = 0, nxi = directionX, nyi = directionY; ; nyy += nyi, nxx += nxi) { if (!(x+nxi+nxx= 0 && y+nyi+nyy >= 0)) { break; } @@ -110,6 +111,13 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) if((r&0xFF)==PT_PSTN) { if(parts[r>>8].ctype) armCount++; + else if (armCount) + { + pistonEndX = x+nxi+nxx; + pistonEndY = y+nyi+nyy; + foundEnd = true; + break; + } else pistonCount++; } else { @@ -133,6 +141,7 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) parts[nr].ctype = 1; } } + movedPiston = true; } } } else if(state == PISTON_RETRACT) { @@ -147,12 +156,14 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) } MoveStack(sim, pistonEndX, pistonEndY, directionX, directionY, maxSize, pistonCount, true); //newSpace = MoveStack(sim, pistonEndX, pistonEndY, directionX, directionY, maxSize, pistonCount, true); + movedPiston = true; } } } } - break; + if (movedPiston) + break; } }