diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-01-23 12:36:31 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-01-23 12:36:31 (GMT) |
| commit | a7aa26fa1a203b97eb2a4a1a00eb18384aab9f2c (patch) | |
| tree | ad578f9fd719c2170fb9718eb4b884cdd159a8a2 /src/simulation/elements/PSTN.cpp | |
| parent | 00cf48b520d42965269bb0ea540a70e399dd2ae1 (diff) | |
| download | powder-a7aa26fa1a203b97eb2a4a1a00eb18384aab9f2c.zip powder-a7aa26fa1a203b97eb2a4a1a00eb18384aab9f2c.tar.gz | |
Added FRME - A solid that keeps its simple structure when pushed by piston
Diffstat (limited to 'src/simulation/elements/PSTN.cpp')
| -rw-r--r-- | src/simulation/elements/PSTN.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/simulation/elements/PSTN.cpp b/src/simulation/elements/PSTN.cpp index 90b85b8..361f103 100644 --- a/src/simulation/elements/PSTN.cpp +++ b/src/simulation/elements/PSTN.cpp @@ -53,6 +53,7 @@ int Element_PSTN::tempParts[128]; #define PISTON_INACTIVE 0x00 #define PISTON_RETRACT 0x01 #define PISTON_EXTEND 0x02 +#define MAX_FRAME 0xFF //#TPT-Directive ElementHeader Element_PSTN static int update(UPDATE_FUNC_ARGS) int Element_PSTN::update(UPDATE_FUNC_ARGS) @@ -150,11 +151,42 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS) return 0; } -//#TPT-Directive ElementHeader Element_PSTN static int MoveStack(Simulation * sim, int stackX, int stackY, int directionX, int directionY, int size, int amount, bool retract) -int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int directionX, int directionY, int size, int amount, bool retract) +//#TPT-Directive ElementHeader Element_PSTN static int MoveStack(Simulation * sim, int stackX, int stackY, int directionX, int directionY, int size, int amount, bool retract, int callDepth = 0) +int Element_PSTN::MoveStack(Simulation * sim, int stackX, int stackY, int directionX, int directionY, int size, int amount, bool retract, int callDepth) { bool foundEnd = false, foundParts = false; int posX, posY, r, spaces = 0, currentPos = 0; + r = sim->pmap[stackY][stackX]; + if(!callDepth && (r&0xFF) == PT_FRME) { + int biggestMove = amount; + int newY = !!directionX, newX = !!directionY; + //If the piston is pushing frame, iterate out from the centre to the edge and push everything resting on frame + for(int c = 0; c < MAX_FRAME; c++) { + posY = stackY + (c*newY); + posX = stackX + (c*newX); + if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0) { + r = sim->pmap[posY][posX]; + if((r&0xFF) == PT_FRME) { + int val = MoveStack(sim, posX, posY, directionX, directionY, size, amount, retract, 1); + if(val < biggestMove) + biggestMove = val; + } + } + if(!c) + continue; //If in the centre, don't do extend twice + posY = stackY - (c*newY); + posX = stackX - (c*newX); + if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0) { + r = sim->pmap[posY][posX]; + if((r&0xFF) == PT_FRME) { + int val = MoveStack(sim, posX, posY, directionX, directionY, size, amount, retract, 1); + if(val < biggestMove) + biggestMove = val; + } + } + } + return biggestMove; + } if(retract){ for(posX = stackX, posY = stackY; currentPos < size; posX += directionX, posY += directionY) { if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0)) { |
