Files
Paradise/code/modules/power/power_machine.dm
warriorstar-orion 525c68d617 Attack chain, initial setup. (pull *immediately* for *any* TM issues) (#26834)
* refactor: Attack chain, initial setup.

* migrate curtain to make dreamchecker happy

* update thurible

* don't call attacked_by separately for legacy attack chain

* remove duplicate proc

* condense similar code, put allowances for legacy code in new procs

* update docs, include diagram source

* add comment on how to update diagram

* fix admonition

* mindflayer updates

* remove commented out code

* clarify all steps

* after_attack should be overridable

* whoops

* retrofit recent changes

* duh, can't restrict this yet because of tool_acts

* i hate ore bags with the fire of a thousand suns

* return correct value for object attack logic

* Various cleanups.

We don't want to attempt to pull stuff out of `/obj/item/attackby`,
because those pieces are part of the related objects' migrations, not
`/obj/item` itself. Attempting to do this causes knockon effects where
things expected to call e.g. `/obj/item/storage/attackby` in the call
chain were not ferried over to the new item interaction code, because
the related objects hadn't actually been migrated over yet.

I've used refactoring /obj/vehicle as the example for migrating
`attackby` methods instead.

* simplify some argument names

* fuck it

* make it do the thing

* Rename CI module call

* Prove that CI works

* improve test output

* aaand fix it again

* fix curtain tool interactions

* fix compile error

* fix compile error

* Better docs, introduce migration plan tool.
2024-12-02 23:36:36 +00:00

112 lines
3.4 KiB
Plaintext

//////////////////////////////
// POWER MACHINERY BASE CLASS
//////////////////////////////
/obj/machinery/power
name = null
icon = 'icons/obj/power.dmi'
anchored = TRUE
on_blueprints = TRUE
power_state = NO_POWER_USE
var/datum/regional_powernet/powernet = null
/obj/machinery/power/Destroy()
disconnect_from_network()
return ..()
/// Adds available power to the next powernet process (Watts)
/obj/machinery/power/proc/produce_direct_power(amount)
if(powernet)
powernet.queued_power_production += amount
return TRUE
return FALSE
/// Adds power demand to the powernet (Watts)
/// machines should use this proc
/obj/machinery/power/proc/consume_direct_power(amount)
powernet?.power_demand += amount
/// Gets surplus power available on this machine's powernet (Watts)
/obj/machinery/power/proc/get_surplus()
return powernet ? powernet.calculate_surplus() : 0
/// Gets surplus power available on this machine's powernet (Watts)
/obj/machinery/power/proc/get_power_balance()
return powernet ? powernet.calculate_power_balance() : 0
/// Gets power available (NOT EXTRA) on this cables powernet (Watts)
/// machines should use this proc
/obj/machinery/power/proc/get_available_power()
return powernet ? powernet.available_power : 0
/// Adds queued power demand to be met next process cycle (Watts)
/obj/machinery/power/proc/add_queued_power_demand(amount)
powernet?.queued_power_demand += amount
/// Gets surplus power queued for next process cycle on this cables powernet (Watts)
/obj/machinery/power/proc/get_queued_surplus()
return powernet?.calculate_queued_surplus()
/// Gets available (NOT EXTRA) power queued for next process cycle on this machine's powernet (Watts)
/obj/machinery/power/proc/get_queued_available_power()
return powernet?.queued_power_production
/obj/machinery/power/proc/disconnect_terminal() // machines without a terminal will just return, no harm no fowl.
return
// connect the machine to a powernet if a node cable is present on the turf
/obj/machinery/power/proc/connect_to_network()
var/turf/T = loc
if(!istype(T))
return FALSE
var/obj/structure/cable/C = T.get_cable_node() //check if we have a node cable on the machine turf, the first found is picked
if(!C || !C.powernet)
return FALSE
C.powernet.add_machine(src)
return TRUE
// remove and disconnect the machine from its current powernet
/obj/machinery/power/proc/disconnect_from_network()
if(!powernet)
return FALSE
powernet.remove_machine(src)
return TRUE
// attach a wire to a power machine - leads from the turf you are standing on
//almost never called, overwritten by all power machines but terminal and generator
/obj/machinery/power/attackby__legacy__attackchain(obj/item/I, mob/user, params)
if(istype(I, /obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/coil = I
var/turf/T = user.loc
if(T.intact || !isfloorturf(T))
return
if(get_dist(src, user) > 1)
return
coil.place_turf(T, user)
else
return ..()
////////////////////////////////////////////////
// Misc.
///////////////////////////////////////////////
// return a knot cable (O-X) if one is present in the turf
// null if there's none
/turf/proc/get_cable_node()
if(!can_have_cabling())
return null
for(var/obj/structure/cable/C in src)
if(C.d1 == NO_DIRECTION)
return C
return null
/area/proc/get_apc()
for(var/thing in GLOB.apcs)
var/obj/machinery/power/apc/APC = thing
if(APC.apc_area == src)
return APC