Ethereals: Standardize defines, lower hunger rate, refactor charging methods (#88960)

## About The Pull Request

Man.

### Standardizing Ethereal Defines

The _single_ biggest issue with all of the recent Ethereal prs has been
that, well, none of our Ethereal defines meaningfully tie to each other,
and as shown repeatedly it's _incredibly_ easy to the others when
changing one of them.
To resolve this, we introduce a `STANDARD_ETHEREAL_CHARGE` define that
every single other Ethereal define is scaled around, which itself is
tied to `STANDARD_CELL_CHARGE`.
Now these can be changed without immediately blowing up everything else,
and with awareness that they tie back to something.

As a side to this, we redefine all reagent-based charge recovery to be
relative to `ETHEREAL_DISCHARGE_RATE` rather than an arbitrary power
level, so it's easier to compare them to how quickly an ethereal
discharges.

### Adjusting Ethereal Defines

Previously, we defined `ETHEREAL_DISCHARGE_RATE` as `8e-3 *
STANDARD_CELL_CHARGE` per second, while defining `ETHEREAL_CHARGE_FULL`
as `2 * STANDARD_CELL_CHARGE`.
With some math, we get that we'd `2 / 8e-3 = 250 seconds`, 4 whole
minutes, to go from full charge to none at all.
It only takes half as much to get hungry, and about 3 minutes to start
taking toxin damage from roundstart.
So we slash this by eight, to `1e-3 STANDARD_ETHEREAL_CHARGE`, giving us
a nice 16-17~ minutes until we're hungry, and another 16-17~ until we
are 100% out of charge. This is also closer to the pre-power-rework
discharge rate.

What made this _worse_ was that the Ethereal APC charge define
`ETHEREAL_APC_POWER_GAIN` wasn't updated to match the current
charge/discharge levels, still being at `10 * STANDARD_CELL_CHARGE`,
which due to how it was coded led to it being impossible for Ethereals
to recharge from APCs.
We first and foremost change this to `0.1 * STANDARD_ETHEREAL_CHARGE`,
which is roughly equal to what it was before the most recent change, and
actually falls in line with Ethereal charge levels.

### Refactoring Ethereal Charge Methods

APC and Power Store recharging were both performing some awkward checks,
which led to our primary issues above, where they would refuse to even
attempt to charge if the stomach couldn't handle a full load or the cell
didn't have a full load.
So we rewrite their entire method to instead check how much can be
charged by taking the minimum of the cell charge, stomach used charge,
and charge-per-step.
We do this instead of just discharging it and taking the return value,
as the stomach may not have enough space for the cell's power, and
that'd get wasted.

This rewrite also allows us to address a small list of bugs.
We keep the `to_chat` for power store draining, as it better
communicates that this method is imperfect than a balloon alert would.

# Testing:<br>I spent an extended period of time looking at Ethereals
slowly starve in front of me with a stopwatch in hand.

## Why It's Good For The Game

Fixes #88934.
Fixes #88977.
16-17~ minutes is a _lot_ more bearable than 2-3~ minutes, and more in
line with discharge rates before the power rework.
Having Ethereal charging stuff actually work is nice.

## Changelog
🆑
balance: Ethereal hunger rate has been adjusted to be 1/8th of its
previous rate, now taking roughly 16-17~ minutes to go down from full to
normal or normal to none. Ethereal defines have been standardized to
help keep this sane.
refactor: Ethereal APC and power store draining/charging methods have
been refactored. Please report any issues.
fix: Ethereal APC and power store draining/charging no longer
arbitrarily caps out at slightly below or above the max/min.
fix: Ethereal APC draining/charging no longer runtimes when there is no
cell or it gets removed mid-charge.
fix: Ethereals can no longer continue charging their stomach even if it
gets surgically removed from them mid-charge.
fix: Ethereal power store draining actually updated the charge level
overlay.
qol: Ethereal APC and power store draining displays a balloon alert when
it can't continue for whatever reason.
/🆑
This commit is contained in:
_0Steven
2025-01-11 00:44:04 +00:00
committed by GitHub
parent 41e0d75ea8
commit 18c346274e
6 changed files with 144 additions and 91 deletions
+10 -8
View File
@@ -297,14 +297,16 @@
//Used as an upper limit for species that continuously gain nutriment
#define NUTRITION_LEVEL_ALMOST_FULL 535
//Charge levels for Ethereals, in joules.
// The standard charge all other Ethereal charge defines are scaled against.
#define STANDARD_ETHEREAL_CHARGE (1 * STANDARD_CELL_CHARGE)
// Charge levels for Ethereals, in joules.
#define ETHEREAL_CHARGE_NONE 0
#define ETHEREAL_CHARGE_LOWPOWER (0.4 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CHARGE_NORMAL (1 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CHARGE_ALMOSTFULL (1.5 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CHARGE_FULL (2 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CHARGE_OVERLOAD (2.5 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CHARGE_DANGEROUS (3 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CHARGE_LOWPOWER (0.4 * STANDARD_ETHEREAL_CHARGE)
#define ETHEREAL_CHARGE_NORMAL (1 * STANDARD_ETHEREAL_CHARGE)
#define ETHEREAL_CHARGE_ALMOSTFULL (1.5 * STANDARD_ETHEREAL_CHARGE)
#define ETHEREAL_CHARGE_FULL (2 * STANDARD_ETHEREAL_CHARGE)
#define ETHEREAL_CHARGE_OVERLOAD (2.5 * STANDARD_ETHEREAL_CHARGE)
#define ETHEREAL_CHARGE_DANGEROUS (3 * STANDARD_ETHEREAL_CHARGE)
#define CRYSTALIZE_COOLDOWN_LENGTH (120 SECONDS)
@@ -452,7 +454,7 @@
#define DOOR_CRUSH_DAMAGE 15 //the amount of damage that airlocks deal when they crush you
#define HUNGER_FACTOR 0.05 //factor at which mob nutrition decreases
#define ETHEREAL_DISCHARGE_RATE (8e-3 * STANDARD_CELL_CHARGE) // Rate at which ethereal stomach charge decreases
#define ETHEREAL_DISCHARGE_RATE (1e-3 * STANDARD_ETHEREAL_CHARGE) // Rate at which ethereal stomach charge decreases
/// How much nutrition eating clothes as moth gives and drains
#define CLOTHING_NUTRITION_GAIN 15
#define REAGENTS_METABOLISM 0.2 //How many units of reagent are consumed per second, by default.
+81 -46
View File
@@ -2,7 +2,9 @@
/// How long it takes an ethereal to drain or charge APCs. Also used as a spam limiter.
#define ETHEREAL_APC_DRAIN_TIME (3 SECONDS)
/// How much power ethereals gain/drain from APCs.
#define ETHEREAL_APC_POWER_GAIN (10 * STANDARD_CELL_CHARGE)
#define ETHEREAL_APC_POWER_GAIN (0.1 * STANDARD_ETHEREAL_CHARGE)
/// Delay between ethereal action and balloon alert, to avoid colliding with previously queued balloon alerts.
#define ETHEREAL_APC_ALERT_DELAY (0.75 SECONDS)
/obj/machinery/power/apc/attack_hand_secondary(mob/user, list/modifiers)
. = ..()
@@ -12,68 +14,100 @@
return
if(!ishuman(user))
return
var/mob/living/carbon/human/apc_interactor = user
var/obj/item/organ/stomach/ethereal/maybe_ethereal_stomach = apc_interactor.get_organ_slot(ORGAN_SLOT_STOMACH)
var/mob/living/carbon/human/human_user = user
var/obj/item/organ/stomach/ethereal/maybe_ethereal_stomach = human_user.get_organ_slot(ORGAN_SLOT_STOMACH)
if(!istype(maybe_ethereal_stomach))
togglelock(user)
else
if(maybe_ethereal_stomach.cell.charge() >= ETHEREAL_CHARGE_NORMAL)
togglelock(user)
ethereal_interact(user, modifiers)
ethereal_interact(human_user, maybe_ethereal_stomach, modifiers)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
/// Special behavior for when an ethereal interacts with an APC.
/obj/machinery/power/apc/proc/ethereal_interact(mob/living/user, list/modifiers)
if(!ishuman(user))
/obj/machinery/power/apc/proc/ethereal_interact(mob/living/carbon/human/user, obj/item/organ/stomach/ethereal/used_stomach, list/modifiers)
if(!LAZYACCESS(modifiers, RIGHT_CLICK))
return
var/mob/living/carbon/human/ethereal = user
var/obj/item/organ/stomach/maybe_stomach = ethereal.get_organ_slot(ORGAN_SLOT_STOMACH)
// how long we wanna wait before we show the balloon alert. don't want it to be very long in case the ethereal wants to opt-out of doing that action, just long enough to where it doesn't collide with previously queued balloon alerts.
var/alert_timer_duration = 0.75 SECONDS
if(isnull(cell))
return
if(used_stomach.drain_time > world.time)
return
if(user.combat_mode)
discharge_to_ethereal(user, used_stomach)
else
charge_from_ethereal(user, used_stomach)
if(!istype(maybe_stomach, /obj/item/organ/stomach/ethereal))
return
var/charge_limit = ETHEREAL_CHARGE_DANGEROUS - ETHEREAL_APC_POWER_GAIN
var/obj/item/organ/stomach/ethereal/stomach = maybe_stomach
var/obj/item/stock_parts/power_store/stomach_cell = stomach.cell
if(!((stomach?.drain_time < world.time) && LAZYACCESS(modifiers, RIGHT_CLICK)))
return
if(ethereal.combat_mode)
if(cell.charge <= (cell.maxcharge / 2)) // ethereals can't drain APCs under half charge, this is so that they are forced to look to alternative power sources if the station is running low
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), ethereal, "safeties prevent draining!"), alert_timer_duration)
return
if(stomach_cell.charge() > charge_limit)
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), ethereal, "charge is full!"), alert_timer_duration)
return
stomach.drain_time = world.time + ETHEREAL_APC_DRAIN_TIME
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), ethereal, "draining power"), alert_timer_duration)
while(do_after(user, ETHEREAL_APC_DRAIN_TIME, target = src))
if(cell.charge <= (cell.maxcharge / 2) || (stomach_cell.charge() > charge_limit))
return
balloon_alert(ethereal, "received charge")
stomach.adjust_charge(ETHEREAL_APC_POWER_GAIN)
cell.use(ETHEREAL_APC_POWER_GAIN)
/// Handles discharging our internal cell to an ethereal and their stomach
/obj/machinery/power/apc/proc/discharge_to_ethereal(mob/living/carbon/human/user, obj/item/organ/stomach/ethereal/used_stomach)
var/half_max_charge = cell.max_charge() / 2
// Ethereals can't drain APCs under half charge, so that they are forced to look to alternative power sources if the station is running low
if(cell.charge() < half_max_charge)
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), user, "safeties prevent draining!"), ETHEREAL_APC_ALERT_DELAY)
return
if(cell.charge >= cell.maxcharge - ETHEREAL_APC_POWER_GAIN)
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), ethereal, "APC can't receive more power!"), alert_timer_duration)
var/obj/item/stock_parts/power_store/stomach_cell = used_stomach.cell
used_stomach.drain_time = world.time + ETHEREAL_APC_DRAIN_TIME
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), user, "draining power..."), ETHEREAL_APC_ALERT_DELAY)
while(do_after(user, ETHEREAL_APC_DRAIN_TIME, target = src))
if(isnull(used_stomach) || (used_stomach != user.get_organ_slot(ORGAN_SLOT_STOMACH)))
balloon_alert(user, "stomach removed!?")
return
if(isnull(cell))
balloon_alert(user, "cell removed!")
return
if(cell.charge() < half_max_charge)
balloon_alert(user, "safeties kicked in!")
return
var/our_available_charge = cell.charge() - half_max_charge
var/stomach_used_charge = stomach_cell.used_charge()
var/potential_charge = min(our_available_charge, stomach_used_charge)
var/to_drain = min(ETHEREAL_APC_POWER_GAIN, potential_charge)
var/energy_drained = cell.use(to_drain, force = TRUE)
used_stomach.adjust_charge(energy_drained)
if(stomach_cell.used_charge() <= 0)
balloon_alert(user, "your charge is full!")
return
if(cell.charge() <= 0)
balloon_alert(user, "apc is empty!")
return
/// Handles charging our internal cell from an ethereal and their stomach
/obj/machinery/power/apc/proc/charge_from_ethereal(mob/living/carbon/human/user, obj/item/organ/stomach/ethereal/used_stomach)
if(cell.charge() >= cell.max_charge())
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), user, "apc full!"), ETHEREAL_APC_ALERT_DELAY)
return
if(stomach_cell.charge() < ETHEREAL_APC_POWER_GAIN)
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), ethereal, "charge is too low!"), alert_timer_duration)
var/obj/item/stock_parts/power_store/stomach_cell = used_stomach.cell
if(stomach_cell.charge() <= 0)
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), user, "charge is too low!"), ETHEREAL_APC_ALERT_DELAY)
return
stomach.drain_time = world.time + ETHEREAL_APC_DRAIN_TIME
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), ethereal, "transfering power"), alert_timer_duration)
used_stomach.drain_time = world.time + ETHEREAL_APC_DRAIN_TIME
addtimer(CALLBACK(src, TYPE_PROC_REF(/atom, balloon_alert), user, "transferring power..."), ETHEREAL_APC_ALERT_DELAY)
if(!do_after(user, ETHEREAL_APC_DRAIN_TIME, target = src))
return
if((cell.charge >= (cell.maxcharge - ETHEREAL_APC_POWER_GAIN)) || (stomach_cell.charge() < ETHEREAL_APC_POWER_GAIN))
balloon_alert(ethereal, "can't transfer power!")
if(isnull(used_stomach) || (used_stomach != user.get_organ_slot(ORGAN_SLOT_STOMACH)))
balloon_alert(user, "stomach removed!?")
return
if(istype(stomach))
while(do_after(user, ETHEREAL_APC_DRAIN_TIME, target = src))
balloon_alert(ethereal, "transferred power")
cell.give(-stomach.adjust_charge(-ETHEREAL_APC_POWER_GAIN))
else
balloon_alert(ethereal, "can't transfer power!")
if(isnull(cell))
balloon_alert(user, "cell removed!")
return
var/stomach_charge = stomach_cell.charge()
var/our_used_charge = cell.used_charge()
var/potential_charge = min(stomach_charge, our_used_charge)
var/to_drain = min(ETHEREAL_APC_POWER_GAIN, potential_charge)
var/energy_drained = used_stomach.adjust_charge(-to_drain)
cell.give(-energy_drained)
if(cell.used_charge() <= 0)
balloon_alert(user, "apc is full!")
return
if(stomach_cell.charge() <= 0)
balloon_alert(user, "out of charge!")
return
// attack with hand - remove cell (if cover open) or interact with the APC
/obj/machinery/power/apc/attack_hand(mob/user, list/modifiers)
@@ -134,3 +168,4 @@
#undef ETHEREAL_APC_DRAIN_TIME
#undef ETHEREAL_APC_POWER_GAIN
#undef ETHEREAL_APC_ALERT_DELAY
+48 -32
View File
@@ -1,6 +1,7 @@
#define CELL_DRAIN_TIME 35
#define CELL_POWER_GAIN (0.06 * STANDARD_CELL_CHARGE)
#define CELL_POWER_DRAIN (0.75 * STANDARD_CELL_CHARGE)
#define ETHEREAL_CELL_DRAIN_TIME (3.5 SECONDS)
#define ETHEREAL_CELL_POWER_DRAIN (0.75 * STANDARD_CELL_CHARGE)
/// The factor by which we multiply drain to get how much we gain
#define ETHEREAL_CELL_POWER_GAIN_FACTOR 0.08
/**
* # Power store abstract type
@@ -288,36 +289,51 @@
tesla_zap(source = src, zap_range = 10, power = discharged_energy)
/obj/item/stock_parts/power_store/attack_self(mob/user)
if(ishuman(user))
var/mob/living/carbon/human/H = user
var/obj/item/organ/stomach/maybe_stomach = H.get_organ_slot(ORGAN_SLOT_STOMACH)
. = ..()
if(.)
return
if(istype(maybe_stomach, /obj/item/organ/stomach/ethereal))
if(!ishuman(user))
return
var/charge_limit = ETHEREAL_CHARGE_DANGEROUS - CELL_POWER_GAIN
var/obj/item/organ/stomach/ethereal/stomach = maybe_stomach
var/obj/item/stock_parts/power_store/stomach_cell = stomach.cell
if((stomach.drain_time > world.time) || !stomach)
return
if(charge < CELL_POWER_DRAIN)
to_chat(H, span_warning("[src] doesn't have enough power!"))
return
if(stomach_cell.charge() > charge_limit)
to_chat(H, span_warning("Your charge is full!"))
return
to_chat(H, span_notice("You begin clumsily channeling power from [src] into your body."))
stomach.drain_time = world.time + CELL_DRAIN_TIME
while(do_after(user, CELL_DRAIN_TIME, target = src))
if((charge < CELL_POWER_DRAIN) || (stomach_cell.charge() > charge_limit))
return
if(istype(stomach))
to_chat(H, span_notice("You receive some charge from [src], wasting some in the process."))
stomach.adjust_charge(CELL_POWER_GAIN)
charge -= CELL_POWER_DRAIN //you waste way more than you receive, so that ethereals cant just steal one cell and forget about hunger
else
to_chat(H, span_warning("You can't receive charge from [src]!"))
var/mob/living/carbon/human/human_user = user
var/obj/item/organ/stomach/ethereal/user_stomach = human_user.get_organ_slot(ORGAN_SLOT_STOMACH)
if(!istype(user_stomach))
return
if(user_stomach.drain_time > world.time)
return
ethereal_drain(human_user, user_stomach)
/// Handles letting an ethereal drain our charge into their stomach
/obj/item/stock_parts/power_store/proc/ethereal_drain(mob/living/carbon/human/user, obj/item/organ/stomach/ethereal/used_stomach)
if(charge() <= 0)
balloon_alert(user, "out of charge!")
return
var/obj/item/stock_parts/power_store/stomach_cell = used_stomach.cell
used_stomach.drain_time = world.time + ETHEREAL_CELL_DRAIN_TIME
to_chat(user, span_notice("You begin clumsily channeling power from [src] into your body."))
while(do_after(user, ETHEREAL_CELL_DRAIN_TIME, target = src))
if(isnull(used_stomach) || (used_stomach != user.get_organ_slot(ORGAN_SLOT_STOMACH)))
balloon_alert(user, "stomach removed!?")
return
var/our_charge = charge()
var/scaled_stomach_used_charge = stomach_cell.used_charge() / ETHEREAL_CELL_POWER_GAIN_FACTOR
var/potential_charge = min(our_charge, scaled_stomach_used_charge)
var/to_drain = min(ETHEREAL_CELL_POWER_DRAIN, potential_charge)
var/energy_drained = use(to_drain, force = TRUE)
used_stomach.adjust_charge(energy_drained * ETHEREAL_CELL_POWER_GAIN_FACTOR)
update_appearance(UPDATE_OVERLAYS)
if(stomach_cell.used_charge() <= 0)
balloon_alert(user, "your charge is full!")
return
if(charge() <= 0)
balloon_alert(user, "out of charge!")
return
/obj/item/stock_parts/power_store/blob_act(obj/structure/blob/B)
SSexplosions.high_mov_atom += src
@@ -328,6 +344,6 @@
/obj/item/stock_parts/power_store/get_part_rating()
return maxcharge * 10 + charge
#undef CELL_DRAIN_TIME
#undef CELL_POWER_GAIN
#undef CELL_POWER_DRAIN
#undef ETHEREAL_CELL_DRAIN_TIME
#undef ETHEREAL_CELL_POWER_DRAIN
#undef ETHEREAL_CELL_POWER_GAIN_FACTOR
@@ -2655,7 +2655,7 @@
var/mob/living/carbon/exposed_carbon = exposed_mob
var/obj/item/organ/stomach/ethereal/stomach = exposed_carbon.get_organ_slot(ORGAN_SLOT_STOMACH)
if(istype(stomach))
stomach.adjust_charge(reac_volume * 0.001 * ETHEREAL_CHARGE_NORMAL)
stomach.adjust_charge(reac_volume * ETHEREAL_DISCHARGE_RATE)
/datum/reagent/consumable/ethanol/telepole
name = "Telepole"
@@ -2675,7 +2675,7 @@
var/mob/living/carbon/exposed_carbon = exposed_mob
var/obj/item/organ/stomach/ethereal/stomach = exposed_carbon.get_organ_slot(ORGAN_SLOT_STOMACH)
if(istype(stomach))
stomach.adjust_charge(reac_volume * 0.008 * ETHEREAL_CHARGE_NORMAL)
stomach.adjust_charge(reac_volume * 8 * ETHEREAL_DISCHARGE_RATE)
/datum/reagent/consumable/ethanol/pod_tesla
name = "Pod Tesla"
@@ -2702,7 +2702,7 @@
var/mob/living/carbon/exposed_carbon = exposed_mob
var/obj/item/organ/stomach/ethereal/stomach = exposed_carbon.get_organ_slot(ORGAN_SLOT_STOMACH)
if(istype(stomach))
stomach.adjust_charge(reac_volume * 0.03 * ETHEREAL_CHARGE_NORMAL)
stomach.adjust_charge(reac_volume * 30 * ETHEREAL_DISCHARGE_RATE)
// Welcome to the Blue Room Bar and Grill, home to Mars' finest cocktails
/datum/reagent/consumable/ethanol/rice_beer
@@ -1296,4 +1296,4 @@
var/mob/living/carbon/exposed_carbon = exposed_mob
var/obj/item/organ/stomach/ethereal/stomach = exposed_carbon.get_organ_slot(ORGAN_SLOT_STOMACH)
if(istype(stomach))
stomach.adjust_charge(reac_volume * 0.02 * ETHEREAL_CHARGE_NORMAL)
stomach.adjust_charge(reac_volume * 20 * ETHEREAL_DISCHARGE_RATE)
@@ -979,7 +979,7 @@
var/mob/living/carbon/exposed_carbon = exposed_mob
var/obj/item/organ/stomach/ethereal/stomach = exposed_carbon.get_organ_slot(ORGAN_SLOT_STOMACH)
if(istype(stomach))
stomach.adjust_charge(reac_volume * 0.03 * ETHEREAL_CHARGE_NORMAL)
stomach.adjust_charge(reac_volume * 30 * ETHEREAL_DISCHARGE_RATE)
/datum/reagent/consumable/liquidelectricity/enriched/on_mob_life(mob/living/carbon/affected_mob, seconds_per_tick, times_fired)
. = ..()