forked from ParadiseSS13/Paradise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicon_smoothing.dm
390 lines (343 loc) · 11.2 KB
/
icon_smoothing.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
//generic (by snowflake) tile smoothing code; smooth your icons with this!
/*
Each tile is divided in 4 corners, each corner has an image associated to it; the tile is then overlayed by these 4 images
To use this, just set your atom's 'smooth' var to 1. If your atom can be moved/unanchored, set its 'can_be_unanchored' var to 1.
If you don't want your atom's icon to smooth with anything but atoms of the same type, set the list 'canSmoothWith' to null;
Otherwise, put all types you want the atom icon to smooth with in 'canSmoothWith' INCLUDING THE TYPE OF THE ATOM ITSELF.
Each atom has its own icon file with all the possible corner states. See 'smooth_wall.dmi' for a template.
DIAGONAL SMOOTHING INSTRUCTIONS
To make your atom smooth diagonally you need all the proper icon states (see 'smooth_wall.dmi' for a template) and
to add the 'SMOOTH_DIAGONAL' flag to the atom's smooth var (in addition to either SMOOTH_TRUE or SMOOTH_MORE).
For turfs, what appears under the diagonal corners depends on the turf that was in the same position previously: if you make a wall on
a plating floor, you will see plating under the diagonal wall corner, if it was space, you will see space.
If you wish to map a diagonal wall corner with a fixed underlay, you must configure the turf's 'fixed_underlay' list var, like so:
fixed_underlay = list("icon"='icon_file.dmi', "icon_state"="iconstatename")
A non null 'fixed_underlay' list var will skip copying the previous turf appearance and always use the list. If the list is
not set properly, the underlay will default to regular floor plating.
To see an example of a diagonal wall, see '/turf/simulated/wall/shuttle' and its subtypes.
*/
//Redefinitions of the diagonal directions so they can be stored in one var without conflicts
#define N_NORTH 2
#define N_SOUTH 4
#define N_EAST 16
#define N_WEST 256
#define N_NORTHEAST 32
#define N_NORTHWEST 512
#define N_SOUTHEAST 64
#define N_SOUTHWEST 1024
#define SMOOTH_FALSE 0 //not smooth
#define SMOOTH_TRUE 1 //smooths with exact specified types or just itself
#define SMOOTH_MORE 2 //smooths with all subtypes of specified types or just itself (this value can replace SMOOTH_TRUE)
#define SMOOTH_DIAGONAL 4 //if atom should smooth diagonally, this should be present in 'smooth' var
#define SMOOTH_BORDER 8 //atom will smooth with the borders of the map
#define NULLTURF_BORDER 123456789
#define DEFAULT_UNDERLAY_ICON 'icons/turf/floors.dmi'
#define DEFAULT_UNDERLAY_ICON_STATE "plating"
#define DEFAULT_UNDERLAY_IMAGE image(DEFAULT_UNDERLAY_ICON, DEFAULT_UNDERLAY_ICON_STATE)
/atom/var/smooth = SMOOTH_FALSE
/atom/var/top_left_corner
/atom/var/top_right_corner
/atom/var/bottom_left_corner
/atom/var/bottom_right_corner
/atom/var/list/canSmoothWith = null // TYPE PATHS I CAN SMOOTH WITH~~~~~ If this is null and atom is smooth, it smooths only with itself
/atom/movable/var/can_be_unanchored = FALSE
/turf/var/list/fixed_underlay = null
/proc/calculate_adjacencies(atom/A)
if(!A.loc)
return 0
var/adjacencies = 0
var/atom/movable/AM
if(ismovable(A))
AM = A
if(AM.can_be_unanchored && !AM.anchored)
return 0
for(var/direction in GLOB.cardinal)
AM = find_type_in_direction(A, direction)
if(AM == NULLTURF_BORDER)
if((A.smooth & SMOOTH_BORDER))
adjacencies |= 1 << direction
else if( (AM && !istype(AM)) || (istype(AM) && AM.anchored) )
adjacencies |= 1 << direction
if(adjacencies & N_NORTH)
if(adjacencies & N_WEST)
AM = find_type_in_direction(A, NORTHWEST)
if(AM == NULLTURF_BORDER)
if((A.smooth & SMOOTH_BORDER))
adjacencies |= N_NORTHWEST
else if( (AM && !istype(AM)) || (istype(AM) && AM.anchored) )
adjacencies |= N_NORTHWEST
if(adjacencies & N_EAST)
AM = find_type_in_direction(A, NORTHEAST)
if(AM == NULLTURF_BORDER)
if((A.smooth & SMOOTH_BORDER))
adjacencies |= N_NORTHEAST
else if( (AM && !istype(AM)) || (istype(AM) && AM.anchored) )
adjacencies |= N_NORTHEAST
if(adjacencies & N_SOUTH)
if(adjacencies & N_WEST)
AM = find_type_in_direction(A, SOUTHWEST)
if(AM == NULLTURF_BORDER)
if((A.smooth & SMOOTH_BORDER))
adjacencies |= N_SOUTHWEST
else if( (AM && !istype(AM)) || (istype(AM) && AM.anchored) )
adjacencies |= N_SOUTHWEST
if(adjacencies & N_EAST)
AM = find_type_in_direction(A, SOUTHEAST)
if(AM == NULLTURF_BORDER)
if((A.smooth & SMOOTH_BORDER))
adjacencies |= N_SOUTHEAST
else if( (AM && !istype(AM)) || (istype(AM) && AM.anchored) )
adjacencies |= N_SOUTHEAST
return adjacencies
//do not use, use queue_smooth(atom)
/proc/smooth_icon(atom/A)
if(!A || !A.smooth || !A.z)
return
if(QDELETED(A))
return
if(A.smooth & (SMOOTH_TRUE | SMOOTH_MORE))
var/adjacencies = calculate_adjacencies(A)
if(A.smooth & SMOOTH_DIAGONAL)
A.diagonal_smooth(adjacencies)
else
cardinal_smooth(A, adjacencies)
/atom/proc/diagonal_smooth(adjacencies)
switch(adjacencies)
if(N_NORTH|N_WEST)
replace_smooth_overlays("d-se","d-se-0")
if(N_NORTH|N_EAST)
replace_smooth_overlays("d-sw","d-sw-0")
if(N_SOUTH|N_WEST)
replace_smooth_overlays("d-ne","d-ne-0")
if(N_SOUTH|N_EAST)
replace_smooth_overlays("d-nw","d-nw-0")
if(N_NORTH|N_WEST|N_NORTHWEST)
replace_smooth_overlays("d-se","d-se-1")
if(N_NORTH|N_EAST|N_NORTHEAST)
replace_smooth_overlays("d-sw","d-sw-1")
if(N_SOUTH|N_WEST|N_SOUTHWEST)
replace_smooth_overlays("d-ne","d-ne-1")
if(N_SOUTH|N_EAST|N_SOUTHEAST)
replace_smooth_overlays("d-nw","d-nw-1")
else
cardinal_smooth(src, adjacencies)
return
icon_state = ""
return adjacencies
//only walls should have a need to handle underlays
/turf/simulated/wall/diagonal_smooth(adjacencies)
adjacencies = reverse_ndir(..())
if(adjacencies)
var/mutable_appearance/underlay_appearance = mutable_appearance(layer = TURF_LAYER, plane = FLOOR_PLANE)
var/list/U = list(underlay_appearance)
if(fixed_underlay)
if(fixed_underlay["space"])
underlay_appearance.icon = 'icons/turf/space.dmi'
underlay_appearance.icon_state = SPACE_ICON_STATE
underlay_appearance.plane = PLANE_SPACE
else
underlay_appearance.icon = fixed_underlay["icon"]
underlay_appearance.icon_state = fixed_underlay["icon_state"]
else
var/turned_adjacency = turn(adjacencies, 180)
var/turf/T = get_step(src, turned_adjacency)
if(!T.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency))
T = get_step(src, turn(adjacencies, 135))
if(!T.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency))
T = get_step(src, turn(adjacencies, 225))
//if all else fails, ask our own turf
if(!T.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency) && !get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency))
underlay_appearance.icon = DEFAULT_UNDERLAY_ICON
underlay_appearance.icon_state = DEFAULT_UNDERLAY_ICON_STATE
underlays = U
// Drop posters which were previously placed on this wall.
for(var/obj/structure/sign/poster/P in src)
P.roll_and_drop(src)
/proc/cardinal_smooth(atom/A, adjacencies)
//NW CORNER
var/nw = "1-i"
if((adjacencies & N_NORTH) && (adjacencies & N_WEST))
if(adjacencies & N_NORTHWEST)
nw = "1-f"
else
nw = "1-nw"
else
if(adjacencies & N_NORTH)
nw = "1-n"
else if(adjacencies & N_WEST)
nw = "1-w"
//NE CORNER
var/ne = "2-i"
if((adjacencies & N_NORTH) && (adjacencies & N_EAST))
if(adjacencies & N_NORTHEAST)
ne = "2-f"
else
ne = "2-ne"
else
if(adjacencies & N_NORTH)
ne = "2-n"
else if(adjacencies & N_EAST)
ne = "2-e"
//SW CORNER
var/sw = "3-i"
if((adjacencies & N_SOUTH) && (adjacencies & N_WEST))
if(adjacencies & N_SOUTHWEST)
sw = "3-f"
else
sw = "3-sw"
else
if(adjacencies & N_SOUTH)
sw = "3-s"
else if(adjacencies & N_WEST)
sw = "3-w"
//SE CORNER
var/se = "4-i"
if((adjacencies & N_SOUTH) && (adjacencies & N_EAST))
if(adjacencies & N_SOUTHEAST)
se = "4-f"
else
se = "4-se"
else
if(adjacencies & N_SOUTH)
se = "4-s"
else if(adjacencies & N_EAST)
se = "4-e"
var/list/New = list()
if(A.top_left_corner != nw)
A.overlays -= A.top_left_corner
A.top_left_corner = nw
New += nw
if(A.top_right_corner != ne)
A.overlays -= A.top_right_corner
A.top_right_corner = ne
New += ne
if(A.bottom_right_corner != sw)
A.overlays -= A.bottom_right_corner
A.bottom_right_corner = sw
New += sw
if(A.bottom_left_corner != se)
A.overlays -= A.bottom_left_corner
A.bottom_left_corner = se
New += se
if(New.len)
A.overlays.Add(New)
/proc/find_type_in_direction(atom/source, direction)
var/turf/target_turf = get_step(source, direction)
if(!target_turf)
return NULLTURF_BORDER
if(source.canSmoothWith)
var/atom/A
if(source.smooth & SMOOTH_MORE)
for(var/a_type in source.canSmoothWith)
if( istype(target_turf, a_type) )
return target_turf
A = locate(a_type) in target_turf
if(A)
return A
return null
for(var/a_type in source.canSmoothWith)
if(a_type == target_turf.type)
return target_turf
A = locate(a_type) in target_turf
if(A && A.type == a_type)
return A
return null
else
if(isturf(source))
return source.type == target_turf.type ? target_turf : null
var/atom/A = locate(source.type) in target_turf
return A && A.type == source.type ? A : null
//Icon smoothing helpers
/proc/smooth_zlevel(zlevel, now = FALSE)
var/list/away_turfs = block(locate(1, 1, zlevel), locate(world.maxx, world.maxy, zlevel))
for(var/V in away_turfs)
var/turf/T = V
if(T.smooth)
if(now)
smooth_icon(T)
else
queue_smooth(T)
for(var/R in T)
var/atom/A = R
if(A.smooth)
if(now)
smooth_icon(A)
else
queue_smooth(A)
/atom/proc/clear_smooth_overlays()
overlays -= top_left_corner
top_left_corner = null
overlays -= top_right_corner
top_right_corner = null
overlays -= bottom_right_corner
bottom_right_corner = null
overlays -= bottom_left_corner
bottom_left_corner = null
/atom/proc/replace_smooth_overlays(nw, ne, sw, se)
clear_smooth_overlays()
var/list/O = list()
top_left_corner = nw
O += nw
top_right_corner = ne
O += ne
bottom_left_corner = sw
O += sw
bottom_right_corner = se
O += se
overlays.Add(O)
/proc/reverse_ndir(ndir)
switch(ndir)
if(N_NORTH)
return NORTH
if(N_SOUTH)
return SOUTH
if(N_WEST)
return WEST
if(N_EAST)
return EAST
if(N_NORTHWEST)
return NORTHWEST
if(N_NORTHEAST)
return NORTHEAST
if(N_SOUTHEAST)
return SOUTHEAST
if(N_SOUTHWEST)
return SOUTHWEST
if(N_NORTH|N_WEST)
return NORTHWEST
if(N_NORTH|N_EAST)
return NORTHEAST
if(N_SOUTH|N_WEST)
return SOUTHWEST
if(N_SOUTH|N_EAST)
return SOUTHEAST
if(N_NORTH|N_WEST|N_NORTHWEST)
return NORTHWEST
if(N_NORTH|N_EAST|N_NORTHEAST)
return NORTHEAST
if(N_SOUTH|N_WEST|N_SOUTHWEST)
return SOUTHWEST
if(N_SOUTH|N_EAST|N_SOUTHEAST)
return SOUTHEAST
else
return 0
//SSicon_smooth
/proc/queue_smooth_neighbors(atom/A)
for(var/V in orange(1,A))
var/atom/T = V
if(T.smooth)
queue_smooth(T)
//SSicon_smooth
/proc/queue_smooth(atom/A)
if(SSicon_smooth)
SSicon_smooth.smooth_queue[A] = A
SSicon_smooth.can_fire = 1
else
smooth_icon(A)
//Example smooth wall
/turf/simulated/wall/smooth
name = "smooth wall"
icon = 'icons/turf/smooth_wall.dmi'
icon_state = "smooth"
smooth = SMOOTH_TRUE|SMOOTH_DIAGONAL|SMOOTH_BORDER
canSmoothWith = null