-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerr.cpp
35 lines (33 loc) · 1018 Bytes
/
Terr.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
#include "Terr.h"
#include "JSON_util.h"
#include <algorithm>
#include <cassert>
using std::find_if;
using std::map;
using std::string;
using std::shared_ptr;
Terr::Terr(const Json::Value& loc,
const Json::Value locs,
map<string, shared_ptr<Terr>>& terrs)
: short_name{get_val("short_name", loc).asString()}
, display_name{get_val("display_name", loc).asString()}
, has_center{get_val("has_center", loc).asBool()}
, adjacent{}
, piece{}
{
terrs[short_name] = shared_ptr<Terr>(this); // sketchy...
assert(terrs.find(short_name) != terrs.end());
for(const auto& adj_val : get_val("adjacent", loc)) {
string adj_name = adj_val.asString();
if(terrs.find(adj_name) == terrs.end()) {
const auto it = find_if(locs.begin(), locs.end(),
[&adj_name](const Json::Value& t) {
return get_val("short_name", t) == adj_name;
});
assert(it != locs.end());
set_terrs(*it, locs, terrs);
assert(terrs.find(adj_name) != terrs.end()); // TODO NDEBUG
adjacent.push_back(terrs[adj_name]);
}
}
}