Project Alice
Loading...
Searching...
No Matches
economy_templates.hpp
Go to the documentation of this file.
1#pragma once
2#include "system_state.hpp"
3
4namespace economy {
5
6template<typename F>
7void for_each_new_factory(sys::state& state, dcon::state_instance_id s, F&& func) {
8 for(auto st_con : state.world.state_instance_get_state_building_construction(s)) {
9 if(!st_con.get_is_upgrade()) {
10 float admin_eff = state.world.nation_get_administrative_efficiency(st_con.get_nation());
11 float factory_mod = state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_cost) + 1.0f;
12 float pop_factory_mod = std::max(0.1f, state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_owner_cost));
13 float admin_cost_factor = (st_con.get_is_pop_project() ? pop_factory_mod : (2.0f - admin_eff)) * factory_mod;
14
15 float total = 0.0f;
16 float purchased = 0.0f;
17 auto& goods = state.world.factory_type_get_construction_costs(st_con.get_type());
18
19 for(uint32_t i = 0; i < commodity_set::set_size; ++i) {
20 total += goods.commodity_amounts[i] * admin_cost_factor;
21 purchased += st_con.get_purchased_goods().commodity_amounts[i];
22 }
23
24 func(new_factory{total > 0.0f ? purchased / total : 0.0f, st_con.get_type().id});
25 }
26 }
27}
28
29template<typename F>
30void for_each_upgraded_factory(sys::state& state, dcon::state_instance_id s, F&& func) {
31 for(auto st_con : state.world.state_instance_get_state_building_construction(s)) {
32 if(st_con.get_is_upgrade()) {
33 float admin_eff = state.world.nation_get_administrative_efficiency(st_con.get_nation());
34 float factory_mod = state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_cost) + 1.0f;
35 float pop_factory_mod = std::max(0.1f, state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_owner_cost));
36 float admin_cost_factor = (st_con.get_is_pop_project() ? pop_factory_mod : (2.0f - admin_eff)) * factory_mod;
37
38 float total = 0.0f;
39 float purchased = 0.0f;
40 auto& goods = state.world.factory_type_get_construction_costs(st_con.get_type());
41
42 for(uint32_t i = 0; i < commodity_set::set_size; ++i) {
43 total += goods.commodity_amounts[i] * admin_cost_factor;
44 purchased += st_con.get_purchased_goods().commodity_amounts[i];
45 }
46
47 func(upgraded_factory{total > 0.0f ? purchased / total : 0.0f, st_con.get_type().id});
48 }
49 }
50}
51
52} // namespace economy
void for_each_new_factory(sys::state &state, dcon::state_instance_id s, F &&func)
void for_each_upgraded_factory(sys::state &state, dcon::state_instance_id s, F &&func)
uint uint32_t
static constexpr uint32_t set_size