diff --git a/code/_globalvars/lists/objects.dm b/code/_globalvars/lists/objects.dm index 906bacf0e54..e6f463d6f23 100644 --- a/code/_globalvars/lists/objects.dm +++ b/code/_globalvars/lists/objects.dm @@ -19,7 +19,6 @@ GLOBAL_LIST_INIT(navigation_computers, list()) GLOBAL_LIST_INIT(all_areas, list()) GLOBAL_LIST_INIT(machines, list()) -GLOBAL_LIST_INIT(processing_power_items, list()) //items that ask to be called every cycle GLOBAL_LIST_INIT(rcd_list, list()) //list of Rapid Construction Devices. GLOBAL_LIST_INIT(apcs, list()) diff --git a/code/_globalvars/misc.dm b/code/_globalvars/misc.dm index 0b8c8d58a95..77443fb4ab2 100644 --- a/code/_globalvars/misc.dm +++ b/code/_globalvars/misc.dm @@ -1,6 +1,9 @@ var/global/obj/effect/overlay/plmaster = null var/global/obj/effect/overlay/slmaster = null +GLOBAL_VAR_INIT(CELLRATE, 0.002) // conversion ratio between a watt-tick and kilojoule +GLOBAL_VAR_INIT(CHARGELEVEL, 0.001) // Cap for how fast cells charge, as a percentage-per-tick (.001 means cellcharge is capped to 1% per second) + // Announcer intercom, because too much stuff creates an intercom for one message then hard del()s it. var/global/obj/item/radio/intercom/global_announcer = create_global_announcer() var/global/obj/item/radio/intercom/command/command_announcer = create_command_announcer() diff --git a/code/_globalvars/station.dm b/code/_globalvars/station.dm index 2d635996b30..e997a672e1f 100644 --- a/code/_globalvars/station.dm +++ b/code/_globalvars/station.dm @@ -1,6 +1,3 @@ var/global/datum/datacore/data_core = null -var/CELLRATE = 0.002 // multiplier for watts per tick <> cell storage (eg: .002 means if there is a load of 1000 watts, 20 units will be taken from a cell per second) -var/CHARGELEVEL = 0.001 // Cap for how fast cells charge, as a percentage-per-tick (.001 means cellcharge is capped to 1% per second) - var/map_name = "Unknown" //The name of the map that is loaded. Assigned in world/New() \ No newline at end of file diff --git a/code/controllers/subsystem/machinery.dm b/code/controllers/subsystem/machinery.dm index 7038ad4db4f..9a73c1dbabb 100644 --- a/code/controllers/subsystem/machinery.dm +++ b/code/controllers/subsystem/machinery.dm @@ -64,23 +64,6 @@ SUBSYSTEM_DEF(machines) if(MC_TICK_CHECK) return -/datum/controller/subsystem/machines/proc/process_premachines(resumed = 0) - /* Literally exists as snowflake for fucking powersinks goddamnit */ - if(!resumed) - src.currentrun = GLOB.processing_power_items.Copy() - //cache for sanid speed (lists are references anyways) - var/list/currentrun = src.currentrun - while(currentrun.len) - var/obj/item/I = currentrun[currentrun.len] - currentrun.len-- - if(!QDELETED(I)) - if(!I.pwr_drain()) - GLOB.processing_power_items.Remove(I) - else - GLOB.processing_power_items.Remove(I) - if(MC_TICK_CHECK) - return - /datum/controller/subsystem/machines/proc/process_machines(resumed = 0) var/seconds = wait * 0.1 if(!resumed) @@ -113,13 +96,6 @@ SUBSYSTEM_DEF(machines) if(state != SS_RUNNING) return resumed = 0 - currentpart = SSMACHINES_PREMACHINERY - - if(currentpart == SSMACHINES_PREMACHINERY || !resumed) - process_premachines(resumed) - if(state != SS_RUNNING) - return - resumed = 0 currentpart = SSMACHINES_MACHINERY if(currentpart == SSMACHINES_MACHINERY || !resumed) diff --git a/code/game/machinery/computer/power.dm b/code/game/machinery/computer/power.dm index a5198da6e56..b39c005855c 100644 --- a/code/game/machinery/computer/power.dm +++ b/code/game/machinery/computer/power.dm @@ -38,7 +38,7 @@ if(isturf(T)) attached = locate() in T if(attached) - return attached.get_powernet() + return attached.powernet /obj/machinery/computer/monitor/attack_ai(mob/user) attack_hand(user) diff --git a/code/game/machinery/syndicatebeacon.dm b/code/game/machinery/syndicatebeacon.dm index 304dc7dc639..6422e94dc74 100644 --- a/code/game/machinery/syndicatebeacon.dm +++ b/code/game/machinery/syndicatebeacon.dm @@ -188,11 +188,11 @@ /obj/machinery/power/singularity_beacon/process() if(!active) return PROCESS_KILL + + if(surplus() >= 1500) + add_load(1500) else - if(surplus() > 1500) - draw_power(1500) - else - Deactivate() + Deactivate() /obj/machinery/power/singularity_beacon/syndicate icontype = "beaconsynd" diff --git a/code/game/objects/items/devices/powersink.dm b/code/game/objects/items/devices/powersink.dm index 463223f4268..562800c2ce0 100644 --- a/code/game/objects/items/devices/powersink.dm +++ b/code/game/objects/items/devices/powersink.dm @@ -1,3 +1,7 @@ +#define DISCONNECTED 0 +#define CLAMPED_OFF 1 +#define OPERATING 2 + // Powersink - used to drain station power /obj/item/powersink @@ -13,28 +17,55 @@ throw_range = 2 materials = list(MAT_METAL=750) origin_tech = "powerstorage=5;syndicate=5" - var/drain_rate = 1600000 // amount of power to drain per tick - var/apc_drain_rate = 50 // Max. amount drained from single APC. In Watts. - var/dissipation_rate = 20000 // Passive dissipation of drained power. In Watts. - var/power_drained = 0 // Amount of power drained. - var/max_power = 1e10 // Detonation point. - var/mode = 0 // 0 = off, 1=clamped (off), 2=operating - var/drained_this_tick = 0 // This is unfortunately necessary to ensure we process powersinks BEFORE other machinery such as APCs. - var/admins_warned = 0 // stop spam, only warn the admins once that we are about to go boom + var/drain_rate = 2000000 // amount of power to drain per tick + var/power_drained = 0 // has drained this much power + var/max_power = 6e8 // maximum power that can be drained before exploding + var/mode = 0 // 0 = off, 1=clamped (off), 2=operating + var/admins_warned = FALSE // stop spam, only warn the admins once that we are about to boom - var/datum/powernet/PN // Our powernet var/obj/structure/cable/attached // the attached cable /obj/item/powersink/Destroy() STOP_PROCESSING(SSobj, src) - GLOB.processing_power_items.Remove(src) - PN = null attached = null return ..() -/obj/item/powersink/attackby(var/obj/item/I, var/mob/user) - if(istype(I, /obj/item/screwdriver)) - if(mode == 0) +/obj/item/powersink/update_icon() + icon_state = "powersink[mode == OPERATING]" + +/obj/item/powersink/proc/set_mode(value) + if(value == mode) + return + switch(value) + if(DISCONNECTED) + attached = null + if(mode == OPERATING) + STOP_PROCESSING(SSobj, src) + anchored = FALSE + density = FALSE + + if(CLAMPED_OFF) + if(!attached) + return + if(mode == OPERATING) + STOP_PROCESSING(SSobj, src) + anchored = TRUE + density = TRUE + + if(OPERATING) + if(!attached) + return + START_PROCESSING(SSobj, src) + anchored = TRUE + density = TRUE + + mode = value + update_icon() + set_light(0) + +/obj/item/powersink/attackby(obj/item/I, mob/user) + if(isscrewdriver(I)) + if(mode == DISCONNECTED) var/turf/T = loc if(isturf(T) && !T.intact) attached = locate() in T @@ -42,98 +73,81 @@ to_chat(user, "No exposed cable here to attach to.") return else - anchored = 1 - mode = 1 - src.visible_message("[user] attaches [src] to the cable!") + set_mode(CLAMPED_OFF) + visible_message("[user] attaches [src] to the cable!") message_admins("Power sink activated by [key_name_admin(user)] at ([x],[y],[z] - JMP)") log_game("Power sink activated by [key_name(user)] at ([x],[y],[z])") - return else to_chat(user, "Device must be placed over an exposed cable to attach to it.") - return else - if(mode == 2) - STOP_PROCESSING(SSobj, src) // Now the power sink actually stops draining the station's power if you unhook it. --NeoFite - GLOB.processing_power_items.Remove(src) - anchored = 0 - mode = 0 + set_mode(DISCONNECTED) src.visible_message("[user] detaches [src] from the cable!") - set_light(0) - icon_state = "powersink0" - - return else - ..() + return ..() /obj/item/powersink/attack_ai() return /obj/item/powersink/attack_hand(var/mob/user) switch(mode) - if(0) + if(DISCONNECTED) ..() - if(1) - src.visible_message("[user] activates [src]!") - mode = 2 - icon_state = "powersink1" - START_PROCESSING(SSobj, src) - GLOB.processing_power_items.Add(src) - if(2) //This switch option wasn't originally included. It exists now. --NeoFite - src.visible_message("[user] deactivates [src]!") - mode = 1 - set_light(0) - icon_state = "powersink0" - STOP_PROCESSING(SSobj, src) - GLOB.processing_power_items.Remove(src) - -/obj/item/powersink/pwr_drain() - if(!attached) - return 0 - - if(drained_this_tick) - return 1 - drained_this_tick = 1 - - var/drained = 0 - - if(!PN) - return 1 - - set_light(12) - PN.trigger_warning() - // found a powernet, so drain up to max power from it - drained = PN.draw_power(drain_rate) - // if tried to drain more than available on powernet - // now look for APCs and drain their cells - if(drained < drain_rate) - for(var/obj/machinery/power/terminal/T in PN.nodes) - // Enough power drained this tick, no need to torture more APCs - if(drained >= drain_rate) - break - if(istype(T.master, /obj/machinery/power/apc)) - var/obj/machinery/power/apc/A = T.master - if(A.operating && A.cell) - A.cell.charge = max(0, A.cell.charge - apc_drain_rate) - drained += apc_drain_rate - if(A.charging == 2) // If the cell was full - A.charging = 1 // It's no longer full - power_drained += drained - return 1 + if(CLAMPED_OFF) + user.visible_message( \ + "[user] activates \the [src]!", \ + "You activate \the [src].", + "You hear a click.") + message_admins("Power sink activated by [ADMIN_LOOKUPFLW(user)] at [ADMIN_VERBOSEJMP(src)]") + log_game("Power sink activated by [key_name(user)] at [AREACOORD(src)]") + set_mode(OPERATING) + if(OPERATING) + user.visible_message( \ + "[user] deactivates \the [src]!", \ + "You deactivate \the [src].", + "You hear a click.") + set_mode(CLAMPED_OFF) /obj/item/powersink/process() - drained_this_tick = 0 - power_drained -= min(dissipation_rate, power_drained) + if(!attached) + set_mode(DISCONNECTED) + return + + var/datum/powernet/PN = attached.powernet + if(PN) + set_light(5) + + // found a powernet, so drain up to max power from it + + var/drained = min (drain_rate, attached.newavail()) + attached.add_delayedload(drained) + power_drained += drained + + // if tried to drain more than available on powernet + // now look for APCs and drain their cells + if(drained < drain_rate) + for(var/obj/machinery/power/terminal/T in PN.nodes) + if(istype(T.master, /obj/machinery/power/apc)) + var/obj/machinery/power/apc/A = T.master + if(A.operating && A.cell) + A.cell.charge = max(0, A.cell.charge - 50) + power_drained += 50 + if(A.charging == 2) // If the cell was full + A.charging = 1 // It's no longer full + if(drained >= drain_rate) + break + if(power_drained > max_power * 0.98) - if(!admins_warned) - admins_warned = 1 + if (!admins_warned) + admins_warned = TRUE message_admins("Power sink at ([x],[y],[z] - JMP) is 95% full. Explosion imminent.") playsound(src, 'sound/effects/screech.ogg', 100, 1, 1) + if(power_drained >= max_power) + STOP_PROCESSING(SSobj, src) explosion(src.loc, 4,8,16,32) qdel(src) - return - if(attached && attached.powernet) - PN = attached.powernet - else - PN = null + +#undef DISCONNECTED +#undef CLAMPED_OFF +#undef OPERATING \ No newline at end of file diff --git a/code/game/objects/structures/grille.dm b/code/game/objects/structures/grille.dm index 154d4438530..1e3cb331cd1 100644 --- a/code/game/objects/structures/grille.dm +++ b/code/game/objects/structures/grille.dm @@ -273,8 +273,8 @@ var/obj/structure/cable/C = T.get_cable_node() if(C) playsound(loc, 'sound/magic/lightningshock.ogg', 100, 1, extrarange = 5) - tesla_zap(src, 3, C.powernet.avail * 0.01) //Zap for 1/100 of the amount of power. At a million watts in the grid, it will be as powerful as a tesla revolver shot. - C.powernet.load += C.powernet.avail * 0.0375 // you can gain up to 3.5 via the 4x upgrades power is halved by the pole so thats 2x then 1X then .5X for 3.5x the 3 bounces shock. + tesla_zap(src, 3, C.newavail() * 0.01) //Zap for 1/100 of the amount of power. At a million watts in the grid, it will be as powerful as a tesla revolver shot. + C.add_delayedload(C.newavail() * 0.0375) // you can gain up to 3.5 via the 4x upgrades power is halved by the pole so thats 2x then 1X then .5X for 3.5x the 3 bounces shock. return ..() /obj/structure/grille/broken // Pre-broken grilles for map placement diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index 9d5d09c0447..4fcf95dbfd2 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -950,9 +950,6 @@ var/gamma_ship_location = 1 // 0 = station , 1 = space for(var/obj/machinery/mech_bay_recharge_port/P in toArea) P.update_recharge_turf() - for(var/obj/machinery/power/apc/A in toArea) - A.init() - if(gamma_ship_location) gamma_ship_location = 0 else @@ -1096,7 +1093,7 @@ var/gamma_ship_location = 1 // 0 = station , 1 = space dat += "