mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-19 14:51:27 +00:00
* initial edits * more cleanup, yipee * moving shit around * dme fixes * fixes file ticking issue * more dme fixes + duplicate files??? * Apply suggestions from code review Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com> * glass floor fixes * Apply suggestions from code review Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> * requested reviews * the most painful bugfix of my life * forgot to remove some debug stuff * fixed issues with excess power * fuck powernets (fix) * Update code/modules/power/powernets/README.md Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com> --------- Co-authored-by: Henri215 <77684085+Henri215@users.noreply.github.com> Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com>
110 lines
3.3 KiB
Plaintext
110 lines
3.3 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 ..()
|
|
|
|
/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, machines should use this
|
|
/obj/machinery/power/proc/consume_direct_power(amount)
|
|
powernet?.power_demand += amount
|
|
|
|
/// Gets surplus power available on this machines powernet, machines should use this proc
|
|
/obj/machinery/power/proc/get_surplus()
|
|
return powernet ? powernet.calculate_surplus() : 0
|
|
|
|
/// Gets surplus power available on this machines powernet, machines should use this proc
|
|
/obj/machinery/power/proc/get_power_balance()
|
|
return powernet ? powernet.calculate_power_balance() : 0
|
|
|
|
/// Gets power available (NOT EXTRA) on this cables powernet, machines should use this
|
|
/obj/machinery/power/proc/get_available_power()
|
|
return powernet ? powernet.available_power : 0
|
|
|
|
/// Adds queued power demand to be met next process cycle
|
|
/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
|
|
/obj/machinery/power/proc/get_queued_surplus()
|
|
return powernet?.calculate_queued_surplus()
|
|
|
|
/// Gets available (NOT EXTRA) power queued for next process cycle on this machines powernet
|
|
/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
|