Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Fix multi-cell charger and convert to new grid power consumption #2802

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
circuit = null
obj_flags = CAN_BE_HIT | NO_DECONSTRUCTION
max_batteries = 3
charge_rate = 750
charge_rate = 750 KILO WATTS
/// The item we turn into when repacked
var/repacked_type = /obj/item/wallframe/cell_charger_multi

Expand All @@ -33,7 +33,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/cell_charger_multi/wall_mounted, 29)

/obj/machinery/cell_charger_multi/wall_mounted/RefreshParts()
. = ..()
charge_rate = 750 // Nuh uh!
charge_rate = 750 KILO WATTS // Nuh uh!

// Item for creating the arc furnace or carrying it around

Expand Down
50 changes: 29 additions & 21 deletions modular_nova/modules/multicellcharger/code/multi_cell_charger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
power_channel = AREA_USAGE_EQUIP
circuit = /obj/item/circuitboard/machine/cell_charger_multi
pass_flags = PASSTABLE
var/list/charging_batteries = list() //The list of batteries we are gonna charge!
/// The list of batteries we are gonna charge!
var/list/charging_batteries = list()
/// Number of concurrent batteries that can be charged
var/max_batteries = 4
var/charge_rate = 250
var/charge_rate_base = 250 // Amount of charge we gain from a level one capacitor
var/charge_rate_max = 4000 // The highest we allow the charge rate to go
/// The base charge rate when spawned
var/charge_rate = 250 KILO WATTS

/obj/machinery/cell_charger_multi/update_overlays()
. = ..()
Expand Down Expand Up @@ -49,7 +50,7 @@
for(var/obj/item/stock_parts/cell/charging in charging_batteries)
. += "There's [charging] cell in the charger, current charge: [round(charging.percent(), 1)]%."
if(in_range(user, src) || isobserver(user))
. += span_notice("The status display reads: Charging power: <b>[charge_rate]W</b>.")
. += span_notice("The status display reads: Charging power: <b>[display_power(charge_rate, convert = FALSE)]</b>.")
. += span_notice("Right click it to remove all the cells at once!")

/obj/machinery/cell_charger_multi/attackby(obj/item/tool, mob/user, params)
Expand Down Expand Up @@ -93,15 +94,27 @@
if(!charging_batteries.len || !anchored || (machine_stat & (BROKEN|NOPOWER)))
return

for(var/obj/item/stock_parts/cell/charging in charging_batteries)
if(charging.percent() >= 100)
continue
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
if(!main_draw)
return
charging.give(main_draw)
use_energy(charge_rate / 100) //use a small bit for the charger itself, but power usage scales up with the part tier
// create a charging queue, we only want cells that require charging to use the power budget
var/list/charging_queue = list()
for(var/obj/item/stock_parts/cell/battery_slot in charging_batteries)
if(battery_slot.percent() >= 100)
continue
LAZYADD(charging_queue, battery_slot)

if(!length(charging_queue))
return

// since this loop is running multiple times per tick, we divide so that the total usage in the tick is the expected charge rate
// 4 batteries can no longer magically each pull 4MW per tick (16MW total per tick) out of thin air like in the old system
var/charge_current = (charge_rate / length(charging_queue)) * seconds_per_tick
if(!charge_current)
return

for(var/obj/item/stock_parts/cell/charging_cell in charging_queue)
use_energy(charge_current * 0.01) //use a small bit for the charger itself, but power usage scales up with the part tier
charge_cell(charge_current, charging_cell, grid_only = TRUE)

LAZYNULL(charging_queue)
update_appearance()

/obj/machinery/cell_charger_multi/attack_tk(mob/user)
Expand All @@ -115,14 +128,9 @@
/obj/machinery/cell_charger_multi/RefreshParts()
. = ..()
charge_rate = 0 // No, you cant get free charging speed!
var/charge_rate_base = 250 KILO WATTS
for(var/datum/stock_part/capacitor/capacitor in component_parts)
charge_rate += charge_rate_base * capacitor.tier
if(charge_rate >= charge_rate_max) // We've hit the charge speed cap, stop iterating.
charge_rate = charge_rate_max
break

if(charge_rate < charge_rate_base) // This should never happen; but we need to pretend it can.
charge_rate = charge_rate_base
charge_rate += (charge_rate_base * capacitor.tier) / 4

/obj/machinery/cell_charger_multi/emp_act(severity)
. = ..()
Expand Down Expand Up @@ -165,7 +173,7 @@
if(charging_batteries.len > 1 && user)
var/list/buttons = list()
for(var/obj/item/stock_parts/cell/battery in charging_batteries)
buttons["[battery] [battery.percent()]%"] = battery
buttons["[battery.name] ([round(battery.percent(), 1)]%)"] = battery
var/cell_name = tgui_input_list(user, "Please choose what cell you'd like to remove.", "Remove a cell", buttons)
charging = buttons[cell_name]
else
Expand Down
Loading