5#include "dcon_generated.hpp"
55 auto key =
state.lookup_key(
"alice_armygroup_selection_control_panel");
57 auto window = ui::make_element_by_type<ui::battleplanner_selection_control>(
state, def);
61 auto key =
state.lookup_key(
"alice_armygroup_exit_units_selection");
63 auto button = ui::make_element_by_type<ui::go_to_battleplanner_button>(
state, def);
70 state.world.for_each_province([&](dcon::province_id
id) {
71 auto ptr = ui::make_element_by_type<ui::army_group_counter_window>(
state,
"alice_army_group_on_map");
77 auto key =
state.lookup_key(
"alice_army_group_regiments_list");
79 auto new_elm_army_group = ui::make_element_by_type<ui::army_group_details_window>(
state, def);
86 auto key =
state.lookup_key(
"alice_exit_battleplanner");
88 auto button = ui::make_element_by_type<ui::go_to_base_game_button>(
state, def);
93 auto key =
state.lookup_key(
"alice_battleplanner_control_panel");
95 auto window = ui::make_element_by_type<ui::battleplanner_control>(
state, def);
103 auto ewin = ui::make_element_by_type<ui::end_window>(
state,
state.ui_state.
defs_by_name.find(
state.lookup_key(
"back_end"))->second.definition);
107 auto window = ui::make_element_by_type<ui::console_window>(
state,
"alice_console_window");
111 state.world.for_each_province([&](dcon::province_id
id) {
112 if(
state.world.province_get_port_to(
id)) {
113 auto ptr = ui::make_element_by_type<ui::port_window>(state,
"alice_port_icon");
114 static_cast<ui::port_window*>(ptr.get())->set_province(state, id);
115 state.ui_state.units_root->add_child_to_front(std::move(ptr));
119 state.world.for_each_province([&](dcon::province_id
id) {
120 auto ptr = ui::make_element_by_type<ui::unit_counter_window>(
state,
"alice_map_unit");
124 state.world.for_each_province([&](dcon::province_id
id) {
125 auto ptr = ui::make_element_by_type<ui::rgo_icon>(
state,
"alice_rgo_mapicon");
130 auto ptr = ui::make_element_by_type<ui::province_details_container>(
state,
"alice_province_values");
135 auto new_elm = ui::make_element_by_type<ui::chat_message_listbox<false>>(
state,
"chat_list");
136 new_elm->base_data.position.x += 156;
137 new_elm->base_data.position.y += 24;
138 new_elm->impl_on_update(
state);
140 state.ui_state.
root->add_child_to_front(std::move(new_elm));
143 auto new_elm = ui::make_element_by_type<ui::outliner_window>(
state,
"outliner");
145 new_elm->impl_on_update(
state);
146 state.ui_state.
root->add_child_to_front(std::move(new_elm));
151 for(
size_t i =
state.ui_defs.gui.size(); i-- > 0;) {
152 auto gdef = dcon::gui_def_id(dcon::gui_def_id::value_base_t(i));
153 if(
state.to_string_view(
state.ui_defs.gui[gdef].name) ==
"topbar_outlinerbutton_bg") {
154 auto new_bg = ui::make_element_by_type<ui::outliner_button>(
state, gdef);
155 state.ui_state.
root->add_child_to_front(std::move(new_bg));
160 for(
size_t i =
state.ui_defs.gui.size(); i-- > 0;) {
161 auto gdef = dcon::gui_def_id(dcon::gui_def_id::value_base_t(i));
162 if(
state.to_string_view(
state.ui_defs.gui[gdef].name) ==
"topbar_outlinerbutton") {
163 auto new_btn = ui::make_element_by_type<ui::outliner_button>(
state, gdef);
164 new_btn->impl_on_update(
state);
165 state.ui_state.
root->add_child_to_front(std::move(new_btn));
171 auto new_elm = ui::make_element_by_type<ui::minimap_container_window>(
state,
"alice_menubar");
173 state.ui_state.
root->add_child_to_front(std::move(new_elm));
176 auto new_elm = ui::make_element_by_type<ui::minimap_picture_window>(
state,
"minimap_pic");
177 state.ui_state.
root->add_child_to_front(std::move(new_elm));
180 auto new_elm = ui::make_element_by_type<ui::province_view_window>(
state,
"province_view");
181 state.ui_state.
root->add_child_to_front(std::move(new_elm));
184 auto new_elm_army = ui::make_element_by_type<ui::unit_details_window<dcon::army_id>>(
state,
"sup_unit_status");
187 state.ui_state.
root->add_child_to_front(std::move(new_elm_army));
189 auto new_elm_navy = ui::make_element_by_type<ui::unit_details_window<dcon::navy_id>>(
state,
"sup_unit_status");
192 state.ui_state.
root->add_child_to_front(std::move(new_elm_navy));
196 auto mselection = ui::make_element_by_type<ui::mulit_unit_selection_panel>(
state,
"alice_multi_unitpanel");
198 mselection->set_visible(
state,
false);
199 state.ui_state.
root->add_child_to_front(std::move(mselection));
202 auto new_elm = ui::make_element_by_type<ui::diplomacy_request_window>(
state,
"defaultdialog");
204 state.ui_state.
root->add_child_to_front(std::move(new_elm));
207 auto new_elm = ui::make_element_by_type<ui::message_window>(
state,
"defaultpopup");
209 state.ui_state.
root->add_child_to_front(std::move(new_elm));
212 auto new_elm = ui::make_element_by_type<ui::leader_selection_window>(
state,
"alice_leader_selection_panel");
214 state.ui_state.
root->add_child_to_front(std::move(new_elm));
217 auto new_elm = ui::make_element_by_type<ui::naval_combat_end_popup>(
state,
"endofnavalcombatpopup");
218 new_elm->set_visible(
state,
false);
219 state.ui_state.
root->add_child_to_front(std::move(new_elm));
222 auto new_elm = ui::make_element_by_type<ui::naval_combat_window>(
state,
"alice_naval_combat");
223 new_elm->set_visible(
state,
false);
224 state.ui_state.
root->add_child_to_front(std::move(new_elm));
227 auto new_elm = ui::make_element_by_type<ui::land_combat_window>(
state,
"alice_land_combat");
228 new_elm->set_visible(
state,
false);
229 state.ui_state.
root->add_child_to_front(std::move(new_elm));
232 auto new_elm = ui::make_element_by_type<ui::topbar_window>(
state,
"topbar");
233 new_elm->impl_on_update(
state);
234 state.ui_state.
root->add_child_to_front(std::move(new_elm));
237 auto legend_win = ui::make_element_by_type<ui::map_legend_gradient>(
state,
"alice_map_legend_gradient_window");
239 state.ui_state.
root->add_child_to_front(std::move(legend_win));
242 auto legend_win = ui::make_element_by_type<ui::map_legend_civ_level>(
state,
"alice_map_legend_civ_level");
244 state.ui_state.
root->add_child_to_front(std::move(legend_win));
247 auto legend_win = ui::make_element_by_type<ui::map_legend_col>(
state,
"alice_map_legend_colonial");
249 state.ui_state.
root->add_child_to_front(std::move(legend_win));
252 auto legend_win = ui::make_element_by_type<ui::map_legend_dip>(
state,
"alice_map_legend_diplomatic");
254 state.ui_state.
root->add_child_to_front(std::move(legend_win));
257 auto legend_win = ui::make_element_by_type<ui::map_legend_rr>(
state,
"alice_map_legend_infrastructure");
259 state.ui_state.
root->add_child_to_front(std::move(legend_win));
262 auto legend_win = ui::make_element_by_type<ui::map_legend_nav>(
state,
"alice_map_legend_naval");
264 state.ui_state.
root->add_child_to_front(std::move(legend_win));
267 auto legend_win = ui::make_element_by_type<ui::map_legend_rank>(
state,
"alice_map_legend_rank");
269 state.ui_state.
root->add_child_to_front(std::move(legend_win));
272 auto legend_win = ui::make_element_by_type<ui::map_legend_rec>(
state,
"alice_map_legend_rec");
274 state.ui_state.
root->add_child_to_front(std::move(legend_win));
277 auto new_elm = ui::make_element_by_type<ui::chat_window>(
state,
"ingame_lobby_window");
280 state.ui_state.
root->add_child_to_front(std::move(new_elm));
403 while(b !=
nullptr) {
465 auto game_state_was_updated =
game_state_updated.exchange(
false, std::memory_order::acq_rel);
472 if(ownership_update) {
477 if(game_state_was_updated) {
481 std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
486 auto microseconds_since_last_render = std::chrono::duration_cast<std::chrono::microseconds>(now -
ui_state.
last_render_time);
487 auto frames_per_second = 1.f / float(microseconds_since_last_render.count() / 1e6);
523 if(game_state_was_updated) {
541 world.for_each_automated_army_group([&](dcon::automated_army_group_id item) {
556 auto auto_choice =
world.national_event_get_auto_choice(c1->e);
557 if(auto_choice == 0) {
559 if(
world.national_event_get_is_major(c1->e)) {
573 auto auto_choice =
world.free_national_event_get_auto_choice(c2->e);
574 if(auto_choice == 0) {
576 if(
world.free_national_event_get_is_major(c2->e)) {
590 auto auto_choice =
world.provincial_event_get_auto_choice(c3->e);
591 if(auto_choice == 0) {
603 auto auto_choice =
world.free_provincial_event_get_auto_choice(c4->e);
604 if(auto_choice == 0) {
618 if(lr->player_on_winning_side ==
true && (!lr->attacking_nation || !lr->defending_nation)) {
643 bool had_diplo_msg =
false;
650 had_diplo_msg =
true;
661 auto base_type = c6->
type;
703 ui_pause.store(
true, std::memory_order_release);
808 text::layout_parameters{ 0, 0, tooltip_width, int16_t(root_elm->base_data.size.y - 20), ui_state.tooltip_font, 0,
809 text::alignment::left,
810 text::text_color::white, true },
816 container.used_width = -container.used_width;
817 for(
auto& t : container.base_layout.contents) {
818 t.x += 16 + container.used_width;
822 for(
auto& t : container.base_layout.contents) {
827 ui_state.
tooltip->base_data.size.x = int16_t(container.used_width + 32);
828 ui_state.
tooltip->base_data.size.y = int16_t(container.used_height + 32);
829 if(container.used_width > 0)
840 if(tooltip_probe.under_mouse) {
847 text::layout_parameters{ 0, 0, tooltip_width,int16_t(root_elm->base_data.size.y - 20), ui_state.tooltip_font, 0,
848 text::alignment::left, text::text_color::white, true }, 10);
853 container.used_width = -container.used_width;
854 for(
auto& t : container.base_layout.contents) {
855 t.x += 16 + container.used_width;
859 for(
auto& t : container.base_layout.contents) {
864 ui_state.
tooltip->base_data.size.x = int16_t(container.used_width + 32);
865 ui_state.
tooltip->base_data.size.y = int16_t(container.used_height + 32);
866 if(container.used_width > 0)
878 text::layout_parameters{ 0, 0, tooltip_width, int16_t(root_elm->base_data.size.y - 20), ui_state.tooltip_font, 0,
879 text::alignment::left, text::text_color::white, true }, 10);
883 container.used_width = -container.used_width;
884 for(
auto& t : container.base_layout.contents) {
885 t.x += 16 + container.used_width;
889 for(
auto& t : container.base_layout.contents) {
894 ui_state.
tooltip->base_data.size.x = int16_t(container.used_width + 32);
895 ui_state.
tooltip->base_data.size.y = int16_t(container.used_height + 32);
896 if(container.used_width > 0)
939 prov = dcon::province_id{};
954 auto c =
world.province_get_nation_from_province_control(prov);
970 && !mouse_probe.under_mouse
971 && !tooltip_probe.under_mouse
984 prov = dcon::province_id{};
988 text::layout_parameters{ 0, 0, tooltip_width, int16_t(ui_state.root->base_data.size.y - 20), ui_state.tooltip_font, 0, text::alignment::left, text::text_color::white, true },
992 container.used_width = -container.used_width;
993 for(
auto& t : container.base_layout.contents) {
994 t.x += 16 + container.used_width;
998 for(
auto& t : container.base_layout.contents) {
1003 ui_state.
tooltip->base_data.size.x = int16_t(container.used_width + 32);
1004 ui_state.
tooltip->base_data.size.y = int16_t(container.used_height + 32);
1005 if(container.used_width > 0) {
1007 auto mid_point =
world.province_get_mid_point(prov);
1011 glm::vec2 screen_pos;
1029 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1030 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1032 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1043 glDepthRange(-1.0f, 1.0f);
1045 if(gfx_def.primary_texture_handle) {
1057 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1065 glDepthRange(-1.0f, 1.0f);
1076 constexpr static auto tooltip_delay = std::chrono::milliseconds{ 0 };
1078 if((std::chrono::steady_clock::now() -
tooltip_timer) > tooltip_delay) {
1106 }
else if(!mouse_probe.under_mouse && !tooltip_probe.under_mouse) {
1108 if(last_prov_id != now_prov_id) {
1111 last_prov_id = now_prov_id;
1123 static const std::string_view elem_names[] = {
1125 "production_goods_name",
1127 "new_factory_option",
1128 "ledger_legend_entry",
1131 for(
const auto& elem_name : elem_names) {
1134 auto& gfx_def =
ui_defs.
gui[it->second.definition];
1135 gfx_def.flags &=
~ui::element_data::orientation_mask;
1141 static const std::string_view elem_names[] = {
1144 "event_election_window",
1145 "invest_project_window",
1150 "defaultdiplomacydialog",
1151 "gpselectdiplomacydialog",
1155 "setupcrisisbackdowndialog",
1156 "endofnavalcombatpopup",
1157 "endoflandcombatpopup",
1158 "ingame_lobby_window",
1160 for(
const auto& elem_name : elem_names) {
1163 auto& gfx_def =
ui_defs.
gui[it->second.definition];
1177 auto window = ui::make_element_by_type<ui::console_window>(*
this,
"console_wnd");
1179 window->set_visible(*
this,
false);
1183 auto new_elm = ui::make_element_by_type<ui::chat_window>(*
this,
"ingame_lobby_window");
1198 return std::string_view();
1200 auto start_position =
key_data.data() + tag.index();
1202 auto end_position = start_position;
1203 for(; end_position <
key_data.data() + data_size; ++end_position) {
1204 if(*end_position == 0)
1207 return std::string_view(
key_data.data() + tag.index(),
size_t(end_position - start_position));
1214 auto end_position = start_position;
1215 for(; end_position <
locale_text_data.data() + data_size; ++end_position) {
1216 if(*end_position == 0)
1219 return std::string_view(
locale_text_data.data() + tag,
size_t(end_position - start_position));
1230 auto assets_dir = open_directory(root_dir,
NATIVE(
"assets/localisation"));
1232 auto load_base_files = [&](int32_t column) {
1233 auto text_dir = open_directory(root_dir,
NATIVE(
"localisation"));
1234 for(
auto& file : list_files(text_dir,
NATIVE(
".csv"))) {
1235 if(
auto ofile = open_file(file); ofile) {
1236 auto content = view_contents(*ofile);
1240 for(
auto& file : list_files(assets_dir,
NATIVE(
".csv"))) {
1241 if(
auto ofile = open_file(file); ofile) {
1242 auto content = view_contents(*ofile);
1248 if(locale_name.starts_with(
"en")) {
1250 }
else if(locale_name.starts_with(
"fr")) {
1252 }
else if(locale_name.starts_with(
"de")) {
1254 }
else if(locale_name.starts_with(
"pl")) {
1256 }
else if(locale_name.starts_with(
"es")) {
1258 }
else if(locale_name.starts_with(
"it")) {
1260 }
else if(locale_name.starts_with(
"sv")) {
1262 }
else if(locale_name.starts_with(
"cs")) {
1264 }
else if(locale_name.starts_with(
"hu")) {
1266 }
else if(locale_name.starts_with(
"nl")) {
1267 load_base_files(10);
1268 }
else if(locale_name.starts_with(
"pt")) {
1269 load_base_files(11);
1270 }
else if(locale_name.starts_with(
"ru")) {
1271 load_base_files(12);
1272 }
else if(locale_name.starts_with(
"fi")) {
1273 load_base_files(13);
1277 for(
auto& file : list_files(locale_dir,
NATIVE(
".csv"))) {
1278 if(
auto ofile = open_file(file); ofile) {
1279 auto content = view_contents(*ofile);
1298 return dcon::text_key{};
1306 for(
auto c :
text) {
1308 if(unicode == 0x00A7)
1309 unicode = uint16_t(
'?');
1310 if(unicode <= 0x007F) {
1311 temp.push_back(
char(unicode));
1312 }
else if(unicode <= 0x7FF) {
1313 temp.push_back(
char(0xC0 |
uint8_t(0x1F & (unicode >> 6))));
1314 temp.push_back(
char(0x80 |
uint8_t(0x3F & unicode)));
1316 temp.push_back(
char(0xE0 |
uint8_t(0x0F & (unicode >> 12))));
1317 temp.push_back(
char(0x80 |
uint8_t(0x3F & (unicode >> 6))));
1318 temp.push_back(
char(0x80 |
uint8_t(0x3F & unicode)));
1321 assert(temp[temp.size()] ==
'\0');
1325 return add_key_utf8(std::string_view(new_text.data()));
1333 auto length = new_text.length();
1335 return dcon::text_key();
1336 key_data.resize(start + length + 1,
char(0));
1337 std::copy_n(new_text.data(), length,
key_data.data() + start);
1340 auto ret = dcon::text_key(dcon::text_key::value_base_t(start));
1349 for(
auto c :
text) {
1351 if(unicode == 0x00A7)
1352 unicode = uint16_t(
'?');
1353 if(unicode <= 0x007F) {
1355 }
else if(unicode <= 0x7FF) {
1372 auto length = new_text.length();
1383 return dcon::unit_name_id();
1386 for(
auto c :
text) {
1388 if(unicode == 0x00A7)
1389 unicode = uint16_t(
'?');
1390 if(unicode <= 0x007F) {
1391 temp.push_back(
char(unicode));
1392 }
else if(unicode <= 0x7FF) {
1393 temp.push_back(
char(0xC0 |
uint8_t(0x1F & (unicode >> 6))));
1394 temp.push_back(
char(0x80 |
uint8_t(0x3F & unicode)));
1396 temp.push_back(
char(0xE0 |
uint8_t(0x0F & (unicode >> 12))));
1397 temp.push_back(
char(0x80 |
uint8_t(0x3F & (unicode >> 6))));
1398 temp.push_back(
char(0x80 |
uint8_t(0x3F & unicode)));
1402 assert(temp[temp.size()] ==
'\0');
1404 unit_names.resize(start + temp.length() + 1,
char(0));
1405 std::copy_n(temp.data(), temp.length(),
unit_names.data() + start);
1408 return dcon::unit_name_id(dcon::unit_name_id::value_base_t(
unit_names_indices.size() - 1));
1412 return std::string_view();
1416 auto end_position = start_position;
1417 for(; end_position <
unit_names.data() + data_size; ++end_position) {
1418 if(*end_position == 0)
1431 return dcon::trigger_key();
1435 std::boyer_moore_horspool_searcher(data.data(), data.data() + data.size()));
1437 auto const start = search_result -
trigger_data.data();
1441 return dcon::trigger_key(dcon::trigger_key::value_base_t(d - 1));
1445 return dcon::trigger_key(dcon::trigger_key::value_base_t(
trigger_data_indices.size() - 1 - 1));
1449 auto size = data.size();
1451 std::copy_n(data.data(), size,
trigger_data.data() + start);
1454 return dcon::trigger_key(dcon::trigger_key::value_base_t(
trigger_data_indices.size() - 1 - 1));
1465 return dcon::effect_key();
1469 std::boyer_moore_horspool_searcher(data.data(), data.data() + data.size()));
1471 auto const start = search_result -
effect_data.data();
1475 return dcon::effect_key(dcon::effect_key::value_base_t(d - 1));
1479 return dcon::effect_key(dcon::effect_key::value_base_t(
effect_data_indices.size() - 1 - 1));
1483 auto size = data.size();
1485 std::copy_n(data.data(), size,
effect_data.data() + start);
1488 return dcon::effect_key(dcon::effect_key::value_base_t(
effect_data_indices.size() - 1 - 1));
1496 char* ptr = &buffer[0];
1499 std::memcpy(ptr, &user_settings.x, sizeof(user_settings.x)); \
1500 ptr += sizeof(user_settings.x);
1512 constexpr size_t lower_half_count = 98;
1520 constexpr size_t upper_half_count = 128 - 98;
1522 ptr += upper_half_count;
1524 ptr += upper_half_count;
1526 ptr += upper_half_count;
1535 US_SAVE(left_mouse_click_hold_and_release);
1537 US_SAVE(mouse_edge_scrolling);
1542 US_SAVE(diplomatic_message_popup);
1543 US_SAVE(wasd_for_map_movement);
1544 US_SAVE(notify_rebels_defeat);
1554 auto settings_file = open_file(settings_location,
NATIVE(
"user_settings.dat"));
1556 auto content = view_contents(*settings_file);
1557 auto ptr = content.data;
1560 if(ptr > content.data + content.file_size - sizeof(user_settings.x)) break; \
1561 std::memcpy(&user_settings.x, ptr, sizeof(user_settings.x)); \
1562 ptr += sizeof(user_settings.x);
1576 constexpr size_t lower_half_count = 98;
1588 constexpr size_t upper_half_count = 128 - 98;
1590 ptr += upper_half_count;
1592 ptr += upper_half_count;
1594 ptr += upper_half_count;
1603 US_LOAD(left_mouse_click_hold_and_release);
1605 US_LOAD(mouse_edge_scrolling);
1610 US_LOAD(diplomatic_message_popup);
1611 US_LOAD(wasd_for_map_movement);
1612 US_LOAD(notify_rebels_defeat);
1665 bool locale_loaded =
false;
1680 for(
auto l :
world.in_locale) {
1681 auto ln = l.get_locale_name();
1682 auto ln_sv = std::string_view{ (
char const*)ln.begin(), ln.size() };
1683 if(ln_sv == lname) {
1685 locale_loaded =
true;
1690 if(!locale_loaded) {
1691 for(
auto l :
world.in_locale) {
1692 auto ln = l.get_locale_name();
1693 auto ln_sv = std::string_view{ (
char const*)ln.begin(), ln.size() };
1694 if(ln_sv ==
"en-US") {
1696 locale_loaded =
true;
1702 if(!locale_loaded) {
1718 auto poptypes = open_directory(root,
NATIVE(
"poptypes"));
1721 auto full_name = get_full_name(file);
1722 auto last = full_name.c_str() + full_name.length();
1723 auto first = full_name.c_str();
1724 for(; last > first; --last) {
1728 auto start_of_name = last;
1729 for(; start_of_name >= first; --start_of_name) {
1730 if(*start_of_name ==
NATIVE(
'\\') || *start_of_name ==
NATIVE(
'/')) {
1738 auto type_id =
state.
world.create_pop_type();
1739 state.
world.pop_type_set_name(type_id, name_id);
1740 context.
map_of_poptypes.insert_or_assign(std::string(utf8typename), type_id);
1758 auto common = open_directory(root,
NATIVE(
"common"));
1765 auto map = open_directory(root,
NATIVE(
"map"));
1768 auto def_map_file = open_file(
map,
NATIVE(
"default.map"));
1770 auto content = view_contents(*def_map_file);
1773 parsers::parse_default_map_file(gen, err, context);
1781 auto def_csv_file = open_file(
map,
NATIVE(
"definition.csv"));
1783 auto content = view_contents(*def_csv_file);
1794 auto adj_csv_file = open_file(
map,
NATIVE(
"adjacencies.csv"));
1796 auto adj_content = view_contents(*adj_csv_file);
1852 auto countries = open_file(common,
NATIVE(
"countries.txt"));
1854 auto content = view_contents(*countries);
1857 parsers::parse_national_identity_file(gen, err, context);
1865 auto religion = open_file(common,
NATIVE(
"religion.txt"));
1867 auto content = view_contents(*religion);
1870 parsers::parse_religion_file(gen, err, context);
1878 auto cultures = open_file(common,
NATIVE(
"cultures.txt"));
1880 auto content = view_contents(*cultures);
1883 parsers::parse_culture_file(gen, err, context);
1892 if(
world.commodity_size() == 0) {
1894 auto money_id =
world.create_commodity();
1895 assert(money_id.index() == 0);
1897 auto goods = open_file(common,
NATIVE(
"goods.txt"));
1899 auto content = view_contents(*goods);
1902 parsers::parse_goods_file(gen, err, context);
1911 auto buildings = open_file(common,
NATIVE(
"buildings.txt"));
1913 auto content = view_contents(*buildings);
1916 parsers::parse_building_file(gen, err, context);
1929 parsers::parse_ideology_file(gen, err, context);
1939 auto content = view_contents(*context.
issues_file);
1942 parsers::parse_issues_file(gen, err, context);
1965 auto governments = open_file(common,
NATIVE(
"governments.txt"));
1967 auto content = view_contents(*governments);
1970 parsers::parse_governments_file(gen, err, context);
1983 parsers::parse_cb_types_file(gen, err, context);
1991 auto traits = open_file(common,
NATIVE(
"traits.txt"));
1993 auto content = view_contents(*traits);
1996 parsers::parse_traits_file(gen, err, context);
2006 auto content = view_contents(*context.
crimes_file);
2009 parsers::parse_crimes_file(gen, err, context);
2020 err.
file_name =
"triggered_modifiers.txt";
2022 parsers::parse_triggered_modifiers_file(gen, err, context);
2025 err.
accumulated_errors +=
"File common/triggered_modifiers.txt could not be opened\n";
2030 auto nv_file = open_file(common,
NATIVE(
"nationalvalues.txt"));
2032 auto content = view_contents(*nv_file);
2035 parsers::parse_national_values_file(gen, err, context);
2043 auto sm_file = open_file(common,
NATIVE(
"static_modifiers.txt"));
2045 auto content = view_contents(*sm_file);
2048 parsers::parse_static_modifiers_file(gen, err, context);
2056 auto em_file = open_file(common,
NATIVE(
"event_modifiers.txt"));
2058 auto content = view_contents(*em_file);
2061 parsers::parse_event_modifiers_file(gen, err, context);
2073 auto opened_file = open_file(defines_file);
2075 auto content = view_contents(*opened_file);
2077 defines.
parse_file(*
this, std::string_view(content.data, content.data + content.file_size), err);
2091 parsers::parse_rebel_types_file(gen, err, context);
2100 auto terrain_file = open_file(
map,
NATIVE(
"terrain.txt"));
2102 auto content = view_contents(*terrain_file);
2105 parsers::parse_terrain_file(gen, err, context);
2113 auto region_file = open_file(
map,
NATIVE(
"region.txt"));
2115 auto content = view_contents(*region_file);
2118 parsers::parse_region_file(gen, err, context);
2126 auto super_region_file = open_file(
map,
NATIVE(
"super_region.txt"));
2127 if(super_region_file) {
2128 auto content = view_contents(*super_region_file);
2131 parsers::parse_region_file(gen, err, context);
2138 auto continent_file = open_file(
map,
NATIVE(
"continent.txt"));
2139 if(continent_file) {
2140 auto content = view_contents(*continent_file);
2143 parsers::parse_continent_file(gen, err, context);
2151 auto climate_file = open_file(
map,
NATIVE(
"climate.txt"));
2153 auto content = view_contents(*climate_file);
2156 parsers::parse_climate_file(gen, err, context);
2164 auto tech_file = open_file(common,
NATIVE(
"technology.txt"));
2166 auto content = view_contents(*tech_file);
2169 parsers::parse_technology_main_file(gen, err, context);
2177 auto inventions = open_directory(root,
NATIVE(
"inventions"));
2202 auto i_file = open_file(invf);
2204 auto content = view_contents(*i_file);
2207 parsers::parse_inventions_file(gen, err, invention_context);
2216 auto units = open_directory(root,
NATIVE(
"units"));
2218 auto opened_file = open_file(unit_file);
2220 auto content = view_contents(*opened_file);
2223 parsers::parse_unit_file(gen, err, context);
2242 world.political_party_resize_party_issues(
world.issue_size());
2244 world.province_resize_party_loyalty(
world.ideology_size());
2247 world.pop_type_resize_everyday_needs(
world.commodity_size());
2248 world.pop_type_resize_luxury_needs(
world.commodity_size());
2249 world.pop_type_resize_life_needs(
world.commodity_size());
2250 world.pop_type_resize_ideology(
world.ideology_size());
2251 world.pop_type_resize_issues(
world.issue_option_size());
2252 world.pop_type_resize_promotion(
world.pop_type_size());
2254 world.national_focus_resize_production_focus(
world.commodity_size());
2256 world.technology_resize_activate_building(
world.factory_type_size());
2261 world.invention_resize_activate_building(
world.factory_type_size());
2265 world.rebel_type_resize_government_change(
world.government_type_size());
2268 world.nation_resize_active_inventions(
world.invention_size());
2269 world.nation_resize_active_technologies(
world.technology_size());
2270 world.nation_resize_upper_house(
world.ideology_size());
2272 world.national_identity_resize_government_flag_type(
world.government_type_size());
2273 world.national_identity_resize_government_name(
world.government_type_size());
2274 world.national_identity_resize_government_adjective(
world.government_type_size());
2275 world.national_identity_resize_government_ruler_name(
world.government_type_size());
2276 world.national_identity_resize_government_color(
world.government_type_size());
2279 for(
auto ident :
world.in_national_identity) {
2282 auto const name = tag +
"_" + named_gov.first;
2284 ident.set_government_name(named_gov.second, name_k);
2285 auto const adj = tag +
"_" + named_gov.first +
"_ADJ";
2287 ident.set_government_adjective(named_gov.second, adj_k);
2288 auto const ruler = tag +
"_" + named_gov.first +
"_ruler";
2290 ident.set_government_ruler_name(named_gov.second, ruler_k);
2295 auto stdir = open_directory(root,
NATIVE(
"scripted triggers"));
2297 auto opened_file = open_file(st_file);
2299 auto content = view_contents(*opened_file);
2302 parsers::parse_scripted_trigger_file(gen, err, context);
2307 world.for_each_national_identity([&](dcon::national_identity_id i) {
2311 auto content = view_contents(*country_file);
2314 parsers::parse_country_file(gen, err, c_context);
2318 world.province_resize_rgo_max_size_per_good(
world.commodity_size());
2321 auto history = open_directory(root,
NATIVE(
"history"));
2323 auto prov_history = open_directory(history,
NATIVE(
"provinces"));
2324 for(
auto subdir : list_subdirectories(prov_history)) {
2326 for(
auto province_file : list_files(subdir,
NATIVE(
".csv"))) {
2327 auto opened_file = open_file(province_file);
2330 auto content = view_contents(*opened_file);
2335 for(
auto prov_file : list_files(subdir,
NATIVE(
".txt"))) {
2337 auto name_start = file_name.c_str();
2338 auto name_end = name_start + file_name.length();
2340 if(name_start < name_end && !isdigit(*name_start))
2343 auto value_start = name_start;
2344 for(; value_start < name_end; ++value_start) {
2345 if(isdigit(*value_start))
2348 auto value_end = value_start;
2349 for(; value_end < name_end; ++value_end) {
2350 if(!isdigit(*value_end))
2355 auto province_id =
parsers::parse_int(std::string_view(value_start, value_end), 0, err);
2357 auto opened_file = open_file(prov_file);
2361 auto content = view_contents(*opened_file);
2363 parsers::parse_province_history_file(gen, err, pf_context);
2372 auto pop_history = open_directory(history,
NATIVE(
"pops"));
2374 auto start_dir_name = std::to_string(startdate.year) +
"." + std::to_string(startdate.month) +
"." + std::to_string(startdate.day);
2380 auto directory_file_count = list_files(date_directory,
NATIVE(
".txt")).size();
2381 if(directory_file_count == 0)
2383 for(
auto pop_file : list_files(date_directory,
NATIVE(
".txt"))) {
2384 auto opened_file = open_file(pop_file);
2387 auto content = view_contents(*opened_file);
2389 parsers::parse_pop_history_file(gen, err, context);
2395 for(
auto pop_file : list_files(date_directory,
NATIVE(
".csv"))) {
2396 auto opened_file = open_file(pop_file);
2399 auto content = view_contents(*opened_file);
2407 auto poptypes = open_directory(root,
NATIVE(
"poptypes"));
2412 auto content = view_contents(*opened_file);
2415 parsers::parse_poptype_file(gen, err, inner_context);
2425 parsers::parse_individual_ideology(pr.second.generator_state, err, new_context);
2440 err.
file_name =
"triggered_modifiers.txt";
2451 parsers::parse_cb_body(r.second.generator_state, err, new_context);
2461 world.issue_option_resize_support_modifiers(
world.issue_option_size());
2478 auto nat_focus = open_file(common,
NATIVE(
"national_focus.txt"));
2480 auto content = view_contents(*nat_focus);
2483 parsers::parse_national_focus_file(gen, err, context);
2491 auto pop_types_file = open_file(common,
NATIVE(
"pop_types.txt"));
2492 if(pop_types_file) {
2493 auto content = view_contents(*pop_types_file);
2496 parsers::parse_main_pop_type_file(gen, err, context);
2517 for(
auto inv :
world.in_invention) {
2519 auto lim_trigger = inv.get_limit();
2522 [&](uint16_t* tval) {
2523 if((tval[0] & trigger::code_mask) == trigger::technology) {
2524 auto findex = this->world.technology_get_folder_index(trigger::payload(tval[1]).tech_id);
2525 inv.set_technology_type(uint8_t(this->culture_definitions.tech_folders[findex].category));
2538 auto on_action = open_file(common,
NATIVE(
"on_actions.txt"));
2540 auto content = view_contents(*on_action);
2541 err.file_name =
"on_actions.txt";
2543 parsers::parse_on_action_file(gen, err, context);
2546 err.accumulated_errors +=
"File common/on_actions.txt could not be opened\n";
2554 err.file_name =
"production_types.txt";
2558 parsers::parse_production_types_file(gen, err, new_context);
2560 for(
const auto ft : world.in_factory_type) {
2561 if(!
bool(world.factory_type_get_output(ft))) {
2562 err.accumulated_errors +=
"No output defined for factory " + std::string(
text::produce_simple_string(*
this, world.factory_type_get_name(ft))) +
" (" + err.file_name +
")\n";
2565 if(!new_context.found_worker_types) {
2567 err.accumulated_errors +=
"Unable to identify factory worker types from production_types.txt\n";
2571 err.accumulated_errors +=
"File common/production_types.txt could not be opened\n";
2576 err.file_name =
"rebel_types.txt";
2577 for(
auto& r : context.map_of_rebeltypes) {
2585 auto opened_file =
open_file(decision_file);
2590 parsers::parse_decision_file(gen, err, context);
2597 std::vector<simple_fs::file> held_open_files;
2599 auto opened_file =
open_file(event_file);
2604 parsers::parse_event_file(gen, err, context);
2605 held_open_files.emplace_back(std::move(*opened_file));
2608 err.file_name =
"pending events";
2615 auto opened_file =
open_file(news_file);
2628 auto opened_file =
open_file(tutorial_file);
2633 parsers::parse_tutorial_file(gen, err, context);
2645 parsers::parse_battleplan_settings_file(gen, err, context);
2656 if(file_name ==
NATIVE(
"v2dd2.txt"))
2658 auto last = file_name.c_str() + file_name.length();
2659 auto first = file_name.c_str();
2660 auto start_of_name =
last;
2661 for(; start_of_name >=
first; --start_of_name) {
2662 if(*start_of_name ==
NATIVE(
'\\') || *start_of_name ==
NATIVE(
'/')) {
2667 if(last - start_of_name >= 3) {
2669 if(
auto it = context.map_of_ident_names.find(
nations::tag_to_int(utf8name[0], utf8name[1], utf8name[2])); it != context.map_of_ident_names.end()) {
2670 auto holder = context.state.world.national_identity_get_nation_from_identity_holder(it->second);
2675 err.file_name = utf8name;
2678 parsers::parse_oob_file(gen, err, new_context);
2681 err.accumulated_warnings +=
"dead tag " + utf8name.substr(0, 3) +
" encountered while scanning oob files\n";
2684 err.accumulated_warnings +=
"invalid tag " + utf8name.substr(0, 3) +
" encountered while scanning oob files\n";
2689 auto startdate = current_date.to_ymd(start_date);
2690 auto start_dir_name = std::to_string(startdate.year);
2694 auto last = file_name.c_str() + file_name.length();
2695 auto first = file_name.c_str();
2696 auto start_of_name =
last;
2697 for(; start_of_name >=
first; --start_of_name) {
2698 if(*start_of_name ==
NATIVE(
'\\') || *start_of_name ==
NATIVE(
'/')) {
2703 if(last - start_of_name >= 3) {
2705 if(
auto it = context.map_of_ident_names.find(
nations::tag_to_int(utf8name[0], utf8name[1], utf8name[2])); it != context.map_of_ident_names.end()) {
2706 auto holder = context.state.world.national_identity_get_nation_from_identity_holder(it->second);
2711 err.file_name = utf8name;
2714 parsers::parse_oob_file(gen, err, new_context);
2717 err.accumulated_warnings +=
"dead tag " + utf8name.substr(0, 3) +
" encountered while scanning oob files\n";
2720 err.accumulated_warnings +=
"invalid tag " + utf8name.substr(0, 3) +
" encountered while scanning oob files\n";
2734 parsers::parse_diplomacy_file(gen, err, context);
2740 world.nation_resize_flag_variables(
uint32_t(national_definitions.num_allocated_national_flags));
2741 national_definitions.global_flag_variables.resize((national_definitions.num_allocated_global_flags + 7) / 8, dcon::bitfield_type{ 0 });
2742 world.nation_resize_accepted_cultures(world.culture_size());
2744 std::vector<std::pair<dcon::nation_id, dcon::decision_id>> pending_decisions;
2751 auto last = file_name.c_str() + file_name.length();
2752 auto first = file_name.c_str();
2753 auto start_of_name =
last;
2754 for(; start_of_name >=
first; --start_of_name) {
2755 if(*start_of_name ==
NATIVE(
'\\') || *start_of_name ==
NATIVE(
'/')) {
2760 if(last - start_of_name >= 6) {
2763 if(
auto it = context.map_of_ident_names.find(
nations::tag_to_int(utf8name[0], utf8name[1], utf8name[2]));
2764 it != context.map_of_ident_names.end()) {
2765 auto holder = context.state.world.national_identity_get_nation_from_identity_holder(it->second);
2768 holder = world.create_nation();
2769 world.nation_set_diplomatic_points(holder, 1.0f);
2770 world.try_create_identity_holder(holder, it->second);
2775 auto opened_file =
open_file(country_file);
2777 err.file_name = utf8name;
2780 parsers::parse_country_history_file(gen, err, new_context);
2784 err.accumulated_warnings +=
"invalid tag " + utf8name.substr(0, 3) +
" encountered while scanning country history files\n";
2801 parsers::parse_war_history_file(gen, err, new_context);
2808 world.nation_resize_stockpiles(world.commodity_size());
2809 world.nation_resize_variables(
uint32_t(national_definitions.num_allocated_national_variables));
2811 national_definitions.global_flag_variables.resize((national_definitions.num_allocated_global_flags + 7) / 8, dcon::bitfield_type{ 0 });
2814 world.for_each_national_identity([&](dcon::national_identity_id
id) {
2815 if(!world.national_identity_get_nation_from_identity_holder(
id)) {
2816 auto new_nation = world.create_nation();
2817 world.try_create_identity_holder(new_nation, id);
2822 world.nation_resize_rgo_goods_output(world.commodity_size());
2823 world.nation_resize_factory_goods_output(world.commodity_size());
2824 world.nation_resize_factory_goods_throughput(world.commodity_size());
2825 world.nation_resize_rgo_size(world.commodity_size());
2826 world.nation_resize_rebel_org_modifier(world.rebel_type_size());
2827 world.nation_resize_active_unit(
uint32_t(military_definitions.unit_base_definitions.size()));
2828 world.nation_resize_active_crime(
uint32_t(culture_definitions.crimes.size()));
2829 world.nation_resize_active_building(world.factory_type_size());
2830 world.nation_resize_unit_stats(
uint32_t(military_definitions.unit_base_definitions.size()));
2836 world.province_resize_rgo_profit_per_good(world.commodity_size());
2837 world.province_resize_rgo_actual_production_per_good(world.commodity_size());
2838 world.province_resize_rgo_employment_per_good(world.commodity_size());
2839 world.province_resize_rgo_target_employment_per_good(world.commodity_size());
2841 world.nation_resize_domestic_market_pool(world.commodity_size());
2842 world.nation_resize_real_demand(world.commodity_size());
2843 world.nation_resize_intermediate_demand(world.commodity_size());
2844 world.nation_resize_stockpile_targets(world.commodity_size());
2845 world.nation_resize_drawing_on_stockpiles(world.commodity_size());
2846 world.nation_resize_life_needs_costs(world.pop_type_size());
2847 world.nation_resize_everyday_needs_costs(world.pop_type_size());
2848 world.nation_resize_luxury_needs_costs(world.pop_type_size());
2849 world.nation_resize_imports(world.commodity_size());
2850 world.nation_resize_army_demand(world.commodity_size());
2851 world.nation_resize_navy_demand(world.commodity_size());
2852 world.nation_resize_construction_demand(world.commodity_size());
2853 world.nation_resize_private_construction_demand(world.commodity_size());
2854 world.nation_resize_demand_satisfaction(world.commodity_size());
2855 world.nation_resize_direct_demand_satisfaction(world.commodity_size());
2856 world.nation_resize_life_needs_weights(world.commodity_size());
2857 world.nation_resize_everyday_needs_weights(world.commodity_size());
2858 world.nation_resize_luxury_needs_weights(world.commodity_size());
2859 world.nation_resize_effective_prices(world.commodity_size());
2863 nations_by_rank.resize(2000);
2864 nations_by_industrial_score.resize(2000);
2865 nations_by_military_score.resize(2000);
2866 nations_by_prestige_score.resize(2000);
2867 crisis_participants.resize(2000);
2869 for(
auto t : world.in_technology) {
2870 for(
auto n : world.in_nation) {
2871 if(
n.get_active_technologies(t))
2875 for(
auto t : world.in_invention) {
2876 for(
auto n : world.in_nation) {
2879 n.set_active_inventions(t,
true);
2881 if(
n.get_active_inventions(t)) {
2890 world.for_each_province_adjacency([&](dcon::province_adjacency_id
id) {
2891 auto frel =
fatten(world,
id);
2892 auto prov_a = frel.get_connected_provinces(0);
2893 auto prov_b = frel.get_connected_provinces(1);
2894 if(prov_a.id.index() < province_definitions.first_sea_province.index() && prov_b.id.index() >= province_definitions.first_sea_province.index()) {
2896 }
else if(prov_a.id.index() >= province_definitions.first_sea_province.index() && prov_b.id.index() < province_definitions.first_sea_province.index()) {
2899 if(prov_a.get_state_from_abstract_state_membership() != prov_b.get_state_from_abstract_state_membership()) {
2902 if(prov_a.get_nation_from_province_ownership() != prov_b.get_nation_from_province_ownership()) {
2909 for(int32_t i = 0; i < province_definitions.first_sea_province.index(); ++i) {
2910 dcon::province_id
id{ dcon::province_id::value_base_t(i) };
2911 if(!world.province_get_terrain(
id)) {
2913 if(terrain_type < 64) {
2914 auto modifier = context.modifier_by_terrain_index[terrain_type];
2915 world.province_set_terrain(
id, modifier);
2919 for(int32_t i = province_definitions.first_sea_province.index(); i < int32_t(world.province_size()); ++i) {
2920 dcon::province_id
id{ dcon::province_id::value_base_t(i) };
2921 world.province_set_terrain(
id, context.ocean_terrain);
2929 world.for_each_province([&](dcon::province_id
id) { world.province_set_connected_region_id(
id, 0); });
2931 std::vector<dcon::province_id> to_fill_list;
2932 std::vector<int32_t> region_sizes;
2934 uint16_t current_fill_id = 0;
2935 province_definitions.connected_region_is_coastal.clear();
2937 to_fill_list.reserve(world.province_size());
2939 for(int32_t i = int32_t(world.province_size()); i-- > province_definitions.first_sea_province.index();) {
2940 dcon::province_id
id{ dcon::province_id::value_base_t(i) };
2942 if(world.province_get_connected_region_id(
id) == 0) {
2945 region_sizes.push_back(0);
2946 to_fill_list.push_back(
id);
2948 while(!to_fill_list.empty()) {
2949 auto current_id = to_fill_list.back();
2950 to_fill_list.pop_back();
2951 region_sizes.back() += 1;
2953 world.province_set_connected_region_id(current_id, current_fill_id);
2954 for(
auto rel : world.province_get_province_adjacency(current_id)) {
2956 if(
rel.get_connected_provinces(0).get_connected_region_id() == 0)
2957 to_fill_list.push_back(
rel.get_connected_provinces(0));
2958 if(
rel.get_connected_provinces(1).get_connected_region_id() == 0)
2959 to_fill_list.push_back(
rel.get_connected_provinces(1));
2964 to_fill_list.clear();
2969 for(int32_t i = 0; i < int32_t(region_sizes.size()); ++i) {
2970 if(region_sizes[max] < region_sizes[i])
2974 if(!region_sizes.empty()) {
2975 for(
auto k =
uint32_t(context.state.province_definitions.first_sea_province.index()); k < context.state.world.province_size(); ++k) {
2976 dcon::province_id p{ dcon::province_id::value_base_t(k) };
2977 if(world.province_get_connected_region_id(p) != int16_t(max + 1)) {
2978 world.province_set_is_coast(p,
false);
2979 world.province_set_port_to(p, dcon::province_id{});
2980 for(
auto adj : context.state.world.province_get_province_adjacency(p)) {
2981 auto other =
adj.get_connected_provinces(0) != p ?
adj.get_connected_provinces(0) :
adj.get_connected_provinces(1);
2982 other.set_is_coast(
false);
2983 other.set_port_to(dcon::province_id{});
2991 for(
auto ip : context.special_impassible) {
2992 for(
auto adj : world.province_get_province_adjacency(ip)) {
2999 for(
auto adj : world.province_get_province_adjacency(p)) {
3000 auto other = adj.get_connected_provinces(0) != p ? adj.get_connected_provinces(0) : adj.get_connected_provinces(1);
3001 auto bits = adj.get_type();
3002 if(other && (bits & province::border::coastal_bit) != 0 && (bits & province::border::impassible_bit) == 0) {
3003 world.province_set_port_to(p, other.id);
3004 world.province_set_is_coast(p, true);
3012 bool is_mine = world.commodity_get_is_mine(world.province_get_rgo(p));
3014 for(
auto pop : world.province_get_pop_location(p)) {
3015 if(is_mine && pop.get_pop().get_poptype() == culture_definitions.farmers) {
3016 pop.get_pop().set_poptype(culture_definitions.laborers);
3018 if(!is_mine &&
pop.get_pop().get_poptype() == culture_definitions.laborers) {
3019 pop.get_pop().set_poptype(culture_definitions.farmers);
3024 bool gov_error =
false;
3025 for(
auto n : world.in_nation) {
3026 auto g =
n.get_government_type();
3027 if(!g &&
n.get_owned_province_count() != 0) {
3029 err.accumulated_errors +=
name +
" exists but has no governmentnt (This will result in a crash)\n";
3039 for(
auto& s : context.gfx_context.nation_buttons_allow) {
3040 if(s.button_element) {
3041 err.file_name = s.original_file;
3043 ui_defs.gui[s.button_element].data.button.scriptable_enable =
make_trigger(s.generator_state, err, t_context);
3047 for(
auto& s : context.gfx_context.nation_buttons_effect) {
3048 if(s.button_element) {
3049 err.file_name = s.original_file;
3051 ui_defs.gui[s.button_element].data.button.scriptable_effect =
make_effect(s.generator_state, err, t_context);
3055 for(
auto& s : context.gfx_context.province_buttons_allow) {
3056 if(s.button_element) {
3057 err.file_name = s.original_file;
3058 auto existing_scripting = ui_defs.gui[s.button_element].data.button.get_button_scripting();
3060 err.accumulated_errors += std::string(
"Button ") + std::string(to_string_view(ui_defs.gui[s.button_element].name)) +
"in " + err.file_name +
" has both province and nation scripting set\n";
3063 ui_defs.gui[s.button_element].data.button.scriptable_enable =
make_trigger(s.generator_state, err, t_context);
3068 for(
auto& s : context.gfx_context.province_buttons_effect) {
3069 if(s.button_element) {
3070 err.file_name = s.original_file;
3071 auto existing_scripting = ui_defs.gui[s.button_element].data.button.get_button_scripting();
3073 err.accumulated_errors += std::string(
"Button ") + std::string(to_string_view(ui_defs.gui[s.button_element].name)) +
"in " + err.file_name +
" has both province and nation scripting set\n";
3076 ui_defs.gui[s.button_element].data.button.scriptable_effect =
make_effect(s.generator_state, err, t_context);
3083 for(
auto n : world.in_navy) {
3084 auto p =
n.get_navy_location().get_location();
3085 if(p.id.index() >= province_definitions.first_sea_province.index()) {
3088 auto pp = world.province_get_port_to(p);
3089 auto adj = world.get_province_adjacency_by_province_pair(p, pp);
3091 err.accumulated_errors +=
"Navy defined in " +
text::produce_simple_string(*
this, p.get_name()) +
"; but said province isn't connected to a sea province\n";
3095 for(
auto a : world.in_army) {
3096 auto p = a.get_army_location().get_location();
3097 if(p.id.index() >= province_definitions.first_sea_province.index()) {
3106 for(
auto nid : world.in_national_identity) {
3112 std::fill(has_reported.begin(), has_reported.end(),
false);
3113 for(
auto g : world.in_government_type) {
3114 if(!has_reported[g.get_flag()]) {
3117 file_str +=
NATIVE(
".tga");
3121 has_reported[g.get_flag()] =
true;
3128 for(
auto p : world.in_pop_location) {
3129 for(
const auto src : p.get_pop().get_regiment_source()) {
3130 if(src.get_regiment().get_army_from_army_membership().get_controller_from_army_control() == p.get_province().get_nation_from_province_ownership())
3132 err.accumulated_warnings +=
"Army defined in " +
text::produce_simple_string(*
this, p.get_province().get_name()) +
"; but regiment comes from a province owned by someone else\n";
3133 if(!src.get_regiment().get_army_from_army_membership().get_is_retreating()
3134 && !src.get_regiment().get_army_from_army_membership().get_navy_from_army_transport()
3135 && !src.get_regiment().get_army_from_army_membership().get_battle_from_army_battle_participation()
3136 && !src.get_regiment().get_army_from_army_membership().get_controller_from_army_rebel_control()) {
3137 auto new_u = world.create_army();
3138 world.army_set_controller_from_army_control(new_u, p.get_province().get_nation_from_province_ownership());
3139 src.get_regiment().set_army_from_army_membership(new_u);
3142 src.get_regiment().set_strength(0.f);
3148 fill_unsaved_data();
3150 for(
auto n : world.in_nation) {
3151 auto g =
n.get_government_type();
3153 if(!(
n.get_owned_province_count() == 0 || world.government_type_is_valid(g))) {
3157 for(
auto g : world.in_government_type) {
3158 for(
auto rt : world.in_rebel_type) {
3159 auto ng = rt.get_government_change(g);
3160 if(!(!ng ||
uint32_t(ng.id.index()) < world.government_type_size())) {
3167 for(
auto pending_decision : pending_decisions) {
3168 dcon::nation_id
n = pending_decision.first;
3169 dcon::decision_id
d = pending_decision.second;
3170 if(
auto e = world.decision_get_effect(d); e)
3192 assert(great_nations.size() == 0);
3195 while(greatpowersfound <
uint32_t(defines.great_nations_count)) {
3196 if(i >= nations_by_rank.size()) {
3199 if(nations_by_rank[i] && world.overlord_get_ruler(world.nation_get_overlord_as_subject(nations_by_rank[i])) == dcon::nation_id()) {
3200 great_nations.push_back(great_nation{
sys::date{0}, nations_by_rank[i] });
3201 world.nation_set_is_great_power(nations_by_rank[i],
true);
3208 for(
auto p : world.in_province) {
3213 if(
auto rgo = world.province_get_rgo(p); !rgo) {
3214 auto name = world.province_get_name(p);
3215 err.accumulated_errors += std::string(
"province ") + text::produce_simple_string(*this, name) +
" is missing an rgo\n";
3216 world.province_set_rgo(p, economy::money);
3233void state::preload() {
3234 adjacency_data_out_of_date =
true;
3235 for(
auto si : world.in_state_instance) {
3236 si.set_naval_base_is_taken(
false);
3237 si.set_capital(dcon::province_id{});
3239 for(
auto n : world.in_nation) {
3240 n.set_combined_issue_rules(0);
3241 n.set_is_at_war(
false);
3242 n.set_allies_count(0);
3243 n.set_vassals_count(0);
3244 n.set_substates_count(0);
3245 n.set_administrative_efficiency(0.0f);
3246 n.set_is_target_of_some_cb(
false);
3247 n.set_in_sphere_of(dcon::nation_id{});
3248 n.set_is_player_controlled(
false);
3249 n.set_is_great_power(
false);
3250 n.set_is_colonial_nation(
false);
3251 n.set_has_flash_point_state(
false);
3252 n.set_ai_is_threatened(
false);
3253 n.set_ai_home_port(dcon::province_id{});
3255 for(
auto p : world.in_pop) {
3258 p.set_is_primary_or_accepted_culture(
false);
3260 for(
auto p : world.in_province) {
3261 p.set_state_membership(dcon::state_instance_id{});
3262 p.set_is_owner_core(
false);
3263 p.set_is_blockaded(
false);
3265 for(
auto m : world.in_movement) {
3266 m.set_pop_support(0.0f);
3267 m.set_radicalism(0.0f);
3269 for(
auto s : world.in_ship) {
3270 s.set_pending_split(
false);
3272 for(
auto r : world.in_regiment) {
3273 r.set_pending_split(
false);
3277void state::on_scenario_load() {
3278 world.pop_type_resize_issues_fns(world.issue_option_size());
3279 world.pop_type_resize_ideology_fns(world.ideology_size());
3280 world.pop_type_resize_promotion_fns(world.pop_type_size());
3282 if(network_mode != network_mode_type::single_player)
3290 std::thread dispatch{ [&]() {
3291 jit_environment = std::make_unique<fif::environment>();
3293 int32_t error_count = 0;
3294 std::string error_list;
3295 jit_environment->report_error = [&](std::string_view s) {
3296 console_command_error += std::string(
"?R ERROR: ") + std::string(s) +
"?W\\n";
3307 for(
auto p : world.in_pop_type) {
3308 for(
auto i : world.in_issue_option) {
3309 auto mkey = world.pop_type_get_issues(p, i);
3310 std::string base_name =
"pi" + std::to_string(p.id.index()) +
"_" + std::to_string(i.id.index());
3313 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3316 std::string fn_str =
": " + base_name +
"internal" +
" drop 0.0 ; ";
3317 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3322 for(
auto id : world.in_ideology) {
3323 auto mkey = world.pop_type_get_ideology(p,
id);
3324 std::string base_name =
"pid" + std::to_string(p.id.index()) +
"_" + std::to_string(
id.
id.index());
3327 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3330 std::string fn_str =
": " + base_name +
"internal" +
" drop 0.0 ; ";
3331 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3336 for(
auto t : world.in_pop_type) {
3337 auto mkey = world.pop_type_get_promotion(p, t);
3338 std::string base_name =
"pp" + std::to_string(p.id.index()) +
"_" + std::to_string(t.id.index());
3341 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3347 auto mkey = world.pop_type_get_migration_target(p);
3348 std::string base_name =
"pmt" + std::to_string(p.id.index());
3351 fn_str +=
":export " + base_name +
"ext" +
" i32 i32 " + base_name +
"internal ; ";
3356 auto mkey = world.pop_type_get_country_migration_target(p);
3357 std::string base_name =
"pcmt" + std::to_string(p.id.index());
3360 fn_str +=
":export " + base_name +
"ext" +
" i32 i32 " + base_name +
"internal ; ";
3366 std::string fn_str =
": promote_internal >pop_id dup " +
fif_trigger::additive_modifier(*
this, culture_definitions.promotion_chance) +
" drop drop r> ; ";
3367 fn_str +=
":export promote_ext i32 promote_internal ; ";
3371 std::string fn_str =
": demote_internal >pop_id dup " +
fif_trigger::additive_modifier(*
this, culture_definitions.demotion_chance) +
" drop drop r> ; ";
3372 fn_str +=
":export demote_ext i32 demote_internal ; ";
3376 fif::perform_jit(*jit_environment);
3381 for(
auto p : world.in_pop_type) {
3382 for(
auto i : world.in_issue_option) {
3383 std::string name =
"pi" + std::to_string(p.id.index()) +
"_" + std::to_string(i.id.index()) +
"ext";
3386 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, name.c_str());
3391 OutputDebugStringA(msg);
3392 OutputDebugStringA(
"\n");
3396 assert(bare_address != 0);
3397 world.pop_type_set_issues_fns(p, i, bare_address);
3400 for(
auto id : world.in_ideology) {
3401 std::string name =
"pid" + std::to_string(p.id.index()) +
"_" + std::to_string(
id.
id.index()) +
"ext";
3404 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, name.c_str());
3409 OutputDebugStringA(msg);
3410 OutputDebugStringA(
"\n");
3414 assert(bare_address != 0);
3415 world.pop_type_set_ideology_fns(p,
id, bare_address);
3418 for(
auto t : world.in_pop_type) {
3419 if(world.pop_type_get_promotion(p, t)) {
3420 std::string name =
"pp" + std::to_string(p.id.index()) +
"_" + std::to_string(t.id.index()) +
"ext";
3423 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, name.c_str());
3428 OutputDebugStringA(msg);
3429 OutputDebugStringA(
"\n");
3433 assert(bare_address != 0);
3434 world.pop_type_set_promotion_fns(p, t, bare_address);
3440 auto mkey = world.pop_type_get_migration_target(p);
3442 std::string base_name =
"pmt" + std::to_string(p.id.index()) +
"ext";
3444 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, base_name.c_str());
3449 OutputDebugStringA(msg);
3450 OutputDebugStringA(
"\n");
3454 assert(bare_address != 0);
3455 world.pop_type_set_migration_target_fn(p, bare_address);
3460 auto mkey = world.pop_type_get_country_migration_target(p);
3462 std::string base_name =
"pcmt" + std::to_string(p.id.index()) +
"ext";
3464 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, base_name.c_str());
3469 OutputDebugStringA(msg);
3470 OutputDebugStringA(
"\n");
3474 assert(bare_address != 0);
3475 world.pop_type_set_country_migration_target_fn(p, bare_address);
3483 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"promote_ext");
3488 OutputDebugStringA(msg);
3489 OutputDebugStringA(
"\n");
3493 assert(bare_address != 0);
3494 culture_definitions.promotion_chance_fn = bare_address;
3499 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"demote_ext");
3504 OutputDebugStringA(msg);
3505 OutputDebugStringA(
"\n");
3509 assert(bare_address != 0);
3510 culture_definitions.demotion_chance_fn = bare_address;
3519 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"set_container");
3524 OutputDebugStringA(msg);
3525 OutputDebugStringA(
"\n");
3529 assert(bare_address != 0);
3530 using ftype = void(*)(
void*);
3531 ftype fn = (ftype)bare_address;
3537 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"set_vector_storage");
3542 OutputDebugStringA(msg);
3543 OutputDebugStringA(
"\n");
3547 assert(bare_address != 0);
3548 using ftype = void(*)(
void*);
3549 ftype fn = (ftype)bare_address;
3550 fn(dcon::shared_backing_storage.allocation);
3555 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"set_state");
3560 OutputDebugStringA(msg);
3561 OutputDebugStringA(
"\n");
3565 assert(bare_address != 0);
3566 using ftype = void(*)(
void*);
3567 ftype fn = (ftype)bare_address;
3581void state::fill_unsaved_data() {
3582 great_nations.reserve(int32_t(defines.great_nations_count));
3585 world.nation_resize_rgo_goods_output(world.commodity_size());
3586 world.nation_resize_factory_goods_output(world.commodity_size());
3587 world.nation_resize_factory_goods_throughput(world.commodity_size());
3588 world.nation_resize_rgo_size(world.commodity_size());
3589 world.nation_resize_rebel_org_modifier(world.rebel_type_size());
3590 world.nation_resize_active_unit(
uint32_t(military_definitions.unit_base_definitions.size()));
3591 world.nation_resize_active_crime(
uint32_t(culture_definitions.crimes.size()));
3592 world.nation_resize_active_building(world.factory_type_size());
3593 world.nation_resize_unit_stats(
uint32_t(military_definitions.unit_base_definitions.size()));
3596 world.province_resize_modifier_values(provincial_mod_offsets::count);
3609 nations_by_rank.resize(2000);
3610 nations_by_industrial_score.resize(2000);
3611 nations_by_military_score.resize(2000);
3612 nations_by_prestige_score.resize(2000);
3613 crisis_participants.resize(2000);
3615 world.for_each_issue([&](dcon::issue_id
id) {
3616 for(
auto& opt : world.issue_get_options(
id)) {
3618 world.issue_option_set_parent_issue(opt,
id);
3622 world.for_each_reform([&](dcon::reform_id
id) {
3623 for(
auto& opt : world.reform_get_options(
id)) {
3625 world.reform_option_set_parent_reform(opt,
id);
3629 for(
auto i : culture_definitions.party_issues) {
3632 for(
auto i : culture_definitions.military_issues) {
3635 for(
auto i : culture_definitions.economic_issues) {
3638 for(
auto i : culture_definitions.social_issues) {
3641 for(
auto i : culture_definitions.political_issues) {
3684 new_n_event.~SPSCQueue();
3697 if(local_player_nation) {
3698 world.nation_set_is_player_controlled(local_player_nation,
true);
3700 for(
auto const& e : pending_n_event) {
3701 if(e.n == local_player_nation) {
3702 auto auto_choice = world.national_event_get_auto_choice(e.e);
3703 if(auto_choice == 0)
3709 for(
auto const& e : pending_f_n_event) {
3710 if(e.n == local_player_nation) {
3711 auto auto_choice = world.free_national_event_get_auto_choice(e.e);
3712 if(auto_choice == 0)
3713 auto b = new_f_n_event.try_push(e);
3718 for(
auto const& e : pending_p_event) {
3719 if(world.province_get_nation_from_province_ownership(e.p) == local_player_nation) {
3720 auto auto_choice = world.provincial_event_get_auto_choice(e.e);
3721 if(auto_choice == 0)
3722 auto b = new_p_event.try_push(e);
3727 for(
auto const& e : pending_f_p_event) {
3728 if(world.province_get_nation_from_province_ownership(e.p) == local_player_nation) {
3729 auto auto_choice = world.free_provincial_event_get_auto_choice(e.e);
3730 if(auto_choice == 0)
3731 auto b = new_f_p_event.try_push(e);
3736 for(
auto const& m : pending_messages) {
3738 auto b = new_requests.try_push(m);
3742 ui_date = current_date;
3755 military_definitions.pending_blackflag_update =
true;
3762 for(
auto p : world.in_pop) {
3764 for(
auto i : world.in_ideology) {
3766 if(0.0 <= val && val <= 1.0f) {
3773 for(
auto i : world.in_ideology) {
3780 for(
auto a : world.in_army) {
3781 if(a.get_arrival_time() && a.get_arrival_time() <= current_date) {
3782 a.set_arrival_time(current_date + 1);
3785 for(
auto a : world.in_navy) {
3786 if(a.get_arrival_time() && a.get_arrival_time() <= current_date) {
3787 a.set_arrival_time(current_date + 1);
3790 for(
auto shp : world.in_ship) {
3791 assert(shp.get_navy_from_navy_membership());
3794 std::vector<dcon::ship_id> sin_battle;
3795 for(
auto b : world.in_naval_battle) {
3796 for(
auto slot : b.get_slots()) {
3800 assert(world.ship_is_valid(slot.ship));
3801 auto it = std::find(sin_battle.begin(), sin_battle.end(), slot.ship);
3802 assert(it == sin_battle.end());
3803 sin_battle.push_back(slot.ship);
3810 game_state_updated.store(
true, std::memory_order::release);
3813void state::single_game_tick() {
3820 game_state_updated.store(
true, std::memory_order::release);
3824 auto ymd_date = current_date.to_ymd(start_date);
3843 concurrency::parallel_for(0, 7, [&](int32_t index) {
3848 if(o >= days_in_month)
3855 auto o =
uint32_t(ymd_date.day + 1);
3856 if(o >= days_in_month)
3863 auto o =
uint32_t(ymd_date.day + 6);
3864 if(o >= days_in_month)
3871 auto o =
uint32_t(ymd_date.day + 7);
3872 if(o >= days_in_month)
3879 auto o =
uint32_t(ymd_date.day + 8);
3880 if(o >= days_in_month)
3887 auto o =
uint32_t(ymd_date.day + 9);
3888 if(o >= days_in_month)
3895 auto o =
uint32_t(ymd_date.day + 10);
3896 if(o >= days_in_month)
3907 concurrency::parallel_for(0, 8, [&](int32_t index) {
3911 auto o =
uint32_t(ymd_date.day + 0);
3912 if(o >= days_in_month)
3919 auto o =
uint32_t(ymd_date.day + 1);
3920 if(o >= days_in_month)
3927 auto o =
uint32_t(ymd_date.day + 2);
3928 if(o >= days_in_month)
3935 auto o =
uint32_t(ymd_date.day + 3);
3936 if(o >= days_in_month)
3943 auto o =
uint32_t(ymd_date.day + 4);
3944 if(o >= days_in_month)
3951 auto o =
uint32_t(ymd_date.day + 5);
3952 if(o >= days_in_month)
3959 [&](
auto ids) { world.province_set_daily_net_migration(ids, ve::fp_vector{}); });
3963 [&](
auto ids) { world.province_set_daily_net_immigration(ids, ve::fp_vector{}); });
3972 auto o =
uint32_t(ymd_date.day + 6);
3973 if(o >= days_in_month)
3978 auto o =
uint32_t(ymd_date.day + 7);
3979 if(o >= days_in_month)
3984 auto o =
uint32_t(ymd_date.day + 8);
3985 if(o >= days_in_month)
3990 auto o =
uint32_t(ymd_date.day + 9);
3991 if(o >= days_in_month)
3996 auto o =
uint32_t(ymd_date.day + 10);
3997 if(o >= days_in_month)
4006 int64_t pc_difference = 0;
4008 if(network_mode != network_mode_type::single_player)
4016 concurrency::parallel_invoke([&]() {
4018 concurrency::parallel_for(0, 17, [&](int32_t index) {
4025 for(
auto n : this->cheat_data.instant_research_nations) {
4026 auto tech = this->world.nation_get_current_research(n);
4027 if(
tech.is_valid()) {
4029 this->world.nation_set_research_points(n, points);
4114 if(current_date.value % 4 == 0) {
4118 if(defines.alice_eval_ai_mil_everyday != 0.0f) {
4125 switch(ymd_date.day) {
4140 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4150 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4198 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4214 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4236 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4252 if(ymd_date.day == 1) {
4253 if(ymd_date.month == 1) {
4255 for(
auto n : world.in_nation) {
4256 if(n.get_owned_province_count() != 0)
4262 if(ymd_date.month == 2) {
4265 if(ymd_date.month == 3 && !national_definitions.on_quarterly_pulse.empty()) {
4266 for(
auto n : world.in_nation) {
4267 if(n.get_owned_province_count() > 0) {
4272 if(ymd_date.month == 4 && ymd_date.year % 2 == 0) {
4275 if(ymd_date.month == 5) {
4278 if(ymd_date.month == 6 && !national_definitions.on_quarterly_pulse.empty()) {
4279 for(
auto n : world.in_nation) {
4280 if(n.get_owned_province_count() > 0) {
4285 if(ymd_date.month == 7) {
4288 if(ymd_date.month == 9 && !national_definitions.on_quarterly_pulse.empty()) {
4289 for(
auto n : world.in_nation) {
4290 if(n.get_owned_province_count() > 0) {
4295 if(ymd_date.month == 10 && !national_definitions.on_yearly_pulse.empty()) {
4296 for(
auto n : world.in_nation) {
4297 if(n.get_owned_province_count() > 0) {
4302 if(ymd_date.month == 11) {
4305 if(ymd_date.month == 12 && !national_definitions.on_quarterly_pulse.empty()) {
4306 for(
auto n : world.in_nation) {
4307 if(n.get_owned_province_count() > 0) {
4328 if(network_mode == network_mode_type::single_player)
4333 if(network_mode == network_mode_type::single_player) {
4334 world.nation_swap_demographics_demographics_alt();
4335 world.state_instance_swap_demographics_demographics_alt();
4336 world.province_swap_demographics_demographics_alt();
4345 player_data_cache.treasury_record[current_date.value % 32] =
nations::get_treasury(*
this, local_player_nation);
4346 player_data_cache.population_record[current_date.value % 32] = world.nation_get_demographics(local_player_nation,
demographics::total);
4347 if((current_date.value % 16) == 0) {
4349 for(
auto c : world.in_commodity) {
4350 c.set_price_record(index, c.get_current_price());
4354 if(((ymd_date.month % 3) == 0) && (ymd_date.day == 1)) {
4356 for(
auto n : world.in_nation) {
4361 ui_date = current_date;
4363 game_state_updated.store(
true, std::memory_order::release);
4365 switch(user_settings.autosaves) {
4366 case autosave_frequency::none:
4368 case autosave_frequency::daily:
4371 case autosave_frequency::monthly:
4372 if(ymd_date.day == 1)
4375 case autosave_frequency::yearly:
4376 if(ymd_date.month == 1 && ymd_date.day == 1)
4385 dcon::load_record loaded = world.make_serialize_record_store_save();
4386 auto buffer = std::unique_ptr<uint8_t[]>(
new uint8_t[world.serialize_size(loaded)]);
4387 std::byte* start =
reinterpret_cast<std::byte*
>(buffer.get());
4388 world.serialize(start, loaded);
4390 auto buffer_position =
reinterpret_cast<uint8_t*
>(start);
4391 int32_t total_size_used =
static_cast<int32_t
>(buffer_position - buffer.get());
4394 blake2b(&key,
sizeof(key), buffer.get(), total_size_used,
nullptr, 0);
4398void state::debug_save_oos_dump() {
4402 dcon::load_record loaded = world.make_serialize_record_store_save();
4403 auto save_buffer = std::unique_ptr<uint8_t[]>(
new uint8_t[world.serialize_size(loaded)]);
4404 auto buffer_position =
reinterpret_cast<std::byte*
>(save_buffer.get());
4405 world.serialize(buffer_position, loaded);
4406 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - save_buffer.get();
4412 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - buffer.get();
4417void state::debug_scenario_oos_dump() {
4421 dcon::load_record loaded = world.make_serialize_record_store_scenario();
4422 auto buffer = std::unique_ptr<uint8_t[]>(
new uint8_t[world.serialize_size(loaded)]);
4423 auto buffer_position =
reinterpret_cast<std::byte*
>(buffer.get());
4424 world.serialize(buffer_position, loaded);
4425 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - buffer.get();
4431 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - buffer.get();
4436void state::game_loop() {
4437 static int32_t game_speed[] = {
4444 game_speed[1] = int32_t(defines.alice_speed_1);
4445 game_speed[2] = int32_t(defines.alice_speed_2);
4446 game_speed[3] = int32_t(defines.alice_speed_3);
4447 game_speed[4] = int32_t(defines.alice_speed_4);
4449 while(quit_signaled.load(std::memory_order::acquire) ==
false) {
4452 std::lock_guard l{ ugly_ui_game_interaction_hack };
4456 std::this_thread::sleep_for(std::chrono::milliseconds(15));
4458 auto speed = actual_game_speed.load(std::memory_order::acquire);
4459 auto upause = ui_pause.load(std::memory_order::acquire);
4464 if(speed <= 0 || upause || internally_paused || current_scene.enforced_pause) {
4465 std::this_thread::sleep_for(std::chrono::milliseconds(15));
4467 auto entry_time = std::chrono::steady_clock::now();
4468 auto ms_count = std::chrono::duration_cast<std::chrono::milliseconds>(entry_time - last_update).count();
4469 if(speed >= 5 || ms_count >= game_speed[speed]) {
4470 last_update = entry_time;
4474 std::lock_guard l{ugly_ui_game_interaction_hack};
4478 std::this_thread::sleep_for(std::chrono::milliseconds(1));
4485void state::console_log(std::string_view message) {
4486 current_scene.console_log(*
this, message);
4489void state::new_army_group(dcon::province_id hq) {
4490 bool invalid_province =
false;
4491 world.for_each_automated_army_group(
4492 [&](dcon::automated_army_group_id item) {
4493 auto item_hq = world.automated_army_group_get_hq(item);
4495 invalid_province =
true;
4499 if(invalid_province) {
4502 auto new_group = world.create_automated_army_group();
4503 world.automated_army_group_set_hq(new_group, hq);
4504 world.automated_army_group_set_owner(new_group, local_player_nation);
4506 game_state_updated.store(
true, std::memory_order_release);
4509void state::toggle_defensive_position(dcon::automated_army_group_id group, dcon::province_id position) {
4510 auto fat_group = fatten(world, group);
4512 if(fat_group.get_provinces_defend().contains(position)) {
4513 fat_group.get_provinces_defend().remove_unique(position);
4515 fat_group.get_provinces_defend().push_back(position);
4518 game_state_updated.store(
true, std::memory_order_release);
4519 map_state.unhandled_province_selection =
true;
4522void state::toggle_enforce_control_position(dcon::automated_army_group_id group, dcon::province_id position) {
4523 auto fat_group = fatten(world, group);
4525 if(fat_group.get_provinces_enforce_control().contains(position)) {
4526 fat_group.get_provinces_enforce_control().remove_unique(position);
4528 fat_group.get_provinces_enforce_control().push_back(position);
4531 game_state_updated.store(
true, std::memory_order_release);
4532 map_state.unhandled_province_selection =
true;
4535void state::toggle_designated_port(dcon::automated_army_group_id group, dcon::province_id position) {
4536 auto fat_group = fatten(world, group);
4538 if(!world.province_get_is_coast(position)) {
4542 if(fat_group.get_provinces_ferry_origin().contains(position)) {
4543 fat_group.get_provinces_ferry_origin().remove_unique(position);
4545 fat_group.get_provinces_ferry_origin().push_back(position);
4548 game_state_updated.store(
true, std::memory_order_release);
4549 map_state.unhandled_province_selection =
true;
4552void state::army_group_add_regiment(dcon::automated_army_group_id group, dcon::regiment_id
id) {
4554 auto automation_check = world.regiment_get_automation(
id);
4555 if(automation_check) {
4559 auto automation_data = world.create_regiment_automation_data();
4562 std::lock_guard l{ ugly_ui_game_interaction_hack };
4563 world.try_create_automated_army_group_membership_regiment(automation_data, group);
4564 world.try_create_automation(automation_data,
id);
4567 auto fat_automation = fatten(world, automation_data);
4569 auto army = world.regiment_get_army_from_army_membership(
id);
4570 auto location = world.army_get_location_from_army_location(army);
4572 fat_automation.set_status(army_group_regiment_status::standby);
4573 fat_automation.set_task(army_group_regiment_task::idle);
4574 fat_automation.set_target(location);
4575 fat_automation.set_ferry_origin({ });
4576 fat_automation.set_ferry_target({ });
4577 fat_automation.set_await_command_execution_flag(
false);
4580 std::array<dcon::regiment_id, command::num_packed_units> data;
4582 data.fill(dcon::regiment_id{});
4587 game_state_updated.store(
true, std::memory_order_release);
4590void state::remove_navy_from_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id navy_to_delete) {
4591 std::lock_guard l{ ugly_ui_game_interaction_hack };
4593 auto membership = world.navy_get_automated_army_group_membership_navy(navy_to_delete);
4598 world.delete_automated_army_group_membership_navy(membership);
4601void state::remove_regiment_from_army_group(dcon::automated_army_group_id selected_group, dcon::regiment_id regiment_to_delete) {
4602 std::lock_guard l{ ugly_ui_game_interaction_hack };
4604 auto regiment_automation_relation = world.regiment_get_automation(regiment_to_delete);
4605 auto automation_data = world.automation_get_automation_data(regiment_automation_relation);
4607 if(!automation_data) {
4611 world.delete_regiment_automation_data(automation_data);
4614void state::remove_regiment_from_all_army_groups(dcon::regiment_id regiment_to_delete) {
4615 world.for_each_automated_army_group([&](dcon::automated_army_group_id item) {
4616 remove_regiment_from_army_group(item, regiment_to_delete);
4620void state::remove_army_army_group_clean(dcon::automated_army_group_id group, dcon::army_id army_to_delete) {
4621 for(
auto regiment_membership : world.army_get_army_membership(army_to_delete)) {
4622 remove_regiment_from_army_group(group, regiment_membership.get_regiment().id);
4626void state::add_army_to_army_group(dcon::automated_army_group_id selected_group, dcon::army_id selected_army) {
4627 for(
auto item : world.army_get_army_membership(selected_army)) {
4628 army_group_add_regiment(selected_group, item.get_regiment());
4632void state::add_navy_to_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id selected_navy) {
4633 auto automation_link = world.navy_get_automated_army_group_membership_navy(selected_navy);
4634 auto current_group = world.automated_army_group_membership_navy_get_army(automation_link);
4641 std::lock_guard l{ ugly_ui_game_interaction_hack };
4642 auto new_link = world.try_create_automated_army_group_membership_navy(selected_navy, selected_group);
4645 game_state_updated.store(
true, std::memory_order_release);
4648void state::delete_army_group(dcon::automated_army_group_id group) {
4649 static std::vector<dcon::regiment_automation_data_id> to_delete = {};
4652 world.automated_army_group_for_each_automated_army_group_membership_regiment(group, [&](dcon::automated_army_group_membership_regiment_id item) {
4653 auto regiment = world.automated_army_group_membership_regiment_get_regiment(item);
4654 to_delete.push_back(regiment);
4657 std::lock_guard l{ ugly_ui_game_interaction_hack };
4659 if(!to_delete.empty()) {
4660 for(
auto& regiment : to_delete) {
4661 world.delete_regiment_automation_data(regiment);
4665 world.delete_automated_army_group(group);
4666 game_state_updated.store(
true, std::memory_order_release);
4669void state::update_armies_and_fleets(dcon::automated_army_group_id group) {
4670 auto owner = world.automated_army_group_get_owner(group);
4672 if(owner == local_player_nation) {
4674 static std::vector<dcon::regiment_automation_data_id> to_delete = {};
4677 world.automated_army_group_for_each_automated_army_group_membership_regiment(group, [&](dcon::automated_army_group_membership_regiment_id item) {
4678 auto regiment = world.automated_army_group_membership_regiment_get_regiment(item);
4679 auto regiment_true = world.regiment_automation_data_get_regiment_from_automation(regiment);
4680 if(!regiment_true) {
4681 to_delete.push_back(regiment);
4685 if(!to_delete.empty()) {
4686 std::lock_guard l{ ugly_ui_game_interaction_hack };
4687 for(
auto& regiment : to_delete) {
4688 world.delete_regiment_automation_data(regiment);
4693 delete_army_group(group);
4697void state::smart_select_army_group(dcon::automated_army_group_id selected_group) {
4698 if(!selected_army_group) {
4699 select_army_group(selected_group);
4703 if(selected_army_group == selected_group) {
4704 deselect_army_group();
4708 select_army_group(selected_group);
4711void state::select_army_group(dcon::automated_army_group_id selected_group) {
4712 selected_army_group = selected_group;
4714 game_state_updated.store(
true, std::memory_order_release);
4717void state::deselect_army_group() {
4718 selected_army_group = {};
4720 game_state_updated.store(
true, std::memory_order_release);
4723dcon::regiment_automation_data_id state::fill_province_up_to_supply_limit(
4724 dcon::automated_army_group_id group_id,
4725 dcon::province_id target,
4726 std::vector<float>& regiments_distribution,
4727 float overestimate_supply_limit,
4728 bool ignore_enemy_regiments_in_supply_calculations
4730 auto group = fatten(world, group_id);
4732 static std::vector<float> regiments_expectation_ideal;
4733 regiments_expectation_ideal.resize(military_definitions.unit_base_definitions.size() + 2);
4735 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4736 regiments_expectation_ideal[i] = 0.f;
4742 local_player_nation,
4744 )) * overestimate_supply_limit;
4751 if(ignore_enemy_regiments_in_supply_calculations) {
4756 for(
auto regiment_id : group.get_automated_army_group_membership_regiment()) {
4757 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4758 if(regiment.get_target() == target && regiment.get_status() == army_group_regiment_status::move_to_target) {
4759 current_weight += 3.f;
4760 }
else if(regiment.get_ferry_target() == target && regiment.get_status() == army_group_regiment_status::move_to_port) {
4761 current_weight += 3.f;
4767 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4768 regiments_expectation_ideal[i] = floor(regiments_distribution[i] * floor(supply_limit / 3.f)) * 3.f;
4769 ideal += regiments_expectation_ideal[i];
4772 if(current_weight + 3.f < ideal) {
4773 return fill_province(group, target, regiments_expectation_ideal);
4779float state::army_group_available_supply(dcon::automated_army_group_id group, dcon::province_id
province) {
4781 float current_weight = 0.f;
4782 for(
auto regiment_id : world.automated_army_group_get_automated_army_group_membership_regiment(group)) {
4783 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4784 if(regiment.get_target() ==
province) {
4785 current_weight += 3.f;
4787 regiment.get_ferry_target() ==
province
4789 regiment.get_status() == army_group_regiment_status::move_to_port
4790 || regiment.get_status() == army_group_regiment_status::await_transport
4791 || regiment.get_status() == army_group_regiment_status::is_transported
4792 || regiment.get_status() == army_group_regiment_status::disembark
4795 current_weight += 3.f;
4797 regiment.get_ferry_origin() ==
province
4799 regiment.get_status() == army_group_regiment_status::move_to_port
4800 || regiment.get_status() == army_group_regiment_status::await_transport
4803 current_weight += 3.f;
4807 return max_supply - current_weight;
4810void state::regiment_reset_order(dcon::regiment_automation_data_id regiment) {
4811 auto fat_data = fatten(world, regiment);
4813 fat_data.set_status(army_group_regiment_status::standby);
4814 fat_data.set_task(army_group_regiment_task::idle);
4817dcon::province_id state::find_available_ferry_origin(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment) {
4818 auto fat_reg = fatten(world, regiment);
4819 auto army = fat_reg.get_regiment_from_automation().get_army_from_army_membership();
4820 auto fat_group = fatten(world, group);
4822 for(
auto& item : fat_group.get_provinces_ferry_origin()) {
4824 if(army_group_available_supply(group, item) < 3.f) {
4833 if(world.province_get_is_coast(army.get_location_from_army_location())) {
4834 return army.get_location_from_army_location();
4838 static std::vector<dcon::province_id> origin_port_candidates;
4839 origin_port_candidates.clear();
4842 origin_port_candidates.push_back(army.get_location_from_army_location());
4844 while(l < r && l < 30) {
4845 auto current_location = origin_port_candidates[l];
4847 if(world.province_get_is_coast(current_location)) {
4848 return current_location;
4851 if(current_location.value >= province_definitions.first_sea_province.value) {
4861 for(
auto adj : world.province_get_province_adjacency(current_location)) {
4862 auto other = adj.get_connected_provinces(adj.get_connected_provinces(0) == current_location ? 1 : 0);
4864 if(std::find(origin_port_candidates.begin(), origin_port_candidates.end(), other) == origin_port_candidates.end()) {
4865 origin_port_candidates.push_back(other);
4874 dcon::province_id invalid_province{};
4875 return invalid_province;
4878bool state::move_to_available_port(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment) {
4879 auto fat_reg = fatten(world, regiment);
4880 dcon::province_id target = find_available_ferry_origin(group, regiment);
4881 auto army = fat_reg.get_regiment_from_automation().get_army_from_army_membership();
4884 if(army.get_location_from_army_location() != target) {
4886 fat_reg.set_await_command_execution_flag(
true);
4888 fat_reg.set_status(army_group_regiment_status::move_to_port);
4889 fat_reg.set_ferry_origin(target);
4896bool state::army_group_recalculate_distribution(dcon::automated_army_group_id group, std::vector<float>& regiments_distribution) {
4897 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4898 regiments_distribution[i] = 0.f;
4903 for(
auto regiment_id : world.automated_army_group_get_automated_army_group_membership_regiment(group)) {
4904 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4906 auto regiment_type = regiment.get_regiment_from_automation().get_type();
4908 if(!regiment_type) {
4912 auto task = regiment.get_task();
4913 auto status = regiment.get_status();
4915 task == army_group_regiment_task::idle ||
4916 task == army_group_regiment_task::gather_at_hq
4918 regiments_distribution[regiment_type.index()] += 1.f;
4924 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4925 regiments_distribution[i] = regiments_distribution[i] / total;
4932void state::army_group_update_tasks(dcon::automated_army_group_id group) {
4936 dcon::province_id potential_ferry_target{};
4937 float ferry_supply_budget = 0.f;
4939 auto fat_group = fatten(world, group);
4941 for(
auto regiment_id : world.automated_army_group_get_automated_army_group_membership_regiment(group)) {
4942 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4944 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
4946 auto current_path = world.army_get_path(army);
4947 if(current_path.size() > 0) {
4951 auto province = world.army_get_location_from_army_location(army);
4952 auto controller = world.province_get_nation_from_province_control(
province);
4954 if(regiment.get_status() != army_group_regiment_status::standby) {
4958 switch(regiment.get_task()) {
4959 case army_group_regiment_task::idle:
4961 case army_group_regiment_task::gather_at_hq:
4963 case army_group_regiment_task::defend_position:
4964 if(!fat_group.get_provinces_defend().contains(regiment.get_target())) {
4965 regiment_reset_order(regiment);
4968 case army_group_regiment_task::siege:
4969 if(regiment.get_target() !=
province) {
4975 regiment_reset_order(regiment);
4983dcon::province_id state::get_port_for_landing(dcon::automated_army_group_id group, dcon::province_id target) {
4984 auto fat_group = fatten(world, group);
4986 if(world.province_get_is_coast(target)) {
4990 dcon::province_id potential_target_port{};
4991 for(
auto& target_port : fat_group.get_provinces_ferry_origin()) {
4993 if(path.size() > 0) {
4994 potential_target_port = target_port;
4998 return potential_target_port;
5001void state::army_group_distribute_tasks(dcon::automated_army_group_id group) {
5002 static std::vector<dcon::province_id> province_queue;
5003 static std::vector<dcon::province_id> provinces_to_reduce_weight;
5004 static std::vector<dcon::province_id> provinces_to_maintain;
5005 static std::vector<float> regiments_distribution;
5006 regiments_distribution.resize(military_definitions.unit_base_definitions.size() + 2);
5008 auto fat_group = fatten(world, group);
5013 if(army_group_recalculate_distribution(group, regiments_distribution)) {
5015 dcon::province_id candidate{};
5016 float supply_limit = 0.f;
5017 for(dcon::province_id defensive_position : fat_group.get_provinces_defend()) {
5018 auto regiment = fill_province_up_to_supply_limit(
5021 regiments_distribution,
5026 world.regiment_automation_data_set_task(regiment, army_group_regiment_task::defend_position);
5035 if(army_group_recalculate_distribution(group, regiments_distribution)) {
5036 for(dcon::province_id province_to_siege : fat_group.get_provinces_enforce_control()) {
5037 auto controller = world.province_get_nation_from_province_control(province_to_siege);
5042 auto regiment = fill_province_up_to_supply_limit(
5045 regiments_distribution,
5050 world.regiment_automation_data_set_task(regiment, army_group_regiment_task::siege);
5061 for(
auto fleet_membership : fat_group.get_automated_army_group_membership_navy()) {
5062 auto fleet = fleet_membership.get_navy();
5063 auto location = fleet.get_location_from_navy_location();
5065 auto path = fleet.get_path();
5067 if(path.size() > 0) {
5071 auto transported_armies = fleet.get_army_transport();
5072 bool wait_for_disembark =
false;
5073 for(
auto item : transported_armies) {
5074 auto army = item.get_army();
5075 auto path_army = world.army_get_path(army);
5077 if(path_army.size() > 0) {
5078 wait_for_disembark =
true;
5082 if(wait_for_disembark) {
5090 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5091 auto regiment = regiment_automation_link.get_regiment();
5092 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5093 auto target = regiment.get_ferry_target();
5094 auto port_to = world.province_get_port_to(target);
5095 auto transport = world.army_get_army_transport(army);
5096 auto regiment_fleet = world.army_transport_get_navy(transport);
5097 auto fleet_location = world.navy_get_location_from_navy_location(fleet);
5099 if(regiment_fleet == fleet) {
5101 if(port_to == fleet_location) {
5113 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5114 auto regiment = regiment_automation_link.get_regiment();
5117 regiment.get_status() != army_group_regiment_status::await_transport
5118 && regiment.get_status() != army_group_regiment_status::embark
5122 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5123 auto regiment_location = army.get_location_from_army_location();
5124 auto port_to = regiment_location.get_port_to();
5126 if(port_to == fleet.get_location_from_navy_location()) {
5140 province_queue.clear();
5141 provinces_to_reduce_weight.clear();
5142 provinces_to_maintain.clear();
5144 province_queue.push_back(fat_group.get_hq());
5150 auto current_location = province_queue[l];
5152 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5154 auto regiment = regiment_automation_link.get_regiment();
5155 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5156 auto army_location = army.get_location_from_army_location();
5157 auto current_path = army.get_path();
5158 auto status = regiment.get_task();
5159 if(status != army_group_regiment_task::idle) {
5162 if(current_path.size() > 0) {
5165 if(current_location == army_location) {
5166 regiment.set_task(army_group_regiment_task::gather_at_hq);
5167 regiment.set_status(army_group_regiment_status::standby);
5172 if(current_location.value >= province_definitions.first_sea_province.value) {
5177 auto ownership = world.province_get_province_ownership_as_province(current_location);
5178 auto owner = world.province_ownership_get_nation(ownership);
5184 if(fat_group.get_provinces_defend().contains(current_location)) {
5191 local_player_nation,
5196 *
this, current_location
5199 auto supply_left = army_group_available_supply(group, current_location);
5201 if(4.f < supply_left) {
5203 }
else if(current_weight > supply_limit) {
5204 provinces_to_reduce_weight.push_back(current_location);
5206 provinces_to_maintain.push_back(current_location);
5210 for(
auto adj : world.province_get_province_adjacency(current_location)) {
5211 auto other = adj.get_connected_provinces(adj.get_connected_provinces(0) == current_location ? 1 : 0);
5213 if(std::find(province_queue.begin(), province_queue.end(), other) == province_queue.end()) {
5214 province_queue.push_back(other);
5223 auto target_location = province_queue[l];
5224 dcon::province_id potential_target_port = get_port_for_landing(group, fat_group.get_hq());
5226 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5227 auto regiment = regiment_automation_link.get_regiment();
5228 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5229 auto army_location = army.get_location_from_army_location();
5230 auto army_path = army.get_path();
5232 if(regiment.get_task() != army_group_regiment_task::idle) {
5235 if(army_path.size() > 0) {
5238 if(army_location == target_location) {
5239 regiment.set_task(army_group_regiment_task::gather_at_hq);
5240 regiment.set_status(army_group_regiment_status::standby);
5247 if(potential_target_port) {
5248 if(move_to_available_port(group, regiment)) {
5249 regiment.set_task(army_group_regiment_task::gather_at_hq);
5250 regiment.set_target(target_location);
5251 regiment.set_ferry_target(potential_target_port);
5256 regiment.set_task(army_group_regiment_task::gather_at_hq);
5257 regiment.set_status(army_group_regiment_status::move_to_target);
5258 regiment.set_target(path[0]);
5265void state::army_group_update_regiment_status(dcon::automated_army_group_id group) {
5266 auto fat_group = fatten(world, group);
5268 for(
auto regiment_link : fat_group.get_automated_army_group_membership_regiment()) {
5269 auto regiment = regiment_link.get_regiment();
5270 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5275 auto current_path = army.get_path();
5276 if(current_path.size() > 0) {
5277 regiment.set_await_command_execution_flag(
false);
5281 if(regiment.get_await_command_execution_flag()) {
5285 auto location = world.army_get_location_from_army_location(army);
5286 auto target = regiment.get_target();
5290 switch(regiment.get_status()) {
5291 case army_group_regiment_status::move_to_target:
5292 if(location == target) {
5293 regiment.set_status(army_group_regiment_status::standby);
5298 regiment.set_await_command_execution_flag(
true);
5300 regiment_reset_order(regiment);
5304 case army_group_regiment_status::move_to_port:
5306 if(regiment.get_ferry_origin() == location) {
5307 regiment.set_status(army_group_regiment_status::await_transport);
5309 command::move_army(*
this, local_player_nation, army, regiment.get_ferry_origin(),
false);
5313 case army_group_regiment_status::standby:
5314 if(location != target) {
5315 regiment.set_status(army_group_regiment_status::move_to_target);
5318 case army_group_regiment_status::await_transport:
5320 if(location.value >= province_definitions.first_sea_province.value) {
5322 regiment.set_status(army_group_regiment_status::is_transported);
5327 bool at_ferry_origin = location == regiment.get_ferry_origin();
5328 if(!at_ferry_origin) {
5329 regiment_reset_order(regiment);
5332 dcon::province_id port_to = world.province_get_port_to(location);
5334 for(
auto fleet_membership : fat_group.get_automated_army_group_membership_navy()) {
5335 auto fleet = fleet_membership.get_navy();
5337 auto path = fleet.get_path();
5338 if(path.size() > 0) {
5342 auto fleet_location = world.navy_get_location_from_navy_location(fleet);
5343 if(fleet_location == port_to) {
5346 if(path_army.size() > 0) {
5348 regiment.set_status(army_group_regiment_status::embark);
5349 regiment.set_await_command_execution_flag(
true);
5357 case army_group_regiment_status::is_transported:
5358 if(location.value >= province_definitions.first_sea_province.value) {
5360 auto ferry_target = regiment.get_ferry_target();
5361 auto port_to = world.province_get_port_to(ferry_target);
5362 auto transport = world.army_get_army_transport(army);
5363 auto fleet = world.army_transport_get_navy(transport);
5364 auto fleet_location = world.navy_get_location_from_navy_location(fleet);
5367 if(fleet_location == port_to) {
5370 if(path_army.size() > 0) {
5372 regiment.set_await_command_execution_flag(
true);
5373 regiment.set_status(army_group_regiment_status::disembark);
5380 regiment_reset_order(regiment);
5382 case army_group_regiment_status::disembark:
5383 if(location == regiment.get_ferry_target()) {
5384 regiment.set_status(army_group_regiment_status::move_to_target);
5388 regiment.set_status(army_group_regiment_status::is_transported);
5390 case army_group_regiment_status::embark:
5391 if(location.value >= province_definitions.first_sea_province.value) {
5392 regiment.set_status(army_group_regiment_status::is_transported);
5396 regiment.set_status(army_group_regiment_status::await_transport);
5404dcon::regiment_automation_data_id state::fill_province(
5405 dcon::automated_army_group_id group_id,
5406 dcon::province_id target,
5407 std::vector<float> & regiments_expectation_ideal
5409 static std::vector<float> regiments_expectation_current;
5410 static std::vector<float> regiments_in_candidate_army;
5412 regiments_expectation_current.resize(military_definitions.unit_base_definitions.size() + 2);
5413 regiments_in_candidate_army.resize(military_definitions.unit_base_definitions.size() + 2);
5415 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
5416 regiments_expectation_current[i] = 0.f;
5417 regiments_in_candidate_army[i] = 0.f;
5420 auto fat_group = fatten(world, group_id);
5422 bool success =
false;
5426 for(
auto regiment_membership : fat_group.get_automated_army_group_membership_regiment()) {
5427 auto regiment = regiment_membership.get_regiment();
5428 if(regiment.get_target() == target) {
5429 auto regiment_type = regiment.get_regiment_from_automation().get_type();
5431 regiments_expectation_current[regiment_type.index()] += 3.f;
5436 dcon::regiment_automation_data_id final_regiment{};
5439 auto target_port = get_port_for_landing(group_id, target);
5440 for(
auto regiment_membership : fat_group.get_automated_army_group_membership_regiment()) {
5441 auto regiment = regiment_membership.get_regiment();
5443 auto current_task = regiment.get_task();
5445 if(current_task != army_group_regiment_task::idle && current_task != army_group_regiment_task::gather_at_hq) {
5449 auto regiment_type = regiment.get_regiment_from_automation().get_type();
5451 if(!regiment_type) {
5456 regiments_expectation_ideal[regiment_type.index()]
5457 - regiments_expectation_current[regiment_type.index()];
5459 if(required >= 2.9f) {
5460 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5462 if(path.empty() && target != army.get_location_from_army_location()) {
5464 if(target_port && move_to_available_port(group_id, regiment)) {
5465 regiment.set_ferry_target(target_port);
5466 regiment.set_target(target);
5471 regiment.set_status(army_group_regiment_status::move_to_target);
5472 regiment.set_target(target);
5481void state::fill_vector_of_connected_provinces(dcon::province_id p1,
bool is_land, std::vector<dcon::province_id> & provinces) {
5483 if(world.province_get_nation_from_province_ownership(p1) == local_player_nation) {
5485 auto rid = world.province_get_connected_region_id(p1);
5486 for(
const auto pc : world.nation_get_province_ownership_as_nation(local_player_nation)) {
5487 if(pc.get_province().get_connected_region_id() == rid
5488 && pc.get_province().get_province_control().get_nation() == local_player_nation) {
5489 provinces.push_back(pc.get_province());
5493 for(
const auto pc : world.nation_get_province_ownership_as_nation(local_player_nation)) {
5494 if(pc.get_province().get_province_control().get_nation() == local_player_nation
5495 && pc.get_province().get_is_coast()) {
5496 provinces.push_back(pc.get_province());
5504 dcon::province_id
p;
5506 dcon::unit_type_id
u;
5509void state::build_up_to_template_land(
5511 dcon::province_id target_province,
5512 std::vector<dcon::province_id> & available_provinces,
5513 std::array<uint8_t, sys::macro_builder_template::max_types> & current_distribution
5516 std::vector<build_queue_data> build_queue;
5521 std::memcpy(remaining_to_build, target_template.
amounts,
sizeof(remaining_to_build));
5524 for(dcon::unit_type_id::value_base_t i = 0; i < upper_limit; i++) {
5525 dcon::unit_type_id utid = dcon::unit_type_id(i);
5526 if(remaining_to_build[i] < current_distribution[i]) {
5527 remaining_to_build[i] = 0;
5529 remaining_to_build[i] -= current_distribution[i];
5533 for(
const auto prov : available_provinces) {
5534 for(
const auto p : world.province_get_pop_location_as_province(prov)) {
5535 auto pop = p.get_pop();
5536 if(pop.get_poptype() != culture_definitions.soldiers)
5540 auto source = pop.get_regiment_source();
5541 int32_t used = int32_t(source.end() - source.begin());
5543 auto constructions = pop.get_province_land_construction_as_pop();
5544 used += int32_t(constructions.end() - constructions.begin());
5546 int32_t avail = possible - used;
5555 auto unit_types = military_definitions.unit_base_definitions.size();
5557 for(dcon::unit_type_id::value_base_t i = 0; i < unit_types; i++) {
5558 dcon::unit_type_id utid = dcon::unit_type_id(i);
5560 if(!military_definitions.unit_base_definitions[utid].is_land) {
5564 if(remaining_to_build[i] == 0) {
5570 local_player_nation,
5581 for(int32_t j = 0; j < int32_t(remaining_to_build[i]) && j < avail; j++) {
5583 remaining_to_build[i]--;
5585 if(remaining_to_build[i] == 0)
5592 for(
const auto& build : build_queue) {
5595 local_player_nation,
int blake2b(void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen)
void update_fog_of_war(sys::state &state)
bool map_to_screen(sys::state &state, glm::vec2 map_pos, glm::vec2 screen_size, glm::vec2 &screen_pos)
void on_mouse_wheel(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod, float amount)
void load_map_data(parsers::scenario_building_context &context)
void on_mbuttom_up(int32_t x, int32_t y, sys::key_modifiers mod)
void on_mbuttom_down(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
void update(sys::state &state)
void on_key_up(sys::virtual_key keycode, sys::key_modifiers mod)
glm::vec2 normalize_map_coord(glm::vec2 pos)
map_mode::mode active_map_mode
void on_mouse_move(int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y, sys::key_modifiers mod)
dcon::province_id get_province_under_mouse(sys::state &state, int32_t x, int32_t y, int32_t screen_size_x, int32_t screen_size_y)
std::string accumulated_errors
std::string accumulated_warnings
RIGTORP_NODISCARD T * front() noexcept
RIGTORP_NODISCARD bool try_push(const T &v) noexcept(std::is_nothrow_copy_constructible< T >::value)
year_month_day to_ymd(absolute_time_point base) const noexcept
void change_locale(sys::state &state, dcon::locale_id l)
tagged_vector< element_data, dcon::gui_def_id > gui
tagged_vector< gfx_object, dcon::gfx_object_id > gfx
std::vector< diplomatic_message::message > messages
virtual message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept
virtual tooltip_behavior has_tooltip(sys::state &state) noexcept
virtual void on_text(sys::state &state, char32_t ch) noexcept
virtual void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual message_result impl_on_scroll(sys::state &state, int32_t x, int32_t y, float amount, sys::key_modifiers mods) noexcept
virtual void impl_on_update(sys::state &state) noexcept
virtual void impl_render(sys::state &state, int32_t x, int32_t y) noexcept
virtual void on_drag_finish(sys::state &state) noexcept
virtual void on_drag(sys::state &state, int32_t oldx, int32_t oldy, int32_t x, int32_t y, sys::key_modifiers mods) noexcept
void set_visible(sys::state &state, bool vis)
virtual message_result impl_on_mouse_move(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept
virtual mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept
static void make_new_report(sys::state &state, military::land_battle_report const &r)
std::vector< notification::message > messages
#define assert(condition)
char * LLVMGetErrorMessage(LLVMErrorRef Err)
void LLVMDisposeErrorMessage(char *ErrMsg)
LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J, LLVMOrcExecutorAddress *Result, const char *Name)
uint64_t LLVMOrcExecutorAddress
void update_crisis_leaders(sys::state &state)
void initialize_ai_tech_weights(sys::state &state)
void daily_cleanup(sys::state &state)
void take_reforms(sys::state &state)
void form_alliances(sys::state &state)
void update_ai_ruling_party(sys::state &state)
void make_war_decs(sys::state &state)
void upgrade_colonies(sys::state &state)
void update_cb_fabrication(sys::state &state)
void make_defense(sys::state &state)
void refresh_home_ports(sys::state &state)
void update_ai_colony_starting(sys::state &state)
void update_focuses(sys::state &state)
void update_budget(sys::state &state)
void update_ai_colonial_investment(sys::state &state)
void perform_influence_actions(sys::state &state)
void make_attacks(sys::state &state)
void update_ships(sys::state &state)
void update_ai_econ_construction(sys::state &state)
void build_ships(sys::state &state)
void prune_alliances(sys::state &state)
void update_war_intervention(sys::state &state)
void update_influence_priorities(sys::state &state)
void update_ai_research(sys::state &state)
void update_ai_general_status(sys::state &state)
void update_land_constructions(sys::state &state)
void identify_focuses(sys::state &state)
void civilize(sys::state &state)
void make_peace_offers(sys::state &state)
void take_ai_decisions(sys::state &state)
void general_ai_unit_tick(sys::state &state)
void add_gw_goals(sys::state &state)
bool can_start_research(sys::state &state, dcon::nation_id source, dcon::technology_id tech)
void start_land_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province)
void mark_regiments_to_split(sys::state &state, dcon::nation_id source, std::array< dcon::regiment_id, num_packed_units > const &list)
bool can_start_land_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province)
std::vector< dcon::province_id > can_move_navy(sys::state &state, dcon::nation_id source, dcon::navy_id n, dcon::province_id dest)
void make_event_choice(sys::state &state, event::pending_human_n_event const &e, uint8_t option_id)
void execute_pending_commands(sys::state &state)
std::vector< dcon::province_id > can_move_army(sys::state &state, dcon::nation_id source, dcon::army_id a, dcon::province_id dest)
void discover_inventions(sys::state &state)
void apply_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
float effective_technology_cost(sys::state &state, uint32_t current_year, dcon::nation_id target_nation, dcon::technology_id tech_id)
void fix_slaves_in_province(sys::state &state, dcon::nation_id owner, dcon::province_id p)
void clear_existing_tech_effects(sys::state &state)
void repopulate_technology_effects(sys::state &state)
void update_all_nations_issue_rules(sys::state &state)
void set_default_issue_and_reform_options(sys::state &state)
void repopulate_invention_effects(sys::state &state)
void update_research(sys::state &state, uint32_t current_year)
void restore_unsaved_values(sys::state &state)
void create_initial_ideology_and_issues_distribution(sys::state &state)
void apply_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
void alt_demographics_update_extras(sys::state &state)
void remove_small_pops(sys::state &state)
void update_immigration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
constexpr dcon::demographics_key total(0)
void apply_assimilation(sys::state &state, uint32_t offset, uint32_t divisions, assimilation_buffer &pbuf)
void update_internal_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void apply_type_changes(sys::state &state, uint32_t offset, uint32_t divisions, promotion_buffer &pbuf)
void update_growth(sys::state &state, uint32_t offset, uint32_t divisions)
void alt_regenerate_from_pop_data_daily(sys::state &state)
void update_issues(sys::state &state, uint32_t offset, uint32_t divisions, issues_buffer &ibuf)
void apply_internal_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void update_type_changes(sys::state &state, uint32_t offset, uint32_t divisions, promotion_buffer &pbuf)
void regenerate_from_pop_data_full(sys::state &state)
uint32_t size(sys::state const &state)
void update_assimilation(sys::state &state, uint32_t offset, uint32_t divisions, assimilation_buffer &pbuf)
void alt_regenerate_from_pop_data_full(sys::state &state)
void remove_size_zero_pops(sys::state &state)
void update_colonial_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void apply_ideologies(sys::state &state, uint32_t offset, uint32_t divisions, ideology_buffer &pbuf)
void update_ideologies(sys::state &state, uint32_t offset, uint32_t divisions, ideology_buffer &ibuf)
void update_consciousness(sys::state &state, uint32_t offset, uint32_t divisions)
void update_literacy(sys::state &state, uint32_t offset, uint32_t divisions)
void update_militancy(sys::state &state, uint32_t offset, uint32_t divisions)
void apply_colonial_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void regenerate_from_pop_data_daily(sys::state &state)
void apply_immigration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void apply_issues(sys::state &state, uint32_t offset, uint32_t divisions, issues_buffer &pbuf)
void update_pending(sys::state &state)
void initialize(sys::state &state)
void update_factory_employment(sys::state &state)
void prune_factories(sys::state &state)
constexpr uint32_t gdp_history_length
float gdp_adjusted(sys::state &state, dcon::nation_id n)
void presimulate(sys::state &state)
void update_rgo_employment(sys::state &state)
constexpr uint32_t price_history_length
void regenerate_unsaved_values(sys::state &state)
int32_t most_recent_price_record_index(sys::state &state)
constexpr int32_t max_building_types
int32_t most_recent_gdp_record_index(sys::state &state)
void daily_update(sys::state &state, bool initiate_buildings)
constexpr uint16_t no_payload
void execute(sys::state &state, dcon::effect_key key, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
void fire_fixed_event(sys::state &state, std::vector< nations::fixed_event > const &v, int32_t primary_slot, slot_type pt, dcon::nation_id this_slot, int32_t from_slot, slot_type ft)
void update_events(sys::state &state)
std::string multiplicative_modifier(sys::state &state, dcon::value_modifier_key modifier)
std::string additive_modifier(sys::state &state, dcon::value_modifier_key modifier)
void run_fif_interpreter(environment &env, std::string_view on_text)
void common_fif_environment(sys::state &state, fif::environment &env)
void on_lbutton_up(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mod)
void switch_scene(sys::state &state, scene_id ui_scene)
void on_rbutton_down(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mod)
void on_key_down(sys::state &state, sys::virtual_key keycode, sys::key_modifiers mod)
void on_lbutton_down(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mod)
void set_map_mode(sys::state &state, mode mode)
constexpr float zoom_close
void update_text_lines(sys::state &state, display_data &map_data)
void run_gc(sys::state &state)
void update_naval_supply_points(sys::state &state)
void army_arrives_in_province(sys::state &state, dcon::army_id a, dcon::province_id p, crossing_type crossing, dcon::land_battle_id from)
int32_t free_transport_capacity(sys::state &state, dcon::navy_id n)
void apply_base_unit_stat_modifiers(sys::state &state)
void update_blockade_status(sys::state &state)
void update_ticking_war_score(sys::state &state)
void increase_dig_in(sys::state &state)
void apply_attrition(sys::state &state)
void reset_unit_stats(sys::state &state)
void update_land_battles(sys::state &state)
void update_cbs(sys::state &state)
float local_enemy_army_weight_max(sys::state &state, dcon::province_id prov, dcon::nation_id nation)
void regenerate_land_unit_average(sys::state &state)
void recover_org(sys::state &state)
void advance_mobilizations(sys::state &state)
void update_movement(sys::state &state)
int32_t regiments_possible_from_pop(sys::state &state, dcon::pop_id p)
void reinforce_regiments(sys::state &state)
void apply_regiment_damage(sys::state &state)
void monthly_leaders_update(sys::state &state)
float local_army_weight_max(sys::state &state, dcon::province_id prov)
void update_naval_battles(sys::state &state)
void update_siege_progress(sys::state &state)
void update_all_recruitable_regiments(sys::state &state)
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
void set_initial_leaders(sys::state &state)
void regenerate_total_regiment_counts(sys::state &state)
int32_t supply_limit_in_province(sys::state &state, dcon::nation_id n, dcon::province_id p)
int32_t transport_capacity(sys::state &state, dcon::navy_id n)
void repair_ships(sys::state &state)
void daily_leaders_update(sys::state &state)
void restore_unsaved_values(sys::state &state)
void regenerate_ship_scores(sys::state &state)
void update_blackflag_status(sys::state &state, dcon::province_id p)
bool siege_potential(sys::state &state, dcon::nation_id army_controller, dcon::nation_id province_controller)
std::string int_to_tag(uint32_t v)
void run_gc(sys::state &state)
void restore_unsaved_values(sys::state &state)
void daily_update_flashpoint_tension(sys::state &state)
void monthly_flashpoint_update(sys::state &state)
void update_administrative_efficiency(sys::state &state)
void update_influence(sys::state &state)
void update_military_scores(sys::state &state)
void update_monthly_points(sys::state &state)
void generate_initial_state_instances(sys::state &state)
void update_cached_values(sys::state &state)
void update_revanchism(sys::state &state)
uint32_t tag_to_int(char first, char second, char third)
void update_industrial_scores(sys::state &state)
void update_research_points(sys::state &state)
void restore_state_instances(sys::state &state)
void update_great_powers(sys::state &state)
float get_treasury(sys::state &state, dcon::nation_id n)
void update_ui_rankings(sys::state &state)
void update_rankings(sys::state &state)
void update_crisis(sys::state &state)
void send_and_receive_commands(sys::state &state)
bool nation_is_interesting(sys::state &state, dcon::nation_id n)
void initialize_msaa(sys::state &state, int32_t size_x, int32_t size_y)
void deinitialize_msaa(sys::state &state)
void render_textured_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, ui::rotation r, bool flipped, bool rtl)
GLuint get_texture_handle(sys::state &state, dcon::texture_id id, bool keep_data)
native_string flag_type_to_name(sys::state &state, culture::flag_type type)
void parse_csv_pop_history_file(sys::state &state, const char *start, const char *end, error_handler &err, scenario_building_context &context)
void read_map_adjacency(char const *start, char const *end, error_handler &err, scenario_building_context &context)
void read_pending_rebel_type(dcon::rebel_type_id id, token_generator &gen, error_handler &err, scenario_building_context &context)
dcon::trigger_key read_triggered_modifier_condition(token_generator &gen, error_handler &err, scenario_building_context &context)
dcon::trigger_key make_trigger(token_generator &gen, error_handler &err, trigger_building_context &context)
void parse_csv_province_history_file(sys::state &state, const char *start, const char *end, error_handler &err, scenario_building_context &context)
void read_pending_technology(dcon::technology_id id, token_generator &gen, error_handler &err, scenario_building_context &context)
void commit_pending_events(error_handler &err, scenario_building_context &context)
void read_pending_reform(dcon::reform_option_id id, token_generator &gen, error_handler &err, scenario_building_context &context)
void read_pending_invention(dcon::invention_id id, token_generator &gen, error_handler &err, scenario_building_context &context)
void read_pending_option(dcon::issue_option_id id, token_generator &gen, error_handler &err, scenario_building_context &context)
void read_pending_crime(dcon::crime_id id, token_generator &gen, error_handler &err, scenario_building_context &context)
void make_leader_images(scenario_building_context &outer_context)
int32_t parse_int(std::string_view content, int32_t line, error_handler &err)
void add_locale(sys::state &state, std::string_view locale_name, char const *data_start, char const *data_end)
dcon::effect_key make_effect(token_generator &gen, error_handler &err, effect_building_context &context)
void make_base_units(scenario_building_context &context)
void read_map_colors(char const *start, char const *end, error_handler &err, scenario_building_context &context)
void daily_party_loyalty_update(sys::state &state)
void recalculate_upper_house(sys::state &state, dcon::nation_id n)
void update_displayed_identity(sys::state &state, dcon::nation_id id)
void update_elections(sys::state &state)
void set_political_reform_desire(sys::state &state, dcon::pop_id p, float v)
void set_social_reform_desire(sys::state &state, dcon::pop_id p, float v)
uint32_t size(sys::state const &state)
void regenerate_is_primary_or_accepted(sys::state &state)
void set_demo(sys::state &state, dcon::pop_id p, dcon::pop_demographics_key k, float v)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
constexpr uint8_t impassible_bit
constexpr uint8_t state_bit
constexpr uint8_t national_bit
constexpr uint8_t coastal_bit
void update_connected_regions(sys::state &state)
void update_blockaded_cache(sys::state &state)
void update_nationalism(sys::state &state)
void update_crimes(sys::state &state)
std::vector< dcon::province_id > make_safe_land_path(sys::state &state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as)
void ve_for_each_land_province(sys::state &state, F const &func)
void restore_unsaved_values(sys::state &state)
void for_each_land_province(sys::state &state, F const &func)
void update_cached_values(sys::state &state)
void update_colonization(sys::state &state)
constexpr uint16_t to_map_id(dcon::province_id id)
void restore_distances(sys::state &state)
void execute_province_defections(sys::state &state)
void rebel_risings_check(sys::state &state)
void update_movement_values(sys::state &state)
void update_armies(sys::state &state)
void update_factions(sys::state &state)
void execute_rebel_victories(sys::state &state)
void daily_update_rebel_organization(sys::state &state)
void update_movements(sys::state &state)
void rebel_hunting_check(sys::state &state)
std::vector< unopened_file > list_files(directory const &dir, native_char const *extension)
native_string win1250_to_native(std::string_view data_in)
std::vector< directory > list_subdirectories(directory const &dir)
directory open_directory(directory const &dir, native_string_view directory_name)
native_string utf8_to_native(std::string_view data_in)
void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
directory get_or_create_oos_directory()
directory get_or_create_settings_directory()
native_string get_full_name(directory const &f)
directory get_or_create_save_game_directory()
std::optional< file > open_file(directory const &dir, native_string_view file_name)
std::optional< unopened_file > peek_file(directory const &dir, native_string_view file_name)
std::string native_to_utf8(native_string_view data_in)
file_contents view_contents(file const &f)
native_string get_file_name(unopened_file const &f)
audio_instance & get_peace_sound(sys::state &state)
audio_instance & get_minor_event_sound(sys::state &state)
audio_instance & get_revolt_sound(sys::state &state)
audio_instance & get_hover_sound(sys::state &state)
audio_instance & get_army_built_sound(sys::state &state)
audio_instance & get_accept_sound(sys::state &state)
audio_instance & get_technology_finished_sound(sys::state &state)
audio_instance & get_declaration_of_war_sound(sys::state &state)
audio_instance & get_naval_base_built_sound(sys::state &state)
audio_instance & get_major_event_sound(sys::state &state)
audio_instance & get_railroad_built_sound(sys::state &state)
void play_effect(sys::state &state, audio_instance &s, float volume)
audio_instance & get_decline_sound(sys::state &state)
audio_instance & get_election_sound(sys::state &state)
audio_instance & get_navy_built_sound(sys::state &state)
audio_instance & get_fort_built_sound(sys::state &state)
void play_interface_sound(sys::state &state, audio_instance &s, float volume)
audio_instance & get_diplomatic_request_sound(sys::state &state)
audio_instance & get_chat_message_sound(sys::state &state)
audio_instance & get_factory_built_sound(sys::state &state)
MOD_NAT_LIST constexpr uint32_t count
MOD_PROV_LIST constexpr uint32_t count
int32_t days_difference(year_month_day start, year_month_day end)
uint8_t * write_scenario_section(uint8_t *ptr_in, sys::state &state)
constexpr msg_setting_entry message_setting_map[size_t(message_base_type::count)]
size_t sizeof_save_section(sys::state &state)
uint8_t const * read_save_header(uint8_t const *ptr_in, save_header &header_out)
uint32_t pack_color(float r, float g, float b)
void repopulate_modifier_effects(sys::state &state)
@ crisis_join_offer_accepted
@ crisis_join_offer_declined
@ crisis_resolution_declined
@ crisis_resolution_accepted
uint8_t * write_save_section(uint8_t *ptr_in, sys::state &state)
scenario_size sizeof_scenario_section(sys::state &state)
constexpr int32_t tooltip_width
void update_modifier_effects(sys::state &state)
constexpr int32_t max_autosaves
size_t sizeof_save_header(save_header const &header_in)
bool is_playable_date(date d, absolute_time_point start, absolute_time_point end)
void write_save_file(sys::state &state, save_type type, std::string const &name)
void list_pop_types(sys::state &state, parsers::scenario_building_context &context)
columnar_layout create_columnar_layout(sys::state &state, layout &dest, layout_parameters const ¶ms, int32_t column_width)
char16_t win1250toUTF16(char in)
uint16_t name_into_font_id(sys::state &state, std::string_view txt)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
void consume_csv_file(sys::state &state, char const *file_content, uint32_t file_size, int32_t target_column, bool as_unicode)
dcon::text_key find_or_add_key(sys::state &state, std::string_view key, bool as_unicode)
int32_t to_generic(dcon::province_id v)
constexpr uint16_t no_payload
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
float evaluate_additive_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
uint16_t * recurse_over_triggers(uint16_t *source, T const &f)
constexpr uint16_t association_ne
void populate_map_tooltip(sys::state &state, text::columnar_layout &contents, dcon::province_id prov)
xy_pair get_absolute_location(sys::state &state, element_base const &node)
@ position_sensitive_tooltip
void create_in_game_windows(sys::state &state)
ogl::color_modification get_color_modification(bool is_under_mouse, bool is_disabled, bool is_interactable)
void load_text_gui_definitions(sys::state &state, parsers::building_gfx_context &context, parsers::error_handler &err)
bool events_pause_test(sys::state &state)
void new_event_window(sys::state &state, event_data_wrapper dat)
void change_cursor(sys::state &state, cursor_type type)
std::string_view native_string_view
std::string native_string
#define NATIVE_DIR_SEPARATOR
std::vector< dcon::issue_id > political_issues
std::vector< dcon::reform_id > military_issues
tagged_vector< crime_info, dcon::crime_id > crimes
std::vector< dcon::reform_id > economic_issues
std::vector< dcon::issue_id > party_issues
std::vector< dcon::issue_id > social_issues
dcon::ideology_id conservative
std::function< void(sys::state &state)> on_game_state_update
std::function< ui::mouse_probe(sys::state &state, ui::mouse_probe mouse_probe, ui::mouse_probe tooltip_probe)> recalculate_tooltip_probe
std::function< void(sys::state &state)> clean_up
std::function< void(sys::state &state)> on_game_state_update_update_ui
bool overwrite_map_tooltip
std::function< void(sys::state &state)> render_map
std::function< ui::mouse_probe(sys::state &state, ui::mouse_probe mouse_probe, ui::mouse_probe tooltip_probe)> recalculate_mouse_probe
std::function< ui::element_base *(sys::state &state)> get_root
std::function< void(sys::state &state)> render_ui
dcon::unit_type_id irregular
tagged_vector< unit_definition, dcon::unit_type_id > unit_base_definitions
dcon::unit_type_id infantry
dcon::unit_type_id artillery
static constexpr uint16_t mode_retreated
static constexpr uint16_t mode_sunk
static constexpr uint16_t mode_mask
std::vector< triggered_modifier > triggered_modifiers
sys::message_base_type type
GLuint ui_shader_screen_height_uniform
GLuint ui_shader_secondary_texture_sampler_uniform
GLuint ui_shader_screen_width_uniform
GLuint ui_shader_texture_sampler_uniform
GLuint ui_shader_gamma_uniform
std::optional< simple_fs::file > ideologies_file
tagged_vector< std::string, dcon::national_identity_id > file_names_for_idents
std::optional< simple_fs::file > crimes_file
ankerl::unordered_dense::map< std::string, pending_invention_content > map_of_inventions
std::vector< simple_fs::file > tech_and_invention_files
ankerl::unordered_dense::map< std::string, pending_roption_content > map_of_roptions
ankerl::unordered_dense::map< std::string, pending_tech_content > map_of_technologies
ankerl::unordered_dense::map< std::string, dcon::pop_type_id > map_of_poptypes
ankerl::unordered_dense::map< std::string, pending_ideology_content > map_of_ideologies
std::optional< simple_fs::file > issues_file
std::vector< dcon::province_id > original_id_to_prov_id_map
ankerl::unordered_dense::map< std::string, pending_crime_content > map_of_crimes
std::optional< simple_fs::file > rebel_types_file
ankerl::unordered_dense::map< std::string, pending_option_content > map_of_ioptions
ankerl::unordered_dense::map< std::string, pending_cb_content > map_of_cb_types
std::optional< simple_fs::file > cb_types_file
std::vector< pending_triggered_modifier_content > set_of_triggered_modifiers
building_gfx_context gfx_context
std::optional< simple_fs::file > triggered_modifiers_file
ankerl::unordered_dense::map< uint32_t, dcon::province_id > map_color_to_province_id
ankerl::unordered_dense::map< std::string, dcon::government_type_id > map_of_governments
void parse_file(sys::state &state, std::string_view data, parsers::error_handler &err)
uint8_t amounts[max_types]
static constexpr uint32_t max_types
text::font_manager font_collection
uint32_t add_locale_data_win1252(std::string const &text)
culture::global_cultural_state culture_definitions
network_mode_type network_mode
std::vector< char > key_data
user_settings_s user_settings
void save_user_settings() const
dcon::text_key add_key_win1252(std::string const &text)
dcon::trigger_key commit_trigger_data(std::vector< uint16_t > data)
std::atomic< bool > ui_pause
std::vector< dcon::army_id > selected_armies
ankerl::unordered_dense::set< dcon::text_key, text::vector_backed_ci_hash, text::vector_backed_ci_eq > untrans_key_to_text_sequence
void on_resize(int32_t x, int32_t y, window::window_state win_state)
std::vector< dcon::navy_id > selected_navies
dcon::data_container world
uint32_t add_locale_data_utf8(std::string const &text)
void on_lbutton_down(int32_t x, int32_t y, key_modifiers mod)
rigtorp::SPSCQueue< event::pending_human_p_event > new_p_event
void army_group_distribute_tasks(dcon::automated_army_group_id group)
std::vector< uint16_t > effect_data
void on_rbutton_down(int32_t x, int32_t y, key_modifiers mod)
dcon::nation_id local_player_nation
std::atomic< bool > game_state_updated
std::chrono::time_point< std::chrono::steady_clock > tooltip_timer
dcon::effect_key commit_effect_data(std::vector< uint16_t > data)
std::vector< char > unit_names
std::vector< int32_t > trigger_data_indices
std::string_view to_string_view(dcon::text_key tag) const
std::string_view locale_string_view(uint32_t tag) const
void on_mouse_wheel(int32_t x, int32_t y, key_modifiers mod, float amount)
std::vector< char > locale_text_data
simple_fs::file_system common_fs
game_scene::scene_properties current_scene
absolute_time_point start_date
absolute_time_point end_date
rigtorp::SPSCQueue< military::land_battle_report > land_battle_reports
void army_group_update_tasks(dcon::automated_army_group_id group)
military::global_military_state military_definitions
rigtorp::SPSCQueue< notification::message > new_messages
void open_diplomacy(dcon::nation_id target)
dcon::unit_name_id add_unit_name(std::string_view text)
void start_state_selection(state_selection_data &data)
std::vector< int32_t > unit_names_indices
void on_drag_finished(int32_t x, int32_t y, key_modifiers mod)
void on_rbutton_up(int32_t x, int32_t y, key_modifiers mod)
void on_key_up(virtual_key keycode, key_modifiers mod)
void on_mouse_move(int32_t x, int32_t y, key_modifiers mod)
dcon::text_key lookup_key(std::string_view text) const
void load_user_settings()
void on_lbutton_up(int32_t x, int32_t y, key_modifiers mod)
ankerl::unordered_dense::map< dcon::text_key, uint32_t, text::vector_backed_ci_hash, text::vector_backed_ci_eq > locale_key_to_text_sequence
void on_mouse_drag(int32_t x, int32_t y, key_modifiers mod)
void update_armies_and_fleets(dcon::automated_army_group_id group)
void on_key_down(virtual_key keycode, key_modifiers mod)
rigtorp::SPSCQueue< event::pending_human_f_p_event > new_f_p_event
void load_locale_strings(std::string_view locale_name)
void on_mbutton_up(int32_t x, int32_t y, key_modifiers mod)
void army_group_update_regiment_status(dcon::automated_army_group_id group)
rigtorp::SPSCQueue< diplomatic_message::message > new_requests
rigtorp::SPSCQueue< event::pending_human_n_event > new_n_event
void load_scenario_data(parsers::error_handler &err, sys::year_month_day bookmark_date)
void on_mbutton_down(int32_t x, int32_t y, key_modifiers mod)
dcon::text_key add_key_utf8(std::string const &text)
bool key_is_localized(dcon::text_key tag) const
std::vector< int32_t > effect_data_indices
rigtorp::SPSCQueue< military::naval_battle_report > naval_battle_reports
void state_select(dcon::state_definition_id sdef)
std::vector< uint16_t > trigger_data
void update_ui_scale(float new_scale)
std::optional< state_selection_data > state_selection
rigtorp::SPSCQueue< event::pending_human_f_n_event > new_f_n_event
std::atomic< bool > province_ownership_changed
nations::global_national_state national_definitions
bool wasd_for_map_movement
bool diplomatic_message_popup
uint8_t interesting_message_settings[int32_t(sys::message_setting_type::count)]
uint8_t self_message_settings[int32_t(sys::message_setting_type::count)]
bool notify_rebels_defeat
uint8_t other_message_settings[int32_t(sys::message_setting_type::count)]
element_base * under_mouse
std::unique_ptr< element_base > army_group_selector_root
element_base * map_rr_legend
element_base * msg_log_window
element_base * menubar_window
element_base * map_rec_legend
std::unique_ptr< element_base > end_screen
std::chrono::time_point< std::chrono::steady_clock > last_render_time
element_base * chat_window
std::unique_ptr< element_base > nation_picker
element_base * multi_unit_selection_window
element_base * last_tooltip
std::unique_ptr< grid_box > unit_details_box
std::unique_ptr< element_base > province_details_root
element_base * map_nav_legend
std::unique_ptr< tool_tip > tooltip
std::unique_ptr< element_base > rgos_root
std::unique_ptr< element_base > select_states_legend
xy_pair relative_mouse_location
element_base * topbar_subwindow
element_base * change_leader_window
element_base * r_chat_window
unit_details_window< dcon::army_id > * army_status_window
unit_details_window< dcon::navy_id > * navy_status_window
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
std::unique_ptr< element_base > root
element_base * edit_target
element_base * map_civ_level_legend
element_base * left_mouse_hold_target
std::vector< std::unique_ptr< element_base > > endof_navalcombat_windows
element_base * request_window
element_base * request_topbar_listbox
element_base * console_window
element_base * army_group_window_land
element_base * map_col_legend
bool scrollbar_continuous_movement
element_base * map_rank_legend
element_base * tl_chat_list
std::vector< dcon::technology_id > tech_queue
element_base * outliner_window
dcon::gfx_object_id bg_gfx_id
element_base * mouse_sensitive_target
element_base * map_dip_legend
element_base * diplomacy_subwindow
std::unique_ptr< element_base > military_root
element_base * drag_target
element_base * under_mouse
element_base * msg_window
element_base * scroll_target
element_base * map_gradient_legend
element_base * console_window_r
std::unique_ptr< element_base > units_root
static constexpr uint8_t is_moveable_mask