Skip to content

Commit

Permalink
Changes chem dispenser code (#3830)
Browse files Browse the repository at this point in the history
# About the pull request

Shuffled a bunch of stuff around

# Explain why it's good for the game

Makes it easier to add or remove reagents that are restricted to hacking
the dispenser

# Changelog

:cl:
code: Messed with chem and drink dispenser code
/:cl:

---------

Co-authored-by: harryob <[email protected]>
  • Loading branch information
BeagleGaming1 and harryob authored Jul 14, 2023
1 parent 9d7da19 commit 56ebd39
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 103 deletions.
203 changes: 116 additions & 87 deletions code/modules/reagents/chemistry_machinery/chem_dispenser.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#define DISPENSER_UNHACKABLE -1
#define DISPENSER_NOT_HACKED 0
#define DISPENSER_HACKED 1

/obj/structure/machinery/chem_dispenser
name = "chemical dispenser"
desc = "A complex machine for mixing elements into chemicals. A Wey-Yu product."
Expand All @@ -6,6 +10,7 @@
icon = 'icons/obj/structures/machinery/science_machines.dmi'
icon_state = "dispenser"
use_power = USE_POWER_NONE
wrenchable = FALSE
idle_power_usage = 40
layer = BELOW_OBJ_LAYER //So beakers reliably appear above it
var/req_skill = SKILL_MEDICAL
Expand All @@ -14,13 +19,37 @@
var/obj/structure/machinery/chem_storage/chem_storage
var/network = "Ground"
var/amount = 30
var/accept_glass = 0 //At 0 ONLY accepts glass containers. Kinda misleading varname.
var/accept_beaker_only = TRUE
var/obj/item/reagent_container/beaker = null
var/ui_check = 0
var/static/list/possible_transfer_amounts = list(5,10,20,30,40)
var/list/dispensable_reagents = list("hydrogen","lithium","carbon","nitrogen","oxygen","fluorine",
"sodium","aluminum","silicon","phosphorus","sulfur","chlorine","potassium","iron",
"copper","mercury","radium","water","ethanol","sugar","sulphuric acid")
var/list/dispensable_reagents = list(
"hydrogen",
"lithium",
"carbon",
"nitrogen",
"oxygen",
"fluorine",
"sodium",
"aluminum",
"silicon",
"phosphorus",
"sulfur",
"chlorine",
"potassium",
"iron",
"copper",
"mercury",
"radium",
"water",
"ethanol",
"sugar",
"sulphuric acid",
)
/// Has it been hacked
var/hacked_check = DISPENSER_UNHACKABLE
/// Additional reagents gotten when it is hacked
var/hacked_reagents = list()

/obj/structure/machinery/chem_dispenser/medbay
network = "Medbay"
Expand Down Expand Up @@ -112,9 +141,9 @@
var/list/beakerContents = list()
var/beakerCurrentVolume = 0
if(beaker && beaker.reagents && beaker.reagents.reagent_list.len)
for(var/datum/reagent/R in beaker.reagents.reagent_list)
beakerContents += list(list("name" = R.name, "volume" = R.volume)) // list in a list because Byond merges the first list...
beakerCurrentVolume += R.volume
for(var/datum/reagent/current_reagent in beaker.reagents.reagent_list)
beakerContents += list(list("name" = current_reagent.name, "volume" = current_reagent.volume)) // list in a list because Byond merges the first list...
beakerCurrentVolume += current_reagent.volume
.["beakerContents"] = beakerContents

if (beaker)
Expand Down Expand Up @@ -150,11 +179,11 @@
return
var/reagent_name = params["reagent"]
if(beaker && dispensable_reagents.Find(reagent_name))
var/obj/item/reagent_container/B = beaker
var/datum/reagents/R = B.reagents
var/space = R.maximum_volume - R.total_volume
var/obj/item/reagent_container/current_beaker = beaker
var/datum/reagents/current_reagent = current_beaker.reagents
var/space = current_reagent.maximum_volume - current_reagent.total_volume

R.add_reagent(reagent_name, min(amount, chem_storage.energy * 10, space))
current_reagent.add_reagent(reagent_name, min(amount, chem_storage.energy * 10, space))
chem_storage.energy = max(chem_storage.energy - min(amount, chem_storage.energy * 10, space) / 10, 0)

. = TRUE
Expand All @@ -171,32 +200,64 @@
replace_beaker(usr)
. = TRUE

/obj/structure/machinery/chem_dispenser/attackby(obj/item/reagent_container/B, mob/user)
/obj/structure/machinery/chem_dispenser/attackby(obj/item/reagent_container/attacking_object, mob/user)
if(isrobot(user))
return
if(istype(B, /obj/item/reagent_container/glass) || istype(B, /obj/item/reagent_container/food))
if(!accept_glass && istype(B,/obj/item/reagent_container/food))

if(istype(attacking_object, /obj/item/reagent_container/glass) || istype(attacking_object, /obj/item/reagent_container/food))
if(accept_beaker_only && istype(attacking_object,/obj/item/reagent_container/food))
to_chat(user, SPAN_NOTICE("This machine only accepts beakers"))
if(user.drop_inv_item_to_loc(B, src))
if(user.drop_inv_item_to_loc(attacking_object, src))
var/obj/item/old_beaker = beaker
beaker = B
beaker = attacking_object
if(old_beaker)
to_chat(user, SPAN_NOTICE("You swap out \the [old_beaker] for \the [B]."))
to_chat(user, SPAN_NOTICE("You swap out [old_beaker] for [attacking_object]."))
user.put_in_hands(old_beaker)
else
to_chat(user, SPAN_NOTICE("You set \the [B] on the machine."))
to_chat(user, SPAN_NOTICE("You set [attacking_object] on the machine."))
SStgui.update_uis(src)
update_icon()
return

if(HAS_TRAIT(attacking_object, TRAIT_TOOL_MULTITOOL))
switch(hacked_check)
if(DISPENSER_UNHACKABLE)
to_chat(user, SPAN_NOTICE("[src] cannot be hacked."))
if(DISPENSER_NOT_HACKED)
user.visible_message("[user] modifies [src] with [attacking_object], turning a light on.", "You enable a light in [src].")
dispensable_reagents += hacked_reagents
hacked_check = DISPENSER_HACKED
if(DISPENSER_HACKED)
user.visible_message("[user] modifies [src] with [attacking_object], turning a light off.", "You disable a light in [src].")
dispensable_reagents -= hacked_reagents
hacked_check = DISPENSER_NOT_HACKED

if(HAS_TRAIT(attacking_object, TRAIT_TOOL_WRENCH))
if(!wrenchable)
to_chat(user, "[src] cannot be unwrenched.")

if(!do_after(user, 2 SECONDS, INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
return
if(!src)
return

playsound(loc, 'sound/items/Ratchet.ogg', 25, 1)
anchored = !anchored
if(anchored)
user.visible_message("[user] tightens the bolts securing [src] to the surface.", "You tighten the bolts securing [src] to the surface.")
return

user.visible_message("[user] unfastens the bolts securing [src] to the surface.", "You unfasten the bolts securing [src] to the surface.")

/obj/structure/machinery/chem_dispenser/attack_remote(mob/user as mob)
return src.attack_hand(user)

/obj/structure/machinery/chem_dispenser/attack_hand(mob/user as mob)
if(stat & BROKEN)
to_chat(user, SPAN_WARNING("[src] is inoperative."))
return
if(req_skill && !skillcheck(user, req_skill, req_skill_level))
to_chat(user, SPAN_WARNING("You don't have the training to use this."))
to_chat(user, SPAN_WARNING("You don't have the training to use [src]."))
return
tgui_interact(user)

Expand All @@ -207,9 +268,10 @@
ui_title = "Soda Dispens-o-matic"
req_skill = null
req_skill_level = null
accept_glass = 1
accept_beaker_only = FALSE
wrenchable = TRUE
network = "Misc"
hacked_check = DISPENSER_NOT_HACKED
dispensable_reagents = list(
"water",
"ice",
Expand All @@ -234,76 +296,43 @@
"lemonjuice",
"banana",
)
var/hackedcheck = 0

/obj/structure/machinery/chem_dispenser/soda/attackby(obj/item/B as obj, mob/user as mob)
..()
if(HAS_TRAIT(B, TRAIT_TOOL_MULTITOOL))
if(hackedcheck == 0)
to_chat(user, "You change the mode from 'Soda Magic' to 'Milking Time'.")
dispensable_reagents += list("milk","soymilk")
hackedcheck = 1
return

else
to_chat(user, "You change the mode from 'Milking Time' to 'Soda Magic'.")
dispensable_reagents -= list("milk","soymilk")
hackedcheck = 0
return
else if(HAS_TRAIT(B, TRAIT_TOOL_WRENCH))
if(!wrenchable) return

if(do_after(user, 20, INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
if(!src) return
playsound(src.loc, 'sound/items/Ratchet.ogg', 25, 1)
switch (anchored)
if (FALSE)
anchored = TRUE
user.visible_message("[user] tightens the bolts securing \the [src] to the surface.", "You tighten the bolts securing \the [src] to the surface.")
if (TRUE)
user.visible_message("[user] unfastens the bolts securing \the [src] to the surface.", "You unfasten the bolts securing \the [src] to the surface.")
anchored = FALSE
return
hacked_reagents = list(
"milk",
"soymilk",
)

/obj/structure/machinery/chem_dispenser/beer
/obj/structure/machinery/chem_dispenser/soda/beer
icon_state = "booze_dispenser"
name = "booze dispenser"
ui_title = "Booze Portal 9001"
req_skill = null
req_skill_level = null
accept_glass = 1
wrenchable = TRUE
network = "Misc"
desc = "A technological marvel, supposedly able to mix just the mixture you'd like to drink the moment you ask for one."
dispensable_reagents = list("water","ice","sodawater","sugar","tonic","beer","kahlua","whiskey","sake","wine","vodka","gin","rum","vermouth","cognac","ale","mead","thirteenloko","tequila")
var/hackedcheck = 0

/obj/structure/machinery/chem_dispenser/beer/attackby(obj/item/B as obj, mob/user as mob)
..()

if(HAS_TRAIT(B, TRAIT_TOOL_MULTITOOL))
if(hackedcheck == 0)
to_chat(user, "You disable the 'Weyland-Yutani-are-cheap-bastards' lock, enabling hidden and very expensive boozes.")
dispensable_reagents += list("goldschlager","patron","absinthe")
hackedcheck = 1
return
dispensable_reagents = list(
"water",
"ice",
"sodawater",
"sugar",
"tonic",
"beer",
"kahlua",
"whiskey",
"sake",
"wine",
"vodka",
"gin",
"rum",
"vermouth",
"cognac",
"ale",
"mead",
"thirteenloko",
"tequila",
)
hacked_reagents = list(
"goldschlager",
"patron",
"absinthe",
)

else
to_chat(user, "You re-enable the 'Weyland-Yutani-are-cheap-bastards' lock, disabling hidden and very expensive boozes.")
dispensable_reagents -= list("goldschlager","patron","absinthe")
hackedcheck = 0
return
else if(HAS_TRAIT(B, TRAIT_TOOL_WRENCH))
if(!wrenchable) return

if(do_after(user, 20, INTERRUPT_ALL|BEHAVIOR_IMMOBILE, BUSY_ICON_BUILD))
if(!src) return
playsound(src.loc, 'sound/items/Ratchet.ogg', 25, 1)
switch (anchored)
if (FALSE)
anchored = TRUE
user.visible_message("[user] tightens the bolts securing \the [src] to the surface.", "You tighten the bolts securing \the [src] to the surface.")
if (TRUE)
user.visible_message("[user] unfastens the bolts securing \the [src] to the surface.", "You unfasten the bolts securing \the [src] to the surface.")
anchored = FALSE
return
#undef DISPENSER_UNHACKABLE
#undef DISPENSER_NOT_HACKED
#undef DISPENSER_HACKED
2 changes: 1 addition & 1 deletion maps/interiors/fancylocker.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
/area/vehicle/apc)
"t" = (
/obj/structure/surface/table/woodentable/fancy,
/obj/structure/machinery/chem_dispenser/beer,
/obj/structure/machinery/chem_dispenser/soda/beer,
/turf/open/floor/wood,
/area/vehicle/apc)
"u" = (
Expand Down
4 changes: 2 additions & 2 deletions maps/map_files/CORSAT/Corsat.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -22132,7 +22132,7 @@
/area/corsat/gamma/biodome/toxins)
"biR" = (
/obj/structure/surface/table/woodentable,
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
dir = 8;
pixel_x = 15
},
Expand Down Expand Up @@ -25197,7 +25197,7 @@
/area/corsat/sigma/south/offices)
"bsN" = (
/obj/structure/surface/table/woodentable,
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
dir = 8
},
/turf/open/floor/corsat{
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/Ice_Colony_v2/Ice_Colony_v2.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -14261,7 +14261,7 @@
/area/ice_colony/surface/bar/bar)
"aPy" = (
/obj/structure/surface/table/woodentable,
/obj/structure/machinery/chem_dispenser/beer,
/obj/structure/machinery/chem_dispenser/soda/beer,
/obj/structure/machinery/alarm{
dir = 1;
pixel_y = -24
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/Ice_Colony_v3/Shivas_Snowball.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -6004,7 +6004,7 @@
/turf/open/floor/plating,
/area/shiva/interior/colony/s_admin)
"aRc" = (
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
pixel_y = 8
},
/obj/structure/surface/table/reinforced/prison,
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/Kutjevo/Kutjevo.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
/turf/open/floor/kutjevo/grey/plate,
/area/kutjevo/interior/complex/med/cells)
"azb" = (
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
icon_state = "dispenser"
},
/turf/open/floor/kutjevo/tan/multi_tiles,
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/LV624/LV624.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -12062,7 +12062,7 @@
/area/lv624/lazarus/comms)
"aZi" = (
/obj/structure/surface/table/woodentable/fancy,
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
pixel_y = 26
},
/obj/effect/landmark/item_pool_spawner/survivor_ammo/buckshot,
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/New_Varadero/New_Varadero.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -6101,7 +6101,7 @@
/area/varadero/interior/hall_SE)
"fvw" = (
/obj/structure/surface/table/reinforced/prison,
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
pixel_y = 8
},
/turf/open/floor/shiva{
Expand Down
6 changes: 3 additions & 3 deletions maps/map_files/Sorokyne_Strata/Sorokyne_Strata.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -9733,7 +9733,7 @@
},
/area/strata/ag/interior/outpost/canteen)
"aDr" = (
/obj/structure/machinery/chem_dispenser/beer,
/obj/structure/machinery/chem_dispenser/soda/beer,
/turf/open/floor/interior/plastic,
/area/strata/ag/interior/outpost/canteen)
"aDs" = (
Expand Down Expand Up @@ -10184,7 +10184,7 @@
},
/area/strata/ag/interior/dorms)
"aEK" = (
/obj/structure/machinery/chem_dispenser/beer,
/obj/structure/machinery/chem_dispenser/soda/beer,
/obj/structure/surface/table/reinforced/prison,
/turf/open/floor/strata{
icon_state = "orange_tile"
Expand Down Expand Up @@ -12088,7 +12088,7 @@
},
/area/strata/ag/interior/outpost/admin)
"aKQ" = (
/obj/structure/machinery/chem_dispenser/beer,
/obj/structure/machinery/chem_dispenser/soda/beer,
/obj/structure/surface/table/reinforced/prison,
/turf/open/floor/strata{
dir = 4;
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/USS_Almayer/USS_Almayer.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -12663,7 +12663,7 @@
/area/almayer/hallways/starboard_hallway)
"aSt" = (
/obj/structure/surface/table/reinforced/almayer_B,
/obj/structure/machinery/chem_dispenser/beer,
/obj/structure/machinery/chem_dispenser/soda/beer,
/turf/open/floor/prison{
icon_state = "kitchen"
},
Expand Down
2 changes: 1 addition & 1 deletion maps/map_files/generic/Admin_level.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@
},
/area/adminlevel/ert_station)
"zk" = (
/obj/structure/machinery/chem_dispenser/beer{
/obj/structure/machinery/chem_dispenser/soda/beer{
density = 0;
pixel_y = 10
},
Expand Down
Loading

0 comments on commit 56ebd39

Please sign in to comment.