-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
bluespace_sender.dm
179 lines (159 loc) · 5.99 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
/obj/machinery/atmospherics/components/unary/bluespace_sender
icon = 'icons/obj/atmospherics/components/bluespace_gas_selling.dmi'
icon_state = "bluespace_sender_off"
name = "Bluespace Gas Sender"
desc = "Sends gases to the bluespace network to be shared with the connected vendors, who knows what's beyond!"
density = TRUE
max_integrity = 300
armor = list(MELEE = 0, BULLET = 0, LASER = 0, ENERGY = 100, BOMB = 0, BIO = 100, RAD = 100, FIRE = 80, ACID = 30)
layer = OBJ_LAYER
circuit = /obj/item/circuitboard/machine/bluespace_sender
pipe_flags = PIPING_ONE_PER_TURF | PIPING_DEFAULT_LAYER_ONLY
///Base icon name for updating the appearance
var/base_icon = "bluespace_sender"
///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
/obj/machinery/atmospherics/components/unary/bluespace_sender/Initialize()
. = ..()
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)
update_appearance()
/obj/machinery/atmospherics/components/unary/bluespace_sender/Destroy()
if(bluespace_network.total_moles())
var/turf/local_turf = get_turf(src)
local_turf.assume_air(bluespace_network)
local_turf.air_update_turf(FALSE, FALSE)
return ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/update_icon_state()
if(panel_open)
icon_state = "[base_icon]_open"
return ..()
if(on && is_operational)
icon_state = "[base_icon]_on"
return ..()
icon_state = "[base_icon]_off"
return ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/update_overlays()
. = ..()
. += getpipeimage(icon, "pipe", dir, , piping_layer)
if(showpipe)
. += getpipeimage(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/attackby(obj/item/item, mob/user, params)
if(!on)
if(default_deconstruction_screwdriver(user, "[base_icon]_open", "[base_icon]_off", item))
update_appearance()
return
if(default_change_direction_wrench(user, item))
return
if(item.tool_behaviour == TOOL_CROWBAR && panel_open && bluespace_network.total_moles() > 0)
say("WARNING - Bluespace network can contain hazardous gases, deconstruct with caution!")
if(!do_after(user, 3 SECONDS, src))
return
if(default_deconstruction_crowbar(item))
return
return ..()
/obj/machinery/atmospherics/components/unary/bluespace_sender/default_change_direction_wrench(mob/user, obj/item/item)
if(!..())
return FALSE
SetInitDirections()
var/obj/machinery/atmospherics/node = nodes[1]
if(node)
if(src in node.nodes) //Only if it's actually connected. On-pipe version would is one-sided.
node.disconnect(src)
nodes[1] = null
if(parents[1])
nullifyPipenet(parents[1])
atmosinit()
node = nodes[1]
if(node)
node.atmosinit()
node.addMember(src)
SSair.add_to_rebuild_queue(src)
return TRUE
/obj/machinery/atmospherics/components/unary/bluespace_sender/multitool_act(mob/living/user, obj/item/item)
var/obj/item/multitool/multitool = item
multitool.buffer = src
to_chat(user, "<span class='notice'>You store linkage information in [item]'s buffer.</span>")
return TRUE
/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