Skip to content

Commit

Permalink
General code maintenance for rcd devices and their DEFINE file (tgsta…
Browse files Browse the repository at this point in the history
…tion#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
- tgstation#74194
- tgstation#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
:cl:
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
/:cl:

---------

Co-authored-by: Ghom <[email protected]>
  • Loading branch information
SyncIt21 and Ghommie authored Oct 12, 2023
1 parent 595a7ac commit 66f726d
Show file tree
Hide file tree
Showing 50 changed files with 1,138 additions and 1,132 deletions.
4 changes: 4 additions & 0 deletions code/__DEFINES/colors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
/// Icon filter that creates gaussian blur
#define GAUSSIAN_BLUR(filter_size) filter(type="blur", size=filter_size)

// Colors related to items used in construction
#define CABLE_COLOR_BLUE "blue"
#define CABLE_HEX_COLOR_BLUE COLOR_STRONG_BLUE
#define CABLE_COLOR_BROWN "brown"
Expand All @@ -308,6 +309,9 @@
#define CABLE_HEX_COLOR_WHITE COLOR_WHITE
#define CABLE_COLOR_YELLOW "yellow"
#define CABLE_HEX_COLOR_YELLOW COLOR_YELLOW
//windows affected by Nar'Sie turn this color.
#define NARSIE_WINDOW_COLOUR "#7D1919"


#define COLOR_CARP_PURPLE "#aba2ff"
#define COLOR_CARP_PINK "#da77a8"
Expand Down
227 changes: 0 additions & 227 deletions code/__DEFINES/construction.dm

This file was deleted.

11 changes: 11 additions & 0 deletions code/__DEFINES/construction/actions.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//default_unfasten_wrench() return defines
#define CANT_UNFASTEN 0
#define FAILED_UNFASTEN 1
#define SUCCESSFUL_UNFASTEN 2

// Defines for the construction component
#define FORWARD 1
#define BACKWARD -1

#define ITEM_DELETE "delete"
#define ITEM_MOVE_INSIDE "move_inside"
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
//Defines for amount of material retrived from sheets & other items
/// The amount of materials you get from a sheet of mineral like iron/diamond/glass etc. 100 Units.
#define SHEET_MATERIAL_AMOUNT 100
/// The amount of materials you get from half a sheet. Used in standard object quantities. 50 units.
#define HALF_SHEET_MATERIAL_AMOUNT (SHEET_MATERIAL_AMOUNT / 2)
/// The amount of materials used in the smallest of objects, like pens and screwdrivers. 10 units.
#define SMALL_MATERIAL_AMOUNT (HALF_SHEET_MATERIAL_AMOUNT / 5)
/// The amount of material that goes into a coin, which determines the value of the coin.
#define COIN_MATERIAL_AMOUNT (HALF_SHEET_MATERIAL_AMOUNT * 0.4)

//Cable related values
/// The maximum size of a stack object.
#define MAX_STACK_SIZE 50
/// Maximum amount of cable in a coil
#define MAXCOIL 30

//Category of materials
/// Is the material from an ore? currently unused but exists atm for categorizations sake
#define MAT_CATEGORY_ORE "ore capable"

/// Hard materials, such as iron or silver
#define MAT_CATEGORY_RIGID "rigid material"

/// Materials that can be used to craft items
#define MAT_CATEGORY_ITEM_MATERIAL "item material"

///Use this flag on TRUE if you want the basic recipes
/// Use this flag on TRUE if you want the basic recipes
#define MAT_CATEGORY_BASE_RECIPES "basic recipes"

///Flags for map loaded materials
/// Used to make a material initialize at roundstart.
#define MATERIAL_INIT_MAPLOAD (1<<0)
/// Used to make a material type able to be instantiated on demand after roundstart.
#define MATERIAL_INIT_BESPOKE (1<<1)

/// Makes sure only integer values are used when consuming, removing & checking for mats
#define OPTIMAL_COST(cost)(max(1, round(cost)))

//Material Container Flags.
///If the container shows the amount of contained materials on examine.
#define MATCONTAINER_EXAMINE (1<<0)
///If the container cannot have materials inserted through attackby().
#define MATCONTAINER_NO_INSERT (1<<1)
///if the user can insert mats into the container despite the intent.
///If the user can insert mats into the container despite the intent.
#define MATCONTAINER_ANY_INTENT (1<<2)
///if the user won't receive a warning when attacking the container with an unallowed item.
///If the user won't receive a warning when attacking the container with an unallowed item.
#define MATCONTAINER_SILENT (1<<3)

// The following flags are for decomposing alloys. Should be expanded upon and diversified once someone gets around to reworking recycling.
Expand Down Expand Up @@ -59,14 +71,12 @@
/// Applies the material greyscale color to the atom's greyscale color.
#define MATERIAL_GREYSCALE (1<<4)

/// Wrapper for fetching material references. Exists exclusively so that people don't need to wrap everything in a list every time.
#define GET_MATERIAL_REF(arguments...) SSmaterials._GetMaterialRef(list(##arguments))

#define MATERIAL_SOURCE(mat) "[mat.name]_material"

///Special return values of [/datum/component/material_container/insert_item]
//Special return values of [/datum/component/material_container/insert_item]
/// No material was found inside them item
#define MATERIAL_INSERT_ITEM_NO_MATS -1
/// The container does not have the space for the item
#define MATERIAL_INSERT_ITEM_NO_SPACE -2
/// The item material type was not accepted or other reasons
#define MATERIAL_INSERT_ITEM_FAILURE 0


Expand Down
50 changes: 50 additions & 0 deletions code/__DEFINES/construction/rcd.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//rcd constants for the design list
/// The mode of operation to design an specific type of rcd design
#define RCD_DESIGN_MODE "rcd_design_mode"
/// For changing turfs
#define RCD_TURF (1 << 0)
/// Full tile windows
#define RCD_WINDOWGRILLE (1 << 1)
/// Windoors & Airlocks
#define RCD_AIRLOCK (1 << 2)
/// Literarly anything that is spawned on top of a turf such as tables, machines etc
#define RCD_STRUCTURE (1 << 3)
/// For wallmounts like air alarms, fire alarms & apc
#define RCD_WALLFRAME (1 << 4)
/// For deconstructing an structure
#define RCD_DECONSTRUCT (1 << 5)
/// The typepath of the structure the rcd is trying to build
#define RCD_DESIGN_PATH "rcd_design_path"

/// Time taken for an rcd hologram to disappear
#define RCD_HOLOGRAM_FADE_TIME (15 SECONDS)

//All available upgrades
/// Upgrade for building machines
#define RCD_UPGRADE_FRAMES (1 << 0)
/// Upgrade for installing circuitboards in air alarms, fire alarms, apc & cells in them
#define RCD_UPGRADE_SIMPLE_CIRCUITS (1 << 1)
/// Upgrade for drawing iron from ore silo
#define RCD_UPGRADE_SILO_LINK (1 << 2)
/// Upgrade for building furnishing items
#define RCD_UPGRADE_FURNISHING (1 << 3)
/// Upgrade to stop construction effect from getting attacked
#define RCD_UPGRADE_ANTI_INTERRUPT (1 << 4)
/// Upgrade to disable delay multiplier when building multiple structures
#define RCD_UPGRADE_NO_FREQUENT_USE_COOLDOWN (1 << 5)
/// All upgrades packed in 1 flag
#define RCD_ALL_UPGRADES (RCD_UPGRADE_FRAMES | RCD_UPGRADE_SIMPLE_CIRCUITS | RCD_UPGRADE_SILO_LINK | RCD_UPGRADE_FURNISHING | RCD_UPGRADE_ANTI_INTERRUPT | RCD_UPGRADE_NO_FREQUENT_USE_COOLDOWN)
/// Upgrades for the Rapid Pipe Dispenser to unwrench pipes
#define RPD_UPGRADE_UNWRENCH (1 << 0)

//Memory constants for faster construction speeds
/// The memory constant for a wall
#define RCD_MEMORY_WALL 1
/// The memory constant for full tile windows
#define RCD_MEMORY_WINDOWGRILLE 2
// How much faster to use the RCD when on a tile with memory
#define RCD_MEMORY_SPEED_BUFF 5
/// How much less resources the RCD uses when reconstructing
#define RCD_MEMORY_COST_BUFF 8
/// If set to TRUE in rcd_vals, will bypass the cooldown on slowing down frequent use
#define RCD_RESULT_BYPASS_FREQUENT_USE_COOLDOWN "bypass_frequent_use_cooldown"
Loading

0 comments on commit 66f726d

Please sign in to comment.