diff --git a/.github/guides/STYLE.md b/.github/guides/STYLE.md index 9c462b99df648..63de3a5d21030 100644 --- a/.github/guides/STYLE.md +++ b/.github/guides/STYLE.md @@ -457,7 +457,7 @@ deal_damage(10) // Fine! The proc name makes it obvious `10` is the damage...at deal_damage(10, FIRE) // Also fine! `FIRE` makes it obvious the second parameter is damage type. deal_damage(damage = 10) // Redundant, but not prohibited. -use_power(30) // Fine! `30` is obviously something like watts. +use_energy(30 JOULES) // Use energy in joules. turn_on(30) // Not fine! turn_on(power_usage = 30) // Fine! diff --git a/_maps/shuttles/emergency_medisim.dmm b/_maps/shuttles/emergency_medisim.dmm index 0780ea89d20e6..4e62c20d74b65 100644 --- a/_maps/shuttles/emergency_medisim.dmm +++ b/_maps/shuttles/emergency_medisim.dmm @@ -701,7 +701,7 @@ iron_cost = 0; maximum_idle = 1; name = "binoculars fabricator"; - power_used = 0; + energy_used = 0; starting_amount = 25000 }, /turf/open/floor/mineral/titanium/yellow, diff --git a/code/__DEFINES/apc_defines.dm b/code/__DEFINES/apc_defines.dm index 4cc5e31cb10d1..3ce6e4a873c85 100644 --- a/code/__DEFINES/apc_defines.dm +++ b/code/__DEFINES/apc_defines.dm @@ -58,7 +58,7 @@ /// How long it takes an ethereal to drain or charge APCs. Also used as a spam limiter. #define APC_DRAIN_TIME (7.5 SECONDS) /// How much power ethereals gain/drain from APCs. -#define APC_POWER_GAIN 200 +#define APC_POWER_GAIN (200 KILO JOULES) // Wires & EMPs: /// The wire value used to reset the APCs wires after one's EMPed. diff --git a/code/__DEFINES/combat.dm b/code/__DEFINES/combat.dm index e9b6d0ce31457..847fd52cc2232 100644 --- a/code/__DEFINES/combat.dm +++ b/code/__DEFINES/combat.dm @@ -389,3 +389,8 @@ GLOBAL_LIST_INIT(arm_zones, list(BODY_ZONE_L_ARM, BODY_ZONE_R_ARM)) #define DEATHMATCH_NOT_PLAYING 0 #define DEATHMATCH_PRE_PLAYING 1 #define DEATHMATCH_PLAYING 2 + +/// The amount of energy needed to increase the burn force by 1 damage during electrocution. +#define JOULES_PER_DAMAGE (25 KILO JOULES) +/// Calculates the amount of burn force when applying this much energy to a mob via electrocution from an energy source. +#define ELECTROCUTE_DAMAGE(energy) (energy >= 1 KILO JOULES ? clamp(20 + round(energy / JOULES_PER_DAMAGE), 20, 195) + rand(-5,5) : 0) diff --git a/code/__DEFINES/devices.dm b/code/__DEFINES/devices.dm index 5e63d9bd6d398..8f98f040dbcee 100644 --- a/code/__DEFINES/devices.dm +++ b/code/__DEFINES/devices.dm @@ -8,8 +8,8 @@ #define INSPECTOR_PRINT_SOUND_MODE_FAFAFOGGY 4 #define BANANIUM_CLOWN_INSPECTOR_PRINT_SOUND_MODE_LAST 4 #define CLOWN_INSPECTOR_PRINT_SOUND_MODE_LAST 4 -#define INSPECTOR_POWER_USAGE_HONK 15 -#define INSPECTOR_POWER_USAGE_NORMAL 5 +#define INSPECTOR_ENERGY_USAGE_HONK (15 KILO JOULES) +#define INSPECTOR_ENERGY_USAGE_NORMAL (5 KILO JOULES) #define INSPECTOR_TIME_MODE_SLOW 1 #define INSPECTOR_TIME_MODE_FAST 2 #define INSPECTOR_TIME_MODE_HONK 3 diff --git a/code/__DEFINES/machines.dm b/code/__DEFINES/machines.dm index cbcab503b4193..2c63f2568dcf3 100644 --- a/code/__DEFINES/machines.dm +++ b/code/__DEFINES/machines.dm @@ -6,7 +6,8 @@ #define AREA_USAGE_STATIC_EQUIP 4 #define AREA_USAGE_STATIC_LIGHT 5 #define AREA_USAGE_STATIC_ENVIRON 6 -#define AREA_USAGE_LEN AREA_USAGE_STATIC_ENVIRON // largest idx +#define AREA_USAGE_APC_CHARGE 7 +#define AREA_USAGE_LEN AREA_USAGE_APC_CHARGE // largest idx /// Index of the first dynamic usage channel #define AREA_USAGE_DYNAMIC_START AREA_USAGE_EQUIP @@ -27,8 +28,8 @@ #define ACTIVE_POWER_USE 2 ///Base global power consumption for idling machines -#define BASE_MACHINE_IDLE_CONSUMPTION 100 -///Base global power consumption for active machines +#define BASE_MACHINE_IDLE_CONSUMPTION (100 WATTS) +///Base global power consumption for active machines. The unit is ambiguous (joules or watts) depending on the use case for dynamic users. #define BASE_MACHINE_ACTIVE_CONSUMPTION (BASE_MACHINE_IDLE_CONSUMPTION * 10) /// Bitflags for a machine's preferences on when it should start processing. For use with machinery's `processing_flags` var. diff --git a/code/__DEFINES/mobs.dm b/code/__DEFINES/mobs.dm index d20c8dba8a56d..5e6cec96cba82 100644 --- a/code/__DEFINES/mobs.dm +++ b/code/__DEFINES/mobs.dm @@ -289,14 +289,14 @@ //Used as an upper limit for species that continuously gain nutriment #define NUTRITION_LEVEL_ALMOST_FULL 535 -//Charge levels for Ethereals +//Charge levels for Ethereals, in joules. #define ETHEREAL_CHARGE_NONE 0 -#define ETHEREAL_CHARGE_LOWPOWER 400 -#define ETHEREAL_CHARGE_NORMAL 1000 -#define ETHEREAL_CHARGE_ALMOSTFULL 1500 -#define ETHEREAL_CHARGE_FULL 2000 -#define ETHEREAL_CHARGE_OVERLOAD 2500 -#define ETHEREAL_CHARGE_DANGEROUS 3000 +#define ETHEREAL_CHARGE_LOWPOWER (400 KILO JOULES) +#define ETHEREAL_CHARGE_NORMAL (1 MEGA JOULES) +#define ETHEREAL_CHARGE_ALMOSTFULL (1.5 MEGA JOULES) +#define ETHEREAL_CHARGE_FULL (2 MEGA JOULES) +#define ETHEREAL_CHARGE_OVERLOAD (2.5 MEGA JOULES) +#define ETHEREAL_CHARGE_DANGEROUS (3 MEGA JOULES) #define CRYSTALIZE_COOLDOWN_LENGTH (120 SECONDS) diff --git a/code/__DEFINES/mod.dm b/code/__DEFINES/mod.dm index e0b7d6ff4a399..be59793927f07 100644 --- a/code/__DEFINES/mod.dm +++ b/code/__DEFINES/mod.dm @@ -1,8 +1,8 @@ /// Default value for the max_complexity var on MODsuits #define DEFAULT_MAX_COMPLEXITY 15 -/// Default cell drain per process on MODsuits -#define DEFAULT_CHARGE_DRAIN 5 +/// The default cell drain of a modsuit. The standard modsuit active power usage drains this much energy per modsuit second. +#define DEFAULT_CHARGE_DRAIN (0.005 * STANDARD_CELL_CHARGE) // A standard cell lasts 200 seconds with this on active power usage, while a high power one lasts 2,000 seconds. /// Default time for a part to seal #define MOD_ACTIVATION_STEP_TIME (2 SECONDS) diff --git a/code/__DEFINES/power.dm b/code/__DEFINES/power.dm index 65c83dd65454a..0eda3669a7123 100644 --- a/code/__DEFINES/power.dm +++ b/code/__DEFINES/power.dm @@ -10,12 +10,19 @@ #define SOLAR_TRACK_TIMED 1 #define SOLAR_TRACK_AUTO 2 -///conversion ratio from joules to watts -#define WATTS / 0.002 -///conversion ratio from watts to joules -#define JOULES * 0.002 +///The watt is the standard unit of power for this codebase. Do not change this. +#define WATT 1 +///The joule is the standard unit of energy for this codebase. Do not change this. +#define JOULE 1 +///The watt is the standard unit of power for this codebase. You can use this with other defines to clarify that it will be multiplied by time. +#define WATTS * WATT +///The joule is the standard unit of energy for this codebase. You can use this with other defines to clarify that it will not be multiplied by time. +#define JOULES * JOULE -GLOBAL_VAR_INIT(CHARGELEVEL, 0.001) // Cap for how fast cells charge, as a percentage-per-tick (.001 means cellcharge is capped to 1% per second) +///The amount of energy, in joules, a standard powercell has. +#define STANDARD_CELL_CHARGE (1 MEGA JOULES) // 1 MJ. + +GLOBAL_VAR_INIT(CHARGELEVEL, 0.01) // Cap for how fast cells charge, as a percentage per second (.01 means cellcharge is capped to 1% per second) // Converts cable layer to its human readable name GLOBAL_LIST_INIT(cable_layer_to_name, list( diff --git a/code/__DEFINES/projectiles.dm b/code/__DEFINES/projectiles.dm index 58f25ac39f112..e471fe2324d93 100644 --- a/code/__DEFINES/projectiles.dm +++ b/code/__DEFINES/projectiles.dm @@ -82,8 +82,9 @@ #define RETURN_POINT_VECTOR(ATOM, ANGLE, SPEED) (new /datum/point/vector(ATOM, null, null, null, null, ANGLE, SPEED)) #define RETURN_POINT_VECTOR_INCREMENT(ATOM, ANGLE, SPEED, AMT) (new /datum/point/vector(ATOM, null, null, null, null, ANGLE, SPEED, AMT)) -/// The amount of energy that a standard energy weapon cell can hold -#define STANDARD_CELL_CHARGE 1000 +///The self charging rate of energy guns that magically recharge themselves, in watts. +#define STANDARD_ENERGY_GUN_SELF_CHARGE_RATE (0.05 * STANDARD_CELL_CHARGE) + /// Macro to turn a number of laser shots into an energy cost, based on the above define /// e.g. LASER_SHOTS(12, STANDARD_CELL_CHARGE) means 12 shots #define LASER_SHOTS(X, MAX_CHARGE) (((100 * MAX_CHARGE) - ((100 * MAX_CHARGE) % X)) / (100 * X)) // I wish I could just use round, but it can't be used in datum members diff --git a/code/__DEFINES/robots.dm b/code/__DEFINES/robots.dm index 73351de60f2c4..4ec8e1294c312 100644 --- a/code/__DEFINES/robots.dm +++ b/code/__DEFINES/robots.dm @@ -34,6 +34,10 @@ /// Special value to reset cyborg's lamp_cooldown #define BORG_LAMP_CD_RESET -1 +/// How many watts per lamp power is consumed while the lamp is on. +#define BORG_LAMP_POWER_CONSUMPTION (1000 WATTS) +/// The minimum power consumption of a cyborg. +#define BORG_MINIMUM_POWER_CONSUMPTION (500 WATTS) //Module slot define ///The third module slots is disabed. diff --git a/code/__DEFINES/si.dm b/code/__DEFINES/si.dm new file mode 100644 index 0000000000000..b63f048e0b3b2 --- /dev/null +++ b/code/__DEFINES/si.dm @@ -0,0 +1,21 @@ +// Prefix values. +#define QUECTO * 1e-30 +#define RONTO * 1e-27 +#define YOCTO * 1e-24 +#define ZEPTO * 1e-21 +#define ATTO * 1e-18 +#define FEMPTO * 1e-15 +#define PICO * 1e-12 +#define NANO * 1e-9 +#define MICRO * 1e-6 +#define MILLI * 1e-3 +#define KILO * 1e3 +#define MEGA * 1e6 +#define GIGA * 1e9 +#define TERA * 1e12 +#define PETA * 1e15 +#define EXA * 1e18 +#define ZETTA * 1e21 +#define YOTTA * 1e24 +#define RONNA * 1e27 +#define QUETTA * 1e30 diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 5e20cdef2b987..6d04fca876b48 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -297,6 +297,11 @@ #define SSEXPLOSIONS_MOVABLES 2 #define SSEXPLOSIONS_THROWS 3 +// Machines subsystem subtasks. +#define SSMACHINES_APCS_EARLY 1 +#define SSMACHINES_MACHINES 2 +#define SSMACHINES_APCS_LATE 3 + // Wardrobe subsystem tasks #define SSWARDROBE_STOCK 1 #define SSWARDROBE_INSPECT 2 diff --git a/code/__HELPERS/maths.dm b/code/__HELPERS/maths.dm index ead9d54ebaa5f..e3c6ad49c4e06 100644 --- a/code/__HELPERS/maths.dm +++ b/code/__HELPERS/maths.dm @@ -154,27 +154,28 @@ var/prefix = prefixes[prefix_index] . = list(SI_COEFFICIENT = coefficient, SI_UNIT = " [prefix][unit]") -///Format a power value in prefixed watts. -/proc/display_power(powerused) - return siunit(powerused, "W", 3) +/**Format a power value in prefixed watts. + * Converts from energy if convert is true. + * Args: + * - power: The value of power to format. + * - convert: Whether to convert this from joules. + * Returns: The string containing the formatted power. + */ +/proc/display_power(power, convert = TRUE) + power = convert ? energy_to_power(power) : power + return siunit(power, "W", 3) ///Format an energy value in prefixed joules. -/proc/display_joules(units) +/proc/display_energy(units) return siunit(units, "J", 3) -/proc/joules_to_energy(joules) +///Converts the joule to the watt, assuming SSmachines tick rate. +/proc/energy_to_power(joules) return joules * (1 SECONDS) / SSmachines.wait -/proc/energy_to_joules(energy_units) - return energy_units * SSmachines.wait / (1 SECONDS) - -///Format an energy value measured in Power Cell units. -/proc/display_energy(units) - // APCs process every (SSmachines.wait * 0.1) seconds, and turn 1 W of - // excess power into watts when charging cells. - // With the current configuration of wait=20 and CELLRATE=0.002, this - // means that one unit is 1 kJ. - return display_joules(energy_to_joules(units) WATTS) +///Converts the watt to the joule, assuming SSmachines tick rate. +/proc/power_to_energy(watts) + return watts * SSmachines.wait / (1 SECONDS) ///chances are 1:value. anyprob(1) will always return true /proc/anyprob(value) diff --git a/code/controllers/subsystem/machines.dm b/code/controllers/subsystem/machines.dm index 8a0b17f195bc4..3e07eca8a2e87 100644 --- a/code/controllers/subsystem/machines.dm +++ b/code/controllers/subsystem/machines.dm @@ -12,6 +12,9 @@ SUBSYSTEM_DEF(machines) var/list/processing = list() var/list/currentrun = list() + var/list/apc_early_processing = list() + var/list/apc_late_processing = list() + var/current_part = SSMACHINES_APCS_EARLY ///List of all powernets on the server. var/list/datum/powernet/powernets = list() @@ -43,7 +46,7 @@ SUBSYSTEM_DEF(machines) for(var/next_type in typesof(machine_type)) var/list/found_machines = machines_by_type[next_type] if(found_machines) - machines += found_machines + machines += found_machines return machines @@ -79,19 +82,52 @@ SUBSYSTEM_DEF(machines) if (!resumed) for(var/datum/powernet/powernet as anything in powernets) powernet.reset() //reset the power state. + current_part = SSMACHINES_APCS_EARLY + src.currentrun = apc_early_processing.Copy() + + //APC early processing. Draws static power usages from their grids. + if(current_part == SSMACHINES_APCS_EARLY) + //cache for sanic speed (lists are references anyways) + var/list/currentrun = src.currentrun + while(currentrun.len) + var/obj/machinery/power/apc/apc = currentrun[currentrun.len] + currentrun.len-- + if(QDELETED(apc) || apc.early_process(wait * 0.1) == PROCESS_KILL) + apc_early_processing -= apc + apc.datum_flags &= ~DF_ISPROCESSING + if(MC_TICK_CHECK) + return + current_part = SSMACHINES_MACHINES src.currentrun = processing.Copy() - //cache for sanic speed (lists are references anyways) - var/list/currentrun = src.currentrun - - while(currentrun.len) - var/obj/machinery/thing = currentrun[currentrun.len] - currentrun.len-- - if(QDELETED(thing) || thing.process(wait * 0.1) == PROCESS_KILL) - processing -= thing - thing.datum_flags &= ~DF_ISPROCESSING - if (MC_TICK_CHECK) - return + //General machine processing. Their power usage can be dynamic and based on surplus power, so they come after static power usage have been applied. + if(current_part == SSMACHINES_MACHINES) + //cache for sanic speed (lists are references anyways) + var/list/currentrun = src.currentrun + while(currentrun.len) + var/obj/machinery/thing = currentrun[currentrun.len] + currentrun.len-- + if(QDELETED(thing) || thing.process(wait * 0.1) == PROCESS_KILL) + processing -= thing + thing.datum_flags &= ~DF_ISPROCESSING + if (MC_TICK_CHECK) + return + current_part = SSMACHINES_APCS_LATE + src.currentrun = apc_late_processing.Copy() + + //APC late processing. APCs will use the remaining power on the grid to charge their cells if needed. + //This is applied at the end so charging APCs don't cause others to discharge by taking all the power from the grid before machines use power. + if(current_part == SSMACHINES_APCS_LATE) + //cache for sanic speed (lists are references anyways) + var/list/currentrun = src.currentrun + while(currentrun.len) + var/obj/machinery/power/apc/apc = currentrun[currentrun.len] + currentrun.len-- + if(QDELETED(apc) || apc.late_process(wait * 0.1) == PROCESS_KILL) + apc_late_processing -= apc + apc.datum_flags &= ~DF_ISPROCESSING + if(MC_TICK_CHECK) + return /datum/controller/subsystem/machines/proc/setup_template_powernets(list/cables) var/obj/structure/cable/PC diff --git a/code/datums/components/shell.dm b/code/datums/components/shell.dm index 4646d30fc3123..53d0ebc6505d4 100644 --- a/code/datums/components/shell.dm +++ b/code/datums/components/shell.dm @@ -294,7 +294,7 @@ if(attached_circuit) remove_circuit() return - location.use_power(power_to_use, AREA_USAGE_EQUIP) + location.apc?.terminal?.use_energy(power_to_use, channel = AREA_USAGE_EQUIP) power_used_in_minute += power_to_use COOLDOWN_START(src, power_used_cooldown, 1 MINUTES) return COMPONENT_OVERRIDE_POWER_USAGE @@ -327,7 +327,7 @@ else if(circuitboard.loc != parent_atom) circuitboard.forceMove(parent_atom) attached_circuit.set_shell(parent_atom) - + // call after set_shell() sets on to true if(shell_flags & SHELL_FLAG_REQUIRE_ANCHOR) attached_circuit.set_on(parent_atom.anchored) diff --git a/code/datums/mutations/touch.dm b/code/datums/mutations/touch.dm index 743f2b3fbf83b..ca94f109ac664 100644 --- a/code/datums/mutations/touch.dm +++ b/code/datums/mutations/touch.dm @@ -38,7 +38,7 @@ ///This var decides if the spell should chain, dictated by presence of power chromosome var/chain = FALSE ///Affects damage, should do about 1 per limb - var/zap_power = 7500 + var/zap_power = 7.5 KILO JOULES ///Range of tesla shock bounces var/zap_range = 7 ///flags that dictate what the tesla shock can interact with, Can only damage mobs, Cannot damage machines or generate energy @@ -60,7 +60,7 @@ span_userdanger("[caster] electrocutes you!"), ) if(chain) - tesla_zap(source = victim, zap_range = zap_range, power = zap_power, cutoff = 1e3, zap_flags = zap_flags) + tesla_zap(source = victim, zap_range = zap_range, power = zap_power, cutoff = 1 KILO JOULES, zap_flags = zap_flags) carbon_victim.visible_message(span_danger("An arc of electricity explodes out of [victim]!")) return TRUE @@ -72,7 +72,7 @@ span_userdanger("[caster] electrocutes you!"), ) if(chain) - tesla_zap(source = victim, zap_range = zap_range, power = zap_power, cutoff = 1e3, zap_flags = zap_flags) + tesla_zap(source = victim, zap_range = zap_range, power = zap_power, cutoff = 1 KILO JOULES, zap_flags = zap_flags) living_victim.visible_message(span_danger("An arc of electricity explodes out of [victim]!")) return TRUE diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 05334d78851aa..347dfc480b95f 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -79,6 +79,7 @@ var/power_equip = TRUE var/power_light = TRUE var/power_environ = TRUE + var/power_apc_charge = TRUE var/has_gravity = FALSE @@ -105,7 +106,8 @@ ///Typepath to limit the areas (subtypes included) that atoms in this area can smooth with. Used for shuttles. var/area/area_limited_icon_smoothing - var/list/power_usage + /// The energy usage of the area in the last machines SS tick. + var/list/energy_usage /// Wire assignment for airlocks in this area var/airlock_wires = /datum/wires/airlock @@ -161,7 +163,7 @@ GLOBAL_LIST_EMPTY(teleportlocs) if (area_flags & UNIQUE_AREA) GLOB.areas_by_type[type] = src GLOB.areas += src - power_usage = new /list(AREA_USAGE_LEN) // Some atoms would like to use power in Initialize() + energy_usage = new /list(AREA_USAGE_LEN) // Some atoms would like to use power in Initialize() alarm_manager = new(src) // just in case return ..() @@ -473,7 +475,7 @@ GLOBAL_LIST_EMPTY(teleportlocs) /** - * Add a static amount of power load to an area + * Add a static amount of power load to an area. The value is assumed as the watt. * * Possible channels * *AREA_USAGE_STATIC_EQUIP @@ -481,12 +483,13 @@ GLOBAL_LIST_EMPTY(teleportlocs) * *AREA_USAGE_STATIC_ENVIRON */ /area/proc/addStaticPower(value, powerchannel) + value = power_to_energy(value) switch(powerchannel) if(AREA_USAGE_STATIC_START to AREA_USAGE_STATIC_END) - power_usage[powerchannel] += value + energy_usage[powerchannel] += value /** - * Remove a static amount of power load to an area + * Remove a static amount of power load to an area. The value is assumed as the watt. * * Possible channels * *AREA_USAGE_STATIC_EQUIP @@ -494,9 +497,10 @@ GLOBAL_LIST_EMPTY(teleportlocs) * *AREA_USAGE_STATIC_ENVIRON */ /area/proc/removeStaticPower(value, powerchannel) + value = power_to_energy(value) switch(powerchannel) if(AREA_USAGE_STATIC_START to AREA_USAGE_STATIC_END) - power_usage[powerchannel] -= value + energy_usage[powerchannel] -= value /** * Clear all non-static power usage in area @@ -504,18 +508,21 @@ GLOBAL_LIST_EMPTY(teleportlocs) * Clears all power used for the dynamic equipment, light and environment channels */ /area/proc/clear_usage() - power_usage[AREA_USAGE_EQUIP] = 0 - power_usage[AREA_USAGE_LIGHT] = 0 - power_usage[AREA_USAGE_ENVIRON] = 0 + energy_usage[AREA_USAGE_EQUIP] = 0 + energy_usage[AREA_USAGE_LIGHT] = 0 + energy_usage[AREA_USAGE_ENVIRON] = 0 + energy_usage[AREA_USAGE_APC_CHARGE] = 0 /** * Add a power value amount to the stored used_x variables */ -/area/proc/use_power(amount, chan) +/area/proc/use_energy(amount, chan) switch(chan) - if(AREA_USAGE_DYNAMIC_START to AREA_USAGE_DYNAMIC_END) - power_usage[chan] += amount + if(AREA_USAGE_STATIC_START to AREA_USAGE_STATIC_END) + return + else + energy_usage[chan] += amount /** * Call back when an atom enters an area diff --git a/code/game/area/areas/holodeck.dm b/code/game/area/areas/holodeck.dm index b0691803bb723..9a0ef3711e4d5 100644 --- a/code/game/area/areas/holodeck.dm +++ b/code/game/area/areas/holodeck.dm @@ -33,7 +33,7 @@ ASSERT(!istype(A, /area/station/holodeck)) return ..() -/area/station/holodeck/use_power(amount, chan) +/area/station/holodeck/use_energy(amount, chan) if(!linked) return FALSE var/area/A = get_area(linked) diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 86c9c6274bf51..b4d4c4d3cea7c 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -57,13 +57,13 @@ * * * Default definition uses 'use_power', 'power_channel', 'active_power_usage', - * 'idle_power_usage', 'powered()', and 'use_power()' implement behavior. + * 'idle_power_usage', 'powered()', and 'use_energy()' implement behavior. * * powered(chan = -1) 'modules/power/power.dm' * Checks to see if area that contains the object has power available for power * channel given in 'chan'. -1 defaults to power_channel * - * use_power(amount, chan=-1) 'modules/power/power.dm' + * use_energy(amount, chan=-1) 'modules/power/power.dm' * Deducts 'amount' from the power channel 'chan' of the area that contains the object. * * power_change() 'modules/power/power.dm' @@ -304,7 +304,7 @@ . = ..() if(!use_power || machine_stat || (. & EMP_PROTECT_SELF)) return - use_power(7500/severity) + use_energy(7.5 KILO JOULES / severity) new /obj/effect/temp_visual/emp(loc) if(!prob(70/severity)) diff --git a/code/game/machinery/announcement_system.dm b/code/game/machinery/announcement_system.dm index df3e402525d16..edb945f483e9c 100644 --- a/code/game/machinery/announcement_system.dm +++ b/code/game/machinery/announcement_system.dm @@ -99,7 +99,7 @@ GLOBAL_LIST_EMPTY(announcement_systems) /// Sends a message to the appropriate channels. /obj/machinery/announcement_system/proc/broadcast(message, list/channels) - use_power(active_power_usage) + use_energy(active_power_usage) if(channels.len == 0) radio.talk_into(src, message, null) else diff --git a/code/game/machinery/autolathe.dm b/code/game/machinery/autolathe.dm index 4649d5ac20c23..9536d645247de 100644 --- a/code/game/machinery/autolathe.dm +++ b/code/game/machinery/autolathe.dm @@ -4,7 +4,8 @@ icon = 'icons/obj/machines/lathes.dmi' icon_state = "autolathe" density = TRUE - active_power_usage = BASE_MACHINE_ACTIVE_CONSUMPTION * 0.5 + //Energy cost per full stack of sheets worth of materials used. Material insertion is 40% of this. + active_power_usage = 25 * BASE_MACHINE_ACTIVE_CONSUMPTION circuit = /obj/item/circuitboard/machine/autolathe layer = BELOW_OBJ_LAYER processing_flags = NONE @@ -96,7 +97,7 @@ SIGNAL_HANDLER //we use initial(active_power_usage) because higher tier parts will have higher active usage but we have no benifit from it - if(directly_use_power(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.02 * initial(active_power_usage)))) + if(directly_use_energy(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.4 * initial(active_power_usage)))) flick_overlay_view(mutable_appearance('icons/obj/machines/lathes.dmi', "autolathe_mat"), 1 SECONDS) var/datum/material/highest_mat_ref @@ -283,7 +284,7 @@ var/charge_per_item = 0 for(var/material in design.materials) charge_per_item += design.materials[material] - charge_per_item = ROUND_UP((charge_per_item / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * material_cost_coefficient * 0.05 * active_power_usage) + charge_per_item = ROUND_UP((charge_per_item / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * material_cost_coefficient * active_power_usage) var/build_time_per_item = (design.construction_time * design.lathe_time_factor) ** 0.8 //do the printing sequentially @@ -320,7 +321,7 @@ finalize_build() return - if(!is_operational || !directly_use_power(charge_per_item)) + if(!is_operational || !directly_use_energy(charge_per_item)) say("Unable to continue production, power failure.") finalize_build() return diff --git a/code/game/machinery/botlaunchpad.dm b/code/game/machinery/botlaunchpad.dm index 0744954257a3c..c8004af84ba86 100644 --- a/code/game/machinery/botlaunchpad.dm +++ b/code/game/machinery/botlaunchpad.dm @@ -44,6 +44,10 @@ user.balloon_alert(user, "too many bots on the pad!") return possible_bot = robot // We don't change the launched_bot var here because we are not sure if there is another bot on the pad. + + if(!use_energy(active_power_usage, force = FALSE)) + balloon_alert(user, "not enough energy!") + return launched_bot = WEAKREF(possible_bot) podspawn(list( "target" = get_turf(src), @@ -51,7 +55,6 @@ "style" = STYLE_SEETHROUGH, "reverse_dropoff_coords" = list(reverse_turf.x, reverse_turf.y, reverse_turf.z) )) - use_power(active_power_usage) /obj/machinery/botpad/proc/recall(mob/living/user) var/atom/our_bot = launched_bot?.resolve() diff --git a/code/game/machinery/buttons.dm b/code/game/machinery/buttons.dm index ccb21be468c3f..552afbb4ed81a 100644 --- a/code/game/machinery/buttons.dm +++ b/code/game/machinery/buttons.dm @@ -228,7 +228,7 @@ flick_overlay_view("[base_icon_state]-overlay-error", 1 SECONDS) return - use_power(5) + use_energy(5 JOULES) flick_overlay_view("[base_icon_state]-overlay-success", 1 SECONDS) if(device) diff --git a/code/game/machinery/cell_charger.dm b/code/game/machinery/cell_charger.dm index 7cc10dcb840a7..aaa24526da5e5 100644 --- a/code/game/machinery/cell_charger.dm +++ b/code/game/machinery/cell_charger.dm @@ -7,7 +7,7 @@ circuit = /obj/item/circuitboard/machine/cell_charger pass_flags = PASSTABLE var/obj/item/stock_parts/cell/charging = null - var/charge_rate = 250 + var/charge_rate = 250 KILO WATTS /obj/machinery/cell_charger/update_overlays() . = ..() @@ -31,7 +31,7 @@ if(charging) . += "Current charge: [round(charging.percent(), 1)]%." if(in_range(user, src) || isobserver(user)) - . += span_notice("The status display reads: Charging power: [charge_rate]W.") + . += span_notice("The status display reads: Charging power: [display_power(charge_rate, convert = FALSE)].") /obj/machinery/cell_charger/wrench_act(mob/living/user, obj/item/tool) . = ..() @@ -125,7 +125,7 @@ /obj/machinery/cell_charger/RefreshParts() . = ..() - charge_rate = 250 + charge_rate = 250 KILO WATTS for(var/datum/stock_part/capacitor/capacitor in component_parts) charge_rate *= capacitor.tier @@ -136,10 +136,11 @@ if(charging.percent() >= 100) return - var/main_draw = use_power_from_net(charge_rate * seconds_per_tick, take_any = TRUE) //Pulls directly from the Powernet to dump into the cell + var/main_draw = charge_rate * seconds_per_tick if(!main_draw) return - charging.give(main_draw) - use_power(charge_rate / 100) //use a small bit for the charger itself, but power usage scales up with the part tier + + use_energy(main_draw * 0.01) //use a small bit for the charger itself, but power usage scales up with the part tier + charge_cell(main_draw, charging) update_appearance() diff --git a/code/game/machinery/computer/aifixer.dm b/code/game/machinery/computer/aifixer.dm index 74632b926b131..ba3041cc4840c 100644 --- a/code/game/machinery/computer/aifixer.dm +++ b/code/game/machinery/computer/aifixer.dm @@ -64,7 +64,9 @@ . = TRUE /obj/machinery/computer/aifixer/proc/Fix() - use_power(1000) + if(!use_energy(active_power_usage, force = TRUE)) + say("Not enough energy. Restoration cancelled.") + return FALSE var/need_mob_update = FALSE need_mob_update += occupier.adjustOxyLoss(-5, updating_health = FALSE) need_mob_update += occupier.adjustFireLoss(-5, updating_health = FALSE) diff --git a/code/game/machinery/computer/atmos_computers/_air_sensor.dm b/code/game/machinery/computer/atmos_computers/_air_sensor.dm index 3a8cd36de8998..d9d461149bca0 100644 --- a/code/game/machinery/computer/atmos_computers/_air_sensor.dm +++ b/code/game/machinery/computer/atmos_computers/_air_sensor.dm @@ -43,7 +43,7 @@ if(!on) return . = ..() - use_power(active_power_usage) //use power for analyzing gases + use_energy(active_power_usage) //use power for analyzing gases /obj/machinery/air_sensor/process() //update appearance according to power state diff --git a/code/game/machinery/computer/camera.dm b/code/game/machinery/computer/camera.dm index da807f52764e2..d0f137d18ab7b 100644 --- a/code/game/machinery/computer/camera.dm +++ b/code/game/machinery/computer/camera.dm @@ -68,7 +68,7 @@ // Turn on the console if(length(concurrent_users) == 1 && is_living) playsound(src, 'sound/machines/terminal_on.ogg', 25, FALSE) - use_power(active_power_usage) + use_energy(active_power_usage) // Register map objects cam_screen.display_to(user) user.client.register_map_obj(cam_background) @@ -173,7 +173,6 @@ active_camera = null last_camera_turf = null playsound(src, 'sound/machines/terminal_off.ogg', 25, FALSE) - use_power(0) /obj/machinery/computer/security/proc/show_camera_static() cam_screen.vis_contents.Cut() diff --git a/code/game/machinery/computer/dna_console.dm b/code/game/machinery/computer/dna_console.dm index c1b5f453d1b83..eb1aa91ed2970 100644 --- a/code/game/machinery/computer/dna_console.dm +++ b/code/game/machinery/computer/dna_console.dm @@ -440,9 +440,9 @@ to_chat(usr,span_notice("DNA scrambled.")) scanner_occupant.apply_status_effect(/datum/status_effect/genetic_damage, GENETIC_DAMAGE_STRENGTH_MULTIPLIER*50/(connected_scanner.damage_coeff ** 2)) if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Check whether a specific mutation is eligible for discovery within the @@ -578,9 +578,9 @@ // Check if we cracked a mutation check_discovery(alias) if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Apply a chromosome to a specific mutation. @@ -615,9 +615,9 @@ stored_chromosomes -= CM CM.apply(HM) if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Attempt overwriting Base DNA : The pairs are instead the top row vs the top row of the new code. @@ -754,9 +754,9 @@ scanner_occupant.domutcheck() if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return @@ -838,9 +838,9 @@ else injector_ready = world.time + INJECTOR_TIMEOUT * 5 if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Save a mutation to the console's storage buffer. @@ -1052,9 +1052,9 @@ stored_research.discovered_mutations += result_path say("Successfully mutated [HM.name].") if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Combines two mutations from the disk to try and create a new mutation @@ -1118,9 +1118,9 @@ stored_research.discovered_mutations += result_path say("Successfully mutated [HM.name].") if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Sets the Genetic Makeup pulse strength. @@ -1357,9 +1357,9 @@ if(I) injector_ready = world.time + INJECTOR_TIMEOUT if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Applies a genetic makeup buffer to the scanner occupant @@ -1397,9 +1397,9 @@ apply_genetic_makeup(type, buffer_slot) if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Applies a genetic makeup buffer to the next scanner occupant. This sets @@ -1466,9 +1466,9 @@ genetic_damage_pulse_index = WRAP(text2num(params["index"]), 1, len+1) begin_processing() if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Cancels the delayed action - In this context it is not the genetic damage @@ -1628,9 +1628,9 @@ injector_selection[adv_inj] += A to_chat(usr,span_notice("Mutation successfully added to advanced injector.")) if(connected_scanner) - connected_scanner.use_power(connected_scanner.active_power_usage) + connected_scanner.use_energy(connected_scanner.active_power_usage) else - use_power(active_power_usage) + use_energy(active_power_usage) return // Deletes a mutation from an advanced injector diff --git a/code/game/machinery/defibrillator_mount.dm b/code/game/machinery/defibrillator_mount.dm index cb12a39926021..4e6e45bb20482 100644 --- a/code/game/machinery/defibrillator_mount.dm +++ b/code/game/machinery/defibrillator_mount.dm @@ -8,6 +8,7 @@ icon_state = "defibrillator_mount" density = FALSE use_power = NO_POWER_USE + active_power_usage = 40 * BASE_MACHINE_ACTIVE_CONSUMPTION power_channel = AREA_USAGE_EQUIP req_one_access = list(ACCESS_MEDICAL, ACCESS_COMMAND, ACCESS_SECURITY) //used to control clamps processing_flags = NONE @@ -196,12 +197,11 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/defibrillator_mount, 28) /obj/machinery/defibrillator_mount/charging/process(seconds_per_tick) - var/obj/item/stock_parts/cell/C = get_cell() - if(!C || !is_operational) + var/obj/item/stock_parts/cell/cell = get_cell() + if(!cell || !is_operational) return PROCESS_KILL - if(C.charge < C.maxcharge) - use_power(active_power_usage * seconds_per_tick) - C.give(40 * seconds_per_tick) + if(cell.charge < cell.maxcharge) + charge_cell(active_power_usage * seconds_per_tick, cell) defib.update_power() //wallframe, for attaching the mounts easily diff --git a/code/game/machinery/dish_drive.dm b/code/game/machinery/dish_drive.dm index 888a855cf28ae..1b21d812dc0dd 100644 --- a/code/game/machinery/dish_drive.dm +++ b/code/game/machinery/dish_drive.dm @@ -159,9 +159,11 @@ var/disposed = 0 for(var/obj/item/dish in dish_drive_contents) if(is_type_in_list(dish, disposable_items)) + if(!use_energy(active_power_usage, force = FALSE)) + say("Not enough energy to continue!") + break LAZYREMOVE(dish_drive_contents, dish) dish.forceMove(bin) - use_power(active_power_usage) disposed++ if (disposed) visible_message(span_notice("[src] [pick("whooshes", "bwooms", "fwooms", "pshooms")] and beams [disposed] stored item\s into the nearby [bin.name].")) diff --git a/code/game/machinery/doors/airlock.dm b/code/game/machinery/doors/airlock.dm index 4173a52409acf..26a48c0bbdc08 100644 --- a/code/game/machinery/doors/airlock.dm +++ b/code/game/machinery/doors/airlock.dm @@ -1253,14 +1253,14 @@ if(DEFAULT_DOOR_CHECKS) // Regular behavior. if(!hasPower() || wires.is_cut(WIRE_OPEN) || (obj_flags & EMAGGED)) return FALSE - use_power(50) + use_energy(50 JOULES) playsound(src, doorOpen, 30, TRUE) return TRUE if(FORCING_DOOR_CHECKS) // Only one check. if(obj_flags & EMAGGED) return FALSE - use_power(50) + use_energy(50 JOULES) playsound(src, doorOpen, 30, TRUE) return TRUE @@ -1335,7 +1335,7 @@ if(DEFAULT_DOOR_CHECKS to FORCING_DOOR_CHECKS) if(obj_flags & EMAGGED) return FALSE - use_power(50) + use_energy(50 JOULES) playsound(src, doorClose, 30, TRUE) return TRUE diff --git a/code/game/machinery/doors/door.dm b/code/game/machinery/doors/door.dm index af38c929fd359..40a803d356103 100644 --- a/code/game/machinery/doors/door.dm +++ b/code/game/machinery/doors/door.dm @@ -422,7 +422,7 @@ if(operating) return FALSE operating = TRUE - use_power(active_power_usage) + use_energy(active_power_usage) do_animate("opening") set_opacity(0) SLEEP_NOT_DEL(0.5 SECONDS) diff --git a/code/game/machinery/droneDispenser.dm b/code/game/machinery/droneDispenser.dm index 91e7d1a3d4896..5495033651a89 100644 --- a/code/game/machinery/droneDispenser.dm +++ b/code/game/machinery/droneDispenser.dm @@ -23,7 +23,7 @@ var/starting_amount = 0 var/iron_cost = HALF_SHEET_MATERIAL_AMOUNT var/glass_cost = HALF_SHEET_MATERIAL_AMOUNT - var/power_used = 1000 + var/energy_used = 1 KILO JOULES var/mode = DRONE_READY var/timer @@ -95,7 +95,7 @@ // Those holoprojectors aren't cheap iron_cost = SHEET_MATERIAL_AMOUNT glass_cost = SHEET_MATERIAL_AMOUNT - power_used = 2000 + energy_used = 2 KILO JOULES starting_amount = SHEET_MATERIAL_AMOUNT * 5 // If the derelict gets lonely, make more friends. @@ -128,7 +128,7 @@ icon_creating = "hivebot_fab_on" iron_cost = 0 glass_cost = 0 - power_used = 0 + energy_used = 0 cooldownTime = 10 //Only 1 second - hivebots are extremely weak dispense_type = /mob/living/basic/hivebot begin_create_message = "closes and begins fabricating something within." @@ -177,8 +177,8 @@ if(DRONE_PRODUCTION) materials.use_materials(using_materials) - if(power_used) - use_power(power_used) + if(energy_used) + use_energy(energy_used) var/atom/A = new dispense_type(loc) A.flags_1 |= (flags_1 & ADMIN_SPAWNED_1) diff --git a/code/game/machinery/ecto_sniffer.dm b/code/game/machinery/ecto_sniffer.dm index 54d2b5e6f1e00..7f94df42b72ae 100644 --- a/code/game/machinery/ecto_sniffer.dm +++ b/code/game/machinery/ecto_sniffer.dm @@ -29,9 +29,10 @@ activate(user) /obj/machinery/ecto_sniffer/proc/activate(mob/activator) + if(!use_energy(active_power_usage, force = FALSE)) + return flick("ecto_sniffer_flick", src) playsound(loc, 'sound/machines/ectoscope_beep.ogg', 75) - use_power(active_power_usage) say("Reporting [pick(world.file2list("strings/spook_levels.txt"))] levels of paranormal activity!") if(activator?.ckey) ectoplasmic_residues += activator.ckey diff --git a/code/game/machinery/embedded_controller/access_controller.dm b/code/game/machinery/embedded_controller/access_controller.dm index 38cf3f449b998..ad4d32deadf90 100644 --- a/code/game/machinery/embedded_controller/access_controller.dm +++ b/code/game/machinery/embedded_controller/access_controller.dm @@ -73,7 +73,7 @@ controller.cycle_close(door) else controller.only_close(door) - use_power(active_power_usage) + use_energy(active_power_usage) addtimer(CALLBACK(src, PROC_REF(not_busy)), 2 SECONDS) /obj/machinery/door_buttons/access_button/proc/not_busy() diff --git a/code/game/machinery/fat_sucker.dm b/code/game/machinery/fat_sucker.dm index 6e1f745772e70..279e83ecbe999 100644 --- a/code/game/machinery/fat_sucker.dm +++ b/code/game/machinery/fat_sucker.dm @@ -153,7 +153,7 @@ playsound(loc, 'sound/machines/chime.ogg', 30, FALSE) else next_fact-- - use_power(active_power_usage) + use_energy(active_power_usage * seconds_per_tick) /obj/machinery/fat_sucker/proc/start_extracting() if(state_open || !occupant || processing || !powered()) diff --git a/code/game/machinery/flasher.dm b/code/game/machinery/flasher.dm index 678b2c655094a..94612b8c9db35 100644 --- a/code/game/machinery/flasher.dm +++ b/code/game/machinery/flasher.dm @@ -113,7 +113,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/flasher, 26) flash_lighting_fx() COOLDOWN_START(src, flash_cooldown, flash_cooldown_duration) - use_power(1000) + use_energy(1 KILO JOULES) var/flashed = FALSE for(var/mob/living/living_mob in viewers(src, null)) diff --git a/code/game/machinery/gulag_item_reclaimer.dm b/code/game/machinery/gulag_item_reclaimer.dm index e1c2c8c73d6f8..72ac0e746f4b0 100644 --- a/code/game/machinery/gulag_item_reclaimer.dm +++ b/code/game/machinery/gulag_item_reclaimer.dm @@ -99,6 +99,9 @@ /obj/machinery/gulag_item_reclaimer/proc/drop_items(mob/user) if(!stored_items[user]) return + if(!use_energy(active_power_usage, force = FALSE)) + balloon_alert(user, "not enough energy!") + return var/drop_location = drop_location() for(var/i in stored_items[user]) var/obj/item/W = i @@ -106,4 +109,3 @@ W.forceMove(drop_location) stored_items -= user user.log_message("has reclaimed their items from the gulag item reclaimer.", LOG_GAME) - use_power(active_power_usage) diff --git a/code/game/machinery/gulag_teleporter.dm b/code/game/machinery/gulag_teleporter.dm index 1a9194fc9278e..1799e51564be8 100644 --- a/code/game/machinery/gulag_teleporter.dm +++ b/code/game/machinery/gulag_teleporter.dm @@ -172,7 +172,7 @@ The console is located at computer/gulag_teleporter.dm if(target) target.wanted_status = WANTED_PRISONER - use_power(active_power_usage) + use_energy(active_power_usage) /obj/item/circuitboard/machine/gulag_teleporter name = "labor camp teleporter (Machine Board)" diff --git a/code/game/machinery/harvester.dm b/code/game/machinery/harvester.dm index 612277d57845c..33d08def9d292 100644 --- a/code/game/machinery/harvester.dm +++ b/code/game/machinery/harvester.dm @@ -136,7 +136,7 @@ organ_to_remove.forceMove(target) //Some organs, like chest ones, are different so we need to manually move them operation_order.Remove(limb_to_remove) break - use_power(active_power_usage) + use_energy(active_power_usage) addtimer(CALLBACK(src, PROC_REF(harvest)), interval) /obj/machinery/harvester/proc/end_harvesting(success = TRUE) diff --git a/code/game/machinery/hypnochair.dm b/code/game/machinery/hypnochair.dm index ecf47b39633f2..4594e09a9af9a 100644 --- a/code/game/machinery/hypnochair.dm +++ b/code/game/machinery/hypnochair.dm @@ -115,7 +115,7 @@ "...an annoying buzz in your ears..."\ )]") - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) /obj/machinery/hypnochair/proc/finish_interrogation() interrogating = FALSE diff --git a/code/game/machinery/igniter.dm b/code/game/machinery/igniter.dm index 75d0566e42c4e..9ad6bcac58dc0 100644 --- a/code/game/machinery/igniter.dm +++ b/code/game/machinery/igniter.dm @@ -113,12 +113,13 @@ on = FALSE if(machine_stat & NOPOWER) on = FALSE + if(!use_energy(active_power_usage, force = FALSE)) // Use energy to keep the turf hot. Doesn't necessarily use the correct amount of energy though (this should be changed). + on = FALSE if(!on) update_appearance() return PROCESS_KILL location.hotspot_expose(1000, 500, 1) - use_power(active_power_usage) //use power to keep the turf hot /obj/machinery/igniter/update_icon_state() icon_state = "[base_icon_state][on]" @@ -250,11 +251,13 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/sparker, 26) if(!isturf(location) || !isopenturf(location)) return FALSE + if(!use_energy(active_power_usage, force = FALSE)) + return FALSE + flick("[initial(icon_state)]-spark", src) spark_system.start() last_spark = world.time location.hotspot_expose(1000, 2500, 1) - use_power(active_power_usage) return TRUE diff --git a/code/game/machinery/launch_pad.dm b/code/game/machinery/launch_pad.dm index a950750f4d81b..0c95d3aa5c1d1 100644 --- a/code/game/machinery/launch_pad.dm +++ b/code/game/machinery/launch_pad.dm @@ -203,7 +203,7 @@ playsound(target, 'sound/weapons/emitter2.ogg', 25, TRUE) // use a lot of power - use_power(active_power_usage) + use_energy(active_power_usage) var/turf/source = target var/list/log_msg = list() diff --git a/code/game/machinery/limbgrower.dm b/code/game/machinery/limbgrower.dm index 197feb4118ddd..1fe2f542ba215 100644 --- a/code/game/machinery/limbgrower.dm +++ b/code/game/machinery/limbgrower.dm @@ -184,7 +184,7 @@ power = max(active_power_usage, (power + consumed_reagents_list[reagent_id])) busy = TRUE - use_power(power) + use_energy(power) flick("limbgrower_fill", src) icon_state = "limbgrower_idleon" var/temp_category = params["active_tab"] diff --git a/code/game/machinery/mass_driver.dm b/code/game/machinery/mass_driver.dm index e3922415a66cf..6963b23afb09d 100644 --- a/code/game/machinery/mass_driver.dm +++ b/code/game/machinery/mass_driver.dm @@ -43,7 +43,7 @@ /obj/machinery/mass_driver/proc/drive(amount) if(machine_stat & (BROKEN|NOPOWER) || panel_open) return - use_power(power_per_obj) + use_energy(power_per_obj) var/O_limit var/atom/target = get_edge_target_turf(src, dir) for(var/atom/movable/O in loc) @@ -54,7 +54,7 @@ if(O_limit >= 20) audible_message(span_notice("[src] lets out a screech, it doesn't seem to be able to handle the load.")) break - use_power(power_per_obj) + use_energy(power_per_obj) O.throw_at(target, drive_range * power, power) flick("mass_driver1", src) diff --git a/code/game/machinery/mechlaunchpad.dm b/code/game/machinery/mechlaunchpad.dm index 254467fc2171e..b8c282ae22cca 100644 --- a/code/game/machinery/mechlaunchpad.dm +++ b/code/game/machinery/mechlaunchpad.dm @@ -60,7 +60,7 @@ "style" = STYLE_SEETHROUGH, "reverse_dropoff_coords" = list(reverse_turf.x, reverse_turf.y, reverse_turf.z) )) - use_power(active_power_usage) + use_energy(active_power_usage) /obj/structure/closet/supplypod/mechpod style = STYLE_SEETHROUGH diff --git a/code/game/machinery/medical_kiosk.dm b/code/game/machinery/medical_kiosk.dm index eb75dfbfa3aac..6a63f07e5f51d 100644 --- a/code/game/machinery/medical_kiosk.dm +++ b/code/game/machinery/medical_kiosk.dm @@ -75,7 +75,7 @@ var/obj/item/card/id/card = paying.get_idcard(TRUE) if(card?.registered_account?.account_job?.paycheck_department == payment_department) - use_power(active_power_usage) + use_energy(active_power_usage) paying_customer = TRUE say("Hello, esteemed medical staff!") RefreshParts() @@ -83,7 +83,7 @@ var/bonus_fee = pandemonium ? rand(10,30) : 0 if(attempt_charge(src, paying, bonus_fee) & COMPONENT_OBJ_CANCEL_CHARGE ) return - use_power(active_power_usage) + use_energy(active_power_usage) paying_customer = TRUE icon_state = "[base_icon_state]_active" say("Thank you for your patronage!") diff --git a/code/game/machinery/medipen_refiller.dm b/code/game/machinery/medipen_refiller.dm index 5563000183c64..241b43d93da78 100644 --- a/code/game/machinery/medipen_refiller.dm +++ b/code/game/machinery/medipen_refiller.dm @@ -80,7 +80,7 @@ medipen.add_initial_reagents() reagents.remove_reagent(allowed_pens[medipen.type], 10) balloon_alert(user, "refilled") - use_power(active_power_usage) + use_energy(active_power_usage) cut_overlays() return return ..() diff --git a/code/game/machinery/porta_turret/portable_turret.dm b/code/game/machinery/porta_turret/portable_turret.dm index f5f8327607af3..a3b410e4a01c8 100644 --- a/code/game/machinery/porta_turret/portable_turret.dm +++ b/code/game/machinery/porta_turret/portable_turret.dm @@ -638,11 +638,11 @@ DEFINE_BITFIELD(turret_flags, list( var/obj/projectile/A //any emagged turrets drains 2x power and uses a different projectile? if(mode == TURRET_STUN) - use_power(reqpower) + use_energy(reqpower) A = new stun_projectile(T) playsound(loc, stun_projectile_sound, 75, TRUE) else - use_power(reqpower * 2) + use_energy(reqpower * 2) A = new lethal_projectile(T) playsound(loc, lethal_projectile_sound, 75, TRUE) diff --git a/code/game/machinery/prisonlabor.dm b/code/game/machinery/prisonlabor.dm index 2144b957326ce..116edc2430e18 100644 --- a/code/game/machinery/prisonlabor.dm +++ b/code/game/machinery/prisonlabor.dm @@ -58,7 +58,7 @@ update_appearance() return FALSE - use_power(active_power_usage) + use_energy(active_power_usage) to_chat(user, span_notice("You finish pressing a new license plate!")) pressing = FALSE diff --git a/code/game/machinery/quantum_pad.dm b/code/game/machinery/quantum_pad.dm index 53730ffd57954..99aaaff46c1c5 100644 --- a/code/game/machinery/quantum_pad.dm +++ b/code/game/machinery/quantum_pad.dm @@ -158,7 +158,7 @@ last_teleport = world.time // use a lot of power - use_power(active_power_usage / power_efficiency) + use_energy(active_power_usage / power_efficiency) sparks() target_pad.sparks() diff --git a/code/game/machinery/recharger.dm b/code/game/machinery/recharger.dm index 12a9ec2528442..f310c1afd3ea2 100644 --- a/code/game/machinery/recharger.dm +++ b/code/game/machinery/recharger.dm @@ -40,7 +40,7 @@ if(using_power) status_display_message_shown = TRUE . += span_notice("The status display reads:") - . += span_notice("- Recharging [recharge_coeff*10]% cell charge per cycle.") + . += span_notice("- Recharging efficiency: [recharge_coeff*100]%.") if(isnull(charging)) return @@ -146,8 +146,7 @@ var/obj/item/stock_parts/cell/charging_cell = charging.get_cell() if(charging_cell) if(charging_cell.charge < charging_cell.maxcharge) - charging_cell.give(charging_cell.chargerate * recharge_coeff * seconds_per_tick / 2) - use_power(active_power_usage * recharge_coeff * seconds_per_tick) + charge_cell(charging_cell.chargerate * recharge_coeff * seconds_per_tick, charging_cell) using_power = TRUE update_appearance() @@ -155,7 +154,7 @@ var/obj/item/ammo_box/magazine/recharge/power_pack = charging if(power_pack.stored_ammo.len < power_pack.max_ammo) power_pack.stored_ammo += new power_pack.ammo_type(power_pack) - use_power(active_power_usage * recharge_coeff * seconds_per_tick) + use_energy(active_power_usage * recharge_coeff * seconds_per_tick) using_power = TRUE update_appearance() return diff --git a/code/game/machinery/rechargestation.dm b/code/game/machinery/rechargestation.dm index f875617bd4045..f43431b8e7900 100644 --- a/code/game/machinery/rechargestation.dm +++ b/code/game/machinery/rechargestation.dm @@ -156,7 +156,7 @@ /obj/machinery/recharge_station/proc/process_occupant(seconds_per_tick) if(!occupant) return - var/main_draw = use_power_from_net(recharge_speed * seconds_per_tick, take_any = TRUE) //Pulls directly from the Powernet to dump into the cell + var/main_draw = use_energy(recharge_speed * seconds_per_tick) //Pulls directly from the Powernet to dump into the cell if(!main_draw) return SEND_SIGNAL(occupant, COMSIG_PROCESS_BORGCHARGER_OCCUPANT, main_draw, repairs, sendmats) diff --git a/code/game/machinery/recycler.dm b/code/game/machinery/recycler.dm index 5d4fd671c9623..405a38e4167f1 100644 --- a/code/game/machinery/recycler.dm +++ b/code/game/machinery/recycler.dm @@ -167,7 +167,7 @@ if(!is_operational) //we ran out of power after recycling a large amount to living stuff, time to stop break crush_living(CRUNCH) - use_power(active_power_usage) + use_energy(active_power_usage) else // Stop processing right now without eating anything. emergency_stop() return @@ -180,7 +180,7 @@ for(var/i = length(nom); i >= 1; i--) if(!is_operational) //we ran out of power after recycling a large amount to items, time to stop break - use_power(active_power_usage / (recycle_item(nom[i]) ? 1 : 2)) //recycling stuff that produces no material takes just half the power + use_energy(active_power_usage / (recycle_item(nom[i]) ? 1 : 2)) //recycling stuff that produces no material takes just half the power if(nom.len && sound) playsound(src, item_recycle_sound, (50 + nom.len * 5), TRUE, nom.len, ignore_walls = (nom.len - 10)) // As a substitute for playing 50 sounds at once. if(not_eaten) diff --git a/code/game/machinery/roulette_machine.dm b/code/game/machinery/roulette_machine.dm index 45a69e0b41a01..f2e6ddd819532 100644 --- a/code/game/machinery/roulette_machine.dm +++ b/code/game/machinery/roulette_machine.dm @@ -226,7 +226,7 @@ addtimer(CALLBACK(src, PROC_REF(finish_play), player_id, bet_type, bet_amount, payout, rolled_number), 34) //4 deciseconds more so the animation can play addtimer(CALLBACK(src, PROC_REF(finish_play_animation)), 30) - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/roulette/proc/finish_play_animation() icon_state = "idle" diff --git a/code/game/machinery/scan_gate.dm b/code/game/machinery/scan_gate.dm index 49d5fab21f2fa..3986b109ffc7d 100644 --- a/code/game/machinery/scan_gate.dm +++ b/code/game/machinery/scan_gate.dm @@ -193,7 +193,7 @@ assembly?.activate() set_scanline("scanning", 10) - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/scanner_gate/proc/alarm_beep() if(next_beep <= world.time) diff --git a/code/game/machinery/sheetifier.dm b/code/game/machinery/sheetifier.dm index 69bebfca69ee5..d9619092af6f3 100644 --- a/code/game/machinery/sheetifier.dm +++ b/code/game/machinery/sheetifier.dm @@ -56,7 +56,7 @@ busy_processing = FALSE update_appearance() materials.retrieve_all() //Returns all as sheets - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/sheetifier/wrench_act(mob/living/user, obj/item/tool) . = ..() diff --git a/code/game/machinery/sleepers.dm b/code/game/machinery/sleepers.dm index daa474029f6d6..68b4026b7444a 100644 --- a/code/game/machinery/sleepers.dm +++ b/code/game/machinery/sleepers.dm @@ -178,7 +178,7 @@ . += span_notice("Alt-click [src] to [state_open ? "close" : "open"] it.") /obj/machinery/sleeper/process() - use_power(idle_power_usage) + use_energy(idle_power_usage) /obj/machinery/sleeper/nap_violation(mob/violator) . = ..() diff --git a/code/game/machinery/slotmachine.dm b/code/game/machinery/slotmachine.dm index b7eec3994b8d1..842f01ae7542b 100644 --- a/code/game/machinery/slotmachine.dm +++ b/code/game/machinery/slotmachine.dm @@ -238,8 +238,10 @@ //WARNING: no sanity checking for user since it's not needed and would complicate things (machine should still spin even if user is gone), be wary of this if you're changing this code. /obj/machinery/computer/slot_machine/proc/do_spin() + if(!use_energy(active_power_usage, force = FALSE)) + say("Not enough energy!") + return randomize_reels() - use_power(active_power_usage) /obj/machinery/computer/slot_machine/proc/finish_spinning(spin_loop, mob/user, the_name) toggle_reel_spin(0, REEL_DEACTIVATE_DELAY) diff --git a/code/game/machinery/spaceheater.dm b/code/game/machinery/spaceheater.dm index 6a5b53e2a0bdc..b47eb34e3bdcc 100644 --- a/code/game/machinery/spaceheater.dm +++ b/code/game/machinery/spaceheater.dm @@ -30,7 +30,7 @@ ///How much heat/cold we can deliver var/heating_power = 40000 ///How efficiently we can deliver that heat/cold (higher indicates less cell consumption) - var/efficiency = 20000 + var/efficiency = 20 ///The amount of degrees above and below the target temperature for us to change mode to heater or cooler var/temperature_tolerance = 1 ///What's the middle point of our settable temperature (30 °C) @@ -95,7 +95,7 @@ else . += "There is no power cell installed." if(in_range(user, src) || isobserver(user)) - . += span_notice("The status display reads: Temperature range at [settable_temperature_range]°C.
Heating power at [siunit(heating_power, "W", 1)].
Power consumption at [(efficiency*-0.0025)+150]%.") //100%, 75%, 50%, 25% + . += span_notice("The status display reads: Temperature range at [settable_temperature_range]°C.
Heating power at [siunit(heating_power, "W", 1)].
Power consumption at [100 / efficiency]%.") //100%, 75%, 50%, 25% . += span_notice("Right-click to toggle [on ? "off" : "on"].") /obj/machinery/space_heater/update_icon_state() @@ -173,7 +173,7 @@ heating_power = laser * 40000 settable_temperature_range = cap * 30 - efficiency = (cap + 1) * 10000 + efficiency = (cap + 1) * 10 target_temperature = clamp(target_temperature, max(settable_temperature_median - settable_temperature_range, TCMB), @@ -453,13 +453,13 @@ heating_power = lasers_rating * 20000 settable_temperature_range = capacitors_rating * 50 //-20 - 80 at base - efficiency = (capacitors_rating + 1) * 10000 + efficiency = (capacitors_rating + 1) * 10 target_temperature = clamp(target_temperature, max(settable_temperature_median - settable_temperature_range, TCMB), settable_temperature_median + settable_temperature_range) - chem_heating_power = efficiency/20000 //1-2.5 + chem_heating_power = efficiency/20 #undef HEATER_MODE_STANDBY #undef HEATER_MODE_HEAT diff --git a/code/game/machinery/suit_storage_unit.dm b/code/game/machinery/suit_storage_unit.dm index f96e1c1199bf2..2da6a3fa9a76b 100644 --- a/code/game/machinery/suit_storage_unit.dm +++ b/code/game/machinery/suit_storage_unit.dm @@ -561,9 +561,7 @@ if(!cell || cell.charge == cell.maxcharge) return - var/cell_charged = cell.give(final_charge_rate * seconds_per_tick) - if(cell_charged) - use_power((active_power_usage + final_charge_rate) * seconds_per_tick) + charge_cell(final_charge_rate * seconds_per_tick, cell) /obj/machinery/suit_storage_unit/proc/shock(mob/user, prb) if(!prob(prb)) diff --git a/code/game/machinery/telecomms/machines/broadcaster.dm b/code/game/machinery/telecomms/machines/broadcaster.dm index a3b4caecf392c..1ad464b3b6876 100644 --- a/code/game/machinery/telecomms/machines/broadcaster.dm +++ b/code/game/machinery/telecomms/machines/broadcaster.dm @@ -56,7 +56,7 @@ GLOBAL_VAR_INIT(message_delay, FALSE) /* --- Do a snazzy animation! --- */ flick("broadcaster_send", src) - use_power(idle_power_usage) + use_energy(idle_power_usage) /** * Simply resets the message delay and the recent messages list, to ensure that diff --git a/code/game/machinery/telecomms/machines/bus.dm b/code/game/machinery/telecomms/machines/bus.dm index 8ac8297b612b3..15d20b3d1eb25 100644 --- a/code/game/machinery/telecomms/machines/bus.dm +++ b/code/game/machinery/telecomms/machines/bus.dm @@ -47,7 +47,7 @@ if(relay_information(signal, send)) break - use_power(idle_power_usage) + use_energy(idle_power_usage) // Preset Buses diff --git a/code/game/machinery/telecomms/machines/hub.dm b/code/game/machinery/telecomms/machines/hub.dm index 094180a6e70d7..83d0f6e3209a0 100644 --- a/code/game/machinery/telecomms/machines/hub.dm +++ b/code/game/machinery/telecomms/machines/hub.dm @@ -31,7 +31,7 @@ // Then broadcast that signal to relay_information(signal, /obj/machinery/telecomms/broadcaster) - use_power(idle_power_usage) + use_energy(idle_power_usage) /obj/machinery/telecomms/hub/update_power() var/old_on = on diff --git a/code/game/machinery/telecomms/machines/receiver.dm b/code/game/machinery/telecomms/machines/receiver.dm index ff3064e73c781..8d6f8c85f43a1 100644 --- a/code/game/machinery/telecomms/machines/receiver.dm +++ b/code/game/machinery/telecomms/machines/receiver.dm @@ -30,7 +30,7 @@ if(!relay_information(signal_copy, /obj/machinery/telecomms/hub)) relay_information(signal_copy, /obj/machinery/telecomms/bus) - use_power(idle_power_usage) + use_energy(idle_power_usage) /** * Checks whether the signal can be received by this receiver or not, based on diff --git a/code/game/machinery/telecomms/machines/relay.dm b/code/game/machinery/telecomms/machines/relay.dm index 2173a519be4e1..504702e3176da 100644 --- a/code/game/machinery/telecomms/machines/relay.dm +++ b/code/game/machinery/telecomms/machines/relay.dm @@ -32,7 +32,7 @@ else signal.levels |= SSmapping.get_connected_levels(relay_turf) - use_power(idle_power_usage) + use_energy(idle_power_usage) /** * Checks to see if the relay can send/receive the signal, by checking if it's diff --git a/code/game/machinery/telecomms/machines/server.dm b/code/game/machinery/telecomms/machines/server.dm index fedcf519ff240..0c87a6101d182 100644 --- a/code/game/machinery/telecomms/machines/server.dm +++ b/code/game/machinery/telecomms/machines/server.dm @@ -61,7 +61,7 @@ if(!can_send) relay_information(signal, /obj/machinery/telecomms/broadcaster) - use_power(idle_power_usage) + use_energy(idle_power_usage) #undef MAX_LOG_ENTRIES diff --git a/code/game/machinery/teleporter.dm b/code/game/machinery/teleporter.dm index f7300f720863d..972497da9b316 100644 --- a/code/game/machinery/teleporter.dm +++ b/code/game/machinery/teleporter.dm @@ -75,7 +75,7 @@ return if (ismovable(M)) if(do_teleport(M, target, channel = TELEPORT_CHANNEL_BLUESPACE)) - use_power(active_power_usage) + use_energy(active_power_usage) if(!calibrated && prob(30 - ((accuracy) * 10))) //oh dear a problem if(ishuman(M))//don't remove people from the round randomly you jerks var/mob/living/carbon/human/human = M @@ -196,7 +196,7 @@ to_chat(user, span_alert("The teleporter hub isn't responding.")) else engaged = !engaged - use_power(active_power_usage) + use_energy(active_power_usage) to_chat(user, span_notice("Teleporter [engaged ? "" : "dis"]engaged!")) else teleporter_console.target_ref = null diff --git a/code/game/machinery/transformer.dm b/code/game/machinery/transformer.dm index d60cc70a45137..9c87ca0cfc746 100644 --- a/code/game/machinery/transformer.dm +++ b/code/game/machinery/transformer.dm @@ -99,7 +99,7 @@ // Sleep for a couple of ticks to allow the human to see the pain sleep(0.5 SECONDS) - use_power(active_power_usage) // Use a lot of power. + use_energy(active_power_usage) // Use a lot of power. var/mob/living/silicon/robot/new_borg = victim.Robotize() new_borg.cell = new /obj/item/stock_parts/cell/upgraded/plus(new_borg, robot_cell_charge) diff --git a/code/game/machinery/washing_machine.dm b/code/game/machinery/washing_machine.dm index a51fb9304e1c0..6ae82fd2654e4 100644 --- a/code/game/machinery/washing_machine.dm +++ b/code/game/machinery/washing_machine.dm @@ -227,7 +227,7 @@ GLOBAL_LIST_INIT(dye_registry, list( qdel(color_source) color_source = null update_appearance() - use_power(active_power_usage) + use_energy(active_power_usage) /obj/item/proc/dye_item(dye_color, dye_key_override) var/dye_key_selector = dye_key_override ? dye_key_override : dying_key diff --git a/code/game/objects/items/defib.dm b/code/game/objects/items/defib.dm index 9e9e791c952a7..fce00156b7ff5 100644 --- a/code/game/objects/items/defib.dm +++ b/code/game/objects/items/defib.dm @@ -28,7 +28,7 @@ /// If the cell can be removed via screwdriver var/cell_removable = TRUE var/obj/item/shockpaddles/paddles - var/obj/item/stock_parts/cell/high/cell + var/obj/item/stock_parts/cell/cell /// If true, revive through space suits, allow for combat shocking var/combat = FALSE /// How long does it take to recharge @@ -346,7 +346,7 @@ resistance_flags = INDESTRUCTIBLE base_icon_state = "defibpaddles" - var/revivecost = 1000 + var/revivecost = STANDARD_CELL_CHARGE * 0.1 var/cooldown = FALSE var/busy = FALSE var/obj/item/defibrillator/defib diff --git a/code/game/objects/items/devices/powersink.dm b/code/game/objects/items/devices/powersink.dm index 2a0a78c626acf..1b000ea2f9160 100644 --- a/code/game/objects/items/devices/powersink.dm +++ b/code/game/objects/items/devices/powersink.dm @@ -158,7 +158,7 @@ /// Drains power from the connected powernet, if any. /obj/item/powersink/proc/drain_power() - var/datum/powernet/PN = attached.powernet + var/datum/powernet/powernet = attached.powernet var/drained = 0 set_light(5) @@ -167,14 +167,11 @@ attached.add_delayedload(drained) // If tried to drain more than available on powernet, now look for APCs and drain their cells - for(var/obj/machinery/power/terminal/T in PN.nodes) - if(istype(T.master, /obj/machinery/power/apc)) - var/obj/machinery/power/apc/A = T.master - if(A.operating && A.cell) - A.cell.charge = max(0, A.cell.charge - 50) - drained += 50 - if(A.charging == 2) // If the cell was full - A.charging = 1 // It's no longer full + for(var/obj/machinery/power/terminal/terminal in powernet.nodes) + if(istype(terminal.master, /obj/machinery/power/apc)) + var/obj/machinery/power/apc/apc = terminal.master + if(apc.operating && apc.cell) + drained += 0.001 * apc.cell.use(50 KILO JOULES, force = TRUE) internal_heat += drained /obj/item/powersink/process() diff --git a/code/game/objects/items/devices/scanners/gas_analyzer.dm b/code/game/objects/items/devices/scanners/gas_analyzer.dm index 859d119bbbebd..5a1be36b37ea8 100644 --- a/code/game/objects/items/devices/scanners/gas_analyzer.dm +++ b/code/game/objects/items/devices/scanners/gas_analyzer.dm @@ -207,8 +207,8 @@ message += span_notice("Temperature: [round(temperature - T0C,0.01)] °C ([round(temperature, 0.01)] K)") message += span_notice("Volume: [volume] L") message += span_notice("Pressure: [round(pressure, 0.01)] kPa") - message += span_notice("Heat Capacity: [display_joules(heat_capacity)] / K") - message += span_notice("Thermal Energy: [display_joules(thermal_energy)]") + message += span_notice("Heat Capacity: [display_energy(heat_capacity)] / K") + message += span_notice("Thermal Energy: [display_energy(thermal_energy)]") else message += airs.len > 1 ? span_notice("This node is empty!") : span_notice("[target] is empty!") message += span_notice("Volume: [volume] L") // don't want to change the order volume appears in, suck it diff --git a/code/game/objects/items/inducer.dm b/code/game/objects/items/inducer.dm index f2493bf869d01..9cbb3f054f571 100644 --- a/code/game/objects/items/inducer.dm +++ b/code/game/objects/items/inducer.dm @@ -7,7 +7,7 @@ lefthand_file = 'icons/mob/inhands/equipment/tools_lefthand.dmi' righthand_file = 'icons/mob/inhands/equipment/tools_righthand.dmi' force = 7 - var/powertransfer = 1000 + var/powertransfer = STANDARD_CELL_CHARGE var/opened = FALSE var/cell_type = /obj/item/stock_parts/cell/high var/obj/item/stock_parts/cell/cell @@ -106,7 +106,7 @@ return FALSE if(recharging) return TRUE - + recharging = TRUE var/obj/item/stock_parts/cell/our_cell = get_cell() var/obj/item/stock_parts/cell/target_cell = target.get_cell() diff --git a/code/game/objects/items/inspector.dm b/code/game/objects/items/inspector.dm index c0b6a5dd14559..2f25e53c1fb77 100644 --- a/code/game/objects/items/inspector.dm +++ b/code/game/objects/items/inspector.dm @@ -26,10 +26,10 @@ var/obj/item/stock_parts/cell/cell = /obj/item/stock_parts/cell/crap ///Cell cover status var/cell_cover_open = FALSE - ///Power used per print in cell units - var/power_per_print = INSPECTOR_POWER_USAGE_NORMAL - ///Power used to say an error message - var/power_to_speak = 1 + ///Energy used per print. + var/energy_per_print = INSPECTOR_ENERGY_USAGE_NORMAL + ///Energy used to say an error message. + var/energy_to_speak = 1 KILO JOULES /obj/item/inspector/Initialize(mapload) . = ..() @@ -111,8 +111,8 @@ if(cell.charge == 0) to_chat(user, "\The [src] doesn't seem to be on... Perhaps it ran out of power?") return - if(!cell.use(power_per_print)) - if(cell.use(power_to_speak)) + if(!cell.use(energy_per_print)) + if(cell.use(energy_to_speak)) say("ERROR! POWER CELL CHARGE LEVEL TOO LOW TO PRINT REPORT!") return @@ -238,8 +238,8 @@ * * Can print things way faster, at full power the reports printed by this will destroy * themselves and leave water behind when folding is attempted by someone who isn't an - * origami master. Printing at full power costs INSPECTOR_POWER_USAGE_HONK cell units - * instead of INSPECTOR_POWER_USAGE_NORMAL cell units. + * origami master. Printing at full power costs INSPECTOR_ENERGY_USAGE_HONK cell units + * instead of INSPECTOR_ENERGY_USAGE_NORMAL cell units. */ /obj/item/inspector/clown/bananium name = "\improper Bananium HONK-spect scanner" @@ -258,11 +258,11 @@ /obj/item/inspector/clown/bananium/proc/check_settings_legality() if(print_sound_mode == INSPECTOR_PRINT_SOUND_MODE_NORMAL && time_mode == INSPECTOR_TIME_MODE_HONK) - if(cell.use(power_to_speak)) + if(cell.use(energy_to_speak)) say("Setting combination forbidden by Geneva convention revision CCXXIII selected, reverting to defaults") time_mode = INSPECTOR_TIME_MODE_SLOW print_sound_mode = INSPECTOR_PRINT_SOUND_MODE_NORMAL - power_per_print = INSPECTOR_POWER_USAGE_NORMAL + energy_per_print = INSPECTOR_ENERGY_USAGE_NORMAL /obj/item/inspector/clown/bananium/screwdriver_act(mob/living/user, obj/item/tool) . = ..() @@ -296,7 +296,7 @@ if(time_mode != INSPECTOR_TIME_MODE_HONK) return ..() if(paper_charges == 0) - if(cell.use(power_to_speak)) + if(cell.use(energy_to_speak)) say("ERROR! OUT OF PAPER! MAXIMUM PRINTING SPEED UNAVAIBLE! SWITCH TO A SLOWER SPEED TO OR PROVIDE PAPER!") else to_chat(user, "\The [src] doesn't seem to be on... Perhaps it ran out of power?") @@ -308,7 +308,7 @@ var/message switch(time_mode) if(INSPECTOR_TIME_MODE_HONK) - power_per_print = INSPECTOR_POWER_USAGE_NORMAL + energy_per_print = INSPECTOR_ENERGY_USAGE_NORMAL time_mode = INSPECTOR_TIME_MODE_SLOW message = "SLOW." if(INSPECTOR_TIME_MODE_SLOW) @@ -316,7 +316,7 @@ message = "LIGHTNING FAST." else time_mode = INSPECTOR_TIME_MODE_HONK - power_per_print = INSPECTOR_POWER_USAGE_HONK + energy_per_print = INSPECTOR_ENERGY_USAGE_HONK message = "HONK!" balloon_alert(user, "scanning speed set to [message]") diff --git a/code/game/objects/items/rcd/RCD.dm b/code/game/objects/items/rcd/RCD.dm index a75091e47aacc..539821d1607a9 100644 --- a/code/game/objects/items/rcd/RCD.dm +++ b/code/game/objects/items/rcd/RCD.dm @@ -547,7 +547,7 @@ if(!ismecha(owner)) return 0 var/obj/vehicle/sealed/mecha/gundam = owner - if(!gundam.use_power(amount * mass_to_energy)) + if(!gundam.use_energy(amount * mass_to_energy)) gundam.balloon_alert(user, "insufficient charge!") return FALSE return TRUE diff --git a/code/game/objects/items/robot/items/generic.dm b/code/game/objects/items/robot/items/generic.dm index 7ebd87408f60f..ef93e09d7875a 100644 --- a/code/game/objects/items/robot/items/generic.dm +++ b/code/game/objects/items/robot/items/generic.dm @@ -251,10 +251,7 @@ if((target_machine.machine_stat & (NOPOWER|BROKEN)) || !target_machine.anchored) break - if(!user.cell.give(150)) - break - - target_machine.use_power(200) + target_machine.charge_cell(0.15 * STANDARD_CELL_CHARGE, user.cell) to_chat(user, span_notice("You stop charging yourself.")) diff --git a/code/game/objects/items/stacks/golem_food/golem_status_effects.dm b/code/game/objects/items/stacks/golem_food/golem_status_effects.dm index 43cd135904f87..c55a39c20f76a 100644 --- a/code/game/objects/items/stacks/golem_food/golem_status_effects.dm +++ b/code/game/objects/items/stacks/golem_food/golem_status_effects.dm @@ -168,7 +168,7 @@ alert_icon_state = "sheet-plasma" alert_desc = "You are protected from high pressure and can convert heat damage into power." /// What do we multiply our damage by to convert it into power? - var/power_multiplier = 5 + var/energy_per_damage = 5 KILO JOULES /// Multiplier to apply to burn damage, not 0 so that we can reverse it more easily var/burn_multiplier = 0.05 @@ -195,7 +195,7 @@ if(damagetype != BURN) return - var/power = damage * power_multiplier + var/power = damage * energy_per_damage var/obj/machinery/power/energy_accumulator/ground = get_closest_atom(/obj/machinery/power/energy_accumulator, view(4, owner), owner) if (ground) zap_effect(ground) diff --git a/code/modules/antagonists/fugitive/hunters/hunter_gear.dm b/code/modules/antagonists/fugitive/hunters/hunter_gear.dm index 7ba0401829a82..54f2ef351a78e 100644 --- a/code/modules/antagonists/fugitive/hunters/hunter_gear.dm +++ b/code/modules/antagonists/fugitive/hunters/hunter_gear.dm @@ -31,7 +31,7 @@ antag.is_captured = TRUE to_chat(fugitive, span_userdanger("You are thrown into a vast void of bluespace, and as you fall further into oblivion the comparatively small entrance to reality gets smaller and smaller until you cannot see it anymore. You have failed to avoid capture.")) fugitive.ghostize(TRUE) //so they cannot suicide, round end stuff. - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/computer/shuttle/hunter name = "shuttle console" diff --git a/code/modules/antagonists/ninja/ninjaDrainAct.dm b/code/modules/antagonists/ninja/ninjaDrainAct.dm index c24dca086d2c6..7f11d934cc6ff 100644 --- a/code/modules/antagonists/ninja/ninjaDrainAct.dm +++ b/code/modules/antagonists/ninja/ninjaDrainAct.dm @@ -313,7 +313,7 @@ /mob/living/carbon/ninjadrain_act(mob/living/carbon/human/ninja, obj/item/mod/module/hacker/hacking_module) if(!ninja || !hacking_module) return NONE - //Default cell = 10,000 charge, 10,000/1000 = 10 uses without charging/upgrading + //20 uses for a standard cell. 200 for high capacity cells. if(hacking_module.mod.subtract_charge(DEFAULT_CHARGE_DRAIN*10)) //Got that electric touch var/datum/effect_system/spark_spread/spark_system = new /datum/effect_system/spark_spread() diff --git a/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm b/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm index b33f8845d4694..4a625a283bd3f 100644 --- a/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm +++ b/code/modules/atmospherics/machinery/components/binary_devices/temperature_pump.dm @@ -70,7 +70,7 @@ air_output.merge(remove_output) if(power_usage) - use_power(power_usage) + use_energy(power_usage) /obj/machinery/atmospherics/components/binary/temperature_pump/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) diff --git a/code/modules/atmospherics/machinery/components/electrolyzer/electrolyzer.dm b/code/modules/atmospherics/machinery/components/electrolyzer/electrolyzer.dm index 7cee01e0cf792..3be95de560507 100644 --- a/code/modules/atmospherics/machinery/components/electrolyzer/electrolyzer.dm +++ b/code/modules/atmospherics/machinery/components/electrolyzer/electrolyzer.dm @@ -125,7 +125,7 @@ var/power_to_use = (5 * (3 * working_power) * working_power) / (efficiency + working_power) if(anchored) - use_power(power_to_use) + use_energy(power_to_use) else cell.use(power_to_use) diff --git a/code/modules/atmospherics/machinery/components/fusion/_hfr_defines.dm b/code/modules/atmospherics/machinery/components/fusion/_hfr_defines.dm index 46a64a7e10a06..d113f3d7f05a4 100644 --- a/code/modules/atmospherics/machinery/components/fusion/_hfr_defines.dm +++ b/code/modules/atmospherics/machinery/components/fusion/_hfr_defines.dm @@ -21,7 +21,7 @@ ///Conduction of heat near the external cooling loop #define HIGH_EFFICIENCY_CONDUCTIVITY 0.975 ///Sets the minimum amount of power the machine uses -#define MIN_POWER_USAGE 50000 +#define MIN_POWER_USAGE (50 KILO WATTS) ///Sets the multiplier for the damage #define DAMAGE_CAP_MULTIPLIER 0.005 ///Sets the range of the hallucinations diff --git a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm index aa890b0b574a0..0af962ac0f341 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm @@ -196,7 +196,7 @@ // This produces a nice curve that scales decently well for really hot stuff, and is nice to not fusion. It'll do var/power_usage = idle_power_usage + (heat_amount * 0.05) ** (1.05 - (5e7 * 0.16 / max(heat_amount, 5e7))) - use_power(power_usage) + use_energy(power_usage) update_parents() /obj/machinery/atmospherics/components/unary/thermomachine/screwdriver_act(mob/living/user, obj/item/tool) diff --git a/code/modules/atmospherics/machinery/other/miner.dm b/code/modules/atmospherics/machinery/other/miner.dm index 823ce9066171a..ebab8af4ea7da 100644 --- a/code/modules/atmospherics/machinery/other/miner.dm +++ b/code/modules/atmospherics/machinery/other/miner.dm @@ -97,7 +97,7 @@ if(GASMINER_POWER_FULLSCALE) update_use_power(ACTIVE_POWER_USE, (spawn_mol * power_draw_dynamic_mol_coeff) + (P * power_draw_dynamic_kpa_coeff)) -/obj/machinery/atmospherics/miner/proc/do_use_power(amount) +/obj/machinery/atmospherics/miner/proc/do_use_energy(amount) var/turf/T = get_turf(src) if(T && istype(T)) var/obj/structure/cable/C = T.get_cable_node() //check if we have a node cable on the machine turf, the first found is picked @@ -105,7 +105,7 @@ C.powernet.load += amount return TRUE if(powered()) - use_power(amount) + use_energy(amount) return TRUE return FALSE @@ -126,7 +126,7 @@ if(active && !broken) if(isnull(spawn_id)) return FALSE - if(do_use_power(active_power_usage)) + if(do_use_energy(active_power_usage)) mine_gas(seconds_per_tick) /obj/machinery/atmospherics/miner/proc/mine_gas(seconds_per_tick = 2) diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index 8c3a3301b6804..dba4c5bff2f4b 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -482,7 +482,7 @@ var/power_factor = round(log(10, max(our_pressure - pressure_limit, 1)) + log(10, max(our_temperature - temp_limit, 1))) var/power_consumed = power_factor * 250 * seconds_per_tick if(powered(AREA_USAGE_EQUIP, ignore_use_power = TRUE)) - use_power(power_consumed, AREA_USAGE_EQUIP) + use_energy(power_consumed, AREA_USAGE_EQUIP) else if(!internal_cell?.use(power_consumed * 0.025)) shielding_powered = FALSE SSair.start_processing_machine(src) diff --git a/code/modules/cargo/markets/market_telepad.dm b/code/modules/cargo/markets/market_telepad.dm index 3738a314afdfe..4545b07e487f4 100644 --- a/code/modules/cargo/markets/market_telepad.dm +++ b/code/modules/cargo/markets/market_telepad.dm @@ -19,10 +19,10 @@ idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 2 - /// Divider for power_usage_per_teleport. + /// Divider for energy_usage_per_teleport. var/power_efficiency = 1 /// Power used per teleported which gets divided by power_efficiency. - var/power_usage_per_teleport = 10000 + var/energy_usage_per_teleport = 10 KILO JOULES /// The time it takes for the machine to recharge before being able to send or receive items. var/recharge_time = 0 /// Current recharge progress. @@ -92,7 +92,7 @@ receiving.item = receiving.entry.spawn_item(turf, receiving) - use_power(power_usage_per_teleport / power_efficiency) + use_energy(energy_usage_per_teleport / power_efficiency) var/datum/effect_system/spark_spread/sparks = new sparks.set_up(5, 1, get_turf(src)) sparks.attach(receiving.item) @@ -106,7 +106,7 @@ if(transmitting) if(transmitting.item.loc == turf) do_teleport(transmitting.item, get_turf(transmitting.uplink)) - use_power(power_usage_per_teleport / power_efficiency) + use_energy(energy_usage_per_teleport / power_efficiency) QDEL_NULL(transmitting) return diff --git a/code/modules/experisci/destructive_scanner.dm b/code/modules/experisci/destructive_scanner.dm index de0b03b0f0920..5740b715bd42f 100644 --- a/code/modules/experisci/destructive_scanner.dm +++ b/code/modules/experisci/destructive_scanner.dm @@ -42,7 +42,7 @@ return aggressive = TRUE start_closing(aggressive) - use_power(idle_power_usage) + use_energy(idle_power_usage) ///Closes the machine to kidnap everything in the turf into it. /obj/machinery/destructive_scanner/proc/start_closing(aggressive) @@ -55,7 +55,7 @@ scanning = TRUE update_icon() playsound(src, 'sound/machines/destructive_scanner/TubeDown.ogg', 100) - use_power(idle_power_usage) + use_energy(idle_power_usage) addtimer(CALLBACK(src, PROC_REF(start_scanning), aggressive), 1.2 SECONDS) ///Starts scanning the fancy scanning effects @@ -64,7 +64,7 @@ playsound(src, 'sound/machines/destructive_scanner/ScanDangerous.ogg', 100, extrarange = 5) else playsound(src, 'sound/machines/destructive_scanner/ScanSafe.ogg', 100) - use_power(active_power_usage) + use_energy(active_power_usage) addtimer(CALLBACK(src, PROC_REF(finish_scanning), aggressive), 6 SECONDS) diff --git a/code/modules/food_and_drinks/machinery/coffeemaker.dm b/code/modules/food_and_drinks/machinery/coffeemaker.dm index de751979ca8d6..d79eebc993abc 100644 --- a/code/modules/food_and_drinks/machinery/coffeemaker.dm +++ b/code/modules/food_and_drinks/machinery/coffeemaker.dm @@ -401,7 +401,7 @@ if(!silent) playsound(src, 'sound/machines/coffeemaker_brew.ogg', 20, vary = TRUE) toggle_steam() - use_power(active_power_usage * time * 0.1) // .1 needed here to convert time (in deciseconds) to seconds such that watts * seconds = joules + use_energy(active_power_usage * time / (1 SECONDS)) // .1 needed here to convert time (in deciseconds) to seconds such that watts * seconds = joules addtimer(CALLBACK(src, PROC_REF(stop_operating)), time / speed) /obj/machinery/coffeemaker/proc/stop_operating() diff --git a/code/modules/food_and_drinks/machinery/deep_fryer.dm b/code/modules/food_and_drinks/machinery/deep_fryer.dm index fb86b95639b63..07b7c4a1d7696 100644 --- a/code/modules/food_and_drinks/machinery/deep_fryer.dm +++ b/code/modules/food_and_drinks/machinery/deep_fryer.dm @@ -148,7 +148,7 @@ GLOBAL_LIST_INIT(oilfry_blacklisted_items, typecacheof(list( frying_burnt = TRUE visible_message(span_warning("[src] emits an acrid smell!")) - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/deepfryer/Exited(atom/movable/gone, direction) . = ..() diff --git a/code/modules/food_and_drinks/machinery/gibber.dm b/code/modules/food_and_drinks/machinery/gibber.dm index 62157177bdcaf..e0002817f782e 100644 --- a/code/modules/food_and_drinks/machinery/gibber.dm +++ b/code/modules/food_and_drinks/machinery/gibber.dm @@ -154,7 +154,7 @@ set_occupant(null) return - use_power(active_power_usage) + use_energy(active_power_usage) audible_message(span_hear("You hear a loud squelchy grinding sound.")) playsound(loc, 'sound/machines/juicer.ogg', 50, TRUE) operating = TRUE diff --git a/code/modules/food_and_drinks/machinery/griddle.dm b/code/modules/food_and_drinks/machinery/griddle.dm index 80646a8ab0960..f997b049feb2c 100644 --- a/code/modules/food_and_drinks/machinery/griddle.dm +++ b/code/modules/food_and_drinks/machinery/griddle.dm @@ -176,7 +176,7 @@ if(prob(10)) visible_message(span_danger("[griddled_item] doesn't seem to be doing too great on the [src]!")) - use_power(active_power_usage) + use_energy(active_power_usage) var/turf/griddle_loc = loc if(isturf(griddle_loc)) diff --git a/code/modules/food_and_drinks/machinery/microwave.dm b/code/modules/food_and_drinks/machinery/microwave.dm index abc22bcab4574..1834b23e56345 100644 --- a/code/modules/food_and_drinks/machinery/microwave.dm +++ b/code/modules/food_and_drinks/machinery/microwave.dm @@ -675,7 +675,7 @@ pre_success(cooker) return cycles-- - use_power(active_power_usage) + use_energy(active_power_usage) addtimer(CALLBACK(src, PROC_REF(cook_loop), type, cycles, wait, cooker), wait) /obj/machinery/microwave/power_change() @@ -831,8 +831,9 @@ if(cell_powered && !cell.use(charge_rate)) charge_loop_finish(cooker) - vampire_cell.give(charge_rate * (0.85 + (efficiency * 0.5))) // we lose a tiny bit of power in the transfer as heat - use_power(charge_rate) + use_energy(charge_rate * (0.5 - efficiency * 0.12)) //Some of the power gets lost as heat. + charge_cell(charge_rate * (0.5 + efficiency * 0.12), vampire_cell) //Cell gets charged, which further uses power. + vampire_charge_amount = vampire_cell.maxcharge - vampire_cell.charge diff --git a/code/modules/food_and_drinks/machinery/monkeyrecycler.dm b/code/modules/food_and_drinks/machinery/monkeyrecycler.dm index 6a7db397300e1..d340d4d478d30 100644 --- a/code/modules/food_and_drinks/machinery/monkeyrecycler.dm +++ b/code/modules/food_and_drinks/machinery/monkeyrecycler.dm @@ -79,7 +79,7 @@ GLOBAL_LIST_EMPTY(monkey_recyclers) playsound(src.loc, 'sound/machines/juicer.ogg', 50, TRUE) var/offset = prob(50) ? -2 : 2 animate(src, pixel_x = pixel_x + offset, time = 0.2, loop = 200) //start shaking - use_power(active_power_usage) + use_energy(active_power_usage) stored_matter += cube_production addtimer(VARSET_CALLBACK(src, pixel_x, base_pixel_x)) addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(to_chat), user, span_notice("The machine now has [stored_matter] monkey\s worth of material stored."))) diff --git a/code/modules/food_and_drinks/machinery/oven.dm b/code/modules/food_and_drinks/machinery/oven.dm index 87cffebc8aec8..517e25c6dcba7 100644 --- a/code/modules/food_and_drinks/machinery/oven.dm +++ b/code/modules/food_and_drinks/machinery/oven.dm @@ -93,7 +93,7 @@ visible_message(span_danger("You smell a burnt smell coming from [src]!")) set_smoke_state(worst_cooked_food_state) update_appearance() - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/oven/attackby(obj/item/I, mob/user, params) diff --git a/code/modules/food_and_drinks/machinery/processor.dm b/code/modules/food_and_drinks/machinery/processor.dm index e1d027306eac6..d6780bc95abad 100644 --- a/code/modules/food_and_drinks/machinery/processor.dm +++ b/code/modules/food_and_drinks/machinery/processor.dm @@ -147,7 +147,7 @@ span_notice("You turn on [src]."), \ span_hear("You hear a food processor.")) playsound(src.loc, 'sound/machines/blender.ogg', 50, TRUE) - use_power(active_power_usage) + use_energy(active_power_usage) var/total_time = 0 for(var/atom/movable/movable_input as anything in processor_contents) var/datum/food_processor_process/recipe = PROCESSOR_SELECT_RECIPE(movable_input) diff --git a/code/modules/food_and_drinks/machinery/smartfridge.dm b/code/modules/food_and_drinks/machinery/smartfridge.dm index eeb5efd2642ca..de458bb218736 100644 --- a/code/modules/food_and_drinks/machinery/smartfridge.dm +++ b/code/modules/food_and_drinks/machinery/smartfridge.dm @@ -411,7 +411,7 @@ if(!living_mob.put_in_hands(dispensed_item)) dispensed_item.forceMove(drop_location()) adjust_item_drop_location(dispensed_item) - use_power(active_power_usage) + use_energy(active_power_usage) desired-- if (visible_contents) @@ -546,7 +546,7 @@ SStgui.update_uis(src) update_appearance() - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/smartfridge/drying_rack/accept_check(obj/item/O) return HAS_TRAIT(O, TRAIT_DRYABLE) diff --git a/code/modules/food_and_drinks/machinery/stove_component.dm b/code/modules/food_and_drinks/machinery/stove_component.dm index 697e27f584909..1a39c3b205746 100644 --- a/code/modules/food_and_drinks/machinery/stove_component.dm +++ b/code/modules/food_and_drinks/machinery/stove_component.dm @@ -75,7 +75,7 @@ return container?.reagents.expose_temperature(SOUP_BURN_TEMP + 80, heat_coefficient) - real_parent.use_power(real_parent.active_power_usage) + real_parent.use_energy(real_parent.active_power_usage) var/turf/stove_spot = real_parent.loc if(isturf(stove_spot)) diff --git a/code/modules/holodeck/computer.dm b/code/modules/holodeck/computer.dm index c346d1b31d027..f75a1329246b3 100644 --- a/code/modules/holodeck/computer.dm +++ b/code/modules/holodeck/computer.dm @@ -116,9 +116,9 @@ GLOBAL_LIST_INIT(typecache_holodeck_linked_floorcheck_ok, typecacheof(list(/turf linked.linked = src var/area/my_area = get_area(src) if(my_area) - linked.power_usage = my_area.power_usage + linked.energy_usage = my_area.energy_usage else - linked.power_usage = list(AREA_USAGE_LEN) + linked.energy_usage = list(AREA_USAGE_LEN) COOLDOWN_START(src, holodeck_cooldown, HOLODECK_CD) generate_program_list() @@ -446,7 +446,7 @@ GLOBAL_LIST_INIT(typecache_holodeck_linked_floorcheck_ok, typecacheof(list(/turf reset_to_default() if(linked) linked.linked = null - linked.power_usage = list(AREA_USAGE_LEN) + linked.energy_usage = list(AREA_USAGE_LEN) return ..() /obj/machinery/computer/holodeck/blob_act(obj/structure/blob/B) diff --git a/code/modules/hydroponics/biogenerator.dm b/code/modules/hydroponics/biogenerator.dm index 5b8ce2a930939..260c4042a0a76 100644 --- a/code/modules/hydroponics/biogenerator.dm +++ b/code/modules/hydroponics/biogenerator.dm @@ -322,7 +322,7 @@ convert_to_biomass(food_to_convert) - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) if(!current_item_count) stop_process(FALSE) diff --git a/code/modules/mining/boulder_processing/_boulder_processing.dm b/code/modules/mining/boulder_processing/_boulder_processing.dm index b79bfe36dc6d3..0dfc43cf7f788 100644 --- a/code/modules/mining/boulder_processing/_boulder_processing.dm +++ b/code/modules/mining/boulder_processing/_boulder_processing.dm @@ -195,8 +195,11 @@ if(!can_process_golem(rockman)) return + if(!use_energy(active_power_usage * 1.5, force = FALSE)) + say("Not enough energy!") + return + maim_golem(rockman) - use_power(active_power_usage * 1.5) playsound(src, usage_sound, 50, TRUE, SHORT_RANGE_SOUND_EXTRARANGE) COOLDOWN_START(src, accept_cooldown, 3 SECONDS) @@ -332,6 +335,9 @@ return if(chosen_boulder.loc != src) return + if(!use_energy(active_power_usage, force = FALSE)) + say("Not enough energy!") + return //if boulders are kept inside because there is no space to eject them, then they could be reprocessed, lets avoid that if(!chosen_boulder.processed_by) @@ -347,7 +353,6 @@ points_held = round(points_held + (quantity * possible_mat.points_per_unit * MINING_POINT_MACHINE_MULTIPLIER)) // put point total here into machine if(!silo_materials.mat_container.insert_amount_mat(quantity, possible_mat)) rejected_mats[possible_mat] = quantity - use_power(active_power_usage) //puts back materials that couldn't be processed chosen_boulder.set_custom_materials(rejected_mats, refining_efficiency) diff --git a/code/modules/mining/boulder_processing/brm.dm b/code/modules/mining/boulder_processing/brm.dm index 592ade5b75796..259c3eed5f651 100644 --- a/code/modules/mining/boulder_processing/brm.dm +++ b/code/modules/mining/boulder_processing/brm.dm @@ -268,7 +268,7 @@ random_boulder.pixel_x = rand(-2, 2) random_boulder.pixel_y = rand(-2, 2) balloon_alert_to_viewers("boulder appears!") - use_power(active_power_usage) + use_energy(active_power_usage) //try again if we have more boulders to work with boulders_remaining -= 1 diff --git a/code/modules/mob/living/basic/festivus_pole.dm b/code/modules/mob/living/basic/festivus_pole.dm index aec6de74e1e4c..90eca4b272d3c 100644 --- a/code/modules/mob/living/basic/festivus_pole.dm +++ b/code/modules/mob/living/basic/festivus_pole.dm @@ -38,7 +38,7 @@ ai_controller = /datum/ai_controller/basic_controller/festivus_pole ///how much charge we give off to cells around us when rubbed - var/recharge_value = 75 + var/recharge_value = 75 KILO JOULES /mob/living/basic/festivus/Initialize(mapload) diff --git a/code/modules/mob/living/silicon/ai/life.dm b/code/modules/mob/living/silicon/ai/life.dm index 966db2b7697cd..331291db4ea2f 100644 --- a/code/modules/mob/living/silicon/ai/life.dm +++ b/code/modules/mob/living/silicon/ai/life.dm @@ -31,7 +31,7 @@ if(!lacks_power()) var/area/home = get_area(src) if(home.powered(AREA_USAGE_EQUIP)) - home.use_power(500 * seconds_per_tick, AREA_USAGE_EQUIP) + home.apc?.terminal?.use_energy(500 WATTS * seconds_per_tick, channel = AREA_USAGE_EQUIP) if(aiRestorePowerRoutine >= POWER_RESTORATION_SEARCH_APC) ai_restore_power() diff --git a/code/modules/mob/living/silicon/robot/life.dm b/code/modules/mob/living/silicon/robot/life.dm index ae56f65b0cdf0..2a9631339fc61 100644 --- a/code/modules/mob/living/silicon/robot/life.dm +++ b/code/modules/mob/living/silicon/robot/life.dm @@ -14,14 +14,14 @@ if(cell?.charge) low_power_mode = FALSE else if(stat == CONSCIOUS) - use_power(seconds_per_tick, times_fired) + use_energy(seconds_per_tick, times_fired) -/mob/living/silicon/robot/proc/use_power(seconds_per_tick, times_fired) +/mob/living/silicon/robot/proc/use_energy(seconds_per_tick, times_fired) if(cell?.charge) - if(cell.charge <= 100) + if(cell.charge <= (10 KILO JOULES)) drop_all_held_items() - var/amt = clamp(lamp_enabled * lamp_intensity * seconds_per_tick, 0.5 * seconds_per_tick, cell.charge) //Lamp will use a max of 5 charge, depending on brightness of lamp. If lamp is off, borg systems consume 1 point of charge, or the rest of the cell if it's lower than that. - cell.use(amt) //Usage table: 0.5/second if off/lowest setting, 4 = 2/second, 6 = 4/second, 8 = 6/second, 10 = 8/second + var/energy_consumption = max(lamp_power_consumption * lamp_enabled * lamp_intensity * seconds_per_tick, BORG_MINIMUM_POWER_CONSUMPTION * seconds_per_tick) //Lamp will use a max of 5 * [BORG_LAMP_POWER_CONSUMPTION], depending on brightness of lamp. If lamp is off, borg systems consume [BORG_MINIMUM_POWER_CONSUMPTION], or the rest of the cell if it's lower than that. + cell.use(energy_consumption, force = TRUE) else drop_all_held_items() low_power_mode = TRUE diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index fa6b2d0571630..83f454bc27116 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -226,11 +226,9 @@ if(!ionpulse_on) return - if(cell.charge <= 10) + if(!cell.use(10 KILO JOULES)) toggle_ionpulse() return - - cell.charge -= 10 return TRUE /mob/living/silicon/robot/proc/toggle_ionpulse() @@ -252,7 +250,7 @@ /mob/living/silicon/robot/get_status_tab_items() . = ..() if(cell) - . += "Charge Left: [cell.charge]/[cell.maxcharge]" + . += "Charge Left: [display_energy(cell.charge)]/[display_energy(cell.maxcharge)]" else . += "No Cell Inserted!" diff --git a/code/modules/mob/living/silicon/robot/robot_defines.dm b/code/modules/mob/living/silicon/robot/robot_defines.dm index 12f557962f672..04aadc7e5bc9d 100644 --- a/code/modules/mob/living/silicon/robot/robot_defines.dm +++ b/code/modules/mob/living/silicon/robot/robot_defines.dm @@ -52,6 +52,8 @@ var/lamp_doom = FALSE ///Lamp brightness. Starts at 3, but can be 1 - 5. var/lamp_intensity = 3 + ////Power consumption of the light per lamp_intensity. + var/lamp_power_consumption = BORG_LAMP_POWER_CONSUMPTION var/mutable_appearance/eye_lights diff --git a/code/modules/mod/adding_new_mod.md b/code/modules/mod/adding_new_mod.md index 5dbd10cc5b1be..b0bf12486c14a 100644 --- a/code/modules/mod/adding_new_mod.md +++ b/code/modules/mod/adding_new_mod.md @@ -217,7 +217,7 @@ As we have an usable module, we want to set a cooldown time. All modules are als icon_state = "neuron_healer" module_type = MODULE_USABLE complexity = 3 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/neuron_healer) cooldown_time = 15 SECONDS var/brain_damage_healed = 25 @@ -245,7 +245,7 @@ After this, we want to put our special code, a basic effect of healing all mobs carbon_mob.adjustOrganLoss(ORGAN_SLOT_BRAIN, -brain_damage_healed) mod.wearer.Beam(carbon_mob, icon_state = "plasmabeam", time = 1.5 SECONDS) playsound(src, 'sound/effects/magic.ogg', 100, TRUE) - drain_power(use_power_cost) + drain_power(use_energy_cost) ``` We now have a basic module, we can add it to the techwebs to make it printable ingame, and we can add an inbuilt, advanced version of it for our psychological suit. We'll give it more healing power, no complexity and make it unremovable. diff --git a/code/modules/mod/mod_control.dm b/code/modules/mod/mod_control.dm index d910aef79934a..d316add994910 100644 --- a/code/modules/mod/mod_control.dm +++ b/code/modules/mod/mod_control.dm @@ -233,7 +233,7 @@ if(seconds_electrified > MACHINE_NOT_ELECTRIFIED) seconds_electrified-- if(mod_link.link_call) - subtract_charge((DEFAULT_CHARGE_DRAIN * 0.25) * seconds_per_tick) + subtract_charge(0.25 * DEFAULT_CHARGE_DRAIN * seconds_per_tick) if(!active) return if(!get_charge() && active && !activating) @@ -241,7 +241,7 @@ return var/malfunctioning_charge_drain = 0 if(malfunctioning) - malfunctioning_charge_drain = rand(1,20) + malfunctioning_charge_drain = rand(0.2 * DEFAULT_CHARGE_DRAIN, 4 * DEFAULT_CHARGE_DRAIN) // About triple power usage on average. subtract_charge((charge_drain + malfunctioning_charge_drain) * seconds_per_tick) for(var/obj/item/mod/module/module as anything in modules) if(malfunctioning && module.active && SPT_PROB(5, seconds_per_tick)) diff --git a/code/modules/mod/mod_core.dm b/code/modules/mod/mod_core.dm index 5e7183e2563a3..cd564e12cb82e 100644 --- a/code/modules/mod/mod_core.dm +++ b/code/modules/mod/mod_core.dm @@ -68,7 +68,7 @@ return TRUE /obj/item/mod/core/infinite/subtract_charge(amount) - return TRUE + return amount /obj/item/mod/core/infinite/check_charge(amount) return TRUE @@ -273,8 +273,7 @@ var/obj/item/organ/internal/stomach/ethereal/charge_source = charge_source() if(!charge_source) return FALSE - charge_source.adjust_charge(-amount*charge_modifier) - return TRUE + return -charge_source.adjust_charge(-amount*charge_modifier) /obj/item/mod/core/ethereal/check_charge(amount) return charge_amount() >= amount*charge_modifier @@ -282,8 +281,8 @@ /obj/item/mod/core/ethereal/get_charge_icon_state() return charge_source() ? "0" : "missing" -#define PLASMA_CORE_ORE_CHARGE 1500 -#define PLASMA_CORE_SHEET_CHARGE 2000 +#define PLASMA_CORE_ORE_CHARGE (1.5 * STANDARD_CELL_CHARGE) +#define PLASMA_CORE_SHEET_CHARGE (2 * STANDARD_CELL_CHARGE) /obj/item/mod/core/plasma name = "MOD plasma core" @@ -291,9 +290,9 @@ desc = "Nanotrasen's attempt at capitalizing on their plasma research. These plasma cores are refueled \ through plasma fuel, allowing for easy continued use by their mining squads." /// How much charge we can store. - var/maxcharge = 10000 + var/maxcharge = 10 * STANDARD_CELL_CHARGE /// How much charge we are currently storing. - var/charge = 10000 + var/charge = 10 * STANDARD_CELL_CHARGE /// Associated list of charge sources and how much they charge, only stacks allowed. var/list/charger_list = list(/obj/item/stack/ore/plasma = PLASMA_CORE_ORE_CHARGE, /obj/item/stack/sheet/mineral/plasma = PLASMA_CORE_SHEET_CHARGE) @@ -325,9 +324,10 @@ return TRUE /obj/item/mod/core/plasma/subtract_charge(amount) - charge = max(0, charge - amount) + amount = min(amount, charge) + charge -= amount mod.update_charge_alert() - return TRUE + return amount /obj/item/mod/core/plasma/check_charge(amount) return charge_amount() >= amount diff --git a/code/modules/mod/mod_ui.dm b/code/modules/mod/mod_ui.dm index ec3f393ed506e..2f1e6faa0f429 100644 --- a/code/modules/mod/mod_ui.dm +++ b/code/modules/mod/mod_ui.dm @@ -47,7 +47,7 @@ "pinned" = module.pinned_to[REF(user)], "idle_power" = module.idle_power_cost, "active_power" = module.active_power_cost, - "use_power" = module.use_power_cost, + "use_energy" = module.use_energy_cost, "module_complexity" = module.complexity, "cooldown_time" = module.cooldown_time, "cooldown" = round(COOLDOWN_TIMELEFT(module, cooldown_timer), 1 SECONDS), diff --git a/code/modules/mod/modules/_module.dm b/code/modules/mod/modules/_module.dm index 32a8f2e6cbd1d..8b3166f811b4a 100644 --- a/code/modules/mod/modules/_module.dm +++ b/code/modules/mod/modules/_module.dm @@ -16,7 +16,7 @@ /// Power use when active var/active_power_cost = DEFAULT_CHARGE_DRAIN * 0 /// Power use when used, we call it manually - var/use_power_cost = DEFAULT_CHARGE_DRAIN * 0 + var/use_energy_cost = DEFAULT_CHARGE_DRAIN * 0 /// ID used by their TGUI var/tgui_id /// Linked MODsuit @@ -151,7 +151,7 @@ if(!COOLDOWN_FINISHED(src, cooldown_timer)) balloon_alert(mod.wearer, "on cooldown!") return FALSE - if(!check_power(use_power_cost)) + if(!check_power(use_energy_cost)) balloon_alert(mod.wearer, "not enough charge!") return FALSE if(!(allow_flags & MODULE_ALLOW_PHASEOUT) && istype(mod.wearer.loc, /obj/effect/dummy/phased_mob)) diff --git a/code/modules/mod/modules/module_kinesis.dm b/code/modules/mod/modules/module_kinesis.dm index 0cd1387107188..e6cc55b7a641b 100644 --- a/code/modules/mod/modules/module_kinesis.dm +++ b/code/modules/mod/modules/module_kinesis.dm @@ -9,7 +9,7 @@ icon_state = "kinesis" module_type = MODULE_ACTIVE complexity = 3 - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 incompatible_modules = list(/obj/item/mod/module/anomaly_locked/kinesis) cooldown_time = 0.5 SECONDS overlay_state_inactive = "module_kinesis" @@ -59,7 +59,7 @@ if(!can_grab(target)) balloon_alert(mod.wearer, "can't grab!") return - drain_power(use_power_cost) + drain_power(use_energy_cost) grab_atom(target) /obj/item/mod/module/anomaly_locked/kinesis/on_deactivation(display_message = TRUE, deleting = FALSE) @@ -76,7 +76,7 @@ balloon_alert(mod.wearer, "out of range!") clear_grab() return - drain_power(use_power_cost/10) + drain_power(use_energy_cost/10) if(kinesis_catcher.mouse_params) kinesis_catcher.calculate_params() if(!kinesis_catcher.given_turf) @@ -259,7 +259,7 @@ name = "MOD prototype kinesis module" prebuilt = TRUE complexity = 0 - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 removable = FALSE core_removable = FALSE @@ -280,7 +280,7 @@ This one can force some of the grasped objects to phase through walls. Oh no." complexity = 0 grab_range = INFINITY - use_power_cost = DEFAULT_CHARGE_DRAIN * 0 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0 prebuilt = TRUE stat_required = CONSCIOUS /// Does our object phase through stuff? diff --git a/code/modules/mod/modules/module_pathfinder.dm b/code/modules/mod/modules/module_pathfinder.dm index 087718d14b350..1681496036887 100644 --- a/code/modules/mod/modules/module_pathfinder.dm +++ b/code/modules/mod/modules/module_pathfinder.dm @@ -11,7 +11,7 @@ Nakamura Engineering swears up and down there's airbrakes." icon_state = "pathfinder" complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 10 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 10 incompatible_modules = list(/obj/item/mod/module/pathfinder) /// The pathfinding implant. var/obj/item/implant/mod/implant @@ -68,7 +68,7 @@ human_user.update_action_buttons(TRUE) balloon_alert(human_user, "[mod] attached") playsound(mod, 'sound/machines/ping.ogg', 50, TRUE) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/implant/mod name = "MOD pathfinder implant" diff --git a/code/modules/mod/modules/modules_antag.dm b/code/modules/mod/modules/modules_antag.dm index 2e53e380fd02f..5e335d4955f72 100644 --- a/code/modules/mod/modules/modules_antag.dm +++ b/code/modules/mod/modules/modules_antag.dm @@ -101,7 +101,7 @@ icon_state = "energy_shield" complexity = 3 idle_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 - use_power_cost = DEFAULT_CHARGE_DRAIN * 2 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 2 incompatible_modules = list(/obj/item/mod/module/energy_shield) /// Max charges of the shield. var/max_charges = 1 @@ -148,7 +148,7 @@ SIGNAL_HANDLER if(SEND_SIGNAL(mod, COMSIG_ITEM_HIT_REACT, owner, hitby, attack_text, 0, damage, attack_type, damage_type) & COMPONENT_HIT_REACTION_BLOCK) - drain_power(use_power_cost) + drain_power(use_energy_cost) return SUCCESSFUL_BLOCK return NONE @@ -159,8 +159,8 @@ This shield can perfectly nullify attacks ranging from high-caliber rifles to magic missiles, \ though can also be drained by more mundane attacks. It will not protect the caster from social ridicule." icon_state = "battlemage_shield" - idle_power_cost = DEFAULT_CHARGE_DRAIN * 0 //magic - use_power_cost = DEFAULT_CHARGE_DRAIN * 0 //magic too + idle_power_cost = 0 //magic + use_energy_cost = 0 //magic too max_charges = 15 recharge_start_delay = 0 SECONDS charge_recovery = 8 @@ -271,7 +271,7 @@ desc = initial(the_dna_lock_behind_the_slaughter.desc) icon_state = initial(the_dna_lock_behind_the_slaughter.icon_state) complexity = initial(the_dna_lock_behind_the_slaughter.complexity) - use_power_cost = initial(the_dna_lock_behind_the_slaughter.use_power_cost) + use_energy_cost = initial(the_dna_lock_behind_the_slaughter.use_energy_cost) /obj/item/mod/module/springlock/bite_of_87/on_install() mod.activation_step_time *= 0.1 @@ -293,7 +293,7 @@ icon_state = "flamethrower" module_type = MODULE_ACTIVE complexity = 3 - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 incompatible_modules = list(/obj/item/mod/module/flamethrower) cooldown_time = 2.5 SECONDS overlay_state_inactive = "module_flamethrower" @@ -308,7 +308,7 @@ flame.firer = mod.wearer playsound(src, 'sound/items/modsuit/flamethrower.ogg', 75, TRUE) INVOKE_ASYNC(flame, TYPE_PROC_REF(/obj/projectile, fire)) - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Power kick - Lets the user launch themselves at someone to kick them. /obj/item/mod/module/power_kick @@ -317,7 +317,7 @@ icon_state = "power_kick" module_type = MODULE_ACTIVE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/power_kick) cooldown_time = 5 SECONDS /// Damage on kick. @@ -341,7 +341,7 @@ animate(mod.wearer, 0.2 SECONDS, pixel_z = -16, flags = ANIMATION_RELATIVE, easing = SINE_EASING|EASE_IN) return animate(mod.wearer) - drain_power(use_power_cost) + drain_power(use_energy_cost) playsound(src, 'sound/items/modsuit/loader_launch.ogg', 75, TRUE) var/angle = get_angle(mod.wearer, target) + 180 mod.wearer.transform = mod.wearer.transform.Turn(angle) diff --git a/code/modules/mod/modules/modules_engineering.dm b/code/modules/mod/modules/modules_engineering.dm index fa746048e8201..1ddcab0818073 100644 --- a/code/modules/mod/modules/modules_engineering.dm +++ b/code/modules/mod/modules/modules_engineering.dm @@ -86,7 +86,7 @@ icon_state = "tether" module_type = MODULE_ACTIVE complexity = 2 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/tether) cooldown_time = 1.5 SECONDS @@ -106,7 +106,7 @@ tether.firer = mod.wearer playsound(src, 'sound/weapons/batonextend.ogg', 25, TRUE) INVOKE_ASYNC(tether, TYPE_PROC_REF(/obj/projectile, fire)) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/projectile/tether name = "tether" @@ -187,7 +187,7 @@ module_type = MODULE_USABLE complexity = 2 idle_power_cost = DEFAULT_CHARGE_DRAIN * 0.2 - use_power_cost = DEFAULT_CHARGE_DRAIN * 2 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 2 incompatible_modules = list(/obj/item/mod/module/constructor, /obj/item/mod/module/quick_carry) cooldown_time = 11 SECONDS @@ -202,7 +202,7 @@ if(!.) return rcd_scan(src, fade_time = 10 SECONDS) - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Safety-First Head Protection - Protects your brain matter from sudden impacts. /obj/item/mod/module/headprotector diff --git a/code/modules/mod/modules/modules_general.dm b/code/modules/mod/modules/modules_general.dm index 041e671ccdfff..f80fd952cefe9 100644 --- a/code/modules/mod/modules/modules_general.dm +++ b/code/modules/mod/modules/modules_general.dm @@ -97,7 +97,7 @@ module_type = MODULE_TOGGLE complexity = 3 active_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/jetpack) cooldown_time = 0.5 SECONDS overlay_state_inactive = "module_jetpack" @@ -160,8 +160,8 @@ /obj/item/mod/module/jetpack/proc/allow_thrust(use_fuel = TRUE) if(!use_fuel) - return check_power(use_power_cost) - if(!drain_power(use_power_cost)) + return check_power(use_energy_cost) + if(!drain_power(use_energy_cost)) return FALSE return TRUE @@ -186,7 +186,7 @@ module_type = MODULE_USABLE complexity = 3 cooldown_time = 30 SECONDS - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/jump_jet) /obj/item/mod/module/jump_jet/on_use() @@ -225,7 +225,7 @@ to alert anyone nearby that someone has, in fact, died." icon_state = "status" complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.1 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.1 incompatible_modules = list(/obj/item/mod/module/status_readout) tgui_id = "status_readout" /// Does this show damage types, body temp, satiety @@ -461,7 +461,7 @@ icon_state = "dispenser" module_type = MODULE_USABLE complexity = 3 - use_power_cost = DEFAULT_CHARGE_DRAIN * 2 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 2 incompatible_modules = list(/obj/item/mod/module/dispenser) cooldown_time = 5 SECONDS /// Path we dispense. @@ -480,7 +480,7 @@ mod.wearer.put_in_hands(dispensed) balloon_alert(mod.wearer, "[dispensed] dispensed") playsound(src, 'sound/machines/click.ogg', 100, TRUE) - drain_power(use_power_cost) + drain_power(use_energy_cost) return dispensed ///Longfall - Nullifies fall damage, removing charge instead. @@ -492,7 +492,7 @@ Useful for mining, monorail tracks, or even skydiving!" icon_state = "longfall" complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/longfall) /obj/item/mod/module/longfall/on_suit_activation() @@ -503,7 +503,7 @@ /obj/item/mod/module/longfall/proc/z_impact_react(datum/source, levels, turf/fell_on) SIGNAL_HANDLER - if(!drain_power(use_power_cost * levels)) + if(!drain_power(use_energy_cost * levels)) return NONE new /obj/effect/temp_visual/mook_dust(fell_on) mod.wearer.Stun(levels * 1 SECONDS) @@ -553,7 +553,7 @@ icon_state = "dnalock" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 incompatible_modules = list(/obj/item/mod/module/dna_lock, /obj/item/mod/module/eradication_lock) cooldown_time = 0.5 SECONDS /// The DNA we lock with. @@ -577,7 +577,7 @@ return dna = mod.wearer.dna.unique_enzymes balloon_alert(mod.wearer, "dna updated") - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/dna_lock/emp_act(severity) . = ..() diff --git a/code/modules/mod/modules/modules_maint.dm b/code/modules/mod/modules/modules_maint.dm index 5d0d374523f35..1f7c322e031f7 100644 --- a/code/modules/mod/modules/modules_maint.dm +++ b/code/modules/mod/modules/modules_maint.dm @@ -148,7 +148,7 @@ icon_state = "tanning" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/tanner) cooldown_time = 30 SECONDS @@ -162,7 +162,7 @@ holder.trans_to(mod.wearer, 10, methods = VAPOR) if(prob(5)) SSradiation.irradiate(mod.wearer) - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Balloon Blower - Blows a balloon. /obj/item/mod/module/balloon @@ -171,7 +171,7 @@ icon_state = "bloon" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.5 incompatible_modules = list(/obj/item/mod/module/balloon) cooldown_time = 15 SECONDS @@ -185,7 +185,7 @@ playsound(src, 'sound/items/modsuit/inflate_bloon.ogg', 50, TRUE) var/obj/item/toy/balloon/balloon = new(get_turf(src)) mod.wearer.put_in_hands(balloon) - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Paper Dispenser - Dispenses (sometimes burning) paper sheets. /obj/item/mod/module/paper_dispenser @@ -195,7 +195,7 @@ icon_state = "paper_maker" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.5 incompatible_modules = list(/obj/item/mod/module/paper_dispenser) cooldown_time = 5 SECONDS /// The total number of sheets created by this MOD. The more sheets, them more likely they set on fire. @@ -227,7 +227,7 @@ crisp_paper.visible_message(span_warning("[crisp_paper] bursts into flames, it's too crisp!")) crisp_paper.fire_act(1000, 100) - drain_power(use_power_cost) + drain_power(use_energy_cost) num_sheets_dispensed++ diff --git a/code/modules/mod/modules/modules_medical.dm b/code/modules/mod/modules/modules_medical.dm index 2346d8f930579..6068b18fe1022 100644 --- a/code/modules/mod/modules/modules_medical.dm +++ b/code/modules/mod/modules/modules_medical.dm @@ -14,7 +14,7 @@ icon_state = "health" module_type = MODULE_ACTIVE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/health_analyzer) cooldown_time = 0.5 SECONDS tgui_id = "health_analyzer" @@ -48,7 +48,7 @@ woundscan(mod.wearer, target) if(CHEM_SCAN) chemscan(mod.wearer, target) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/health_analyzer/get_configuration() . = ..() @@ -128,7 +128,7 @@ icon_state = "organ_thrower" module_type = MODULE_ACTIVE complexity = 2 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/organ_thrower, /obj/item/mod/module/microwave_beam) cooldown_time = 0.5 SECONDS /// How many organs the module can hold. @@ -152,7 +152,7 @@ organ.forceMove(src) balloon_alert(mod.wearer, "picked up [organ]") playsound(src, 'sound/mecha/hydraulic.ogg', 25, TRUE) - drain_power(use_power_cost) + drain_power(use_energy_cost) return if(!length(organ_list)) return @@ -162,7 +162,7 @@ projectile.firer = mod.wearer playsound(src, 'sound/mecha/hydraulic.ogg', 25, TRUE) INVOKE_ASYNC(projectile, TYPE_PROC_REF(/obj/projectile, fire)) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/projectile/organ name = "organ" @@ -241,7 +241,7 @@ icon_state = "defibrillator" module_type = MODULE_ACTIVE complexity = 2 - use_power_cost = DEFAULT_CHARGE_DRAIN * 25 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 25 device = /obj/item/shockpaddles/mod overlay_state_inactive = "module_defibrillator" overlay_state_active = "module_defibrillator_active" @@ -254,7 +254,7 @@ RegisterSignal(device, COMSIG_DEFIBRILLATOR_SUCCESS, PROC_REF(on_defib_success)) /obj/item/mod/module/defibrillator/proc/on_defib_success(obj/item/shockpaddles/source) - drain_power(use_power_cost) + drain_power(use_energy_cost) source.recharge(defib_cooldown) return COMPONENT_DEFIB_STOP @@ -304,7 +304,7 @@ icon_state = "thread_ripper" module_type = MODULE_ACTIVE complexity = 2 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/thread_ripper) cooldown_time = 1.5 SECONDS overlay_state_inactive = "module_threadripper" diff --git a/code/modules/mod/modules/modules_ninja.dm b/code/modules/mod/modules/modules_ninja.dm index f175dda031761..44b3678132a9e 100644 --- a/code/modules/mod/modules/modules_ninja.dm +++ b/code/modules/mod/modules/modules_ninja.dm @@ -10,7 +10,7 @@ module_type = MODULE_TOGGLE complexity = 4 active_power_cost = DEFAULT_CHARGE_DRAIN * 2 - use_power_cost = DEFAULT_CHARGE_DRAIN * 10 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 10 incompatible_modules = list(/obj/item/mod/module/stealth) cooldown_time = 5 SECONDS /// Whether or not the cloak turns off on bumping. @@ -28,7 +28,7 @@ RegisterSignal(mod.wearer, COMSIG_ATOM_BULLET_ACT, PROC_REF(on_bullet_act)) RegisterSignals(mod.wearer, list(COMSIG_MOB_ITEM_ATTACK, COMSIG_ATOM_ATTACKBY, COMSIG_ATOM_ATTACK_HAND, COMSIG_ATOM_HITBY, COMSIG_ATOM_HULK_ATTACK, COMSIG_ATOM_ATTACK_PAW, COMSIG_CARBON_CUFF_ATTEMPTED), PROC_REF(unstealth)) animate(mod.wearer, alpha = stealth_alpha, time = 1.5 SECONDS) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/stealth/on_deactivation(display_message = TRUE, deleting = FALSE) . = ..() @@ -44,7 +44,7 @@ to_chat(mod.wearer, span_warning("[src] gets discharged from contact!")) do_sparks(2, TRUE, src) - drain_power(use_power_cost) + drain_power(use_energy_cost) on_deactivation(display_message = TRUE, deleting = FALSE) /obj/item/mod/module/stealth/proc/on_unarmed_attack(datum/source, atom/target) @@ -73,7 +73,7 @@ bumpoff = FALSE stealth_alpha = 20 active_power_cost = DEFAULT_CHARGE_DRAIN - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 cooldown_time = 3 SECONDS /obj/item/mod/module/stealth/ninja/on_activation() @@ -174,7 +174,7 @@ icon_state = "recall" removable = FALSE module_type = MODULE_USABLE - use_power_cost = DEFAULT_CHARGE_DRAIN * 2 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 2 incompatible_modules = list(/obj/item/mod/module/weapon_recall) cooldown_time = 0.5 SECONDS /// The item linked to the module that will get recalled. @@ -205,7 +205,7 @@ return var/distance = get_dist(mod.wearer, linked_weapon) var/in_view = (linked_weapon in view(mod.wearer)) - if(!in_view && !drain_power(use_power_cost * distance)) + if(!in_view && !drain_power(use_energy_cost * distance)) balloon_alert(mod.wearer, "not enough charge!") return linked_weapon.forceMove(linked_weapon.drop_location()) @@ -263,7 +263,7 @@ Due to utilizing a skintight dampening shield, this one is entirely sealed against electromagnetic interference; \ it also dutifully protects the secrets of the Spider Clan from unknowing outsiders." icon_state = "dnalock_ninja" - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.5 /obj/item/mod/module/dna_lock/reinforced/on_mod_activation(datum/source, mob/user) . = ..() @@ -288,7 +288,7 @@ it will piss off everyone around them." icon_state = "emp_pulse" module_type = MODULE_USABLE - use_power_cost = DEFAULT_CHARGE_DRAIN * 10 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 10 cooldown_time = 8 SECONDS /obj/item/mod/module/emp_shield/pulse/on_use() @@ -297,7 +297,7 @@ return playsound(src, 'sound/effects/empulse.ogg', 60, TRUE) empulse(src, heavy_range = 4, light_range = 6) - drain_power(use_power_cost) + drain_power(use_energy_cost) /// Ninja Status Readout - Like the normal status display (see the base type), but with a clock. /obj/item/mod/module/status_readout/ninja @@ -321,7 +321,7 @@ icon_state = "energy_net" removable = FALSE module_type = MODULE_ACTIVE - use_power_cost = DEFAULT_CHARGE_DRAIN * 6 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 6 incompatible_modules = list(/obj/item/mod/module/energy_net) cooldown_time = 5 SECONDS /// List of all energy nets this module made. @@ -342,7 +342,7 @@ net.firer = mod.wearer playsound(src, 'sound/weapons/punchmiss.ogg', 25, TRUE) INVOKE_ASYNC(net, TYPE_PROC_REF(/obj/projectile, fire)) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/energy_net/proc/add_net(obj/structure/energy_net/net) energy_nets += net diff --git a/code/modules/mod/modules/modules_science.dm b/code/modules/mod/modules/modules_science.dm index c8d3cef027ae6..a5a56975f6c53 100644 --- a/code/modules/mod/modules/modules_science.dm +++ b/code/modules/mod/modules/modules_science.dm @@ -100,7 +100,7 @@ icon_state = "teleporter" module_type = MODULE_ACTIVE complexity = 3 - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 cooldown_time = 5 SECONDS accepted_anomalies = list(/obj/item/assembly/signaler/anomaly/bluespace) /// Time it takes to teleport @@ -127,7 +127,7 @@ animate(mod.wearer, teleport_time*0.1, color = null, transform = post_matrix.Multiply(mod.wearer.transform), easing = SINE_EASING|EASE_IN) if(!do_teleport(mod.wearer, target_turf, asoundin = 'sound/effects/phasein.ogg')) return - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/anomaly_locked/teleporter/prebuilt prebuilt = TRUE diff --git a/code/modules/mod/modules/modules_security.dm b/code/modules/mod/modules/modules_security.dm index f5033cea4f67e..6d91b24469ba0 100644 --- a/code/modules/mod/modules/modules_security.dm +++ b/code/modules/mod/modules/modules_security.dm @@ -6,7 +6,7 @@ desc = "Based off old TerraGov harness kits, this magnetic harness automatically attaches dropped guns back to the wearer." icon_state = "mag_harness" complexity = 2 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/magnetic_harness) /// Time before we activate the magnet. var/magnet_delay = 0.8 SECONDS @@ -51,7 +51,7 @@ return playsound(src, 'sound/items/modsuit/magnetic_harness.ogg', 50, TRUE) balloon_alert(mod.wearer, "[item] reattached") - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Pepper Shoulders - When hit, reacts with a spray of pepper spray around the user. /obj/item/mod/module/pepper_shoulders @@ -60,7 +60,7 @@ icon_state = "pepper_shoulder" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/pepper_shoulders) cooldown_time = 5 SECONDS overlay_state_inactive = "module_pepper" @@ -89,7 +89,7 @@ if(!COOLDOWN_FINISHED(src, cooldown_timer)) return - if(!check_power(use_power_cost)) + if(!check_power(use_energy_cost)) return mod.wearer.visible_message(span_warning("[src] reacts to the attack with a smoke of pepper spray!"), span_notice("Your [src] releases a cloud of pepper spray!")) on_use() @@ -152,7 +152,7 @@ icon_state = "megaphone" module_type = MODULE_TOGGLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.5 incompatible_modules = list(/obj/item/mod/module/megaphone) cooldown_time = 0.5 SECONDS /// List of spans we add to the speaker. @@ -174,7 +174,7 @@ SIGNAL_HANDLER speech_args[SPEECH_SPANS] |= voicespan - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Criminal Capture - Generates hardlight bags you can put people in and sinch. /obj/item/mod/module/criminalcapture @@ -187,7 +187,7 @@ icon_state = "criminal_capture" module_type = MODULE_ACTIVE complexity = 2 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.5 incompatible_modules = list(/obj/item/mod/module/criminalcapture) cooldown_time = 0.5 SECONDS /// Time to capture a prisoner. @@ -366,7 +366,7 @@ icon_state = "active_sonar" module_type = MODULE_USABLE idle_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 complexity = 2 incompatible_modules = list(/obj/item/mod/module/active_sonar) cooldown_time = 15 SECONDS diff --git a/code/modules/mod/modules/modules_service.dm b/code/modules/mod/modules/modules_service.dm index e6e4a01c66475..b4870a84ec503 100644 --- a/code/modules/mod/modules/modules_service.dm +++ b/code/modules/mod/modules/modules_service.dm @@ -8,7 +8,7 @@ icon_state = "bikehorn" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/bikehorn) cooldown_time = 1 SECONDS @@ -17,7 +17,7 @@ if(!.) return playsound(src, 'sound/items/bikehorn.ogg', 100, FALSE) - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Microwave Beam - Microwaves items instantly. /obj/item/mod/module/microwave_beam @@ -28,7 +28,7 @@ icon_state = "microwave_beam" module_type = MODULE_ACTIVE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/microwave_beam, /obj/item/mod/module/organ_thrower) cooldown_time = 10 SECONDS @@ -53,7 +53,7 @@ var/datum/effect_system/spark_spread/spark_effect_two = new() spark_effect_two.set_up(2, 1, microwave_target) spark_effect_two.start() - drain_power(use_power_cost) + drain_power(use_energy_cost) //Waddle - Makes you waddle and squeak. /obj/item/mod/module/waddle diff --git a/code/modules/mod/modules/modules_supply.dm b/code/modules/mod/modules/modules_supply.dm index e897bcba179b2..de1efdcc4e2fd 100644 --- a/code/modules/mod/modules/modules_supply.dm +++ b/code/modules/mod/modules/modules_supply.dm @@ -9,7 +9,7 @@ icon_state = "gps" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.2 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.2 incompatible_modules = list(/obj/item/mod/module/gps) cooldown_time = 0.5 SECONDS allow_flags = MODULE_ALLOW_INACTIVE @@ -33,7 +33,7 @@ icon_state = "clamp" module_type = MODULE_ACTIVE complexity = 3 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/clamp) cooldown_time = 0.5 SECONDS overlay_state_inactive = "module_clamp" @@ -64,7 +64,7 @@ stored_crates += picked_crate picked_crate.forceMove(src) balloon_alert(mod.wearer, "picked up [picked_crate]") - drain_power(use_power_cost) + drain_power(use_energy_cost) else if(length(stored_crates)) var/turf/target_turf = get_turf(target) if(target_turf.is_blocked_turf()) @@ -78,7 +78,7 @@ var/atom/movable/dropped_crate = pop(stored_crates) dropped_crate.forceMove(target_turf) balloon_alert(mod.wearer, "dropped [dropped_crate]") - drain_power(use_power_cost) + drain_power(use_energy_cost) else balloon_alert(mod.wearer, "invalid target!") @@ -119,7 +119,7 @@ icon_state = "drill" module_type = MODULE_ACTIVE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN + use_energy_cost = DEFAULT_CHARGE_DRAIN incompatible_modules = list(/obj/item/mod/module/drill) cooldown_time = 0.5 SECONDS overlay_state_active = "module_drill" @@ -145,17 +145,17 @@ if(ismineralturf(target)) var/turf/closed/mineral/mineral_turf = target mineral_turf.gets_drilled(mod.wearer) - drain_power(use_power_cost) + drain_power(use_energy_cost) else if(isasteroidturf(target)) var/turf/open/misc/asteroid/sand_turf = target if(!sand_turf.can_dig(mod.wearer)) return sand_turf.getDug() - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/drill/proc/bump_mine(mob/living/carbon/human/bumper, atom/bumped_into, proximity) SIGNAL_HANDLER - if(!ismineralturf(bumped_into) || !drain_power(use_power_cost)) + if(!ismineralturf(bumped_into) || !drain_power(use_energy_cost)) return var/turf/closed/mineral/mineral_turf = bumped_into var/turf/closed/mineral/gibtonite/giberal_turf = mineral_turf @@ -176,7 +176,7 @@ icon_state = "ore" module_type = MODULE_USABLE complexity = 1 - use_power_cost = DEFAULT_CHARGE_DRAIN * 0.2 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 0.2 incompatible_modules = list(/obj/item/mod/module/orebag) cooldown_time = 0.5 SECONDS allow_flags = MODULE_ALLOW_INACTIVE @@ -214,7 +214,7 @@ for(var/obj/item/ore as anything in ores) ore.forceMove(drop_location()) ores -= ore - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/hydraulic name = "MOD loader hydraulic arms module" @@ -222,7 +222,7 @@ icon_state = "launch_loader" module_type = MODULE_ACTIVE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN*10 + use_energy_cost = DEFAULT_CHARGE_DRAIN*10 incompatible_modules = list(/obj/item/mod/module/hydraulic) cooldown_time = 4 SECONDS overlay_state_inactive = "module_hydraulic" @@ -252,7 +252,7 @@ if(!do_after(mod.wearer, launch_time, target = mod)) power = world.time - current_time animate(game_renderer) - drain_power(use_power_cost) + drain_power(use_energy_cost) new /obj/effect/temp_visual/mook_dust(get_turf(src)) playsound(src, 'sound/items/modsuit/loader_launch.ogg', 75, TRUE) game_renderer.transform = game_renderer.transform.Scale(0.8, 0.8) @@ -311,7 +311,7 @@ icon_state = "magnet_loader" module_type = MODULE_ACTIVE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 incompatible_modules = list(/obj/item/mod/module/magnet) cooldown_time = 1.5 SECONDS overlay_state_active = "module_magnet" @@ -479,7 +479,7 @@ module_type = MODULE_ACTIVE removable = FALSE active_power_cost = DEFAULT_CHARGE_DRAIN * 0.5 - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 incompatible_modules = list(/obj/item/mod/module/sphere_transform) cooldown_time = 1.25 SECONDS /// Time it takes us to complete the animation. @@ -544,7 +544,7 @@ bomb.firer = mod.wearer playsound(src, 'sound/weapons/gun/general/grenade_launch.ogg', 75, TRUE) INVOKE_ASYNC(bomb, TYPE_PROC_REF(/obj/projectile, fire)) - drain_power(use_power_cost) + drain_power(use_energy_cost) /obj/item/mod/module/sphere_transform/on_active_process(seconds_per_tick) animate(mod.wearer) //stop the animation diff --git a/code/modules/mod/modules/modules_timeline.dm b/code/modules/mod/modules/modules_timeline.dm index 7adf7b13cd931..4e4d751065c71 100644 --- a/code/modules/mod/modules/modules_timeline.dm +++ b/code/modules/mod/modules/modules_timeline.dm @@ -13,7 +13,7 @@ icon_state = "eradicationlock" module_type = MODULE_USABLE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 3 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 3 incompatible_modules = list(/obj/item/mod/module/eradication_lock, /obj/item/mod/module/dna_lock) cooldown_time = 0.5 SECONDS /// The ckey we lock with, to allow all alternate versions of the user. @@ -33,7 +33,7 @@ return true_owner_ckey = mod.wearer.ckey balloon_alert(mod.wearer, "user remembered") - drain_power(use_power_cost) + drain_power(use_energy_cost) ///Signal fired when the modsuit tries activating /obj/item/mod/module/eradication_lock/proc/on_mod_activation(datum/source, mob/user) @@ -62,7 +62,7 @@ icon_state = "rewinder" module_type = MODULE_USABLE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/rewinder) cooldown_time = 20 SECONDS @@ -106,7 +106,7 @@ icon_state = "timestop" module_type = MODULE_USABLE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/timestopper) cooldown_time = 60 SECONDS ///The current timestop in progress. @@ -153,7 +153,7 @@ icon_state = "timeline_jumper" module_type = MODULE_USABLE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/timeline_jumper) cooldown_time = 5 SECONDS allow_flags = MODULE_ALLOW_PHASEOUT @@ -207,7 +207,7 @@ icon_state = "chronogun" module_type = MODULE_ACTIVE removable = FALSE - use_power_cost = DEFAULT_CHARGE_DRAIN * 5 + use_energy_cost = DEFAULT_CHARGE_DRAIN * 5 incompatible_modules = list(/obj/item/mod/module/tem) cooldown_time = 0.5 SECONDS ///Reference to the chrono field being controlled by this module diff --git a/code/modules/modular_computers/computers/item/computer.dm b/code/modules/modular_computers/computers/item/computer.dm index 30373b0d84e61..b2046e75b5188 100644 --- a/code/modules/modular_computers/computers/item/computer.dm +++ b/code/modules/modular_computers/computers/item/computer.dm @@ -156,12 +156,12 @@ /obj/item/modular_computer/proc/on_circuit_attached(datum/source) SIGNAL_HANDLER - RegisterSignal(shell.attached_circuit, COMSIG_CIRCUIT_PRE_POWER_USAGE, PROC_REF(use_power_for_circuits)) + RegisterSignal(shell.attached_circuit, COMSIG_CIRCUIT_PRE_POWER_USAGE, PROC_REF(use_energy_for_circuits)) ///Try to draw power from our internal cell first, before switching to that of the circuit. -/obj/item/modular_computer/proc/use_power_for_circuits(datum/source, power_usage_per_input) +/obj/item/modular_computer/proc/use_energy_for_circuits(datum/source, energy_usage_per_input) SIGNAL_HANDLER - if(use_power(power_usage_per_input, check_programs = FALSE)) + if(use_energy(energy_usage_per_input, check_programs = FALSE)) return COMPONENT_OVERRIDE_POWER_USAGE /obj/item/modular_computer/proc/on_circuit_removed(datum/source) @@ -456,7 +456,7 @@ /obj/item/modular_computer/Exited(atom/movable/gone, direction) if(internal_cell == gone) internal_cell = null - if(enabled && !use_power()) + if(enabled && !use_energy()) shutdown_computer() if(computer_id_slot == gone) computer_id_slot = null @@ -491,7 +491,7 @@ to_chat(user, span_warning("You press the power button, but the computer fails to boot up, displaying variety of errors before shutting down again.")) return FALSE - if(use_power()) // checks if the PC is powered + if(use_energy()) // checks if the PC is powered if(looping_sound) soundloop.start() enabled = TRUE @@ -556,7 +556,7 @@ physical.loc.visible_message(span_notice("[icon2html(physical, viewers(physical.loc))] \The [src] displays a [caller.filedesc] notification: [alerttext]")) /obj/item/modular_computer/proc/ring(ringtone) // bring bring - if(!use_power()) + if(!use_energy()) return if(HAS_TRAIT(SSstation, STATION_TRAIT_PDA_GLITCHED)) playsound(src, pick('sound/machines/twobeep_voice1.ogg', 'sound/machines/twobeep_voice2.ogg'), 50, TRUE) diff --git a/code/modules/modular_computers/computers/item/computer_power.dm b/code/modules/modular_computers/computers/item/computer_power.dm index f74a799603f2f..0b18bf47bdc47 100644 --- a/code/modules/modular_computers/computers/item/computer_power.dm +++ b/code/modules/modular_computers/computers/item/computer_power.dm @@ -3,17 +3,17 @@ ///Draws power from its rightful source (area if its a computer, the cell otherwise) ///Takes into account special cases, like silicon PDAs through override, and nopower apps. -/obj/item/modular_computer/proc/use_power(amount = 0, check_programs = TRUE) +/obj/item/modular_computer/proc/use_energy(amount = 0, check_programs = TRUE) if(check_power_override(amount)) return TRUE if(!internal_cell) return FALSE - if(internal_cell.use(amount JOULES)) + if(internal_cell.use(amount)) return TRUE if(!check_programs) return FALSE - internal_cell.use(min(amount JOULES, internal_cell.charge)) //drain it anyways. + internal_cell.use(min(amount, internal_cell.charge)) //drain it anyways. if(active_program?.program_flags & PROGRAM_RUNS_WITHOUT_POWER) return TRUE INVOKE_ASYNC(src, PROC_REF(close_all_programs)) @@ -53,7 +53,7 @@ if(open_programs in idle_threads) power_usage += (open_programs.power_cell_use / 2) - if(use_power(power_usage * seconds_per_tick)) + if(use_energy(power_usage * seconds_per_tick)) return TRUE power_failure() return FALSE diff --git a/code/modules/modular_computers/computers/item/processor.dm b/code/modules/modular_computers/computers/item/processor.dm index 1d947a5574be0..3a8f58576c945 100644 --- a/code/modules/modular_computers/computers/item/processor.dm +++ b/code/modules/modular_computers/computers/item/processor.dm @@ -44,10 +44,10 @@ machinery_computer = null return ..() -/obj/item/modular_computer/processor/use_power(amount = 0, check_programs = TRUE) +/obj/item/modular_computer/processor/use_energy(amount = 0, check_programs = TRUE) var/obj/machinery/machine_holder = physical if(machine_holder.powered()) - machine_holder.use_power(amount) + machine_holder.use_energy(amount) return TRUE return ..() diff --git a/code/modules/modular_computers/computers/machinery/modular_computer.dm b/code/modules/modular_computers/computers/machinery/modular_computer.dm index 8fb32244e1d5f..0e17f012453ab 100644 --- a/code/modules/modular_computers/computers/machinery/modular_computer.dm +++ b/code/modules/modular_computers/computers/machinery/modular_computer.dm @@ -6,7 +6,7 @@ desc = "You shouldn't see this. If you do, report it." //they should be examining the processor instead icon = 'icons/obj/machines/modular_console.dmi' icon_state = "console" - idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 0.05 + idle_power_usage = BASE_MACHINE_IDLE_CONSUMPTION * 0.025 density = TRUE max_integrity = 300 integrity_failure = 0.5 @@ -129,7 +129,7 @@ // Modular computers can have battery in them, we handle power in previous proc, so prevent this from messing it up for us. /obj/machinery/modular_computer/power_change() - if(cpu?.use_power()) // If it still has a power source, PC wouldn't go offline. + if(cpu?.use_energy()) // If it still has a power source, PC wouldn't go offline. set_machine_stat(machine_stat & ~NOPOWER) update_appearance() return @@ -140,10 +140,7 @@ var/obj/item/stock_parts/cell/cell = get_cell() if(isnull(cell) || cell.percent() >= 100) return - var/power_to_draw = idle_power_usage * seconds_per_tick * 0.5 - if(!use_power_from_net(power_to_draw)) - return - cell.give(power_to_draw) + charge_cell(idle_power_usage * seconds_per_tick, cell) /obj/machinery/modular_computer/get_cell() return cpu?.internal_cell diff --git a/code/modules/modular_computers/file_system/programs/powermonitor.dm b/code/modules/modular_computers/file_system/programs/powermonitor.dm index c5a8eba952b2a..817cad275cd1e 100644 --- a/code/modules/modular_computers/file_system/programs/powermonitor.dm +++ b/code/modules/modular_computers/file_system/programs/powermonitor.dm @@ -67,13 +67,13 @@ var/list/supply = history["supply"] if(connected_powernet) - supply += connected_powernet.viewavail + supply += energy_to_power(connected_powernet.avail) if(supply.len > record_size) supply.Cut(1, 2) var/list/demand = history["demand"] if(connected_powernet) - demand += connected_powernet.viewload + demand += energy_to_power(connected_powernet.load) if(demand.len > record_size) demand.Cut(1, 2) @@ -84,8 +84,8 @@ data["interval"] = record_interval / 10 data["attached"] = connected_powernet ? TRUE : FALSE if(connected_powernet) - data["supply"] = display_power(connected_powernet.viewavail) - data["demand"] = display_power(connected_powernet.viewload) + data["supply"] = display_power(connected_powernet.avail) + data["demand"] = display_power(connected_powernet.load) data["history"] = history data["areas"] = list() diff --git a/code/modules/modular_computers/file_system/programs/robotact.dm b/code/modules/modular_computers/file_system/programs/robotact.dm index 8a2a824d004d2..1738943b53399 100644 --- a/code/modules/modular_computers/file_system/programs/robotact.dm +++ b/code/modules/modular_computers/file_system/programs/robotact.dm @@ -47,6 +47,7 @@ data["maxcharge"] = maxcharge //Cell max charge data["integrity"] = ((cyborg.health + 100) / 2) //health, as percentage data["lampIntensity"] = cyborg.lamp_intensity //lamp power setting + data["lampConsumption"] = cyborg.lamp_power_consumption //Power consumption of the lamp per lamp intensity. data["sensors"] = "[cyborg.sensors_on?"ACTIVE":"DISABLED"]" data["printerPictures"] = cyborg.connected_ai? cyborg.connected_ai.aicamera.stored.len : cyborg.aicamera.stored.len //Number of pictures taken, synced to AI if available data["printerToner"] = cyborg.toner //amount of toner diff --git a/code/modules/plumbing/plumbers/acclimator.dm b/code/modules/plumbing/plumbers/acclimator.dm index 850ebaaa3ed1c..79b525d3504da 100644 --- a/code/modules/plumbing/plumbers/acclimator.dm +++ b/code/modules/plumbing/plumbers/acclimator.dm @@ -55,7 +55,7 @@ if(!emptying) //suspend heating/cooling during emptying phase reagents.adjust_thermal_energy((target_temperature - reagents.chem_temp) * HEATER_COEFFICIENT * seconds_per_tick * SPECIFIC_HEAT_DEFAULT * reagents.total_volume) //keep constant with chem heater reagents.handle_reactions() - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) else if(acclimate_state != NEUTRAL) acclimate_state = NEUTRAL update_appearance() diff --git a/code/modules/plumbing/plumbers/bottler.dm b/code/modules/plumbing/plumbers/bottler.dm index 8e0158b61da78..1acbed37a74e0 100644 --- a/code/modules/plumbing/plumbers/bottler.dm +++ b/code/modules/plumbing/plumbers/bottler.dm @@ -80,7 +80,7 @@ ///see if machine has enough to fill, is anchored down and has any inputspot objects to pick from if(reagents.total_volume >= wanted_amount && anchored && length(inputspot.contents)) - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) var/obj/AM = pick(inputspot.contents)///pick a reagent_container that could be used //allowed containers var/static/list/allowed_containers = list( diff --git a/code/modules/plumbing/plumbers/destroyer.dm b/code/modules/plumbing/plumbers/destroyer.dm index 9ba669818cf45..5f81e24eaf24c 100644 --- a/code/modules/plumbing/plumbers/destroyer.dm +++ b/code/modules/plumbing/plumbers/destroyer.dm @@ -19,7 +19,7 @@ if(icon_state != initial(icon_state) + "_working") //threw it here instead of update icon since it only has two states icon_state = initial(icon_state) + "_working" reagents.remove_all(disposal_rate * seconds_per_tick) - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) else if(icon_state != initial(icon_state)) icon_state = initial(icon_state) diff --git a/code/modules/plumbing/plumbers/fermenter.dm b/code/modules/plumbing/plumbers/fermenter.dm index 0fd631ca45733..8800029779db3 100644 --- a/code/modules/plumbing/plumbers/fermenter.dm +++ b/code/modules/plumbing/plumbers/fermenter.dm @@ -47,5 +47,5 @@ if(G.distill_reagent) var/amount = G.seed.potency * 0.25 reagents.add_reagent(G.distill_reagent, amount) - use_power(active_power_usage * amount) + use_energy(active_power_usage * amount) qdel(G) diff --git a/code/modules/plumbing/plumbers/grinder_chemical.dm b/code/modules/plumbing/plumbers/grinder_chemical.dm index e70977bc1f445..ae356fef089ce 100644 --- a/code/modules/plumbing/plumbers/grinder_chemical.dm +++ b/code/modules/plumbing/plumbers/grinder_chemical.dm @@ -57,7 +57,7 @@ var/obj/item/I = AM var/result if(I.grind_results || I.juice_typepath) - use_power(active_power_usage) + use_energy(active_power_usage) if(I.grind_results) result = I.grind(reagents, usr) else if (I.juice_typepath) diff --git a/code/modules/plumbing/plumbers/pill_press.dm b/code/modules/plumbing/plumbers/pill_press.dm index 26835e7c92d6f..2db9222e7c7f6 100644 --- a/code/modules/plumbing/plumbers/pill_press.dm +++ b/code/modules/plumbing/plumbers/pill_press.dm @@ -105,7 +105,7 @@ stored_products -= AM AM.forceMove(drop_location()) - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) /obj/machinery/plumbing/pill_press/ui_assets(mob/user) return list( diff --git a/code/modules/plumbing/plumbers/reaction_chamber.dm b/code/modules/plumbing/plumbers/reaction_chamber.dm index 2b56bfb4ae6c9..72caa60376745 100644 --- a/code/modules/plumbing/plumbers/reaction_chamber.dm +++ b/code/modules/plumbing/plumbers/reaction_chamber.dm @@ -64,7 +64,7 @@ //full power for doing reactions power_usage *= 2 - use_power(power_usage * seconds_per_tick) + use_energy(power_usage * seconds_per_tick) ///For subtypes that want to do additional reagent handling /obj/machinery/plumbing/reaction_chamber/proc/handle_reagents(seconds_per_tick) @@ -198,7 +198,7 @@ return //some power for accurate ph balancing & keep track of attempts made - use_power(active_power_usage * 0.03 * buffer_amount) + use_energy(active_power_usage * 0.03 * buffer_amount) /obj/machinery/plumbing/reaction_chamber/chem/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) diff --git a/code/modules/plumbing/plumbers/synthesizer.dm b/code/modules/plumbing/plumbers/synthesizer.dm index 8f5b46abaa19a..d7a5d83a2518e 100644 --- a/code/modules/plumbing/plumbers/synthesizer.dm +++ b/code/modules/plumbing/plumbers/synthesizer.dm @@ -57,7 +57,7 @@ return reagents.add_reagent(reagent_id, amount) - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/plumbing/synthesizer/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) diff --git a/code/modules/plumbing/plumbers/teleporter.dm b/code/modules/plumbing/plumbers/teleporter.dm index 7bb098eae4e06..e1aa26532dce8 100644 --- a/code/modules/plumbing/plumbers/teleporter.dm +++ b/code/modules/plumbing/plumbers/teleporter.dm @@ -95,7 +95,7 @@ next_index++ - use_power(active_power_usage * seconds_per_tick) + use_energy(active_power_usage * seconds_per_tick) ///Notify all senders to forget us /obj/machinery/plumbing/receiver/proc/lose_senders() diff --git a/code/modules/power/apc/apc_attack.dm b/code/modules/power/apc/apc_attack.dm index 88271a6b1fc24..a76a8a9756967 100644 --- a/code/modules/power/apc/apc_attack.dm +++ b/code/modules/power/apc/apc_attack.dm @@ -34,7 +34,6 @@ cell = attacking_object user.visible_message(span_notice("[user.name] inserts the power cell to [src.name]!")) balloon_alert(user, "cell inserted") - chargecount = 0 update_appearance() return @@ -134,7 +133,6 @@ var/obj/item/stock_parts/cell/crap/empty/bad_cell = new(src) bad_cell.forceMove(src) cell = bad_cell - chargecount = 0 user.visible_message(span_notice("[user] fabricates a weak power cell and places it into [src]."), \ span_warning("Your [pseudocircuit.name] whirrs with strain as you create a weak power cell and place it into [src]!")) update_appearance() @@ -246,7 +244,7 @@ while(do_after(user, APC_DRAIN_TIME, target = src)) balloon_alert(ethereal, "transferred power") stomach.adjust_charge(-APC_POWER_GAIN) - cell.give(APC_POWER_GAIN) + cell.give(-stomach.adjust_charge(-APC_POWER_GAIN)) else balloon_alert(ethereal, "can't transfer power!") diff --git a/code/modules/power/apc/apc_main.dm b/code/modules/power/apc/apc_main.dm index df0cbe9eda979..72b8f8084cdb7 100644 --- a/code/modules/power/apc/apc_main.dm +++ b/code/modules/power/apc/apc_main.dm @@ -17,6 +17,7 @@ damage_deflection = 10 resistance_flags = FIRE_PROOF interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON + processing_flags = START_PROCESSING_MANUALLY ///Range of the light emitted when on var/light_on_range = 1.5 @@ -46,8 +47,6 @@ var/charging = APC_NOT_CHARGING ///Can the APC charge? var/chargemode = TRUE - ///Number of ticks where the apc is trying to recharge - var/chargecount = 0 ///Is the apc interface locked? var/locked = TRUE ///Is the apc cover locked? @@ -140,6 +139,12 @@ /obj/machinery/power/apc/Initialize(mapload, ndir) . = ..() + //APCs get added to their own processing tasks for the machines subsystem. + if (!(datum_flags & DF_ISPROCESSING)) + datum_flags |= DF_ISPROCESSING + SSmachines.apc_early_processing += src + SSmachines.apc_late_processing += src + //Pixel offset its appearance based on its direction dir = ndir switch(dir) @@ -329,6 +334,7 @@ "powerCellStatus" = cell ? cell.percent() : null, "chargeMode" = chargemode, "chargingStatus" = charging, + "chargingPowerDisplay" = display_power(area.energy_usage[AREA_USAGE_APC_CHARGE]), "totalLoad" = display_power(lastused_total), "coverLocked" = coverlocked, "remoteAccess" = (user == remote_control_user), @@ -481,7 +487,20 @@ if(user == remote_control_user) disconnect_remote_access() -/obj/machinery/power/apc/process() +/** + * APC early processing. This gets processed before any other machine does. + * This adds up the total static power usage for the apc's area, then draw that power usage from the grid or APC cell. + * This is done early so machines that use dynamic power get a more truthful surplus when accessing available energy. + */ +/obj/machinery/power/apc/proc/early_process() + var/total_static_energy_usage = 0 + total_static_energy_usage += APC_CHANNEL_IS_ON(lighting) * area.energy_usage[AREA_USAGE_STATIC_LIGHT] + total_static_energy_usage += APC_CHANNEL_IS_ON(equipment) * area.energy_usage[AREA_USAGE_STATIC_EQUIP] + total_static_energy_usage += APC_CHANNEL_IS_ON(environ) * area.energy_usage[AREA_USAGE_STATIC_ENVIRON] + if(total_static_energy_usage) //Use power from static power users. + draw_energy(total_static_energy_usage) + +/obj/machinery/power/apc/proc/late_process(seconds_per_tick) if(icon_update_needed) update_appearance() if(machine_stat & (BROKEN|MAINT)) @@ -499,13 +518,14 @@ flicker_hacked_icon() //dont use any power from that channel if we shut that power channel off - lastused_light = APC_CHANNEL_IS_ON(lighting) ? area.power_usage[AREA_USAGE_LIGHT] + area.power_usage[AREA_USAGE_STATIC_LIGHT] : 0 - lastused_equip = APC_CHANNEL_IS_ON(equipment) ? area.power_usage[AREA_USAGE_EQUIP] + area.power_usage[AREA_USAGE_STATIC_EQUIP] : 0 - lastused_environ = APC_CHANNEL_IS_ON(environ) ? area.power_usage[AREA_USAGE_ENVIRON] + area.power_usage[AREA_USAGE_STATIC_ENVIRON] : 0 + lastused_light = APC_CHANNEL_IS_ON(lighting) ? area.energy_usage[AREA_USAGE_LIGHT] + area.energy_usage[AREA_USAGE_STATIC_LIGHT] : 0 + lastused_equip = APC_CHANNEL_IS_ON(equipment) ? area.energy_usage[AREA_USAGE_EQUIP] + area.energy_usage[AREA_USAGE_STATIC_EQUIP] : 0 + lastused_environ = APC_CHANNEL_IS_ON(environ) ? area.energy_usage[AREA_USAGE_ENVIRON] + area.energy_usage[AREA_USAGE_STATIC_ENVIRON] : 0 area.clear_usage() lastused_total = lastused_light + lastused_equip + lastused_environ + //store states to update icon if any change var/last_lt = lighting var/last_eq = equipment @@ -516,49 +536,13 @@ if(!avail()) main_status = APC_NO_POWER - else if(excess < 0) + else if(excess <= 0) main_status = APC_LOW_POWER else main_status = APC_HAS_POWER - var/cellused - if(cell && !shorted) - // draw power from cell as before to power the area - cellused = min(cell.charge, lastused_total JOULES) // clamp deduction to a max, amount left in cell - cell.use(cellused) - - if(cell && !shorted) //need to check to make sure the cell is still there since rigged/corrupted cells can randomly explode after use(). - if(excess > lastused_total) // if power excess recharge the cell - // by the same amount just used - cell.give(cellused) - if(cell) //make sure the cell didn't expode and actually used power. - add_load(cellused WATTS) // add the load used to recharge the cell - - - else // no excess, and not enough per-apc - if((cell.charge WATTS + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage? - cell.charge = min(cell.maxcharge, cell.charge + excess JOULES) //recharge with what we can - add_load(excess) // so draw what we can from the grid - charging = APC_NOT_CHARGING - - else // not enough power available to run the last tick! - charging = APC_NOT_CHARGING - chargecount = 0 - // This turns everything off in the case that there is still a charge left on the battery, just not enough to run the room. - equipment = autoset(equipment, AUTOSET_FORCE_OFF) - lighting = autoset(lighting, AUTOSET_FORCE_OFF) - environ = autoset(environ, AUTOSET_FORCE_OFF) - if(cell && !shorted) //need to check to make sure the cell is still there since rigged/corrupted cells can randomly explode after give(). - // set channels depending on how much charge we have left - - // Allow the APC to operate as normal if the cell can charge - if(charging && long_term_power < 10) - long_term_power += 1 - else if(long_term_power > -10) - long_term_power -= 2 - if(cell.charge <= 0) // zero charge, turn all off equipment = autoset(equipment, AUTOSET_FORCE_OFF) lighting = autoset(lighting, AUTOSET_FORCE_OFF) @@ -567,7 +551,7 @@ if(!nightshift_lights || (nightshift_lights && !low_power_nightshift_lights)) low_power_nightshift_lights = TRUE INVOKE_ASYNC(src, PROC_REF(set_nightshift), TRUE) - else if(cell.percent() < 15 && long_term_power < 0) // <15%, turn off lighting & equipment + else if(cell.percent() < 15) // <15%, turn off lighting & equipment equipment = autoset(equipment, AUTOSET_OFF) lighting = autoset(lighting, AUTOSET_OFF) environ = autoset(environ, AUTOSET_ON) @@ -575,7 +559,7 @@ if(!nightshift_lights || (nightshift_lights && !low_power_nightshift_lights)) low_power_nightshift_lights = TRUE INVOKE_ASYNC(src, PROC_REF(set_nightshift), TRUE) - else if(cell.percent() < 30 && long_term_power < 0) // <30%, turn off equipment + else if(cell.percent() < 30) // <30%, turn off equipment equipment = autoset(equipment, AUTOSET_OFF) lighting = autoset(lighting, AUTOSET_ON) environ = autoset(environ, AUTOSET_ON) @@ -594,44 +578,20 @@ if(cell.percent() > 75) alarm_manager.clear_alarm(ALARM_POWER) - + charging = APC_NOT_CHARGING // now trickle-charge the cell - if(chargemode && charging == APC_CHARGING && operating) - if(excess > 0) // check to make sure we have enough to charge - // Max charge is capped to % per second constant - var/ch = min(excess JOULES, cell.maxcharge JOULES) - add_load(ch WATTS) // Removes the power we're taking from the grid - cell.give(ch) // actually recharge the cell - - else - charging = APC_NOT_CHARGING // stop charging - chargecount = 0 + if(chargemode && operating && excess && cell.used_charge()) + // Max charge is capped to % per second constant. + lastused_total += charge_cell(min(cell.chargerate, cell.maxcharge * GLOB.CHARGELEVEL) * seconds_per_tick, cell = cell, grid_only = TRUE, channel = AREA_USAGE_APC_CHARGE) + charging = APC_CHARGING // show cell as fully charged if so if(cell.charge >= cell.maxcharge) cell.charge = cell.maxcharge charging = APC_FULLY_CHARGED - if(chargemode) - if(!charging) - if(excess > cell.maxcharge*GLOB.CHARGELEVEL) - chargecount++ - else - chargecount = 0 - - if(chargecount == 10) - - chargecount = 0 - charging = APC_CHARGING - - else // chargemode off - charging = APC_NOT_CHARGING - chargecount = 0 - else // no cell, switch everything off - charging = APC_NOT_CHARGING - chargecount = 0 equipment = autoset(equipment, AUTOSET_FORCE_OFF) lighting = autoset(lighting, AUTOSET_FORCE_OFF) environ = autoset(environ, AUTOSET_FORCE_OFF) @@ -666,8 +626,7 @@ /obj/machinery/power/apc/proc/overload_lighting() if(!operating || shorted) return - if(cell && cell.charge >= 20) - cell.use(20) + if(cell && cell.use(20 KILO JOULES)) INVOKE_ASYNC(src, PROC_REF(break_lights)) /obj/machinery/power/apc/proc/break_lights() @@ -730,6 +689,23 @@ /obj/machinery/power/apc/proc/set_full_charge() cell.charge = cell.maxcharge +/// Returns the cell's current charge. +/obj/machinery/power/apc/proc/charge() + return cell.charge + +/// Draws energy from the connected grid. When there isn't enough surplus energy from the grid, draws the rest of the demand from its cell. Returns the energy used. +/obj/machinery/power/apc/proc/draw_energy(amount) + var/grid_used = min(terminal?.surplus(), amount) + terminal?.add_load(grid_used) + var/cell_used = 0 + if(amount > grid_used) + cell_used += cell.use(amount - grid_used) + return grid_used + cell_used + +/// Draws power from the connected grid. When there isn't enough surplus energy from the grid, draws the rest of the demand from its cell. Returns the energy used. +/obj/machinery/power/apc/proc/draw_power(amount) + return draw_energy(power_to_energy(amount)) + /*Power module, used for APC construction*/ /obj/item/electronics/apc name = "power control module" diff --git a/code/modules/power/apc/apc_power_proc.dm b/code/modules/power/apc/apc_power_proc.dm index 52a671f00f5ae..ba60ec723b6a1 100644 --- a/code/modules/power/apc/apc_power_proc.dm +++ b/code/modules/power/apc/apc_power_proc.dm @@ -50,20 +50,27 @@ update() update_appearance() +/// Returns the surplus energy from the terminal's grid. /obj/machinery/power/apc/surplus() if(terminal) return terminal.surplus() return 0 +/// Adds load (energy) to the terminal's grid. /obj/machinery/power/apc/add_load(amount) if(terminal?.powernet) terminal.add_load(amount) +/// Returns the amount of energy the terminal's grid has. /obj/machinery/power/apc/avail(amount) if(terminal) return terminal.avail(amount) return 0 +/// Returns the surplus energy from the terminal's grid and the cell. +/obj/machinery/power/apc/available_energy() + return charge() + surplus() + /** * Returns the new status value for an APC channel. * diff --git a/code/modules/power/apc/apc_tool_act.dm b/code/modules/power/apc/apc_tool_act.dm index e712f47446481..568563639c839 100644 --- a/code/modules/power/apc/apc_tool_act.dm +++ b/code/modules/power/apc/apc_tool_act.dm @@ -193,7 +193,6 @@ var/obj/item/stock_parts/cell/crap/empty/C = new(src) C.forceMove(src) cell = C - chargecount = 0 balloon_alert(user, "power cell installed") update_appearance() return TRUE diff --git a/code/modules/power/cell.dm b/code/modules/power/cell.dm index 795ff6f099a74..2c4ea37881e53 100644 --- a/code/modules/power/cell.dm +++ b/code/modules/power/cell.dm @@ -30,8 +30,8 @@ var/rigged = FALSE ///If the power cell was damaged by an explosion, chance for it to become corrupted and function the same as rigged. var/corrupted = FALSE - ///how much power is given every tick in a recharger - var/chargerate = STANDARD_CELL_CHARGE * 0.1 + ///How much power is given per second in a recharger. + var/chargerate = STANDARD_CELL_CHARGE * 0.05 ///If true, the cell will state it's maximum charge in it's description var/ratingdesc = TRUE ///If it's a grown that acts as a battery, add a wire overlay to it. @@ -134,30 +134,56 @@ return ..() +/** + * Returns the percentage of the cell's charge. + */ /obj/item/stock_parts/cell/proc/percent() // return % charge of cell return 100 * charge / maxcharge -// use power from a cell -/obj/item/stock_parts/cell/use(used, force) - if(rigged && used > 0) +/** + * Returns the maximum charge of the cell. + */ +/obj/item/stock_parts/cell/proc/max_charge() + return maxcharge + +/** + * Returns the current charge of the cell. + */ +/obj/item/stock_parts/cell/proc/charge() + return charge + +/** + * Returns the amount of charge used on the cell. + */ +/obj/item/stock_parts/cell/proc/used_charge() + return maxcharge - charge + +/// Use power from the cell. +/// Args: +/// - used: Amount of power in joules to use. +/// - force: If true, uses the remaining power from the cell if there isn't enough power to supply the demand. +/// Returns: The power used from the cell in joules. +/obj/item/stock_parts/cell/use(used, force = FALSE) + var/power_used = min(used, charge) + if(rigged && power_used > 0) explode() - return FALSE + return 0 // The cell decided to explode so we won't be able to use it. if(!force && charge < used) - return FALSE - charge = max(charge - used, 0) + return 0 + charge -= power_used if(!istype(loc, /obj/machinery/power/apc)) SSblackbox.record_feedback("tally", "cell_used", 1, type) - return TRUE + return power_used -// recharge the cell +/// Recharge the cell. +/// Args: +/// - amount: The amount of energy to give to the cell in joules. +/// Returns: The power given to the cell in joules. /obj/item/stock_parts/cell/proc/give(amount) - if(rigged && amount > 0) - explode() - return 0 - if(maxcharge < amount) - amount = maxcharge var/power_used = min(maxcharge-charge,amount) charge += power_used + if(rigged && amount > 0) + explode() return power_used /obj/item/stock_parts/cell/examine(mob/user) @@ -180,9 +206,9 @@ /obj/item/stock_parts/cell/proc/explode() if(!charge) return - var/range_devastation = -1 //round(charge/11000) - var/range_heavy = round(sqrt(charge)/60) - var/range_light = round(sqrt(charge)/30) + var/range_devastation = -1 + var/range_heavy = round(sqrt(charge / (3.6 * STANDARD_CELL_CHARGE))) + var/range_light = round(sqrt(charge / (0.9 * STANDARD_CELL_CHARGE))) var/range_flash = range_light if(!range_light) rigged = FALSE @@ -193,7 +219,6 @@ usr?.log_message("triggered a rigged/corrupted power cell explosion", LOG_GAME) usr?.log_message("triggered a rigged/corrupted power cell explosion", LOG_VICTIM, log_globally = FALSE) - //explosion(T, 0, 1, 2, 2) explosion(src, devastation_range = range_devastation, heavy_impact_range = range_heavy, light_impact_range = range_light, flash_range = range_flash) qdel(src) @@ -262,10 +287,7 @@ SSexplosions.high_mov_atom += src /obj/item/stock_parts/cell/proc/get_electrocute_damage() - if(charge >= 1000) - return clamp(20 + round(charge/25000), 20, 195) + rand(-5,5) - else - return 0 + return ELECTROCUTE_DAMAGE(charge) /obj/item/stock_parts/cell/get_part_rating() return maxcharge * 10 + charge @@ -292,7 +314,7 @@ desc = "A power cell with a slightly higher capacity than normal!" maxcharge = STANDARD_CELL_CHARGE * 2.5 custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.5) - chargerate = STANDARD_CELL_CHARGE + chargerate = STANDARD_CELL_CHARGE * 0.5 /obj/item/stock_parts/cell/upgraded/plus name = "upgraded power cell+" @@ -318,7 +340,7 @@ /obj/item/stock_parts/cell/pulse //200 pulse shots name = "pulse rifle power cell" maxcharge = STANDARD_CELL_CHARGE * 40 - chargerate = STANDARD_CELL_CHARGE * 1.5 + chargerate = STANDARD_CELL_CHARGE * 0.75 /obj/item/stock_parts/cell/pulse/carbine //25 pulse shots name = "pulse carbine power cell" @@ -333,14 +355,14 @@ icon_state = "bscell" maxcharge = STANDARD_CELL_CHARGE * 10 custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.6) - chargerate = STANDARD_CELL_CHARGE * 2 + chargerate = STANDARD_CELL_CHARGE /obj/item/stock_parts/cell/high name = "high-capacity power cell" icon_state = "hcell" maxcharge = STANDARD_CELL_CHARGE * 10 custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.6) - chargerate = STANDARD_CELL_CHARGE * 1.5 + chargerate = STANDARD_CELL_CHARGE * 0.75 /obj/item/stock_parts/cell/high/empty empty = TRUE @@ -350,7 +372,7 @@ icon_state = "scell" maxcharge = STANDARD_CELL_CHARGE * 20 custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT * 3) - chargerate = STANDARD_CELL_CHARGE * 2 + chargerate = STANDARD_CELL_CHARGE /obj/item/stock_parts/cell/super/empty empty = TRUE @@ -360,7 +382,7 @@ icon_state = "hpcell" maxcharge = STANDARD_CELL_CHARGE * 30 custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT * 4) - chargerate = STANDARD_CELL_CHARGE * 3 + chargerate = STANDARD_CELL_CHARGE * 1.5 /obj/item/stock_parts/cell/hyper/empty empty = TRUE @@ -371,7 +393,7 @@ icon_state = "bscell" maxcharge = STANDARD_CELL_CHARGE * 40 custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*6) - chargerate = STANDARD_CELL_CHARGE * 4 + chargerate = STANDARD_CELL_CHARGE * 2 /obj/item/stock_parts/cell/bluespace/empty empty = TRUE @@ -384,7 +406,7 @@ chargerate = INFINITY ratingdesc = FALSE -/obj/item/stock_parts/cell/infinite/use(used) +/obj/item/stock_parts/cell/infinite/use(used, force = FALSE) return TRUE /obj/item/stock_parts/cell/infinite/abductor @@ -441,7 +463,7 @@ name = "beam rifle capacitor" desc = "A high powered capacitor that can provide huge amounts of energy in an instant." maxcharge = STANDARD_CELL_CHARGE * 50 - chargerate = STANDARD_CELL_CHARGE * 5 //Extremely energy intensive + chargerate = STANDARD_CELL_CHARGE * 2.5 //Extremely energy intensive /obj/item/stock_parts/cell/beam_rifle/corrupt() return diff --git a/code/modules/power/energy_accumulator.dm b/code/modules/power/energy_accumulator.dm index 80c76f3916d2a..b4970014a6923 100644 --- a/code/modules/power/energy_accumulator.dm +++ b/code/modules/power/energy_accumulator.dm @@ -1,4 +1,4 @@ -/// (this*100)% of stored power outputted per tick. +/// The coefficient of the proportionate power output. /// 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 @@ -9,7 +9,9 @@ /// - 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 +#define ACCUMULATOR_PROPORTIONAL_COEFFICIENT 0.04 +/// The coefficient for the constant power output. +#define ACCUMULATOR_CONSTANT_COEFFICIENT 2000 /// Abstract type for generators that accumulate energy over time and slowly release it /// eg. radiation collectors, tesla coils @@ -20,24 +22,45 @@ var/wants_powernet = TRUE ///The amount of energy that is currently inside the machine before being converted to electricity var/stored_energy = 0 + ///The amount of energy that got processed last tick. + var/processed_energy = 0 /obj/machinery/power/energy_accumulator/proc/get_stored_joules() - return energy_to_joules(stored_energy) + return 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)) +/** + * Gets the energy the energy_accumulator would release within the given timespan time. + * The power output is proportional to the energy, and has a constant power output added to it. + * Args: + * - time: The amount of time that is being processed, in seconds. + * Returns: The amount of energy it would release in the timespan. + */ +/obj/machinery/power/energy_accumulator/proc/calculate_energy_output(time = 0) + // dE/dt = -[ACCUMULATOR_PROPORTIONAL_COEFFICIENT] * E - [ACCUMULATOR_CONSTANT_COEFFICIENT] + return min(stored_energy, stored_energy - ((ACCUMULATOR_PROPORTIONAL_COEFFICIENT * stored_energy + ACCUMULATOR_CONSTANT_COEFFICIENT) * NUM_E ** (-ACCUMULATOR_PROPORTIONAL_COEFFICIENT * time) - ACCUMULATOR_CONSTANT_COEFFICIENT) / ACCUMULATOR_PROPORTIONAL_COEFFICIENT) + +/** + * Calculates the power needed to sustain the energy accumulator at its current energy. + */ +/obj/machinery/power/energy_accumulator/proc/calculate_sustainable_power() + return ACCUMULATOR_PROPORTIONAL_COEFFICIENT * stored_energy + ACCUMULATOR_CONSTANT_COEFFICIENT /obj/machinery/power/energy_accumulator/process(seconds_per_tick) - // NB: stored_energy is stored in energy units, a unit of measurement which already includes SSmachines.wait - // Do not multiply by seconds_per_tick here. It is already accounted for by being energy units. - var/power_produced = get_power_output() - release_energy(power_produced) - stored_energy -= power_produced + release_energy(calculate_energy_output(seconds_per_tick)) -/obj/machinery/power/energy_accumulator/proc/release_energy(power_produced) +/** + * Releases joules amount of its stored energy onto the powernet. + * Args: + * - joules: The amount of energy to release. + * Returns: Whether it successfully released its energy or not. + */ +/obj/machinery/power/energy_accumulator/proc/release_energy(joules = 0) if(wants_powernet) - add_avail(power_produced) + add_avail(joules) + stored_energy -= joules + processed_energy = joules + return TRUE + return FALSE /obj/machinery/power/energy_accumulator/should_have_node() return wants_powernet && anchored @@ -53,4 +76,5 @@ return connect_to_network() -#undef ACCUMULATOR_STORED_OUTPUT +#undef ACCUMULATOR_PROPORTIONAL_COEFFICIENT +#undef ACCUMULATOR_CONSTANT_COEFFICIENT diff --git a/code/modules/power/lighting/light.dm b/code/modules/power/lighting/light.dm index 41485539afa5b..03d84401473a6 100644 --- a/code/modules/power/lighting/light.dm +++ b/code/modules/power/lighting/light.dm @@ -472,7 +472,7 @@ if(!has_emergency_power(power_usage_amount)) return FALSE var/obj/item/stock_parts/cell/real_cell = get_cell() - if(real_cell.charge > 300) //it's meant to handle 120 W, ya doofus + if(real_cell.charge > 2.5 * /obj/item/stock_parts/cell/emergency_light::maxcharge) //it's meant to handle 120 W, ya doofus visible_message(span_warning("[src] short-circuits from too powerful of a power cell!")) burn_out() return FALSE diff --git a/code/modules/power/monitor.dm b/code/modules/power/monitor.dm index 3d4c92d8b19e2..289b2d46fab38 100644 --- a/code/modules/power/monitor.dm +++ b/code/modules/power/monitor.dm @@ -61,13 +61,13 @@ var/list/supply = history["supply"] if(connected_powernet) - supply += connected_powernet.viewavail + supply += energy_to_power(connected_powernet.avail) if(supply.len > record_size) supply.Cut(1, 2) var/list/demand = history["demand"] if(connected_powernet) - demand += connected_powernet.viewload + demand += energy_to_power(connected_powernet.load) if(demand.len > record_size) demand.Cut(1, 2) @@ -88,8 +88,8 @@ data["areas"] = list() if(connected_powernet) - data["supply"] = display_power(connected_powernet.viewavail) - data["demand"] = display_power(connected_powernet.viewload) + data["supply"] = display_power(connected_powernet.avail) + data["demand"] = display_power(connected_powernet.load) for(var/obj/machinery/power/terminal/term in connected_powernet.nodes) var/obj/machinery/power/apc/A = term.master if(istype(A)) diff --git a/code/modules/power/port_gen.dm b/code/modules/power/port_gen.dm index b0f801275150d..84542805d484d 100644 --- a/code/modules/power/port_gen.dm +++ b/code/modules/power/port_gen.dm @@ -66,7 +66,7 @@ TogglePower() return if(powernet) - add_avail(power_gen * power_output) + add_avail(power_to_energy(power_gen * power_output)) UseFuel() else handleInactive() @@ -114,7 +114,7 @@ /obj/machinery/power/port_gen/pacman/examine(mob/user) . = ..() - . += span_notice("The generator has [sheets] units of [sheet_name] fuel left, producing [display_power(power_gen)] per cycle.") + . += span_notice("The generator has [sheets] units of [sheet_name] fuel left, producing [display_power(power_gen)].") if(anchored) . += span_notice("It is anchored to the ground.") @@ -240,8 +240,8 @@ data["anchored"] = anchored data["connected"] = (powernet == null ? 0 : 1) data["ready_to_boot"] = anchored && HasFuel() - data["power_generated"] = display_power(power_gen) - data["power_output"] = display_power(power_gen * power_output) + data["power_generated"] = display_power(power_gen, convert = FALSE) + data["power_output"] = display_power(power_gen * power_output, convert = FALSE) data["power_available"] = (powernet == null ? 0 : display_power(avail())) data["current_heat"] = current_heat . = data diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index f12da549da358..437fcc5c2a1e9 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -132,28 +132,85 @@ return A.powered(chan) // return power status of the area -// increment the power usage stats for an area -/obj/machinery/proc/use_power(amount, chan = power_channel) - amount = max(amount * machine_power_rectifier, 0) // make sure we don't use negative power - var/area/A = get_area(src) // make sure it's in an area - A?.use_power(amount, chan) +/** + * Returns the available energy from the apc's cell and grid that can be used. + * Args: + * - consider_cell: Whether to count the energy from the APC's cell or not. + * Returns: The available energy the machine can access from the APC. + */ +/obj/machinery/proc/available_energy(consider_cell = TRUE) + var/area/home = get_area(src) + + if(isnull(home)) + return FALSE + if(!home.requires_power) + return INFINITY + + var/obj/machinery/power/apc/local_apc = home.apc + if(isnull(local_apc)) + return FALSE + + return consider_cell ? local_apc.available_energy() : local_apc.surplus() /** - * An alternative to 'use_power', this proc directly costs the APC in direct charge, as opposed to being calculated periodically. - * - Amount: How much power the APC's cell is to be costed. + * Draws energy from the APC. Will use excess energy from the APC's connected grid, + * then use energy from the APC's cell if there wasn't enough energy from the grid, unless ignore_apc is true. + * Args: + * - amount: The amount of energy to use. + * - channel: The power channel to use. + * - ignore_apc: If true, do not consider the APC's cell when demanding energy. + * - force: If true and if there isn't enough energy, consume the remaining energy. Returns 0 if false and there isn't enough energy. + * Returns: The amount of energy used. */ -/obj/machinery/proc/directly_use_power(amount) +/obj/machinery/proc/use_energy(amount, channel = power_channel, ignore_apc = FALSE, force = TRUE) + if(amount <= 0) //just in case + return FALSE + var/area/home = get_area(src) + + if(isnull(home)) + return FALSE //apparently space isn't an area + if(!home.requires_power) + return amount //Shuttles get free power, don't ask why + + var/obj/machinery/power/apc/local_apc = home.apc + if(isnull(local_apc)) + return FALSE + + // Surplus from the grid. + var/surplus = local_apc.surplus() + var/grid_used = min(surplus, amount) + var/apc_used = 0 + if((amount > grid_used) && !ignore_apc) // Use from the APC's cell if there isn't enough energy from the grid. + apc_used = local_apc.cell.use(amount - grid_used, force = force) + + if(!force && (amount < grid_used + apc_used)) // If we aren't forcing it and there isn't enough energy to supply demand, return nothing. + return FALSE + + // Use the grid's and APC's energy. + amount = grid_used + apc_used + local_apc.add_load(grid_used JOULES) + home.use_energy(amount JOULES, channel) + return amount + +/** + * An alternative to 'use_power', this proc directly costs the APC in direct charge, as opposed to prioritising the grid. + * Args: + * - amount: How much energy the APC's cell is to be costed. + * - force: If true, consumes the remaining energy of the cell if there isn't enough energy to supply the demand. + * Returns: The amount of energy that got used by the cell. + */ +/obj/machinery/proc/directly_use_energy(amount, force = FALSE) var/area/my_area = get_area(src) if(isnull(my_area)) stack_trace("machinery is somehow not in an area, nullspace?") return FALSE if(!my_area.requires_power) - return TRUE + return amount var/obj/machinery/power/apc/my_apc = my_area.apc if(isnull(my_apc)) return FALSE - return my_apc.cell.use(amount) + return my_apc.cell.use(amount, force = force) /** * Attempts to draw power directly from the APC's Powernet rather than the APC's battery. For high-draw machines, like the cell charger @@ -163,7 +220,7 @@ * If the take_any var arg is set to true, this proc will use and return any surplus that is under the requested amount, assuming that * the surplus is above zero. * Args: - * - amount, the amount of power requested from the Powernet. In standard loosely-defined SS13 power units. + * - amount, the amount of power requested from the powernet. In joules. * - take_any, a bool of whether any amount of power is acceptable, instead of all or nothing. Defaults to FALSE */ /obj/machinery/proc/use_power_from_net(amount, take_any = FALSE) @@ -189,6 +246,21 @@ local_apc.add_load(amount) return amount +/** + * Draws power from the apc's powernet and cell to charge a power cell. + * Args: + * - amount: The amount of energy given to the cell. + * - cell: The cell to charge. + * - grid_only: If true, only draw from the grid and ignore the APC's cell. + * - channel: The power channel to use. + * Returns: The amount of energy the cell received. + */ +/obj/machinery/proc/charge_cell(amount, obj/item/stock_parts/cell/cell, grid_only = FALSE, channel = AREA_USAGE_EQUIP) + var/demand = use_energy(min(amount, cell.used_charge()), channel = channel, ignore_apc = grid_only) + var/power_given = cell.give(demand) + return power_given + + /obj/machinery/proc/addStaticPower(value, powerchannel) var/area/A = get_area(src) A?.addStaticPower(value, powerchannel) @@ -448,10 +520,9 @@ if (isarea(power_source)) var/area/source_area = power_source - source_area.use_power(drained_energy WATTS) + source_area.apc?.terminal?.use_energy(drained_energy) else if (istype(power_source, /datum/powernet)) - var/drained_power = drained_energy WATTS //convert from "joules" to "watts" - PN.delayedload += (min(drained_power, max(PN.newavail - PN.delayedload, 0))) + PN.delayedload += (min(drained_energy, max(PN.newavail - PN.delayedload, 0))) else if (istype(power_source, /obj/item/stock_parts/cell)) cell.use(drained_energy) return drained_energy diff --git a/code/modules/power/powernet.dm b/code/modules/power/powernet.dm index ac24b10991350..618812351f955 100644 --- a/code/modules/power/powernet.dm +++ b/code/modules/power/powernet.dm @@ -10,8 +10,6 @@ var/load = 0 // the current load on the powernet, increased by each machine at processing var/newavail = 0 // what available power was gathered last tick, then becomes... var/avail = 0 //...the current available power in the powernet - var/viewavail = 0 // the available power as it appears on the power console (gradually updated) - var/viewload = 0 // the load as it appears on the power console (gradually updated) var/netexcess = 0 // excess power on the powernet (typically avail-load)/////// var/delayedload = 0 // load applied to powernet between power ticks. @@ -84,10 +82,6 @@ for(var/obj/machinery/power/smes/S in nodes) // find the SMESes in the network S.restore() // and restore some of the power that was used - // update power consoles - viewavail = round(0.8 * viewavail + 0.2 * avail) - viewload = round(0.8 * viewload + 0.2 * load) - // reset the powernet load = delayedload delayedload = 0 @@ -95,7 +89,4 @@ newavail = 0 /datum/powernet/proc/get_electrocute_damage() - if(avail >= 1000) - return clamp(20 + round(avail/25000), 20, 195) + rand(-5,5) - else - return 0 + return ELECTROCUTE_DAMAGE(energy_to_power(avail)) // Assuming 1 second of contact. diff --git a/code/modules/power/rtg.dm b/code/modules/power/rtg.dm index f79eb808a8756..657263b3de415 100644 --- a/code/modules/power/rtg.dm +++ b/code/modules/power/rtg.dm @@ -22,7 +22,7 @@ connect_to_network() /obj/machinery/power/rtg/process() - add_avail(power_gen) + add_avail(power_to_energy(power_gen)) /obj/machinery/power/rtg/RefreshParts() . = ..() @@ -35,7 +35,7 @@ /obj/machinery/power/rtg/examine(mob/user) . = ..() if(in_range(user, src) || isobserver(user)) - . += span_notice("The status display reads: Power generation now at [power_gen*0.001]kW.") + . += span_notice("The status display reads: Power generation at [display_power(power_gen, convert = FALSE)].") /obj/machinery/power/rtg/attackby(obj/item/I, mob/user, params) if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-open", initial(icon_state), I)) diff --git a/code/modules/power/singularity/emitter.dm b/code/modules/power/singularity/emitter.dm index c8fba21c09f5a..871fae14af429 100644 --- a/code/modules/power/singularity/emitter.dm +++ b/code/modules/power/singularity/emitter.dm @@ -123,7 +123,7 @@ . += span_notice("Its status display is glowing faintly.") else . += span_notice("Its status display reads: Emitting one beam between [DisplayTimeText(minimum_fire_delay)] and [DisplayTimeText(maximum_fire_delay)].") - . += span_notice("Power consumption at [display_power(active_power_usage)].") + . += span_notice("Power consumption at [display_power(active_power_usage, convert = FALSE)].") /obj/machinery/power/emitter/should_have_node() return welded @@ -186,15 +186,16 @@ return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN /obj/machinery/power/emitter/process(seconds_per_tick) + var/power_usage = active_power_usage * seconds_per_tick if(machine_stat & (BROKEN)) return - if(!welded || (!powernet && active_power_usage)) + if(!welded || (!powernet && power_usage)) active = FALSE update_appearance() return if(!active) return - if(active_power_usage && surplus() < active_power_usage) + if(power_usage && surplus() < power_usage) if(powered) powered = FALSE update_appearance() @@ -202,7 +203,7 @@ log_game("[src] lost power in [AREACOORD(src)]") return - add_load(active_power_usage) + add_load(power_usage) if(!powered) powered = TRUE update_appearance() diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index 308b8bc246519..856ea0cdcaa7c 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -1,7 +1,6 @@ // the SMES // stores power -#define SMESRATE 0.05 // rate of internal charge to external power //Cache defines #define SMES_CLEVEL_1 1 @@ -23,19 +22,19 @@ circuit = /obj/item/circuitboard/machine/smes can_change_cable_layer = TRUE - var/capacity = 5e6 // maximum charge + var/capacity = 5 MEGA JOULES // maximum charge var/charge = 0 // actual charge var/input_attempt = TRUE // TRUE = attempting to charge, FALSE = not attempting to charge var/inputting = TRUE // TRUE = actually inputting, FALSE = not inputting - var/input_level = 50000 // amount of power the SMES attempts to charge by - var/input_level_max = 200000 // cap on input_level + var/input_level = 50 KILO WATTS // amount of power the SMES attempts to charge by + var/input_level_max = 200 KILO WATTS // cap on input_level var/input_available = 0 // amount of charge available from input last tick var/output_attempt = TRUE // TRUE = attempting to output, FALSE = not attempting to output var/outputting = TRUE // TRUE = actually outputting, FALSE = not outputting - var/output_level = 50000 // amount of power the SMES attempts to output - var/output_level_max = 200000 // cap on output_level + var/output_level = 50 KILO WATTS // amount of power the SMES attempts to output + var/output_level_max = 200 KILO WATTS // cap on output_level var/output_used = 0 // amount of power actually outputted. may be less than output_level if the powernet returns excess power var/obj/machinery/power/terminal/terminal = null @@ -48,10 +47,10 @@ /obj/machinery/power/smes/Initialize(mapload) . = ..() dir_loop: - for(var/d in GLOB.cardinals) - var/turf/T = get_step(src, d) - for(var/obj/machinery/power/terminal/term in T) - if(term && term.dir == REVERSE_DIR(d)) + for(var/direction in GLOB.cardinals) + var/turf/turf = get_step(src, direction) + for(var/obj/machinery/power/terminal/term in turf) + if(term && term.dir == REVERSE_DIR(direction)) terminal = term break dir_loop @@ -63,19 +62,19 @@ /obj/machinery/power/smes/RefreshParts() SHOULD_CALL_PARENT(FALSE) - var/IO = 0 - var/MC = 0 - var/C + var/power_coefficient = 0 + var/max_charge = 0 + var/new_charge = 0 for(var/datum/stock_part/capacitor/capacitor in component_parts) - IO += capacitor.tier - input_level_max = initial(input_level_max) * IO - output_level_max = initial(output_level_max) * IO - for(var/obj/item/stock_parts/cell/PC in component_parts) - MC += PC.maxcharge - C += PC.charge - capacity = MC / (15000) * 1e6 + power_coefficient += capacitor.tier + input_level_max = initial(input_level_max) * power_coefficient + output_level_max = initial(output_level_max) * power_coefficient + for(var/obj/item/stock_parts/cell/power_cell in component_parts) + max_charge += power_cell.maxcharge + new_charge += power_cell.charge + capacity = max_charge if(!initial(charge) && !charge) - charge = C / 15000 * 1e6 + charge = new_charge /obj/machinery/power/smes/should_have_node() return TRUE @@ -86,17 +85,17 @@ return FALSE return TRUE -/obj/machinery/power/smes/attackby(obj/item/I, mob/user, params) +/obj/machinery/power/smes/attackby(obj/item/item, mob/user, params) //opening using screwdriver - if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-o", initial(icon_state), I)) + if(default_deconstruction_screwdriver(user, "[initial(icon_state)]-o", initial(icon_state), item)) update_appearance() return //changing direction using wrench - if(default_change_direction_wrench(user, I)) + if(default_change_direction_wrench(user, item)) terminal = null - var/turf/T = get_step(src, dir) - for(var/obj/machinery/power/terminal/term in T) + var/turf/turf = get_step(src, dir) + for(var/obj/machinery/power/terminal/term in turf) if(term && term.dir == REVERSE_DIR(dir)) terminal = term terminal.master = src @@ -110,7 +109,7 @@ return //building and linking a terminal - if(istype(I, /obj/item/stack/cable_coil)) + if(istype(item, /obj/item/stack/cable_coil)) var/dir = get_dir(user,src) if(dir & (dir-1))//we don't want diagonal click return @@ -123,14 +122,14 @@ to_chat(user, span_warning("You must open the maintenance panel first!")) return - var/turf/T = get_turf(user) - if (T.underfloor_accessibility < UNDERFLOOR_INTERACTABLE) //can we get to the underfloor? + var/turf/turf = get_turf(user) + if (turf.underfloor_accessibility < UNDERFLOOR_INTERACTABLE) //can we get to the underfloor? to_chat(user, span_warning("You must first remove the floor plating!")) return - var/obj/item/stack/cable_coil/C = I - if(C.get_amount() < 10) + var/obj/item/stack/cable_coil/cable = item + if(cable.get_amount() < 10) to_chat(user, span_warning("You need more wires!")) return @@ -145,45 +144,45 @@ playsound(src.loc, 'sound/items/deconstruct.ogg', 50, TRUE) if(do_after(user, 20, target = src)) - if(C.get_amount() < 10 || !C) + if(cable.get_amount() < 10 || !cable) return - var/obj/structure/cable/N = T.get_cable_node(terminal_cable_layer) //get the connecting node cable, if there's one - if (prob(50) && electrocute_mob(usr, N, N, 1, TRUE)) //animate the electrocution if uncautious and unlucky + var/obj/structure/cable/connected_cable = turf.get_cable_node(terminal_cable_layer) //get the connecting node cable, if there's one + if (prob(50) && electrocute_mob(user, connected_cable, connected_cable, 1, TRUE)) //animate the electrocution if uncautious and unlucky do_sparks(5, TRUE, src) return if(!terminal) - C.use(10) + cable.use(10) user.visible_message(span_notice("[user.name] builds a power terminal."),\ span_notice("You build the power terminal.")) //build the terminal and link it to the network - make_terminal(T, terminal_cable_layer) + make_terminal(turf, terminal_cable_layer) terminal.connect_to_network() connect_to_network() return //crowbarring it ! - var/turf/T = get_turf(src) - if(default_deconstruction_crowbar(I)) - message_admins("[src] has been deconstructed by [ADMIN_LOOKUPFLW(user)] in [ADMIN_VERBOSEJMP(T)].") + var/turf/turf = get_turf(src) + if(default_deconstruction_crowbar(item)) + message_admins("[src] has been deconstructed by [ADMIN_LOOKUPFLW(user)] in [ADMIN_VERBOSEJMP(turf)].") user.log_message("deconstructed [src]", LOG_GAME) investigate_log("deconstructed by [key_name(user)] at [AREACOORD(src)].", INVESTIGATE_ENGINE) return - else if(panel_open && I.tool_behaviour == TOOL_CROWBAR) + else if(panel_open && item.tool_behaviour == TOOL_CROWBAR) return return ..() -/obj/machinery/power/smes/wirecutter_act(mob/living/user, obj/item/I) +/obj/machinery/power/smes/wirecutter_act(mob/living/user, obj/item/item) //disassembling the terminal . = ..() if(terminal && panel_open) - terminal.dismantle(user, I) + terminal.dismantle(user, item) return TRUE -/obj/machinery/power/smes/default_deconstruction_crowbar(obj/item/crowbar/C) - if(istype(C) && terminal) +/obj/machinery/power/smes/default_deconstruction_crowbar(obj/item/crowbar/crowbar) + if(istype(crowbar) && terminal) to_chat(usr, span_warning("You must first remove the power terminal!")) return FALSE @@ -195,20 +194,20 @@ /obj/machinery/power/smes/Destroy() if(SSticker.IsRoundInProgress()) - var/turf/T = get_turf(src) - message_admins("[src] deleted at [ADMIN_VERBOSEJMP(T)]") - log_game("[src] deleted at [AREACOORD(T)]") - investigate_log("deleted at [AREACOORD(T)]", INVESTIGATE_ENGINE) + var/turf/turf = get_turf(src) + message_admins("[src] deleted at [ADMIN_VERBOSEJMP(turf)]") + log_game("[src] deleted at [AREACOORD(turf)]") + investigate_log("deleted at [AREACOORD(turf)]", INVESTIGATE_ENGINE) if(terminal) disconnect_terminal() return ..() // create a terminal object pointing towards the SMES // wires will attach to this -/obj/machinery/power/smes/proc/make_terminal(turf/T, terminal_cable_layer = cable_layer) - terminal = new/obj/machinery/power/terminal(T) +/obj/machinery/power/smes/proc/make_terminal(turf/turf, terminal_cable_layer = cable_layer) + terminal = new/obj/machinery/power/terminal(turf) terminal.cable_layer = terminal_cable_layer - terminal.setDir(get_dir(T,src)) + terminal.setDir(get_dir(turf,src)) terminal.master = src set_machine_stat(machine_stat & ~BROKEN) @@ -238,7 +237,7 @@ /obj/machinery/power/smes/proc/chargedisplay() return clamp(round(5.5*charge/capacity),0,5) -/obj/machinery/power/smes/process() +/obj/machinery/power/smes/process(seconds_per_tick) if(machine_stat & BROKEN) return @@ -246,6 +245,28 @@ var/last_disp = chargedisplay() var/last_chrg = inputting var/last_onln = outputting + var/input_energy = power_to_energy(input_level) + var/output_energy = power_to_energy(output_level) + + //outputting + if(output_attempt) + if(outputting) + output_used = min(charge, output_energy) //limit output to that stored + + if (add_avail(output_used)) // add output to powernet if it exists (smes side) + charge -= output_used // reduce the storage (may be recovered in /restore() if excessive) + else + outputting = FALSE + + if(output_used < 0.1) // either from no charge or set to 0 + outputting = FALSE + investigate_log("lost power and turned off", INVESTIGATE_ENGINE) + else if(output_attempt && charge > output_energy && output_level > 0) + outputting = TRUE + else + output_used = 0 + else + outputting = FALSE //inputting if(terminal && input_attempt) @@ -254,9 +275,9 @@ if(inputting) if(input_available > 0) // if there's power available, try to charge - var/load = min(min((capacity-charge)/SMESRATE, input_level), input_available) // charge at set rate, limited to spare capacity + var/load = min((capacity-charge), input_energy, input_available) // charge at set rate, limited to spare capacity - charge += load * SMESRATE // increase the charge + charge += load // increase the charge terminal.add_load(load) // add the load to the terminal side network @@ -269,26 +290,6 @@ else inputting = FALSE - //outputting - if(output_attempt) - if(outputting) - output_used = min( charge/SMESRATE, output_level) //limit output to that stored - - if (add_avail(output_used)) // add output to powernet if it exists (smes side) - charge -= output_used*SMESRATE // reduce the storage (may be recovered in /restore() if excessive) - else - outputting = FALSE - - if(output_used < 0.0001) // either from no charge or set to 0 - outputting = FALSE - investigate_log("lost power and turned off", INVESTIGATE_ENGINE) - else if(output_attempt && charge > output_level && output_level > 0) - outputting = TRUE - else - output_used = 0 - else - outputting = FALSE - // only update icon if state changed if(last_disp != chargedisplay() || last_chrg != inputting || last_onln != outputting) update_appearance() @@ -309,13 +310,13 @@ excess = min(output_used, excess) // clamp it to how much was actually output by this SMES last ptick - excess = min((capacity-charge)/SMESRATE, excess) // for safety, also limit recharge by space capacity of SMES (shouldn't happen) + excess = min((capacity-charge), excess) // for safety, also limit recharge by space capacity of SMES (shouldn't happen) // now recharge this amount var/clev = chargedisplay() - charge += excess * SMESRATE // restore unused power + charge += excess // restore unused power powernet.netexcess -= excess // remove the excess from the powernet, so later SMESes don't try to use it output_used -= excess @@ -339,15 +340,15 @@ "inputAttempt" = input_attempt, "inputting" = inputting, "inputLevel" = input_level, - "inputLevel_text" = display_power(input_level), + "inputLevel_text" = display_power(input_level, convert = FALSE), "inputLevelMax" = input_level_max, - "inputAvailable" = input_available, + "inputAvailable" = energy_to_power(input_available), "outputAttempt" = output_attempt, - "outputting" = outputting, + "outputting" = energy_to_power(outputting), "outputLevel" = output_level, - "outputLevel_text" = display_power(output_level), + "outputLevel_text" = display_power(output_level, convert = FALSE), "outputLevelMax" = output_level_max, - "outputUsed" = output_used, + "outputUsed" = energy_to_power(output_used), ) return data @@ -416,15 +417,15 @@ outputting = output_attempt output_level = rand(0, output_level_max) input_level = rand(0, input_level_max) - charge -= 1e6/severity + charge -= STANDARD_CELL_CHARGE/severity if (charge < 0) charge = 0 update_appearance() log_smes() /obj/machinery/power/smes/engineering - charge = 2.5e6 // Engineering starts with some charge for singulo //sorry little one, singulo as engine is gone - output_level = 90000 + charge = 50 * STANDARD_CELL_CHARGE // Engineering starts with some charge for singulo //sorry little one, singulo as engine is gone + output_level = 90 KILO WATTS /obj/machinery/power/smes/magical name = "magical power storage unit" @@ -436,8 +437,6 @@ ..() -#undef SMESRATE - #undef SMES_CLEVEL_1 #undef SMES_CLEVEL_2 #undef SMES_CLEVEL_3 diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index c62552913bbbe..9b47c133705f2 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -248,7 +248,7 @@ return var/sgen = SOLAR_GEN_RATE * sunfrac - add_avail(sgen) + add_avail(power_to_energy(sgen)) if(control) control.gen += sgen diff --git a/code/modules/power/supermatter/supermatter.dm b/code/modules/power/supermatter/supermatter.dm index c7bba14e49c5e..1c50f8312d4ae 100644 --- a/code/modules/power/supermatter/supermatter.dm +++ b/code/modules/power/supermatter/supermatter.dm @@ -109,7 +109,7 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal) var/external_damage_immediate = 0 ///The cutoff for a bolt jumping, grows with heat, lowers with higher mol count, - var/zap_cutoff = 1.2e6 + var/zap_cutoff = 1.2 MEGA JOULES ///How much the bullets damage should be multiplied by when it is added to the internal variables var/bullet_energy = SUPERMATTER_DEFAULT_BULLET_ENERGY ///How much hallucination should we produce per unit of power? @@ -306,7 +306,7 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal) range = 3, zap_str = internal_energy * zap_transmission_rate * delta_time, zap_flags = ZAP_SUPERMATTER_FLAGS, - zap_cutoff = 2.4e5 * delta_time, + zap_cutoff = 240 KILO WATTS * delta_time, power_level = internal_energy, color = zap_color, ) @@ -890,7 +890,7 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal) delamination_strategy.on_select(src) return TRUE -/obj/machinery/proc/supermatter_zap(atom/zapstart = src, range = 5, zap_str = 3.2e6, zap_flags = ZAP_SUPERMATTER_FLAGS, list/targets_hit = list(), zap_cutoff = 1.2e6, power_level = 0, zap_icon = DEFAULT_ZAP_ICON_STATE, color = null) +/obj/machinery/proc/supermatter_zap(atom/zapstart = src, range = 5, zap_str = 3.2 MEGA JOULES, zap_flags = ZAP_SUPERMATTER_FLAGS, list/targets_hit = list(), zap_cutoff = 1.2 MEGA JOULES, power_level = 0, zap_icon = DEFAULT_ZAP_ICON_STATE, color = null) if(QDELETED(zapstart)) return . = zapstart.dir diff --git a/code/modules/power/supermatter/supermatter_gas.dm b/code/modules/power/supermatter/supermatter_gas.dm index df8ef8e5b4fa8..35b9db0731f92 100644 --- a/code/modules/power/supermatter/supermatter_gas.dm +++ b/code/modules/power/supermatter/supermatter_gas.dm @@ -39,7 +39,7 @@ "positive" = TRUE, )) if(sm_gas.heat_power_generation) - var/list/si_derived_data = siunit_isolated(sm_gas.heat_power_generation * GAS_HEAT_POWER_SCALING_COEFFICIENT * 1e7 / SSair.wait, "eV/K/s", 2) + var/list/si_derived_data = siunit_isolated(sm_gas.heat_power_generation * GAS_HEAT_POWER_SCALING_COEFFICIENT MEGA SECONDS / SSair.wait, "eV/K/s", 2) numeric_data += list(list( "name" = "Heat Power Gain", "amount" = si_derived_data["coefficient"], @@ -222,7 +222,7 @@ GLOBAL_LIST_INIT(sm_gas_behavior, init_sm_gas()) sm.supermatter_zap( sm, range = 6, - zap_str = clamp(sm.internal_energy * 1600, 3.2e6, 1.6e7), + zap_str = clamp(sm.internal_energy * 1.6 KILO JOULES, 3.2 MEGA JOULES, 16 MEGA JOULES), zap_flags = ZAP_MOB_STUN, zap_cutoff = sm.zap_cutoff, power_level = sm.internal_energy, diff --git a/code/modules/power/tesla/coil.dm b/code/modules/power/tesla/coil.dm index def7bf7aa4d28..607fafdc3f918 100644 --- a/code/modules/power/tesla/coil.dm +++ b/code/modules/power/tesla/coil.dm @@ -1,6 +1,3 @@ -// zap needs to be over this amount to get power -#define TESLA_COIL_THRESHOLD 32000 - /obj/machinery/power/energy_accumulator/tesla_coil name = "tesla coil" desc = "For the union!" @@ -58,8 +55,8 @@ . += span_notice("The status display reads:
" + \ "Power generation at [input_power_multiplier*100]%.
" + \ "Shock interval at [zap_cooldown*0.1] seconds.
" + \ - "Stored [display_joules(get_stored_joules())].
" + \ - "Processing [display_power(get_power_output())].") + "Stored [display_energy(get_stored_joules())].
" + \ + "Processing [display_power(processed_energy)].") /obj/machinery/power/energy_accumulator/tesla_coil/default_unfasten_wrench(mob/user, obj/item/I, time = 20) . = ..() @@ -90,8 +87,8 @@ /obj/machinery/power/energy_accumulator/tesla_coil/process(seconds_per_tick) . = ..() - zap_sound_volume = min(energy_to_joules(stored_energy)/200000, 100) - zap_sound_range = min(energy_to_joules(stored_energy)/4000000, 10) + zap_sound_volume = min(energy_to_power(processed_energy) / (4 KILO WATTS), 100) // 1 sound volume per 4kW. + zap_sound_range = min(energy_to_power(processed_energy) / (80 KILO WATTS), 10) // 1 sound range per 80kW. /obj/machinery/power/energy_accumulator/tesla_coil/zap_act(power, zap_flags) if(!anchored || panel_open) @@ -105,7 +102,7 @@ power /= 10 zap_buckle_check(power) var/power_removed = powernet ? power * input_power_multiplier : power - stored_energy += max(joules_to_energy(power_removed - TESLA_COIL_THRESHOLD), 0) + stored_energy += max(power_removed, 0) return max(power - power_removed, 0) //You get back the amount we didn't use /obj/machinery/power/energy_accumulator/tesla_coil/proc/zap() @@ -139,8 +136,8 @@ . = ..() if(in_range(user, src) || isobserver(user)) . += span_notice("The status display reads:
" + \ - "Recently grounded [display_joules(get_stored_joules())].
" + \ - "This energy would sustainably release [display_power(get_power_output())].") + "Recently grounded [display_energy(get_stored_joules())].
" + \ + "This energy would sustainably release [display_power(calculate_sustainable_power(), convert = FALSE)].") /obj/machinery/power/energy_accumulator/grounding_rod/default_unfasten_wrench(mob/user, obj/item/I, time = 20) . = ..() @@ -164,13 +161,15 @@ return ..() -/obj/machinery/power/energy_accumulator/grounding_rod/zap_act(power, zap_flags) +/obj/machinery/power/energy_accumulator/grounding_rod/zap_act(energy, zap_flags) if(anchored && !panel_open) flick("grounding_rodhit", src) - zap_buckle_check(power) - stored_energy += joules_to_energy(power) + zap_buckle_check(energy) + stored_energy += energy return 0 else . = ..() - -#undef TESLA_COIL_THRESHOLD +/obj/machinery/power/energy_accumulator/grounding_rod/release_energy(joules = 0) + stored_energy -= joules + processed_energy = joules + return FALSE //Grounding rods don't release energy to the grid. diff --git a/code/modules/power/tesla/energy_ball.dm b/code/modules/power/tesla/energy_ball.dm index 89dec17a26eca..376cebb7dcd9e 100644 --- a/code/modules/power/tesla/energy_ball.dm +++ b/code/modules/power/tesla/energy_ball.dm @@ -1,5 +1,5 @@ -#define TESLA_DEFAULT_POWER 6.95304e8 -#define TESLA_MINI_POWER 3.47652e8 +#define TESLA_DEFAULT_ENERGY (695.304 MEGA JOULES) +#define TESLA_MINI_ENERGY (347.652 MEGA JOULES) // Has a weird scaling thing so this is a lie for now (doesn't generate power anyways). //Zap constants, speeds up targeting #define BIKE (COIL + 1) #define COIL (ROD + 1) @@ -76,7 +76,7 @@ pixel_y = 0 shocked_things.Cut(1, shocked_things.len / 1.3) var/list/shocking_info = list() - tesla_zap(source = src, zap_range = 3, power = TESLA_DEFAULT_POWER, shocked_targets = shocking_info) + tesla_zap(source = src, zap_range = 3, power = TESLA_DEFAULT_ENERGY, shocked_targets = shocking_info) pixel_x = -32 pixel_y = -32 @@ -84,7 +84,7 @@ var/range = rand(1, clamp(orbiting_balls.len, 2, 3)) var/list/temp_shock = list() //We zap off the main ball instead of ourselves to make things looks proper - tesla_zap(source = src, zap_range = range, power = TESLA_MINI_POWER / 7 * range, shocked_targets = temp_shock) + tesla_zap(source = src, zap_range = range, power = TESLA_MINI_ENERGY / 7 * range, shocked_targets = temp_shock) shocking_info += temp_shock shocked_things += shocking_info @@ -365,5 +365,5 @@ #undef BLOB #undef STRUCTURE -#undef TESLA_DEFAULT_POWER -#undef TESLA_MINI_POWER +#undef TESLA_DEFAULT_ENERGY +#undef TESLA_MINI_ENERGY diff --git a/code/modules/projectiles/guns/energy.dm b/code/modules/projectiles/guns/energy.dm index e76f13e1fc200..dfcb59f1e9c1c 100644 --- a/code/modules/projectiles/guns/energy.dm +++ b/code/modules/projectiles/guns/energy.dm @@ -150,7 +150,7 @@ if(charge_timer < charge_delay) return charge_timer = 0 - cell.give(100) + cell.give(STANDARD_ENERGY_GUN_SELF_CHARGE_RATE * seconds_per_tick) if(!chambered) //if empty chamber we try to charge a new shot recharge_newshot(TRUE) update_appearance() @@ -169,10 +169,10 @@ return if(use_cyborg_cell && !no_cyborg_drain) if(iscyborg(loc)) - var/mob/living/silicon/robot/R = loc - if(R.cell) + var/mob/living/silicon/robot/robot = loc + if(robot.cell) var/obj/item/ammo_casing/energy/shot = ammo_type[select] //Necessary to find cost of shot - if(R.cell.use(shot.e_cost)) //Take power from the borg... + if(robot.cell.use(shot.e_cost)) //Take power from the borg... cell.give(shot.e_cost) //... to recharge the shot if(!chambered) var/obj/item/ammo_casing/energy/AC = ammo_type[select] diff --git a/code/modules/projectiles/guns/energy/laser_gatling.dm b/code/modules/projectiles/guns/energy/laser_gatling.dm index 94dcb3bba7be0..7b80e0c69f5cb 100644 --- a/code/modules/projectiles/guns/energy/laser_gatling.dm +++ b/code/modules/projectiles/guns/energy/laser_gatling.dm @@ -145,9 +145,8 @@ ..() ammo_pack.overheat++ if(ammo_pack.battery) - var/totransfer = min(100, ammo_pack.battery.charge) - var/transferred = cell.give(totransfer) - ammo_pack.battery.use(transferred) + var/transferred = ammo_pack.battery.use(cell.maxcharge - cell.charge, force = TRUE) + cell.give(transferred) /obj/item/gun/energy/minigun/afterattack(atom/target, mob/living/user, flag, params) @@ -158,5 +157,5 @@ /obj/item/stock_parts/cell/minigun name = "gatling gun fusion core" desc = "Where did these come from?" - maxcharge = 500000 - chargerate = 5000 + maxcharge = 500 * STANDARD_CELL_CHARGE + chargerate = 5 * STANDARD_CELL_CHARGE diff --git a/code/modules/projectiles/guns/energy/special.dm b/code/modules/projectiles/guns/energy/special.dm index 922a5d71ead11..f8e692e25a81d 100644 --- a/code/modules/projectiles/guns/energy/special.dm +++ b/code/modules/projectiles/guns/energy/special.dm @@ -125,7 +125,7 @@ balloon_alert(user, "already fully charged!") return I.use(1) - cell.give(500*charge_multiplier) + cell.give(500 KILO JOULES * charge_multiplier) balloon_alert(user, "cell recharged") else ..() diff --git a/code/modules/reagents/chemistry/machinery/chem_dispenser.dm b/code/modules/reagents/chemistry/machinery/chem_dispenser.dm index c3910529fc86b..1b446377195f4 100644 --- a/code/modules/reagents/chemistry/machinery/chem_dispenser.dm +++ b/code/modules/reagents/chemistry/machinery/chem_dispenser.dm @@ -12,14 +12,12 @@ /// The cell used to dispense reagents var/obj/item/stock_parts/cell/cell - /// Efficiency used when converting cell power to reagents - var/powerefficiency = 0.1 + /// Efficiency used when converting cell power to reagents. Units (volume) per joule. + var/powerefficiency = 1e-4 /// The current amount this machine is dispensing var/amount = 30 - /// The rate at which this machine recharges the power cell - var/recharge_amount = 10 - /// Keep track of the intervals made during recharges - var/recharge_counter = 0 + /// The rate at which this machine recharges the power cell. + var/recharge_amount = 1.25 KILO WATTS /// The temperature reagents are dispensed into the beaker var/dispensed_temperature = DEFAULT_REAGENT_TEMPERATURE /// If the UI has the pH meter shown @@ -125,8 +123,8 @@ . += span_notice("[src]'s maintenance hatch is open!") if(in_range(user, src) || isobserver(user)) . += "The status display reads:\n\ - Recharging [recharge_amount] power units per interval.\n\ - Power efficiency increased by [round((powerefficiency * 1000) -100, 1)]%." + Recharge rate: [display_power(recharge_amount, convert = FALSE)].\n\ + Energy cost: [siunit(INVERSE(powerefficiency), "J/u", 3)].
" . += span_notice("Use RMB to eject a stored beaker.") /obj/machinery/chem_dispenser/on_set_is_operational(old_value) @@ -136,13 +134,11 @@ begin_processing() /obj/machinery/chem_dispenser/process(seconds_per_tick) - if (recharge_counter >= 8) - var/usedpower = cell.give(recharge_amount) - if(usedpower) - use_power(active_power_usage + recharge_amount) - recharge_counter = 0 + if(cell.maxcharge == cell.charge) return - recharge_counter += seconds_per_tick + use_energy(active_power_usage * seconds_per_tick) //Additional power cost before charging the cell. + charge_cell(recharge_amount * seconds_per_tick, cell) //This also costs power. + /obj/machinery/chem_dispenser/proc/display_beaker() var/mutable_appearance/b_o = beaker_overlay || mutable_appearance(icon, "disp_beaker") @@ -217,8 +213,10 @@ /obj/machinery/chem_dispenser/ui_data(mob/user) . = list() .["amount"] = amount - .["energy"] = cell.charge ? cell.charge * powerefficiency : 0 //To prevent NaN in the UI. - .["maxEnergy"] = cell.maxcharge * powerefficiency + .["energy"] = cell.charge ? cell.charge : 0 //To prevent NaN in the UI. + .["maxEnergy"] = cell.maxcharge + .["displayedEnergy"] = display_energy(cell.charge) + .["displayedMaxEnergy"] = display_energy(cell.maxcharge) var/list/chemicals = list() var/is_hallucinating = FALSE @@ -435,12 +433,12 @@ /obj/machinery/chem_dispenser/RefreshParts() . = ..() recharge_amount = initial(recharge_amount) - var/newpowereff = 0.0666666 + var/newpowereff = INVERSE(1.5e4) var/parts_rating = 0 for(var/obj/item/stock_parts/cell/stock_cell in component_parts) cell = stock_cell for(var/datum/stock_part/matter_bin/matter_bin in component_parts) - newpowereff += 0.0166666666 * matter_bin.tier + newpowereff += matter_bin.tier / 6e4 parts_rating += matter_bin.tier for(var/datum/stock_part/capacitor/capacitor in component_parts) recharge_amount *= capacitor.tier @@ -451,7 +449,7 @@ else dispensable_reagents -= upgrade_reagents parts_rating += servo.tier - powerefficiency = round(newpowereff, 0.01) + powerefficiency = round(newpowereff, 1e-5) /obj/machinery/chem_dispenser/proc/replace_beaker(mob/living/user, obj/item/reagent_containers/new_beaker) if(!user) diff --git a/code/modules/reagents/chemistry/machinery/chem_heater.dm b/code/modules/reagents/chemistry/machinery/chem_heater.dm index e3208d8d461d7..857cd5bd22124 100644 --- a/code/modules/reagents/chemistry/machinery/chem_heater.dm +++ b/code/modules/reagents/chemistry/machinery/chem_heater.dm @@ -179,7 +179,7 @@ //heat the beaker and use some power. we want to use only a small amount of power since this proc gets called frequently beaker.reagents.adjust_thermal_energy((target_temperature - beaker.reagents.chem_temp) * heater_coefficient * seconds_per_tick * SPECIFIC_HEAT_DEFAULT * beaker.reagents.total_volume) - use_power(active_power_usage * seconds_per_tick * 0.3) + use_energy(active_power_usage * seconds_per_tick * 0.3) return TRUE /obj/machinery/chem_heater/proc/on_reaction_step(datum/reagents/holder, num_reactions, seconds_per_tick) diff --git a/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm b/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm index e9ffc91cd3464..298fe25981445 100644 --- a/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm +++ b/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm @@ -458,7 +458,8 @@ if(!is_operational || panel_open || !anchored || (machine_stat & (BROKEN | NOPOWER))) return - use_power(active_power_usage) + if(!use_energy(active_power_usage * seconds_per_tick)) + return progress_time += seconds_per_tick if(progress_time >= delay_time) diff --git a/code/modules/reagents/chemistry/machinery/chem_master.dm b/code/modules/reagents/chemistry/machinery/chem_master.dm index 6c961571b613f..afd81d7fb9544 100644 --- a/code/modules/reagents/chemistry/machinery/chem_master.dm +++ b/code/modules/reagents/chemistry/machinery/chem_master.dm @@ -365,7 +365,7 @@ while(item_count > 0) if(!is_printing) break - use_power(active_power_usage) + use_energy(active_power_usage) stoplag(printing_speed) for(var/i in 1 to printing_amount_current) if(!item_count) @@ -394,7 +394,7 @@ if (!reagent) return FALSE - use_power(active_power_usage) + use_energy(active_power_usage) if (target == TARGET_BUFFER) if(!check_reactions(reagent, beaker.reagents)) diff --git a/code/modules/reagents/chemistry/machinery/pandemic.dm b/code/modules/reagents/chemistry/machinery/pandemic.dm index bbde13c78a818..f08989390a29e 100644 --- a/code/modules/reagents/chemistry/machinery/pandemic.dm +++ b/code/modules/reagents/chemistry/machinery/pandemic.dm @@ -198,7 +198,7 @@ if(!istype(adv_disease) || !adv_disease.mutable) to_chat(usr, span_warning("ERROR: Cannot replicate virus strain.")) return FALSE - use_power(active_power_usage) + use_energy(active_power_usage) adv_disease = adv_disease.Copy() var/list/data = list("viruses" = list(adv_disease)) var/obj/item/reagent_containers/cup/tube/bottle = new(drop_location()) @@ -220,7 +220,7 @@ * @returns {boolean} - Success or failure. */ /obj/machinery/computer/pandemic/proc/create_vaccine_bottle(index) - use_power(active_power_usage) + use_energy(active_power_usage) var/id = index var/datum/disease/disease = SSdisease.archive_diseases[id] var/obj/item/reagent_containers/cup/tube/bottle = new(drop_location()) diff --git a/code/modules/reagents/chemistry/machinery/reagentgrinder.dm b/code/modules/reagents/chemistry/machinery/reagentgrinder.dm index 358ac29719c97..c3ec9bbddb473 100644 --- a/code/modules/reagents/chemistry/machinery/reagentgrinder.dm +++ b/code/modules/reagents/chemistry/machinery/reagentgrinder.dm @@ -315,7 +315,7 @@ playsound(src, 'sound/machines/blender.ogg', 50, TRUE) else playsound(src, 'sound/machines/juicer.ogg', 20, TRUE) - use_power(active_power_usage * time * 0.1) // .1 needed here to convert time (in deciseconds) to seconds such that watts * seconds = joules + use_energy(active_power_usage * time / (1 SECONDS)) addtimer(CALLBACK(src, PROC_REF(stop_operating)), time / speed) /obj/machinery/reagentgrinder/proc/stop_operating() diff --git a/code/modules/reagents/chemistry/machinery/smoke_machine.dm b/code/modules/reagents/chemistry/machinery/smoke_machine.dm index e9b920c20e508..cf0b579acbaaa 100644 --- a/code/modules/reagents/chemistry/machinery/smoke_machine.dm +++ b/code/modules/reagents/chemistry/machinery/smoke_machine.dm @@ -88,7 +88,7 @@ var/datum/effect_system/fluid_spread/smoke/chem/smoke_machine/smoke = new() smoke.set_up(setting * 3, holder = src, location = location, carry = reagents, efficiency = efficiency) smoke.start() - use_power(active_power_usage) + use_energy(active_power_usage) /obj/machinery/smoke_machine/wrench_act(mob/living/user, obj/item/tool) . = ..() diff --git a/code/modules/reagents/chemistry/recipes/pyrotechnics.dm b/code/modules/reagents/chemistry/recipes/pyrotechnics.dm index bc41e25090bf1..edb11633e91bc 100644 --- a/code/modules/reagents/chemistry/recipes/pyrotechnics.dm +++ b/code/modules/reagents/chemistry/recipes/pyrotechnics.dm @@ -560,7 +560,7 @@ var/atom/holder_atom = holder.my_atom if(QDELETED(holder_atom)) return - tesla_zap(source = holder_atom, zap_range = 7, power = power, cutoff = 1e3, zap_flags = zap_flags) + tesla_zap(source = holder_atom, zap_range = 7, power = power, cutoff = 1 KILO JOULES, zap_flags = zap_flags) playsound(holder_atom, 'sound/machines/defib_zap.ogg', 50, TRUE) /datum/chemical_reaction/reagent_explosion/teslium_lightning/heat diff --git a/code/modules/recycling/disposal/bin.dm b/code/modules/recycling/disposal/bin.dm index 097aa3f079c1d..5e5cce21f9e07 100644 --- a/code/modules/recycling/disposal/bin.dm +++ b/code/modules/recycling/disposal/bin.dm @@ -517,13 +517,13 @@ if(machine_stat & NOPOWER) // won't charge if no power return - use_power(idle_power_usage) // base power usage + use_energy(idle_power_usage) // base power usage if(!pressure_charging) // if off or ready, no need to charge return // otherwise charge - use_power(idle_power_usage) // charging power usage + use_energy(idle_power_usage) // charging power usage var/atom/L = loc //recharging from loc turf diff --git a/code/modules/research/destructive_analyzer.dm b/code/modules/research/destructive_analyzer.dm index e9e34bfd806f0..06351975615fc 100644 --- a/code/modules/research/destructive_analyzer.dm +++ b/code/modules/research/destructive_analyzer.dm @@ -146,7 +146,7 @@ flick("[base_icon_state]_process", src) busy = TRUE addtimer(CALLBACK(src, PROC_REF(reset_busy)), 2.4 SECONDS) - use_power(DESTRUCTIVE_ANALYZER_POWER_USAGE) + use_energy(DESTRUCTIVE_ANALYZER_POWER_USAGE) var/list/all_contents = loaded_item.get_all_contents() for(var/innerthing in all_contents) destroy_item_individual(innerthing, gain_research_points) diff --git a/code/modules/research/experimentor.dm b/code/modules/research/experimentor.dm index db24cf7626e56..11d87bdd66780 100644 --- a/code/modules/research/experimentor.dm +++ b/code/modules/research/experimentor.dm @@ -235,7 +235,7 @@ stored_research.unhide_node(SSresearch.techweb_node_by_id(picked_node_id)) experiment(reaction, loaded_item) - use_power(750) + use_energy(750 JOULES) /obj/machinery/rnd/experimentor/proc/throwSmoke(turf/where) var/datum/effect_system/fluid_spread/smoke/smoke = new @@ -505,7 +505,7 @@ ejectItem(TRUE) if(globalMalf > 76 && globalMalf < 98) visible_message(span_warning("[src] begins to smoke and hiss, shaking violently!")) - use_power(500000) + use_energy(500 KILO JOULES) investigate_log("Experimentor has drained power from its APC", INVESTIGATE_EXPERIMENTOR) if(globalMalf == 99) visible_message(span_warning("[src] begins to glow and vibrate. It's going to blow!")) diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm index c3aea4162a630..868dba61e50a3 100644 --- a/code/modules/research/machinery/_production.dm +++ b/code/modules/research/machinery/_production.dm @@ -1,6 +1,8 @@ /obj/machinery/rnd/production name = "technology fabricator" desc = "Makes researched and prototype items with materials and energy." + // Energy cost per full stack of materials spent. Material insertion is 40% of this. + active_power_usage = 50 * BASE_MACHINE_ACTIVE_CONSUMPTION /// The efficiency coefficient. Material costs and print times are multiplied by this number; var/efficiency_coeff = 1 @@ -144,7 +146,7 @@ PRIVATE_PROC(TRUE) //we use initial(active_power_usage) because higher tier parts will have higher active usage but we have no benifit from it - if(directly_use_power(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.02 * initial(active_power_usage)))) + if(directly_use_energy(ROUND_UP((amount_inserted / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * 0.4 * initial(active_power_usage)))) var/datum/material/highest_mat_ref var/highest_mat = 0 @@ -289,7 +291,7 @@ return //we use initial(active_power_usage) because higher tier parts will have higher active usage but we have no benifit from it - if(!directly_use_power(ROUND_UP((amount / MAX_STACK_SIZE) * 0.02 * initial(active_power_usage)))) + if(!directly_use_energy(ROUND_UP((amount / MAX_STACK_SIZE) * 0.4 * initial(active_power_usage)))) say("No power to dispense sheets") return @@ -338,7 +340,7 @@ var/charge_per_item = 0 for(var/material in design.materials) charge_per_item += design.materials[material] - charge_per_item = ROUND_UP((charge_per_item / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * coefficient * 0.05 * active_power_usage) + charge_per_item = ROUND_UP((charge_per_item / (MAX_STACK_SIZE * SHEET_MATERIAL_AMOUNT)) * coefficient * active_power_usage) var/build_time_per_item = (design.construction_time * design.lathe_time_factor) ** 0.8 //start production @@ -375,7 +377,7 @@ finalize_build() return - if(!is_operational || !directly_use_power(charge_per_item)) + if(!is_operational || !directly_use_energy(charge_per_item)) say("Unable to continue production, power failure.") finalize_build() return diff --git a/code/modules/research/xenobiology/xenobio_camera.dm b/code/modules/research/xenobiology/xenobio_camera.dm index 97e7812190831..27de108c0cb8a 100644 --- a/code/modules/research/xenobiology/xenobio_camera.dm +++ b/code/modules/research/xenobiology/xenobio_camera.dm @@ -212,7 +212,7 @@ Due to keyboard shortcuts, the second one is not necessarily the remote eye's lo return target_mob.visible_message(span_notice("[target_mob] vanishes as [p_theyre()] reclaimed for recycling!")) - connected_recycler.use_power(500) + connected_recycler.use_energy(500 JOULES) monkeys += connected_recycler.cube_production monkeys = round(monkeys, 0.1) //Prevents rounding errors qdel(target_mob) diff --git a/code/modules/station_goals/bsa.dm b/code/modules/station_goals/bsa.dm index beb154b645c4a..db5a5e09761b9 100644 --- a/code/modules/station_goals/bsa.dm +++ b/code/modules/station_goals/bsa.dm @@ -257,7 +257,7 @@ GLOBAL_VAR_INIT(bsa_unlock, FALSE) /obj/machinery/bsa/full/proc/reload() ready = FALSE - use_power(power_used_per_shot) + use_energy(power_used_per_shot) addtimer(CALLBACK(src,"ready_cannon"),600) /obj/machinery/bsa/full/proc/ready_cannon() diff --git a/code/modules/station_goals/dna_vault.dm b/code/modules/station_goals/dna_vault.dm index 5c146758d123f..354f08667ebd3 100644 --- a/code/modules/station_goals/dna_vault.dm +++ b/code/modules/station_goals/dna_vault.dm @@ -220,7 +220,7 @@ H.dna.add_mutation(associated_mutation[upgrade_type], MUT_OTHER, 0) ADD_TRAIT(H, TRAIT_USED_DNA_VAULT, DNA_VAULT_TRAIT) power_lottery[human_weakref] = list() - use_power(active_power_usage) + use_energy(active_power_usage) #undef VAULT_TOXIN #undef VAULT_NOBREATH diff --git a/code/modules/surgery/organs/internal/stomach/stomach_ethereal.dm b/code/modules/surgery/organs/internal/stomach/stomach_ethereal.dm index 9f268b41c178a..215eaf0ec12e6 100644 --- a/code/modules/surgery/organs/internal/stomach/stomach_ethereal.dm +++ b/code/modules/surgery/organs/internal/stomach/stomach_ethereal.dm @@ -40,8 +40,15 @@ adjust_charge(shock_damage * siemens_coeff * 2) to_chat(owner, span_notice("You absorb some of the shock into your body!")) +/**Changes the energy of the crystal stomach. +* Args: +* - amount: The change of the energy, in joules. +* Returns: The amount of energy that actually got changed in joules. +**/ /obj/item/organ/internal/stomach/ethereal/proc/adjust_charge(amount) - crystal_charge = clamp(crystal_charge + amount, ETHEREAL_CHARGE_NONE, ETHEREAL_CHARGE_DANGEROUS) + var/amount_changed = clamp(amount, ETHEREAL_CHARGE_NONE - crystal_charge, ETHEREAL_CHARGE_DANGEROUS - crystal_charge) + crystal_charge = crystal_charge + amount + return amount_changed /obj/item/organ/internal/stomach/ethereal/proc/handle_charge(mob/living/carbon/carbon, seconds_per_tick, times_fired) switch(crystal_charge) @@ -92,7 +99,7 @@ playsound(carbon, 'sound/magic/lightningshock.ogg', 100, TRUE, extrarange = 5) carbon.cut_overlay(overcharge) - tesla_zap(source = carbon, zap_range = 2, power = crystal_charge * 2.5, cutoff = 1e3, zap_flags = ZAP_OBJ_DAMAGE | ZAP_LOW_POWER_GEN | ZAP_ALLOW_DUPLICATES) + tesla_zap(source = carbon, zap_range = 2, power = crystal_charge * 2.5, cutoff = 1 KILO JOULES, zap_flags = ZAP_OBJ_DAMAGE | ZAP_LOW_POWER_GEN | ZAP_ALLOW_DUPLICATES) adjust_charge(ETHEREAL_CHARGE_FULL - crystal_charge) carbon.visible_message(span_danger("[carbon] violently discharges energy!"), span_warning("You violently discharge energy!")) diff --git a/code/modules/transport/elevator/elev_indicator.dm b/code/modules/transport/elevator/elev_indicator.dm index 9751b44e0ff12..7b34f2d610556 100644 --- a/code/modules/transport/elevator/elev_indicator.dm +++ b/code/modules/transport/elevator/elev_indicator.dm @@ -109,7 +109,7 @@ set_lift_state(0, 0, force = !is_operational) return PROCESS_KILL - use_power(active_power_usage) + use_energy(active_power_usage) var/obj/structure/transport/linear/lift_part = lift.transport_modules[1] diff --git a/code/modules/transport/tram/tram_controller.dm b/code/modules/transport/tram/tram_controller.dm index 9e95870ab6d6a..8f5fae1deea95 100644 --- a/code/modules/transport/tram/tram_controller.dm +++ b/code/modules/transport/tram/tram_controller.dm @@ -955,7 +955,7 @@ * Since the machinery obj is a dumb terminal for the controller datum, sync the display with the status bitfield of the tram */ /obj/machinery/transport/tram_controller/proc/sync_controller(source, controller, controller_status, travel_direction, destination_platform) - use_power(active_power_usage) + use_energy(active_power_usage) if(controller != controller_datum) return update_appearance() diff --git a/code/modules/transport/tram/tram_doors.dm b/code/modules/transport/tram/tram_doors.dm index d836685acf11f..7e21b93679119 100644 --- a/code/modules/transport/tram/tram_doors.dm +++ b/code/modules/transport/tram/tram_doors.dm @@ -90,7 +90,7 @@ if((obj_flags & EMAGGED) || !safe) do_sparks(3, TRUE, src) playsound(src, SFX_SPARKS, vol = 75, vary = FALSE, extrarange = SHORT_RANGE_SOUND_EXTRARANGE) - use_power(50) + use_energy(50 JOULES) playsound(src, doorClose, vol = 40, vary = FALSE) operating = TRUE layer = CLOSED_DOOR_LAYER diff --git a/code/modules/vehicles/mecha/_mecha.dm b/code/modules/vehicles/mecha/_mecha.dm index f718bd5c6951f..0ae36784cc756 100644 --- a/code/modules/vehicles/mecha/_mecha.dm +++ b/code/modules/vehicles/mecha/_mecha.dm @@ -554,7 +554,7 @@ if(internal_damage & MECHA_INT_SHORT_CIRCUIT && get_charge()) spark_system.start() - use_power(min(10 * seconds_per_tick, cell.charge)) + use_energy(min(10 * seconds_per_tick, cell.charge)) cell.maxcharge -= min(10 * seconds_per_tick, cell.maxcharge) /obj/vehicle/sealed/mecha/proc/process_cabin_air(seconds_per_tick) @@ -620,7 +620,7 @@ diag_hud_set_mechstat() /obj/vehicle/sealed/mecha/proc/process_constant_power_usage(seconds_per_tick) - if(mecha_flags & LIGHTS_ON && !use_power(light_energy_drain * seconds_per_tick)) + if(mecha_flags & LIGHTS_ON && !use_energy(light_energy_drain * seconds_per_tick)) mecha_flags &= ~LIGHTS_ON set_light_on(mecha_flags & LIGHTS_ON) playsound(src,'sound/machines/clockcult/brass_skewer.ogg', 40, TRUE) @@ -696,7 +696,7 @@ if(!has_charge(melee_energy_drain)) return - use_power(melee_energy_drain) + use_energy(melee_energy_drain) SEND_SIGNAL(user, COMSIG_MOB_USED_MECH_MELEE, src) target.mech_melee_attack(src, user) diff --git a/code/modules/vehicles/mecha/combat/durand.dm b/code/modules/vehicles/mecha/combat/durand.dm index f7da6ea90c8a2..880f16b929669 100644 --- a/code/modules/vehicles/mecha/combat/durand.dm +++ b/code/modules/vehicles/mecha/combat/durand.dm @@ -50,7 +50,7 @@ /obj/vehicle/sealed/mecha/durand/process() . = ..() - if(defense_mode && !use_power(100)) //Defence mode can only be on with a occupant so we check if one of them can toggle it and toggle + if(defense_mode && !use_energy(100 KILO JOULES)) //Defence mode can only be on with a occupant so we check if one of them can toggle it and toggle for(var/O in occupants) var/mob/living/occupant = O var/datum/action/action = LAZYACCESSASSOC(occupant_actions, occupant, /datum/action/vehicle/sealed/mecha/mech_defense_mode) @@ -271,7 +271,7 @@ own integrity back to max. Shield is automatically dropped if we run out of powe return . = ..() flick("shield_impact", src) - if(!chassis.use_power((max_integrity - atom_integrity) * 100)) + if(!chassis.use_energy((max_integrity - atom_integrity) * 100)) chassis.cell?.charge = 0 for(var/O in chassis.occupants) var/mob/living/occupant = O diff --git a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm index d650ce66f2ead..b80ac6ef02580 100644 --- a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm +++ b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm @@ -114,7 +114,7 @@ /obj/item/mecha_parts/mecha_equipment/proc/action(mob/source, atom/target, list/modifiers) TIMER_COOLDOWN_START(chassis, COOLDOWN_MECHA_EQUIPMENT(type), equip_cooldown)//Cooldown is on the MECH so people dont bypass it by switching equipment SEND_SIGNAL(source, COMSIG_MOB_USED_MECH_EQUIPMENT, chassis) - chassis.use_power(energy_drain) + chassis.use_energy(energy_drain) return TRUE /** @@ -128,7 +128,7 @@ /obj/item/mecha_parts/mecha_equipment/proc/do_after_cooldown(atom/target, mob/user, interaction_key) if(!chassis) return FALSE - chassis.use_power(energy_drain) + chassis.use_energy(energy_drain) return do_after(user, equip_cooldown, target, extra_checks = CALLBACK(src, PROC_REF(do_after_checks), target), interaction_key = interaction_key) ///Do after wrapper for mecha equipment diff --git a/code/modules/vehicles/mecha/equipment/tools/medical_tools.dm b/code/modules/vehicles/mecha/equipment/tools/medical_tools.dm index fd138bbeaf8f9..902779591fc75 100644 --- a/code/modules/vehicles/mecha/equipment/tools/medical_tools.dm +++ b/code/modules/vehicles/mecha/equipment/tools/medical_tools.dm @@ -228,7 +228,7 @@ ex_patient.AdjustUnconscious(-40 * seconds_per_tick) if(ex_patient.reagents.get_reagent_amount(/datum/reagent/medicine/epinephrine) < 5) ex_patient.reagents.add_reagent(/datum/reagent/medicine/epinephrine, 5) - chassis.use_power(energy_drain) + chassis.use_energy(energy_drain) ///////////////////////////////// Syringe Gun /////////////////////////////////////////////////////////////// @@ -474,7 +474,7 @@ var/amount = seconds_per_tick * synth_speed / LAZYLEN(processed_reagents) for(var/reagent in processed_reagents) reagents.add_reagent(reagent,amount) - chassis.use_power(energy_drain) + chassis.use_energy(energy_drain) #undef FIRE_SYRINGE_MODE #undef ANALYZE_SYRINGE_MODE diff --git a/code/modules/vehicles/mecha/equipment/tools/other_tools.dm b/code/modules/vehicles/mecha/equipment/tools/other_tools.dm index 4b62478fa023d..2a166411b17b9 100644 --- a/code/modules/vehicles/mecha/equipment/tools/other_tools.dm +++ b/code/modules/vehicles/mecha/equipment/tools/other_tools.dm @@ -254,7 +254,7 @@ chassis.repair_damage(h_boost) repaired = TRUE if(repaired) - if(!chassis.use_power(energy_drain)) + if(!chassis.use_energy(energy_drain)) active = FALSE return PROCESS_KILL else //no repair needed, we turn off @@ -458,7 +458,7 @@ /obj/item/mecha_parts/mecha_equipment/thrusters/ion/thrust(movement_dir) if(!chassis) return FALSE - if(chassis.use_power(chassis.step_energy_drain)) + if(chassis.use_energy(chassis.step_energy_drain)) generate_effect(movement_dir) return TRUE return FALSE diff --git a/code/modules/vehicles/mecha/equipment/weapons/weapons.dm b/code/modules/vehicles/mecha/equipment/weapons/weapons.dm index c0047eb91d7f0..bd9bbfca91f27 100644 --- a/code/modules/vehicles/mecha/equipment/weapons/weapons.dm +++ b/code/modules/vehicles/mecha/equipment/weapons/weapons.dm @@ -370,7 +370,7 @@ if(!action_checks(target)) return TIMER_COOLDOWN_START(chassis, COOLDOWN_MECHA_EQUIPMENT(type), equip_cooldown) - chassis.use_power(energy_drain) + chassis.use_energy(energy_drain) var/newtonian_target = turn(chassis.dir,180) var/obj/O = new projectile(chassis.loc) playsound(chassis, fire_sound, 50, TRUE) diff --git a/code/modules/vehicles/mecha/mech_bay.dm b/code/modules/vehicles/mecha/mech_bay.dm index 398a9c6c59b6c..888bb05daba4e 100644 --- a/code/modules/vehicles/mecha/mech_bay.dm +++ b/code/modules/vehicles/mecha/mech_bay.dm @@ -66,7 +66,7 @@ if(recharging_mech.cell.charge < recharging_mech.cell.maxcharge) var/delta = min(recharge_power * seconds_per_tick, recharging_mech.cell.maxcharge - recharging_mech.cell.charge) recharging_mech.give_power(delta) - use_power(delta + active_power_usage) + use_energy(delta + active_power_usage) else recharge_console.update_appearance() if(recharging_mech.loc != recharging_turf) diff --git a/code/modules/vehicles/mecha/mecha_defense.dm b/code/modules/vehicles/mecha/mecha_defense.dm index c1207c2677f94..426efaf1e6fee 100644 --- a/code/modules/vehicles/mecha/mecha_defense.dm +++ b/code/modules/vehicles/mecha/mecha_defense.dm @@ -171,7 +171,7 @@ if (. & EMP_PROTECT_SELF) return if(get_charge()) - use_power((cell.charge/3)/(severity*2)) + use_energy((cell.charge/3)/(severity*2)) take_damage(30 / severity, BURN, ENERGY, 1) log_message("EMP detected", LOG_MECHA, color="red") diff --git a/code/modules/vehicles/mecha/mecha_helpers.dm b/code/modules/vehicles/mecha/mecha_helpers.dm index c9de84747e915..37757ac1f5c2a 100644 --- a/code/modules/vehicles/mecha/mecha_helpers.dm +++ b/code/modules/vehicles/mecha/mecha_helpers.dm @@ -7,7 +7,7 @@ /obj/vehicle/sealed/mecha/proc/get_charge() return cell?.charge -/obj/vehicle/sealed/mecha/proc/use_power(amount) +/obj/vehicle/sealed/mecha/proc/use_energy(amount) var/output = get_charge() && cell.use(amount) if (output) diag_hud_set_mechcell() diff --git a/code/modules/vehicles/mecha/mecha_movement.dm b/code/modules/vehicles/mecha/mecha_movement.dm index aa86d57a0da8f..53e61690aba7f 100644 --- a/code/modules/vehicles/mecha/mecha_movement.dm +++ b/code/modules/vehicles/mecha/mecha_movement.dm @@ -103,7 +103,7 @@ to_chat(occupants, "[icon2html(src, occupants)][span_warning("Missing [english_list(missing_parts)].")]") TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS) return FALSE - if(!use_power(step_energy_drain)) + if(!use_energy(step_energy_drain)) if(TIMER_COOLDOWN_FINISHED(src, COOLDOWN_MECHA_MESSAGE)) to_chat(occupants, "[icon2html(src, occupants)][span_warning("Insufficient power to move!")]") TIMER_COOLDOWN_START(src, COOLDOWN_MECHA_MESSAGE, 2 SECONDS) @@ -142,7 +142,7 @@ //Otherwise just walk normally . = try_step_multiz(direction) if(phasing) - use_power(phasing_energy_drain) + use_energy(phasing_energy_drain) if(strafe) setDir(olddir) diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index debf5f31af2a0..cf966727abb74 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -1426,7 +1426,7 @@ GLOBAL_LIST_EMPTY(vending_machines_to_restock) purchase_message_cooldown = world.time + 5 SECONDS //This is not the best practice, but it's safe enough here since the chances of two people using a machine with the same ref in 5 seconds is fuck low last_shopper = REF(usr) - use_power(active_power_usage) + use_energy(active_power_usage) if(icon_vend) //Show the vending animation if needed flick(icon_vend,src) playsound(src, 'sound/machines/machine_vend.ogg', 50, TRUE, extrarange = -3) @@ -1827,7 +1827,7 @@ GLOBAL_LIST_EMPTY(vending_machines_to_restock) last_shopper = REF(usr) /// Remove the item loaded_items-- - use_power(active_power_usage) + use_energy(active_power_usage) vending_machine_input[choice] = max(vending_machine_input[choice] - 1, 0) if(user.CanReach(src) && user.put_in_hands(dispensed_item)) to_chat(user, span_notice("You take [dispensed_item.name] out of the slot.")) diff --git a/code/modules/wiremod/components/sensors/view_sensor.dm b/code/modules/wiremod/components/sensors/view_sensor.dm index 1725044c03597..1a86f2b4c8edf 100644 --- a/code/modules/wiremod/components/sensors/view_sensor.dm +++ b/code/modules/wiremod/components/sensors/view_sensor.dm @@ -11,7 +11,7 @@ circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL - power_usage_per_input = 10 //Normal components have 1 + energy_usage_per_input = 0.01 * STANDARD_CELL_CHARGE //Normal components have 0.001 * STANDARD_CELL_CHARGE ///Allows setting the range of the view sensor var/datum/port/input/range diff --git a/code/modules/wiremod/core/component.dm b/code/modules/wiremod/core/component.dm index 39f3380907344..530f73ded8cd6 100644 --- a/code/modules/wiremod/core/component.dm +++ b/code/modules/wiremod/core/component.dm @@ -47,8 +47,8 @@ /// Used to determine the y position of the component within the UI var/rel_y = 0 - /// The power usage whenever this component receives an input - var/power_usage_per_input = 1 + /// The energy usage whenever this component receives an input. + var/energy_usage_per_input = 0.001 * STANDARD_CELL_CHARGE /// Whether the component is removable or not. Only affects user UI var/removable = TRUE @@ -266,10 +266,10 @@ message_admins("[display_name] tried to execute on [parent.get_creator_admin()] that has admin_only set to 0") return FALSE - var/flags = SEND_SIGNAL(parent, COMSIG_CIRCUIT_PRE_POWER_USAGE, power_usage_per_input) + var/flags = SEND_SIGNAL(parent, COMSIG_CIRCUIT_PRE_POWER_USAGE, energy_usage_per_input) if(!(flags & COMPONENT_OVERRIDE_POWER_USAGE)) var/obj/item/stock_parts/cell/cell = parent.get_cell() - if(!cell?.use(power_usage_per_input)) + if(!cell?.use(energy_usage_per_input)) return FALSE if((!port || port.trigger == PROC_REF(input_received)) && (circuit_flags & CIRCUIT_FLAG_INPUT_SIGNAL) && !COMPONENT_TRIGGERED_BY(trigger_input, port)) @@ -340,7 +340,7 @@ . += create_ui_notice(initial(shell.name), "green", "plus-square") if(length(input_ports)) - . += create_ui_notice("Power Usage Per Input: [power_usage_per_input]", "orange", "bolt") + . += create_ui_notice("Energy Usage Per Input: [display_energy(energy_usage_per_input)]", "orange", "bolt") /** diff --git a/code/modules/wiremod/shell/gun.dm b/code/modules/wiremod/shell/gun.dm index 3a37501e8e17c..ff5815367139b 100644 --- a/code/modules/wiremod/shell/gun.dm +++ b/code/modules/wiremod/shell/gun.dm @@ -82,6 +82,6 @@ if(!parent?.cell) return var/obj/item/gun/energy/fired_gun = source - var/totransfer = min(100, parent.cell.charge) + var/totransfer = min(100 KILO JOULES, parent.cell.charge) var/transferred = fired_gun.cell.give(totransfer) parent.cell.use(transferred) diff --git a/tgstation.dme b/tgstation.dme index 68758083eabe7..1717bf80102e5 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -204,6 +204,7 @@ #include "code\__DEFINES\screentips.dm" #include "code\__DEFINES\security.dm" #include "code\__DEFINES\shuttles.dm" +#include "code\__DEFINES\si.dm" #include "code\__DEFINES\sight.dm" #include "code\__DEFINES\skills.dm" #include "code\__DEFINES\song.dm" diff --git a/tgui/packages/tgui/format.ts b/tgui/packages/tgui/format.ts index 86a9c2907805b..c648fb1484899 100644 --- a/tgui/packages/tgui/format.ts +++ b/tgui/packages/tgui/format.ts @@ -65,6 +65,10 @@ export const formatPower = (value: number, minBase1000 = 0) => { return formatSiUnit(value, minBase1000, 'W'); }; +export const formatEnergy = (value: number, minBase1000 = 0) => { + return formatSiUnit(value, minBase1000, 'J'); +}; + // Formats a number as a currency string export const formatMoney = (value: number, precision = 0) => { if (!Number.isFinite(value)) { diff --git a/tgui/packages/tgui/interfaces/Apc.jsx b/tgui/packages/tgui/interfaces/Apc.jsx index 13261e23bbd9f..13a8984f9d4c0 100644 --- a/tgui/packages/tgui/interfaces/Apc.jsx +++ b/tgui/packages/tgui/interfaces/Apc.jsx @@ -29,7 +29,7 @@ const powerStatusMap = { 1: { color: 'average', externalPowerText: 'Low External Power', - chargingText: 'Charging', + chargingText: 'Charging: ', }, 0: { color: 'bad', @@ -131,7 +131,10 @@ const ApcContent = (props) => { /> } > - [ {chargingStatus.chargingText} ] + [{' '} + {chargingStatus.chargingText + + (data.chargingStatus === 1 ? data.chargingPowerDisplay : '')}{' '} + ] diff --git a/tgui/packages/tgui/interfaces/ChemDispenser.tsx b/tgui/packages/tgui/interfaces/ChemDispenser.tsx index 3982c35326319..6c564378a4425 100644 --- a/tgui/packages/tgui/interfaces/ChemDispenser.tsx +++ b/tgui/packages/tgui/interfaces/ChemDispenser.tsx @@ -1,4 +1,3 @@ -import { toFixed } from 'common/math'; import { BooleanLike } from 'common/react'; import { toTitleCase } from 'common/string'; import { useState } from 'react'; @@ -31,6 +30,8 @@ type Data = { amount: number; energy: number; maxEnergy: number; + displayedEnergy: string; + displayedMaxEnergy: string; chemicals: DispensableReagent[]; recipes: string[]; recordingRecipe: string[]; @@ -91,7 +92,7 @@ export const ChemDispenser = (props) => { - {toFixed(data.energy) + ' units'} + {data.displayedEnergy + ' / ' + data.displayedMaxEnergy} diff --git a/tgui/packages/tgui/interfaces/MODsuit.tsx b/tgui/packages/tgui/interfaces/MODsuit.tsx index 45cf75af33942..c8e4bdc3b85e9 100644 --- a/tgui/packages/tgui/interfaces/MODsuit.tsx +++ b/tgui/packages/tgui/interfaces/MODsuit.tsx @@ -19,7 +19,7 @@ import { Stack, Table, } from '../components'; -import { formatSiUnit } from '../format'; +import { formatEnergy, formatPower, formatSiUnit } from '../format'; import { Window } from '../layouts'; type MODsuitData = { @@ -98,7 +98,7 @@ type Module = { pinned: BooleanLike; idle_power: number; active_power: number; - use_power: number; + use_energy: number; module_complexity: number; cooldown_time: number; cooldown: number; @@ -120,8 +120,8 @@ export const MODsuit = (props) => { const { interface_break } = data.suit_status; return ( @@ -402,11 +402,11 @@ const SuitStatusSection = (props) => { : cell_charge_current === 1e31 ? 'Infinite' : `${formatSiUnit( - cell_charge_current * 1000, + cell_charge_current, 0, 'J', )} of ${formatSiUnit( - cell_charge_max * 1000, + cell_charge_max, 0, 'J', )} (${charge_percent}%)`} @@ -710,7 +710,7 @@ const ModuleSection = (props) => {