Project Alice
Loading...
Searching...
No Matches
party_loyalty.hpp
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3
4struct party_info {
5 dcon::ideology_id ideology;
6 float loyalty;
8};
9
10std::vector<party_info> get_sorted_parties_info(sys::state& state, dcon::province_id prov_id) {
11 std::vector<party_info> result;
12
13 state.world.for_each_ideology([&](dcon::ideology_id ideology) {
14 auto loyalty = state.world.province_get_party_loyalty(prov_id, ideology);
15 if(loyalty > 0) {
16 result.push_back({ideology, loyalty, state.world.ideology_get_color(ideology)});
17 }
18 });
19
20 std::sort(result.begin(), result.end(), [&](party_info a, party_info b) { return a.loyalty > b.loyalty; });
21
22 return result;
23}
24
25std::vector<uint32_t> party_loyalty_map_from(sys::state& state) {
26 uint32_t province_size = state.world.province_size();
27 uint32_t texture_size = province_size + 256 - province_size % 256;
28
29 std::vector<uint32_t> prov_color(texture_size * 2);
30
31 state.world.for_each_province([&](dcon::province_id prov_id) {
32 auto parties_info = get_sorted_parties_info(state, prov_id);
33
34 auto i = province::to_map_id(prov_id);
35
36 if(parties_info.size() == 0) {
37
38 prov_color[i] = 0xFFFFFF;
39 prov_color[i + texture_size] = 0xFFFFFF;
40
41 } else if(parties_info.size() == 1) {
42
43 uint32_t color = parties_info[0].color;
44 prov_color[i] = color;
45 prov_color[i + texture_size] = color;
46
47 } else {
48 party_info a = parties_info[0];
49 party_info b = parties_info[1];
50
51 prov_color[i] = a.color;
52
53 if(b.loyalty >= a.loyalty * 0.75) {
54 prov_color[i + texture_size] = b.color;
55 } else {
56 prov_color[i + texture_size] = a.color;
57 }
58 }
59 });
60
61 return prov_color;
62}
constexpr uint16_t to_map_id(dcon::province_id id)
Definition: province.hpp:10
uint uint32_t
std::vector< uint32_t > party_loyalty_map_from(sys::state &state)
std::vector< party_info > get_sorted_parties_info(sys::state &state, dcon::province_id prov_id)
dcon::ideology_id ideology
uint32_t color