/
bluespace_sender.dm
232 lines (200 loc) · 7.86 KB
/
bluespace_sender.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/obj/machinery/atmospherics/components/unary/bluespace_sender
icon = 'icons/obj/machines/atmospherics/bluespace_gas_selling.dmi'
icon_state = "bluespace_sender_off"
base_icon_state = "bluespace_sender"
name = "Bluespace Gas Sender"
desc = "Sends gases to the bluespace network to be shared with the connected vendors, who knows what's beyond!"
interaction_flags_atom = INTERACT_ATOM_ATTACK_HAND | INTERACT_ATOM_UI_INTERACT
density = TRUE
max_integrity = 300
armor_type = /datum/armor/unary_bluespace_sender
layer = OBJ_LAYER
circuit = /obj/item/circuitboard/machine/bluespace_sender
move_resist = MOVE_RESIST_DEFAULT
set_dir_on_move = FALSE
pipe_flags = PIPING_ONE_PER_TURF | PIPING_DEFAULT_LAYER_ONLY
///Gas mixture containing the inserted gases and that is connected to the vendors
var/datum/gas_mixture/bluespace_network
///Rate of gas transfer inside the network (from 0 to 1)
var/gas_transfer_rate = 0.5
///A base price for each and every gases, in case you don't want to change them
var/list/base_prices = list()
///List storing all the vendors connected to the machine
var/list/vendors
///Amount of credits gained from each vendor
var/credits_gained = 0
/// All bluespace gas senders
GLOBAL_LIST_EMPTY_TYPED(bluespace_senders, /obj/machinery/atmospherics/components/unary/bluespace_sender)
/datum/armor/unary_bluespace_sender
energy = 100
fire = 80
acid = 30
/obj/machinery/atmospherics/components/unary/bluespace_sender/Initialize(mapload)
. = ..()
initialize_directions = dir
bluespace_network = new
for(var/gas_id in GLOB.meta_gas_info)
bluespace_network.assert_gas(gas_id)
for(var/gas_id in GLOB.meta_gas_info)
var/datum/gas/gas = gas_id
base_prices[gas_id] = initial(gas.base_value)
GLOB.bluespace_senders += src
update_appearance()
register_context()
/obj/machinery/atmospherics/components/unary/bluespace_sender/Destroy()
GLOB.bluespace_senders -= src
return ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/examine(mob/user)
. = ..()
. += span_notice("With the panel open:")
. += span_notice(" -Use a wrench with left-click to rotate [src] and right-click to unanchor it.")
/obj/machinery/atmospherics/components/unary/bluespace_sender/add_context(atom/source, list/context, obj/item/held_item, mob/user)
. = ..()
context[SCREENTIP_CONTEXT_CTRL_LMB] = "Turn [on ? "off" : "on"]"
if(!held_item)
return CONTEXTUAL_SCREENTIP_SET
switch(held_item.tool_behaviour)
if(TOOL_SCREWDRIVER)
context[SCREENTIP_CONTEXT_LMB] = "[panel_open ? "Close" : "Open"] panel"
if(TOOL_WRENCH)
context[SCREENTIP_CONTEXT_LMB] = "Rotate"
context[SCREENTIP_CONTEXT_RMB] = "[anchored ? "Unan" : "An"]chor"
return CONTEXTUAL_SCREENTIP_SET
/obj/machinery/atmospherics/components/unary/bluespace_sender/is_connectable()
if(!anchored)
return FALSE
. = ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/update_icon_state()
if(panel_open)
icon_state = "[base_icon_state]_open"
return ..()
if(on && is_operational)
icon_state = "[base_icon_state]_on"
return ..()
icon_state = "[base_icon_state]_off"
return ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/update_overlays()
. = ..()
. += get_pipe_image(icon, "pipe", dir, , piping_layer)
if(showpipe)
. += get_pipe_image(icon, "pipe", initialize_directions)
/obj/machinery/atmospherics/components/unary/bluespace_sender/process_atmos()
if(!is_operational || !on || !nodes[1]) //if it has no power or its switched off, dont process atmos
return
var/datum/gas_mixture/content = airs[1]
var/datum/gas_mixture/remove = content.remove_ratio(gas_transfer_rate)
bluespace_network.merge(remove)
bluespace_network.temperature = T20C
update_parents()
/obj/machinery/atmospherics/components/unary/bluespace_sender/relocate_airs()
if(bluespace_network.total_moles() > 0)
airs[1].merge(bluespace_network)
airs[1].garbage_collect()
return ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/screwdriver_act(mob/living/user, obj/item/tool)
if(on)
balloon_alert(user, "turn off!")
return ITEM_INTERACT_SUCCESS
if(!anchored)
balloon_alert(user, "anchor!")
return ITEM_INTERACT_SUCCESS
if(default_deconstruction_screwdriver(user, "[base_icon_state]_open", "[base_icon_state]_off", tool))
return ITEM_INTERACT_SUCCESS
/obj/machinery/atmospherics/components/unary/bluespace_sender/crowbar_act(mob/living/user, obj/item/tool)
if(panel_open && bluespace_network.total_moles() > 0 && !nodes[1])
say("WARNING - Bluespace network can contain hazardous gases, deconstruct with caution!")
return crowbar_deconstruction_act(user, tool)
/obj/machinery/atmospherics/components/unary/bluespace_sender/multitool_act(mob/living/user, obj/item/item)
var/obj/item/multitool/multitool = item
multitool.set_buffer(src)
balloon_alert(user, "saved to multitool buffer")
return TRUE
/obj/machinery/atmospherics/components/unary/bluespace_sender/wrench_act(mob/living/user, obj/item/tool)
return default_change_direction_wrench(user, tool)
/obj/machinery/atmospherics/components/unary/bluespace_sender/wrench_act_secondary(mob/living/user, obj/item/tool)
if(!panel_open)
balloon_alert(user, "open panel!")
return
if(default_unfasten_wrench(user, tool))
change_pipe_connection(!anchored)
return ITEM_INTERACT_SUCCESS
return
/obj/machinery/atmospherics/components/unary/bluespace_sender/default_change_direction_wrench(mob/user, obj/item/item)
if(!..())
return FALSE
set_init_directions()
update_appearance()
return TRUE
/obj/machinery/atmospherics/components/unary/bluespace_sender/CtrlClick(mob/living/user)
if(!panel_open)
if(!can_interact(user))
return
on = !on
balloon_alert(user, "turned [on ? "on" : "off"]")
investigate_log("was turned [on ? "on" : "off"] by [key_name(user)]", INVESTIGATE_ATMOS)
update_appearance()
return
. = ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "BluespaceSender", name)
ui.open()
/obj/machinery/atmospherics/components/unary/bluespace_sender/ui_data(mob/user)
var/list/data = list()
data["on"] = on
data["gas_transfer_rate"] = gas_transfer_rate
var/list/bluespace_gasdata = list()
if(bluespace_network.total_moles())
for(var/gas_id in bluespace_network.gases)
bluespace_gasdata.Add(list(list(
"name" = bluespace_network.gases[gas_id][GAS_META][META_GAS_NAME],
"id" = bluespace_network.gases[gas_id][GAS_META][META_GAS_ID],
"amount" = round(bluespace_network.gases[gas_id][MOLES], 0.01),
"price" = base_prices[gas_id],
)))
else
for(var/gas_id in bluespace_network.gases)
bluespace_gasdata.Add(list(list(
"name" = bluespace_network.gases[gas_id][GAS_META][META_GAS_NAME],
"id" = "",
"amount" = 0,
"price" = 0,
)))
data["bluespace_network_gases"] = bluespace_gasdata
var/list/vendors_list = list()
if(vendors)
for(var/obj/machinery/bluespace_vendor/vendor in vendors)
vendors_list.Add(list(list(
"name" = vendor.name,
"area" = get_area(vendor),
)))
data["vendors_list"] = vendors_list
data["credits"] = credits_gained
return data
/obj/machinery/atmospherics/components/unary/bluespace_sender/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("power")
on = !on
investigate_log("was turned [on ? "on" : "off"] by [key_name(usr)]", INVESTIGATE_ATMOS)
update_appearance()
. = TRUE
if("rate")
gas_transfer_rate = clamp(params["rate"], 0, 1)
. = TRUE
if("price")
var/gas_type = gas_id2path(params["gas_type"])
base_prices[gas_type] = clamp(params["gas_price"], 0, 100)
. = TRUE
if("retrieve")
if(bluespace_network.total_moles() > 0)
var/datum/gas_mixture/remove = bluespace_network.remove(bluespace_network.total_moles())
airs[1].merge(remove)
update_parents()
bluespace_network.garbage_collect()
. = TRUE
/obj/machinery/atmospherics/components/unary/bluespace_sender/update_layer()
return