Skip to content

Commit

Permalink
Adjacency Dispense proc, chem machines code cleanup, and Suit Storage…
Browse files Browse the repository at this point in the history
… Unit fixes (#10023)

* try_put_in_hand

* suit update

* tgstation/tgstation#49126

* update_appearance

* whitespace guhh

* Requested changes
  • Loading branch information
Tsar-Salat authored Oct 27, 2023
1 parent a72759e commit 503567d
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 91 deletions.
14 changes: 14 additions & 0 deletions code/game/machinery/_machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ Class Procs:
if(occupant == movable_atom)
occupant = null

/**
* Puts passed object in to user's hand
*
* Puts the passed object in to the users hand if they are adjacent.
* If the user is not adjacent then place the object on top of the machine.
*
* Vars:
* * object (obj) The object to be moved in to the users hand.
* * user (mob/living) The user to recive the object
*/
/obj/machinery/proc/try_put_in_hand(obj/object, mob/living/user)
if(!user.CanReach(src) || !user.put_in_hands(object))
object.forceMove(drop_location())

/obj/machinery/proc/can_be_occupant(atom/movable/am)
return occupant_typecache ? is_type_in_typecache(am, occupant_typecache) : isliving(am)

Expand Down
10 changes: 6 additions & 4 deletions code/game/machinery/suit_storage_unit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
src,
choices,
custom_check = CALLBACK(src, PROC_REF(check_interactable), user),
require_near = !issiliconoradminghost(user),
)

if (!choice)
Expand Down Expand Up @@ -326,14 +327,15 @@
var/obj/item/item_to_dispense = vars[choice]
if (item_to_dispense)
vars[choice] = null
user.put_in_hands(item_to_dispense)
try_put_in_hand(item_to_dispense, user)
else
var/obj/item/in_hands = user.get_active_held_item()
if (in_hands)
attackby(in_hands, user)

interact(user)

/obj/machinery/suit_storage_unit/proc/check_interactable(mob/user)
if (state_open && !powered())
return FALSE

if (!state_open && !can_interact(user))
return FALSE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
anchored = TRUE //Prevent movement
pixel_x = new_port.pixel_x
pixel_y = new_port.pixel_y
update_icon()

update_appearance()
return TRUE

/obj/machinery/portable_atmospherics/Move()
Expand All @@ -86,14 +87,16 @@
connected_port = null
pixel_x = 0
pixel_y = 0
update_icon()

update_appearance()
return TRUE

/obj/machinery/portable_atmospherics/portableConnectorReturnAir()
return air_contents

/obj/machinery/portable_atmospherics/AltClick(mob/living/user)
if(!istype(user) || !user.canUseTopic(src, BE_CLOSE, !ismonkey(user)))
. = ..()
if(!istype(user) || !user.canUseTopic(src, BE_CLOSE, !ismonkey(user)) || !can_interact(user))
return
if(holding)
to_chat(user, "<span class='notice'>You remove [holding] from [src].</span>")
Expand All @@ -106,15 +109,14 @@
"<span class='notice'>Click [src] with another gas tank to hot swap [holding].</span>"

/obj/machinery/portable_atmospherics/proc/replace_tank(mob/living/user, close_valve, obj/item/tank/new_tank)
if(!user)
return FALSE
if(holding)
holding.forceMove(drop_location())
if(Adjacent(user) && !issiliconoradminghost(user))
user.put_in_hands(holding)
user.put_in_hands(holding)
holding = null
if(new_tank)
holding = new_tank
else
holding = null
update_icon()
update_appearance()
return TRUE

/obj/machinery/portable_atmospherics/attackby(obj/item/W, mob/user, params)
Expand All @@ -126,7 +128,7 @@
to_chat(user, "<span class='notice'>[holding ? "In one smooth motion you pop [holding] out of [src]'s connector and replace it with [T]" : "You insert [T] into [src]"].</span>")
investigate_log("had its internal [holding] swapped with [T] by [key_name(user)].", INVESTIGATE_ATMOS)
replace_tank(user, FALSE, T)
update_icon()
update_appearance()
else if(W.tool_behaviour == TOOL_WRENCH)
if(!(machine_stat & BROKEN))
if(connected_port)
Expand All @@ -137,7 +139,7 @@
"[user] disconnects [src].", \
"<span class='notice'>You unfasten [src] from the port.</span>", \
"<span class='italics'>You hear a ratchet.</span>")
update_icon()
update_appearance()
return
else
var/obj/machinery/atmospherics/components/unary/portables_connector/possible_port = locate(/obj/machinery/atmospherics/components/unary/portables_connector) in loc
Expand All @@ -152,7 +154,7 @@
"[user] connects [src].", \
"<span class='notice'>You fasten [src] to the port.</span>", \
"<span class='italics'>You hear a ratchet.</span>")
update_icon()
update_appearance()
investigate_log("was connected to [possible_port] by [key_name(user)].", INVESTIGATE_ATMOS)
else
return ..()
Expand Down
39 changes: 23 additions & 16 deletions code/modules/reagents/chemistry/machinery/chem_dispenser.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
density = TRUE
icon = 'icons/obj/chemical.dmi'
icon_state = "dispenser"
base_icon_state = "dispenser"
use_power = IDLE_POWER_USE
idle_power_usage = 40
interaction_flags_machine = INTERACT_MACHINE_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OFFLINE
Expand Down Expand Up @@ -90,7 +91,7 @@
emagged_reagents = sort_list(emagged_reagents, GLOBAL_PROC_REF(cmp_reagents_asc))
if(upgrade_reagents)
upgrade_reagents = sort_list(upgrade_reagents, GLOBAL_PROC_REF(cmp_reagents_asc))
update_icon()
update_appearance()

/obj/machinery/chem_dispenser/Destroy()
QDEL_NULL(beaker)
Expand Down Expand Up @@ -127,14 +128,18 @@
if(working_state)
flick(working_state,src)

/obj/machinery/chem_dispenser/update_icon()
cut_overlays()
/obj/machinery/chem_dispenser/update_icon_state()
icon_state = "[(nopower_state && !powered()) ? nopower_state : base_icon_state]"
return ..()

/obj/machinery/chem_dispenser/update_overlays()
. = ..()
if(has_panel_overlay && panel_open)
add_overlay(mutable_appearance(icon, "[initial(icon_state)]_panel-o"))
. += mutable_appearance(icon, "[base_icon_state]_panel-o")

if(beaker)
beaker_overlay = display_beaker()
add_overlay(beaker_overlay)
. += beaker_overlay

/obj/machinery/chem_dispenser/on_emag(mob/user)
..()
Expand Down Expand Up @@ -330,7 +335,7 @@
if(default_unfasten_wrench(user, I))
return
if(default_deconstruction_screwdriver(user, icon_state, icon_state, I))
update_icon()
update_appearance()
return
if(default_deconstruction_crowbar(I))
return
Expand All @@ -342,7 +347,6 @@
replace_beaker(user, B)
to_chat(user, "<span class='notice'>You add [B] to [src].</span>")
updateUsrDialog()
update_icon()
else if(user.a_intent != INTENT_HARM && !istype(I, /obj/item/card/emag) && !istype(I, /obj/item/stock_parts/cell))
to_chat(user, "<span class='warning'>You can't load [I] into [src]!</span>")
return ..()
Expand Down Expand Up @@ -387,15 +391,14 @@
powerefficiency = round(newpowereff, 0.01)

/obj/machinery/chem_dispenser/proc/replace_beaker(mob/living/user, obj/item/reagent_containers/new_beaker)
if(!user)
return FALSE
if(beaker)
beaker.forceMove(drop_location())
if(user && Adjacent(user) && !issiliconoradminghost(user))
user.put_in_hands(beaker)
try_put_in_hand(beaker, user)
beaker = null
if(new_beaker)
beaker = new_beaker
else
beaker = null
update_icon()
update_appearance()
return TRUE

/obj/machinery/chem_dispenser/on_deconstruction()
Expand All @@ -407,8 +410,9 @@

/obj/machinery/chem_dispenser/AltClick(mob/living/user)
. = ..()
if(istype(user) && user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK))
replace_beaker(user)
if(!can_interact(user) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK))
return
replace_beaker(user)

/obj/machinery/chem_dispenser/drinks/Initialize(mapload)
. = ..()
Expand All @@ -418,7 +422,7 @@
var/old = dir
. = ..()
if(dir != old)
update_icon() // the beaker needs to be re-positioned if we rotate
update_appearance() // the beaker needs to be re-positioned if we rotate

/obj/machinery/chem_dispenser/drinks/display_beaker()
var/mutable_appearance/b_o = beaker_overlay || mutable_appearance(icon, "disp_beaker")
Expand All @@ -442,6 +446,7 @@
desc = "Contains a large reservoir of soft drinks."
icon = 'icons/obj/chemical.dmi'
icon_state = "soda_dispenser"
base_icon_state = "soda_dispenser"
has_panel_overlay = FALSE
amount = 10
pixel_y = 6
Expand Down Expand Up @@ -498,6 +503,7 @@
desc = "Contains a large reservoir of the good stuff."
icon = 'icons/obj/chemical.dmi'
icon_state = "booze_dispenser"
base_icon_state = "booze_dispenser"
circuit = /obj/item/circuitboard/machine/chem_dispenser/drinks/beer
dispensable_reagents = list(
/datum/reagent/consumable/ethanol/beer,
Expand Down Expand Up @@ -608,6 +614,7 @@
desc = "Synthesizes a variety of reagents using proto-matter."
icon = 'icons/obj/abductor.dmi'
icon_state = "chem_dispenser"
base_icon_state = "chem_dispenser"
has_panel_overlay = FALSE
circuit = /obj/item/circuitboard/machine/chem_dispenser/abductor
working_state = null
Expand Down
31 changes: 13 additions & 18 deletions code/modules/reagents/chemistry/machinery/chem_heater.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
density = TRUE
icon = 'icons/obj/chemical.dmi'
icon_state = "mixer0b"
base_icon_state = "mixer"
use_power = IDLE_POWER_USE
idle_power_usage = 40
resistance_flags = FIRE_PROOF | ACID_PROOF
circuit = /obj/item/circuitboard/machine/chem_heater



var/obj/item/reagent_containers/beaker = null
var/target_temperature = 300
var/heater_coefficient = 0.05
Expand All @@ -23,32 +22,28 @@
. = ..()
if(A == beaker)
beaker = null
update_icon()
update_appearance()

/obj/machinery/chem_heater/update_icon()
if(beaker)
icon_state = "mixer1b"
else
icon_state = "mixer0b"
/obj/machinery/chem_heater/update_icon_state()
icon_state = "[base_icon_state][beaker ? 1 : 0]b"
return ..()

/obj/machinery/chem_heater/AltClick(mob/living/user)
if(!istype(user) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK))
. = ..()
if(!can_interact(user) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK))
return
replace_beaker(user)
ui_update()
return

/obj/machinery/chem_heater/proc/replace_beaker(mob/living/user, obj/item/reagent_containers/new_beaker)
if(!user)
return FALSE
if(beaker)
beaker.forceMove(drop_location())
if(user && Adjacent(user) && !issiliconoradminghost(user))
user.put_in_hands(beaker)
try_put_in_hand(beaker, user)
beaker = null
if(new_beaker)
beaker = new_beaker
else
beaker = null
on = FALSE
update_icon()
update_appearance()
return TRUE

/obj/machinery/chem_heater/RefreshParts()
Expand Down Expand Up @@ -86,7 +81,7 @@
replace_beaker(user, B)
to_chat(user, "<span class='notice'>You add [B] to [src].</span>")
ui_update()
update_icon()
update_appearance()
return
return ..()

Expand Down
Loading

0 comments on commit 503567d

Please sign in to comment.