refactors radios to use proximity (#25303)

* refactors radios to use proximity

* Apply suggestions from code review

Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>

---------

Signed-off-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
This commit is contained in:
GDN
2024-05-21 19:17:26 -05:00
committed by GitHub
parent 8f2bcdba85
commit 06db6bc004
6 changed files with 85 additions and 49 deletions
@@ -60,6 +60,8 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
var/obj/item/encryptionkey/syndicate/syndiekey = null
/// How many times this is disabled by EMPs
var/disable_timer = 0
/// List of all the mobs that can hear this radio
var/list/listeners = list()
/// Areas in which this radio cannot send messages
var/static/list/blacklisted_areas = list(/area/adminconstruction, /area/tdome, /area/ruin/space/bubblegum_arena)
@@ -82,7 +84,6 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
var/requires_tcomms = FALSE // Does this device require tcomms to work.If TRUE it wont function at all without tcomms. If FALSE, it will work without tcomms, just slowly
var/instant = FALSE // Should this device instantly communicate if there isnt tcomms
/obj/item/radio/proc/set_frequency(new_frequency)
SSradio.remove_object(src, frequency)
frequency = new_frequency
@@ -97,6 +98,7 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
/obj/item/radio/Destroy()
SStgui.close_uis(wires)
listeners.Cut()
QDEL_NULL(wires)
if(SSradio)
SSradio.remove_object(src, frequency)
@@ -107,7 +109,6 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
follow_target = null
return ..()
/obj/item/radio/Initialize()
..()
if(frequency < RADIO_LOW_FREQ || frequency > RADIO_HIGH_FREQ)
@@ -116,6 +117,31 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
for(var/ch_name in channels)
secure_radio_connections[ch_name] = SSradio.add_object(src, SSradio.radiochannels[ch_name], RADIO_CHAT)
if(canhear_range)
AddComponent(/datum/component/proximity_monitor, canhear_range)
/obj/item/radio/HasProximity(mob/crosser)
if(!istype(crosser) || (crosser in listeners))
return
listeners += crosser
RegisterSignal(crosser, COMSIG_MOVABLE_MOVED, PROC_REF(is_crosser_still_listening))
RegisterSignal(crosser, COMSIG_PARENT_QDELETING, PROC_REF(remove_from_listener_list))
/obj/item/radio/proc/is_crosser_still_listening(mob/crosser)
SIGNAL_HANDLER // COMSIG_MOVABLE_MOVED
var/still_listening = FALSE
for(var/obj/effect/abstract/proximity_checker/checker in get_turf(crosser))
if(checker.monitor.hasprox_receiver == src)
still_listening = TRUE
break
if(still_listening)
return
remove_from_listener_list(crosser)
/obj/item/radio/proc/remove_from_listener_list(mob/crosser)
SIGNAL_HANDLER // COMSIG_PARENT_QDELETING
listeners -= crosser
UnregisterSignal(crosser, list(COMSIG_PARENT_QDELETING, COMSIG_MOVABLE_MOVED))
/obj/item/radio/attack_ghost(mob/user)
return interact(user)
@@ -210,14 +236,26 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
if(has_loudspeaker)
loudspeaker = !loudspeaker
if(loudspeaker)
canhear_range = 3
update_hear_range(3)
else
canhear_range = 0
update_hear_range(0)
else
. = FALSE
if(.)
add_fingerprint(usr)
/obj/item/radio/proc/update_hear_range(new_hear_range)
canhear_range = new_hear_range
var/datum/component/proximity_monitor/our_prox_component = GetComponent(/datum/component/proximity_monitor)
if(!canhear_range)
QDEL_NULL(our_prox_component)
return
if(our_prox_component)
our_prox_component.set_radius(canhear_range)
else
AddComponent(/datum/component/proximity_monitor, canhear_range)
/obj/item/radio/proc/list_secure_channels(mob/user)
var/list/dat = list()
for(var/channel in channels)
@@ -538,9 +576,7 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
/obj/item/radio/proc/send_announcement()
if(is_listening())
return get_mobs_in_view(canhear_range, src)
return null
return listeners
/obj/item/radio/examine(mob/user)
. = ..()
@@ -808,3 +844,16 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
return
return M.say_dead(message)
GLOBAL_DATUM_INIT(deadchat_radio, /obj/item/radio/dchat_radio_handler, new())
/obj/item/radio/dchat_radio_handler
name = "Deadchat radio handler. Do not fuck with"
canhear_range = 0
/obj/item/radio/dchat_radio_handler/Destroy(force)
. = ..()
stack_trace("Someone just tried to delete the deadchat handler!")
if(!force)
return QDEL_HINT_LETMELIVE
return ..()