forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_field_transformations.cpp
66 lines (59 loc) · 1.99 KB
/
event_field_transformations.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
61
62
63
64
65
66
#include "event_field_transformations.h"
#include <set>
#include "int_id.h"
#include "mapdata.h"
#include "mtype.h"
#include "string_id.h"
#include "type_id.h"
static std::vector<cata_variant> flags_of_terrain( const cata_variant &v )
{
const std::set<std::string> &flags = v.get<ter_id>()->get_flags();
std::vector<cata_variant> result;
result.reserve( flags.size() );
for( const std::string &s : flags ) {
result.push_back( cata_variant( s ) );
}
return result;
}
static std::vector<cata_variant> is_mounted( const cata_variant &v )
{
const mtype_id mount = v.get<mtype_id>();
std::vector<cata_variant> result = { cata_variant( !mount.is_empty() ) };
return result;
}
static std::vector<cata_variant> is_swimming_terrain( const cata_variant &v )
{
const ter_id ter = v.get<ter_id>();
const bool swimming = ter->has_flag( ter_bitflags::TFLAG_DEEP_WATER ) &&
ter->has_flag( ter_bitflags::TFLAG_SWIMMABLE );
std::vector<cata_variant> result = { cata_variant( swimming ) };
return result;
}
static std::vector<cata_variant> species_of_monster( const cata_variant &v )
{
const std::set<species_id> &species = v.get<mtype_id>()->species;
std::vector<cata_variant> result;
result.reserve( species.size() );
for( const species_id &s : species ) {
result.push_back( cata_variant( s ) );
}
return result;
}
const std::unordered_map<std::string, event_field_transformation> event_field_transformations = {
{
"flags_of_terrain",
{flags_of_terrain, cata_variant_type::string, { cata_variant_type::ter_id}}
},
{
"is_mounted",
{ is_mounted, cata_variant_type::bool_, { cata_variant_type::mtype_id } }
},
{
"is_swimming_terrain",
{is_swimming_terrain, cata_variant_type::bool_, { cata_variant_type::ter_id } }
},
{
"species_of_monster",
{ species_of_monster, cata_variant_type::species_id, { cata_variant_type::mtype_id } }
},
};