Skip to content

Commit b1e5b8a

Browse files
authored
tank shuttle rotate (#1154)
1 parent 655fe02 commit b1e5b8a

File tree

4 files changed

+88
-29
lines changed

4 files changed

+88
-29
lines changed

code/modules/atmospherics/machinery/atmosmachinery.dm

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
///Check if the object can be unwrenched
2727
var/can_unwrench = FALSE
2828
///Bitflag of the initialized directions (NORTH | SOUTH | EAST | WEST)
29-
var/initialize_directions = 0
29+
var/initialize_directions = NONE
3030
///The color of the pipe
3131
var/pipe_color = COLOR_VERY_LIGHT_GRAY
3232
///What layer the pipe is in (from 1 to 5, default 3)
@@ -165,8 +165,7 @@ GLOBAL_REAL_VAR(atmos_machinery_default_armor) = list(BLUNT = 25, PUNCTURE = 10,
165165
* Return a list of the nodes that can connect to other machines, get called by atmos_init()
166166
*/
167167
/obj/machinery/atmospherics/proc/get_node_connects()
168-
var/list/node_connects = list()
169-
node_connects.len = device_type
168+
var/list/node_connects = new /list(device_type)
170169

171170
var/init_directions = get_init_directions()
172171
for(var/i in 1 to device_type)

code/modules/atmospherics/machinery/components/tank.dm

+72-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
///The image showing the gases inside of the tank
3232
var/image/window
3333

34+
/// The open node directions of the tank, assuming that the tank is facing NORTH.
35+
var/open_ports = NONE
3436
/// The volume of the gas mixture
3537
var/volume = 2500 //in liters
3638
/// The max pressure of the gas mixture before damaging the tank
@@ -104,7 +106,8 @@
104106

105107
// Mapped in tanks should automatically connect to adjacent pipenets in the direction set in dir
106108
if(mapload)
107-
initialize_directions = dir
109+
set_portdir_relative(dir, TRUE)
110+
set_init_directions()
108111

109112
return INITIALIZE_HINT_LATELOAD
110113

@@ -156,28 +159,60 @@
156159
refresh_window()
157160

158161
///////////////////////////////////////////////////////////////////
159-
// Pipenet stuff
160-
161-
/obj/machinery/atmospherics/components/tank/return_analyzable_air()
162-
return air_contents
162+
// Port stuff
163+
164+
/**
165+
* Enables/Disables a port direction in var/open_ports. \
166+
* Use this, then call set_init_directions() instead of setting initialize_directions directly \
167+
* This system exists because tanks not having all initialize_directions set correctly breaks shuttle rotations
168+
*/
169+
/obj/machinery/atmospherics/components/tank/proc/set_portdir_relative(relative_port_dir, enable)
170+
ASSERT(!isnull(enable))
171+
172+
// Rotate the given dir so that it's relative to north
173+
var/port_dir
174+
if(dir == NORTH) // We're already facing north, no rotation needed
175+
port_dir = relative_port_dir
176+
else
177+
var/offnorth_angle = dir2angle(dir)
178+
port_dir = turn(relative_port_dir, offnorth_angle)
163179

164-
/obj/machinery/atmospherics/components/tank/return_airs_for_reconcilation(datum/pipeline/requester)
165-
. = ..()
166-
if(!air_contents)
180+
if(enable)
181+
open_ports |= port_dir
182+
else
183+
open_ports &= ~port_dir
184+
185+
/**
186+
* Toggles a port direction in var/open_ports \
187+
* Use this, then call set_init_directions() instead of setting initialize_directions directly \
188+
* This system exists because tanks not having all initialize_directions set correctly breaks shuttle rotations
189+
*/
190+
/obj/machinery/atmospherics/components/tank/proc/toggle_portdir_relative(relative_port_dir)
191+
var/toggle = ((initialize_directions & relative_port_dir) ? FALSE : TRUE)
192+
set_portdir_relative(relative_port_dir, toggle)
193+
194+
/obj/machinery/atmospherics/components/tank/set_init_directions()
195+
if(!open_ports)
196+
initialize_directions = NONE
167197
return
168-
. += air_contents
169198

170-
/obj/machinery/atmospherics/components/tank/return_pipenets_for_reconcilation(datum/pipeline/requester)
171-
. = ..()
172-
var/datum/merger/merge_group = GetMergeGroup(merger_id, merger_typecache)
173-
for(var/obj/machinery/atmospherics/components/tank/tank as anything in merge_group.members)
174-
. += tank.parents
199+
//We're rotating open_ports relative to dir, and
200+
//setting initialize_directions to that rotated dir
201+
var/relative_port_dirs = NONE
202+
var/dir_angle = dir2angle(dir)
203+
for(var/cardinal in GLOB.cardinals)
204+
var/current_dir = cardinal & open_ports
205+
if(!current_dir)
206+
continue
175207

176-
/obj/machinery/atmospherics/components/tank/proc/toggle_side_port(new_dir)
177-
if(initialize_directions & new_dir)
178-
initialize_directions &= ~new_dir
179-
else
180-
initialize_directions |= new_dir
208+
var/rotated_dir = turn(current_dir, -dir_angle)
209+
relative_port_dirs |= rotated_dir
210+
211+
initialize_directions = relative_port_dirs
212+
213+
/obj/machinery/atmospherics/components/tank/proc/toggle_side_port(port_dir)
214+
toggle_portdir_relative(port_dir)
215+
set_init_directions()
181216

182217
for(var/i in 1 to length(nodes))
183218
var/obj/machinery/atmospherics/components/node = nodes[i]
@@ -200,6 +235,24 @@
200235

201236
update_parents()
202237

238+
///////////////////////////////////////////////////////////////////
239+
// Pipenet stuff
240+
241+
/obj/machinery/atmospherics/components/tank/return_analyzable_air()
242+
return air_contents
243+
244+
/obj/machinery/atmospherics/components/tank/return_airs_for_reconcilation(datum/pipeline/requester)
245+
. = ..()
246+
if(!air_contents)
247+
return
248+
. += air_contents
249+
250+
/obj/machinery/atmospherics/components/tank/return_pipenets_for_reconcilation(datum/pipeline/requester)
251+
. = ..()
252+
var/datum/merger/merge_group = GetMergeGroup(merger_id, merger_typecache)
253+
for(var/obj/machinery/atmospherics/components/tank/tank as anything in merge_group.members)
254+
. += tank.parents
255+
203256
///////////////////////////////////////////////////////////////////
204257
// Merger handling
205258

code/modules/shuttle/on_move.dm

+4-5
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,17 @@ All ShuttleMove procs go here
208208
. = ..()
209209
recharging_turf = get_step(loc, dir)
210210

211-
/obj/machinery/atmospherics/afterShuttleMove(turf/oldT, list/movement_force, shuttle_dir, shuttle_preferred_direction, move_dir, rotation)
212-
. = ..()
213-
if(pipe_vision_img)
214-
pipe_vision_img.loc = loc
215-
216211
/obj/machinery/computer/auxiliary_base/afterShuttleMove(turf/oldT, list/movement_force, shuttle_dir, shuttle_preferred_direction, move_dir, rotation)
217212
. = ..()
218213
if(is_mining_level(z)) //Avoids double logging and landing on other Z-levels due to badminnery
219214
SSblackbox.record_feedback("associative", "colonies_dropped", 1, list("x" = x, "y" = y, "z" = z))
220215

221216
/obj/machinery/atmospherics/afterShuttleMove(turf/oldT, list/movement_force, shuttle_dir, shuttle_preferred_direction, move_dir, rotation)
222217
. = ..()
218+
219+
if(pipe_vision_img)
220+
pipe_vision_img.loc = loc
221+
223222
var/missing_nodes = FALSE
224223
for(var/i in 1 to device_type)
225224
if(nodes[i])

code/modules/shuttle/shuttle_rotate.dm

+10-2
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,23 @@ If ever any of these procs are useful for non-shuttles, rename it to proc/rotate
8282
/obj/machinery/atmospherics/shuttleRotate(rotation, params)
8383
var/list/real_node_connect = get_node_connects()
8484
for(var/i in 1 to device_type)
85-
real_node_connect[i] = angle2dir(rotation+dir2angle(real_node_connect[i]))
85+
var/node_dir = real_node_connect[i]
86+
if(isnull(node_dir))
87+
continue
88+
89+
real_node_connect[i] = turn(node_dir, -rotation)
8690

8791
. = ..()
8892
set_init_directions()
8993
var/list/supposed_node_connect = get_node_connects()
9094
var/list/nodes_copy = nodes.Copy()
9195

9296
for(var/i in 1 to device_type)
93-
var/new_pos = supposed_node_connect.Find(real_node_connect[i])
97+
var/node_dir = real_node_connect[i]
98+
if(isnull(node_dir))
99+
continue
100+
101+
var/new_pos = supposed_node_connect.Find(node_dir)
94102
nodes[new_pos] = nodes_copy[i]
95103

96104
//prevents shuttles attempting to rotate this since it messes up sprites

0 commit comments

Comments
 (0)