diff --git a/src/simulation/elements/SWCH.cpp b/src/simulation/elements/SWCH.cpp index fa8e49e9f..818af2700 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))) + //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 = 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)))) - { - 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; }