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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
#include "GameManager.hpp"
using namespace OpenVic;
GameManager::GameManager(state_updated_func_t state_updated_callback)
: clock { [this]() { tick(); }, [this]() { update_state(); } },
state_updated { state_updated_callback } {}
Map& GameManager::get_map() {
return map;
}
Map const& GameManager::get_map() const {
return map;
}
BuildingManager& GameManager::get_building_manager() {
return building_manager;
}
BuildingManager const& GameManager::get_building_manager() const {
return building_manager;
}
GoodManager& GameManager::get_good_manager() {
return good_manager;
}
GoodManager const& GameManager::get_good_manager() const {
return good_manager;
}
PopManager& GameManager::get_pop_manager() {
return pop_manager;
}
PopManager const& GameManager::get_pop_manager() const {
return pop_manager;
}
IdeologyManager& GameManager::get_ideology_manager() {
return ideology_manager;
}
IdeologyManager const& GameManager::get_ideology_manager() const {
return ideology_manager;
}
IssueManager& GameManager::get_issue_manager() {
return issue_manager;
}
IssueManager const& GameManager::get_issue_manager() const {
return issue_manager;
}
ProductionTypeManager& GameManager::get_production_type_manager() {
return production_type_manager;
}
ProductionTypeManager const& GameManager::get_production_type_manager() const {
return production_type_manager;
}
UnitManager& GameManager::get_unit_manager() {
return unit_manager;
}
UnitManager const& GameManager::get_unit_manager() const {
return unit_manager;
}
ModifierManager& GameManager::get_modifier_manager() {
return modifier_manager;
}
ModifierManager const& GameManager::get_modifier_manager() const{
return modifier_manager;
}
GameAdvancementHook& GameManager::get_clock() {
return clock;
}
GameAdvancementHook const& GameManager::get_clock() const {
return clock;
}
void GameManager::set_needs_update() {
needs_update = true;
}
void GameManager::update_state() {
if (!needs_update) return;
Logger::info("Update: ", today);
map.update_state(today);
if (state_updated) state_updated();
needs_update = false;
}
/* REQUIREMENTS:
* SS-98, SS-101
*/
void GameManager::tick() {
today++;
Logger::info("Tick: ", today);
map.tick(today);
set_needs_update();
}
bool GameManager::setup() {
session_start = time(nullptr);
clock.reset();
today = { 1836 };
good_manager.reset_to_defaults();
bool ret = map.setup(good_manager, building_manager, pop_manager);
set_needs_update();
return ret;
}
Date const& GameManager::get_today() const {
return today;
}
bool GameManager::expand_building(Province::index_t province_index, std::string_view building_type_identifier) {
set_needs_update();
Province* province = map.get_province_by_index(province_index);
if (province == nullptr) {
Logger::error("Invalid province index ", province_index, " while trying to expand building ", building_type_identifier);
return false;
}
return province->expand_building(building_type_identifier);
}
static constexpr colour_t LOW_ALPHA_VALUE = float_to_alpha_value(0.4f);
static constexpr colour_t HIGH_ALPHA_VALUE = float_to_alpha_value(0.7f);
static colour_t default_colour(Province const& province) {
/* Nice looking colours to blend with the terrain textures */
static constexpr colour_t LAND_COLOUR = 0x0D7017;
static constexpr colour_t WATER_COLOUR = 0x4287F5;
return LOW_ALPHA_VALUE | (province.get_water() ? WATER_COLOUR : LAND_COLOUR);
}
bool GameManager::load_hardcoded_defines() {
bool ret = true;
using mapmode_t = std::pair<std::string, Mapmode::colour_func_t>;
const std::vector<mapmode_t> mapmodes {
{ "mapmode_terrain",
[](Map const&, Province const& province) -> colour_t {
return default_colour(province);
} },
{ "mapmode_province",
[](Map const&, Province const& province) -> colour_t {
return HIGH_ALPHA_VALUE | province.get_colour();
} },
{ "mapmode_region",
[](Map const&, Province const& province) -> colour_t {
Region const* region = province.get_region();
return region != nullptr ? HIGH_ALPHA_VALUE | region->get_colour() : default_colour(province);
} },
{ "mapmode_index",
[](Map const& map, Province const& province) -> colour_t {
const colour_t f = fraction_to_colour_byte(province.get_index(), map.get_province_count() + 1);
return HIGH_ALPHA_VALUE | (f << 16) | (f << 8) | f;
} },
{ "mapmode_terrain_type",
[](Map const& map, Province const& province) -> colour_t {
TerrainType const* terrarin_type = province.get_terrain_type();
return terrarin_type != nullptr ? HIGH_ALPHA_VALUE | terrarin_type->get_colour() : default_colour(province);
} },
{ "mapmode_rgo",
[](Map const& map, Province const& province) -> colour_t {
Good const* rgo = province.get_rgo();
return rgo != nullptr ? HIGH_ALPHA_VALUE | rgo->get_colour() : default_colour(province);
} },
{ "mapmode_infrastructure",
[](Map const& map, Province const& province) -> colour_t {
BuildingInstance const* railroad = province.get_building_by_identifier("building_railroad");
if (railroad != nullptr) {
colour_t val = fraction_to_colour_byte(railroad->get_current_level(), railroad->get_building().get_max_level() + 1, 0.5f, 1.0f);
switch (railroad->get_expansion_state()) {
case ExpansionState::CannotExpand: val <<= 16; break;
case ExpansionState::CanExpand: break;
default: val <<= 8; break;
}
return HIGH_ALPHA_VALUE | val;
}
return default_colour(province);
} },
{ "mapmode_population",
[](Map const& map, Province const& province) -> colour_t {
return HIGH_ALPHA_VALUE | (fraction_to_colour_byte(province.get_total_population(), map.get_highest_province_population() + 1, 0.1f, 1.0f) << 8);
} },
{ "mapmode_culture",
[](Map const& map, Province const& province) -> colour_t {
HasIdentifierAndColour const* largest = get_largest_item(province.get_culture_distribution()).first;
return largest != nullptr ? HIGH_ALPHA_VALUE | largest->get_colour() : default_colour(province);
} },
{ "mapmode_religion",
[](Map const& map, Province const& province) -> colour_t {
HasIdentifierAndColour const* largest = get_largest_item(province.get_religion_distribution()).first;
return largest != nullptr ? HIGH_ALPHA_VALUE | largest->get_colour() : default_colour(province);
} }
};
for (mapmode_t const& mapmode : mapmodes)
ret &= map.add_mapmode(mapmode.first, mapmode.second);
map.lock_mapmodes();
return ret;
}
|