Project Alice
Loading...
Searching...
No Matches
nations_templates.hpp
Go to the documentation of this file.
1#pragma once
3#include "system_state.hpp"
4
5namespace nations {
6
7// returns whether a culture is on the accepted list OR is the primary culture
8template<typename T, typename U>
9auto nation_accepts_culture(sys::state const& state, T ids, U cul_ids) {
10 auto is_accepted = ve::apply(
11 [&state](dcon::nation_id n, dcon::culture_id c) {
12 if(n)
13 return state.world.nation_get_accepted_cultures(n, c);
14 else
15 return false;
16 },
17 ids, cul_ids);
18 return (state.world.nation_get_primary_culture(ids) == cul_ids) || is_accepted;
19}
20
21template<typename T>
22auto primary_culture_group(sys::state const& state, T ids) {
23 auto cultures = state.world.nation_get_primary_culture(ids);
24 return state.world.culture_get_group_from_culture_group_membership(cultures);
25}
26
27template<typename T>
28auto owner_of_pop(sys::state const& state, T pop_ids) {
29 auto location = state.world.pop_get_province_from_pop_location(pop_ids);
30 return state.world.province_get_nation_from_province_ownership(location);
31}
32
33template<typename T>
34auto central_blockaded_fraction(sys::state const& state, T ids) {
35 auto cpc = ve::to_float(state.world.nation_get_central_ports(ids));
36 auto b_count = ve::to_float(state.world.nation_get_central_blockaded(ids));
37 auto ret = decltype(cpc){};
38 return ve::select(cpc != 0.0f, b_count / cpc, ret);
39}
40
41template<typename T>
43 auto cpc = ve::to_float(state.world.nation_get_central_province_count(ids));
44 auto reb_count = ve::to_float(state.world.nation_get_central_rebel_controlled(ids));
45 return ve::select(cpc != 0.0f, reb_count / cpc, decltype(cpc)());
46}
47
48template<typename T>
49auto central_has_crime_fraction(sys::state const& state, T ids) {
50 auto cpc = ve::to_float(state.world.nation_get_central_province_count(ids));
51 auto crim_count = ve::to_float(state.world.nation_get_central_crime_count(ids));
52 return ve::select(cpc != 0.0f, crim_count / cpc, decltype(cpc)());
53}
54
55template<typename T>
56auto occupied_provinces_fraction(sys::state const& state, T ids) {
57 auto cpc = ve::to_float(state.world.nation_get_owned_province_count(ids));
58 auto occ_count = ve::to_float(state.world.nation_get_occupied_count(ids));
59 return ve::select(cpc != 0.0f, occ_count / cpc, decltype(cpc)());
60}
61} // namespace nations
auto central_reb_controlled_fraction(sys::state const &state, T ids)
auto occupied_provinces_fraction(sys::state const &state, T ids)
auto primary_culture_group(sys::state const &state, T ids)
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
Definition: nations.cpp:69
auto central_blockaded_fraction(sys::state const &state, T ids)
auto central_has_crime_fraction(sys::state const &state, T ids)
auto nation_accepts_culture(sys::state const &state, T ids, U cul_ids)
T select(bool v, T a, T b)
float to_float(int32_t a)