mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
Merge pull request #6019 from mwerezak/radio
Fixes machines being able to put the Radio Controller to sleep + Radio Controller cleanup
This commit is contained in:
@@ -1,307 +1,294 @@
|
||||
/*
|
||||
HOW IT WORKS
|
||||
|
||||
The radio_controller is a global object maintaining all radio transmissions, think about it as about "ether".
|
||||
Note that walkie-talkie, intercoms and headsets handle transmission using nonstandard way.
|
||||
procs:
|
||||
|
||||
add_object(obj/device as obj, var/new_frequency as num, var/filter as text|null = null)
|
||||
Adds listening object.
|
||||
parameters:
|
||||
device - device receiving signals, must have proc receive_signal (see description below).
|
||||
one device may listen several frequencies, but not same frequency twice.
|
||||
new_frequency - see possibly frequencies below;
|
||||
filter - thing for optimization. Optional, but recommended.
|
||||
All filters should be consolidated in this file, see defines later.
|
||||
Device without listening filter will receive all signals (on specified frequency).
|
||||
Device with filter will receive any signals sent without filter.
|
||||
Device with filter will not receive any signals sent with different filter.
|
||||
returns:
|
||||
Reference to frequency object.
|
||||
|
||||
remove_object (obj/device, old_frequency)
|
||||
Obliviously, after calling this proc, device will not receive any signals on old_frequency.
|
||||
Other frequencies will left unaffected.
|
||||
|
||||
return_frequency(var/frequency as num)
|
||||
returns:
|
||||
Reference to frequency object. Use it if you need to send and do not need to listen.
|
||||
|
||||
radio_frequency is a global object maintaining list of devices that listening specific frequency.
|
||||
procs:
|
||||
|
||||
post_signal(obj/source as obj|null, datum/signal/signal, var/filter as text|null = null, var/range as num|null = null)
|
||||
Sends signal to all devices that wants such signal.
|
||||
parameters:
|
||||
source - object, emitted signal. Usually, devices will not receive their own signals.
|
||||
signal - see description below.
|
||||
filter - described above.
|
||||
range - radius of regular byond's square circle on that z-level. null means everywhere, on all z-levels.
|
||||
|
||||
obj/proc/receive_signal(datum/signal/signal, var/receive_method as num, var/receive_param)
|
||||
Handler from received signals. By default does nothing. Define your own for your object.
|
||||
Avoid of sending signals directly from this proc, use spawn(-1). Do not use sleep() here please.
|
||||
parameters:
|
||||
signal - see description below. Extract all needed data from the signal before doing sleep(), spawn() or return!
|
||||
receive_method - may be TRANSMISSION_WIRE or TRANSMISSION_RADIO.
|
||||
TRANSMISSION_WIRE is currently unused.
|
||||
receive_param - for TRANSMISSION_RADIO here comes frequency.
|
||||
|
||||
datum/signal
|
||||
vars:
|
||||
source
|
||||
an object that emitted signal. Used for debug and bearing.
|
||||
data
|
||||
list with transmitting data. Usual use pattern:
|
||||
data["msg"] = "hello world"
|
||||
encryption
|
||||
Some number symbolizing "encryption key".
|
||||
Note that game actually do not use any cryptography here.
|
||||
If receiving object don't know right key, it must ignore encrypted signal in its receive_signal.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Frequency range: 1200 to 1600
|
||||
Radiochat range: 1441 to 1489 (most devices refuse to be tune to other frequency, even during mapmaking)
|
||||
|
||||
Radio:
|
||||
1459 - standard radio chat
|
||||
1351 - Science
|
||||
1353 - Command
|
||||
1355 - Medical
|
||||
1357 - Engineering
|
||||
1359 - Security
|
||||
1441 - death squad
|
||||
1443 - Confession Intercom
|
||||
1347 - Cargo techs
|
||||
|
||||
Devices:
|
||||
1451 - tracking implant
|
||||
1457 - RSD default
|
||||
|
||||
On the map:
|
||||
1311 for prison shuttle console (in fact, it is not used)
|
||||
1435 for status displays
|
||||
1437 for atmospherics/fire alerts
|
||||
1439 for engine components
|
||||
1439 for air pumps, air scrubbers, atmo control
|
||||
1441 for atmospherics - supply tanks
|
||||
1443 for atmospherics - distribution loop/mixed air tank
|
||||
1445 for bot nav beacons
|
||||
1447 for mulebot, secbot and ed209 control
|
||||
1449 for airlock controls, electropack, magnets
|
||||
1451 for toxin lab access
|
||||
1453 for engineering access
|
||||
1455 for AI access
|
||||
*/
|
||||
|
||||
var/list/radiochannels = list(
|
||||
"Common" = 1459,
|
||||
"Science" = 1351,
|
||||
"Command" = 1353,
|
||||
"Medical" = 1355,
|
||||
"Engineering" = 1357,
|
||||
"Security" = 1359,
|
||||
"Response Team" = 1345,
|
||||
"Deathsquad" = 1341,
|
||||
"Syndicate" = 1213,
|
||||
"Supply" = 1347,
|
||||
)
|
||||
//depenging helpers
|
||||
var/list/DEPT_FREQS = list(1351, 1355, 1357, 1359, 1213, 1345, 1341, 1347)
|
||||
|
||||
// central command channels, i.e deathsquid & response teams
|
||||
var/list/CENT_FREQS = list(1345, 1341)
|
||||
|
||||
var/const/COMM_FREQ = 1353 //command, colored gold in chat window
|
||||
var/const/SYND_FREQ = 1213
|
||||
|
||||
// department channels
|
||||
var/const/SEC_FREQ = 1359
|
||||
var/const/ENG_FREQ = 1357
|
||||
var/const/SCI_FREQ = 1351
|
||||
var/const/MED_FREQ = 1355
|
||||
var/const/SUP_FREQ = 1347
|
||||
|
||||
#define TRANSMISSION_WIRE 0
|
||||
#define TRANSMISSION_RADIO 1
|
||||
|
||||
/* filters */
|
||||
var/const/RADIO_TO_AIRALARM = "1"
|
||||
var/const/RADIO_FROM_AIRALARM = "2"
|
||||
var/const/RADIO_CHAT = "3"
|
||||
var/const/RADIO_ATMOSIA = "4"
|
||||
var/const/RADIO_NAVBEACONS = "5"
|
||||
var/const/RADIO_AIRLOCK = "6"
|
||||
var/const/RADIO_SECBOT = "7"
|
||||
var/const/RADIO_MULEBOT = "8"
|
||||
var/const/RADIO_MAGNETS = "9"
|
||||
|
||||
var/global/datum/controller/radio/radio_controller
|
||||
|
||||
/hook/startup/proc/createRadioController()
|
||||
radio_controller = new /datum/controller/radio()
|
||||
return 1
|
||||
|
||||
datum/controller/radio
|
||||
var/list/datum/radio_frequency/frequencies = list()
|
||||
|
||||
proc/add_object(obj/device as obj, var/new_frequency as num, var/filter = null as text|null)
|
||||
var/f_text = num2text(new_frequency)
|
||||
var/datum/radio_frequency/frequency = frequencies[f_text]
|
||||
|
||||
if(!frequency)
|
||||
frequency = new
|
||||
frequency.frequency = new_frequency
|
||||
frequencies[f_text] = frequency
|
||||
|
||||
frequency.add_listener(device, filter)
|
||||
return frequency
|
||||
|
||||
proc/remove_object(obj/device, old_frequency)
|
||||
var/f_text = num2text(old_frequency)
|
||||
var/datum/radio_frequency/frequency = frequencies[f_text]
|
||||
|
||||
if(frequency)
|
||||
frequency.remove_listener(device)
|
||||
|
||||
if(frequency.devices.len == 0)
|
||||
del(frequency)
|
||||
frequencies -= f_text
|
||||
|
||||
return 1
|
||||
|
||||
proc/return_frequency(var/new_frequency as num)
|
||||
var/f_text = num2text(new_frequency)
|
||||
var/datum/radio_frequency/frequency = frequencies[f_text]
|
||||
|
||||
if(!frequency)
|
||||
frequency = new
|
||||
frequency.frequency = new_frequency
|
||||
frequencies[f_text] = frequency
|
||||
|
||||
return frequency
|
||||
|
||||
datum/radio_frequency
|
||||
var/frequency as num
|
||||
var/list/list/obj/devices = list()
|
||||
|
||||
proc
|
||||
post_signal(obj/source as obj|null, datum/signal/signal, var/filter = null as text|null, var/range = null as num|null)
|
||||
//log_admin("DEBUG \[[world.timeofday]\]: post_signal {source=\"[source]\", [signal.debug_print()], filter=[filter]}")
|
||||
// var/N_f=0
|
||||
// var/N_nf=0
|
||||
// var/Nt=0
|
||||
var/turf/start_point
|
||||
if(range)
|
||||
start_point = get_turf(source)
|
||||
if(!start_point)
|
||||
del(signal)
|
||||
return 0
|
||||
if (filter) //here goes some copypasta. It is for optimisation. -rastaf0
|
||||
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(max(abs(start_point.x-end_point.x), abs(start_point.y-end_point.y)) <= range)
|
||||
if(start_point.z!=end_point.z || get_dist(start_point, end_point) > range)
|
||||
continue
|
||||
device.receive_signal(signal, TRANSMISSION_RADIO, frequency)
|
||||
for(var/obj/device in devices["_default"])
|
||||
if(device == source)
|
||||
continue
|
||||
if(range)
|
||||
var/turf/end_point = get_turf(device)
|
||||
if(!end_point)
|
||||
continue
|
||||
//if(max(abs(start_point.x-end_point.x), abs(start_point.y-end_point.y)) <= range)
|
||||
if(start_point.z!=end_point.z || get_dist(start_point, end_point) > range)
|
||||
continue
|
||||
device.receive_signal(signal, TRANSMISSION_RADIO, frequency)
|
||||
// N_f++
|
||||
else
|
||||
for (var/next_filter in devices)
|
||||
// var/list/obj/DDD = devices[next_filter]
|
||||
// Nt+=DDD.len
|
||||
for(var/obj/device in devices[next_filter])
|
||||
if(device == source)
|
||||
continue
|
||||
if(range)
|
||||
var/turf/end_point = get_turf(device)
|
||||
if(!end_point)
|
||||
continue
|
||||
//if(max(abs(start_point.x-end_point.x), abs(start_point.y-end_point.y)) <= range)
|
||||
if(start_point.z!=end_point.z || get_dist(start_point, end_point) > range)
|
||||
continue
|
||||
device.receive_signal(signal, TRANSMISSION_RADIO, frequency)
|
||||
// N_nf++
|
||||
|
||||
// log_admin("DEBUG: post_signal(source=[source] ([source.x], [source.y], [source.z]),filter=[filter]) frequency=[frequency], N_f=[N_f], N_nf=[N_nf]")
|
||||
|
||||
|
||||
// del(signal)
|
||||
|
||||
add_listener(obj/device as obj, var/filter as text|null)
|
||||
if (!filter)
|
||||
filter = "_default"
|
||||
//log_admin("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_admin("DEBUG: devices_line.len=[devices_line.len]")
|
||||
//log_admin("DEBUG: devices(filter_str).len=[l]")
|
||||
|
||||
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)
|
||||
|
||||
|
||||
obj/proc
|
||||
receive_signal(datum/signal/signal, receive_method, receive_param)
|
||||
return null
|
||||
|
||||
datum/signal
|
||||
var/obj/source
|
||||
|
||||
var/transmission_method = 0
|
||||
//0 = wire
|
||||
//1 = radio transmission
|
||||
//2 = subspace transmission
|
||||
|
||||
var/data = list()
|
||||
var/encryption
|
||||
|
||||
var/frequency = 0
|
||||
|
||||
proc/copy_from(datum/signal/model)
|
||||
source = model.source
|
||||
transmission_method = model.transmission_method
|
||||
data = model.data
|
||||
encryption = model.encryption
|
||||
frequency = model.frequency
|
||||
|
||||
proc/debug_print()
|
||||
if (source)
|
||||
. = "signal = {source = '[source]' ([source:x],[source:y],[source:z])\n"
|
||||
else
|
||||
. = "signal = {source = '[source]' ()\n"
|
||||
for (var/i in data)
|
||||
. += "data\[\"[i]\"\] = \"[data[i]]\"\n"
|
||||
if(islist(data[i]))
|
||||
var/list/L = data[i]
|
||||
for(var/t in L)
|
||||
. += "data\[\"[i]\"\] list has: [t]"
|
||||
/*
|
||||
HOW IT WORKS
|
||||
|
||||
The radio_controller is a global object maintaining all radio transmissions, think about it as about "ether".
|
||||
Note that walkie-talkie, intercoms and headsets handle transmission using nonstandard way.
|
||||
procs:
|
||||
|
||||
add_object(obj/device as obj, var/new_frequency as num, var/filter as text|null = null)
|
||||
Adds listening object.
|
||||
parameters:
|
||||
device - device receiving signals, must have proc receive_signal (see description below).
|
||||
one device may listen several frequencies, but not same frequency twice.
|
||||
new_frequency - see possibly frequencies below;
|
||||
filter - thing for optimization. Optional, but recommended.
|
||||
All filters should be consolidated in this file, see defines later.
|
||||
Device without listening filter will receive all signals (on specified frequency).
|
||||
Device with filter will receive any signals sent without filter.
|
||||
Device with filter will not receive any signals sent with different filter.
|
||||
returns:
|
||||
Reference to frequency object.
|
||||
|
||||
remove_object (obj/device, old_frequency)
|
||||
Obliviously, after calling this proc, device will not receive any signals on old_frequency.
|
||||
Other frequencies will left unaffected.
|
||||
|
||||
return_frequency(var/frequency as num)
|
||||
returns:
|
||||
Reference to frequency object. Use it if you need to send and do not need to listen.
|
||||
|
||||
radio_frequency is a global object maintaining list of devices that listening specific frequency.
|
||||
procs:
|
||||
|
||||
post_signal(obj/source as obj|null, datum/signal/signal, var/filter as text|null = null, var/range as num|null = null)
|
||||
Sends signal to all devices that wants such signal.
|
||||
parameters:
|
||||
source - object, emitted signal. Usually, devices will not receive their own signals.
|
||||
signal - see description below.
|
||||
filter - described above.
|
||||
range - radius of regular byond's square circle on that z-level. null means everywhere, on all z-levels.
|
||||
|
||||
obj/proc/receive_signal(datum/signal/signal, var/receive_method as num, var/receive_param)
|
||||
Handler from received signals. By default does nothing. Define your own for your object.
|
||||
Avoid of sending signals directly from this proc, use spawn(-1). Do not use sleep() here please.
|
||||
parameters:
|
||||
signal - see description below. Extract all needed data from the signal before doing sleep(), spawn() or return!
|
||||
receive_method - may be TRANSMISSION_WIRE or TRANSMISSION_RADIO.
|
||||
TRANSMISSION_WIRE is currently unused.
|
||||
receive_param - for TRANSMISSION_RADIO here comes frequency.
|
||||
|
||||
datum/signal
|
||||
vars:
|
||||
source
|
||||
an object that emitted signal. Used for debug and bearing.
|
||||
data
|
||||
list with transmitting data. Usual use pattern:
|
||||
data["msg"] = "hello world"
|
||||
encryption
|
||||
Some number symbolizing "encryption key".
|
||||
Note that game actually do not use any cryptography here.
|
||||
If receiving object don't know right key, it must ignore encrypted signal in its receive_signal.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Frequency range: 1200 to 1600
|
||||
Radiochat range: 1441 to 1489 (most devices refuse to be tune to other frequency, even during mapmaking)
|
||||
|
||||
Radio:
|
||||
1459 - standard radio chat
|
||||
1351 - Science
|
||||
1353 - Command
|
||||
1355 - Medical
|
||||
1357 - Engineering
|
||||
1359 - Security
|
||||
1441 - death squad
|
||||
1443 - Confession Intercom
|
||||
1347 - Cargo techs
|
||||
|
||||
Devices:
|
||||
1451 - tracking implant
|
||||
1457 - RSD default
|
||||
|
||||
On the map:
|
||||
1311 for prison shuttle console (in fact, it is not used)
|
||||
1435 for status displays
|
||||
1437 for atmospherics/fire alerts
|
||||
1439 for engine components
|
||||
1439 for air pumps, air scrubbers, atmo control
|
||||
1441 for atmospherics - supply tanks
|
||||
1443 for atmospherics - distribution loop/mixed air tank
|
||||
1445 for bot nav beacons
|
||||
1447 for mulebot, secbot and ed209 control
|
||||
1449 for airlock controls, electropack, magnets
|
||||
1451 for toxin lab access
|
||||
1453 for engineering access
|
||||
1455 for AI access
|
||||
*/
|
||||
|
||||
var/list/radiochannels = list(
|
||||
"Common" = 1459,
|
||||
"Science" = 1351,
|
||||
"Command" = 1353,
|
||||
"Medical" = 1355,
|
||||
"Engineering" = 1357,
|
||||
"Security" = 1359,
|
||||
"Response Team" = 1345,
|
||||
"Deathsquad" = 1341,
|
||||
"Syndicate" = 1213,
|
||||
"Supply" = 1347,
|
||||
)
|
||||
//depenging helpers
|
||||
var/list/DEPT_FREQS = list(1351, 1355, 1357, 1359, 1213, 1345, 1341, 1347)
|
||||
|
||||
// central command channels, i.e deathsquid & response teams
|
||||
var/list/CENT_FREQS = list(1345, 1341)
|
||||
|
||||
var/const/COMM_FREQ = 1353 //command, colored gold in chat window
|
||||
var/const/SYND_FREQ = 1213
|
||||
|
||||
// department channels
|
||||
var/const/SEC_FREQ = 1359
|
||||
var/const/ENG_FREQ = 1357
|
||||
var/const/SCI_FREQ = 1351
|
||||
var/const/MED_FREQ = 1355
|
||||
var/const/SUP_FREQ = 1347
|
||||
|
||||
#define TRANSMISSION_WIRE 0
|
||||
#define TRANSMISSION_RADIO 1
|
||||
|
||||
/* filters */
|
||||
//When devices register with the radio controller, they might register under a certain filter.
|
||||
//Other devices can then choose to send signals to only those devices that belong to a particular filter.
|
||||
//This is done for performance, so we don't send signals to lots of machines unnecessarily.
|
||||
|
||||
//This filter is special because devices belonging to default also recieve signals sent to any other filter.
|
||||
var/const/RADIO_DEFAULT = "radio_default"
|
||||
|
||||
var/const/RADIO_TO_AIRALARM = "radio_airalarm" //air alarms
|
||||
var/const/RADIO_FROM_AIRALARM = "radio_airalarm_rcvr" //devices interested in recieving signals from air alarms
|
||||
var/const/RADIO_CHAT = "radio_telecoms"
|
||||
var/const/RADIO_ATMOSIA = "radio_atmos"
|
||||
var/const/RADIO_NAVBEACONS = "radio_navbeacon"
|
||||
var/const/RADIO_AIRLOCK = "radio_airlock"
|
||||
var/const/RADIO_SECBOT = "radio_secbot"
|
||||
var/const/RADIO_MULEBOT = "radio_mulebot"
|
||||
var/const/RADIO_MAGNETS = "radio_magnet"
|
||||
|
||||
var/global/datum/controller/radio/radio_controller
|
||||
|
||||
/hook/startup/proc/createRadioController()
|
||||
radio_controller = new /datum/controller/radio()
|
||||
return 1
|
||||
|
||||
//callback used by objects to react to incoming radio signals
|
||||
/obj/proc/receive_signal(datum/signal/signal, receive_method, receive_param)
|
||||
return null
|
||||
|
||||
//The global radio controller
|
||||
/datum/controller/radio
|
||||
var/list/datum/radio_frequency/frequencies = list()
|
||||
|
||||
/datum/controller/radio/proc/add_object(obj/device as obj, var/new_frequency as num, var/filter = null as text|null)
|
||||
var/f_text = num2text(new_frequency)
|
||||
var/datum/radio_frequency/frequency = frequencies[f_text]
|
||||
|
||||
if(!frequency)
|
||||
frequency = new
|
||||
frequency.frequency = new_frequency
|
||||
frequencies[f_text] = frequency
|
||||
|
||||
frequency.add_listener(device, filter)
|
||||
return frequency
|
||||
|
||||
/datum/controller/radio/proc/remove_object(obj/device, old_frequency)
|
||||
var/f_text = num2text(old_frequency)
|
||||
var/datum/radio_frequency/frequency = frequencies[f_text]
|
||||
|
||||
if(frequency)
|
||||
frequency.remove_listener(device)
|
||||
|
||||
if(frequency.devices.len == 0)
|
||||
del(frequency)
|
||||
frequencies -= f_text
|
||||
|
||||
return 1
|
||||
|
||||
/datum/controller/radio/proc/return_frequency(var/new_frequency as num)
|
||||
var/f_text = num2text(new_frequency)
|
||||
var/datum/radio_frequency/frequency = frequencies[f_text]
|
||||
|
||||
if(!frequency)
|
||||
frequency = new
|
||||
frequency.frequency = new_frequency
|
||||
frequencies[f_text] = frequency
|
||||
|
||||
return frequency
|
||||
|
||||
/datum/radio_frequency
|
||||
var/frequency as num
|
||||
var/list/list/obj/devices = list()
|
||||
|
||||
/datum/radio_frequency/proc/post_signal(obj/source as obj|null, datum/signal/signal, var/filter = null as text|null, var/range = null as num|null)
|
||||
var/turf/start_point
|
||||
if(range)
|
||||
start_point = get_turf(source)
|
||||
if(!start_point)
|
||||
del(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, var/filter, var/turf/start_point = null, var/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
|
||||
|
||||
//allow sequential signals before round start, so that every air alarm sounding off at once doesn't cause trouble.
|
||||
if(!ticker || ticker.current_state < 3)
|
||||
device.receive_signal(signal, TRANSMISSION_RADIO, frequency)
|
||||
else
|
||||
spawn(0)
|
||||
if(device) //in case the device got destroyed somehow
|
||||
device.receive_signal(signal, TRANSMISSION_RADIO, frequency)
|
||||
|
||||
/datum/radio_frequency/proc/add_listener(obj/device as obj, var/filter as text|null)
|
||||
if (!filter)
|
||||
filter = RADIO_DEFAULT
|
||||
//log_admin("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_admin("DEBUG: devices_line.len=[devices_line.len]")
|
||||
//log_admin("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)
|
||||
|
||||
/datum/signal
|
||||
var/obj/source
|
||||
|
||||
var/transmission_method = 0 //unused at the moment
|
||||
//0 = wire
|
||||
//1 = radio transmission
|
||||
//2 = subspace transmission
|
||||
|
||||
var/data = list()
|
||||
var/encryption
|
||||
|
||||
var/frequency = 0
|
||||
|
||||
/datum/signal/proc/copy_from(datum/signal/model)
|
||||
source = model.source
|
||||
transmission_method = model.transmission_method
|
||||
data = model.data
|
||||
encryption = model.encryption
|
||||
frequency = model.frequency
|
||||
|
||||
/datum/signal/proc/debug_print()
|
||||
if (source)
|
||||
. = "signal = {source = '[source]' ([source:x],[source:y],[source:z])\n"
|
||||
else
|
||||
. = "signal = {source = '[source]' ()\n"
|
||||
for (var/i in data)
|
||||
. += "data\[\"[i]\"\] = \"[data[i]]\"\n"
|
||||
if(islist(data[i]))
|
||||
var/list/L = data[i]
|
||||
for(var/t in L)
|
||||
. += "data\[\"[i]\"\] list has: [t]"
|
||||
@@ -88,7 +88,7 @@ obj/machinery/door/airlock/proc/command_completed(var/command)
|
||||
|
||||
return 1 //Unknown command. Just assume it's completed.
|
||||
|
||||
obj/machinery/door/airlock/proc/send_status()
|
||||
obj/machinery/door/airlock/proc/send_status(var/bumped = 0)
|
||||
if(radio_connection)
|
||||
var/datum/signal/signal = new
|
||||
signal.transmission_method = 1 //radio signal
|
||||
@@ -97,6 +97,9 @@ obj/machinery/door/airlock/proc/send_status()
|
||||
|
||||
signal.data["door_status"] = density?("closed"):("open")
|
||||
signal.data["lock_status"] = locked?("locked"):("unlocked")
|
||||
|
||||
if (bumped)
|
||||
signal.data["bumped_with_access"] = 1
|
||||
|
||||
radio_connection.post_signal(src, signal, range = AIRLOCK_CONTROL_RANGE, filter = RADIO_AIRLOCK)
|
||||
|
||||
@@ -116,17 +119,7 @@ obj/machinery/door/airlock/Bumped(atom/AM)
|
||||
if(istype(AM, /obj/mecha))
|
||||
var/obj/mecha/mecha = AM
|
||||
if(density && radio_connection && mecha.occupant && (src.allowed(mecha.occupant) || src.check_access_list(mecha.operation_req_access)))
|
||||
var/datum/signal/signal = new
|
||||
signal.transmission_method = 1 //radio signal
|
||||
signal.data["tag"] = id_tag
|
||||
signal.data["timestamp"] = world.time
|
||||
|
||||
signal.data["door_status"] = density?("closed"):("open")
|
||||
signal.data["lock_status"] = locked?("locked"):("unlocked")
|
||||
|
||||
signal.data["bumped_with_access"] = 1
|
||||
|
||||
radio_connection.post_signal(src, signal, range = AIRLOCK_CONTROL_RANGE, filter = RADIO_AIRLOCK)
|
||||
send_status(1)
|
||||
return
|
||||
|
||||
obj/machinery/door/airlock/proc/set_frequency(new_frequency)
|
||||
@@ -252,6 +245,12 @@ obj/machinery/access_button/update_icon()
|
||||
else
|
||||
icon_state = "access_button_off"
|
||||
|
||||
obj/machinery/access_button/attackby(obj/item/I as obj, mob/user as mob)
|
||||
//Swiping ID on the access button
|
||||
if (istype(I, /obj/item/weapon/card/id) || istype(I, /obj/item/device/pda))
|
||||
attack_hand(user)
|
||||
return
|
||||
..()
|
||||
|
||||
obj/machinery/access_button/attack_hand(mob/user)
|
||||
add_fingerprint(usr)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//base type for controllers of two-door systems
|
||||
/obj/machinery/embedded_controller/radio/airlock
|
||||
// Setup parameters only
|
||||
radio_filter = RADIO_AIRLOCK
|
||||
var/tag_exterior_door
|
||||
var/tag_interior_door
|
||||
var/tag_airpump
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//Handles the control of airlocks
|
||||
|
||||
#define STATE_WAIT 0
|
||||
#define STATE_DEPRESSURIZE 1
|
||||
#define STATE_PRESSURIZE 2
|
||||
#define STATE_IDLE 0
|
||||
#define STATE_PREPARE 1
|
||||
#define STATE_DEPRESSURIZE 2
|
||||
#define STATE_PRESSURIZE 3
|
||||
|
||||
#define TARGET_NONE 0
|
||||
#define TARGET_INOPEN -1
|
||||
@@ -18,7 +19,7 @@
|
||||
var/tag_interior_sensor
|
||||
var/tag_mech_sensor
|
||||
|
||||
var/state = STATE_WAIT
|
||||
var/state = STATE_IDLE
|
||||
var/target_state = TARGET_NONE
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/New(var/obj/machinery/embedded_controller/M)
|
||||
@@ -157,7 +158,7 @@
|
||||
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/process()
|
||||
if(!state)
|
||||
if(!state) //Idle
|
||||
if(target_state)
|
||||
switch(target_state)
|
||||
if(TARGET_INOPEN)
|
||||
@@ -168,38 +169,45 @@
|
||||
//lock down the airlock before activating pumps
|
||||
close_doors()
|
||||
|
||||
var/chamber_pressure = memory["chamber_sensor_pressure"]
|
||||
var/target_pressure = memory["target_pressure"]
|
||||
|
||||
if(memory["purge"])
|
||||
target_pressure = 0
|
||||
|
||||
if(chamber_pressure <= target_pressure)
|
||||
state = STATE_PRESSURIZE
|
||||
signalPump(tag_airpump, 1, 1, target_pressure) //send a signal to start pressurizing
|
||||
|
||||
else if(chamber_pressure > target_pressure)
|
||||
state = STATE_DEPRESSURIZE
|
||||
signalPump(tag_airpump, 1, 0, target_pressure) //send a signal to start depressurizing
|
||||
|
||||
//Check for vacuum - this is set after the pumps so the pumps are aiming for 0
|
||||
if(!memory["target_pressure"])
|
||||
memory["target_pressure"] = ONE_ATMOSPHERE * 0.05
|
||||
state = STATE_PREPARE
|
||||
else
|
||||
//make sure to return to a sane idle state
|
||||
if(memory["pump_status"] != "off") //send a signal to stop pumping
|
||||
signalPump(tag_airpump, 0)
|
||||
|
||||
//the airlock will not allow itself to continue to cycle when any of the doors are forced open.
|
||||
if (state && !check_doors_secured())
|
||||
if ((state == STATE_PRESSURIZE || state == STATE_DEPRESSURIZE) && !check_doors_secured())
|
||||
//the airlock will not allow itself to continue to cycle when any of the doors are forced open.
|
||||
stop_cycling()
|
||||
|
||||
switch(state)
|
||||
if(STATE_PREPARE)
|
||||
if (check_doors_secured())
|
||||
var/chamber_pressure = memory["chamber_sensor_pressure"]
|
||||
var/target_pressure = memory["target_pressure"]
|
||||
|
||||
if(memory["purge"])
|
||||
target_pressure = 0
|
||||
|
||||
if(memory["purge"])
|
||||
target_pressure = 0
|
||||
|
||||
if(chamber_pressure <= target_pressure)
|
||||
state = STATE_PRESSURIZE
|
||||
signalPump(tag_airpump, 1, 1, target_pressure) //send a signal to start pressurizing
|
||||
|
||||
else if(chamber_pressure > target_pressure)
|
||||
state = STATE_DEPRESSURIZE
|
||||
signalPump(tag_airpump, 1, 0, target_pressure) //send a signal to start depressurizing
|
||||
|
||||
//Check for vacuum - this is set after the pumps so the pumps are aiming for 0
|
||||
if(!memory["target_pressure"])
|
||||
memory["target_pressure"] = ONE_ATMOSPHERE * 0.05
|
||||
|
||||
if(STATE_PRESSURIZE)
|
||||
if(memory["chamber_sensor_pressure"] >= memory["target_pressure"] * 0.95)
|
||||
cycleDoors(target_state)
|
||||
|
||||
state = STATE_WAIT
|
||||
state = STATE_IDLE
|
||||
target_state = TARGET_NONE
|
||||
|
||||
if(memory["pump_status"] != "off")
|
||||
@@ -216,7 +224,7 @@
|
||||
else if(memory["chamber_sensor_pressure"] <= memory["target_pressure"] * 1.05)
|
||||
cycleDoors(target_state)
|
||||
|
||||
state = STATE_WAIT
|
||||
state = STATE_IDLE
|
||||
target_state = TARGET_NONE
|
||||
|
||||
//send a signal to stop pumping
|
||||
@@ -231,11 +239,11 @@
|
||||
//these are here so that other types don't have to make so many assuptions about our implementation
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/proc/begin_cycle_in()
|
||||
state = STATE_WAIT
|
||||
state = STATE_IDLE
|
||||
target_state = TARGET_INOPEN
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/proc/begin_cycle_out()
|
||||
state = STATE_WAIT
|
||||
state = STATE_IDLE
|
||||
target_state = TARGET_OUTOPEN
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/proc/close_doors()
|
||||
@@ -243,11 +251,11 @@
|
||||
toggleDoor(memory["exterior_status"], tag_exterior_door, 1, "close")
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/proc/stop_cycling()
|
||||
state = STATE_WAIT
|
||||
state = STATE_IDLE
|
||||
target_state = TARGET_NONE
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/proc/done_cycling()
|
||||
return (state == STATE_WAIT && target_state == TARGET_NONE)
|
||||
return (state == STATE_IDLE && target_state == TARGET_NONE)
|
||||
|
||||
//are the doors closed and locked?
|
||||
/datum/computer/file/embedded_program/airlock/proc/check_exterior_door_secured()
|
||||
@@ -265,7 +273,7 @@
|
||||
var/datum/signal/signal = new
|
||||
signal.data["tag"] = tag
|
||||
signal.data["command"] = command
|
||||
post_signal(signal)
|
||||
post_signal(signal, RADIO_AIRLOCK)
|
||||
|
||||
/datum/computer/file/embedded_program/airlock/proc/signalPump(var/tag, var/power, var/direction, var/pressure)
|
||||
var/datum/signal/signal = new
|
||||
@@ -355,7 +363,7 @@ send an additional command to open the door again.
|
||||
signalDoor(doorTag, doorCommand)
|
||||
|
||||
|
||||
#undef STATE_WAIT
|
||||
#undef STATE_IDLE
|
||||
#undef STATE_DEPRESSURIZE
|
||||
#undef STATE_PRESSURIZE
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
//var/radio_power_use = 50 //power used to xmit signals
|
||||
|
||||
var/frequency = 1379
|
||||
var/radio_filter = null
|
||||
var/datum/radio_frequency/radio_connection
|
||||
unacidable = 1
|
||||
|
||||
@@ -64,15 +65,15 @@
|
||||
else
|
||||
icon_state = "airlock_control_off"
|
||||
|
||||
/obj/machinery/embedded_controller/radio/post_signal(datum/signal/signal)
|
||||
/obj/machinery/embedded_controller/radio/post_signal(datum/signal/signal, var/filter = null)
|
||||
signal.transmission_method = TRANSMISSION_RADIO
|
||||
if(radio_connection)
|
||||
//use_power(radio_power_use) //neat idea, but causes way too much lag.
|
||||
return radio_connection.post_signal(src, signal)
|
||||
return radio_connection.post_signal(src, signal, filter)
|
||||
else
|
||||
del(signal)
|
||||
|
||||
/obj/machinery/embedded_controller/radio/proc/set_frequency(new_frequency)
|
||||
radio_controller.remove_object(src, frequency)
|
||||
frequency = new_frequency
|
||||
radio_connection = radio_controller.add_object(src, frequency)
|
||||
radio_connection = radio_controller.add_object(src, frequency, radio_filter)
|
||||
@@ -76,17 +76,6 @@
|
||||
set category = "Debug"
|
||||
set name = "Radio report"
|
||||
|
||||
var/filters = list(
|
||||
"1" = "RADIO_TO_AIRALARM",
|
||||
"2" = "RADIO_FROM_AIRALARM",
|
||||
"3" = "RADIO_CHAT",
|
||||
"4" = "RADIO_ATMOSIA",
|
||||
"5" = "RADIO_NAVBEACONS",
|
||||
"6" = "RADIO_AIRLOCK",
|
||||
"7" = "RADIO_SECBOT",
|
||||
"8" = "RADIO_MULEBOT",
|
||||
"_default" = "NO_FILTER"
|
||||
)
|
||||
var/output = "<b>Radio Report</b><hr>"
|
||||
for (var/fq in radio_controller.frequencies)
|
||||
output += "<b>Freq: [fq]</b><br>"
|
||||
@@ -97,9 +86,9 @@
|
||||
for (var/filter in fqs.devices)
|
||||
var/list/f = fqs.devices[filter]
|
||||
if (!f)
|
||||
output += " [filters[filter]]: ERROR<br>"
|
||||
output += " [filter]: ERROR<br>"
|
||||
continue
|
||||
output += " [filters[filter]]: [f.len]<br>"
|
||||
output += " [filter]: [f.len]<br>"
|
||||
for (var/device in f)
|
||||
if (isobj(device))
|
||||
output += " [device] ([device:x],[device:y],[device:z] in area [get_area(device:loc)])<br>"
|
||||
|
||||
Reference in New Issue
Block a user