diff --git a/code/game/objects/structures/tables_racks.dm b/code/game/objects/structures/tables_racks.dm index 58ed13b9d9..f95a2b5d93 100644 --- a/code/game/objects/structures/tables_racks.dm +++ b/code/game/objects/structures/tables_racks.dm @@ -48,29 +48,30 @@ /obj/structure/table/update_icon() - if(flipped) - var/type = 0 - var/tabledirs = 0 - for(var/direction in list(turn(dir,90), turn(dir,-90)) ) - var/obj/structure/table/T = locate(/obj/structure/table,get_step(src,direction)) - if (T && T.flipped) - type++ - tabledirs |= direction - var/base = "table" - if (istype(src, /obj/structure/table/woodentable)) - base = "wood" - if (istype(src, /obj/structure/table/reinforced)) - base = "rtable" - - icon_state = "[base]flip[type]" - if (type==1) - if (tabledirs & turn(dir,90)) - icon_state = icon_state+"-" - if (tabledirs & turn(dir,-90)) - icon_state = icon_state+"+" - return 1 - spawn(2) //So it properly updates when deleting + + if(flipped) + var/type = 0 + var/tabledirs = 0 + for(var/direction in list(turn(dir,90), turn(dir,-90)) ) + var/obj/structure/table/T = locate(/obj/structure/table,get_step(src,direction)) + if (T && T.flipped && T.dir == src.dir) + type++ + tabledirs |= direction + var/base = "table" + if (istype(src, /obj/structure/table/woodentable)) + base = "wood" + if (istype(src, /obj/structure/table/reinforced)) + base = "rtable" + + icon_state = "[base]flip[type]" + if (type==1) + if (tabledirs & turn(dir,90)) + icon_state = icon_state+"-" + if (tabledirs & turn(dir,-90)) + icon_state = icon_state+"+" + return 1 + var/dir_sum = 0 for(var/direction in list(1,2,4,8,5,6,9,10)) var/skip_sum = 0 @@ -393,20 +394,19 @@ return /obj/structure/table/proc/straight_table_check(var/direction) - var/turf/left = get_step(src,turn(direction,90)) - var/turf/right = get_step(src,turn(direction,-90)) - var/turf/next = get_step(src,direction) - if(locate(/obj/structure/table,left) || locate(/obj/structure/table,right)) - return 0 - var/obj/structure/table/T = locate(/obj/structure/table, next) + var/obj/structure/table/T + for(var/angle in list(-90,90)) + T = locate() in get_step(src.loc,turn(direction,angle)) + if(T && !T.flipped) + return 0 + T = locate() in get_step(src.loc,direction) + if (!T || T.flipped) + return 1 if (istype(T,/obj/structure/table/reinforced/)) var/obj/structure/table/reinforced/R = T if (R.status == 2) return 0 - if (!T) - return 1 - else - return T.straight_table_check(direction) + return T.straight_table_check(direction) /obj/structure/table/verb/do_flip() set name = "Flip table" @@ -423,21 +423,35 @@ usr.visible_message("[usr] flips \the [src]!") return +/obj/structure/table/proc/unflipping_check(var/direction) + for(var/mob/M in oview(src,0)) + return 0 + + var/list/L = list() + if(direction) + L.Add(direction) + else + L.Add(turn(src.dir,-90)) + L.Add(turn(src.dir,90)) + for(var/new_dir in L) + var/obj/structure/table/T = locate() in get_step(src.loc,new_dir) + if(T) + if(T.flipped && T.dir == src.dir && !T.unflipping_check(new_dir)) + return 0 + return 1 + /obj/structure/table/proc/do_put() set name = "Put table back" set desc = "Puts flipped table back" set category = "Object" set src in oview(1) - if (!unflip()) + if (!unflipping_check()) usr << "It won't budge." return - + unflip() /obj/structure/table/proc/flip(var/direction) - if (flipped) - return 0 - if( !straight_table_check(turn(direction,90)) || !straight_table_check(turn(direction,-90)) ) return 0 @@ -456,8 +470,8 @@ flipped = 1 flags |= ON_BORDER for(var/D in list(turn(direction, 90), turn(direction, -90))) - if(locate(/obj/structure/table,get_step(src,D))) - var/obj/structure/table/T = locate(/obj/structure/table,get_step(src,D)) + var/obj/structure/table/T = locate() in get_step(src,D) + if(T && !T.flipped) T.flip(direction) update_icon() update_adjacent() @@ -465,16 +479,6 @@ return 1 /obj/structure/table/proc/unflip() - if (!flipped) - return 0 - - var/can_flip = 1 - for (var/mob/A in oview(src,0))//src.loc) - if (istype(A)) - can_flip = 0 - if (!can_flip) - return 0 - verbs -=/obj/structure/table/proc/do_put verbs +=/obj/structure/table/verb/do_flip @@ -482,8 +486,8 @@ flipped = 0 flags &= ~ON_BORDER for(var/D in list(turn(dir, 90), turn(dir, -90))) - if(locate(/obj/structure/table,get_step(src,D))) - var/obj/structure/table/T = locate(/obj/structure/table,get_step(src,D)) + var/obj/structure/table/T = locate() in get_step(src.loc,D) + if(T && T.flipped && T.dir == src.dir) T.unflip() update_icon() update_adjacent() @@ -646,4 +650,4 @@ del(src) /obj/structure/rack/attack_tk() // no telehulk sorry - return + return \ No newline at end of file