mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Merge pull request #4721 from VOREStation/upstream-merge-5901
[MIRROR] Unclogs powersink drains
This commit is contained in:
@@ -42,10 +42,10 @@ SUBSYSTEM_DEF(machines)
|
||||
/datum/controller/subsystem/machines/fire(resumed = 0)
|
||||
var/timer = TICK_USAGE
|
||||
|
||||
INTERNAL_PROCESS_STEP(SSMACHINES_POWER_OBJECTS,FALSE,process_power_objects,cost_power_objects,SSMACHINES_PIPENETS) // Higher priority, damnit
|
||||
INTERNAL_PROCESS_STEP(SSMACHINES_PIPENETS,TRUE,process_pipenets,cost_pipenets,SSMACHINES_MACHINERY)
|
||||
INTERNAL_PROCESS_STEP(SSMACHINES_MACHINERY,FALSE,process_machinery,cost_machinery,SSMACHINES_POWERNETS)
|
||||
INTERNAL_PROCESS_STEP(SSMACHINES_POWERNETS,FALSE,process_powernets,cost_powernets,SSMACHINES_POWER_OBJECTS)
|
||||
INTERNAL_PROCESS_STEP(SSMACHINES_POWER_OBJECTS,FALSE,process_power_objects,cost_power_objects,SSMACHINES_PIPENETS)
|
||||
|
||||
// rebuild all power networks from scratch - only called at world creation or by the admin verb
|
||||
// The above is a lie. Turbolifts also call this proc.
|
||||
|
||||
@@ -1,133 +1,134 @@
|
||||
// Powersink - used to drain station power
|
||||
|
||||
/obj/item/device/powersink
|
||||
name = "power sink"
|
||||
desc = "A nulling power sink which drains energy from electrical systems."
|
||||
icon_state = "powersink0"
|
||||
w_class = ITEMSIZE_LARGE
|
||||
flags = CONDUCT
|
||||
throwforce = 5
|
||||
throw_speed = 1
|
||||
throw_range = 2
|
||||
|
||||
matter = list(DEFAULT_WALL_MATERIAL = 750,"waste" = 750)
|
||||
|
||||
origin_tech = list(TECH_POWER = 3, TECH_ILLEGAL = 5)
|
||||
var/drain_rate = 1500000 // amount of power to drain per tick
|
||||
var/apc_drain_rate = 5000 // 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 = 1e9 // 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/datum/powernet/PN // Our powernet
|
||||
var/obj/structure/cable/attached // the attached cable
|
||||
|
||||
/obj/item/device/powersink/Destroy()
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
STOP_PROCESSING_POWER_OBJECT(src)
|
||||
..()
|
||||
|
||||
/obj/item/device/powersink/attackby(var/obj/item/I, var/mob/user)
|
||||
if(I.is_screwdriver())
|
||||
if(mode == 0)
|
||||
var/turf/T = loc
|
||||
if(isturf(T) && !!T.is_plating())
|
||||
attached = locate() in T
|
||||
if(!attached)
|
||||
to_chat(user, "No exposed cable here to attach to.")
|
||||
return
|
||||
else
|
||||
anchored = 1
|
||||
mode = 1
|
||||
src.visible_message("<span class='notice'>[user] attaches [src] to the cable!</span>")
|
||||
playsound(src, I.usesound, 50, 1)
|
||||
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
|
||||
STOP_PROCESSING_POWER_OBJECT(src)
|
||||
anchored = 0
|
||||
mode = 0
|
||||
src.visible_message("<span class='notice'>[user] detaches [src] from the cable!</span>")
|
||||
set_light(0)
|
||||
playsound(src, I.usesound, 50, 1)
|
||||
icon_state = "powersink0"
|
||||
|
||||
return
|
||||
else
|
||||
..()
|
||||
|
||||
/obj/item/device/powersink/attack_ai()
|
||||
return
|
||||
|
||||
/obj/item/device/powersink/attack_hand(var/mob/user)
|
||||
switch(mode)
|
||||
if(0)
|
||||
..()
|
||||
if(1)
|
||||
src.visible_message("<span class='notice'>[user] activates [src]!</span>")
|
||||
mode = 2
|
||||
icon_state = "powersink1"
|
||||
// Powersink - used to drain station power
|
||||
|
||||
/obj/item/device/powersink
|
||||
name = "power sink"
|
||||
desc = "A nulling power sink which drains energy from electrical systems."
|
||||
icon_state = "powersink0"
|
||||
w_class = ITEMSIZE_LARGE
|
||||
flags = CONDUCT
|
||||
throwforce = 5
|
||||
throw_speed = 1
|
||||
throw_range = 2
|
||||
|
||||
matter = list(DEFAULT_WALL_MATERIAL = 750,"waste" = 750)
|
||||
|
||||
origin_tech = list(TECH_POWER = 3, TECH_ILLEGAL = 5)
|
||||
var/drain_rate = 1500000 // amount of power to drain per tick
|
||||
var/apc_drain_rate = 5000 // 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 = 1e9 // 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/datum/powernet/PN // Our powernet
|
||||
var/obj/structure/cable/attached // the attached cable
|
||||
|
||||
/obj/item/device/powersink/Destroy()
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
STOP_PROCESSING_POWER_OBJECT(src)
|
||||
..()
|
||||
|
||||
/obj/item/device/powersink/attackby(var/obj/item/I, var/mob/user)
|
||||
if(I.is_screwdriver())
|
||||
if(mode == 0)
|
||||
var/turf/T = loc
|
||||
if(isturf(T) && !!T.is_plating())
|
||||
attached = locate() in T
|
||||
if(!attached)
|
||||
to_chat(user, "No exposed cable here to attach to.")
|
||||
return
|
||||
else
|
||||
anchored = 1
|
||||
mode = 1
|
||||
src.visible_message("<span class='notice'>[user] attaches [src] to the cable!</span>")
|
||||
playsound(src, I.usesound, 50, 1)
|
||||
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
|
||||
STOP_PROCESSING_POWER_OBJECT(src)
|
||||
anchored = 0
|
||||
mode = 0
|
||||
src.visible_message("<span class='notice'>[user] detaches [src] from the cable!</span>")
|
||||
set_light(0)
|
||||
playsound(src, I.usesound, 50, 1)
|
||||
icon_state = "powersink0"
|
||||
|
||||
return
|
||||
else
|
||||
..()
|
||||
|
||||
/obj/item/device/powersink/attack_ai()
|
||||
return
|
||||
|
||||
/obj/item/device/powersink/attack_hand(var/mob/user)
|
||||
switch(mode)
|
||||
if(0)
|
||||
..()
|
||||
if(1)
|
||||
src.visible_message("<span class='notice'>[user] activates [src]!</span>")
|
||||
mode = 2
|
||||
icon_state = "powersink1"
|
||||
START_PROCESSING(SSobj, src)
|
||||
START_PROCESSING_POWER_OBJECT(src)
|
||||
if(2) //This switch option wasn't originally included. It exists now. --NeoFite
|
||||
src.visible_message("<span class='notice'>[user] deactivates [src]!</span>")
|
||||
mode = 1
|
||||
set_light(0)
|
||||
icon_state = "powersink0"
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
STOP_PROCESSING_POWER_OBJECT(src)
|
||||
|
||||
/obj/item/device/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)
|
||||
var/cur_charge = A.cell.charge / CELLRATE
|
||||
var/drain_val = min(apc_drain_rate, cur_charge)
|
||||
A.cell.use(drain_val * CELLRATE)
|
||||
drained += drain_val
|
||||
power_drained += drained
|
||||
return 1
|
||||
|
||||
|
||||
/obj/item/device/powersink/process()
|
||||
drained_this_tick = 0
|
||||
power_drained -= min(dissipation_rate, power_drained)
|
||||
if(power_drained > max_power * 0.95)
|
||||
playsound(src, 'sound/effects/screech.ogg', 100, 1, 1)
|
||||
if(power_drained >= max_power)
|
||||
explosion(src.loc, 3,6,9,12)
|
||||
qdel(src)
|
||||
return
|
||||
if(attached && attached.powernet)
|
||||
PN = attached.powernet
|
||||
else
|
||||
PN = null
|
||||
datum_flags &= ~DF_ISPROCESSING // Have to reset this flag so that PROCESSING_POWER_OBJECT can re-add it. It fails if the flag is already present. - Ater
|
||||
START_PROCESSING_POWER_OBJECT(src)
|
||||
if(2) //This switch option wasn't originally included. It exists now. --NeoFite
|
||||
src.visible_message("<span class='notice'>[user] deactivates [src]!</span>")
|
||||
mode = 1
|
||||
set_light(0)
|
||||
icon_state = "powersink0"
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
STOP_PROCESSING_POWER_OBJECT(src)
|
||||
|
||||
/obj/item/device/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)
|
||||
var/cur_charge = A.cell.charge / CELLRATE
|
||||
var/drain_val = min(apc_drain_rate, cur_charge)
|
||||
A.cell.use(drain_val * CELLRATE)
|
||||
drained += drain_val
|
||||
power_drained += drained
|
||||
return 1
|
||||
|
||||
|
||||
/obj/item/device/powersink/process()
|
||||
drained_this_tick = 0
|
||||
power_drained -= min(dissipation_rate, power_drained)
|
||||
if(power_drained > max_power * 0.95)
|
||||
playsound(src, 'sound/effects/screech.ogg', 100, 1, 1)
|
||||
if(power_drained >= max_power)
|
||||
explosion(src.loc, 3,6,9,12)
|
||||
qdel(src)
|
||||
return
|
||||
if(attached && attached.powernet)
|
||||
PN = attached.powernet
|
||||
else
|
||||
PN = null
|
||||
|
||||
4
html/changelogs/ater - sinks.yml
Normal file
4
html/changelogs/ater - sinks.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
author: Atermonera
|
||||
delete-after: True
|
||||
changes
|
||||
- bugfix: "Powersink drains have been unclogged and work once more"
|
||||
Reference in New Issue
Block a user