From 8468c8210c133a9e6c844a1432a11994c50d59cb Mon Sep 17 00:00:00 2001 From: DreamySkrell <107256943+DreamySkrell@users.noreply.github.com> Date: Tue, 25 Aug 2026 17:32:26 +0000 Subject: [PATCH] Ship gun loader auto connects to ship gun (#23101) . --------- Co-authored-by: DreamySkrell <> --- .../ship_weaponry/_ship_ammo_loader.dm | 39 ++++++++++++++----- .../overmap/ship_weaponry/_ship_gun.dm | 12 +++--- html/changelogs/DreamySkrell-loader-auto.yml | 7 ++++ maps/away/ships/scc/scc_scout_ship.dmm | 7 +--- 4 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 html/changelogs/DreamySkrell-loader-auto.yml diff --git a/code/modules/overmap/ship_weaponry/_ship_ammo_loader.dm b/code/modules/overmap/ship_weaponry/_ship_ammo_loader.dm index 67f66fd0fc1..a9e15112ae8 100644 --- a/code/modules/overmap/ship_weaponry/_ship_ammo_loader.dm +++ b/code/modules/overmap/ship_weaponry/_ship_ammo_loader.dm @@ -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) diff --git a/code/modules/overmap/ship_weaponry/_ship_gun.dm b/code/modules/overmap/ship_weaponry/_ship_gun.dm index 0c4fbd22587..a2b5ce33ddd 100644 --- a/code/modules/overmap/ship_weaponry/_ship_gun.dm +++ b/code/modules/overmap/ship_weaponry/_ship_gun.dm @@ -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) diff --git a/html/changelogs/DreamySkrell-loader-auto.yml b/html/changelogs/DreamySkrell-loader-auto.yml new file mode 100644 index 00000000000..f90d14de7dc --- /dev/null +++ b/html/changelogs/DreamySkrell-loader-auto.yml @@ -0,0 +1,7 @@ + +author: DreamySkrell + +delete-after: True + +changes: + - rscadd: "Ship gun loader auto connects to ship gun" diff --git a/maps/away/ships/scc/scc_scout_ship.dmm b/maps/away/ships/scc/scc_scout_ship.dmm index e4e428b19dd..d8a37d62525 100644 --- a/maps/away/ships/scc/scc_scout_ship.dmm +++ b/maps/away/ships/scc/scc_scout_ship.dmm @@ -2179,9 +2179,7 @@ /turf/simulated/floor/tiled/white, /area/ship/scc_scout_ship/quarters) "mF" = ( -/obj/structure/machinery/ammunition_loader/grauwolf{ - weapon_id = "SCC Scout Ship Flak Cannon" - }, +/obj/structure/machinery/ammunition_loader/grauwolf, /turf/simulated/floor/plating, /area/ship/scc_scout_ship/maint_atmos) "mH" = ( @@ -3299,8 +3297,7 @@ /obj/structure/ship_weapon_dummy, /obj/structure/machinery/ship_weapon/grauwolf{ pixel_x = -32; - pixel_y = -192; - weapon_id = "SCC Scout Ship Flak Cannon" + pixel_y = -192 }, /turf/space/dynamic, /area/ship/scc_scout_ship/maint_atmos)