-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathhide_weather_planes.dm
136 lines (115 loc) · 4.95 KB
/
hide_weather_planes.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
/**
* Component that manages a list of plane masters that are dependent on weather
* Force hides/shows them depending on the weather activity of their z stack
* Transparency is achieved by manipulating the alpha of the planes that are visible
* Applied to the plane master group that owns them
*/
/datum/component/hide_weather_planes
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
var/list/datum/weather/active_weather = list()
var/list/atom/movable/screen/plane_master/plane_masters = list()
/datum/component/hide_weather_planes/Initialize(atom/movable/screen/plane_master/care_about)
if(!istype(parent, /datum/plane_master_group))
return COMPONENT_INCOMPATIBLE
var/datum/plane_master_group/home = parent
plane_masters += care_about
RegisterSignal(care_about, COMSIG_QDELETING, PROC_REF(plane_master_deleted))
var/list/starting_signals = list()
var/list/ending_signals = list()
for(var/datum/weather/weather_type as anything in typesof(/datum/weather))
starting_signals += COMSIG_WEATHER_TELEGRAPH(weather_type)
ending_signals += COMSIG_WEATHER_END(weather_type)
RegisterSignals(SSdcs, starting_signals, PROC_REF(weather_started))
RegisterSignals(SSdcs, ending_signals, PROC_REF(weather_finished))
if(home.our_hud)
attach_hud(home.our_hud)
else
RegisterSignal(home, COMSIG_GROUP_HUD_CHANGED, PROC_REF(new_hud_attached))
/datum/component/hide_weather_planes/Destroy(force)
hide_planes()
active_weather = null
plane_masters = null
return ..()
/datum/component/hide_weather_planes/InheritComponent(datum/component/new_comp, i_am_original, atom/movable/screen/plane_master/care_about)
if(!i_am_original)
return
var/datum/plane_master_group/home = parent
var/mob/our_lad = home.our_hud?.mymob
var/our_offset = GET_TURF_PLANE_OFFSET(our_lad)
plane_masters += care_about
RegisterSignal(care_about, COMSIG_QDELETING, PROC_REF(plane_master_deleted))
if(length(active_weather))
//If there's weather to care about we unhide our new plane and adjust its alpha
care_about.unhide_plane(our_lad)
if(care_about.offset >= our_offset)
care_about.enable_alpha()
else
care_about.disable_alpha()
else
care_about.hide_plane(our_lad)
/datum/component/hide_weather_planes/proc/new_hud_attached(datum/source, datum/hud/new_hud)
SIGNAL_HANDLER
attach_hud(new_hud)
/datum/component/hide_weather_planes/proc/attach_hud(datum/hud/new_hud)
RegisterSignal(new_hud, COMSIG_HUD_Z_CHANGED, PROC_REF(z_changed))
var/mob/eye = new_hud?.mymob?.client?.eye
var/turf/eye_location = get_turf(eye)
z_changed(new_hud, eye_location?.z)
/datum/component/hide_weather_planes/proc/plane_master_deleted(atom/movable/screen/plane_master/source)
SIGNAL_HANDLER
plane_masters -= source
/**
* Unhides the relevant planes for the weather to be visible and manipulated.
* Also updates the alpha of the planes so enabled planes are either fully opaque or fully transparent
*/
/datum/component/hide_weather_planes/proc/display_planes()
var/datum/plane_master_group/home = parent
var/mob/our_lad = home.our_hud?.mymob
var/our_offset = GET_TURF_PLANE_OFFSET(our_lad)
for(var/atom/movable/screen/plane_master/weather_concious as anything in plane_masters)
//If the plane is hidden, unhide it
if(weather_concious.force_hidden)
weather_concious.unhide_plane(our_lad)
//Now we update the alpha of the plane based on our offset. Weather above us (lower offset) are transparent, weather at or below us (higher offset) are opaque.
if(weather_concious.offset >= our_offset)
weather_concious.enable_alpha()
else
weather_concious.disable_alpha()
///Hides the planes from the mob when no weather is occuring
/datum/component/hide_weather_planes/proc/hide_planes()
var/datum/plane_master_group/home = parent
var/mob/our_lad = home.our_hud?.mymob
for(var/atom/movable/screen/plane_master/weather_concious as anything in plane_masters)
weather_concious.hide_plane(our_lad)
/datum/component/hide_weather_planes/proc/z_changed(datum/source, new_z)
SIGNAL_HANDLER
active_weather = list()
if(!SSmapping.initialized)
return
var/list/connected_levels = SSmapping.get_connected_levels(new_z)
for(var/datum/weather/active as anything in SSweather.processing)
if(length(connected_levels & active.impacted_z_levels))
active_weather += WEAKREF(active)
if(length(active_weather))
display_planes()
else
hide_planes()
/datum/component/hide_weather_planes/proc/weather_started(datum/source, datum/weather/starting)
SIGNAL_HANDLER
var/datum/plane_master_group/home = parent
var/mob/eye = home.our_hud?.mymob?.client?.eye
var/turf/viewing_from = get_turf(eye)
if(!viewing_from)
return
var/list/connected_levels = SSmapping.get_connected_levels(viewing_from)
if(length(connected_levels & starting.impacted_z_levels))
active_weather += WEAKREF(starting)
if(!length(active_weather))
return
display_planes()
/datum/component/hide_weather_planes/proc/weather_finished(datum/source, datum/weather/stopping)
SIGNAL_HANDLER
active_weather -= WEAKREF(stopping)
if(length(active_weather))
return
hide_planes()