Files
VOREStation/code/modules/power/antimatter/control.dm
Kashargul f881d54dbf Panel port test [IDB IGNORE] (#17350)
* no more self callbacks on update fullness

* fix missing code

* Belly test

* import type

* full partiy

* .

* fix preview

* in belly to late join

* robot nutri

* .

* .

* update export

* finish open todos

* code cleanup

* fix some old slacking

* move this to a define

* fixing

* ,

* .

* Creates a Consume Belly Reagents pref (#10)

* Creates a Consume Belly Reagents pref

Added a Consume Belly Reagents pref that blocks the consumption of all reagents produced by a belly via reagent containers such as food, drink, beakers, pills, syringes and hyposprays. Seems to work well as intended.

* These changes at least do not cause any problems

* Missed this one

* Reverts reagent_names

* _BELLY versions

* Fixed typo

* .

* fix admin spawn mobs bellies

* also fix that bug

* hints

* fix that

* .

* initial

* should be all

* that is no longer needed

* fluids into hand items

I was convinced this was broken until it was pointed out that the item has to be ON THE GROUND to fill it...Instead of in your hand. That seems so convoluted.

ARC = active-hand reagent container. IRC = inactive-hand reagent container.

* some stuff

---------

Co-authored-by: SatinIsle <98125273+SatinIsle@users.noreply.github.com>
Co-authored-by: Cameron Lennox <killer65311@gmail.com>
2025-03-16 17:08:47 -04:00

320 lines
9.4 KiB
Plaintext

/obj/machinery/power/am_control_unit
name = "antimatter control unit"
desc = "This device injects antimatter into connected shielding units, the more antimatter injected the more power produced. Wrench the device to set it up."
icon = 'icons/obj/machines/antimatter.dmi'
icon_state = "control"
anchored = TRUE
density = TRUE
use_power = USE_POWER_IDLE
idle_power_usage = 100
active_power_usage = 1000
var/list/obj/machinery/am_shielding/linked_shielding = list()
var/list/obj/machinery/am_shielding/linked_cores = list()
var/obj/item/am_containment/fueljar
var/update_shield_icons = 0
var/stability = 100
var/exploding = 0
var/active = 0//On or not
var/fuel_injection = 2//How much fuel to inject
var/shield_icon_delay = 0//delays resetting for a short time
var/reported_core_efficiency = 0
var/power_cycle = 0
var/power_cycle_delay = 4//How many ticks till produce_power is called
var/stored_core_stability = 0
var/stored_core_stability_delay = 0
var/stored_power = 0//Power to deploy per tick
/obj/machinery/power/am_control_unit/Destroy()//Perhaps damage and run stability checks rather than just qdel on the others
for(var/obj/machinery/am_shielding/AMS in linked_shielding)
qdel(AMS)
. = ..()
/obj/machinery/power/am_control_unit/process()
if(exploding)
explosion(get_turf(src),8,12,18,12)
if(src) qdel(src)
if(update_shield_icons && !shield_icon_delay)
check_shield_icons()
update_shield_icons = 0
if(stat & (NOPOWER|BROKEN) || !active)//can update the icons even without power
return
if(!fueljar)//No fuel but we are on, shutdown
toggle_power()
//Angry buzz or such here
return
add_avail(stored_power)
power_cycle++
if(power_cycle >= power_cycle_delay)
produce_power()
power_cycle = 0
return
/obj/machinery/power/am_control_unit/proc/produce_power()
playsound(src, 'sound/effects/bang.ogg', 25, 1)
var/core_power = reported_core_efficiency//Effectively how much fuel we can safely deal with
if(core_power <= 0) return 0//Something is wrong
var/core_damage = 0
var/fuel = fueljar.usefuel(fuel_injection)
stored_power = (fuel/core_power)*fuel*200000
//Now check if the cores could deal with it safely, this is done after so you can overload for more power if needed, still a bad idea
if(fuel > (2*core_power))//More fuel has been put in than the current cores can deal with
if(prob(50))core_damage = 1//Small chance of damage
if((fuel-core_power) > 5) core_damage = 5//Now its really starting to overload the cores
if((fuel-core_power) > 10) core_damage = 20//Welp now you did it, they wont stand much of this
if(core_damage == 0) return
for(var/obj/machinery/am_shielding/AMS in linked_cores)
AMS.stability -= core_damage
AMS.check_stability(1)
playsound(src, 'sound/effects/bang.ogg', 50, 1)
return
/obj/machinery/power/am_control_unit/emp_act(severity)
switch(severity)
if(1)
if(active) toggle_power()
stability -= rand(15,30)
if(2)
if(active) toggle_power()
stability -= rand(10,20)
if(3)
if(active) toggle_power()
stability -= rand(8,15)
if(4)
if(active) toggle_power()
stability -= rand(5,10)
..()
return 0
/obj/machinery/power/am_control_unit/ex_act(severity)
switch(severity)
if(1.0)
stability -= 60
if(2.0)
stability -= 40
if(3.0)
stability -= 20
check_stability()
return
/obj/machinery/power/am_control_unit/bullet_act(var/obj/item/projectile/Proj)
if(Proj.check_armour != "bullet")
stability -= Proj.force
return 0
/obj/machinery/power/am_control_unit/power_change()
..()
if(stat & NOPOWER && active)
toggle_power()
return
/obj/machinery/power/am_control_unit/update_icon()
if(active) icon_state = "control_on"
else icon_state = "control"
//No other icons for it atm
/obj/machinery/power/am_control_unit/attackby(obj/item/W, mob/user)
if(!istype(W) || !user) return
if(W.has_tool_quality(TOOL_WRENCH))
if(!anchored)
playsound(src, W.usesound, 75, 1)
user.visible_message("[user.name] secures the [src.name] to the floor.", \
"You secure the anchor bolts to the floor.", \
"You hear a ratchet.")
src.anchored = TRUE
connect_to_network()
else if(!linked_shielding.len > 0)
playsound(src, W.usesound, 75, 1)
user.visible_message("[user.name] unsecures the [src.name].", \
"You remove the anchor bolts.", \
"You hear a ratchet.")
src.anchored = FALSE
disconnect_from_network()
else
to_chat(user, span_red("Once bolted and linked to a shielding unit it the [src.name] is unable to be moved!"))
return
if(istype(W, /obj/item/am_containment))
if(fueljar)
to_chat(user, span_red("There is already a [fueljar] inside!"))
return
fueljar = W
user.remove_from_mob(W)
W.loc = src
user.update_icons()
user.visible_message("[user.name] loads an [W.name] into the [src.name].", \
"You load an [W.name].", \
"You hear a thunk.")
return
if(W.force >= 20)
stability -= W.force/2
check_stability()
..()
return
/obj/machinery/power/am_control_unit/attack_hand(mob/user as mob)
if(anchored)
interact(user)
return
/obj/machinery/power/am_control_unit/proc/add_shielding(var/obj/machinery/am_shielding/AMS, var/AMS_linking = 0)
if(!istype(AMS)) return 0
if(!anchored) return 0
if(!AMS_linking && !AMS.link_control(src)) return 0
linked_shielding.Add(AMS)
update_shield_icons = 1
return 1
/obj/machinery/power/am_control_unit/proc/remove_shielding(var/obj/machinery/am_shielding/AMS)
if(!istype(AMS)) return 0
linked_shielding.Remove(AMS)
update_shield_icons = 2
if(active) toggle_power()
return 1
/obj/machinery/power/am_control_unit/proc/check_stability()//TODO: make it break when low also might want to add a way to fix it like a part or such that can be replaced
if(stability <= 0)
qdel(src)
return
/obj/machinery/power/am_control_unit/proc/toggle_power()
active = !active
if(active)
update_use_power(USE_POWER_ACTIVE)
visible_message("The [src.name] starts up.")
else
update_use_power(USE_POWER_IDLE)
visible_message("The [src.name] shuts down.")
update_icon()
return
/obj/machinery/power/am_control_unit/proc/check_shield_icons()//Forces icon_update for all shields
if(shield_icon_delay) return
shield_icon_delay = 1
if(update_shield_icons == 2)//2 means to clear everything and rebuild
for(var/obj/machinery/am_shielding/AMS in linked_shielding)
if(AMS.processing) AMS.shutdown_core()
AMS.control_unit = null
addtimer(CALLBACK(AMS, TYPE_PROC_REF(/obj/machinery/am_shielding, controllerscan)), 1 SECOND, TIMER_DELETE_ME)
linked_shielding = list()
else
for(var/obj/machinery/am_shielding/AMS in linked_shielding)
AMS.update_icon()
VARSET_IN(src, shield_icon_delay, 0, 2 SECONDS)
/obj/machinery/power/am_control_unit/proc/check_core_stability()
if(stored_core_stability_delay || linked_cores.len <= 0) return
stored_core_stability_delay = 1
stored_core_stability = 0
for(var/obj/machinery/am_shielding/AMS in linked_cores)
stored_core_stability += AMS.stability
stored_core_stability/=linked_cores.len
VARSET_IN(src, stored_core_stability_delay, 0, 4 SECONDS)
return
/obj/machinery/power/am_control_unit/interact(mob/user)
if((get_dist(src, user) > 1) || (stat & (BROKEN|NOPOWER)))
if(!isAI(user))
user.unset_machine()
user << browse(null, "window=AMcontrol")
return
user.set_machine(src)
var/dat = ""
dat += "AntiMatter Control Panel<BR>"
dat += "<A href='byond://?src=\ref[src];close=1'>Close</A><BR>"
dat += "<A href='byond://?src=\ref[src];refresh=1'>Refresh</A><BR>"
dat += "<A href='byond://?src=\ref[src];refreshicons=1'>Force Shielding Update</A><BR><BR>"
dat += "Status: [(active?"Injecting":"Standby")] <BR>"
dat += "<A href='byond://?src=\ref[src];togglestatus=1'>Toggle Status</A><BR>"
dat += "Instability: [stability]%<BR>"
dat += "Reactor parts: [linked_shielding.len]<BR>"//TODO: perhaps add some sort of stability check
dat += "Cores: [linked_cores.len]<BR><BR>"
dat += "-Current Efficiency: [reported_core_efficiency]<BR>"
dat += "-Average Stability: [stored_core_stability] <A href='byond://?src=\ref[src];refreshstability=1'>(update)</A><BR>"
dat += "Last Produced: [stored_power]<BR>"
dat += "Fuel: "
if(!fueljar)
dat += "<BR>No fuel receptacle detected."
else
dat += "<A href='byond://?src=\ref[src];ejectjar=1'>Eject</A><BR>"
dat += "- [fueljar.fuel]/[fueljar.fuel_max] Units<BR>"
dat += "- Injecting: [fuel_injection] units<BR>"
dat += "- <A href='byond://?src=\ref[src];strengthdown=1'>--</A>|<A href='byond://?src=\ref[src];strengthup=1'>++</A><BR><BR>"
user << browse("<html>[dat]</html>", "window=AMcontrol;size=420x500")
onclose(user, "AMcontrol")
return
/obj/machinery/power/am_control_unit/Topic(href, href_list)
..()
//Ignore input if we are broken or guy is not touching us, AI can control from a ways away
if(stat & (BROKEN|NOPOWER) || (get_dist(src, usr) > 1 && !isAI(usr)))
usr.unset_machine()
usr << browse(null, "window=AMcontrol")
return
if(href_list["close"])
usr << browse(null, "window=AMcontrol")
usr.unset_machine()
return
if(href_list["togglestatus"])
toggle_power()
if(href_list["refreshicons"])
update_shield_icons = 1
if(href_list["ejectjar"])
if(fueljar)
fueljar.loc = src.loc
fueljar = null
//fueljar.control_unit = null currently it does not care where it is
//update_icon() when we have the icon for it
if(href_list["strengthup"])
fuel_injection++
if(href_list["strengthdown"])
fuel_injection--
if(fuel_injection < 0) fuel_injection = 0
if(href_list["refreshstability"])
check_core_stability()
updateDialog()
return