mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
Request Emergency Temporary Access - RETA (#92753)
<img width="819" height="348" alt="image" src="https://github.com/user-attachments/assets/0424ec76-2648-43d3-8e94-d44558b44bcf" /> ## About The Pull Request Follow up from #92751 - Not to conflict with it but as an idea on how to change it for the long run. Paramedics currently start with broad department access. This proposal replaces that by granting temporary department access only when an emergency is called. When a player presses "Call X" on a Requests Console, responders called receive temporary access to the common work areas of that department.  > [Security] The Automated Announcement System coldly states, "SECURITY EMERGENCY in Research Lab! (Called by Sloan Keppel, Scientist) RETA door access granted to responders." > [Science] The Automated Announcement System coldly states, "RETA activated (Called by Sloan Keppel, Scientist). Security personnel now have temporary access to your areas." They do not receive access to sub rooms or high risk areas. - Access lasts 5 minutes (configurable) - Access is removed when the timer expires or the emergency is resolved - No mapping changes are required (uses existing request consoles) - Removes Paramedics round start access but gives them external access to rescue bodies in space by default - Flashing blue lights on doors affected by temporary access <img width="897" height="837" alt="image" src="https://github.com/user-attachments/assets/97980cb4-3481-44b6-9f96-fc241ca16f57" /> **The full document is here: https://hackmd.io/@NM8HxpG_Toahg5pimrpsKw/Hk0tKq3Yxe** **Wiki documentation for players and admins: https://wiki.tgstation13.org/Guide_To_RETA** ## Why It's Good For The Game - Removes paramedics’ broad “Doctor+” access. - Keeps them effective as emergency responders. - Responders must be called in OR access upgraded. - Keeps sensitive areas secure. - Prevents spam or stacking through cooldown. - Scales across all maps without mapper work. - Gives admins a new tool for temp department wide access - Dedicated logging file and unit tests - Very performant, only affects living players with connected mind - Gives Request Consoles more use as an alarm button and further utility - Imagine later on "Request Janitor" which sorts access and tells Janitor where needed ## Changelog 🆑 add: RETA System - Request Consoles give temporary access to responders when used for some areas. Paramedics lose broad access but get external space access. qol: Request consoles now show name and job role on call message & Cooldown on spamming calls + sound prompt qol: Medibot access no longer based on Paramedic trim ID - Still has original access image: Added "lights_reta" for temporary door access when in effect admin: Gives admins "RETA door access" verb for giving department wide area access on maps. config: New config settings for RETA /🆑
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Request Emergency Temporary Access - Admin Verbs
|
||||
*/
|
||||
|
||||
/// Admin command to manually trigger RETA access grant for admins
|
||||
ADMIN_VERB(reta_manual_trigger, R_ADMIN, "RETA Door Access", "Manually trigger RETA access for testing", ADMIN_CATEGORY_EVENTS)
|
||||
|
||||
var/calling_dept = tgui_input_list(user, "RETA - Which department is CALLING for help?", "Calling Department", list("Security", "Engineering", "Medical", "Science", "Service", "Command", "Cargo", "Mining"))
|
||||
if(!calling_dept)
|
||||
return
|
||||
|
||||
var/list/available_depts = list("Security", "Engineering", "Medical", "Science", "Service", "Command", "Cargo", "Mining")
|
||||
available_depts -= calling_dept
|
||||
|
||||
// Multi-select using repeated input_list calls
|
||||
var/list/selected_depts = list()
|
||||
var/list/remaining_depts = available_depts.Copy()
|
||||
|
||||
while(length(remaining_depts))
|
||||
remaining_depts += "DONE - Finish selection"
|
||||
var/choice = tgui_input_list(user, "RETA - Select departments to RESPOND to [calling_dept]\nCurrently selected: [english_list(selected_depts)]\n\nSelect another department or DONE:", "Responding Departments", remaining_depts)
|
||||
|
||||
if(!choice || choice == "DONE - Finish selection")
|
||||
break
|
||||
|
||||
selected_depts += choice
|
||||
remaining_depts -= choice
|
||||
remaining_depts -= "DONE - Finish selection"
|
||||
|
||||
if(!length(selected_depts))
|
||||
message_admins("No departments selected for RETA response.")
|
||||
return
|
||||
|
||||
var/duration = tgui_input_number(user, "Duration in minutes:", "RETA Duration", 5, 60, 1)
|
||||
if(!duration)
|
||||
return
|
||||
|
||||
message_admins("[key_name_admin(user)] is manually triggering RETA: [calling_dept] called for help, [english_list(selected_depts)] will get access to [calling_dept] areas for [duration] minutes.")
|
||||
log_game("ADMIN: [key_name(user)] is manually triggering RETA: [calling_dept] called for help, [english_list(selected_depts)] will get access to [calling_dept] areas for [duration] minutes.")
|
||||
|
||||
// Grant access to each responding department and collect results
|
||||
var/successful_grants = 0
|
||||
var/list/granted_depts = list()
|
||||
var/total_eligible_cards = 0
|
||||
|
||||
for(var/responding_dept in selected_depts)
|
||||
var/dept_eligible_cards = 0
|
||||
var/list/job_trims = GLOB.reta_job_trims[responding_dept]
|
||||
|
||||
for(var/mob/living/carbon/human/human_player as anything in GLOB.human_list)
|
||||
if(!human_player.client || human_player.stat == DEAD)
|
||||
continue
|
||||
|
||||
var/obj/item/card/id/id_card = human_player.get_idcard(hand_first = FALSE)
|
||||
if(!id_card || !id_card.trim)
|
||||
continue
|
||||
|
||||
if(is_type_in_list(id_card.trim, job_trims))
|
||||
dept_eligible_cards++
|
||||
|
||||
total_eligible_cards += dept_eligible_cards
|
||||
message_admins("[responding_dept] department: [dept_eligible_cards] eligible cards from living players")
|
||||
|
||||
// Note: RETA grants access FROM calling_dept TO responding_dept personnel
|
||||
// So if Medical calls Security, Security personnel get Medical access
|
||||
if(reta_find_and_grant_access(responding_dept, calling_dept, duration MINUTES))
|
||||
successful_grants++
|
||||
granted_depts += responding_dept
|
||||
|
||||
// Report results
|
||||
if(successful_grants > 0)
|
||||
message_admins("RETA access granted successfully: [english_list(granted_depts)] personnel now have [calling_dept] access. Total eligible cards: [total_eligible_cards]")
|
||||
|
||||
// Send department announcement like the normal system
|
||||
var/caller_info = " (Called by CENTCOM)"
|
||||
var/enhanced_location = "[calling_dept][caller_info]"
|
||||
|
||||
// Send announcements to all successfully granted departments
|
||||
for(var/dept in granted_depts)
|
||||
switch(dept)
|
||||
if("Security")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_SECURITY), "Security")
|
||||
if("Engineering")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_ENGINEERING), "Engineering")
|
||||
if("Medical")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_MEDICAL), "Medical")
|
||||
if("Science")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_SCIENCE), "Science")
|
||||
if("Service")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_SERVICE), "Service")
|
||||
if("Command")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_COMMAND), "Command")
|
||||
if("Cargo")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_SUPPLY), "Cargo")
|
||||
if("Mining")
|
||||
aas_config_announce(/datum/aas_config_entry/rc_emergency, list("LOCATION" = enhanced_location), null, list(RADIO_CHANNEL_SUPPLY), "Mining")
|
||||
|
||||
// Send confirmation to the calling department about who has been given access
|
||||
var/calling_message = "RETA activated[caller_info]. The following now have temporary door access: [english_list(granted_depts)]."
|
||||
|
||||
// Get an announcement system to send simple radio messages
|
||||
var/obj/machinery/announcement_system/announcer = get_announcement_system(null, null, list(RADIO_CHANNEL_COMMON))
|
||||
if(announcer)
|
||||
switch(calling_dept)
|
||||
if("Security")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_SECURITY)
|
||||
if("Engineering")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_ENGINEERING)
|
||||
if("Medical")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_MEDICAL)
|
||||
if("Science")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_SCIENCE)
|
||||
if("Service")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_SERVICE)
|
||||
if("Command")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_COMMAND)
|
||||
if("Cargo")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_SUPPLY)
|
||||
if("Mining")
|
||||
announcer.radio.talk_into(announcer, calling_message, RADIO_CHANNEL_SUPPLY)
|
||||
else
|
||||
message_admins("RETA access grant failed for all departments.")
|
||||
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* Request Emergency Temporary Access - ID Card Extensions
|
||||
* code\modules\reta\reta_system.dm
|
||||
*/
|
||||
|
||||
/obj/item/card/id
|
||||
/// Dictionary of temporary department access: dept_name -> list(access_flags)
|
||||
var/list/reta_temp_access = list()
|
||||
/// Dictionary of timer IDs for clearing temporary access: dept_name -> timer_id
|
||||
var/list/reta_timers = list()
|
||||
|
||||
/// Grants temporary department access to this ID card
|
||||
/obj/item/card/id/proc/grant_reta_access(dept, duration_ds)
|
||||
if(!GLOB.reta_dept_grants[dept])
|
||||
return FALSE
|
||||
|
||||
// Clear existing timer for this department if any (allows extending/refreshing access)
|
||||
if(reta_timers[dept] && reta_timers[dept] != -1)
|
||||
deltimer(reta_timers[dept])
|
||||
reta_timers[dept] = null
|
||||
|
||||
// Grant access flags for this department
|
||||
var/list/access_flags = GLOB.reta_dept_grants[dept]
|
||||
var/list/new_access = list()
|
||||
|
||||
// Initialize department access list if needed
|
||||
if(!reta_temp_access[dept])
|
||||
reta_temp_access[dept] = list()
|
||||
|
||||
for(var/flag in access_flags)
|
||||
if(!(flag in access)) // Only add if not permanently granted
|
||||
// Add to department-specific temporary access
|
||||
reta_temp_access[dept] |= flag
|
||||
// Add to main access list
|
||||
access += flag
|
||||
new_access += flag
|
||||
|
||||
if(!LAZYLEN(new_access))
|
||||
return FALSE // No new access granted
|
||||
|
||||
// Set timer for this specific department
|
||||
reta_timers[dept] = addtimer(CALLBACK(src, PROC_REF(clear_reta_access_for_dept), dept), duration_ds, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE)
|
||||
|
||||
// Add to global registry for mass operations
|
||||
GLOB.reta_active_cards |= src
|
||||
|
||||
// User feedback
|
||||
var/mob/living/carbon/human/holder = get_id_holder()
|
||||
if(holder)
|
||||
playsound(holder, 'sound/machines/cryo_warning.ogg', 25, TRUE)
|
||||
holder.balloon_alert(holder, "emergency access: [dept]")
|
||||
|
||||
// Enhanced logging
|
||||
var/access_names = list()
|
||||
for(var/flag in new_access)
|
||||
access_names += SSid_access.get_access_desc(flag)
|
||||
|
||||
var/holder_info = holder ? "held by [holder]" : "not being held"
|
||||
log_reta("Granted [dept] temporary access ([english_list(access_names)]) to ID '[registered_name || "Unknown"]' ([holder_info]) for [duration_ds/10] seconds")
|
||||
investigate_log("RETA: Granted [dept] temporary access ([english_list(access_names)]) to ID '[registered_name || "Unknown"]' ([holder_info])", INVESTIGATE_ACCESSCHANGES)
|
||||
|
||||
return TRUE
|
||||
|
||||
/// Clears temporary access for a specific department
|
||||
/obj/item/card/id/proc/clear_reta_access_for_dept(dept)
|
||||
if(!reta_temp_access[dept] || !LAZYLEN(reta_temp_access[dept]))
|
||||
return
|
||||
|
||||
// User feedback before clearing
|
||||
var/mob/living/carbon/human/holder = get_id_holder()
|
||||
if(holder)
|
||||
holder.balloon_alert(holder, "[dept] access expired")
|
||||
to_chat(holder, span_warning("Emergency access to [dept] has expired."))
|
||||
|
||||
// Remove department's temporary access from the main access list
|
||||
var/list/dept_access = reta_temp_access[dept]
|
||||
for(var/flag in dept_access)
|
||||
// Only remove if no other department also grants this access
|
||||
var/still_needed = FALSE
|
||||
for(var/other_dept in reta_temp_access)
|
||||
if(other_dept != dept && reta_temp_access[other_dept] && (flag in reta_temp_access[other_dept]))
|
||||
still_needed = TRUE
|
||||
break
|
||||
|
||||
if(!still_needed)
|
||||
access -= flag
|
||||
|
||||
// Enhanced logging
|
||||
var/access_names = list()
|
||||
for(var/flag in dept_access)
|
||||
access_names += SSid_access.get_access_desc(flag)
|
||||
|
||||
var/holder_info = holder ? "held by [holder]" : "not being held"
|
||||
log_reta("Cleared [dept] temporary access ([english_list(access_names)]) from ID '[registered_name || "Unknown"]' ([holder_info])")
|
||||
investigate_log("RETA: Cleared [dept] temporary access ([english_list(access_names)]) from ID '[registered_name || "Unknown"]' ([holder_info])", INVESTIGATE_ACCESSCHANGES)
|
||||
|
||||
// Clean up department data
|
||||
reta_temp_access[dept] = null
|
||||
reta_timers[dept] = null
|
||||
|
||||
// Remove from global registry if no more temporary access
|
||||
if(!has_any_reta_access())
|
||||
GLOB.reta_active_cards -= src
|
||||
|
||||
/// Clears all temporary department access from this ID card
|
||||
/obj/item/card/id/proc/clear_reta_access()
|
||||
if(!LAZYLEN(reta_temp_access))
|
||||
return
|
||||
|
||||
// User feedback before clearing
|
||||
var/mob/living/carbon/human/holder = get_id_holder()
|
||||
if(holder)
|
||||
holder.balloon_alert(holder, "emergency access expired")
|
||||
to_chat(holder, span_warning("Emergency access has expired."))
|
||||
|
||||
// Collect all temporary access flags for logging
|
||||
var/list/all_temp_access = list()
|
||||
for(var/dept in reta_temp_access)
|
||||
if(reta_temp_access[dept])
|
||||
all_temp_access |= reta_temp_access[dept]
|
||||
|
||||
// Remove all temporary access from the main access list
|
||||
for(var/flag in all_temp_access)
|
||||
access -= flag
|
||||
|
||||
// Enhanced logging
|
||||
var/access_names = list()
|
||||
for(var/flag in all_temp_access)
|
||||
access_names += SSid_access.get_access_desc(flag)
|
||||
|
||||
var/holder_info = holder ? "held by [holder]" : "not being held"
|
||||
log_reta("Cleared all temporary access ([english_list(access_names)]) from ID '[registered_name || "Unknown"]' ([holder_info])")
|
||||
investigate_log("RETA: Cleared all temporary access ([english_list(access_names)]) from ID '[registered_name || "Unknown"]' ([holder_info])", INVESTIGATE_ACCESSCHANGES)
|
||||
|
||||
// Clear all timers
|
||||
for(var/dept in reta_timers)
|
||||
if(reta_timers[dept] && reta_timers[dept] != -1)
|
||||
deltimer(reta_timers[dept])
|
||||
|
||||
LAZYCLEARLIST(reta_temp_access)
|
||||
LAZYCLEARLIST(reta_timers)
|
||||
|
||||
// Remove from global registry
|
||||
GLOB.reta_active_cards -= src
|
||||
|
||||
/// Checks if this ID card has any temporary access
|
||||
/obj/item/card/id/proc/has_any_reta_access()
|
||||
for(var/dept in reta_temp_access)
|
||||
if(reta_temp_access[dept] && LAZYLEN(reta_temp_access[dept]))
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/// Checks if this ID card has temporary access to a specific flag
|
||||
/obj/item/card/id/proc/has_reta_access(access_flag)
|
||||
for(var/dept in reta_temp_access)
|
||||
if(reta_temp_access[dept] && (access_flag in reta_temp_access[dept]))
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/// Checks if this ID card has temporary access for a specific department
|
||||
/obj/item/card/id/proc/has_reta_access_for_dept(dept)
|
||||
return reta_temp_access[dept] && LAZYLEN(reta_temp_access[dept])
|
||||
|
||||
/// Gets all current temporary access flags for this ID card
|
||||
/obj/item/card/id/proc/get_reta_access()
|
||||
var/list/all_access = list()
|
||||
for(var/dept in reta_temp_access)
|
||||
if(reta_temp_access[dept])
|
||||
all_access |= reta_temp_access[dept]
|
||||
return all_access
|
||||
|
||||
/// Gets temporary access flags for a specific department
|
||||
/obj/item/card/id/proc/get_reta_access_for_dept(dept)
|
||||
var/list/dept_access = reta_temp_access[dept]
|
||||
return dept_access?.Copy() || list()
|
||||
|
||||
/// Gets a summary of all active RETA accesses (for debugging/display)
|
||||
/obj/item/card/id/proc/get_reta_summary()
|
||||
var/list/summary = list()
|
||||
for(var/dept in reta_temp_access)
|
||||
if(reta_temp_access[dept] && LAZYLEN(reta_temp_access[dept]))
|
||||
var/time_left = "unknown"
|
||||
if(reta_timers[dept])
|
||||
var/remaining = timeleft(reta_timers[dept])
|
||||
if(remaining > 0)
|
||||
time_left = "[remaining/10]s"
|
||||
summary += "[dept] ([LAZYLEN(reta_temp_access[dept])] access, [time_left] left)"
|
||||
return summary
|
||||
|
||||
/// Helper to get the human holding this ID card
|
||||
/obj/item/card/id/proc/get_id_holder()
|
||||
var/mob/living/carbon/human/holder
|
||||
if(istype(loc, /mob/living/carbon/human))
|
||||
holder = loc
|
||||
else if(istype(loc, /obj/item/card/id) && istype(loc.loc, /mob/living/carbon/human))
|
||||
holder = loc.loc
|
||||
else
|
||||
// Check if worn in ID slot
|
||||
for(var/mob/living/carbon/human/human in range(0, src))
|
||||
if(human.get_idcard() == src)
|
||||
holder = human
|
||||
break
|
||||
return holder
|
||||
|
||||
/// Cleanup temporary access when ID card is deleted
|
||||
/obj/item/card/id/Destroy()
|
||||
// Clear all department timers
|
||||
for(var/dept in reta_timers)
|
||||
if(reta_timers[dept] && reta_timers[dept] != -1)
|
||||
deltimer(reta_timers[dept])
|
||||
GLOB.reta_active_cards -= src
|
||||
return ..()
|
||||
/*
|
||||
/mob/living/death(gibbed)
|
||||
. = ..()
|
||||
clear_temp_dept_access()
|
||||
*/
|
||||
@@ -0,0 +1,319 @@
|
||||
/**
|
||||
* Request Emergency Temporary Access - RETA System
|
||||
* Provides temporary department access when Requests Console emergency calls are made.
|
||||
*/
|
||||
|
||||
/// Helper function for RETA-specific logging
|
||||
/proc/log_reta(text)
|
||||
WRITE_LOG(GLOB.reta_log, "[time_stamp()] RETA: [text]")
|
||||
log_game("RETA: [text]")
|
||||
|
||||
/proc/initialize_reta_system()
|
||||
// Define which access flags are granted for each department
|
||||
GLOB.reta_dept_grants = list(
|
||||
"Medical" = list(ACCESS_MEDICAL, ACCESS_SURGERY),
|
||||
"Security" = list(ACCESS_SECURITY, ACCESS_BRIG, ACCESS_BRIG_ENTRANCE),
|
||||
"Engineering" = list(ACCESS_ENGINEERING, ACCESS_ATMOSPHERICS),
|
||||
"Science" = list(ACCESS_SCIENCE, ACCESS_RESEARCH),
|
||||
"Service" = list(ACCESS_SERVICE, ACCESS_BAR, ACCESS_KITCHEN, ACCESS_HYDROPONICS),
|
||||
"Cargo" = list(ACCESS_CARGO),
|
||||
"Mining" = list(ACCESS_MINING, ACCESS_MINING_STATION, ACCESS_CARGO),
|
||||
"Command" = list(ACCESS_COMMAND), // Admin-only, not available through request consoles
|
||||
)
|
||||
|
||||
/// Checks if an origin department is on cooldown for calling a target department
|
||||
/proc/reta_on_cooldown(origin, target)
|
||||
var/list/by_target = GLOB.reta_cooldown[origin]
|
||||
if(!by_target)
|
||||
return FALSE
|
||||
var/next_ok = by_target[target] || 0
|
||||
return world.time < next_ok
|
||||
|
||||
/// Sets a cooldown for an origin department calling a target department
|
||||
/proc/reta_set_cooldown(origin, target, cd_ds)
|
||||
if(!GLOB.reta_cooldown[origin])
|
||||
GLOB.reta_cooldown[origin] = list()
|
||||
GLOB.reta_cooldown[origin][target] = world.time + cd_ds
|
||||
|
||||
/// Tracks recent emergency calls for multiple department analysis
|
||||
/proc/reta_track_call(origin, target)
|
||||
var/list/call_info = list(
|
||||
"time" = world.time,
|
||||
"origin" = origin
|
||||
)
|
||||
|
||||
if(!GLOB.reta_recent_calls[target])
|
||||
GLOB.reta_recent_calls[target] = list()
|
||||
GLOB.reta_recent_calls[target] += list(call_info)
|
||||
|
||||
// Clean old calls (older than 10 minutes)
|
||||
var/cutoff_time = world.time - 6000 // 10 minutes
|
||||
if(GLOB.reta_recent_calls[target])
|
||||
var/list/recent_calls = GLOB.reta_recent_calls[target]
|
||||
GLOB.reta_recent_calls[target] = recent_calls.Copy()
|
||||
for(var/list/old_call in GLOB.reta_recent_calls[target])
|
||||
if(old_call["time"] < cutoff_time)
|
||||
GLOB.reta_recent_calls[target] -= list(old_call)
|
||||
|
||||
// Check for multiple calls scenario
|
||||
if(LAZYLEN(GLOB.reta_recent_calls[target]) >= 3)
|
||||
var/list/origins = list()
|
||||
for(var/list/call_data in GLOB.reta_recent_calls[target])
|
||||
origins |= call_data["origin"]
|
||||
|
||||
if(LAZYLEN(origins) >= 3)
|
||||
message_admins("RETA: Multiple emergency scenario detected! [target] has been called by [english_list(origins)] in the last 10 minutes. Consider station-wide emergency protocols.")
|
||||
log_game("RETA: Multiple department emergency - [target] called by [english_list(origins)]")
|
||||
|
||||
/// Finds eligible responders and grants them temporary access
|
||||
/proc/reta_find_and_grant_access(target_dept, origin_dept, duration_ds)
|
||||
. = 0
|
||||
|
||||
var/list/job_trims = GLOB.reta_job_trims[target_dept]
|
||||
if(!LAZYLEN(job_trims))
|
||||
log_reta("No job trims defined for department '[target_dept]'")
|
||||
return FALSE
|
||||
|
||||
var/granted_count = 0
|
||||
var/total_players_checked = 0
|
||||
var/matching_trim_players = 0
|
||||
|
||||
// Check ID cards being carried by living players (fast and efficient)
|
||||
for(var/mob/living/carbon/human/human_player as anything in GLOB.human_list)
|
||||
// Only check players who are alive and have clients (actively playing)
|
||||
if(!human_player.client || human_player.stat == DEAD)
|
||||
continue
|
||||
|
||||
total_players_checked++
|
||||
|
||||
// Get their ID card (worn_id, hands, or belt)
|
||||
var/obj/item/card/id/id_card = human_player.get_idcard(hand_first = FALSE)
|
||||
if(!id_card || !id_card.trim)
|
||||
continue
|
||||
|
||||
// Check if this card's trim matches the target department
|
||||
if(!is_type_in_list(id_card.trim, job_trims))
|
||||
continue
|
||||
|
||||
matching_trim_players++
|
||||
|
||||
if(id_card.grant_reta_access(origin_dept, duration_ds))
|
||||
granted_count++
|
||||
|
||||
if(granted_count > 0)
|
||||
// Register this as an active RETA grant for new cards
|
||||
if(!GLOB.reta_active_grants[target_dept])
|
||||
GLOB.reta_active_grants[target_dept] = list()
|
||||
GLOB.reta_active_grants[target_dept][origin_dept] = world.time + duration_ds
|
||||
|
||||
// Set up automatic cleanup when the grant expires
|
||||
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(cleanup_expired_reta_grant), target_dept, origin_dept), duration_ds)
|
||||
|
||||
// Update all doors to show RETA lights for newly activated grants
|
||||
update_all_doors_reta_lights()
|
||||
|
||||
log_reta("Granted temporary [origin_dept] access to [granted_count] [target_dept] department ID cards from a call by [origin_dept].")
|
||||
. = TRUE
|
||||
else
|
||||
log_reta("No [target_dept] personnel found who needed [origin_dept] access from a call by [origin_dept]. (Checked [total_players_checked] living players, [matching_trim_players] had matching trims)")
|
||||
|
||||
return .
|
||||
|
||||
/// Populates the job trims list for RETA system
|
||||
/proc/populate_reta_job_trims()
|
||||
GLOB.reta_job_trims = list(
|
||||
"Medical" = list(),
|
||||
"Security" = list(),
|
||||
"Engineering" = list(),
|
||||
"Science" = list(),
|
||||
"Service" = list(),
|
||||
"Command" = list(),
|
||||
"Cargo" = list(),
|
||||
"Mining" = list()
|
||||
)
|
||||
|
||||
log_game("RETA: Starting job trim population...")
|
||||
var/total_trims = 0
|
||||
for(var/job_trim_path in subtypesof(/datum/id_trim/job))
|
||||
var/datum/id_trim/job/trim = new job_trim_path()
|
||||
total_trims++
|
||||
|
||||
if(!trim.job)
|
||||
log_game("RETA: Trim [job_trim_path] has no job")
|
||||
continue
|
||||
if(!trim.job.departments_bitflags)
|
||||
log_game("RETA: Trim [job_trim_path] job [trim.job] has no departments_bitflags")
|
||||
continue
|
||||
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_MEDICAL)
|
||||
GLOB.reta_job_trims["Medical"] += job_trim_path
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_SECURITY)
|
||||
GLOB.reta_job_trims["Security"] += job_trim_path
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_ENGINEERING)
|
||||
GLOB.reta_job_trims["Engineering"] += job_trim_path
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_SCIENCE)
|
||||
GLOB.reta_job_trims["Science"] += job_trim_path
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_SERVICE)
|
||||
GLOB.reta_job_trims["Service"] += job_trim_path
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_COMMAND)
|
||||
GLOB.reta_job_trims["Command"] += job_trim_path
|
||||
if(trim.job.departments_bitflags & DEPARTMENT_BITFLAG_CARGO)
|
||||
GLOB.reta_job_trims["Cargo"] += job_trim_path
|
||||
GLOB.reta_job_trims["Mining"] += job_trim_path // Mining uses CARGO bitflag
|
||||
|
||||
log_game("RETA: Processed [total_trims] trims. Final counts: Medical=[LAZYLEN(GLOB.reta_job_trims["Medical"])], Security=[LAZYLEN(GLOB.reta_job_trims["Security"])], Engineering=[LAZYLEN(GLOB.reta_job_trims["Engineering"])], Science=[LAZYLEN(GLOB.reta_job_trims["Science"])], Service=[LAZYLEN(GLOB.reta_job_trims["Service"])], Command=[LAZYLEN(GLOB.reta_job_trims["Command"])], Cargo=[LAZYLEN(GLOB.reta_job_trims["Cargo"])], Mining=[LAZYLEN(GLOB.reta_job_trims["Mining"])]")
|
||||
|
||||
/// Pushes UI updates to all consoles in the same origin department
|
||||
/proc/reta_push_ui_updates(origin, target)
|
||||
for(var/obj/machinery/requests_console/console in GLOB.reta_consoles_by_origin[origin])
|
||||
console.ui_update()
|
||||
|
||||
/// Gets the department string for a user based on their job
|
||||
/proc/reta_get_user_department(mob/user)
|
||||
if(!user?.mind?.assigned_role)
|
||||
return null
|
||||
|
||||
var/datum/job/job = user.mind.assigned_role
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_ENGINEERING)
|
||||
return "Engineering"
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_SCIENCE)
|
||||
return "Science"
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_CARGO)
|
||||
return "Cargo"
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_SERVICE)
|
||||
return "Service"
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_MEDICAL)
|
||||
return "Medical"
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_SECURITY)
|
||||
return "Security"
|
||||
if(job.departments_bitflags & DEPARTMENT_BITFLAG_COMMAND)
|
||||
return "Command"
|
||||
|
||||
return null
|
||||
|
||||
/// Gets the standardized department string from a console department name
|
||||
/proc/reta_get_user_department_by_name(dept_name)
|
||||
if(!dept_name)
|
||||
return null
|
||||
|
||||
var/dept_lower = LOWER_TEXT(dept_name)
|
||||
|
||||
// Check for partial matches to handle variations in console naming
|
||||
if(findtext(dept_lower, "engineering") || findtext(dept_lower, "engine"))
|
||||
return "Engineering"
|
||||
if(findtext(dept_lower, "science") || findtext(dept_lower, "research"))
|
||||
return "Science"
|
||||
if(findtext(dept_lower, "cargo") || findtext(dept_lower, "supply"))
|
||||
return "Cargo"
|
||||
if(findtext(dept_lower, "mining") || findtext(dept_lower, "mine"))
|
||||
return "Mining"
|
||||
if(findtext(dept_lower, "service") || findtext(dept_lower, "civilian"))
|
||||
return "Service"
|
||||
if(findtext(dept_lower, "medical") || findtext(dept_lower, "medbay"))
|
||||
return "Medical"
|
||||
if(findtext(dept_lower, "security") || findtext(dept_lower, "sec"))
|
||||
return "Security"
|
||||
if(findtext(dept_lower, "command") || findtext(dept_lower, "bridge"))
|
||||
return "Command"
|
||||
|
||||
// Autonamed areas that belong to service department
|
||||
if(findtext(dept_lower, "kitchen") || findtext(dept_lower, "bar") || findtext(dept_lower, "cafeteria") || findtext(dept_lower, "diner"))
|
||||
return "Service"
|
||||
if(findtext(dept_lower, "hydroponics") || findtext(dept_lower, "botany"))
|
||||
return "Service"
|
||||
if(findtext(dept_lower, "janitor") || findtext(dept_lower, "custodial"))
|
||||
return "Service"
|
||||
|
||||
// Autonamed areas for medical
|
||||
if(findtext(dept_lower, "pharmacy") || findtext(dept_lower, "chemistry") || findtext(dept_lower, "chem"))
|
||||
return "Medical"
|
||||
if(findtext(dept_lower, "morgue") || findtext(dept_lower, "virology"))
|
||||
return "Medical"
|
||||
if(findtext(dept_lower, "surgery") || findtext(dept_lower, "operating") || findtext(dept_lower, "cryo"))
|
||||
return "Medical"
|
||||
if(findtext(dept_lower, "patients") || findtext(dept_lower, "exam"))
|
||||
return "Medical"
|
||||
|
||||
// Autonamed areas for engineering
|
||||
if(findtext(dept_lower, "atmospherics") || findtext(dept_lower, "atmos"))
|
||||
return "Engineering"
|
||||
if(findtext(dept_lower, "supermatter") || findtext(dept_lower, "engine"))
|
||||
return "Engineering"
|
||||
if(findtext(dept_lower, "gravity") || findtext(dept_lower, "telecomm") || findtext(dept_lower, "tcomm"))
|
||||
return "Engineering"
|
||||
|
||||
// Autonamed areas for science department
|
||||
if(findtext(dept_lower, "xenobiology") || findtext(dept_lower, "xenobio"))
|
||||
return "Science"
|
||||
if(findtext(dept_lower, "robotics") || findtext(dept_lower, "genetics"))
|
||||
return "Science"
|
||||
if(findtext(dept_lower, "ordnance") || findtext(dept_lower, "cytology"))
|
||||
return "Science"
|
||||
|
||||
// Handle specific autonamed areas that belong to security department
|
||||
if(findtext(dept_lower, "brig") || findtext(dept_lower, "holding"))
|
||||
return "Security"
|
||||
if(findtext(dept_lower, "armory") || findtext(dept_lower, "checkpoint"))
|
||||
return "Security"
|
||||
|
||||
return null
|
||||
|
||||
/// Cleans up an expired RETA grant from the active grants registry
|
||||
/proc/cleanup_expired_reta_grant(target_dept, origin_dept)
|
||||
if(!GLOB.reta_active_grants[target_dept])
|
||||
return
|
||||
GLOB.reta_active_grants[target_dept] -= origin_dept
|
||||
if(!length(GLOB.reta_active_grants[target_dept]))
|
||||
GLOB.reta_active_grants -= target_dept
|
||||
log_reta("Cleaned up expired [origin_dept] grant for [target_dept] department")
|
||||
|
||||
// Update all doors to remove RETA lights for expired grants
|
||||
update_all_doors_reta_lights()
|
||||
|
||||
/// Updates RETA lighting for all doors in the game
|
||||
/proc/update_all_doors_reta_lights()
|
||||
for(var/obj/machinery/door/airlock/door as anything in SSmachines.get_machines_by_type_and_subtypes(/obj/machinery/door/airlock))
|
||||
door.update_appearance(UPDATE_OVERLAYS)
|
||||
|
||||
/// Applies any currently active RETA grants to a newly created/spawned ID card
|
||||
/// This should be called when ID cards are created, spawned, or have their trim changed
|
||||
/proc/apply_active_reta_grants_to_card(obj/item/card/id/id_card)
|
||||
if(!id_card || !id_card.trim)
|
||||
return
|
||||
|
||||
// If no active grants, nothing to do (prevents spam during round start)
|
||||
if(!LAZYLEN(GLOB.reta_active_grants))
|
||||
return
|
||||
|
||||
// Check if this card's department has any active incoming RETA grants
|
||||
for(var/target_dept in GLOB.reta_active_grants)
|
||||
var/list/job_trims = GLOB.reta_job_trims[target_dept]
|
||||
if(!LAZYLEN(job_trims))
|
||||
continue
|
||||
|
||||
// Check if this card's trim matches the target department
|
||||
if(!is_type_in_list(id_card.trim, job_trims))
|
||||
continue
|
||||
|
||||
log_reta("Card trim [id_card.trim] matches [target_dept] department - applying active grants")
|
||||
|
||||
// Apply all active grants for this department
|
||||
for(var/origin_dept in GLOB.reta_active_grants[target_dept])
|
||||
var/expiry_time = GLOB.reta_active_grants[target_dept][origin_dept]
|
||||
if(world.time >= expiry_time)
|
||||
continue // Grant expired, skip it
|
||||
|
||||
var/remaining_time = expiry_time - world.time
|
||||
if(id_card.grant_reta_access(origin_dept, remaining_time))
|
||||
log_reta("Auto-granted [origin_dept] access to newly created [id_card] ([target_dept] department)")
|
||||
|
||||
// Default config values
|
||||
#define RETA_DEFAULT_DURATION_DS 3000 // 5 minutes
|
||||
#define RETA_DEFAULT_COOLDOWN_DS 150 // 15 seconds
|
||||
|
||||
/// Initialize RETA config values
|
||||
/proc/reta_init_config()
|
||||
log_world("RETA: System initialized with duration=[CONFIG_GET(number/reta_duration_ds)]ds, cooldown=[CONFIG_GET(number/reta_dept_cooldown_ds)]ds, enabled=[CONFIG_GET(flag/reta_enabled)]")
|
||||
|
||||
#undef RETA_DEFAULT_DURATION_DS
|
||||
#undef RETA_DEFAULT_COOLDOWN_DS
|
||||
Reference in New Issue
Block a user