From 8ec1ce7f6fc3972e9db94111f9fbfe00d4fc5898 Mon Sep 17 00:00:00 2001 From: MLGTASTICa <61350382+MLGTASTICa@users.noreply.github.com> Date: Sat, 9 Dec 2023 12:19:39 +0200 Subject: [PATCH] Battery rack update (#8382) * ZAMN * Bump webpack from 5.51.1 to 5.76.0 in /tgui Bumps [webpack](https://github.com/webpack/webpack) from 5.51.1 to 5.76.0. - [Release notes](https://github.com/webpack/webpack/releases) - [Commits](https://github.com/webpack/webpack/compare/v5.51.1...v5.76.0) --- updated-dependencies: - dependency-name: webpack dependency-type: direct:production ... Signed-off-by: dependabot[bot] * Bump fastify from 3.20.2 to 3.29.4 in /tgui Bumps [fastify](https://github.com/fastify/fastify) from 3.20.2 to 3.29.4. - [Release notes](https://github.com/fastify/fastify/releases) - [Commits](https://github.com/fastify/fastify/compare/v3.20.2...v3.29.4) --- updated-dependencies: - dependency-name: fastify dependency-type: direct:production ... Signed-off-by: dependabot[bot] * Bump json5 from 1.0.1 to 1.0.2 in /tgui Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] * Update batteryrack.dm * zz * aaaa * power gen sprites too * Update code/modules/power/batteryrack.dm * Update code/modules/power/batteryrack.dm * Delete bin/build_and_linter.cmd --------- Signed-off-by: dependabot[bot] Co-authored-by: MLGTASTICa Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: hyperioo <64754494+hyperioo@users.noreply.github.com> --- .../weapons/circuitboards/machinery/power.dm | 6 +- code/modules/power/batteryrack.dm | 136 ++++++++++++++---- code/modules/power/diesel_gen.dm | 8 +- code/modules/power/port_gen.dm | 2 +- 4 files changed, 118 insertions(+), 34 deletions(-) diff --git a/code/game/objects/items/weapons/circuitboards/machinery/power.dm b/code/game/objects/items/weapons/circuitboards/machinery/power.dm index 99b9484f5b6..435a857acf8 100755 --- a/code/game/objects/items/weapons/circuitboards/machinery/power.dm +++ b/code/game/objects/items/weapons/circuitboards/machinery/power.dm @@ -14,7 +14,8 @@ board_type = "machine" origin_tech = list(TECH_POWER = 3, TECH_ENGINEERING = 2) req_components = list( - /obj/item/cell/large = 3 + /obj/item/stack/cable_coil = 10, + /obj/item/stock_parts/capacitor = 1 ) /obj/item/electronics/circuitboard/apc @@ -26,7 +27,8 @@ build_path = /obj/machinery/power/smes/batteryrack/makeshift board_type = "machine" req_components = list( - /obj/item/cell/large = 3 + /obj/item/stack/cable_coil = 15, + /obj/item/stock_parts/capacitor = 2 ) matter = list(MATERIAL_PLASTIC = 2, MATERIAL_GLASS = 3) diff --git a/code/modules/power/batteryrack.dm b/code/modules/power/batteryrack.dm index df6f66ecc77..2f17fa95ae7 100644 --- a/code/modules/power/batteryrack.dm +++ b/code/modules/power/batteryrack.dm @@ -1,19 +1,86 @@ +#define OVERKEY_PSU_CAPACITORS "CapacitorOverlays" +#define OVERKEY_PSU_INPUT "InputOverlays" +#define OVERKEY_PSU_OUTPUT "OutputOverlays" //The one that works safely. /obj/machinery/power/smes/batteryrack name = "power cell rack PSU" desc = "A rack of power cells working as a PSU." + icon_state = "mpsu_closed" charge = 0 //you dont really want to make a potato PSU which already is overloaded output_attempt = 0 input_level = 0 output_level = 0 input_level_max = 0 output_level_max = 0 - icon_state = "gsmes" + icon_state = "mpsu_closed" circuit = /obj/item/electronics/circuitboard/batteryrack var/cells_amount = 0 var/capacitors_amount = 0 var/global/list/br_cache = null +/obj/machinery/power/smes/batteryrack/examine(mob/user, distance, infix, suffix) + . = ..() + if(open_hatch) + to_chat(user, SPAN_NOTICE("It currently hosts [cells_amount] cells.")) + if(distance <= 1) + to_chat(user, SPAN_NOTICE("Click any cell below to remove them from \the [src]:")) + for(var/obj/item/cell/battery in component_parts) + to_chat(user, SPAN_NOTICE("\icon[battery] [battery.name]")) + else + to_chat(user, SPAN_NOTICE("The hatch needs to be opened with a screwdriver to interact with the cells inside!")) + to_chat(user, SPAN_NOTICE("It currently has [capacitors_amount] capacitors installed.")) + to_chat(user, SPAN_NOTICE("It has a LCD screen. Left side is for charging and right side for discharging. Green means operating. Yellow means not discharging/charging or no network.")) + to_chat(user, SPAN_NOTICE("Can toggle input and output on/off with CtrlClick and AltClick. It is currently set to discharge at a maximum rate of [output_level] W, and recharge at a maximum rate of [input_level] W.")) + +/obj/machinery/power/smes/batteryrack/attack_hand(mob/living/user) + . = ..() + if(!istype(user)) + return + if(open_hatch && !user.incapacitated(INCAPACITATION_DEFAULT)) + var/list/inputs = list() + for(var/obj/item/cell/large/battery in component_parts) + inputs.Add(battery) + var/obj/item/input = input(user, "Choose cell to remove", "Cell removal UI", null) as anything in inputs + if(input) + if(!Adjacent(user)) + return + if(!component_parts.Find(input)) + return + input.forceMove(get_turf(user)) + user.put_in_active_hand(input) + +/obj/machinery/power/smes/batteryrack/Topic(href, href_list) + /// For any UI related fuckery to NanoUI/Tgui + . = ..() + if(QDELETED(src)) + return + if(open_hatch) + if(href_list["remove_cell_in_hand"]) + var/mob/living/target = locate(href_list["user"]) + var/obj/item/cell/battery = locate(href_list["remove_cell_in_hand"]) + if(!target || !battery) + return + // No funny HREF switching to grab anything in the world... or anything inside the machine. + // Don't use locate here , it searches by Type instead of reference + if(!component_parts.Find(battery) || !istype(battery)) + return + if(target.incapacitated(INCAPACITATION_DEFAULT)) + return + if(!Adjacent(target)) + to_chat(target, SPAN_NOTICE("You are too far away from \the [src].")) + return + to_chat(target, SPAN_NOTICE("You remove \the [battery] from \the [src].")) + component_parts.Remove(battery) + battery.forceMove(get_turf(target)) + target.put_in_active_hand(battery) + +/obj/machinery/power/smes/batteryrack/Initialize(mapload, d) + . = ..() + var/datum/component/overlay_manager/overlay_manager = AddComponent(/datum/component/overlay_manager) + overlay_manager.addOverlay(OVERKEY_PSU_CAPACITORS, mutable_appearance(icon, "caps_0")) + overlay_manager.addOverlay(OVERKEY_PSU_INPUT, mutable_appearance(icon, "mpsu_tryinginput")) + overlay_manager.addOverlay(OVERKEY_PSU_OUTPUT, mutable_appearance(icon, "mpsu_tryingdischarge")) + /obj/machinery/power/smes/batteryrack/RefreshParts() capacitors_amount = 0 @@ -24,6 +91,8 @@ capacitors_amount++ input_level_max = 50000 + max_level * 20000 output_level_max = 50000 + max_level * 20000 + output_level = output_level_max + input_level = input_level_max var/C = 0 for(var/obj/item/cell/large/PC in component_parts) @@ -33,30 +102,26 @@ /obj/machinery/power/smes/batteryrack/update_icon() - overlays.Cut() - if(stat & BROKEN) return - - if(!br_cache) - br_cache = list() - br_cache.len = 7 - br_cache[1] = image('icons/obj/power.dmi', "gsmes_outputting") - br_cache[2] = image('icons/obj/power.dmi', "gsmes_charging") - br_cache[3] = image('icons/obj/power.dmi', "gsmes_overcharge") - br_cache[4] = image('icons/obj/power.dmi', "gsmes_og1") - br_cache[5] = image('icons/obj/power.dmi', "gsmes_og2") - br_cache[6] = image('icons/obj/power.dmi', "gsmes_og3") - br_cache[7] = image('icons/obj/power.dmi', "gsmes_og4") - - if (output_attempt) - overlays += br_cache[1] - if(inputting) - overlays += br_cache[2] - - var/clevel = chargedisplay() - if(clevel>0) - overlays += br_cache[3+clevel] + if(!open_hatch) + icon_state = "mpsu_closed" + else + switch(cells_amount) + if(0) + icon_state = "mpsu_0" + if(1) + icon_state = "mpsu_1" + if(2 to 3) + icon_state = "mpsu_3" + if(4 to 5) + icon_state = "mpsu_5" + var/datum/component/overlay_manager/overlay_manager = GetComponent(/datum/component/overlay_manager) + overlay_manager.updateOverlay(OVERKEY_PSU_CAPACITORS, mutable_appearance(icon, "caps_[capacitors_amount]")) + overlay_manager.updateOverlay(OVERKEY_PSU_INPUT, mutable_appearance(icon, inputting == 2 ? "mpsu_input" : "mpsu_tryinginput")) + overlay_manager.updateOverlay(OVERKEY_PSU_OUTPUT, mutable_appearance(icon, outputting == 2 ? "mpsu_discharging" : "mpsu_tryingdischarge")) return +#undef OVERKEY_PSU_CAPACITORS + /obj/machinery/power/smes/batteryrack/chargedisplay() return round(4 * charge/(capacity ? capacity : 5e6)) @@ -64,16 +129,18 @@ /obj/machinery/power/smes/batteryrack/attackby(var/obj/item/W as obj, var/mob/user as mob) //these can only be moved by being reconstructed, solves having to remake the powernet. ..() //SMES attackby for now handles screwdriver, cable coils and wirecutters, no need to repeat that here + // we need to update icon incase we get opened in the parent call + update_icon() if(open_hatch) if(istype(W, /obj/item/tool/crowbar)) - if (charge < (capacity / 100)) + if (charge < (capacity / 100) || capacity == 0) if (!output_attempt && !input_attempt) playsound(get_turf(src), 'sound/items/Crowbar.ogg', 50, 1) var/obj/machinery/constructable_frame/machine_frame/M = new /obj/machinery/constructable_frame/machine_frame(src.loc) M.state = 2 M.icon_state = "box_1" for(var/obj/I in component_parts) - I.loc = src.loc + I.forceMove(get_turf(src)) qdel(src) return 1 else @@ -81,13 +148,14 @@ else to_chat(user, SPAN_WARNING("Better let [src] discharge before dismantling it.")) else if ((istype(W, /obj/item/stock_parts/capacitor) && (capacitors_amount < 5)) || (istype(W, /obj/item/cell/large) && (cells_amount < 5))) - if (charge < (capacity / 100)) + if (charge < (capacity / 100) || capacity == 0) if (!output_attempt && !input_attempt) user.drop_item() component_parts += W - W.loc = src + W.forceMove(src) RefreshParts() to_chat(user, SPAN_NOTICE("You upgrade the [src] with [W.name].")) + update_icon() else to_chat(user, SPAN_WARNING("Turn off the [src] before dismantling it.")) else @@ -98,11 +166,14 @@ return 1 return +/obj/machinery/power/smes/batteryrack/attack_hand() + //The shitty one that will blow up. /obj/machinery/power/smes/batteryrack/makeshift name = "makeshift PSU" desc = "A rack of batteries connected by a mess of wires posing as a PSU." + icon_state = "gsmes" circuit = /obj/item/electronics/circuitboard/apc var/overcharge_percent = 0 @@ -111,6 +182,17 @@ overlays.Cut() if(stat & BROKEN) return + if(!br_cache) + br_cache = list() + br_cache.len = 7 + br_cache[1] = image('icons/obj/power.dmi', "gsmes_outputting") + br_cache[2] = image('icons/obj/power.dmi', "gsmes_charging") + br_cache[3] = image('icons/obj/power.dmi', "gsmes_overcharge") + br_cache[4] = image('icons/obj/power.dmi', "gsmes_og1") + br_cache[5] = image('icons/obj/power.dmi', "gsmes_og2") + br_cache[6] = image('icons/obj/power.dmi', "gsmes_og3") + br_cache[7] = image('icons/obj/power.dmi', "gsmes_og4") + if (output_attempt) overlays += br_cache[1] if(inputting) diff --git a/code/modules/power/diesel_gen.dm b/code/modules/power/diesel_gen.dm index 9422db2fd16..ddd20b7c3dd 100644 --- a/code/modules/power/diesel_gen.dm +++ b/code/modules/power/diesel_gen.dm @@ -307,12 +307,12 @@ if(href_list["action"]) if(href_list["action"] == "enable") if(!active && HasFuel() && !IsBroken()) - active = 1 - icon_state = "portgen1" + active = TRUE + update_icon() if(href_list["action"] == "disable") if (active) - active = 0 - icon_state = "portgen0" + active = FALSE + update_icon() if(href_list["action"] == "eject") if(!active) DropFuel() diff --git a/code/modules/power/port_gen.dm b/code/modules/power/port_gen.dm index aba85a2320a..c82107abd97 100644 --- a/code/modules/power/port_gen.dm +++ b/code/modules/power/port_gen.dm @@ -446,7 +446,7 @@ /obj/machinery/power/port_gen/pacman/super name = "S.U.P.E.R.P.A.C.M.A.N.-type Portable Generator" desc = "A power generator that utilizes uranium sheets as fuel. Can run for much longer than the standard PACMAN type generators. Rated for 80 kW max safe output." - icon_state = "portgen1" + icon_state = "portgen_u0" sheet_path = /obj/item/stack/material/uranium sheet_name = "Uranium Sheets" time_per_fuel_unit = 576 //same power output, but a 50 sheet stack will last 2 hours at max safe power