Files
Bubberstation/code/game/objects/structures/window.dm
MrPerson ff3f84ab81 Replaces /image with /mutable_appearance, where appropriate (#26518)
In cases where you're creating an image to use as an overlay, it makes more sense to use a mutable_appearance if you can. The image will create a static appearance for not just the image but also each intermediate step if you change vars along the way. The mutable appearance avoids this unnecessary and expensive process. The only situation that requires an image instead of a mutable_appearance is if the overlay is supposed to be directional. MA's ignore direction while images don't. I dunno why, probably another BYOND-ism.

I added a convenience function, mutable_appearance(), designed to emulate image(). Also went ahead and set the default plane of /mutable_appearance to FLOAT_PLANE because it's fucking 0 by default.

Several overlays that were image() calls were changed to just text strings when I could. overlays += "string" has the same result as overlays += image(icon, "string") and saves a proc call.
2017-04-25 12:15:16 +02:00

577 lines
18 KiB
Plaintext

/obj/structure/window
name = "window"
desc = "A window."
icon_state = "window"
density = 1
layer = ABOVE_OBJ_LAYER //Just above doors
pressure_resistance = 4*ONE_ATMOSPHERE
anchored = 1 //initially is 0 for tile smoothing
flags = ON_BORDER
max_integrity = 25
obj_integrity = 25
var/ini_dir = null
var/state = WINDOW_OUT_OF_FRAME
var/reinf = 0
var/heat_resistance = 800
var/decon_speed = 30
var/wtype = "glass"
var/fulltile = 0
var/glass_type = /obj/item/stack/sheet/glass
var/glass_amount = 1
var/static/mutable_appearance/crack_overlay = mutable_appearance('icons/obj/structures.dmi')
var/list/debris = list()
can_be_unanchored = 1
resistance_flags = ACID_PROOF
armor = list(melee = 0, bullet = 0, laser = 0, energy = 0, bomb = 0, bio = 0, rad = 0, fire = 80, acid = 100)
CanAtmosPass = ATMOS_PASS_PROC
/obj/structure/window/examine(mob/user)
..()
to_chat(user, "<span class='notice'>Alt-click to rotate it clockwise.</span>")
/obj/structure/window/Initialize(mapload, direct)
..()
obj_integrity = max_integrity
if(direct)
setDir(direct)
if(reinf && anchored)
state = WINDOW_SCREWED_TO_FRAME
ini_dir = dir
air_update_turf(1)
// Precreate our own debris
var/shards = 1
if(fulltile)
shards++
setDir()
var/rods = 0
if(reinf)
rods++
if(fulltile)
rods++
for(var/i in 1 to shards)
debris += new /obj/item/weapon/shard(src)
if(rods)
debris += new /obj/item/stack/rods(src, rods)
/obj/structure/window/rcd_vals(mob/user, obj/item/weapon/construction/rcd/the_rcd)
switch(the_rcd.mode)
if(RCD_DECONSTRUCT)
return list("mode" = RCD_DECONSTRUCT, "delay" = 20, "cost" = 5)
return FALSE
/obj/structure/window/rcd_act(mob/user, var/obj/item/weapon/construction/rcd/the_rcd)
switch(the_rcd.mode)
if(RCD_DECONSTRUCT)
to_chat(user, "<span class='notice'>You deconstruct the window.</span>")
qdel(src)
return TRUE
return FALSE
/obj/structure/window/narsie_act()
add_atom_colour(NARSIE_WINDOW_COLOUR, FIXED_COLOUR_PRIORITY)
for(var/obj/item/weapon/shard/shard in debris)
shard.add_atom_colour(NARSIE_WINDOW_COLOUR, FIXED_COLOUR_PRIORITY)
/obj/structure/window/ratvar_act()
if(!fulltile)
new/obj/structure/window/reinforced/clockwork(get_turf(src), dir)
else
new/obj/structure/window/reinforced/clockwork/fulltile(get_turf(src))
qdel(src)
/obj/structure/window/singularity_pull(S, current_size)
if(current_size >= STAGE_FIVE)
deconstruct(FALSE)
/obj/structure/window/setDir(direct)
if(!fulltile)
..()
else
..(FULLTILE_WINDOW_DIR)
/obj/structure/window/CanPass(atom/movable/mover, turf/target, height=0)
if(istype(mover) && mover.checkpass(PASSGLASS))
return 1
if(dir == FULLTILE_WINDOW_DIR)
return 0 //full tile window, you can't move into it!
if(get_dir(loc, target) == dir)
return !density
if(istype(mover, /obj/structure/window))
var/obj/structure/window/W = mover
if(!valid_window_location(loc, W.ini_dir))
return FALSE
else if(istype(mover, /obj/structure/windoor_assembly))
var/obj/structure/windoor_assembly/W = mover
if(!valid_window_location(loc, W.ini_dir))
return FALSE
else if(istype(mover, /obj/machinery/door/window) && !valid_window_location(loc, mover.dir))
return FALSE
return 1
/obj/structure/window/CheckExit(atom/movable/O as mob|obj, target)
if(istype(O) && O.checkpass(PASSGLASS))
return 1
if(get_dir(O.loc, target) == dir)
return 0
return 1
/obj/structure/window/attack_tk(mob/user)
user.changeNext_move(CLICK_CD_MELEE)
user.visible_message("<span class='notice'>Something knocks on [src].</span>")
add_fingerprint(user)
playsound(loc, 'sound/effects/Glassknock.ogg', 50, 1)
/obj/structure/window/attack_hulk(mob/living/carbon/human/user, does_attack_animation = 0)
if(!can_be_reached(user))
return 1
. = ..()
/obj/structure/window/attack_hand(mob/user)
if(!can_be_reached(user))
return
user.changeNext_move(CLICK_CD_MELEE)
user.visible_message("[user] knocks on [src].")
add_fingerprint(user)
playsound(loc, 'sound/effects/Glassknock.ogg', 50, 1)
/obj/structure/window/attack_paw(mob/user)
return attack_hand(user)
/obj/structure/window/attack_generic(mob/user, damage_amount = 0, damage_type = BRUTE, damage_flag = 0, sound_effect = 1) //used by attack_alien, attack_animal, and attack_slime
if(!can_be_reached(user))
return
..()
/obj/structure/window/attackby(obj/item/I, mob/living/user, params)
if(!can_be_reached(user))
return 1 //skip the afterattack
add_fingerprint(user)
if(istype(I, /obj/item/weapon/weldingtool) && user.a_intent == INTENT_HELP)
var/obj/item/weapon/weldingtool/WT = I
if(obj_integrity < max_integrity)
if(WT.remove_fuel(0,user))
to_chat(user, "<span class='notice'>You begin repairing [src]...</span>")
playsound(loc, WT.usesound, 40, 1)
if(do_after(user, 40*I.toolspeed, target = src))
obj_integrity = max_integrity
playsound(loc, 'sound/items/Welder2.ogg', 50, 1)
update_nearby_icons()
to_chat(user, "<span class='notice'>You repair [src].</span>")
else
to_chat(user, "<span class='warning'>[src] is already in good condition!</span>")
return
if(!(flags&NODECONSTRUCT))
if(istype(I, /obj/item/weapon/screwdriver))
playsound(loc, I.usesound, 75, 1)
if(reinf)
if(state == WINDOW_SCREWED_TO_FRAME || state == WINDOW_IN_FRAME)
to_chat(user, "<span class='notice'>You begin to [state == WINDOW_SCREWED_TO_FRAME ? "unscrew the window from":"screw the window to"] the frame...</span>")
if(do_after(user, decon_speed*I.toolspeed, target = src, extra_checks = CALLBACK(src, .proc/check_state_and_anchored, state, anchored)))
state = (state == WINDOW_IN_FRAME ? WINDOW_SCREWED_TO_FRAME : WINDOW_IN_FRAME)
to_chat(user, "<span class='notice'>You [state == WINDOW_IN_FRAME ? "unfasten the window from":"fasten the window to"] the frame.</span>")
else if(state == WINDOW_OUT_OF_FRAME)
to_chat(user, "<span class='notice'>You begin to [anchored ? "unscrew the frame from":"screw the frame to"] the floor...</span>")
if(do_after(user, decon_speed*I.toolspeed, target = src, extra_checks = CALLBACK(src, .proc/check_state_and_anchored, state, anchored)))
anchored = !anchored
update_nearby_icons()
to_chat(user, "<span class='notice'>You [anchored ? "fasten the frame to":"unfasten the frame from"] the floor.</span>")
else //if we're not reinforced, we don't need to check or update state
to_chat(user, "<span class='notice'>You begin to [anchored ? "unscrew the window from":"screw the window to"] the floor...</span>")
if(do_after(user, decon_speed*I.toolspeed, target = src, extra_checks = CALLBACK(src, .proc/check_anchored, anchored)))
anchored = !anchored
update_nearby_icons()
to_chat(user, "<span class='notice'>You [anchored ? "fasten the window to":"unfasten the window from"] the floor.</span>")
return
else if (istype(I, /obj/item/weapon/crowbar) && reinf && (state == WINDOW_OUT_OF_FRAME || state == WINDOW_IN_FRAME))
to_chat(user, "<span class='notice'>You begin to lever the window [state == WINDOW_OUT_OF_FRAME ? "into":"out of"] the frame...</span>")
playsound(loc, I.usesound, 75, 1)
if(do_after(user, decon_speed*I.toolspeed, target = src, extra_checks = CALLBACK(src, .proc/check_state_and_anchored, state, anchored)))
state = (state == WINDOW_OUT_OF_FRAME ? WINDOW_IN_FRAME : WINDOW_OUT_OF_FRAME)
to_chat(user, "<span class='notice'>You pry the window [state == WINDOW_IN_FRAME ? "into":"out of"] the frame.</span>")
return
else if(istype(I, /obj/item/weapon/wrench) && !anchored)
playsound(loc, I.usesound, 75, 1)
to_chat(user, "<span class='notice'> You begin to disassemble [src]...</span>")
if(do_after(user, decon_speed*I.toolspeed, target = src, extra_checks = CALLBACK(src, .proc/check_state_and_anchored, state, anchored)))
var/obj/item/stack/sheet/G = new glass_type(user.loc, glass_amount)
G.add_fingerprint(user)
playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
to_chat(user, "<span class='notice'>You successfully disassemble [src].</span>")
qdel(src)
return
return ..()
/obj/structure/window/proc/check_state(checked_state)
if(state == checked_state)
return TRUE
/obj/structure/window/proc/check_anchored(checked_anchored)
if(anchored == checked_anchored)
return TRUE
/obj/structure/window/proc/check_state_and_anchored(checked_state, checked_anchored)
return check_state(checked_state) && check_anchored(checked_anchored)
/obj/structure/window/mech_melee_attack(obj/mecha/M)
if(!can_be_reached())
return
..()
/obj/structure/window/proc/can_be_reached(mob/user)
if(!fulltile)
if(get_dir(user,src) & dir)
for(var/obj/O in loc)
if(!O.CanPass(user, user.loc, 1))
return 0
return 1
/obj/structure/window/take_damage(damage_amount, damage_type = BRUTE, damage_flag = 0, sound_effect = 1)
. = ..()
if(.) //received damage
update_nearby_icons()
/obj/structure/window/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
switch(damage_type)
if(BRUTE)
if(damage_amount)
playsound(src.loc, 'sound/effects/Glasshit.ogg', 75, 1)
else
playsound(src, 'sound/weapons/tap.ogg', 50, 1)
if(BURN)
playsound(src.loc, 'sound/items/Welder.ogg', 100, 1)
/obj/structure/window/deconstruct(disassembled = TRUE)
if(QDELETED(src))
return
if(!disassembled)
playsound(src, "shatter", 70, 1)
var/turf/T = loc
if(!(flags & NODECONSTRUCT))
for(var/i in debris)
var/obj/item/I = i
I.loc = T
transfer_fingerprints_to(I)
qdel(src)
update_nearby_icons()
/obj/structure/window/verb/rotate()
set name = "Rotate Window Counter-Clockwise"
set category = "Object"
set src in oview(1)
if(usr.stat || !usr.canmove || usr.restrained())
return
if(anchored)
to_chat(usr, "<span class='warning'>[src] cannot be rotated while it is fastened to the floor!</span>")
return FALSE
var/target_dir = turn(dir, 90)
if(!valid_window_location(loc, target_dir))
to_chat(usr, "<span class='warning'>[src] cannot be rotated in that direction!</span>")
return FALSE
setDir(target_dir)
air_update_turf(1)
ini_dir = dir
add_fingerprint(usr)
return TRUE
/obj/structure/window/verb/revrotate()
set name = "Rotate Window Clockwise"
set category = "Object"
set src in oview(1)
if(usr.stat || !usr.canmove || usr.restrained())
return
if(anchored)
to_chat(usr, "<span class='warning'>[src] cannot be rotated while it is fastened to the floor!</span>")
return FALSE
var/target_dir = turn(dir, 270)
if(!valid_window_location(loc, target_dir))
to_chat(usr, "<span class='warning'>[src] cannot be rotated in that direction!</span>")
return FALSE
setDir(target_dir)
air_update_turf(1)
ini_dir = dir
add_fingerprint(usr)
return TRUE
/obj/structure/window/AltClick(mob/user)
..()
if(user.incapacitated())
to_chat(user, "<span class='warning'>You can't do that right now!</span>")
return
if(!in_range(src, user))
return
else
revrotate()
/obj/structure/window/Destroy()
density = 0
air_update_turf(1)
update_nearby_icons()
return ..()
/obj/structure/window/Move()
var/turf/T = loc
..()
setDir(ini_dir)
move_update_air(T)
/obj/structure/window/CanAtmosPass(turf/T)
if(get_dir(loc, T) == dir)
return !density
if(dir == FULLTILE_WINDOW_DIR)
return !density
return 1
//This proc is used to update the icons of nearby windows.
/obj/structure/window/proc/update_nearby_icons()
update_icon()
if(smooth)
queue_smooth_neighbors(src)
//merges adjacent full-tile windows into one
/obj/structure/window/update_icon()
if(!QDELETED(src))
if(!fulltile)
return
var/ratio = obj_integrity / max_integrity
ratio = Ceiling(ratio*4) * 25
if(smooth)
queue_smooth(src)
cut_overlays()
if(ratio > 75)
return
crack_overlay.icon_state = "damage[ratio]"
add_overlay(crack_overlay)
/obj/structure/window/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume)
if(exposed_temperature > (T0C + heat_resistance))
take_damage(round(exposed_volume / 100), BURN, 0, 0)
..()
/obj/structure/window/storage_contents_dump_act(obj/item/weapon/storage/src_object, mob/user)
return 0
/obj/structure/window/CanAStarPass(ID, to_dir)
if(!density)
return 1
if((dir == FULLTILE_WINDOW_DIR) || (dir == to_dir))
return 0
return 1
/obj/structure/window/unanchored
anchored = FALSE
/obj/structure/window/reinforced
name = "reinforced window"
icon_state = "rwindow"
reinf = 1
heat_resistance = 1600
armor = list(melee = 50, bullet = 0, laser = 0, energy = 0, bomb = 25, bio = 100, rad = 100, fire = 80, acid = 100)
max_integrity = 50
explosion_block = 1
glass_type = /obj/item/stack/sheet/rglass
/obj/structure/window/reinforced/unanchored
anchored = FALSE
/obj/structure/window/reinforced/tinted
name = "tinted window"
icon_state = "twindow"
opacity = 1
/obj/structure/window/reinforced/tinted/frosted
name = "frosted window"
icon_state = "fwindow"
/obj/structure/window/reinforced/highpressure
name = "high pressure window"
max_integrity = 1000
heat_resistance = 50000
pressure_resistance = 4*ONE_ATMOSPHERE
/* Full Tile Windows (more obj_integrity) */
/obj/structure/window/fulltile
icon = 'icons/obj/smooth_structures/window.dmi'
icon_state = "window"
dir = FULLTILE_WINDOW_DIR
max_integrity = 50
fulltile = 1
flags = NONE
smooth = SMOOTH_TRUE
canSmoothWith = list(/obj/structure/window/fulltile, /obj/structure/window/reinforced/fulltile,/obj/structure/window/reinforced/highpressure/fulltile, /obj/structure/window/reinforced/tinted/fulltile)
glass_amount = 2
/obj/structure/window/fulltile/unanchored
anchored = FALSE
/obj/structure/window/reinforced/fulltile
icon = 'icons/obj/smooth_structures/reinforced_window.dmi'
icon_state = "r_window"
dir = FULLTILE_WINDOW_DIR
max_integrity = 100
fulltile = 1
flags = NONE
smooth = SMOOTH_TRUE
canSmoothWith = list(/obj/structure/window/fulltile, /obj/structure/window/reinforced/fulltile,/obj/structure/window/reinforced/highpressure/fulltile, /obj/structure/window/reinforced/tinted/fulltile)
level = 3
glass_amount = 2
/obj/structure/window/reinforced/highpressure/fulltile
icon = 'icons/obj/smooth_structures/reinforced_window.dmi'
icon_state = "r_window"
dir = FULLTILE_WINDOW_DIR
max_integrity = 1000
fulltile = 1
flags = NONE
smooth = SMOOTH_TRUE
canSmoothWith = list(/obj/structure/window/fulltile, /obj/structure/window/reinforced/fulltile,/obj/structure/window/reinforced/highpressure/fulltile, /obj/structure/window/reinforced/tinted/fulltile)
level = 3
glass_amount = 2
/obj/structure/window/reinforced/fulltile/unanchored
anchored = FALSE
/obj/structure/window/reinforced/tinted/fulltile
icon = 'icons/obj/smooth_structures/tinted_window.dmi'
icon_state = "tinted_window"
dir = FULLTILE_WINDOW_DIR
fulltile = 1
flags = NONE
smooth = SMOOTH_TRUE
canSmoothWith = list(/obj/structure/window/fulltile, /obj/structure/window/reinforced/fulltile,/obj/structure/window/reinforced/highpressure/fulltile, /obj/structure/window/reinforced/tinted/fulltile/)
level = 3
glass_amount = 2
/obj/structure/window/reinforced/fulltile/ice
icon = 'icons/obj/smooth_structures/rice_window.dmi'
icon_state = "ice_window"
max_integrity = 150
canSmoothWith = list(/obj/structure/window/fulltile, /obj/structure/window/reinforced/fulltile, /obj/structure/window/reinforced/tinted/fulltile, /obj/structure/window/reinforced/fulltile/ice)
level = 3
glass_amount = 2
/obj/structure/window/shuttle
name = "shuttle window"
desc = "A reinforced, air-locked pod window."
icon = 'icons/obj/smooth_structures/shuttle_window.dmi'
icon_state = "shuttle_window"
dir = FULLTILE_WINDOW_DIR
max_integrity = 100
wtype = "shuttle"
fulltile = 1
flags = NONE
reinf = 1
heat_resistance = 1600
armor = list(melee = 50, bullet = 0, laser = 0, energy = 0, bomb = 25, bio = 100, rad = 100, fire = 80, acid = 100)
smooth = SMOOTH_TRUE
canSmoothWith = null
explosion_block = 1
level = 3
glass_type = /obj/item/stack/sheet/rglass
glass_amount = 2
/obj/structure/window/shuttle/narsie_act()
add_atom_colour("#3C3434", FIXED_COLOUR_PRIORITY)
/obj/structure/window/shuttle/tinted
opacity = TRUE
/obj/structure/window/reinforced/clockwork
name = "brass window"
desc = "A paper-thin pane of translucent yet reinforced brass."
icon = 'icons/obj/smooth_structures/clockwork_window.dmi'
icon_state = "clockwork_window_single"
resistance_flags = FIRE_PROOF | ACID_PROOF
max_integrity = 80
armor = list(melee = 60, bullet = 25, laser = 0, energy = 0, bomb = 25, bio = 100, rad = 100, fire = 80, acid = 100)
explosion_block = 2 //fancy AND hard to destroy. the most useful combination.
decon_speed = 40
glass_type = /obj/item/stack/tile/brass
glass_amount = 1
reinf = FALSE
var/made_glow = FALSE
/obj/structure/window/reinforced/clockwork/Initialize(mapload, direct)
if(fulltile)
made_glow = TRUE
..()
for(var/obj/item/I in debris)
debris -= I
qdel(I)
var/amount_of_gears = 2
if(fulltile)
new /obj/effect/overlay/temp/ratvar/window(get_turf(src))
amount_of_gears = 4
for(var/i in 1 to amount_of_gears)
debris += new/obj/item/clockwork/alloy_shards/medium/gear_bit()
change_construction_value(fulltile ? 2 : 1)
/obj/structure/window/reinforced/clockwork/setDir(direct)
if(!made_glow)
var/obj/effect/E = new /obj/effect/overlay/temp/ratvar/window/single(get_turf(src))
E.setDir(direct)
made_glow = TRUE
..()
/obj/structure/window/reinforced/clockwork/Destroy()
change_construction_value(fulltile ? -2 : -1)
return ..()
/obj/structure/window/reinforced/clockwork/ratvar_act()
if(GLOB.ratvar_awakens)
obj_integrity = max_integrity
update_icon()
/obj/structure/window/reinforced/clockwork/narsie_act()
take_damage(rand(25, 75), BRUTE)
if(src)
var/previouscolor = color
color = "#960000"
animate(src, color = previouscolor, time = 8)
addtimer(CALLBACK(src, /atom/proc/update_atom_colour), 8)
/obj/structure/window/reinforced/clockwork/unanchored
anchored = FALSE
/obj/structure/window/reinforced/clockwork/fulltile
icon_state = "clockwork_window"
smooth = SMOOTH_TRUE
canSmoothWith = null
fulltile = 1
flags = NONE
dir = FULLTILE_WINDOW_DIR
max_integrity = 120
level = 3
glass_amount = 2
/obj/structure/window/reinforced/clockwork/fulltile/unanchored
anchored = FALSE