10 auto target = retrieve<dcon::nation_id>(
state,
parent);
13 auto const we_lead = (
state.local_player_nation ==
state.world.war_get_primary_attacker(war) ||
state.local_player_nation ==
state.world.war_get_primary_defender(war));
14 auto const they_lead = (target ==
state.world.war_get_primary_attacker(war) || target ==
state.world.war_get_primary_defender(war));
23template<
bool is_concession>
37 if(
name ==
"war_desc") {
38 return make_element_by_type<diplomacy_peace_pick_side_description>(
state,
id);
39 }
else if(
name ==
"offer_button") {
40 return make_element_by_type<diplomacy_peace_tab_button<true>>(
state, id);
41 }
else if(
name ==
"offer_text") {
42 return make_element_by_type<simple_text_element_base>(
state,
id);
43 }
else if(
name ==
"demand_button") {
44 return make_element_by_type<diplomacy_peace_tab_button<false>>(
state, id);
45 }
else if(
name ==
"demand_text") {
46 return make_element_by_type<simple_text_element_base>(
state,
id);
67 dcon::national_identity_id get_current_nation(
sys::state&
state)
noexcept override {
68 auto wg = retrieve<dcon::wargoal_id>(
state,
parent);
69 return state.world.nation_get_identity_from_identity_holder(
state.world.wargoal_get_target_nation(wg));
74 dcon::national_identity_id get_current_nation(
sys::state&
state)
noexcept override {
75 auto wg = retrieve<dcon::wargoal_id>(
state,
parent);
76 return state.world.nation_get_identity_from_identity_holder(
state.world.wargoal_get_added_by(wg));
83 dcon::wargoal_id wg = retrieve<dcon::wargoal_id>(
state,
parent);
84 dcon::cb_type_id cbt =
state.world.wargoal_get_type(wg);
89 if(
state.world.wargoal_get_secondary_nation(wg))
91 else if(
state.world.wargoal_get_associated_tag(wg))
104 int32_t score =
military::peace_cost(
state, retrieve<dcon::war_id>(
state,
parent), wg.get_type(), wg.get_added_by(), wg.get_target_nation(), wg.get_secondary_nation(), wg.get_associated_state(), wg.get_associated_tag());
112 auto wg = retrieve<dcon::wargoal_id>(
state,
parent);
117 frame = any_cast<toggled_wargoal>(setting).added ? 1 : 0;
121 auto wg = retrieve<dcon::wargoal_id>(
state,
parent);
129 if(
name ==
"select") {
130 return make_element_by_type<diplomacy_peace_select_button>(
state,
id);
131 }
else if(
name ==
"country_flag") {
132 return make_element_by_type<peace_wg_from>(
state,
id);
133 }
else if(
name ==
"country_flag2") {
134 return make_element_by_type<peace_wg_to>(
state,
id);
135 }
else if(
name ==
"cb_direction_arrow") {
136 return make_element_by_type<image_element_base>(
state,
id);
137 }
else if(
name ==
"select_label") {
138 return make_element_by_type<diplomacy_peace_wargoal_text>(
state,
id);
139 }
else if(
name ==
"score") {
140 return make_element_by_type<diplomacy_peace_wargoal_score_text>(
state,
id);
150 return "peace_goal_item";
156 auto is_concession = retrieve<bool>(
state,
parent);
158 auto target = retrieve<dcon::nation_id>(
state,
parent);
161 auto we_lead = (
state.local_player_nation ==
state.world.war_get_primary_attacker(war) ||
state.local_player_nation ==
state.world.war_get_primary_defender(war));
162 auto they_lead = (target ==
state.world.war_get_primary_attacker(war) || target ==
state.world.war_get_primary_defender(war));
165 if(they_lead && we_lead && is_concession) {
166 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
171 }
else if(they_lead && we_lead && !is_concession) {
172 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
177 }
else if(!they_lead && !is_concession) {
178 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
179 if(wg.get_wargoal().get_target_nation() == target || wg.get_wargoal().get_target_nation().get_overlord_as_subject().get_ruler() == target) {
183 }
else if(!we_lead && is_concession) {
184 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
185 if(wg.get_wargoal().get_target_nation() ==
state.local_player_nation || wg.get_wargoal().get_target_nation().get_overlord_as_subject().get_ruler() ==
state.local_player_nation) {
189 }
else if(we_lead && is_concession) {
190 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
191 if(wg.get_wargoal().get_added_by() == target || wg.get_wargoal().get_added_by().get_overlord_as_subject().get_ruler() == target) {
195 }
else if(they_lead && !is_concession) {
196 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
197 if(wg.get_wargoal().get_added_by() ==
state.local_player_nation || wg.get_wargoal().get_added_by().get_overlord_as_subject().get_ruler() ==
state.local_player_nation) {
225 if(
name ==
"wargoal_list") {
226 return make_element_by_type<diplomacy_peace_goal_listbox>(
state,
id);
227 }
else if(
name ==
"score") {
228 return make_element_by_type<total_peace_cost>(
state,
id);
229 }
else if(
name ==
"acceptance") {
230 return make_element_by_type<simple_text_element_base>(
state,
id);
240 const dcon::war_id w = retrieve<dcon::war_id>(
state,
parent);
241 const dcon::nation_id target = retrieve<dcon::nation_id>(
state,
parent);
242 if( (
state.world.war_get_primary_attacker(w) == target &&
state.world.war_get_primary_defender(w) ==
state.local_player_nation)
243 || (
state.world.war_get_primary_defender(w) == target &&
state.world.war_get_primary_attacker(w) ==
state.local_player_nation)) {
246 if(
state.world.war_get_primary_attacker(w) ==
state.local_player_nation)
268 auto target = retrieve<dcon::nation_id>(
state,
parent);
271 auto const we_lead = (
state.local_player_nation ==
state.world.war_get_primary_attacker(war) ||
state.local_player_nation ==
state.world.war_get_primary_defender(war));
276 if(
state.world.nation_get_is_player_controlled(target)) {
280 auto res = retrieve<test_acceptance>(
state,
parent);
290 bool is_concession =
false;
291 std::vector<toggled_wargoal> wargoals;
297 auto target = retrieve<dcon::nation_id>(
state,
parent);
299 is_concession =
false;
301 if(
state.world.war_get_primary_attacker(war) ==
state.local_player_nation &&
state.world.war_get_primary_defender(war) == target) {
302 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
305 }
else if(
state.world.war_get_primary_attacker(war) == target &&
state.world.war_get_primary_defender(war) ==
state.local_player_nation) {
306 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
310 for(
auto wg :
state.world.war_get_wargoals_attached(war)) {
311 if(
state.world.war_get_primary_attacker(war) ==
state.local_player_nation ||
state.world.war_get_primary_defender(war) ==
state.local_player_nation) {
312 if(wg.get_wargoal().get_added_by() == target || wg.get_wargoal().get_added_by().get_overlord_as_subject().get_ruler() == target || wg.get_wargoal().get_target_nation() == target || wg.get_wargoal().get_target_nation().get_overlord_as_subject().get_ruler() == target) {
316 if(wg.get_wargoal().get_added_by() ==
state.local_player_nation || wg.get_wargoal().get_added_by().get_overlord_as_subject().get_ruler() ==
state.local_player_nation || wg.get_wargoal().get_target_nation() ==
state.local_player_nation || wg.get_wargoal().get_target_nation().get_overlord_as_subject().get_ruler() ==
state.local_player_nation) {
325 if(
name ==
"background") {
326 auto ptr = make_element_by_type<draggable_target>(
state,
id);
329 }
else if(
name ==
"diplo_peace_bg") {
330 return make_element_by_type<image_element_base>(
state,
id);
331 }
else if(
name ==
"leftshield") {
332 return make_element_by_type<nation_player_flag>(
state,
id);
333 }
else if(
name ==
"rightshield") {
334 return make_element_by_type<flag_button>(
state,
id);
335 }
else if(
name ==
"title") {
336 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
340 }
else if(
name ==
"warscore_label") {
341 return make_element_by_type<simple_text_element_base>(
state,
id);
342 }
else if(
name ==
"warscore") {
343 return make_element_by_type<diplomacy_peace_total_warscore>(
state,
id);
344 }
else if(
name ==
"agreebutton") {
345 return make_element_by_type<diplomacy_peace_send>(
state,
id);
346 }
else if(
name ==
"declinebutton") {
347 return make_element_by_type<generic_close_button>(
state,
id);
348 }
else if(
name ==
"pick_side") {
349 return make_element_by_type<diplomacy_peace_pick_side_window>(
state,
id);
350 }
else if(
name ==
"setup_goals") {
351 return make_element_by_type<diplomacy_peace_setup_goals_window>(
state,
id);
358 if(payload.holds_type<dcon::war_id>()) {
359 const dcon::nation_id n = retrieve<dcon::nation_id>(
state,
parent);
361 payload.emplace<dcon::war_id>(w);
364 is_concession = any_cast<element_selection_wrapper<bool>>(payload).data;
367 }
else if(payload.holds_type<
bool>()) {
368 payload.emplace<
bool>(is_concession);
372 for(
auto& w : wargoals) {
381 for(
auto& w : wargoals) {
389 }
else if(payload.holds_type<
offer_cost>()) {
391 auto target = retrieve<dcon::nation_id>(
state,
parent);
395 for(
auto& twg : wargoals) {
397 auto wg = fatten(
state.world, twg.wg);
399 total +=
military::peace_cost(
state, war, wg.get_type(), wg.get_added_by(), wg.get_target_nation(), wg.get_secondary_nation(), wg.get_associated_state(), wg.get_associated_tag());
407 auto target = retrieve<dcon::nation_id>(
state,
parent);
411 for(
auto& twg : wargoals) {
413 auto wg = fatten(
state.world, twg.wg);
423 auto target = retrieve<dcon::nation_id>(
state,
parent);
425 auto war_duration =
state.current_date.value -
state.world.war_get_start_date(w).value;
427 int32_t target_personal_po_value = 0;
428 int32_t potential_peace_score_against = 0;
429 int32_t my_side_against_target = 0;
431 int32_t overall_po_value = 0;
432 int32_t my_po_target = 0;
433 auto prime_attacker =
state.world.war_get_primary_attacker(w);
434 auto prime_defender =
state.world.war_get_primary_defender(w);
435 bool contains_sq =
false;
437 for(
auto& twg : wargoals) {
438 auto wg = fatten(
state.world, twg.wg);
439 auto wg_value =
military::peace_cost(
state, w, wg.get_type(), wg.get_added_by(), wg.get_target_nation(), wg.get_secondary_nation(), wg.get_associated_state(), wg.get_associated_tag());
442 overall_po_value += wg_value;
443 if(wg.get_target_nation() == target) {
444 target_personal_po_value += wg_value;
446 if(wg.get_target_nation() ==
state.local_player_nation) {
447 my_side_against_target += wg_value;
452 if(wg.get_target_nation() == target || wg.get_added_by() == target) {
453 if(wg.get_target_nation() == target && (wg.get_added_by() ==
state.local_player_nation ||
state.local_player_nation == prime_attacker ||
state.local_player_nation == prime_defender)) {
454 potential_peace_score_against += wg_value;
456 if(wg.get_added_by() == target && (wg.get_target_nation() ==
state.local_player_nation ||
state.local_player_nation == prime_attacker ||
state.local_player_nation == prime_defender)) {
457 my_po_target += wg_value;
463 target,
state.local_player_nation,
464 prime_attacker, prime_defender,
467 overall_po_value, my_po_target,
468 target_personal_po_value, potential_peace_score_against,
469 my_side_against_target, my_side_peace_cost,
470 war_duration, contains_sq);
472 if(
state.cheat_data.always_accept_deals)
500 dcon::national_identity_id get_current_nation(
sys::state&
state)
noexcept override {
502 return state.world.nation_get_identity_from_identity_holder(wg.target_nation);
507 dcon::national_identity_id get_current_nation(
sys::state&
state)
noexcept override {
509 return state.world.nation_get_identity_from_identity_holder(wg.added_by);
517 dcon::cb_type_id cbt = wg.cb;
522 if(wg.secondary_nation)
549 frame = any_cast<toggled_crisis_wargoal>(setting).added ? 1 : 0;
561 if(
name ==
"select") {
562 return make_element_by_type<diplomacy_crisis_peace_select_button>(
state,
id);
563 }
else if(
name ==
"country_flag") {
564 return make_element_by_type<crisis_peace_wg_from>(
state,
id);
565 }
else if(
name ==
"country_flag2") {
566 return make_element_by_type<crisis_peace_wg_to>(
state,
id);
567 }
else if(
name ==
"select_label") {
568 return make_element_by_type<diplomacy_crisis_peace_wargoal_text>(
state,
id);
569 }
else if(
name ==
"score") {
570 return make_element_by_type<diplomacy_crisis_peace_wargoal_score_text>(
state,
id);
580 return "peace_goal_item";
586 auto is_concession = retrieve<bool>(
state,
parent);
588 bool attacker_filter = ((
state.local_player_nation ==
state.primary_crisis_attacker) != is_concession);
590 for(int32_t i = 0; i <
count; ++i) {
603 if(
name ==
"wargoal_list") {
604 return make_element_by_type<diplomacy_crisis_peace_goal_listbox>(
state,
id);
605 }
else if(
name ==
"score") {
606 return make_element_by_type<total_peace_cost>(
state,
id);
614 bool is_concession =
false;
615 std::vector<bool> wargoals;
621 is_concession =
false;
625 if(
name ==
"background") {
626 auto ptr = make_element_by_type<draggable_target>(
state,
id);
629 }
else if(
name ==
"leftshield") {
630 return make_element_by_type<nation_player_flag>(
state,
id);
631 }
else if(
name ==
"rightshield") {
632 return make_element_by_type<flag_button>(
state,
id);
633 }
else if(
name ==
"title") {
634 auto ptr = make_element_by_type<simple_text_element_base>(
state,
id);
638 }
else if(
name ==
"warscore_label") {
639 return make_element_by_type<simple_text_element_base>(
state,
id);
640 }
else if(
name ==
"warscore") {
641 return make_element_by_type<diplomacy_crisis_peace_total_warscore>(
state,
id);
642 }
else if(
name ==
"agreebutton") {
643 return make_element_by_type<diplomacy_peace_send>(
state,
id);
644 }
else if(
name ==
"declinebutton") {
645 return make_element_by_type<generic_close_button>(
state,
id);
646 }
else if(
name ==
"pick_side") {
647 return make_element_by_type<diplomacy_peace_pick_side_window>(
state,
id);
648 }
else if(
name ==
"setup_goals") {
649 return make_element_by_type<diplomacy_crisis_peace_setup_goals_window>(
state,
id);
656 if(payload.holds_type<dcon::nation_id>()) {
657 payload.emplace<dcon::nation_id>(
state.local_player_nation ==
state.primary_crisis_attacker ?
state.primary_crisis_defender :
state.primary_crisis_attacker);
659 }
else if(payload.holds_type<dcon::national_identity_id>()) {
660 payload.emplace<dcon::national_identity_id>(
state.world.nation_get_identity_from_identity_holder(
state.local_player_nation ==
state.primary_crisis_attacker ?
state.primary_crisis_defender :
state.primary_crisis_attacker));
663 is_concession = any_cast<element_selection_wrapper<bool>>(payload).data;
666 }
else if(payload.holds_type<
bool>()) {
667 payload.emplace<
bool>(is_concession);
683 bool attacker_filter = ((
state.local_player_nation ==
state.primary_crisis_attacker) != is_concession);
684 for(
uint32_t i = 0; i < wargoals.size(); ++i) {
696 bool attacker_filter = ((
state.local_player_nation ==
state.primary_crisis_attacker) != is_concession);
698 for(
uint32_t i = 0; i < wargoals.size(); ++i) {
709 auto target =
state.local_player_nation ==
state.primary_crisis_attacker ?
state.primary_crisis_defender :
state.primary_crisis_attacker;
710 bool missing_wargoal =
false;
712 bool attacker_filter = ((
state.local_player_nation ==
state.primary_crisis_attacker) != is_concession);
714 for(
uint32_t i = 0; i < wargoals.size(); ++i) {
716 missing_wargoal = missing_wargoal || !wargoals[i];
void impl_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 open_window(sys::state &state)
message_result get(sys::state &state, Cyto::Any &payload) 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
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
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
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_action(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
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void open_window(sys::state &state)
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 impl_get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
std::vector< dcon::wargoal_id > row_contents
void update(sys::state &state)
void set_text(sys::state &state, std::string const &new_text)
void on_update(sys::state &state) noexcept override
#define assert(condition)
bool will_accept_crisis_peace_offer(sys::state &state, dcon::nation_id to, bool is_concession, bool missing_wg)
bool will_accept_peace_offer_value(sys::state &state, dcon::nation_id n, dcon::nation_id from, dcon::nation_id prime_attacker, dcon::nation_id prime_defender, float primary_warscore, float scoreagainst_me, bool offer_from_attacker, bool concession, int32_t overall_po_value, int32_t my_po_target, int32_t target_personal_po_value, int32_t potential_peace_score_against, int32_t my_side_against_target, int32_t my_side_peace_cost, int32_t war_duration, bool contains_sq)
void add_to_crisis_peace_offer(sys::state &state, dcon::nation_id source, dcon::nation_id wargoal_from, 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)
@ send_crisis_peace_offer
@ start_crisis_peace_offer
void add_to_peace_offer(sys::state &state, dcon::nation_id source, dcon::wargoal_id goal)
constexpr uint32_t po_status_quo
float primary_warscore(sys::state &state, dcon::war_id w)
float directed_warscore(sys::state &state, dcon::war_id w, dcon::nation_id primary, dcon::nation_id secondary)
int32_t defender_peace_cost(sys::state &state, dcon::war_id war)
war_role get_role(sys::state const &state, dcon::war_id w, dcon::nation_id n)
int32_t attacker_peace_cost(sys::state &state, dcon::war_id war)
bool is_attacker(sys::state &state, dcon::war_id w, dcon::nation_id n)
dcon::war_id find_war_between(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
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)
bool nth_crisis_war_goal_is_for_attacker(sys::state &state, int32_t index)
military::full_wg get_nth_crisis_war_goal(sys::state &state, int32_t index)
int32_t num_crisis_wargoals(sys::state &state)
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
layout_box open_layout_box(layout_base &dest, int32_t indent)
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
void close_layout_box(columnar_layout &dest, layout_box &box)
void send(sys::state &state, element_base *parent, T value)