From e6d19faeba2340eb2dc2bd21d7957eb41bd9a418 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Sun, 29 Mar 2015 23:49:15 -0400 Subject: [PATCH] Cleans up mob/inventory.dm, fixes removed_from_mob() not calling dropped() on items. Updates u_equip() accordingly in the other inventory.dm files as well, and moves some random inventory procs from mob.dm to mob/inventory.dm. --- code/modules/mob/inventory.dm | 106 ++++++++++++++---- .../mob/living/carbon/human/inventory.dm | 60 ++++------ .../mob/living/carbon/human/update_icons.dm | 3 +- code/modules/mob/mob.dm | 71 ------------ 4 files changed, 106 insertions(+), 134 deletions(-) diff --git a/code/modules/mob/inventory.dm b/code/modules/mob/inventory.dm index 653e33b2dd..303f1665de 100644 --- a/code/modules/mob/inventory.dm +++ b/code/modules/mob/inventory.dm @@ -1,15 +1,81 @@ +//This proc is called whenever someone clicks an inventory ui slot. +/mob/proc/attack_ui(slot) + var/obj/item/W = get_active_hand() + if(istype(W)) + equip_to_slot_if_possible(W, slot) + +/mob/proc/put_in_any_hand_if_possible(obj/item/W as obj, del_on_fail = 0, disable_warning = 1, redraw_mob = 1) + if(equip_to_slot_if_possible(W, slot_l_hand, del_on_fail, disable_warning, redraw_mob)) + return 1 + else if(equip_to_slot_if_possible(W, slot_r_hand, del_on_fail, disable_warning, redraw_mob)) + return 1 + return 0 + +//This is a SAFE proc. Use this instead of equip_to_slot()! +//set del_on_fail to have it delete W if it fails to equip +//set disable_warning to disable the 'you are unable to equip that' warning. +//unset redraw_mob to prevent the mob from being redrawn at the end. +/mob/proc/equip_to_slot_if_possible(obj/item/W as obj, slot, del_on_fail = 0, disable_warning = 0, redraw_mob = 1) + if(!istype(W)) return 0 + + if(!W.mob_can_equip(src, slot)) + if(del_on_fail) + del(W) + else + if(!disable_warning) + src << "\red You are unable to equip that." //Only print if del_on_fail is false + return 0 + + equip_to_slot(W, slot, redraw_mob) //This proc should not ever fail. + return 1 + +//This is an UNSAFE proc. It merely handles the actual job of equipping. All the checks on whether you can or can't eqip need to be done before! Use mob_can_equip() for that task. +//In most cases you will want to use equip_to_slot_if_possible() +/mob/proc/equip_to_slot(obj/item/W as obj, slot) + return + +//This is just a commonly used configuration for the equip_to_slot_if_possible() proc, used to equip people when the rounds tarts and when events happen and such. +/mob/proc/equip_to_slot_or_del(obj/item/W as obj, slot) + return equip_to_slot_if_possible(W, slot, 1, 1, 0) + +//The list of slots by priority. equip_to_appropriate_slot() uses this list. Doesn't matter if a mob type doesn't have a slot. +var/list/slot_equipment_priority = list( \ + slot_back,\ + slot_wear_id,\ + slot_w_uniform,\ + slot_wear_suit,\ + slot_wear_mask,\ + slot_head,\ + slot_shoes,\ + slot_gloves,\ + slot_l_ear,\ + slot_r_ear,\ + slot_glasses,\ + slot_belt,\ + slot_s_store,\ + slot_tie,\ + slot_l_store,\ + slot_r_store\ + ) + +//puts the item "W" into an appropriate slot in a human's inventory +//returns 0 if it cannot, 1 if successful +/mob/proc/equip_to_appropriate_slot(obj/item/W) + if(!istype(W)) return 0 + + for(var/slot in slot_equipment_priority) + if(equip_to_slot_if_possible(W, slot, del_on_fail=0, disable_warning=1, redraw_mob=1)) + return 1 + + return 0 + //These procs handle putting s tuff in your hand. It's probably best to use these rather than setting l_hand = ...etc //as they handle all relevant stuff like adding it to the player's screen and updating their overlays. //Returns the thing in our active hand /mob/proc/get_active_hand() - if(issilicon(src)) - if(isrobot(src)) - if(src:module_active) - return src:module_active - else - if(hand) return l_hand - else return r_hand + if(hand) return l_hand + else return r_hand //Returns the thing in our inactive hand /mob/proc/get_inactive_hand() @@ -84,28 +150,20 @@ return drop_item() return 0 - +// Removes an item from inventory and places it in the target atom /mob/proc/drop_from_inventory(var/obj/item/W, var/atom/Target = null) if(W) if(!Target) Target = loc - if(client) client.screen -= W - u_equip(W) + remove_from_mob(W) if(!W) return 1 // self destroying objects (tk, grabs) - W.layer = initial(W.layer) - W.loc = Target - - var/turf/T = get_turf(Target) - if(isturf(T)) - T.Entered(W) - - W.dropped(src) + + W.forceMove(Target) update_icons() return 1 return 0 - //Drops the item in our left hand /mob/proc/drop_l_hand(var/atom/Target) if(l_hand) @@ -166,7 +224,12 @@ return -/mob/proc/u_equip(W as obj) +//Removes the object from any slots the mob might have, calling the appropriate icon update proc. +//Does nothing else. +//DO NOT CALL THIS PROC DIRECTLY. It is meant to be called only by other inventory procs. +//As far as I can tell the proc exists so that mobs with different inventory slots can override +//the search through all the slots, without having to duplicate the rest of the item dropping. +/mob/proc/u_equip(obj/W as obj) if (W == r_hand) r_hand = null update_inv_r_hand(0) @@ -215,6 +278,9 @@ src.client.screen -= O O.layer = initial(O.layer) O.screen_loc = null + if(istype(O, /obj/item)) + var/obj/item/I = O + I.dropped() return 1 diff --git a/code/modules/mob/living/carbon/human/inventory.dm b/code/modules/mob/living/carbon/human/inventory.dm index 7846a1ac26..43b66d9ccc 100644 --- a/code/modules/mob/living/carbon/human/inventory.dm +++ b/code/modules/mob/living/carbon/human/inventory.dm @@ -76,19 +76,13 @@ if(slot_tie) return 1 -/mob/living/carbon/human/u_equip(obj/item/W as obj) +/mob/living/carbon/human/u_equip(obj/W as obj) if(!W) return 0 - var/success - if (W == wear_suit) if(s_store) drop_from_inventory(s_store) - if(W) - success = 1 wear_suit = null - if(W.flags_inv & HIDESHOES) - update_inv_shoes(0) update_inv_wear_suit() else if (W == w_uniform) if (r_store) @@ -100,43 +94,43 @@ if (belt) drop_from_inventory(belt) w_uniform = null - success = 1 update_inv_w_uniform() else if (W == gloves) gloves = null - success = 1 update_inv_gloves() else if (W == glasses) glasses = null - success = 1 update_inv_glasses() else if (W == head) head = null - if((W.flags & BLOCKHAIR) || (W.flags & BLOCKHEADHAIR)|| (W.flags_inv & HIDEMASK)) + + var/update_hair = 0 + if((W.flags & BLOCKHAIR) || (W.flags & BLOCKHEADHAIR)) + update_hair = 1 + else if(istype(W, /obj/item)) + var/obj/item/I = W + if(I.flags_inv & HIDEMASK) + update_hair = 1 + if(update_hair) update_hair(0) //rebuild hair update_inv_ears(0) update_inv_wear_mask(0) - success = 1 + update_inv_head() else if (W == l_ear) l_ear = null - success = 1 update_inv_ears() else if (W == r_ear) r_ear = null - success = 1 update_inv_ears() else if (W == shoes) shoes = null - success = 1 update_inv_shoes() else if (W == belt) belt = null - success = 1 update_inv_belt() else if (W == wear_mask) wear_mask = null - success = 1 if((W.flags & BLOCKHAIR) || (W.flags & BLOCKHEADHAIR)) update_hair(0) //rebuild hair update_inv_ears(0) @@ -147,51 +141,34 @@ update_inv_wear_mask() else if (W == wear_id) wear_id = null - success = 1 update_inv_wear_id() else if (W == r_store) r_store = null - success = 1 update_inv_pockets() else if (W == l_store) l_store = null - success = 1 update_inv_pockets() else if (W == s_store) s_store = null - success = 1 update_inv_s_store() else if (W == back) back = null - success = 1 update_inv_back() else if (W == handcuffed) handcuffed = null - success = 1 update_inv_handcuffed() else if (W == legcuffed) legcuffed = null - success = 1 update_inv_legcuffed() else if (W == r_hand) r_hand = null - success = 1 update_inv_r_hand() else if (W == l_hand) l_hand = null - success = 1 update_inv_l_hand() else return 0 - - if(success) - if (W) - if (client) - client.screen -= W - W.loc = loc - W.dropped(src) - //if(W) - //W.layer = initial(W.layer) + update_action_buttons() return 1 @@ -304,7 +281,7 @@ update_inv_s_store(redraw_mob) if(slot_in_backpack) if(src.get_active_hand() == W) - src.u_equip(W) + src.remove_from_mob(W) W.loc = src.back if(slot_tie) var/obj/item/clothing/under/uniform = src.w_uniform @@ -324,6 +301,10 @@ return +/* + MouseDrop human inventory menu +*/ + /obj/effect/equip_e name = "equip e" var/mob/source = null @@ -757,15 +738,12 @@ It can still be worn/put on as normal. W.add_fingerprint(source) if(slot_to_process == slot_l_store) //pockets! Needs to process the other one too. Snowflake code, wooo! It's not like anyone will rewrite this anytime soon. If I'm wrong then... CONGRATULATIONS! ;) if(target.r_store) - target.u_equip(target.r_store) //At this stage l_store is already processed by the code above, we only need to process r_store. + target.remove_from_mob(target.r_store) //At this stage l_store is already processed by the code above, we only need to process r_store. else if(item && target.has_organ_for_slot(slot_to_process)) //Placing an item on the mob if(item.mob_can_equip(target, slot_to_process, 0)) - source.u_equip(item) + source.remove_from_mob(item) target.equip_to_slot_if_possible(item, slot_to_process, 0, 1, 1) - item.dropped(source) - source.update_icons() - target.update_icons() if(source && target) if(source.machine == target) diff --git a/code/modules/mob/living/carbon/human/update_icons.dm b/code/modules/mob/living/carbon/human/update_icons.dm index 0bdcf6d427..bb19583119 100644 --- a/code/modules/mob/living/carbon/human/update_icons.dm +++ b/code/modules/mob/living/carbon/human/update_icons.dm @@ -752,13 +752,12 @@ proc/get_damage_icon_part(damage_state, body_part) standing.overlays += bloodsies overlays_standing[SUIT_LAYER] = standing - update_tail_showing(0) else overlays_standing[SUIT_LAYER] = null - update_tail_showing(0) + update_inv_shoes(0) update_collar(0) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 1b92c92ae6..0ab9b162d1 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -117,77 +117,6 @@ /mob/proc/restrained() return -//This proc is called whenever someone clicks an inventory ui slot. -/mob/proc/attack_ui(slot) - var/obj/item/W = get_active_hand() - if(istype(W)) - equip_to_slot_if_possible(W, slot) - -/mob/proc/put_in_any_hand_if_possible(obj/item/W as obj, del_on_fail = 0, disable_warning = 1, redraw_mob = 1) - if(equip_to_slot_if_possible(W, slot_l_hand, del_on_fail, disable_warning, redraw_mob)) - return 1 - else if(equip_to_slot_if_possible(W, slot_r_hand, del_on_fail, disable_warning, redraw_mob)) - return 1 - return 0 - -//This is a SAFE proc. Use this instead of equip_to_slot()! -//set del_on_fail to have it delete W if it fails to equip -//set disable_warning to disable the 'you are unable to equip that' warning. -//unset redraw_mob to prevent the mob from being redrawn at the end. -/mob/proc/equip_to_slot_if_possible(obj/item/W as obj, slot, del_on_fail = 0, disable_warning = 0, redraw_mob = 1) - if(!istype(W)) return 0 - - if(!W.mob_can_equip(src, slot)) - if(del_on_fail) - del(W) - else - if(!disable_warning) - src << "\red You are unable to equip that." //Only print if del_on_fail is false - return 0 - - equip_to_slot(W, slot, redraw_mob) //This proc should not ever fail. - return 1 - -//This is an UNSAFE proc. It merely handles the actual job of equipping. All the checks on whether you can or can't eqip need to be done before! Use mob_can_equip() for that task. -//In most cases you will want to use equip_to_slot_if_possible() -/mob/proc/equip_to_slot(obj/item/W as obj, slot) - return - -//This is just a commonly used configuration for the equip_to_slot_if_possible() proc, used to equip people when the rounds tarts and when events happen and such. -/mob/proc/equip_to_slot_or_del(obj/item/W as obj, slot) - return equip_to_slot_if_possible(W, slot, 1, 1, 0) - -//The list of slots by priority. equip_to_appropriate_slot() uses this list. Doesn't matter if a mob type doesn't have a slot. -var/list/slot_equipment_priority = list( \ - slot_back,\ - slot_wear_id,\ - slot_w_uniform,\ - slot_wear_suit,\ - slot_wear_mask,\ - slot_head,\ - slot_shoes,\ - slot_gloves,\ - slot_l_ear,\ - slot_r_ear,\ - slot_glasses,\ - slot_belt,\ - slot_s_store,\ - slot_tie,\ - slot_l_store,\ - slot_r_store\ - ) - -//puts the item "W" into an appropriate slot in a human's inventory -//returns 0 if it cannot, 1 if successful -/mob/proc/equip_to_appropriate_slot(obj/item/W) - if(!istype(W)) return 0 - - for(var/slot in slot_equipment_priority) - if(equip_to_slot_if_possible(W, slot, del_on_fail=0, disable_warning=1, redraw_mob=1)) - return 1 - - return 0 - /mob/proc/reset_view(atom/A) if (client) if (istype(A, /atom/movable))