Skip to content

Commit e99f357

Browse files
committed
Add game rule for economic country
1 parent f8f506b commit e99f357

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

src/openvic-simulation/InstanceManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ bool InstanceManager::setup() {
145145
ret &= map_instance.setup(
146146
definition_manager.get_economy_manager().get_building_type_manager(),
147147
market_instance,
148+
game_rules_manager,
148149
definition_manager.get_modifier_manager().get_modifier_effect_cache(),
149150
definition_manager.get_pop_manager().get_stratas(),
150151
definition_manager.get_pop_manager().get_pop_types(),

src/openvic-simulation/map/MapInstance.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ProvinceInstance const& MapInstance::get_province_instance_from_definition(Provi
1919
bool MapInstance::setup(
2020
BuildingTypeManager const& building_type_manager,
2121
MarketInstance& market_instance,
22+
GameRulesManager const& game_rules_manager,
2223
ModifierEffectCache const& modifier_effect_cache,
2324
decltype(ProvinceInstance::population_by_strata)::keys_type const& strata_keys,
2425
decltype(ProvinceInstance::pop_type_distribution)::keys_type const& pop_type_keys,
@@ -40,6 +41,7 @@ bool MapInstance::setup(
4041
for (ProvinceDefinition const& province : map_definition.get_province_definitions()) {
4142
if (province_instances.add_item({
4243
market_instance,
44+
game_rules_manager,
4345
modifier_effect_cache,
4446
province,
4547
strata_keys,

src/openvic-simulation/map/MapInstance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace OpenVic {
4949
bool setup(
5050
BuildingTypeManager const& building_type_manager,
5151
MarketInstance& market_instance,
52+
GameRulesManager const& game_rules_manager,
5253
ModifierEffectCache const& modifier_effect_cache,
5354
decltype(ProvinceInstance::population_by_strata)::keys_type const& strata_keys,
5455
decltype(ProvinceInstance::pop_type_distribution)::keys_type const& pop_type_keys,

src/openvic-simulation/map/ProvinceInstance.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "openvic-simulation/map/Region.hpp"
1111
#include "openvic-simulation/map/TerrainType.hpp"
1212
#include "openvic-simulation/military/UnitInstanceGroup.hpp"
13+
#include "openvic-simulation/misc/GameRulesManager.hpp"
1314
#include "openvic-simulation/modifier/StaticModifierCache.hpp"
1415
#include "openvic-simulation/politics/Ideology.hpp"
1516
#include "openvic-simulation/pop/PopValuesFromProvince.hpp"
@@ -19,6 +20,7 @@ using namespace OpenVic;
1920

2021
ProvinceInstance::ProvinceInstance(
2122
MarketInstance& new_market_instance,
23+
GameRulesManager const& new_game_rules_manager,
2224
ModifierEffectCache const& new_modifier_effect_cache,
2325
ProvinceDefinition const& new_province_definition,
2426
decltype(population_by_strata)::keys_type const& strata_keys,
@@ -28,6 +30,7 @@ ProvinceInstance::ProvinceInstance(
2830
HasIndex { new_province_definition.get_index() },
2931
FlagStrings { "province" },
3032
province_definition { new_province_definition },
33+
game_rules_manager { new_game_rules_manager },
3134
modifier_effect_cache { new_modifier_effect_cache },
3235
terrain_type { new_province_definition.get_default_terrain_type() },
3336
rgo { new_market_instance, pop_type_keys },
@@ -84,6 +87,14 @@ bool ProvinceInstance::set_owner(CountryInstance* new_owner) {
8487
for (Pop& pop : pops) {
8588
pop.update_location_based_attributes();
8689
}
90+
91+
if (game_rules_manager.get_country_to_report_economy() == country_to_report_economy_t::Owner) {
92+
country_to_report_economy = new_owner;
93+
} else if (game_rules_manager.get_country_to_report_economy() == country_to_report_economy_t::NeitherWhenOccupied) {
94+
country_to_report_economy = is_occupied()
95+
? nullptr
96+
: owner;
97+
}
8798
}
8899

89100
return ret;
@@ -92,6 +103,10 @@ bool ProvinceInstance::set_owner(CountryInstance* new_owner) {
92103
bool ProvinceInstance::set_controller(CountryInstance* new_controller) {
93104
bool ret = true;
94105

106+
if (new_controller == nullptr) {
107+
new_controller = owner;
108+
}
109+
95110
if (controller != new_controller) {
96111
if (controller != nullptr) {
97112
ret &= controller->remove_controlled_province(*this);
@@ -102,6 +117,14 @@ bool ProvinceInstance::set_controller(CountryInstance* new_controller) {
102117
if (controller != nullptr) {
103118
ret &= controller->add_controlled_province(*this);
104119
}
120+
121+
if (game_rules_manager.get_country_to_report_economy() == country_to_report_economy_t::Controller) {
122+
country_to_report_economy = new_controller;
123+
} else if (game_rules_manager.get_country_to_report_economy() == country_to_report_economy_t::NeitherWhenOccupied) {
124+
country_to_report_economy = is_occupied()
125+
? nullptr
126+
: owner;
127+
}
105128
}
106129

107130
return ret;

src/openvic-simulation/map/ProvinceInstance.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace OpenVic {
3232
struct CountryInstanceManager;
3333
struct ModifierEffectCache;
3434
struct MarketInstance;
35+
struct GameRulesManager;
3536

3637
struct UnitInstanceGroup;
3738

@@ -64,6 +65,7 @@ namespace OpenVic {
6465

6566
private:
6667
ProvinceDefinition const& PROPERTY(province_definition);
68+
GameRulesManager const& PROPERTY(game_rules_manager);
6769
ModifierEffectCache const& PROPERTY(modifier_effect_cache);
6870

6971
TerrainType const* PROPERTY(terrain_type);
@@ -73,6 +75,7 @@ namespace OpenVic {
7375

7476
CountryInstance* PROPERTY_PTR(owner, nullptr);
7577
CountryInstance* PROPERTY_PTR(controller, nullptr);
78+
CountryInstance* PROPERTY_PTR(country_to_report_economy, nullptr);
7679
ordered_set<CountryInstance*> PROPERTY(cores);
7780

7881
// The total/resultant modifier of local effects on this province (global effects come from the province's owner)
@@ -117,6 +120,7 @@ namespace OpenVic {
117120

118121
ProvinceInstance(
119122
MarketInstance& new_market_instance,
123+
GameRulesManager const& new_game_rules_manager,
120124
ModifierEffectCache const& new_modifier_effect_cache,
121125
ProvinceDefinition const& new_province_definition,
122126
decltype(population_by_strata)::keys_type const& strata_keys,
@@ -136,14 +140,6 @@ namespace OpenVic {
136140
return province_definition;
137141
}
138142

139-
constexpr CountryInstance const* get_country_to_report_economy() const {
140-
return controller;
141-
}
142-
143-
constexpr CountryInstance* get_country_to_report_economy() {
144-
return controller;
145-
}
146-
147143
void set_state(State* new_state);
148144

149145
constexpr GoodDefinition const* get_rgo_good() const {
@@ -157,6 +153,7 @@ namespace OpenVic {
157153

158154
bool set_owner(CountryInstance* new_owner);
159155
bool set_controller(CountryInstance* new_controller);
156+
160157
// The warn argument controls whether a log message is emitted when a core already does/doesn't exist, e.g. we may
161158
// want to know if there are redundant province history instructions setting a core multiple times, but we may not
162159
// want to be swamped with log messages by effect scripts which use add_core/remove_core very liberally. Regardless
@@ -170,6 +167,9 @@ namespace OpenVic {
170167
constexpr bool is_colonial_province() const {
171168
return colony_status != colony_status_t::STATE;
172169
}
170+
constexpr bool is_occupied() const {
171+
return owner != controller;
172+
}
173173

174174
// The values returned by these functions are scaled by population size, so they must be divided by population size
175175
// to get the support as a proportion of 1.0

src/openvic-simulation/misc/GameRulesManager.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
#include "openvic-simulation/utility/Getters.hpp"
44
namespace OpenVic {
5+
enum struct country_to_report_economy_t : uint8_t {
6+
Owner,
7+
Controller,
8+
NeitherWhenOccupied
9+
};
10+
511
enum struct demand_category : uint8_t {
612
None,
713
PopNeeds,
@@ -14,6 +20,7 @@ namespace OpenVic {
1420
// if changed during a session, call on_use_exponential_price_changes_changed for each GoodInstance.
1521
bool PROPERTY_RW(use_exponential_price_changes, false);
1622
demand_category PROPERTY_RW(artisanal_input_demand_category, demand_category::None);
23+
country_to_report_economy_t PROPERTY_RW(country_to_report_economy, country_to_report_economy_t::Owner);
1724

1825
public:
1926
constexpr bool get_use_optimal_pricing() const {

0 commit comments

Comments
 (0)