summaryrefslogtreecommitdiff
path: root/src/elements
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2012-08-10 14:20:05 (GMT)
committer jacksonmj <mj-pt@jacksonmj.co.uk>2012-09-02 20:48:58 (GMT)
commitd83774602f0e5a547ce171bc1ca785b594018ec6 (patch)
tree39a51a670699f78bf129dae34cda7ee16db92063 /src/elements
parent355dcf50d2292b7505696ffbb85be4daa27a7930 (diff)
downloadpowder-d83774602f0e5a547ce171bc1ca785b594018ec6.zip
powder-d83774602f0e5a547ce171bc1ca785b594018ec6.tar.gz
DTEC, generates a spark when something with it's ctype is nearby
Diffstat (limited to 'src/elements')
-rw-r--r--src/elements/dtec.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/elements/dtec.c b/src/elements/dtec.c
new file mode 100644
index 0000000..28058e7
--- /dev/null
+++ b/src/elements/dtec.c
@@ -0,0 +1,59 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <element.h>
+
+int update_DTEC(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 (parts_avg(i,r>>8,PT_INSL) != PT_INSL)
+ {
+ if ((ptypes[rt].properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && in_radius(rd, rx, ry))
+ {
+ parts[r>>8].life = 4;
+ parts[r>>8].ctype = rt;
+ 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].type == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[r>>8].tmp))
+ parts[i].life = 1;
+ }
+ return 0;
+}
+
+int 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));
+} \ No newline at end of file