-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
telecomunications.dm
153 lines (120 loc) · 4.68 KB
/
telecomunications.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Hello, friends, this is Doohl from sexylands. You may be wondering what this
monstrous code file is. Sit down, boys and girls, while I tell you the tale.
The telecom machines were designed to be compatible with any radio
signals, provided they use subspace transmission. Currently they are only used for
headsets, but they can eventually be outfitted for real COMPUTER networks. This
is just a skeleton, ladies and gentlemen.
Look at radio.dm for the prequel to this code.
*/
GLOBAL_LIST_EMPTY(telecomms_list)
/obj/machinery/telecomms
icon = 'icons/obj/machines/telecomms.dmi'
critical_machine = TRUE
var/list/links = list() // list of machines this machine is linked to
var/traffic = 0 // value increases as traffic increases
var/netspeed = 2.5 // how much traffic to lose per second (50 gigabytes/second * netspeed)
var/list/autolinkers = list() // list of text/number values to link with
var/id = "NULL" // identification string
var/network = "NULL" // the network of the machinery
var/list/freq_listening = list() // list of frequencies to tune into: if none, will listen to all
var/on = TRUE
var/toggled = TRUE // Is it toggled on
var/long_range_link = FALSE // Can you link it across Z levels or on the otherside of the map? (Relay & Hub)
var/hide = FALSE // Is it a hidden machine?
///Looping sounds for any servers
var/datum/looping_sound/server/soundloop
/obj/machinery/telecomms/proc/relay_information(datum/signal/subspace/signal, filter, copysig, amount = 20)
// relay signal to all linked machinery that are of type [filter]. If signal has been sent [amount] times, stop sending
if(!on)
return
var/send_count = 0
// Apply some lag based on traffic rates
var/netlag = round(traffic / 50)
if(netlag > signal.data["slow"])
signal.data["slow"] = netlag
// Loop through all linked machines and send the signal or copy.
for(var/obj/machinery/telecomms/machine in links)
if(filter && !istype( machine, filter ))
continue
if(!machine.on)
continue
if(amount && send_count >= amount)
break
if(z != machine.loc.z && !long_range_link && !machine.long_range_link)
continue
send_count++
if(machine.is_freq_listening(signal))
machine.traffic++
if(copysig)
machine.receive_information(signal.copy(), src)
else
machine.receive_information(signal, src)
if(send_count > 0 && is_freq_listening(signal))
traffic++
return send_count
/obj/machinery/telecomms/proc/relay_direct_information(datum/signal/signal, obj/machinery/telecomms/machine)
// send signal directly to a machine
machine.receive_information(signal, src)
/obj/machinery/telecomms/proc/receive_information(datum/signal/signal, obj/machinery/telecomms/machine_from)
// receive information from linked machinery
/obj/machinery/telecomms/proc/is_freq_listening(datum/signal/signal)
// return TRUE if found, FALSE if not found
return signal && (!freq_listening.len || (signal.frequency in freq_listening))
/obj/machinery/telecomms/Initialize(mapload)
. = ..()
soundloop = new(src, on)
GLOB.telecomms_list += src
if(mapload && autolinkers.len)
return INITIALIZE_HINT_LATELOAD
/obj/machinery/telecomms/LateInitialize()
..()
for(var/obj/machinery/telecomms/T in (long_range_link ? GLOB.telecomms_list : urange(20, src, 1)))
add_link(T)
/obj/machinery/telecomms/Destroy()
GLOB.telecomms_list -= src
QDEL_NULL(soundloop)
for(var/obj/machinery/telecomms/comm in GLOB.telecomms_list)
comm.links -= src
links = list()
return ..()
// Used in auto linking
/obj/machinery/telecomms/proc/add_link(obj/machinery/telecomms/T)
var/turf/position = get_turf(src)
var/turf/T_position = get_turf(T)
if((position.z == T_position.z) || (long_range_link && T.long_range_link))
if(src != T)
for(var/x in autolinkers)
if(x in T.autolinkers)
links |= T
T.links |= src
/obj/machinery/telecomms/update_icon_state()
icon_state = "[initial(icon_state)][panel_open ? "_o" : null][on ? null : "_off"]"
return ..()
/obj/machinery/telecomms/proc/update_power()
if(toggled)
if(machine_stat & (BROKEN|NOPOWER|EMPED)) // if powered, on. if not powered, off. if too damaged, off
on = FALSE
soundloop.stop()
else
on = TRUE
soundloop.start()
else
on = FALSE
soundloop.stop()
/obj/machinery/telecomms/process(delta_time)
update_power()
// Update the icon
update_appearance()
if(traffic > 0)
traffic -= netspeed * delta_time
/obj/machinery/telecomms/emp_act(severity)
. = ..()
if(. & EMP_PROTECT_SELF)
return
if(prob(100/severity) && !(machine_stat & EMPED))
set_machine_stat(machine_stat | EMPED)
var/duration = (300 * 10)/severity
addtimer(CALLBACK(src, .proc/de_emp), rand(duration - 20, duration + 20))
/obj/machinery/telecomms/proc/de_emp()
set_machine_stat(machine_stat & ~EMPED)