aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r--src/openvic-simulation/GameManager.cpp23
-rw-r--r--src/openvic-simulation/GameManager.hpp15
-rw-r--r--src/openvic-simulation/InstanceManager.cpp16
-rw-r--r--src/openvic-simulation/InstanceManager.hpp9
-rw-r--r--src/openvic-simulation/ModifierCalculationTestToggle.hpp3
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp16
-rw-r--r--src/openvic-simulation/country/CountryInstance.hpp12
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp10
-rw-r--r--src/openvic-simulation/map/MapInstance.hpp5
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp22
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp9
11 files changed, 137 insertions, 3 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index 2980dbd..84666cb 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -49,10 +49,21 @@ bool GameManager::setup_instance(Bookmark const* bookmark) {
Logger::info("Setting up first game instance.");
}
- instance_manager.emplace(definition_manager, gamestate_updated_callback, clock_state_changed_callback);
+ bool ret = true;
- bool ret = instance_manager->setup();
+#if OV_MODIFIER_CALCULATION_TEST
+ instance_manager.emplace(true, definition_manager, gamestate_updated_callback, clock_state_changed_callback);
+ ret &= instance_manager->setup();
+ ret &= instance_manager->load_bookmark(bookmark);
+
+ instance_manager_no_add.emplace(false, definition_manager, gamestate_updated_callback, clock_state_changed_callback);
+ ret &= instance_manager_no_add->setup();
+ ret &= instance_manager_no_add->load_bookmark(bookmark);
+#else
+ instance_manager.emplace(definition_manager, gamestate_updated_callback, clock_state_changed_callback);
+ ret &= instance_manager->setup();
ret &= instance_manager->load_bookmark(bookmark);
+#endif
return ret;
}
@@ -72,7 +83,11 @@ bool GameManager::start_game_session() {
Logger::warning("Starting game session with no bookmark loaded!");
}
+#if OV_MODIFIER_CALCULATION_TEST
+ return instance_manager->start_game_session() & instance_manager_no_add->start_game_session();
+#else
return instance_manager->start_game_session();
+#endif
}
bool GameManager::update_clock() {
@@ -81,5 +96,9 @@ bool GameManager::update_clock() {
return false;
}
+#if OV_MODIFIER_CALCULATION_TEST
+ return instance_manager->update_clock() & instance_manager_no_add->update_clock();
+#else
return instance_manager->update_clock();
+#endif
}
diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp
index 91de279..4dba4ff 100644
--- a/src/openvic-simulation/GameManager.hpp
+++ b/src/openvic-simulation/GameManager.hpp
@@ -6,12 +6,17 @@
#include "openvic-simulation/DefinitionManager.hpp"
#include "openvic-simulation/InstanceManager.hpp"
+#include "openvic-simulation/ModifierCalculationTestToggle.hpp"
+
namespace OpenVic {
struct GameManager {
private:
Dataloader PROPERTY(dataloader);
DefinitionManager PROPERTY(definition_manager);
std::optional<InstanceManager> instance_manager;
+#if OV_MODIFIER_CALCULATION_TEST
+ std::optional<InstanceManager> instance_manager_no_add;
+#endif
InstanceManager::gamestate_updated_func_t gamestate_updated_callback;
SimulationClock::state_changed_function_t clock_state_changed_callback;
@@ -31,6 +36,16 @@ namespace OpenVic {
return instance_manager ? &*instance_manager : nullptr;
}
+#if OV_MODIFIER_CALCULATION_TEST
+ inline constexpr InstanceManager* get_instance_manager_no_add() {
+ return instance_manager_no_add ? &*instance_manager_no_add : nullptr;
+ }
+
+ inline constexpr InstanceManager const* get_instance_manager_no_add() const {
+ return instance_manager_no_add ? &*instance_manager_no_add : nullptr;
+ }
+#endif
+
bool set_roots(Dataloader::path_vector_t const& roots);
bool load_definitions(Dataloader::localisation_callback_t localisation_callback);
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp
index eaa0692..1cbf53c 100644
--- a/src/openvic-simulation/InstanceManager.cpp
+++ b/src/openvic-simulation/InstanceManager.cpp
@@ -6,9 +6,15 @@
using namespace OpenVic;
InstanceManager::InstanceManager(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool new_ADD_OWNER_CONTRIBUTION,
+#endif
DefinitionManager const& new_definition_manager, gamestate_updated_func_t gamestate_updated_callback,
SimulationClock::state_changed_function_t clock_state_changed_callback
) : definition_manager { new_definition_manager },
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION { new_ADD_OWNER_CONTRIBUTION },
+#endif
map_instance { new_definition_manager.get_map_definition() },
simulation_clock {
std::bind(&InstanceManager::tick, this), std::bind(&InstanceManager::update_gamestate, this),
@@ -39,7 +45,11 @@ void InstanceManager::update_gamestate() {
Logger::info("Update: ", today);
+#if OV_MODIFIER_CALCULATION_TEST
+ if (ADD_OWNER_CONTRIBUTION) {
+#else
if constexpr (ProvinceInstance::ADD_OWNER_CONTRIBUTION) {
+#endif
// Calculate local province modifier sums first, then national country modifier sums, then loop over owned provinces
// adding their contributions to the owner country's modifier sum and loop over them again to add the country's total
// (including province contributions) to the provinces' modifier sum. This results in every country and province
@@ -99,11 +109,17 @@ bool InstanceManager::setup() {
bool ret = good_instance_manager.setup(definition_manager.get_economy_manager().get_good_definition_manager());
ret &= map_instance.setup(
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION,
+#endif
definition_manager.get_economy_manager().get_building_type_manager(),
definition_manager.get_pop_manager().get_pop_types(),
definition_manager.get_politics_manager().get_ideology_manager().get_ideologies()
);
ret &= country_instance_manager.generate_country_instances(
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION,
+#endif
definition_manager.get_country_definition_manager(),
definition_manager.get_economy_manager().get_building_type_manager().get_building_types(),
definition_manager.get_research_manager().get_technology_manager().get_technologies(),
diff --git a/src/openvic-simulation/InstanceManager.hpp b/src/openvic-simulation/InstanceManager.hpp
index cfb5447..799a269 100644
--- a/src/openvic-simulation/InstanceManager.hpp
+++ b/src/openvic-simulation/InstanceManager.hpp
@@ -11,6 +11,8 @@
#include "openvic-simulation/misc/SimulationClock.hpp"
#include "openvic-simulation/types/Date.hpp"
+#include "openvic-simulation/ModifierCalculationTestToggle.hpp"
+
namespace OpenVic {
struct DefinitionManager;
struct Bookmark;
@@ -21,6 +23,10 @@ namespace OpenVic {
private:
DefinitionManager const& PROPERTY(definition_manager);
+#if OV_MODIFIER_CALCULATION_TEST
+ const bool ADD_OWNER_CONTRIBUTION;
+#endif
+
CountryInstanceManager PROPERTY_REF(country_instance_manager);
CountryRelationManager PROPERTY_REF(country_relation_manager);
GoodInstanceManager PROPERTY_REF(good_instance_manager);
@@ -51,6 +57,9 @@ namespace OpenVic {
public:
InstanceManager(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool new_ADD_OWNER_CONTRIBUTION,
+#endif
DefinitionManager const& new_definition_manager, gamestate_updated_func_t gamestate_updated_callback,
SimulationClock::state_changed_function_t clock_state_changed_callback
);
diff --git a/src/openvic-simulation/ModifierCalculationTestToggle.hpp b/src/openvic-simulation/ModifierCalculationTestToggle.hpp
new file mode 100644
index 0000000..2eea4f2
--- /dev/null
+++ b/src/openvic-simulation/ModifierCalculationTestToggle.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+#define OV_MODIFIER_CALCULATION_TEST 1
diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp
index 043494d..ea9596f 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -18,6 +18,9 @@ using enum CountryInstance::country_status_t;
static constexpr colour_t ERROR_COLOUR = colour_t::from_integer(0xFF0000);
CountryInstance::CountryInstance(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool new_ADD_OWNER_CONTRIBUTION,
+#endif
CountryDefinition const* new_country_definition,
decltype(building_type_unlock_levels)::keys_t const& building_type_keys,
decltype(technology_unlock_levels)::keys_t const& technology_keys,
@@ -30,6 +33,9 @@ CountryInstance::CountryInstance(
decltype(regiment_type_unlock_levels)::keys_t const& regiment_type_unlock_levels_keys,
decltype(ship_type_unlock_levels)::keys_t const& ship_type_unlock_levels_keys
) : /* Main attributes */
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION { new_ADD_OWNER_CONTRIBUTION },
+#endif
country_definition { new_country_definition },
colour { ERROR_COLOUR },
capital { nullptr },
@@ -1009,7 +1015,11 @@ void CountryInstance::update_modifier_sum(Date today, StaticModifierCache const&
}
}
+#if OV_MODIFIER_CALCULATION_TEST
+ if (ADD_OWNER_CONTRIBUTION) {
+#else
if constexpr (ProvinceInstance::ADD_OWNER_CONTRIBUTION) {
+#endif
// Add province base modifiers (with local province modifier effects removed)
for (ProvinceInstance const* province : controlled_provinces) {
contribute_province_modifier_sum(province->get_modifier_sum());
@@ -1219,6 +1229,9 @@ CountryInstance const& CountryInstanceManager::get_country_instance_from_definit
}
bool CountryInstanceManager::generate_country_instances(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool ADD_OWNER_CONTRIBUTION,
+#endif
CountryDefinitionManager const& country_definition_manager,
decltype(CountryInstance::building_type_unlock_levels)::keys_t const& building_type_keys,
decltype(CountryInstance::technology_unlock_levels)::keys_t const& technology_keys,
@@ -1237,6 +1250,9 @@ bool CountryInstanceManager::generate_country_instances(
for (CountryDefinition const& country_definition : country_definition_manager.get_country_definitions()) {
ret &= country_instances.add_item({
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION,
+#endif
&country_definition,
building_type_keys,
technology_keys,
diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp
index ea30c0d..d62a138 100644
--- a/src/openvic-simulation/country/CountryInstance.hpp
+++ b/src/openvic-simulation/country/CountryInstance.hpp
@@ -14,6 +14,8 @@
#include "openvic-simulation/types/IndexedMap.hpp"
#include "openvic-simulation/utility/Getters.hpp"
+#include "openvic-simulation/ModifierCalculationTestToggle.hpp"
+
namespace OpenVic {
struct CountryInstanceManager;
struct CountryDefinition;
@@ -64,6 +66,10 @@ namespace OpenVic {
using unit_variant_t = uint8_t;
private:
+#if OV_MODIFIER_CALCULATION_TEST
+ const bool ADD_OWNER_CONTRIBUTION;
+#endif
+
/* Main attributes */
// We can always assume country_definition is not null, as it is initialised from a reference and only ever changed
// by swapping with another CountryInstance's country_definition.
@@ -187,6 +193,9 @@ namespace OpenVic {
UNIT_BRANCHED_GETTER(get_unit_type_unlock_levels, regiment_type_unlock_levels, ship_type_unlock_levels);
CountryInstance(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool new_ADD_OWNER_CONTRIBUTION,
+#endif
CountryDefinition const* new_country_definition,
decltype(building_type_unlock_levels)::keys_t const& building_type_keys,
decltype(technology_unlock_levels)::keys_t const& technology_keys,
@@ -345,6 +354,9 @@ namespace OpenVic {
CountryInstance const& get_country_instance_from_definition(CountryDefinition const& country) const;
bool generate_country_instances(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool ADD_OWNER_CONTRIBUTION,
+#endif
CountryDefinitionManager const& country_definition_manager,
decltype(CountryInstance::building_type_unlock_levels)::keys_t const& building_type_keys,
decltype(CountryInstance::technology_unlock_levels)::keys_t const& technology_keys,
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index d8ec2fb..2875a66 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -42,6 +42,9 @@ ProvinceDefinition::index_t MapInstance::get_selected_province_index() const {
}
bool MapInstance::setup(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool ADD_OWNER_CONTRIBUTION,
+#endif
BuildingTypeManager const& building_type_manager,
decltype(ProvinceInstance::pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys
@@ -60,7 +63,12 @@ bool MapInstance::setup(
province_instances.reserve(map_definition.get_province_definition_count());
for (ProvinceDefinition const& province : map_definition.get_province_definitions()) {
- ret &= province_instances.add_item({ province, pop_type_keys, ideology_keys });
+ ret &= province_instances.add_item({
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION,
+#endif
+ province, pop_type_keys, ideology_keys
+ });
}
province_instances.lock();
diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp
index e7c623e..d3decb4 100644
--- a/src/openvic-simulation/map/MapInstance.hpp
+++ b/src/openvic-simulation/map/MapInstance.hpp
@@ -6,6 +6,8 @@
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/ModifierCalculationTestToggle.hpp"
+
namespace OpenVic {
struct MapDefinition;
struct BuildingTypeManager;
@@ -43,6 +45,9 @@ namespace OpenVic {
ProvinceDefinition::index_t get_selected_province_index() const;
bool setup(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool ADD_OWNER_CONTRIBUTION,
+#endif
BuildingTypeManager const& building_type_manager,
decltype(ProvinceInstance::pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index cbb23bd..3ef81eb 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -14,9 +14,15 @@
using namespace OpenVic;
ProvinceInstance::ProvinceInstance(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool new_ADD_OWNER_CONTRIBUTION,
+#endif
ProvinceDefinition const& new_province_definition, decltype(pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ideology_distribution)::keys_t const& ideology_keys
) : HasIdentifierAndColour { new_province_definition },
+#if OV_MODIFIER_CALCULATION_TEST
+ ADD_OWNER_CONTRIBUTION { new_ADD_OWNER_CONTRIBUTION },
+#endif
province_definition { new_province_definition },
terrain_type { new_province_definition.get_default_terrain_type() },
life_rating { 0 },
@@ -237,7 +243,11 @@ void ProvinceInstance::update_modifier_sum(Date today, StaticModifierCache const
modifier_sum.add_modifier_nullcheck(terrain_type, province_source);
+#if OV_MODIFIER_CALCULATION_TEST
+ if (!ADD_OWNER_CONTRIBUTION) {
+#else
if constexpr (!ADD_OWNER_CONTRIBUTION) {
+#endif
if (controller != nullptr) {
controller->contribute_province_modifier_sum(modifier_sum);
}
@@ -249,7 +259,11 @@ void ProvinceInstance::contribute_country_modifier_sum(ModifierSum const& owner_
}
fixed_point_t ProvinceInstance::get_modifier_effect_value(ModifierEffect const& effect) const {
+#if OV_MODIFIER_CALCULATION_TEST
+ if (ADD_OWNER_CONTRIBUTION) {
+#else
if constexpr (ADD_OWNER_CONTRIBUTION) {
+#endif
return modifier_sum.get_effect(effect);
} else {
using enum ModifierEffect::target_t;
@@ -279,7 +293,11 @@ fixed_point_t ProvinceInstance::get_modifier_effect_value_nullcheck(ModifierEffe
void ProvinceInstance::push_contributing_modifiers(
ModifierEffect const& effect, std::vector<ModifierSum::modifier_entry_t>& contributions
) const {
+#if OV_MODIFIER_CALCULATION_TEST
+ if (ADD_OWNER_CONTRIBUTION) {
+#else
if constexpr (ADD_OWNER_CONTRIBUTION) {
+#endif
modifier_sum.push_contributing_modifiers(effect, contributions);
} else {
using enum ModifierEffect::target_t;
@@ -300,7 +318,11 @@ void ProvinceInstance::push_contributing_modifiers(
}
std::vector<ModifierSum::modifier_entry_t> ProvinceInstance::get_contributing_modifiers(ModifierEffect const& effect) const {
+#if OV_MODIFIER_CALCULATION_TEST
+ if (ADD_OWNER_CONTRIBUTION) {
+#else
if constexpr (ADD_OWNER_CONTRIBUTION) {
+#endif
return modifier_sum.get_contributing_modifiers(effect);
} else {
std::vector<ModifierSum::modifier_entry_t> contributions;
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index e7c0326..2794a50 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -11,6 +11,8 @@
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
+#include "openvic-simulation/ModifierCalculationTestToggle.hpp"
+
namespace OpenVic {
struct MapInstance;
struct ProvinceDefinition;
@@ -70,10 +72,14 @@ namespace OpenVic {
CountryInstance* PROPERTY(controller);
ordered_set<CountryInstance*> PROPERTY(cores);
+#if OV_MODIFIER_CALCULATION_TEST
+ const bool ADD_OWNER_CONTRIBUTION;
+#else
public:
static constexpr bool ADD_OWNER_CONTRIBUTION = true;
private:
+#endif
// The total/resultant modifier affecting this province, including owner country contributions if
// ADD_OWNER_CONTRIBUTION is true.
ModifierSum PROPERTY(modifier_sum);
@@ -102,6 +108,9 @@ namespace OpenVic {
size_t PROPERTY(max_supported_regiments);
ProvinceInstance(
+#if OV_MODIFIER_CALCULATION_TEST
+ bool new_ADD_OWNER_CONTRIBUTION,
+#endif
ProvinceDefinition const& new_province_definition, decltype(pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ideology_distribution)::keys_t const& ideology_keys
);