Project Alice
Loading...
Searching...
No Matches
gui_pick_wargoal_window.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace ui {
4
5
7public:
8 void button_action(sys::state& state) noexcept override {
10 }
11};
12
13
15public:
16 void on_update(sys::state& state) noexcept override {
17 auto content = retrieve<dcon::cb_type_id>(state, parent);
18 frame = (dcon::fatten(state.world, content).get_sprite_index() - 1);
19 }
20};
21
23public:
24 void button_action(sys::state& state) noexcept override {
25 dcon::cb_type_id content = retrieve<dcon::cb_type_id>(state, parent);
26 dcon::cb_type_id selected = parent ? retrieve<dcon::cb_type_id>(state, parent->parent) : dcon::cb_type_id{};
27 if(content == selected)
29 else
31 }
32
33 void on_update(sys::state& state) noexcept override {
34 dcon::cb_type_id content = retrieve<dcon::cb_type_id>(state, parent);
35 dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
36 auto target_state = retrieve<dcon::state_definition_id>(state, parent);
37
38 auto war = retrieve<dcon::war_id>(state, parent);
39 auto cb_infamy = !war
40 ? (military::has_truce_with(state, state.local_player_nation, target)
41 ? military::truce_break_cb_infamy(state, content, target)
42 : military::cb_infamy(state, content, target, target_state))
43 : military::cb_addition_infamy_cost(state, war, content, state.local_player_nation, target, target_state);
44 if(state.world.nation_get_infamy(state.local_player_nation) + cb_infamy >= state.defines.badboy_limit) {
45 color = sys::pack_color(255, 196, 196);
46 } else {
47 color = sys::pack_color(255, 255, 255);
48 }
49
50 auto fat_id = dcon::fatten(state.world, content);
52 }
53
56 }
57 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
58 dcon::cb_type_id content = retrieve<dcon::cb_type_id>(state, parent);
59 dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
60 auto war = retrieve<dcon::war_id>(state, parent);
61 auto cb_infamy = !war
62 ? (military::has_truce_with(state, state.local_player_nation, target)
63 ? military::truce_break_cb_infamy(state, content, target)
64 : 0.f)
65 : military::cb_addition_infamy_cost(state, war, content, state.local_player_nation, target);
66 if(state.world.nation_get_infamy(state.local_player_nation) + cb_infamy >= state.defines.badboy_limit) {
67 text::add_line(state, contents, "alice_tt_wg_infamy_limit");
68 }
69
70 auto fat_id = dcon::fatten(state.world, content);
71 if(fat_id.get_can_use()) {
72 text::add_line(state, contents, "tt_can_use_nation");
73 trigger_description(state, contents, fat_id.get_can_use(), trigger::to_generic(target), trigger::to_generic(state.local_player_nation), trigger::to_generic(target));
74 }
75 if(auto allowed_substates = fat_id.get_allowed_substate_regions(); allowed_substates) {
76 text::add_line_with_condition(state, contents, "is_substate", state.world.nation_get_is_substate(target));
77 if(state.world.nation_get_is_substate(target)) {
78 auto ruler = state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(target));
79 trigger_description(state, contents, allowed_substates, trigger::to_generic(ruler), trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation));
80 }
81 }
82 text::add_line(state, contents, "et_on_add");
83 effect_description(state, contents, fat_id.get_on_add(), trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation), trigger::to_generic(target),
84 uint32_t(state.current_date.value), uint32_t((state.local_player_nation.index() << 7) ^ target.index() ^ (fat_id.id.index() << 3)));
85 text::add_line(state, contents, "et_on_po_accepted");
86 auto windx = 0;//wargoal.index()
87 effect_description(state, contents, fat_id.get_on_po_accepted(), trigger::to_generic(target), trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation),
88 uint32_t((state.current_date.value << 8) ^ target.index()), uint32_t(state.local_player_nation.index() ^ (windx << 3)));
89
90 if(auto allowed_states = fat_id.get_allowed_states(); allowed_states) {
91 bool described = false;
92 for(auto si : state.world.nation_get_state_ownership(target)) {
93 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation))) {
94 ui::trigger_description(state, contents, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation));
95 described = true;
96 break;
97 }
98 }
99 if(!described) {
100 ui::trigger_description(state, contents, allowed_states, -1, trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation));
101 }
102 }
103 }
104};
105
106class wargoal_type_item : public listbox_row_element_base<dcon::cb_type_id> {
107public:
108 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
109 if(name == "wargoal_icon") {
110 auto ptr = make_element_by_type<wargoal_type_item_icon>(state, id);
111 //ptr->base_data.position.x += 16; // Nudge
112 return ptr;
113 } else if(name == "select_goal_invalid") {
114 return make_element_by_type<invisible_element>(state, id);
115 } else if(name == "select_goal") {
116 auto ptr = make_element_by_type<wargoal_type_item_button>(state, id);
117 //ptr->base_data.position.x += 16; // Nudge
118 return ptr;
119 } else {
120 return nullptr;
121 }
122 }
123};
124
125class wargoal_type_listbox : public listbox_element_base<wargoal_type_item, dcon::cb_type_id> {
126protected:
127 std::string_view get_row_element_name() override {
128 return "wargoal_item";
129 }
130
131public:
132 void on_update(sys::state& state) noexcept override {
133 row_contents.clear();
134
135 auto selected_cb = retrieve<dcon::cb_type_id>(state, parent);
136 if(selected_cb) {
137 row_contents.push_back(selected_cb);
138 update(state);
139 return;
140 }
141
142 dcon::nation_id content = retrieve<dcon::nation_id>(state, parent);
143 auto w = military::find_war_between(state, state.local_player_nation, content);
144
145 if(w) { // war is ongoing
146 for(auto cb_type : state.world.in_cb_type) {
147 // prevent duplicate war goals
149 if(military::war_goal_would_be_duplicate(state, state.local_player_nation, w, content, cb_type, dcon::state_definition_id{}, dcon::national_identity_id{}, dcon::nation_id{}))
150 continue;
151 }
152
153 if((state.world.cb_type_get_type_bits(cb_type) & military::cb_flag::always) == 0 && military::cb_conditions_satisfied(state, state.local_player_nation, content, cb_type)) {
154 bool cb_fabbed = false;
155 for(auto& fab_cb : state.world.nation_get_available_cbs(state.local_player_nation)) {
156 if(fab_cb.cb_type == cb_type && fab_cb.target == content) {
157 cb_fabbed = true;
158 break;
159 }
160 }
161 if(!cb_fabbed) {
162 if((state.world.cb_type_get_type_bits(cb_type) & military::cb_flag::is_not_constructing_cb) != 0)
163 continue; // can only add a constructable cb this way
164
165 auto totalpop = state.world.nation_get_demographics(state.local_player_nation, demographics::total);
166 auto jingoism_perc = totalpop > 0 ? state.world.nation_get_demographics(state.local_player_nation, demographics::to_key(state, state.culture_definitions.jingoism)) / totalpop : 0.0f;
167 if(state.world.war_get_is_great(w)) {
168 if(jingoism_perc >= state.defines.wargoal_jingoism_requirement * state.defines.gw_wargoal_jingoism_requirement_mod) {
169 row_contents.push_back(cb_type);
170 continue;
171 }
172 } else {
173 if(jingoism_perc >= state.defines.wargoal_jingoism_requirement) {
174 row_contents.push_back(cb_type);
175 continue;
176 }
177 }
178 } else {
179 row_contents.push_back(cb_type);
180 continue;
181 }
182 } else { // this is an always CB
183 if(military::cb_conditions_satisfied(state, state.local_player_nation, content, cb_type) && military::can_add_always_cb_to_war(state, state.local_player_nation, content, cb_type, w)) {
184 row_contents.push_back(cb_type);
185 continue;
186 }
187 }
188 }
189 } else { // this is a declare war action
190 auto other_cbs = state.world.nation_get_available_cbs(state.local_player_nation);
191 for(auto cb : state.world.in_cb_type) {
192 bool can_use = military::cb_conditions_satisfied(state, state.local_player_nation, content, cb) && [&]() {
193 if((cb.get_type_bits() & military::cb_flag::always) != 0) {
194 return true;
195 }
196 for(auto& fabbed : other_cbs) {
197 if(fabbed.cb_type == cb && fabbed.target == content)
198 return true;
199 }
200 return false;
201 }();
202
203 if(can_use) {
204 row_contents.push_back(cb);
205 }
206 }
207 }
208
209 update(state);
210 }
211};
212
214public:
215 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
216 if(name == "wargoal_list") {
217 return make_element_by_type<wargoal_type_listbox>(state, id);
218 } else if(name == "cancel_select") {
219 return make_element_by_type<wargoal_cancel_button>(state, id);
220 } else {
221 return nullptr;
222 }
223 }
224};
225
227public:
228 void button_action(sys::state& state) noexcept override {
229 dcon::national_identity_id content = retrieve<dcon::national_identity_id>(state, parent);
231 }
232
233 void on_update(sys::state& state) noexcept override {
234 dcon::national_identity_id content = retrieve<dcon::national_identity_id>(state, parent);
236 }
237
240 }
241 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
242 dcon::cb_type_id cb = retrieve<dcon::cb_type_id>(state, parent);
243 if(auto allowed_countries = state.world.cb_type_get_allowed_countries(cb); allowed_countries) {
244 dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
245 auto holder = state.world.national_identity_get_nation_from_identity_holder(retrieve<dcon::national_identity_id>(state, parent));
246 trigger_description(state, contents, allowed_countries, trigger::to_generic(target), trigger::to_generic(state.local_player_nation), trigger::to_generic(holder));
247 }
248 }
249};
250
251class wargoal_country_item : public listbox_row_element_base<dcon::national_identity_id> {
252public:
253 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
254 if(name == "select_country") {
255 return make_element_by_type<wargoal_country_item_button>(state, id);
256 } else {
257 return nullptr;
258 }
259 }
260};
261
262class wargoal_country_listbox : public listbox_element_base<wargoal_country_item, dcon::national_identity_id> {
263protected:
264 std::string_view get_row_element_name() override {
265 return "wargoal_country_item";
266 }
267
268public:
269 void on_update(sys::state& state) noexcept override {
270 row_contents.clear();
271
272 dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
273 auto actor = state.local_player_nation;
274 dcon::cb_type_id cb = retrieve<dcon::cb_type_id>(state, parent);
275 auto war = military::find_war_between(state, actor, target);
276
277 dcon::trigger_key allowed_countries = state.world.cb_type_get_allowed_countries(cb);
278 if(!allowed_countries) {
279 update(state);
280 return;
281 }
282
283 for(auto n : state.world.in_nation) {
284 if(n != actor && trigger::evaluate(state, allowed_countries, trigger::to_generic(target), trigger::to_generic(actor), trigger::to_generic(n.id))) {
285 auto id = state.world.nation_get_identity_from_identity_holder(n);
286 if(!war) {
287 row_contents.push_back(id);
289 row_contents.push_back(id);
290 } else {
292 if(!military::war_goal_would_be_duplicate(state, state.local_player_nation, war, target, cb, dcon::state_definition_id{}, id, dcon::nation_id{})) {
293 row_contents.push_back(id);
294 }
295 } else {
296 if(!military::war_goal_would_be_duplicate(state, state.local_player_nation, war, target, cb, dcon::state_definition_id{}, dcon::national_identity_id{}, n)) {
297 row_contents.push_back(id);
298 }
299 }
300 }
301 }
302 }
303
304 update(state);
305 }
306};
307
309public:
310 void button_action(sys::state& state) noexcept override {
312 }
313};
314
316public:
317 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
318 if(name == "country_list") {
319 return make_element_by_type<wargoal_country_listbox>(state, id);
320 } else if(name == "cancel_select") {
321 return make_element_by_type<wargoal_cancel_country_select>(state, id);
322 } else {
323 return nullptr;
324 }
325 }
326};
327
328
330public:
331 void on_update(sys::state& state) noexcept override {
332 auto cb = retrieve<dcon::cb_type_id>(state, parent);
333 auto target = retrieve<dcon::nation_id>(state, parent);
334 auto source = state.local_player_nation;
335
336 dcon::nation_id real_target = target;
337
338 auto target_ol_rel = state.world.nation_get_overlord_as_subject(target);
339 if(state.world.overlord_get_ruler(target_ol_rel))
340 real_target = state.world.overlord_get_ruler(target_ol_rel);
341
342 if(cb) {
343 if(auto w = military::find_war_between(state, source, target); w) {
345 set_text(state, "0.0");
346 } else if(military::has_truce_with(state, source, real_target)) {
347 auto cb_prestige_loss = military::truce_break_cb_prestige_cost(state, cb);
348
350 set_text(state, text::format_float(cb_prestige_loss, 1));
351 } else {
353 set_text(state, "0.0");
354 }
355 } else {
357 set_text(state, "0.0");
358 }
359 }
360};
362public:
363 void on_update(sys::state& state) noexcept override {
364 auto cb = retrieve<dcon::cb_type_id>(state, parent);
365 auto target = retrieve<dcon::nation_id>(state, parent);
366 auto target_state = retrieve<dcon::state_definition_id>(state, parent);
367
368 auto source = state.local_player_nation;
369
370 dcon::nation_id real_target = target;
371
372 auto target_ol_rel = state.world.nation_get_overlord_as_subject(target);
373 if(state.world.overlord_get_ruler(target_ol_rel))
374 real_target = state.world.overlord_get_ruler(target_ol_rel);
375
376 if(cb) {
377 if(auto w = military::find_war_between(state, source, target); w) {
378 auto cb_infamy = military::cb_addition_infamy_cost(state, w, cb, source, target, target_state);
379
381 set_text(state, text::format_float(cb_infamy, 1));
382 } else if(military::has_truce_with(state, source, real_target)) {
383 auto cb_infamy = military::truce_break_cb_infamy(state, cb, target, target_state);
384
386 set_text(state, text::format_float(cb_infamy, 1));
387 } else {
389 set_text(state, "0.0");
390 }
391 } else {
393 set_text(state, "0.0");
394 }
395 }
396};
398public:
399 void on_update(sys::state& state) noexcept override {
400 auto cb = retrieve<dcon::cb_type_id>(state, parent);
401 auto target = retrieve<dcon::nation_id>(state, parent);
402 auto source = state.local_player_nation;
403
404 dcon::nation_id real_target = target;
405
406 auto target_ol_rel = state.world.nation_get_overlord_as_subject(target);
407 if(state.world.overlord_get_ruler(target_ol_rel))
408 real_target = state.world.overlord_get_ruler(target_ol_rel);
409
410 if(cb) {
411 if(auto w = military::find_war_between(state, source, target); w) {
413 set_text(state, "0.0");
414 } else if(military::has_truce_with(state, source, real_target)) {
415 auto cb_militancy = military::truce_break_cb_militancy(state, cb);
416
418 set_text(state, text::format_float(cb_militancy, 1));
419 } else {
421 set_text(state, "0.0");
422 }
423 } else {
425 set_text(state, "0.0");
426 }
427 }
428};
429
431public:
432 void on_create(sys::state& state) noexcept override {
435 }
436};
437
439public:
440 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
441 if(name == "wargoal_gain_effect_text") {
442 return make_element_by_type<wargoal_add_header>(state, id);
443 } else if(name == "prestige_icon") {
444 return make_element_by_type<image_element_base>(state, id);
445 } else if(name == "prestige") {
446 return make_element_by_type<wargoal_add_prestige>(state, id);
447 } else if(name == "infamy_icon") {
448 return make_element_by_type<image_element_base>(state, id);
449 } else if(name == "infamy") {
450 return make_element_by_type<wargoal_add_infamy>(state, id);
451 } else if(name == "militancy_icon") {
452 return make_element_by_type<image_element_base>(state, id);
453 } else if(name == "militancy") {
454 return make_element_by_type<wargoal_add_militancy>(state, id);
455 } else {
456 return nullptr;
457 }
458 }
459};
460
462public:
463 void on_create(sys::state& state) noexcept override {
465 set_text(state, "0.0");
466 }
467};
468
469
471public:
472 void on_update(sys::state& state) noexcept override {
473 auto cb = retrieve<dcon::cb_type_id>(state, parent);
474 auto source = state.local_player_nation;
475
476 if(cb) {
477 float prestige_gain = military::successful_cb_prestige(state, cb, source);
478 if(prestige_gain > 0) {
480 set_text(state, text::format_float(prestige_gain, 1));
481 } else {
483 set_text(state, "0.0");
484 }
485 } else {
487 set_text(state, "0.0");
488 }
489 }
490};
491
493public:
494 void on_create(sys::state& state) noexcept override {
497 }
498};
499
501public:
502 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
503 if(name == "wargoal_gain_effect_text") {
504 return make_element_by_type<wargoal_success_header>(state, id);
505 } else if(name == "prestige_icon") {
506 return make_element_by_type<image_element_base>(state, id);
507 } else if(name == "prestige") {
508 return make_element_by_type<wargoal_success_prestige>(state, id);
509 } else if(name == "infamy_icon") {
510 return make_element_by_type<image_element_base>(state, id);
511 } else if(name == "infamy") {
512 return make_element_by_type<fixed_zero>(state, id);
513 } else if(name == "militancy_icon") {
514 return make_element_by_type<image_element_base>(state, id);
515 } else if(name == "militancy") {
516 return make_element_by_type<fixed_zero>(state, id);
517 } else {
518 return nullptr;
519 }
520 }
521};
522
524public:
525 void on_update(sys::state& state) noexcept override {
526 auto cb = retrieve<dcon::cb_type_id>(state, parent);
527 auto source = state.local_player_nation;
528 if(cb) {
529 float prestige_loss = std::min(state.defines.war_failed_goal_prestige_base, state.defines.war_failed_goal_prestige * nations::prestige_score(state, source)) * state.world.cb_type_get_penalty_factor(cb);
530
531 if(prestige_loss < 0) {
533 set_text(state, text::format_float(prestige_loss, 1));
534 } else {
536 set_text(state, "0.0");
537 }
538 } else {
540 set_text(state, "0.0");
541 }
542 }
543};
544
546public:
547 void on_update(sys::state& state) noexcept override {
548 auto cb = retrieve<dcon::cb_type_id>(state, parent);
549 if(cb) {
550 auto pop_militancy = state.defines.war_failed_goal_militancy * state.world.cb_type_get_penalty_factor(cb);
551
552 if(pop_militancy > 0) {
554 set_text(state, text::format_float(pop_militancy, 1));
555 } else {
557 set_text(state, "0.0");
558 }
559 } else {
561 set_text(state, "0.0");
562 }
563 }
564};
565
567public:
568 void on_create(sys::state& state) noexcept override {
571 }
572};
573
575public:
576 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
577 if(name == "wargoal_gain_effect_text") {
578 return make_element_by_type<wargoal_failure_header>(state, id);
579 } else if(name == "prestige_icon") {
580 return make_element_by_type<image_element_base>(state, id);
581 } else if(name == "prestige") {
582 return make_element_by_type<wargoal_failure_prestige>(state, id);
583 } else if(name == "infamy_icon") {
584 return make_element_by_type<image_element_base>(state, id);
585 } else if(name == "infamy") {
586 return make_element_by_type<fixed_zero>(state, id);
587 } else if(name == "militancy_icon") {
588 return make_element_by_type<image_element_base>(state, id);
589 } else if(name == "militancy") {
590 return make_element_by_type<wargoal_failure_militancy>(state, id);
591 } else {
592 return nullptr;
593 }
594 }
595};
596
598public:
599 void on_update(sys::state& state) noexcept override {
600 auto war = retrieve<dcon::war_id>(state, parent);
601 if(!war) {
603 } else {
605 }
606 }
607};
608
610 bool done = false;
611};
612
616
618public:
619 void on_update(sys::state& state) noexcept override {
620 auto wg_ready = retrieve<check_wg_completion>(state, parent).done;
621 if(!wg_ready) {
622 disabled = true;
623 return;
624 }
625
626 dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
627 dcon::state_definition_id s = retrieve<dcon::state_definition_id>(state, parent);
628 dcon::national_identity_id ni = retrieve<dcon::national_identity_id>(state, parent);
629 dcon::cb_type_id c = retrieve<dcon::cb_type_id>(state, parent);
630
631 if(military::are_at_war(state, state.local_player_nation, n)) {
632 dcon::war_id w = military::find_war_between(state, state.local_player_nation, n);
633 disabled = !command::can_add_war_goal(state, state.local_player_nation, w, n, c, s, ni,
634 state.world.national_identity_get_nation_from_identity_holder(ni));
635 } else {
636 disabled = !command::can_declare_war(state, state.local_player_nation, n, c, s, ni,
637 state.world.national_identity_get_nation_from_identity_holder(ni));
638 }
639 }
640
641 void button_action(sys::state& state) noexcept override {
642 dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
643 dcon::state_definition_id s = retrieve<dcon::state_definition_id>(state, parent);
644 dcon::national_identity_id ni = retrieve<dcon::national_identity_id>(state, parent);
645 dcon::cb_type_id c = retrieve<dcon::cb_type_id>(state, parent);
646
647 auto checkboxes = retrieve<diplomacy_declare_war_run_state>(state, parent);
648 if(military::are_at_war(state, state.local_player_nation, n)) {
649 dcon::war_id w = military::find_war_between(state, state.local_player_nation, n);
650 command::add_war_goal(state, state.local_player_nation, w, n, c, s, ni,
651 state.world.national_identity_get_nation_from_identity_holder(ni));
652 } else {
653 command::declare_war(state, state.local_player_nation, n, c, s, ni,
654 state.world.national_identity_get_nation_from_identity_holder(ni),
657 }
658 parent->set_visible(state, false);
659 }
660
663 }
664
665 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
666 auto wg_ready = retrieve<check_wg_completion>(state, parent).done;
667 if(!wg_ready) {
668 text::add_line_with_condition(state, contents, "wg_not_ready", false);
669 return;
670 }
671
672 dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
673 dcon::state_definition_id s = retrieve<dcon::state_definition_id>(state, parent);
674 dcon::national_identity_id ni = retrieve<dcon::national_identity_id>(state, parent);
675 dcon::cb_type_id c = retrieve<dcon::cb_type_id>(state, parent);
676
677 if(command::can_declare_war(state, state.local_player_nation, n, c, s, ni,
678 state.world.national_identity_get_nation_from_identity_holder(ni))) {
679 auto box = text::open_layout_box(contents, 0);
680 text::localised_format_box(state, contents, box, std::string_view("valid_wartarget"));
681 text::close_layout_box(contents, box);
682 text::add_line_with_condition(state, contents, "alice_condition_diplo_points", !(state.world.nation_get_is_player_controlled(state.local_player_nation) && state.world.nation_get_diplomatic_points(state.local_player_nation) < state.defines.declarewar_diplomatic_cost), text::variable_type::x, int64_t(state.defines.declarewar_diplomatic_cost));
683 } else {
684 dcon::war_id w = military::find_war_between(state, state.local_player_nation, n);
685 auto box = text::open_layout_box(contents, 0);
686 if(military::are_allied_in_war(state, state.local_player_nation, n)) {
687 text::localised_format_box(state, contents, box, std::string_view("invalid_wartarget_shared_war"));
688 }
689 auto rel = state.world.get_diplomatic_relation_by_diplomatic_pair(state.local_player_nation, n);
690 if(state.world.diplomatic_relation_get_are_allied(rel)) {
691 text::localised_format_box(state, contents, box, std::string_view("no_war_allied"));
692 }
693 text::close_layout_box(contents, box);
694 text::add_line_with_condition(state, contents, "alice_condition_diplo_points", !(state.world.nation_get_is_player_controlled(state.local_player_nation) && state.world.nation_get_diplomatic_points(state.local_player_nation) < state.defines.addwargoal_diplomatic_cost), text::variable_type::x, int64_t(state.defines.addwargoal_diplomatic_cost));
695
696 bool is_attacker = military::is_attacker(state, w, state.local_player_nation);
697 bool target_in_war = false;
698 for(auto par : state.world.war_get_war_participant(w)) {
699 if(par.get_nation() == n) {
700 text::add_line_with_condition(state, contents, "alice_wg_condition_4", !(par.get_is_attacker() == is_attacker));
701 target_in_war = true;
702 break;
703 }
704 }
705 text::add_line_with_condition(state, contents, "alice_wg_condition_1", !(!is_attacker && military::defenders_have_status_quo_wargoal(state, w)));
706 text::add_line_with_condition(state, contents, "alice_wg_condition_2", bool(!target_in_war));
707 text::add_line_with_condition(state, contents, "alice_wg_condition_3", !(military::war_goal_would_be_duplicate(state, state.local_player_nation, w, n, c, s, ni, state.world.national_identity_get_nation_from_identity_holder(ni))));
708
709 if((state.world.cb_type_get_type_bits(c) & military::cb_flag::always) == 0) {
710 bool cb_fabbed = false;
711 for(auto& fab_cb : state.world.nation_get_available_cbs(state.local_player_nation)) {
712 if(fab_cb.cb_type == c && fab_cb.target == n) {
713 cb_fabbed = true;
714 break;
715 }
716 }
717 if(!cb_fabbed) {
718 text::add_line_with_condition(state, contents, "alice_wg_condition_7", !((state.world.cb_type_get_type_bits(c) & military::cb_flag::is_not_constructing_cb) != 0));
719 auto totalpop = state.world.nation_get_demographics(state.local_player_nation, demographics::total);
720 auto jingoism_perc = totalpop > 0 ? state.world.nation_get_demographics(state.local_player_nation, demographics::to_key(state, state.culture_definitions.jingoism)) / totalpop : 0.0f;
721 if(state.world.war_get_is_great(w)) {
722 text::add_line_with_condition(state, contents, "alice_wg_condition_6", jingoism_perc >= state.defines.gw_wargoal_jingoism_requirement_mod,
723 text::variable_type::need, text::fp_two_places{ state.defines.gw_wargoal_jingoism_requirement_mod },
725 } else {
726 text::add_line_with_condition(state, contents, "alice_wg_condition_6", jingoism_perc >= state.defines.wargoal_jingoism_requirement,
727 text::variable_type::need, text::fp_two_places{ state.defines.wargoal_jingoism_requirement },
729 }
730 }
731 }
732 }
733 text::add_line_with_condition(state, contents, "alice_wg_condition_5", military::cb_instance_conditions_satisfied(state, state.local_player_nation, n, c, s, ni, state.world.national_identity_get_nation_from_identity_holder(ni)));
734
735 if(auto can_use = state.world.cb_type_get_can_use(c); can_use) {
736 text::add_line(state, contents, "alice_wg_usage_trigger");
737 ui::trigger_description(state, contents, can_use, trigger::to_generic(n), trigger::to_generic(state.local_player_nation), trigger::to_generic(n));
738 }
739 }
740};
741
742
743int32_t calculate_partial_score(sys::state& state, dcon::nation_id target, dcon::cb_type_id id, dcon::state_definition_id state_def, dcon::national_identity_id second_nation) {
744 int32_t cost = -1;
745
746 auto war = military::find_war_between(state, state.local_player_nation, target);
748
749 cost = military::peace_cost(state, military::find_war_between(state, state.local_player_nation, target), id, state.local_player_nation, target, dcon::nation_id{}, dcon::state_definition_id{}, dcon::national_identity_id{});
751
752 if(state_def) {
754 if(!second_nation) {
755 return -1;
756 }
758 if(!second_nation) {
759 return -1;
760 }
761 }
762
763 cost = 0;
764
765 // for each state ...
766 if(war) {
767 auto is_attacker = military::is_attacker(state, war, state.local_player_nation);
768 for(auto si : state.world.in_state_instance) {
769 if(si.get_definition() == state_def) {
770 auto wr = military::get_role(state, war, si.get_nation_from_state_ownership());
771 if((is_attacker && wr == military::war_role::defender) || (!is_attacker && wr == military::war_role::attacker)) {
773 cost += military::peace_cost(state, war, id, state.local_player_nation, si.get_nation_from_state_ownership(), dcon::nation_id{}, state_def, second_nation);
775 cost += military::peace_cost(state, war, id, state.local_player_nation, si.get_nation_from_state_ownership(), state.world.national_identity_get_nation_from_identity_holder(second_nation), state_def, dcon::national_identity_id{});
776 } else {
777 cost += military::peace_cost(state, war, id, state.local_player_nation, si.get_nation_from_state_ownership(), dcon::nation_id{}, state_def, dcon::national_identity_id{});
778 }
779 }
780 }
781 }
782 } else {
783 for(auto si : state.world.in_state_instance) {
784 if(si.get_definition() == state_def) {
785 auto n = si.get_nation_from_state_ownership();
786 auto no = n.get_overlord_as_subject().get_ruler();
787 if(n == target || no == target) {
789 cost += military::peace_cost(state, dcon::war_id{}, id, state.local_player_nation, si.get_nation_from_state_ownership(), dcon::nation_id{}, state_def, second_nation);
791 cost += military::peace_cost(state, dcon::war_id{}, id, state.local_player_nation, si.get_nation_from_state_ownership(), state.world.national_identity_get_nation_from_identity_holder(second_nation), state_def, dcon::national_identity_id{});
792 } else {
793 cost += military::peace_cost(state, dcon::war_id{}, id, state.local_player_nation, si.get_nation_from_state_ownership(), dcon::nation_id{}, state_def, dcon::national_identity_id{});
794 }
795 }
796 }
797 }
798 }
799 }
801 if(second_nation) {
802 cost = military::peace_cost(state, military::find_war_between(state, state.local_player_nation, target), id, state.local_player_nation, target, dcon::nation_id{}, dcon::state_definition_id{}, second_nation);
803 }
805 if(second_nation) {
806 cost = military::peace_cost(state, military::find_war_between(state, state.local_player_nation, target), id, state.local_player_nation, target, state.world.national_identity_get_nation_from_identity_holder(second_nation), dcon::state_definition_id{}, dcon::national_identity_id{});
807 }
808 }
809 return cost;
810}
811
813public:
814 void populate_layout(sys::state& state, text::endless_layout& contents) noexcept override {
815 auto id = retrieve<dcon::cb_type_id>(state, parent);
816 auto fat_cb = dcon::fatten(state.world, id);
817 auto box = text::open_layout_box(contents);
818 auto target = retrieve<dcon::nation_id>(state, parent);
819
821
822 if(id) {
824 text::localised_format_box(state, contents, box, std::string_view("add_wargoal_wargoal"), sub);
825 } else {
826 auto str = text::produce_simple_string(state, "nocasusbelli");
827 text::add_to_substitution_map(sub, text::variable_type::goal, std::string_view(str));
828 text::localised_format_box(state, contents, box, std::string_view("add_wargoal_wargoal"), sub);
829 }
830 text::close_layout_box(contents, box);
831
832 if(id) {
833 auto state_def = retrieve<dcon::state_definition_id>(state, parent);
834 auto second_nation = retrieve<dcon::national_identity_id>(state, parent);
835 auto cost = calculate_partial_score(state, target, id, state_def, second_nation);
836 if(cost != -1) {
837 text::add_line(state, contents, "add_wargoal_peace_cost", text::variable_type::cost, int64_t(cost));
838 }
839 }
840
841 }
842};
843
845public:
846 void populate_layout(sys::state& state, text::endless_layout& contents) noexcept override {
847 auto id = retrieve<dcon::cb_type_id>(state, parent);
848
849 auto content = retrieve<dcon::nation_id>(state, parent);
850 auto sdef = retrieve<dcon::state_definition_id>(state, parent);
851 auto nid = retrieve<dcon::national_identity_id>(state, parent);
852 auto fat_cb = dcon::fatten(state.world, id);
853 auto box = text::open_layout_box(contents);
854
855 if(id) {
858 text::add_to_substitution_map(sub, text::variable_type::third, nid); // Third Party Country
862 text::add_to_layout_box(state, contents, box, fat_cb.get_long_desc(), sub);
863 }
864 text::close_layout_box(contents, box);
865 }
866};
867
869public:
870 bool show = true;
871
872 void button_action(sys::state& state) noexcept override {
873 if(parent) {
874 auto content = retrieve<diplomacy_declare_war_run_state>(state, parent);
875 auto checked = content == diplomacy_declare_war_run_state::call_allies;
877
878 if(checked) {
880 }
881 parent->impl_get(state, b_payload);
882 }
883 }
884
885 void on_update(sys::state& state) noexcept override {
886 auto content = retrieve<diplomacy_declare_war_run_state>(state, parent);
887 auto checked = content == diplomacy_declare_war_run_state::call_allies;
888 frame = checked ? 1 : 0;
889 auto war = retrieve<dcon::war_id>(state, parent);
890 show = !bool(war);
891 }
892
893 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
894 if(show)
896 }
899 }
900 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
901 if(!show)
902 return;
903
904 auto target = retrieve<dcon::nation_id>(state, parent);
905
906 bool has_allies = false;
907 for(auto dr : state.world.nation_get_diplomatic_relation(state.local_player_nation)) {
908 if(dr.get_are_allied()) {
909 auto other = dr.get_related_nations(0) == state.local_player_nation ? dr.get_related_nations(1) : dr.get_related_nations(0);
910 if(other.get_is_player_controlled()) {
911 text::add_line(state, contents, "att_call_is_human", text::variable_type::x, other.id);
912 } else {
913 if(target == other || military::are_in_common_war(state, target, other) || military::are_at_war(state, target, other) || nations::are_allied(state, target, other)) {
914 text::add_line(state, contents, "att_call_will_decline", text::variable_type::x, other.id);
915 } else {
916 bool will_join = false;
917
918 if(military::can_use_cb_against(state, other, target))
919 will_join = true;
920 if(state.world.nation_get_ai_rival(other) == target)
921 will_join = true;
922
923 // TODO: check subjects, other nations that can be expected to defensively answer the CTA
924
925 if(will_join) {
926 text::add_line(state, contents, "att_call_will_accept", text::variable_type::x, other.id);
927 } else {
928 text::add_line(state, contents, "att_call_will_decline", text::variable_type::x, other.id);
929 }
930 }
931 }
932 has_allies = true;
933 }
934 }
935 if(!has_allies) {
936 text::add_line(state, contents, "att_call_no_allies");
937 }
938 }
939};
940
942public:
943 bool show = true;
944
945 void button_action(sys::state& state) noexcept override {
946 if(parent) {
947 auto content = retrieve<diplomacy_declare_war_run_state>(state, parent);
948 auto checked = content == diplomacy_declare_war_run_state::run_conference;
949
951
952 if(checked) {
954 }
955 parent->impl_get(state, b_payload);
956 }
957 }
958
959 void on_update(sys::state& state) noexcept override {
960 auto content = retrieve<diplomacy_declare_war_run_state>(state, parent);
961 auto checked = content == diplomacy_declare_war_run_state::run_conference;
962 disabled = state.current_crisis_state != sys::crisis_state::inactive;
963 if(state.current_crisis_state != sys::crisis_state::inactive) {
964 checked = false;
965 }
966
967 frame = checked ? 1 : 0;
968 auto war = retrieve<dcon::war_id>(state, parent);
969 show = !bool(war);
970 }
971
972 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
973 if(show)
975 }
978 }
979 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
980 if(!show)
981 return;
982 }
983};
984
986public:
987 bool show = true;
988
989 void on_update(sys::state& state) noexcept override {
990 auto war = retrieve<dcon::war_id>(state, parent);
991 show = !bool(war);
992 }
993
994 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
995 if(show)
997 }
998};
999
1001public:
1002 void button_action(sys::state& state) noexcept override {
1003 if(parent) {
1004 parent->set_visible(state, false);
1005 }
1007 }
1008};
1009
1010class diplomacy_declare_war_dialog : public window_element_base { // eu3dialogtype
1011private:
1012 wargoal_setup_window* wargoal_setup_win = nullptr;
1013 wargoal_country_select_window* wargoal_country_win = nullptr;
1014
1015 dcon::cb_type_id cb_to_use;
1016 dcon::state_definition_id target_state;
1017 dcon::national_identity_id target_country;
1018 diplomacy_declare_war_run_state checkboxes_state;
1019 bool wargoal_decided_upon = false;
1020
1021 void select_mode(sys::state& state) {
1023 seldata.single_state_select = true;
1024 dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
1025 auto actor = state.local_player_nation;
1026 dcon::cb_type_id cb = cb_to_use;
1027 auto war = military::find_war_between(state, actor, target);
1028 auto secondary_tag = target_country;
1029 auto allowed_substate_regions = state.world.cb_type_get_allowed_substate_regions(cb);
1030
1031 if ((state.world.cb_type_get_type_bits(cb) & military::cb_flag::always) == 0) {
1032 for(auto available_cb : state.world.nation_get_available_cbs(state.local_player_nation)) {
1033 if(available_cb.cb_type != cb || available_cb.target != target || !available_cb.target_state) {
1034 continue;
1035 }
1036
1037 auto def = available_cb.target_state;
1038 if(!military::war_goal_would_be_duplicate(state, state.local_player_nation, war, target, cb, def, dcon::national_identity_id{}, dcon::nation_id{})) {
1039 seldata.selectable_states.push_back(def);
1040 }
1041 }
1042 }
1043 if (seldata.selectable_states.empty()) {
1044 if(allowed_substate_regions) {
1045 for(auto v : state.world.nation_get_overlord_as_ruler(target)) {
1046 if(v.get_subject().get_is_substate()) {
1047 for(auto si : state.world.nation_get_state_ownership(target)) {
1048 if(trigger::evaluate(state, allowed_substate_regions, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(actor))) {
1049 auto def = si.get_state().get_definition().id;
1050 if(std::find(seldata.selectable_states.begin(), seldata.selectable_states.end(), def) == seldata.selectable_states.end()) {
1051 if(!military::war_goal_would_be_duplicate(state, state.local_player_nation, war, v.get_subject(), cb, def, dcon::national_identity_id{}, dcon::nation_id{})) {
1052 seldata.selectable_states.push_back(def);
1053 }
1054 }
1055 }
1056 }
1057 }
1058 }
1059 } else {
1060 auto allowed_states = state.world.cb_type_get_allowed_states(cb);
1061 if(auto ac = state.world.cb_type_get_allowed_countries(cb); ac) {
1062 auto in_nation = state.world.national_identity_get_nation_from_identity_holder(secondary_tag);
1063 for(auto si : state.world.nation_get_state_ownership(target)) {
1064 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(in_nation))) {
1065 auto def = si.get_state().get_definition().id;
1066 if(!military::war_goal_would_be_duplicate(state, state.local_player_nation, war, target, cb, def, secondary_tag, dcon::nation_id{})) {
1067 seldata.selectable_states.push_back(def);
1068 }
1069 }
1070 }
1071 } else {
1072 for(auto si : state.world.nation_get_state_ownership(target)) {
1073 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(actor))) {
1074 auto def = si.get_state().get_definition().id;
1075 if(!military::war_goal_would_be_duplicate(state, state.local_player_nation, war, target, cb, def, dcon::national_identity_id{}, dcon::nation_id{})) {
1076 seldata.selectable_states.push_back(def);
1077 }
1078 }
1079 }
1080 }
1081 }
1082 }
1083 seldata.on_select = [&](sys::state& state, dcon::state_definition_id sdef) {
1084 target_state = sdef;
1085 wargoal_decided_upon = true;
1086 wargoal_setup_win->set_visible(state, true);
1087 wargoal_country_win->set_visible(state, false);
1089 };
1090 seldata.on_cancel = [&](sys::state& state) {
1091 target_state = dcon::state_definition_id{};
1093 wargoal_setup_win->set_visible(state, false);
1094 wargoal_country_win->set_visible(state, true);
1095 } else {
1096 cb_to_use = dcon::cb_type_id{};
1097 wargoal_decided_upon = false;
1098 wargoal_setup_win->set_visible(state, true);
1099 wargoal_country_win->set_visible(state, false);
1100 }
1102 };
1103 state.start_state_selection(seldata);
1104 }
1105public:
1107 cb_to_use = dcon::cb_type_id{};
1108 target_state = dcon::state_definition_id{};
1109 target_country = dcon::national_identity_id{};
1110 checkboxes_state = diplomacy_declare_war_run_state::none;
1111 wargoal_decided_upon = false;
1112 wargoal_setup_win->set_visible(state, true);
1113 wargoal_country_win->set_visible(state, false);
1114 }
1115
1116 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1117 if(name == "background") {
1118 auto ptr = make_element_by_type<draggable_target>(state, id);
1119 ptr->base_data.size = base_data.size; // Nudge size for proper sizing
1120 return ptr;
1121 } else if(name == "diplo_declarewar_bg") {
1122 return make_element_by_type<image_element_base>(state, id);
1123 } else if(name == "leftshield") {
1124 return make_element_by_type<nation_player_flag>(state, id);
1125 } else if(name == "rightshield") {
1126 return make_element_by_type<flag_button>(state, id);
1127 } else if(name == "title") {
1128 return make_element_by_type<diplomacy_declare_war_title>(state, id);
1129 } else if(name == "description") {
1130 return make_element_by_type<diplomacy_declare_war_description1>(state, id);
1131 } else if(name == "wargoal_add_effect") {
1132 return make_element_by_type<diplomacy_wargoal_add_window>(state, id);
1133 } else if(name == "wargoal_success_effect") {
1134 return make_element_by_type<diplomacy_wargoal_success_window>(state, id);
1135 } else if(name == "wargoal_failure_effect") {
1136 return make_element_by_type<diplomacy_wargoal_failure_window>(state, id);
1137 } else if(name == "description2") {
1138 return make_element_by_type<diplomacy_declare_war_description2>(state, id);
1139 } else if(name == "acceptance") {
1140 return make_element_by_type<simple_text_element_base>(state, id);
1141 } else if(name == "call_allies_checkbox") {
1142 return make_element_by_type<diplomacy_declare_war_call_allies_checkbox>(state, id);
1143 } else if(name == "run_conference_checkbox") {
1144 return make_element_by_type<diplomacy_declare_war_run_conference_checkbox>(state, id);
1145 } else if(name == "call_allies_text") {
1146 return make_element_by_type<diplomacy_declare_war_call_allies_text>(state, id);
1147 } else if(name == "agreebutton") {
1148 return make_element_by_type<diplomacy_declare_war_agree_button>(state, id);
1149 } else if(name == "declinebutton") {
1150 return make_element_by_type<cancel_pick_wg_button>(state, id);
1151 } else if(name == "wargoal_setup") {
1152 auto ptr = make_element_by_type<wargoal_setup_window>(state, id);
1153 wargoal_setup_win = ptr.get();
1154 ptr->set_visible(state, true);
1155 return ptr;
1156 } else if(name == "wargoal_state_select") {
1157 return make_element_by_type<invisible_element>(state, id);
1158 } else if(name == "wargoal_country_select") {
1159 auto ptr = make_element_by_type<wargoal_country_select_window>(state, id);
1160 wargoal_country_win = ptr.get();
1161 ptr->set_visible(state, false);
1162 return ptr;
1163 } else {
1164 return nullptr;
1165 }
1166 }
1167
1168 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1169 if(payload.holds_type<dcon::war_id>()) {
1170 const dcon::nation_id n = retrieve<dcon::nation_id>(state, parent);
1171 const dcon::war_id w = military::find_war_between(state, state.local_player_nation, n);
1172 payload.emplace<dcon::war_id>(w);
1174 } else if(payload.holds_type< check_wg_completion>()) {
1175 payload.emplace<check_wg_completion>(check_wg_completion{ wargoal_decided_upon });
1177 } else if(payload.holds_type<element_selection_wrapper<dcon::cb_type_id>>()) {
1178 cb_to_use = any_cast<element_selection_wrapper<dcon::cb_type_id>>(payload).data;
1179 if(!cb_to_use) {
1180 wargoal_decided_upon = false;
1182 wargoal_setup_win->set_visible(state, false);
1183 wargoal_country_win->set_visible(state, true);
1184 } else if(military::cb_requires_selection_of_a_state(state, cb_to_use)) {
1185 wargoal_setup_win->set_visible(state, true);
1186 wargoal_country_win->set_visible(state, false);
1187 select_mode(state);
1188 } else {
1189 wargoal_decided_upon = true;
1190 wargoal_setup_win->set_visible(state, true);
1191 wargoal_country_win->set_visible(state, false);
1192 }
1195 } else if(payload.holds_type<element_selection_wrapper<dcon::national_identity_id>>()) {
1196 target_country = any_cast<element_selection_wrapper<dcon::national_identity_id>>(payload).data;
1197 if(target_country) { // goto next step
1199 wargoal_setup_win->set_visible(state, true);
1200 wargoal_country_win->set_visible(state, false);
1201 select_mode(state);
1202 } else {
1203 wargoal_decided_upon = true;
1204 wargoal_setup_win->set_visible(state, true);
1205 wargoal_country_win->set_visible(state, false);
1206 }
1207 } else {
1208 wargoal_decided_upon = false;
1209 cb_to_use = dcon::cb_type_id{};
1210 wargoal_setup_win->set_visible(state, true);
1211 wargoal_country_win->set_visible(state, false);
1212 }
1215 } else if(payload.holds_type<element_selection_wrapper<diplomacy_declare_war_run_state>>()) {
1216 checkboxes_state = any_cast<element_selection_wrapper<diplomacy_declare_war_run_state>>(payload).data;
1219 } else if(payload.holds_type<dcon::cb_type_id>()) {
1220 payload.emplace<dcon::cb_type_id>(cb_to_use);
1222 } else if(payload.holds_type<dcon::state_definition_id>()) {
1223 payload.emplace<dcon::state_definition_id>(target_state);
1225 } else if(payload.holds_type<dcon::national_identity_id>()) {
1226 payload.emplace<dcon::national_identity_id>(target_country);
1228 } else if(payload.holds_type<diplomacy_declare_war_run_state>()) {
1229 payload.emplace<diplomacy_declare_war_run_state>(checkboxes_state);
1231 }
1233 }
1234};
1235
1237 dcon::nation_id n;
1238};
1240 dcon::nation_id n;
1241};
1243 dcon::nation_id n;
1244};
1245
1247public:
1248 void populate_layout(sys::state& state, text::endless_layout& contents) noexcept override {
1249 auto id = retrieve<dcon::cb_type_id>(state, parent);
1250 auto fat_cb = dcon::fatten(state.world, id);
1251 auto box = text::open_layout_box(contents);
1252 auto target = retrieve<get_target>(state, parent).n;
1253
1255
1256 if(id) {
1258 text::localised_format_box(state, contents, box, std::string_view("add_wargoal_wargoal"), sub);
1259 } else {
1260 auto str = text::produce_simple_string(state, "nocasusbelli");
1261 text::add_to_substitution_map(sub, text::variable_type::goal, std::string_view(str));
1262 text::localised_format_box(state, contents, box, std::string_view("add_wargoal_wargoal"), sub);
1263 }
1264 text::close_layout_box(contents, box);
1265
1266 if(id) {
1267 auto state_def = retrieve<dcon::state_definition_id>(state, parent);
1268 auto second_nation = retrieve<dcon::national_identity_id>(state, parent);
1269 auto cost = calculate_partial_score(state, target, id, state_def, second_nation);
1270 if(cost != -1) {
1271 text::add_line(state, contents, "add_wargoal_peace_cost", text::variable_type::cost, int64_t(cost));
1272 }
1273 }
1274
1275 }
1276};
1277
1279public:
1280 void populate_layout(sys::state& state, text::endless_layout& contents) noexcept override {
1281 auto id = retrieve<dcon::cb_type_id>(state, parent);
1282
1283 auto content = retrieve<get_target>(state, parent).n;
1284 auto dest = retrieve<get_offer_to>(state, parent).n;
1285 auto staat = retrieve<dcon::state_definition_id>(state, parent);
1286 auto nacion = retrieve<dcon::national_identity_id>(state, parent);
1287
1288 auto fat_cb = dcon::fatten(state.world, id);
1289
1290 auto box = text::open_layout_box(contents);
1291
1292 if(id) {
1294 text::add_to_substitution_map(sub, text::variable_type::recipient, content); // Target Nation
1295 text::add_to_substitution_map(sub, text::variable_type::third, nacion); // Third Party Country
1299
1300 text::add_to_layout_box(state, contents, box, fat_cb.get_long_desc(), sub);
1301 }
1302
1303 text::close_layout_box(contents, box);
1304 }
1305};
1306
1307
1309public:
1310 void on_update(sys::state& state) noexcept override {
1311 auto wg_ready = retrieve<check_wg_completion>(state, parent).done;
1312 if(!wg_ready) {
1313 disabled = true;
1314 return;
1315 }
1316 auto ni = retrieve<dcon::national_identity_id>(state, parent);
1317 disabled = !command::can_invite_to_crisis(state, state.local_player_nation, retrieve<get_offer_to>(state, parent).n, retrieve<get_target>(state, parent).n, retrieve<dcon::cb_type_id>(state, parent), retrieve<dcon::state_definition_id>(state, parent), ni, state.world.national_identity_get_nation_from_identity_holder(ni));
1318 }
1319
1320 void button_action(sys::state& state) noexcept override {
1321 auto ni = retrieve<dcon::national_identity_id>(state, parent);
1322 command::invite_to_crisis(state, state.local_player_nation, retrieve<get_offer_to>(state, parent).n, retrieve<get_target>(state, parent).n, retrieve<dcon::cb_type_id>(state, parent), retrieve<dcon::state_definition_id>(state, parent), ni, state.world.national_identity_get_nation_from_identity_holder(ni));
1323 parent->set_visible(state, false);
1324 }
1325
1328 }
1329
1330 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1331 auto wg_ready = retrieve<check_wg_completion>(state, parent).done;
1332 if(!wg_ready) {
1333 text::add_line_with_condition(state, contents, "wg_not_ready", false);
1334 return;
1335 }
1336 }
1337};
1338
1340public:
1341 void on_create(sys::state& state) noexcept override {
1343 set_text(state, text::produce_simple_string(state, "crisis_offertitle"));
1344 }
1345};
1346
1347
1349public:
1350 void on_update(sys::state& state) noexcept override {
1351 auto cb = retrieve<dcon::cb_type_id>(state, parent);
1352 auto target = retrieve<get_target>(state, parent).n;
1353 auto target_state = retrieve<dcon::state_definition_id>(state, parent);
1354 auto offered = retrieve<get_offer_to>(state, parent).n;
1355
1356 auto infamy = military::crisis_cb_addition_infamy_cost(state, cb, offered, target, target_state) *
1357 state.defines.crisis_wargoal_infamy_mult;
1358
1359 if(infamy > 0) {
1361 set_text(state, text::format_float(infamy, 1));
1362 } else {
1364 set_text(state, "0.0");
1365 }
1366 }
1367};
1368
1369
1371public:
1372 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1373 if(name == "wargoal_gain_effect_text") {
1374 return make_element_by_type<wargoal_add_header>(state, id);
1375 } else if(name == "prestige_icon") {
1376 return make_element_by_type<image_element_base>(state, id);
1377 } else if(name == "prestige") {
1378 return make_element_by_type<fixed_zero>(state, id);
1379 } else if(name == "infamy_icon") {
1380 return make_element_by_type<image_element_base>(state, id);
1381 } else if(name == "infamy") {
1382 return make_element_by_type<wargoal_offer_add_infamy>(state, id);
1383 } else if(name == "militancy_icon") {
1384 return make_element_by_type<image_element_base>(state, id);
1385 } else if(name == "militancy") {
1386 return make_element_by_type<fixed_zero>(state, id);
1387 } else {
1388 return nullptr;
1389 }
1390 }
1391};
1392
1393class wargoal_offer_type_listbox : public listbox_element_base<wargoal_type_item, dcon::cb_type_id> {
1394protected:
1395 std::string_view get_row_element_name() override {
1396 return "wargoal_item";
1397 }
1398
1399public:
1400 void on_update(sys::state& state) noexcept override {
1401 row_contents.clear();
1402
1403 auto selected_cb = retrieve<dcon::cb_type_id>(state, parent);
1404 if(selected_cb) {
1405 row_contents.push_back(selected_cb);
1406 update(state);
1407 return;
1408 }
1409
1410 dcon::nation_id actor = retrieve<get_offer_to>(state, parent).n;
1411 dcon::nation_id content = retrieve<get_target>(state, parent).n;
1412
1413 for(auto cb_type : state.world.in_cb_type) {
1414
1415 if(military::cb_conditions_satisfied(state, actor, content, cb_type)) {
1416 if((cb_type.get_type_bits() & military::cb_flag::always) != 0)
1417 row_contents.push_back(cb_type);
1418 else if((cb_type.get_type_bits() & military::cb_flag::is_not_constructing_cb) == 0)
1419 row_contents.push_back(cb_type);
1420 }
1421 }
1422
1423 update(state);
1424 }
1425};
1426
1428public:
1429 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1430 if(name == "country_list") {
1431 return make_element_by_type<wargoal_offer_type_listbox>(state, id);
1432 } else if(name == "cancel_select") {
1433 return make_element_by_type<wargoal_cancel_button>(state, id);
1434 } else {
1435 return nullptr;
1436 }
1437 }
1438};
1439
1440
1442public:
1443 void button_action(sys::state& state) noexcept override {
1444 auto n = retrieve<dcon::nation_id>(state, parent);
1445 send(state, parent, set_target{ n });
1446 }
1447
1448 void on_update(sys::state& state) noexcept override {
1449 auto n = retrieve<dcon::nation_id>(state, parent);
1451 }
1454 }
1455 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1456 dcon::cb_type_id cb = retrieve<dcon::cb_type_id>(state, parent);
1457 if(auto allowed_countries = state.world.cb_type_get_allowed_countries(cb); allowed_countries) {
1458 dcon::nation_id target = retrieve<dcon::nation_id>(state, parent);
1459 auto holder = state.world.national_identity_get_nation_from_identity_holder(retrieve<dcon::national_identity_id>(state, parent));
1460 trigger_description(state, contents, allowed_countries, trigger::to_generic(target), trigger::to_generic(state.local_player_nation), trigger::to_generic(holder));
1461 }
1462 }
1463};
1464
1466public:
1467 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1468 if(name == "select_country") {
1469 return make_element_by_type<wargoal_target_country_item_button>(state, id);
1470 } else {
1471 return nullptr;
1472 }
1473 }
1474};
1475
1476class wargoal_target_country_listbox : public listbox_element_base<wargoal_target_country_item, dcon::nation_id> {
1477protected:
1478 std::string_view get_row_element_name() override {
1479 return "wargoal_country_item";
1480 }
1481
1482public:
1483 void on_update(sys::state& state) noexcept override {
1484 row_contents.clear();
1485 for(auto& par : state.crisis_participants) {
1486 if(!par.id) {
1487 break; // not in crisis
1488 }
1489 if(!par.merely_interested) {
1490 if(state.local_player_nation == state.primary_crisis_attacker && !par.supports_attacker)
1491 row_contents.push_back(par.id);
1492 else if(state.local_player_nation == state.primary_crisis_defender && par.supports_attacker)
1493 row_contents.push_back(par.id);
1494 }
1495 }
1496
1497 update(state);
1498 }
1499};
1500
1502public:
1503 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1504 if(name == "wargoal_list") {
1505 return make_element_by_type<wargoal_target_country_listbox>(state, id);
1506 } else {
1507 return nullptr;
1508 }
1509 }
1510};
1511
1512class wargoal_offer_country_listbox : public listbox_element_base<wargoal_country_item, dcon::national_identity_id> {
1513protected:
1514 std::string_view get_row_element_name() override {
1515 return "wargoal_country_item";
1516 }
1517
1518public:
1519 void on_update(sys::state& state) noexcept override {
1520 row_contents.clear();
1521
1522 dcon::nation_id target = retrieve<get_target>(state, parent).n;
1523 auto actor = retrieve<get_offer_to>(state, parent).n;
1524 dcon::cb_type_id cb = retrieve<dcon::cb_type_id>(state, parent);
1525
1526 dcon::trigger_key allowed_countries = state.world.cb_type_get_allowed_countries(cb);
1527 if(!allowed_countries) {
1528 update(state);
1529 return;
1530 }
1531
1532 for(auto n : state.world.in_nation) {
1533 if(n != actor && trigger::evaluate(state, allowed_countries, trigger::to_generic(target), trigger::to_generic(actor), trigger::to_generic(n.id))) {
1534 row_contents.push_back(state.world.nation_get_identity_from_identity_holder(n));
1535 }
1536 }
1537 update(state);
1538 }
1539};
1540
1542public:
1543 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1544 if(name == "country_list") {
1545 return make_element_by_type<wargoal_offer_country_listbox>(state, id);
1546 } else if(name == "cancel_select") {
1547 return make_element_by_type<wargoal_cancel_country_select>(state, id);
1548 } else {
1549 return nullptr;
1550 }
1551 }
1552};
1553
1555private:
1556 wargoal_offer_setup_window* wargoal_setup_win = nullptr;
1557 wargoal_offer_country_select_window* wargoal_country_win = nullptr;
1558 wargoal_target_country_select_window* wargoal_target_win = nullptr;
1559
1560 dcon::nation_id offer_made_to;
1561 dcon::nation_id wargoal_against;
1562 dcon::cb_type_id cb_to_use;
1563 dcon::state_definition_id target_state;
1564 dcon::national_identity_id target_country;
1565 bool will_call_allies = false;
1566 bool wargoal_decided_upon = false;
1567
1568 void select_mode(sys::state& state) {
1570 seldata.single_state_select = true;
1571 // Populate selectable states...
1572 dcon::nation_id target = wargoal_against;
1573 auto actor = state.local_player_nation;
1574 dcon::cb_type_id cb = cb_to_use;
1575 auto secondary_tag = target_country;
1576 auto allowed_substate_regions = state.world.cb_type_get_allowed_substate_regions(cb);
1577 if(allowed_substate_regions) {
1578 auto in_nation = state.world.national_identity_get_nation_from_identity_holder(secondary_tag);
1579 for(auto v : state.world.nation_get_overlord_as_ruler(target)) {
1580 if(v.get_subject().get_is_substate()) {
1581 for(auto si : state.world.nation_get_state_ownership(target)) {
1582 if(trigger::evaluate(state, allowed_substate_regions, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(actor)) &&
1583 command::can_invite_to_crisis(state, actor, offer_made_to, wargoal_against, cb_to_use, si.get_state().get_definition(), target_country, in_nation)) {
1584 seldata.selectable_states.push_back(si.get_state().get_definition().id);
1585 }
1586 }
1587 }
1588 }
1589 } else {
1590 auto allowed_states = state.world.cb_type_get_allowed_states(cb);
1591 if(auto allowed_countries = state.world.cb_type_get_allowed_countries(cb); allowed_countries) {
1592 auto in_nation = state.world.national_identity_get_nation_from_identity_holder(secondary_tag);
1593 for(auto si : state.world.nation_get_state_ownership(target)) {
1594 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(in_nation)) &&
1595 command::can_invite_to_crisis(state, actor, offer_made_to, wargoal_against, cb_to_use, si.get_state().get_definition(), target_country, in_nation)) {
1596 seldata.selectable_states.push_back(si.get_state().get_definition().id);
1597 }
1598 }
1599 } else {
1600 auto in_nation = state.world.national_identity_get_nation_from_identity_holder(secondary_tag);
1601 for(auto si : state.world.nation_get_state_ownership(target)) {
1602 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(actor)) &&
1603 command::can_invite_to_crisis(state, actor, offer_made_to, wargoal_against, cb_to_use, si.get_state().get_definition(), target_country, in_nation)) {
1604 seldata.selectable_states.push_back(si.get_state().get_definition().id);
1605 }
1606 }
1607 }
1608 }
1609 seldata.on_select = [&](sys::state& state, dcon::state_definition_id sdef) {
1610 target_state = sdef;
1611 wargoal_decided_upon = true;
1612 wargoal_setup_win->set_visible(state, true);
1613 wargoal_country_win->set_visible(state, false);
1615 };
1616 seldata.on_cancel = [&](sys::state& state) {
1617 target_state = dcon::state_definition_id{};
1619 wargoal_setup_win->set_visible(state, false);
1620 //wargoal_state_win->set_visible(state, false);
1621 wargoal_country_win->set_visible(state, true);
1622 } else {
1623 cb_to_use = dcon::cb_type_id{};
1624 wargoal_decided_upon = false;
1625 wargoal_setup_win->set_visible(state, true);
1626 //wargoal_state_win->set_visible(state, false);
1627 wargoal_country_win->set_visible(state, false);
1628 }
1630 };
1631 state.start_state_selection(seldata);
1632 }
1633public:
1634 void reset_window(sys::state& state, dcon::nation_id offer_to) {
1635 wargoal_against = dcon::nation_id{};
1636 offer_made_to = offer_to;
1637 cb_to_use = dcon::cb_type_id{};
1638 target_state = dcon::state_definition_id{};
1639 target_country = dcon::national_identity_id{};
1640 will_call_allies = false;
1641 wargoal_decided_upon = false;
1642
1643 wargoal_setup_win->set_visible(state, false);
1644 //wargoal_state_win->set_visible(state, false);
1645 wargoal_country_win->set_visible(state, false);
1646 wargoal_target_win->set_visible(state, true);
1647 }
1648
1649 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1650 if(name == "background") {
1651 auto ptr = make_element_by_type<draggable_target>(state, id);
1652 ptr->base_data.size = base_data.size; // Nudge size for proper sizing
1653 return ptr;
1654 } else if(name == "leftshield") {
1655 return make_element_by_type<nation_player_flag>(state, id);
1656 } else if(name == "rightshield") {
1657 return make_element_by_type<flag_button>(state, id);
1658 } else if(name == "title") {
1659 return make_element_by_type<wargoal_offer_title>(state, id);
1660 } else if(name == "description") {
1661 return make_element_by_type<wargoal_offer_description1>(state, id);
1662 } else if(name == "wargoal_add_effect") {
1663 return make_element_by_type<wargoal_offer_add_window>(state, id);
1664 } else if(name == "wargoal_success_effect" || name == "wargoal_failure_effect") {
1665 return make_element_by_type<invisible_element>(state, id);
1666 } else if(name == "description2") {
1667 return make_element_by_type<wargoal_offer_description2>(state, id);
1668 } else if(name == "acceptance") {
1669 return make_element_by_type<simple_text_element_base>(state, id);
1670 } else if(name == "call_allies_checkbox") {
1671 return make_element_by_type<invisible_element>(state, id);
1672 } if(name == "call_allies_checkbox") {
1673 return make_element_by_type<invisible_element>(state, id);
1674 } else if(name == "run_conference_checkbox") {
1675 return make_element_by_type<invisible_element>(state, id);
1676 } else if(name == "agreebutton") {
1677 return make_element_by_type<wargoal_offer_agree_button>(state, id);
1678 } else if(name == "declinebutton") {
1679 return make_element_by_type<cancel_pick_wg_button>(state, id);
1680 } else if(name == "wargoal_setup") {
1681 auto ptr = make_element_by_type<wargoal_target_country_select_window>(state, id);
1682 wargoal_target_win = ptr.get();
1683 ptr->set_visible(state, true);
1684 return ptr;
1685 } else if(name == "wargoal_state_select") {
1686 return make_element_by_type<invisible_element>(state, id);
1687 } else if(name == "wargoal_country_select") {
1688 {
1689 auto ptr = make_element_by_type<wargoal_offer_setup_window>(state, id);
1690 wargoal_setup_win = ptr.get();
1691 ptr->set_visible(state, false);
1692 add_child_to_front(std::move(ptr));
1693 }
1694 {
1695 auto ptr = make_element_by_type<wargoal_offer_country_select_window>(state, id);
1696 wargoal_country_win = ptr.get();
1697 ptr->set_visible(state, false);
1698 return ptr;
1699 }
1700 } else {
1701 return nullptr;
1702 }
1703 }
1704
1705 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1706 if(payload.holds_type<dcon::nation_id>()) {
1707 payload.emplace<dcon::nation_id>(offer_made_to);
1708 } else if(payload.holds_type<get_target>()) {
1709 payload.emplace<get_target>(get_target{ wargoal_against });
1710 } else if(payload.holds_type<get_offer_to>()) {
1711 payload.emplace<get_offer_to>(get_offer_to{ offer_made_to });
1712 } else if(payload.holds_type< check_wg_completion>()) {
1713 payload.emplace<check_wg_completion>(check_wg_completion{ wargoal_decided_upon });
1715 } else if(payload.holds_type<element_selection_wrapper<dcon::cb_type_id>>()) {
1716 cb_to_use = any_cast<element_selection_wrapper<dcon::cb_type_id>>(payload).data;
1717 if(!cb_to_use) {
1718 wargoal_against = dcon::nation_id{};
1719 cb_to_use = dcon::cb_type_id{};
1720 target_state = dcon::state_definition_id{};
1721 target_country = dcon::national_identity_id{};
1722 wargoal_decided_upon = false;
1723
1724 wargoal_setup_win->set_visible(state, false);
1725 //wargoal_state_win->set_visible(state, false);
1726 wargoal_country_win->set_visible(state, false);
1727 wargoal_target_win->set_visible(state, true);
1729 wargoal_setup_win->set_visible(state, false);
1730 //wargoal_state_win->set_visible(state, false);
1731 wargoal_country_win->set_visible(state, true);
1732 wargoal_target_win->set_visible(state, false);
1733 } else if(military::cb_requires_selection_of_a_state(state, cb_to_use)) {
1734 wargoal_setup_win->set_visible(state, false);
1735 //wargoal_state_win->set_visible(state, true);
1736 wargoal_country_win->set_visible(state, false);
1737 wargoal_target_win->set_visible(state, false);
1738 select_mode(state);
1739 } else {
1740 wargoal_decided_upon = true;
1741 wargoal_setup_win->set_visible(state, true);
1742 //wargoal_state_win->set_visible(state, false);
1743 wargoal_country_win->set_visible(state, false);
1744 wargoal_target_win->set_visible(state, false);
1745 }
1748 } else if(payload.holds_type<element_selection_wrapper<dcon::national_identity_id>>()) {
1749 target_country = any_cast<element_selection_wrapper<dcon::national_identity_id>>(payload).data;
1750
1751 if(target_country) { // goto next step
1753 wargoal_setup_win->set_visible(state, true);
1754 //wargoal_state_win->set_visible(state, true);
1755 wargoal_country_win->set_visible(state, false);
1756 wargoal_target_win->set_visible(state, true);
1757 select_mode(state);
1758 } else {
1759 wargoal_setup_win->set_visible(state, true);
1760 //wargoal_state_win->set_visible(state, false);
1761 wargoal_country_win->set_visible(state, false);
1762 wargoal_target_win->set_visible(state, false);
1763 wargoal_decided_upon = true;
1764 }
1765 } else {
1766 wargoal_decided_upon = false;
1767 cb_to_use = dcon::cb_type_id{};
1768 wargoal_setup_win->set_visible(state, true);
1769 //wargoal_state_win->set_visible(state, false);
1770 wargoal_country_win->set_visible(state, false);
1771 wargoal_target_win->set_visible(state, false);
1772 }
1773
1776 } else if(payload.holds_type<set_target>()) {
1777 wargoal_against = any_cast<set_target>(payload).n;
1778 if(wargoal_against) {
1779 wargoal_decided_upon = false;
1780 cb_to_use = dcon::cb_type_id{};
1781 wargoal_setup_win->set_visible(state, true);
1782 //wargoal_state_win->set_visible(state, false);
1783 wargoal_country_win->set_visible(state, false);
1784 wargoal_target_win->set_visible(state, false);
1785 }
1787 } else if(payload.holds_type<dcon::cb_type_id>()) {
1788 payload.emplace<dcon::cb_type_id>(cb_to_use);
1790 } else if(payload.holds_type<dcon::state_definition_id>()) {
1791 payload.emplace<dcon::state_definition_id>(target_state);
1793 } else if(payload.holds_type<dcon::national_identity_id>()) {
1794 payload.emplace<dcon::national_identity_id>(target_country);
1796 } else if(payload.holds_type<bool>()) {
1797 payload.emplace<bool>(will_call_allies);
1799 }
1801 }
1802};
1803
1804}
dcon::text_key get_name() noexcept
void set_button_text(sys::state &state, std::string const &new_text)
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(sys::state &state) noexcept override
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
void impl_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 on_update(sys::state &state) 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
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void populate_layout(sys::state &state, text::endless_layout &contents) noexcept override
void populate_layout(sys::state &state, text::endless_layout &contents) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) 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_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
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
void on_create(sys::state &state) noexcept override
void reset_window(sys::state &state, dcon::nation_id offer_to)
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_create(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_create(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) 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 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
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::string_view get_row_element_name() 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
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) 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
std::string_view get_row_element_name() 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
void populate_layout(sys::state &state, text::endless_layout &contents) noexcept override
void populate_layout(sys::state &state, text::endless_layout &contents) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_create(sys::state &state) noexcept override
std::string_view get_row_element_name() 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
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void 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
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::string_view get_row_element_name() 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
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
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
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
bool can_invite_to_crisis(sys::state &state, dcon::nation_id source, dcon::nation_id invitation_to, dcon::nation_id target, dcon::cb_type_id primary_cb, dcon::state_definition_id cb_state, dcon::national_identity_id cb_tag, dcon::nation_id cb_secondary_nation)
Definition: commands.cpp:4506
bool can_add_war_goal(sys::state &state, dcon::nation_id source, dcon::war_id w, dcon::nation_id target, dcon::cb_type_id cb_type, dcon::state_definition_id cb_state, dcon::national_identity_id cb_tag, dcon::nation_id cb_secondary_nation)
Definition: commands.cpp:2838
bool can_declare_war(sys::state &state, dcon::nation_id source, dcon::nation_id target, dcon::cb_type_id primary_cb, dcon::state_definition_id cb_state, dcon::national_identity_id cb_tag, dcon::nation_id cb_secondary_nation)
Definition: commands.cpp:2709
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)
void switch_scene(sys::state &state, scene_id ui_scene)
Definition: game_scene.cpp:13
constexpr uint32_t is_not_constructing_cb
Definition: military.hpp:12
constexpr uint32_t always
Definition: military.hpp:10
bool are_allied_in_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:662
float truce_break_cb_prestige_cost(sys::state &state, dcon::cb_type_id t)
Definition: military.cpp:1587
bool cb_conditions_satisfied(sys::state &state, dcon::nation_id actor, dcon::nation_id target, dcon::cb_type_id cb)
Definition: military.cpp:404
float crisis_cb_addition_infamy_cost(sys::state &state, dcon::cb_type_id type, dcon::nation_id from, dcon::nation_id target, dcon::state_definition_id cb_state)
Definition: military.cpp:2030
bool can_use_cb_against(sys::state &state, dcon::nation_id from, dcon::nation_id target)
Definition: military.cpp:245
bool has_truce_with(sys::state &state, dcon::nation_id attacker, dcon::nation_id target)
Definition: military.cpp:2296
float cb_addition_infamy_cost(sys::state &state, dcon::war_id war, dcon::cb_type_id type, dcon::nation_id from, dcon::nation_id target, dcon::state_definition_id cb_state)
Definition: military.cpp:2038
war_role get_role(sys::state const &state, dcon::war_id w, dcon::nation_id n)
Definition: military.cpp:2501
bool is_attacker(sys::state &state, dcon::war_id w, dcon::nation_id n)
Definition: military.cpp:2493
float truce_break_cb_infamy(sys::state &state, dcon::cb_type_id t, dcon::nation_id target, dcon::state_definition_id cb_state)
Definition: military.cpp:1709
bool cb_requires_selection_of_a_valid_nation(sys::state const &state, dcon::cb_type_id t)
Definition: military.cpp:2057
bool are_in_common_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:673
dcon::war_id find_war_between(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:718
bool cb_instance_conditions_satisfied(sys::state &state, dcon::nation_id actor, dcon::nation_id target, dcon::cb_type_id cb, dcon::state_definition_id st, dcon::national_identity_id tag, dcon::nation_id secondary)
Definition: military.cpp:471
float truce_break_cb_militancy(sys::state &state, dcon::cb_type_id t)
Definition: military.cpp:1648
float cb_infamy(sys::state &state, dcon::cb_type_id t, dcon::nation_id target, dcon::state_definition_id cb_state)
Definition: military.cpp:1519
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:649
bool cb_requires_selection_of_a_liberatable_tag(sys::state const &state, dcon::cb_type_id t)
Definition: military.cpp:2061
int32_t peace_cost(sys::state &state, dcon::war_id war, dcon::cb_type_id wargoal, dcon::nation_id from, dcon::nation_id target, dcon::nation_id secondary_nation, dcon::state_definition_id wargoal_state, dcon::national_identity_id wargoal_tag)
Definition: military.cpp:1799
bool can_add_always_cb_to_war(sys::state &state, dcon::nation_id actor, dcon::nation_id target, dcon::cb_type_id cb, dcon::war_id w)
Definition: military.cpp:260
bool defenders_have_status_quo_wargoal(sys::state const &state, dcon::war_id w)
Definition: military.cpp:768
bool war_goal_would_be_duplicate(sys::state &state, dcon::nation_id source, dcon::war_id w, dcon::nation_id target, dcon::cb_type_id cb_type, dcon::state_definition_id cb_state, dcon::national_identity_id cb_tag, dcon::nation_id cb_secondary_nation)
Definition: military.cpp:7693
float successful_cb_prestige(sys::state &state, dcon::cb_type_id t, dcon::nation_id actor)
Definition: military.cpp:1964
bool cb_requires_selection_of_a_state(sys::state const &state, dcon::cb_type_id t)
Definition: military.cpp:2065
bool are_allied(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: nations.cpp:685
float prestige_score(sys::state const &state, dcon::nation_id n)
Definition: nations.cpp:961
uint32_t pack_color(float r, float g, float b)
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1823
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1904
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_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:797
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
Definition: text.cpp:880
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1831
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5895
int32_t calculate_partial_score(sys::state &state, dcon::nation_id target, dcon::cb_type_id id, dcon::state_definition_id state_def, dcon::national_identity_id second_nation)
void effect_description(sys::state &state, text::layout_base &layout, dcon::effect_key k, int32_t primary_slot, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
void trigger_description(sys::state &state, text::layout_base &layout, dcon::trigger_key k, int32_t primary_slot=-1, int32_t this_slot=-1, int32_t from_slot=-1)
message_result
uint uint32_t
std::vector< dcon::state_definition_id > selectable_states
std::function< void(sys::state &, dcon::state_definition_id)> on_select
std::function< void(sys::state &)> on_cancel
Holds important data about the game world, state, and other data regarding windowing,...