summaryrefslogtreecommitdiff
path: root/src/simulation/elements/LIGH.cpp
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-01-06 03:29:33 (GMT)
committer jacob1 <jfu614@gmail.com>2013-01-06 03:29:33 (GMT)
commit0cf027c52986f20eb984d2b6f64a75044786166b (patch)
treee40e27b47d66a9308978971437c052e152b570c7 /src/simulation/elements/LIGH.cpp
parent8f4d936de81c15e1ba91a2a4a2e79e039707a121 (diff)
downloadpowder-0cf027c52986f20eb984d2b6f64a75044786166b.zip
powder-0cf027c52986f20eb984d2b6f64a75044786166b.tar.gz
VOID, VACU, and BHOL eat LIGH as it moves
Diffstat (limited to 'src/simulation/elements/LIGH.cpp')
-rw-r--r--src/simulation/elements/LIGH.cpp90
1 files changed, 60 insertions, 30 deletions
diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp
index c0c723e..f697ebe 100644
--- a/src/simulation/elements/LIGH.cpp
+++ b/src/simulation/elements/LIGH.cpp
@@ -285,14 +285,33 @@ int Element_LIGH::contact_part(Simulation * sim, int i, int tp)
return -1;
}
+//#TPT-Directive ElementHeader Element_LIGH static bool create_LIGH(Simulation * sim, int x, int y, int c, int temp, int life, int tmp, int tmp2)
+bool Element_LIGH::create_LIGH(Simulation * sim, int x, int y, int c, int temp, int life, int tmp, int tmp2)
+{
+ int p = sim->create_part(-1, x, y,c);
+ if (p != -1)
+ {
+ sim->parts[p].life = life;
+ sim->parts[p].temp = temp;
+ sim->parts[p].tmp = tmp;
+ sim->parts[p].tmp2 = tmp2;
+ }
+ else
+ {
+ int r = sim->pmap[y][x];
+ if ((((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && sim->parts[r>>8].life >= 10)) && (!sim->parts[r>>8].ctype || (sim->parts[r>>8].ctype==c)!=(sim->parts[r>>8].tmp&1))) || (r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) // VOID, PVOD, VACU, and BHOL eat LIGH here
+ return true;
+ }
+ return false;
+}
+
//#TPT-Directive ElementHeader Element_LIGH static void create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2)
void Element_LIGH::create_line_par(Simulation * sim, int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2)
{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (c==WL_EHOLE || c==WL_ALLOWGAS || c==WL_ALLOWALLELEC || c==WL_ALLOWSOLID || c==WL_ALLOWAIR || c==WL_WALL || c==WL_DESTROYALL || c==WL_ALLOWLIQUID || c==WL_FAN || c==WL_STREAM || c==WL_DETECT || c==WL_EWALL || c==WL_WALLELEC)
- return; // this function only for particles, no walls
- if (cp)
+ bool reverseXY = abs(y2-y1) > abs(x2-x1), back = false;
+ int x, y, dx, dy, Ystep;
+ float e = 0.0f, de;
+ if (reverseXY)
{
y = x1;
x1 = y1;
@@ -302,42 +321,53 @@ void Element_LIGH::create_line_par(Simulation * sim, int x1, int y1, int x2, int
y2 = y;
}
if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
+ back = 1;
dx = x2 - x1;
dy = abs(y2 - y1);
- e = 0.0f;
if (dx)
de = dy/(float)dx;
else
de = 0.0f;
y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
+ Ystep = (y1<y2) ? 1 : -1;
+ if (!back)
{
- int p;
- if (cp)
- p = sim->create_part(-1, y, x, c);
- else
- p = sim->create_part(-1, x, y,c);
- if (p!=-1)
+ for (x = x1; x <= x2; x++)
{
- sim->parts[p].life = life;
- sim->parts[p].temp = temp;
- sim->parts[p].tmp = tmp;
- sim->parts[p].tmp2 = tmp2;
+ bool ret;
+ if (reverseXY)
+ ret = create_LIGH(sim, y, x, c, temp, life, tmp, tmp2);
+ else
+ ret = create_LIGH(sim, x, y, c, temp, life, tmp, tmp2);
+ if (ret)
+ return;
+
+ e += de;
+ if (e >= 0.5f)
+ {
+ y += Ystep;
+ e -= 1.0f;
+ }
}
- e += de;
- if (e >= 0.5f)
+ }
+ else
+ {
+ for (x = x1; x >= x2; x--)
{
- y += sy;
- e -= 1.0f;
+ bool ret;
+ if (reverseXY)
+ ret = create_LIGH(sim, y, x, c, temp, life, tmp, tmp2);
+ else
+ ret = create_LIGH(sim, x, y, c, temp, life, tmp, tmp2);
+ if (ret)
+ return;
+
+ e += de;
+ if (e <= -0.5f)
+ {
+ y += Ystep;
+ e += 1.0f;
+ }
}
}
}