mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-30 11:19:51 +02:00
Added FRME - A solid that keeps its simple structure when pushed by piston
This commit is contained in:
59
src/simulation/elements/FRME.cpp
Normal file
59
src/simulation/elements/FRME.cpp
Normal 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() {}
|
@@ -53,6 +53,7 @@ int Element_PSTN::tempParts[128];
|
|||||||
#define PISTON_INACTIVE 0x00
|
#define PISTON_INACTIVE 0x00
|
||||||
#define PISTON_RETRACT 0x01
|
#define PISTON_RETRACT 0x01
|
||||||
#define PISTON_EXTEND 0x02
|
#define PISTON_EXTEND 0x02
|
||||||
|
#define MAX_FRAME 0xFF
|
||||||
|
|
||||||
//#TPT-Directive ElementHeader Element_PSTN static int update(UPDATE_FUNC_ARGS)
|
//#TPT-Directive ElementHeader Element_PSTN static int update(UPDATE_FUNC_ARGS)
|
||||||
int Element_PSTN::update(UPDATE_FUNC_ARGS)
|
int Element_PSTN::update(UPDATE_FUNC_ARGS)
|
||||||
@@ -150,11 +151,42 @@ int Element_PSTN::update(UPDATE_FUNC_ARGS)
|
|||||||
return 0;
|
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)
|
//#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 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;
|
bool foundEnd = false, foundParts = false;
|
||||||
int posX, posY, r, spaces = 0, currentPos = 0;
|
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){
|
if(retract){
|
||||||
for(posX = stackX, posY = stackY; currentPos < size; posX += directionX, posY += directionY) {
|
for(posX = stackX, posY = stackY; currentPos < size; posX += directionX, posY += directionY) {
|
||||||
if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0)) {
|
if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0)) {
|
||||||
|
Reference in New Issue
Block a user