summaryrefslogtreecommitdiff
path: root/src/simulation
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
parent249e3dcad3aa62ba09e0b712ff508d94f255a947 (diff)
downloadpowder-da07c22ee457899236c8c6d457696daa019fd07e.zip
powder-da07c22ee457899236c8c6d457696daa019fd07e.tar.gz
new elements: DMG (Force bomb) and TSNS (Temperature sensor)
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp2
-rw-r--r--src/simulation/SimulationData.cpp5
-rw-r--r--src/simulation/SimulationData.h29
-rw-r--r--src/simulation/elements/DMG.cpp118
-rw-r--r--src/simulation/elements/DTEC.cpp5
-rw-r--r--src/simulation/elements/TSNS.cpp91
6 files changed, 232 insertions, 18 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 61b0944..023d90c 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -2932,6 +2932,8 @@ int Simulation::create_part(int p, int x, int y, int tv)
break;
case PT_DTEC:
parts[i].tmp2 = 2;
+ case PT_TSNS:
+ parts[i].tmp2 = 2;
break;
default:
if (t==PT_FIGH)
diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp
index 2be899d..d9dccf5 100644
--- a/src/simulation/SimulationData.cpp
+++ b/src/simulation/SimulationData.cpp
@@ -1,4 +1,4 @@
-/*
+#/*
* SimulationData.cpp
*
* Created on: Jan 24, 2012
@@ -150,7 +150,8 @@ menu_section * LoadMenus(int & menuCount)
{"\xC1", "Walls", 0, 1},
{"\xC2", "Electronics", 0, 1},
{"\xD6", "Powered Materials", 0, 1},
- {"\xE2", "Force", 0, 1},
+ {"\xD6", "Sensors", 0, 1},
+ {"\xE2", "Force", 0, 1},
{"\xC3", "Explosives", 0, 1},
{"\xC5", "Gasses", 0, 1},
{"\xC4", "Liquids", 0, 1},
diff --git a/src/simulation/SimulationData.h b/src/simulation/SimulationData.h
index fabb62c..1d47813 100644
--- a/src/simulation/SimulationData.h
+++ b/src/simulation/SimulationData.h
@@ -10,20 +10,21 @@
#define SC_WALL 0
#define SC_ELEC 1
#define SC_POWERED 2
-#define SC_FORCE 3
-#define SC_EXPLOSIVE 4
-#define SC_GAS 5
-#define SC_LIQUID 6
-#define SC_POWDERS 7
-#define SC_SOLIDS 8
-#define SC_NUCLEAR 9
-#define SC_SPECIAL 10
-#define SC_LIFE 11
-#define SC_TOOL 12
-#define SC_DECO 13
-#define SC_CRACKER 14
-#define SC_CRACKER2 15
-#define SC_TOTAL 14
+#define SC_SENSOR 3
+#define SC_FORCE 4
+#define SC_EXPLOSIVE 5
+#define SC_GAS 6
+#define SC_LIQUID 7
+#define SC_POWDERS 8
+#define SC_SOLIDS 9
+#define SC_NUCLEAR 10
+#define SC_SPECIAL 11
+#define SC_LIFE 12
+#define SC_TOOL 13
+#define SC_DECO 14
+#define SC_CRACKER 15
+#define SC_CRACKER2 16
+#define SC_TOTAL 15
#define UI_WALLSTART 222
#define UI_ACTUALSTART 122
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() {}
diff --git a/src/simulation/elements/DTEC.cpp b/src/simulation/elements/DTEC.cpp
index 62b409a..38161cf 100644
--- a/src/simulation/elements/DTEC.cpp
+++ b/src/simulation/elements/DTEC.cpp
@@ -6,7 +6,7 @@ Element_DTEC::Element_DTEC()
Name = "DTEC";
Colour = PIXPACK(0xFD9D18);
MenuVisible = 1;
- MenuSection = SC_ELEC;
+ MenuSection = SC_SENSOR;
Enabled = 1;
Advection = 0.0f;
@@ -46,7 +46,8 @@ Element_DTEC::Element_DTEC()
}
-int in_radius(int rd, int x, int y)
+//#TPT-Directive ElementHeader Element_DTEC static int in_radius(int rd, int x, int y)
+int Element_DTEC::in_radius(int rd, int x, int y)
{
return (pow((double)x,2)*pow((double)rd,2)+pow((double)y,2)*pow((double)rd,2)<=pow((double)rd,2)*pow((double)rd,2));
}
diff --git a/src/simulation/elements/TSNS.cpp b/src/simulation/elements/TSNS.cpp
new file mode 100644
index 0000000..5c8a23b
--- /dev/null
+++ b/src/simulation/elements/TSNS.cpp
@@ -0,0 +1,91 @@
+#include "simulation/Elements.h"
+//#TPT-Directive ElementClass Element_TSNS PT_TSNS 164
+Element_TSNS::Element_TSNS()
+{
+ Identifier = "DEFAULT_PT_TSNS";
+ Name = "TSNS";
+ Colour = PIXPACK(0xFD9D18);
+ MenuVisible = 1;
+ MenuSection = SC_SENSOR;
+ Enabled = 1;
+
+ Advection = 0.0f;
+ AirDrag = 0.00f * CFDS;
+ AirLoss = 0.96f;
+ 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 = "Creates a spark when there's a nearby particle with equal or greater temperature";
+
+ State = ST_SOLID;
+ Properties = TYPE_SOLID;
+
+ LowPressure = IPL;
+ LowPressureTransition = NT;
+ HighPressure = IPH;
+ HighPressureTransition = NT;
+ LowTemperature = ITL;
+ LowTemperatureTransition = NT;
+ HighTemperature = ITH;
+ HighTemperatureTransition = NT;
+
+ Update = &Element_TSNS::update;
+
+}
+
+//#TPT-Directive ElementHeader Element_TSNS static int update(UPDATE_FUNC_ARGS)
+int Element_TSNS::update(UPDATE_FUNC_ARGS)
+{
+ int r, rx, ry, rt, rd = parts[i].tmp2;
+ if (rd > 25) parts[i].tmp2 = rd = 25;
+ if (parts[i].life)
+ {
+ parts[i].life = 0;
+ 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;
+ rt = parts[r>>8].type;
+ if (sim->parts_avg(i,r>>8,PT_INSL) != PT_INSL)
+ {
+ if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && Element_DTEC::in_radius(rd, rx, ry))
+ {
+ parts[r>>8].life = 4;
+ parts[r>>8].ctype = rt;
+ sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
+ }
+ }
+ }
+ }
+ for (rx=-rd; rx<rd+1; rx++)
+ for (ry=-rd; ry<rd+1; 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 (parts[r>>8].temp >= parts[i].temp && parts[r>>8].type != PT_TSNS)
+ parts[i].life = 1;
+ }
+ return 0;
+}
+
+
+
+Element_TSNS::~Element_TSNS() {}