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

improves chem dispenser sprites #375

Closed
wants to merge 1 commit into from
Closed
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
153 changes: 105 additions & 48 deletions code/modules/reagents/machinery/dispenser/dispenser2.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

var/ui_title = "Chemical Dispenser"

var/accept_drinking = 0
var/accept_drinking = FALSE
var/amount = 30

use_power = USE_POWER_IDLE
idle_power_usage = 100
idle_power_usage = 0.1 KILOWATTS
anchored = TRUE
unacidable = TRUE

Expand All @@ -29,6 +29,44 @@
/obj/machinery/chemical_dispenser/examine(mob/user)
. = ..()
. += "It has [cartridges.len] cartridges installed, and has space for [DISPENSER_MAX_CARTRIDGES - cartridges.len] more."
. += "Use a crowbar to retrieve installed cartridges"

/obj/machinery/chemical_dispenser/update_icon()
if(accept_drinking) //drink dispensors don't have fancy sprites, so this is a very handy checker
icon_state = initial(icon_state) //just in case some weirdness happens I guess.
return

cut_overlays()
icon_state = initial(icon_state)
if(panel_open)
add_overlay("[initial(icon_state)]_panel-o")
if(container)
icon_state = "[initial(icon_state)]_working"
if(istype(container, /obj/item/weapon/reagent_containers/glass/beaker/bluespace))
add_overlay("[initial(icon_state)]_bsbeaker")
else if(istype(container, /obj/item/weapon/reagent_containers/glass/beaker/noreact))
add_overlay("[initial(icon_state)]_nrbeaker")
else //the only see-through one gets filling updates, and we can only do glass and subtypes of glass anyway.
var/obj/item/weapon/reagent_containers/glass/C = container
if(C.reagents && C.reagents.total_volume)
var/mutable_appearance/filling = mutable_appearance('icons/obj/reagentfillings.dmi', "[initial(icon_state)]_1")
var/percent = round((C.reagents.total_volume / C.volume) * 100)
switch(percent)
if(0 to 35) filling.icon_state = "[initial(icon_state)]_1"
if(36 to 74) filling.icon_state = "[initial(icon_state)]_5"
if(75 to INFINITY) filling.icon_state = "[initial(icon_state)]_10"
filling.color = C.reagents.get_color()
//Add our filling, if any.
add_overlay(filling)
//Then overlay the beaker atop of the filling, so it appears behind it.
add_overlay("[initial(icon_state)]_beaker")

if(stat & NOPOWER)
icon_state = "[initial(icon_state)]_nopower"

if(stat & BROKEN)
icon_state = "[initial(icon_state)]_broken"
return

/obj/machinery/chemical_dispenser/verb/rotate_clockwise()
set name = "Rotate Dispenser Clockwise"
Expand All @@ -37,36 +75,36 @@

if (src.anchored || usr:stat)
to_chat(usr, "It is fastened down!")
return 0
return FALSE
src.set_dir(turn(src.dir, 270))
return 1
return TRUE

/obj/machinery/chemical_dispenser/proc/add_cartridge(obj/item/weapon/reagent_containers/chem_disp_cartridge/C, mob/user)
if(!istype(C))
if(user)
to_chat(user, "<span class='warning'>\The [C] will not fit in \the [src]!</span>")
to_chat(user, span_warning("[C] will not fit in [src]!"))
return

if(cartridges.len >= DISPENSER_MAX_CARTRIDGES)
if(user)
to_chat(user, "<span class='warning'>\The [src] does not have any slots open for \the [C] to fit into!</span>")
to_chat(user, span_warning("[src] does not have any slots open for [C] to fit into!"))
return

if(!C.label)
if(user)
to_chat(user, "<span class='warning'>\The [C] does not have a label!</span>")
to_chat(user, span_warning("[C] does not have a label!"))
return

if(cartridges[C.label])
if(user)
to_chat(user, "<span class='warning'>\The [src] already contains a cartridge with that label!</span>")
to_chat(user, span_warning("[src] already contains a cartridge with that label!"))
return

if(user)
user.drop_from_inventory(C)
to_chat(user, "<span class='notice'>You add \the [C] to \the [src].</span>")
user.drop_from_inventory(C, src)
to_chat(user, span_notice("You add [C] to [src]."))

C.loc = src
C.forceMove(src)
cartridges[C.label] = C
cartridges = sortAssoc(cartridges)
SStgui.update_uis(src)
Expand All @@ -77,52 +115,74 @@
SStgui.update_uis(src)

/obj/machinery/chemical_dispenser/attackby(obj/item/weapon/W, mob/user)
if(W.is_wrench())
playsound(src, W.usesound, 50, 1)
to_chat(user, "<span class='notice'>You begin to [anchored ? "un" : ""]fasten \the [src].</span>")
if (do_after(user, 20 * W.toolspeed))
user.visible_message(
"<span class='notice'>\The [user] [anchored ? "un" : ""]fastens \the [src].</span>",
"<span class='notice'>You have [anchored ? "un" : ""]fastened \the [src].</span>",
"You hear a ratchet.")
anchored = !anchored
else
to_chat(user, "<span class='notice'>You decide not to [anchored ? "un" : ""]fasten \the [src].</span>")
if(default_unfasten_wrench(user, W, 5 SECONDS))
return

else if(istype(W, /obj/item/weapon/reagent_containers/chem_disp_cartridge))
if(istype(W, /obj/item/weapon/reagent_containers/chem_disp_cartridge))
if(!panel_open)
to_chat(user, span_notice("You need to open the access hatch first!"))
return
add_cartridge(W, user)

else if(W.is_screwdriver())
var/label = tgui_input_list(user, "Which cartridge would you like to remove?", "Chemical Dispenser", cartridges)
if(!label) return
var/obj/item/weapon/reagent_containers/chem_disp_cartridge/C = remove_cartridge(label)
if(C)
to_chat(user, "<span class='notice'>You remove \the [C] from \the [src].</span>")
C.loc = loc
playsound(src, W.usesound, 50, 1)

else if(istype(W, /obj/item/weapon/reagent_containers/glass) || istype(W, /obj/item/weapon/reagent_containers/food))
if(istype(W, /obj/item/weapon/reagent_containers/glass) || istype(W, /obj/item/weapon/reagent_containers/food))
if(container)
to_chat(user, "<span class='warning'>There is already \a [container] on \the [src]!</span>")
to_chat(user, span_warning("There is already \a [container] on [src]!"))
return

var/obj/item/weapon/reagent_containers/RC = W

if(!accept_drinking && istype(RC,/obj/item/weapon/reagent_containers/food))
to_chat(user, "<span class='warning'>This machine only accepts beakers!</span>")
to_chat(user, span_warning("This machine only accepts beakers!"))
return

if(!RC.is_open_container())
to_chat(user, "<span class='warning'>You don't see how \the [src] could dispense reagents into \the [RC].</span>")
to_chat(user, span_warning("You don't see how [src] could dispense reagents into [RC] with the lid on."))
return

container = RC
user.drop_from_inventory(RC)
RC.loc = src
to_chat(user, "<span class='notice'>You set \the [RC] on \the [src].</span>")
replace_container(user, RC)
to_chat(user, span_notice("You add [RC] to [src]."))
updateUsrDialog()
update_icon()

if(default_deconstruction_screwdriver(user, W))
update_icon()
return

if(panel_open)
if(W.has_tool_quality(TOOL_CROWBAR)) //I would make the deconstructable, but the cartridge system makes this... unwise.
var/label = tgui_input_list(user, "Which cartridge would you like to remove?", "Chemical Dispenser", cartridges)
if(!label) return
var/obj/item/weapon/reagent_containers/chem_disp_cartridge/C = remove_cartridge(label)
if(C)
to_chat(user, span_notice("You remove [C] from [src]."))
C.forceMove(get_turf(src))
playsound(src, W.usesound, 50, 1)

else
return ..()

/obj/machinery/chemical_dispenser/AltClick(mob/user)
if(container)
container.forceMove(get_turf(src))
if(Adjacent(usr)) // So the AI doesn't get a beaker somehow.
user.put_in_hands(container)
container = null
update_icon()

/obj/machinery/chemical_dispenser/proc/replace_container(mob/living/user, obj/item/weapon/reagent_containers/new_container)
if(container)
container.forceMove(drop_location())
if(user && Adjacent(user))
user.put_in_hands(container)
if(new_container)
if(user && Adjacent(user))
user.drop_from_inventory(new_container, src)
container = new_container
else
container = null
update_icon()
return TRUE

/obj/machinery/chemical_dispenser/tgui_interact(mob/user, datum/tgui/ui = null)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
Expand All @@ -134,7 +194,7 @@
data["amount"] = amount
data["isBeakerLoaded"] = container ? 1 : 0
data["glass"] = accept_drinking

var/beakerContents[0]
if(container && container.reagents && container.reagents.reagent_list.len)
for(var/datum/reagent/R in container.reagents.reagent_list)
Expand Down Expand Up @@ -169,6 +229,7 @@
var/obj/item/weapon/reagent_containers/chem_disp_cartridge/C = cartridges[label]
playsound(src, 'sound/machines/reagent_dispense.ogg', 25, 1)
C.reagents.trans_to(container, amount)
update_icon()
if("remove")
var/amount = text2num(params["amount"])
if(!container || !amount)
Expand All @@ -179,14 +240,10 @@
R.remove_reagent(id, amount)
else if(amount == -1) // Isolate
R.isolate_reagent(id)
update_icon()
if("ejectBeaker")
if(container)
container.forceMove(get_turf(src))

if(Adjacent(usr)) // So the AI doesn't get a beaker somehow.
usr.put_in_hands(container)

container = null
replace_container(usr)
. = TRUE //no afterattack
else
return FALSE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
desc = "A soda machine."
icon_state = "soda_dispenser"
ui_title = "Soda Dispenser"
accept_drinking = 1
accept_drinking = TRUE

/obj/machinery/chemical_dispenser/bar_soft/full
spawn_cartridges = list(
Expand Down Expand Up @@ -93,7 +93,7 @@
desc = "A beer machine. Like a soda machine, but more fun!"
icon_state = "booze_dispenser"
ui_title = "Booze Dispenser"
accept_drinking = 1
accept_drinking = TRUE

/obj/machinery/chemical_dispenser/bar_alc/full
spawn_cartridges = list(
Expand Down Expand Up @@ -125,7 +125,7 @@
desc = "Driving crack dealers out of employment since 2280."
icon_state = "coffee_dispenser"
ui_title = "Coffee Dispenser"
accept_drinking = 1
accept_drinking = TRUE

/obj/machinery/chemical_dispenser/bar_coffee/full
spawn_cartridges = list(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/obj/machinery/chemical_dispenser/xenoflora
name = "xenoflora chem dispenser"
icon_state = "minidispenser"
ui_title = "Xenoflora Chemical Dispenser"
dispense_reagents = list(
"water", "sugar", "ethanol", "radium", "ammonia", "diethylamine", "plantbgone", "mutagen", "calcium"
Expand All @@ -20,6 +21,7 @@

/obj/machinery/chemical_dispenser/biochemistry
name = "bioproduct dispenser"
icon_state = "minidispenser"
ui_title = "Bioproduct Dispenser"
dispense_reagents = list(
"nutriment", "protein", "milk"
Expand Down Expand Up @@ -70,4 +72,4 @@
name = "chemical dispenser"
icon = 'icons/obj/abductor_vr.dmi'
icon_state = "dispenser_2way"
desc = "A mysterious machine which can fabricate many chemicals."
desc = "A mysterious machine which can fabricate many chemicals."
Binary file modified icons/obj/chemical.dmi
Binary file not shown.
Binary file modified icons/obj/reagentfillings.dmi
Binary file not shown.
Loading