/
icon_smoothing.dm
673 lines (574 loc) · 22.6 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
//generic (by snowflake) tile smoothing code; smooth your icons with this!
/*
Each tile is divided in 4 corners, each corner has an appearance associated to it; the tile is then overlayed by these 4 appearances
To use this, just set your atom's 'smoothing_flags' 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 the smoothing groups you want the atom icon to smooth with in 'canSmoothWith', including the group of the atom itself.
Smoothing groups are just shared flags between objects. If one of the 'canSmoothWith' of A matches one of the `smoothing_groups` of B, then A will smooth with B.
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_CORNERS' flag to the atom's smoothing_flags 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/closed/wall/mineral/titanium' and its subtypes.
*/
#define NO_ADJ_FOUND 0
#define ADJ_FOUND 1
#define NULLTURF_BORDER 2
GLOBAL_LIST_INIT(adjacent_direction_lookup, generate_adjacent_directions())
/* Attempting to mirror the below
* Each 3x3 grid is a tile, with each X representing a direction a border object could be in IN said grid
* Directions marked with A are acceptable smoothing targets, M is the example direction
* The example given here is of a northfacing border object
xxx AxA xxx
xxx AxA xxx
xxx AxA xxx
AAA MMM AAA
xxx AxA xxx
xxx AxA xxx
xxx xxx xxx
xxx xxx xxx
xxx xxx xxx
*/
/// Encodes connectivity between border objects
/// Returns a list accessable by a border object's dir, the direction between it and a target, and a target
/// Said list will return the direction the two objects connect, if any exists (if the target isn't a border object and the direction is fine, return the inverse of the direction in use)
/proc/generate_adjacent_directions()
// Have to hold all conventional dir pairs, so we size to the largest
// We don't HAVE diagonal border objects, so I'm gonna pretend they'll never exist
// You might be like, lemon, can't we use GLOB.cardinals/GLOB.alldirs here
// No, they aren't loaded yet. life is pain
var/list/cardinals = list(NORTH, SOUTH, EAST, WEST)
var/list/alldirs = cardinals + list(NORTH|EAST, SOUTH|EAST, NORTH|WEST, SOUTH|WEST)
var/largest_cardinal = max(cardinals)
var/largest_dir = max(alldirs)
var/list/direction_map = new /list(largest_cardinal)
for(var/dir in cardinals)
var/left = turn(dir, 90)
var/right = turn(dir, -90)
var/opposite = REVERSE_DIR(dir)
// Need to encode diagonals here because it's possible, even if it is always false
var/list/acceptable_adjacents = new /list(largest_dir)
// Alright, what directions are acceptable to us
for(var/connectable_dir in (cardinals + NONE))
// And what border objects INSIDE those directions are alright
var/list/smoothable_dirs = new /list(largest_cardinal + 1) // + 1 because we need to provide space for NONE to be a valid index
// None is fine, we want to smooth with things on our own turf
// We'll do the two dirs to our left and right
// They connect.. "below" us and on their side
if(connectable_dir == NONE)
smoothable_dirs[left] = dir_to_junction(opposite | left)
smoothable_dirs[right] = dir_to_junction(opposite | right)
// If it's to our right or left we'll include just the dir matching ours
// Left edge touches only our left side, and so on
else if (connectable_dir == left)
smoothable_dirs[dir] = left
else if (connectable_dir == right)
smoothable_dirs[dir] = right
// If it's straight on we'll include our direction as a link
// Then include the two edges on the other side as diagonals
else if(connectable_dir == dir)
smoothable_dirs[opposite] = dir
smoothable_dirs[left] = dir_to_junction(dir | left)
smoothable_dirs[right] = dir_to_junction(dir | right)
// otherwise, go HOME, I don't want to encode anything for you
else
continue
acceptable_adjacents[connectable_dir + 1] = smoothable_dirs
direction_map[dir] = acceptable_adjacents
return direction_map
/// Are two atoms border adjacent, takes a border object, something to compare against, and the direction between A and B
/// Returns the way in which the first thing is adjacent to the second
#define CAN_DIAGONAL_SMOOTH(border_obj, target, direction) (\
(target.smoothing_flags & SMOOTH_BORDER_OBJECT) ? \
GLOB.adjacent_direction_lookup[border_obj.dir][direction + 1]?[target.dir] : \
(GLOB.adjacent_direction_lookup[border_obj.dir][direction + 1]) ? REVERSE_DIR(direction) : NONE \
)
#define DEFAULT_UNDERLAY_ICON 'icons/turf/floors.dmi'
#define DEFAULT_UNDERLAY_ICON_STATE "plating"
///Scans all adjacent turfs to find targets to smooth with.
/atom/proc/calculate_adjacencies()
. = NONE
if(!loc)
return
for(var/direction in GLOB.cardinals)
switch(find_type_in_direction(direction))
if(NULLTURF_BORDER)
if((smoothing_flags & SMOOTH_BORDER))
. |= direction //BYOND and smooth dirs are the same for cardinals
if(ADJ_FOUND)
. |= direction //BYOND and smooth dirs are the same for cardinals
if(. & NORTH_JUNCTION)
if(. & WEST_JUNCTION)
switch(find_type_in_direction(NORTHWEST))
if(NULLTURF_BORDER)
if((smoothing_flags & SMOOTH_BORDER))
. |= NORTHWEST_JUNCTION
if(ADJ_FOUND)
. |= NORTHWEST_JUNCTION
if(. & EAST_JUNCTION)
switch(find_type_in_direction(NORTHEAST))
if(NULLTURF_BORDER)
if((smoothing_flags & SMOOTH_BORDER))
. |= NORTHEAST_JUNCTION
if(ADJ_FOUND)
. |= NORTHEAST_JUNCTION
if(. & SOUTH_JUNCTION)
if(. & WEST_JUNCTION)
switch(find_type_in_direction(SOUTHWEST))
if(NULLTURF_BORDER)
if((smoothing_flags & SMOOTH_BORDER))
. |= SOUTHWEST_JUNCTION
if(ADJ_FOUND)
. |= SOUTHWEST_JUNCTION
if(. & EAST_JUNCTION)
switch(find_type_in_direction(SOUTHEAST))
if(NULLTURF_BORDER)
if((smoothing_flags & SMOOTH_BORDER))
. |= SOUTHEAST_JUNCTION
if(ADJ_FOUND)
. |= SOUTHEAST_JUNCTION
/atom/movable/calculate_adjacencies()
if(can_be_unanchored && !anchored)
return NONE
return ..()
///do not use, use QUEUE_SMOOTH(atom)
/atom/proc/smooth_icon()
if(QDELETED(src))
return
smoothing_flags &= ~SMOOTH_QUEUED
flags_1 |= HTML_USE_INITAL_ICON_1
if (!z)
CRASH("[type] called smooth_icon() without being on a z-level")
if(smoothing_flags & SMOOTH_CORNERS)
if(smoothing_flags & SMOOTH_DIAGONAL_CORNERS)
corners_diagonal_smooth(calculate_adjacencies())
else
corners_cardinal_smooth(calculate_adjacencies())
else if(smoothing_flags & SMOOTH_BITMASK)
bitmask_smooth()
else
CRASH("smooth_icon called for [src] with smoothing_flags == [smoothing_flags]")
SEND_SIGNAL(src, COMSIG_ATOM_SMOOTHED_ICON)
// As a rule, movables will most always care about smoothing changes
// Turfs on the other hand, don't, so we don't do the update for THEM unless they explicitly request it
/atom/movable/smooth_icon()
. = ..()
update_appearance(~UPDATE_SMOOTHING)
/atom/proc/corners_diagonal_smooth(adjacencies)
switch(adjacencies)
if(NORTH_JUNCTION|WEST_JUNCTION)
replace_smooth_overlays("d-se","d-se-0")
if(NORTH_JUNCTION|EAST_JUNCTION)
replace_smooth_overlays("d-sw","d-sw-0")
if(SOUTH_JUNCTION|WEST_JUNCTION)
replace_smooth_overlays("d-ne","d-ne-0")
if(SOUTH_JUNCTION|EAST_JUNCTION)
replace_smooth_overlays("d-nw","d-nw-0")
if(NORTH_JUNCTION|WEST_JUNCTION|NORTHWEST_JUNCTION)
replace_smooth_overlays("d-se","d-se-1")
if(NORTH_JUNCTION|EAST_JUNCTION|NORTHEAST_JUNCTION)
replace_smooth_overlays("d-sw","d-sw-1")
if(SOUTH_JUNCTION|WEST_JUNCTION|SOUTHWEST_JUNCTION)
replace_smooth_overlays("d-ne","d-ne-1")
if(SOUTH_JUNCTION|EAST_JUNCTION|SOUTHEAST_JUNCTION)
replace_smooth_overlays("d-nw","d-nw-1")
else
corners_cardinal_smooth(adjacencies)
return FALSE
icon_state = ""
return TRUE
/atom/proc/corners_cardinal_smooth(adjacencies)
var/mutable_appearance/temp_ma
//NW CORNER
var/nw = "1-i"
if((adjacencies & NORTH_JUNCTION) && (adjacencies & WEST_JUNCTION))
if(adjacencies & NORTHWEST_JUNCTION)
nw = "1-f"
else
nw = "1-nw"
else
if(adjacencies & NORTH_JUNCTION)
nw = "1-n"
else if(adjacencies & WEST_JUNCTION)
nw = "1-w"
temp_ma = mutable_appearance(icon, nw)
nw = temp_ma.appearance
//NE CORNER
var/ne = "2-i"
if((adjacencies & NORTH_JUNCTION) && (adjacencies & EAST_JUNCTION))
if(adjacencies & NORTHEAST_JUNCTION)
ne = "2-f"
else
ne = "2-ne"
else
if(adjacencies & NORTH_JUNCTION)
ne = "2-n"
else if(adjacencies & EAST_JUNCTION)
ne = "2-e"
temp_ma = mutable_appearance(icon, ne)
ne = temp_ma.appearance
//SW CORNER
var/sw = "3-i"
if((adjacencies & SOUTH_JUNCTION) && (adjacencies & WEST_JUNCTION))
if(adjacencies & SOUTHWEST_JUNCTION)
sw = "3-f"
else
sw = "3-sw"
else
if(adjacencies & SOUTH_JUNCTION)
sw = "3-s"
else if(adjacencies & WEST_JUNCTION)
sw = "3-w"
temp_ma = mutable_appearance(icon, sw)
sw = temp_ma.appearance
//SE CORNER
var/se = "4-i"
if((adjacencies & SOUTH_JUNCTION) && (adjacencies & EAST_JUNCTION))
if(adjacencies & SOUTHEAST_JUNCTION)
se = "4-f"
else
se = "4-se"
else
if(adjacencies & SOUTH_JUNCTION)
se = "4-s"
else if(adjacencies & EAST_JUNCTION)
se = "4-e"
temp_ma = mutable_appearance(icon, se)
se = temp_ma.appearance
var/list/new_overlays
if(top_left_corner != nw)
cut_overlay(top_left_corner)
top_left_corner = nw
LAZYADD(new_overlays, nw)
if(top_right_corner != ne)
cut_overlay(top_right_corner)
top_right_corner = ne
LAZYADD(new_overlays, ne)
if(bottom_right_corner != sw)
cut_overlay(bottom_right_corner)
bottom_right_corner = sw
LAZYADD(new_overlays, sw)
if(bottom_left_corner != se)
cut_overlay(bottom_left_corner)
bottom_left_corner = se
LAZYADD(new_overlays, se)
if(new_overlays)
add_overlay(new_overlays)
///Scans direction to find targets to smooth with.
/atom/proc/find_type_in_direction(direction)
var/turf/target_turf = get_step(src, direction)
if(!target_turf)
return NULLTURF_BORDER
var/area/target_area = get_area(target_turf)
var/area/source_area = get_area(src)
if((source_area.area_limited_icon_smoothing && !istype(target_area, source_area.area_limited_icon_smoothing)) || (target_area.area_limited_icon_smoothing && !istype(source_area, target_area.area_limited_icon_smoothing)))
return NO_ADJ_FOUND
if(isnull(canSmoothWith)) //special case in which it will only smooth with itself
if(isturf(src))
return (type == target_turf.type) ? ADJ_FOUND : NO_ADJ_FOUND
var/atom/matching_obj = locate(type) in target_turf
return (matching_obj && matching_obj.type == type) ? ADJ_FOUND : NO_ADJ_FOUND
if(!isnull(target_turf.smoothing_groups))
for(var/target in canSmoothWith)
if(!(canSmoothWith[target] & target_turf.smoothing_groups[target]))
continue
return ADJ_FOUND
if(smoothing_flags & SMOOTH_OBJ)
for(var/atom/movable/thing as anything in target_turf)
if(!thing.anchored || isnull(thing.smoothing_groups))
continue
for(var/target in canSmoothWith)
if(!(canSmoothWith[target] & thing.smoothing_groups[target]))
continue
return ADJ_FOUND
return NO_ADJ_FOUND
/**
* Basic smoothing proc. The atom checks for adjacent directions to smooth with and changes the icon_state based on that.
*
* Returns the previous smoothing_junction state so the previous state can be compared with the new one after the proc ends, and see the changes, if any.
*
*/
/atom/proc/bitmask_smooth()
var/new_junction = NONE
// cache for sanic speed
var/canSmoothWith = src.canSmoothWith
var/smooth_border = (smoothing_flags & SMOOTH_BORDER)
var/smooth_obj = (smoothing_flags & SMOOTH_OBJ)
var/border_object_smoothing = (smoothing_flags & SMOOTH_BORDER_OBJECT)
// Did you know you can pass defines into other defines? very handy, lets take advantage of it here to allow 0 cost variation
#define SEARCH_ADJ_IN_DIR(direction, direction_flag, ADJ_FOUND, WORLD_BORDER, BORDER_CHECK) \
do { \
var/turf/neighbor = get_step(src, direction); \
if(neighbor && ##BORDER_CHECK(neighbor, direction)) { \
var/neighbor_smoothing_groups = neighbor.smoothing_groups; \
if(neighbor_smoothing_groups) { \
for(var/target in canSmoothWith) { \
if(canSmoothWith[target] & neighbor_smoothing_groups[target]) { \
##ADJ_FOUND(neighbor, direction, direction_flag); \
} \
} \
} \
if(smooth_obj) { \
for(var/atom/movable/thing as anything in neighbor) { \
var/thing_smoothing_groups = thing.smoothing_groups; \
if(!thing.anchored || isnull(thing_smoothing_groups) || !##BORDER_CHECK(thing, direction)) { \
continue; \
}; \
for(var/target in canSmoothWith) { \
if(canSmoothWith[target] & thing_smoothing_groups[target]) { \
##ADJ_FOUND(thing, direction, direction_flag); \
} \
} \
} \
} \
} else if (smooth_border) { \
##WORLD_BORDER(null, direction, direction_flag); \
} \
} while(FALSE) \
#define BITMASK_FOUND(target, direction, direction_flag) \
new_junction |= direction_flag; \
break set_adj_in_dir; \
/// Check that non border objects use to smooth against border objects
/// Returns true if the smooth is acceptable, FALSE otherwise
#define BITMASK_ON_BORDER_CHECK(target, direction) (!(target.smoothing_flags & SMOOTH_BORDER_OBJECT) || CAN_DIAGONAL_SMOOTH(target, src, REVERSE_DIR(direction)))
#define BORDER_FOUND(target, direction, direction_flag) new_junction |= CAN_DIAGONAL_SMOOTH(src, target, direction)
// Border objects require an object as context, so we need a dummy. I'm sorry
#define WORLD_BORDER_FOUND(target, direction, direction_flag) \
var/static/atom/dummy; \
if(!dummy) { \
dummy = new(); \
dummy.smoothing_flags &= ~SMOOTH_BORDER_OBJECT; \
} \
BORDER_FOUND(dummy, direction, direction_flag);
// Handle handle border on border checks. no-op, we handle this check inside CAN_DIAGONAL_SMOOTH
#define BORDER_ON_BORDER_CHECK(target, direction) (TRUE)
// We're building 2 different types of smoothing searches here
// One for standard bitmask smoothing (We provide a label so our macro can eary exit, as it wants to do)
#define SET_ADJ_IN_DIR(direction, direction_flag) do { set_adj_in_dir: { SEARCH_ADJ_IN_DIR(direction, direction_flag, BITMASK_FOUND, BITMASK_FOUND, BITMASK_ON_BORDER_CHECK) }} while(FALSE)
// and another for border object work (Doesn't early exit because we can hit more then one direction by checking the same turf)
#define SET_BORDER_ADJ_IN_DIR(direction) SEARCH_ADJ_IN_DIR(direction, direction, BORDER_FOUND, WORLD_BORDER_FOUND, BORDER_ON_BORDER_CHECK)
// Let's go over all our cardinals
if(border_object_smoothing)
SET_BORDER_ADJ_IN_DIR(NORTH)
SET_BORDER_ADJ_IN_DIR(SOUTH)
SET_BORDER_ADJ_IN_DIR(EAST)
SET_BORDER_ADJ_IN_DIR(WEST)
// We want to check against stuff in our own turf
SET_BORDER_ADJ_IN_DIR(NONE)
// Border objects don't do diagonals, so GO HOME
set_smoothed_icon_state(new_junction)
return
SET_ADJ_IN_DIR(NORTH, NORTH)
SET_ADJ_IN_DIR(SOUTH, SOUTH)
SET_ADJ_IN_DIR(EAST, EAST)
SET_ADJ_IN_DIR(WEST, WEST)
// If there's nothing going on already
if(!(new_junction & (NORTH|SOUTH)) || !(new_junction & (EAST|WEST)))
set_smoothed_icon_state(new_junction)
return
if(new_junction & NORTH_JUNCTION)
if(new_junction & WEST_JUNCTION)
SET_ADJ_IN_DIR(NORTHWEST, NORTHWEST_JUNCTION)
if(new_junction & EAST_JUNCTION)
SET_ADJ_IN_DIR(NORTHEAST, NORTHEAST_JUNCTION)
if(new_junction & SOUTH_JUNCTION)
if(new_junction & WEST_JUNCTION)
SET_ADJ_IN_DIR(SOUTHWEST, SOUTHWEST_JUNCTION)
if(new_junction & EAST_JUNCTION)
SET_ADJ_IN_DIR(SOUTHEAST, SOUTHEAST_JUNCTION)
set_smoothed_icon_state(new_junction)
#undef SET_BORDER_ADJ_IN_DIR
#undef SET_ADJ_IN_DIR
#undef BORDER_ON_BORDER_CHECK
#undef WORLD_BORDER_FOUND
#undef BORDER_FOUND
#undef BITMASK_ON_BORDER_CHECK
#undef BITMASK_FOUND
#undef SEARCH_ADJ_IN_DIR
///Changes the icon state based on the new junction bitmask
/atom/proc/set_smoothed_icon_state(new_junction)
. = smoothing_junction
smoothing_junction = new_junction
icon_state = "[base_icon_state]-[smoothing_junction]"
/turf/closed/set_smoothed_icon_state(new_junction)
// Avoid calling ..() here to avoid setting icon_state twice, which is expensive given how hot this proc is
var/old_junction = smoothing_junction
smoothing_junction = new_junction
if (!(smoothing_flags & SMOOTH_DIAGONAL_CORNERS))
icon_state = "[base_icon_state]-[smoothing_junction]"
return
switch(new_junction)
if(
NORTH_JUNCTION|WEST_JUNCTION,
NORTH_JUNCTION|EAST_JUNCTION,
SOUTH_JUNCTION|WEST_JUNCTION,
SOUTH_JUNCTION|EAST_JUNCTION,
NORTH_JUNCTION|WEST_JUNCTION|NORTHWEST_JUNCTION,
NORTH_JUNCTION|EAST_JUNCTION|NORTHEAST_JUNCTION,
SOUTH_JUNCTION|WEST_JUNCTION|SOUTHWEST_JUNCTION,
SOUTH_JUNCTION|EAST_JUNCTION|SOUTHEAST_JUNCTION,
)
icon_state = "[base_icon_state]-[smoothing_junction]-d"
if(new_junction == old_junction || fixed_underlay) // Mutable underlays?
return
var/junction_dir = reverse_ndir(smoothing_junction)
var/turned_adjacency = REVERSE_DIR(junction_dir)
var/turf/neighbor_turf = get_step(src, turned_adjacency & (NORTH|SOUTH))
var/mutable_appearance/underlay_appearance = mutable_appearance(layer = TURF_LAYER, offset_spokesman = src, plane = FLOOR_PLANE)
if(!neighbor_turf.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency))
neighbor_turf = get_step(src, turned_adjacency & (EAST|WEST))
if(!neighbor_turf.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency))
neighbor_turf = get_step(src, turned_adjacency)
if(!neighbor_turf.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency))
if(!get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency)) //if all else fails, ask our own turf
underlay_appearance.icon = DEFAULT_UNDERLAY_ICON
underlay_appearance.icon_state = DEFAULT_UNDERLAY_ICON_STATE
underlays += underlay_appearance
else
icon_state = "[base_icon_state]-[smoothing_junction]"
/turf/open/floor/set_smoothed_icon_state(new_junction)
if(broken || burnt)
return
return ..()
//Icon smoothing helpers
/proc/smooth_zlevel(zlevel, now = FALSE)
var/list/away_turfs = Z_TURFS(zlevel)
for(var/turf/turf_to_smooth as anything in away_turfs)
if(turf_to_smooth.smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(now)
turf_to_smooth.smooth_icon()
else
QUEUE_SMOOTH(turf_to_smooth)
for(var/atom/movable/movable_to_smooth as anything in turf_to_smooth)
if(movable_to_smooth.smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(now)
movable_to_smooth.smooth_icon()
else
QUEUE_SMOOTH(movable_to_smooth)
/atom/proc/clear_smooth_overlays()
cut_overlay(top_left_corner)
top_left_corner = null
cut_overlay(top_right_corner)
top_right_corner = null
cut_overlay(bottom_right_corner)
bottom_right_corner = null
cut_overlay(bottom_left_corner)
bottom_left_corner = null
/// Internal: Takes icon states as text to replace smoothing corner overlays
/atom/proc/replace_smooth_overlays(nw, ne, sw, se)
clear_smooth_overlays()
var/mutable_appearance/temp_ma
temp_ma = mutable_appearance(icon, nw)
nw = temp_ma.appearance
temp_ma = mutable_appearance(icon, ne)
ne = temp_ma.appearance
temp_ma = mutable_appearance(icon, sw)
sw = temp_ma.appearance
temp_ma = mutable_appearance(icon, se)
se = temp_ma.appearance
var/list/new_overlays = list()
top_left_corner = nw
new_overlays += nw
top_right_corner = ne
new_overlays += ne
bottom_left_corner = sw
new_overlays += sw
bottom_right_corner = se
new_overlays += se
add_overlay(new_overlays)
/// Takes a direction, turns it into all the junctions that contain it
/proc/dir_to_all_junctions(dir)
var/handback = NONE
if(dir & NORTH)
handback |= NORTH_JUNCTION | NORTHEAST_JUNCTION | NORTHWEST_JUNCTION
if(dir & SOUTH)
handback |= SOUTH_JUNCTION | SOUTHEAST_JUNCTION | SOUTHWEST_JUNCTION
if(dir & EAST)
handback |= EAST_JUNCTION | SOUTHEAST_JUNCTION | NORTHEAST_JUNCTION
if(dir & WEST)
handback |= WEST_JUNCTION | NORTHWEST_JUNCTION | SOUTHWEST_JUNCTION
return handback
/proc/dir_to_junction(dir)
switch(dir)
if(NORTH)
return NORTH_JUNCTION
if(SOUTH)
return SOUTH_JUNCTION
if(WEST)
return WEST_JUNCTION
if(EAST)
return EAST_JUNCTION
if(NORTHWEST)
return NORTHWEST_JUNCTION
if(NORTHEAST)
return NORTHEAST_JUNCTION
if(SOUTHEAST)
return SOUTHEAST_JUNCTION
if(SOUTHWEST)
return SOUTHWEST_JUNCTION
else
return NONE
/proc/reverse_ndir(ndir)
switch(ndir)
if(NORTH_JUNCTION)
return NORTH
if(SOUTH_JUNCTION)
return SOUTH
if(WEST_JUNCTION)
return WEST
if(EAST_JUNCTION)
return EAST
if(NORTHWEST_JUNCTION)
return NORTHWEST
if(NORTHEAST_JUNCTION)
return NORTHEAST
if(SOUTHEAST_JUNCTION)
return SOUTHEAST
if(SOUTHWEST_JUNCTION)
return SOUTHWEST
if(NORTH_JUNCTION | WEST_JUNCTION)
return NORTHWEST
if(NORTH_JUNCTION | EAST_JUNCTION)
return NORTHEAST
if(SOUTH_JUNCTION | WEST_JUNCTION)
return SOUTHWEST
if(SOUTH_JUNCTION | EAST_JUNCTION)
return SOUTHEAST
if(NORTH_JUNCTION | WEST_JUNCTION | NORTHWEST_JUNCTION)
return NORTHWEST
if(NORTH_JUNCTION | EAST_JUNCTION | NORTHEAST_JUNCTION)
return NORTHEAST
if(SOUTH_JUNCTION | WEST_JUNCTION | SOUTHWEST_JUNCTION)
return SOUTHWEST
if(SOUTH_JUNCTION | EAST_JUNCTION | SOUTHEAST_JUNCTION)
return SOUTHEAST
else
return NONE
//Example smooth wall
/turf/closed/wall/smooth
name = "smooth wall"
icon = 'icons/turf/smooth_wall.dmi'
icon_state = "smooth"
smoothing_flags = SMOOTH_CORNERS|SMOOTH_DIAGONAL_CORNERS|SMOOTH_BORDER
smoothing_groups = null
canSmoothWith = null
#undef NORTH_JUNCTION
#undef SOUTH_JUNCTION
#undef EAST_JUNCTION
#undef WEST_JUNCTION
#undef NORTHEAST_JUNCTION
#undef NORTHWEST_JUNCTION
#undef SOUTHEAST_JUNCTION
#undef SOUTHWEST_JUNCTION
#undef NO_ADJ_FOUND
#undef ADJ_FOUND
#undef NULLTURF_BORDER
#undef DEFAULT_UNDERLAY_ICON
#undef DEFAULT_UNDERLAY_ICON_STATE
#undef CAN_DIAGONAL_SMOOTH