summaryrefslogtreecommitdiff
path: root/src/simulation/elements/DMG.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-10-10 18:29:11 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-10-10 18:29:11 (GMT)
commitda07c22ee457899236c8c6d457696daa019fd07e (patch)
treee5421e6b03a8aece969c995d6bf5586e5854b8bc /src/simulation/elements/DMG.cpp
parent249e3dcad3aa62ba09e0b712ff508d94f255a947 (diff)
downloadpowder-da07c22ee457899236c8c6d457696daa019fd07e.zip
powder-da07c22ee457899236c8c6d457696daa019fd07e.tar.gz
new elements: DMG (Force bomb) and TSNS (Temperature sensor)
Diffstat (limited to 'src/simulation/elements/DMG.cpp')
-rw-r--r--src/simulation/elements/DMG.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/simulation/elements/DMG.cpp b/src/simulation/elements/DMG.cpp
new file mode 100644
index 0000000..2e755d9
--- /dev/null
+++ b/src/simulation/elements/DMG.cpp
@@ -0,0 +1,118 @@
+#include "simulation/Elements.h"
+//#TPT-Directive ElementClass Element_DMG PT_DMG 163
+Element_DMG::Element_DMG()
+{
+ Identifier = "DEFAULT_PT_DMG";
+ Name = "DMG";
+ Colour = PIXPACK(0x88FF88);
+ MenuVisible = 1;
+ MenuSection = SC_FORCE;
+ Enabled = 1;
+
+ Advection = 0.0f;
+ AirDrag = 0.01f * CFDS;
+ AirLoss = 0.98f;
+ Loss = 0.95f;
+ Collision = 0.0f;
+ Gravity = 0.1f;
+ Diffusion = 0.00f;
+ HotAir = 0.000f * CFDS;
+ Falldown = 1;
+
+ Flammable = 0;
+ Explosive = 0;
+ Meltable = 0;
+ Hardness = 20;
+
+ Weight = 30;
+
+ Temperature = R_TEMP-2.0f +273.15f;
+ HeatConduct = 29;
+ Description = "DMG.";
+
+ State = ST_NONE;
+ Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC|PROP_SPARKSETTLE;
+
+ LowPressure = IPL;
+ LowPressureTransition = NT;
+ HighPressure = IPH;
+ HighPressureTransition = NT;
+ LowTemperature = ITL;
+ LowTemperatureTransition = NT;
+ HighTemperature = ITH;
+ HighTemperatureTransition = NT;
+
+ Update = &Element_DMG::update;
+ Graphics = &Element_DMG::graphics;
+}
+
+//#TPT-Directive ElementHeader Element_DMG static int update(UPDATE_FUNC_ARGS)
+int Element_DMG::update(UPDATE_FUNC_ARGS)
+ {
+ int r, rr, rx, ry, nb, nxi, nxj, t, dist;
+ int rad = 25;
+ float angle, fx, fy;
+
+ 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_DMG && (r&0xFF)!=PT_EMBR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN)
+ {
+ sim->kill_part(i);
+ for (nxj=-rad; nxj<=rad; nxj++)
+ for (nxi=-rad; nxi<=rad; nxi++)
+ if (x+nxi>=0 && y+nxj>=0 && x+nxi<XRES && y+nxj<YRES && (nxi || nxj))
+ {
+ dist = sqrt(pow(nxi, 2)+pow(nxj, 2));//;(pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2));
+ if (!dist || (dist <= rad))
+ {
+ rr = pmap[y+nxj][x+nxi];
+ if (rr)
+ {
+ angle = atan2(nxj, nxi);
+ fx = cos(angle) * 7.0f;
+ fy = sin(angle) * 7.0f;
+
+ parts[rr>>8].vx += fx;
+ parts[rr>>8].vy += fy;
+
+ sim->vx[(y+nxj)/CELL][(x+nxi)/CELL] += fx;
+ sim->vy[(y+nxj)/CELL][(x+nxi)/CELL] += fy;
+
+ sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 1.0f;
+
+ t = parts[rr>>8].type;
+ if(t && sim->elements[t].HighPressureTransition>-1 && sim->elements[t].HighPressureTransition<PT_NUM)
+ sim->part_change_type(rr>>8, x+nxi, y+nxj, sim->elements[t].HighPressureTransition);
+ else if(t == PT_BMTL)
+ sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BRMT);
+ else if(t == PT_GLAS)
+ sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BGLA);
+ else if(t == PT_COAL)
+ sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_BCOL);
+ else if(t == PT_QRTZ)
+ sim->part_change_type(rr>>8, x+nxi, y+nxj, PT_PQRT);
+ }
+ }
+ }
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+//#TPT-Directive ElementHeader Element_DMG static int graphics(GRAPHICS_FUNC_ARGS)
+int Element_DMG::graphics(GRAPHICS_FUNC_ARGS)
+
+{
+ *pixel_mode |= PMODE_FLARE;
+ return 1;
+}
+
+
+Element_DMG::~Element_DMG() {}