mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-23 08:31:57 +00:00
* Initial * Cleared duplicates * More work, get rid of log_error * more * log_debug() to macro LOG_DEBUG * More work * More * Guh * Maybe better? * More work * gah * Dear lord * *inserts swears here* * gdi * More work * More * dear lord * fsdfsdafs * rsdaf * sadfasf * sdafsad * fgsd * small fuckup fix * jfsd * sdafasf * gdi * sdfa * sfdafgds * sdafasdvf * sdfasdfg * sdfsga * asdf * dsfasfsagf * ihibhbjh * fsadf * adfas * sdafsad * sdfasd * fsda * vhb * asf * for arrow * removed source file-line logging, added header for tgui
60 lines
1.9 KiB
Plaintext
60 lines
1.9 KiB
Plaintext
/datum/radio_frequency
|
|
var/frequency as num
|
|
var/list/list/obj/devices = list()
|
|
|
|
/datum/radio_frequency/proc/post_signal(obj/source, datum/signal/signal, filter = null, range = null)
|
|
var/turf/start_point
|
|
if(range)
|
|
start_point = get_turf(source)
|
|
if(!start_point)
|
|
qdel(signal)
|
|
return 0
|
|
if (filter)
|
|
send_to_filter(source, signal, filter, start_point, range)
|
|
send_to_filter(source, signal, RADIO_DEFAULT, start_point, range)
|
|
else
|
|
//Broadcast the signal to everyone!
|
|
for (var/next_filter in devices)
|
|
send_to_filter(source, signal, next_filter, start_point, range)
|
|
|
|
//Sends a signal to all machines belonging to a given filter. Should be called by post_signal()
|
|
/datum/radio_frequency/proc/send_to_filter(obj/source, datum/signal/signal, filter, turf/start_point = null, range = null)
|
|
if (range && !start_point)
|
|
return
|
|
|
|
for(var/obj/device in devices[filter])
|
|
if(device == source)
|
|
continue
|
|
if(range)
|
|
var/turf/end_point = get_turf(device)
|
|
if(!end_point)
|
|
continue
|
|
if(start_point.z != end_point.z || get_dist(start_point, end_point) > range)
|
|
continue
|
|
|
|
device.receive_signal(signal, TRANSMISSION_RADIO, frequency)
|
|
|
|
/datum/radio_frequency/proc/add_listener(obj/device, filter)
|
|
if (!filter)
|
|
filter = RADIO_DEFAULT
|
|
//LOG_DEBUG("add_listener(device=[device],filter=[filter]) frequency=[frequency]")
|
|
var/list/obj/devices_line = devices[filter]
|
|
if (!devices_line)
|
|
devices_line = new
|
|
devices[filter] = devices_line
|
|
devices_line |= device
|
|
// var/list/obj/devices_line___ = devices[filter_str]
|
|
// var/l = devices_line___.len
|
|
//LOG_DEBUG("DEBUG: devices_line.len=[devices_line.len]")
|
|
//LOG_DEBUG("DEBUG: devices(filter_str).len=[l]")
|
|
|
|
/datum/radio_frequency/proc/remove_listener(obj/device)
|
|
for (var/devices_filter in devices)
|
|
var/list/devices_line = devices[devices_filter]
|
|
devices_line-=device
|
|
while (null in devices_line)
|
|
devices_line -= null
|
|
if (devices_line.len==0)
|
|
devices -= devices_filter
|
|
del(devices_line)
|