aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-12-31 01:47:31 +0100
committer hop311 <hop3114@gmail.com>2024-01-02 14:41:28 +0100
commit5f64f983d0cead266a28791be42162c443fd2a75 (patch)
treeda5fbb48d6c01d6faedd16b46ff846c65fdb4c33 /src/openvic-simulation/map
parent9988b21278dc1c8df044631bd2935a7e450a7bff (diff)
Added framework for loading all Conditions and Effects
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Crime.cpp26
-rw-r--r--src/openvic-simulation/map/Crime.hpp10
-rw-r--r--src/openvic-simulation/map/Map.hpp2
-rw-r--r--src/openvic-simulation/map/State.cpp2
4 files changed, 30 insertions, 10 deletions
diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp
index c0bc04e..65760a3 100644
--- a/src/openvic-simulation/map/Crime.cpp
+++ b/src/openvic-simulation/map/Crime.cpp
@@ -3,17 +3,22 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;
-Crime::Crime(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, bool new_default_active)
- : TriggeredModifier { new_identifier, std::move(new_values), new_icon }, default_active { new_default_active } {}
+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) },
+ default_active { new_default_active } {}
bool CrimeManager::add_crime_modifier(
- std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, bool default_active
+ std::string_view identifier, ModifierValue&& values, Modifier::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, default_active }, duplicate_warning_callback);
+ return crime_modifiers.add_item(
+ { identifier, std::move(values), icon, std::move(trigger), default_active }, duplicate_warning_callback
+ );
}
bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager, ast::NodeCPtr root) {
@@ -22,17 +27,26 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager,
[this, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierValue modifier_value;
Modifier::icon_t icon = 0;
+ ConditionScript trigger;
bool default_active = false;
bool ret = modifier_manager.expect_modifier_value_and_keys(
move_variable_callback(modifier_value),
"icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)),
- "trigger", ONE_EXACTLY, success_callback, // TODO - load condition
+ "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, default_active);
+ ret &= add_crime_modifier(key, std::move(modifier_value), icon, std::move(trigger), default_active);
return ret;
}
)(root);
lock_crime_modifiers();
return ret;
}
+
+bool CrimeManager::parse_scripts(GameManager const& game_manager) {
+ bool ret = true;
+ for (Crime& crime : crime_modifiers.get_items()) {
+ ret &= crime.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/map/Crime.hpp b/src/openvic-simulation/map/Crime.hpp
index 26f52ab..01044f9 100644
--- a/src/openvic-simulation/map/Crime.hpp
+++ b/src/openvic-simulation/map/Crime.hpp
@@ -9,7 +9,10 @@ namespace OpenVic {
private:
const bool PROPERTY(default_active);
- Crime(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, bool new_default_active);
+ Crime(
+ std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger,
+ bool new_default_active
+ );
public:
Crime(Crime&&) = default;
@@ -21,9 +24,12 @@ namespace OpenVic {
public:
bool add_crime_modifier(
- std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, bool default_active
+ std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger,
+ bool default_active
);
bool load_crime_modifiers(ModifierManager const& modifier_manager, ast::NodeCPtr root);
+
+ bool parse_scripts(GameManager const& game_manager);
};
}
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index 3e7ff35..33ca4b2 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -75,7 +75,7 @@ namespace OpenVic {
Province::index_t PROPERTY(max_provinces);
Province* PROPERTY(selected_province);
- Pop::pop_size_t PROPERTY(highest_province_population)
+ Pop::pop_size_t PROPERTY(highest_province_population);
Pop::pop_size_t PROPERTY(total_map_population);
Province::index_t get_index_from_colour(colour_t colour) const;
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index faf8d1b..c1f802d 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -59,7 +59,7 @@ StateSet::states_t& StateSet::get_states() {
void StateManager::generate_states(Map& map) {
regions.clear();
regions.reserve(map.get_region_count());
- for(Region const& region : map.get_regions()) {
+ for (Region const& region : map.get_regions()) {
if (!region.get_meta()) {
regions.emplace_back(map, region);
}