Project Alice
Loading...
Searching...
No Matches
gui_province_window.cpp
Go to the documentation of this file.
2
3namespace ui {
4
5void province_owner_rgo_draw_tooltip(sys::state& state, text::columnar_layout& contents, dcon::province_id prov_id) noexcept {
6 auto rgo_good = state.world.province_get_rgo(prov_id);
7 auto nat_id = state.world.province_get_nation_from_province_ownership(prov_id);
8
9 state.world.for_each_commodity([&](dcon::commodity_id c) {
10 auto production = province::rgo_production_quantity(state, prov_id, c);
11 auto profit = state.world.province_get_rgo_profit_per_good(prov_id, c);
12
13 if(production < 0.0001f) {
14 return;
15 }
16
17 auto base_box = text::open_layout_box(contents);
18 auto name_box = base_box;
19 name_box.x_size = 75;
20 auto production_box = base_box;
21 production_box.x_position += 90.f;
22
23 auto profit_box = base_box;
24 profit_box.x_position += 180.f;
25
27 text::add_to_layout_box(state, contents, production_box, text::fp_two_places{ production });
29 text::add_to_layout_box(state, contents, base_box, std::string(" "));
30 text::close_layout_box(contents, base_box);
31 });
32
33 if(rgo_good) {
34
35 text::add_line(state, contents, "provinceview_goodsincome", text::variable_type::goods, rgo_good.get_name(), text::variable_type::value,
36 text::fp_three_places{ province::rgo_income(state, prov_id) });
37
38 {
39 auto box = text::open_layout_box(contents, 0);
41 auto const production = province::rgo_production_quantity(state, prov_id, rgo_good);
42
44 text::localised_format_box(state, contents, box, std::string_view("production_output_goods_tooltip2"), sub_map);
45 text::localised_format_box(state, contents, box, std::string_view("production_output_explanation"));
46 text::close_layout_box(contents, box);
47 }
48
50
51 {
52 auto const production = province::rgo_production_quantity(state, prov_id, rgo_good);
53 auto const base_size = economy::rgo_effective_size(state, nat_id, prov_id, rgo_good) * state.world.commodity_get_rgo_amount(rgo_good);
54 text::add_line(state, contents, std::string_view("production_base_output_goods_tooltip"), text::variable_type::base, text::fp_two_places{ base_size });
55 }
56
57 {
58 auto box = text::open_layout_box(contents, 0);
59 bool const is_mine = state.world.commodity_get_is_mine(rgo_good);
60 auto const efficiency = 1.0f +
61 state.world.province_get_modifier_values(prov_id,
62 is_mine ? sys::provincial_mod_offsets::mine_rgo_eff : sys::provincial_mod_offsets::farm_rgo_eff) +
63 state.world.nation_get_modifier_values(nat_id,
64 is_mine ? sys::national_mod_offsets::mine_rgo_eff : sys::national_mod_offsets::farm_rgo_eff);
65 text::localised_format_box(state, contents, box, std::string_view("production_output_efficiency_tooltip"));
66 text::add_to_layout_box(state, contents, box, text::fp_percentage{ efficiency }, efficiency >= 0.0f ? text::text_color::green : text::text_color::red);
67 text::close_layout_box(contents, box);
68 }
69
71
72 {
73 auto box = text::open_layout_box(contents, 0);
74 auto const throughput = state.world.province_get_rgo_employment(prov_id);
75 text::localised_format_box(state, contents, box, std::string_view("production_throughput_efficiency_tooltip"));
76 text::add_to_layout_box(state, contents, box, text::fp_percentage{ throughput }, throughput >= 0.0f ? text::text_color::green : text::text_color::red);
77
78 text::close_layout_box(contents, box);
79 }
80 }
81}
82
84 auto province_window = static_cast<province_view_window*>(state.ui_state.province_window);
85 province_window->nf_win->set_visible(state, !province_window->nf_win->is_visible());
86}
87
88float trade_route_profit(sys::state& state, dcon::trade_route_id route, dcon::commodity_id c) {
89 auto current_volume = state.world.trade_route_get_volume(route, c);
90 auto A = state.world.trade_route_get_connected_markets(route, 0);
91 auto B = state.world.trade_route_get_connected_markets(route, 1);
92
93 auto absolute_volume = std::abs(current_volume);
94 //auto sat = state.world.market_get_direct_demand_satisfaction(origin, c);
95
96 auto s_A = state.world.market_get_zone_from_local_market(A);
97 auto s_B = state.world.market_get_zone_from_local_market(B);
98
99 if(A == B) {
100 return 0.f;
101 }
102
103 auto n_A = state.world.state_instance_get_nation_from_state_ownership(s_A);
104 auto n_B = state.world.state_instance_get_nation_from_state_ownership(s_B);
105
106 auto at_war = military::are_at_war(state, n_A, n_B);
107
108 auto capital_A = state.world.state_instance_get_capital(s_A);
109 auto capital_B = state.world.state_instance_get_capital(s_B);
110
111 auto port_A = province::state_get_coastal_capital(state, s_A);
112 auto port_B = province::state_get_coastal_capital(state, s_B);
113
114 auto controller_capital_A = state.world.province_get_nation_from_province_control(capital_A);
115 auto controller_capital_B = state.world.province_get_nation_from_province_control(capital_B);
116
117 auto controller_port_A = state.world.province_get_nation_from_province_control(port_A);
118 auto controller_port_B = state.world.province_get_nation_from_province_control(port_B);
119
120 auto sphere_A = state.world.nation_get_in_sphere_of(controller_capital_A);
121 auto sphere_B = state.world.nation_get_in_sphere_of(controller_capital_B);
122
123 auto overlord_A = state.world.overlord_get_ruler(
124 state.world.nation_get_overlord_as_subject(controller_capital_A)
125 );
126 auto overlord_B = state.world.overlord_get_ruler(
127 state.world.nation_get_overlord_as_subject(controller_capital_B)
128 );
129
130 auto A_is_open_to_B = sphere_A == controller_capital_B || overlord_A == controller_capital_B;
131 auto B_is_open_to_A = sphere_B == controller_capital_A || overlord_B == controller_capital_A;
132
133 auto import_tariff_A = economy::effective_tariff_import_rate(state, controller_capital_A);
134 auto export_tariff_A = economy::effective_tariff_export_rate(state, controller_capital_A);
135 auto import_tariff_B = economy::effective_tariff_import_rate(state, controller_capital_B);
136 auto export_tariff_B = economy::effective_tariff_export_rate(state, controller_capital_B);
137
138 auto is_sea_route = state.world.trade_route_get_is_sea_route(route);
139 auto is_land_route = state.world.trade_route_get_is_land_route(route);
140
141 if(is_sea_route) {
142 if(state.world.province_get_is_blockaded(port_A)) {
143 is_sea_route = false;
144 }
145 if(state.world.province_get_is_blockaded(port_B)) {
146 is_sea_route = false;
147 }
148 }
149
150 if(!(is_sea_route || is_land_route)) {
151 return 0.f;
152 }
153
154 auto merchant_cut = economy::merchant_cut_foreign;
155
156 if(controller_capital_A == controller_capital_B) {
157 import_tariff_A = 0.f;
158 export_tariff_A = 0.f;
159 import_tariff_B = 0.f;
160 export_tariff_B = 0.f;
161 merchant_cut = economy::merchant_cut_domestic;
162 }
163 if(A_is_open_to_B) {
164 import_tariff_A = 0.f;
165 export_tariff_A = 0.f;
166 }
167 if(B_is_open_to_A) {
168 import_tariff_B = 0.f;
169 export_tariff_B = 0.f;
170 }
171
172 auto distance = 999999.f;
173
174 if(is_land_route) {
175 distance = std::min(distance, state.world.trade_route_get_land_distance(route));
176 }
177 if(is_sea_route) {
178 distance = std::min(distance, state.world.trade_route_get_sea_distance(route));
179 }
180
181 auto trade_good_loss_mult = std::max(0.f, 1.f - 0.0001f * distance);
182
183 auto transport_cost = distance * 0.0075f;
184 // effect of scale
185 // volume reduces transport costs
186 auto effect_of_scale = std::max(0.1f, 1.f - absolute_volume * 0.0005f);
187
188
189 auto price_A_export = economy::price(state, A, c) * (1.f + export_tariff_A);
190 auto price_B_export = economy::price(state, B, c) * (1.f + export_tariff_B);
191
192 auto price_A_import = economy::price(state, A, c) * (1.f - import_tariff_A) * trade_good_loss_mult;
193 auto price_B_import = economy::price(state, B, c) * (1.f - import_tariff_B) * trade_good_loss_mult;
194
195 auto current_profit_A_to_B = price_B_import - price_A_export * merchant_cut - transport_cost * effect_of_scale;
196 auto current_profit_B_to_A = price_A_import - price_B_export * merchant_cut - transport_cost * effect_of_scale;
197
198 return std::max(0.f, std::max(current_profit_A_to_B / price_A_export, current_profit_B_to_A / price_B_export));
199}
200
201}
void set_visible(sys::state &state, bool vis)
void button_action(sys::state &state) noexcept override
#define B(name, bit)
Definition: cpu.h:216
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr float merchant_cut_foreign
Definition: economy.hpp:138
constexpr float merchant_cut_domestic
Definition: economy.hpp:139
float price(sys::state const &state, dcon::state_instance_id s, dcon::commodity_id c)
Definition: economy.cpp:150
float rgo_effective_size(sys::state const &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
Definition: economy.cpp:1780
float effective_tariff_import_rate(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:1737
float effective_tariff_export_rate(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:1742
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:649
dcon::province_id state_get_coastal_capital(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1640
float rgo_production_quantity(sys::state &state, dcon::province_id id, dcon::commodity_id c)
Definition: province.cpp:523
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
std::string format_money(float num)
Definition: text.cpp:1029
std::string get_name_as_string(sys::state &state, T t)
Definition: text.hpp:957
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1823
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1904
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1923
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
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:797
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1831
float trade_route_profit(sys::state &state, dcon::trade_route_id route, dcon::commodity_id c)
void province_owner_rgo_draw_tooltip(sys::state &state, text::columnar_layout &contents, dcon::province_id prov_id) noexcept
Holds important data about the game world, state, and other data regarding windowing,...
element_base * province_window