/
_material.dm
257 lines (219 loc) · 9.86 KB
/
_material.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*! Material datum
Simple datum which is instanced once per type and is used for every object of said material. It has a variety of variables that define behavior. Subtyping from this makes it easier to create your own materials.
*/
/datum/material
/// What the material is referred to as IC.
var/name = "material"
/// A short description of the material. Not used anywhere, yet...
var/desc = "its..stuff."
/// What the material is indexed by in the DSmaterials.materials list. Defaults to the type of the material.
var/id
///Base color of the material, is used for greyscale. Item isn't changed in color if this is null.
///Deprecated, use greyscale_color instead.
var/color
///Determines the color palette of the material. Formatted the same as atom/var/greyscale_colors
var/greyscale_colors
///Base alpha of the material, is used for greyscale icons.
var/alpha = 255
///Starlight color of the material
///This is the color of light it'll emit if its turf is transparent and over space. Defaults to COLOR_STARLIGHT if not set
var/starlight_color
///Bitflags that influence how DSmaterials handles this material.
var/init_flags = MATERIAL_INIT_MAPLOAD
///Materials "Traits". its a map of key = category | Value = Bool. Used to define what it can be used for
var/list/categories = list()
///The type of sheet this material creates. This should be replaced as soon as possible by greyscale sheets
var/sheet_type
/// What type of ore is this material associated with? Used for mining, and not every material has one.
var/obj/item/ore_type
///This is a modifier for force, and resembles the strength of the material
var/strength_modifier = 1
///This is a modifier for integrity, and resembles the strength of the material
var/integrity_modifier = 1
///This is the amount of value per 1 unit of the material
var/value_per_unit = 0
///This is the minimum value of the material, used in the stock market for any mat that isn't set to null
var/minimum_value_override = null
///Is this material traded on the stock market?
var/tradable = FALSE
///If this material is tradable, what is the base quantity of the material on the stock market?
var/tradable_base_quantity = 0
///Armor modifiers, multiplies an items normal armor vars by these amounts.
var/armor_modifiers = list(MELEE = 1, BULLET = 1, LASER = 1, ENERGY = 1, BOMB = 1, BIO = 1, FIRE = 1, ACID = 1)
///How beautiful is this material per unit.
var/beauty_modifier = 0
///Can be used to override the sound items make, lets add some SLOSHing.
var/item_sound_override
///Can be used to override the stepsound a turf makes. MORE SLOOOSH
var/turf_sound_override
///what texture icon state to overlay
var/texture_layer_icon_state
///a cached icon for the texture filter
var/cached_texture_filter_icon
///What type of shard the material will shatter to
var/obj/item/shard_type
///What type of debris the tile will leave behind when shattered.
var/obj/effect/decal/debris_type
/// How likely this mineral is to be found in a boulder during mining.
var/mineral_rarity = MATERIAL_RARITY_COMMON
/// How many points per units of ore does this grant?
var/points_per_unit = 1
/** Handles initializing the material.
*
* Arugments:
* - _id: The ID the material should use. Overrides the existing ID.
*/
/datum/material/proc/Initialize(_id, ...)
if(_id)
id = _id
else if(isnull(id))
id = type
if(texture_layer_icon_state)
cached_texture_filter_icon = icon('icons/turf/composite.dmi', texture_layer_icon_state)
return TRUE
///This proc is called when the material is added to an object.
/datum/material/proc/on_applied(atom/source, amount, material_flags)
if(material_flags & MATERIAL_COLOR) //Prevent changing things with pre-set colors, to keep colored toolboxes their looks for example
if(color) //Do we have a custom color?
source.add_atom_colour(color, FIXED_COLOUR_PRIORITY)
if(alpha)
source.alpha = alpha
if(texture_layer_icon_state)
ADD_KEEP_TOGETHER(source, MATERIAL_SOURCE(src))
source.add_filter("material_texture_[name]",1,layering_filter(icon=cached_texture_filter_icon,blend_mode=BLEND_INSET_OVERLAY))
if(material_flags & MATERIAL_GREYSCALE)
var/config_path = get_greyscale_config_for(source.greyscale_config)
source.set_greyscale(greyscale_colors, config_path)
if(alpha < 255)
source.opacity = FALSE
if(material_flags & MATERIAL_ADD_PREFIX)
source.name = "[name] [source.name]"
if(beauty_modifier)
source.AddElement(/datum/element/beauty, beauty_modifier * amount)
if(isobj(source)) //objs
on_applied_obj(source, amount, material_flags)
else if(istype(source, /turf)) //turfs
on_applied_turf(source, amount, material_flags)
source.mat_update_desc(src)
///This proc is called when a material updates an object's description
/atom/proc/mat_update_desc(datum/material/mat)
return
///This proc is called when the material is added to an object specifically.
/datum/material/proc/on_applied_obj(obj/o, amount, material_flags)
if(material_flags & MATERIAL_AFFECT_STATISTICS)
var/new_max_integrity = CEILING(o.max_integrity * integrity_modifier, 1)
o.modify_max_integrity(new_max_integrity)
o.force *= strength_modifier
o.throwforce *= strength_modifier
o.set_armor(o.get_armor().generate_new_with_multipliers(armor_modifiers))
if(!isitem(o))
return
var/obj/item/item = o
if(material_flags & MATERIAL_GREYSCALE)
var/worn_path = get_greyscale_config_for(item.greyscale_config_worn)
var/lefthand_path = get_greyscale_config_for(item.greyscale_config_inhand_left)
var/righthand_path = get_greyscale_config_for(item.greyscale_config_inhand_right)
item.set_greyscale(
new_worn_config = worn_path,
new_inhand_left = lefthand_path,
new_inhand_right = righthand_path
)
if(!item_sound_override)
return
item.hitsound = item_sound_override
item.usesound = item_sound_override
item.mob_throw_hit_sound = item_sound_override
item.equip_sound = item_sound_override
item.pickup_sound = item_sound_override
item.drop_sound = item_sound_override
/datum/material/proc/on_applied_turf(turf/T, amount, material_flags)
if(isopenturf(T))
if(turf_sound_override)
var/turf/open/O = T
O.footstep = turf_sound_override
O.barefootstep = turf_sound_override + "barefoot"
O.clawfootstep = turf_sound_override + "claw"
O.heavyfootstep = FOOTSTEP_GENERIC_HEAVY
if(alpha < 255)
T.AddElement(/datum/element/turf_z_transparency)
setup_glow(T)
return
/datum/material/proc/setup_glow(turf/on)
if(GET_TURF_PLANE_OFFSET(on) != GET_LOWEST_STACK_OFFSET(on.z)) // We ain't the bottom brother
return
// We assume no parallax means no space means no light
if(SSmapping.level_trait(on.z, ZTRAIT_NOPARALLAX))
return
if(!starlight_color)
on.RegisterSignal(SSdcs, COMSIG_STARLIGHT_COLOR_CHANGED, TYPE_PROC_REF(/turf, material_starlight_changed))
RegisterSignal(on, COMSIG_QDELETING, PROC_REF(lit_turf_deleted))
on.set_light(2, 1, starlight_color || GLOB.starlight_color, l_height = LIGHTING_HEIGHT_SPACE)
/turf/proc/material_starlight_changed(datum/source, old_star, new_star)
if(light_color == old_star)
set_light_color(new_star)
/datum/material/proc/lit_turf_deleted(turf/source)
source.set_light(0, 0, null)
/datum/material/proc/get_greyscale_config_for(datum/greyscale_config/config_path)
if(!config_path)
return
for(var/datum/greyscale_config/path as anything in subtypesof(config_path))
if(type != initial(path.material_skin))
continue
return path
///This proc is called when the material is removed from an object.
/datum/material/proc/on_removed(atom/source, amount, material_flags)
if(material_flags & MATERIAL_COLOR) //Prevent changing things with pre-set colors, to keep colored toolboxes their looks for example
if(color)
source.remove_atom_colour(FIXED_COLOUR_PRIORITY, color)
if(texture_layer_icon_state)
source.remove_filter("material_texture_[name]")
REMOVE_KEEP_TOGETHER(source, MATERIAL_SOURCE(src))
source.alpha = initial(source.alpha)
if(material_flags & MATERIAL_GREYSCALE)
source.set_greyscale(initial(source.greyscale_colors), initial(source.greyscale_config))
if(material_flags & MATERIAL_ADD_PREFIX)
source.name = initial(source.name)
if(beauty_modifier)
source.RemoveElement(/datum/element/beauty, beauty_modifier * amount)
if(isobj(source)) //objs
on_removed_obj(source, amount, material_flags)
if(istype(source, /turf)) //turfs
on_removed_turf(source, amount, material_flags)
///This proc is called when the material is removed from an object specifically.
/datum/material/proc/on_removed_obj(obj/o, amount, material_flags)
if(material_flags & MATERIAL_AFFECT_STATISTICS)
var/new_max_integrity = initial(o.max_integrity)
o.modify_max_integrity(new_max_integrity)
o.force = initial(o.force)
o.throwforce = initial(o.throwforce)
if(isitem(o) && (material_flags & MATERIAL_GREYSCALE))
var/obj/item/item = o
item.set_greyscale(
new_worn_config = initial(item.greyscale_config_worn),
new_inhand_left = initial(item.greyscale_config_inhand_left),
new_inhand_right = initial(item.greyscale_config_inhand_right)
)
/datum/material/proc/on_removed_turf(turf/T, amount, material_flags)
if(alpha < 255)
T.RemoveElement(/datum/element/turf_z_transparency)
// yeets glow
T.UnregisterSignal(SSdcs, COMSIG_STARLIGHT_COLOR_CHANGED)
T.set_light(0, 0, null)
/**
* This proc is called when the mat is found in an item that's consumed by accident. see /obj/item/proc/on_accidental_consumption.
* Arguments
* * M - person consuming the mat
* * S - (optional) item the mat is contained in (NOT the item with the mat itself)
*/
/datum/material/proc/on_accidental_mat_consumption(mob/living/carbon/M, obj/item/S)
return FALSE
/** Returns the composition of this material.
*
* Mostly used for alloys when breaking down materials.
*
* Arguments:
* - amount: The amount of the material to break down.
*/
/datum/material/proc/return_composition(amount = 1)
// Yes we need the parenthesis, without them BYOND stringifies src into "src" and things break.
return list((src) = amount)