Project Alice
Loading...
Searching...
No Matches
province_templates.hpp
Go to the documentation of this file.
1#pragma once
2#include "system_state.hpp"
3
4namespace province {
5
6template<typename T>
7auto is_overseas(sys::state const& state, T ids) {
8 auto owners = state.world.province_get_nation_from_province_ownership(ids);
9 auto owner_cap = state.world.nation_get_capital(owners);
10 return (state.world.province_get_continent(ids) != state.world.province_get_continent(owner_cap)) &&
11 (state.world.province_get_connected_region_id(ids) != state.world.province_get_connected_region_id(owner_cap));
12}
13
14template<typename F>
15void for_each_land_province(sys::state& state, F const& func) {
16 int32_t last = state.province_definitions.first_sea_province.index();
17 for(int32_t i = 0; i < last; ++i) {
18 dcon::province_id pid{dcon::province_id::value_base_t(i)};
19 func(pid);
20 }
21}
22
23template<typename F>
24void ve_for_each_land_province(sys::state& state, F const& func) {
25 int32_t last = state.province_definitions.first_sea_province.index();
26 ve::execute_serial<dcon::province_id>(uint32_t(last), func);
27}
28
29template<typename F>
30void for_each_sea_province(sys::state& state, F const& func) {
31 int32_t first = state.province_definitions.first_sea_province.index();
32 for(int32_t i = first; i < int32_t(state.world.province_size()); ++i) {
33 dcon::province_id pid{dcon::province_id::value_base_t(i)};
34 func(pid);
35 }
36}
37
38template<typename F>
39void for_each_province_in_state_instance(sys::state& state, dcon::state_instance_id s, F const& func) {
40 auto d = state.world.state_instance_get_definition(s);
41 auto o = state.world.state_instance_get_nation_from_state_ownership(s);
42 for(auto p : state.world.state_definition_get_abstract_state_membership(d)) {
43 if(p.get_province().get_nation_from_province_ownership() == o) {
44 func(p.get_province().id);
45 }
46 }
47}
48} // namespace province
bool is_overseas(sys::state const &state, dcon::province_id ids)
Definition: province.cpp:18
void ve_for_each_land_province(sys::state &state, F const &func)
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
void for_each_sea_province(sys::state &state, F const &func)
void for_each_land_province(sys::state &state, F const &func)
uint uint32_t