summaryrefslogtreecommitdiff
path: root/src/simulation/elements
diff options
context:
space:
mode:
authorSimon 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)
commita7aa26fa1a203b97eb2a4a1a00eb18384aab9f2c (patch)
treead578f9fd719c2170fb9718eb4b884cdd159a8a2 /src/simulation/elements
parent00cf48b520d42965269bb0ea540a70e399dd2ae1 (diff)
downloadpowder-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')
-rw-r--r--src/simulation/elements/FRME.cpp59
-rw-r--r--src/simulation/elements/PSTN.cpp36
2 files changed, 93 insertions, 2 deletions
diff --git a/src/simulation/elements/FRME.cpp b/src/simulation/elements/FRME.cpp
new file mode 100644
index 0000000..62668ea
--- /dev/null
+++ b/src/simulation/elements/FRME.cpp
@@ -0,0 +1,59 @@
+#include "simulation/Elements.h"
+//#TPT-Directive ElementClass Element_FRME PT_FRME 169
+Element_FRME::Element_FRME()
+{
+ Identifier = "DEFAULT_PT_FRME";
+ Name = "FRME";
+ Colour = PIXPACK(0xBBDD50);
+ MenuVisible = 1;
+ MenuSection = SC_ELEC;
+ Enabled = 1;
+
+ Advection = 0.0f;
+ AirDrag = 0.00f * CFDS;
+ AirLoss = 0.90f;
+ Loss = 0.00f;
+ Collision = 0.0f;
+ Gravity = 0.0f;
+ Diffusion = 0.00f;
+ HotAir = 0.000f * CFDS;
+ Falldown = 0;
+
+ Flammable = 0;
+ Explosive = 0;
+ Meltable = 0;
+ Hardness = 1;
+
+ Weight = 100;
+
+ Temperature = R_TEMP+0.0f +273.15f;
+ HeatConduct = 0;
+ Description = "Frame, can be used with pistons to push many particles";
+
+ State = ST_SOLID;
+ Properties = TYPE_SOLID|PROP_LIFE_DEC;
+
+ LowPressure = IPL;
+ LowPressureTransition = NT;
+ HighPressure = IPH;
+ HighPressureTransition = NT;
+ LowTemperature = ITL;
+ LowTemperatureTransition = NT;
+ HighTemperature = ITH;
+ HighTemperatureTransition = NT;
+
+ Graphics = &Element_FRME::graphics;
+}
+
+//#TPT-Directive ElementHeader Element_FRME static int graphics(GRAPHICS_FUNC_ARGS)
+int Element_FRME::graphics(GRAPHICS_FUNC_ARGS)
+{
+ if(cpart->ctype)
+ {
+ *colr -= 60;
+ *colg -= 60;
+ }
+ return 0;
+}
+
+Element_FRME::~Element_FRME() {} \ No newline at end of file
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)) {