8struct military_unit_info :
public std::variant<T, dcon::province_land_construction_id, dcon::province_naval_construction_id> { };
14 auto content = retrieve<military_unit_info<T>>(
state,
parent);
16 if(std::holds_alternative<dcon::province_land_construction_id>(content)) {
17 auto c = std::get<dcon::province_land_construction_id>(content);
18 auto utid =
state.world.province_land_construction_get_type(c);
19 auto unitname = utid ?
state.military_definitions.unit_base_definitions[utid].name : dcon::text_key{};
24 else if(std::holds_alternative<dcon::province_naval_construction_id>(content)) {
25 auto c = std::get<dcon::province_naval_construction_id>(content);
26 auto utid =
state.world.province_naval_construction_get_type(c);
27 auto unitname = utid ?
state.military_definitions.unit_base_definitions[utid].name : dcon::text_key{};
32 else if(std::holds_alternative<T>(content)) {
34 auto unit_name = std::string{
state.to_string_view(fat_id.get_name()) };
48 auto container = retrieve<military_unit_info<T>>(
state,
parent);
49 float admin_eff =
state.world.nation_get_administrative_efficiency(
state.local_player_nation);
50 float admin_cost_factor = 2.0f - admin_eff;
52 if(std::holds_alternative<dcon::province_land_construction_id>(container)) {
53 auto c = std::get<dcon::province_land_construction_id>(container);
55 auto&
goods =
state.military_definitions.unit_base_definitions[
state.world.province_land_construction_get_type(c)].build_cost;
56 auto& cgoods =
state.world.province_land_construction_get_purchased_goods(c);
59 float purchased = 0.0f;
62 if(
goods.commodity_type[i]) {
65 auto cid =
goods.commodity_type[i];
66 std::string padding = cid.index() < 10 ?
"0" :
"";
67 std::string description =
"@$" + padding + std::to_string(cid.index());
78 }
else if(std::holds_alternative<dcon::province_naval_construction_id>(container)) {
79 auto c = std::get<dcon::province_naval_construction_id>(container);
81 auto&
goods =
state.military_definitions.unit_base_definitions[
state.world.province_naval_construction_get_type(c)].build_cost;
82 auto& cgoods =
state.world.province_naval_construction_get_purchased_goods(c);
85 float purchased = 0.0f;
88 if(
goods.commodity_type[i]) {
91 auto cid =
goods.commodity_type[i];
92 std::string padding = cid.index() < 10 ?
"0" :
"";
93 std::string description =
"@$" + padding + std::to_string(cid.index());
141 dcon::gfx_object_id default_img;
147 auto container = retrieve<military_unit_info<T>>(
state,
parent);
148 if(!std::holds_alternative<T>(container)) {
153 auto unit = std::get<T>(container);
155 if constexpr(std::is_same_v<T, dcon::army_id>) {
156 lid =
state.world.army_get_general_from_army_leadership(unit);
158 lid =
state.world.navy_get_admiral_from_navy_leadership(unit);
161 auto pculture =
state.world.nation_get_primary_culture(
state.local_player_nation);
162 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
165 auto admiral =
state.world.leader_get_is_admiral(lid);
167 auto arange = ltype.get_admirals();
168 if(arange.size() > 0) {
174 auto grange = ltype.get_generals();
175 if(grange.size() > 0) {
187 void render(
sys::state&
state, int32_t x, int32_t y)
noexcept override {
197 auto container = retrieve<military_unit_info<T>>(
state,
parent);
198 if(!std::holds_alternative<T>(container)) {
202 auto unit = std::get<T>(container);
204 if constexpr(std::is_same_v<T, dcon::army_id>) {
205 lid =
state.world.army_get_general_from_army_leadership(unit);
207 lid =
state.world.navy_get_admiral_from_navy_leadership(unit);
221 auto info = retrieve<military_unit_info<dcon::army_id>>(
state, parent);
222 if(std::holds_alternative<dcon::province_land_construction_id>(info)) {
223 auto pc = std::get<dcon::province_land_construction_id>(info);
224 auto pop =
state.world.province_land_construction_get_pop(pc);
229 auto info = retrieve<military_unit_info<dcon::army_id>>(
state, parent);
230 if(std::holds_alternative<dcon::province_land_construction_id>(info)) {
231 auto pc = std::get<dcon::province_land_construction_id>(info);
232 auto pop =
state.world.province_land_construction_get_pop(pc);
242 auto info = retrieve<military_unit_info<dcon::navy_id>>(
state, parent);
243 if(std::holds_alternative<dcon::province_naval_construction_id>(info)) {
244 auto pc = std::get<dcon::province_naval_construction_id>(info);
245 auto loc =
state.world.province_naval_construction_get_province(pc);
246 auto type =
state.world.province_naval_construction_get_type(pc);
251 auto info = retrieve<military_unit_info<dcon::navy_id>>(
state, parent);
252 if(std::holds_alternative<dcon::province_naval_construction_id>(info)) {
253 auto pc = std::get<dcon::province_naval_construction_id>(info);
254 auto loc =
state.world.province_naval_construction_get_province(pc);
255 auto type =
state.world.province_naval_construction_get_type(pc);
265 auto container = retrieve<military_unit_info<T>>(
state,
parent);
272 auto container = retrieve<military_unit_info<T>>(
state,
parent);
273 if(std::holds_alternative<T>(container)) {
274 T
id = std::get<T>(container);
275 state.selected_armies.clear();
276 state.selected_navies.clear();
278 if constexpr(std::is_same_v<T, dcon::army_id>) {
279 state.map_state.center_map_on_province(
state,
state.world.army_get_location_from_army_location(
id));
281 state.map_state.center_map_on_province(
state,
state.world.navy_get_location_from_navy_location(
id));
308 if(
name ==
"military_unit_entry_bg") {
309 return make_element_by_type<mil_goto_background_button<T>>(
state, id);
310 }
else if(
name ==
"unit_progress") {
311 auto ptr = make_element_by_type<military_unit_building_progress_bar<T>>(
state, id);
312 unit_building_progress = ptr.
get();
314 }
else if(
name ==
"leader") {
315 auto ptr = make_element_by_type<leader_in_army_img<T>>(
state, id);
316 leader_icon = ptr.
get();
318 }
else if(
name ==
"unit_strip") {
319 auto ptr = make_element_by_type<image_element_base>(
state,
id);
320 unit_icon = ptr.
get();
322 }
else if(
name ==
"name") {
323 auto ptr = make_element_by_type<military_unit_name_text<T>>(
state, id);
324 unit_name = ptr.
get();
326 }
else if(
name ==
"location") {
327 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(
state, id);
328 location_text = ptr.
get();
331 else if(
name ==
"unit_eta") {
332 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
333 eta_date_text = ptr.
get();
335 }
else if(
name ==
"military_cancel_unit") {
336 auto ptr = make_element_by_type<cancel_unit_construction_button<T>>(
state, id);
337 cancel_button = ptr.
get();
339 }
else if(
name ==
"regiments") {
340 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
341 unit_regiments_text = ptr.
get();
343 }
else if(
name ==
"men") {
344 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
345 unit_men_text = ptr.
get();
347 }
else if(
name ==
"morale_progress") {
348 auto ptr = make_element_by_type<military_unit_morale_progress_bar>(
state,
id);
349 unit_morale_progress = ptr.
get();
351 }
else if(
name ==
"strength_progress") {
352 auto ptr = make_element_by_type<military_unit_strength_progress_bar>(
state,
id);
353 unit_strength_progress = ptr.
get();
355 }
else if(
name ==
"moving") {
356 auto ptr = make_element_by_type<image_element_base>(
state,
id);
357 unit_moving_icon = ptr.
get();
359 }
else if(
name ==
"digin") {
360 auto ptr = make_element_by_type<image_element_base>(
state,
id);
361 unit_digin_icon = ptr.
get();
363 }
else if(
name ==
"combat") {
364 auto ptr = make_element_by_type<image_element_base>(
state,
id);
365 unit_combat_icon = ptr.
get();
375 bool is_building = !std::holds_alternative<T>(
content);
376 bool is_moving =
false;
377 bool is_digin =
false;
378 bool is_combat =
false;
381 if(std::holds_alternative<dcon::province_land_construction_id>(
content)) {
382 auto c = std::get<dcon::province_land_construction_id>(
content);
383 if(unit_icon) unit_icon->
frame =
state.military_definitions.unit_base_definitions[
state.world.province_land_construction_get_type(c)].icon - 1;
385 }
else if(std::holds_alternative<dcon::province_naval_construction_id>(
content)) {
386 auto c = std::get<dcon::province_naval_construction_id>(
content);
387 if(unit_icon) unit_icon->
frame =
state.military_definitions.unit_base_definitions[
state.world.province_naval_construction_get_type(c)].icon - 1;
393 auto full_strength = 0.f;
395 if constexpr(std::is_same_v<T, dcon::army_id>) {
396 state.world.army_for_each_army_membership_as_army(std::get<dcon::army_id>(
content), [&](dcon::army_membership_id amid) {
397 auto rid =
state.world.army_membership_get_regiment(amid);
398 full_strength += 1.f *
state.defines.pop_size_per_regiment;
399 strength +=
state.world.regiment_get_strength(rid) *
state.defines.pop_size_per_regiment;
404 if constexpr(std::is_same_v<T, dcon::navy_id>) {
405 state.world.navy_for_each_navy_membership_as_navy(std::get<dcon::navy_id>(
content), [&](dcon::navy_membership_id nmid) {
406 auto sid =
state.world.navy_membership_get_ship(nmid);
407 full_strength += 1.f;
408 strength +=
state.world.ship_get_strength(sid);
412 if(unit_strength_progress) unit_strength_progress->
progress = (full_strength != 0.0f) ? strength / full_strength : 0.f;
414 if(unit_regiments_text) unit_regiments_text->
set_text(
state, std::to_string(regiments));
422 if(unit_building_progress) unit_building_progress->
set_visible(
state, is_building);
426 if(unit_regiments_text) unit_regiments_text->
set_visible(
state, !is_building);
428 if(unit_morale_progress) unit_morale_progress->
set_visible(
state, !is_building);
429 if(unit_strength_progress) unit_strength_progress->
set_visible(
state, !is_building);
430 if(unit_moving_icon) unit_moving_icon->
set_visible(
state, !is_building && is_moving);
431 if(unit_digin_icon) unit_digin_icon->
set_visible(
state, !is_building && is_digin);
432 if(unit_combat_icon) unit_combat_icon->
set_visible(
state, !is_building && is_combat);
438 if(payload.holds_type<dcon::province_id>()) {
439 dcon::province_id p{};
440 if(std::holds_alternative<dcon::province_land_construction_id>(
content)) {
441 auto c = std::get<dcon::province_land_construction_id>(
content);
442 p =
state.world.pop_location_get_province(
443 state.world.pop_get_pop_location_as_pop(
state.world.province_land_construction_get_pop(c)));
444 }
else if(std::holds_alternative<dcon::province_naval_construction_id>(
content)) {
445 auto c = std::get<dcon::province_naval_construction_id>(
content);
446 p =
state.world.province_naval_construction_get_province(c);
448 payload.emplace<dcon::province_id>(p);
469 dcon::nation_id n = Cyto::any_cast<dcon::nation_id>(payload);
471 if constexpr(std::is_same_v<T, dcon::army_id>) {
472 state.world.nation_for_each_army_control_as_controller(n, [&](dcon::army_control_id acid) {
473 auto aid =
state.world.army_control_get_army(acid);
476 state.world.nation_for_each_province_land_construction_as_nation(n,
480 if constexpr(std::is_same_v<T, dcon::navy_id>) {
481 state.world.nation_for_each_navy_control_as_controller(n, [&](dcon::navy_control_id ncid) {
482 auto nid =
state.world.navy_control_get_navy(ncid);
485 state.world.nation_for_each_province_naval_construction_as_nation(n,
516 if constexpr(std::is_same_v<T, dcon::army_id>) {
518 }
else if constexpr(std::is_same_v<T, dcon::navy_id>) {
525 if(
state.world.nation_get_disarmed_until(
state.local_player_nation) &&
state.current_date <
state.world.nation_get_disarmed_until(
state.local_player_nation)) {
529 dcon::unit_type_id utid = dcon::unit_type_id{ 0 };
533 for(
auto const& ubd :
state.military_definitions.unit_base_definitions) {
534 if(
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].is_land) {
535 if(!
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].primary_culture) {
536 if(
state.world.nation_get_active_unit(
state.local_player_nation, dcon::unit_type_id{ unit_def_count }) ||
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].active) {
543 utid = dcon::unit_type_id{ unit_def_count };
544 if constexpr(std::is_same_v<T, dcon::army_id>) {
545 for(
auto ucon :
state.world.nation_get_province_land_construction(
state.local_player_nation)) {
553 for(
auto po :
state.world.nation_get_province_ownership_as_nation(
state.local_player_nation)) {
554 auto p = po.get_province();
555 state.world.for_each_culture([&](dcon::culture_id c) {
570 utid = dcon::unit_type_id{ 0 };
573 for(
auto const& ubd :
state.military_definitions.unit_base_definitions) {
574 if(!
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].is_land) {
575 if(
state.world.nation_get_active_unit(
state.local_player_nation, dcon::unit_type_id{ unit_def_count }) ||
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].active) {
576 utid = dcon::unit_type_id{ unit_def_count };
577 for(
auto po :
state.world.nation_get_province_ownership_as_nation(
state.local_player_nation)) {
578 auto p = po.get_province();
599 return tooltip_behavior::variable_tooltip;
602 auto rng =
state.world.nation_get_army_control(
state.local_player_nation);
608 auto rng =
state.world.nation_get_army_control(
state.local_player_nation);
618 return tooltip_behavior::variable_tooltip;
621 auto rng =
state.world.nation_get_navy_control(
state.local_player_nation);
626 auto rng =
state.world.nation_get_navy_control(
state.local_player_nation);
636 auto cstr_range =
state.world.nation_get_province_land_construction(
state.local_player_nation);
637 set_text(
state, std::to_string(cstr_range.end() - cstr_range.begin()));
644 auto cstr_range =
state.world.nation_get_province_naval_construction(
state.local_player_nation);
645 set_text(
state, std::to_string(cstr_range.end() - cstr_range.begin()));
652 return tooltip_behavior::variable_tooltip;
665 return tooltip_behavior::variable_tooltip;
681 if(
name ==
"current_count") {
682 if constexpr(std::is_same_v<T, dcon::army_id>) {
683 return make_element_by_type<military_armies_text>(
state,
id);
685 return make_element_by_type<military_navies_text>(
state,
id);
687 }
else if(
name ==
"under_construction") {
688 if constexpr(std::is_same_v<T, dcon::army_id>) {
689 return make_element_by_type<military_armies_construction_text>(
state,
id);
691 return make_element_by_type<military_navies_construction_text>(
state,
id);
693 }
else if(
name ==
"cut_down_to_size") {
694 auto ptr = make_element_by_type<image_element_base>(
state,
id);
695 ptr->set_visible(
state,
false);
696 cdts_icon = ptr.
get();
698 }
else if(
name ==
"sort_name") {
699 return make_element_by_type<military_units_sortby_name>(
state,
id);
700 }
else if(
name ==
"sort_strength") {
701 return make_element_by_type<military_units_sortby_strength>(
state,
id);
702 }
else if(
name ==
"build_new") {
703 auto ptr = make_element_by_type<build_unit_button<T>>(
state, id);
704 if constexpr(std::is_same_v<T, dcon::army_id>) {
710 }
else if(
name ==
"unit_listbox") {
711 return make_element_by_type<military_units_listbox<T>>(
state, id);
virtual message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
void render(sys::state &state, int32_t x, int32_t y) noexcept override
std::vector< military_unit_info< T > > row_contents
void update(sys::state &state)
military_unit_info< T > content
void on_update(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void set_text(sys::state &state, std::string const &new_text)
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)
bool can_cancel_land_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type)
bool can_cancel_naval_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type)
@ cancel_land_unit_construction
@ cancel_naval_unit_construction
bool can_start_naval_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
float unit_construction_progress(sys::state &state, dcon::province_land_construction_id c)
uint32_t reduce(uint32_t value_in, uint32_t upper_bound)
uint64_t get_random(sys::state const &state, uint32_t value_in)
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
layout_box open_layout_box(layout_base &dest, int32_t indent)
void add_unparsed_text_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view sv, substitution_map const &mp)
void localised_single_sub_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, variable_type subkey, substitution value)
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
std::string prettify(int64_t num)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
void close_layout_box(columnar_layout &dest, layout_box &box)
void display_leader_full(sys::state &state, dcon::leader_id lid, text::layout_base &contents, int32_t indent)
static constexpr uint32_t set_size
Holds important data about the game world, state, and other data regarding windowing,...
union ui::element_data::internal_data data
dcon::gfx_object_id gfx_object
element_base * military_subwindow
element_base * unit_window_army
element_base * unit_window_navy
std::unique_ptr< element_base > root
element_base * build_unit_window