aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r--src/openvic-simulation/politics/Ideology.cpp60
-rw-r--r--src/openvic-simulation/politics/Ideology.hpp21
-rw-r--r--src/openvic-simulation/politics/Issue.cpp62
-rw-r--r--src/openvic-simulation/politics/Issue.hpp30
-rw-r--r--src/openvic-simulation/politics/NationalFocus.cpp34
-rw-r--r--src/openvic-simulation/politics/NationalFocus.hpp27
-rw-r--r--src/openvic-simulation/politics/Rebel.cpp62
-rw-r--r--src/openvic-simulation/politics/Rebel.hpp24
8 files changed, 256 insertions, 64 deletions
diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp
index 577ab79..2678bee 100644
--- a/src/openvic-simulation/politics/Ideology.cpp
+++ b/src/openvic-simulation/politics/Ideology.cpp
@@ -9,9 +9,27 @@ IdeologyGroup::IdeologyGroup(std::string_view new_identifier) : HasIdentifier {
Ideology::Ideology(
std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
- bool new_can_reduce_militancy, Date new_spawn_date
+ bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeight&& new_add_political_reform,
+ ConditionalWeight&& new_remove_political_reform, ConditionalWeight&& new_add_social_reform,
+ ConditionalWeight&& new_remove_social_reform, ConditionalWeight&& new_add_military_reform,
+ ConditionalWeight&& new_add_economic_reform
) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, uncivilised { new_uncivilised },
- can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date } {}
+ can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date },
+ add_political_reform { std::move(new_add_political_reform) },
+ remove_political_reform { std::move(new_remove_political_reform) },
+ add_social_reform { std::move(new_add_social_reform) }, remove_social_reform { std::move(new_remove_social_reform) },
+ add_military_reform { std::move(new_add_military_reform) }, add_economic_reform { std::move(new_add_economic_reform) } {}
+
+bool Ideology::parse_scripts(GameManager const& game_manager) {
+ bool ret = true;
+ ret &= add_political_reform.parse_scripts(game_manager);
+ ret &= remove_political_reform.parse_scripts(game_manager);
+ ret &= add_social_reform.parse_scripts(game_manager);
+ ret &= remove_social_reform.parse_scripts(game_manager);
+ ret &= add_military_reform.parse_scripts(game_manager);
+ ret &= add_economic_reform.parse_scripts(game_manager);
+ return ret;
+}
bool IdeologyManager::add_ideology_group(std::string_view identifier) {
if (identifier.empty()) {
@@ -24,7 +42,9 @@ bool IdeologyManager::add_ideology_group(std::string_view identifier) {
bool IdeologyManager::add_ideology(
std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, bool can_reduce_militancy,
- Date spawn_date
+ Date spawn_date, ConditionalWeight&& add_political_reform, ConditionalWeight&& remove_political_reform,
+ ConditionalWeight&& add_social_reform, ConditionalWeight&& remove_social_reform, ConditionalWeight&& add_military_reform,
+ ConditionalWeight&& add_economic_reform
) {
if (identifier.empty()) {
Logger::error("Invalid ideology identifier - empty!");
@@ -36,7 +56,11 @@ bool IdeologyManager::add_ideology(
return false;
}
- return ideologies.add_item({ identifier, colour, *group, uncivilised, can_reduce_militancy, spawn_date });
+ return ideologies.add_item({
+ identifier, colour, *group, uncivilised, can_reduce_militancy, spawn_date, std::move(add_political_reform),
+ std::move(remove_political_reform), std::move(add_social_reform), std::move(remove_social_reform),
+ std::move(add_military_reform), std::move(add_economic_reform)
+ });
}
/* REQUIREMENTS:
@@ -61,20 +85,26 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
colour_t colour = colour_t::null();
bool uncivilised = true, can_reduce_militancy = false;
Date spawn_date;
+ ConditionalWeight add_political_reform, remove_political_reform, add_social_reform, remove_social_reform,
+ add_military_reform, add_economic_reform;
bool ret = expect_dictionary_keys(
"uncivilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(uncivilised)),
"color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
"date", ZERO_OR_ONE, expect_date(assign_variable_callback(spawn_date)),
"can_reduce_militancy", ZERO_OR_ONE, expect_bool(assign_variable_callback(can_reduce_militancy)),
- "add_political_reform", ONE_EXACTLY, success_callback,
- "remove_political_reform", ONE_EXACTLY, success_callback,
- "add_social_reform", ONE_EXACTLY, success_callback,
- "remove_social_reform", ONE_EXACTLY, success_callback,
- "add_military_reform", ZERO_OR_ONE, success_callback,
- "add_economic_reform", ZERO_OR_ONE, success_callback
+ "add_political_reform", ONE_EXACTLY, add_political_reform.expect_conditional_weight(ConditionalWeight::BASE),
+ "remove_political_reform", ONE_EXACTLY, remove_political_reform.expect_conditional_weight(ConditionalWeight::BASE),
+ "add_social_reform", ONE_EXACTLY, add_social_reform.expect_conditional_weight(ConditionalWeight::BASE),
+ "remove_social_reform", ONE_EXACTLY, remove_social_reform.expect_conditional_weight(ConditionalWeight::BASE),
+ "add_military_reform", ZERO_OR_ONE, add_military_reform.expect_conditional_weight(ConditionalWeight::BASE),
+ "add_economic_reform", ZERO_OR_ONE, add_economic_reform.expect_conditional_weight(ConditionalWeight::BASE)
)(value);
- ret &= add_ideology(key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date);
+ ret &= add_ideology(
+ key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date, std::move(add_political_reform),
+ std::move(remove_political_reform), std::move(add_social_reform), std::move(remove_social_reform),
+ std::move(add_military_reform), std::move(add_economic_reform)
+ );
return ret;
})(ideology_group_value);
})(root);
@@ -82,3 +112,11 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
return ret;
}
+
+bool IdeologyManager::parse_scripts(GameManager const& game_manager) {
+ bool ret = true;
+ for (Ideology& ideology : ideologies.get_items()) {
+ ideology.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/politics/Ideology.hpp b/src/openvic-simulation/politics/Ideology.hpp
index 8039dbd..ad07f06 100644
--- a/src/openvic-simulation/politics/Ideology.hpp
+++ b/src/openvic-simulation/politics/Ideology.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "openvic-simulation/scripts/ConditionalWeight.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
@@ -23,14 +24,25 @@ namespace OpenVic {
const bool PROPERTY_CUSTOM_PREFIX(uncivilised, is);
const bool PROPERTY(can_reduce_militancy);
const Date PROPERTY(spawn_date);
+ ConditionalWeight PROPERTY(add_political_reform);
+ ConditionalWeight PROPERTY(remove_political_reform);
+ ConditionalWeight PROPERTY(add_social_reform);
+ ConditionalWeight PROPERTY(remove_social_reform);
+ ConditionalWeight PROPERTY(add_military_reform);
+ ConditionalWeight PROPERTY(add_economic_reform);
// TODO - willingness to repeal/pass reforms (and its modifiers)
Ideology(
std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
- bool new_can_reduce_militancy, Date new_spawn_date
+ bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeight&& new_add_political_reform,
+ ConditionalWeight&& new_remove_political_reform, ConditionalWeight&& new_add_social_reform,
+ ConditionalWeight&& new_remove_social_reform, ConditionalWeight&& new_add_military_reform,
+ ConditionalWeight&& new_add_economic_reform
);
+ bool parse_scripts(GameManager const& game_manager);
+
public:
Ideology(Ideology&&) = default;
};
@@ -45,9 +57,14 @@ namespace OpenVic {
bool add_ideology(
std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised,
- bool can_reduce_militancy, Date spawn_date
+ bool can_reduce_militancy, Date spawn_date, ConditionalWeight&& add_political_reform,
+ ConditionalWeight&& remove_political_reform, ConditionalWeight&& add_social_reform,
+ ConditionalWeight&& remove_social_reform, ConditionalWeight&& add_military_reform,
+ ConditionalWeight&& add_economic_reform
);
bool load_ideology_file(ast::NodeCPtr root);
+
+ bool parse_scripts(GameManager const& game_manager);
};
}
diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp
index 4ad1625..3e64af4 100644
--- a/src/openvic-simulation/politics/Issue.cpp
+++ b/src/openvic-simulation/politics/Issue.cpp
@@ -17,9 +17,19 @@ ReformGroup::ReformGroup(std::string_view new_identifier, ReformType const& new_
Reform::Reform(
std::string_view new_identifier, ModifierValue&& new_values, ReformGroup const& new_group, size_t new_ordinal,
- RuleSet&& new_rules, tech_cost_t new_technology_cost
-) : Issue { new_identifier, std::move(new_values), new_group, std::move(new_rules), false },
- ordinal { new_ordinal }, reform_group { new_group }, technology_cost { new_technology_cost } {}
+ RuleSet&& new_rules, tech_cost_t new_technology_cost, ConditionScript&& new_allow,
+ ConditionScript&& new_on_execute_trigger, EffectScript&& new_on_execute_effect
+) : Issue { new_identifier, std::move(new_values), new_group, std::move(new_rules), false }, ordinal { new_ordinal },
+ reform_group { new_group }, technology_cost { new_technology_cost }, allow { std::move(new_allow) },
+ on_execute_trigger { std::move(new_on_execute_trigger) }, on_execute_effect { std::move(new_on_execute_effect) } {}
+
+bool Reform::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ ret &= allow.parse_script(true, game_manager);
+ ret &= on_execute_trigger.parse_script(true, game_manager);
+ ret &= on_execute_effect.parse_script(true, game_manager);
+ return ret;
+}
bool IssueManager::add_issue_group(std::string_view identifier) {
if (identifier.empty()) {
@@ -30,7 +40,9 @@ bool IssueManager::add_issue_group(std::string_view identifier) {
return issue_groups.add_item({ identifier });
}
-bool IssueManager::add_issue(std::string_view identifier, ModifierValue&& values, IssueGroup const* group, RuleSet&& rules, bool jingoism) {
+bool IssueManager::add_issue(
+ std::string_view identifier, ModifierValue&& values, IssueGroup const* group, RuleSet&& rules, bool jingoism
+) {
if (identifier.empty()) {
Logger::error("Invalid issue identifier - empty!");
return false;
@@ -68,8 +80,9 @@ bool IssueManager::add_reform_group(std::string_view identifier, ReformType cons
}
bool IssueManager::add_reform(
- std::string_view identifier, ModifierValue&& values, ReformGroup const* group, size_t ordinal,
- RuleSet&& rules, Reform::tech_cost_t technology_cost
+ std::string_view identifier, ModifierValue&& values, ReformGroup const* group, size_t ordinal, RuleSet&& rules,
+ Reform::tech_cost_t technology_cost, ConditionScript&& allow, ConditionScript&& on_execute_trigger,
+ EffectScript&& on_execute_effect
) {
if (identifier.empty()) {
Logger::error("Invalid issue identifier - empty!");
@@ -89,7 +102,10 @@ bool IssueManager::add_reform(
Logger::warning("Non-zero technology cost ", technology_cost, " found in civilised reform ", identifier, "!");
}
- return reforms.add_item({ identifier, std::move(values), *group, ordinal, std::move(rules), technology_cost });
+ return reforms.add_item({
+ identifier, std::move(values), *group, ordinal, std::move(rules), technology_cost, std::move(allow),
+ std::move(on_execute_trigger), std::move(on_execute_effect)
+ });
}
bool IssueManager::_load_issue_group(size_t& expected_issues, std::string_view identifier, ast::NodeCPtr node) {
@@ -129,17 +145,25 @@ bool IssueManager::_load_reform(
ModifierManager const& modifier_manager, RuleManager const& rule_manager, size_t ordinal, std::string_view identifier,
ReformGroup const* group, ast::NodeCPtr node
) {
- // TODO: conditions to allow, policy rule changes
ModifierValue values;
RuleSet rules;
Reform::tech_cost_t technology_cost = 0;
+ ConditionScript allow, on_execute_trigger;
+ EffectScript on_execute_effect;
+
bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values),
"technology_cost", ZERO_OR_ONE, expect_uint(assign_variable_callback(technology_cost)),
- "allow", ZERO_OR_ONE, success_callback, //TODO: allow block
+ "allow", ZERO_OR_ONE, allow.expect_script(),
"rules", ZERO_OR_ONE, rule_manager.expect_rule_set(move_variable_callback(rules)),
- "on_execute", ZERO_OR_MORE, success_callback //TODO: trigger/effect blocks
+ "on_execute", ZERO_OR_ONE, expect_dictionary_keys(
+ "trigger", ZERO_OR_ONE, on_execute_trigger.expect_script(),
+ "effect", ONE_EXACTLY, on_execute_effect.expect_script()
+ )
)(node);
- ret &= add_reform(identifier, std::move(values), group, ordinal, std::move(rules), technology_cost);
+ ret &= add_reform(
+ identifier, std::move(values), group, ordinal, std::move(rules), technology_cost, std::move(allow),
+ std::move(on_execute_trigger), std::move(on_execute_effect)
+ );
return ret;
}
@@ -157,10 +181,12 @@ bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, Rul
size_t expected_reform_groups = 0;
bool ret = expect_dictionary_reserve_length(reform_types,
[this, &expected_issue_groups, &expected_reform_groups](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key == "party_issues")
+ if (key == "party_issues") {
return expect_length(add_variable_callback(expected_issue_groups))(value);
- else return expect_length(add_variable_callback(expected_reform_groups))(value)
- & add_reform_type(key, key == "economic_reforms" || "education_reforms" || "military_reforms");
+ } else {
+ return expect_length(add_variable_callback(expected_reform_groups))(value)
+ & add_reform_type(key, key == "economic_reforms" || key == "education_reforms" || key == "military_reforms");
+ }
}
)(root);
lock_reform_types();
@@ -216,3 +242,11 @@ bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, Rul
return ret;
}
+
+bool IssueManager::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ for (Reform& reform : reforms.get_items()) {
+ ret &= reform.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/politics/Issue.hpp b/src/openvic-simulation/politics/Issue.hpp
index a034959..b836e6f 100644
--- a/src/openvic-simulation/politics/Issue.hpp
+++ b/src/openvic-simulation/politics/Issue.hpp
@@ -1,8 +1,10 @@
#pragma once
-#include "openvic-simulation/politics/Rule.hpp"
-#include "openvic-simulation/misc/Modifier.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/misc/Modifier.hpp"
+#include "openvic-simulation/politics/Rule.hpp"
+#include "openvic-simulation/scripts/ConditionScript.hpp"
+#include "openvic-simulation/scripts/EffectScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
@@ -76,12 +78,18 @@ namespace OpenVic {
ReformGroup const& PROPERTY(reform_group); // stores an already casted reference
const size_t PROPERTY(ordinal); // assigned by the parser to allow policy sorting
const tech_cost_t PROPERTY(technology_cost);
+ ConditionScript PROPERTY(allow);
+ ConditionScript PROPERTY(on_execute_trigger);
+ EffectScript PROPERTY(on_execute_effect);
Reform(
std::string_view new_identifier, ModifierValue&& new_values, ReformGroup const& new_group, size_t new_ordinal,
- RuleSet&& new_rules, tech_cost_t new_technology_cost
+ RuleSet&& new_rules, tech_cost_t new_technology_cost, ConditionScript&& new_allow,
+ ConditionScript&& new_on_execute_trigger, EffectScript&& new_on_execute_effect
);
+ bool parse_scripts(GameManager& game_manager);
+
public:
Reform(Reform&&) = default;
};
@@ -104,16 +112,24 @@ namespace OpenVic {
size_t& expected_reforms, std::string_view identifier, ReformType const* type, ast::NodeCPtr node
);
bool _load_reform(
- ModifierManager const& modifier_manager, RuleManager const& rule_manager, size_t ordinal, std::string_view identifier,
- ReformGroup const* group, ast::NodeCPtr node
+ ModifierManager const& modifier_manager, RuleManager const& rule_manager, size_t ordinal,
+ std::string_view identifier, ReformGroup const* group, ast::NodeCPtr node
);
public:
bool add_issue_group(std::string_view identifier);
- bool add_issue(std::string_view identifier, ModifierValue&& values, IssueGroup const* group, RuleSet&& rules, bool jingoism);
+ bool add_issue(
+ std::string_view identifier, ModifierValue&& values, IssueGroup const* group, RuleSet&& rules, bool jingoism
+ );
bool add_reform_type(std::string_view identifier, bool uncivilised);
bool add_reform_group(std::string_view identifier, ReformType const* type, bool ordered, bool administrative);
- bool add_reform(std::string_view identifier, ModifierValue&& values, ReformGroup const* group, size_t ordinal, RuleSet&& rules, Reform::tech_cost_t technology_cost);
+ bool add_reform(
+ std::string_view identifier, ModifierValue&& values, ReformGroup const* group, size_t ordinal, RuleSet&& rules,
+ Reform::tech_cost_t technology_cost, ConditionScript&& allow, ConditionScript&& on_execute_trigger,
+ EffectScript&& on_execute_effect
+ );
bool load_issues_file(ModifierManager const& modifier_manager, RuleManager const& rule_manager, ast::NodeCPtr root);
+
+ bool parse_scripts(GameManager& game_manager);
};
}
diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp
index a2003eb..d4066af 100644
--- a/src/openvic-simulation/politics/NationalFocus.cpp
+++ b/src/openvic-simulation/politics/NationalFocus.cpp
@@ -14,14 +14,20 @@ NationalFocus::NationalFocus(
ModifierValue&& new_modifiers,
pop_promotion_map_t&& new_encouraged_promotion,
party_loyalty_map_t&& new_encouraged_loyalty,
- production_map_t&& new_encouraged_production
+ production_map_t&& new_encouraged_production,
+ ConditionScript&& new_limit
) : HasIdentifier { new_identifier },
icon { new_icon },
group { new_group },
modifiers { std::move(new_modifiers) },
encouraged_promotion { std::move(new_encouraged_promotion) },
encouraged_loyalty { std::move(new_encouraged_loyalty) },
- encouraged_production { std::move(new_encouraged_production) } {}
+ encouraged_production { std::move(new_encouraged_production) },
+ limit { std::move(new_limit) } {}
+
+bool NationalFocus::parse_scripts(GameManager const& game_manager) {
+ return limit.parse_script(true, game_manager);
+}
inline bool NationalFocusManager::add_national_focus_group(std::string_view identifier) {
if (identifier.empty()) {
@@ -38,7 +44,8 @@ inline bool NationalFocusManager::add_national_focus(
ModifierValue&& modifiers,
NationalFocus::pop_promotion_map_t&& encouraged_promotion,
NationalFocus::party_loyalty_map_t&& encouraged_loyalty,
- NationalFocus::production_map_t&& encouraged_production
+ NationalFocus::production_map_t&& encouraged_production,
+ ConditionScript&& limit
) {
if (identifier.empty()) {
Logger::error("No identifier for national focus!");
@@ -48,7 +55,10 @@ inline bool NationalFocusManager::add_national_focus(
Logger::error("Invalid icon ", icon, " for national focus ", identifier);
return false;
}
- return national_foci.add_item({ identifier, icon, group, std::move(modifiers), std::move(encouraged_promotion), std::move(encouraged_loyalty), std::move(encouraged_production) });
+ return national_foci.add_item({
+ identifier, icon, group, std::move(modifiers), std::move(encouraged_promotion), std::move(encouraged_loyalty),
+ std::move(encouraged_production), std::move(limit)
+ });
}
bool NationalFocusManager::load_national_foci_file(PopManager const& pop_manager, IdeologyManager const& ideology_manager, GoodManager const& good_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root) {
@@ -64,6 +74,7 @@ bool NationalFocusManager::load_national_foci_file(PopManager const& pop_manager
NationalFocus::pop_promotion_map_t promotions;
NationalFocus::party_loyalty_map_t loyalties;
NationalFocus::production_map_t production;
+ ConditionScript limit;
Ideology const* last_specified_ideology = nullptr; // weird, I know
@@ -98,13 +109,16 @@ bool NationalFocusManager::load_national_foci_file(PopManager const& pop_manager
loyalties[last_specified_ideology] += boost;
return ret;
},
- "limit", ZERO_OR_ONE, success_callback, // TODO: implement conditions
+ "limit", ZERO_OR_ONE, limit.expect_script(),
"has_flashpoint", ZERO_OR_ONE, success_callback, // special case, include in limit
"own_provinces", ZERO_OR_ONE, success_callback, // special case, include in limit
"outliner_show_as_percent", ZERO_OR_ONE, success_callback // special case
)(node);
- add_national_focus(identifier, icon, group, std::move(modifiers), std::move(promotions), std::move(loyalties), std::move(production));
+ add_national_focus(
+ identifier, icon, group, std::move(modifiers), std::move(promotions), std::move(loyalties),
+ std::move(production), std::move(limit)
+ );
return ret;
})(node);
@@ -114,3 +128,11 @@ bool NationalFocusManager::load_national_foci_file(PopManager const& pop_manager
return ret;
}
+
+bool NationalFocusManager::parse_scripts(GameManager const& game_manager) {
+ bool ret = true;
+ for (NationalFocus& national_focus : national_foci.get_items()) {
+ ret &= national_focus.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/politics/NationalFocus.hpp b/src/openvic-simulation/politics/NationalFocus.hpp
index 0fe0ddc..44e58e3 100644
--- a/src/openvic-simulation/politics/NationalFocus.hpp
+++ b/src/openvic-simulation/politics/NationalFocus.hpp
@@ -1,13 +1,12 @@
#pragma once
-#include "openvic-simulation/types/IdentifierRegistry.hpp"
-#include "openvic-simulation/utility/Getters.hpp"
+#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/misc/Modifier.hpp"
-#include "openvic-simulation/pop/Pop.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
-#include "openvic-simulation/economy/Good.hpp"
-
-#include <optional>
+#include "openvic-simulation/pop/Pop.hpp"
+#include "openvic-simulation/scripts/ConditionScript.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/utility/Getters.hpp"
namespace OpenVic {
struct NationalFocusManager;
@@ -34,6 +33,7 @@ namespace OpenVic {
pop_promotion_map_t PROPERTY(encouraged_promotion);
party_loyalty_map_t PROPERTY(encouraged_loyalty);
production_map_t PROPERTY(encouraged_production);
+ ConditionScript PROPERTY(limit);
NationalFocus(
std::string_view new_identifier,
@@ -42,9 +42,12 @@ namespace OpenVic {
ModifierValue&& new_modifiers,
pop_promotion_map_t&& new_encouraged_promotion,
party_loyalty_map_t&& new_encouraged_loyalty,
- production_map_t&& new_encouraged_production
+ production_map_t&& new_encouraged_production,
+ ConditionScript&& new_limit
);
+ bool parse_scripts(GameManager const& game_manager);
+
public:
NationalFocus(NationalFocus&&) = default;
};
@@ -64,9 +67,15 @@ namespace OpenVic {
ModifierValue&& modifiers,
NationalFocus::pop_promotion_map_t&& encouraged_promotion,
NationalFocus::party_loyalty_map_t&& encouraged_loyalty,
- NationalFocus::production_map_t&& encouraged_production
+ NationalFocus::production_map_t&& encouraged_production,
+ ConditionScript&& limit
+ );
+
+ bool load_national_foci_file(
+ PopManager const& pop_manager, IdeologyManager const& ideology_manager, GoodManager const& good_manager,
+ ModifierManager const& modifier_manager, ast::NodeCPtr root
);
- bool load_national_foci_file(PopManager const& pop_manager, IdeologyManager const& ideology_manager, GoodManager const& good_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root);
+ bool parse_scripts(GameManager const& game_manager);
};
} // namespace OpenVic
diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp
index 6850e83..ca8e945 100644
--- a/src/openvic-simulation/politics/Rebel.cpp
+++ b/src/openvic-simulation/politics/Rebel.cpp
@@ -8,20 +8,41 @@ RebelType::RebelType(
RebelType::government_map_t&& desired_governments, RebelType::defection_t defection,
RebelType::independence_t independence, uint16_t defect_delay, Ideology const* ideology, bool allow_all_cultures,
bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient, bool reinforcing,
- bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
+ bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult, ConditionalWeight&& new_will_rise,
+ ConditionalWeight&& new_spawn_chance, ConditionalWeight&& new_movement_evaluation, ConditionScript&& new_siege_won_trigger,
+ EffectScript&& new_siege_won_effect, ConditionScript&& new_demands_enforced_trigger,
+ EffectScript&& new_demands_enforced_effect
) : HasIdentifier { new_identifier }, icon { icon }, area { area }, break_alliance_on_win { break_alliance_on_win },
desired_governments { std::move(desired_governments) }, defection { defection }, independence { independence },
defect_delay { defect_delay }, ideology { ideology }, allow_all_cultures { allow_all_cultures },
allow_all_culture_groups { allow_all_culture_groups }, allow_all_religions { allow_all_religions },
allow_all_ideologies { allow_all_ideologies }, resilient { resilient }, reinforcing { reinforcing }, general { general },
- smart { smart }, unit_transfer { unit_transfer }, occupation_mult { occupation_mult } {}
+ smart { smart }, unit_transfer { unit_transfer }, occupation_mult { occupation_mult },
+ will_rise { std::move(new_will_rise) }, spawn_chance { std::move(new_spawn_chance) },
+ movement_evaluation { std::move(new_movement_evaluation) }, siege_won_trigger { std::move(new_siege_won_trigger) },
+ siege_won_effect { std::move(new_siege_won_effect) }, demands_enforced_trigger { std::move(new_demands_enforced_trigger) },
+ demands_enforced_effect { std::move(new_demands_enforced_effect) } {}
+
+bool RebelType::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ ret &= will_rise.parse_scripts(game_manager);
+ ret &= spawn_chance.parse_scripts(game_manager);
+ ret &= movement_evaluation.parse_scripts(game_manager);
+ ret &= siege_won_trigger.parse_script(true, game_manager);
+ ret &= siege_won_effect.parse_script(true, game_manager);
+ ret &= demands_enforced_trigger.parse_script(true, game_manager);
+ ret &= demands_enforced_effect.parse_script(true, game_manager);
+ return ret;
+}
bool RebelManager::add_rebel_type(
std::string_view new_identifier, RebelType::icon_t icon, RebelType::area_t area, bool break_alliance_on_win,
RebelType::government_map_t&& desired_governments, RebelType::defection_t defection,
RebelType::independence_t independence, uint16_t defect_delay, Ideology const* ideology, bool allow_all_cultures,
bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient, bool reinforcing,
- bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
+ bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult, ConditionalWeight&& will_rise,
+ ConditionalWeight&& spawn_chance, ConditionalWeight&& movement_evaluation, ConditionScript&& siege_won_trigger,
+ EffectScript&& siege_won_effect, ConditionScript&& demands_enforced_trigger, EffectScript&& demands_enforced_effect
) {
if (new_identifier.empty()) {
Logger::error("Invalid rebel type identifier - empty!");
@@ -31,7 +52,9 @@ bool RebelManager::add_rebel_type(
return rebel_types.add_item({
new_identifier, icon, area, break_alliance_on_win, std::move(desired_governments), defection, independence,
defect_delay, ideology, allow_all_cultures, allow_all_culture_groups, allow_all_religions, allow_all_ideologies,
- resilient, reinforcing, general, smart, unit_transfer, occupation_mult
+ resilient, reinforcing, general, smart, unit_transfer, occupation_mult, std::move(will_rise), std::move(spawn_chance),
+ std::move(movement_evaluation), std::move(siege_won_trigger), std::move(siege_won_effect),
+ std::move(demands_enforced_trigger), std::move(demands_enforced_effect)
});
}
@@ -81,6 +104,9 @@ bool RebelManager::load_rebels_file(
allow_all_religions = true, allow_all_ideologies = true, resilient = true, reinforcing = true, general = true,
smart = true, unit_transfer = false;
fixed_point_t occupation_mult = 0;
+ ConditionalWeight will_rise, spawn_chance, movement_evaluation;
+ ConditionScript siege_won_trigger, demands_enforced_trigger;
+ EffectScript siege_won_effect, demands_enforced_effect;
bool ret = expect_dictionary_keys(
"icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)),
@@ -118,19 +144,21 @@ bool RebelManager::load_rebels_file(
"smart", ONE_EXACTLY, expect_bool(assign_variable_callback(smart)),
"unit_transfer", ONE_EXACTLY, expect_bool(assign_variable_callback(unit_transfer)),
"occupation_mult", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(occupation_mult)),
- "will_rise", ONE_EXACTLY, success_callback, //TODO
- "spawn_chance", ONE_EXACTLY, success_callback, //TODO
- "movement_evaluation", ONE_EXACTLY, success_callback, //TODO
- "siege_won_trigger", ZERO_OR_ONE, success_callback, //TODO
- "siege_won_effect", ZERO_OR_ONE, success_callback, //TODO
- "demands_enforced_trigger", ZERO_OR_ONE, success_callback, //TODO
- "demands_enforced_effect", ZERO_OR_ONE, success_callback //TODO
+ "will_rise", ONE_EXACTLY, will_rise.expect_conditional_weight(ConditionalWeight::FACTOR),
+ "spawn_chance", ONE_EXACTLY, spawn_chance.expect_conditional_weight(ConditionalWeight::FACTOR),
+ "movement_evaluation", ONE_EXACTLY, movement_evaluation.expect_conditional_weight(ConditionalWeight::FACTOR),
+ "siege_won_trigger", ZERO_OR_ONE, siege_won_trigger.expect_script(),
+ "siege_won_effect", ZERO_OR_ONE, siege_won_effect.expect_script(),
+ "demands_enforced_trigger", ZERO_OR_ONE, demands_enforced_trigger.expect_script(),
+ "demands_enforced_effect", ZERO_OR_ONE, demands_enforced_effect.expect_script()
)(node);
ret &= add_rebel_type(
identifier, icon, area, break_alliance_on_win, std::move(desired_governments), defection, independence,
defect_delay, ideology, allow_all_cultures, allow_all_culture_groups, allow_all_religions,
- allow_all_ideologies, resilient, reinforcing, general, smart, unit_transfer, occupation_mult
+ allow_all_ideologies, resilient, reinforcing, general, smart, unit_transfer, occupation_mult,
+ std::move(will_rise), std::move(spawn_chance), std::move(movement_evaluation), std::move(siege_won_trigger),
+ std::move(siege_won_effect), std::move(demands_enforced_trigger), std::move(demands_enforced_effect)
);
return ret;
@@ -155,4 +183,12 @@ bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const {
);
}
return ret;
-} \ No newline at end of file
+}
+
+bool RebelManager::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ for (RebelType& rebel_type : rebel_types.get_items()) {
+ ret &= rebel_type.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/politics/Rebel.hpp b/src/openvic-simulation/politics/Rebel.hpp
index f7e8795..f098fe0 100644
--- a/src/openvic-simulation/politics/Rebel.hpp
+++ b/src/openvic-simulation/politics/Rebel.hpp
@@ -5,6 +5,8 @@
#include "openvic-simulation/misc/Modifier.hpp"
#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
+#include "openvic-simulation/scripts/ConditionalWeight.hpp"
+#include "openvic-simulation/scripts/EffectScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
@@ -51,15 +53,28 @@ namespace OpenVic {
const bool PROPERTY_CUSTOM_PREFIX(smart, is);
const bool PROPERTY_CUSTOM_NAME(unit_transfer, will_transfer_units);
const fixed_point_t PROPERTY(occupation_mult);
+ ConditionalWeight PROPERTY(will_rise);
+ ConditionalWeight PROPERTY(spawn_chance);
+ ConditionalWeight PROPERTY(movement_evaluation);
+ ConditionScript PROPERTY(siege_won_trigger);
+ EffectScript PROPERTY(siege_won_effect);
+ ConditionScript PROPERTY(demands_enforced_trigger);
+ EffectScript PROPERTY(demands_enforced_effect);
RebelType(
std::string_view new_identifier, RebelType::icon_t icon, RebelType::area_t area, bool break_alliance_on_win,
RebelType::government_map_t&& desired_governments, RebelType::defection_t defection,
RebelType::independence_t independence, uint16_t defect_delay, Ideology const* ideology, bool allow_all_cultures,
bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient,
- bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
+ bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult,
+ ConditionalWeight&& new_will_rise, ConditionalWeight&& new_spawn_chance,
+ ConditionalWeight&& new_movement_evaluation, ConditionScript&& new_siege_won_trigger,
+ EffectScript&& new_siege_won_effect, ConditionScript&& new_demands_enforced_trigger,
+ EffectScript&& new_demands_enforced_effect
);
+ bool parse_scripts(GameManager& game_manager);
+
public:
RebelType(RebelType&&) = default;
};
@@ -74,10 +89,15 @@ namespace OpenVic {
RebelType::government_map_t&& desired_governments, RebelType::defection_t defection,
RebelType::independence_t independence, uint16_t defect_delay, Ideology const* ideology, bool allow_all_cultures,
bool allow_all_culture_groups, bool allow_all_religions, bool allow_all_ideologies, bool resilient,
- bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
+ bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult,
+ ConditionalWeight&& will_rise, ConditionalWeight&& spawn_chance, ConditionalWeight&& movement_evaluation,
+ ConditionScript&& siege_won_trigger, EffectScript&& siege_won_effect, ConditionScript&& demands_enforced_trigger,
+ EffectScript&& demands_enforced_effect
);
bool load_rebels_file(IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root);
bool generate_modifiers(ModifierManager& modifier_manager) const;
+
+ bool parse_scripts(GameManager& game_manager);
};
} \ No newline at end of file