Files
Paradise/code/modules/power/power_machine.dm
Migratingcocofruit 6f1a90c59d Documents and standardizes power and energy units. Fixes a pulse demon bug. (#26560)
* Documents units of electrical power storage and production. Defines KJ. SMES properly convert watt ticks to KJ. Pulse demon bugfix

* extra documentation

* corrected pulse watt tick to joule conversion location on the pulse demon code

* oops

* Fixes nomenclature formats

* fixes some comments, consolidates power defines in the power defines file
2024-09-03 13:13:24 +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(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