Added FRME - A solid that keeps its simple structure when pushed by piston

This commit is contained in:
Simon Robertshaw 2013-01-23 12:36:31 +00:00
parent 00cf48b520
commit a7aa26fa1a
2 changed files with 93 additions and 2 deletions

View File

@ -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() {}

View File

@ -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)) {