Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactor changes #5657

Merged
merged 14 commits into from
Feb 19, 2024
2 changes: 1 addition & 1 deletion code/__DEFINES/dcs/signals/signals_global.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#define COMSIG_GLOB_RESEARCH_LOCKDOWN "!research_lockdown_closed"
#define COMSIG_GLOB_RESEARCH_LIFT "!research_lockdown_opened"

/// From /obj/structure/machinery/power/fusion_engine/proc/set_overloading() : (set_overloading)
/// From /obj/structure/machinery/power/reactor/proc/set_overloading() : (set_overloading)
#define COMSIG_GLOB_GENERATOR_SET_OVERLOADING "!generator_set_overloading"

#define COMSIG_GLOB_HIJACK_IMPACTED "!hijack_impacted"
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/hijack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ SUBSYSTEM_DEF(hijack)
sd_unlocked = TRUE
marine_announcement("Fuel reserves full. Manual detonation of fuel reserves by overloading the on-board fusion reactors now possible.", HIJACK_ANNOUNCE)

/datum/controller/subsystem/hijack/proc/on_generator_overload(obj/structure/machinery/power/fusion_engine/source, new_overloading)
/datum/controller/subsystem/hijack/proc/on_generator_overload(obj/structure/machinery/power/reactor/source, new_overloading)
SIGNAL_HANDLER

if(!generator_ever_overloaded)
Expand Down
21 changes: 10 additions & 11 deletions code/game/gamemodes/events/power_failure.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@
if(announce)
marine_announcement("Power has been restored. Reason: Unknown.", "Power Systems Nominal", 'sound/AI/poweron.ogg')

/proc/power_restore_ship_reactors(announce = 1)
for(var/obj/structure/machinery/power/fusion_engine/FE in GLOB.machines)
FE.buildstate = 0
FE.is_on = 1
FE.fusion_cell = new
FE.power_gen_percent = 98
FE.update_icon()
FE.start_processing()
FE.power_change()
/proc/power_restore_ship_reactors(announce = TRUE)
for(var/obj/structure/machinery/power/reactor/reactor in GLOB.machines)
if(!is_mainship_level(reactor.z)) //Only ship reactors should be repaired
continue
reactor.buildstate = 0
if(reactor.require_fusion_cell && !reactor.fusion_cell)
reactor.fusion_cell = new
reactor.power_gen_percent = 98
reactor.start_functioning(TRUE)

sleep(100)
if(announce)
marine_announcement("Power has been restored. Reason: Unknown.", "Power Systems Nominal", 'sound/AI/poweron.ogg')
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(marine_announcement), "Power has been restored. Reason: Unknown.", "Power Systems Nominal", 'sound/AI/poweron.ogg'), 10 SECONDS)
Original file line number Diff line number Diff line change
@@ -1,206 +1,3 @@
/obj/structure/machinery/power/geothermal
name = "\improper G-11 geothermal generator"
icon = 'icons/obj/structures/machinery/geothermal.dmi'
icon_state = "weld"
desc = "A thermoelectric generator sitting atop a plasma-filled borehole. This one is heavily damaged. Use a blowtorch, wirecutters, then wrench to repair it."
anchored = TRUE
density = TRUE
directwired = 0 //Requires a cable directly underneath
unslashable = TRUE
unacidable = TRUE //NOPE.jpg
var/power_gen_percent = 0 //100,000W at full capacity
var/power_generation_max = 100000 //Full capacity
var/powernet_connection_failed = 0 //Logic checking for powernets
var/buildstate = 1 //What state of building it are we on, 0-3, 1 is "broken", the default
var/is_on = 0 //Is this damn thing on or what?
var/fail_rate = 10 //% chance of failure each fail_tick check
var/fail_check_ticks = 100 //Check for failure every this many ticks
var/cur_tick = 0 //Tick updater
power_machine = TRUE

//We don't want to cut/update the power overlays every single proc. Just when it actually changes. This should save on CPU cycles. Efficiency!
/obj/structure/machinery/power/geothermal/update_icon()
..()
if(!buildstate && is_on)
desc = "A thermoelectric generator sitting atop a borehole dug deep in the planet's surface. It generates energy by boiling the plasma steam that rises from the well.\nIt is old technology and has a large failure rate, and must be repaired frequently.\nIt is currently on, and beeping randomly amid faint hisses of steam."
switch(power_gen_percent)
if(25) icon_state = "on[power_gen_percent]"
if(50) icon_state = "on[power_gen_percent]"
if(75) icon_state = "on[power_gen_percent]"
if(100) icon_state = "on[power_gen_percent]"


else if (!buildstate && !is_on)
icon_state = "off"
desc = "A thermoelectric generator sitting atop a borehole dug deep in the planet's surface. It generates energy by boiling the plasma steam that rises from the well.\nIt is old technology and has a large failure rate, and must be repaired frequently.\nIt is currently turned off and silent."
else
if(buildstate == 1)
icon_state = "weld"
desc = "A thermoelectric generator sitting atop a plasma-filled borehole. This one is heavily damaged. Use a blowtorch, wirecutters, then wrench to repair it."
else if(buildstate == 2)
icon_state = "wire"
desc = "A thermoelectric generator sitting atop a plasma-filled borehole. This one is damaged. Use a wirecutters, then wrench to repair it."
else
icon_state = "wrench"
desc = "A thermoelectric generator sitting atop a plasma-filled borehole. This one is lightly damaged. Use a wrench to repair it."

/obj/structure/machinery/power/geothermal/Initialize(mapload, ...)
. = ..()
if(!connect_to_network()) //Should start with a cable piece underneath, if it doesn't, something's messed up in mapping
powernet_connection_failed = 1

/obj/structure/machinery/power/geothermal/power_change()
return

/obj/structure/machinery/power/geothermal/process()
if(!is_on || buildstate || !anchored) //Default logic checking
return 0

if(!powernet && !powernet_connection_failed) //Powernet checking, make sure there's valid cables & powernets
if(!connect_to_network())
powernet_connection_failed = 1 //God damn it, where'd our network go
is_on = 0
stop_processing()
// Error! Check again in 15 seconds. Someone could have blown/acided or snipped a cable
addtimer(VARSET_CALLBACK(src, powernet_connection_failed, FALSE), 15 SECONDS)
else if(powernet) //All good! Let's fire it up!
if(!check_failure()) //Wait! Check to see if it breaks during processing
update_icon()
if(power_gen_percent < 100) power_gen_percent++
switch(power_gen_percent)
if(10) visible_message("[icon2html(src, viewers(src))] [SPAN_NOTICE("<b>[src]</b> begins to whirr as it powers up.")]")
if(50) visible_message("[icon2html(src, viewers(src))] [SPAN_NOTICE("<b>[src]</b> begins to hum loudly as it reaches half capacity.")]")
if(99) visible_message("[icon2html(src, viewers(src))] [SPAN_NOTICE("<b>[src]</b> rumbles loudly as the combustion and thermal chambers reach full strength.")]")
add_avail(power_generation_max * (power_gen_percent / 100) ) //Nope, all good, just add the power

/obj/structure/machinery/power/geothermal/proc/check_failure()
cur_tick++
if(cur_tick < fail_check_ticks) //Nope, not time for it yet
return 0
else if(cur_tick > fail_check_ticks) //Went past with no fail, reset the timer
cur_tick = 0
if(rand(1,100) < fail_rate) //Oh snap, we failed! Shut it down!
if(rand(0,3) == 0)
visible_message("[icon2html(src, viewers(src))] [SPAN_NOTICE("<b>[src]</b> beeps wildly and a fuse blows! Use wirecutters, then a wrench to repair it.")]")
buildstate = 2
icon_state = "wire"
else
visible_message("[icon2html(src, viewers(src))] [SPAN_NOTICE("<b>[src]</b> beeps wildly and sprays random pieces everywhere! Use a wrench to repair it.")]")
buildstate = 3
icon_state = "wrench"
is_on = 0
power_gen_percent = 0
update_icon()
cur_tick = 0
stop_processing()
return 1
return 0 //Nope, all fine

/obj/structure/machinery/power/geothermal/attack_hand(mob/user as mob)
if(!anchored) return 0 //Shouldn't actually be possible
if(user.is_mob_incapacitated()) return 0
if(!ishuman(user))
to_chat(user, SPAN_DANGER("You have no idea how to use that.")) //No xenos or mankeys
return 0

add_fingerprint(user)

if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no clue how this thing works..."))
return 0

if(buildstate == 1)
to_chat(usr, SPAN_INFO("Use a blowtorch, then wirecutters, then wrench to repair it."))
return 0
else if (buildstate == 2)
to_chat(usr, SPAN_INFO("Use a wirecutters, then wrench to repair it."))
return 0
else if (buildstate == 3)
to_chat(usr, SPAN_INFO("Use a wrench to repair it."))
return 0
if(is_on)
visible_message("[icon2html(src, viewers(src))] [SPAN_WARNING("<b>[src]</b> beeps softly and the humming stops as [usr] shuts off the turbines.")]")
is_on = 0
power_gen_percent = 0
cur_tick = 0
icon_state = "off"
stop_processing()
return 1
visible_message("[icon2html(src, viewers(src))] [SPAN_WARNING("<b>[src]</b> beeps loudly as [usr] turns on the turbines and the generator begins spinning up.")]")
icon_state = "on10"
is_on = 1
cur_tick = 0
start_processing()
return 1

/obj/structure/machinery/power/geothermal/attackby(obj/item/O as obj, mob/user as mob)
if(iswelder(O))
if(!HAS_TRAIT(O, TRAIT_TOOL_BLOWTORCH))
to_chat(user, SPAN_WARNING("You need a stronger blowtorch!"))
return
if(buildstate == 1 && !is_on)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no clue how to repair this thing."))
return 0
var/obj/item/tool/weldingtool/WT = O
if(WT.remove_fuel(1, user))

playsound(loc, 'sound/items/weldingtool_weld.ogg', 25)
user.visible_message(SPAN_NOTICE("[user] starts welding [src]'s internal damage."),
SPAN_NOTICE("You start welding [src]'s internal damage."))
if(do_after(user, 200 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
if(buildstate != 1 || is_on || !WT.isOn())
return FALSE
playsound(loc, 'sound/items/Welder2.ogg', 25, 1)
buildstate = 2
user.visible_message(SPAN_NOTICE("[user] welds [src]'s internal damage."),
SPAN_NOTICE("You weld [src]'s internal damage."))
update_icon()
return TRUE
else
to_chat(user, SPAN_WARNING("You need more welding fuel to complete this task."))
return
else if(HAS_TRAIT(O, TRAIT_TOOL_WIRECUTTERS))
if(buildstate == 2 && !is_on)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no clue how to repair this thing."))
return 0
playsound(loc, 'sound/items/Wirecutter.ogg', 25, 1)
user.visible_message(SPAN_NOTICE("[user] starts securing [src]'s wiring."),
SPAN_NOTICE("You start securing [src]'s wiring."))
if(do_after(user, 120 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD, numticks = 12))
if(buildstate != 2 || is_on)
return FALSE
playsound(loc, 'sound/items/Wirecutter.ogg', 25, 1)
buildstate = 3
user.visible_message(SPAN_NOTICE("[user] secures [src]'s wiring."),
SPAN_NOTICE("You secure [src]'s wiring."))
update_icon()
return TRUE
else if(HAS_TRAIT(O, TRAIT_TOOL_WRENCH))
if(buildstate == 3 && !is_on)
if(!skillcheck(user, SKILL_ENGINEER, SKILL_ENGINEER_ENGI))
to_chat(user, SPAN_WARNING("You have no clue how to repair this thing."))
return 0
playsound(loc, 'sound/items/Ratchet.ogg', 25, 1)
user.visible_message(SPAN_NOTICE("[user] starts repairing [src]'s tubing and plating."),
SPAN_NOTICE("You start repairing [src]'s tubing and plating."))
if(do_after(user, 150 * user.get_skill_duration_multiplier(SKILL_ENGINEER), INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
if(buildstate != 3 || is_on)
return FALSE
playsound(loc, 'sound/items/Ratchet.ogg', 25, 1)
buildstate = 0
user.count_niche_stat(STATISTICS_NICHE_REPAIR_GENERATOR)
user.visible_message(SPAN_NOTICE("[user] repairs [src]'s tubing and plating."),
SPAN_NOTICE("You repair [src]'s tubing and plating."))
update_icon()
return TRUE
else
return ..() //Deal with everything else, like hitting with stuff

/obj/structure/machinery/power/geothermal/ex_act(severity, direction)
return FALSE //gameplay-wise these should really never go away

//Putting these here since it's power-related
/obj/structure/machinery/colony_floodlight_switch
name = "Colony Floodlight Switch"
Expand Down
Loading
Loading