summaryrefslogtreecommitdiff
path: root/src/simulation/elements/COAL.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-07 16:59:50 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-07 16:59:50 (GMT)
commit51b17badf4c72270bb762ea795d05d51c8b355e3 (patch)
treeb66671e0496b68114c6e91eedb58bf783d5343c0 /src/simulation/elements/COAL.cpp
parentfb111f42d00dd8a2041bae970c0913e096ac5101 (diff)
downloadpowder-51b17badf4c72270bb762ea795d05d51c8b355e3.zip
powder-51b17badf4c72270bb762ea795d05d51c8b355e3.tar.gz
A bit of refactoring (elements)
Diffstat (limited to 'src/simulation/elements/COAL.cpp')
-rw-r--r--src/simulation/elements/COAL.cpp153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/simulation/elements/COAL.cpp b/src/simulation/elements/COAL.cpp
new file mode 100644
index 0000000..eae7450
--- /dev/null
+++ b/src/simulation/elements/COAL.cpp
@@ -0,0 +1,153 @@
+#include "simulation/Elements.h"
+//#TPT-Directive ElementClass Element_COAL PT_COAL 59
+Element_COAL::Element_COAL()
+{
+ Identifier = "DEFAULT_PT_COAL";
+ Name = "COAL";
+ Colour = PIXPACK(0x222222);
+ MenuVisible = 1;
+ MenuSection = SC_SOLIDS;
+ Enabled = 1;
+
+ Advection = 0.0f;
+ AirDrag = 0.00f * CFDS;
+ AirLoss = 0.90f;
+ Loss = 0.00f;
+ Collision = 0.0f;
+ Gravity = 0.0f;
+ Diffusion = 0.0f;
+ HotAir = 0.0f * CFDS;
+ Falldown = 0;
+
+ Flammable = 0;
+ Explosive = 0;
+ Meltable = 0;
+ Hardness = 20;
+
+ Weight = 100;
+
+ Temperature = R_TEMP+0.0f +273.15f;
+ HeatConduct = 200;
+ Description = "Solid. Burns slowly.";
+
+ State = ST_SOLID;
+ Properties = TYPE_SOLID;
+
+ LowPressure = IPL;
+ LowPressureTransition = NT;
+ HighPressure = IPH;
+ HighPressureTransition = NT;
+ LowTemperature = ITL;
+ LowTemperatureTransition = NT;
+ HighTemperature = ITH;
+ HighTemperatureTransition = NT;
+
+ Update = &Element_COAL::update;
+ Graphics = &Element_COAL::graphics;
+}
+
+//#TPT-Directive ElementHeader Element_COAL static int update(UPDATE_FUNC_ARGS)
+int Element_COAL::update(UPDATE_FUNC_ARGS)
+ {
+ int r, rx, ry, trade, temp;
+ if (parts[i].life<=0) {
+ sim->create_part(i, x, y, PT_FIRE);
+ return 1;
+ } else if (parts[i].life < 100) {
+ parts[i].life--;
+ sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
+ }
+ if ((sim->pv[y/CELL][x/CELL] > 4.3f)&&parts[i].tmp>40)
+ parts[i].tmp=39;
+ else if (parts[i].tmp<40&&parts[i].tmp>0)
+ parts[i].tmp--;
+ else if (parts[i].tmp<=0) {
+ sim->create_part(i, x, y, PT_BCOL);
+ return 1;
+ }
+ for (rx=-2; rx<3; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+ if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
+ {
+ if (parts[i].life>100) {
+ parts[i].life = 99;
+ }
+ }
+ if ((r&0xFF)==PT_LAVA && 1>(rand()%500))
+ {
+ if (parts[r>>8].ctype == PT_IRON) {
+ parts[r>>8].ctype = PT_METL;
+ sim->kill_part(i);
+ return 1;
+ }
+ }
+ }
+ /*if(100-parts[i].life > parts[i].tmp2)
+ parts[i].tmp2 = 100-parts[i].life;
+ if(parts[i].tmp2 < 0) parts[i].tmp2 = 0;
+ for ( trade = 0; trade<4; trade ++)
+ {
+ rx = rand()%5-2;
+ ry = rand()%5-2;
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+ if (((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL)&&(parts[i].tmp2>parts[r>>8].tmp2)&&parts[i].tmp2>0)//diffusion
+ {
+ int temp = parts[i].tmp2 - parts[r>>8].tmp2;
+ if(temp < 10)
+ continue;
+ if (temp ==1)
+ {
+ parts[r>>8].tmp2 ++;
+ parts[i].tmp2 --;
+ }
+ else if (temp>0)
+ {
+ parts[r>>8].tmp2 += temp/2;
+ parts[i].tmp2 -= temp/2;
+ }
+ }
+ }
+ }*/
+ if(parts[i].temp > parts[i].tmp2)
+ parts[i].tmp2 = parts[i].temp;
+ return 0;
+}
+
+
+//#TPT-Directive ElementHeader Element_COAL static int graphics(GRAPHICS_FUNC_ARGS)
+int Element_COAL::graphics(GRAPHICS_FUNC_ARGS)
+ //Both COAL and Broken Coal
+{
+ *colr += (cpart->tmp2-295.15f)/3;
+
+ if (*colr > 170)
+ *colr = 170;
+ if (*colr < *colg)
+ *colr = *colg;
+
+ *colg = *colb = *colr;
+
+ if((cpart->temp-295.15f) > 300.0f-200.0f)
+ {
+ float frequency = 3.1415/(2*300.0f-(300.0f-200.0f));
+ int q = ((cpart->temp-295.15f)>300.0f)?300.0f-(300.0f-200.0f):(cpart->temp-295.15f)-(300.0f-200.0f);
+
+ *colr += sin(frequency*q) * 226;
+ *colg += sin(frequency*q*4.55 +3.14) * 34;
+ *colb += sin(frequency*q*2.22 +3.14) * 64;
+ }
+ return 0;
+}
+
+
+
+Element_COAL::~Element_COAL() {} \ No newline at end of file