[MIRROR] Fix: Robotic Damage / Reagents Refactor [MDB IGNORE] (#18132)

* Fix: Robotic Damage / Reagents Refactor (#71937)

This PR is a continuing refactor of and fixes bugs introduced by my
prior PR #71864

![when-you-finish-fixing-something-and-it-no-longer-works](https://cdn.discordapp.com/attachments/752427120365404172/1052037482771906640/Attachment.jpg)

Due to many functions in reagents having been implemented on top of
prior buggy code, their new behaviors are not as expected in-game, and
as a result reagents damage/heal robotic/cybernetic bodyparts/organs
when not appropriate; bugs like healing robotic arms with Libital is
currently possible.

To fix the errant behaviors in the newly debugged code, I have added
three variables to `datum/reagent` which are used throughout reagent
code, mainly inside of `on_mob_life` etc:

- `affected_bodytype = BODYTYPE_ORGANIC` - Used if the reagent
damages/heals bodyparts (Brute/Fire) of an affected mob.
- `affected_biotype = MOB_ORGANIC` - Used if the reagent damages/heals
generic damage (Toxin/Oxygen) of an affected mob.
- `affected_organtype = ORGAN_ORGANIC` - Used if the reagent
damages/heals organ damage of an affected mob.

The diff is large, and I have refactored the readability/maintainability
around the sections of code I was modifying. At one point I chose to
perform a quality pass on reagents because I found it quite hard to
maintain reagents code in its current state. This PR also replaces many
single-letter variables with more descriptive and readable variable
names. I also found and fixed a stray tab which was located in the
flavortext of `proc/item_heal_robotic`

Due to an old bug being fixed recently by PR #71864 a lot of
healing/damaging reagents now have an effect on robotic bodyparts. This
PR corrects the issue and changes reagents to explicitly define the body
type, bio type, and organ type which they can affect with
helaing/damage. This PR replaces a lot of single-letter variable names
with more descriptive names. I also fixed a small typo in
`item_heal_robotic` which was inserting an extra tab.

🆑
fix: Fixed a stray-tab typo in "item_heal_robotic"
fix: Fixed reagents and other effects which were inappropriately
affecting robotic limbs.
code: Refactored all of reagents code to be more readable and
maintainable.
/🆑

Co-authored-by: Time-Green <timkoster1@hotmail.com>

* Modular!

* More Modular!

Co-authored-by: Dani Glore <fantasticdragons@gmail.com>
Co-authored-by: Time-Green <timkoster1@hotmail.com>
Co-authored-by: Funce <funce.973@gmail.com>
This commit is contained in:
SkyratBot
2022-12-19 22:04:01 +13:00
committed by GitHub
co-authored by Time-Green Dani Glore Funce
parent 7ed74e22a4
commit cf1416ed79
36 changed files with 1767 additions and 1734 deletions
+4 -4
View File
@@ -404,7 +404,7 @@
//Applies brute and burn damage to the organ. Returns 1 if the damage-icon states changed at all.
//Damage will not exceed max_damage using this proc
//Cannot apply negative damage
/obj/item/bodypart/proc/receive_damage(brute = 0, burn = 0, blocked = 0, updating_health = TRUE, required_status = null, wound_bonus = 0, bare_wound_bonus = 0, sharpness = NONE, attack_direction = null)
/obj/item/bodypart/proc/receive_damage(brute = 0, burn = 0, blocked = 0, updating_health = TRUE, required_bodytype = null, wound_bonus = 0, bare_wound_bonus = 0, sharpness = NONE, attack_direction = null)
SHOULD_CALL_PARENT(TRUE)
var/hit_percent = (100-blocked)/100
@@ -412,7 +412,7 @@
return FALSE
if(owner && (owner.status_flags & GODMODE))
return FALSE //godmode
if(required_status && !(bodytype & required_status))
if(required_bodytype && !(bodytype & required_bodytype))
return FALSE
var/dmg_multi = CONFIG_GET(number/damage_multiplier) * hit_percent
@@ -529,10 +529,10 @@
//Heals brute and burn damage for the organ. Returns 1 if the damage-icon states changed at all.
//Damage cannot go below zero.
//Cannot remove negative damage (i.e. apply damage)
/obj/item/bodypart/proc/heal_damage(brute, burn, required_status, updating_health = TRUE)
/obj/item/bodypart/proc/heal_damage(brute, burn, required_bodytype, updating_health = TRUE)
SHOULD_CALL_PARENT(TRUE)
if(required_status && !(bodytype & required_status)) //So we can only heal certain kinds of limbs, ie robotic vs organic.
if(required_bodytype && !(bodytype & required_bodytype)) //So we can only heal certain kinds of limbs, ie robotic vs organic.
return
if(brute)
+5 -3
View File
@@ -170,11 +170,13 @@ INITIALIZE_IMMEDIATE(/obj/item/organ)
return //so we don't grant the organ's action to mobs who pick up the organ.
///Adjusts an organ's damage by the amount "damage_amount", up to a maximum amount, which is by default max damage
/obj/item/organ/proc/applyOrganDamage(damage_amount, maximum = maxHealth) //use for damaging effects
/obj/item/organ/proc/applyOrganDamage(damage_amount, maximum = maxHealth, required_organtype) //use for damaging effects
if(!damage_amount) //Micro-optimization.
return
if(maximum < damage)
return
if(required_organtype && (status != required_organtype))
return
damage = clamp(damage + damage_amount, 0, maximum)
var/mess = check_damage_thresholds(owner)
check_failing_thresholds()
@@ -183,8 +185,8 @@ INITIALIZE_IMMEDIATE(/obj/item/organ)
to_chat(owner, mess)
///SETS an organ's damage to the amount "damage_amount", and in doing so clears or sets the failing flag, good for when you have an effect that should fix an organ if broken
/obj/item/organ/proc/setOrganDamage(damage_amount) //use mostly for admin heals
applyOrganDamage(damage_amount - damage)
/obj/item/organ/proc/setOrganDamage(damage_amount, required_organtype) //use mostly for admin heals
applyOrganDamage(damage_amount - damage, required_organtype = required_organtype)
/** check_damage_thresholds
* input: mob/organ_owner (a mob, the owner of the organ we call the proc on)