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]) {
72 }
else if(std::holds_alternative<dcon::province_naval_construction_id>(container)) {
73 auto c = std::get<dcon::province_naval_construction_id>(container);
75 auto&
goods =
state.military_definitions.unit_base_definitions[
state.world.province_naval_construction_get_type(c)].build_cost;
76 auto& cgoods =
state.world.province_naval_construction_get_purchased_goods(c);
79 float purchased = 0.0f;
82 if(
goods.commodity_type[i]) {
129 dcon::gfx_object_id default_img;
135 auto container = retrieve<military_unit_info<T>>(
state,
parent);
136 if(!std::holds_alternative<T>(container)) {
141 auto unit = std::get<T>(container);
143 if constexpr(std::is_same_v<T, dcon::army_id>) {
144 lid =
state.world.army_get_general_from_army_leadership(unit);
146 lid =
state.world.navy_get_admiral_from_navy_leadership(unit);
149 auto pculture =
state.world.nation_get_primary_culture(
state.local_player_nation);
150 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
153 auto admiral =
state.world.leader_get_is_admiral(lid);
155 auto arange = ltype.get_admirals();
156 if(arange.size() > 0) {
162 auto grange = ltype.get_generals();
163 if(grange.size() > 0) {
175 void render(
sys::state&
state, int32_t x, int32_t y)
noexcept override {
185 auto container = retrieve<military_unit_info<T>>(
state,
parent);
186 if(!std::holds_alternative<T>(container)) {
190 auto unit = std::get<T>(container);
192 if constexpr(std::is_same_v<T, dcon::army_id>) {
193 lid =
state.world.army_get_general_from_army_leadership(unit);
195 lid =
state.world.navy_get_admiral_from_navy_leadership(unit);
209 auto info = retrieve<military_unit_info<dcon::army_id>>(
state, parent);
210 if(std::holds_alternative<dcon::province_land_construction_id>(info)) {
211 auto pc = std::get<dcon::province_land_construction_id>(info);
212 auto pop =
state.world.province_land_construction_get_pop(pc);
217 auto info = retrieve<military_unit_info<dcon::army_id>>(
state, parent);
218 if(std::holds_alternative<dcon::province_land_construction_id>(info)) {
219 auto pc = std::get<dcon::province_land_construction_id>(info);
220 auto pop =
state.world.province_land_construction_get_pop(pc);
230 auto info = retrieve<military_unit_info<dcon::navy_id>>(
state, parent);
231 if(std::holds_alternative<dcon::province_naval_construction_id>(info)) {
232 auto pc = std::get<dcon::province_naval_construction_id>(info);
233 auto loc =
state.world.province_naval_construction_get_province(pc);
234 auto type =
state.world.province_naval_construction_get_type(pc);
239 auto info = retrieve<military_unit_info<dcon::navy_id>>(
state, parent);
240 if(std::holds_alternative<dcon::province_naval_construction_id>(info)) {
241 auto pc = std::get<dcon::province_naval_construction_id>(info);
242 auto loc =
state.world.province_naval_construction_get_province(pc);
243 auto type =
state.world.province_naval_construction_get_type(pc);
253 auto container = retrieve<military_unit_info<T>>(
state,
parent);
260 auto container = retrieve<military_unit_info<T>>(
state,
parent);
261 if(std::holds_alternative<T>(container)) {
262 T
id = std::get<T>(container);
263 state.selected_armies.clear();
264 state.selected_navies.clear();
266 if constexpr(std::is_same_v<T, dcon::army_id>) {
267 state.map_state.center_map_on_province(
state,
state.world.army_get_location_from_army_location(
id));
269 state.map_state.center_map_on_province(
state,
state.world.navy_get_location_from_navy_location(
id));
296 if(
name ==
"military_unit_entry_bg") {
297 return make_element_by_type<mil_goto_background_button<T>>(
state, id);
298 }
else if(
name ==
"unit_progress") {
299 auto ptr = make_element_by_type<military_unit_building_progress_bar<T>>(
state, id);
300 unit_building_progress = ptr.
get();
302 }
else if(
name ==
"leader") {
303 auto ptr = make_element_by_type<leader_in_army_img<T>>(
state, id);
304 leader_icon = ptr.
get();
306 }
else if(
name ==
"unit_strip") {
307 auto ptr = make_element_by_type<image_element_base>(
state,
id);
308 unit_icon = ptr.
get();
310 }
else if(
name ==
"name") {
311 auto ptr = make_element_by_type<military_unit_name_text<T>>(
state, id);
312 unit_name = ptr.
get();
314 }
else if(
name ==
"location") {
315 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(
state, id);
316 location_text = ptr.
get();
319 else if(
name ==
"unit_eta") {
320 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
321 eta_date_text = ptr.
get();
323 }
else if(
name ==
"military_cancel_unit") {
324 auto ptr = make_element_by_type<cancel_unit_construction_button<T>>(
state, id);
325 cancel_button = ptr.
get();
327 }
else if(
name ==
"regiments") {
328 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
329 unit_regiments_text = ptr.
get();
331 }
else if(
name ==
"men") {
332 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
333 unit_men_text = ptr.
get();
335 }
else if(
name ==
"morale_progress") {
336 auto ptr = make_element_by_type<military_unit_morale_progress_bar>(
state,
id);
337 unit_morale_progress = ptr.
get();
339 }
else if(
name ==
"strength_progress") {
340 auto ptr = make_element_by_type<military_unit_strength_progress_bar>(
state,
id);
341 unit_strength_progress = ptr.
get();
343 }
else if(
name ==
"moving") {
344 auto ptr = make_element_by_type<image_element_base>(
state,
id);
345 unit_moving_icon = ptr.
get();
347 }
else if(
name ==
"digin") {
348 auto ptr = make_element_by_type<image_element_base>(
state,
id);
349 unit_digin_icon = ptr.
get();
351 }
else if(
name ==
"combat") {
352 auto ptr = make_element_by_type<image_element_base>(
state,
id);
353 unit_combat_icon = ptr.
get();
363 bool is_building = !std::holds_alternative<T>(
content);
364 bool is_moving =
false;
365 bool is_digin =
false;
366 bool is_combat =
false;
369 if(std::holds_alternative<dcon::province_land_construction_id>(
content)) {
370 auto c = std::get<dcon::province_land_construction_id>(
content);
371 if(unit_icon) unit_icon->
frame =
state.military_definitions.unit_base_definitions[
state.world.province_land_construction_get_type(c)].icon - 1;
373 }
else if(std::holds_alternative<dcon::province_naval_construction_id>(
content)) {
374 auto c = std::get<dcon::province_naval_construction_id>(
content);
375 if(unit_icon) unit_icon->
frame =
state.military_definitions.unit_base_definitions[
state.world.province_naval_construction_get_type(c)].icon - 1;
381 auto full_strength = 0.f;
383 if constexpr(std::is_same_v<T, dcon::army_id>) {
384 state.world.army_for_each_army_membership_as_army(std::get<dcon::army_id>(
content), [&](dcon::army_membership_id amid) {
385 auto rid =
state.world.army_membership_get_regiment(amid);
386 full_strength += 1.f *
state.defines.pop_size_per_regiment;
387 strength +=
state.world.regiment_get_strength(rid) *
state.defines.pop_size_per_regiment;
392 if constexpr(std::is_same_v<T, dcon::navy_id>) {
393 state.world.navy_for_each_navy_membership_as_navy(std::get<dcon::navy_id>(
content), [&](dcon::navy_membership_id nmid) {
394 auto sid =
state.world.navy_membership_get_ship(nmid);
395 full_strength += 1.f;
396 strength +=
state.world.ship_get_strength(sid);
400 if(unit_strength_progress) unit_strength_progress->
progress = (full_strength != 0.0f) ? strength / full_strength : 0.f;
402 if(unit_regiments_text) unit_regiments_text->
set_text(
state, std::to_string(regiments));
410 if(unit_building_progress) unit_building_progress->
set_visible(
state, is_building);
414 if(unit_regiments_text) unit_regiments_text->
set_visible(
state, !is_building);
416 if(unit_morale_progress) unit_morale_progress->
set_visible(
state, !is_building);
417 if(unit_strength_progress) unit_strength_progress->
set_visible(
state, !is_building);
418 if(unit_moving_icon) unit_moving_icon->
set_visible(
state, !is_building && is_moving);
419 if(unit_digin_icon) unit_digin_icon->
set_visible(
state, !is_building && is_digin);
420 if(unit_combat_icon) unit_combat_icon->
set_visible(
state, !is_building && is_combat);
426 if(payload.holds_type<dcon::province_id>()) {
427 dcon::province_id p{};
428 if(std::holds_alternative<dcon::province_land_construction_id>(
content)) {
429 auto c = std::get<dcon::province_land_construction_id>(
content);
430 p =
state.world.pop_location_get_province(
431 state.world.pop_get_pop_location_as_pop(
state.world.province_land_construction_get_pop(c)));
432 }
else if(std::holds_alternative<dcon::province_naval_construction_id>(
content)) {
433 auto c = std::get<dcon::province_naval_construction_id>(
content);
434 p =
state.world.province_naval_construction_get_province(c);
436 payload.emplace<dcon::province_id>(p);
457 dcon::nation_id n = Cyto::any_cast<dcon::nation_id>(payload);
459 if constexpr(std::is_same_v<T, dcon::army_id>) {
460 state.world.nation_for_each_army_control_as_controller(n, [&](dcon::army_control_id acid) {
461 auto aid =
state.world.army_control_get_army(acid);
464 state.world.nation_for_each_province_land_construction_as_nation(n,
468 if constexpr(std::is_same_v<T, dcon::navy_id>) {
469 state.world.nation_for_each_navy_control_as_controller(n, [&](dcon::navy_control_id ncid) {
470 auto nid =
state.world.navy_control_get_navy(ncid);
473 state.world.nation_for_each_province_naval_construction_as_nation(n,
504 if constexpr(std::is_same_v<T, dcon::army_id>) {
506 }
else if constexpr(std::is_same_v<T, dcon::navy_id>) {
513 if(
state.world.nation_get_disarmed_until(
state.local_player_nation) &&
state.current_date <
state.world.nation_get_disarmed_until(
state.local_player_nation)) {
517 dcon::unit_type_id utid = dcon::unit_type_id{ 0 };
521 for(
auto const& ubd :
state.military_definitions.unit_base_definitions) {
522 if(
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].is_land) {
523 if(!
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].primary_culture) {
524 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) {
531 utid = dcon::unit_type_id{ unit_def_count };
532 if constexpr(std::is_same_v<T, dcon::army_id>) {
533 for(
auto ucon :
state.world.nation_get_province_land_construction(
state.local_player_nation)) {
541 for(
auto po :
state.world.nation_get_province_ownership_as_nation(
state.local_player_nation)) {
542 auto p = po.get_province();
543 state.world.for_each_culture([&](dcon::culture_id c) {
558 utid = dcon::unit_type_id{ 0 };
561 for(
auto const& ubd :
state.military_definitions.unit_base_definitions) {
562 if(!
state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].is_land) {
563 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) {
564 utid = dcon::unit_type_id{ unit_def_count };
565 for(
auto po :
state.world.nation_get_province_ownership_as_nation(
state.local_player_nation)) {
566 auto p = po.get_province();
587 return tooltip_behavior::variable_tooltip;
590 auto rng =
state.world.nation_get_army_control(
state.local_player_nation);
596 auto rng =
state.world.nation_get_army_control(
state.local_player_nation);
606 return tooltip_behavior::variable_tooltip;
609 auto rng =
state.world.nation_get_navy_control(
state.local_player_nation);
614 auto rng =
state.world.nation_get_navy_control(
state.local_player_nation);
624 auto cstr_range =
state.world.nation_get_province_land_construction(
state.local_player_nation);
625 set_text(
state, std::to_string(cstr_range.end() - cstr_range.begin()));
632 auto cstr_range =
state.world.nation_get_province_naval_construction(
state.local_player_nation);
633 set_text(
state, std::to_string(cstr_range.end() - cstr_range.begin()));
640 return tooltip_behavior::variable_tooltip;
653 return tooltip_behavior::variable_tooltip;
669 if(
name ==
"current_count") {
670 if constexpr(std::is_same_v<T, dcon::army_id>) {
671 return make_element_by_type<military_armies_text>(
state,
id);
673 return make_element_by_type<military_navies_text>(
state,
id);
675 }
else if(
name ==
"under_construction") {
676 if constexpr(std::is_same_v<T, dcon::army_id>) {
677 return make_element_by_type<military_armies_construction_text>(
state,
id);
679 return make_element_by_type<military_navies_construction_text>(
state,
id);
681 }
else if(
name ==
"cut_down_to_size") {
682 auto ptr = make_element_by_type<image_element_base>(
state,
id);
683 ptr->set_visible(
state,
false);
684 cdts_icon = ptr.
get();
686 }
else if(
name ==
"sort_name") {
687 return make_element_by_type<military_units_sortby_name>(
state,
id);
688 }
else if(
name ==
"sort_strength") {
689 return make_element_by_type<military_units_sortby_strength>(
state,
id);
690 }
else if(
name ==
"build_new") {
691 auto ptr = make_element_by_type<build_unit_button<T>>(
state, id);
692 if constexpr(std::is_same_v<T, dcon::army_id>) {
698 }
else if(
name ==
"unit_listbox") {
699 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 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
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