diff --git a/code/datums/smooth.dm b/code/datums/smooth.dm index 8eb2d85c06e..16d6f49e3cb 100644 --- a/code/datums/smooth.dm +++ b/code/datums/smooth.dm @@ -1,157 +1,134 @@ /atom/var/smooth = 0 -/atom/var/datum/tile_smoother/smoother = null +/atom/var/top_left_corner +/atom/var/top_right_corner +/atom/var/bottom_left_corner +/atom/var/bottom_right_corner +/atom/var/can_be_unanchored = 0 /atom/var/list/canSmoothWith=list() // TYPE PATHS I CAN SMOOTH WITH~~~~~ -//generic (by snowflake) tile smoothing datum; smooth your icons with this! +//generic (by snowflake) tile smoothing code; smooth your icons with this! /* Each tile is divided in 4 corners, each corner has an image associated to it; the tile is then overlayed by these 4 images - To use this, just set your atom's 'smooth' var to 1. If your atom can't be moved/unanchored, set its 'can_be_unanchored' var to 0. + To use this, just set your atom's 'smooth' var to 1. If your atom can be moved/unanchored, set its 'can_be_unanchored' var to 1. If you don't want your atom's icon to smooth with anything but atoms of the same type, set the list 'canSmoothWith' to null; Otherwise, put all types you want the atom icon to smooth with in 'canSmoothWith' INCLUDING THE TYPE OF THE ATOM ITSELF. Each atom has its own icon file with all the possible corner states. See 'smooth_wall.dmi' for a template. */ -/datum/tile_smoother - var/image/top_right - var/image/top_left - var/image/bottom_left - var/image/bottom_right - var/atom/holder - var/cardinal_adj - var/list/diagonal_adj - var/list/siblings - var/movable - var/enabled = 1 -/datum/tile_smoother/New(var/a_holder, var/list/s_list=null, movable_b = 0) - holder = a_holder - top_left += "1-i" - top_right += "2-i" - bottom_left += "3-i" - bottom_right += "4-i" - if(s_list && s_list.len == 0) - siblings = null - else - siblings = s_list - movable = movable_b +//Redefinitions of the diagonal directions so they can be stored in one var without conflicts +#define NORTH_EAST 16 +#define NORTH_WEST 32 +#define SOUTH_EAST 64 +#define SOUTH_WEST 128 -/datum/tile_smoother/proc/update_adjacencies() - cardinal_adj = 0 - diagonal_adj = list() - if(movable) - var/atom/movable/A = holder - if(!A.anchored) - cardinal_adj = 0 - diagonal_adj = list() - return - for(var/direction in cardinal) - var/atom/movable/AM = find_type_in_direction(holder, direction, siblings) +/proc/calculate_adjacencies(atom/A) + var/adjacencies = 0 + + if(A.can_be_unanchored) + var/atom/movable/T = A + if(!T.anchored) + return 0 + + for(var/direction in alldirs) + var/atom/movable/AM = find_type_in_direction(A, direction) if(AM) if(AM.anchored) - cardinal_adj |= direction - for(var/direction in diagonals) - if(find_type_in_direction(holder, direction, siblings)) - diagonal_adj |= direction + adjacencies |= transform_dir(direction) else - for(var/direction in cardinal) - if(find_type_in_direction(holder, direction, siblings)) - cardinal_adj |= direction - for(var/direction in diagonals) - if(find_type_in_direction(holder, direction, siblings)) - diagonal_adj |= direction + for(var/direction in alldirs) + if(find_type_in_direction(A, direction)) + adjacencies |= transform_dir(direction) + return adjacencies -/datum/tile_smoother/proc/smooth() - if(!enabled) return +/proc/smooth_icon(atom/A) spawn(2) - if(holder && holder.smooth) - holder.overlays -= top_left - holder.overlays -= top_right - holder.overlays -= bottom_right - holder.overlays -= bottom_left + if(A && A.smooth) + clear_overlays(A) + var/adjacencies = calculate_adjacencies(A) - update_adjacencies() - make_nw_corner() - make_ne_corner() - make_sw_corner() - make_se_corner() + A.top_left_corner = make_nw_corner(adjacencies) + A.top_right_corner = make_ne_corner(adjacencies) + A.bottom_left_corner = make_sw_corner(adjacencies) + A.bottom_right_corner = make_se_corner(adjacencies) - holder.overlays += top_left - holder.overlays += top_right - holder.overlays += bottom_right - holder.overlays += bottom_left + A.overlays += A.top_left_corner + A.overlays += A.top_right_corner + A.overlays += A.bottom_right_corner + A.overlays += A.bottom_left_corner -/datum/tile_smoother/proc/make_nw_corner() - var/sdir = "" - if((cardinal_adj & NORTH) && (cardinal_adj & WEST)) - if(NORTHWEST in diagonal_adj) +/proc/make_nw_corner(adjacencies) + var/sdir = "i" + if((adjacencies & NORTH) && (adjacencies & WEST)) + if(adjacencies & NORTH_WEST) sdir = "f" else sdir = "nw" else - if(cardinal_adj & NORTH) + if(adjacencies & NORTH) sdir = "n" - else if(cardinal_adj & WEST) + else if(adjacencies & WEST) sdir = "w" else sdir = "i" - top_left = "1-[sdir]" + return "1-[sdir]" -/datum/tile_smoother/proc/make_ne_corner() - var/sdir = "" - if((cardinal_adj & NORTH) && (cardinal_adj & EAST)) - if(NORTHEAST in diagonal_adj) +/proc/make_ne_corner(adjacencies) + var/sdir = "i" + if((adjacencies & NORTH) && (adjacencies & EAST)) + if(adjacencies & NORTH_EAST) sdir = "f" else sdir = "ne" else - if(cardinal_adj & NORTH) + if(adjacencies & NORTH) sdir = "n" - else if(cardinal_adj & EAST) + else if(adjacencies & EAST) sdir = "e" else sdir = "i" - top_right = "2-[sdir]" + return "2-[sdir]" -/datum/tile_smoother/proc/make_sw_corner() - var/sdir = "" - if((cardinal_adj & SOUTH) && (cardinal_adj & WEST)) - if(SOUTHWEST in diagonal_adj) +/proc/make_sw_corner(adjacencies) + var/sdir = "i" + if((adjacencies & SOUTH) && (adjacencies & WEST)) + if(adjacencies & SOUTH_WEST) sdir = "f" else sdir = "sw" else - if(cardinal_adj & SOUTH) + if(adjacencies & SOUTH) sdir = "s" - else if(cardinal_adj & WEST) + else if(adjacencies & WEST) sdir = "w" else sdir = "i" - bottom_left = "3-[sdir]" + return "3-[sdir]" -/datum/tile_smoother/proc/make_se_corner() - var/sdir = "" - if((cardinal_adj & SOUTH) && (cardinal_adj & EAST)) - if(SOUTHEAST in diagonal_adj) +/proc/make_se_corner(adjacencies) + var/sdir = "i" + if((adjacencies & SOUTH) && (adjacencies & EAST)) + if(adjacencies & SOUTH_EAST) sdir = "f" else sdir = "se" else - if(cardinal_adj & SOUTH) + if(adjacencies & SOUTH) sdir = "s" else - if(cardinal_adj & EAST) + if(adjacencies & EAST) sdir = "e" else sdir = "i" - bottom_right = "4-[sdir]" + return "4-[sdir]" -/datum/tile_smoother/proc/update_neighbors() - for(var/atom/A in orange(1,holder)) - if(A.smoother) - A.smoother.smooth() +/proc/smooth_icon_neighbors(atom/A) + for(var/atom/T in orange(1,A)) + if(T.smooth) + smooth_icon(T) -/proc/find_type_in_direction(atom/source, direction, list/siblings=null, range=1) +/proc/find_type_in_direction(atom/source, direction, range=1) var/x_offset = 0 var/y_offset = 0 @@ -165,6 +142,7 @@ else if(direction & WEST) x_offset -= range + var/list/siblings = source.canSmoothWith if(istype(source, /turf)) if(siblings) for(var/a_type in siblings) @@ -194,13 +172,21 @@ var/atom/A = locate(source.type) in locate(source.x + x_offset, source.y + y_offset, source.z) return A && A.type == source.type ? A : null -/datum/tile_smoother/proc/enable_smoothing(enable = 1) - if(!enable) - enabled = 0 - holder.overlays -= top_left - holder.overlays -= top_right - holder.overlays -= bottom_right - holder.overlays -= bottom_left - else - enabled = 1 - smooth() +/proc/clear_overlays(atom/A) + A.overlays -= A.top_left_corner + A.overlays -= A.top_right_corner + A.overlays -= A.bottom_right_corner + A.overlays -= A.bottom_left_corner + +/proc/transform_dir(direction) + switch(direction) + if(NORTH,SOUTH,EAST,WEST) + return direction + if(NORTHEAST) + return NORTH_EAST + if(NORTHWEST) + return NORTH_WEST + if(SOUTHEAST) + return SOUTH_EAST + if(SOUTHWEST) + return SOUTH_WEST \ No newline at end of file diff --git a/code/game/objects/structures.dm b/code/game/objects/structures.dm index 714e5a6065b..1e32b6d50d1 100644 --- a/code/game/objects/structures.dm +++ b/code/game/objects/structures.dm @@ -1,14 +1,12 @@ /obj/structure icon = 'icons/obj/structures.dmi' pressure_resistance = 8 - var/can_be_unanchored = 1 /obj/structure/New() ..() if(smooth) - smoother = new /datum/tile_smoother(src, canSmoothWith, can_be_unanchored) - smoother.smooth() - smoother.update_neighbors() + smooth_icon(src) + smooth_icon_neighbors(src) icon_state = "" /obj/structure/blob_act() @@ -18,8 +16,8 @@ /obj/structure/Destroy() if(opacity) UpdateAffectingLights() - if(smoother) - smoother.update_neighbors() + if(smooth) + smooth_icon_neighbors(src) ..() /obj/structure/mech_melee_attack(obj/mecha/M) diff --git a/code/game/objects/structures/tables_racks.dm b/code/game/objects/structures/tables_racks.dm index 5c15301f36f..02c24df2966 100644 --- a/code/game/objects/structures/tables_racks.dm +++ b/code/game/objects/structures/tables_racks.dm @@ -29,7 +29,6 @@ var/framestackamount = 2 var/mob/tableclimber smooth = 1 - can_be_unanchored = 0 canSmoothWith = list(/obj/structure/table, /obj/structure/table/reinforced) /obj/structure/table/New() @@ -39,9 +38,9 @@ qdel(T) /obj/structure/table/update_icon() - if(smoother) - smoother.smooth() - smoother.update_neighbors() + if(smooth) + smooth_icon(src) + smooth_icon_neighbors(src) /obj/structure/table/ex_act(severity, target) ..() diff --git a/code/game/objects/structures/window.dm b/code/game/objects/structures/window.dm index fbc02b21c3c..da4391f6856 100644 --- a/code/game/objects/structures/window.dm +++ b/code/game/objects/structures/window.dm @@ -19,6 +19,7 @@ // var/silicate = 0 // number of units of silicate // var/icon/silicateIcon = null // the silicated icon var/image/crack_overlay + can_be_unanchored = 1 /obj/structure/window/New(Loc,re=0) ..() @@ -380,8 +381,8 @@ //This proc is used to update the icons of nearby windows. /obj/structure/window/proc/update_nearby_icons() update_icon() - if(smoother) - smoother.update_neighbors() + if(smooth) + smooth_icon_neighbors(src) //merges adjacent full-tile windows into one (blatant ripoff from game/smoothwall.dm) /obj/structure/window/update_icon() @@ -396,8 +397,8 @@ var/ratio = health / maxhealth ratio = Ceiling(ratio*4) * 25 - if(smoother) - smoother.smooth() + if(smooth) + smooth_icon(src) if(ratio > 75) overlays -= crack_overlay return diff --git a/code/game/turfs/simulated.dm b/code/game/turfs/simulated.dm index b6ed60e1f03..d61b3cd006c 100644 --- a/code/game/turfs/simulated.dm +++ b/code/game/turfs/simulated.dm @@ -13,8 +13,7 @@ ..() levelupdate() if(smooth) - smoother = new /datum/tile_smoother(src, canSmoothWith) - smoother.smooth() + smooth_icon(src) icon_state = "" /turf/simulated/proc/burn_tile() @@ -57,6 +56,4 @@ /turf/simulated/ChangeTurf(var/path) . = ..() - for(var/turf/T in orange(1,src)) //manual update because it doesnt work otherwise - if(T.smoother) - T.smoother.smooth() + smooth_icon_neighbors(src) diff --git a/code/game/turfs/simulated/floor/fancy_floor.dm b/code/game/turfs/simulated/floor/fancy_floor.dm index 06e12c63a76..d09281d8e70 100644 --- a/code/game/turfs/simulated/floor/fancy_floor.dm +++ b/code/game/turfs/simulated/floor/fancy_floor.dm @@ -60,12 +60,12 @@ if(!..()) return 0 if(!broken && !burnt) - if(smoother) - smoother.smooth() + if(smooth) + smooth_icon(src) else make_plating() - if(smoother) - smoother.update_neighbors() + if(smooth) + smooth_icon_neighbors(src) /turf/simulated/floor/carpet/break_tile() broken = 1 diff --git a/code/game/turfs/simulated/walls_reinforced.dm b/code/game/turfs/simulated/walls_reinforced.dm index f363b8e77c4..c1642ac09c1 100644 --- a/code/game/turfs/simulated/walls_reinforced.dm +++ b/code/game/turfs/simulated/walls_reinforced.dm @@ -54,7 +54,7 @@ MS.use(1) src.d_state = 0 src.icon_state = "r_wall" - smoother.update_neighbors() + smooth_icon_neighbors(src) user << "You repair the last of the damage." return 1 return 0 @@ -215,9 +215,10 @@ /turf/simulated/wall/r_wall/proc/update_icon() if(d_state) icon_state = "r_wall-[d_state]" - smoother.enable_smoothing(0) + smooth = 0 + clear_overlays(src) else - smoother.enable_smoothing(1) + smooth = 1 icon_state = "" /turf/simulated/wall/r_wall/singularity_pull(S, current_size) diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index a5e4bc0a0ad..a2851a7c4c4 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -291,8 +291,7 @@ /turf/indestructible/riveted/New() ..() if(smooth) - smoother = new /datum/tile_smoother(src, canSmoothWith) - smoother.smooth() + smooth_icon(src) icon_state = "" /turf/indestructible/riveted/uranium