-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsimulationWindow.cpp
179 lines (156 loc) · 6.55 KB
/
simulationWindow.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "mapgen/SimulationWindow.hpp"
#include <imgui.h>
SimulationWindow::SimulationWindow(sf::RenderWindow *w, MapGenerator *m)
: window(w), mapgen(m) {}
void SimulationWindow::draw() {
ImGui::Text("Total cities count: %zu", mapgen->map->cities.size());
ImGui::Text("Ports count: %zu",
std::count_if(mapgen->map->cities.begin(),
mapgen->map->cities.end(),
[](City *c) { return c->type == PORT; }));
ImGui::Text("Mines count: %zu",
std::count_if(mapgen->map->cities.begin(),
mapgen->map->cities.end(),
[](City *c) { return c->type == MINE; }));
ImGui::Text("Agro count: %zu",
std::count_if(mapgen->map->cities.begin(),
mapgen->map->cities.end(),
[](City *c) { return c->type == AGRO; }));
ImGui::Text("Forts count: %zu",
std::count_if(mapgen->map->cities.begin(),
mapgen->map->cities.end(),
[](City *c) { return c->type == FORT; }));
ImGui::Text("\n");
if (ImGui::TreeNode("Economy variables")) {
ImGui::Columns(2, "vars");
ImGui::Text("POPULATION_GROWS");
ImGui::NextColumn();
ImGui::DragFloat("##POPULATION_GROWS",
&mapgen->simulator->vars->POPULATION_GROWS, 0.01, 0.01,
0.5);
ImGui::NextColumn();
ImGui::Text("POPULATION_GROWS_WEALTH_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat("##POPULATION_GROWS_WEALTH_MODIFIER",
&mapgen->simulator->vars->POPULATION_GROWS_WEALTH_MODIFIER,
0.01, 0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("PACKAGES_PER_NICE");
ImGui::NextColumn();
ImGui::DragFloat("##PACKAGES_PER_NICE",
&mapgen->simulator->vars->PACKAGES_PER_NICE, 1.f, 1.f,
1000.f);
ImGui::NextColumn();
ImGui::Text("PACKAGES_AGRO_POPULATION_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat(
"##PACKAGES_AGRO_POPULATION_MODIFIER",
&mapgen->simulator->vars->PACKAGES_AGRO_POPULATION_MODIFIER, 0.01, 0.01,
1.f);
ImGui::NextColumn();
ImGui::Text("PACKAGES_PER_MINERALS");
ImGui::NextColumn();
ImGui::DragFloat("##PACKAGES_PER_MINERALS",
&mapgen->simulator->vars->PACKAGES_PER_MINERALS, 1.f, 1.f,
1000.f);
ImGui::NextColumn();
ImGui::Text("PACKAGES_MINERALS_POPULATION_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat(
"##PACKAGES_MINERALS_POPULATION_MODIFIER",
&mapgen->simulator->vars->PACKAGES_MINERALS_POPULATION_MODIFIER, 0.01,
0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("CONSUME_AGRO_POPULATION_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat("##CONSUME_AGRO_POPULATION_MODIFIER",
&mapgen->simulator->vars->CONSUME_AGRO_POPULATION_MODIFIER,
0.01, 0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("CONSUME_MINERALS_POPULATION_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat(
"##CONSUME_MINERALS_POPULATION_MODIFIER",
&mapgen->simulator->vars->CONSUME_MINERALS_POPULATION_MODIFIER, 0.01,
0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("CONSUME_AGRO_WEALTH_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat("##CONSUME_AGRO_WEALTH_MODIFIER",
&mapgen->simulator->vars->CONSUME_AGRO_WEALTH_MODIFIER,
0.01, 0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("CONSUME_MINERALS_WEALTH_MODIFIER");
ImGui::NextColumn();
ImGui::DragFloat("##CONSUME_MINERALS_WEALTH_MODIFIER",
&mapgen->simulator->vars->CONSUME_MINERALS_WEALTH_MODIFIER,
0.01, 0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("CANT_BUY_AGRO");
ImGui::NextColumn();
ImGui::DragFloat("##CANT_BUY_AGRO", &mapgen->simulator->vars->CANT_BUY_AGRO,
0.01, 0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("CANT_BUY_MINERALS");
ImGui::NextColumn();
ImGui::DragFloat("##CANT_BUY_MINERALS",
&mapgen->simulator->vars->CANT_BUY_MINERALS, 0.01, 0.01,
1.f);
ImGui::NextColumn();
ImGui::Text("MINERALS_POPULATION_PRODUCE");
ImGui::NextColumn();
ImGui::DragFloat("##MINERALS_POPULATION_PRODUCE",
&mapgen->simulator->vars->MINERALS_POPULATION_PRODUCE,
0.01, 0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("AGRO_POPULATION_PRODUCE");
ImGui::NextColumn();
ImGui::DragFloat("##AGRO_POPULATION_PRODUCE",
&mapgen->simulator->vars->AGRO_POPULATION_PRODUCE, 0.01,
0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("PORT_FEE");
ImGui::NextColumn();
ImGui::DragFloat("##PORT_FEE", &mapgen->simulator->vars->PORT_FEE, 0.01,
0.01, 1.f);
ImGui::NextColumn();
ImGui::Text("PRICE_CORRECTION");
ImGui::NextColumn();
ImGui::DragFloat("##PRICE_CORRECTION", &mapgen->simulator->vars->PRICE_CORRECTION, 0.01,
0.01, 1.f);
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::TreePop();
}
ImGui::Text("\n");
if (mapgen->simulator->report != nullptr) {
ImGui::Text("Last simulation report");
auto report = mapgen->simulator->report;
auto pop = &report->population;
if (pop->size() > 0) {
char t[1000];
sprintf(t, "Total: %f\nAvg: %f\nMax: %d\nMin: %d", pop->back(),
pop->back() / mapgen->map->cities.size(), report->maxPopulation,
report->minPopulation);
ImGui::PlotLines(t,
[](void *data, int idx) {
return ((std::vector<float> *)data)->at(idx) / 1000.f;
},
(void *)pop, pop->size(), 0.f, "Total Population (k)",
pop->front() / 1000.f, pop->back() / 1000.f,
ImVec2(0, 100));
}
auto w = &mapgen->simulator->report->wealth;
if (pop->size() > 0) {
char tw[1000];
sprintf(tw, "Total: %f\nAvg: %f\nMax: %f\nMin: %f", w->back(), w->back() / mapgen->map->cities.size(), report->maxWealth, report->minWealth);
ImGui::PlotLines(tw,
[](void *data, int idx) {
return ((std::vector<float> *)data)->at(idx);
},
(void *)w, pop->size(), 0.f, "Total Wealth", w->front(),
w->back(), ImVec2(0, 100));
}
ImGui::Text("\n");
}
}