diff --git a/code/modules/power/cable.dm b/code/modules/power/cable.dm index 5d6aa52281..02e2147f28 100644 --- a/code/modules/power/cable.dm +++ b/code/modules/power/cable.dm @@ -347,64 +347,54 @@ obj/structure/cable/proc/cableColor(var/colorC) . = list() // this will be a list of all connected power objects var/turf/T -///// Z-Level Stuff - if (d1 == 11 || d1 == 12) + // Handle up/down cables + if(d1 == 11 || d1 == 12 || d2 == 11 || d2 == 12) var/turf/controllerlocation = locate(1, 1, z) for(var/obj/effect/landmark/zcontroller/controller in controllerlocation) - if(controller.up && d1 == 12) + if(controller.up && (d1 == 12 || d2 == 12)) T = locate(src.x, src.y, controller.up_target) if(T) . += power_list(T, src, 11, 1) - if(controller.down && d1 == 11) + if(controller.down && (d1 == 11 || d2 == 11)) T = locate(src.x, src.y, controller.down_target) if(T) . += power_list(T, src, 12, 1) -///// Z-Level Stuff - //get matching cables from the first direction - else if(d1) //if not a node cable - T = get_step(src, d1) - if(T) - . += power_list(T, src, turn(d1, 180), powernetless_only) //get adjacents matching cables - if(d1&(d1-1)) //diagonal direction, must check the 4 possibles adjacents tiles - T = get_step(src,d1&3) // go north/south + // Handle standard cables in adjacent turfs + for(var/cable_dir in list(d1, d2)) + if(cable_dir == 11 || cable_dir == 12 || cable_dir == 0) + continue + var/reverse = reverse_dir[cable_dir] + T = get_step(src, cable_dir) if(T) - . += power_list(T, src, d1 ^ 3, powernetless_only) //get diagonally matching cables - T = get_step(src,d1&12) // go east/west - if(T) - . += power_list(T, src, d1 ^ 12, powernetless_only) //get diagonally matching cables - - . += power_list(loc, src, d1, powernetless_only) //get on turf matching cables - -///// Z-Level Stuff - if(d2 == 11 || d2 == 12) - var/turf/controllerlocation = locate(1, 1, z) - for(var/obj/effect/landmark/zcontroller/controller in controllerlocation) - if(controller.up && d2 == 12) - T = locate(src.x, src.y, controller.up_target) + for(var/obj/structure/cable/C in T) + if((C.d1 && C.d1 == reverse) || (C.d2 && C.d2 == reverse)) + . += C + if(cable_dir & (cable_dir - 1)) // Diagonal, check for /\/\/\ style cables along cardinal directions + for(var/pair in list(NORTH|SOUTH, EAST|WEST)) + T = get_step(src, cable_dir & pair) if(T) - . += power_list(T, src, 11, 1) - if(controller.down && d2 == 11) - T = locate(src.x, src.y, controller.down_target) - if(T) - . += power_list(T, src, 12, 1) -///// Z-Level Stuff - else - //do the same on the second direction (which can't be 0) - T = get_step(src, d2) - if(T) - . += power_list(T, src, turn(d2, 180), powernetless_only) //get adjacents matching cables + var/req_dir = cable_dir ^ pair + for(var/obj/structure/cable/C in T) + if((C.d1 && C.d1 == req_dir) || (C.d2 && C.d2 == req_dir)) + . += C - if(d2&(d2-1)) //diagonal direction, must check the 4 possibles adjacents tiles - T = get_step(src,d2&3) // go north/south - if(T) - . += power_list(T, src, d2 ^ 3, powernetless_only) //get diagonally matching cables - T = get_step(src,d2&12) // go east/west - if(T) - . += power_list(T, src, d2 ^ 12, powernetless_only) //get diagonally matching cables - . += power_list(loc, src, d2, powernetless_only) //get on turf matching cables + // Handle cables on the same turf as us + for(var/obj/structure/cable/C in loc) + if(C.d1 == d1 || C.d2 == d1 || C.d1 == d2 || C.d2 == d2) // if either of C's d1 and d2 match either of ours + . += C - return . + if(d1 == 0) + for(var/obj/machinery/power/P in loc) + if(P.powernet == 0) continue // exclude APCs with powernet=0 + if(!powernetless_only || !P.powernet) + . += P + + // if the caller asked for powernetless cables only, dump the ones with powernets + if(powernetless_only) + for(var/obj/structure/cable/C in .) + if(C.powernet) + . -= C //should be called after placing a cable which extends another cable, creating a "smooth" cable that no longer terminates in the centre of a turf. //needed as this can, unlike other placements, disconnect cables