Skip to content

Commit

Permalink
[MIRROR] Fixing cell power usage (Part 4) (#2604)
Browse files Browse the repository at this point in the history
* Fixing cell power usage (Part 4)

* prepare for merge master

* Restore Mirror

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: SyncIt21 <[email protected]>
Co-authored-by: SomeRandomOwl <[email protected]>
Co-authored-by: Iajret <[email protected]>
  • Loading branch information
5 people authored Mar 28, 2024
1 parent 861af9d commit 56afc59
Showing 13 changed files with 60 additions and 42 deletions.
31 changes: 24 additions & 7 deletions code/__HELPERS/maths.dm
Original file line number Diff line number Diff line change
@@ -165,17 +165,34 @@
power = convert ? energy_to_power(power) : power
return siunit(power, "W", 3)

///Format an energy value in prefixed joules.
/**
* Format an energy value in prefixed joules.
* Arguments
*
* * units - the value t convert
*/
/proc/display_energy(units)
return siunit(units, "J", 3)

///Converts the joule to the watt, assuming SSmachines tick rate.
/proc/energy_to_power(joules)
return joules * (1 SECONDS) / SSmachines.wait
/**
* Converts the joule to the watt, assuming SSmachines tick rate.
* Arguments
*
* * joules - the value in joules to convert
* * datum/controller/subsystem/scheduler - the subsystem whos wait time is used in the conversion
*/
/proc/energy_to_power(joules, datum/controller/subsystem/scheduler = SSmachines)
return joules * (1 SECONDS) / scheduler.wait

///Converts the watt to the joule, assuming SSmachines tick rate.
/proc/power_to_energy(watts)
return watts * SSmachines.wait / (1 SECONDS)
/**
* Converts the watt to the joule, assuming SSmachines tick rate.
* * Arguments
*
* * joules - the value in joules to convert
* * datum/controller/subsystem/scheduler - the subsystem whos wait time is used in the conversion
*/
/proc/power_to_energy(watts, datum/controller/subsystem/scheduler = SSmachines)
return watts * scheduler.wait / (1 SECONDS)

///chances are 1:value. anyprob(1) will always return true
/proc/anyprob(value)
9 changes: 6 additions & 3 deletions code/datums/actions/mobs/charge_apc.dm
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
///how much charge are we giving off to an APC?
#define CHARGE_AMOUNT (80 KILO JOULES)

/datum/action/cooldown/mob_cooldown/charge_apc
name = "Charge APCs"
button_icon = 'icons/obj/machines/wallmounts.dmi'
button_icon_state = "apc0"
desc = "Give off charge to an APC."
cooldown_time = 5 SECONDS
///how much charge are we giving off to an APC?
var/given_charge = 80

/datum/action/cooldown/mob_cooldown/charge_apc/Activate(atom/target_atom)
if(!istype(target_atom,/obj/machinery/power/apc))
@@ -14,6 +15,8 @@
if(!target_apc.cell)
return
new /obj/effect/particle_effect/sparks(target_apc.loc)
target_apc.cell.give(given_charge)
target_apc.cell.give(CHARGE_AMOUNT)
StartCooldown()
return TRUE

#undef CHARGE_AMOUNT
2 changes: 1 addition & 1 deletion code/game/machinery/doors/firedoor.dm
Original file line number Diff line number Diff line change
@@ -887,7 +887,7 @@
return
if(istype(attacking_object, /obj/item/electroadaptive_pseudocircuit))
var/obj/item/electroadaptive_pseudocircuit/raspberrypi = attacking_object
if(!raspberrypi.adapt_circuit(user, DEFAULT_STEP_TIME * 0.5))
if(!raspberrypi.adapt_circuit(user, circuit_cost = DEFAULT_STEP_TIME * 0.5 KILO JOULES))
return
user.visible_message(span_notice("[user] fabricates a circuit and places it into [src]."), \
span_notice("You adapt a firelock circuit and slot it into the assembly."))
2 changes: 1 addition & 1 deletion code/game/machinery/firealarm.dm
Original file line number Diff line number Diff line change
@@ -404,7 +404,7 @@

else if(istype(tool, /obj/item/electroadaptive_pseudocircuit))
var/obj/item/electroadaptive_pseudocircuit/pseudoc = tool
if(!pseudoc.adapt_circuit(user, 15))
if(!pseudoc.adapt_circuit(user, circuit_cost = 15 KILO JOULES))
return
user.visible_message(span_notice("[user] fabricates a circuit and places it into [src]."), \
span_notice("You adapt a fire alarm circuit and slot it into the assembly."))
20 changes: 10 additions & 10 deletions code/game/objects/items/defib.dm
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@
/obj/item/defibrillator/emp_act(severity)
. = ..()
if(cell && !(. & EMP_PROTECT_CONTENTS))
deductcharge(1000 / severity)
deductcharge(STANDARD_CELL_CHARGE / severity)
if (. & EMP_PROTECT_SELF)
return

@@ -239,15 +239,15 @@
return ..()

/obj/item/defibrillator/proc/deductcharge(chrgdeductamt)
if(cell)
if(cell.charge < (paddles.revivecost+chrgdeductamt))
powered = FALSE
update_power()
if(cell.use(chrgdeductamt))
update_power()
return TRUE
else
return FALSE
if(QDELETED(cell))
return

if(cell.charge < (paddles.revivecost + chrgdeductamt))
powered = FALSE
if(!cell.use(chrgdeductamt))
powered = FALSE

update_power()

/obj/item/defibrillator/proc/cooldowncheck()
addtimer(CALLBACK(src, PROC_REF(finish_charging)), cooldown_duration)
Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@

if(istype(W, /obj/item/electroadaptive_pseudocircuit))
var/obj/item/electroadaptive_pseudocircuit/P = W
if(!P.adapt_circuit(user, 25))
if(!P.adapt_circuit(user, circuit_cost = 25 KILO JOULES))
return
user.visible_message(span_notice("[user] fabricates a circuit and places it into [src]."), \
span_notice("You adapt an air alarm circuit and slot it into the assembly."))
8 changes: 4 additions & 4 deletions code/modules/mod/modules/modules_ninja.dm
Original file line number Diff line number Diff line change
@@ -133,10 +133,10 @@
icon_state = "hacker"
removable = FALSE
incompatible_modules = list(/obj/item/mod/module/hacker)
/// Minimum amount of power we can drain in a single drain action
var/mindrain = 200
/// Maximum amount of power we can drain in a single drain action
var/maxdrain = 400
/// Minimum amount of energy we can drain in a single drain action
var/mindrain = 200 KILO JOULES
/// Maximum amount of energy we can drain in a single drain action
var/maxdrain = 400 KILO JOULES
/// Whether or not the communication console hack was used to summon another antagonist.
var/communication_console_hack_success = FALSE
/// How many times the module has been used to force open doors.
4 changes: 2 additions & 2 deletions code/modules/power/apc/apc_attack.dm
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@
if(machine_stat & BROKEN)
balloon_alert(user, "frame is too damaged!")
return
if(!pseudocircuit.adapt_circuit(user, 50))
if(!pseudocircuit.adapt_circuit(user, circuit_cost = 50 KILO JOULES))
return
user.visible_message(span_notice("[user] fabricates a circuit and places it into [src]."), \
span_notice("You adapt a power control board and click it into place in [src]'s guts."))
@@ -128,7 +128,7 @@
if(machine_stat & MAINT)
balloon_alert(user, "no board for a cell!")
return
if(!pseudocircuit.adapt_circuit(user, 500))
if(!pseudocircuit.adapt_circuit(user, circuit_cost = 500 KILO JOULES))
return
var/obj/item/stock_parts/cell/crap/empty/bad_cell = new(src)
bad_cell.forceMove(src)
4 changes: 1 addition & 3 deletions code/modules/power/cell.dm
Original file line number Diff line number Diff line change
@@ -233,9 +233,7 @@
. = ..()
if(. & EMP_PROTECT_SELF)
return
charge -= 1000 / severity
if (charge < 0)
charge = 0
use(STANDARD_CELL_CHARGE / severity, force = TRUE)

/obj/item/stock_parts/cell/ex_act(severity, target)
. = ..()
14 changes: 7 additions & 7 deletions code/modules/vehicles/mecha/_mecha.dm
Original file line number Diff line number Diff line change
@@ -36,11 +36,11 @@
hud_possible = list(DIAG_STAT_HUD, DIAG_BATT_HUD, DIAG_MECH_HUD, DIAG_TRACK_HUD, DIAG_CAMERA_HUD)
mouse_pointer = 'icons/effects/mouse_pointers/mecha_mouse.dmi'
///How much energy the mech will consume each time it moves. this is the current active energy consumed
var/step_energy_drain = 8
var/step_energy_drain = 8 KILO JOULES
///How much energy we drain each time we mechpunch someone
var/melee_energy_drain = 15
var/melee_energy_drain = 15 KILO JOULES
///Power we use to have the lights on
var/light_energy_drain = 2
var/light_power_drain = 2 KILO WATTS
///Modifiers for directional damage reduction
var/list/facing_modifiers = list(MECHA_FRONT_ARMOUR = 0.5, MECHA_SIDE_ARMOUR = 1, MECHA_BACK_ARMOUR = 1.5)
///if we cant use our equipment(such as due to EMP)
@@ -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_energy(light_energy_drain * seconds_per_tick))
if(mecha_flags & LIGHTS_ON && !use_energy(light_power_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)
@@ -856,19 +856,19 @@
if(capacitor)
phasing_energy_drain = initial(phasing_energy_drain) / capacitor.rating
melee_energy_drain = initial(melee_energy_drain) / capacitor.rating
light_energy_drain = initial(light_energy_drain) / capacitor.rating
light_power_drain = initial(light_power_drain) / capacitor.rating
else
phasing_energy_drain = initial(phasing_energy_drain)
melee_energy_drain = initial(melee_energy_drain)
light_energy_drain = initial(light_energy_drain)
light_power_drain = initial(light_power_drain)

/// Toggle lights on/off
/obj/vehicle/sealed/mecha/proc/toggle_lights(forced_state = null, mob/user)
if(!(mecha_flags & HAS_LIGHTS))
if(user)
balloon_alert(user, "mech has no lights!")
return
if((!(mecha_flags & LIGHTS_ON) && forced_state != FALSE) && get_charge() < light_energy_drain)
if((!(mecha_flags & LIGHTS_ON) && forced_state != FALSE) && get_charge() < power_to_energy(light_power_drain, scheduler = SSobj))
if(user)
balloon_alert(user, "no power for lights!")
return
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
desc = "Equipment for engineering and combat exosuits. This is the drill that'll pierce the heavens!"
icon_state = "mecha_drill"
equip_cooldown = 15
energy_drain = 10
energy_drain = 10 KILO JOULES
force = 15
harmful = TRUE
range = MECHA_MELEE
2 changes: 1 addition & 1 deletion code/modules/vehicles/mecha/equipment/tools/other_tools.dm
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
desc = "An exosuit module that allows exosuits to teleport to any position in view."
icon_state = "mecha_teleport"
equip_cooldown = 150
energy_drain = 1000
energy_drain = 1 MEGA JOULES
range = MECHA_RANGED
var/teleport_range = 7

2 changes: 1 addition & 1 deletion code/modules/vehicles/mecha/equipment/tools/work_tools.dm
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
desc = "Equipment for engineering exosuits. Lifts objects and loads them into cargo."
icon_state = "mecha_clamp"
equip_cooldown = 15
energy_drain = 10
energy_drain = 10 KILO JOULES
tool_behaviour = TOOL_RETRACTOR
range = MECHA_MELEE
toolspeed = 0.8

0 comments on commit 56afc59

Please sign in to comment.