From fe629442af267db1f87de00fe0cae198ad7f97a9 Mon Sep 17 00:00:00 2001 From: zxaber <37497534+zxaber@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:30:39 -0700 Subject: [PATCH] Fixes borg chargers constantly (abet slowly) draining borg cells. (#83743) ## About The Pull Request - Adds in checks for the borg consumables resupplying to stop drawing power once supplies are full. Specifically, the `respawn_consumables()` proc will run attempting to stock everything it can, and will return TRUE if any item required stocking. ## Why It's Good For The Game Certain borg tools are still supplied by the borg chargers directly at a power cost because material costs just don't make sense. These did not have a check in place for if the various resources were full, meaning every process cycle a bit of the borg's cell would be used attempting to restock things. Since it's a percentage of the cell's current charge, a filled bluespace cell could have a surprising power leak. Now that borg chargers pull directly from the SMES units, borgs don't recharge if the powernet is empty (regardless of local APC charge). But borg consumables restocking carries on, which causes borgs to slowly drain. So I have added some checks to stop the drain if nothing was actually done. ## Changelog :cl: fix: Fixed borg chargers (especially unpowered ones) constantly draining a borg's cell. /:cl: --- .../modules/mob/living/silicon/robot/robot.dm | 4 +- .../mob/living/silicon/robot/robot_model.dm | 42 +++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index 3fa78b9dda1..6fefbb05f7c 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -952,7 +952,9 @@ SIGNAL_HANDLER if(model) - model.respawn_consumable(src, cell.use(cell.charge * 0.005)) + if(cell.charge) + if(model.respawn_consumable(src, cell.charge * 0.005)) + cell.use(cell.charge * 0.005) if(sendmats) model.restock_consumable() if(repairs) diff --git a/code/modules/mob/living/silicon/robot/robot_model.dm b/code/modules/mob/living/silicon/robot/robot_model.dm index a46389e11b2..1721d6ec2c1 100644 --- a/code/modules/mob/living/silicon/robot/robot_model.dm +++ b/code/modules/mob/living/silicon/robot/robot_model.dm @@ -137,29 +137,43 @@ if(cyborg.hud_used) cyborg.hud_used.update_robot_modules_display() + +///Restocks things that don't take mats, generally at a power cost. Returns True if anything was restocked/replaced, and False otherwise. /obj/item/robot_model/proc/respawn_consumable(mob/living/silicon/robot/cyborg, coeff = 1) SHOULD_CALL_PARENT(TRUE) + ///If anything was actually replaced/refilled/recharged. If not, we won't draw power. + . = FALSE + for(var/datum/robot_energy_storage/storage_datum in storages) if(storage_datum.renewable == FALSE) continue - storage_datum.energy = min(storage_datum.max_energy, storage_datum.energy + coeff * storage_datum.recharge_rate) + if(storage_datum.energy < storage_datum.max_energy) + . = TRUE + storage_datum.energy = min(storage_datum.max_energy, storage_datum.energy + coeff * storage_datum.recharge_rate) for(var/obj/item/module in get_usable_modules()) if(istype(module, /obj/item/assembly/flash)) var/obj/item/assembly/flash/flash = module + if(flash.burnt_out) + . = TRUE flash.times_used = 0 flash.burnt_out = FALSE flash.update_appearance() else if(istype(module, /obj/item/melee/baton/security)) var/obj/item/melee/baton/security/baton = module - baton.cell?.charge = baton.cell.maxcharge + if(baton.cell?.charge < baton.cell.maxcharge) + . = TRUE //if sec borgs ever make a mainstream return, we should probably do this differntly. + baton.cell?.charge = baton.cell.maxcharge else if(istype(module, /obj/item/gun/energy)) var/obj/item/gun/energy/gun = module if(!gun.chambered) + . = TRUE gun.recharge_newshot() //try to reload a new shot. - cyborg.toner = cyborg.tonermax + if(cyborg.toner < cyborg.tonermax) + . = TRUE + cyborg.toner = cyborg.tonermax /** * Refills consumables that require materials, rather than being given for free. @@ -350,6 +364,7 @@ if(!soap) return if(soap.uses < initial(soap.uses)) + . = TRUE soap.uses += ROUND_UP(initial(soap.uses) / 100) * coeff /obj/item/robot_model/engineering @@ -627,20 +642,29 @@ ..() var/obj/item/lightreplacer/light_replacer = locate(/obj/item/lightreplacer) in basic_modules if(light_replacer) - light_replacer.Charge(cyborg, coeff) + if(light_replacer.uses < light_replacer.max_uses) + . = TRUE + light_replacer.Charge(cyborg, coeff) var/obj/item/reagent_containers/spray/cyborg_drying/drying_agent = locate(/obj/item/reagent_containers/spray/cyborg_drying) in basic_modules if(drying_agent) - drying_agent.reagents.add_reagent(/datum/reagent/drying_agent, 5 * coeff) + var/datum/reagents/anti_water = drying_agent.reagents + if(anti_water.total_volume < anti_water.maximum_volume) + . = TRUE + drying_agent.reagents.add_reagent(/datum/reagent/drying_agent, 5 * coeff) var/obj/item/reagent_containers/spray/cyborg_lube/lube = locate(/obj/item/reagent_containers/spray/cyborg_lube) in emag_modules if(lube) - lube.reagents.add_reagent(/datum/reagent/lube, 2 * coeff) + var/datum/reagents/anti_friction = lube.reagents + if(anti_friction.total_volume < anti_friction.maximum_volume) + . = TRUE + lube.reagents.add_reagent(/datum/reagent/lube, 2 * coeff) var/obj/item/soap/nanotrasen/cyborg/soap = locate(/obj/item/soap/nanotrasen/cyborg) in basic_modules if(!soap) return if(soap.uses < initial(soap.uses)) + . = TRUE soap.uses += ROUND_UP(initial(soap.uses) / 100) * coeff /obj/item/robot_model/medical @@ -760,6 +784,7 @@ var/obj/item/gun/energy/e_gun/advtaser/cyborg/taser = locate(/obj/item/gun/energy/e_gun/advtaser/cyborg) in basic_modules if(taser) if(taser.cell.charge < taser.cell.maxcharge) + . = TRUE var/obj/item/ammo_casing/energy/shot = taser.ammo_type[taser.select] taser.cell.give(shot.e_cost * coeff) taser.update_appearance() @@ -811,7 +836,10 @@ ..() var/obj/item/reagent_containers/enzyme = locate(/obj/item/reagent_containers/condiment/enzyme) in basic_modules if(enzyme) - enzyme.reagents.add_reagent(/datum/reagent/consumable/enzyme, 2 * coeff) + var/datum/reagents/spicyketchup = enzyme.reagents + if(spicyketchup.total_volume < spicyketchup.maximum_volume) + . = TRUE + enzyme.reagents.add_reagent(/datum/reagent/consumable/enzyme, 2 * coeff) /obj/item/robot_model/syndicate name = "Syndicate Assault"