Files
Bubberstation/code/game/objects/items/rcd/RPLD.dm
T
66f726dfe3 General code maintenance for rcd devices and their DEFINE file (#78443)
## About The Pull Request
The changes made can be best summarized into points

**1. Cleans up `code/_DEFINES/construction.dm`**

Looking at the top comment of this file 

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/__DEFINES/construction.dm#L1

One would expect stuff related to materials, rcd, and other construction
related stuff. Well this file is anything but

Why is there stuff related to food & crafting over here then?

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/__DEFINES/construction.dm#L91-L94

It gets worse why are global lists declared here?

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/__DEFINES/construction.dm#L115
There is a dedicated folder to store global lists i.e.
`code/_globalvars/lists` for lists like these. These clearly don't
belong here

On top of that a lot of construction related defines has been just
dumped here making it too large for it's purposes. which is why this
file has been scraped and it's
1. crafting related stuff have been moved to its
`code/_DEFINES/crafting.dm`
2. global lists for crafting moved to
`code/_globalvars/lists/crafting.dm`
3. Finally remaining construction related defines split apart into 4
file types under the new `code/_DEFINES/construction` folder
- `code/_DEFINES/construction/actions.dm` -> for wrench act or other
construction related actions
- `code/_DEFINES/construction/material.dm` -> contains your sheet
defines and cable & stack related values. Also merged
`code/_DEFINES/material.dm` with this file so it belongs in one place
- `code/_DEFINES/construction/rcd.dm` -> dedicated file for everything
rcd related
- `code/_DEFINES/construction/structures.dm` -> contains the
construction states for various stuff like walls, girders, floodlight
etc

By splitting this file into multiple meaningful define file names will
help in reducing merge conflicts and will aid in faster navigation so
this is the 1st part of this PR

**2. Debloats the `RCD.dm` file(Part 1)**

This uses the same concepts as above. i.e. moving defines into their
appropriate files for e.g.

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/game/objects/items/rcd/RCD.dm#L170

1. Global vars belong in the `code/_globalvars` folder so these vars and
their related functions to initialize them are moved into the
`code/_globalvars/rcd.dm` file
2. See this proc

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/game/objects/items/rcd/RCD.dm#L200
This proc does not belong to the `obj/item/construction/rcd` type it's a
global "helper function" this is an effect proc as it creates rcd
holograms so it has been moved to the `code/game/objects/effects/rcd.dm`
file which is a global effect that can be used by anyone

And with that we have moved these vars & procs into their correct places
& reduced the size of this file . We can go even further

**3. Debloats the `RCD.dm` file(Part 2)**
This deals with the large list which contains all the designs supported
by the RCD

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/game/objects/items/rcd/RCD.dm#L42

This list contains a lot of local defines. We can scrape some of them
and reduce the overall bulkiness & memory requirements of this list and
so the following defines

```
#define WINDOW_TYPE "window_type"
#define COMPUTER_DIR "computer_dir"
#define WALLFRAME_TYPE "wallframe_type"
#define FURNISH_TYPE "furnish_type"
#define AIRLOCK_TYPE "airlock_type"
#define TITLE "title"
#define ICON "icon"
#define CATEGORY_ICON_STATE  "category_icon_state"
#define CATEGORY_ICON_SUFFIX "category_icon_suffix"
#define TITLE_ICON "ICON=TITLE"
```

Have all been removed making this list a lot more cleaner. Why? because
a lot of these are just semantic sugar, we can infer the value of a lot
of these defines if we just know the type path of the structure the rcd
is trying to build for e.g. take these 2 defines

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/game/objects/items/rcd/RCD.dm#L13-L15

These defines tell the rcd UI the name and the icon it should display.
Rather than specifying these manually in the design we can infer them
like this

```
var/obj/design = /obj/structure/window  //let's say the rcd is trying to build an window
var/name = initial(design.name)         //we have inferred the name of the design without requiring TITLE define
var/icon = initial(design.icon_state)   //we have inferred the icon of the design without requiring ICON define
```

And so by using similar logic to the remaining defines we can eliminate
a lot of these local defines and reduce the overall size of this list.

The same logic applies to the different modes of construction, the
following defines

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/__DEFINES/construction.dm#L186-L192
Have all been removed and replaced with a single value `RCD_STRUCTURE`

All these modes follow the same principle when building them
1. First check the turf if the structure exists. If it does early return
2. If not create a new structure there and that's it

So rather than creating a new construction mode every time you want to
add a new design we can use this mode to apply this general approach
every time

The design list has also now been made into a global list rather than a
private static list. The big advantage to this is that the rcd asset
cache can now access this list and load the correct icons from the list
directly. This means you no longer have to manually specify what icons
you want to load which is the case currently.

https://github.com/tgstation/tgstation/blob/0fb8b8b218400b3f1805ae81e9bb0364d7a4e9c6/code/modules/asset_cache/assets/rcd.dm#L8-L9
This has lead to the UI icons breaking twice now in the past
- #74194
- #77217

Hopefully this should never repeat itself again

**4. Other RCD like device changes**
- Fixed the broken silo link icon when the radial menu of the RLD was
opened
- replaced a lot of vars inside RLD with defines to save memory
- Small changes to `ui_act` across RCD, Plumbing RCD and RTD
- Removed unused vars in RCD and snowflaked code
- Moved a large majority of `ui_data()` to `ui_static_data()` making the
experience much faster

Just some general clean up going on here

**5. The Large majority of other code changes**
These are actually small code changes spread across multiple files.
These effect the `rcd_act()` & the `rcd_vals()` procs across all items.
Basically it
- Removes a large majority of `to_chat()` & `visible_message()` calls.
This was done because we already have enough visual feedback of what's
going on. When we construct a wall we don't need a `to_chat()` to tell
us you have a built a wall, we can clearly see that
- replaces the static string `"mode"` with a predefined constant
`RCD_DESIGN_MODE` to bring some standard to use across all cases

Should reduce chat spam and improve readability of code. 

**6. Airlock & Window names**
The rcd asset cache relies on the design name to be unique. So i filled
in the missing names for some airlocks & windows which are subjective
and open to change but must have some value

**7 Removes Microwave PDA upgrade**
The RCD should not be allowed to build this microwave considering how
quickly it can spawn multiple structures and more importantly as it's a
special multipurpose machine so you should spend some effort in printing
it's parts and acquiring tools to complete it. This upgrade makes
obsolete the need to carry an
- A RPED to install the parts
- A screwdriver to complete the frame
- The circuit board for the microwave 

The most important point to note here is that whenever an RPED/circuit
board is printed at an lathe it charges you "Lathe Tax". The RCD with
this upgrade would essentially bypass the need to "Pay Taxes" at these
lathes as you are just creating a circuit board from thin air. This
causes economy imbalance(10 cr per print) which scales up the more of
these machines you make so to avoid this let's end the problem here

Not to mention people would not find the need to print the circuit board
for a regular microwave now if they have an RCD because they can just
make this microwave type making the need for a regular microwave
completely pointless.

Just build a machine frame with the RCD and complete the microwave from
there

## Changelog
🆑
code: moved global vars, lists and helper procs for construction related
stuff to their appropriate files
code: reduced overall code size & memory of rcd design list and removed
unused defines
refactor: removed a ton of chat alerts for rcd related actions to help
reduce chat spam
refactor: some airlock & window default names have changed
fix: broken icon in radial menu of rld silo link
remove: removes microwave pda upgrade from RCD. It's a special machine
so spend some time in building it rather than shitting them out for free
with the RCD. Use the RCD upgrade to spawn a machine frame instead & go
from there
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2023-10-12 19:46:41 +02:00

379 lines
13 KiB
Plaintext

///The plumbing RCD. All the blueprints are located in _globalvars > lists > construction.dm
/obj/item/construction/plumbing
name = "Plumbing Constructor"
desc = "An expertly modified RCD outfitted to construct plumbing machinery."
icon_state = "plumberer2"
inhand_icon_state = "plumberer"
lefthand_file = 'icons/mob/inhands/equipment/tools_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/tools_righthand.dmi'
worn_icon_state = "plumbing"
icon = 'icons/obj/tools.dmi'
slot_flags = ITEM_SLOT_BELT
banned_upgrades = RCD_ALL_UPGRADES & ~RCD_UPGRADE_SILO_LINK
matter = 200
max_matter = 200
///category of design selected
var/selected_category
///type of the plumbing machine
var/obj/machinery/blueprint = null
///This list that holds all the plumbing design types the plumberer can construct. Its purpose is to make it easy to make new plumberer subtypes with a different selection of machines.
var/list/plumbing_design_types = null
///Current selected layer
var/current_layer = "Default Layer"
///Current selected color, for ducts
var/current_color = "omni"
///maps layer name to layer number value. didnt make this global cause only this class needs it
var/static/list/name_to_number = list(
"First Layer" = 1,
"Second Layer" = 2,
"Default Layer" = 3,
"Fourth Layer" = 4,
"Fifth Layer" = 5,
)
///Design types for general plumbing constructor
var/static/list/general_design_types = list(
//category 1 Synthesizers i.e devices which creates , reacts & destroys chemicals
"Synthesizers" = list(
/obj/machinery/plumbing/synthesizer = 15,
/obj/machinery/plumbing/reaction_chamber/chem = 15,
/obj/machinery/plumbing/grinder_chemical = 30,
/obj/machinery/plumbing/growing_vat = 20,
/obj/machinery/plumbing/fermenter = 30,
/obj/machinery/plumbing/liquid_pump = 35, //extracting chemicals from ground is one way of creation
/obj/machinery/plumbing/disposer = 10,
/obj/machinery/plumbing/buffer = 10, //creates chemicals as it waits for other buffers containing other chemicals and when mixed creates new chemicals
),
//category 2 distributors i.e devices which inject , move around , remove chemicals from the network
"Distributors" = list(
/obj/machinery/duct = 1,
/obj/machinery/plumbing/layer_manifold = 5,
/obj/machinery/plumbing/input = 5,
/obj/machinery/plumbing/filter = 5,
/obj/machinery/plumbing/splitter = 5,
/obj/machinery/plumbing/sender = 20,
/obj/machinery/plumbing/output = 5,
),
//category 3 Storage i.e devices which stores & makes the processed chemicals ready for consumption
"Storage" = list(
/obj/machinery/plumbing/tank = 20,
/obj/machinery/plumbing/acclimator = 10,
/obj/machinery/plumbing/bottler = 50,
/obj/machinery/plumbing/pill_press = 20,
/obj/machinery/iv_drip/plumbing = 20
),
)
/obj/item/construction/plumbing/Initialize(mapload)
. = ..()
if(isnull(plumbing_design_types))
plumbing_design_types = general_design_types
selected_category = plumbing_design_types[1]
/**
* plumbing_design_types["Synthesizers"] = <list of designs under synthesizers>
* <list of designs under synthesizers>[1] = <first design in this list>
*/
blueprint = plumbing_design_types[selected_category][1]
/obj/item/construction/plumbing/equipped(mob/user, slot, initial)
. = ..()
if(slot & ITEM_SLOT_HANDS)
RegisterSignal(user, COMSIG_MOUSE_SCROLL_ON, PROC_REF(mouse_wheeled))
else
UnregisterSignal(user, COMSIG_MOUSE_SCROLL_ON)
/obj/item/construction/plumbing/dropped(mob/user, silent)
UnregisterSignal(user, COMSIG_MOUSE_SCROLL_ON)
return ..()
/obj/item/construction/plumbing/cyborg_unequip(mob/user)
UnregisterSignal(user, COMSIG_MOUSE_SCROLL_ON)
return ..()
/obj/item/construction/plumbing/attack_self(mob/user)
. = ..()
ui_interact(user)
/obj/item/construction/plumbing/examine(mob/user)
. = ..()
. += "You can scroll your mouse wheel to change the piping layer."
. += "You can right click a fluid duct to set the Plumbing RPD to its color and layer."
/obj/item/construction/plumbing/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "RapidPlumbingDevice", name)
ui.open()
/obj/item/construction/plumbing/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/spritesheet/plumbing),
)
/obj/item/construction/plumbing/ui_static_data(mob/user)
var/list/data = ..()
data["paint_colors"] = GLOB.pipe_paint_colors
var/category_list = list()
for(var/category_name in plumbing_design_types)
var/list/designs = plumbing_design_types[category_name]
//Create category
var/list/item_list = list()
item_list["cat_name"] = category_name //used by RapidPipeDispenser.js
item_list["recipes"] = list() //used by RapidPipeDispenser.js
category_list[category_name] = item_list
//Add designs to category
for(var/obj/machinery/recipe as anything in designs)
category_list[category_name]["recipes"] += list(list(
"icon" = initial(recipe.icon_state),
"name" = initial(recipe.name),
))
data["categories"] = list()
for(var/category_name in category_list)
data["categories"] += list(category_list[category_name])
return data
/obj/item/construction/plumbing/ui_data(mob/user)
var/list/data = ..()
data["piping_layer"] = name_to_number[current_layer] //maps layer name to layer number's 1,2,3,4,5
data["selected_color"] = current_color
data["layer_icon"] = "plumbing_layer[GLOB.plumbing_layers[current_layer]]"
data["selected_category"] = selected_category
data["selected_recipe"] = initial(blueprint.name)
return data
/obj/item/construction/plumbing/handle_ui_act(action, params, datum/tgui/ui, datum/ui_state/state)
switch(action)
if("color")
var/color = params["paint_color"]
if(GLOB.pipe_paint_colors[color] != null) //validate if the color is in the allowed list of values
current_color = color
if("piping_layer")
var/bitflag = text2num(params["piping_layer"]) //convert from layer number back to layer string
bitflag = 1 << (bitflag - 1)
var/layer = GLOB.plumbing_layer_names["[bitflag]"]
if(layer != null) //validate if this value exists in the list
current_layer = layer
if("recipe")
var/category = params["category"]
var/list/designs = plumbing_design_types[category]
if(!length(designs))
return FALSE
selected_category = category
var/design = designs[text2num(params["id"]) + 1]
if(!design)
return FALSE
blueprint = design
playsound(src, 'sound/effects/pop.ogg', 50, vary = FALSE)
return TRUE
///pretty much rcd_create, but named differently to make myself feel less bad for copypasting from a sibling-type
/obj/item/construction/plumbing/proc/create_machine(atom/destination, mob/user)
if(!isopenturf(destination))
return FALSE
var/cost = 0
for(var/category in plumbing_design_types)
cost = plumbing_design_types[category][blueprint]
if(cost)
break
if(!cost)
return FALSE
//resource & placement sanity check before & after delay
var/is_allowed = TRUE
if(!checkResource(cost, user) || !(is_allowed = canPlace(destination)))
if(!is_allowed)
balloon_alert(user, "turf is blocked!")
return FALSE
if(!do_after(user, cost, target = destination)) //"cost" is relative to delay at a rate of 10 matter/second (1matter/decisecond) rather than playing with 2 different variables since everyone set it to this rate anyways.
return FALSE
if(!checkResource(cost, user) || !(is_allowed = canPlace(destination)))
if(!is_allowed)
balloon_alert(user, "turf is blocked!")
return FALSE
if(!useResource(cost, user))
return FALSE
activate()
playsound(loc, 'sound/machines/click.ogg', 50, TRUE)
if(ispath(blueprint, /obj/machinery/duct))
var/is_omni = current_color == DUCT_COLOR_OMNI
new blueprint(destination, FALSE, GLOB.pipe_paint_colors[current_color], GLOB.plumbing_layers[current_layer], null, is_omni)
else
new blueprint(destination, FALSE, GLOB.plumbing_layers[current_layer])
return TRUE
/obj/item/construction/plumbing/proc/canPlace(turf/destination)
if(!isopenturf(destination))
return FALSE
if(initial(blueprint.density) && destination.is_blocked_turf(exclude_mobs = FALSE, source_atom = null, ignore_atoms = null))
return FALSE
. = TRUE
var/layer_id = GLOB.plumbing_layers[current_layer]
for(var/obj/content_obj in destination.contents)
// Make sure plumbling isn't overlapping.
for(var/datum/component/plumbing/plumber as anything in content_obj.GetComponents(/datum/component/plumbing))
if(plumber.ducting_layer & layer_id)
return FALSE
// Make sure ducts aren't overlapping.
if(istype(content_obj, /obj/machinery/duct))
var/obj/machinery/duct/duct_machine = content_obj
if(duct_machine.duct_layer & layer_id)
return FALSE
/obj/item/construction/plumbing/pre_attack_secondary(obj/machinery/target, mob/user, params)
if(!istype(target, /obj/machinery/duct))
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
var/obj/machinery/duct/duct = target
if(duct.duct_layer && duct.duct_color)
current_color = GLOB.pipe_color_name[duct.duct_color]
current_layer = GLOB.plumbing_layer_names["[duct.duct_layer]"]
balloon_alert(user, "using [current_color], layer [current_layer]")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
/obj/item/construction/plumbing/afterattack(atom/target, mob/user, proximity)
. = ..()
if(!proximity)
return
for(var/category_name in plumbing_design_types)
var/list/designs = plumbing_design_types[category_name]
for(var/obj/machinery/recipe as anything in designs)
if(target.type != recipe)
continue
var/obj/machinery/machine_target = target
if(machine_target.anchored)
balloon_alert(user, "unanchor first!")
return
if(do_after(user, 20, target = target))
machine_target.deconstruct() //Let's not substract matter
playsound(get_turf(src), 'sound/machines/click.ogg', 50, TRUE) //this is just such a great sound effect
return
create_machine(target, user)
/obj/item/construction/plumbing/AltClick(mob/user)
ui_interact(user)
/obj/item/construction/plumbing/proc/mouse_wheeled(mob/source, atom/A, delta_x, delta_y, params)
SIGNAL_HANDLER
if(source.incapacitated(IGNORE_RESTRAINTS|IGNORE_STASIS))
return
if(delta_y == 0)
return
if(delta_y < 0)
var/current_loc = GLOB.plumbing_layers.Find(current_layer) + 1
if(current_loc > GLOB.plumbing_layers.len)
current_loc = 1
current_layer = GLOB.plumbing_layers[current_loc]
else
var/current_loc = GLOB.plumbing_layers.Find(current_layer) - 1
if(current_loc < 1)
current_loc = GLOB.plumbing_layers.len
current_layer = GLOB.plumbing_layers[current_loc]
to_chat(source, span_notice("You set the layer to [current_layer]."))
/obj/item/construction/plumbing/research
name = "research plumbing constructor"
desc = "A type of plumbing constructor designed to rapidly deploy the machines needed to conduct cytological research."
icon_state = "plumberer_sci"
inhand_icon_state = "plumberer_sci"
lefthand_file = 'icons/mob/inhands/equipment/tools_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/tools_righthand.dmi'
///Design types for research plumbing constructor
var/list/static/research_design_types = list(
//Category 1 Synthesizers
"Synthesizers" = list(
/obj/machinery/plumbing/reaction_chamber = 15,
/obj/machinery/plumbing/grinder_chemical = 30,
/obj/machinery/plumbing/disposer = 10,
/obj/machinery/plumbing/growing_vat = 20,
),
//Category 2 Distributors
"Distributors" = list(
/obj/machinery/duct = 1,
/obj/machinery/plumbing/input = 5,
/obj/machinery/plumbing/filter = 5,
/obj/machinery/plumbing/splitter = 5,
/obj/machinery/plumbing/output = 5,
),
//Category 3 storage
"Storage" = list(
/obj/machinery/plumbing/tank = 20,
/obj/machinery/plumbing/acclimator = 10,
),
)
/obj/item/construction/plumbing/research/Initialize(mapload)
plumbing_design_types = research_design_types
. = ..()
/obj/item/construction/plumbing/service
name = "service plumbing constructor"
desc = "A type of plumbing constructor designed to rapidly deploy the machines needed to make a brewery."
icon_state = "plumberer_service"
///Design types for plumbing service constructor
var/static/list/service_design_types = list(
//Category 1 synthesizers
"Synthesizers" = list(
/obj/machinery/plumbing/synthesizer/soda = 15,
/obj/machinery/plumbing/synthesizer/beer = 15,
/obj/machinery/plumbing/reaction_chamber = 15,
/obj/machinery/plumbing/buffer = 10,
/obj/machinery/plumbing/fermenter = 30,
/obj/machinery/plumbing/grinder_chemical = 30,
/obj/machinery/plumbing/disposer = 10,
),
//Category 2 distributors
"Distributors" = list(
/obj/machinery/duct = 1,
/obj/machinery/plumbing/layer_manifold = 5,
/obj/machinery/plumbing/input = 5,
/obj/machinery/plumbing/filter = 5,
/obj/machinery/plumbing/splitter = 5,
/obj/machinery/plumbing/output/tap = 5,
/obj/machinery/plumbing/sender = 20,
),
//category 3 storage
"Storage" = list(
/obj/machinery/plumbing/bottler = 50,
/obj/machinery/plumbing/tank = 20,
/obj/machinery/plumbing/acclimator = 10,
),
)
/obj/item/construction/plumbing/service/Initialize(mapload)
plumbing_design_types = service_design_types
. = ..()