summaryrefslogtreecommitdiff
path: root/src/simulation/elements/SWCH.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-05 20:10:35 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-05 20:10:35 (GMT)
commit150a2e528ee41cb596b59c8a3c9ec62e9bf686fa (patch)
tree4aa02da9f38c5f24acc5ac1176d4010ace8fc8dd /src/simulation/elements/SWCH.cpp
parent8614a2d9638da8ee6982e2a8eadf95eaf5365aa6 (diff)
parent7da144fbae1dac390ddf3bbcc69a990cf91398ac (diff)
downloadpowder-150a2e528ee41cb596b59c8a3c9ec62e9bf686fa.zip
powder-150a2e528ee41cb596b59c8a3c9ec62e9bf686fa.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/simulation/elements/SWCH.cpp')
-rw-r--r--src/simulation/elements/SWCH.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/simulation/elements/SWCH.cpp b/src/simulation/elements/SWCH.cpp
index fa8e49e..818af27 100644
--- a/src/simulation/elements/SWCH.cpp
+++ b/src/simulation/elements/SWCH.cpp
@@ -46,6 +46,11 @@ Element_SWCH::Element_SWCH()
Graphics = &Element_SWCH::graphics;
}
+bool isRedBRAY(UPDATE_FUNC_ARGS, int xc, int yc)
+{
+ return (pmap[yc][xc]&0xFF) == PT_BRAY && parts[pmap[yc][xc]>>8].tmp == 2;
+}
+
//#TPT-Directive ElementHeader Element_SWCH static int update(UPDATE_FUNC_ARGS)
int Element_SWCH::update(UPDATE_FUNC_ARGS)
{
@@ -78,15 +83,13 @@ int Element_SWCH::update(UPDATE_FUNC_ARGS)
}
}
}
- //turn off SWCH from two red BRAYS
- if (parts[i].life==10 && (!(pmap[y-1][x-1]&0xFF) && ((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) && !(pmap[y-1][x+1]&0xFF) && ((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2)))
- {
- parts[i].life = 9;
- }
- //turn on SWCH from two red BRAYS
- else if (parts[i].life<=5 && (!(pmap[y-1][x-1]&0xFF) && (((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) || ((pmap[y+1][x]&0xFF)==PT_BRAY&&parts[pmap[y+1][x]>>8].tmp==2)) && !(pmap[y-1][x+1]&0xFF) && (((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2) || ((pmap[y][x-1]&0xFF)==PT_BRAY&&parts[pmap[y][x-1]>>8].tmp==2))))
+ //turn SWCH on/off from two red BRAYS. There must be one either above or below, and one either left or right to work, and it can't come from the side, it must be a diagonal beam
+ if (!(pmap[y-1][x-1]&0xFF) && !(pmap[y-1][x+1]&0xFF) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y-1) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x, y+1)) && (isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x+1, y) || isRedBRAY(UPDATE_FUNC_SUBCALL_ARGS, x-1, y)))
{
- parts[i].life = 14;
+ if (parts[i].life == 10)
+ parts[i].life = 9;
+ else if (parts[i].life <= 5)
+ parts[i].life = 14;
}
return 0;
}