Ship gun loader auto connects to ship gun (#23101)

.

---------

Co-authored-by: DreamySkrell <>
This commit is contained in:
DreamySkrell
2026-08-25 17:32:26 +00:00
committed by GitHub
co-authored by DreamySkrell <>
parent f0161713d6
commit 8468c8210c
4 changed files with 46 additions and 19 deletions
@@ -1,4 +1,4 @@
/obj/structure/machinery/ammunition_loader
ABSTRACT_TYPE(/obj/structure/machinery/ammunition_loader)
name = "ammunition loader"
desc = "An ammunition loader for ship weapons systems. All hands to battlestations!"
icon = 'icons/obj/machinery/ship_guns/ship_weapon_attachments.dmi'
@@ -7,7 +7,9 @@
anchored = TRUE
maxhealth = 1000
var/obj/structure/machinery/ship_weapon/weapon
var/weapon_id //Used to connect weapon systems to the relevant ammunition loader.
/// Used to connect weapon systems to the relevant ammunition loader.
/// If empty, it will try to find the closest ship gun, and connect to it.
var/weapon_id = ""
/obj/structure/machinery/ammunition_loader/mechanics_hints(mob/user, distance, is_adjacent)
. += ..()
@@ -22,14 +24,33 @@
/obj/structure/machinery/ammunition_loader/LateInitialize()
. = ..()
for(var/obj/structure/machinery/ship_weapon/SW in SSmachinery.machinery)
if(SW.weapon_id == weapon_id)
if(get_area(SW) == get_area(src))
weapon = SW
else
crash_with("[src] is set to [weapon_id] of [SW] at [x] [y] [z], but areas mismatch!")
if(weapon_id)
// explicit weapon id match
for(var/obj/structure/machinery/ship_weapon/sw in SSmachinery.machinery)
if(sw.weapon_id != weapon_id)
continue
if(get_area(sw) != get_area(src))
crash_with("[src] is set to [weapon_id] of [sw] at ([x], [y], [z]), but areas mismatch!")
continue
weapon = sw
break
else
// automatic fallback to try to find the closest ship weapon within the same area
var/area/our_area = get_area(src)
var/obj/structure/machinery/ship_weapon/closest_gun
var/closest_dist = null
for(var/obj/structure/machinery/ship_weapon/sw in SSmachinery.machinery)
if(get_area(sw) != our_area)
continue
var/dist = get_dist(src, sw)
if(isnull(closest_dist) || dist < closest_dist)
closest_dist = dist
closest_gun = sw
weapon = closest_gun
if(!weapon)
crash_with("[src] at [x] [y] [z] has no weapon attached!")
crash_with("[src] at ([x], [y], [z]) has no weapon attached!")
/obj/structure/machinery/ammunition_loader/ex_act(severity)
switch(severity)
@@ -1,4 +1,4 @@
/obj/structure/machinery/ship_weapon
ABSTRACT_TYPE(/obj/structure/machinery/ship_weapon)
name = "ship weapon"
desc = DESC_PARENT
icon = 'icons/obj/machinery/ship_guns/longbow.dmi'
@@ -24,8 +24,10 @@
var/load_time = 5 SECONDS
/// When toggled, targeting computers will be able to force ammunition heading direction. Used for guns on visitables.
var/mobile_platform = FALSE
var/weapon_id //Used to identify a gun in the targeting consoles and connect weapon systems to the relevant ammunition loader. Must be unique!
/// Used to identify a gun in the targeting consoles and connect weapon systems to the relevant ammunition loader.
/// Must be unique!
/// If empty, it will be set automatically in the form of `name (123)`.
var/weapon_id
var/list/obj/structure/ship_weapon_dummy/connected_dummies = list()
var/obj/structure/ship_weapon_dummy/barrel
@@ -75,6 +77,8 @@
/obj/structure/machinery/ship_weapon/Initialize(mapload)
..()
appearance_flags &= ~TILE_BOUND //NOT BOUND BY ANY LIMITS
if(!weapon_id)
weapon_id = "[name] - [get_area(src)]"
return INITIALIZE_HINT_LATELOAD
/obj/structure/machinery/ship_weapon/LateInitialize()
@@ -84,8 +88,6 @@
SSshuttle.initialize_ship_weapons()
for(var/obj/structure/ship_weapon_dummy/SD in orange(1, src))
SD.connect(src)
if(!weapon_id)
weapon_id = "[name] - [sequential_id(type)]"
/obj/structure/machinery/ship_weapon/Destroy()
for(var/obj/O in ammunition)