Project Alice
Loading...
Searching...
No Matches
gui_production_window.hpp
Go to the documentation of this file.
1#pragma once
2
12#include "economy_templates.hpp"
14#include "widgets/table.hpp"
15
16namespace ui {
17
19 dcon::state_instance_id data{};
20 bool is_build = false;
22};
23
25public:
26 void on_update(sys::state& state) noexcept override {
27 auto content = retrieve<dcon::factory_id>(state, parent);
28 auto sid = retrieve<dcon::state_instance_id>(state, parent);
29 auto mid = state.world.state_instance_get_market_from_local_market(sid);
30 frame = int32_t(
31 state.world.factory_get_primary_employment(content)
32 * 10.f
33 * state.world.market_get_labor_unskilled_demand_satisfaction(mid)
34 );
35 }
36
39 }
40
41 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
42 auto fid = retrieve<dcon::factory_id>(state, parent);
43 auto sid = retrieve<dcon::state_instance_id>(state, parent);
44 auto mid = state.world.state_instance_get_market_from_local_market(sid);
45
46 auto max_emp = economy::factory_max_employment(state, fid);
47 {
48 auto box = text::open_layout_box(contents, 0);
50 state,
51 contents,
52 box,
53 state.world.pop_type_get_name(state.culture_definitions.primary_factory_worker)
54 );
55 text::add_to_layout_box(state, contents, box, std::string_view{": " });
56 text::add_to_layout_box(state, contents, box, int64_t(std::ceil(
57 state.world.factory_get_primary_employment(fid)
58 * max_emp
59 * state.economy_definitions.craftsmen_fraction
60 * state.world.market_get_labor_unskilled_demand_satisfaction(mid))
61 ));
62 text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
63 text::add_to_layout_box(state, contents, box, int64_t(std::ceil(max_emp * state.economy_definitions.craftsmen_fraction)));
64 text::close_layout_box(contents, box);
65 }
66 {
67 auto box = text::open_layout_box(contents, 0);
68 text::add_to_layout_box(state, contents, box, state.world.pop_type_get_name(state.culture_definitions.secondary_factory_worker));
69 text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
70 text::add_to_layout_box(state, contents, box, int64_t(std::ceil(
71 state.world.factory_get_secondary_employment(fid)
72 * max_emp
73 * (1.0f - state.economy_definitions.craftsmen_fraction)
74 * state.world.market_get_labor_skilled_demand_satisfaction(mid))
75 ));
76 text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
77 text::add_to_layout_box(state, contents, box, int64_t(std::ceil(max_emp * (1.0f - state.economy_definitions.craftsmen_fraction))));
78 text::close_layout_box(contents, box);
79 }
80 }
81};
82
84public:
85 void on_update(sys::state& state) noexcept override {
86 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
87 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
89 auto rules = state.world.nation_get_combined_issue_rules(n);
90 disabled = (rules & issue_rule::factory_priority) == 0 || n != state.local_player_nation;
91 }
92
93 void button_action(sys::state& state) noexcept override {
94 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
95 auto fat = dcon::fatten(state.world, fid);
96 switch(economy::factory_priority(state, fid)) {
97 case 0:
98 command::change_factory_settings(state, state.local_player_nation, fid, 1, fat.get_subsidized());
99 break;
100 case 1:
101 command::change_factory_settings(state, state.local_player_nation, fid, 2, fat.get_subsidized());
102 break;
103 case 2:
104 command::change_factory_settings(state, state.local_player_nation, fid, 3, fat.get_subsidized());
105 break;
106 case 3:
107 command::change_factory_settings(state, state.local_player_nation, fid, 0, fat.get_subsidized());
108 break;
109 default:
110 break;
111 }
112 }
113
116 }
117
118 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
119 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
120 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
121 if(n != state.local_player_nation)
122 return;
123
124 if(disabled) {
125 text::add_line(state, contents, "production_not_allowed_to_change_prio_tooltip");
126 text::add_line(state, contents, "cant_prioritize_explanation");
127 } else {
128 text::add_line(state, contents, "production_allowed_to_change_prio_tooltip");
129 switch(economy::factory_priority(state, fid)) {
130 case 0:
131 text::add_line(state, contents, "diplomacy_prio_none");
132 break;
133 case 1:
134 text::add_line(state, contents, "diplomacy_prio_low");
135 break;
136 case 2:
137 text::add_line(state, contents, "diplomacy_prio_middle");
138 break;
139 case 3:
140 text::add_line(state, contents, "diplomacy_prio_high");
141 break;
142 default:
143 break;
144 }
145 }
146 text::add_line_break_to_layout(state, contents); // TODO: Classic needs this as a divider
147 text::add_line(state, contents, "production_prio_factory_desc_tooltip");
148 }
149};
150
152public:
153 void on_update(sys::state& state) noexcept override {
154 auto fid = retrieve<dcon::factory_id>(state, parent);
155 auto fat = dcon::fatten(state.world, fid);
156 auto sid = retrieve<dcon::state_instance_id>(state, parent);
157
159 fat.get_building_type().id, true);
160
161 }
162
163 void button_right_action(sys::state& state) noexcept override {
164
165 }
166
167 void button_shift_action(sys::state& state) noexcept override {
168 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
169 auto sid = retrieve<dcon::state_instance_id>(state, parent);
170 for(auto p : state.world.state_definition_get_abstract_state_membership_as_state(state.world.state_instance_get_definition(sid))) {
171 for(auto fac : p.get_province().get_factory_location()) {
173 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true)) {
175 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true);
176 }
177 }
178 }
179 }
180
181 void button_shift_right_action(sys::state& state) noexcept override {
182 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
183 auto sid = retrieve<dcon::state_instance_id>(state, parent);
184 for(auto p : state.world.state_definition_get_abstract_state_membership_as_state(state.world.state_instance_get_definition(sid))) {
185 for(auto fac : p.get_province().get_factory_location()) {
186 if(fac.get_factory().get_primary_employment() >= 0.95f && fac.get_factory().get_production_scale() > 0.8f) {
188 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true)) {
190 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true);
191 }
192 }
193 }
194 }
195 }
196
197 void button_ctrl_action(sys::state& state) noexcept override {
198 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
199 for(auto p : state.world.nation_get_province_ownership(n)) {
200 for(auto fac : p.get_province().get_factory_location()) {
202 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true)) {
204 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true);
205 }
206 }
207 }
208 }
209
210 void button_ctrl_right_action(sys::state& state) noexcept override {
211 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
212 for(auto p : state.world.nation_get_province_ownership(n)) {
213 for(auto fac : p.get_province().get_factory_location()) {
214 if(fac.get_factory().get_primary_employment() >= 0.95f && fac.get_factory().get_production_scale() > 0.8f) {
216 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true)) {
218 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true);
219 }
220 }
221 }
222 }
223 }
224
225 void button_ctrl_shift_action(sys::state& state) noexcept override {
226 auto fid = retrieve<dcon::factory_id>(state, parent);
227 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
228 for(auto p : state.world.nation_get_province_ownership(n)) {
229 for(auto fac : p.get_province().get_factory_location()) {
230 if(fac.get_factory().get_building_type() == state.world.factory_get_building_type(fid)
232 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true)) {
234 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true);
235 }
236 }
237 }
238 }
239
241 auto fid = retrieve<dcon::factory_id>(state, parent);
242 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
243 for(auto p : state.world.nation_get_province_ownership(n)) {
244 for(auto fac : p.get_province().get_factory_location()) {
245 if(fac.get_factory().get_building_type() == state.world.factory_get_building_type(fid)
246 && fac.get_factory().get_primary_employment() >= 0.95f && fac.get_factory().get_production_scale() > 0.8f) {
248 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true)) {
250 p.get_province().get_state_membership(), fac.get_factory().get_building_type(), true);
251 }
252 }
253 }
254 }
255 }
256
257 void button_action(sys::state& state) noexcept override {
258 auto fid = retrieve<dcon::factory_id>(state, parent);
259 auto fat = dcon::fatten(state.world, fid);
260 auto sid = retrieve<dcon::state_instance_id>(state, parent);
261 command::begin_factory_building_construction(state, state.local_player_nation, sid, fat.get_building_type().id, true);
262 }
263
264 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
265 auto fid = retrieve<dcon::factory_id>(state, parent);
266 auto sid = retrieve<dcon::state_instance_id>(state, parent);
267 auto type = state.world.factory_get_building_type(fid);
268
269
270 // no double upgrade
271 bool is_not_upgrading = true;
272 for(auto p : state.world.state_instance_get_state_building_construction(sid)) {
273 if(p.get_type() == type)
274 is_not_upgrading = false;
275 }
276 if(is_not_upgrading) {
278 }
279 }
280
283 }
284
285 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
286 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
287 auto fat = dcon::fatten(state.world, fid);
288 const dcon::state_instance_id sid = retrieve<dcon::state_instance_id>(state, parent);
289 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
290
291 auto type = state.world.factory_get_building_type(fid);
292
293 // no double upgrade
294 bool is_not_upgrading = true;
295 for(auto p : state.world.state_instance_get_state_building_construction(sid)) {
296 if(p.get_type() == type)
297 is_not_upgrading = false;
298 }
299 if(!is_not_upgrading) {
300 return;
301 }
302
303 text::add_line(state, contents, "production_expand_factory_tooltip");
304
306
307 bool is_civ = state.world.nation_get_is_civilized(state.local_player_nation);
308 text::add_line_with_condition(state, contents, "factory_upgrade_condition_1", is_civ);
309
310 bool state_is_not_colonial = !state.world.province_get_is_colonial(state.world.state_instance_get_capital(sid));
311 text::add_line_with_condition(state, contents, "factory_upgrade_condition_2", state_is_not_colonial);
312
313 bool is_activated = state.world.nation_get_active_building(n, type) == true || state.world.factory_type_get_is_available_from_start(type);
314 text::add_line_with_condition(state, contents, "factory_upgrade_condition_3", is_activated);
315 if(n != state.local_player_nation) {
316 bool gp_condition = (state.world.nation_get_is_great_power(state.local_player_nation) == true &&
317 state.world.nation_get_is_great_power(n) == false);
318 text::add_line_with_condition(state, contents, "factory_upgrade_condition_4", gp_condition);
319
320 text::add_line_with_condition(state, contents, "factory_upgrade_condition_5", state.world.nation_get_is_civilized(n));
321
322 auto rules = state.world.nation_get_combined_issue_rules(n);
323 text::add_line_with_condition(state, contents, "factory_upgrade_condition_6",
325
326 text::add_line_with_condition(state, contents, "factory_upgrade_condition_7",
327 !military::are_at_war(state, state.local_player_nation, n));
328 } else {
329 auto rules = state.world.nation_get_combined_issue_rules(state.local_player_nation);
330 text::add_line_with_condition(state, contents, "factory_upgrade_condition_8", (rules & issue_rule::expand_factory) != 0);
331 }
332 text::add_line_with_condition(state, contents, "factory_upgrade_condition_9", is_not_upgrading);
333 text::add_line_with_condition(state, contents, "factory_upgrade_condition_10", fat.get_level() < 255);
335
336 text::add_line(state, contents, "factory_upgrade_shortcuts");
337 }
338};
339
341public:
342 void on_update(sys::state& state) noexcept override {
343 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
345 }
346
347 void button_action(sys::state& state) noexcept override {
348 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
350 }
351
352 void on_create(sys::state& state) noexcept override {
353 frame = 0;
354 }
355
358 }
359
360 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
361 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
362 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
363 if(n == state.local_player_nation) {
364 text::add_line(state, contents, "open_and_sub");
365 if(disabled) {
366 text::add_line(state, contents, "production_not_allowed_to_subsidise_tooltip");
367 text::add_line(state, contents, "cant_subsidize_explanation");
368 }
369 }
370 }
371};
372
374public:
375 void on_update(sys::state& state) noexcept override {
376 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
377 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
378 auto rules = state.world.nation_get_combined_issue_rules(n);
379 disabled = (rules & issue_rule::can_subsidise) == 0 || state.local_player_nation != n;
380 frame = state.world.factory_get_subsidized(fid) ? 1 : 0;
381 }
382
383 void button_action(sys::state& state) noexcept override {
384 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
385 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
386 auto fat = dcon::fatten(state.world, fid);
387 if(fat.get_subsidized()) {
388 if(command::can_change_factory_settings(state, state.local_player_nation, fid, uint8_t(economy::factory_priority(state, fid)), false)) {
390 false);
391 }
392 } else {
393 if(command::can_change_factory_settings(state, state.local_player_nation, fid, uint8_t(economy::factory_priority(state, fid)), true)) {
395 }
396 }
397 }
398
401 }
402
403 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
404 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
405 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
406 if(n == state.local_player_nation) {
407 if(dcon::fatten(state.world, fid).get_subsidized()) {
408 text::add_line(state, contents, "production_cancel_subsidies");
409 } else {
410 if(disabled) {
411 text::add_line(state, contents, "production_not_allowed_to_subsidise_tooltip");
412 text::add_line(state, contents, "cant_subsidize_explanation");
413 } else {
414 text::add_line(state, contents, "production_allowed_to_subsidise_tooltip");
415 }
416 }
418 text::add_line(state, contents, "production_subsidies_desc");
419 }
420 }
421};
422
424public:
425 void on_update(sys::state& state) noexcept override {
426 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
427 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
428 disabled = !command::can_delete_factory(state, state.local_player_nation, fid);
429 }
430
431 void button_action(sys::state& state) noexcept override {
432 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
433 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
434 command::delete_factory(state, state.local_player_nation, fid);
435 }
436
439 }
440
441 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
442 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
443 if(n == state.local_player_nation) {
444 text::add_line(state, contents, "factory_delete_header");
445 if(disabled) {
447 text::add_line(state, contents, "factory_delete_not_allowed");
448 }
449 }
450 }
451};
452
454public:
455 bool visible = true;
456
457 void on_update(sys::state& state) noexcept override {
458 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
459 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
460
461 visible = dcon::fatten(state.world, fid).get_production_scale() >= 0.05f;
462 disabled = !command::can_delete_factory(state, state.local_player_nation, fid);
463 frame = 1;
464 }
465 message_result test_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
466 auto prov = retrieve<dcon::province_id>(state, parent);
467 if(visible)
470 }
471 void button_action(sys::state& state) noexcept override {
472 const dcon::factory_id fid = retrieve<dcon::factory_id>(state, parent);
473 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
474 command::delete_factory(state, state.local_player_nation, fid);
475 }
476
477 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
478 if(visible)
480 }
481
484 }
485
486 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
487 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
488 if(n == state.local_player_nation) {
489 text::add_line(state, contents, "close_and_del");
490 if(disabled) {
492 text::add_line(state, contents, "factory_delete_not_allowed");
493 }
494 }
495 }
496};
497
499 dcon::factory_id id;
500 std::variant<std::monostate, economy::upgraded_factory, economy::new_factory> activity;
501};
502
504 size_t index = 0;
505};
506
508public:
509 void on_update(sys::state& state) noexcept override {
510 progress = retrieve<economy::new_factory>(state, parent).progress;
511 }
514 }
515
516 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
517 auto nf = retrieve< economy::new_factory>(state, parent);
518 auto si = retrieve<dcon::state_instance_id>(state, parent);
519 if(!nf.type)
520 return;
521 for(auto p : state.world.state_instance_get_state_building_construction(si)) {
522 if(p.get_type() == nf.type) {
523 float admin_eff = state.world.nation_get_administrative_efficiency(p.get_nation());
524 float factory_mod = state.world.nation_get_modifier_values(p.get_nation(), sys::national_mod_offsets::factory_cost) + 1.0f;
525 float pop_factory_mod = std::max(0.1f, state.world.nation_get_modifier_values(p.get_nation(), sys::national_mod_offsets::factory_owner_cost));
526 float admin_cost_factor = (p.get_is_pop_project() ? pop_factory_mod : (2.0f - admin_eff)) * factory_mod;
527
528 auto& goods = state.world.factory_type_get_construction_costs(nf.type);
529 auto& cgoods = p.get_purchased_goods();
530
531 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
532 if(goods.commodity_type[i]) {
533 auto box = text::open_layout_box(contents, 0);
534 auto cid = goods.commodity_type[i];
535 std::string padding = cid.index() < 10 ? "0" : "";
536 std::string description = "@$" + padding + std::to_string(cid.index());
537 text::add_unparsed_text_to_layout_box(state, contents, box, description);
538 text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
539 text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
540 text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
541 text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
542 text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * admin_cost_factor });
543 text::close_layout_box(contents, box);
544 }
545 }
546 return;
547 }
548 }
549 }
550};
551
553public:
554 void on_update(sys::state& state) noexcept override {
555 progress = retrieve<economy::upgraded_factory>(state, parent).progress;
556 }
559 }
560
561 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
562 auto nf = retrieve<economy::upgraded_factory>(state, parent);
563 auto si = retrieve<dcon::state_instance_id>(state, parent);
564 if(!nf.type)
565 return;
566 for(auto p : state.world.state_instance_get_state_building_construction(si)) {
567 if(p.get_type() == nf.type) {
568 float admin_eff = state.world.nation_get_administrative_efficiency(p.get_nation());
569 float factory_mod = state.world.nation_get_modifier_values(p.get_nation(), sys::national_mod_offsets::factory_cost) + 1.0f;
570 float pop_factory_mod = std::max(0.1f, state.world.nation_get_modifier_values(p.get_nation(), sys::national_mod_offsets::factory_owner_cost));
571 float admin_cost_factor = (p.get_is_pop_project() ? pop_factory_mod : (2.0f - admin_eff)) * factory_mod;
572
573 auto& goods = state.world.factory_type_get_construction_costs(nf.type);
574 auto& cgoods = p.get_purchased_goods();
575
576 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
577 if(goods.commodity_type[i]) {
578 auto box = text::open_layout_box(contents, 0);
579 auto cid = goods.commodity_type[i];
580 std::string padding = cid.index() < 10 ? "0" : "";
581 std::string description = "@$" + padding + std::to_string(cid.index());
582 text::add_unparsed_text_to_layout_box(state, contents, box, description);
583 text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
584 text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
585 text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
586 text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
587 text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * admin_cost_factor });
588 text::close_layout_box(contents, box);
589 }
590 }
591 return;
592 }
593 }
594 }
595};
596
598 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
600 }
601
602 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
603 auto fid = retrieve<dcon::factory_id>(state, parent);
604 if(!fid)
605 return;
606 dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
607 auto p = state.world.factory_get_province_from_factory_location(retrieve<dcon::factory_id>(state, parent));
608 auto p_fat = fatten(state.world, p);
609 auto sdef = state.world.abstract_state_membership_get_state(state.world.province_get_abstract_state_membership(p));
610 dcon::state_instance_id s{};
611 state.world.for_each_state_instance([&](dcon::state_instance_id id) {
612 if(state.world.state_instance_get_definition(id) == sdef)
613 s = id;
614 });
615 auto market = state.world.state_instance_get_market_from_local_market(s);
616
617 // nation data
618
619 float mobilization_impact = state.world.nation_get_is_mobilized(n) ? military::mobilization_impact(state, n) : 1.0f;
620 auto cap_prov = state.world.nation_get_capital(n);
621 auto cap_continent = state.world.province_get_continent(cap_prov);
622 auto cap_region = state.world.province_get_connected_region_id(cap_prov);
623
624
625 auto fac = fatten(state.world, fid);
626 auto type = state.world.factory_get_building_type(fid);
627
628 auto& inputs = type.get_inputs();
629 auto& einputs = type.get_efficiency_inputs();
630
631 //inputs
632
633 float input_total = economy::factory_input_total_cost(state, market, type);
634 float min_input_available = economy::factory_min_input_available(state, market, type);
635 float e_input_total = economy::factory_e_input_total_cost(state, market, type);
636 float min_e_input_available = economy::factory_min_e_input_available(state, market, type);
637
638 //modifiers
639
640 float input_multiplier = economy::factory_input_multiplier(state, fac, n, p, s);
641 float e_input_multiplier = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
642 float throughput_multiplier = economy::factory_throughput_multiplier(state, type, n, p, s);
643 float output_multiplier = economy::factory_output_multiplier(state, fac, n, market, p);
644
645 float bonus_profit_thanks_to_max_e_input = fac.get_building_type().get_output_amount()
646 * 0.25f
647 * throughput_multiplier
648 * output_multiplier
649 * min_input_available
650 * economy::price(state, market, fac.get_building_type().get_output());
651
652 // if efficiency inputs are not worth it, then do not buy them
653 if(bonus_profit_thanks_to_max_e_input < e_input_total * e_input_multiplier * input_multiplier)
654 min_e_input_available = 0.f;
655
656 float max_production_scale = economy::factory_max_production_scale(
657 state,
658 fac,
659 mobilization_impact,
660 p_fat.get_nation_from_province_control() != n
661 );
662
663 float effective_production_scale = std::min(fac.get_production_scale() * fac.get_level(), max_production_scale);
664
665 auto amount = (0.75f + 0.25f * min_e_input_available) * min_input_available * state.world.factory_get_production_scale(fid);
666
667 text::add_line(state, contents, state.world.factory_type_get_name(type));
668
670
671 text::add_line(state, contents, "factory_stats_1", text::variable_type::val, text::fp_percentage{amount});
672
673 text::add_line(state, contents, "factory_stats_2", text::variable_type::val,
674 text::fp_percentage{state.world.factory_get_production_scale(fid)});
675
676 text::add_line(state, contents, "factory_stats_3", text::variable_type::val,
677 text::fp_one_place{state.world.factory_get_actual_production(fid) }, text::variable_type::x, type.get_output().get_name());
678
679 text::add_line(state, contents, "factory_stats_4", text::variable_type::val,
680 text::fp_currency{state.world.factory_get_full_profit(fid)});
681
683
684 text::add_line(state, contents, "factory_stats_5");
685
686
687 float total_expenses = 0.f;
688
689 int position_demand_sat = 100;
690 int position_amount = 180;
691 int position_cost = 250;
692
693 auto input_cost_line = [&] (
694 dcon::commodity_id cid,
695 float base_amount
696 ) {
697 auto box = text::open_layout_box(contents);
698 text::layout_box name_entry = box;
699 text::layout_box demand_satisfaction = box;
700 text::layout_box amount_box = box;
701 text::layout_box cost_box = box;
702
703 demand_satisfaction.x_position += position_demand_sat;
704 amount_box.x_position += position_amount;
705 cost_box.x_position += position_cost;
706
707 name_entry.x_size /= 10;
708
709 std::string padding = cid.index() < 10 ? "0" : "";
710 std::string description = "@$" + padding + std::to_string(cid.index());
711 text::add_unparsed_text_to_layout_box(state, contents, name_entry, description);
712
713 text::add_to_layout_box(state, contents, name_entry, state.world.commodity_get_name(cid));
714
715 auto sat = state.world.market_get_demand_satisfaction(market, cid);
717 demand_satisfaction,
718 text::fp_percentage{ sat },
720 );
721
722 float amount =
723 base_amount
724 * input_multiplier
725 * throughput_multiplier
726 * min_input_available
727 * effective_production_scale;
728
729 float cost =
730 economy::price(state, market, cid)
731 * amount;
732
733 total_expenses += cost;
734
735 text::add_to_layout_box(state, contents, amount_box, text::fp_two_places{ amount });
737
738 text::add_to_layout_box(state, contents, box, std::string(" "));
739 text::close_layout_box(contents, box);
740 };
741
742 auto e_input_cost_line = [&](
743 dcon::commodity_id cid,
744 float base_amount
745 ) {
746 auto box = text::open_layout_box(contents);
747 text::layout_box name_entry = box;
748 text::layout_box demand_satisfaction = box;
749 text::layout_box amount_box = box;
750 text::layout_box cost_box = box;
751
752 demand_satisfaction.x_position += position_demand_sat;
753 amount_box.x_position += position_amount;
754 cost_box.x_position += position_cost;
755
756 name_entry.x_size /= 10;
757 std::string padding = cid.index() < 10 ? "0" : "";
758 std::string description = "@$" + padding + std::to_string(cid.index());
759 text::add_unparsed_text_to_layout_box(state, contents, name_entry, description);
760 text::add_to_layout_box(state, contents, name_entry, state.world.commodity_get_name(cid));
761
762 auto sat = state.world.market_get_demand_satisfaction(market, cid);
764 demand_satisfaction,
765 text::fp_percentage{ sat },
767 );
768
769 float amount =
770 base_amount
771 * input_multiplier * e_input_multiplier
772 * min_e_input_available
773 * min_input_available
774 * effective_production_scale;
775
776 float cost =
777 economy::price(state, market, cid)
778 * amount;
779
780 total_expenses += cost;
781
782 text::add_to_layout_box(state, contents, amount_box, text::fp_two_places{ amount });
784
785 text::add_to_layout_box(state, contents, box, std::string(" "));
786 text::close_layout_box(contents, box);
787 };
788
789 auto named_money_line = [&](
790 std::string_view loc,
791 float value
792 ) {
793 auto box = text::open_layout_box(contents);
794 text::layout_box name_entry = box;
795 text::layout_box cost = box;
796
797 cost.x_position += position_cost;
798 name_entry.x_size /= 10;
799
800 text::localised_format_box(state, contents, name_entry, loc);
802
803 text::add_to_layout_box(state, contents, box, std::string(" "));
804 text::close_layout_box(contents, box);
805 };
806
807 auto output_cost_line = [&](
808 dcon::commodity_id cid,
809 float base_amount
810 ) {
811 auto box = text::open_layout_box(contents);
812 text::layout_box name_entry = box;
813 text::layout_box amount = box;
814 text::layout_box cost = box;
815
816 amount.x_position += position_amount;
817 cost.x_position += position_cost;
818
819 name_entry.x_size /= 10;
820
821 std::string padding = cid.index() < 10 ? "0" : "";
822 std::string description = "@$" + padding + std::to_string(cid.index());
823 text::add_unparsed_text_to_layout_box(state, contents, name_entry, description);
824 text::add_to_layout_box(state, contents, name_entry, state.world.commodity_get_name(cid));
825
826 float output_amount =
827 base_amount
828 * (0.75f + 0.25f * min_e_input_available)
829 * throughput_multiplier
830 * output_multiplier
831 * min_input_available
832 * effective_production_scale;
833
834 float output_cost =
835 economy::price(state, market, cid)
837
840
841 text::add_to_layout_box(state, contents, box, std::string(" "));
842 text::close_layout_box(contents, box);
843 };
844
845 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
846 if(inputs.commodity_type[i]) {
847 input_cost_line(inputs.commodity_type[i], inputs.commodity_amounts[i]);
848 } else {
849 break;
850 }
851 }
852
854
855 text::add_line(state, contents, "factory_stats_6");
856
858 if(einputs.commodity_type[i]) {
859 e_input_cost_line(einputs.commodity_type[i], einputs.commodity_amounts[i]);
860 } else {
861 break;
862 }
863 }
864
866
867 auto const min_wage_factor = economy::pop_min_wage_factor(state, n);
868
869 auto wage_unskilled = state.world.market_get_labor_unskilled_price(market);
870 auto wage_skilled = state.world.market_get_labor_skilled_price(market);
871
872 float wage_estimation = 0.f;
873
874 wage_estimation +=
875 wage_unskilled
876 * state.defines.alice_factory_per_level_employment
877 * float(state.world.factory_get_level(fid))
878 * state.world.factory_get_primary_employment(fid)
879 * state.world.market_get_labor_unskilled_demand_satisfaction(market)
880 * (state.economy_definitions.craftsmen_fraction);
881
882 wage_estimation +=
883 wage_skilled
884 * state.defines.alice_factory_per_level_employment
885 * float(state.world.factory_get_level(fid))
886 * state.world.factory_get_secondary_employment(fid)
887 * state.world.market_get_labor_skilled_demand_satisfaction(market)
888 * (1.f - state.economy_definitions.craftsmen_fraction);
889
890 total_expenses += wage_estimation;
891
892 named_money_line("factory_stats_wage",
893 -wage_estimation
894 );
895
897
898 named_money_line("factory_stats_expenses",
899 -total_expenses
900 );
901
902 output_cost_line(type.get_output(), type.get_output_amount());
903
904 float desired_income = economy::factory_desired_raw_profit(fac, total_expenses);
905
906 named_money_line("factory_stats_desired_income",
907 desired_income
908 );
909 }
910};
911
913public:
914 dcon::commodity_id com{};
915
918 }
919
920 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
921 auto n = retrieve<dcon::nation_id>(state, parent);
922 auto p = state.world.factory_get_province_from_factory_location(retrieve<dcon::factory_id>(state, parent));
923 //auto com = retrieve<dcon::commodity_id>(state, parent);
924 if(!com)
925 return;
926
927 auto box = text::open_layout_box(contents, 0);
929 text::close_layout_box(contents, box);
930
931 auto commodity_mod_description = [&](float value, std::string_view locale_base_name, std::string_view locale_farm_base_name) {
932 if(value == 0.f)
933 return;
934 auto box = text::open_layout_box(contents, 0);
936 text::add_space_to_layout_box(state, contents, box);
937 text::add_to_layout_box(state, contents, box, text::produce_simple_string(state, state.world.commodity_get_is_mine(com) ? locale_base_name : locale_farm_base_name), text::text_color::white);
938 text::add_to_layout_box(state, contents, box, std::string{ ":" }, text::text_color::white);
939 text::add_space_to_layout_box(state, contents, box);
940 auto color = value > 0.f ? text::text_color::green : text::text_color::red;
941 text::add_to_layout_box(state, contents, box, (value > 0.f ? "+" : "") + text::format_percentage(value, 1), color);
942 text::close_layout_box(contents, box);
943 };
944 commodity_mod_description(state.world.nation_get_factory_goods_output(n, com), "tech_output", "tech_output");
945 commodity_mod_description(state.world.nation_get_rgo_goods_output(n, com), "tech_mine_output", "tech_farm_output");
946 commodity_mod_description(state.world.nation_get_rgo_size(n, com), "tech_mine_size", "tech_farm_size");
947 // If any factory has good as output
949 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::factory_output, true);
950 active_modifiers_description(state, contents, p, 0, sys::provincial_mod_offsets::local_factory_output, true);
951 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::factory_throughput, true);
952 active_modifiers_description(state, contents, p, 0, sys::provincial_mod_offsets::local_factory_throughput, true);
953 } else {
954 if(state.world.commodity_get_is_mine(com)) {
955 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::mine_rgo_eff, true);
956 active_modifiers_description(state, contents, p, 0, sys::provincial_mod_offsets::mine_rgo_eff, true);
957 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::mine_rgo_size, true);
958 active_modifiers_description(state, contents, p, 0, sys::provincial_mod_offsets::mine_rgo_size, true);
959 } else {
960 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::farm_rgo_eff, true);
961 active_modifiers_description(state, contents, p, 0, sys::provincial_mod_offsets::farm_rgo_eff, true);
962 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::farm_rgo_size, true);
963 active_modifiers_description(state, contents, p, 0, sys::provincial_mod_offsets::farm_rgo_size, true);
964 }
965 }
966 }
967
968 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
969 if(com)
971 }
972};
973
975public:
976 void on_update(sys::state& state) noexcept override {
977 auto v = retrieve<economy::new_factory>(state, parent);
978 auto sid = retrieve<dcon::state_instance_id>(state, parent);
979 disabled = !command::can_cancel_factory_building_construction(state, state.local_player_nation, sid, v.type);
980 }
981 void button_action(sys::state& state) noexcept override {
982 auto v = retrieve<economy::new_factory>(state, parent);
983 auto sid = retrieve<dcon::state_instance_id>(state, parent);
984 command::cancel_factory_building_construction(state, state.local_player_nation, sid, v.type);
985 }
988 }
989 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
990 text::add_line(state, contents, "cancel_fac_construction");
991 }
992};
994public:
995 void on_update(sys::state& state) noexcept override {
996 auto v = retrieve<economy::upgraded_factory>(state, parent);
997 auto sid = retrieve<dcon::state_instance_id>(state, parent);
998 disabled = !command::can_cancel_factory_building_construction(state, state.local_player_nation, sid, v.type);
999 }
1000 void button_action(sys::state& state) noexcept override {
1001 auto v = retrieve<economy::upgraded_factory>(state, parent);
1002 auto sid = retrieve<dcon::state_instance_id>(state, parent);
1003 command::cancel_factory_building_construction(state, state.local_player_nation, sid, v.type);
1004 }
1007 }
1008 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1009 text::add_line(state, contents, "cancel_fac_upgrade");
1010 }
1011};
1012
1014 factory_input_icon* input_icons[economy::commodity_set::set_size] = {nullptr};
1015 image_element_base* input_lack_icons[economy::commodity_set::set_size] = {nullptr};
1016 std::vector<element_base*> factory_elements;
1017 std::vector<element_base*> upgrade_elements;
1018 std::vector<element_base*> build_elements;
1019 std::vector<element_base*> closed_elements;
1020 dcon::commodity_id output_commodity;
1021
1022public:
1023 uint8_t index = 0; // from 0 to int32_t(state.defines.factories_per_state)
1024
1025 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1026 if(name == "prod_factory_bg") {
1027 return make_element_by_type<normal_factory_background>(state, id);
1028 } else if(name == "level") {
1029 auto ptr = make_element_by_type<factory_level_text>(state, id);
1030 factory_elements.push_back(ptr.get());
1031 return ptr;
1032 } else if(name == "income") {
1033 auto ptr = make_element_by_type<factory_profit_text>(state, id);
1034 factory_elements.push_back(ptr.get());
1035 return ptr;
1036 } else if(name == "income_icon") {
1037 auto ptr = make_element_by_type<factory_income_image>(state, id);
1038 factory_elements.push_back(ptr.get());
1039 return ptr;
1040 } else if(name == "output") {
1041 return make_element_by_type<commodity_image>(state, id);
1042 } else if(name == "closed_overlay") {
1043 return make_element_by_type<invisible_element>(state, id);
1044 } else if(name == "factory_closed_text") {
1045 return make_element_by_type<invisible_element>(state, id);
1046 } else if(name == "prod_factory_inprogress_bg") {
1047 auto ptr = make_element_by_type<image_element_base>(state, id);
1048 build_elements.push_back(ptr.get());
1049 return ptr;
1050 } else if(name == "build_factory_progress") {
1051 auto ptr = make_element_by_type<factory_build_progress_bar>(state, id);
1052 build_elements.push_back(ptr.get());
1053 return ptr;
1054 } else if(name == "prod_cancel_progress") {
1055 auto ptr = make_element_by_type<factory_cancel_new_const_button>(state, id);
1056 build_elements.push_back(ptr.get());
1057 return ptr;
1058 } else if(name == "upgrade_factory_progress") {
1059 auto ptr = make_element_by_type<factory_upgrade_progress_bar>(state, id);
1060 upgrade_elements.push_back(ptr.get());
1061 return ptr;
1062 } else if(name == "progress_overlay_16_64") {
1063 auto ptr = make_element_by_type<image_element_base>(state, id);
1064 upgrade_elements.push_back(ptr.get());
1065 return ptr;
1066 } else if(name == "employment_ratio") {
1067 auto ptr = make_element_by_type<factory_employment_image>(state, id);
1068 factory_elements.push_back(ptr.get());
1069 return ptr;
1070 } else if(name == "priority") {
1071 auto ptr = make_element_by_type<factory_priority_button>(state, id);
1072 factory_elements.push_back(ptr.get());
1073 return ptr;
1074 } else if(name == "upgrade") {
1075 auto ptr = make_element_by_type<factory_upgrade_button>(state, id);
1076 factory_elements.push_back(ptr.get());
1077 return ptr;
1078 } else if(name == "subsidise") {
1079 auto ptr = make_element_by_type<factory_subsidise_button>(state, id);
1080 factory_elements.push_back(ptr.get());
1081 return ptr;
1082 } else if(name == "delete_factory") {
1083 auto ptr = make_element_by_type<factory_delete_button>(state, id);
1084 closed_elements.push_back(ptr.get());
1085 return ptr;
1086 } else if(name == "open_close") {
1087 auto ptr = make_element_by_type<factory_reopen_button>(state, id);
1088 closed_elements.push_back(ptr.get());
1089 auto ptrb = make_element_by_type<factory_close_and_delete_button>(state, id);
1090 factory_elements.push_back(ptrb.get());
1091 add_child_to_front(std::move(ptrb));
1092 return ptr;
1093 } else if(name.substr(0, 6) == "input_") {
1094 auto input_index = size_t(std::stoi(std::string(name.substr(6))));
1095 if(name.ends_with("_lack2")) {
1096 auto ptr = make_element_by_type<image_element_base>(state, id);
1097 input_lack_icons[input_index] = ptr.get();
1098 return ptr;
1099 } else {
1100 auto ptr = make_element_by_type<factory_input_icon>(state, id);
1101 input_icons[input_index] = static_cast<factory_input_icon*>(ptr.get());
1102 return ptr;
1103 }
1104 } else {
1105 return nullptr;
1106 }
1107 }
1108
1109 void on_update(sys::state& state) noexcept override {
1110 if(parent) {
1111 Cyto::Any payload = production_factory_slot_data{{dcon::factory_id{}, std::monostate{}}, index};
1112 parent->impl_get(state, payload);
1113 auto content = any_cast<production_factory_slot_data>(payload);
1114
1115 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1116 dcon::factory_type_fat_id fat_btid(state.world, dcon::factory_type_id{});
1117 if(std::holds_alternative<economy::new_factory>(content.activity)) {
1118 // New factory
1119 economy::new_factory nf = std::get<economy::new_factory>(content.activity);
1120 fat_btid = dcon::fatten(state.world, nf.type);
1121
1122 for(auto const& e : factory_elements)
1123 e->set_visible(state, false);
1124 for(auto const& e : upgrade_elements)
1125 e->set_visible(state, false);
1126 for(auto const& e : build_elements)
1127 e->set_visible(state, true);
1128 for(auto const& e : closed_elements)
1129 e->set_visible(state, false);
1130 } else if(std::holds_alternative<economy::upgraded_factory>(content.activity)) {
1131 // Upgrade
1132 economy::upgraded_factory uf = std::get<economy::upgraded_factory>(content.activity);
1133 fat_btid = dcon::fatten(state.world, uf.type);
1134
1135 for(auto const& e : factory_elements)
1136 e->set_visible(state, true);
1137 for(auto const& e : upgrade_elements)
1138 e->set_visible(state, true);
1139 for(auto const& e : build_elements)
1140 e->set_visible(state, false);
1141 for(auto const& e : closed_elements)
1142 e->set_visible(state, false);
1143 } else {
1144 // "Normal" factory, not being upgraded or built
1145 dcon::factory_id fid = content.id;
1146 fat_btid = state.world.factory_get_building_type(fid);
1147
1148 bool is_closed = dcon::fatten(state.world, fid).get_production_scale() < economy::factory_closed_threshold;
1149 for(auto const& e : factory_elements)
1150 e->set_visible(state, true);
1151 for(auto const& e : upgrade_elements)
1152 e->set_visible(state, false);
1153 for(auto const& e : build_elements)
1154 e->set_visible(state, false);
1155 for(auto const& e : closed_elements)
1156 e->set_visible(state, is_closed);
1157 }
1158
1159 auto s = retrieve<dcon::state_instance_id>(state, parent);
1160 auto market = state.world.state_instance_get_market_from_local_market(s);
1161
1162 auto& cset = fat_btid.get_inputs();
1163 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
1164 if(input_icons[size_t(i)]) {
1165 dcon::commodity_id cid = cset.commodity_type[size_t(i)];
1166 input_icons[size_t(i)]->frame = int32_t(state.world.commodity_get_icon(cid));
1167 input_icons[size_t(i)]->com = cid;
1168 bool is_lack = cid != dcon::commodity_id{} ? state.world.market_get_demand_satisfaction(market, cid) < 0.5f : false;
1169 input_lack_icons[size_t(i)]->set_visible(state, is_lack);
1170 }
1171 }
1172 output_commodity = fat_btid.get_output().id;
1173 }
1174 }
1175
1176 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1177 if(parent) {
1178 Cyto::Any p_payload = production_factory_slot_data{{dcon::factory_id{}, std::monostate{}}, index};
1179 parent->impl_get(state, p_payload);
1180 auto content = any_cast<production_factory_slot_data>(p_payload);
1181 if(payload.holds_type<dcon::factory_id>()) {
1182 payload.emplace<dcon::factory_id>(content.id);
1184 } else if(payload.holds_type<economy::upgraded_factory>()) {
1185 if(std::holds_alternative<economy::upgraded_factory>(content.activity))
1186 payload.emplace<economy::upgraded_factory>(std::get<economy::upgraded_factory>(content.activity));
1188 } else if(payload.holds_type<economy::new_factory>()) {
1189 if(std::holds_alternative<economy::new_factory>(content.activity))
1190 payload.emplace<economy::new_factory>(std::get<economy::new_factory>(content.activity));
1192 } else if(payload.holds_type<dcon::commodity_id>()) {
1193 payload.emplace<dcon::commodity_id>(output_commodity);
1195 } else if(payload.holds_type<dcon::province_id>()) {
1196 payload.emplace<dcon::province_id>(state.world.factory_get_province_from_factory_location(content.id));
1198 }
1199 }
1201 }
1202};
1203
1204
1205
1207 std::vector<element_base*> infos;
1208 std::vector<state_factory_slot> factories;
1209
1210 bool get_filter(sys::state& state, dcon::commodity_id cid) {
1211 Cyto::Any payload = commodity_filter_query_data{cid, false};
1212 parent->impl_get(state, payload);
1213 auto content = any_cast<commodity_filter_query_data>(payload);
1214 return content.filter;
1215 }
1216
1217public:
1218 void on_create(sys::state& state) noexcept override {
1220 factories.resize(size_t(state.defines.factories_per_state));
1221 xy_pair vert_bound{ 0, 0 };
1222 int16_t num_cols = 8;
1223 // Create factory slots for each of the provinces
1224 for(int16_t factory_index = 0; factory_index < int16_t(state.defines.factories_per_state); ++factory_index) {
1225 auto ptr = make_element_by_type<production_factory_info>(state,
1226 state.ui_state.defs_by_name.find(state.lookup_key("factory_info"))->second.definition);
1227 ptr->index = uint8_t(factory_index);
1228 ptr->base_data.position.x = (factory_index % num_cols) * ptr->base_data.size.x;
1229 ptr->base_data.position.y += std::max<int16_t>(0, (factory_index / num_cols) * (ptr->base_data.size.y - 26));
1230 infos.push_back(ptr.get());
1231 add_child_to_front(std::move(ptr));
1232 }
1233 base_data.size.y += state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("factory_info"))->second.definition].size.y
1234 * ((int16_t(state.defines.factories_per_state) + num_cols - 1) / num_cols);
1235 }
1236
1237 void on_update(sys::state& state) noexcept override {
1238 auto state_id = retrieve<dcon::state_instance_id>(state, parent);
1239
1240 for(auto const c : infos)
1241 c->set_visible(state, false);
1242
1243 std::vector<bool> visited_types(state.world.factory_type_size(), false);
1244 size_t index = 0;
1245 // First, the new factories are taken into account
1246 economy::for_each_new_factory(state, state_id, [&](economy::new_factory const& nf) {
1247 dcon::commodity_id cid = state.world.factory_type_get_output(nf.type).id;
1248 if(!visited_types[nf.type.index()] && get_filter(state, cid) && index < state.defines.factories_per_state) {
1249 factories[index].activity = nf;
1250 factories[index].id = dcon::factory_id{};
1251 visited_types[nf.type.index()] = true;
1252 infos[index]->set_visible(state, true);
1253 ++index;
1254 }
1255 });
1256 // Then, the factories being upgraded
1258 dcon::commodity_id cid = state.world.factory_type_get_output(uf.type).id;
1259 if(!visited_types[uf.type.index()] && get_filter(state, cid) && index < state.defines.factories_per_state) {
1260 factories[index].activity = uf;
1261 province::for_each_province_in_state_instance(state, state_id, [&](dcon::province_id prov) {
1262 for(auto fa : state.world.province_get_factory_location(prov)) {
1263 if(fa.get_factory().get_building_type() == uf.type) {
1264 factories[index].id = fa.get_factory().id;
1265 }
1266 }
1267 });
1268
1269 visited_types[uf.type.index()] = true;
1270 infos[index]->set_visible(state, true);
1271 ++index;
1272 }
1273 });
1274 // Finally, factories "doing nothing" are accounted for
1275 province::for_each_province_in_state_instance(state, state_id, [&](dcon::province_id pid) {
1276 dcon::fatten(state.world, pid).for_each_factory_location_as_province([&](dcon::factory_location_id flid) {
1277 dcon::factory_id fid = state.world.factory_location_get_factory(flid);
1278 dcon::factory_type_id ftid = state.world.factory_get_building_type(fid);
1279 dcon::commodity_id cid = state.world.factory_type_get_output(ftid).id;
1280 if(!visited_types[ftid.index()] && get_filter(state, cid) && index < state.defines.factories_per_state) {
1281 factories[index].activity = std::monostate{};
1282 factories[index].id = fid;
1283 infos[index]->set_visible(state, true);
1284 ++index;
1285 }
1286 });
1287 });
1288 }
1289
1290 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1291 if(payload.holds_type<production_factory_slot_data>()) {
1292 auto content = any_cast<production_factory_slot_data>(payload);
1293 auto index = content.index;
1294 static_cast<state_factory_slot&>(content) = factories[index];
1295 content.index = index;
1296 payload.emplace<production_factory_slot_data>(content);
1297 return message_result::consumed;
1298 }
1299 return message_result::unseen;
1300 }
1301};
1302
1304public:
1305 void on_update(sys::state& state) noexcept override {
1306 const dcon::province_id pid = retrieve<dcon::province_id>(state, parent);
1307 const dcon::state_instance_id sid = state.world.province_get_state_membership(pid);
1308 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1309
1310 bool can_build = false;
1311 state.world.for_each_factory_type([&](dcon::factory_type_id ftid) {
1312 can_build =
1313 can_build || command::can_begin_factory_building_construction(state, state.local_player_nation, sid, ftid, false);
1314 });
1315 disabled = !can_build;
1316 }
1317
1318 void button_action(sys::state& state) noexcept override {
1319 if(parent) {
1320 const dcon::province_id pid = retrieve<dcon::province_id>(state, parent);
1321 const dcon::state_instance_id sid = state.world.province_get_state_membership(pid);
1323 state.ui_state.root->move_child_to_front(state.ui_state.production_subwindow);
1325 send(state, state.ui_state.production_subwindow, production_window_tab::factories);
1326 send(state, state.ui_state.production_subwindow, production_selection_wrapper{ sid, true, xy_pair{0, 0} });
1327 }
1328 }
1329
1331 return tooltip_behavior::variable_tooltip;
1332 }
1333
1334 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1335 const dcon::province_id pid = retrieve<dcon::province_id>(state, parent);
1336 const dcon::state_instance_id sid = state.world.province_get_state_membership(pid);
1337 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1338
1339 bool non_colonial = !state.world.province_get_is_colonial(state.world.state_instance_get_capital(sid));
1340
1341 bool is_civilized = state.world.nation_get_is_civilized(n);
1342 int32_t num_factories = economy::state_factory_count(state, sid, n);
1343
1344 text::add_line(state, contents, "production_build_new_factory_tooltip");
1346 text::add_line_with_condition(state, contents, "factory_condition_1", is_civilized);
1347 text::add_line_with_condition(state, contents, "factory_condition_2", non_colonial);
1348
1349 if(n == state.local_player_nation) {
1350 auto rules = state.world.nation_get_combined_issue_rules(n);
1351 text::add_line_with_condition(state, contents, "factory_condition_3", (rules & issue_rule::build_factory) != 0);
1352 } else {
1353 text::add_line_with_condition(state, contents, "factory_upgrade_condition_4", state.world.nation_get_is_great_power(state.local_player_nation) && !state.world.nation_get_is_great_power(n));
1354
1355 text::add_line_with_condition(state, contents, "factory_upgrade_condition_5", state.world.nation_get_is_civilized(n));
1356
1357 auto target = state.world.nation_get_combined_issue_rules(n);
1358 text::add_line_with_condition(state, contents, "factory_upgrade_condition_6",
1359 (target & issue_rule::allow_foreign_investment) != 0);
1360
1361 text::add_line_with_condition(state, contents, "factory_upgrade_condition_7", !military::are_at_war(state, state.local_player_nation, n));
1362 }
1363
1364 {
1365 auto box = text::open_layout_box(contents);
1366 auto r = num_factories < int32_t(state.defines.factories_per_state);
1367 if(r) {
1369 } else {
1371 }
1372 text::add_space_to_layout_box(state, contents, box);
1373 text::localised_single_sub_box(state, contents, box, "factory_condition_4", text::variable_type::val, int64_t(state.defines.factories_per_state));
1374 text::close_layout_box(contents, box);
1375 }
1376 }
1377};
1378
1380public:
1381 void on_update(sys::state& state) noexcept override {
1382 const dcon::state_instance_id sid = retrieve<dcon::state_instance_id>(state, parent);
1383 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1384
1385 bool can_build = false;
1386 state.world.for_each_factory_type([&](dcon::factory_type_id ftid) {
1387 can_build =
1388 can_build || command::can_begin_factory_building_construction(state, state.local_player_nation, sid, ftid, false);
1389 });
1390 disabled = !can_build;
1391 }
1392
1393 void button_action(sys::state& state) noexcept override {
1394 if(parent) {
1395 dcon::state_instance_id sid = retrieve<dcon::state_instance_id>(state, parent);
1396 send(state, parent, production_selection_wrapper{sid, true, xy_pair{0, 0}});
1397 }
1398 }
1399
1401 return tooltip_behavior::variable_tooltip;
1402 }
1403
1404 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1405 const dcon::state_instance_id sid = retrieve<dcon::state_instance_id>(state, parent);
1406 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1407
1408 bool non_colonial = !state.world.province_get_is_colonial(state.world.state_instance_get_capital(sid));
1409
1410 bool is_civilized = state.world.nation_get_is_civilized(n);
1411 int32_t num_factories = economy::state_factory_count(state, sid, n);
1412
1413 text::add_line(state, contents, "production_build_new_factory_tooltip");
1415 text::add_line_with_condition(state, contents, "factory_condition_1", is_civilized);
1416 text::add_line_with_condition(state, contents, "factory_condition_2", non_colonial);
1417
1418 if(n == state.local_player_nation) {
1419 auto rules = state.world.nation_get_combined_issue_rules(n);
1420 text::add_line_with_condition(state, contents, "factory_condition_3", (rules & issue_rule::build_factory) != 0);
1421 } else {
1422 text::add_line_with_condition(state, contents, "factory_upgrade_condition_4", state.world.nation_get_is_great_power(state.local_player_nation) && !state.world.nation_get_is_great_power(n));
1423
1424 text::add_line_with_condition(state, contents, "factory_upgrade_condition_5", state.world.nation_get_is_civilized(n));
1425
1426 auto target = state.world.nation_get_combined_issue_rules(n);
1427 text::add_line_with_condition(state, contents, "factory_upgrade_condition_6",
1428 (target & issue_rule::allow_foreign_investment) != 0);
1429
1430 text::add_line_with_condition(state, contents, "factory_upgrade_condition_7", !military::are_at_war(state, state.local_player_nation, n));
1431 }
1432
1433 {
1434 auto box = text::open_layout_box(contents);
1435 auto r = num_factories < int32_t(state.defines.factories_per_state);
1436 if(r) {
1438 } else {
1440 }
1441 text::add_space_to_layout_box(state, contents, box);
1442 text::localised_single_sub_box(state, contents, box, "factory_condition_4", text::variable_type::val, int64_t(state.defines.factories_per_state));
1443 text::close_layout_box(contents, box);
1444 }
1445 }
1446};
1447
1449 int32_t get_icon_frame(sys::state& state) noexcept {
1450 auto content = retrieve<dcon::state_instance_id>(state, parent);
1451 return bool(state.world.state_instance_get_owner_focus(content).id)
1452 ? state.world.state_instance_get_owner_focus(content).get_icon() - 1
1453 : 0;
1454 }
1455
1456public:
1457 void on_update(sys::state& state) noexcept override {
1458 auto content = retrieve<dcon::state_instance_id>(state, parent);
1459 dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1460 disabled = true;
1461 for(auto nfid : state.world.in_national_focus) {
1462 disabled = command::can_set_national_focus(state, state.local_player_nation, content, nfid) ? false : disabled;
1463 }
1464 frame = get_icon_frame(state);
1465 }
1466
1467 void button_action(sys::state& state) noexcept override {
1468 auto sid = retrieve<dcon::state_instance_id>(state, parent);
1469 send(state, parent, production_selection_wrapper{sid, false, base_data.position});
1470 }
1471
1472 void button_right_action(sys::state& state) noexcept override {
1473 auto sid = retrieve<dcon::state_instance_id>(state, parent);
1474 command::set_national_focus(state, state.local_player_nation, sid, dcon::national_focus_id{});
1475 }
1476
1478 return tooltip_behavior::variable_tooltip;
1479 }
1480
1481 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1482 auto box = text::open_layout_box(contents, 0);
1483
1484 auto sid = retrieve<dcon::state_instance_id>(state, parent);
1485 auto fat_si = dcon::fatten(state.world, sid);
1486 text::add_to_layout_box(state, contents, box, sid);
1488 auto content = state.world.state_instance_get_owner_focus(sid);
1489 if(bool(content)) {
1490 auto fat_nf = dcon::fatten(state.world, content);
1491 text::add_to_layout_box(state, contents, box, state.world.national_focus_get_name(content), text::substitution_map{});
1493 auto color = text::text_color::white;
1494 if(fat_nf.get_promotion_type()) {
1495 //Is the NF not optimal? Recolor it
1496 if(fat_nf.get_promotion_type() == state.culture_definitions.clergy) {
1497 if((fat_si.get_demographics(demographics::to_key(state, fat_nf.get_promotion_type())) / fat_si.get_demographics(demographics::total)) > state.defines.max_clergy_for_literacy) {
1498 color = text::text_color::red;
1499 }
1500 } else if(fat_nf.get_promotion_type() == state.culture_definitions.bureaucrat) {
1501 if(province::state_admin_efficiency(state, fat_si.id) > state.defines.max_bureaucracy_percentage) {
1502 color = text::text_color::red;
1503 }
1504 }
1505 auto full_str = text::format_percentage(fat_si.get_demographics(demographics::to_key(state, fat_nf.get_promotion_type())) / fat_si.get_demographics(demographics::total));
1506 text::add_to_layout_box(state, contents, box, std::string_view(full_str), color);
1507 }
1508 }
1509 text::close_layout_box(contents, box);
1510 if(auto mid = state.world.national_focus_get_modifier(content); mid) {
1511 modifier_description(state, contents, mid, 15);
1512 }
1513 text::add_line(state, contents, "alice_nf_controls");
1514 }
1515};
1516
1518 void on_update(sys::state& state) noexcept override {
1519 auto content = retrieve<dcon::state_instance_id>(state, parent);
1520 auto total = state.world.state_instance_get_demographics(content, demographics::to_key(state, state.culture_definitions.primary_factory_worker));
1521 auto employed = state.world.state_instance_get_demographics(content, demographics::to_employment_key(state, state.culture_definitions.primary_factory_worker));
1522 auto unemployed = total - employed;
1523 set_text(state, text::prettify(int64_t(unemployed)) + "/" + text::prettify(int64_t(employed)));
1524 }
1525 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1526 return tooltip_behavior::variable_tooltip;
1527 }
1528 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1529 auto content = retrieve<dcon::state_instance_id>(state, parent);
1530 auto total = state.world.state_instance_get_demographics(content, demographics::to_key(state, state.culture_definitions.primary_factory_worker));
1531 auto employed = state.world.state_instance_get_demographics(content, demographics::to_employment_key(state, state.culture_definitions.primary_factory_worker));
1532 auto unemployed = total - employed;
1533 text::add_line(state, contents, "alice_factory_worker_1", text::variable_type::x, text::pretty_integer{ int32_t(employed) });
1534 text::add_line(state, contents, "alice_factory_worker_2", text::variable_type::x, text::pretty_integer{ int32_t(unemployed) });
1535 }
1536};
1537
1539 void on_update(sys::state& state) noexcept override {
1540 auto content = retrieve<dcon::state_instance_id>(state, parent);
1541 auto total = state.world.state_instance_get_demographics(content, demographics::to_key(state, state.culture_definitions.secondary_factory_worker));
1542 auto employed = state.world.state_instance_get_demographics(content, demographics::to_employment_key(state, state.culture_definitions.secondary_factory_worker));
1543 auto unemployed = total - employed;
1544 set_text(state, text::prettify(int64_t(unemployed)) + "/" + text::prettify(int64_t(employed)));
1545 }
1546 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1547 return tooltip_behavior::variable_tooltip;
1548 }
1549 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1550 auto content = retrieve<dcon::state_instance_id>(state, parent);
1551 auto total = state.world.state_instance_get_demographics(content, demographics::to_key(state, state.culture_definitions.secondary_factory_worker));
1552 auto employed = state.world.state_instance_get_demographics(content, demographics::to_employment_key(state, state.culture_definitions.secondary_factory_worker));
1553 auto unemployed = total - employed;
1554 text::add_line(state, contents, "alice_factory_worker_1", text::variable_type::x, text::pretty_integer{ int32_t(employed) });
1555 text::add_line(state, contents, "alice_factory_worker_2", text::variable_type::x, text::pretty_integer{ int32_t(unemployed) });
1556 }
1557};
1558
1560 void on_update(sys::state& state) noexcept override {
1561 auto content = retrieve<dcon::state_instance_id>(state, parent);
1562 auto total = state.world.state_instance_get_demographics(content,
1564 if(total > 0)
1566 state.world.state_instance_get_demographics(content, demographics::to_key(state, state.culture_definitions.capitalists)) / total,
1567 1));
1568 else
1569 set_text(state, "0.0%");
1570 }
1571};
1572
1573
1575 void on_update(sys::state& state) noexcept override {
1576 auto content = retrieve<dcon::state_instance_id>(state, parent);
1577 float total = 0.0f;
1578 float p_total = 0.0f;
1579 province::for_each_province_in_state_instance(state, content, [&](dcon::province_id p) {
1580 total += state.economy_definitions.building_definitions[int32_t(economy::province_building_type::railroad)].infrastructure * float(state.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad)));
1581 p_total += 1.0f;
1582 });
1583 set_text(state, text::format_float(p_total > 0 ? total / p_total : 0.0f, 3));
1584 }
1585};
1586
1587class production_state_info : public listbox_row_element_base<dcon::state_instance_id> {
1588public:
1590 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1591 if(name == "state_focus") {
1592 return make_element_by_type<production_national_focus_button>(state, id);
1593 } else if(name == "state_name") {
1594 return make_element_by_type<state_name_text>(state, id);
1595 } else if(name == "factory_count") {
1596 auto temp = make_element_by_type<state_factory_count_text>(state, id);
1597 memcpy(&factory_number_def, &(temp->base_data), sizeof(ui::element_data));
1598 return temp;
1599 } else if(name == "build_new_factory") {
1600 return make_element_by_type<production_build_new_factory>(state, id);
1601 } else if(name == "avg_infra_text") {
1602 return make_element_by_type<state_infrastructure>(state, id);
1603 } else if(name == "factory_info_bounds") {
1604 return make_element_by_type<production_factory_info_bounds_window>(state, id);
1605 } else {
1606 return nullptr;
1607 }
1608 }
1609 void on_create(sys::state& state) noexcept override {
1611 constexpr int16_t num_cols = 8;
1612 base_data.size.y += state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("factory_info"))->second.definition].size.y
1613 * (((int16_t(state.defines.factories_per_state) + num_cols - 1) / num_cols) - 1);
1614 // (8 + 7 - 1) - 1 = (8 + 6) - 1 = (14 / 8) - 1 ~= 1.75 rundown 1 - 1 = 0, ok
1615
1616 xy_pair base_sort_template_offset =
1617 state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("sort_by_pop_template_offset"))->second.definition].position;
1618
1619 {
1620 auto text_elm = std::make_unique< per_state_primary_worker_amount>();
1621 memcpy(&(text_elm->base_data), &factory_number_def, sizeof(ui::element_data));
1622 text_elm->base_data.position.x = int16_t(500 + base_sort_template_offset.x * 0);
1623 text_elm->on_create(state);
1624 add_child_to_front(std::move(text_elm));
1625 }
1626 {
1627 auto text_elm = std::make_unique< per_state_secondary_worker_amount>();
1628 memcpy(&(text_elm->base_data), &factory_number_def, sizeof(ui::element_data));
1629 text_elm->base_data.position.x = int16_t(500 + base_sort_template_offset.x * 1);
1630 text_elm->on_create(state);
1631 add_child_to_front(std::move(text_elm));
1632 }
1633 {
1634 auto text_elm = std::make_unique< per_state_capitalist_amount>();
1635 memcpy(&(text_elm->base_data), &factory_number_def, sizeof(ui::element_data));
1636 text_elm->base_data.position.x = int16_t(500 + base_sort_template_offset.x * 2);
1637 text_elm->on_create(state);
1638 add_child_to_front(std::move(text_elm));
1639 }
1640 }
1641};
1642
1643void populate_production_states_list(sys::state& state, std::vector<dcon::state_instance_id>& row_contents, dcon::nation_id n, bool show_empty, production_sort_order sort_order);
1644
1646 dcon::nation_id n;
1647};
1648
1649class production_state_invest_listbox : public listbox_element_base<production_state_info, dcon::state_instance_id> {
1650protected:
1651 std::string_view get_row_element_name() override {
1652 return "state_info";
1653 }
1654
1655public:
1656 production_sort_order sort_order = production_sort_order::name;
1657
1658 void on_update(sys::state& state) noexcept override {
1659 row_contents.clear();
1660 if(parent) {
1661 auto show_empty = retrieve<bool>(state, parent);
1662 dcon::nation_id n = retrieve<production_foreign_invest_target>(state, parent).n;
1663
1664 populate_production_states_list(state, row_contents, n, show_empty, sort_order);
1665 }
1666 update(state);
1667 }
1668
1669 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1670 if(payload.holds_type<dcon::nation_id>()) {
1671 payload.emplace<dcon::nation_id>(retrieve<production_foreign_invest_target>(state, parent).n);
1672 return message_result::consumed;
1673 }
1674 return message_result::unseen;
1675 }
1676};
1677
1678class production_state_listbox : public listbox_element_base<production_state_info, dcon::state_instance_id> {
1679protected:
1680 std::string_view get_row_element_name() override {
1681 return "state_info";
1682 }
1683
1684public:
1685 production_sort_order sort_order = production_sort_order::name;
1686
1687 void on_update(sys::state& state) noexcept override {
1688 row_contents.clear();
1689 if(parent) {
1690 auto show_empty = retrieve<bool>(state, parent);
1691 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1692 populate_production_states_list(state, row_contents, n, show_empty, sort_order);
1693 }
1694 update(state);
1695 }
1696};
1697
1699 simple_text_element_base* goods_cat_name = nullptr;
1700
1701 std::string_view get_commodity_group_name(sys::commodity_group g) {
1702 switch(g) {
1704 return "military_goods";
1706 return "raw_material_goods";
1708 return "industrial_goods";
1710 return "consumer_goods";
1711 // Non-vanilla
1713 return "industrial_and_consumer_goods";
1714 default:
1715 return "???";
1716 }
1717 }
1718
1719public:
1720 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1721 if(name == "cat_name") {
1722 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
1723 goods_cat_name = ptr.get();
1724 return ptr;
1725 } else {
1726 return nullptr;
1727 }
1728 }
1729
1730 message_result set(sys::state& state, Cyto::Any& payload) noexcept override {
1731 if(payload.holds_type<sys::commodity_group>()) {
1732 auto group = any_cast<sys::commodity_group>(payload);
1733 goods_cat_name->set_text(state, text::produce_simple_string(state, get_commodity_group_name(group)));
1734 return message_result::consumed;
1735 }
1736 return message_result::unseen;
1737 }
1738};
1739
1741 dcon::nation_id id;
1742};
1743
1745 .sortable = true,
1746 .header = "method_name",
1747 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1748 auto av = text::produce_simple_string(state, state.world.factory_type_get_name(a));
1749 auto bv = text::produce_simple_string(state, state.world.factory_type_get_name(b));
1750 if(av != bv)
1751 return av > bv;
1752 else
1753 return a.index() < b.index();
1754 },
1755 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1756 auto item = state.world.factory_type_get_output(id).id;
1757 std::string padding = item.index() < 10 ? "0" : "";
1758 std::string description = "@$" + padding + std::to_string(item.index());
1759
1760 auto value = description + text::produce_simple_string(state, state.world.factory_type_get_name(id));
1761 return value;
1762 },
1763 .cell_definition_string = "thin_cell_name",
1764 .header_definition_string = "thin_cell_name"
1765};
1766
1768 .sortable = true,
1769 .header = "method_input",
1770 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1771 auto nation = retrieve<dcon::nation_id>(state, container);
1772 auto market = retrieve<dcon::market_id>(state, container);
1773
1774 auto av = economy::factory_type_input_cost(state, nation, market, a);
1775 auto bv = economy::factory_type_input_cost(state, nation, market, b);
1776 if(av != bv)
1777 return av > bv;
1778 else
1779 return a.index() < b.index();
1780 },
1781 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1782 auto nation = retrieve<dcon::nation_id>(state, container);
1783 auto market = retrieve<dcon::market_id>(state, container);
1784
1785 auto value = economy::factory_type_input_cost(state, nation, market, id);
1786 return text::format_money(value);
1787 },
1788};
1789
1791 .sortable = true,
1792 .header = "method_output",
1793 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1794 auto nation = retrieve<dcon::nation_id>(state, container);
1795 auto market = retrieve<dcon::market_id>(state, container);
1796
1797 auto av = economy::factory_type_output_cost(state, nation, market, a);
1798 auto bv = economy::factory_type_output_cost(state, nation, market, b);
1799 if(av != bv)
1800 return av > bv;
1801 else
1802 return a.index() < b.index();
1803 },
1804 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1805 auto nation = retrieve<dcon::nation_id>(state, container);
1806 auto market = retrieve<dcon::market_id>(state, container);
1807
1808 auto value = economy::factory_type_output_cost(state, nation, market, id);
1809 return text::format_money(value);
1810 },
1811};
1812
1814 .sortable = true,
1815 .header = "method_profit",
1816 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1817 auto nation = retrieve<dcon::nation_id>(state, container);
1818 auto market = retrieve<dcon::market_id>(state, container);
1819
1820 auto av = economy::factory_type_output_cost(state, nation, market, a)
1821 - economy::factory_type_input_cost(state, nation, market, a);
1822 auto bv = economy::factory_type_output_cost(state, nation, market, b)
1823 - economy::factory_type_input_cost(state, nation, market, b);
1824 if(av != bv)
1825 return av > bv;
1826 else
1827 return a.index() < b.index();
1828 },
1829 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1830 auto nation = retrieve<dcon::nation_id>(state, container);
1831 auto market = retrieve<dcon::market_id>(state, container);
1832
1833 auto value = economy::factory_type_output_cost(state, nation, market, id)
1834 - economy::factory_type_input_cost(state, nation, market, id);
1835 return text::format_money(value);
1836 },
1837};
1838
1840 .sortable = true,
1841 .header = "method_margin",
1842 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1843 auto nation = retrieve<dcon::nation_id>(state, container);
1844 auto market = retrieve<dcon::market_id>(state, container);
1845
1846 auto av = economy::factory_type_output_cost(state, nation, market, a)
1847 - economy::factory_type_input_cost(state, nation, market, a);
1848 auto bv = economy::factory_type_output_cost(state, nation, market, b)
1849 - economy::factory_type_input_cost(state, nation, market, b);
1850
1851 av /= economy::factory_type_output_cost(state, nation, market, a);
1852 bv /= economy::factory_type_output_cost(state, nation, market, b);
1853
1854 if(av != bv)
1855 return av > bv;
1856 else
1857 return a.index() < b.index();
1858 },
1859 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1860 auto nation = retrieve<dcon::nation_id>(state, container);
1861 auto market = retrieve<dcon::market_id>(state, container);
1862
1863 auto value = economy::factory_type_output_cost(state, nation, market, id)
1864 - economy::factory_type_input_cost(state, nation, market, id);
1865 value /= economy::factory_type_output_cost(state, nation, market, id);
1866 return text::format_percentage(value, 2);
1867 },
1868};
1869
1871 .sortable = true,
1872 .header = "method_cost",
1873 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1874 auto nation = retrieve<dcon::nation_id>(state, container);
1875 auto market = retrieve<dcon::market_id>(state, container);
1876
1877 auto av = economy::factory_type_build_cost(state, nation, market, a);
1878 auto bv = economy::factory_type_build_cost(state, nation, market, b);
1879
1880 if(av != bv)
1881 return av > bv;
1882 else
1883 return a.index() < b.index();
1884 },
1885 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1886 auto nation = retrieve<dcon::nation_id>(state, container);
1887 auto market = retrieve<dcon::market_id>(state, container);
1888
1889 auto value = economy::factory_type_build_cost(state, nation, market, id);
1890 return text::format_money(value);
1891 },
1892};
1893
1895 .sortable = true,
1896 .header = "method_payback",
1897 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1898 auto nation = retrieve<dcon::nation_id>(state, container);
1899 auto market = retrieve<dcon::market_id>(state, container);
1900
1901 auto av = economy::factory_type_output_cost(state, nation, market, a)
1902 - economy::factory_type_input_cost(state, nation, market, a);
1903 auto bv = economy::factory_type_output_cost(state, nation, market, b)
1904 - economy::factory_type_input_cost(state, nation, market, b);
1905 av = std::max(0.f, av);
1906 bv = std::max(0.f, bv);
1907 av = economy::factory_type_build_cost(state, nation, market, a) / av;
1908 bv = economy::factory_type_build_cost(state, nation, market, b) / bv;
1909
1910 if(av != bv)
1911 return av > bv;
1912 else
1913 return a.index() < b.index();
1914 },
1915 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1916 auto nation = retrieve<dcon::nation_id>(state, container);
1917 auto market = retrieve<dcon::market_id>(state, container);
1918
1919 auto value = economy::factory_type_output_cost(state, nation, market, id)
1920 - economy::factory_type_input_cost(state, nation, market, id);
1921 value = std::max(0.f, value);
1922 value = economy::factory_type_build_cost(state, nation, market, id) / value;
1923
1924 return text::format_float(value);
1925 },
1926};
1927
1929 .sortable = true,
1930 .header = "method_research",
1931 .compare = [](sys::state& state, element_base* container, dcon::factory_type_id a, dcon::factory_type_id b) {
1932 auto nation = retrieve<dcon::nation_id>(state, container);
1933 auto market = retrieve<dcon::market_id>(state, container);
1934
1935 auto av = state.world.nation_get_factory_type_experience(nation, a);
1936 auto bv = state.world.nation_get_factory_type_experience(nation, b);
1937
1938 if(av != bv)
1939 return av > bv;
1940 else
1941 return a.index() < b.index();
1942 },
1943 .view = [](sys::state& state, element_base* container, dcon::factory_type_id id) {
1944 auto nation = retrieve<dcon::nation_id>(state, container);
1945 auto market = retrieve<dcon::market_id>(state, container);
1946
1947 auto value = state.world.nation_get_factory_type_experience(nation, id);
1948
1949 return text::format_float(value);
1950 },
1951};
1952
1953class production_window : public generic_tabbed_window<production_window_tab> {
1954 bool show_empty_states = true;
1955 std::unique_ptr<bool[]> show_output_commodity;
1956
1957 production_state_listbox* state_listbox = nullptr;
1958 production_state_invest_listbox* state_listbox_invest = nullptr;
1959 element_base* nf_win = nullptr;
1960 element_base* build_win = nullptr;
1961 element_base* project_window = nullptr;
1962 production_foreign_investment_window* foreign_invest_win = nullptr;
1963
1964 sys::commodity_group curr_commodity_group{};
1965 dcon::state_instance_id focus_state{};
1966 dcon::nation_id foreign_nation{};
1967 xy_pair base_commodity_offset{33, 50};
1968 xy_pair commodity_offset{33, 50};
1969
1970 std::vector<element_base*> factory_elements;
1971 std::vector<element_base*> investment_brow_elements;
1972 std::vector<element_base*> project_elements;
1973 std::vector<element_base*> good_elements;
1974 std::vector<element_base*> investment_nation;
1975 std::vector<bool> commodity_filters;
1976 bool open_foreign_invest = false;
1977
1978 void set_visible_vector_elements(sys::state& state, std::vector<element_base*>& elements, bool v) noexcept {
1979 for(auto element : elements)
1980 element->set_visible(state, v);
1981 }
1982
1983 void hide_sub_windows(sys::state& state) noexcept {
1984 set_visible_vector_elements(state, factory_elements, false);
1985 set_visible_vector_elements(state, investment_brow_elements, false);
1986 set_visible_vector_elements(state, project_elements, false);
1987 set_visible_vector_elements(state, good_elements, false);
1988 set_visible_vector_elements(state, investment_nation, false);
1989 }
1990
1991public:
1992 void on_create(sys::state& state) noexcept override {
1993 generic_tabbed_window::on_create(state);
1994
1995 // All filters enabled by default
1996 commodity_filters.resize(state.world.commodity_size(), true);
1997
1998 {
1999 auto ptr = make_element_by_type<national_focus_window>(state, "state_focus_window");
2000 ptr->set_visible(state, false);
2001 nf_win = ptr.get();
2002 add_child_to_front(std::move(ptr));
2003 }
2004
2005 auto win = make_element_by_type<factory_build_window>(state, state.ui_state.defs_by_name.find(state.lookup_key("build_factory"))->second.definition);
2006 build_win = win.get();
2007 add_child_to_front(std::move(win));
2008
2009 auto win2 = make_element_by_type<project_investment_window>(state,
2010 state.ui_state.defs_by_name.find(state.lookup_key("invest_project_window"))->second.definition);
2011 win2->set_visible(state, false);
2012 project_window = win2.get();
2013 add_child_to_front(std::move(win2));
2014
2015 show_output_commodity = std::unique_ptr<bool[]>(new bool[state.world.commodity_size()]);
2016 set_visible(state, false);
2017 }
2018 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
2019 if(name == "main_bg") {
2020 return make_element_by_type<image_element_base>(state, id);
2021 } else if(name == "table_production_methods") {
2022 std::vector<table::column<dcon::factory_type_id>> columns = {
2031 };
2032
2033 auto ptr = make_element_by_type<table::display<dcon::factory_type_id>>(
2034 state,
2035 id,
2036 std::string("table_production_methods_body"),
2037 columns
2038 );
2039 ptr->set_visible(state, false);
2040
2041 state.world.for_each_factory_type([&](dcon::factory_type_id ft) {
2042 ptr->content.data.push_back(ft);
2043 });
2044
2045 good_elements.push_back(ptr.get());
2046 return ptr;
2047 } else if(name == "prod_bg") {
2048 return make_element_by_type<opaque_element_base>(state, id);
2049 } else if(name == "close_button") {
2050 return make_element_by_type<generic_close_button>(state, id);
2051 } else if(name == "tab_factories") {
2052 auto ptr = make_element_by_type<generic_tab_button<production_window_tab>>(state, id);
2053 ptr->target = production_window_tab::factories;
2054 return ptr;
2055 } else if(name == "tab_invest") {
2056 auto ptr = make_element_by_type<generic_tab_button<production_window_tab>>(state, id);
2057 ptr->target = production_window_tab::investments;
2058 return ptr;
2059 } else if(name == "tab_popprojects") {
2060 auto ptr = make_element_by_type<generic_tab_button<production_window_tab>>(state, id);
2061 ptr->target = production_window_tab::projects;
2062 return ptr;
2063 } else if(name == "tab_goodsproduction") {
2064 auto ptr = make_element_by_type<generic_tab_button<production_window_tab>>(state, id);
2065 ptr->target = production_window_tab::goods;
2066 return ptr;
2067 } else if(name == "tab_factories_text") {
2068 return make_element_by_type<invisible_element>(state, id);
2069 } else if(name == "tab_invest_text") {
2070 return make_element_by_type<invisible_element>(state, id);
2071 } else if(name == "tab_goodsproduction_text") {
2072 return make_element_by_type<invisible_element>(state, id);
2073 } else if(name == "tab_popprojects_text") {
2074 return make_element_by_type<invisible_element>(state, id);
2075 } else if(name == "factory_buttons") {
2076 auto ptr = make_element_by_type<factory_buttons_window>(state, id);
2077 factory_elements.push_back(ptr.get());
2078 ptr->set_visible(state, true);
2079 return ptr;
2080 } else if(name == "invest_buttons") {
2081 auto ptr = make_element_by_type<production_foreign_investment_window>(state, id);
2082 foreign_invest_win = ptr.get();
2083 investment_nation.push_back(ptr.get());
2084 ptr->set_visible(state, false);
2085 return ptr;
2086 } else if(name == "state_listbox") {
2087 auto ptr = make_element_by_type<production_state_listbox>(state, id);
2088 state_listbox = ptr.get();
2089 factory_elements.push_back(ptr.get());
2090 ptr->set_visible(state, true);
2091 return ptr;
2092 } else if(name == "state_listbox_invest") {
2093 auto ptr = make_element_by_type<production_state_invest_listbox>(state, id);
2094 state_listbox_invest = ptr.get();
2095 investment_nation.push_back(ptr.get());
2096 ptr->set_visible(state, false);
2097 return ptr;
2098 } else if(name == "investment_browser") {
2099 auto ptr = make_element_by_type<invest_brow_window>(state, id);
2100 investment_brow_elements.push_back(ptr.get());
2101 ptr->set_visible(state, false);
2102 return ptr;
2103 } else if(name == "sort_by_state") {
2104 auto ptr = make_element_by_type<button_element_base>(state, id);
2105 project_elements.push_back(ptr.get());
2106 ptr->set_visible(state, false);
2107 return ptr;
2108 } else if(name == "sort_by_projects") {
2109 auto ptr = make_element_by_type<button_element_base>(state, id);
2110 project_elements.push_back(ptr.get());
2111 ptr->set_visible(state, false);
2112 return ptr;
2113 } else if(name == "sort_by_completion") {
2114 auto ptr = make_element_by_type<button_element_base>(state, id);
2115 project_elements.push_back(ptr.get());
2116 ptr->set_visible(state, false);
2117 return ptr;
2118 } else if(name == "sort_by_projecteers") {
2119 auto ptr = make_element_by_type<button_element_base>(state, id);
2120 project_elements.push_back(ptr.get());
2121 ptr->set_visible(state, false);
2122 return ptr;
2123 } else if(name == "pop_sort_buttons") {
2124 auto ptr = make_element_by_type<pop_sort_buttons_window>(state, id);
2125 factory_elements.push_back(ptr.get());
2126 ptr->set_visible(state, true);
2127 return ptr;
2128 } else if(name == "project_listbox") {
2129 auto ptr = make_element_by_type<production_project_listbox>(state, id);
2130 project_elements.push_back(ptr.get());
2131 ptr->set_visible(state, false);
2132 return ptr;
2133 } else {
2134 return nullptr;
2135 }
2136 }
2137
2138 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
2139 if(payload.holds_type<production_window_tab>()) {
2140 auto enum_val = any_cast<production_window_tab>(payload);
2141 hide_sub_windows(state);
2142 switch(enum_val) {
2143 case production_window_tab::factories:
2144 set_visible_vector_elements(state, factory_elements, true);
2145 break;
2146 case production_window_tab::investments:
2147 set_visible_vector_elements(state, investment_brow_elements, true);
2148 foreign_invest_win->set_visible(state, open_foreign_invest);
2149 break;
2150 case production_window_tab::projects:
2151 set_visible_vector_elements(state, project_elements, true);
2152 break;
2153 case production_window_tab::goods:
2154 set_visible_vector_elements(state, good_elements, true);
2155 break;
2156 }
2157 active_tab = enum_val;
2158 return message_result::consumed;
2159 } else if(payload.holds_type<production_foreign_invest_target>()) {
2161 return message_result::consumed;
2162 } else if(payload.holds_type<open_investment_nation>()) {
2163 hide_sub_windows(state);
2164 auto target = any_cast<open_investment_nation>(payload).id;
2165 active_tab = production_window_tab::investments;
2166 foreign_invest_win->curr_nation = target;
2167 set_visible_vector_elements(state, investment_nation, true);
2168 return message_result::consumed;
2169 } else if(payload.holds_type<production_sort_order>()) {
2170 auto sort_type = any_cast<production_sort_order>(payload);
2171 state_listbox->sort_order = sort_type;
2172 if(state_listbox->is_visible())
2173 state_listbox->impl_on_update(state);
2174 state_listbox_invest->sort_order = sort_type;
2175 if(state_listbox_invest->is_visible())
2176 state_listbox_invest->impl_on_update(state);
2177 } else if(payload.holds_type<dcon::state_instance_id>()) {
2178 payload.emplace<dcon::state_instance_id>(focus_state);
2179 return message_result::consumed;
2180 } else if(payload.holds_type<dcon::market_id>()) {
2181 auto capitol = state.world.nation_get_capital(state.local_player_nation);
2182 auto s = state.world.province_get_state_membership(capitol);
2183 auto m = state.world.state_instance_get_market_from_local_market(s);
2184 payload.emplace<dcon::market_id>(m);
2185 return message_result::consumed;
2186 } else if(payload.holds_type<production_selection_wrapper>()) {
2187 auto data = any_cast<production_selection_wrapper>(payload);
2188 focus_state = data.data;
2189 if(data.is_build) {
2190 build_win->set_visible(state, true);
2191 move_child_to_front(build_win);
2192 } else {
2193 nf_win->set_visible(state, true);
2194 nf_win->base_data.position = data.focus_pos;
2195 move_child_to_front(nf_win);
2196 }
2197 impl_on_update(state);
2198 return message_result::consumed;
2199 } else if(payload.holds_type<bool>()) {
2200 payload.emplace<bool>(show_empty_states);
2201 return message_result::consumed;
2202 } else if(payload.holds_type<element_selection_wrapper<bool>>()) {
2203 show_empty_states = any_cast<element_selection_wrapper<bool>>(payload).data;
2204 impl_on_update(state);
2205 return message_result::consumed;
2206 } else if(payload.holds_type<commodity_filter_query_data>()) {
2207 auto content = any_cast<commodity_filter_query_data>(payload);
2208 content.filter = commodity_filters[content.cid.index()];
2209 payload.emplace<commodity_filter_query_data>(content);
2210 return message_result::consumed;
2211 } else if(payload.holds_type<commodity_filter_toggle_data>()) {
2212 auto content = any_cast<commodity_filter_toggle_data>(payload);
2213 commodity_filters[content.data.index()] = !commodity_filters[content.data.index()];
2214 impl_on_update(state);
2215 return message_result::consumed;
2216 } else if(payload.holds_type<element_selection_wrapper<production_action>>()) {
2217 auto content = any_cast<element_selection_wrapper<production_action>>(payload).data;
2218 switch(content) {
2219 case production_action::investment_window:
2220 project_window->is_visible() ? project_window->set_visible(state, false) : project_window->set_visible(state, true);
2221 break;
2222 case production_action::foreign_invest_window:
2223 foreign_invest_win->is_visible() ? foreign_invest_win->set_visible(state, false) : foreign_invest_win->set_visible(state, true);
2224 break;
2225 default:
2226 break;
2227 }
2228 impl_on_update(state);
2229 return message_result::consumed;
2230 } else if(payload.holds_type<element_selection_wrapper<dcon::nation_id>>()) {
2231 foreign_nation = any_cast<element_selection_wrapper<dcon::nation_id>>(payload).data;
2232 open_foreign_invest = true;
2233 foreign_invest_win->set_visible(state, true);
2234 return message_result::consumed;
2235 } else if(payload.holds_type<dcon::nation_id>()) {
2236 if(foreign_invest_win->is_visible())
2237 payload.emplace<dcon::nation_id>(foreign_nation);
2238 else
2239 payload.emplace<dcon::nation_id>(state.local_player_nation);
2240 return message_result::consumed;
2241 }
2242 return message_result::unseen;
2243 }
2244};
2245
2246void open_foreign_investment(sys::state& state, dcon::nation_id n);
2247void open_build_foreign_factory(sys::state& state, dcon::state_instance_id st);
2248
2249} // namespace ui
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
void impl_on_update(sys::state &state) noexcept override
element_base * parent
virtual message_result test_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
bool is_visible() const
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
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 on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(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 button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
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
message_result test_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
void render(sys::state &state, int32_t x, int32_t y) 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 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 update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void button_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
tooltip_behavior has_tooltip(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 render(sys::state &state, int32_t x, int32_t y) 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 button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_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
void button_action(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 button_ctrl_shift_action(sys::state &state) noexcept override
void button_shift_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_ctrl_shift_right_action(sys::state &state) noexcept override
void button_ctrl_right_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_ctrl_action(sys::state &state) noexcept override
void button_shift_right_action(sys::state &state) noexcept override
void button_right_action(sys::state &state) noexcept override
void button_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 render(sys::state &state, int32_t x, int32_t y) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
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
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(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 on_update(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(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
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
message_result set(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
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_right_action(sys::state &state) noexcept override
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
void button_action(sys::state &state) noexcept 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
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept 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
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
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
void button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
bool can_cancel_factory_building_construction(sys::state &state, dcon::nation_id source, dcon::state_instance_id location, dcon::factory_type_id type)
Definition: commands.cpp:474
bool can_delete_factory(sys::state &state, dcon::nation_id source, dcon::factory_id f)
Definition: commands.cpp:802
bool can_begin_factory_building_construction(sys::state &state, dcon::nation_id source, dcon::state_instance_id location, dcon::factory_type_id type, bool is_upgrade)
Definition: commands.cpp:512
bool can_change_factory_settings(sys::state &state, dcon::nation_id source, dcon::factory_id f, uint8_t priority, bool subsidized)
Definition: commands.cpp:845
bool can_set_national_focus(sys::state &state, dcon::nation_id source, dcon::state_instance_id target_state, dcon::national_focus_id focus)
Definition: commands.cpp:122
void set_national_focus(sys::state &state, dcon::nation_id source, dcon::state_instance_id target_state, dcon::national_focus_id focus)
Definition: commands.cpp:111
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
dcon::demographics_key to_employment_key(sys::state const &state, dcon::pop_type_id v)
float factory_input_total_cost(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
Definition: economy.cpp:2263
float factory_throughput_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s)
Definition: economy.cpp:2362
float factory_max_production_scale(sys::state const &state, dcon::factory_id fac, float mobilization_impact, bool occupied)
Definition: economy.cpp:2400
float factory_min_e_input_available(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
Definition: economy.cpp:2276
float factory_type_output_cost(sys::state &state, dcon::nation_id n, dcon::market_id m, dcon::factory_type_id factory_type)
Definition: economy.cpp:7578
void for_each_new_factory(sys::state &state, dcon::state_instance_id s, F &&func)
float factory_e_input_total_cost(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
Definition: economy.cpp:2294
float factory_desired_raw_profit(dcon::factory_id fac, float spendings)
Definition: economy.cpp:2408
float factory_max_employment(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:2007
int32_t state_factory_count(sys::state &state, dcon::state_instance_id sid, dcon::nation_id n)
Definition: economy.cpp:8347
float factory_min_input_available(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
Definition: economy.cpp:2242
float factory_input_multiplier(sys::state const &state, dcon::factory_id fac, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s)
Definition: economy.cpp:2329
float price(sys::state const &state, dcon::state_instance_id s, dcon::commodity_id c)
Definition: economy.cpp:150
int32_t factory_priority(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1885
constexpr float factory_closed_threshold
Definition: economy.hpp:125
float factory_type_build_cost(sys::state &state, dcon::nation_id n, dcon::market_id m, dcon::factory_type_id factory_type)
Definition: economy.cpp:7559
void for_each_upgraded_factory(sys::state &state, dcon::state_instance_id s, F &&func)
float pop_min_wage_factor(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:16
std::vector< dcon::factory_type_id > commodity_get_factory_types_as_output(sys::state const &state, dcon::commodity_id output_good)
Definition: economy.cpp:883
float factory_type_input_cost(sys::state &state, dcon::nation_id n, dcon::market_id m, dcon::factory_type_id factory_type)
Definition: economy.cpp:7591
float factory_output_multiplier(sys::state const &state, dcon::factory_id fac, dcon::nation_id n, dcon::market_id m, dcon::province_id p)
Definition: economy.cpp:2386
constexpr uint32_t build_factory
Definition: culture.hpp:8
constexpr uint32_t can_subsidise
Definition: culture.hpp:13
constexpr uint32_t allow_foreign_investment
Definition: culture.hpp:26
constexpr uint32_t factory_priority
Definition: culture.hpp:12
constexpr uint32_t expand_factory
Definition: culture.hpp:9
float mobilization_impact(sys::state const &state, dcon::nation_id n)
Definition: military.cpp:1344
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:649
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
float state_admin_efficiency(sys::state &state, dcon::state_instance_id id)
Definition: province.cpp:553
commodity_group
Definition: constants.hpp:223
void add_line_break_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1147
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
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1823
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:1612
void localised_single_sub_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, variable_type subkey, substitution value)
Definition: text.cpp:1912
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
std::string prettify(int64_t num)
Definition: text.cpp:762
std::string format_float(float num, size_t digits)
Definition: text.cpp:981
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1923
void add_line_with_condition(sys::state &state, layout_base &dest, std::string_view key, bool condition_met, int32_t indent)
Definition: text.cpp:1979
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:797
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
void add_space_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1812
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1831
void modifier_description(sys::state &state, text::layout_base &layout, dcon::modifier_id mid, int32_t indentation=0)
production_sort_order
Definition: constants.hpp:584
table::column< dcon::factory_type_id > factory_type_payback
table::column< dcon::factory_type_id > factory_type_profit
table::column< dcon::factory_type_id > factory_type_output_cost
table::column< dcon::factory_type_id > factory_type_cost
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
table::column< dcon::factory_type_id > factory_type_research
table::column< dcon::factory_type_id > factory_type_profit_margin
message_result
void populate_production_states_list(sys::state &state, std::vector< dcon::state_instance_id > &row_contents, dcon::nation_id n, bool show_empty, production_sort_order sort_order)
production_window_tab
Definition: constants.hpp:585
table::column< dcon::factory_type_id > factory_type_name
table::column< dcon::factory_type_id > factory_type_input_cost
void active_modifiers_description(sys::state &state, text::layout_base &layout, dcon::nation_id n, int32_t identation, dcon::national_modifier_value nmid, bool header)
uint uint32_t
uchar uint8_t
static constexpr uint32_t set_size
static constexpr uint32_t set_size
dcon::factory_type_id type
Definition: economy.hpp:545
Holds important data about the game world, state, and other data regarding windowing,...
int32_t x_size
Definition: text.hpp:830
float x_position
Definition: text.hpp:833
std::variant< std::monostate, economy::upgraded_factory, economy::new_factory > activity
element_base * topbar_subwindow
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
std::unique_ptr< element_base > root
element_base * production_subwindow