forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overmap_connection.h
88 lines (67 loc) · 2.19 KB
/
overmap_connection.h
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
#pragma once
#ifndef CATA_SRC_OVERMAP_CONNECTION_H
#define CATA_SRC_OVERMAP_CONNECTION_H
#include <iosfwd>
#include <list>
#include <set>
#include <vector>
#include "int_id.h"
#include "omdata.h"
#include "string_id.h"
class JsonObject;
struct overmap_location;
class overmap_connection
{
public:
class subtype
{
friend overmap_connection;
public:
enum class flag : int { orthogonal };
public:
string_id<oter_type_t> terrain;
int basic_cost = 0;
bool allows_terrain( const int_id<oter_t> &oter ) const;
bool allows_turns() const {
return terrain->is_linear();
}
bool is_orthogonal() const {
return flags.count( flag::orthogonal );
}
void load( const JsonObject &jo );
void deserialize( const JsonObject &jo );
private:
std::set<string_id<overmap_location>> locations;
std::set<flag> flags;
};
public:
const subtype *pick_subtype_for( const int_id<oter_t> &ground ) const;
bool has( const int_id<oter_t> &oter ) const;
void load( const JsonObject &jo, const std::string &src );
void check() const;
void finalize();
public:
string_id<overmap_connection> id;
std::vector<std::pair<string_id<overmap_connection>, mod_id>> src;
bool was_loaded = false;
private:
struct cache {
const subtype *value = nullptr;
bool assigned = false;
explicit operator bool() const {
return assigned;
}
};
std::list<subtype> subtypes;
mutable std::vector<cache> cached_subtypes;
};
namespace overmap_connections
{
void load( const JsonObject &jo, const std::string &src );
void finalize();
void check_consistency();
void reset();
string_id<overmap_connection> guess_for( const int_id<oter_type_t> &oter_id );
string_id<overmap_connection> guess_for( const int_id<oter_t> &oter_id );
} // namespace overmap_connections
#endif // CATA_SRC_OVERMAP_CONNECTION_H