Skip to content

Commit

Permalink
Merge pull request #3484 from MistakeNot4892/sensors
Browse files Browse the repository at this point in the history
Vitals sensors are now handled by an accessory.
  • Loading branch information
out-of-phaze authored Dec 6, 2023
2 parents e4cd66d + c73e361 commit f86861b
Show file tree
Hide file tree
Showing 45 changed files with 402 additions and 244 deletions.
13 changes: 5 additions & 8 deletions code/__defines/items_clothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ACCESSORY_SLOT_ARMOR_M "Misc armor"
#define ACCESSORY_SLOT_HELM_C "Helmet cover"
#define ACCESSORY_SLOT_OVER "Over"
#define ACCESSORY_SLOT_SENSORS "Suit Sensors"

// Bitmasks for the flags_inv variable. These determine when a piece of clothing hides another, i.e. a helmet hiding glasses.
// WARNING: The following flags apply only to the external suit!
Expand Down Expand Up @@ -155,14 +156,10 @@
#define THROWNOBJ_KNOCKBACK_DIVISOR 2 // Affects how much speed the mob is knocked back with.

// Suit sensor levels
#define SUIT_SENSOR_OFF 0
#define SUIT_SENSOR_BINARY 1
#define SUIT_SENSOR_VITAL 2
#define SUIT_SENSOR_TRACKING 3

#define SUIT_NO_SENSORS 0
#define SUIT_HAS_SENSORS 1
#define SUIT_LOCKED_SENSORS 2
#define VITALS_SENSOR_OFF 0
#define VITALS_SENSOR_BINARY 1
#define VITALS_SENSOR_VITAL 2
#define VITALS_SENSOR_TRACKING 3

// Hair Flags
#define VERY_SHORT BITFLAG(0)
Expand Down
4 changes: 4 additions & 0 deletions code/_global_vars/lists/clothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ var/global/list/abstract_inventory_slots = list(
slot_underpants_str,
slot_socks_str
)

var/global/list/vitals_sensor_equip_slots = list(
slot_w_uniform_str
)
19 changes: 12 additions & 7 deletions code/datums/extensions/multitool/items/clothing.dm
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/obj/item/clothing/under/Initialize()
/obj/item/clothing/Initialize()
. = ..()
set_extension(src, /datum/extension/interactive/multitool/items/clothing)
if(ACCESSORY_SLOT_SENSORS in valid_accessory_slots)
set_extension(src, /datum/extension/interactive/multitool/items/clothing)

/datum/extension/interactive/multitool/items/clothing/interact(var/obj/item/multitool/M, var/mob/user)
if(extension_status(user) != STATUS_INTERACTIVE)
return
var/obj/item/clothing/under/u = holder
if(u.has_sensor == SUIT_NO_SENSORS)
to_chat(user, SPAN_WARNING("\The [u] doesn't have suit sensors."))
var/obj/item/clothing/uniform = holder
if(!istype(uniform))
to_chat(user, SPAN_WARNING("\The [user] is not wearing an appropriate uniform."))
return
u.has_sensor = u.has_sensor == SUIT_LOCKED_SENSORS ? SUIT_HAS_SENSORS : SUIT_LOCKED_SENSORS
user.visible_message(SPAN_NOTICE("\The [user] [u.has_sensor == SUIT_LOCKED_SENSORS ? "" : "un"]locks \the [u]'s suit sensor controls."), range = 2)
var/obj/item/clothing/accessory/vitals_sensor/sensor = locate() in uniform.accessories
if(!sensor)
to_chat(user, SPAN_WARNING("\The [uniform] doesn't have a vitals sensors attached."))
return
sensor.toggle_sensors_locked()
user.visible_message(SPAN_NOTICE("\The [user] [sensor.get_sensors_locked() ? "" : "un"]locks \the [user]'s suit sensor controls."), range = 2)
1 change: 1 addition & 0 deletions code/datums/outfits/_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define OUTFIT_HAS_BACKPACK BITFLAG(1)
#define OUTFIT_EXTENDED_SURVIVAL BITFLAG(2)
#define OUTFIT_RESET_EQUIPMENT BITFLAG(3)
#define OUTFIT_HAS_VITALS_SENSOR BITFLAG(4)

#define OUTFIT_ADJUSTMENT_SKIP_POST_EQUIP BITFLAG(0)
#define OUTFIT_ADJUSTMENT_SKIP_SURVIVAL_GEAR BITFLAG(1)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/outfits/jobs/generic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
shoes = /obj/item/clothing/shoes/workboots
pda_type = /obj/item/modular_computer/pda/engineering
pda_slot = slot_l_store_str
flags = OUTFIT_HAS_BACKPACK|OUTFIT_EXTENDED_SURVIVAL
outfit_flags = OUTFIT_HAS_BACKPACK | OUTFIT_EXTENDED_SURVIVAL | OUTFIT_HAS_VITALS_SENSOR

/decl/hierarchy/outfit/job/generic/engineer/Initialize()
. = ..()
Expand Down
2 changes: 1 addition & 1 deletion code/datums/outfits/jobs/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
pda_slot = slot_belt_str
pda_type = /obj/item/modular_computer/pda

flags = OUTFIT_HAS_BACKPACK
outfit_flags = OUTFIT_HAS_BACKPACK | OUTFIT_HAS_VITALS_SENSOR
4 changes: 2 additions & 2 deletions code/datums/outfits/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
uniform = /obj/item/clothing/under/color/grey
back = /obj/item/tank/jetpack/oxygen
mask = /obj/item/clothing/mask/breath
flags = OUTFIT_HAS_JETPACK|OUTFIT_RESET_EQUIPMENT
outfit_flags = OUTFIT_HAS_JETPACK|OUTFIT_RESET_EQUIPMENT

/decl/hierarchy/outfit/soviet_soldier
name = "Soviet soldier"
Expand Down Expand Up @@ -35,7 +35,7 @@
l_ear = /obj/item/radio/headset
uniform = /obj/item/clothing/under/clown
l_pocket = /obj/item/bikehorn
flags = OUTFIT_HAS_BACKPACK|OUTFIT_RESET_EQUIPMENT
outfit_flags = OUTFIT_HAS_BACKPACK | OUTFIT_RESET_EQUIPMENT | OUTFIT_HAS_VITALS_SENSOR

/decl/hierarchy/outfit/clown/Initialize()
. = ..()
Expand Down
37 changes: 32 additions & 5 deletions code/datums/outfits/outfit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var/global/list/outfits_decls_by_type_
var/id_pda_assignment

var/list/backpack_overrides
var/flags = OUTFIT_RESET_EQUIPMENT
var/outfit_flags = OUTFIT_RESET_EQUIPMENT

/decl/hierarchy/outfit/Initialize()
. = ..()
Expand All @@ -62,12 +62,29 @@ var/global/list/outfits_decls_by_type_
outfits_decls_by_type_[type] = src
dd_insertObjectList(outfits_decls_, src)

// This proc is structured slightly strangely because I will be adding pants to it.
/decl/hierarchy/outfit/validate()
. = ..()
if(uniform && (outfit_flags & OUTFIT_HAS_VITALS_SENSOR))
if(!ispath(uniform, /obj/item/clothing))
. += "outfit is flagged for sensors, but uniform cannot take accessories"
var/succeeded = FALSE
var/obj/item/sensor = new /obj/item/clothing/accessory/vitals_sensor
if(uniform)
var/obj/item/clothing/wear_uniform = new uniform // sadly we need to read a list
if(wear_uniform.can_attach_accessory(sensor))
succeeded = TRUE
qdel(wear_uniform)
if(!succeeded)
. += "outfit is flagged for sensors, but uniform does not accept sensors"
qdel(sensor)

/decl/hierarchy/outfit/proc/pre_equip(mob/living/carbon/human/H)
if(flags & OUTFIT_RESET_EQUIPMENT)
if(outfit_flags & OUTFIT_RESET_EQUIPMENT)
H.delete_inventory(TRUE)

/decl/hierarchy/outfit/proc/post_equip(mob/living/carbon/human/H)
if(flags & OUTFIT_HAS_JETPACK)
if(outfit_flags & OUTFIT_HAS_JETPACK)
var/obj/item/tank/jetpack/J = locate(/obj/item/tank/jetpack) in H
if(!J)
return
Expand All @@ -85,6 +102,16 @@ var/global/list/outfits_decls_by_type_
if(!(OUTFIT_ADJUSTMENT_SKIP_POST_EQUIP & equip_adjustments))
post_equip(H)

if(outfit_flags & OUTFIT_HAS_VITALS_SENSOR)
var/obj/item/clothing/accessory/vitals_sensor/sensor = new(get_turf(H))
for(var/check_slot in global.vitals_sensor_equip_slots)
var/obj/item/clothing/equipped = H.get_equipped_item(check_slot)
if(istype(equipped) && !(locate(/obj/item/clothing/accessory/vitals_sensor) in equipped.accessories) && equipped.can_attach_accessory(sensor))
equipped.attach_accessory(null, sensor)
break
if(isturf(sensor))
H.put_in_hands(sensor)

return 1

/decl/hierarchy/outfit/proc/equip_base(mob/living/carbon/human/H, var/equip_adjustments)
Expand Down Expand Up @@ -137,7 +164,7 @@ var/global/list/outfits_decls_by_type_
for(var/hand in hands)
H.put_in_hands(new hand(H))

if((flags & OUTFIT_HAS_BACKPACK) && !(OUTFIT_ADJUSTMENT_SKIP_BACKPACK & equip_adjustments))
if((outfit_flags & OUTFIT_HAS_BACKPACK) && !(OUTFIT_ADJUSTMENT_SKIP_BACKPACK & equip_adjustments))
var/decl/backpack_outfit/bo
var/metadata

Expand All @@ -158,7 +185,7 @@ var/global/list/outfits_decls_by_type_
H.equip_to_slot_or_del(backpack, slot_back_str)

if(H.species && !(OUTFIT_ADJUSTMENT_SKIP_SURVIVAL_GEAR & equip_adjustments))
if(flags & OUTFIT_EXTENDED_SURVIVAL)
if(outfit_flags & OUTFIT_EXTENDED_SURVIVAL)
H.species.equip_survival_gear(H, /obj/item/storage/box/engineer)
else if(H.client?.prefs?.survival_box_choice && global.survival_box_choices[H.client.prefs.survival_box_choice])
var/decl/survival_box_option/box = global.survival_box_choices[H.client.prefs.survival_box_choice]
Expand Down
2 changes: 1 addition & 1 deletion code/datums/outfits/pirates.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
head = /obj/item/clothing/suit/armor/pirate
suit = /obj/item/clothing/suit/pirate
back = /obj/item/tank/jetpack/oxygen
flags = OUTFIT_HAS_JETPACK|OUTFIT_RESET_EQUIPMENT
outfit_flags = OUTFIT_HAS_JETPACK|OUTFIT_RESET_EQUIPMENT
4 changes: 2 additions & 2 deletions code/datums/outfits/spec_op.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
back = /obj/item/tank/jetpack/oxygen
mask = /obj/item/clothing/mask/gas/swat

flags = OUTFIT_HAS_JETPACK|OUTFIT_RESET_EQUIPMENT
outfit_flags = OUTFIT_HAS_JETPACK|OUTFIT_RESET_EQUIPMENT

/decl/hierarchy/outfit/ert
name = "Spec Ops - Emergency response team"
Expand Down Expand Up @@ -54,7 +54,7 @@

backpack_contents = list(/obj/item/clothing/suit/space/void/merc/prepared = 1, /obj/item/clothing/mask/gas/syndicate = 1)

flags = OUTFIT_HAS_BACKPACK|OUTFIT_RESET_EQUIPMENT
outfit_flags = OUTFIT_HAS_BACKPACK|OUTFIT_RESET_EQUIPMENT

/decl/hierarchy/outfit/mercenary/syndicate
name = "Spec Ops - Syndicate"
Expand Down
2 changes: 1 addition & 1 deletion code/datums/outfits/wizardry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
back = /obj/item/storage/backpack
backpack_contents = list(/obj/item/storage/box = 1)
abstract_type = /decl/hierarchy/outfit/wizard
flags = OUTFIT_HAS_BACKPACK|OUTFIT_RESET_EQUIPMENT
outfit_flags = OUTFIT_HAS_BACKPACK|OUTFIT_RESET_EQUIPMENT

/decl/hierarchy/outfit/wizard/blue
name = "Wizard - Blue"
Expand Down
8 changes: 4 additions & 4 deletions code/datums/repositories/crew/binary.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Binary */
/crew_sensor_modifier/binary/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos, var/list/crew_data)
/crew_sensor_modifier/binary/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos, var/list/crew_data)
crew_data["alert"] = FALSE
if(!H.isSynthetic() && H.should_have_organ(BP_HEART))
var/obj/item/organ/internal/heart/O = H.get_organ(BP_HEART, /obj/item/organ/internal/heart)
Expand All @@ -19,11 +19,11 @@
/crew_sensor_modifier/binary/jamming
priority = 5

/crew_sensor_modifier/binary/jamming/alive/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos, var/list/crew_data)
/crew_sensor_modifier/binary/jamming/alive/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos, var/list/crew_data)
crew_data["alert"] = FALSE
return MOD_SUIT_SENSORS_HANDLED

/crew_sensor_modifier/binary/jamming/dead/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos, var/list/crew_data)
/crew_sensor_modifier/binary/jamming/dead/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos, var/list/crew_data)
crew_data["alert"] = TRUE
return MOD_SUIT_SENSORS_HANDLED

Expand All @@ -37,7 +37,7 @@
/crew_sensor_modifier/binary/jamming/random/major
error_prob = 100

/crew_sensor_modifier/binary/jamming/random/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos, var/list/crew_data)
/crew_sensor_modifier/binary/jamming/random/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos, var/list/crew_data)
. = ..()
if(prob(error_prob))
crew_data["alert"] = pick(TRUE, FALSE)
60 changes: 30 additions & 30 deletions code/datums/repositories/crew/crew.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ var/global/datum/repository/crew/crew_repository = new()
tracking_modifiers.Enqueue(new/crew_sensor_modifier/tracking())

modifier_queues = list()
modifier_queues[general_modifiers] = 0
modifier_queues[binary_modifiers] = SUIT_SENSOR_BINARY
modifier_queues[vital_modifiers] = SUIT_SENSOR_VITAL
modifier_queues[tracking_modifiers] = SUIT_SENSOR_TRACKING
modifier_queues[general_modifiers] = VITALS_SENSOR_OFF
modifier_queues[binary_modifiers] = VITALS_SENSOR_BINARY
modifier_queues[vital_modifiers] = VITALS_SENSOR_VITAL
modifier_queues[tracking_modifiers] = VITALS_SENSOR_TRACKING

modifier_queues_by_type = list()
modifier_queues_by_type[/crew_sensor_modifier/general] = general_modifiers
Expand All @@ -49,19 +49,21 @@ var/global/datum/repository/crew/crew_repository = new()

cache_data_alert[num2text(z_level)] = FALSE
var/tracked = scan()
for(var/obj/item/clothing/under/C in tracked)
var/turf/pos = get_turf(C)
if(C.has_sensor && pos && pos.z == z_level && C.sensor_mode != SUIT_SENSOR_OFF)
if(ishuman(C.loc))
var/mob/living/carbon/human/H = C.loc
if(H.get_equipped_item(slot_w_uniform_str) != C)
continue

var/list/crewmemberData = list("sensor_type"=C.sensor_mode, "stat"=H.stat, "area"="", "x"=-1, "y"=-1, "z"=-1, "ref"="\ref[H]")
if(!(run_queues(H, C, pos, crewmemberData) & MOD_SUIT_SENSORS_REJECTED))
crewmembers[++crewmembers.len] = crewmemberData
if (crewmemberData["alert"])
cache_data_alert[num2text(z_level)] = TRUE
for(var/obj/item/clothing/accessory/vitals_sensor/sensor as anything in tracked)
var/turf/pos = get_turf(sensor)
if(!pos || pos.z != z_level || sensor.sensor_mode == VITALS_SENSOR_OFF)
continue
var/mob/living/carbon/human/H = sensor.loc?.loc
if(!istype(H))
continue
var/obj/item/clothing/uniform = H.get_equipped_item(slot_w_uniform_str)
if(!istype(uniform) || !(sensor in uniform.accessories))
continue
var/list/crewmemberData = list("sensor_type" = sensor.sensor_mode, "stat"=H.stat, "area"="", "x"=-1, "y"=-1, "z"=-1, "ref"="\ref[H]")
if(!(run_queues(H, sensor, pos, crewmemberData) & MOD_SUIT_SENSORS_REJECTED))
crewmembers[++crewmembers.len] = crewmemberData
if (crewmemberData["alert"])
cache_data_alert[num2text(z_level)] = TRUE

crewmembers = sortTim(crewmembers, /proc/cmp_list_name_key_asc)

Expand All @@ -80,39 +82,37 @@ var/global/datum/repository/crew/crew_repository = new()
. = cache_data_alert[num2text(z_level)]

/datum/repository/crew/proc/scan()
var/list/tracked = list()
for(var/mob/living/carbon/human/H in SSmobs.mob_list)
var/obj/item/clothing/under/C = H.get_equipped_item(slot_w_uniform_str)
if(istype(C) && C.has_sensor)
tracked |= C
return tracked
var/sensor = H.get_vitals_sensor()
if(sensor)
LAZYDISTINCTADD(., sensor)

/datum/repository/crew/proc/run_queues(H, C, pos, crewmemberData)
/datum/repository/crew/proc/run_queues(H, S, pos, crewmemberData)
for(var/modifier_queue in modifier_queues)
if(crewmemberData["sensor_type"] >= modifier_queues[modifier_queue])
. = process_crew_data(modifier_queue, H, C, pos, crewmemberData)
. = process_crew_data(modifier_queue, H, S, pos, crewmemberData)
if(. & MOD_SUIT_SENSORS_REJECTED)
return

/datum/repository/crew/proc/process_crew_data(var/datum/priority_queue/modifiers, var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos, var/list/crew_data)
/datum/repository/crew/proc/process_crew_data(var/datum/priority_queue/modifiers, var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos, var/list/crew_data)
var/current_priority = INFINITY
var/list/modifiers_of_this_priority = list()

for(var/crew_sensor_modifier/csm in modifiers.L)
if(csm.priority < current_priority)
. = check_queue(modifiers_of_this_priority, H, C, pos, crew_data)
. = check_queue(modifiers_of_this_priority, H, S, pos, crew_data)
if(. != MOD_SUIT_SENSORS_NONE)
return
current_priority = csm.priority
modifiers_of_this_priority += csm
return check_queue(modifiers_of_this_priority, H, C, pos, crew_data)
return check_queue(modifiers_of_this_priority, H, S, pos, crew_data)

/datum/repository/crew/proc/check_queue(var/list/modifiers_of_this_priority, H, C, pos, crew_data)
/datum/repository/crew/proc/check_queue(var/list/modifiers_of_this_priority, H, S, pos, crew_data)
while(modifiers_of_this_priority.len)
var/crew_sensor_modifier/pcsm = pick(modifiers_of_this_priority)
modifiers_of_this_priority -= pcsm
if(pcsm.may_process_crew_data(H, C, pos))
. = pcsm.process_crew_data(H, C, pos, crew_data)
if(pcsm.may_process_crew_data(H, S, pos))
. = pcsm.process_crew_data(H, S, pos, crew_data)
if(. != MOD_SUIT_SENSORS_NONE)
return
return MOD_SUIT_SENSORS_NONE
Expand Down
6 changes: 3 additions & 3 deletions code/datums/repositories/crew/crew_sensor_modifier.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
may_process_proc = null
. = ..()

/crew_sensor_modifier/proc/may_process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos)
return holder && may_process_proc ? call(holder, may_process_proc)(H, C, pos) : TRUE
/crew_sensor_modifier/proc/may_process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos)
return holder && may_process_proc ? call(holder, may_process_proc)(H, S, pos) : TRUE

/crew_sensor_modifier/proc/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/under/C, var/turf/pos, var/list/crew_data)
/crew_sensor_modifier/proc/process_crew_data(var/mob/living/carbon/human/H, var/obj/item/clothing/accessory/vitals_sensor/S, var/turf/pos, var/list/crew_data)
return MOD_SUIT_SENSORS_HANDLED
Loading

0 comments on commit f86861b

Please sign in to comment.