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);
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()));
2837 world.province_resize_rgo_profit_per_good(world.commodity_size());
2838 world.province_resize_rgo_actual_production_per_good(world.commodity_size());
2839 world.province_resize_rgo_employment_per_good(world.commodity_size());
2840 world.province_resize_rgo_target_employment_per_good(world.commodity_size());
2842 world.nation_resize_domestic_market_pool(world.commodity_size());
2843 world.nation_resize_real_demand(world.commodity_size());
2844 world.nation_resize_intermediate_demand(world.commodity_size());
2845 world.nation_resize_stockpile_targets(world.commodity_size());
2846 world.nation_resize_drawing_on_stockpiles(world.commodity_size());
2847 world.nation_resize_life_needs_costs(world.pop_type_size());
2848 world.nation_resize_everyday_needs_costs(world.pop_type_size());
2849 world.nation_resize_luxury_needs_costs(world.pop_type_size());
2850 world.nation_resize_imports(world.commodity_size());
2851 world.nation_resize_army_demand(world.commodity_size());
2852 world.nation_resize_navy_demand(world.commodity_size());
2853 world.nation_resize_construction_demand(world.commodity_size());
2854 world.nation_resize_private_construction_demand(world.commodity_size());
2855 world.nation_resize_demand_satisfaction(world.commodity_size());
2856 world.nation_resize_direct_demand_satisfaction(world.commodity_size());
2857 world.nation_resize_life_needs_weights(world.commodity_size());
2858 world.nation_resize_everyday_needs_weights(world.commodity_size());
2859 world.nation_resize_luxury_needs_weights(world.commodity_size());
2860 world.nation_resize_effective_prices(world.commodity_size());
2864 nations_by_rank.resize(2000);
2865 nations_by_industrial_score.resize(2000);
2866 nations_by_military_score.resize(2000);
2867 nations_by_prestige_score.resize(2000);
2868 crisis_participants.resize(2000);
2870 for(
auto t : world.in_technology) {
2871 for(
auto n : world.in_nation) {
2872 if(
n.get_active_technologies(t))
2876 for(
auto t : world.in_invention) {
2877 for(
auto n : world.in_nation) {
2880 n.set_active_inventions(t,
true);
2882 if(
n.get_active_inventions(t)) {
2891 world.for_each_province_adjacency([&](dcon::province_adjacency_id
id) {
2892 auto frel =
fatten(world,
id);
2893 auto prov_a = frel.get_connected_provinces(0);
2894 auto prov_b = frel.get_connected_provinces(1);
2895 if(prov_a.id.index() < province_definitions.first_sea_province.index() && prov_b.id.index() >= province_definitions.first_sea_province.index()) {
2897 }
else if(prov_a.id.index() >= province_definitions.first_sea_province.index() && prov_b.id.index() < province_definitions.first_sea_province.index()) {
2900 if(prov_a.get_state_from_abstract_state_membership() != prov_b.get_state_from_abstract_state_membership()) {
2903 if(prov_a.get_nation_from_province_ownership() != prov_b.get_nation_from_province_ownership()) {
2910 for(int32_t i = 0; i < province_definitions.first_sea_province.index(); ++i) {
2911 dcon::province_id
id{ dcon::province_id::value_base_t(i) };
2912 if(!world.province_get_terrain(
id)) {
2914 if(terrain_type < 64) {
2915 auto modifier = context.modifier_by_terrain_index[terrain_type];
2916 world.province_set_terrain(
id, modifier);
2920 for(int32_t i = province_definitions.first_sea_province.index(); i < int32_t(world.province_size()); ++i) {
2921 dcon::province_id
id{ dcon::province_id::value_base_t(i) };
2922 world.province_set_terrain(
id, context.ocean_terrain);
2930 world.for_each_province([&](dcon::province_id
id) { world.province_set_connected_region_id(
id, 0); });
2932 std::vector<dcon::province_id> to_fill_list;
2933 std::vector<int32_t> region_sizes;
2935 uint16_t current_fill_id = 0;
2936 province_definitions.connected_region_is_coastal.clear();
2938 to_fill_list.reserve(world.province_size());
2940 for(int32_t i = int32_t(world.province_size()); i-- > province_definitions.first_sea_province.index();) {
2941 dcon::province_id
id{ dcon::province_id::value_base_t(i) };
2943 if(world.province_get_connected_region_id(
id) == 0) {
2946 region_sizes.push_back(0);
2947 to_fill_list.push_back(
id);
2949 while(!to_fill_list.empty()) {
2950 auto current_id = to_fill_list.back();
2951 to_fill_list.pop_back();
2952 region_sizes.back() += 1;
2954 world.province_set_connected_region_id(current_id, current_fill_id);
2955 for(
auto rel : world.province_get_province_adjacency(current_id)) {
2957 if(
rel.get_connected_provinces(0).get_connected_region_id() == 0)
2958 to_fill_list.push_back(
rel.get_connected_provinces(0));
2959 if(
rel.get_connected_provinces(1).get_connected_region_id() == 0)
2960 to_fill_list.push_back(
rel.get_connected_provinces(1));
2965 to_fill_list.clear();
2970 for(int32_t i = 0; i < int32_t(region_sizes.size()); ++i) {
2971 if(region_sizes[max] < region_sizes[i])
2975 if(!region_sizes.empty()) {
2976 for(
auto k =
uint32_t(context.state.province_definitions.first_sea_province.index()); k < context.state.world.province_size(); ++k) {
2977 dcon::province_id p{ dcon::province_id::value_base_t(k) };
2978 if(world.province_get_connected_region_id(p) != int16_t(max + 1)) {
2979 world.province_set_is_coast(p,
false);
2980 world.province_set_port_to(p, dcon::province_id{});
2981 for(
auto adj : context.state.world.province_get_province_adjacency(p)) {
2982 auto other =
adj.get_connected_provinces(0) != p ?
adj.get_connected_provinces(0) :
adj.get_connected_provinces(1);
2983 other.set_is_coast(
false);
2984 other.set_port_to(dcon::province_id{});
2992 for(
auto ip : context.special_impassible) {
2993 for(
auto adj : world.province_get_province_adjacency(ip)) {
3000 for(
auto adj : world.province_get_province_adjacency(p)) {
3001 auto other = adj.get_connected_provinces(0) != p ? adj.get_connected_provinces(0) : adj.get_connected_provinces(1);
3002 auto bits = adj.get_type();
3003 if(other && (bits & province::border::coastal_bit) != 0 && (bits & province::border::impassible_bit) == 0) {
3004 world.province_set_port_to(p, other.id);
3005 world.province_set_is_coast(p, true);
3013 bool is_mine = world.commodity_get_is_mine(world.province_get_rgo(p));
3015 for(
auto pop : world.province_get_pop_location(p)) {
3016 if(is_mine && pop.get_pop().get_poptype() == culture_definitions.farmers) {
3017 pop.get_pop().set_poptype(culture_definitions.laborers);
3019 if(!is_mine &&
pop.get_pop().get_poptype() == culture_definitions.laborers) {
3020 pop.get_pop().set_poptype(culture_definitions.farmers);
3025 bool gov_error =
false;
3026 for(
auto n : world.in_nation) {
3027 auto g =
n.get_government_type();
3028 if(!g &&
n.get_owned_province_count() != 0) {
3030 err.accumulated_errors +=
name +
" exists but has no governmentnt (This will result in a crash)\n";
3040 for(
auto& s : context.gfx_context.nation_buttons_allow) {
3041 if(s.button_element) {
3042 err.file_name = s.original_file;
3044 ui_defs.gui[s.button_element].data.button.scriptable_enable =
make_trigger(s.generator_state, err, t_context);
3048 for(
auto& s : context.gfx_context.nation_buttons_effect) {
3049 if(s.button_element) {
3050 err.file_name = s.original_file;
3052 ui_defs.gui[s.button_element].data.button.scriptable_effect =
make_effect(s.generator_state, err, t_context);
3056 for(
auto& s : context.gfx_context.province_buttons_allow) {
3057 if(s.button_element) {
3058 err.file_name = s.original_file;
3059 auto existing_scripting = ui_defs.gui[s.button_element].data.button.get_button_scripting();
3061 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";
3064 ui_defs.gui[s.button_element].data.button.scriptable_enable =
make_trigger(s.generator_state, err, t_context);
3069 for(
auto& s : context.gfx_context.province_buttons_effect) {
3070 if(s.button_element) {
3071 err.file_name = s.original_file;
3072 auto existing_scripting = ui_defs.gui[s.button_element].data.button.get_button_scripting();
3074 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";
3077 ui_defs.gui[s.button_element].data.button.scriptable_effect =
make_effect(s.generator_state, err, t_context);
3084 for(
auto n : world.in_navy) {
3085 auto p =
n.get_navy_location().get_location();
3086 if(p.id.index() >= province_definitions.first_sea_province.index()) {
3089 auto pp = world.province_get_port_to(p);
3090 auto adj = world.get_province_adjacency_by_province_pair(p, pp);
3092 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";
3096 for(
auto a : world.in_army) {
3097 auto p = a.get_army_location().get_location();
3098 if(p.id.index() >= province_definitions.first_sea_province.index()) {
3107 for(
auto nid : world.in_national_identity) {
3113 std::fill(has_reported.begin(), has_reported.end(),
false);
3114 for(
auto g : world.in_government_type) {
3115 if(!has_reported[g.get_flag()]) {
3118 file_str +=
NATIVE(
".tga");
3122 has_reported[g.get_flag()] =
true;
3129 for(
auto p : world.in_pop_location) {
3130 for(
const auto src : p.get_pop().get_regiment_source()) {
3131 if(src.get_regiment().get_army_from_army_membership().get_controller_from_army_control() == p.get_province().get_nation_from_province_ownership())
3133 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";
3134 if(!src.get_regiment().get_army_from_army_membership().get_is_retreating()
3135 && !src.get_regiment().get_army_from_army_membership().get_navy_from_army_transport()
3136 && !src.get_regiment().get_army_from_army_membership().get_battle_from_army_battle_participation()
3137 && !src.get_regiment().get_army_from_army_membership().get_controller_from_army_rebel_control()) {
3138 auto new_u = world.create_army();
3139 world.army_set_controller_from_army_control(new_u, p.get_province().get_nation_from_province_ownership());
3140 src.get_regiment().set_army_from_army_membership(new_u);
3143 src.get_regiment().set_strength(0.f);
3149 fill_unsaved_data();
3151 for(
auto n : world.in_nation) {
3152 auto g =
n.get_government_type();
3154 if(!(
n.get_owned_province_count() == 0 || world.government_type_is_valid(g))) {
3158 for(
auto g : world.in_government_type) {
3159 for(
auto rt : world.in_rebel_type) {
3160 auto ng = rt.get_government_change(g);
3161 if(!(!ng ||
uint32_t(ng.id.index()) < world.government_type_size())) {
3168 for(
auto pending_decision : pending_decisions) {
3169 dcon::nation_id
n = pending_decision.first;
3170 dcon::decision_id
d = pending_decision.second;
3171 if(
auto e = world.decision_get_effect(d); e)
3193 assert(great_nations.size() == 0);
3196 while(greatpowersfound <
uint32_t(defines.great_nations_count)) {
3197 if(i >= nations_by_rank.size()) {
3200 if(nations_by_rank[i] && world.overlord_get_ruler(world.nation_get_overlord_as_subject(nations_by_rank[i])) == dcon::nation_id()) {
3201 great_nations.push_back(great_nation{
sys::date{0}, nations_by_rank[i] });
3202 world.nation_set_is_great_power(nations_by_rank[i],
true);
3209 for(
auto p : world.in_province) {
3214 if(
auto rgo = world.province_get_rgo(p); !rgo) {
3215 auto name = world.province_get_name(p);
3216 err.accumulated_errors += std::string(
"province ") + text::produce_simple_string(*this, name) +
" is missing an rgo\n";
3217 world.province_set_rgo(p, economy::money);
3234void state::preload() {
3235 adjacency_data_out_of_date =
true;
3236 for(
auto si : world.in_state_instance) {
3237 si.set_naval_base_is_taken(
false);
3238 si.set_capital(dcon::province_id{});
3240 for(
auto n : world.in_nation) {
3241 n.set_combined_issue_rules(0);
3242 n.set_is_at_war(
false);
3243 n.set_allies_count(0);
3244 n.set_vassals_count(0);
3245 n.set_substates_count(0);
3246 n.set_administrative_efficiency(0.0f);
3247 n.set_is_target_of_some_cb(
false);
3248 n.set_in_sphere_of(dcon::nation_id{});
3249 n.set_is_player_controlled(
false);
3250 n.set_is_great_power(
false);
3251 n.set_is_colonial_nation(
false);
3252 n.set_has_flash_point_state(
false);
3253 n.set_ai_is_threatened(
false);
3254 n.set_ai_home_port(dcon::province_id{});
3256 for(
auto p : world.in_pop) {
3257 p.set_political_reform_desire(0);
3258 p.set_social_reform_desire(0);
3259 p.set_is_primary_or_accepted_culture(
false);
3261 for(
auto p : world.in_province) {
3262 p.set_state_membership(dcon::state_instance_id{});
3263 p.set_is_owner_core(
false);
3264 p.set_is_blockaded(
false);
3266 for(
auto m : world.in_movement) {
3267 m.set_pop_support(0.0f);
3268 m.set_radicalism(0.0f);
3270 for(
auto s : world.in_ship) {
3271 s.set_pending_split(
false);
3273 for(
auto r : world.in_regiment) {
3274 r.set_pending_split(
false);
3278void state::on_scenario_load() {
3279 world.pop_type_resize_issues_fns(world.issue_option_size());
3280 world.pop_type_resize_ideology_fns(world.ideology_size());
3281 world.pop_type_resize_promotion_fns(world.pop_type_size());
3283 if(network_mode != network_mode_type::single_player)
3291 std::thread dispatch{ [&]() {
3292 jit_environment = std::make_unique<fif::environment>();
3294 int32_t error_count = 0;
3295 std::string error_list;
3296 jit_environment->report_error = [&](std::string_view s) {
3297 console_command_error += std::string(
"?R ERROR: ") + std::string(s) +
"?W\\n";
3308 for(
auto p : world.in_pop_type) {
3309 for(
auto i : world.in_issue_option) {
3310 auto mkey = world.pop_type_get_issues(p, i);
3311 std::string base_name =
"pi" + std::to_string(p.id.index()) +
"_" + std::to_string(i.id.index());
3314 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3317 std::string fn_str =
": " + base_name +
"internal" +
" drop 0.0 ; ";
3318 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3323 for(
auto id : world.in_ideology) {
3324 auto mkey = world.pop_type_get_ideology(p,
id);
3325 std::string base_name =
"pid" + std::to_string(p.id.index()) +
"_" + std::to_string(
id.
id.index());
3328 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3331 std::string fn_str =
": " + base_name +
"internal" +
" drop 0.0 ; ";
3332 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3337 for(
auto t : world.in_pop_type) {
3338 auto mkey = world.pop_type_get_promotion(p, t);
3339 std::string base_name =
"pp" + std::to_string(p.id.index()) +
"_" + std::to_string(t.id.index());
3342 fn_str +=
":export " + base_name +
"ext" +
" i32 " + base_name +
"internal ; ";
3348 auto mkey = world.pop_type_get_migration_target(p);
3349 std::string base_name =
"pmt" + std::to_string(p.id.index());
3352 fn_str +=
":export " + base_name +
"ext" +
" i32 i32 " + base_name +
"internal ; ";
3357 auto mkey = world.pop_type_get_country_migration_target(p);
3358 std::string base_name =
"pcmt" + std::to_string(p.id.index());
3361 fn_str +=
":export " + base_name +
"ext" +
" i32 i32 " + base_name +
"internal ; ";
3367 std::string fn_str =
": promote_internal >pop_id dup " +
fif_trigger::additive_modifier(*
this, culture_definitions.promotion_chance) +
" drop drop r> ; ";
3368 fn_str +=
":export promote_ext i32 promote_internal ; ";
3372 std::string fn_str =
": demote_internal >pop_id dup " +
fif_trigger::additive_modifier(*
this, culture_definitions.demotion_chance) +
" drop drop r> ; ";
3373 fn_str +=
":export demote_ext i32 demote_internal ; ";
3377 fif::perform_jit(*jit_environment);
3382 for(
auto p : world.in_pop_type) {
3383 for(
auto i : world.in_issue_option) {
3384 std::string name =
"pi" + std::to_string(p.id.index()) +
"_" + std::to_string(i.id.index()) +
"ext";
3387 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, name.c_str());
3392 OutputDebugStringA(msg);
3393 OutputDebugStringA(
"\n");
3397 assert(bare_address != 0);
3398 world.pop_type_set_issues_fns(p, i, bare_address);
3401 for(
auto id : world.in_ideology) {
3402 std::string name =
"pid" + std::to_string(p.id.index()) +
"_" + std::to_string(
id.
id.index()) +
"ext";
3405 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, name.c_str());
3410 OutputDebugStringA(msg);
3411 OutputDebugStringA(
"\n");
3415 assert(bare_address != 0);
3416 world.pop_type_set_ideology_fns(p,
id, bare_address);
3419 for(
auto t : world.in_pop_type) {
3420 if(world.pop_type_get_promotion(p, t)) {
3421 std::string name =
"pp" + std::to_string(p.id.index()) +
"_" + std::to_string(t.id.index()) +
"ext";
3424 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, name.c_str());
3429 OutputDebugStringA(msg);
3430 OutputDebugStringA(
"\n");
3434 assert(bare_address != 0);
3435 world.pop_type_set_promotion_fns(p, t, bare_address);
3441 auto mkey = world.pop_type_get_migration_target(p);
3443 std::string base_name =
"pmt" + std::to_string(p.id.index()) +
"ext";
3445 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, base_name.c_str());
3450 OutputDebugStringA(msg);
3451 OutputDebugStringA(
"\n");
3455 assert(bare_address != 0);
3456 world.pop_type_set_migration_target_fn(p, bare_address);
3461 auto mkey = world.pop_type_get_country_migration_target(p);
3463 std::string base_name =
"pcmt" + std::to_string(p.id.index()) +
"ext";
3465 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address, base_name.c_str());
3470 OutputDebugStringA(msg);
3471 OutputDebugStringA(
"\n");
3475 assert(bare_address != 0);
3476 world.pop_type_set_country_migration_target_fn(p, bare_address);
3484 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"promote_ext");
3489 OutputDebugStringA(msg);
3490 OutputDebugStringA(
"\n");
3494 assert(bare_address != 0);
3495 culture_definitions.promotion_chance_fn = bare_address;
3500 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"demote_ext");
3505 OutputDebugStringA(msg);
3506 OutputDebugStringA(
"\n");
3510 assert(bare_address != 0);
3511 culture_definitions.demotion_chance_fn = bare_address;
3520 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"set_container");
3525 OutputDebugStringA(msg);
3526 OutputDebugStringA(
"\n");
3530 assert(bare_address != 0);
3531 using ftype = void(*)(
void*);
3532 ftype fn = (ftype)bare_address;
3538 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"set_vector_storage");
3543 OutputDebugStringA(msg);
3544 OutputDebugStringA(
"\n");
3548 assert(bare_address != 0);
3549 using ftype = void(*)(
void*);
3550 ftype fn = (ftype)bare_address;
3551 fn(dcon::shared_backing_storage.allocation);
3556 auto error =
LLVMOrcLLJITLookup(jit_environment->llvm_jit, &bare_address,
"set_state");
3561 OutputDebugStringA(msg);
3562 OutputDebugStringA(
"\n");
3566 assert(bare_address != 0);
3567 using ftype = void(*)(
void*);
3568 ftype fn = (ftype)bare_address;
3582void state::fill_unsaved_data() {
3583 great_nations.reserve(int32_t(defines.great_nations_count));
3586 world.nation_resize_rgo_goods_output(world.commodity_size());
3587 world.nation_resize_factory_goods_output(world.commodity_size());
3588 world.nation_resize_factory_goods_throughput(world.commodity_size());
3589 world.nation_resize_rgo_size(world.commodity_size());
3590 world.nation_resize_rebel_org_modifier(world.rebel_type_size());
3591 world.nation_resize_active_unit(
uint32_t(military_definitions.unit_base_definitions.size()));
3592 world.nation_resize_active_crime(
uint32_t(culture_definitions.crimes.size()));
3593 world.nation_resize_active_building(world.factory_type_size());
3594 world.nation_resize_unit_stats(
uint32_t(military_definitions.unit_base_definitions.size()));
3597 world.province_resize_modifier_values(provincial_mod_offsets::count);
3607 nations_by_rank.resize(2000);
3608 nations_by_industrial_score.resize(2000);
3609 nations_by_military_score.resize(2000);
3610 nations_by_prestige_score.resize(2000);
3611 crisis_participants.resize(2000);
3613 world.for_each_issue([&](dcon::issue_id
id) {
3614 for(
auto& opt : world.issue_get_options(
id)) {
3616 world.issue_option_set_parent_issue(opt,
id);
3620 world.for_each_reform([&](dcon::reform_id
id) {
3621 for(
auto& opt : world.reform_get_options(
id)) {
3623 world.reform_option_set_parent_reform(opt,
id);
3627 for(
auto i : culture_definitions.party_issues) {
3630 for(
auto i : culture_definitions.military_issues) {
3633 for(
auto i : culture_definitions.economic_issues) {
3636 for(
auto i : culture_definitions.social_issues) {
3639 for(
auto i : culture_definitions.political_issues) {
3681 new_n_event.~SPSCQueue();
3694 if(local_player_nation) {
3695 world.nation_set_is_player_controlled(local_player_nation,
true);
3697 for(
auto const& e : pending_n_event) {
3698 if(e.n == local_player_nation) {
3699 auto auto_choice = world.national_event_get_auto_choice(e.e);
3700 if(auto_choice == 0)
3706 for(
auto const& e : pending_f_n_event) {
3707 if(e.n == local_player_nation) {
3708 auto auto_choice = world.free_national_event_get_auto_choice(e.e);
3709 if(auto_choice == 0)
3710 auto b = new_f_n_event.try_push(e);
3715 for(
auto const& e : pending_p_event) {
3716 if(world.province_get_nation_from_province_ownership(e.p) == local_player_nation) {
3717 auto auto_choice = world.provincial_event_get_auto_choice(e.e);
3718 if(auto_choice == 0)
3719 auto b = new_p_event.try_push(e);
3724 for(
auto const& e : pending_f_p_event) {
3725 if(world.province_get_nation_from_province_ownership(e.p) == local_player_nation) {
3726 auto auto_choice = world.free_provincial_event_get_auto_choice(e.e);
3727 if(auto_choice == 0)
3728 auto b = new_f_p_event.try_push(e);
3733 for(
auto const& m : pending_messages) {
3735 auto b = new_requests.try_push(m);
3739 ui_date = current_date;
3749 military_definitions.pending_blackflag_update =
true;
3753 for(
auto p : world.in_pop) {
3755 for(
auto i : world.in_ideology) {
3757 if(0.0 <= val && val <= 1.0f) {
3764 for(
auto i : world.in_ideology) {
3771 for(
auto a : world.in_army) {
3772 if(a.get_arrival_time() && a.get_arrival_time() <= current_date) {
3773 a.set_arrival_time(current_date + 1);
3776 for(
auto a : world.in_navy) {
3777 if(a.get_arrival_time() && a.get_arrival_time() <= current_date) {
3778 a.set_arrival_time(current_date + 1);
3781 for(
auto shp : world.in_ship) {
3782 assert(shp.get_navy_from_navy_membership());
3785 std::vector<dcon::ship_id> sin_battle;
3786 for(
auto b : world.in_naval_battle) {
3787 for(
auto slot : b.get_slots()) {
3791 assert(world.ship_is_valid(slot.ship));
3792 auto it = std::find(sin_battle.begin(), sin_battle.end(), slot.ship);
3793 assert(it == sin_battle.end());
3794 sin_battle.push_back(slot.ship);
3801 game_state_updated.store(
true, std::memory_order::release);
3804void state::single_game_tick() {
3811 game_state_updated.store(
true, std::memory_order::release);
3815 auto ymd_date = current_date.to_ymd(start_date);
3835 concurrency::parallel_for(0, 8, [&](int32_t index) {
3840 if(o >= days_in_month)
3847 auto o =
uint32_t(ymd_date.day + 1);
3848 if(o >= days_in_month)
3855 auto o =
uint32_t(ymd_date.day + 6);
3856 if(o >= days_in_month)
3863 auto o =
uint32_t(ymd_date.day + 7);
3864 if(o >= days_in_month)
3871 auto o =
uint32_t(ymd_date.day + 8);
3872 if(o >= days_in_month)
3879 auto o =
uint32_t(ymd_date.day + 9);
3880 if(o >= days_in_month)
3887 auto o =
uint32_t(ymd_date.day + 10);
3888 if(o >= days_in_month)
3895 auto o =
uint32_t(ymd_date.day + 11);
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)
4002 auto o =
uint32_t(ymd_date.day + 11);
4003 if(o >= days_in_month)
4014 concurrency::parallel_for(0, 17, [&](int32_t index) {
4021 for(
auto n: this->cheat_data.instant_research_nations) {
4022 auto tech = this->world.nation_get_current_research(n);
4023 if(
tech.is_valid()) {
4025 this->world.nation_set_research_points(n, points);
4105 if(current_date.value % 4 == 0) {
4109 if(defines.alice_eval_ai_mil_everyday != 0.0f) {
4116 switch(ymd_date.day) {
4131 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4141 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4189 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4205 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4227 if(!
bool(defines.alice_eval_ai_mil_everyday)) {
4243 if(ymd_date.day == 1) {
4244 if(ymd_date.month == 1) {
4246 for(
auto n : world.in_nation) {
4247 if(n.get_owned_province_count() != 0)
4253 if(ymd_date.month == 2) {
4256 if(ymd_date.month == 3 && !national_definitions.on_quarterly_pulse.empty()) {
4257 for(
auto n : world.in_nation) {
4258 if(n.get_owned_province_count() > 0) {
4263 if(ymd_date.month == 4 && ymd_date.year % 2 == 0) {
4266 if(ymd_date.month == 5) {
4269 if(ymd_date.month == 6 && !national_definitions.on_quarterly_pulse.empty()) {
4270 for(
auto n : world.in_nation) {
4271 if(n.get_owned_province_count() > 0) {
4276 if(ymd_date.month == 7) {
4279 if(ymd_date.month == 9 && !national_definitions.on_quarterly_pulse.empty()) {
4280 for(
auto n : world.in_nation) {
4281 if(n.get_owned_province_count() > 0) {
4286 if(ymd_date.month == 10 && !national_definitions.on_yearly_pulse.empty()) {
4287 for(
auto n : world.in_nation) {
4288 if(n.get_owned_province_count() > 0) {
4293 if(ymd_date.month == 11) {
4296 if(ymd_date.month == 12 && !national_definitions.on_quarterly_pulse.empty()) {
4297 for(
auto n : world.in_nation) {
4298 if(n.get_owned_province_count() > 0) {
4319 player_data_cache.treasury_record[current_date.value % 32] =
nations::get_treasury(*
this, local_player_nation);
4320 player_data_cache.population_record[current_date.value % 32] = world.nation_get_demographics(local_player_nation,
demographics::total);
4321 if((current_date.value % 16) == 0) {
4323 for(
auto c : world.in_commodity) {
4324 c.set_price_record(index, c.get_current_price());
4328 if(((ymd_date.month % 3) == 0) && (ymd_date.day == 1)) {
4330 for(
auto n : world.in_nation) {
4335 ui_date = current_date;
4337 game_state_updated.store(
true, std::memory_order::release);
4339 switch(user_settings.autosaves) {
4340 case autosave_frequency::none:
4342 case autosave_frequency::daily:
4345 case autosave_frequency::monthly:
4346 if(ymd_date.day == 1)
4349 case autosave_frequency::yearly:
4350 if(ymd_date.month == 1 && ymd_date.day == 1)
4359 dcon::load_record loaded = world.make_serialize_record_store_save();
4360 auto buffer = std::unique_ptr<uint8_t[]>(
new uint8_t[world.serialize_size(loaded)]);
4361 std::byte* start =
reinterpret_cast<std::byte*
>(buffer.get());
4362 world.serialize(start, loaded);
4364 auto buffer_position =
reinterpret_cast<uint8_t*
>(start);
4365 int32_t total_size_used =
static_cast<int32_t
>(buffer_position - buffer.get());
4368 blake2b(&key,
sizeof(key), buffer.get(), total_size_used,
nullptr, 0);
4372void state::debug_save_oos_dump() {
4376 dcon::load_record loaded = world.make_serialize_record_store_save();
4377 auto save_buffer = std::unique_ptr<uint8_t[]>(
new uint8_t[world.serialize_size(loaded)]);
4378 auto buffer_position =
reinterpret_cast<std::byte*
>(save_buffer.get());
4379 world.serialize(buffer_position, loaded);
4380 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - save_buffer.get();
4386 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - buffer.get();
4391void state::debug_scenario_oos_dump() {
4395 dcon::load_record loaded = world.make_serialize_record_store_scenario();
4396 auto buffer = std::unique_ptr<uint8_t[]>(
new uint8_t[world.serialize_size(loaded)]);
4397 auto buffer_position =
reinterpret_cast<std::byte*
>(buffer.get());
4398 world.serialize(buffer_position, loaded);
4399 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - buffer.get();
4405 size_t total_size_used =
reinterpret_cast<uint8_t*
>(buffer_position) - buffer.get();
4410void state::game_loop() {
4411 static int32_t game_speed[] = {
4418 game_speed[1] = int32_t(defines.alice_speed_1);
4419 game_speed[2] = int32_t(defines.alice_speed_2);
4420 game_speed[3] = int32_t(defines.alice_speed_3);
4421 game_speed[4] = int32_t(defines.alice_speed_4);
4423 while(quit_signaled.load(std::memory_order::acquire) ==
false) {
4426 std::lock_guard l{ ugly_ui_game_interaction_hack };
4430 std::this_thread::sleep_for(std::chrono::milliseconds(15));
4432 auto speed = actual_game_speed.load(std::memory_order::acquire);
4433 auto upause = ui_pause.load(std::memory_order::acquire);
4438 if(speed <= 0 || upause || internally_paused || current_scene.enforced_pause) {
4439 std::this_thread::sleep_for(std::chrono::milliseconds(15));
4441 auto entry_time = std::chrono::steady_clock::now();
4442 auto ms_count = std::chrono::duration_cast<std::chrono::milliseconds>(entry_time - last_update).count();
4443 if(speed >= 5 || ms_count >= game_speed[speed]) {
4444 last_update = entry_time;
4448 std::lock_guard l{ugly_ui_game_interaction_hack};
4452 std::this_thread::sleep_for(std::chrono::milliseconds(1));
4459void state::console_log(std::string_view message) {
4460 current_scene.console_log(*
this, message);
4463void state::new_army_group(dcon::province_id hq) {
4464 bool invalid_province =
false;
4465 world.for_each_automated_army_group(
4466 [&](dcon::automated_army_group_id item) {
4467 auto item_hq = world.automated_army_group_get_hq(item);
4469 invalid_province =
true;
4473 if(invalid_province) {
4476 auto new_group = world.create_automated_army_group();
4477 world.automated_army_group_set_hq(new_group, hq);
4478 world.automated_army_group_set_owner(new_group, local_player_nation);
4480 game_state_updated.store(
true, std::memory_order_release);
4483void state::toggle_defensive_position(dcon::automated_army_group_id group, dcon::province_id position) {
4484 auto fat_group = fatten(world, group);
4486 if(fat_group.get_provinces_defend().contains(position)) {
4487 fat_group.get_provinces_defend().remove_unique(position);
4489 fat_group.get_provinces_defend().push_back(position);
4492 game_state_updated.store(
true, std::memory_order_release);
4493 map_state.unhandled_province_selection =
true;
4496void state::toggle_enforce_control_position(dcon::automated_army_group_id group, dcon::province_id position) {
4497 auto fat_group = fatten(world, group);
4499 if(fat_group.get_provinces_enforce_control().contains(position)) {
4500 fat_group.get_provinces_enforce_control().remove_unique(position);
4502 fat_group.get_provinces_enforce_control().push_back(position);
4505 game_state_updated.store(
true, std::memory_order_release);
4506 map_state.unhandled_province_selection =
true;
4509void state::toggle_designated_port(dcon::automated_army_group_id group, dcon::province_id position) {
4510 auto fat_group = fatten(world, group);
4512 if(!world.province_get_is_coast(position)) {
4516 if(fat_group.get_provinces_ferry_origin().contains(position)) {
4517 fat_group.get_provinces_ferry_origin().remove_unique(position);
4519 fat_group.get_provinces_ferry_origin().push_back(position);
4522 game_state_updated.store(
true, std::memory_order_release);
4523 map_state.unhandled_province_selection =
true;
4526void state::army_group_add_regiment(dcon::automated_army_group_id group, dcon::regiment_id
id) {
4528 auto automation_check = world.regiment_get_automation(
id);
4529 if(automation_check) {
4533 auto automation_data = world.create_regiment_automation_data();
4536 std::lock_guard l{ ugly_ui_game_interaction_hack };
4537 world.try_create_automated_army_group_membership_regiment(automation_data, group);
4538 world.try_create_automation(automation_data,
id);
4541 auto fat_automation = fatten(world, automation_data);
4543 auto army = world.regiment_get_army_from_army_membership(
id);
4544 auto location = world.army_get_location_from_army_location(army);
4546 fat_automation.set_status(army_group_regiment_status::standby);
4547 fat_automation.set_task(army_group_regiment_task::idle);
4548 fat_automation.set_target(location);
4549 fat_automation.set_ferry_origin({ });
4550 fat_automation.set_ferry_target({ });
4551 fat_automation.set_await_command_execution_flag(
false);
4554 std::array<dcon::regiment_id, command::num_packed_units> data;
4556 data.fill(dcon::regiment_id{});
4561 game_state_updated.store(
true, std::memory_order_release);
4564void state::remove_navy_from_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id navy_to_delete) {
4565 std::lock_guard l{ ugly_ui_game_interaction_hack };
4567 auto membership = world.navy_get_automated_army_group_membership_navy(navy_to_delete);
4572 world.delete_automated_army_group_membership_navy(membership);
4575void state::remove_regiment_from_army_group(dcon::automated_army_group_id selected_group, dcon::regiment_id regiment_to_delete) {
4576 std::lock_guard l{ ugly_ui_game_interaction_hack };
4578 auto regiment_automation_relation = world.regiment_get_automation(regiment_to_delete);
4579 auto automation_data = world.automation_get_automation_data(regiment_automation_relation);
4581 if(!automation_data) {
4585 world.delete_regiment_automation_data(automation_data);
4588void state::remove_regiment_from_all_army_groups(dcon::regiment_id regiment_to_delete) {
4589 world.for_each_automated_army_group([&](dcon::automated_army_group_id item) {
4590 remove_regiment_from_army_group(item, regiment_to_delete);
4594void state::remove_army_army_group_clean(dcon::automated_army_group_id group, dcon::army_id army_to_delete) {
4595 for(
auto regiment_membership : world.army_get_army_membership(army_to_delete)) {
4596 remove_regiment_from_army_group(group, regiment_membership.get_regiment().id);
4600void state::add_army_to_army_group(dcon::automated_army_group_id selected_group, dcon::army_id selected_army) {
4601 for(
auto item : world.army_get_army_membership(selected_army)) {
4602 army_group_add_regiment(selected_group, item.get_regiment());
4606void state::add_navy_to_army_group(dcon::automated_army_group_id selected_group, dcon::navy_id selected_navy) {
4607 auto automation_link = world.navy_get_automated_army_group_membership_navy(selected_navy);
4608 auto current_group = world.automated_army_group_membership_navy_get_army(automation_link);
4615 std::lock_guard l{ ugly_ui_game_interaction_hack };
4616 auto new_link = world.try_create_automated_army_group_membership_navy(selected_navy, selected_group);
4619 game_state_updated.store(
true, std::memory_order_release);
4622void state::delete_army_group(dcon::automated_army_group_id group) {
4623 static std::vector<dcon::regiment_automation_data_id> to_delete = {};
4626 world.automated_army_group_for_each_automated_army_group_membership_regiment(group, [&](dcon::automated_army_group_membership_regiment_id item) {
4627 auto regiment = world.automated_army_group_membership_regiment_get_regiment(item);
4628 to_delete.push_back(regiment);
4631 std::lock_guard l{ ugly_ui_game_interaction_hack };
4633 if(!to_delete.empty()) {
4634 for(
auto& regiment : to_delete) {
4635 world.delete_regiment_automation_data(regiment);
4639 world.delete_automated_army_group(group);
4640 game_state_updated.store(
true, std::memory_order_release);
4643void state::update_armies_and_fleets(dcon::automated_army_group_id group) {
4644 auto owner = world.automated_army_group_get_owner(group);
4646 if(owner == local_player_nation) {
4648 static std::vector<dcon::regiment_automation_data_id> to_delete = {};
4651 world.automated_army_group_for_each_automated_army_group_membership_regiment(group, [&](dcon::automated_army_group_membership_regiment_id item) {
4652 auto regiment = world.automated_army_group_membership_regiment_get_regiment(item);
4653 auto regiment_true = world.regiment_automation_data_get_regiment_from_automation(regiment);
4654 if(!regiment_true) {
4655 to_delete.push_back(regiment);
4659 if(!to_delete.empty()) {
4660 std::lock_guard l{ ugly_ui_game_interaction_hack };
4661 for(
auto& regiment : to_delete) {
4662 world.delete_regiment_automation_data(regiment);
4667 delete_army_group(group);
4671void state::smart_select_army_group(dcon::automated_army_group_id selected_group) {
4672 if(!selected_army_group) {
4673 select_army_group(selected_group);
4677 if(selected_army_group == selected_group) {
4678 deselect_army_group();
4682 select_army_group(selected_group);
4685void state::select_army_group(dcon::automated_army_group_id selected_group) {
4686 selected_army_group = selected_group;
4688 game_state_updated.store(
true, std::memory_order_release);
4691void state::deselect_army_group() {
4692 selected_army_group = {};
4694 game_state_updated.store(
true, std::memory_order_release);
4697dcon::regiment_automation_data_id state::fill_province_up_to_supply_limit(
4698 dcon::automated_army_group_id group_id,
4699 dcon::province_id target,
4700 std::vector<float>& regiments_distribution,
4701 float overestimate_supply_limit,
4702 bool ignore_enemy_regiments_in_supply_calculations
4704 auto group = fatten(world, group_id);
4706 static std::vector<float> regiments_expectation_ideal;
4707 regiments_expectation_ideal.resize(military_definitions.unit_base_definitions.size() + 2);
4709 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4710 regiments_expectation_ideal[i] = 0.f;
4716 local_player_nation,
4718 )) * overestimate_supply_limit;
4725 if(ignore_enemy_regiments_in_supply_calculations) {
4730 for(
auto regiment_id : group.get_automated_army_group_membership_regiment()) {
4731 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4732 if(regiment.get_target() == target && regiment.get_status() == army_group_regiment_status::move_to_target) {
4733 current_weight += 3.f;
4734 }
else if(regiment.get_ferry_target() == target && regiment.get_status() == army_group_regiment_status::move_to_port) {
4735 current_weight += 3.f;
4741 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4742 regiments_expectation_ideal[i] = floor(regiments_distribution[i] * floor(supply_limit / 3.f)) * 3.f;
4743 ideal += regiments_expectation_ideal[i];
4746 if(current_weight + 3.f < ideal) {
4747 return fill_province(group, target, regiments_expectation_ideal);
4753float state::army_group_available_supply(dcon::automated_army_group_id group, dcon::province_id
province) {
4755 float current_weight = 0.f;
4756 for(
auto regiment_id : world.automated_army_group_get_automated_army_group_membership_regiment(group)) {
4757 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4758 if(regiment.get_target() ==
province) {
4759 current_weight += 3.f;
4761 regiment.get_ferry_target() ==
province
4763 regiment.get_status() == army_group_regiment_status::move_to_port
4764 || regiment.get_status() == army_group_regiment_status::await_transport
4765 || regiment.get_status() == army_group_regiment_status::is_transported
4766 || regiment.get_status() == army_group_regiment_status::disembark
4769 current_weight += 3.f;
4771 regiment.get_ferry_origin() ==
province
4773 regiment.get_status() == army_group_regiment_status::move_to_port
4774 || regiment.get_status() == army_group_regiment_status::await_transport
4777 current_weight += 3.f;
4781 return max_supply - current_weight;
4784void state::regiment_reset_order(dcon::regiment_automation_data_id regiment) {
4785 auto fat_data = fatten(world, regiment);
4787 fat_data.set_status(army_group_regiment_status::standby);
4788 fat_data.set_task(army_group_regiment_task::idle);
4791dcon::province_id state::find_available_ferry_origin(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment) {
4792 auto fat_reg = fatten(world, regiment);
4793 auto army = fat_reg.get_regiment_from_automation().get_army_from_army_membership();
4794 auto fat_group = fatten(world, group);
4796 for(
auto& item : fat_group.get_provinces_ferry_origin()) {
4798 if(army_group_available_supply(group, item) < 3.f) {
4807 if(world.province_get_is_coast(army.get_location_from_army_location())) {
4808 return army.get_location_from_army_location();
4812 static std::vector<dcon::province_id> origin_port_candidates;
4813 origin_port_candidates.clear();
4816 origin_port_candidates.push_back(army.get_location_from_army_location());
4818 while(l < r && l < 30) {
4819 auto current_location = origin_port_candidates[l];
4821 if(world.province_get_is_coast(current_location)) {
4822 return current_location;
4825 if(current_location.value >= province_definitions.first_sea_province.value) {
4835 for(
auto adj : world.province_get_province_adjacency(current_location)) {
4836 auto other = adj.get_connected_provinces(adj.get_connected_provinces(0) == current_location ? 1 : 0);
4838 if(std::find(origin_port_candidates.begin(), origin_port_candidates.end(), other) == origin_port_candidates.end()) {
4839 origin_port_candidates.push_back(other);
4848 dcon::province_id invalid_province{};
4849 return invalid_province;
4852bool state::move_to_available_port(dcon::automated_army_group_id group, dcon::regiment_automation_data_id regiment) {
4853 auto fat_reg = fatten(world, regiment);
4854 dcon::province_id target = find_available_ferry_origin(group, regiment);
4855 auto army = fat_reg.get_regiment_from_automation().get_army_from_army_membership();
4858 if(army.get_location_from_army_location() != target) {
4860 fat_reg.set_await_command_execution_flag(
true);
4862 fat_reg.set_status(army_group_regiment_status::move_to_port);
4863 fat_reg.set_ferry_origin(target);
4870bool state::army_group_recalculate_distribution(dcon::automated_army_group_id group, std::vector<float>& regiments_distribution) {
4871 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4872 regiments_distribution[i] = 0.f;
4877 for(
auto regiment_id : world.automated_army_group_get_automated_army_group_membership_regiment(group)) {
4878 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4880 auto regiment_type = regiment.get_regiment_from_automation().get_type();
4882 if(!regiment_type) {
4886 auto task = regiment.get_task();
4887 auto status = regiment.get_status();
4889 task == army_group_regiment_task::idle ||
4890 task == army_group_regiment_task::gather_at_hq
4892 regiments_distribution[regiment_type.index()] += 1.f;
4898 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
4899 regiments_distribution[i] = regiments_distribution[i] / total;
4906void state::army_group_update_tasks(dcon::automated_army_group_id group) {
4910 dcon::province_id potential_ferry_target{};
4911 float ferry_supply_budget = 0.f;
4913 auto fat_group = fatten(world, group);
4915 for(
auto regiment_id : world.automated_army_group_get_automated_army_group_membership_regiment(group)) {
4916 auto regiment =
dcon::fatten(world, regiment_id).get_regiment();
4918 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
4920 auto current_path = world.army_get_path(army);
4921 if(current_path.size() > 0) {
4925 auto province = world.army_get_location_from_army_location(army);
4926 auto controller = world.province_get_nation_from_province_control(
province);
4928 if(regiment.get_status() != army_group_regiment_status::standby) {
4932 switch(regiment.get_task()) {
4933 case army_group_regiment_task::idle:
4935 case army_group_regiment_task::gather_at_hq:
4937 case army_group_regiment_task::defend_position:
4938 if(!fat_group.get_provinces_defend().contains(regiment.get_target())) {
4939 regiment_reset_order(regiment);
4942 case army_group_regiment_task::siege:
4943 if(regiment.get_target() !=
province) {
4949 regiment_reset_order(regiment);
4957dcon::province_id state::get_port_for_landing(dcon::automated_army_group_id group, dcon::province_id target) {
4958 auto fat_group = fatten(world, group);
4960 if(world.province_get_is_coast(target)) {
4964 dcon::province_id potential_target_port{};
4965 for(
auto& target_port : fat_group.get_provinces_ferry_origin()) {
4967 if(path.size() > 0) {
4968 potential_target_port = target_port;
4972 return potential_target_port;
4975void state::army_group_distribute_tasks(dcon::automated_army_group_id group) {
4976 static std::vector<dcon::province_id> province_queue;
4977 static std::vector<dcon::province_id> provinces_to_reduce_weight;
4978 static std::vector<dcon::province_id> provinces_to_maintain;
4979 static std::vector<float> regiments_distribution;
4980 regiments_distribution.resize(military_definitions.unit_base_definitions.size() + 2);
4982 auto fat_group = fatten(world, group);
4987 if(army_group_recalculate_distribution(group, regiments_distribution)) {
4989 dcon::province_id candidate{};
4990 float supply_limit = 0.f;
4991 for(dcon::province_id defensive_position : fat_group.get_provinces_defend()) {
4992 auto regiment = fill_province_up_to_supply_limit(
4995 regiments_distribution,
5000 world.regiment_automation_data_set_task(regiment, army_group_regiment_task::defend_position);
5009 if(army_group_recalculate_distribution(group, regiments_distribution)) {
5010 for(dcon::province_id province_to_siege : fat_group.get_provinces_enforce_control()) {
5011 auto controller = world.province_get_nation_from_province_control(province_to_siege);
5016 auto regiment = fill_province_up_to_supply_limit(
5019 regiments_distribution,
5024 world.regiment_automation_data_set_task(regiment, army_group_regiment_task::siege);
5035 for(
auto fleet_membership : fat_group.get_automated_army_group_membership_navy()) {
5036 auto fleet = fleet_membership.get_navy();
5037 auto location = fleet.get_location_from_navy_location();
5039 auto path = fleet.get_path();
5041 if(path.size() > 0) {
5045 auto transported_armies = fleet.get_army_transport();
5046 bool wait_for_disembark =
false;
5047 for(
auto item : transported_armies) {
5048 auto army = item.get_army();
5049 auto path_army = world.army_get_path(army);
5051 if(path_army.size() > 0) {
5052 wait_for_disembark =
true;
5056 if(wait_for_disembark) {
5064 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5065 auto regiment = regiment_automation_link.get_regiment();
5066 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5067 auto target = regiment.get_ferry_target();
5068 auto port_to = world.province_get_port_to(target);
5069 auto transport = world.army_get_army_transport(army);
5070 auto regiment_fleet = world.army_transport_get_navy(transport);
5071 auto fleet_location = world.navy_get_location_from_navy_location(fleet);
5073 if(regiment_fleet == fleet) {
5075 if(port_to == fleet_location) {
5087 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5088 auto regiment = regiment_automation_link.get_regiment();
5091 regiment.get_status() != army_group_regiment_status::await_transport
5092 && regiment.get_status() != army_group_regiment_status::embark
5096 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5097 auto regiment_location = army.get_location_from_army_location();
5098 auto port_to = regiment_location.get_port_to();
5100 if(port_to == fleet.get_location_from_navy_location()) {
5114 province_queue.clear();
5115 provinces_to_reduce_weight.clear();
5116 provinces_to_maintain.clear();
5118 province_queue.push_back(fat_group.get_hq());
5124 auto current_location = province_queue[l];
5126 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5128 auto regiment = regiment_automation_link.get_regiment();
5129 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5130 auto army_location = army.get_location_from_army_location();
5131 auto current_path = army.get_path();
5132 auto status = regiment.get_task();
5133 if(status != army_group_regiment_task::idle) {
5136 if(current_path.size() > 0) {
5139 if(current_location == army_location) {
5140 regiment.set_task(army_group_regiment_task::gather_at_hq);
5141 regiment.set_status(army_group_regiment_status::standby);
5146 if(current_location.value >= province_definitions.first_sea_province.value) {
5151 auto ownership = world.province_get_province_ownership_as_province(current_location);
5152 auto owner = world.province_ownership_get_nation(ownership);
5158 if(fat_group.get_provinces_defend().contains(current_location)) {
5165 local_player_nation,
5170 *
this, current_location
5173 auto supply_left = army_group_available_supply(group, current_location);
5175 if(4.f < supply_left) {
5177 }
else if(current_weight > supply_limit) {
5178 provinces_to_reduce_weight.push_back(current_location);
5180 provinces_to_maintain.push_back(current_location);
5184 for(
auto adj : world.province_get_province_adjacency(current_location)) {
5185 auto other = adj.get_connected_provinces(adj.get_connected_provinces(0) == current_location ? 1 : 0);
5187 if(std::find(province_queue.begin(), province_queue.end(), other) == province_queue.end()) {
5188 province_queue.push_back(other);
5197 auto target_location = province_queue[l];
5198 dcon::province_id potential_target_port = get_port_for_landing(group, fat_group.get_hq());
5200 for(
auto regiment_automation_link : fat_group.get_automated_army_group_membership_regiment()) {
5201 auto regiment = regiment_automation_link.get_regiment();
5202 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5203 auto army_location = army.get_location_from_army_location();
5204 auto army_path = army.get_path();
5206 if(regiment.get_task() != army_group_regiment_task::idle) {
5209 if(army_path.size() > 0) {
5212 if(army_location == target_location) {
5213 regiment.set_task(army_group_regiment_task::gather_at_hq);
5214 regiment.set_status(army_group_regiment_status::standby);
5221 if(potential_target_port) {
5222 if(move_to_available_port(group, regiment)) {
5223 regiment.set_task(army_group_regiment_task::gather_at_hq);
5224 regiment.set_target(target_location);
5225 regiment.set_ferry_target(potential_target_port);
5230 regiment.set_task(army_group_regiment_task::gather_at_hq);
5231 regiment.set_status(army_group_regiment_status::move_to_target);
5232 regiment.set_target(path[0]);
5239void state::army_group_update_regiment_status(dcon::automated_army_group_id group) {
5240 auto fat_group = fatten(world, group);
5242 for(
auto regiment_link : fat_group.get_automated_army_group_membership_regiment()) {
5243 auto regiment = regiment_link.get_regiment();
5244 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5249 auto current_path = army.get_path();
5250 if(current_path.size() > 0) {
5251 regiment.set_await_command_execution_flag(
false);
5255 if(regiment.get_await_command_execution_flag()) {
5259 auto location = world.army_get_location_from_army_location(army);
5260 auto target = regiment.get_target();
5264 switch(regiment.get_status()) {
5265 case army_group_regiment_status::move_to_target:
5266 if(location == target) {
5267 regiment.set_status(army_group_regiment_status::standby);
5272 regiment.set_await_command_execution_flag(
true);
5274 regiment_reset_order(regiment);
5278 case army_group_regiment_status::move_to_port:
5280 if(regiment.get_ferry_origin() == location) {
5281 regiment.set_status(army_group_regiment_status::await_transport);
5283 command::move_army(*
this, local_player_nation, army, regiment.get_ferry_origin(),
false);
5287 case army_group_regiment_status::standby:
5288 if(location != target) {
5289 regiment.set_status(army_group_regiment_status::move_to_target);
5292 case army_group_regiment_status::await_transport:
5294 if(location.value >= province_definitions.first_sea_province.value) {
5296 regiment.set_status(army_group_regiment_status::is_transported);
5301 bool at_ferry_origin = location == regiment.get_ferry_origin();
5302 if(!at_ferry_origin) {
5303 regiment_reset_order(regiment);
5306 dcon::province_id port_to = world.province_get_port_to(location);
5308 for(
auto fleet_membership : fat_group.get_automated_army_group_membership_navy()) {
5309 auto fleet = fleet_membership.get_navy();
5311 auto path = fleet.get_path();
5312 if(path.size() > 0) {
5316 auto fleet_location = world.navy_get_location_from_navy_location(fleet);
5317 if(fleet_location == port_to) {
5320 if(path_army.size() > 0) {
5322 regiment.set_status(army_group_regiment_status::embark);
5323 regiment.set_await_command_execution_flag(
true);
5331 case army_group_regiment_status::is_transported:
5332 if(location.value >= province_definitions.first_sea_province.value) {
5334 auto ferry_target = regiment.get_ferry_target();
5335 auto port_to = world.province_get_port_to(ferry_target);
5336 auto transport = world.army_get_army_transport(army);
5337 auto fleet = world.army_transport_get_navy(transport);
5338 auto fleet_location = world.navy_get_location_from_navy_location(fleet);
5341 if(fleet_location == port_to) {
5344 if(path_army.size() > 0) {
5346 regiment.set_await_command_execution_flag(
true);
5347 regiment.set_status(army_group_regiment_status::disembark);
5354 regiment_reset_order(regiment);
5356 case army_group_regiment_status::disembark:
5357 if(location == regiment.get_ferry_target()) {
5358 regiment.set_status(army_group_regiment_status::move_to_target);
5362 regiment.set_status(army_group_regiment_status::is_transported);
5364 case army_group_regiment_status::embark:
5365 if(location.value >= province_definitions.first_sea_province.value) {
5366 regiment.set_status(army_group_regiment_status::is_transported);
5370 regiment.set_status(army_group_regiment_status::await_transport);
5378dcon::regiment_automation_data_id state::fill_province(
5379 dcon::automated_army_group_id group_id,
5380 dcon::province_id target,
5381 std::vector<float> & regiments_expectation_ideal
5383 static std::vector<float> regiments_expectation_current;
5384 static std::vector<float> regiments_in_candidate_army;
5386 regiments_expectation_current.resize(military_definitions.unit_base_definitions.size() + 2);
5387 regiments_in_candidate_army.resize(military_definitions.unit_base_definitions.size() + 2);
5389 for(
uint32_t i = 0; i < military_definitions.unit_base_definitions.size(); ++i) {
5390 regiments_expectation_current[i] = 0.f;
5391 regiments_in_candidate_army[i] = 0.f;
5394 auto fat_group = fatten(world, group_id);
5396 bool success =
false;
5400 for(
auto regiment_membership : fat_group.get_automated_army_group_membership_regiment()) {
5401 auto regiment = regiment_membership.get_regiment();
5402 if(regiment.get_target() == target) {
5403 auto regiment_type = regiment.get_regiment_from_automation().get_type();
5405 regiments_expectation_current[regiment_type.index()] += 3.f;
5410 dcon::regiment_automation_data_id final_regiment{};
5413 auto target_port = get_port_for_landing(group_id, target);
5414 for(
auto regiment_membership : fat_group.get_automated_army_group_membership_regiment()) {
5415 auto regiment = regiment_membership.get_regiment();
5417 auto current_task = regiment.get_task();
5419 if(current_task != army_group_regiment_task::idle && current_task != army_group_regiment_task::gather_at_hq) {
5423 auto regiment_type = regiment.get_regiment_from_automation().get_type();
5425 if(!regiment_type) {
5430 regiments_expectation_ideal[regiment_type.index()]
5431 - regiments_expectation_current[regiment_type.index()];
5433 if(required >= 2.9f) {
5434 auto army = regiment.get_regiment_from_automation().get_army_from_army_membership();
5436 if(path.empty() && target != army.get_location_from_army_location()) {
5438 if(target_port && move_to_available_port(group_id, regiment)) {
5439 regiment.set_ferry_target(target_port);
5440 regiment.set_target(target);
5445 regiment.set_status(army_group_regiment_status::move_to_target);
5446 regiment.set_target(target);
5455void state::fill_vector_of_connected_provinces(dcon::province_id p1,
bool is_land, std::vector<dcon::province_id> & provinces) {
5457 if(world.province_get_nation_from_province_ownership(p1) == local_player_nation) {
5459 auto rid = world.province_get_connected_region_id(p1);
5460 for(
const auto pc : world.nation_get_province_ownership_as_nation(local_player_nation)) {
5461 if(pc.get_province().get_connected_region_id() == rid
5462 && pc.get_province().get_province_control().get_nation() == local_player_nation) {
5463 provinces.push_back(pc.get_province());
5467 for(
const auto pc : world.nation_get_province_ownership_as_nation(local_player_nation)) {
5468 if(pc.get_province().get_province_control().get_nation() == local_player_nation
5469 && pc.get_province().get_is_coast()) {
5470 provinces.push_back(pc.get_province());
5478 dcon::province_id
p;
5480 dcon::unit_type_id
u;
5483void state::build_up_to_template_land(
5485 dcon::province_id target_province,
5486 std::vector<dcon::province_id> & available_provinces,
5487 std::array<uint8_t, sys::macro_builder_template::max_types> & current_distribution
5490 std::vector<build_queue_data> build_queue;
5495 std::memcpy(remaining_to_build, target_template.
amounts,
sizeof(remaining_to_build));
5498 for(dcon::unit_type_id::value_base_t i = 0; i < upper_limit; i++) {
5499 dcon::unit_type_id utid = dcon::unit_type_id(i);
5500 if(remaining_to_build[i] < current_distribution[i]) {
5501 remaining_to_build[i] = 0;
5503 remaining_to_build[i] -= current_distribution[i];
5507 for(
const auto prov : available_provinces) {
5508 for(
const auto p : world.province_get_pop_location_as_province(prov)) {
5509 auto pop = p.get_pop();
5510 if(pop.get_poptype() != culture_definitions.soldiers)
5514 auto source = pop.get_regiment_source();
5515 int32_t used = int32_t(source.end() - source.begin());
5517 auto constructions = pop.get_province_land_construction_as_pop();
5518 used += int32_t(constructions.end() - constructions.begin());
5520 int32_t avail = possible - used;
5529 auto unit_types = military_definitions.unit_base_definitions.size();
5531 for(dcon::unit_type_id::value_base_t i = 0; i < unit_types; i++) {
5532 dcon::unit_type_id utid = dcon::unit_type_id(i);
5534 if(!military_definitions.unit_base_definitions[utid].is_land) {
5538 if(remaining_to_build[i] == 0) {
5544 local_player_nation,
5555 for(int32_t j = 0; j < int32_t(remaining_to_build[i]) && j < avail; j++) {
5557 remaining_to_build[i]--;
5559 if(remaining_to_build[i] == 0)
5566 for(
const auto& build : build_queue) {
5569 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 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 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 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_conversion(sys::state &state, uint32_t offset, uint32_t divisions, conversion_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 update_conversion(sys::state &state, uint32_t offset, uint32_t divisions, conversion_buffer &pbuf)
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)
uint32_t size(sys::state const &state)
void regenerate_is_primary_or_accepted(sys::state &state)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
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