Project Alice
Loading...
Searching...
No Matches
diplomatic.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> get_selected_diplomatic_color(sys::state& state) {
17 // This could be stored in an other place
18 uint32_t causus_belli_color = 0x00AAFF;
19 uint32_t ally_color = 0xFFAA00;
20 uint32_t selected_color = 0x00FF00; // Also unclaimed cores stripes color
21 uint32_t sphere_color = 0x55AA55;
22 uint32_t puppet_color = 0x009900;
23 uint32_t non_cores_color = 0xFFFFFF;
24 uint32_t war_color = 0x0000FF;
25 uint32_t cultural_union_color = 0x00FFFF;
26
27 uint32_t province_size = state.world.province_size() + 1;
28 uint32_t texture_size = province_size + 256 - province_size % 256;
29 std::vector<uint32_t> prov_color(texture_size * 2);
30
31 auto fat_selected_id = dcon::fatten(state.world, state.map_state.get_selected_province());
32 auto selected_nation = fat_selected_id.get_nation_from_province_ownership();
33
34 if(!bool(selected_nation)) {
35 selected_nation = state.local_player_nation;
36 }
37
38 std::vector<dcon::nation_id> enemies, allies, sphere;
39
40 // Get all enemies
41 for(auto wa : state.world.nation_get_war_participant(selected_nation)) {
42 bool is_attacker = wa.get_is_attacker();
43 for(auto o : wa.get_war().get_war_participant()) {
44 if(o.get_is_attacker() != is_attacker) {
45 enemies.push_back(o.get_nation().id);
46 }
47 }
48 }
49
50 // Get all allies
51 selected_nation.for_each_diplomatic_relation([&](dcon::diplomatic_relation_fat_id relation_id) {
52 if(relation_id.get_are_allied()) {
53 dcon::nation_id ally_id = relation_id.get_related_nations(0).id != selected_nation.id
54 ? relation_id.get_related_nations(0).id
55 : relation_id.get_related_nations(1).id;
56 allies.push_back(ally_id);
57 }
58 });
59
60 auto selected_primary_culture = selected_nation.get_primary_culture();
61
62 state.world.for_each_province([&](dcon::province_id prov_id) {
63 auto fat_id = dcon::fatten(state.world, prov_id);
64 auto i = province::to_map_id(prov_id);
65 uint32_t color = 0x222222;
66 uint32_t stripe_color = 0x222222;
67
68 auto fat_owner = fat_id.get_province_ownership().get_nation();
69 if(bool(fat_owner)) {
70 // Selected nation
71 if(fat_owner.id == selected_nation.id) {
72 color = selected_color;
73 // By default asume its not a core
74 stripe_color = non_cores_color;
75 } else {
76 // Cultural Union
77 auto cultural_union_identity = selected_primary_culture.get_culture_group_membership().get_group().get_identity_from_cultural_union_of();
78 fat_id.for_each_core([&](dcon::core_fat_id core_id) {
79 if(core_id.get_identity().id == cultural_union_identity.id) {
80 stripe_color = cultural_union_color;
81 }
82 });
83
84 // War
85 if(std::find(enemies.begin(), enemies.end(), fat_owner.id) != enemies.end()) {
86 color = war_color;
87 }
88
89 // Allies
90 if(std::find(allies.begin(), allies.end(), fat_owner.id) != allies.end()) {
91 color = ally_color;
92 }
93
94 // Sphere
95 if(fat_owner.get_in_sphere_of() == selected_nation) {
96 color = sphere_color;
97 }
98
99 // Puppets
100 auto province_overlord_id = fat_id.get_province_ownership().get_nation().get_overlord_as_subject();
101 if(bool(province_overlord_id) && province_overlord_id.get_ruler().id == selected_nation.id) {
102 color = puppet_color;
103 } else {
104 auto selected_overlord_id = selected_nation.get_overlord_as_subject();
105 if(bool(selected_overlord_id) && selected_overlord_id.get_ruler().id == fat_owner.id) {
106 color = puppet_color;
107 }
108 }
109 }
110
111 // Core
112 fat_id.for_each_core([&](dcon::core_fat_id core_id) {
113 if(core_id.get_identity().get_nation_from_identity_holder().id == selected_nation.id) {
114 stripe_color = selected_color;
115 }
116 });
117 }
118
119 // If no stripe has been set, use the prov color
120 if(stripe_color == 0x222222) {
121 stripe_color = color;
122 }
123
124 prov_color[i] = color;
125 prov_color[i + texture_size] = stripe_color;
126 });
127
128 return prov_color;
129}
130
131std::vector<uint32_t> diplomatic_map_from(sys::state& state) {
132 std::vector<uint32_t> prov_color;
133
134 if(state.map_state.get_selected_province()) {
135 prov_color = get_selected_diplomatic_color(state);
136 } else {
137 prov_color = get_selected_diplomatic_color(state);
138 }
139
140 return prov_color;
141}
std::vector< uint32_t > diplomatic_map_from(sys::state &state)
Definition: diplomatic.hpp:131
std::vector< uint32_t > get_selected_diplomatic_color(sys::state &state)
Definition: diplomatic.hpp:3
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr uint16_t to_map_id(dcon::province_id id)
Definition: province.hpp:10
uint uint32_t