/
mil_ranks.dm
197 lines (162 loc) · 6.56 KB
/
mil_ranks.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
/**
* Datums for military branches and ranks
*
* Map datums can optionally specify a list of /datum/mil_branch paths. These paths
* are used to initialize the global mil_branches object, which contains a list of
* branch objects the map uses. Each branch definition specifies a list of
* /datum/mil_rank paths, which are ranks available to that branch.
*
* Which branches and ranks can be selected for spawning is specifed in GLOB.using_map
* and each branch datum definition, respectively.
*/
GLOBAL_DATUM_INIT(mil_branches, /datum/mil_branches, new)
/**
* Global object for handling branches
*/
/datum/mil_branches
var/list/branches // All branches that exist
var/list/spawn_branches_ // Branches that a player can choose for spawning, not including species restrictions.
var/list/spawn_branches_by_species_ // Branches that a player can choose for spawning, with species restrictions. Populated on a needed basis
/**
* Retrieve branch object by branch name
*/
/datum/mil_branches/proc/get_branch(branch_name)
if(ispath(branch_name, /datum/mil_branch))
var/datum/mil_branch/branch = branch_name
branch_name = initial(branch.name)
if(branch_name && branch_name != "None")
return branches[branch_name]
/**
* Retrieve branch object by branch type
*/
/datum/mil_branches/proc/get_branch_by_type(branch_type)
for(var/name in branches)
if (istype(branches[name], branch_type))
return branches[name]
/**
* Retrieve a rank object from given branch by name
*/
/datum/mil_branches/proc/get_rank(branch_name, rank_name)
if(ispath(rank_name))
var/datum/mil_rank/rank = rank_name
rank_name = initial(rank.name)
if(rank_name && rank_name != "None")
var/datum/mil_branch/branch = get_branch(branch_name)
if(branch)
return branch.ranks[rank_name]
/**
* Return all spawn branches for the given input
*/
/datum/mil_branches/proc/spawn_branches(datum/species/S)
if(!S)
return spawn_branches_.Copy()
. = LAZYACCESS(spawn_branches_by_species_, S)
if(!.)
. = list()
LAZYSET(spawn_branches_by_species_, S, .)
for(var/spawn_branch in spawn_branches_)
if(!GLOB.using_map.is_species_branch_restricted(S, spawn_branches_[spawn_branch]))
. += spawn_branch
/**
* Return all spawn ranks for the given input
*/
/datum/mil_branches/proc/spawn_ranks(branch_name, datum/species/S)
var/datum/mil_branch/branch = get_branch(branch_name)
return branch && branch.spawn_ranks(S)
/**
* Return a true value if branch_name is a valid spawn branch key
*/
/datum/mil_branches/proc/is_spawn_branch(branch_name, datum/species/S)
return (branch_name in spawn_branches(S))
/**
* Return a true value if rank_name is a valid spawn rank in branch under branch_name
*/
/datum/mil_branches/proc/is_spawn_rank(branch_name, rank_name, datum/species/S)
var/datum/mil_branch/branch = get_branch(branch_name)
if(branch && (rank_name in branch.spawn_ranks(S)))
return TRUE
else
return FALSE
/**
* A single military branch, such as Fleet or Marines
*/
/datum/mil_branch
var/name = "Unknown" // Longer name for branch, eg "Sol Central Marine Corps"
var/name_short // Abbreviation of the name, eg "SCMC"
var/list/ranks // Associative list of full rank names to the corresponding
// /datum/mil_rank objects. These are all ranks available to the branch.
var/list/spawn_ranks_ // Ranks which the player can choose for spawning, not including species restrictions
var/list/spawn_ranks_by_species_ // Ranks which the player can choose for spawning, with species restrictions. Populated on a needed basis
var/list/rank_types // list of paths used to init the ranks list
var/list/spawn_rank_types // list of paths used to init the spawn_ranks list. Subset of rank_types
var/assistant_job = DEFAULT_JOB_TYPE
// Email addresses will be created under this domain name. Mostly for the looks.
var/email_domain = "freemail.net"
var/allow_custom_email = FALSE
var/list/min_skill
/datum/mil_branch/New()
ranks = list()
spawn_ranks_ = list()
spawn_ranks_by_species_ = list()
for(var/rank_path in rank_types)
if(!ispath(rank_path, /datum/mil_rank))
crash_with("[name]'s rank_types includes [rank_path], which is not a subtype of /datum/mil_rank.")
continue
var/datum/mil_rank/rank = new rank_path ()
ranks[rank.name] = rank
if(rank_path in spawn_rank_types)
spawn_ranks_[rank.name] = rank
/datum/mil_branch/proc/spawn_ranks(datum/species/S)
if(!S)
return spawn_ranks_.Copy()
. = spawn_ranks_by_species_[S]
if(!.)
. = list()
spawn_ranks_by_species_[S] = .
for(var/spawn_rank in spawn_ranks_)
if(!GLOB.using_map.is_species_rank_restricted(S, src, spawn_ranks_[spawn_rank]))
. += spawn_rank
/**
* Populate the global branches list from GLOB.using_map
*/
/hook/startup/proc/populate_branches()
if(!(GLOB.using_map.flags & MAP_HAS_BRANCH) && !(GLOB.using_map.flags & MAP_HAS_RANK))
GLOB.mil_branches.branches = null
GLOB.mil_branches.spawn_branches_ = null
GLOB.mil_branches.spawn_branches_by_species_ = null
return 1
GLOB.mil_branches.branches = list()
GLOB.mil_branches.spawn_branches_ = list()
GLOB.mil_branches.spawn_branches_by_species_ = list()
for(var/branch_path in GLOB.using_map.branch_types)
if(!ispath(branch_path, /datum/mil_branch))
crash_with("populate_branches() attempted to instantiate object with path [branch_path], which is not a subtype of /datum/mil_branch.")
continue
var/datum/mil_branch/branch = new branch_path ()
GLOB.mil_branches.branches[branch.name] = branch
if(branch_path in GLOB.using_map.spawn_branch_types)
GLOB.mil_branches.spawn_branches_[branch.name] = branch
return 1
/**
* A military rank
*
* Note that in various places "rank" is used to refer to a character's job, and
* so this is "mil_rank" to distinguish it.
*/
/datum/mil_rank
var/name = "Unknown"
var/name_short // Abbreviation of the name. Should be null if the
// rank doesn't usually serve as a prefix to the individual's name.
var/list/accessory //type of accesory that will be equipped by job code with this rank
var/sort_order = 0 // A numerical equivalent of the rank used to indicate its order when compared to other datums: eg e-1 = 1, o-1 = 11
/// Returns short designation (yes shorter than name_short), like E1, O3 etc.
/datum/mil_rank/proc/grade()
return sort_order
/// Returns category of rank, like commissioned versus enlisted.
/datum/mil_rank/proc/rank_category()
return null
/// Categories of ranks
/singleton/rank_category
var/name = "Unknown"
/// Accesses granted based on being in this category of ranks.
var/add_accesses = list()