Project Alice
Loading...
Searching...
No Matches
unit_tooltip.cpp
Go to the documentation of this file.
1#include "system_state.hpp"
2#include "unit_tooltip.hpp"
3#include "ai.hpp"
4
5namespace ui {
6
8 unitamounts amounts;
9 for(auto n : army.get_army_membership()) {
10 dcon::unit_type_id utid = n.get_regiment().get_type();
11 auto result = state.military_definitions.unit_base_definitions[utid].type;
12 if(result == military::unit_type::infantry) {
13 amounts.type1++;
14 } else
15 if(result == military::unit_type::cavalry) {
16 amounts.type2++;
17 } else
19 amounts.type3++;
20 }
21 }
22 return amounts;
23}
24
26 unitamounts amounts;
27 for(auto n : navy.get_navy_membership()) {
28 dcon::unit_type_id utid = n.get_ship().get_type();
29 auto result = state.military_definitions.unit_base_definitions[utid].type;
30 if(result == military::unit_type::big_ship) {
31 amounts.type1++;
32 } else
34 amounts.type2++;
35 } else
36 if(result == military::unit_type::transport) {
37 amounts.type3++;
38 }
39 }
40 return amounts;
41}
42
43void single_unit_tooltip(sys::state& state, text::columnar_layout& contents, dcon::army_id a) {
44 auto army = dcon::fatten(state.world, a);
46
47 auto controller = army.get_controller_from_army_control();
48 if(!controller) {
49 controller = dcon::fatten(state.world, state.world.national_identity_get_nation_from_identity_holder(state.national_definitions.rebel_id));
50 }
51
52 float total_cost = 0.f;
53 for(const auto memb : army.get_army_membership()) {
54 auto type = state.world.regiment_get_type(memb.get_regiment());
55 auto o_sc_mod = std::max(0.01f, state.world.nation_get_modifier_values(controller, sys::national_mod_offsets::supply_consumption) + 1.0f);
56 auto& supply_cost = state.military_definitions.unit_base_definitions[type].supply_cost;
57 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
58 if(supply_cost.commodity_type[i]) {
59 float cost = state.world.commodity_get_cost(supply_cost.commodity_type[i]);
60 float amount = supply_cost.commodity_amounts[i] * state.world.nation_get_unit_stats(controller, type).supply_consumption * o_sc_mod;
61 total_cost += cost * amount;
62 } else {
63 break;
64 }
65 }
66 }
67
69 text::add_to_substitution_map(sub, text::variable_type::m, std::string_view{ "@(A)" });
76 if(army.get_arrival_time()) {
77 text::add_to_substitution_map(sub, text::variable_type::prov, *(army.get_path().end() - 1));
78 text::add_to_substitution_map(sub, text::variable_type::date, army.get_arrival_time());
79 auto box = text::open_layout_box(contents);
80 text::add_to_layout_box(state, contents, box, text::embedded_flag{ controller.get_identity_from_identity_holder().id } );
81 auto resolved = text::resolve_string_substitution(state, "unit_moving_text", sub);
82 text::add_unparsed_text_to_layout_box(state, contents, box, resolved);
83 text::close_layout_box(contents, box);
84 } else {
85 auto box = text::open_layout_box(contents);
86 text::add_to_layout_box(state, contents, box, text::embedded_flag{ controller.get_identity_from_identity_holder().id });
87 auto resolved = text::resolve_string_substitution(state, "unit_standing_text", sub);
88 text::add_unparsed_text_to_layout_box(state, contents, box, resolved);
89 text::close_layout_box(contents, box);
90 }
91}
92
93void single_unit_tooltip(sys::state& state, text::columnar_layout& contents, dcon::navy_id n) {
94 auto navy = dcon::fatten(state.world, n);
96
97 auto controller = navy.get_controller_from_navy_control();
98 if(!controller) {
99 controller = dcon::fatten(state.world, state.world.national_identity_get_nation_from_identity_holder(state.national_definitions.rebel_id));
100 }
101
102 float total_cost = 0.f;
103 for(const auto memb : navy.get_navy_membership()) {
104 auto type = state.world.ship_get_type(memb.get_ship());
105 auto o_sc_mod = std::max(0.01f, state.world.nation_get_modifier_values(controller, sys::national_mod_offsets::supply_consumption) + 1.0f);
106 auto& supply_cost = state.military_definitions.unit_base_definitions[type].supply_cost;
107 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
108 if(supply_cost.commodity_type[i]) {
109 float cost = state.world.commodity_get_cost(supply_cost.commodity_type[i]);
110 float amount = supply_cost.commodity_amounts[i] * state.world.nation_get_unit_stats(controller, type).supply_consumption * o_sc_mod;
111 total_cost += cost * amount;
112 } else {
113 break;
114 }
115 }
116 }
117
119 text::add_to_substitution_map(sub, text::variable_type::m, std::string_view{ "@(N)" });
126 if(navy.get_arrival_time()) {
127 text::add_to_substitution_map(sub, text::variable_type::prov, *(navy.get_path().end() - 1));
128 text::add_to_substitution_map(sub, text::variable_type::date, navy.get_arrival_time());
129 auto box = text::open_layout_box(contents);
130 text::add_to_layout_box(state, contents, box, text::embedded_flag{ controller.get_identity_from_identity_holder().id });
131 auto resolved = text::resolve_string_substitution(state, "unit_moving_text", sub);
132 text::add_unparsed_text_to_layout_box(state, contents, box, resolved);
133 text::close_layout_box(contents, box);
134 } else {
135 auto box = text::open_layout_box(contents);
136 text::add_to_layout_box(state, contents, box, text::embedded_flag{ controller.get_identity_from_identity_holder().id });
137 auto resolved = text::resolve_string_substitution(state, "unit_standing_text", sub);
138 text::add_unparsed_text_to_layout_box(state, contents, box, resolved);
139 text::close_layout_box(contents, box);
140 }
141}
142
143void populate_armies(sys::state& state, text::columnar_layout& contents, dcon::province_id prov) {
144 auto fat = dcon::fatten(state.world, prov);
145 for(auto armyloc : fat.get_army_location()) {
146 auto army = armyloc.get_army();
147 single_unit_tooltip(state, contents, army);
148 }
149}
150
151void populate_navies(sys::state& state, text::columnar_layout& contents, dcon::province_id prov) {
152 auto fat = dcon::fatten(state.world, prov);
153 for(auto navyloc : fat.get_navy_location()) {
154 auto navy = navyloc.get_navy();
155 single_unit_tooltip(state, contents, navy);
156 }
157}
158
159void populate_unit_tooltip(sys::state& state, text::columnar_layout& contents, dcon::province_id prov) {
160 populate_armies(state, contents, prov);
161 populate_navies(state, contents, prov);
162}
163
164}
float estimate_army_offensive_strength(sys::state &state, dcon::army_id a)
Definition: ai.cpp:4459
float estimate_army_defensive_strength(sys::state &state, dcon::army_id a)
Definition: ai.cpp:4428
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
Definition: text.cpp:2113
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void add_unparsed_text_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view sv, substitution_map const &mp)
Definition: text.cpp:1601
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:794
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
unitamounts calc_amounts_from_navy(sys::state &state, dcon::navy_fat_id navy)
void populate_navies(sys::state &state, text::columnar_layout &contents, dcon::province_id prov)
unitamounts calc_amounts_from_army(sys::state &state, dcon::army_fat_id army)
Definition: unit_tooltip.cpp:7
void populate_unit_tooltip(sys::state &state, text::columnar_layout &contents, dcon::province_id prov)
void populate_armies(sys::state &state, text::columnar_layout &contents, dcon::province_id prov)
void single_unit_tooltip(sys::state &state, text::columnar_layout &contents, dcon::army_id a)
uint uint32_t
static constexpr uint32_t set_size