Files
Joshua Kidder 7a3ad79506 All camelCase (Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss) procs now use snake_case. UNDERSCORES RULE! (#94111)
## About The Pull Request
It's just a partial cleanup of
anti-[STYLE](https://github.com/tgstation/tgstation/blob/master/.github/guides/STYLE.md)
code from /tg/'s ancient history. I compiled & tested with my helpful
assistant and damage is still working.

<img width="1920" height="1040" alt="image"
src="https://github.com/user-attachments/assets/26dabc17-088f-4008-b299-3ff4c27142c3"
/>


I'll upload the .cs script I used to do it shortly.

## Why It's Good For The Game
Just minor code cleanup.

Script used is located at https://metek.tech/camelTo-Snake.7z

EDIT 11/23/25: Updated the script to use multithreading and sequential
scan so it works a hell of a lot faster
```
/*
//
Copyright 2025 Joshua 'Joan Metekillot' Kidder

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
//
*/
using System.Text.RegularExpressions;
class Program
{
    static async Task Main(string[] args)
    {
        var readFile = new FileStreamOptions
        {
            Access = FileAccess.Read,
            Share = FileShare.ReadWrite,
            Options = FileOptions.Asynchronous | FileOptions.SequentialScan
        };
        FileStreamOptions writeFile = new FileStreamOptions
        {
            Share = FileShare.ReadWrite,
            Access = FileAccess.ReadWrite,
            Mode = FileMode.Truncate,
            Options = FileOptions.Asynchronous
        };
        RegexOptions regexOptions = RegexOptions.Multiline | RegexOptions.Compiled;
        Dictionary<string, int> changedProcs = new();
        string regexPattern = @"(?<=\P{L})([a-z]+)([A-Z]{1,2}[a-z]+)*(Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss)([A-Z]{1,2}[a-z]+)*";
        Regex camelCaseProcRegex = new(regexPattern, regexOptions);

        string snakeify(Match matchingRegex)
        {
            var vals =
            matchingRegex.Groups.Cast<Group>().SelectMany(_ => _.Captures).Select(_ => _.Value).ToArray();
            var newVal = string.Join("_", vals.Skip(1).ToArray()).ToLower();
            string logString = $"{vals[0]} => {newVal}";
            if (changedProcs.TryGetValue(logString, out int value))
            {
                changedProcs[logString] = value + 1;
            }
            else
            {
                changedProcs.Add(logString, 1);
            }
            return newVal;
        }
        var dmFiles = Directory.EnumerateFiles(".", "*.dm", SearchOption.AllDirectories).ToAsyncEnumerable<string>();

        // uses default ParallelOptions
        // https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.paralleloptions?view=net-10.0#main
        await Parallel.ForEachAsync(dmFiles, async (filePath, UnusedCancellationToken) =>
        {
            var reader = new StreamReader(filePath, readFile);
            string oldContent = await reader.ReadToEndAsync();
            string newContent = camelCaseProcRegex.Replace(oldContent, new MatchEvaluator((Func<Match, string>)snakeify));
            if (oldContent != newContent)
            {
                var writer = new StreamWriter(filePath, writeFile);
                await writer.WriteAsync(newContent);
                await writer.DisposeAsync();
            }
            reader.Dispose();
        });
        var logToList = changedProcs.Cast<KeyValuePair<string, int>>().ToList();
        foreach (var pair in logToList)
        {
            Console.WriteLine($"{pair.Key}: {pair.Value} locations");
        }
    }
}

```

## Changelog
🆑 Bisar
code: All (Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss) procs now use
snake_case, in-line with the STYLE guide. Underscores rule!
/🆑
2025-11-27 15:50:23 -05:00

158 lines
5.9 KiB
Plaintext

/**
* A mob with this component passes all damage (and healing) it takes to another mob, passed as a parameter
* Essentially we use another mob's health bar as our health bar
*/
/datum/component/life_link
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
/// Mob we pass all of our damage to
var/mob/living/host
/// Optional callback invoked when damage gets transferred
var/datum/callback/on_passed_damage
/// Optional callback invoked when the linked mob dies
var/datum/callback/on_linked_death
/datum/component/life_link/Initialize(mob/living/host, datum/callback/on_passed_damage, datum/callback/on_linked_death)
. = ..()
if (!isliving(parent))
return COMPONENT_INCOMPATIBLE
if (!istype(host))
CRASH("Life link created on [parent.type] and attempted to link to invalid type [host?.type].")
register_host(host)
src.on_passed_damage = on_passed_damage
src.on_linked_death = on_linked_death
/datum/component/life_link/RegisterWithParent()
RegisterSignal(parent, COMSIG_CARBON_LIMB_DAMAGED, PROC_REF(on_limb_damage))
RegisterSignals(parent, COMSIG_LIVING_ADJUST_STANDARD_DAMAGE_TYPES, PROC_REF(on_damage_adjusted))
RegisterSignal(parent, COMSIG_LIVING_HEALTH_UPDATE, PROC_REF(on_health_updated))
RegisterSignal(parent, COMSIG_MOB_GET_STATUS_TAB_ITEMS, PROC_REF(on_status_tab_updated))
if (!isnull(host))
var/mob/living/living_parent = parent
living_parent.updatehealth()
/datum/component/life_link/UnregisterFromParent()
unregister_host()
UnregisterSignal(parent, list(COMSIG_CARBON_LIMB_DAMAGED, COMSIG_LIVING_HEALTH_UPDATE, COMSIG_MOB_GET_STATUS_TAB_ITEMS) + COMSIG_LIVING_ADJUST_STANDARD_DAMAGE_TYPES)
/datum/component/life_link/InheritComponent(datum/component/new_comp, i_am_original, mob/living/host, datum/callback/on_passed_damage, datum/callback/on_linked_death)
register_host(host)
/// Set someone up as our new host
/datum/component/life_link/proc/register_host(mob/living/new_host)
unregister_host()
if (isnull(new_host))
return
host = new_host
RegisterSignal(host, COMSIG_LIVING_DEATH, PROC_REF(on_host_died))
RegisterSignal(host, COMSIG_LIVING_HEALTH_UPDATE, PROC_REF(on_health_updated))
RegisterSignal(host, COMSIG_LIVING_REVIVE, PROC_REF(on_host_revived))
RegisterSignal(host, COMSIG_QDELETING, PROC_REF(on_host_deleted))
var/mob/living/living_parent = parent
living_parent.updatehealth()
/// Drop someone from being our host
/datum/component/life_link/proc/unregister_host()
if (isnull(host))
return
UnregisterSignal(host, list(COMSIG_LIVING_DEATH, COMSIG_LIVING_HEALTH_UPDATE, COMSIG_LIVING_REVIVE, COMSIG_QDELETING))
host = null
/// Called when your damage goes up or down
/datum/component/life_link/proc/on_damage_adjusted(mob/living/our_mob, type, amount, forced)
SIGNAL_HANDLER
if (forced)
return
amount *= our_mob.get_damage_mod(type)
switch (type)
if(BRUTE)
host.adjust_brute_loss(amount, forced = TRUE)
if(BURN)
host.adjust_fire_loss(amount, forced = TRUE)
if(TOX)
host.adjust_tox_loss(amount, forced = TRUE)
if(OXY)
host.adjust_oxy_loss(amount, forced = TRUE)
on_passed_damage?.Invoke(our_mob, host, amount)
return COMPONENT_IGNORE_CHANGE
/// Called when someone hurts one of our limbs, bypassing normal damage adjustment
/datum/component/life_link/proc/on_limb_damage(mob/living/our_mob, limb, brute, burn)
SIGNAL_HANDLER
if (brute != 0)
host.adjust_brute_loss(brute, updating_health = FALSE)
if (burn != 0)
host.adjust_fire_loss(burn, updating_health = FALSE)
if (brute != 0 || burn != 0)
host.updatehealth()
on_passed_damage?.Invoke(our_mob, host, brute + burn)
return COMPONENT_PREVENT_LIMB_DAMAGE
/// Called when either the host or parent's health tries to update, update our displayed health
/datum/component/life_link/proc/on_health_updated()
SIGNAL_HANDLER
update_health_hud(parent)
update_med_hud_health(parent)
update_med_hud_status(parent)
/// Update our parent's health display based on how harmed our host is
/datum/component/life_link/proc/update_health_hud(mob/living/mob_parent)
var/severity = 0
var/healthpercent = health_percentage(host)
switch(healthpercent)
if(100 to INFINITY)
severity = 0
if(85 to 100)
severity = 1
if(70 to 85)
severity = 2
if(55 to 70)
severity = 3
if(40 to 55)
severity = 4
if(25 to 40)
severity = 5
else
severity = 6
if(severity > 0)
mob_parent.overlay_fullscreen("brute", /atom/movable/screen/fullscreen/brute, severity)
else
mob_parent.clear_fullscreen("brute")
if(mob_parent.hud_used?.healths)
mob_parent.hud_used.healths.maptext = MAPTEXT("<div align='center' valign='middle' style='position:relative; top:0px; left:6px'><font color='#efeeef'>[round(healthpercent, 0.5)]%</font></div>")
/// Update our health on the medical hud
/datum/component/life_link/proc/update_med_hud_health(mob/living/mob_parent)
mob_parent.set_hud_image_state(HEALTH_HUD, "hud[RoundHealth(host)]")
/// Update our vital status on the medical hud
/datum/component/life_link/proc/update_med_hud_status(mob/living/mob_parent)
if(host.stat == DEAD || HAS_TRAIT(host, TRAIT_FAKEDEATH))
mob_parent.set_hud_image_state(STATUS_HUD, "huddead")
else
mob_parent.set_hud_image_state(STATUS_HUD, "hudhealthy")
/// When our status tab updates, draw how much HP our host has in there
/datum/component/life_link/proc/on_status_tab_updated(mob/living/source, list/items)
SIGNAL_HANDLER
var/healthpercent = health_percentage(host)
items += "Host Health: [round(healthpercent, 0.5)]%"
/// Called when our host dies, we should die too
/datum/component/life_link/proc/on_host_died(mob/living/source, gibbed)
SIGNAL_HANDLER
on_linked_death?.Invoke(parent, host, gibbed)
var/mob/living/living_parent = parent
living_parent.death(gibbed)
/// Called when our host undies, we should undie too
/datum/component/life_link/proc/on_host_revived(mob/living/source, full_heal_flags)
SIGNAL_HANDLER
var/mob/living/living_parent = parent
living_parent.revive(full_heal_flags)
/// Called when
/datum/component/life_link/proc/on_host_deleted()
SIGNAL_HANDLER
qdel(src)