Skip to content

Commit

Permalink
Refactors Obscurity, caches flags_inv. Improves equip/unequip code. (
Browse files Browse the repository at this point in the history
…#826)

* refactors obscurity

* security

* fix modsuits and other flags_inv changing things

* code cleanup

* wrong proc
  • Loading branch information
Kapu1178 authored Feb 27, 2024
1 parent d879af5 commit 9514d22
Show file tree
Hide file tree
Showing 37 changed files with 192 additions and 195 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
///hides mutant/moth wings, does not apply to functional wings
#define HIDEMUTWINGS (1<<13)

/// Every flag that hides a bodypart or organ.
#define BODYPART_HIDE_FLAGS (HIDESNOUT | HIDEMUTWINGS | HIDEHAIR | HIDEFACIALHAIR | HIDEEYES | HIDEJUMPSUIT)

//bitflags for clothing coverage - also used for limbs
#define CHEST (1<<0)
#define HEAD (1<<1)
Expand Down
17 changes: 17 additions & 0 deletions code/_globalvars/bitfields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,20 @@ DEFINE_BITFIELD(organ_flags, list(
"ORGAN_UNREMOVABLE" = ORGAN_UNREMOVABLE,
"ORGAN_CUT_AWAY" = ORGAN_CUT_AWAY
))

DEFINE_BITFIELD(obscured_slots, list(
"HIDE GLOVES" = HIDEGLOVES,
"HIDE SUITSTORAGE" = HIDESUITSTORAGE,
"HIDE JUMPSUIT" = HIDEJUMPSUIT,
"HIDE SHOES" = HIDESHOES,
"HIDE MASK" = HIDEMASK,
"HIDE EARS" = HIDEEARS,
"HIDE EYES" = HIDEEYES,
"HIDE FACE" = HIDEFACE,
"HIDE HAIR" = HIDEHAIR,
"HIDE FACIALHAIR" = HIDEFACIALHAIR,
"HIDE NECK" = HIDENECK,
"HIDE HEADGEAR" = HIDEHEADGEAR,
"HIDE SNOUT" = HIDESNOUT,
"HIDE MUTWINGS" = HIDEMUTWINGS
))
2 changes: 0 additions & 2 deletions code/game/objects/effects/decals/cleanable/humans.dm
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,8 @@
to_chat(splashed_human, span_alert("You're blinded by a spray of blood!"))
if(splashed_human.wear_suit)
splashed_human.wear_suit.add_blood_DNA(blood_dna_info)
splashed_human.update_worn_oversuit() //updates mob overlays to show the new blood (no refresh)
if(splashed_human.w_uniform)
splashed_human.w_uniform.add_blood_DNA(blood_dna_info)
splashed_human.update_worn_undersuit() //updates mob overlays to show the new blood (no refresh)
splatter_strength--

if(splatter_strength <= 0) // we used all the puff so we delete it.
Expand Down
38 changes: 13 additions & 25 deletions code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ DEFINE_INTERACTABLE(/obj/item)
icon_state = icon_state_wielded
return ..()

/obj/item/add_blood_DNA(list/dna)
. = ..()
update_slot_icon()

/// Called when an action associated with our item is deleted
/obj/item/proc/on_action_deleted(datum/source)
SIGNAL_HANDLER
Expand Down Expand Up @@ -503,6 +507,14 @@ DEFINE_INTERACTABLE(/obj/item)
log_admin("[key_name(usr)] has added [picked_affix_name] fantasy affix to [before_name]")
message_admins(span_notice("[key_name(usr)] has added [picked_affix_name] fantasy affix to [before_name]"))

/obj/item/vv_edit_var(vname, vval)
. = ..()
if(vname == NAMEOF(src, flags_inv) && iscarbon(loc))
var/mob/living/carbon/C = loc
var/slot = C.get_slot_by_item(src)
if(slot)
C.update_slots_for_item(src, slot, TRUE)

/obj/item/attack_hand(mob/user, list/modifiers)
. = ..()
if(.)
Expand Down Expand Up @@ -996,31 +1008,7 @@ DEFINE_INTERACTABLE(/obj/item)
if(!ismob(loc))
return
var/mob/owner = loc
var/flags = slot_flags
if(flags & ITEM_SLOT_OCLOTHING)
owner.update_worn_oversuit()
if(flags & ITEM_SLOT_ICLOTHING)
owner.update_worn_undersuit()
if(flags & ITEM_SLOT_GLOVES)
owner.update_worn_gloves()
if(flags & ITEM_SLOT_EYES)
owner.update_worn_glasses()
if(flags & ITEM_SLOT_EARS)
owner.update_worn_ears()
if(flags & ITEM_SLOT_MASK)
owner.update_worn_mask()
if(flags & ITEM_SLOT_HEAD)
owner.update_worn_head()
if(flags & ITEM_SLOT_FEET)
owner.update_worn_shoes()
if(flags & ITEM_SLOT_ID)
owner.update_worn_id()
if(flags & ITEM_SLOT_BELT)
owner.update_worn_belt()
if(flags & ITEM_SLOT_BACK)
owner.update_worn_back()
if(flags & ITEM_SLOT_NECK)
owner.update_worn_neck()
owner.update_clothing(slot_flags | ITEM_SLOT_HANDS)

///Returns the temperature of src. If you want to know if an item is hot use this proc.
/obj/item/proc/get_temperature()
Expand Down
8 changes: 3 additions & 5 deletions code/game/objects/items/cigs_lighters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,9 @@ CIGARETTE PACKETS ARE IN FANCY.DM
T.visible_message(flavor_text)
START_PROCESSING(SSobj, src)

//can't think of any other way to update the overlays :<
if(ismob(loc))
var/mob/M = loc
M.update_worn_mask()
M.update_held_items()
if(iscarbon(loc))
var/mob/living/carbon/C = loc
C.update_slots_for_item(src)

AddComponent(/datum/component/smell, INTENSITY_STRONG, SCENT_PLUME, "nicotine", 5)
COOLDOWN_START(src, smoke_cooldown, 20 SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
icon_state = "vest_stealth"
if(ishuman(loc))
var/mob/living/carbon/human/H = loc
H.update_worn_oversuit()
H.update_slots_for_item(src)
update_action_buttons()

/obj/item/clothing/suit/armor/abductor/vest/item_action_slot_check(slot, mob/user)
Expand Down
3 changes: 0 additions & 3 deletions code/modules/antagonists/changeling/powers/mutations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
H.visible_message(span_warning("[H] casts off [H.p_their()] [suit_name_simple]!"), span_warning("We cast off our [suit_name_simple]."), span_hear("You hear the organic matter ripping and tearing!"))
H.temporarilyRemoveItemFromInventory(H.head, TRUE) //The qdel on dropped() takes care of it
H.temporarilyRemoveItemFromInventory(H.wear_suit, TRUE)
H.update_worn_oversuit()
H.update_worn_head()
H.update_body_parts()

if(blood_on_castoff)
H.add_splatter_floor()
Expand Down
11 changes: 10 additions & 1 deletion code/modules/clothing/clothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@
//This mostly exists so subtypes can call appriopriate update icon calls on the wearer.
/obj/item/clothing/proc/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
damaged_clothes = damaged_state
update_slot_icon()

/obj/item/clothing/update_overlays()
. = ..()
Expand Down Expand Up @@ -511,7 +512,7 @@ BLIND // can't see anything

if(iscarbon(user))
var/mob/living/carbon/C = user
C.head_update(src, forced = 1)
C.update_slots_for_item(src, force_obscurity_update = TRUE)
update_action_buttons()
return TRUE

Expand All @@ -527,6 +528,10 @@ BLIND // can't see anything
if(visor_vars_to_toggle & VISOR_TINT)
tint ^= initial(tint)

if(iscarbon(loc))
var/mob/living/carbon/C = loc
C.update_slots_for_item(src, force_obscurity_update = TRUE)

/obj/item/clothing/head/helmet/space/plasmaman/visor_toggling() //handles all the actual toggling of flags
up = !up
SEND_SIGNAL(src, COMSIG_CLOTHING_VISOR_TOGGLE, up)
Expand All @@ -538,6 +543,10 @@ BLIND // can't see anything
if(visor_vars_to_toggle & VISOR_TINT)
tint ^= initial(tint)

if(iscarbon(loc))
var/mob/living/carbon/C = loc
C.update_slots_for_item(src, force_obscurity_update = TRUE)

/obj/item/clothing/proc/can_use(mob/user)
if(user && ismob(user))
if(!user.incapacitated())
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/glasses/_glasses.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
user.update_sight()
if(iscarbon(user))
var/mob/living/carbon/carbon_user = user
carbon_user.head_update(src, forced = TRUE)
carbon_user.update_slots_for_item(src, force_obscurity_update = TRUE)

//called when thermal glasses are emped.
/obj/item/clothing/glasses/proc/thermal_overload()
Expand Down
6 changes: 0 additions & 6 deletions code/modules/clothing/gloves/_gloves.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
else
. += mutable_appearance('icons/effects/blood.dmi', "bloodyhands")

/obj/item/clothing/gloves/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
..()
if(ismob(loc))
var/mob/M = loc
M.update_worn_gloves()

/obj/item/clothing/gloves/wirecutter_act(mob/living/user, obj/item/I)
. = ..()
if(!cut_type)
Expand Down
6 changes: 0 additions & 6 deletions code/modules/clothing/head/_head.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,3 @@
. += mutable_appearance('icons/effects/64x64.dmi', "helmetblood_large")
else
. += mutable_appearance('icons/effects/blood.dmi', "helmetblood")

/obj/item/clothing/head/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
..()
if(ismob(loc))
var/mob/M = loc
M.update_worn_head()
5 changes: 2 additions & 3 deletions code/modules/clothing/head/helmet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@
icon_state = "[initial(icon_state)][up ? "up" : ""]"
to_chat(user, span_notice("[up ? alt_toggle_message : toggle_message] \the [src]."))

user.update_worn_head()
if(iscarbon(user))
var/mob/living/carbon/carbon_user = user
carbon_user.head_update(src, forced = TRUE)
var/mob/living/carbon/C = user
C.update_slots_for_item(src, user.get_slot_by_item(src), TRUE)

/obj/item/clothing/head/helmet/justice
name = "helmet of justice"
Expand Down
7 changes: 1 addition & 6 deletions code/modules/clothing/masks/_masks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@
else
. += mutable_appearance('icons/effects/blood.dmi', "maskblood")

/obj/item/clothing/mask/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
..()
if(ismob(loc))
var/mob/M = loc
M.update_worn_mask()

//Proc that moves gas/breath masks out of the way, disabling them and allowing pill/food consumption
/obj/item/clothing/mask/proc/adjustmask(mob/living/carbon/user)
if(user?.incapacitated())
Expand Down Expand Up @@ -116,6 +110,7 @@
return

if(user.wear_mask == src)
user.update_slots_for_item(src, ITEM_SLOT_MASK, TRUE)
user.wear_mask_update(src, toggle_off = mask_adjusted)

if(loc == user)
Expand Down
6 changes: 0 additions & 6 deletions code/modules/clothing/shoes/_shoes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@
restore_offsets(user)
. = ..()

/obj/item/clothing/shoes/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
..()
if(ismob(loc))
var/mob/M = loc
M.update_worn_shoes()

/**
* adjust_laces adjusts whether our shoes (assuming they can_be_tied) and tied, untied, or knotted
*
Expand Down
6 changes: 0 additions & 6 deletions code/modules/clothing/suits/_suits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
if(A.above_suit)
. += U.accessory_overlay

/obj/item/clothing/suit/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
..()
if(ismob(loc))
var/mob/M = loc
M.update_worn_oversuit()

/**
* Wrapper proc to apply shielding through AddComponent().
* Called in /obj/item/clothing/Initialize().
Expand Down
14 changes: 4 additions & 10 deletions code/modules/clothing/under/_under.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@

/obj/item/clothing/under/update_clothes_damaged_state(damaged_state = CLOTHING_DAMAGED)
..()
if(ismob(loc))
var/mob/M = loc
M.update_worn_undersuit()
if(damaged_state == CLOTHING_SHREDDED && has_sensor > NO_SENSORS)
has_sensor = BROKEN_SENSORS
else if(damaged_state == CLOTHING_PRISTINE && has_sensor == BROKEN_SENSORS)
Expand Down Expand Up @@ -186,8 +183,7 @@
return

var/mob/living/carbon/human/holder = loc
holder.update_worn_undersuit()
holder.update_worn_oversuit()
holder.update_slots_for_item(src)
holder.fan_hud_set_fandom()

/obj/item/clothing/under/proc/remove_accessory(mob/user)
Expand All @@ -213,11 +209,9 @@
return

var/mob/living/carbon/human/holder = loc
holder.update_worn_undersuit()
holder.update_worn_oversuit()
holder.update_slots_for_item(src)
holder.fan_hud_set_fandom()


/obj/item/clothing/under/examine(mob/user)
. = ..()
if(freshly_laundered)
Expand Down Expand Up @@ -310,10 +304,10 @@
to_chat(usr, span_notice("You adjust the suit to wear it more casually."))
else
to_chat(usr, span_notice("You adjust the suit back to normal."))

if(ishuman(usr))
var/mob/living/carbon/human/H = usr
H.update_worn_undersuit()
H.update_body()
H.update_slots_for_item(src, force_obscurity_update = TRUE)

/obj/item/clothing/under/proc/toggle_jumpsuit_adjust()
if(adjusted == DIGITIGRADE_STYLE)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/hydroponics/grown/flowers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@
. = ..()
if(slot == ITEM_SLOT_MASK)
worn_icon_state = "[base_icon_state]_mouth"
user.update_worn_mask()
else
worn_icon_state = base_icon_state
user.update_worn_head()

update_slot_icon()

// Carbon Rose
/obj/item/seeds/carbon_rose
Expand Down
22 changes: 17 additions & 5 deletions code/modules/mob/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,23 @@
if(hand_index)
held_items[hand_index] = null
update_held_items()

if(I)
if(client)
client.screen -= I

I.layer = initial(I.layer)
I.plane = initial(I.plane)
I.appearance_flags &= ~NO_CLIENT_COLOR

if(!no_move && !(I.item_flags & DROPDEL)) //item may be moved/qdel'd immedietely, don't bother moving it
if (isnull(newloc))
I.moveToNullspace()
else
I.forceMove(newloc)

I.dropped(src, silent)

SEND_SIGNAL(I, COMSIG_ITEM_POST_UNEQUIP, force, newloc, no_move, invdrop, silent)
SEND_SIGNAL(src, COMSIG_MOB_UNEQUIPPED_ITEM, I, force, newloc, no_move, invdrop, silent)
return TRUE
Expand Down Expand Up @@ -437,14 +442,21 @@
dropItemToGround(I)
drop_all_held_items()

/// Compiles all flags_inv vars of worn items.
/mob/living/carbon/proc/update_obscurity()
PROTECTED_PROC(TRUE)

obscured_slots = NONE
for(var/obj/item/I in get_all_worn_items())
obscured_slots |= I.flags_inv

///Returns a bitfield of covered item slots.
/mob/living/carbon/proc/check_obscured_slots(transparent_protection)
/mob/living/carbon/proc/check_obscured_slots(transparent_protection, input_slots)
var/obscured = NONE
var/hidden_slots = NONE
var/hidden_slots = !isnull(input_slots) ? input_slots : src.obscured_slots

for(var/obj/item/I in get_all_worn_items()) //This contains nulls
hidden_slots |= I.flags_inv
if(transparent_protection)
if(transparent_protection)
for(var/obj/item/I in get_all_worn_items())
hidden_slots |= I.transparent_protection

if(hidden_slots & HIDENECK)
Expand Down
3 changes: 3 additions & 0 deletions code/modules/mob/living/carbon/carbon_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
///only used by humans.
var/obj/item/clothing/ears = null

/// A compilation of all equipped items 'flags_inv' vars.
var/obscured_slots = NONE

/// Carbon
var/datum/dna/dna = null
///last mind to control this mob, for blood-based cloning
Expand Down
2 changes: 2 additions & 0 deletions code/modules/mob/living/carbon/carbon_update_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
update_suit_storage()
if(slot_flags & (ITEM_SLOT_LPOCKET|ITEM_SLOT_RPOCKET))
update_pockets()
if(slot_flags & ITEM_SLOT_HANDS)
update_held_items()


//IMPORTANT: Multiple animate() calls do not stack well, so try to do them all at once if you can.
Expand Down
Loading

0 comments on commit 9514d22

Please sign in to comment.