forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_station_trait.dm
127 lines (109 loc) · 5.03 KB
/
_station_trait.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
/// Station traits displayed in the lobby
GLOBAL_LIST_EMPTY(lobby_station_traits)
///Base class of station traits. These are used to influence rounds in one way or the other by influencing the levers of the station.
/datum/station_trait
///Name of the trait
var/name = "unnamed station trait"
///The type of this trait. Used to classify how this trait influences the station
var/trait_type = STATION_TRAIT_NEUTRAL
///Whether or not this trait uses process()
var/trait_processes = FALSE
///Chance relative to other traits of its type to be picked
var/weight = 10
///Whether this trait is always enabled; generally used for debugging
var/force = FALSE
///Does this trait show in the centcom report?
var/show_in_report = FALSE
///What message to show in the centcom report?
var/report_message
///What code-trait does this station trait give? gives none if null
var/trait_to_give
///What traits are incompatible with this one?
var/blacklist
///Extra flags for station traits such as it being abstract, planetary or space only
var/trait_flags = STATION_TRAIT_MAP_UNRESTRICTED
/// Whether or not this trait can be reverted by an admin
var/can_revert = TRUE
/// If set to true we'll show a button on the lobby to notify people about this trait
var/sign_up_button = FALSE
/// Lobby buttons controlled by this trait
var/list/lobby_buttons = list()
/// The ID that we look for in dynamic.json. Not synced with 'name' because I can already see this go wrong
var/dynamic_threat_id
/// If ran during dynamic, do we reduce the total threat? Will be overriden by config if set
var/threat_reduction = 0
/// Trait should not be instantiated in a round if its type matches this type
var/abstract_type = /datum/station_trait
/datum/station_trait/New()
. = ..()
RegisterSignal(SSticker, COMSIG_TICKER_ROUND_STARTING, PROC_REF(on_round_start))
if(threat_reduction)
GLOB.dynamic_station_traits[src] = threat_reduction
if(sign_up_button)
GLOB.lobby_station_traits += src
if(trait_processes)
START_PROCESSING(SSstation, src)
if(trait_to_give)
ADD_TRAIT(SSstation, trait_to_give, STATION_TRAIT)
/datum/station_trait/Destroy()
SSstation.station_traits -= src
GLOB.dynamic_station_traits.Remove(src)
destroy_lobby_buttons()
return ..()
/// Returns the type of info the centcom report has on this trait, if any.
/datum/station_trait/proc/get_report()
return "<i>[name]</i> - [report_message]"
/// Will attempt to revert the station trait, used by admins.
/datum/station_trait/proc/revert()
if (!can_revert)
CRASH("revert() was called on [type], which can't be reverted!")
if (trait_to_give)
REMOVE_TRAIT(SSstation, trait_to_give, STATION_TRAIT)
qdel(src)
/// Called by decals if they can be colored, to see if we got some cool colors for them. Only takes the first station trait
/proc/request_station_colors(atom/thing_to_color, pattern)
for(var/datum/station_trait/trait in SSstation.station_traits)
var/decal_color = trait.get_decal_color(thing_to_color, pattern || PATTERN_DEFAULT)
if(decal_color)
return decal_color
return null
/// Return a color for the decals, if any
/datum/station_trait/proc/get_decal_color(thing_to_color, pattern)
return
/// Return TRUE if we want to show a lobby button, by default we assume we don't want it after the round begins
/datum/station_trait/proc/can_display_lobby_button(client/player)
return sign_up_button && !SSticker.HasRoundStarted()
/// Apply any additional handling we need to our lobby button
/datum/station_trait/proc/setup_lobby_button(atom/movable/screen/lobby/button/sign_up/lobby_button)
SHOULD_CALL_PARENT(TRUE)
lobby_buttons |= lobby_button
RegisterSignal(lobby_button, COMSIG_ATOM_UPDATE_ICON, PROC_REF(on_lobby_button_update_icon))
RegisterSignal(lobby_button, COMSIG_CLICK, PROC_REF(on_lobby_button_click))
RegisterSignal(lobby_button, COMSIG_QDELETING, PROC_REF(on_lobby_button_destroyed))
lobby_button.update_appearance(UPDATE_ICON)
/// Called when our lobby button is clicked on
/datum/station_trait/proc/on_lobby_button_click(atom/movable/screen/lobby/button/sign_up/lobby_button, location, control, params, mob/dead/new_player/user)
SIGNAL_HANDLER
return
/// Called when our lobby button tries to update its appearance
/datum/station_trait/proc/on_lobby_button_update_icon(atom/movable/screen/lobby/button/sign_up/lobby_button, updates)
SIGNAL_HANDLER
return
/// Don't hold references to deleted buttons
/datum/station_trait/proc/on_lobby_button_destroyed(atom/movable/screen/lobby/button/sign_up/lobby_button)
SIGNAL_HANDLER
lobby_buttons -= lobby_button
/// Proc ran when round starts. Use this for roundstart effects. By default we clean up our buttons here.
/datum/station_trait/proc/on_round_start()
SIGNAL_HANDLER
destroy_lobby_buttons()
/// Remove all of our active lobby buttons
/datum/station_trait/proc/destroy_lobby_buttons()
for (var/atom/movable/screen/button as anything in lobby_buttons)
var/mob/hud_owner = button.get_mob()
qdel(button)
if (QDELETED(hud_owner))
continue
var/datum/hud/using_hud = hud_owner.hud_used
using_hud?.show_hud(using_hud?.hud_version)
lobby_buttons = list()