From 99d95aae62a559364e83229bff956f73aabbbcfe Mon Sep 17 00:00:00 2001 From: SSensum13 <121913313+SSensum13@users.noreply.github.com> Date: Mon, 11 Aug 2025 21:20:50 +0300 Subject: [PATCH] Some ITEM_SLOT bitflags fixes. (#92441) ## About The Pull Request This PR fixes wrong usage of bitflags in a few places, where instead of bitfields lists were used. ## Why It's Good For The Game It will help prevent problems that can be a thing in the future, improving consistency of the codebase. --- code/datums/components/earprotection.dm | 4 ++-- code/datums/components/punchcooldown.dm | 2 +- code/datums/components/sitcomlaughter.dm | 2 +- code/datums/components/slippery.dm | 6 +++--- code/datums/components/wearertargeting.dm | 6 ++++-- code/game/objects/items/devices/radio/headset.dm | 10 +++++----- .../abductor/equipment/gear/abductor_items.dm | 2 +- .../antagonists/fugitive/hunters/hunter_gear.dm | 2 +- code/modules/clothing/ears/_ears.dm | 2 +- code/modules/clothing/head/perceptomatrix.dm | 2 +- code/modules/mod/modules/modules_general.dm | 2 +- .../computers/item/role_tablet_presets.dm | 2 +- 12 files changed, 22 insertions(+), 20 deletions(-) diff --git a/code/datums/components/earprotection.dm b/code/datums/components/earprotection.dm index 6dfa7d9568b..542a1d0c60f 100644 --- a/code/datums/components/earprotection.dm +++ b/code/datums/components/earprotection.dm @@ -3,10 +3,10 @@ mobtype = /mob/living/carbon proctype = PROC_REF(reducebang) var/reduce_amount = 1 + valid_slots = ITEM_SLOT_EARS | ITEM_SLOT_HEAD -/datum/component/wearertargeting/earprotection/Initialize(valid_slots, reduce_amount = 1) +/datum/component/wearertargeting/earprotection/Initialize(reduce_amount = 1) . = ..() - src.valid_slots = valid_slots if(reduce_amount) src.reduce_amount = reduce_amount diff --git a/code/datums/components/punchcooldown.dm b/code/datums/components/punchcooldown.dm index 22a212d4512..72220a91cab 100644 --- a/code/datums/components/punchcooldown.dm +++ b/code/datums/components/punchcooldown.dm @@ -3,7 +3,7 @@ signals = list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_LIVING_HAND_ITEM_ATTACK) mobtype = /mob/living/carbon proctype = PROC_REF(reducecooldown) - valid_slots = list(ITEM_SLOT_GLOVES) + valid_slots = ITEM_SLOT_GLOVES ///The warcry this generates var/warcry = "AT" diff --git a/code/datums/components/sitcomlaughter.dm b/code/datums/components/sitcomlaughter.dm index bc69a08b80c..835a82cee42 100644 --- a/code/datums/components/sitcomlaughter.dm +++ b/code/datums/components/sitcomlaughter.dm @@ -1,5 +1,5 @@ /datum/component/wearertargeting/sitcomlaughter - valid_slots = list(ITEM_SLOT_HANDS, ITEM_SLOT_BELT, ITEM_SLOT_ID, ITEM_SLOT_LPOCKET, ITEM_SLOT_RPOCKET, ITEM_SLOT_SUITSTORE, ITEM_SLOT_DEX_STORAGE) + valid_slots = ITEM_SLOT_HANDS | ITEM_SLOT_BELT | ITEM_SLOT_ID | ITEM_SLOT_LPOCKET | ITEM_SLOT_RPOCKET | ITEM_SLOT_SUITSTORE | ITEM_SLOT_DEX_STORAGE signals = list(COMSIG_MOB_HIT_BY_SPLAT, COMSIG_ON_CARBON_SLIP, COMSIG_POST_TILT_AND_CRUSH, COMSIG_MOB_CLUMSY_SHOOT_FOOT) proctype = PROC_REF(EngageInComedy) mobtype = /mob/living diff --git a/code/datums/components/slippery.dm b/code/datums/components/slippery.dm index 370b3406ff9..edc48a512d2 100644 --- a/code/datums/components/slippery.dm +++ b/code/datums/components/slippery.dm @@ -33,8 +33,8 @@ var/datum/callback/on_slip_callback /// If parent is an item, this is the person currently holding/wearing the parent (or the parent if no one is holding it) var/mob/living/holder - /// Whitelist of item slots the parent can be equipped in that make the holder slippery. If null or empty, it will always make the holder slippery. - var/list/slot_whitelist = list(ITEM_SLOT_OCLOTHING, ITEM_SLOT_ICLOTHING, ITEM_SLOT_GLOVES, ITEM_SLOT_FEET, ITEM_SLOT_HEAD, ITEM_SLOT_MASK, ITEM_SLOT_BELT, ITEM_SLOT_NECK) + /// Whitelist bitfields of item slots bitflags the parent can be equipped in that make the holder slippery. If null or empty, it will always make the holder slippery. + var/slot_whitelist = ITEM_SLOT_OCLOTHING | ITEM_SLOT_ICLOTHING | ITEM_SLOT_GLOVES | ITEM_SLOT_FEET | ITEM_SLOT_HEAD | ITEM_SLOT_MASK | ITEM_SLOT_BELT | ITEM_SLOT_NECK ///what we give to connect_loc by default, makes slippable mobs moving over us slip var/static/list/default_connections = list( COMSIG_ATOM_ENTERED = PROC_REF(Slip), @@ -191,7 +191,7 @@ /datum/component/slippery/proc/on_equip(datum/source, mob/equipper, slot) SIGNAL_HANDLER - if((!LAZYLEN(slot_whitelist) || (slot in slot_whitelist)) && isliving(equipper)) + if((!slot || (slot & slot_whitelist)) && isliving(equipper)) holder = equipper qdel(GetComponent(/datum/component/connect_loc_behalf)) AddComponent(/datum/component/connect_loc_behalf, holder, mob_connections) diff --git a/code/datums/components/wearertargeting.dm b/code/datums/components/wearertargeting.dm index 44c16aa72bd..fa04ebb3918 100644 --- a/code/datums/components/wearertargeting.dm +++ b/code/datums/components/wearertargeting.dm @@ -1,7 +1,9 @@ // A dummy parent type used for easily making components that target an item's wearer rather than the item itself. /datum/component/wearertargeting - var/list/valid_slots = list() + /// Bitflag value of valid slots. + /// You can find all slot bitflags in code/__DEFINES/inventory.dm + var/valid_slots = NONE var/list/signals = list() var/proctype = GLOBAL_PROC_REF(pass) var/mobtype = /mob/living @@ -15,7 +17,7 @@ /datum/component/wearertargeting/proc/on_equip(datum/source, mob/equipper, slot) SIGNAL_HANDLER - if((slot in valid_slots) && istype(equipper, mobtype)) + if((valid_slots & slot) && istype(equipper, mobtype)) RegisterSignals(equipper, signals, proctype, TRUE) else UnregisterSignal(equipper, signals) diff --git a/code/game/objects/items/devices/radio/headset.dm b/code/game/objects/items/devices/radio/headset.dm index bf51058d9ee..08580c0a550 100644 --- a/code/game/objects/items/devices/radio/headset.dm +++ b/code/game/objects/items/devices/radio/headset.dm @@ -183,7 +183,7 @@ GLOBAL_LIST_INIT(channel_tokens, list( /obj/item/radio/headset/syndicate/alt/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) /obj/item/radio/headset/syndicate/alt/leader name = "team leader headset" @@ -207,7 +207,7 @@ GLOBAL_LIST_INIT(channel_tokens, list( /obj/item/radio/headset/headset_sec/alt/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) /obj/item/radio/headset/headset_eng name = "engineering radio headset" @@ -290,7 +290,7 @@ GLOBAL_LIST_INIT(channel_tokens, list( /obj/item/radio/headset/heads/captain/alt/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) /obj/item/radio/headset/heads/rd name = "\proper the research director's headset" @@ -322,7 +322,7 @@ GLOBAL_LIST_INIT(channel_tokens, list( /obj/item/radio/headset/heads/hos/alt/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) /obj/item/radio/headset/heads/ce name = "\proper the chief engineer's headset" @@ -414,7 +414,7 @@ GLOBAL_LIST_INIT(channel_tokens, list( /obj/item/radio/headset/headset_cent/alt/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) /obj/item/radio/headset/headset_cent/alt/leader command = TRUE diff --git a/code/modules/antagonists/abductor/equipment/gear/abductor_items.dm b/code/modules/antagonists/abductor/equipment/gear/abductor_items.dm index 57d3e2a36d7..90d2d5a9053 100644 --- a/code/modules/antagonists/abductor/equipment/gear/abductor_items.dm +++ b/code/modules/antagonists/abductor/equipment/gear/abductor_items.dm @@ -520,7 +520,7 @@ Return to step 11 of normal process."} /obj/item/radio/headset/abductor/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) make_syndie() // Stops humans from disassembling abductor headsets. diff --git a/code/modules/antagonists/fugitive/hunters/hunter_gear.dm b/code/modules/antagonists/fugitive/hunters/hunter_gear.dm index 4efe29b1048..34d10b05789 100644 --- a/code/modules/antagonists/fugitive/hunters/hunter_gear.dm +++ b/code/modules/antagonists/fugitive/hunters/hunter_gear.dm @@ -218,7 +218,7 @@ /obj/item/radio/headset/psyker/Initialize(mapload) . = ..() - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) /obj/item/radio/headset/psyker/equipped(mob/living/user, slot) . = ..() diff --git a/code/modules/clothing/ears/_ears.dm b/code/modules/clothing/ears/_ears.dm index c1898c0ab9d..fe16215c70f 100644 --- a/code/modules/clothing/ears/_ears.dm +++ b/code/modules/clothing/ears/_ears.dm @@ -25,7 +25,7 @@ /obj/item/clothing/ears/earmuffs/Initialize(mapload) . = ..() AddElement(/datum/element/earhealing) - AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_EARS)) + AddComponent(/datum/component/wearertargeting/earprotection) AddComponent(/datum/component/adjust_fishing_difficulty, -2) /obj/item/clothing/ears/earmuffs/debug diff --git a/code/modules/clothing/head/perceptomatrix.dm b/code/modules/clothing/head/perceptomatrix.dm index 9e31361e0c9..45f55a46ff0 100644 --- a/code/modules/clothing/head/perceptomatrix.dm +++ b/code/modules/clothing/head/perceptomatrix.dm @@ -102,7 +102,7 @@ // When someone makes TRAIT_DEAF an element, or status effect, or whatever, give this item a way to bypass said deafness. // just blocking future instances of deafness isn't what the item is meant to do but there's no proper way to do it otherwise at the moment. - active_components += AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_HEAD), reduce_amount = 2) // should be same as highest value + active_components += AddComponent(/datum/component/wearertargeting/earprotection, reduce_amount = 2) // should be same as highest value active_components += AddComponent( /datum/component/anti_magic, \ antimagic_flags = MAGIC_RESISTANCE_MIND, \ diff --git a/code/modules/mod/modules/modules_general.dm b/code/modules/mod/modules/modules_general.dm index 7ff12b07398..f15cc496f16 100644 --- a/code/modules/mod/modules/modules_general.dm +++ b/code/modules/mod/modules/modules_general.dm @@ -1057,7 +1057,7 @@ /obj/item/mod/module/hearing_protection/on_part_activation() var/obj/item/clothing/head_cover = mod.get_part_from_slot(ITEM_SLOT_HEAD) || mod.get_part_from_slot(ITEM_SLOT_MASK) || mod.get_part_from_slot(ITEM_SLOT_EYES) if(istype(head_cover)) - head_cover.AddComponent(/datum/component/wearertargeting/earprotection, list(ITEM_SLOT_HEAD)) + head_cover.AddComponent(/datum/component/wearertargeting/earprotection) var/datum/component/wearertargeting/earprotection/protection = head_cover.GetComponent(/datum/component/wearertargeting/earprotection) protection.on_equip(src, mod.wearer, ITEM_SLOT_HEAD) diff --git a/code/modules/modular_computers/computers/item/role_tablet_presets.dm b/code/modules/modular_computers/computers/item/role_tablet_presets.dm index 5416aa0e7ea..5f16390af0b 100644 --- a/code/modules/modular_computers/computers/item/role_tablet_presets.dm +++ b/code/modules/modular_computers/computers/item/role_tablet_presets.dm @@ -337,7 +337,7 @@ lube_flags = NO_SLIP_WHEN_WALKING,\ on_slip_callback = CALLBACK(src, PROC_REF(AfterSlip)),\ can_slip_callback = CALLBACK(src, PROC_REF(try_slip)),\ - slot_whitelist = list(ITEM_SLOT_ID, ITEM_SLOT_BELT),\ + slot_whitelist = ITEM_SLOT_ID | ITEM_SLOT_BELT,\ ) AddComponent(/datum/component/wearertargeting/sitcomlaughter, CALLBACK(src, PROC_REF(after_sitcom_laugh)))