From 0ef3a33fa41fd6b88665fee434db4eba4fcdb18d Mon Sep 17 00:00:00 2001 From: rebel228 <58699696+rebel228@users.noreply.github.com> Date: Fri, 22 May 2020 03:16:18 +0300 Subject: [PATCH] Cyborg Hypospray QOL tweak (#13403) * Borg Hypospray QOL fix Cyborg Hypospray QOL fix Cyborg's hypospay now replenished reagents in inactive modes once the active mode is full. * code quality improvements moved duplicate code into its own proc return TRUE/FALSE instead of 1/0 replaced magic number with a define * added a trailing newline added * small code improvement robot is pased as a parameter got rid of var/ part in parameters --- .../reagents/reagent_containers/borghydro.dm | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/code/modules/reagents/reagent_containers/borghydro.dm b/code/modules/reagents/reagent_containers/borghydro.dm index 27abeca6d46..1fa4930b0f6 100644 --- a/code/modules/reagents/reagent_containers/borghydro.dm +++ b/code/modules/reagents/reagent_containers/borghydro.dm @@ -1,3 +1,4 @@ +#define BORGHYPO_REFILL_VALUE 5 /obj/item/reagent_containers/borghypo name = "Cyborg Hypospray" @@ -46,18 +47,21 @@ /obj/item/reagent_containers/borghypo/process() //Every [recharge_time] seconds, recharge some reagents for the cyborg charge_tick++ - if(charge_tick < recharge_time) return 0 + if(charge_tick < recharge_time) + return FALSE charge_tick = 0 if(isrobot(loc)) var/mob/living/silicon/robot/R = loc if(R && R.cell) var/datum/reagents/RG = reagent_list[mode] - if(RG.total_volume < RG.maximum_volume) //Don't recharge reagents and drain power if the storage is full. - R.cell.use(charge_cost) //Take power from borg... - RG.add_reagent(reagent_ids[mode], 5) //And fill hypo with reagent. + if(!refill_borghypo(RG, reagent_ids[mode], R)) //If the storage is not full recharge reagents and drain power. + for(var/i in 1 to reagent_list.len) //if active mode is full loop through the list and fill the first one that is not full + RG = reagent_list[i] + if(refill_borghypo(RG, reagent_ids[i], R)) + break //update_icon() - return 1 + return TRUE // Use this to add more chemicals for the borghypo to produce. /obj/item/reagent_containers/borghypo/proc/add_reagent(reagent) @@ -69,6 +73,13 @@ var/datum/reagents/R = reagent_list[reagent_list.len] R.add_reagent(reagent, 30) +/obj/item/reagent_containers/borghypo/proc/refill_borghypo(datum/reagents/RG, reagent_id, mob/living/silicon/robot/R) + if(RG.total_volume < RG.maximum_volume) + RG.add_reagent(reagent_id, BORGHYPO_REFILL_VALUE) + R.cell.use(charge_cost) + return TRUE + return FALSE + /obj/item/reagent_containers/borghypo/attack(mob/living/carbon/human/M, mob/user) var/datum/reagents/R = reagent_list[mode] if(!R.total_volume) @@ -114,3 +125,5 @@ if(empty) . += "It is currently empty. Allow some time for the internal syntheszier to produce more." + +#undef BORGHYPO_REFILL_VALUE