/
compass_holder.dm
136 lines (109 loc) · 3.86 KB
/
compass_holder.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
var/global/list/angle_step_to_dir = list(
"N",
"NE",
"E",
"SE",
"S",
"SW",
"W",
"NW",
"N"
)
#define MIN_VIEW 15
/obj/compass_holder
name = null
icon = null
icon_state = null
screen_loc = "CENTER,CENTER"
var/interval_colour = "#7e6f96"
var/bearing_colour = COLOR_WHITE
var/bearing_outline_colour = "#3b2d53"
/// Number of steps/pips between bolded markers on the compass ring.
var/compass_interval = 3
/// Total angle covered by a single span of the compass ring; divided by compass_interval to get individual spans.
var/compass_period = 45
var/list/compass_static_labels
var/list/compass_waypoints
var/list/compass_waypoint_markers
/obj/compass_holder/Initialize(mapload, ...)
. = ..()
rebuild_compass_overlays()
/obj/compass_holder/proc/get_label_offset()
return (world.icon_size * round(MIN_VIEW/2))
/obj/compass_holder/proc/rebuild_compass_overlays()
var/effective_compass_period = compass_period/compass_interval
LAZYCLEARLIST(compass_static_labels)
for(var/i in 0 to (360/effective_compass_period)-1)
var/image/compass_marker/I = new
I.loc = src
if(i % compass_interval == 0)
I.maptext = STYLE_SMALLFONTS_OUTLINE("<center>[get_string_from_angle(i * effective_compass_period)]</center>", 7, bearing_colour, bearing_outline_colour)
else
I.maptext = STYLE_SMALLFONTS("<center>〡</center>", 7, interval_colour)
var/matrix/M = matrix()
M.Translate(0, get_label_offset())
M.Turn(effective_compass_period * i)
I.transform = M
I.filters = filter(type="drop_shadow", color = "#77777777", size = 2, offset = 1,x = 0, y = 0)
I.layer = HUD_BASE_LAYER
I.plane = HUD_PLANE
LAZYADD(compass_static_labels, I)
rebuild_overlay_lists(TRUE)
/obj/compass_holder/proc/get_string_from_angle(angle)
return global.angle_step_to_dir[clamp(round(angle/45)+1, 1, length(global.angle_step_to_dir))]
/obj/compass_holder/Destroy()
QDEL_NULL_ASSOC_LIST(compass_waypoints)
. = ..()
/obj/compass_holder/proc/get_heading_strength()
return 1
/obj/compass_holder/proc/get_heading_angle()
var/atom/A = loc
// Bit of a strange loop - grab the highest atom in our stack that isn't a turf.
while(istype(A) && A.loc && !isturf(A.loc))
A = A.loc
if(istype(A) && !isturf(A))
. = dir2angle(A.dir)
else
. = 0
/obj/compass_holder/on_update_icon()
SetOverlays(compass_static_labels | compass_waypoint_markers)
/obj/compass_holder/proc/clear_waypoint(id)
LAZYREMOVE(compass_waypoints, id)
rebuild_overlay_lists(TRUE)
/obj/compass_holder/proc/set_waypoint(id, label, heading_x, heading_y, heading_z, label_color)
var/datum/compass_waypoint/wp = LAZYACCESS(compass_waypoints, id)
if(!wp)
wp = new /datum/compass_waypoint()
wp.set_values(label, heading_x, heading_y, heading_z, label_color)
LAZYSET(compass_waypoints, id, wp)
rebuild_overlay_lists(TRUE)
/obj/compass_holder/proc/recalculate_heading(rebuild_icon = TRUE)
if(rebuild_icon)
update_icon()
/obj/compass_holder/proc/show_waypoint(id)
var/datum/compass_waypoint/wp = compass_waypoints[id]
wp.hidden = FALSE
/obj/compass_holder/proc/hide_waypoint(id)
var/datum/compass_waypoint/wp = compass_waypoints[id]
wp.hidden = TRUE
/obj/compass_holder/proc/hide_waypoints(rebuild_overlays = FALSE)
for(var/id in compass_waypoints)
hide_waypoint(id)
if(rebuild_overlays)
rebuild_overlay_lists(TRUE)
/obj/compass_holder/proc/get_compass_origin()
return get_turf(src)
/obj/compass_holder/proc/rebuild_overlay_lists(update_icon = FALSE)
compass_waypoint_markers = null
var/turf/T = get_compass_origin()
if(istype(T))
var/translate_val = get_label_offset()
for(var/id in compass_waypoints)
var/datum/compass_waypoint/wp = compass_waypoints[id]
if(should_show(wp))
wp.recalculate_heading(T.x, T.y, translate_val)
LAZYADD(compass_waypoint_markers, wp.compass_overlay)
if(update_icon)
update_icon()
/obj/compass_holder/proc/should_show(datum/compass_waypoint/wp)
return wp && !wp.hidden