Project Alice
Loading...
Searching...
No Matches
political.hpp
Go to the documentation of this file.
1#pragma once
2#include "prng.hpp"
3
4uint32_t derive_color_from_ol_color(sys::state& state, uint32_t ol_color, dcon::nation_id n) {
5 auto base = sys::rgb_to_hsv(ol_color);
6 auto roff = rng::get_random_pair(state, uint32_t(n.index()), uint32_t(n.index()));
7 base.h = fmod(base.h + (float(roff.low & 0x1F) - 15.5f), 360.0f);
8 base.s = std::clamp(base.s + (float((roff.low >> 8) & 0xFF) / 255.0f) * 0.2f - 0.1f, 0.0f, 1.0f);
9 base.v = std::clamp(base.v + (float((roff.high >> 4) & 0xFF) / 255.0f) * 0.2f - 0.1f, 0.0f, 1.0f);
10 return sys::hsv_to_rgb(base);
11}
12
13std::vector<uint32_t> political_map_from(sys::state& state) {
14 uint32_t province_size = state.world.province_size();
15 uint32_t texture_size = province_size + 256 - province_size % 256;
16
17 std::vector<uint32_t> prov_color(texture_size * 2);
18
19 std::vector<uint32_t> nation_color(state.world.nation_size() + 1);
20 state.world.for_each_nation([&](dcon::nation_id n) {
21 nation_color[n.value] = state.world.nation_get_color(n);
22 auto olr = state.world.nation_get_overlord_as_subject(n);
23 auto ol = state.world.overlord_get_ruler(olr);
24 auto ol_temp = ol;
25
26 while(ol) {
27 olr = state.world.nation_get_overlord_as_subject(ol);
28 ol_temp = ol;
29 ol = state.world.overlord_get_ruler(olr);
30 } ol = ol_temp;
31
32 if(ol) {
33 auto ol_color = state.world.nation_get_color(ol);
34 switch(state.user_settings.vassal_color) {
35 case sys::map_vassal_color_mode::inherit:
36 nation_color[n.value] = derive_color_from_ol_color(state, ol_color, n);
37 break;
38 case sys::map_vassal_color_mode::same:
39 nation_color[n.value] = ol_color;
40 break;
41 case sys::map_vassal_color_mode::none:
42 break;
43 }
44 }
45 });
46
47 state.world.for_each_province([&](dcon::province_id prov_id) {
48 auto fat_id = dcon::fatten(state.world, prov_id);
49 auto i = province::to_map_id(prov_id);
50 if(prov_id.index() >= state.province_definitions.first_sea_province.index()) {
51 prov_color[i] = 0;
52 prov_color[i + texture_size] = 0;
53
54 dcon::nation_id first_n{};
55 dcon::nation_id second_n{};
56 for(const auto adj : fat_id.get_province_adjacency_as_connected_provinces()) {
57 auto p2 = adj.get_connected_provinces(adj.get_connected_provinces(0) == prov_id ? 1 : 0);
58 if(p2.get_is_coast()) {
59 auto n = p2.get_province_control_as_province().get_nation();
60 if(!n || second_n == n || first_n == n)
61 continue;
62 if(!bool(second_n) || n.get_rank() > state.world.nation_get_rank(second_n)) {
63 if(!bool(first_n) || n.get_rank() > state.world.nation_get_rank(first_n)) {
64 second_n = first_n;
65 first_n = n;
66 } else {
67 second_n = n;
68 }
69 }
70 }
71 }
72
73 if(first_n) {
74 prov_color[i] = nation_color[first_n.value];
75 prov_color[i] |= 0xff000000;
76 if(second_n) {
77 prov_color[i + texture_size] = nation_color[second_n.value];
78 prov_color[i + texture_size] |= 0xff000000;
79 }
80 }
81 } else {
82 auto id = fat_id.get_nation_from_province_ownership();
83 uint32_t color = 0;
84 if(bool(id)) {
85 color = nation_color[id.id.value];
86 } else { // If no owner use default color
87 color = 255 << 16 | 255 << 8 | 255;
88 }
89 auto occupier = fat_id.get_nation_from_province_control();
90 uint32_t color_b = occupier ? nation_color[occupier.id.value] :
91 (id ? sys::pack_color(127, 127, 127) : sys::pack_color(255, 255, 255));
92
93 prov_color[i] = color;
94 prov_color[i + texture_size] = color_b;
95 }
96 });
97
98 return prov_color;
99}
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
random_pair get_random_pair(sys::state const &state, uint32_t value_in)
Definition: prng.cpp:26
uint32_t pack_color(float r, float g, float b)
uint32_t hsv_to_rgb(hsv v)
hsv rgb_to_hsv(uint32_t v)
uint uint32_t
uint32_t derive_color_from_ol_color(sys::state &state, uint32_t ol_color, dcon::nation_id n)
Definition: political.hpp:4
std::vector< uint32_t > political_map_from(sys::state &state)
Definition: political.hpp:13