mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-25 17:12:12 +00:00
* Power generation (collectors, coils, grounding rods) cleanup (#62144) * Energy collection: Mass rework Radiation Collectors and Tesla Coils are now subtyles of a common energy_accumulator type. This type combines common code such as smoothing output over energy received, computing power output, and handling wire connections. Inline calculations using machine energy units are now performed by common math functions in maths.dm. Rather than reference 0.1, 1 SECONDS is used to make it clear this is to calculate to and from tickrate dependent units. Constants which are written in terms of tickrate dependent units are now written in terms of joules, and use these helpers to convert to and from these units. With SSmachines.wait / (1 SECONDS) being 2, this usually means doubling the values of constants which were previously defined in terms of machine energy units. * Energy collection: Map path update > git ls-files | grep dmm | xargs sed -i 's1rad_collector1energy_accumulator/&1g' > git ls-files | grep dmm | xargs sed -i 's1tesla_coil1energy_accumulator/&1g' > git ls-files | grep dmm | xargs sed -i 's1grounding_rod1energy_accumulator/&1g' * Power generation (collectors, coils, grounding rods) cleanup * object path update (#8882) * [MDB IGNORE] Missed some paths (#8886) * object path update * oops missed a couple paths Co-authored-by: esainane <esainane+github@gmail.com> Co-authored-by: ORCACommander <orcacommander1@gmail.com>
57 lines
2.4 KiB
Plaintext
57 lines
2.4 KiB
Plaintext
/// (this*100)% of stored power outputted per tick.
|
|
/// Doesn't change output total, lower numbers just increases the smoothing - taking longer to ramp up, and longer to drop away.
|
|
/// 4% means an accumulator, when starting up for the first time:
|
|
/// - emits 50% of what is being received after 40 seconds
|
|
/// - emits 90% of what is being received after two minutes
|
|
/// - emits 99% of what is being received after four minutes
|
|
/// after having stored energy for at least 4-5 minutes, then dropping input to nothing:
|
|
/// - emits 50% of what was previously being received after 40 seconds
|
|
/// - emits 25% of what was previously being received after 79 seconds
|
|
/// - emits 10% of what was previously being received after two minutes
|
|
/// - emits 1% of what was previously being received after four minutes
|
|
#define ACCUMULATOR_STORED_OUTPUT 0.04
|
|
|
|
/// Abstract type for generators that accumulate energy over time and slowly release it
|
|
/// eg. radiation collectors, tesla coils
|
|
/obj/machinery/power/energy_accumulator
|
|
anchored = FALSE
|
|
density = TRUE
|
|
///Whether this accumulator should connect to and power a powernet
|
|
var/wants_powernet = TRUE
|
|
///The amount of energy that is currently inside the machine before being converted to electricity
|
|
var/stored_energy = 0
|
|
|
|
/obj/machinery/power/energy_accumulator/proc/get_stored_joules()
|
|
return energy_to_joules(stored_energy)
|
|
|
|
/obj/machinery/power/energy_accumulator/proc/get_power_output()
|
|
// Always consume at least 2kJ of energy if we have at least that much stored
|
|
return min(stored_energy, (stored_energy*ACCUMULATOR_STORED_OUTPUT)+joules_to_energy(2000))
|
|
|
|
/obj/machinery/power/energy_accumulator/process(delta_time)
|
|
// NB: stored_energy is stored in energy units, a unit of measurement which already includes SSmachines.wait
|
|
// Do not multiply by delta_time here. It is already accounted for by being energy units.
|
|
var/power_produced = get_power_output()
|
|
release_energy(power_produced)
|
|
stored_energy -= power_produced
|
|
|
|
/obj/machinery/power/energy_accumulator/proc/release_energy(power_produced)
|
|
if(wants_powernet)
|
|
add_avail(power_produced)
|
|
|
|
/obj/machinery/power/energy_accumulator/should_have_node()
|
|
return wants_powernet && anchored
|
|
|
|
/obj/machinery/power/energy_accumulator/set_anchored(anchorvalue)
|
|
. = ..()
|
|
if(isnull(.))
|
|
return //no need to process if we didn't change anything.
|
|
if(!wants_powernet)
|
|
return
|
|
if(!anchorvalue)
|
|
disconnect_from_network()
|
|
return
|
|
connect_to_network()
|
|
|
|
#undef ACCUMULATOR_STORED_OUTPUT
|