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

[MIRROR] Change all machinery/attackby to use_tool #1696

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions code/game/machinery/CableLayer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
user.visible_message("\The [user] [!on?"dea":"a"]ctivates \the [src].", "You switch [src] [on? "on" : "off"]")
return TRUE

/obj/machinery/cablelayer/attackby(obj/item/O as obj, mob/user as mob)
/obj/machinery/cablelayer/use_tool(obj/item/O, mob/living/user, list/click_params)
if(istype(O, /obj/item/stack/cable_coil))

var/result = load_cable(O)
if(!result)
to_chat(user, SPAN_WARNING("\The [src]'s cable reel is full."))
else
to_chat(user, "You load [result] lengths of cable into [src].")
return
return TRUE

if(isWirecutter(O))
if(cable && cable.amount)
Expand All @@ -48,6 +47,8 @@
CC.amount = m
else
to_chat(usr, SPAN_WARNING("There's no more cable on the reel."))
return TRUE
return ..()

/obj/machinery/cablelayer/examine(mob/user)
. = ..()
Expand Down
18 changes: 9 additions & 9 deletions code/game/machinery/Sleeper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@
updateUsrDialog()
go_out()

/obj/machinery/sleeper/attackby(obj/item/I, mob/user)
/obj/machinery/sleeper/use_tool(obj/item/I, mob/living/user, list/click_params)
if(istype(I, /obj/item/reagent_containers/glass))
add_fingerprint(user)
if(!beaker)
if(!user.unEquip(I, src))
return
beaker = I
user.visible_message(SPAN_NOTICE("\The [user] adds \a [I] to \the [src]."), SPAN_NOTICE("You add \a [I] to \the [src]."))
else
to_chat(user, SPAN_WARNING("\The [src] has a beaker already."))
if(beaker)
to_chat(user, SPAN_WARNING("There is already a beaker loaded in \the [src]."))
return TRUE
if(!user.unEquip(I, src))
return TRUE
beaker = I
user.visible_message(SPAN_NOTICE("\The [user] adds \a [I] to \the [src]."), SPAN_NOTICE("You add \a [I] to \the [src]."))
return TRUE

return ..()

/obj/machinery/sleeper/user_can_move_target_inside(mob/target, mob/user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@
machine.attack_hand(user)
return TRUE

/*
This returning FALSE means if component_attackby under use_tool called this it will also return FALSE; which means the use_tool call will proceed.
In that same vein, the attackby() children of this proc will also continue the rest of its code if this crashes; since this check is called at the beginning.
*/
/singleton/machine_construction/proc/attackby(obj/item/I, mob/user, obj/machinery/machine)
if(!validate_state(machine))
crash_with("Machine [log_info_line(machine)] violated the state assumptions of the construction state [type]!")
machine.attackby(I, user)
return TRUE
return FALSE

/singleton/machine_construction/proc/mechanics_info()

Expand Down
3 changes: 2 additions & 1 deletion code/game/machinery/_machines_base/machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@


/obj/machinery/post_anchor_change()
..()
update_use_power(anchored)
power_change()
..()

/**
* Called by machines that can hold a mob (sleeper, suit cycler, etc.), checking if mob can be moved before doing so.
Expand Down
15 changes: 12 additions & 3 deletions code/game/machinery/_machines_base/machinery_components.dm
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,23 @@ GLOBAL_LIST_INIT(machine_path_to_circuit_type, cache_circuits_by_build_path())
/// Called whenever an attached component updates it's status. Override to handle updates to the machine.
/obj/machinery/proc/component_stat_change(obj/item/stock_parts/part, old_stat, flag)

/obj/machinery/attackby(obj/item/I, mob/user)
if(component_attackby(I, user))
/obj/machinery/use_tool(obj/item/tool, mob/living/user, list/click_params)
if (component_attackby(tool, user))
return TRUE
return ..()

/obj/machinery/can_anchor(obj/item/tool, mob/user, silent)
if (use_power == POWER_USE_ACTIVE)
if (!silent)
to_chat(user, SPAN_WARNING("Turn \the [src] off first!"))
return FALSE
return ..()


/obj/machinery/post_anchor_change()
update_use_power(anchored)
power_change()
return ..()
..()

/// Passes `attackby()` calls through to components within the machine, if they are accessible.
/obj/machinery/proc/component_attackby(obj/item/I, mob/user)
Expand Down
118 changes: 68 additions & 50 deletions code/game/machinery/alarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -808,71 +808,74 @@
apply_mode()
return TOPIC_REFRESH

/obj/machinery/alarm/attackby(obj/item/W as obj, mob/user as mob)
/obj/machinery/alarm/use_tool(obj/item/W, mob/living/user, list/click_params)
switch(buildstage)
if(2)
if(isScrewdriver(W)) // Opening that Air Alarm up.
// to_chat(user, "You pop the Air Alarm's maintence panel open.")
if (isScrewdriver(W))
wiresexposed = !wiresexposed
to_chat(user, "The wires have been [wiresexposed ? "exposed" : "unexposed"]")
update_icon()
return
return TRUE

if (wiresexposed && isWirecutter(W))
user.visible_message(SPAN_WARNING("[user] has cut the wires inside \the [src]!"), "You have cut the wires inside \the [src].")
playsound(src.loc, 'sound/items/Wirecutter.ogg', 50, 1)
new/obj/item/stack/cable_coil(get_turf(src), 5)
buildstage = 1
update_icon()
return
return TRUE

if (istype(W, /obj/item/card/id) || istype(W, /obj/item/modular_computer))// trying to unlock the interface with an ID card
if (isid(W) || istype(W, /obj/item/modular_computer))
if(inoperable())
to_chat(user, "It does nothing")
return
return TRUE
if(allowed(usr) && !wires.IsIndexCut(AALARM_WIRE_IDSCAN))
locked = !locked
to_chat(user, SPAN_NOTICE("You [ locked ? "lock" : "unlock"] the Air Alarm interface."))
else
if(allowed(usr) && !wires.IsIndexCut(AALARM_WIRE_IDSCAN))
locked = !locked
to_chat(user, SPAN_NOTICE("You [ locked ? "lock" : "unlock"] the Air Alarm interface."))
else
to_chat(user, SPAN_WARNING("Access denied."))
return
to_chat(user, SPAN_WARNING("Access denied."))
return TRUE

if(1)
if(isCoil(W))
if (isCoil(W))
var/obj/item/stack/cable_coil/C = W
if (C.use(5))
to_chat(user, SPAN_NOTICE("You wire \the [src]."))
buildstage = 2
update_icon()
return
return TRUE
else
to_chat(user, SPAN_WARNING("You need 5 pieces of cable to do wire \the [src]."))
return
return TRUE

else if(isCrowbar(W))
if (isCrowbar(W))
to_chat(user, "You start prying out the circuit.")
playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1)
if(do_after(user, (W.toolspeed * 2) SECONDS, src, DO_REPAIR_CONSTRUCT) && buildstage == 1)
to_chat(user, "You pry out the circuit!")
var/obj/item/airalarm_electronics/circuit = new /obj/item/airalarm_electronics()
circuit.dropInto(user.loc)
buildstage = 0
update_icon()
return
if (!do_after(user, (W.toolspeed * 2) SECONDS, src, DO_REPAIR_CONSTRUCT))
return TRUE

to_chat(user, "You pry out the circuit!")
var/obj/item/airalarm_electronics/circuit = new /obj/item/airalarm_electronics()
circuit.dropInto(user.loc)
buildstage = 0
update_icon()
return TRUE

if(0)
if(istype(W, /obj/item/airalarm_electronics))
if (istype(W, /obj/item/airalarm_electronics))
to_chat(user, "You insert the circuit!")
qdel(W)
buildstage = 1
update_icon()
return
return TRUE

else if(isWrench(W))
if (isWrench(W))
to_chat(user, "You remove the fire alarm assembly from the wall!")
new /obj/item/frame/air_alarm(get_turf(user))
var/obj/item/frame/air_alarm/frame = new /obj/item/frame/air_alarm(get_turf(user))
transfer_fingerprints_to(frame)
playsound(src.loc, 'sound/items/Ratchet.ogg', 50, 1)
qdel(src)
return TRUE

return ..()

Expand Down Expand Up @@ -988,63 +991,78 @@ FIRE ALARM
alarm(rand(30/severity, 60/severity))
..()

/obj/machinery/firealarm/attackby(obj/item/W as obj, mob/user as mob)
/obj/machinery/firealarm/use_tool(obj/item/W, mob/living/user, list/click_params)
if ((. = ..()))
return

if(isScrewdriver(W) && buildstage == 2)
wiresexposed = !wiresexposed
update_icon()
return
return TRUE

if(wiresexposed)
switch(buildstage)
if(2)
if(isMultitool(W))
src.detecting = !( src.detecting )
if (src.detecting)
user.visible_message(SPAN_NOTICE("\The [user] has reconnected [src]'s detecting unit!"), SPAN_NOTICE("You have reconnected [src]'s detecting unit."))
else
user.visible_message(SPAN_NOTICE("\The [user] has disconnected [src]'s detecting unit!"), SPAN_NOTICE("You have disconnected [src]'s detecting unit."))
else if(isWirecutter(W))
user.visible_message(SPAN_NOTICE("\The [user] has cut the wires inside \the [src]!"), SPAN_NOTICE("You have cut the wires inside \the [src]."))
detecting = !detecting
user.visible_message(
SPAN_NOTICE("\The [user] has [detecting? "re" : "dis"]connected \the [src]'s detecting unit!"),
SPAN_NOTICE("You have [detecting? "re" : "dis"]connected \the [src]'s detecting unit.")
)
return TRUE

if (isWirecutter(W))
user.visible_message(
SPAN_NOTICE("\The [user] has cut the wires inside \the [src]!"),
SPAN_NOTICE("You have cut the wires inside \the [src].")
)
new/obj/item/stack/cable_coil(get_turf(src), 5)
playsound(src.loc, 'sound/items/Wirecutter.ogg', 50, 1)
buildstage = 1
update_icon()
return TRUE

if(1)
if(istype(W, /obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C = W
if (C.use(5))
to_chat(user, SPAN_NOTICE("You wire \the [src]."))
buildstage = 2
update_icon()
return
return TRUE
else
to_chat(user, SPAN_WARNING("You need 5 pieces of cable to wire \the [src]."))
return
else if(isCrowbar(W))
return TRUE
if(isCrowbar(W))
to_chat(user, "You start prying out the circuit.")
playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1)
if (do_after(user, (W.toolspeed * 2) SECONDS, src, DO_REPAIR_CONSTRUCT))
to_chat(user, "You pry out the circuit!")
var/obj/item/firealarm_electronics/circuit = new /obj/item/firealarm_electronics()
circuit.dropInto(user.loc)
buildstage = 0
update_icon()
if (!do_after(user, (W.toolspeed * 2) SECONDS, src, DO_REPAIR_CONSTRUCT))
return TRUE

to_chat(user, "You pry out the circuit!")
var/obj/item/firealarm_electronics/circuit = new /obj/item/firealarm_electronics()
circuit.dropInto(user.loc)
buildstage = 0
update_icon()
return TRUE
if(0)
if(istype(W, /obj/item/firealarm_electronics))
to_chat(user, "You insert the circuit!")
qdel(W)
buildstage = 1
update_icon()
return TRUE

else if(isWrench(W))
if (isWrench(W))
to_chat(user, "You remove the fire alarm assembly from the wall!")
new /obj/item/frame/fire_alarm(get_turf(user))
playsound(src.loc, 'sound/items/Ratchet.ogg', 50, 1)
qdel(src)
return
return TRUE

src.alarm()
return
to_chat(user, SPAN_WARNING("You fumble with \the [W] and trigger the alarm!"))
alarm()
return TRUE

/obj/machinery/firealarm/Process()//Note: this processing was mostly phased out due to other code, and only runs when needed
if(inoperable())
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/atmoalter/canister.dm
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
return GM.return_pressure()
return 0

/obj/machinery/portable_atmospherics/canister/attackby(obj/item/W as obj, mob/user as mob)
/obj/machinery/portable_atmospherics/canister/use_tool(obj/item/W, mob/living/user, list/click_params)
if(istype(user, /mob/living/silicon/robot) && istype(W, /obj/item/tank/jetpack))
var/datum/gas_mixture/thejetpack = W:air_contents
var/env_pressure = thejetpack.return_pressure()
Expand Down
26 changes: 12 additions & 14 deletions code/game/machinery/atmoalter/portable_atmospherics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -103,38 +103,36 @@
if (network)
network.update = 1

/obj/machinery/portable_atmospherics/attackby(obj/item/W as obj, mob/user as mob)
if ((istype(W, /obj/item/tank) && !( src.destroyed )))
if (src.holding)
/obj/machinery/portable_atmospherics/use_tool(obj/item/W, mob/living/user, list/click_params)
if ((istype(W, /obj/item/tank) && !destroyed))
if (holding)
to_chat(user, SPAN_WARNING("\The [src] already contains a tank!"))
return
if(!user.unEquip(W, src))
return
src.holding = W
return TRUE
holding = W
update_icon()
return
return TRUE

else if(isWrench(W))
if(isWrench(W))
if(connected_port)
disconnect()
to_chat(user, SPAN_NOTICE("You disconnect \the [src] from the port."))
update_icon()
return
return TRUE
else
var/obj/machinery/atmospherics/portables_connector/possible_port = locate(/obj/machinery/atmospherics/portables_connector) in loc
if(possible_port)
if(connect(possible_port))
to_chat(user, SPAN_NOTICE("You connect \the [src] to the port."))
update_icon()
return
return TRUE
else
to_chat(user, SPAN_NOTICE("\The [src] failed to connect to the port."))
return
return TRUE
else
to_chat(user, SPAN_NOTICE("Nothing happens."))
return ..()

else if (istype(W, /obj/item/device/scanner/gas))
return
return TRUE

return ..()

Expand Down
Loading