Surgical kits can now contain their equipment.

The surgical kit can now contain the equipment it came with. It can also not contain more items of a given type than it was spawned with.
This means that even if the storage container otherwise has sufficient space it can, for example, still only ever contain 1 surgical saw.

Fixes #11298. Fixes #11297.
This commit is contained in:
PsiOmegaDelta
2015-10-15 10:18:55 +02:00
parent 21fada644d
commit fd03e4d59b
3 changed files with 37 additions and 16 deletions

View File

@@ -71,11 +71,17 @@ proc/isemptylist(list/list)
return 1 return 1
return 0 return 0
//Empties the list by setting the length to 0. Hopefully the elements get garbage collected /proc/instances_of_type_in_list(var/atom/A, var/list/L)
proc/clearlist(list/list) var/instances = 0
if(istype(list)) for(var/type in L)
list.len = 0 if(istype(A, type))
return instances++
return instances
//Empties the list by .Cut(). Setting lenght = 0 has been confirmed to leak references.
proc/clearlist(var/list/L)
if(islist(L))
L.Cut()
//Removes any null entries from the list //Removes any null entries from the list
proc/listclearnulls(list/list) proc/listclearnulls(list/list)

View File

@@ -130,8 +130,7 @@
/obj/item/weapon/storage/firstaid/surgery /obj/item/weapon/storage/firstaid/surgery
name = "surgery kit" name = "surgery kit"
desc = "Contains tools for surgery." desc = "Contains tools for surgery. Has precise foam fitting for safe transport."
storage_slots = 10
/obj/item/weapon/storage/firstaid/surgery/New() /obj/item/weapon/storage/firstaid/surgery/New()
..() ..()
@@ -146,7 +145,8 @@
new /obj/item/weapon/bonegel(src) new /obj/item/weapon/bonegel(src)
new /obj/item/weapon/FixOVein(src) new /obj/item/weapon/FixOVein(src)
new /obj/item/stack/medical/advanced/bruise_pack(src) new /obj/item/stack/medical/advanced/bruise_pack(src)
return
make_exact_fit()
/* /*
* Pill Bottles * Pill Bottles

View File

@@ -51,10 +51,10 @@
//there's got to be a better way of doing this. //there's got to be a better way of doing this.
if (!(src.loc == usr) || (src.loc && src.loc.loc == usr)) if (!(src.loc == usr) || (src.loc && src.loc.loc == usr))
return return
if (( usr.restrained() ) || ( usr.stat )) if (( usr.restrained() ) || ( usr.stat ))
return return
if ((src.loc == usr) && !usr.unEquip(src)) if ((src.loc == usr) && !usr.unEquip(src))
return return
@@ -232,12 +232,16 @@
usr << "<span class='notice'>[src] is full, make some space.</span>" usr << "<span class='notice'>[src] is full, make some space.</span>"
return 0 //Storage item is full return 0 //Storage item is full
if(can_hold.len && !is_type_in_list(W, can_hold)) if(can_hold.len)
if(!stop_messages) if(!is_type_in_list(W, can_hold))
if (istype(W, /obj/item/weapon/hand_labeler)) if(!stop_messages && ! istype(W, /obj/item/weapon/hand_labeler))
return 0 usr << "<span class='notice'>[src] cannot hold [W].</span>"
usr << "<span class='notice'>[src] cannot hold [W].</span>" return 0
return 0 var/max_instances = can_hold[W.type]
if(max_instances && instances_of_type_in_list(W, contents) >= max_instances)
if(!stop_messages && !istype(W, /obj/item/weapon/hand_labeler))
usr << "<span class='notice'>[src] has no more space for an additional [W].</span>"
return 0
if(cant_hold.len && is_type_in_list(W, cant_hold)) if(cant_hold.len && is_type_in_list(W, cant_hold))
if(!stop_messages) if(!stop_messages)
@@ -449,6 +453,17 @@
var/obj/O = A var/obj/O = A
O.hear_talk(M, text, verb, speaking) O.hear_talk(M, text, verb, speaking)
/obj/item/weapon/storage/proc/make_exact_fit()
storage_slots = contents.len
can_hold.Cut()
max_w_class = 0
max_storage_space = 0
for(var/obj/item/I in src)
max_w_class = max(I.w_class, max_w_class)
max_storage_space += I.get_storage_cost()
can_hold[I.type] = ++can_hold[I.type]
//Returns the storage depth of an atom. This is the number of storage items the atom is contained in before reaching toplevel (the area). //Returns the storage depth of an atom. This is the number of storage items the atom is contained in before reaching toplevel (the area).
//Returns -1 if the atom was not found on container. //Returns -1 if the atom was not found on container.
/atom/proc/storage_depth(atom/container) /atom/proc/storage_depth(atom/container)