blob: 9f58c7d4e4fb90ea654c494c20818f36997105df (
plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include <iostream>
#include <fstream>
#include <vector>
#include "load.h"
#include "nlohmann/json.hpp"
using json = nlohmann::json;
std::vector<Ability> load_abilities () {
std::vector<Ability> abs;
abs.emplace_back("Anti-Cavalry");
abs.emplace_back("Skirmish");
abs.emplace_back("First Strike");
abs.emplace_back("Rapid Fire");
abs.emplace_back("Units Only");
abs.emplace_back("Buildings Only");
abs.emplace_back("No Counter");
abs.emplace_back("No Move & Attack");
abs.emplace_back("Causes Fear");
abs.emplace_back("Desert Charge");
abs.emplace_back("Plains Charge");
abs.emplace_back("Scares Horses");
abs.emplace_back("Woodsman");
abs.emplace_back("Volley");
abs.emplace_back("Frenzy");
abs.emplace_back("Zeal");
abs.emplace_back("Scout");
abs.emplace_back("Convert");
abs.emplace_back("Heal");
abs.emplace_back("Seasoned Veteran");
return abs;
}
void load_json (Inv &inv) {
inv.abilities = load_abilities();
std::ifstream file_tiles("content/tiles.json");
json j_tiles; file_tiles >> j_tiles;
for (auto it : j_tiles) {
Tile tile;
tile.name = it["name"];
tile.move_cost = it["move_cost"];
tile.defence_bonus = it["defence_bonus"];
tile.range_bonus = it["range_bonus"];
tile.spritebounds = vec2 { it["spritebounds"][0], it["spritebounds"][1] };
inv.tiles.push_back(tile);
}
std::ifstream file_ents("content/entities.json");
json j_ents; file_ents >> j_ents;
for (auto it : j_ents) {
EntityInfo ent;
ent.id = it["id"];
ent.name = it["name"];
ent.level = it["level"];
ent.range = it["range"];
ent.move = it["move"];
ent.attack = it["attack"];
ent.defence = it["defence"];
ent.sight = it["sight"];
ent.unit = it["unit"];
for (int i=0; i<it["prod"].size(); i++) {
ent.prod[i] = it["prod"][i];
}
for (int i=0; i<it["cost"].size(); i++) {
ent.cost[i] = it["cost"][i];
}
for (auto blds : it["build"]) {
ent.build.push_back(blds);
}
for (auto train : it["train_id"]) {
ent.train_id.push_back(train);
}
for (auto train : it["train_class"]) {
ent.train_class.push_back((EntityInfo::Class)
EntityClass::from_string(train.get<std::string>()));
}
for (auto ad : it["adjacent"]) {
ent.adjacent.push_back(ad);
}
for (auto ad : it["diagonal"]) {
ent.diagonal.push_back(ad);
}
ent.ent_class = (EntityInfo::Class) EntityClass::from_string(
it["class"].get<std::string>());
for (auto ab : it["abilities"]) {
int index = 0;
for (int i=0; i<inv.abilities.size(); i++) {
if (inv.abilities[i].name == ab) { index = i; break; }
}
ent.abilities.push_back(index);
}
ent.spritebounds = vec2 { it["spritebounds"][0], it["spritebounds"][1] };
if (it.contains("upgrade")) { ent.upgrade = it["upgrade"]; }
if (it.contains("defence_bonus")) {
ent.defence_bonus = it["defence_bonus"];
}
inv.infos.push_back(ent);
}
std::ifstream file_techs("content/techs.json");
json j_techs; file_techs >> j_techs;
for (auto it : j_techs) {
Tech tech;
tech.name = it["name"];
tech.id = it["id"];
tech.level = it["level"];
tech.req_id = it["req_id"];
for (int i=0; i<it["cost"].size(); i++) {
tech.cost[i] = it["cost"][i];
}
auto b = it["bonus"];
if (b != nullptr) {
if (b.contains("attack")) { tech.bonus.attack = b["attack"]; }
if (b.contains("defence")) { tech.bonus.defence = b["defence"]; }
if (b.contains("sight")) { tech.bonus.sight = b["sight"]; }
if (b.contains("move")) { tech.bonus.move = b["move"]; }
if (b.contains("trade")) { tech.bonus.trade = b["trade"]; }
if (b.contains("req_range")) {
tech.bonus.req_range = b["req_range"];
}
if (b.contains("improved_heal")) {
tech.bonus.improved_heal = b["improved_heal"];
}
if (b.contains("improved_convert")) {
tech.bonus.improved_convert = b["improved_convert"];
}
if (b.contains("cost")) tech.bonus.cost.clear();
for (auto v : b["cost"]) { tech.bonus.cost.push_back(v); }
if (b.contains("cost_abs")) tech.bonus.cost_abs.clear();
for (auto v : b["cost_abs"]) { tech.bonus.cost_abs.push_back(v); }
if (b.contains("prod")) tech.bonus.prod.clear();
for (auto v : b["prod"]) { tech.bonus.prod.push_back(v); }
for (auto v : b["aff_id"]) { tech.bonus.aff_id.push_back(v); }
for (auto v : b["aff_class"]) {
tech.bonus.aff_class.push_back(EntityClass::from_string(
v.get<std::string>()));
}
if (b.contains("aff_level")) {
tech.bonus.aff_level = b["aff_level"];
}
if (b.contains("aff_all")) {
tech.bonus.aff_all = b["aff_all"];
}
}
std::cout << tech.id << tech.bonus.to_string() << std::endl;
inv.techs.push_back(tech);
}
}
|