Project Alice
Loading...
Searching...
No Matches
sphere.hpp
Go to the documentation of this file.
1#pragma once
2
3std::vector<uint32_t> get_global_sphere_color(sys::state& state) {
4
5 uint32_t province_size = state.world.province_size() + 1;
6 uint32_t texture_size = province_size + 256 - province_size % 256;
7
8 std::vector<uint32_t> prov_color(texture_size * 2);
9
10 state.world.for_each_province([&](dcon::province_id prov_id) {
11 auto fat_id = dcon::fatten(state.world, prov_id);
12 auto i = province::to_map_id(prov_id);
13
14 auto owner = fat_id.get_nation_from_province_ownership();
15
16 uint32_t color = 0x222222;
17
18 if(bool(owner)) {
19 if(nations::is_great_power(state, owner.id)) {
20 color = owner.get_color();
21 } else {
22 auto master = owner.get_in_sphere_of();
23 if(bool(master)) {
24 color = master.get_color();
25 }
26 }
27 }
28 prov_color[i] = color;
29 prov_color[i + texture_size] = color;
30 });
31
32 return prov_color;
33}
34
35std::vector<uint32_t> get_selected_sphere_color(sys::state& state) {
52 // Todo: Get better colors?
53 uint32_t gp_color = 0x00FF00; // Green
54 uint32_t inf_color = 0xFF0000; // Blue
55 uint32_t sphere_color = 0x00FFFF; // Yellow
56 uint32_t other_inf_color = 0x0000FF; // Red
57
58 // Province color vector init
59 uint32_t province_size = state.world.province_size() + 1;
60 uint32_t texture_size = province_size + 256 - province_size % 256;
61 std::vector<uint32_t> prov_color(texture_size * 2);
62
63 auto fat_selected_id = dcon::fatten(state.world, state.map_state.get_selected_province());
64 auto selected_nation = fat_selected_id.get_nation_from_province_ownership();
65
66 // Get sphere master if exists
67 auto master = selected_nation.get_in_sphere_of();
68 if(!bool(master) && nations::is_great_power(state, selected_nation)) {
69 master = selected_nation;
70 }
71
72 // Paint only sphere countries
73 if(bool(master)) {
74 state.world.for_each_province([&](dcon::province_id prov_id) {
75 auto fat_id = dcon::fatten(state.world, prov_id);
76 auto i = province::to_map_id(prov_id);
77
78 uint32_t color = 0x222222;
79 uint32_t stripe_color = 0x222222;
80
81 auto owner = fat_id.get_nation_from_province_ownership();
82
83 if(bool(owner)) {
84 if(owner.id == master.id) {
85 color = gp_color;
86 } else {
87 auto master_rel_id = state.world.get_gp_relationship_by_gp_influence_pair(owner, master);
88 if(bool(master_rel_id)) {
89 auto master_rel_status = state.world.gp_relationship_get_status(master_rel_id);
90 auto master_rel_inf = state.world.gp_relationship_get_influence(master_rel_id);
91
92 if(master_rel_status == nations::influence::level_in_sphere || master_rel_inf != 0) {
93 owner.for_each_gp_relationship_as_influence_target([&](dcon::gp_relationship_id rel_id) {
94 // Has more than one influencer
95 if(rel_id != master_rel_id && state.world.gp_relationship_get_influence(rel_id) != 0 &&
96 state.world.gp_relationship_get_influence(rel_id) != 0) {
97 stripe_color = other_inf_color;
98 }
99 });
100
101 if(master_rel_status == nations::influence::level_in_sphere) {
102 color = sphere_color;
103 } else if(master_rel_inf != 0) {
104 color = inf_color;
105 }
106 }
107 }
108 }
109 }
110
111 // If no stripe has been set, use the prov color
112 if(stripe_color == 0x222222) {
113 stripe_color = color;
114 }
115
116 prov_color[i] = color;
117 prov_color[i + texture_size] = stripe_color;
118 });
119 } else { // Paint selected country and influencers
120 state.world.for_each_province([&](dcon::province_id prov_id) {
121 auto fat_id = dcon::fatten(state.world, prov_id);
122 auto i = province::to_map_id(prov_id);
123
124 uint32_t color = 0x222222;
125 uint32_t stripe_color = 0x222222;
126
127 auto owner = fat_id.get_nation_from_province_ownership();
128 if(bool(owner)) {
129 bool is_gp = false;
130 uint8_t rel_count = 0;
131
132 selected_nation.for_each_gp_relationship_as_influence_target([&](dcon::gp_relationship_fat_id relation_id) {
133 if(!is_gp && relation_id.get_influence() > 0) {
134 if(owner.id == selected_nation.id) {
135 rel_count++;
136 }
137 if(relation_id.get_great_power() == owner.id) {
138 is_gp = true;
139 }
140 }
141 });
142
143 if(is_gp) {
144 color = gp_color;
145 } else if(rel_count >= 1) {
146 color = inf_color;
147 if(rel_count > 1) {
148 stripe_color = other_inf_color;
149 }
150 }
151 }
152
153 // If no stripe has been set, use the prov color
154 if(stripe_color == 0x222222) {
155 stripe_color = color;
156 }
157
158 prov_color[i] = color;
159 prov_color[i + texture_size] = stripe_color;
160 });
161 }
162
163 return prov_color;
164}
165
166std::vector<uint32_t> sphere_map_from(sys::state& state) {
167 std::vector<uint32_t> prov_color;
168
169 if(state.map_state.get_selected_province()) {
170 prov_color = get_selected_sphere_color(state);
171 } else {
172 prov_color = get_global_sphere_color(state);
173 }
174
175 return prov_color;
176}
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr uint8_t level_in_sphere
Definition: nations.hpp:169
bool is_great_power(sys::state const &state, dcon::nation_id id)
Definition: nations.cpp:503
constexpr uint16_t to_map_id(dcon::province_id id)
Definition: province.hpp:10
uint uint32_t
uchar uint8_t
std::vector< uint32_t > get_global_sphere_color(sys::state &state)
Definition: sphere.hpp:3
std::vector< uint32_t > sphere_map_from(sys::state &state)
Definition: sphere.hpp:166
std::vector< uint32_t > get_selected_sphere_color(sys::state &state)
Definition: sphere.hpp:35