From 3b0b9636095f3b13e5d86d83a67d9467e63f2d7e Mon Sep 17 00:00:00 2001 From: c0 Date: Fri, 21 Apr 2017 11:20:00 +0300 Subject: [PATCH] Fixes wires breaking on shuttle movement/rotation --- code/game/mecha/equipment/tools/work_tools.dm | 4 +- code/modules/power/cable.dm | 63 +++++++++++++++++-- code/modules/shuttle/on_move.dm | 13 ++-- code/modules/shuttle/shuttle.dm | 13 ++++ 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/code/game/mecha/equipment/tools/work_tools.dm b/code/game/mecha/equipment/tools/work_tools.dm index e7e83790953..8a78bad45ae 100644 --- a/code/game/mecha/equipment/tools/work_tools.dm +++ b/code/game/mecha/equipment/tools/work_tools.dm @@ -409,13 +409,13 @@ NC.cableColor("red") NC.d1 = 0 NC.d2 = fdirn - NC.updateicon() + NC.update_icon() var/datum/powernet/PN if(last_piece && last_piece.d2 != chassis.dir) last_piece.d1 = min(last_piece.d2, chassis.dir) last_piece.d2 = max(last_piece.d2, chassis.dir) - last_piece.updateicon() + last_piece.update_icon() PN = last_piece.powernet if(!PN) diff --git a/code/modules/power/cable.dm b/code/modules/power/cable.dm index cbb520b6800..a4c9420ce8a 100644 --- a/code/modules/power/cable.dm +++ b/code/modules/power/cable.dm @@ -108,9 +108,9 @@ By design, d1 is the smallest direction and d2 is the highest if(level == 1 && isturf(loc)) invisibility = i ? INVISIBILITY_MAXIMUM : 0 - updateicon() + update_icon() -/obj/structure/cable/proc/updateicon() +/obj/structure/cable/update_icon() if(invisibility) icon_state = "[d1]-[d2]-f" else @@ -429,6 +429,59 @@ By design, d1 is the smallest direction and d2 is the highest if(!P.connect_to_network()) //can't find a node cable on a the turf to connect to P.disconnect_from_network() //remove from current network +// Ugly procs that ensure proper separation and reconnection of wires on shuttle movement/rotation +/obj/structure/cable/beforeShuttleMove(turf/T1, rotation) + var/on_edge = FALSE + var/A = get_area(src) + + for(var/D in GLOB.alldirs) + if(A != get_area(get_step(src, D))) + on_edge = TRUE + break + + if(on_edge && powernet) + var/tmp_loc = loc + cut_cable_from_powernet() + loc = tmp_loc + +/obj/structure/cable/afterShuttleMove() + var/on_edge = FALSE + var/A = get_area(src) + + for(var/D in GLOB.alldirs) + if(A != get_area(get_step(src, D))) + on_edge = TRUE + break + + if(on_edge) + var/datum/powernet/PN = new() + PN.add_cable(src) + + mergeConnectedNetworks(d1) //merge the powernet with adjacents powernets + mergeConnectedNetworks(d2) + mergeConnectedNetworksOnTurf() //merge the powernet with on turf powernets + + if(d1 & (d1 - 1))// if the cable is layed diagonally, check the others 2 possible directions + mergeDiagonalsNetworks(d1) + if(d2 & (d2 - 1)) + mergeDiagonalsNetworks(d2) + +/obj/structure/cable/shuttleRotate(rotation) + //..() is not called because wires are not supposed to have a non-default direction + //Rotate connections + if(d1) + d1 = angle2dir(rotation+dir2angle(d1)) + if(d2) + d2 = angle2dir(rotation+dir2angle(d2)) + + //d1 should be less than d2 for cable icons to work + if(d1 > d2) + var/temp = d1 + d1 = d2 + d2 = temp + update_icon() + + /////////////////////////////////////////////// // The cable coil object, used for laying cable /////////////////////////////////////////////// @@ -584,7 +637,7 @@ GLOBAL_LIST_INIT(cable_coil_recipes, list (new/datum/stack_recipe("cable restrai C.d1 = 0 //it's a O-X node cable C.d2 = dirn C.add_fingerprint(user) - C.updateicon() + C.update_icon() //create a new powernet with the cable, if needed it will be merged later var/datum/powernet/PN = new() @@ -650,7 +703,7 @@ GLOBAL_LIST_INIT(cable_coil_recipes, list (new/datum/stack_recipe("cable restrai NC.d1 = 0 NC.d2 = fdirn NC.add_fingerprint() - NC.updateicon() + NC.update_icon() //create a new powernet with the cable, if needed it will be merged later var/datum/powernet/newPN = new() @@ -699,7 +752,7 @@ GLOBAL_LIST_INIT(cable_coil_recipes, list (new/datum/stack_recipe("cable restrai C.update_stored(2, item_color) C.add_fingerprint() - C.updateicon() + C.update_icon() C.mergeConnectedNetworks(C.d1) //merge the powernets... diff --git a/code/modules/shuttle/on_move.dm b/code/modules/shuttle/on_move.dm index eadf2503e75..7cf6e37a774 100644 --- a/code/modules/shuttle/on_move.dm +++ b/code/modules/shuttle/on_move.dm @@ -1,3 +1,7 @@ +// Called before shuttle starts moving atoms. +/atom/movable/proc/beforeShuttleMove(turf/T1, rotation) + return + // Called when shuttle attempts to move an atom. /atom/movable/proc/onShuttleMove(turf/T1, rotation) if(rotation) @@ -18,15 +22,6 @@ . = ..() -#define DIR_CHECK_TURF_AREA(X) (get_area(get_ranged_target_turf(src, X, 1)) != A) -/obj/structure/cable/onShuttleMove() - . = ..() - var/A = get_area(src) - //cut cables on the edge - if(DIR_CHECK_TURF_AREA(NORTH) || DIR_CHECK_TURF_AREA(SOUTH) || DIR_CHECK_TURF_AREA(EAST) || DIR_CHECK_TURF_AREA(WEST)) - cut_cable_from_powernet() -#undef DIR_CHECK_TURF_AREA - /atom/movable/light/onShuttleMove() return 0 diff --git a/code/modules/shuttle/shuttle.dm b/code/modules/shuttle/shuttle.dm index fb4afc8c830..94d10392ccd 100644 --- a/code/modules/shuttle/shuttle.dm +++ b/code/modules/shuttle/shuttle.dm @@ -481,6 +481,19 @@ //move or squish anything in the way ship at destination roadkill(L0, L1, S1.dir) + + for(var/i in 1 to L0.len) + var/turf/T0 = L0[i] + if(!T0) + continue + var/turf/T1 = L1[i] + if(!T1) + continue + if(T0.type == T0.baseturf) + continue + for(var/atom/movable/AM in T0) + AM.beforeShuttleMove(T1, rotation) + var/list/moved_atoms = list() for(var/i in 1 to L0.len)