aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Crime.cpp14
-rw-r--r--src/openvic-simulation/map/MapDefinition.cpp12
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp34
-rw-r--r--src/openvic-simulation/map/MapInstance.hpp2
-rw-r--r--src/openvic-simulation/map/Mapmode.cpp2
-rw-r--r--src/openvic-simulation/map/ProvinceDefinition.cpp2
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp191
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp35
-rw-r--r--src/openvic-simulation/map/State.cpp18
-rw-r--r--src/openvic-simulation/map/State.hpp2
-rw-r--r--src/openvic-simulation/map/TerrainType.cpp41
-rw-r--r--src/openvic-simulation/map/TerrainType.hpp1
12 files changed, 324 insertions, 30 deletions
diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp
index fb521ad..ce0c623 100644
--- a/src/openvic-simulation/map/Crime.cpp
+++ b/src/openvic-simulation/map/Crime.cpp
@@ -1,5 +1,8 @@
#include "Crime.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/modifier/ModifierManager.hpp"
+
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -27,17 +30,22 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager,
const bool ret = expect_dictionary_reserve_length(
crime_modifiers,
[this, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool {
+ using enum scope_type_t;
+
ModifierValue modifier_value;
IconModifier::icon_t icon = 0;
- ConditionScript trigger { scope_t::PROVINCE, scope_t::NO_SCOPE, scope_t::NO_SCOPE };
+ ConditionScript trigger { PROVINCE, NO_SCOPE, NO_SCOPE };
bool default_active = false;
- bool ret = modifier_manager.expect_modifier_value_and_keys(
- move_variable_callback(modifier_value),
+
+ bool ret = NodeTools::expect_dictionary_keys_and_default(
+ modifier_manager.expect_base_province_modifier(modifier_value),
"icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)),
"trigger", ONE_EXACTLY, trigger.expect_script(),
"active", ZERO_OR_ONE, expect_bool(assign_variable_callback(default_active))
)(value);
+
ret &= add_crime_modifier(key, std::move(modifier_value), icon, std::move(trigger), default_active);
+
return ret;
}
)(root);
diff --git a/src/openvic-simulation/map/MapDefinition.cpp b/src/openvic-simulation/map/MapDefinition.cpp
index 828a679..faea838 100644
--- a/src/openvic-simulation/map/MapDefinition.cpp
+++ b/src/openvic-simulation/map/MapDefinition.cpp
@@ -3,6 +3,8 @@
#include <cstdint>
#include <vector>
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/modifier/ModifierManager.hpp"
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/Vector.hpp"
@@ -955,7 +957,11 @@ bool MapDefinition::load_climate_file(ModifierManager const& modifier_manager, a
Climate* cur_climate = climates.get_item_by_identifier(identifier);
if (cur_climate == nullptr) {
ModifierValue values;
- ret &= modifier_manager.expect_modifier_value(move_variable_callback(values))(node);
+
+ ret &= NodeTools::expect_dictionary(
+ modifier_manager.expect_base_province_modifier(values)
+ )(node);
+
ret &= climates.add_item({ identifier, std::move(values), Modifier::modifier_type_t::CLIMATE });
} else {
ret &= expect_list_reserve_length(*cur_climate, expect_province_definition_identifier(
@@ -999,6 +1005,7 @@ bool MapDefinition::load_continent_file(ModifierManager const& modifier_manager,
bool ret = expect_dictionary_reserve_length(
continents,
[this, &modifier_manager](std::string_view identifier, ast::NodeCPtr node) -> bool {
+
if (identifier.empty()) {
Logger::error("Invalid continent identifier - empty!");
return false;
@@ -1006,7 +1013,8 @@ bool MapDefinition::load_continent_file(ModifierManager const& modifier_manager,
ModifierValue values;
std::vector<ProvinceDefinition const*> prov_list;
- bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values),
+ bool ret = NodeTools::expect_dictionary_keys_and_default(
+ modifier_manager.expect_base_province_modifier(values),
"provinces", ONE_EXACTLY, expect_list_reserve_length(prov_list, expect_province_definition_identifier(
[&prov_list](ProvinceDefinition const& province) -> bool {
if (province.continent == nullptr) {
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index 0ce8cea..4a4a1e5 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -93,24 +93,34 @@ bool MapInstance::apply_history_to_provinces(
if (history_map != nullptr) {
ProvinceHistoryEntry const* pop_history_entry = nullptr;
+ ProductionType const* rgo_production_type_nullable = nullptr;
for (auto const& [entry_date, entry] : history_map->get_entries()) {
- if (entry_date > date) {
- break;
+ if(entry_date > date) {
+ if(pop_history_entry != nullptr) {
+ break;
+ }
+ } else {
+ province.apply_history_to_province(*entry, country_manager);
+ std::optional<ProductionType const*> const& rgo_production_type_nullable_optional = entry->get_rgo_production_type_nullable();
+ if (rgo_production_type_nullable_optional.has_value()) {
+ rgo_production_type_nullable = rgo_production_type_nullable_optional.value();
+ }
}
- province.apply_history_to_province(*entry, country_manager);
-
if (!entry->get_pops().empty()) {
pop_history_entry = entry.get();
}
}
- if (pop_history_entry != nullptr) {
+ if (pop_history_entry == nullptr) {
+ Logger::warning("No pop history entry for province ",province.get_identifier(), " for date ", date.to_string());
+ } else {
province.add_pop_vec(pop_history_entry->get_pops());
-
province.setup_pop_test_values(issue_manager);
}
+
+ ret&=province.set_rgo_production_type_nullable(rgo_production_type_nullable);
}
}
}
@@ -118,6 +128,12 @@ bool MapInstance::apply_history_to_provinces(
return ret;
}
+void MapInstance::update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache) {
+ for (ProvinceInstance& province : province_instances.get_items()) {
+ province.update_modifier_sum(today, static_modifier_cache);
+ }
+}
+
void MapInstance::update_gamestate(Date today, DefineManager const& define_manager) {
for (ProvinceInstance& province : province_instances.get_items()) {
province.update_gamestate(today, define_manager);
@@ -144,3 +160,9 @@ void MapInstance::tick(Date today) {
province.tick(today);
}
}
+
+void MapInstance::initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache){
+ for (ProvinceInstance& province : province_instances.get_items()) {
+ province.initialise_for_new_game(modifier_effect_cache);
+ }
+} \ No newline at end of file
diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp
index 99c13d3..a580c55 100644
--- a/src/openvic-simulation/map/MapInstance.hpp
+++ b/src/openvic-simulation/map/MapInstance.hpp
@@ -52,7 +52,9 @@ namespace OpenVic {
IssueManager const& issue_manager
);
+ void update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache);
void update_gamestate(Date today, DefineManager const& define_manager);
void tick(Date today);
+ void initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache);
};
}
diff --git a/src/openvic-simulation/map/Mapmode.cpp b/src/openvic-simulation/map/Mapmode.cpp
index f951a05..88eb2eb 100644
--- a/src/openvic-simulation/map/Mapmode.cpp
+++ b/src/openvic-simulation/map/Mapmode.cpp
@@ -179,7 +179,7 @@ bool MapmodeManager::setup_mapmodes() {
"mapmode_terrain_type", get_colour_mapmode(&ProvinceInstance::get_terrain_type)
},
{
- "mapmode_rgo", get_colour_mapmode(&ProvinceInstance::get_rgo)
+ "mapmode_rgo", get_colour_mapmode(&ProvinceInstance::get_rgo_good)
},
{
"mapmode_infrastructure",
diff --git a/src/openvic-simulation/map/ProvinceDefinition.cpp b/src/openvic-simulation/map/ProvinceDefinition.cpp
index 14828e8..60c8d6c 100644
--- a/src/openvic-simulation/map/ProvinceDefinition.cpp
+++ b/src/openvic-simulation/map/ProvinceDefinition.cpp
@@ -89,7 +89,7 @@ bool ProvinceDefinition::load_positions(
port = true;
port_adjacent_province = province;
} else {
- /* Expected provinces with invalid ports: 39, 296, 1047, 1406, 2044 */
+ /* Expected provinces with invalid ports: 39, 296, 1047, 1406, 2044 */
Logger::warning(
"Invalid port for province ", get_identifier(), ": facing province ", province,
" which has: water = ", province->is_water(), ", adjacent = ", is_adjacent_to(province)
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index 06b3f1e..b3d2df3 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -1,11 +1,19 @@
#include "ProvinceInstance.hpp"
#include "openvic-simulation/country/CountryInstance.hpp"
+#include "openvic-simulation/defines/Define.hpp"
+#include "openvic-simulation/economy/production/ProductionType.hpp"
+#include "openvic-simulation/economy/production/ResourceGatheringOperation.hpp"
#include "openvic-simulation/history/ProvinceHistory.hpp"
+#include "openvic-simulation/map/Crime.hpp"
#include "openvic-simulation/map/ProvinceDefinition.hpp"
+#include "openvic-simulation/map/Region.hpp"
+#include "openvic-simulation/map/TerrainType.hpp"
#include "openvic-simulation/military/UnitInstanceGroup.hpp"
-#include "openvic-simulation/misc/Define.hpp"
+#include "openvic-simulation/modifier/StaticModifierCache.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
+#include "openvic-simulation/pop/Pop.hpp"
+#include "openvic-simulation/utility/Logger.hpp"
using namespace OpenVic;
@@ -21,9 +29,11 @@ ProvinceInstance::ProvinceInstance(
owner { nullptr },
controller { nullptr },
cores {},
+ modifier_sum {},
+ event_modifiers {},
slave { false },
crime { nullptr },
- rgo { nullptr },
+ rgo { pop_type_keys },
buildings { "buildings", false },
armies {},
navies {},
@@ -35,6 +45,25 @@ ProvinceInstance::ProvinceInstance(
religion_distribution {},
max_supported_regiments { 0 } {}
+GoodDefinition const* ProvinceInstance::get_rgo_good() const {
+ if (!rgo.is_valid()) { return nullptr; }
+ return &(rgo.get_production_type_nullable()->get_output_good());
+}
+bool ProvinceInstance::set_rgo_production_type_nullable(ProductionType const* rgo_production_type_nullable) {
+ bool is_valid_operation = true;
+ if (rgo_production_type_nullable != nullptr) {
+ ProductionType const& rgo_production_type = *rgo_production_type_nullable;
+ if (rgo_production_type.get_template_type() != ProductionType::template_type_t::RGO) {
+ Logger::error("Tried setting province ", get_identifier(), " rgo to ", rgo_production_type.get_identifier(), " which is not of template_type RGO.");
+ is_valid_operation = false;
+ }
+ is_valid_operation&=convert_rgo_worker_pops_to_equivalent(rgo_production_type);
+ }
+
+ rgo.set_production_type_nullable(rgo_production_type_nullable);
+ return is_valid_operation;
+}
+
bool ProvinceInstance::set_owner(CountryInstance* new_owner) {
bool ret = true;
@@ -155,12 +184,14 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
max_supported_regiments = 0;
+ MilitaryDefines const& military_defines = define_manager.get_military_defines();
+
using enum colony_status_t;
const fixed_point_t pop_size_per_regiment_multiplier =
- colony_status == PROTECTORATE ? define_manager.get_pop_size_per_regiment_protectorate_multiplier()
- : colony_status == COLONY ? define_manager.get_pop_size_per_regiment_colony_multiplier()
- : is_owner_core() ? fixed_point_t::_1() : define_manager.get_pop_size_per_regiment_non_core_multiplier();
+ colony_status == PROTECTORATE ? military_defines.get_pop_size_per_regiment_protectorate_multiplier()
+ : colony_status == COLONY ? military_defines.get_pop_size_per_regiment_colony_multiplier()
+ : is_owner_core() ? fixed_point_t::_1() : military_defines.get_pop_size_per_regiment_non_core_multiplier();
for (Pop& pop : pops) {
pop.update_gamestate(define_manager, owner, pop_size_per_regiment_multiplier);
@@ -170,7 +201,7 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
average_consciousness += pop.get_consciousness();
average_militancy += pop.get_militancy();
- pop_type_distribution[pop.get_type()] += pop.get_size();
+ pop_type_distribution[*pop.get_type()] += pop.get_size();
ideology_distribution += pop.get_ideologies();
culture_distribution[&pop.get_culture()] += pop.get_size();
religion_distribution[&pop.get_religion()] += pop.get_size();
@@ -185,6 +216,144 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
}
}
+void ProvinceInstance::update_modifier_sum(Date today, StaticModifierCache const& static_modifier_cache) {
+ // Update sum of direct province modifiers
+ modifier_sum.clear();
+
+ const ModifierSum::modifier_source_t province_source { this };
+
+ // Erase expired event modifiers and add non-expired ones to the sum
+ std::erase_if(event_modifiers, [this, today, &province_source](ModifierInstance const& modifier) -> bool {
+ if (today <= modifier.get_expiry_date()) {
+ modifier_sum.add_modifier(*modifier.get_modifier(), province_source);
+ return false;
+ } else {
+ return true;
+ }
+ });
+
+ // Add static modifiers
+ if (is_owner_core()) {
+ modifier_sum.add_modifier(static_modifier_cache.get_core(), province_source);
+ }
+ if (province_definition.is_water()) {
+ modifier_sum.add_modifier(static_modifier_cache.get_sea_zone(), province_source);
+ } else {
+ modifier_sum.add_modifier(static_modifier_cache.get_land_province(), province_source);
+
+ if (province_definition.is_coastal()) {
+ modifier_sum.add_modifier(static_modifier_cache.get_coastal(), province_source);
+ } else {
+ modifier_sum.add_modifier(static_modifier_cache.get_non_coastal(), province_source);
+ }
+
+ // TODO - overseas, blockaded, no_adjacent_controlled, has_siege, occupied, nationalism, infrastructure
+ }
+
+ for (BuildingInstance const& building : buildings.get_items()) {
+ modifier_sum.add_modifier(building.get_building_type(), province_source);
+ }
+
+ modifier_sum.add_modifier_nullcheck(crime, province_source);
+
+ modifier_sum.add_modifier_nullcheck(province_definition.get_continent(), province_source);
+
+ modifier_sum.add_modifier_nullcheck(province_definition.get_climate(), province_source);
+
+ modifier_sum.add_modifier_nullcheck(terrain_type, province_source);
+
+ if constexpr (!ADD_OWNER_CONTRIBUTION) {
+ if (controller != nullptr) {
+ controller->contribute_province_modifier_sum(modifier_sum);
+ }
+ }
+}
+
+void ProvinceInstance::contribute_country_modifier_sum(ModifierSum const& owner_modifier_sum) {
+ modifier_sum.add_modifier_sum_exclude_source(owner_modifier_sum, this);
+}
+
+fixed_point_t ProvinceInstance::get_modifier_effect_value(ModifierEffect const& effect) const {
+ if constexpr (ADD_OWNER_CONTRIBUTION) {
+ return modifier_sum.get_effect(effect);
+ } else {
+ using enum ModifierEffect::target_t;
+
+ if (owner != nullptr) {
+ if (ModifierEffect::excludes_targets(effect.get_targets(), PROVINCE)) {
+ // Non-province targeted effects are already added to the country modifier sum
+ return owner->get_modifier_effect_value(effect);
+ } else {
+ // Province-targeted effects aren't passed to the country modifier sum
+ return owner->get_modifier_effect_value(effect) + modifier_sum.get_effect(effect);
+ }
+ } else {
+ return modifier_sum.get_effect(effect);
+ }
+ }
+}
+
+fixed_point_t ProvinceInstance::get_modifier_effect_value_nullcheck(ModifierEffect const* effect) const {
+ if (effect != nullptr) {
+ return get_modifier_effect_value(*effect);
+ } else {
+ return fixed_point_t::_0();
+ }
+}
+
+void ProvinceInstance::push_contributing_modifiers(
+ ModifierEffect const& effect, std::vector<ModifierSum::modifier_entry_t>& contributions
+) const {
+ if constexpr (ADD_OWNER_CONTRIBUTION) {
+ modifier_sum.push_contributing_modifiers(effect, contributions);
+ } else {
+ using enum ModifierEffect::target_t;
+
+ if (owner != nullptr) {
+ if (ModifierEffect::excludes_targets(effect.get_targets(), PROVINCE)) {
+ // Non-province targeted effects are already added to the country modifier sum
+ owner->push_contributing_modifiers(effect, contributions);
+ } else {
+ // Province-targeted effects aren't passed to the country modifier sum
+ modifier_sum.push_contributing_modifiers(effect, contributions);
+ owner->push_contributing_modifiers(effect, contributions);
+ }
+ } else {
+ modifier_sum.push_contributing_modifiers(effect, contributions);
+ }
+ }
+}
+
+std::vector<ModifierSum::modifier_entry_t> ProvinceInstance::get_contributing_modifiers(ModifierEffect const& effect) const {
+ if constexpr (ADD_OWNER_CONTRIBUTION) {
+ return modifier_sum.get_contributing_modifiers(effect);
+ } else {
+ std::vector<ModifierSum::modifier_entry_t> contributions;
+
+ push_contributing_modifiers(effect, contributions);
+
+ return contributions;
+ }
+}
+
+bool ProvinceInstance::convert_rgo_worker_pops_to_equivalent(ProductionType const& production_type) {
+ bool is_valid_operation = true;
+ std::vector<Job> const& jobs = production_type.get_jobs();
+ for(Pop& pop : pops) {
+ for(Job const& job : jobs) {
+ PopType const* const job_pop_type = job.get_pop_type();
+ PopType const* old_pop_type = pop.get_type();
+ if (job_pop_type != old_pop_type) {
+ PopType const* const equivalent = old_pop_type->get_equivalent();
+ if (job_pop_type == equivalent) {
+ is_valid_operation&=pop.convert_to_equivalent();
+ }
+ }
+ }
+ }
+ return is_valid_operation;
+}
+
void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) {
for (BuildingInstance& building : buildings.get_items()) {
building.update_gamestate(today);
@@ -279,7 +448,7 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
ret &= remove_core(country_manager.get_country_instance_from_definition(*country));
}
}
- set_optional(rgo, entry.get_rgo());
+
set_optional(life_rating, entry.get_life_rating());
set_optional(terrain_type, entry.get_terrain_type());
for (auto const& [building, level] : entry.get_province_buildings()) {
@@ -299,8 +468,16 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
return ret;
}
+void ProvinceInstance::initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache) {
+ rgo.initialise_for_new_game(*this, modifier_effect_cache);
+}
+
void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) {
for (Pop& pop : pops) {
pop.setup_pop_test_values(issue_manager);
}
}
+
+plf::colony<Pop>& ProvinceInstance::get_mutable_pops() {
+ return pops;
+} \ No newline at end of file
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index fa0be98..ba800a9 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -3,10 +3,12 @@
#include <plf_colony.h>
#include "openvic-simulation/economy/BuildingInstance.hpp"
+#include "openvic-simulation/economy/production/ProductionType.hpp"
+#include "openvic-simulation/economy/production/ResourceGatheringOperation.hpp"
#include "openvic-simulation/military/UnitInstance.hpp"
#include "openvic-simulation/military/UnitType.hpp"
+#include "openvic-simulation/modifier/ModifierSum.hpp"
#include "openvic-simulation/pop/Pop.hpp"
-#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
@@ -21,6 +23,7 @@ namespace OpenVic {
struct Ideology;
struct Culture;
struct Religion;
+ struct StaticModifierCache;
struct BuildingTypeManager;
struct ProvinceHistoryEntry;
struct IssueManager;
@@ -68,10 +71,18 @@ namespace OpenVic {
CountryInstance* PROPERTY(controller);
ordered_set<CountryInstance*> PROPERTY(cores);
+ public:
+ static constexpr bool ADD_OWNER_CONTRIBUTION = true;
+
+ private:
+ // The total/resultant modifier affecting this province, including owner country contributions if
+ // ADD_OWNER_CONTRIBUTION is true.
+ ModifierSum PROPERTY(modifier_sum);
+ std::vector<ModifierInstance> PROPERTY(event_modifiers);
+
bool PROPERTY(slave);
Crime const* PROPERTY_RW(crime);
- // TODO - change this into a factory-like structure
- GoodDefinition const* PROPERTY(rgo);
+ ResourceGatheringOperation PROPERTY(rgo);
IdentifierRegistry<BuildingInstance> IDENTIFIER_REGISTRY(building);
ordered_set<ArmyInstance*> PROPERTY(armies);
ordered_set<NavyInstance*> PROPERTY(navies);
@@ -84,7 +95,7 @@ namespace OpenVic {
fixed_point_t PROPERTY(average_literacy);
fixed_point_t PROPERTY(average_consciousness);
fixed_point_t PROPERTY(average_militancy);
- IndexedMap<PopType, fixed_point_t> PROPERTY(pop_type_distribution);
+ IndexedMap<PopType, Pop::pop_size_t> PROPERTY(pop_type_distribution);
IndexedMap<Ideology, fixed_point_t> PROPERTY(ideology_distribution);
fixed_point_map_t<Culture const*> PROPERTY(culture_distribution);
fixed_point_map_t<Religion const*> PROPERTY(religion_distribution);
@@ -97,6 +108,7 @@ namespace OpenVic {
void _add_pop(Pop&& pop);
void _update_pops(DefineManager const& define_manager);
+ bool convert_rgo_worker_pops_to_equivalent(ProductionType const& production_type);
public:
ProvinceInstance(ProvinceInstance&&) = default;
@@ -112,6 +124,9 @@ namespace OpenVic {
return controller;
}
+ GoodDefinition const* get_rgo_good() const;
+ bool set_rgo_production_type_nullable(ProductionType const* rgo_production_type_nullable);
+
bool set_owner(CountryInstance* new_owner);
bool set_controller(CountryInstance* new_controller);
bool add_core(CountryInstance& new_core);
@@ -124,6 +139,15 @@ namespace OpenVic {
bool add_pop_vec(std::vector<PopBase> const& pop_vec);
size_t get_pop_count() const;
+ void update_modifier_sum(Date today, StaticModifierCache const& static_modifier_cache);
+ void contribute_country_modifier_sum(ModifierSum const& owner_modifier_sum);
+ fixed_point_t get_modifier_effect_value(ModifierEffect const& effect) const;
+ fixed_point_t get_modifier_effect_value_nullcheck(ModifierEffect const* effect) const;
+ void push_contributing_modifiers(
+ ModifierEffect const& effect, std::vector<ModifierSum::modifier_entry_t>& contributions
+ ) const;
+ std::vector<ModifierSum::modifier_entry_t> get_contributing_modifiers(ModifierEffect const& effect) const;
+
void update_gamestate(Date today, DefineManager const& define_manager);
void tick(Date today);
@@ -135,6 +159,9 @@ namespace OpenVic {
bool setup(BuildingTypeManager const& building_type_manager);
bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager);
+ void initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache);
+
void setup_pop_test_values(IssueManager const& issue_manager);
+ plf::colony<Pop>& get_mutable_pops();
};
}
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index 020b6f1..31ea05f 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -5,6 +5,7 @@
#include "openvic-simulation/map/MapInstance.hpp"
#include "openvic-simulation/map/ProvinceInstance.hpp"
#include "openvic-simulation/map/Region.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/utility/StringUtils.hpp"
using namespace OpenVic;
@@ -65,10 +66,19 @@ void State::update_gamestate() {
const int32_t potential_workforce_in_state = 0; // sum of worker pops, regardless of employment
const int32_t potential_employment_in_state = 0; // sum of (factory level * production method base_workforce_size)
- industrial_power = total_factory_levels_in_state * std::clamp(
- (fixed_point_t { potential_workforce_in_state } / 100).floor() * 400 / potential_employment_in_state,
- fixed_point_t::_0_20(), fixed_point_t::_4()
- );
+ fixed_point_t workforce_scalar;
+ constexpr fixed_point_t min_workforce_scalar = fixed_point_t::_0_20();
+ constexpr fixed_point_t max_workforce_scalar = fixed_point_t::_4();
+ if (potential_employment_in_state <= 0) {
+ workforce_scalar = min_workforce_scalar;
+ } else {
+ workforce_scalar = std::clamp(
+ (fixed_point_t { potential_workforce_in_state } / 100).floor() * 400 / potential_employment_in_state,
+ min_workforce_scalar, max_workforce_scalar
+ );
+ }
+
+ industrial_power = total_factory_levels_in_state * workforce_scalar;
}
/* Whether two provinces in the same region should be grouped into the same state or not.
diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp
index 596206a..a39eea6 100644
--- a/src/openvic-simulation/map/State.hpp
+++ b/src/openvic-simulation/map/State.hpp
@@ -29,7 +29,7 @@ namespace OpenVic {
fixed_point_t PROPERTY(average_literacy);
fixed_point_t PROPERTY(average_consciousness);
fixed_point_t PROPERTY(average_militancy);
- IndexedMap<PopType, fixed_point_t> PROPERTY(pop_type_distribution);
+ IndexedMap<PopType, Pop::pop_size_t> PROPERTY(pop_type_distribution);
fixed_point_t PROPERTY(industrial_power);
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp
index b4cc430..011a3c3 100644
--- a/src/openvic-simulation/map/TerrainType.cpp
+++ b/src/openvic-simulation/map/TerrainType.cpp
@@ -1,5 +1,8 @@
#include "TerrainType.hpp"
+#include <string_view>
+
+#include "openvic-simulation/modifier/ModifierManager.hpp"
#include "openvic-simulation/types/Colour.hpp"
using namespace OpenVic;
@@ -16,6 +19,38 @@ TerrainTypeMapping::TerrainTypeMapping(
) : HasIdentifier { new_identifier }, type { new_type }, terrain_indices { std::move(new_terrain_indicies) },
priority { new_priority }, has_texture { new_has_texture } {}
+bool TerrainTypeManager::generate_modifiers(ModifierManager& modifier_manager) const {
+ using enum ModifierEffect::format_t;
+ IndexedMap<TerrainType, ModifierEffectCache::unit_terrain_effects_t>& unit_terrain_effects =
+ modifier_manager.modifier_effect_cache.unit_terrain_effects;
+
+ unit_terrain_effects.set_keys(&get_terrain_types());
+
+ constexpr bool has_no_effect = true;
+ bool ret = true;
+ for (TerrainType const& terrain_type : get_terrain_types()) {
+ const std::string_view identifier = terrain_type.get_identifier();
+ ModifierEffectCache::unit_terrain_effects_t& this_unit_terrain_effects = unit_terrain_effects[terrain_type];
+ ret &= modifier_manager.register_unit_terrain_modifier_effect(
+ this_unit_terrain_effects.attack, ModifierManager::get_flat_identifier("attack", identifier), true,
+ PROPORTION_DECIMAL, "UA_ATTACK", has_no_effect
+ );
+ ret &= modifier_manager.register_unit_terrain_modifier_effect(
+ this_unit_terrain_effects.defence, ModifierManager::get_flat_identifier("defence", identifier), true,
+ PROPORTION_DECIMAL, "UA_DEFENCE", has_no_effect
+ );
+ ret &= modifier_manager.register_unit_terrain_modifier_effect(
+ this_unit_terrain_effects.attrition, ModifierManager::get_flat_identifier("attrition", identifier), false,
+ RAW_DECIMAL, "UA_ATTRITION", has_no_effect
+ );
+ ret &= modifier_manager.register_unit_terrain_modifier_effect(
+ this_unit_terrain_effects.movement, ModifierManager::get_flat_identifier("movement", identifier), true,
+ PROPORTION_DECIMAL, "UA_MOVEMENT"
+ );
+ }
+ return ret;
+}
+
bool TerrainTypeManager::add_terrain_type(
std::string_view identifier, colour_t colour, ModifierValue&& values, bool is_water
) {
@@ -74,11 +109,15 @@ node_callback_t TerrainTypeManager::_load_terrain_type_categories(ModifierManage
ModifierValue values;
colour_t colour = colour_t::null();
bool is_water = false;
- bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values),
+
+ bool ret = NodeTools::expect_dictionary_keys_and_default(
+ modifier_manager.expect_terrain_modifier(values),
"color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
"is_water", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_water))
)(type_node);
+
ret &= add_terrain_type(type_key, colour, std::move(values), is_water);
+
return ret;
}
)(root);
diff --git a/src/openvic-simulation/map/TerrainType.hpp b/src/openvic-simulation/map/TerrainType.hpp
index 3a88610..b15e650 100644
--- a/src/openvic-simulation/map/TerrainType.hpp
+++ b/src/openvic-simulation/map/TerrainType.hpp
@@ -67,5 +67,6 @@ namespace OpenVic {
TerrainTypeMapping::index_t get_terrain_texture_limit() const;
bool load_terrain_types(ModifierManager const& modifier_manager, ast::NodeCPtr root);
+ bool generate_modifiers(ModifierManager& modifier_manager) const;
};
}