Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tank shuttle rotate #1154

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions code/modules/atmospherics/machinery/atmosmachinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
///Check if the object can be unwrenched
var/can_unwrench = FALSE
///Bitflag of the initialized directions (NORTH | SOUTH | EAST | WEST)
var/initialize_directions = 0
var/initialize_directions = NONE
///The color of the pipe
var/pipe_color = COLOR_VERY_LIGHT_GRAY
///What layer the pipe is in (from 1 to 5, default 3)
Expand Down Expand Up @@ -165,8 +165,7 @@ GLOBAL_REAL_VAR(atmos_machinery_default_armor) = list(BLUNT = 25, PUNCTURE = 10,
* Return a list of the nodes that can connect to other machines, get called by atmos_init()
*/
/obj/machinery/atmospherics/proc/get_node_connects()
var/list/node_connects = list()
node_connects.len = device_type
var/list/node_connects = new /list(device_type)

var/init_directions = get_init_directions()
for(var/i in 1 to device_type)
Expand Down
91 changes: 72 additions & 19 deletions code/modules/atmospherics/machinery/components/tank.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
///The image showing the gases inside of the tank
var/image/window

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

// Mapped in tanks should automatically connect to adjacent pipenets in the direction set in dir
if(mapload)
initialize_directions = dir
set_portdir_relative(dir, TRUE)
set_init_directions()

return INITIALIZE_HINT_LATELOAD

Expand Down Expand Up @@ -156,28 +159,60 @@
refresh_window()

///////////////////////////////////////////////////////////////////
// Pipenet stuff

/obj/machinery/atmospherics/components/tank/return_analyzable_air()
return air_contents
// Port stuff

/**
* Enables/Disables a port direction in var/open_ports. \
* Use this, then call set_init_directions() instead of setting initialize_directions directly \
* This system exists because tanks not having all initialize_directions set correctly breaks shuttle rotations
*/
/obj/machinery/atmospherics/components/tank/proc/set_portdir_relative(relative_port_dir, enable)
ASSERT(!isnull(enable))

// Rotate the given dir so that it's relative to north
var/port_dir
if(dir == NORTH) // We're already facing north, no rotation needed
port_dir = relative_port_dir
else
var/offnorth_angle = dir2angle(dir)
port_dir = turn(relative_port_dir, offnorth_angle)

/obj/machinery/atmospherics/components/tank/return_airs_for_reconcilation(datum/pipeline/requester)
. = ..()
if(!air_contents)
if(enable)
open_ports |= port_dir
else
open_ports &= ~port_dir

/**
* Toggles a port direction in var/open_ports \
* Use this, then call set_init_directions() instead of setting initialize_directions directly \
* This system exists because tanks not having all initialize_directions set correctly breaks shuttle rotations
*/
/obj/machinery/atmospherics/components/tank/proc/toggle_portdir_relative(relative_port_dir)
var/toggle = ((initialize_directions & relative_port_dir) ? FALSE : TRUE)
set_portdir_relative(relative_port_dir, toggle)

/obj/machinery/atmospherics/components/tank/set_init_directions()
if(!open_ports)
initialize_directions = NONE
return
. += air_contents

/obj/machinery/atmospherics/components/tank/return_pipenets_for_reconcilation(datum/pipeline/requester)
. = ..()
var/datum/merger/merge_group = GetMergeGroup(merger_id, merger_typecache)
for(var/obj/machinery/atmospherics/components/tank/tank as anything in merge_group.members)
. += tank.parents
//We're rotating open_ports relative to dir, and
//setting initialize_directions to that rotated dir
var/relative_port_dirs = NONE
var/dir_angle = dir2angle(dir)
for(var/cardinal in GLOB.cardinals)
var/current_dir = cardinal & open_ports
if(!current_dir)
continue

/obj/machinery/atmospherics/components/tank/proc/toggle_side_port(new_dir)
if(initialize_directions & new_dir)
initialize_directions &= ~new_dir
else
initialize_directions |= new_dir
var/rotated_dir = turn(current_dir, -dir_angle)
relative_port_dirs |= rotated_dir

initialize_directions = relative_port_dirs

/obj/machinery/atmospherics/components/tank/proc/toggle_side_port(port_dir)
toggle_portdir_relative(port_dir)
set_init_directions()

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

update_parents()

///////////////////////////////////////////////////////////////////
// Pipenet stuff

/obj/machinery/atmospherics/components/tank/return_analyzable_air()
return air_contents

/obj/machinery/atmospherics/components/tank/return_airs_for_reconcilation(datum/pipeline/requester)
. = ..()
if(!air_contents)
return
. += air_contents

/obj/machinery/atmospherics/components/tank/return_pipenets_for_reconcilation(datum/pipeline/requester)
. = ..()
var/datum/merger/merge_group = GetMergeGroup(merger_id, merger_typecache)
for(var/obj/machinery/atmospherics/components/tank/tank as anything in merge_group.members)
. += tank.parents

///////////////////////////////////////////////////////////////////
// Merger handling

Expand Down
9 changes: 4 additions & 5 deletions code/modules/shuttle/on_move.dm
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,17 @@ All ShuttleMove procs go here
. = ..()
recharging_turf = get_step(loc, dir)

/obj/machinery/atmospherics/afterShuttleMove(turf/oldT, list/movement_force, shuttle_dir, shuttle_preferred_direction, move_dir, rotation)
. = ..()
if(pipe_vision_img)
pipe_vision_img.loc = loc

/obj/machinery/computer/auxiliary_base/afterShuttleMove(turf/oldT, list/movement_force, shuttle_dir, shuttle_preferred_direction, move_dir, rotation)
. = ..()
if(is_mining_level(z)) //Avoids double logging and landing on other Z-levels due to badminnery
SSblackbox.record_feedback("associative", "colonies_dropped", 1, list("x" = x, "y" = y, "z" = z))

/obj/machinery/atmospherics/afterShuttleMove(turf/oldT, list/movement_force, shuttle_dir, shuttle_preferred_direction, move_dir, rotation)
. = ..()

if(pipe_vision_img)
pipe_vision_img.loc = loc

var/missing_nodes = FALSE
for(var/i in 1 to device_type)
if(nodes[i])
Expand Down
12 changes: 10 additions & 2 deletions code/modules/shuttle/shuttle_rotate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,23 @@ If ever any of these procs are useful for non-shuttles, rename it to proc/rotate
/obj/machinery/atmospherics/shuttleRotate(rotation, params)
var/list/real_node_connect = get_node_connects()
for(var/i in 1 to device_type)
real_node_connect[i] = angle2dir(rotation+dir2angle(real_node_connect[i]))
var/node_dir = real_node_connect[i]
if(isnull(node_dir))
continue

real_node_connect[i] = turn(node_dir, -rotation)

. = ..()
set_init_directions()
var/list/supposed_node_connect = get_node_connects()
var/list/nodes_copy = nodes.Copy()

for(var/i in 1 to device_type)
var/new_pos = supposed_node_connect.Find(real_node_connect[i])
var/node_dir = real_node_connect[i]
if(isnull(node_dir))
continue

var/new_pos = supposed_node_connect.Find(node_dir)
nodes[new_pos] = nodes_copy[i]

//prevents shuttles attempting to rotate this since it messes up sprites
Expand Down
Loading