diff options
| author | jacob1 <jfu614@gmail.com> | 2013-07-10 20:59:10 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2013-07-10 20:59:10 (GMT) |
| commit | 3203e597b9546d85c3eff887ea4f01e051ebbba0 (patch) | |
| tree | 9170e9f21628af7aed013daf96b365afc58c9fde /src/simulation/elements/PSTN.cpp | |
| parent | e7a3fd1c29bdc3f16fc6c04ce36f7268adb55092 (diff) | |
| download | powder-3203e597b9546d85c3eff887ea4f01e051ebbba0.zip powder-3203e597b9546d85c3eff887ea4f01e051ebbba0.tar.gz | |
fix piston bugs, fix crashes, don't use bluescreens when compiled with debug mode in visual studio
Diffstat (limited to 'src/simulation/elements/PSTN.cpp')
| -rw-r--r-- | src/simulation/elements/PSTN.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index ba2ba85..d880ee8 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -168,7 +168,7 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) int Element_PSTN::CanMoveStack(Simulation * sim, int stackX, int stackY, int directionX, int directionY, int maxSize, int amount, bool retract, int block) { int posX, posY, r, spaces = 0, currentPos = 0; - if (amount == 0) + if (amount <= 0) return 0; for(posX = stackX, posY = stackY; currentPos < maxSize + amount; posX += directionX, posY += directionY) { if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0)) { @@ -176,14 +176,14 @@ int Element_PSTN::CanMoveStack(Simulation * sim, int stackX, int stackY, int dir } r = sim->pmap[posY][posX]; if (sim->IsWallBlocking(posX, posY, 0) || (block && (r&0xFF) == block)) - break; + return spaces; if(!r) { spaces++; tempParts[currentPos++] = -1; if(spaces >= amount) break; } else { - if(spaces < maxSize && !retract) + if(spaces < maxSize && currentPos < maxSize && (!retract || ((r&0xFF) == PT_FRME) && posX == stackX && posY == stackY)) tempParts[currentPos++] = r>>8; else return spaces; @@ -212,7 +212,7 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct posY = stackY + (c*newY); posX = stackX + (c*newX); if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && (sim->pmap[posY][posX]&0xFF) == PT_FRME) { - int val = CanMoveStack(sim, posX+realDirectionX, posY+realDirectionY, realDirectionX, realDirectionY, maxSize, amount, retract, block); + int val = CanMoveStack(sim, posX, posY, realDirectionX, realDirectionY, maxSize, amount, retract, block); if(val < amount) amount = val; } else { @@ -224,7 +224,7 @@ int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int direct posY = stackY - (c*newY); posX = stackX - (c*newX); if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && (sim->pmap[posY][posX]&0xFF) == PT_FRME) { - int val = CanMoveStack(sim, posX+realDirectionX, posY+realDirectionY, realDirectionX, realDirectionY, maxSize, amount, retract, block); + int val = CanMoveStack(sim, posX, posY, realDirectionX, realDirectionY, maxSize, amount, retract, block); if(val < amount) amount = val; } else { |
