5#include <unordered_map>
8#include "dcon_generated.hpp"
24using unit_var = std::variant<std::monostate, dcon::army_id, dcon::navy_id>;
33 if(std::holds_alternative<dcon::army_id>(u)) {
34 auto a = std::get<dcon::army_id>(u);
36 state.selected_armies.clear();
37 state.selected_navies.clear();
40 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
41 auto a = std::get<dcon::navy_id>(u);
43 state.selected_armies.clear();
44 state.selected_navies.clear();
51 if(std::holds_alternative<dcon::army_id>(u)) {
52 auto a = std::get<dcon::army_id>(u);
53 if(
state.world.army_get_controller_from_army_control(a) ==
state.local_player_nation) {
54 if(!
state.is_selected(a))
59 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
60 auto a = std::get<dcon::navy_id>(u);
61 if(
state.world.navy_get_controller_from_navy_control(a) ==
state.local_player_nation) {
62 if(!
state.is_selected(a))
82 if(std::holds_alternative<dcon::army_id>(u)) {
85 auto a = std::get<dcon::army_id>(u);
86 for(
auto r :
state.world.army_get_army_membership(a)) {
87 total += r.get_regiment().get_org();
93 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
96 auto a = std::get<dcon::navy_id>(u);
97 for(
auto r :
state.world.navy_get_navy_membership(a)) {
98 total += r.get_ship().get_org();
110 auto is_understr = [&]() {
111 for(
auto m :
state.world.army_get_army_membership(a)) {
112 if(m.get_regiment().get_strength() < 1.0f)
117 if(
state.world.army_get_black_flag(a)) {
119 }
else if(
state.world.army_get_is_retreating(a)) {
121 }
else if(
state.world.army_get_battle_from_army_battle_participation(a)) {
123 }
else if(
state.world.army_get_navy_from_army_transport(a)) {
125 }
else if(
state.world.army_get_arrival_time(a)) {
129 }
else if(is_understr()) {
136 auto trange =
state.world.navy_get_army_transport(a);
138 auto is_understr = [&]() {
139 for(
auto m :
state.world.navy_get_navy_membership(a)) {
140 if(m.get_ship().get_strength() < 1.0f)
147 if(
state.world.navy_get_is_retreating(a)) {
149 }
else if(
state.world.navy_get_battle_from_navy_battle_participation(a)) {
153 }
else if(trange.begin() != trange.end()) {
155 }
else if(!(
state.world.navy_get_arrival_time(a)) && nb_level > 0 && is_understr()) {
157 }
else if(
state.world.navy_get_arrival_time(a)) {
168 if(std::holds_alternative<dcon::army_id>(u)) {
169 auto a = std::get<dcon::army_id>(u);
171 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
172 auto a = std::get<dcon::navy_id>(u);
183 if(std::holds_alternative<dcon::army_id>(u)) {
185 auto a = std::get<dcon::army_id>(u);
186 for(
auto m :
state.world.army_get_army_membership(a)) {
187 total += int64_t(floor(m.get_regiment().get_strength() *
state.defines.pop_size_per_regiment));
190 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
192 auto a = std::get<dcon::navy_id>(u);
193 for(
auto m :
state.world.navy_get_navy_membership(a)) {
194 total += m.get_ship().get_strength();
209 if(std::holds_alternative<dcon::army_id>(u)) {
210 auto a = std::get<dcon::army_id>(u);
211 auto dig_in =
state.world.army_get_dig_in(a);
231 static std::vector<int32_t> by_icon_count;
232 for(
auto& i : by_icon_count)
238 if(std::holds_alternative<dcon::army_id>(u)) {
239 auto a = std::get<dcon::army_id>(u);
240 if(
state.world.army_get_controller_from_army_control(a) !=
state.local_player_nation) {
245 for(
auto m :
state.world.army_get_army_membership(a)) {
246 auto icon =
state.military_definitions.unit_base_definitions[m.get_regiment().get_type()].icon - 1;
247 if(
uint32_t(icon) >= by_icon_count.size()) {
248 by_icon_count.resize(icon + 1, 0);
250 ++(by_icon_count[icon]);
252 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
253 auto a = std::get<dcon::navy_id>(u);
254 if(
state.world.navy_get_controller_from_navy_control(a) !=
state.local_player_nation) {
259 for(
auto m :
state.world.navy_get_navy_membership(a)) {
260 auto icon =
state.military_definitions.unit_base_definitions[m.get_ship().get_type()].icon - 1;
261 if(
uint32_t(icon) >= by_icon_count.size()) {
262 by_icon_count.resize(icon + 1, 0);
264 ++(by_icon_count[icon]);
268 int32_t max_index = 0;
269 for(
uint32_t i = 1; i < by_icon_count.size(); ++i) {
270 if(by_icon_count[i] > by_icon_count[max_index])
271 max_index = int32_t(i);
287 static std::vector<int32_t> by_icon_count;
288 for(
auto& i : by_icon_count)
294 if(std::holds_alternative<dcon::army_id>(u)) {
295 auto a = std::get<dcon::army_id>(u);
296 if(
state.world.army_get_controller_from_army_control(a) !=
state.local_player_nation) {
301 for(
auto m :
state.world.army_get_army_membership(a)) {
302 auto icon =
state.military_definitions.unit_base_definitions[m.get_regiment().get_type()].icon - 1;
303 if(
uint32_t(icon) >= by_icon_count.size()) {
304 by_icon_count.resize(icon + 1, 0);
306 ++(by_icon_count[icon]);
308 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
309 auto a = std::get<dcon::navy_id>(u);
310 if(
state.world.navy_get_controller_from_navy_control(a) !=
state.local_player_nation) {
315 for(
auto m :
state.world.navy_get_navy_membership(a)) {
316 auto icon =
state.military_definitions.unit_base_definitions[m.get_ship().get_type()].icon - 1;
317 if(
uint32_t(icon) >= by_icon_count.size()) {
318 by_icon_count.resize(icon + 1, 0);
320 ++(by_icon_count[icon]);
324 if(by_icon_count.size() == 0) {
330 int32_t max_index = 0;
331 for(
uint32_t i = 1; i < by_icon_count.size(); ++i) {
332 if(by_icon_count[i] > by_icon_count[max_index])
333 max_index = int32_t(i);
335 by_icon_count[max_index] = 0;
338 int32_t max_index = 0;
339 for(
uint32_t i = 1; i < by_icon_count.size(); ++i) {
340 if(by_icon_count[i] > by_icon_count[max_index])
341 max_index = int32_t(i);
343 if(by_icon_count[max_index] == 0) {
362 if(payload.holds_type<dcon::nation_id>()) {
364 if(std::holds_alternative<dcon::army_id>(u)) {
365 auto a = std::get<dcon::army_id>(u);
366 payload.emplace<dcon::nation_id>(
state.world.army_get_controller_from_army_control(a));
367 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
368 auto a = std::get<dcon::navy_id>(u);
369 payload.emplace<dcon::nation_id>(
state.world.navy_get_controller_from_navy_control(a));
371 payload.emplace<dcon::nation_id>(dcon::nation_id{});
374 }
else if(payload.holds_type<dcon::rebel_faction_id>()) {
376 if(std::holds_alternative<dcon::army_id>(u)) {
377 auto a = std::get<dcon::army_id>(u);
378 payload.emplace<dcon::rebel_faction_id>(
state.world.army_get_controller_from_army_rebel_control(a));
380 payload.emplace<dcon::rebel_faction_id>(dcon::rebel_faction_id{});
391 if(std::holds_alternative<dcon::army_id>(u)) {
392 auto a = std::get<dcon::army_id>(u);
393 if(
state.world.army_get_controller_from_army_control(a) ==
state.local_player_nation) {
398 }
else if(std::holds_alternative<dcon::navy_id>(u)) {
399 auto a = std::get<dcon::navy_id>(u);
400 if(
state.world.navy_get_controller_from_navy_control(a) ==
state.local_player_nation) {
424 dcon::nation_id controller;
425 bool selected =
false;
426 if(std::holds_alternative<dcon::army_id>(display_unit)) {
427 controller =
state.world.army_get_controller_from_army_control(std::get<dcon::army_id>(display_unit));
428 selected =
state.is_selected(std::get<dcon::army_id>(display_unit));
429 }
else if(std::holds_alternative<dcon::navy_id>(display_unit)) {
430 controller =
state.world.navy_get_controller_from_navy_control(std::get<dcon::navy_id>(display_unit));
431 selected =
state.is_selected(std::get<dcon::navy_id>(display_unit));
436 if(selected && controller ==
state.local_player_nation) {
438 }
else if(controller ==
state.local_player_nation) {
463 return int32_t(a) < int32_t(b);
472 if(
name ==
"frame_bg") {
473 return make_element_by_type<unit_frame_bg>(
state,
id);
474 }
else if(
name ==
"org_bar") {
475 return make_element_by_type<unit_org_bar>(
state,
id);
476 }
else if(
name ==
"status") {
477 return make_element_by_type<unit_status_image>(
state,
id);
478 }
else if(
name ==
"dig_in") {
479 return make_element_by_type<unit_dig_in_pips_image>(
state,
id);
480 }
else if(
name ==
"strength") {
481 return make_element_by_type<unit_strength>(
state,
id);
482 }
else if(
name ==
"unit_2") {
483 return make_element_by_type<unit_second_most_prevalent>(
state,
id);
484 }
else if(
name ==
"unit_1") {
485 return make_element_by_type<unit_most_prevalent>(
state,
id);
486 }
else if(
name ==
"controller_flag") {
487 return make_element_by_type<unit_controller_flag>(
state,
id);
498 if(payload.holds_type<
unit_var>()) {
509 if(!std::holds_alternative<std::monostate>(
display_unit)) {
515 if(!std::holds_alternative<std::monostate>(
display_unit)) {
526 if(std::holds_alternative<std::monostate>(a))
528 if(std::holds_alternative<std::monostate>(b))
530 if(std::holds_alternative<dcon::navy_id>(a) && std::holds_alternative<dcon::army_id>(b))
532 if(std::holds_alternative<dcon::army_id>(a) && std::holds_alternative<dcon::navy_id>(b))
542 if(std::holds_alternative<dcon::army_id>(a)) {
543 auto aa = std::get<dcon::army_id>(a);
544 auto ba = std::get<dcon::army_id>(b);
545 auto aar =
state.world.army_get_army_membership(aa);
546 auto bar =
state.world.army_get_army_membership(ba);
547 auto acount = int32_t(aar.end() - aar.begin());
548 auto bcount = int32_t(bar.end() - bar.begin());
550 return acount > bcount;
551 return aa.index() < ba.index();
553 auto aa = std::get<dcon::navy_id>(a);
554 auto ba = std::get<dcon::navy_id>(b);
555 auto aar =
state.world.navy_get_navy_membership(aa);
556 auto bar =
state.world.navy_get_navy_membership(ba);
557 auto acount = int32_t(aar.end() - aar.begin());
558 auto bcount = int32_t(bar.end() - bar.begin());
560 return acount > bcount;
561 return aa.index() < ba.index();
573 auto win = make_element_by_type<base_unit_container>(
state,
state.ui_state.
defs_by_name.find(
state.lookup_key(
"alice_base_unit_icon"))->second.definition);
574 win->base_data.position.x = int16_t(3 + 67 * 0);
575 win->base_data.position.y = int16_t(3);
580 auto win = make_element_by_type<base_unit_container>(
state,
state.ui_state.
defs_by_name.find(
state.lookup_key(
"alice_base_unit_icon"))->second.definition);
581 win->base_data.position.x = int16_t(3 + 67 * 1);
582 win->base_data.position.y = int16_t(3);
587 auto win = make_element_by_type<base_unit_container>(
state,
state.ui_state.
defs_by_name.find(
state.lookup_key(
"alice_base_unit_icon"))->second.definition);
588 win->base_data.position.x = int16_t(3 + 67 * 2);
589 win->base_data.position.y = int16_t(3);
594 auto win = make_element_by_type<base_unit_container>(
state,
state.ui_state.
defs_by_name.find(
state.lookup_key(
"alice_base_unit_icon"))->second.definition);
595 win->base_data.position.x = int16_t(3 + 67 * 3);
596 win->base_data.position.y = int16_t(3);
618 return "alice_grid_row";
623 static std::vector<unit_var> base_array;
626 auto prov = retrieve<dcon::province_id>(
state,
parent);
629 if(as_port || (prov.index() >=
state.province_definitions.first_sea_province.index())) {
630 for(
auto n :
state.world.province_get_navy_location(prov)) {
631 base_array.emplace_back(n.get_navy().id);
635 for(
auto a :
state.world.province_get_army_location(prov)) {
636 if(a.get_army().get_navy_from_army_transport()) {
637 base_array.emplace_back(a.get_army().id);
640 }
else if(prov.index() >=
state.province_definitions.first_sea_province.index()) {
641 for(
auto a :
state.world.province_get_army_location(prov)) {
642 base_array.emplace_back(a.get_army().id);
645 for(
auto a :
state.world.province_get_army_location(prov)) {
646 if(!(a.get_army().get_navy_from_army_transport())) {
647 base_array.emplace_back(a.get_army().id);
651 for(
uint32_t i = 0; i < base_array.size(); i += 4) {
653 for(
uint32_t j = 0; j < 4 && (i + j) < base_array.size(); ++j) {
654 new_row[j] = base_array[i + j];
669 if(
name ==
"grid_listbox") {
670 return make_element_by_type<unit_grid_lb>(
state,
id);
677 if(payload.holds_type<dcon::province_id>()) {
680 }
else if(payload.holds_type<
bool>()) {
681 payload.emplace<
bool>(
as_port);
689 if(p.index() <
state.province_definitions.first_sea_province.index()) {
691 auto arange =
state.world.province_get_army_location(p);
692 if(int32_t(arange.end() - arange.begin()) <= 1)
695 auto arange =
state.world.province_get_army_location(p);
696 auto nrange =
state.world.province_get_navy_location(p);
697 if(int32_t(nrange.end() - nrange.begin()) <= 1 && arange.begin() == arange.end())
705 auto mx = int32_t(
state.mouse_x_position /
state.user_settings.ui_scale);
706 auto my = int32_t(
state.mouse_y_position /
state.user_settings.ui_scale);
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
virtual void impl_render(sys::state &state, int32_t x, int32_t y) noexcept
virtual void on_create(sys::state &state) noexcept
void set_visible(sys::state &state, bool vis)
virtual mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept
void open(sys::state &state, ui::xy_pair location, ui::xy_pair source_size, dcon::province_id p, bool port)
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
dcon::province_id for_province
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
std::vector< grid_row > row_contents
void update(sys::state &state)
void set_text(sys::state &state, std::string const &new_text)
mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_shift_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_create(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_update(sys::state &state) noexcept override
std::array< base_unit_container *, 4 > grid_items
void on_update(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
bool are_allied_in_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
bool will_recieve_attrition(sys::state &state, dcon::navy_id a)
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
std::string prettify(int64_t num)
std::string format_float(float num, size_t digits)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
std::array< unit_var, 4 > grid_row
bool color_less(outline_color a, outline_color b)
int32_t status_frame(sys::state &state, dcon::army_id a)
bool color_equivalent(outline_color a, outline_color b)
std::variant< std::monostate, dcon::army_id, dcon::navy_id > unit_var
outline_color to_color(sys::state &state, unit_var display_unit)
bool unit_var_ordering(sys::state &state, unit_var a, unit_var b)
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
std::unique_ptr< element_base > root
element_base * mouse_sensitive_target