Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacks inserted into storages will now try to fill other stacks first #8078

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions code/game/objects/items/storage/storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,19 @@ GLOBAL_LIST_EMPTY_TYPED(item_storage_box_cache, /datum/item_storage_box)

///Returns TRUE if there is room for the given item. W_class_override allows checking for just a generic W_class, meant for checking shotgun handfuls without having to spawn and delete one just to check.
/obj/item/storage/proc/has_room(obj/item/new_item, W_class_override = null)
for(var/obj/item/cur_item in contents)
if(!istype(cur_item, /obj/item/stack) || !istype(new_item, /obj/item/stack))
continue

var/obj/item/stack/cur_stack = cur_item
var/obj/item/stack/new_stack = new_item

if(cur_stack.amount < cur_stack.max_amount && new_stack.stack_id == cur_stack.stack_id)
return TRUE

if(storage_slots != null && length(contents) < storage_slots)
return TRUE //At least one open slot.

//calculate storage space only for containers that don't have slots
if (storage_slots == null)
var/sum_storage_cost = W_class_override ? W_class_override : new_item.get_storage_cost() //Takes the override if there is one, the given item otherwise.
Expand Down Expand Up @@ -490,7 +501,27 @@ user can be null, it refers to the potential mob doing the insertion.**/
/obj/item/storage/proc/handle_item_insertion(obj/item/new_item, prevent_warning = FALSE, mob/user)
if(!istype(new_item))
return FALSE

if(user && new_item.loc == user)
if(istype(new_item, /obj/item/stack))
var/obj/item/stack/new_stack = new_item

for(var/obj/item/cur_item in contents)
if(!istype(cur_item, /obj/item/stack))
continue
var/obj/item/stack/cur_stack = cur_item

if(cur_stack.amount < cur_stack.max_amount && new_stack.stack_id == cur_stack.stack_id)
var/amount = min(cur_stack.max_amount - cur_stack.amount, new_stack.amount)
new_stack.use(amount)
cur_stack.add(amount)

if(!QDELETED(new_stack) && can_be_inserted(new_stack, user))
if(!user.drop_inv_item_to_loc(new_item, src))
return FALSE
else
return TRUE

if(!user.drop_inv_item_to_loc(new_item, src))
return FALSE
else
Expand Down
66 changes: 40 additions & 26 deletions code/modules/mob/living/carbon/human/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -215,32 +215,46 @@
if(!has_limb_for_slot(slot))
return

if(equipping_item == l_hand)
if(equipping_item.flags_item & NODROP)
return
l_hand = null
update_inv_l_hand()
//removes item's actions, may be readded once re-equipped to the new slot
for(var/item_actions in equipping_item.actions)
var/datum/action/action = item_actions
action.remove_from(src)

else if(equipping_item == r_hand)
if(equipping_item.flags_item & NODROP)
return
r_hand = null
update_inv_r_hand()
//removes item's actions, may be readded once re-equipped to the new slot
for(var/item_actions in equipping_item.actions)
var/datum/action/action = item_actions
action.remove_from(src)

equipping_item.screen_loc = null
if(equipping_item.loc != src)
equipping_item.pickup(src, disable_warning)
equipping_item.forceMove(src)
equipping_item.layer = ABOVE_HUD_LAYER
equipping_item.plane = ABOVE_HUD_PLANE
// Already handled within the proc, usually storages that force move the item themselves
var/static/list/no_update = list(
WEAR_IN_BACK,
WEAR_IN_SCABBARD,
WEAR_IN_JACKET,
WEAR_IN_HELMET,
WEAR_IN_ACCESSORY,
WEAR_IN_BELT,
WEAR_IN_J_STORE,
WEAR_IN_L_STORE,
WEAR_IN_R_STORE
)

if(!(slot in no_update))
if(equipping_item == l_hand)
if(equipping_item.flags_item & NODROP)
return
l_hand = null
update_inv_l_hand()
//removes item's actions, may be readded once re-equipped to the new slot
for(var/item_actions in equipping_item.actions)
var/datum/action/action = item_actions
action.remove_from(src)

else if(equipping_item == r_hand)
if(equipping_item.flags_item & NODROP)
return
r_hand = null
update_inv_r_hand()
//removes item's actions, may be readded once re-equipped to the new slot
for(var/item_actions in equipping_item.actions)
var/datum/action/action = item_actions
action.remove_from(src)

equipping_item.screen_loc = null
if(equipping_item.loc != src)
equipping_item.pickup(src, disable_warning)
equipping_item.forceMove(src)
equipping_item.layer = ABOVE_HUD_LAYER
equipping_item.plane = ABOVE_HUD_PLANE

switch(slot)
if(WEAR_BACK)
Expand Down
Loading