Files
Bubberstation/code/modules/power/rtg.dm
Pickle-Coding c1f11f26ce Converts arbitrary energy units to the joule. Fixes conservation of energy issues relating to charging cells. (#81579)
## About The Pull Request
Removes all arbitrary energy and power units in the codebase. Everything
is replaced with the joule and watt, with 1 = 1 joule, or 1 watt if you
are going to multiply by time. This is a visible change, where all
arbitrary energy units you see in the game will get proper prefixed
units of energy.

With power cells being converted to the joule, charging one joule of a
power cell will require one joule of energy.

The grid will now store energy, instead of power. When an energy usage
is described as using the watt, a power to energy conversion based on
the relevant subsystem's timing (usually multiplying by seconds_per_tick
or applying power_to_energy()) is needed before adding or removing from
the grid. Power usages that are described as the watt is really anything
you would scale by time before applying the load. If it's described as a
joule, no time conversion is needed. Players will still read the grid as
power, having no visible change.

Machines that dynamically use power with the use_power() proc will
directly drain from the grid (and apc cell if there isn't enough)
instead of just tallying it up on the dynamic power usages for the area.
This should be more robust at conserving energy as the surplus is
updated on the go, preventing charging cells from nothing.

APCs no longer consume power for the dynamic power usage channels. APCs
will consume power for static power usages. Because static power usages
are added up without checking surplus, static power consumption will be
applied before any machine processes. This will give a more truthful
surplus for dynamic power consumers.

APCs will display how much power it is using for charging the cell. APC
cell charging applies power in its own channel, which gets added up to
the total. This will prevent invisible power usage you see when looking
at the power monitoring console.

After testing in MetaStation, I found roundstart power consumption to be
around 406kW after all APCs get fully charged. During the roundstart APC
charge rush, the power consumption can get as high as over 2MW (up to
25kW per roundstart APC charging) as long as there's that much
available.

Because of the absurd potential power consumption of charging APCs near
roundstart, I have changed how APCs decide to charge. APCs will now
charge only after all other machines have processed in the machines
processing subsystem. This will make sure APC charging won't disrupt
machines taking from the grid, and should stop APCs getting their power
drained due to others demanding too much power while charging. I have
removed the delays for APC charging too, so they start charging
immediately whenever there's excess power. It also stops them turning
red when a small amount of cell gets drained (airlocks opening and shit
during APC charge rush), as they immediately become fully charged
(unless too much energy got drained somehow) before changing icon.

Engineering SMES now start at 100% charge instead of 75%. I noticed
cells were draining earlier than usual after these changes, so I am
making them start maxed to try and combat that.

These changes will fix all conservation of energy issues relating to
charging powercells.
## Why It's Good For The Game
Closes #73438
Closes #75789
Closes #80634
Closes #82031

Makes it much easier to interface with the power system in the codebase.
It's more intuitive. Removes a bunch of conservation of energy issues,
making energy and power much more meaningful. It will help the
simulation remain immersive as players won't encounter energy
duplication so easily. Arbitrary energy units getting replaced with the
joule will also tell people more meaningful information when reading it.
APC charging will feel more snappy.
## Changelog
🆑
fix: Fixes conservation of energy issues relating to charging
powercells.
qol: APCs will display how much power they are using to charge their
cell. This is accounted for in the power monitoring console.
qol: All arbitrary power cell energy units you see are replaced with
prefixed joules.
balance: As a consequence of the conservation of energy issues getting
fixed, the power consumption for charging cells is now very significant.
balance: APCs only use surplus power from the grid after every machine
processes when charging, preventing APCs from causing others to
discharge while charging.
balance: Engineering SMES start at max charge to combat the increased
energy loss due to conservation of energy fixes.
/🆑

---------

Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2024-03-23 16:58:56 +01:00

160 lines
5.3 KiB
Plaintext

// Radioisotope Thermoelectric Generator (RTG)
// Simple power generator that would replace "magic SMES" on various derelicts.
/obj/machinery/power/rtg
name = "radioisotope thermoelectric generator"
desc = "A simple nuclear power generator, used in small outposts to reliably provide power for decades."
icon = 'icons/obj/machines/engine/other.dmi'
icon_state = "rtg"
density = TRUE
use_power = NO_POWER_USE
circuit = /obj/item/circuitboard/machine/rtg
// You can buckle someone to RTG, then open its panel. Fun stuff.
can_buckle = TRUE
buckle_lying = 0
buckle_requires_restraints = TRUE
var/power_gen = 1000 // Enough to power a single APC. 4000 output with T4 capacitor.
/obj/machinery/power/rtg/Initialize(mapload)
. = ..()
connect_to_network()
/obj/machinery/power/rtg/process()
add_avail(power_to_energy(power_gen))
/obj/machinery/power/rtg/RefreshParts()
. = ..()
var/part_level = 0
for(var/datum/stock_part/stock_part in component_parts)
part_level += stock_part.tier
power_gen = initial(power_gen) * part_level
/obj/machinery/power/rtg/examine(mob/user)
. = ..()
if(in_range(user, src) || isobserver(user))
. += span_notice("The status display reads: Power generation at <b>[display_power(power_gen, convert = FALSE)]</b>.")
/obj/machinery/power/rtg/attackby(obj/item/I, mob/user, params)
if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-open", initial(icon_state), I))
return
else if(default_deconstruction_crowbar(I))
return
return ..()
/obj/machinery/power/rtg/advanced
desc = "An advanced RTG capable of moderating isotope decay, increasing power output but reducing lifetime. It uses plasma-fueled radiation collectors to increase output even further."
power_gen = 1250 // 2500 on T1, 10000 on T4.
circuit = /obj/item/circuitboard/machine/rtg/advanced
// Void Core, power source for Abductor ships and bases.
// Provides a lot of power, but tends to explode when mistreated.
/obj/machinery/power/rtg/abductor
name = "Void Core"
icon = 'icons/obj/antags/abductor.dmi'
icon_state = "core"
desc = "An alien power source that produces energy seemingly out of nowhere."
circuit = /obj/item/circuitboard/machine/abductor/core
power_gen = 20000 // 280 000 at T1, 400 000 at T4. Starts at T4.
can_buckle = FALSE
pixel_y = 7
var/going_kaboom = FALSE // Is it about to explode?
/obj/machinery/power/rtg/abductor/proc/overload()
if(going_kaboom)
return
going_kaboom = TRUE
visible_message(span_danger("\The [src] lets out a shower of sparks as it starts to lose stability!"),\
span_hear("You hear a loud electrical crack!"))
playsound(src.loc, 'sound/magic/lightningshock.ogg', 100, TRUE, extrarange = 5)
tesla_zap(source = src, zap_range = 5, power = power_gen * 20)
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(explosion), src, 2, 3, 4, null, 8), 10 SECONDS) // Not a normal explosion.
/obj/machinery/power/rtg/abductor/bullet_act(obj/projectile/Proj)
. = ..()
if(!going_kaboom && istype(Proj) && Proj.damage > 0 && ((Proj.damage_type == BURN) || (Proj.damage_type == BRUTE)))
log_bomber(Proj.firer, "triggered a", src, "explosion via projectile")
overload()
/obj/machinery/power/rtg/abductor/blob_act(obj/structure/blob/B)
overload()
/obj/machinery/power/rtg/abductor/ex_act()
if(going_kaboom)
qdel(src)
else
overload()
return TRUE
/obj/machinery/power/rtg/abductor/fire_act(exposed_temperature, exposed_volume)
overload()
/obj/machinery/power/rtg/abductor/zap_act(power, zap_flags)
. = ..() //extend the zap
if(zap_flags & ZAP_MACHINE_EXPLOSIVE)
overload()
/obj/machinery/power/rtg/debug
name = "Debug RTG"
desc = "You really shouldn't be seeing this if you're not a coder or jannie."
power_gen = 20000
circuit = null
/obj/machinery/power/rtg/debug/RefreshParts()
SHOULD_CALL_PARENT(FALSE)
return
/obj/machinery/power/rtg/lavaland
name = "Lava powered RTG"
desc = "This device only works when exposed to the toxic fumes of Lavaland"
circuit = null
power_gen = 1500
anchored = TRUE
resistance_flags = LAVA_PROOF
/obj/machinery/power/rtg/lavaland/Initialize(mapload)
. = ..()
var/turf/our_turf = get_turf(src)
if(!islava(our_turf))
power_gen = 0
if(!is_mining_level(z))
power_gen = 0
/obj/machinery/power/rtg/lavaland/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE)
. = ..()
var/turf/our_turf = get_turf(src)
if(!islava(our_turf))
power_gen = 0
return
if(!is_mining_level(z))
power_gen = 0
return
power_gen = initial(power_gen)
/obj/machinery/power/rtg/old_station
name = "Old RTG"
desc = "A very old RTG, it seems on the verge of being destroyed"
circuit = null
power_gen = 750
anchored = TRUE
/obj/machinery/power/rtg/old_station/attackby(obj/item/I, mob/user, params)
if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-open", initial(icon_state), I))
to_chat(user,span_warning("You feel it crumbling under your hands!"))
return
else if(default_deconstruction_crowbar(I, user = user))
return
return ..()
/obj/machinery/power/rtg/old_station/default_deconstruction_crowbar(obj/item/crowbar, ignore_panel, custom_deconstruct, mob/user)
to_chat(user,span_warning("It's starting to fall off!"))
if(!do_after(user, 3 SECONDS, src))
return TRUE
to_chat(user,span_notice("You feel like you made a mistake"))
new /obj/effect/decal/cleanable/ash/large(loc)
qdel(src)