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

Refactors light switches, igniter switches, mass driver buttons, and crematoriums? #18683

Merged
merged 5 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 64 additions & 93 deletions code/game/machinery/buttons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@

/obj/machinery/driver_button
name = "mass driver button"
desc = "A remote control switch for a mass driver."
icon = 'icons/obj/objects.dmi'
icon_state = "launcherbtt"
desc = "A remote control switch for a mass driver."
var/id_tag = "default"
var/active = FALSE
settagwhitelist = list("id_tag", "logic_id_tag")
anchored = TRUE
armor = list(melee = 50, bullet = 50, laser = 50, energy = 50, bomb = 10, bio = 100, rad = 100, fire = 90, acid = 70)
use_power = IDLE_POWER_USE
idle_power_usage = 2
active_power_usage = 4
resistance_flags = LAVA_PROOF | FIRE_PROOF
/// ID tag of the driver to hook to
var/id_tag = "default"
/// Are we active?
var/active = FALSE
/// Range of drivers + blast doors to hit
var/range = 7
var/logic_id_tag = "default" //Defines the ID tag to send logic signals to, so you don't have to unlink from doors and stuff
var/logic_connect = FALSE //Set this to allow the button to send out logic signals when pressed in addition to normal stuff

/obj/machinery/button/indestructible
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF

/obj/machinery/driver_button/New(turf/loc, w_dir=null)
..()
switch(w_dir)
/obj/machinery/driver_button/Initialize(mapload, place_dir)
. = ..()
switch(place_dir)
if(NORTH)
pixel_y = 25
if(SOUTH)
Expand All @@ -35,122 +35,92 @@
pixel_x = 25
if(WEST)
pixel_x = -25
if(SSradio)
set_frequency(frequency)

/obj/machinery/driver_button/Initialize(mapload)
. = ..()
set_frequency(frequency)

/obj/machinery/driver_button/set_frequency(new_frequency)
SSradio.remove_object(src, frequency)
frequency = new_frequency
radio_connection = SSradio.add_object(src, frequency, RADIO_LOGIC)
return

/obj/machinery/driver_button/Destroy()
if(SSradio)
SSradio.remove_object(src, frequency)
radio_connection = null
return ..()


/obj/machinery/driver_button/attack_ai(mob/user as mob)
return attack_hand(user)
/obj/machinery/driver_button/attack_ai(mob/user)
attack_hand(user)

/obj/machinery/driver_button/attack_ghost(mob/user)
if(user.can_advanced_admin_interact())
return attack_hand(user)
attack_hand(user)

/obj/machinery/driver_button/attackby(obj/item/W, mob/user as mob, params)
/obj/machinery/driver_button/wrench_act(mob/user, obj/item/I)
. = TRUE

if(istype(W, /obj/item/detective_scanner))
if(!I.tool_use_check(user, 0))
return

if(istype(W, /obj/item/multitool))
update_multitool_menu(user)
return 1

if(istype(W, /obj/item/wrench))
playsound(get_turf(src), W.usesound, 50, 1)
if(do_after(user, 30 * W.toolspeed, target = src))
to_chat(user, "<span class='notice'>You detach \the [src] from the wall.</span>")
new/obj/item/mounted/frame/driver_button(get_turf(src))
qdel(src)
return 1

return ..()

/obj/machinery/driver_button/multitool_menu(mob/user, obj/item/multitool/P)
return {"
<ul>
<li><b>ID Tag:</b> [format_tag("ID Tag","id_tag","set_id")]</li>
<li><b>Logic Connection:</b> <a href='?src=[UID()];toggle_logic=1'>[logic_connect ? "On" : "Off"]</a></li>
<li><b>Logic ID Tag:</b> [format_tag("Logic ID Tag", "logic_id_tag")]</li>
</ul>"}
user.visible_message("<span class='notice'>[user] starts unwrenching [src] from the wall...</span>", "<span class='notice'>You are unwrenching [src] from the wall...</span>", "<span class='warning'>You hear ratcheting.</span>")
if(!I.use_tool(src, user, 30, volume = I.tool_volume))
AffectedArc07 marked this conversation as resolved.
Show resolved Hide resolved
return

/obj/machinery/driver_button/attack_hand(mob/user as mob)
WRENCH_UNANCHOR_WALL_MESSAGE
new/obj/item/mounted/frame/driver_button(get_turf(src))
qdel(src)

/obj/machinery/driver_button/attack_hand(mob/user)
add_fingerprint(usr)

if(stat & (NOPOWER|BROKEN))
return

if(active)
return

add_fingerprint(user)
AffectedArc07 marked this conversation as resolved.
Show resolved Hide resolved

use_power(5)

// Start us off
launch_sequence()

/obj/machinery/driver_button/proc/launch_sequence()
active = TRUE
icon_state = "launcheract"

if(logic_connect)
if(!radio_connection) //can't output without this
return

if(logic_id_tag == null) //Don't output to an undefined id_tag
return

var/datum/signal/signal = new
signal.transmission_method = 1 //radio signal
signal.source = src

signal.data = list(
"tag" = logic_id_tag,
"sigtype" = "logic",
"state" = LOGIC_FLICKER, //Buttons are a FLICKER source, since they only register as ON when you press it, then turn OFF after you release
)

radio_connection.post_signal(src, signal, filter = RADIO_LOGIC)
// Time sequence
// OPEN DOORS
// Wait 2 seconds
// LAUNCH
// Wait 5 seconds
// CLOSE
// Then make not active

for(var/obj/machinery/door/poddoor/M in range(src,range))
for(var/obj/machinery/door/poddoor/M in range(src, range))
if(M.id_tag == id_tag && !M.protected)
spawn()
M.open()
INVOKE_ASYNC(M, /obj/machinery/door.proc/open)

sleep(20)
// 2 seconds after previous invocation

for(var/obj/machinery/mass_driver/M in range(src,range))
for(var/obj/machinery/mass_driver/M in range(src, range))
if(M.id_tag == id_tag)
M.drive()
addtimer(CALLBACK(M, /obj/machinery/mass_driver.proc/drive), 2 SECONDS)

sleep(50)
// We want this 5 seconds after open, so the delay is 7 seconds from this proc

for(var/obj/machinery/door/poddoor/M in range(src,range))
for(var/obj/machinery/door/poddoor/M in range(src, range))
if(M.id_tag == id_tag && !M.protected)
spawn()
M.close()
return
addtimer(CALLBACK(M, /obj/machinery/door.proc/close), 7 SECONDS)

// And rearm us
addtimer(CALLBACK(src, .proc/rearm), 7 SECONDS)

/obj/machinery/driver_button/proc/rearm()
icon_state = "launcherbtt"
active = FALSE

/obj/machinery/driver_button/multitool_topic(mob/user, list/href_list, obj/O)
..()
if("toggle_logic" in href_list)
logic_connect = !logic_connect
/obj/machinery/driver_button/multitool_act(mob/user, obj/item/I)
. = TRUE
if(!I.use_tool(src, user, 0, volume = I.tool_volume))
return

if(!Adjacent(user))
return

var/new_tag = clean_input("Enter a new ID tag", "ID Tag", id_tag, user)

if(new_tag && Adjacent(user))
id_tag = new_tag


//////////////////////////////////////
// Ignition Switch //
Expand Down Expand Up @@ -178,6 +148,7 @@
/obj/machinery/ignition_switch/attack_hand(mob/user)
if(stat & (NOPOWER|BROKEN))
return

if(active)
return

Expand All @@ -188,16 +159,16 @@

for(var/obj/machinery/sparker/M in GLOB.machines)
if(M.id == id)
spawn( 0 )
M.spark()
INVOKE_ASYNC(M, /obj/machinery/sparker.proc/spark)

for(var/obj/machinery/igniter/M in GLOB.machines)
if(M.id == id)
use_power(50)
M.on = !( M.on )
M.icon_state = text("igniter[]", M.on)
M.on = !M.on
M.icon_state = "igniter[M.on]"

sleep(50)
addtimer(CALLBACK(src, .proc/rearm), 5 SECONDS)

/obj/machinery/ignition_switch/proc/rearm()
icon_state = "launcherbtt"
active = FALSE
57 changes: 28 additions & 29 deletions code/game/machinery/igniter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,36 @@
max_integrity = 300
armor = list(melee = 50, bullet = 30, laser = 70, energy = 50, bomb = 20, bio = 0, rad = 0, fire = 100, acid = 70)
resistance_flags = FIRE_PROOF
var/id = null
var/on = FALSE
anchored = TRUE
use_power = IDLE_POWER_USE
idle_power_usage = 2
active_power_usage = 4
/// ID to hook buttons into
var/id = null
/// Are we on?
var/on = FALSE

/obj/machinery/igniter/on
on = TRUE

/obj/machinery/igniter/attack_ai(mob/user as mob)
AffectedArc07 marked this conversation as resolved.
Show resolved Hide resolved
return src.attack_hand(user)

attack_hand(user)

/obj/machinery/igniter/attack_hand(mob/user as mob)
hal9000PR marked this conversation as resolved.
Show resolved Hide resolved
if(..())
return

add_fingerprint(user)

use_power(50)
on = !on
update_icon()

if(on)
set_light(1, 1, "#ff821c")
else
set_light(0)
return


/obj/machinery/igniter/update_icon_state()
. = ..()
Expand All @@ -51,12 +54,12 @@
if(on)
underlays += emissive_appearance(icon, "igniter_lightmask")

/obj/machinery/igniter/process() //ugh why is this even in process()?
if(src.on && !(stat & NOPOWER) )
var/turf/location = src.loc
/obj/machinery/igniter/process() //ugh why is this even in process()? // AA 2022-08-02 - I guess it cant go anywhere else?
if(on && !(stat & NOPOWER))
var/turf/location = get_turf(src)
if(isturf(location))
location.hotspot_expose(1000,500,1)
return 1
location.hotspot_expose(1000, 500, 1)
return TRUE

/obj/machinery/igniter/Initialize(mapload)
. = ..()
Expand Down Expand Up @@ -86,58 +89,54 @@
if(powered() && !disable)
stat &= ~NOPOWER
icon_state = "[base_state]"
// src.sd_set_light(2)
else
stat |= ~NOPOWER
icon_state = "[base_state]-p"
// src.sd_set_light(0)

/obj/machinery/sparker/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/detective_scanner))
return
return ..()

/obj/machinery/sparker/screwdriver_act(mob/user, obj/item/I)
. = TRUE
if(!I.use_tool(src, user, 0, volume = I.tool_volume))
return

disable = !disable

if(disable)
user.visible_message("<span class='warning'>[user] has disabled [src]!</span>", "<span class='warning'>You disable the connection to [src].</span>")
icon_state = "[base_state]-d"
if(!disable)
else
user.visible_message("<span class='warning'>[user] has reconnected [src]!</span>", "<span class='warning'>You fix the connection to [src].</span>")
if(powered())
icon_state = "[base_state]"
else
icon_state = "[base_state]-p"

/obj/machinery/sparker/attack_ai()
if(src.anchored)
return src.spark()
else
return
if(anchored)
return spark()


/obj/machinery/sparker/proc/spark()
if(!(powered()))
if(!powered())
return

if((src.disable) || (src.last_spark && world.time < src.last_spark + 50))
if(disable || (last_spark && world.time < last_spark + 50))
AffectedArc07 marked this conversation as resolved.
Show resolved Hide resolved
return


flick("[base_state]-spark", src)
do_sparks(2, 1, src)
src.last_spark = world.time
last_spark = world.time
use_power(1000)
var/turf/location = src.loc

var/turf/location = get_turf(src)
if(isturf(location))
location.hotspot_expose(1000,500,1)
return 1
location.hotspot_expose(1000, 500, 1)

return TRUE

/obj/machinery/sparker/emp_act(severity)
if(stat & (BROKEN|NOPOWER))
..(severity)
return

spark()
..(severity)
Loading