aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-09-21 09:03:51 +0200
committer GitHub <noreply@github.com>2024-09-21 09:03:51 +0200
commite35ff8ed703b0b6a5496a21a29e0b274c6a36874 (patch)
tree68fca0f77f6b20f3e1fe98d32a5a79311cfd3edc /src/openvic-simulation/map
parent118570dc7cf9ae9daf324c2aaba5a5d86fb2c330 (diff)
parent3fcdd0c7fce2de4cbe14a0cc3d6fb4c2731b93d9 (diff)
Merge pull request #205 from OpenVicProject/modifier-typesfix-modifiers
Modifier types
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Crime.cpp12
-rw-r--r--src/openvic-simulation/map/Crime.hpp2
-rw-r--r--src/openvic-simulation/map/MapDefinition.cpp4
-rw-r--r--src/openvic-simulation/map/Region.cpp12
-rw-r--r--src/openvic-simulation/map/Region.hpp2
-rw-r--r--src/openvic-simulation/map/TerrainType.cpp22
6 files changed, 44 insertions, 10 deletions
diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp
index 03da0fc..fb521ad 100644
--- a/src/openvic-simulation/map/Crime.cpp
+++ b/src/openvic-simulation/map/Crime.cpp
@@ -6,16 +6,18 @@ using namespace OpenVic::NodeTools;
Crime::Crime(
std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger,
bool new_default_active
-) : TriggeredModifier { new_identifier, std::move(new_values), new_icon, std::move(new_trigger) },
+) : TriggeredModifier { new_identifier, std::move(new_values), modifier_type_t::CRIME, new_icon, std::move(new_trigger) },
default_active { new_default_active } {}
bool CrimeManager::add_crime_modifier(
- std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger, bool default_active
+ std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger,
+ bool default_active
) {
if (identifier.empty()) {
Logger::error("Invalid crime modifier effect identifier - empty!");
return false;
}
+
return crime_modifiers.add_item(
{ identifier, std::move(values), icon, std::move(trigger), default_active }, duplicate_warning_callback
);
@@ -26,7 +28,7 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager,
crime_modifiers,
[this, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierValue modifier_value;
- Modifier::icon_t icon = 0;
+ 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(
@@ -39,14 +41,18 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager,
return ret;
}
)(root);
+
lock_crime_modifiers();
+
return ret;
}
bool CrimeManager::parse_scripts(DefinitionManager const& definition_manager) {
bool ret = true;
+
for (Crime& crime : crime_modifiers.get_items()) {
ret &= crime.parse_scripts(definition_manager);
}
+
return ret;
}
diff --git a/src/openvic-simulation/map/Crime.hpp b/src/openvic-simulation/map/Crime.hpp
index 757a75e..91fc88a 100644
--- a/src/openvic-simulation/map/Crime.hpp
+++ b/src/openvic-simulation/map/Crime.hpp
@@ -24,7 +24,7 @@ namespace OpenVic {
public:
bool add_crime_modifier(
- std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger,
+ std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger,
bool default_active
);
diff --git a/src/openvic-simulation/map/MapDefinition.cpp b/src/openvic-simulation/map/MapDefinition.cpp
index f3bb619..488133c 100644
--- a/src/openvic-simulation/map/MapDefinition.cpp
+++ b/src/openvic-simulation/map/MapDefinition.cpp
@@ -744,7 +744,7 @@ bool MapDefinition::load_climate_file(ModifierManager const& modifier_manager, a
if (cur_climate == nullptr) {
ModifierValue values;
ret &= modifier_manager.expect_modifier_value(move_variable_callback(values))(node);
- ret &= climates.add_item({ identifier, std::move(values) });
+ 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(
[cur_climate, &identifier](ProvinceDefinition& province) {
@@ -807,7 +807,7 @@ bool MapDefinition::load_continent_file(ModifierManager const& modifier_manager,
))
)(node);
- Continent continent = { identifier, std::move(values) };
+ Continent continent { identifier, std::move(values), Modifier::modifier_type_t::CONTINENT };
continent.add_provinces(prov_list);
continent.lock();
diff --git a/src/openvic-simulation/map/Region.cpp b/src/openvic-simulation/map/Region.cpp
index d8c5fc1..d35ff56 100644
--- a/src/openvic-simulation/map/Region.cpp
+++ b/src/openvic-simulation/map/Region.cpp
@@ -10,15 +10,19 @@ bool ProvinceSet::add_province(ProvinceDefinition const* province) {
Logger::error("Cannot add province to province set - locked!");
return false;
}
+
if (province == nullptr) {
Logger::error("Cannot add province to province set - null province!");
return false;
}
+
if (contains_province(province)) {
Logger::warning("Cannot add province ", province->get_identifier(), " to province set - already in the set!");
return false;
}
+
provinces.push_back(province);
+
return true;
}
@@ -27,16 +31,20 @@ bool ProvinceSet::remove_province(ProvinceDefinition const* province) {
Logger::error("Cannot remove province from province set - locked!");
return false;
}
+
if (province == nullptr) {
Logger::error("Cannot remove province from province set - null province!");
return false;
}
+
const decltype(provinces)::const_iterator it = std::find(provinces.begin(), provinces.end(), province);
if (it == provinces.end()) {
Logger::warning("Cannot remove province ", province->get_identifier(), " from province set - already not in the set!");
return false;
}
+
provinces.erase(it);
+
return true;
}
@@ -84,8 +92,8 @@ bool ProvinceSet::contains_province(ProvinceDefinition const* province) const {
return province != nullptr && std::find(provinces.begin(), provinces.end(), province) != provinces.end();
}
-ProvinceSetModifier::ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values)
- : Modifier { new_identifier, std::move(new_values) } {}
+ProvinceSetModifier::ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type)
+ : Modifier { new_identifier, std::move(new_values), new_type } {}
Region::Region(std::string_view new_identifier, colour_t new_colour, bool new_meta)
: HasIdentifierAndColour { new_identifier, new_colour, false }, meta { new_meta } {}
diff --git a/src/openvic-simulation/map/Region.hpp b/src/openvic-simulation/map/Region.hpp
index ef25b7b..d08ccc4 100644
--- a/src/openvic-simulation/map/Region.hpp
+++ b/src/openvic-simulation/map/Region.hpp
@@ -48,7 +48,7 @@ namespace OpenVic {
struct ProvinceSetModifier : Modifier, ProvinceSet {
friend struct MapDefinition;
private:
- ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values);
+ ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type);
public:
ProvinceSetModifier(ProvinceSetModifier&&) = default;
};
diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp
index 704e79e..b4cc430 100644
--- a/src/openvic-simulation/map/TerrainType.cpp
+++ b/src/openvic-simulation/map/TerrainType.cpp
@@ -7,7 +7,8 @@ using namespace OpenVic::NodeTools;
TerrainType::TerrainType(
std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_modifier, bool new_is_water
-) : Modifier { new_identifier, std::move(new_modifier) }, HasColour { new_colour, false }, is_water { new_is_water } {}
+) : Modifier { new_identifier, std::move(new_modifier), modifier_type_t::TERRAIN }, HasColour { new_colour, false },
+ is_water { new_is_water } {}
TerrainTypeMapping::TerrainTypeMapping(
std::string_view new_identifier, TerrainType const& new_type, std::vector<index_t>&& new_terrain_indicies,
@@ -22,6 +23,7 @@ bool TerrainTypeManager::add_terrain_type(
Logger::error("Invalid terrain type identifier - empty!");
return false;
}
+
return terrain_types.add_item({ identifier, colour, std::move(values), is_water });
}
@@ -33,17 +35,22 @@ bool TerrainTypeManager::add_terrain_type_mapping(
Logger::error("Cannot register terrain type mappings until terrain types are locked!");
return false;
}
+
if (identifier.empty()) {
Logger::error("Invalid terrain type mapping identifier - empty!");
return false;
}
+
if (type == nullptr) {
Logger::error("Null terrain type for mapping ", identifier);
return false;
}
+
bool ret = true;
+
for (TerrainTypeMapping::index_t idx : terrain_indicies) {
const terrain_type_mappings_map_t::const_iterator it = terrain_type_mappings_map.find(idx);
+
if (it == terrain_type_mappings_map.end()) {
terrain_type_mappings_map.emplace(idx, terrain_type_mappings.size());
} else {
@@ -54,7 +61,9 @@ bool TerrainTypeManager::add_terrain_type_mapping(
ret = false;
}
}
+
ret &= terrain_type_mappings.add_item({ identifier, *type, std::move(terrain_indicies), priority, has_texture });
+
return ret;
}
@@ -73,7 +82,9 @@ node_callback_t TerrainTypeManager::_load_terrain_type_categories(ModifierManage
return ret;
}
)(root);
+
lock_terrain_types();
+
return ret;
};
}
@@ -83,10 +94,12 @@ bool TerrainTypeManager::_load_terrain_type_mapping(std::string_view mapping_key
Logger::error("Cannot define terrain type mapping before terrain texture limit: ", mapping_key);
return false;
}
+
if (!terrain_types_are_locked()) {
Logger::error("Cannot define terrain type mapping before categories: ", mapping_key);
return false;
}
+
TerrainType const* type = nullptr;
std::vector<TerrainTypeMapping::index_t> terrain_indicies;
TerrainTypeMapping::index_t priority = 0;
@@ -107,18 +120,23 @@ bool TerrainTypeManager::_load_terrain_type_mapping(std::string_view mapping_key
"priority", ZERO_OR_ONE, expect_uint(assign_variable_callback(priority)),
"has_texture", ZERO_OR_ONE, expect_bool(assign_variable_callback(has_texture))
)(mapping_value);
+
if (has_texture && ++terrain_texture_count == terrain_texture_limit + 1) {
Logger::warning("More terrain textures than limit!");
}
+
ret &= add_terrain_type_mapping(mapping_key, type, std::move(terrain_indicies), priority, has_texture);
+
return true;
}
TerrainTypeMapping const* TerrainTypeManager::get_terrain_type_mapping_for(TerrainTypeMapping::index_t idx) const {
const terrain_type_mappings_map_t::const_iterator it = terrain_type_mappings_map.find(idx);
+
if (it != terrain_type_mappings_map.end()) {
return terrain_type_mappings.get_item_by_index(it->second);
}
+
return nullptr;
}
@@ -135,6 +153,8 @@ bool TerrainTypeManager::load_terrain_types(ModifierManager const& modifier_mana
"terrain", ONE_EXACTLY, expect_uint(assign_variable_callback(terrain_texture_limit)),
"categories", ONE_EXACTLY, _load_terrain_type_categories(modifier_manager)
)(root);
+
lock_terrain_type_mappings();
+
return ret;
}