summaryrefslogtreecommitdiff
path: root/src/simulation/elements/DEUT.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
commit058a2edd75debbd0297f92572316daa704bd379f (patch)
treead303f091f9a08b209b91eb34a9fcad996a3de69 /src/simulation/elements/DEUT.cpp
parente3594aba9e05c6865d396418c028049cda92c2f3 (diff)
parent7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff)
downloadpowder-058a2edd75debbd0297f92572316daa704bd379f.zip
powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/simulation/elements/DEUT.cpp')
-rw-r--r--src/simulation/elements/DEUT.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/simulation/elements/DEUT.cpp b/src/simulation/elements/DEUT.cpp
new file mode 100644
index 0000000..b8209e4
--- /dev/null
+++ b/src/simulation/elements/DEUT.cpp
@@ -0,0 +1,149 @@
+#include "simulation/Elements.h"
+//#TPT-Directive ElementClass Element_DEUT PT_DEUT 95
+Element_DEUT::Element_DEUT()
+{
+ Identifier = "DEFAULT_PT_DEUT";
+ Name = "DEUT";
+ Colour = PIXPACK(0x00153F);
+ MenuVisible = 1;
+ MenuSection = SC_NUCLEAR;
+ Enabled = 1;
+
+ Advection = 0.6f;
+ AirDrag = 0.01f * CFDS;
+ AirLoss = 0.98f;
+ Loss = 0.95f;
+ Collision = 0.0f;
+ Gravity = 0.1f;
+ Diffusion = 0.00f;
+ HotAir = 0.000f * CFDS;
+ Falldown = 2;
+
+ Flammable = 0;
+ Explosive = 0;
+ Meltable = 0;
+ Hardness = 20;
+
+ Weight = 31;
+
+ Temperature = R_TEMP-2.0f +273.15f;
+ HeatConduct = 251;
+ Description = "Deuterium oxide. Volume changes with temp, radioactive with neutrons.";
+
+ State = ST_LIQUID;
+ Properties = TYPE_LIQUID|PROP_NEUTPENETRATE;
+
+ LowPressure = IPL;
+ LowPressureTransition = NT;
+ HighPressure = IPH;
+ HighPressureTransition = NT;
+ LowTemperature = ITL;
+ LowTemperatureTransition = NT;
+ HighTemperature = ITH;
+ HighTemperatureTransition = NT;
+
+ Update = &Element_DEUT::update;
+ Graphics = &Element_DEUT::graphics;
+}
+
+//#TPT-Directive ElementHeader Element_DEUT static int update(UPDATE_FUNC_ARGS)
+int Element_DEUT::update(UPDATE_FUNC_ARGS)
+ {
+ int r, rx, ry, trade, np;
+ float gravtot = fabs(sim->gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(sim->gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
+ int maxlife = ((10000/(parts[i].temp + 1))-1);
+ if ((10000%((int)parts[i].temp+1))>rand()%((int)parts[i].temp+1))
+ maxlife ++;
+ // Compress when Newtonian gravity is applied
+ // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf
+ maxlife = maxlife*(5.0f - 8.0f/(gravtot+2.0f));
+ if (parts[i].life < maxlife)
+ {
+ for (rx=-1; rx<2; rx++)
+ for (ry=-1; ry<2; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (!r || (parts[i].life >=maxlife))
+ continue;
+ if ((r&0xFF)==PT_DEUT&&33>=rand()/(RAND_MAX/100)+1)
+ {
+ if ((parts[i].life + parts[r>>8].life + 1) <= maxlife)
+ {
+ parts[i].life += parts[r>>8].life + 1;
+ sim->kill_part(r>>8);
+ }
+ }
+ }
+ }
+ else
+ for (rx=-1; rx<2; rx++)
+ for (ry=-1; ry<2; ry++)
+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
+ {
+ r = pmap[y+ry][x+rx];
+ if (parts[i].life<=maxlife)
+ continue;
+ if ((!r)&&parts[i].life>=1)//if nothing then create deut
+ {
+ np = sim->create_part(-1,x+rx,y+ry,PT_DEUT);
+ if (np<0) continue;
+ parts[i].life--;
+ parts[np].temp = parts[i].temp;
+ parts[np].life = 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_DEUT&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
+ {
+ int temp = parts[i].life - parts[r>>8].life;
+ if (temp ==1)
+ {
+ parts[r>>8].life ++;
+ parts[i].life --;
+ }
+ else if (temp>0)
+ {
+ parts[r>>8].life += temp/2;
+ parts[i].life -= temp/2;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+
+
+//#TPT-Directive ElementHeader Element_DEUT static int graphics(GRAPHICS_FUNC_ARGS)
+int Element_DEUT::graphics(GRAPHICS_FUNC_ARGS)
+
+{
+ if(cpart->life>=700)
+ {
+ *firea = 60;
+ *firer = *colr += cpart->life*1;
+ *fireg = *colg += cpart->life*2;
+ *fireb = *colb += cpart->life*3;
+ *pixel_mode |= PMODE_GLOW | FIRE_ADD;
+ }
+ else
+ {
+ *colr += cpart->life*1;
+ *colg += cpart->life*2;
+ *colb += cpart->life*3;
+ *pixel_mode |= PMODE_BLUR;
+ }
+ return 0;
+}
+
+
+Element_DEUT::~Element_DEUT() {} \ No newline at end of file