From 647df9541ffb4d8a50158d6bde0a038d82af4edb Mon Sep 17 00:00:00 2001 From: Migratingcocofruit <69551563+Migratingcocofruit@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:25:14 +0200 Subject: [PATCH] BSA now checks if the APC has enough power to reload (#27012) * BSA now checks if the APC has enough power to reload. * Update bsa.dm * removes a redundant instance of setting firing cooldown to a nonsensical value * Update bsa.dm --- code/modules/station_goals/bsa.dm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/code/modules/station_goals/bsa.dm b/code/modules/station_goals/bsa.dm index b150a2da395..bb84a5781d6 100644 --- a/code/modules/station_goals/bsa.dm +++ b/code/modules/station_goals/bsa.dm @@ -115,9 +115,12 @@ var/cannon_direction = WEST var/static/image/top_layer = null var/ex_power = 3 - var/power_used_per_shot = 2000000 //enough to kil standard apc - todo : make this use wires instead and scale explosion power with it + /// Amount of energy required to reload the BSA (Joules) + var/energy_used_per_shot = 2 MJ //enough to kil standard apc - todo : make this use wires instead and scale explosion power with it /// The gun's cooldown - var/reload_cooldown_time = 10 MINUTES + var/reload_cooldown_time = 10 MINUTES + /// Are we trying to reload? Should only be true if we failed to reload due to lack of power. + var/try_reload = FALSE COOLDOWN_DECLARE(firing_cooldown) pixel_y = -32 @@ -136,7 +139,7 @@ cannon_direction = EAST /obj/machinery/bsa/full/admin - power_used_per_shot = 0 + energy_used_per_shot = 0 reload_cooldown_time = 100 SECONDS /obj/machinery/bsa/full/admin/east @@ -221,8 +224,17 @@ reload() /obj/machinery/bsa/full/proc/reload() - use_power(power_used_per_shot) - COOLDOWN_START(src, firing_cooldown, reload_cooldown_time) + if(machine_powernet?.powernet_apc?.cell?.charge KJ >= energy_used_per_shot) + try_reload = FALSE + use_power(energy_used_per_shot) + COOLDOWN_START(src, firing_cooldown, reload_cooldown_time) + else + try_reload = TRUE + +/// If we failed a reload keep trying until the APC has enough energy available. +/obj/machinery/bsa/full/process() + if(try_reload) + reload() /obj/item/circuitboard/machine/bsa/back board_name = "Bluespace Artillery Generator" @@ -330,8 +342,8 @@ if(target) data["target"] = get_target_name() if(cannon) - data["reloadtime_text"] = seconds_to_clock(round(COOLDOWN_TIMELEFT(cannon, firing_cooldown) / 10)) - data["ready"] = COOLDOWN_FINISHED(cannon, firing_cooldown) + data["reloadtime_text"] = cannon.try_reload ? "Insufficient Energy For Reloading" : seconds_to_clock(round(COOLDOWN_TIMELEFT(cannon, firing_cooldown) / 10)) + data["ready"] = !cannon.try_reload && COOLDOWN_FINISHED(cannon, firing_cooldown) else data["ready"] = FALSE return data