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.cpp8
-rw-r--r--src/openvic-simulation/map/MapDefinition.cpp13
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp10
-rw-r--r--src/openvic-simulation/map/State.cpp15
-rw-r--r--src/openvic-simulation/map/TerrainType.cpp41
-rw-r--r--src/openvic-simulation/map/TerrainType.hpp1
6 files changed, 62 insertions, 26 deletions
diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp
index 176f71b..f52352c 100644
--- a/src/openvic-simulation/map/Crime.cpp
+++ b/src/openvic-simulation/map/Crime.cpp
@@ -1,5 +1,6 @@
#include "Crime.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/modifier/ModifierManager.hpp"
using namespace OpenVic;
@@ -29,16 +30,13 @@ 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 Modifier::modifier_type_t;
-
ModifierValue modifier_value;
IconModifier::icon_t icon = 0;
ConditionScript trigger { scope_t::PROVINCE, scope_t::NO_SCOPE, scope_t::NO_SCOPE };
bool default_active = false;
- bool ret = modifier_manager.expect_modifier_value_and_keys(
- move_variable_callback(modifier_value),
- CRIME,
+ 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))
diff --git a/src/openvic-simulation/map/MapDefinition.cpp b/src/openvic-simulation/map/MapDefinition.cpp
index 5fe7189..faea838 100644
--- a/src/openvic-simulation/map/MapDefinition.cpp
+++ b/src/openvic-simulation/map/MapDefinition.cpp
@@ -3,6 +3,7 @@
#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"
@@ -955,11 +956,11 @@ bool MapDefinition::load_climate_file(ModifierManager const& modifier_manager, a
bool ret = true;
Climate* cur_climate = climates.get_item_by_identifier(identifier);
if (cur_climate == nullptr) {
- using enum Modifier::modifier_type_t;
-
ModifierValue values;
- ret &= modifier_manager.expect_modifier_value(move_variable_callback(values), CLIMATE)(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 {
@@ -1004,7 +1005,6 @@ 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 {
- using enum Modifier::modifier_type_t;
if (identifier.empty()) {
Logger::error("Invalid continent identifier - empty!");
@@ -1013,9 +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),
- CONTINENT,
+ 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/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index 236efd2..5bc798d 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -209,17 +209,17 @@ void ProvinceInstance::update_modifier_sum(Date today, StaticModifierCache const
// Add static modifiers
if (is_owner_core()) {
- modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_core(), province_source);
+ modifier_sum.add_modifier(static_modifier_cache.get_core(), province_source);
}
if (province_definition.is_water()) {
- modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_sea_zone(), province_source);
+ modifier_sum.add_modifier(static_modifier_cache.get_sea_zone(), province_source);
} else {
- modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_land_province(), province_source);
+ modifier_sum.add_modifier(static_modifier_cache.get_land_province(), province_source);
if (province_definition.is_coastal()) {
- modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_coastal(), province_source);
+ modifier_sum.add_modifier(static_modifier_cache.get_coastal(), province_source);
} else {
- modifier_sum.add_modifier_nullcheck(static_modifier_cache.get_non_coastal(), province_source);
+ modifier_sum.add_modifier(static_modifier_cache.get_non_coastal(), province_source);
}
// TODO - overseas, blockaded, no_adjacent_controlled, has_siege, occupied, nationalism, infrastructure
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index 020b6f1..619f97b 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,16 @@ 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 unclamped_score_per_factory = fixed_point_t::_0();
+
+ if (potential_employment_in_state > 0) {
+ unclamped_score_per_factory = (fixed_point_t { potential_workforce_in_state } / fixed_point_t::_100()).floor() * 400 / potential_employment_in_state;
+ } else {
+ industrial_power = total_factory_levels_in_state * std::clamp(
+ unclamped_score_per_factory,
+ fixed_point_t::_0_20(), fixed_point_t::_4()
+ );
+ }
}
/* Whether two provinces in the same region should be grouped into the same state or not.
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp
index 1531507..011a3c3 100644
--- a/src/openvic-simulation/map/TerrainType.cpp
+++ b/src/openvic-simulation/map/TerrainType.cpp
@@ -1,5 +1,7 @@
#include "TerrainType.hpp"
+#include <string_view>
+
#include "openvic-simulation/modifier/ModifierManager.hpp"
#include "openvic-simulation/types/Colour.hpp"
@@ -17,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
) {
@@ -72,15 +106,12 @@ node_callback_t TerrainTypeManager::_load_terrain_type_categories(ModifierManage
return [this, &modifier_manager](ast::NodeCPtr root) -> bool {
const bool ret = expect_dictionary_reserve_length(terrain_types,
[this, &modifier_manager](std::string_view type_key, ast::NodeCPtr type_node) -> bool {
- using enum Modifier::modifier_type_t;
-
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),
- TERRAIN,
+ 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);
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;
};
}