Files
Bubberstation/code/game/objects/structures/guncase.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

112 lines
2.8 KiB
Plaintext

//GUNCASES//
/obj/structure/guncase
name = "gun locker"
desc = "A locker that holds guns."
icon = 'icons/obj/closet.dmi'
icon_state = "shotguncase"
anchored = 0
density = 1
opacity = 0
var/case_type = ""
var/gun_category = /obj/item/weapon/gun
var/open = 1
var/capacity = 4
/obj/structure/guncase/Initialize(mapload)
..()
if(mapload)
for(var/obj/item/I in loc.contents)
if(istype(I, gun_category))
I.forceMove(src)
if(contents.len >= capacity)
break
update_icon()
/obj/structure/guncase/update_icon()
cut_overlays()
if(case_type && LAZYLEN(contents))
var/mutable_appearance/gun_overlay = mutable_appearance(icon, case_type)
for(var/i in 1 to contents.len)
gun_overlay.pixel_x = 3 * (i - 1)
add_overlay(gun_overlay)
if(open)
add_overlay("[icon_state]_open")
else
add_overlay("[icon_state]_door")
/obj/structure/guncase/attackby(obj/item/I, mob/user, params)
if(iscyborg(user) || isalien(user))
return
if(istype(I, gun_category) && open)
if(LAZYLEN(contents) < capacity)
if(!user.drop_item())
return
I.forceMove(src)
to_chat(user, "<span class='notice'>You place [I] in [src].</span>")
update_icon()
else
to_chat(user, "<span class='warning'>[src] is full.</span>")
return
else if(user.a_intent != INTENT_HARM)
open = !open
update_icon()
else
return ..()
/obj/structure/guncase/attack_hand(mob/user)
if(iscyborg(user) || isalien(user))
return
if(contents.len && open)
ShowWindow(user)
else
open = !open
update_icon()
/obj/structure/guncase/proc/ShowWindow(mob/user)
var/dat = {"<div class='block'>
<h3>Stored Guns</h3>
<table align='center'>"}
if(LAZYLEN(contents))
for(var/i in 1 to contents.len)
var/obj/item/I = contents[i]
dat += "<tr><A href='?src=\ref[src];retrieve=\ref[I]'>[I.name]</A><br>"
dat += "</table></div>"
var/datum/browser/popup = new(user, "gunlocker", "<div align='center'>[name]</div>", 350, 300)
popup.set_content(dat)
popup.open(0)
/obj/structure/guncase/Topic(href, href_list)
if(href_list["retrieve"])
var/obj/item/O = locate(href_list["retrieve"]) in contents
if(!O || !istype(O))
return
if(!usr.canUseTopic(src) || !open)
return
if(ishuman(usr))
if(!usr.put_in_hands(O))
O.forceMove(get_turf(src))
update_icon()
/obj/structure/guncase/handle_atom_del(atom/A)
update_icon()
/obj/structure/guncase/contents_explosion(severity, target)
for(var/atom/A in contents)
A.ex_act(severity++, target)
CHECK_TICK
/obj/structure/guncase/shotgun
name = "shotgun locker"
desc = "A locker that holds shotguns."
case_type = "shotgun"
gun_category = /obj/item/weapon/gun/ballistic/shotgun
/obj/structure/guncase/ecase
name = "energy gun locker"
desc = "A locker that holds energy guns."
icon_state = "ecase"
case_type = "egun"
gun_category = /obj/item/weapon/gun/energy/e_gun