Project Alice
Loading...
Searching...
No Matches
gui_common_elements.cpp
Go to the documentation of this file.
2#include "ai.hpp"
3
4namespace ui {
5bool country_category_filter_check(sys::state& state, country_list_filter filt, dcon::nation_id a, dcon::nation_id b) {
6 switch(filt) {
8 return true;
10 return nations::are_allied(state, a, b);
12 return military::are_at_war(state, a, b);
14 return state.world.nation_get_in_sphere_of(b) == a;
16 return bool(state.world.get_nation_adjacency_by_nation_adjacency_pair(a, b));
19 && command::can_ask_for_alliance(state, a, b, false);
21 return (state.world.gp_relationship_get_status(state.world.get_gp_relationship_by_gp_influence_pair(b, a))
23 && state.world.nation_get_in_sphere_of(b) != a;
25 for(const auto sub : state.world.nation_get_overlord_as_ruler(b)) {
26 if(state.world.get_nation_adjacency_by_nation_adjacency_pair(a, sub.get_subject()))
27 return true;
28 }
29 return !state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(b))
30 && state.world.get_nation_adjacency_by_nation_adjacency_pair(a, b);
31 default:
32 return true;
33 }
34}
35
36void sort_countries(sys::state& state, std::vector<dcon::nation_id>& list, country_list_sort sort, bool sort_ascend) {
37 switch(sort) {
39 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
42 return a_name < b_name;
43 };
44 std::stable_sort(list.begin(), list.end(), f);
45 }
46 break;
48 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
49 return state.world.nation_get_industrial_rank(a) < state.world.nation_get_industrial_rank(b);
50 };
51 std::stable_sort(list.begin(), list.end(), f);
52 }
53 break;
55 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
56 return state.world.nation_get_military_rank(a) < state.world.nation_get_military_rank(b);
57 };
58 std::stable_sort(list.begin(), list.end(), f);
59 }
60 break;
62 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
63 return state.world.nation_get_prestige_rank(a) < state.world.nation_get_prestige_rank(b);
64 };
65 std::stable_sort(list.begin(), list.end(), f);
66 }
67 break;
69 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
70 return state.world.nation_get_rank(a) < state.world.nation_get_rank(b);
71 };
72 std::stable_sort(list.begin(), list.end(), f);
73 }
74 break;
76 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
77 auto rid_a = state.world.get_diplomatic_relation_by_diplomatic_pair(state.local_player_nation, a);
78 auto va = bool(rid_a) ? state.world.diplomatic_relation_get_value(rid_a) : 0;
79 auto rid_b = state.world.get_diplomatic_relation_by_diplomatic_pair(state.local_player_nation, b);
80 auto vb = bool(rid_b) ? state.world.diplomatic_relation_get_value(rid_b) : 0;
81 return va > vb;
82 };
83 std::stable_sort(list.begin(), list.end(), f);
84 }
85 break;
87 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
88 auto grid_a = state.world.get_gp_relationship_by_gp_influence_pair(a, state.local_player_nation);
89 auto va = bool(grid_a) ? state.world.gp_relationship_get_status(grid_a) : 0;
90 auto grid_b = state.world.get_gp_relationship_by_gp_influence_pair(b, state.local_player_nation);
91 auto vb = bool(grid_b) ? state.world.gp_relationship_get_status(grid_b) : 0;
94 };
95 std::stable_sort(list.begin(), list.end(), f);
96 }
97 break;
99 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
100 auto rel_a = state.world.get_gp_relationship_by_gp_influence_pair(a, state.local_player_nation);
101 uint8_t rel_flags_a = bool(rel_a) ? state.world.gp_relationship_get_status(rel_a) : 0;
102 auto rel_b = state.world.get_gp_relationship_by_gp_influence_pair(b, state.local_player_nation);
103 uint8_t rel_flags_b = bool(rel_b) ? state.world.gp_relationship_get_status(rel_b) : 0;
104 return (rel_flags_a & nations::influence::priority_mask) > (rel_flags_b & nations::influence::priority_mask);
105 };
106 std::stable_sort(list.begin(), list.end(), f);
107 }
108 break;
110 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
111 return state.world.nation_get_in_sphere_of(a).id.index() > state.world.nation_get_in_sphere_of(b).id.index();
112 };
113 std::stable_sort(list.begin(), list.end(), f);
114 }
115 break;
117 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
118 auto rel_a = state.world.get_gp_relationship_by_gp_influence_pair(a, state.local_player_nation);
119 auto rel_b = state.world.get_gp_relationship_by_gp_influence_pair(b, state.local_player_nation);
120 return state.world.gp_relationship_get_influence(rel_a) > state.world.gp_relationship_get_influence(rel_b);
121 };
122 std::stable_sort(list.begin(), list.end(), f);
123 } break;
125 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
126 auto urel_a = state.world.get_unilateral_relationship_by_unilateral_pair(a, state.local_player_nation);
127 auto urel_b = state.world.get_unilateral_relationship_by_unilateral_pair(b, state.local_player_nation);
128 return state.world.unilateral_relationship_get_foreign_investment(urel_a) >
129 state.world.unilateral_relationship_get_foreign_investment(urel_b);
130 };
131 std::stable_sort(list.begin(), list.end(), f);
132 } break;
134 auto num_factories = [&](dcon::nation_id n) {
135 int32_t total = 0;
136 for(auto p : state.world.nation_get_province_ownership(n)) {
137 auto fac = p.get_province().get_factory_location();
138 total += int32_t(fac.end() - fac.begin());
139 }
140 return total;
141 };
142 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
143 return num_factories(a) > num_factories(b);
144 };
145 std::stable_sort(list.begin(), list.end(), f);
146 } break;
147 default:
148 uint8_t rank = uint8_t(sort) & 0x3F;
149 dcon::nation_id gp = nations::get_nth_great_power(state, rank);
150
152 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
153 auto rel_a = state.world.get_gp_relationship_by_gp_influence_pair(a, gp);
154 auto rel_b = state.world.get_gp_relationship_by_gp_influence_pair(b, gp);
155 return state.world.gp_relationship_get_influence(rel_a) > state.world.gp_relationship_get_influence(rel_b);
156 };
157 std::sort(list.begin(), list.end(), f);
158 } else if((uint8_t(sort) & uint8_t(country_list_sort::gp_investment)) != 0) {
159 auto f = [&](dcon::nation_id a, dcon::nation_id b) {
160 auto urel_a = state.world.get_unilateral_relationship_by_unilateral_pair(a, gp);
161 auto urel_b = state.world.get_unilateral_relationship_by_unilateral_pair(b, gp);
162 return state.world.unilateral_relationship_get_foreign_investment(urel_a) >
163 state.world.unilateral_relationship_get_foreign_investment(urel_b);
164 };
165 std::stable_sort(list.begin(), list.end(), f);
166 } else {
167 assert(0);
168 }
169 break;
170 }
171
172 if(!sort_ascend) {
173 std::reverse(list.begin(), list.end());
174 }
175
176}
177std::string get_status_text(sys::state& state, dcon::nation_id nation_id) {
178 switch(nations::get_status(state, nation_id)) {
180 return text::produce_simple_string(state, "diplomacy_greatnation_status");
182 return text::produce_simple_string(state, "diplomacy_colonialnation_status");
184 return text::produce_simple_string(state, "diplomacy_civilizednation_status");
186 return text::produce_simple_string(state, "diplomacy_almost_western_nation_status");
188 return text::produce_simple_string(state, "diplomacy_uncivilizednation_status");
190 return text::produce_simple_string(state, "diplomacy_primitivenation_status");
191 default:
192 return text::produce_simple_string(state, "diplomacy_greatnation_status");
193 }
194}
195} // namespace ui
#define assert(condition)
Definition: debug.h:74
bool ai_will_accept_alliance(sys::state &state, dcon::nation_id target, dcon::nation_id from)
Definition: ai.cpp:275
bool can_ask_for_alliance(sys::state &state, dcon::nation_id asker, dcon::nation_id target, bool ignore_cost)
Definition: commands.cpp:2297
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:475
constexpr uint8_t priority_zero
Definition: nations.hpp:172
constexpr uint8_t priority_mask
Definition: nations.hpp:171
constexpr uint8_t level_mask
Definition: nations.hpp:163
bool is_influence_level_greater(int32_t l, int32_t r)
Definition: nations.hpp:231
status get_status(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:580
bool are_allied(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: nations.cpp:198
dcon::nation_id get_nth_great_power(sys::state const &state, uint16_t n)
Definition: nations.cpp:57
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 sort_countries(sys::state &state, std::vector< dcon::nation_id > &list, country_list_sort sort, bool sort_ascend)
std::string get_status_text(sys::state &state, dcon::nation_id nation_id)
bool country_category_filter_check(sys::state &state, country_list_filter filt, dcon::nation_id a, dcon::nation_id b)
uchar uint8_t