mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-25 17:41:56 +00:00
SMES and APC update (#5578)
SMES now show how much of input they receive SMES and APC estimates how much time it will take to deplete it. Runtime map now uses its SMES, and it is wired to TEG's Added Stack and Queue data structures for use
This commit is contained in:
committed by
Erki
parent
dbcd852fff
commit
21cbff31d4
60
code/_helpers/data_structures.dm
Normal file
60
code/_helpers/data_structures.dm
Normal file
@@ -0,0 +1,60 @@
|
||||
// This file contains data structures such as Stack and Queue
|
||||
|
||||
///////////
|
||||
///Stack///
|
||||
///////////
|
||||
|
||||
/Stack
|
||||
var/list/contents
|
||||
var/next
|
||||
|
||||
/Stack/New()
|
||||
contents = list()
|
||||
next = null
|
||||
|
||||
/Stack/proc/push(var/element)
|
||||
next = element
|
||||
contents += element
|
||||
|
||||
/Stack/proc/pop()
|
||||
. = next
|
||||
if(contents.len > 0)
|
||||
contents.len --
|
||||
if(contents.len == 0)
|
||||
next = null
|
||||
else
|
||||
next = contents[contents.len]
|
||||
|
||||
/Stack/proc/size()
|
||||
return contents.len
|
||||
|
||||
/Stack/proc/as_list()
|
||||
return contents
|
||||
|
||||
|
||||
|
||||
///////////
|
||||
///Queue///
|
||||
///////////
|
||||
|
||||
/Queue
|
||||
var/list/contents
|
||||
|
||||
/Queue/New()
|
||||
contents = list()
|
||||
|
||||
/Queue/proc/enqueue(var/element)
|
||||
contents += element
|
||||
|
||||
/Queue/proc/dequeue()
|
||||
if(!contents.len)
|
||||
return null
|
||||
var/item = contents[1]
|
||||
contents.Cut(1, 2)
|
||||
return item
|
||||
|
||||
/Queue/proc/size()
|
||||
return contents.len
|
||||
|
||||
/Queue/proc/as_list()
|
||||
return contents
|
||||
@@ -81,6 +81,7 @@
|
||||
var/areastring = null
|
||||
var/obj/item/weapon/cell/cell
|
||||
var/chargelevel = 0.0005 // Cap for how fast APC cells charge, as a percentage-per-tick (0.01 means cellcharge is capped to 1% per second)
|
||||
var/cellused = 0
|
||||
var/initalchargelevel = 0.0005 // Cap for how fast APC cells charge, as a percentage-per-tick (0.01 means cellcharge is capped to 1% per second)
|
||||
var/start_charge = 90 // initial cell charge %
|
||||
var/cell_type = /obj/item/weapon/cell/apc
|
||||
@@ -130,6 +131,10 @@
|
||||
|
||||
var/emergency_lights = FALSE
|
||||
|
||||
var/time = 0
|
||||
var/charge_mode = 0
|
||||
var/last_time = 1
|
||||
|
||||
/obj/machinery/power/apc/updateDialog()
|
||||
if (stat & (BROKEN|MAINT))
|
||||
return
|
||||
@@ -859,6 +864,8 @@
|
||||
"failTime" = failure_timer * 2,
|
||||
"siliconUser" = istype(user, /mob/living/silicon),
|
||||
"emergencyMode" = !emergency_lights,
|
||||
"time" = time,
|
||||
"charge_mode" = charge_mode,
|
||||
|
||||
"powerChannels" = list(
|
||||
list(
|
||||
@@ -899,7 +906,7 @@
|
||||
if (!ui)
|
||||
// the ui does not exist, so we'll create a new() one
|
||||
// for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
|
||||
ui = new(user, src, ui_key, "apc.tmpl", "[area.name] - APC", 520, data["siliconUser"] ? 465 : 440)
|
||||
ui = new(user, src, ui_key, "apc.tmpl", "[area.name] - APC", 665, data["siliconUser"] ? 485 : 460)
|
||||
// when the ui is first opened this is the data it will use
|
||||
ui.set_initial_data(data)
|
||||
// open the new ui window
|
||||
@@ -1137,8 +1144,9 @@
|
||||
log_debug("Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light] - Longterm: [longtermpower]")
|
||||
|
||||
if(cell && !shorted)
|
||||
update_time()
|
||||
// draw power from cell as before to power the area
|
||||
var/cellused = min(cell.charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell
|
||||
cellused = min(cell.charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell
|
||||
cell.use(cellused)
|
||||
|
||||
if(excess > lastused_total) // if power excess recharge the cell
|
||||
@@ -1384,3 +1392,21 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on)
|
||||
locked = 1
|
||||
update_icon()
|
||||
return 1
|
||||
|
||||
/obj/machinery/power/apc/proc/update_time()
|
||||
|
||||
var/delta_power = (lastused_charging) ? (-lastused_charging) : (lastused_total)
|
||||
delta_power *= 0.0005
|
||||
|
||||
var/goal = (delta_power > 0) ? (cell.charge) : (cell.maxcharge - cell.charge)
|
||||
|
||||
var/time_secs = (delta_power) ? ((goal / abs(delta_power)) / (round(world.time - last_time) / 10)) : (0)
|
||||
// If it is negative - we are discharging
|
||||
if(delta_power < 0)
|
||||
charge_mode = 1
|
||||
else if(delta_power != 0)
|
||||
charge_mode = 0
|
||||
else
|
||||
charge_mode = 2
|
||||
last_time = world.time
|
||||
time = ((time_secs / 3600) > 1) ? ("[round(time_secs / 3600)] hours, [round((time_secs % 3600) / 60)] minutes") : ("[round(time_secs / 60)] minutes, [round(time_secs % 60)] seconds")
|
||||
@@ -33,7 +33,7 @@
|
||||
var/inputting = 0 // 1 = actually inputting, 0 = 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_available = 0 // amount of charge available from input last tick
|
||||
var/input_taken = 0 // amount that we received from powernet last tick
|
||||
|
||||
var/output_attempt = 0 // 1 = attempting to output, 0 = not attempting to output
|
||||
var/outputting = 0 // 1 = actually outputting, 0 = not outputting
|
||||
@@ -65,6 +65,10 @@
|
||||
var/datum/effect_system/sparks/big_spark
|
||||
var/datum/effect_system/sparks/small_spark
|
||||
|
||||
var/time = 0
|
||||
var/charge_mode = 0
|
||||
var/last_time = 1
|
||||
|
||||
/obj/machinery/power/smes/drain_power(var/drain_check, var/surge, var/amount = 0)
|
||||
|
||||
if(drain_check)
|
||||
@@ -123,7 +127,7 @@
|
||||
|
||||
/obj/machinery/power/smes/update_icon()
|
||||
cut_overlays()
|
||||
if(stat & BROKEN)
|
||||
if(stat & BROKEN)
|
||||
return
|
||||
|
||||
if(inputting == 2)
|
||||
@@ -153,12 +157,31 @@
|
||||
if(terminal && terminal.powernet)
|
||||
inputted_power = terminal.powernet.draw_power(inputted_power)
|
||||
charge += inputted_power * SMESRATE
|
||||
input_taken = inputted_power
|
||||
if(percentage == 100)
|
||||
inputting = 2
|
||||
else if(percentage)
|
||||
inputting = 1
|
||||
// else inputting = 0, as set in process()
|
||||
|
||||
/obj/machinery/power/smes/proc/update_time()
|
||||
|
||||
var/delta_power = input_taken - output_used
|
||||
delta_power *= SMESRATE
|
||||
|
||||
var/goal = (delta_power < 0) ? (charge) : (capacity - charge)
|
||||
|
||||
var/time_secs = (delta_power) ? ((goal / abs(delta_power)) * (round(world.time - last_time) / 10)) : (0)
|
||||
// If it is negative - we are discharging
|
||||
if(delta_power < 0)
|
||||
charge_mode = 0
|
||||
else if(delta_power != 0)
|
||||
charge_mode = 1
|
||||
else
|
||||
charge_mode = 2
|
||||
last_time = world.time
|
||||
time = ((time_secs / 3600) > 1) ? ("[round(time_secs / 3600)] hours, [round((time_secs % 3600) / 60)] minutes") : ("[round(time_secs / 60)] minutes, [round(time_secs % 60)] seconds")
|
||||
|
||||
/obj/machinery/power/smes/machinery_process()
|
||||
if(stat & BROKEN) return
|
||||
if(failure_timer) // Disabled by gridcheck.
|
||||
@@ -174,6 +197,8 @@
|
||||
last_chrg = inputting
|
||||
last_onln = outputting
|
||||
|
||||
update_time()
|
||||
|
||||
//inputting
|
||||
if(input_attempt && (!input_pulsed && !input_cut))
|
||||
target_load = min((capacity-charge)/SMESRATE, input_level) // Amount we will request from the powernet.
|
||||
@@ -341,12 +366,15 @@
|
||||
data["chargeMode"] = input_attempt
|
||||
data["chargeLevel"] = input_level
|
||||
data["chargeMax"] = input_level_max
|
||||
data["charge_taken"] = round(input_taken)
|
||||
data["outputOnline"] = output_attempt
|
||||
data["outputLevel"] = output_level
|
||||
data["outputMax"] = output_level_max
|
||||
data["outputLoad"] = round(output_used)
|
||||
data["failTime"] = failure_timer * 2
|
||||
data["outputting"] = outputting
|
||||
data["time"] = time
|
||||
data["charge_mode"] = charge_mode
|
||||
|
||||
|
||||
// update the ui if it exists, returns null if no ui is passed/found
|
||||
@@ -354,7 +382,7 @@
|
||||
if (!ui)
|
||||
// the ui does not exist, so we'll create a new() one
|
||||
// for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
|
||||
ui = new(user, src, ui_key, "smes.tmpl", "SMES Unit", 540, 380)
|
||||
ui = new(user, src, ui_key, "smes.tmpl", "SMES Unit", 540, 420)
|
||||
// when the ui is first opened this is the data it will use
|
||||
ui.set_initial_data(data)
|
||||
// open the new ui window
|
||||
|
||||
Reference in New Issue
Block a user