Skip to content

Commit

Permalink
Merge pull request #3931 from MistakeNot4892/rework/accessory_slots
Browse files Browse the repository at this point in the history
Simplifying how accessory slot flags and slot strings are handled.
  • Loading branch information
out-of-phaze authored Apr 23, 2024
2 parents a6d38ce + c7b4a2c commit b8ddc49
Show file tree
Hide file tree
Showing 38 changed files with 96 additions and 145 deletions.
8 changes: 4 additions & 4 deletions code/__defines/items_clothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#define slot_socks_str "slot_socks"

// Bodypart coverage bitflags.
#define SLOT_NONE 0
#define SLOT_UPPER_BODY BITFLAG(0)
#define SLOT_LOWER_BODY BITFLAG(1)
#define SLOT_OVER_BODY BITFLAG(2)
Expand All @@ -83,10 +84,9 @@
#define SLOT_HEAD BITFLAG(14)
#define SLOT_ID BITFLAG(15)
#define SLOT_BACK BITFLAG(16)
#define SLOT_TIE BITFLAG(17)
#define SLOT_HOLSTER BITFLAG(18)
#define SLOT_POCKET BITFLAG(19)
#define SLOT_TAIL BITFLAG(20)
#define SLOT_HOLSTER BITFLAG(17)
#define SLOT_POCKET BITFLAG(18)
#define SLOT_TAIL BITFLAG(19)
#define SLOT_LEGS (SLOT_LEG_LEFT|SLOT_LEG_RIGHT)
#define SLOT_FEET (SLOT_FOOT_LEFT|SLOT_FOOT_RIGHT)
#define SLOT_ARMS (SLOT_ARM_LEFT|SLOT_ARM_RIGHT)
Expand Down
27 changes: 13 additions & 14 deletions code/_helpers/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@ var/global/list/string_part_flags = list(

// Strings which corraspond to slot flags, useful for outputting what slot something is.
var/global/list/string_slot_flags = list(
"back" = SLOT_BACK,
"face" = SLOT_FACE,
"waist" = SLOT_LOWER_BODY,
"tail" = SLOT_TAIL,
"ID slot" = SLOT_ID,
"ears" = SLOT_EARS,
"eyes" = SLOT_EYES,
"hands" = SLOT_HANDS,
"head" = SLOT_HEAD,
"feet" = SLOT_FEET,
"exo slot" = SLOT_OVER_BODY,
"body" = SLOT_UPPER_BODY,
"uniform" = SLOT_TIE,
"holster" = SLOT_HOLSTER
"back" = SLOT_BACK,
"face" = SLOT_FACE,
"waist" = SLOT_LOWER_BODY,
"tail" = SLOT_TAIL,
"ID slot" = SLOT_ID,
"ears" = SLOT_EARS,
"eyes" = SLOT_EYES,
"hands" = SLOT_HANDS,
"head" = SLOT_HEAD,
"feet" = SLOT_FEET,
"exo slot" = SLOT_OVER_BODY,
"body" = SLOT_UPPER_BODY,
"holster" = SLOT_HOLSTER
)

//////////////////////////
Expand Down
5 changes: 3 additions & 2 deletions code/game/objects/item_mob_overlay.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ var/global/list/icon_state_cache = list()
var/useicon = get_icon_for_bodytype(bodytype)
var/use_state = "[bodytype]-[slot][state_modifier]"

var/is_not_held_slot = !(slot in global.all_hand_slots)
if(bodytype != BODYTYPE_HUMANOID && !check_state_in_icon(use_state, useicon) && use_fallback_if_icon_missing)
var/fallback = get_fallback_slot(slot)
var/fallback = is_not_held_slot && get_fallback_slot(slot)
if(fallback && fallback != slot && check_state_in_icon("[bodytype]-[fallback][state_modifier]", useicon))
slot = fallback
else
Expand All @@ -86,7 +87,7 @@ var/global/list/icon_state_cache = list()
use_state = "[bodytype]-[global.bodypart_to_slot_lookup_table[slot]][state_modifier]"

if(!check_state_in_icon(use_state, useicon))
var/fallback = use_fallback_if_icon_missing && get_fallback_slot(slot)
var/fallback = use_fallback_if_icon_missing && is_not_held_slot && get_fallback_slot(slot)
if(!fallback)
return new /image
slot = fallback
Expand Down
6 changes: 4 additions & 2 deletions code/game/objects/items/__item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
var/randpixel = 6
var/material_health_multiplier = 0.2
var/hitsound
var/slot_flags = 0 //This is used to determine on which slots an item can fit.
var/no_attack_log = 0 //If it's an item we don't want to log attack_logs with, set this to 1
/// This is used to determine on which slots an item can fit.
var/slot_flags = SLOT_NONE
/// If it's an item we don't want to log attack_logs with, set this to TRUE
var/no_attack_log = 0
var/obj/item/master = null
var/origin_tech //Used by R&D to determine what research bonuses it grants.
var/list/attack_verb = list("hit") //Used in attackby() to say how something was attacked "[x] has been [z.attack_verb] by [y] with [z]"
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/dog_tags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
desc = "Plain identification tags made from a durable metal. They are stamped with a variety of informational details."
gender = PLURAL
icon = 'icons/clothing/accessories/jewelry/dogtags.dmi'
slot_flags = SLOT_FACE | SLOT_TIE
slot_flags = SLOT_FACE
badge_string = null
material = /decl/material/solid/metal/stainlesssteel
var/owner_rank
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/decl/loadout_option/accessory
category = /decl/loadout_category/accessories
abstract_type = /decl/loadout_option/accessory
slot = slot_tie_str

/decl/loadout_option/accessory/tie
name = "tie selection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
/decl/loadout_option/clothing
category = /decl/loadout_category/clothing
abstract_type = /decl/loadout_option/clothing
slot = slot_tie_str

/decl/loadout_option/clothing/flannel
name = "flannel (colorable)"
path = /obj/item/clothing/shirt/flannel
slot = slot_tie_str
loadout_flags = GEAR_HAS_COLOR_SELECTION

/decl/loadout_option/clothing/scarf
Expand Down
2 changes: 1 addition & 1 deletion code/modules/client/preference_setup/loadout/loadout.dm
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ var/global/list/gear_datums = list()
var/description // Description of this gear. If left blank will default to the description of the pathed item.
var/path // Path of item.
var/cost = 1 // Number of points used. Items in general cost 1 point, storage/armor/gloves/special use costs 2 points.
var/slot // Slot to equip to.
var/slot = slot_tie_str // Slot to equip to.
var/list/allowed_roles // Roles that can spawn with this item.
var/list/allowed_branches // Service branches that can spawn with it.
var/list/allowed_skills // Skills required to spawn with this item.
Expand Down
18 changes: 10 additions & 8 deletions code/modules/clothing/_clothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@
var/markings_state_modifier // simple colored overlay that would be applied to the icon
var/markings_color // for things like colored parts of labcoats or shoes
var/should_display_id = TRUE
var/fallback_slot

/obj/item/clothing/Initialize()

. = ..()

accessory_hide_on_states = get_initial_accessory_hide_on_states()
if(accessory_slot)
if(isnull(accessory_removable))
accessory_removable = TRUE
if(isnull(fallback_slot))
fallback_slot = slot_tie_str
accessory_hide_on_states = get_initial_accessory_hide_on_states()

if(starting_accessories)
for(var/T in starting_accessories)
Expand All @@ -47,6 +53,9 @@
on_removed()
return ..()

/obj/item/clothing/get_fallback_slot(slot)
return fallback_slot

/obj/item/clothing/get_stored_inventory()
. = ..()
if(length(.) && length(accessories))
Expand Down Expand Up @@ -377,10 +386,3 @@
. = ..()
LAZYADD(., /decl/interaction_handler/clothing_set_sensors)

// This stub is so the linter stops yelling about sleeping during Initialize()
// due to corpse props equipping themselves, which calls equip_to_slot, which
// calls attackby(), which sometimes sleeps due to input(). Yeah.
// Remove this if a better fix presents itself.
/obj/item/clothing/proc/try_attach_accessory(var/obj/item/accessory, var/mob/user)
set waitfor = FALSE
attackby(accessory, user)
28 changes: 14 additions & 14 deletions code/modules/clothing/_clothing_accessories.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/obj/item/clothing
var/accessory_slot
var/accessory_removable = FALSE
var/accessory_removable
/// if it should appear on examine without detailed view
var/accessory_high_visibility
/// used when an accessory is meant to slow the wearer down when attached to clothing
Expand All @@ -10,15 +10,19 @@
/obj/item/clothing/proc/get_initial_accessory_hide_on_states()
return null

/obj/item/clothing/proc/can_attach_accessory(obj/item/clothing/accessory)
if(valid_accessory_slots && istype(accessory) && !isnull(accessory.accessory_slot) && (accessory.accessory_slot in valid_accessory_slots))
. = 1
else
return 0
/obj/item/clothing/proc/can_attach_accessory(obj/item/clothing/accessory, mob/user)
if(!length(valid_accessory_slots))
to_chat(user, SPAN_WARNING("You cannot attach accessories of any kind to \the [src]."))
return FALSE
if(!istype(accessory) || isnull(accessory.accessory_slot) || !(accessory.accessory_slot in valid_accessory_slots))
to_chat(user, SPAN_WARNING("You cannot attach accessories of this kind to \the [src]."))
return FALSE
if(LAZYLEN(accessories) && restricted_accessory_slots && (accessory.accessory_slot in restricted_accessory_slots))
for(var/obj/item/clothing/other_accessory in accessories)
if (other_accessory.accessory_slot == accessory.accessory_slot)
return 0
to_chat(user, SPAN_WARNING("You cannot attach more accessories of this kind to \the [src]."))
return FALSE
return TRUE

// Override for action buttons.
/obj/item/clothing/attack_self(mob/user)
Expand All @@ -43,20 +47,16 @@
return ..()

/obj/item/clothing/attackby(var/obj/item/I, var/mob/user)

if(istype(I, /obj/item/clothing))

var/obj/item/clothing/accessory = I
if(!isnull(accessory.accessory_slot))

if(!valid_accessory_slots || !valid_accessory_slots.len)
to_chat(usr, SPAN_WARNING("You cannot attach accessories of any kind to \the [src]."))
return TRUE

if(can_attach_accessory(accessory))
if(can_attach_accessory(accessory, user))
if(user.try_unequip(accessory))
attach_accessory(user, accessory)
else
to_chat(user, SPAN_WARNING("You cannot attach more accessories of this type to [src]."))
to_chat(user, SPAN_WARNING("You cannot attach \the [I] to \the [src]."))
return TRUE

if(length(accessories))
Expand Down
6 changes: 1 addition & 5 deletions code/modules/clothing/badges/_badge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
desc = "A leather-backed badge, with gold trimmings."
icon = 'icons/clothing/accessories/badges/detectivebadge.dmi'
w_class = ITEM_SIZE_SMALL
slot_flags = SLOT_LOWER_BODY | SLOT_TIE
slot_flags = SLOT_LOWER_BODY
accessory_slot = ACCESSORY_SLOT_INSIGNIA
accessory_removable = TRUE
var/badge_string = "Detective"
var/stored_name

/obj/item/clothing/badge/get_fallback_slot(var/slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_tie_str

/obj/item/clothing/badge/get_initial_accessory_hide_on_states()
var/static/list/initial_accessory_hide_on_states = list(
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/badges/holobadge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/obj/item/clothing/badge/holo/cord
icon = 'icons/clothing/accessories/badges/holobadge_cord.dmi'
slot_flags = SLOT_FACE | SLOT_TIE
slot_flags = SLOT_FACE

/obj/item/clothing/badge/holo/set_name(var/new_name)
..()
Expand Down
8 changes: 2 additions & 6 deletions code/modules/clothing/belts/suspenders.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
name = "suspenders"
desc = "They suspend the illusion of the mime's play."
icon = 'icons/clothing/belt/suspenders_red.dmi'
slot_flags = SLOT_TIE | SLOT_LOWER_BODY
slot_flags = SLOT_LOWER_BODY
w_class = ITEM_SIZE_SMALL
accessory_slot = ACCESSORY_SLOT_DECOR
accessory_removable = TRUE

/obj/item/clothing/suspenders/get_fallback_slot(slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_belt_str
fallback_slot = slot_belt_str

/obj/item/clothing/suspenders/colorable
icon = 'icons/clothing/belt/suspenders.dmi'
5 changes: 1 addition & 4 deletions code/modules/clothing/gloves/_gloves.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
attack_verb = list("challenged")
blood_overlay_type = "bloodyhands"
bodytype_equip_flags = BODY_FLAG_HUMANOID
fallback_slot = slot_gloves_str
var/obj/item/clothing/ring/covering_ring

/obj/item/clothing/gloves/get_fallback_slot(slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_gloves_str

/obj/item/clothing/gloves/get_associated_equipment_slots()
. = ..()
LAZYDISTINCTADD(., slot_gloves_str)
Expand Down
7 changes: 1 addition & 6 deletions code/modules/clothing/medals/medals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
icon = 'icons/clothing/accessories/medals/medal_bronze.dmi'
w_class = ITEM_SIZE_SMALL
accessory_slot = ACCESSORY_SLOT_MEDAL
slot_flags = SLOT_UPPER_BODY | SLOT_TIE
accessory_removable = TRUE

/obj/item/clothing/medal/get_fallback_slot(var/slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_tie_str
slot_flags = SLOT_UPPER_BODY

/obj/item/clothing/medal/bronze
name = "bronze medal"
Expand Down
5 changes: 0 additions & 5 deletions code/modules/clothing/neck/_neck.dm
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/obj/item/clothing/neck
abstract_type = /obj/item/clothing/neck
slot_flags = SLOT_TIE
w_class = ITEM_SIZE_SMALL
accessory_slot = ACCESSORY_SLOT_NECK

/obj/item/clothing/neck/get_fallback_slot(var/slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_tie_str
6 changes: 1 addition & 5 deletions code/modules/clothing/pants/_pants.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
slot_flags = SLOT_UPPER_BODY // SLOT_LOWER_BODY when pants slot exists
w_class = ITEM_SIZE_NORMAL
force = 0
fallback_slot = slot_w_uniform_str
valid_accessory_slots = list(
ACCESSORY_SLOT_SENSORS,
ACCESSORY_SLOT_UTILITY,
Expand All @@ -34,8 +35,3 @@
. = ..()
var/static/list/pants_slots = list(slot_w_uniform_str, slot_wear_id_str)
LAZYDISTINCTADD(., pants_slots)


/obj/item/clothing/pants/get_fallback_slot(var/slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_w_uniform_str
6 changes: 0 additions & 6 deletions code/modules/clothing/pants/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
name = "fire overpants"
desc = "some overpants made of fire-resistant synthetic fibers. To be worn over the uniform."
icon = 'icons/clothing/under/pants/overpants.dmi'

gas_transfer_coefficient = 0.90
permeability_coefficient = 0.50

armor = list(ARMOR_LASER = ARMOR_LASER_MINOR, ARMOR_ENERGY = ARMOR_ENERGY_MINOR, ARMOR_BOMB = ARMOR_BOMB_MINOR)
body_parts_covered = SLOT_LOWER_BODY | SLOT_LEGS | SLOT_TAIL
accessory_slowdown = 0.5

heat_protection = SLOT_LOWER_BODY | SLOT_LEGS | SLOT_TAIL
cold_protection = SLOT_LOWER_BODY | SLOT_LEGS | SLOT_TAIL

max_heat_protection_temperature = FIRESUIT_MAX_HEAT_PROTECTION_TEMPERATURE
max_pressure_protection = FIRESUIT_MAX_PRESSURE

accessory_slot = ACCESSORY_SLOT_DECOR
accessory_removable = TRUE
2 changes: 0 additions & 2 deletions code/modules/clothing/sensors/_sensor.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/obj/item/clothing/sensor
name = "sensor"
abstract_type = /obj/item/clothing/sensor
slot_flags = SLOT_TIE
icon_state = ICON_STATE_WORLD
accessory_slot = ACCESSORY_SLOT_SENSORS

/obj/item/clothing/sensor/get_mob_overlay(mob/user_mob, slot, bodypart, use_fallback_if_icon_missing = TRUE, skip_adjustment = FALSE)
Expand Down
7 changes: 2 additions & 5 deletions code/modules/clothing/shirts/_shirts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
abstract_type = /obj/item/clothing/shirt
body_parts_covered = SLOT_UPPER_BODY|SLOT_ARMS
permeability_coefficient = 0.90
slot_flags = SLOT_UPPER_BODY | SLOT_TIE
slot_flags = SLOT_UPPER_BODY
w_class = ITEM_SIZE_SMALL
accessory_slot = ACCESSORY_SLOT_DECOR
accessory_removable = TRUE
force = 0
fallback_slot = slot_w_uniform_str

/obj/item/clothing/shirt/get_associated_equipment_slots()
. = ..()
var/static/list/shirt_slots = list(slot_w_uniform_str, slot_wear_id_str)
LAZYDISTINCTADD(., shirt_slots)

/obj/item/clothing/shirt/get_fallback_slot(var/slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_w_uniform_str
5 changes: 1 addition & 4 deletions code/modules/clothing/shoes/_shoes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
blood_overlay_type = "shoeblood"
material = /decl/material/solid/organic/leather
origin_tech = @'{"materials":1,"engineering":1}'
fallback_slot = slot_shoes_str

var/can_fit_under_magboots = TRUE
var/can_add_cuffs = TRUE
Expand All @@ -30,10 +31,6 @@
/// A modifier applied to move delay when walking on snow.
var/snow_slowdown_mod = 0

/obj/item/clothing/shoes/get_fallback_slot(slot)
if(slot != BP_L_HAND && slot != BP_R_HAND)
return slot_shoes_str

/obj/item/clothing/shoes/Destroy()
. = ..()
if (hidden_item)
Expand Down
Loading

0 comments on commit b8ddc49

Please sign in to comment.