1 #pragma once
2 #ifndef CATA_SRC_OVERMAP_CONNECTION_H
3 #define CATA_SRC_OVERMAP_CONNECTION_H
4 
5 #include <iosfwd>
6 #include <list>
7 #include <set>
8 #include <vector>
9 
10 #include "int_id.h"
11 #include "omdata.h"
12 #include "string_id.h"
13 
14 class JsonIn;
15 class JsonObject;
16 struct overmap_location;
17 
18 class overmap_connection
19 {
20     public:
21         class subtype
22         {
23                 friend overmap_connection;
24 
25             public:
26                 enum class flag : int { orthogonal };
27 
28             public:
29                 string_id<oter_type_t> terrain;
30 
31                 int basic_cost = 0;
32 
33                 bool allows_terrain( const int_id<oter_t> &oter ) const;
allows_turns()34                 bool allows_turns() const {
35                     return terrain->is_linear();
36                 }
37 
is_orthogonal()38                 bool is_orthogonal() const {
39                     return flags.count( flag::orthogonal );
40                 }
41 
42                 void load( const JsonObject &jo );
43                 void deserialize( JsonIn &jsin );
44 
45             private:
46                 std::set<string_id<overmap_location>> locations;
47                 std::set<flag> flags;
48         };
49 
50     public:
51         const subtype *pick_subtype_for( const int_id<oter_t> &ground ) const;
52         bool has( const int_id<oter_t> &oter ) const;
53 
54         void load( const JsonObject &jo, const std::string &src );
55         void check() const;
56         void finalize();
57 
58     public:
59         string_id<overmap_connection> id;
60         bool was_loaded = false;
61 
62     private:
63         struct cache {
64             const subtype *value = nullptr;
65             bool assigned = false;
66             explicit operator bool() const {
67                 return assigned;
68             }
69         };
70 
71         std::list<subtype> subtypes;
72         mutable std::vector<cache> cached_subtypes;
73 };
74 
75 namespace overmap_connections
76 {
77 
78 void load( const JsonObject &jo, const std::string &src );
79 void finalize();
80 void check_consistency();
81 void reset();
82 
83 string_id<overmap_connection> guess_for( const int_id<oter_type_t> &oter_id );
84 string_id<overmap_connection> guess_for( const int_id<oter_t> &oter_id );
85 
86 } // namespace overmap_connections
87 
88 #endif // CATA_SRC_OVERMAP_CONNECTION_H
89