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:
Mykhailo Bykhovtsev
2018-12-05 15:43:10 +02:00
committed by Erki
parent dbcd852fff
commit 21cbff31d4
8 changed files with 228 additions and 14 deletions
+1
View File
@@ -57,6 +57,7 @@
#include "code\_helpers\area_movement.dm"
#include "code\_helpers\areas.dm"
#include "code\_helpers\atmospherics.dm"
#include "code\_helpers\data_structures.dm"
#include "code\_helpers\files.dm"
#include "code\_helpers\functional.dm"
#include "code\_helpers\game.dm"
+60
View 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
+28 -2
View File
@@ -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")
+31 -3
View File
@@ -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
+38
View File
@@ -0,0 +1,38 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
#################################
# Your name.
author: PoZe
# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True
# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- rscadd: "SMES now shows in their UI how much input they taken."
- rscadd: "SMES and APC now show in UI how long it will take to charge/discharge."
+21 -8
View File
@@ -113,7 +113,11 @@
/obj/effect/floor_decal/industrial/warning{
dir = 9
},
/obj/machinery/power/smes/buildable,
/obj/machinery/power/smes/buildable{
charge = 1000000;
input_attempt = 1;
output_attempt = 1
},
/turf/simulated/floor/tiled,
/area/engineering/gravity_gen)
"ar" = (
@@ -228,15 +232,12 @@
icon_state = "1-2"
},
/obj/structure/cable{
d1 = 2;
d1 = 4;
d2 = 8;
icon_state = "2-8"
icon_state = "4-8"
},
/turf/simulated/floor/plating,
/area/engineering)
"aE" = (
/turf/simulated/floor/plating,
/area/engineering)
"aF" = (
/obj/machinery/power/terminal{
dir = 1
@@ -247,6 +248,10 @@
/obj/effect/floor_decal/industrial/warning{
dir = 8
},
/obj/structure/cable{
icon_state = "0-8";
d2 = 8
},
/turf/simulated/floor/tiled,
/area/engineering/gravity_gen)
"aG" = (
@@ -1356,6 +1361,14 @@
/obj/structure/table/standard,
/turf/simulated/floor/tiled,
/area/storage/primary)
"jf" = (
/obj/structure/cable{
d1 = 4;
d2 = 8;
icon_state = "4-8"
},
/turf/simulated/wall/r_wall,
/area/engineering/gravity_gen)
(1,1,1) = {"
aa
@@ -2938,7 +2951,7 @@ ac
ae
ah
ap
aE
aC
aC
bc
bm
@@ -2992,7 +3005,7 @@ ac
ae
ai
ai
ai
jf
aQ
ai
ai
+18
View File
@@ -77,6 +77,24 @@
{{/if}}
</div>
<div class="item">
<div class="itemLabel">
Power Cell charge status:
</div>
<div class="itemContent">
<div class="statusValue">
{{if data.charge_mode == 1}}
APC's power cell will be fully charged in {{:data.time}}
{{else data.charge_mode == 2}}
APC's power cell inputts same amount as it outputts
{{else}}
APC's power cell will run out of charge in {{:data.time}}
{{/if}}
</div>
</div>
</div>
{{if data.powerCellStatus != null}}
<div class="item">
<div class="itemLabel">
+31 -1
View File
@@ -18,6 +18,24 @@
</div>
</div>
<div class="item">
<div class="itemLabel">
Charge status:
</div>
<div class="itemContent">
<div class="statusValue">
{{if data.charge_mode == 1}}
SMES will be fully charged in {{:data.time}}
{{else data.charge_mode == 2}}
SMES inputts same amount as outputts
{{else}}
SMES will run out of charge in {{:data.time}}
{{/if}}
</div>
</div>
</div>
<h3>Input Management</h3>
<div class="item">
<div class="itemLabel">
@@ -48,6 +66,17 @@
{{:helper.link('MAX', null, {'input' : 'max'}, (data.chargeLevel < data.chargeMax) ? null : 'disabled')}}
<div style="float: left; width: 100px; text-align: center;">&nbsp;{{:data.chargeLevel}} W&nbsp;</div>
</div>
</div>
<div class="item">
<div class="itemLabel">
Input Load:
</div>
<div class="itemContent">
{{:helper.displayBar(data.charge_taken, 0, data.chargeMax, (data.charge_taken < data.chargeLevel) ? 'average' : 'good')}}
<div class="statusValue">
{{:data.charge_taken}} W
</div>
</div>
</div>
@@ -95,4 +124,5 @@
</div>
</div>
</div>
{{/if}}
{{/if}}