forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutation_type.cpp
60 lines (51 loc) · 1.6 KB
/
mutation_type.cpp
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
#include "mutation.h" // IWYU pragma: associated
#include "json.h"
struct mutation_type {
std::string id;
};
static std::map<std::string, mutation_type> mutation_types;
void load_mutation_type( const JsonObject &jsobj )
{
mutation_type new_type;
new_type.id = jsobj.get_string( "id" );
mutation_types[new_type.id] = new_type;
}
bool mutation_type_exists( const std::string &id )
{
return mutation_types.find( id ) != mutation_types.end();
}
std::vector<trait_id> get_mutations_in_type( const std::string &id )
{
std::vector<trait_id> ret;
for( const mutation_branch &it : mutation_branch::get_all() ) {
if( it.types.find( id ) != it.types.end() ) {
ret.push_back( it.id );
}
}
return ret;
}
std::vector<trait_and_var> mutations_var_in_type( const std::string &id )
{
std::vector<trait_and_var> ret;
for( const mutation_branch &it : mutation_branch::get_all() ) {
if( it.types.find( id ) != it.types.end() ) {
if( it.variants.empty() ) {
ret.emplace_back( it.id, "" );
continue;
}
for( const std::pair<const std::string, mutation_variant> &var : it.variants ) {
ret.emplace_back( it.id, var.second.id );
}
}
}
return ret;
}
std::vector<trait_id> get_mutations_in_types( const std::set<std::string> &ids )
{
std::vector<trait_id> ret;
for( const std::string &it : ids ) {
std::vector<trait_id> this_id = get_mutations_in_type( it );
ret.insert( ret.end(), this_id.begin(), this_id.end() );
}
return ret;
}