Skip to content

Commit bbde9de

Browse files
committed
Rework ConditionalWeight to use addition/multiplication correctly
1 parent 49f0d86 commit bbde9de

File tree

19 files changed

+225
-206
lines changed

19 files changed

+225
-206
lines changed

src/openvic-simulation/misc/Decision.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Decision::Decision(
77
std::string_view new_identifier, bool new_alert, bool new_news, std::string_view new_news_title,
88
std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
99
std::string_view new_picture, ConditionScript&& new_potential, ConditionScript&& new_allow,
10-
ConditionalWeight&& new_ai_will_do, EffectScript&& new_effect
10+
ConditionalWeightFactorMul&& new_ai_will_do, EffectScript&& new_effect
1111
) : HasIdentifier { new_identifier }, alert { new_alert }, news { new_news }, news_title { new_news_title },
1212
news_desc_long { new_news_desc_long }, news_desc_medium { new_news_desc_medium },
1313
news_desc_short { new_news_desc_short }, picture { new_picture }, potential { std::move(new_potential) },
@@ -25,7 +25,7 @@ bool Decision::parse_scripts(DefinitionManager const& definition_manager) {
2525
bool DecisionManager::add_decision(
2626
std::string_view identifier, bool alert, bool news, std::string_view news_title, std::string_view news_desc_long,
2727
std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture, ConditionScript&& potential,
28-
ConditionScript&& allow, ConditionalWeight&& ai_will_do, EffectScript&& effect
28+
ConditionScript&& allow, ConditionalWeightFactorMul&& ai_will_do, EffectScript&& effect
2929
) {
3030
if (identifier.empty()) {
3131
Logger::error("Invalid decision identifier - empty!");
@@ -61,7 +61,7 @@ bool DecisionManager::load_decision_file(ast::NodeCPtr root) {
6161
std::string_view news_title, news_desc_long, news_desc_medium, news_desc_short, picture;
6262
ConditionScript potential { COUNTRY, COUNTRY, NO_SCOPE };
6363
ConditionScript allow { COUNTRY, COUNTRY, NO_SCOPE };
64-
ConditionalWeight ai_will_do { COUNTRY, COUNTRY, NO_SCOPE };
64+
ConditionalWeightFactorMul ai_will_do { COUNTRY, COUNTRY, NO_SCOPE };
6565
EffectScript effect;
6666

6767
bool ret = expect_dictionary_keys(
@@ -75,7 +75,7 @@ bool DecisionManager::load_decision_file(ast::NodeCPtr root) {
7575
"potential", ONE_EXACTLY, potential.expect_script(),
7676
"allow", ONE_EXACTLY, allow.expect_script(),
7777
"effect", ONE_EXACTLY, effect.expect_script(),
78-
"ai_will_do", ZERO_OR_ONE, ai_will_do.expect_conditional_weight(ConditionalWeight::FACTOR)
78+
"ai_will_do", ZERO_OR_ONE, ai_will_do.expect_conditional_weight()
7979
)(node);
8080

8181
ret &= add_decision(

src/openvic-simulation/misc/Decision.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ namespace OpenVic {
2020
std::string PROPERTY(picture);
2121
ConditionScript PROPERTY(potential);
2222
ConditionScript PROPERTY(allow);
23-
ConditionalWeight PROPERTY(ai_will_do);
23+
ConditionalWeightFactorMul PROPERTY(ai_will_do);
2424
EffectScript PROPERTY(effect);
2525

2626
Decision(
2727
std::string_view new_identifier, bool new_alert, bool new_news, std::string_view new_news_title,
2828
std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
2929
std::string_view new_picture, ConditionScript&& new_potential, ConditionScript&& new_allow,
30-
ConditionalWeight&& new_ai_will_do, EffectScript&& new_effect
30+
ConditionalWeightFactorMul&& new_ai_will_do, EffectScript&& new_effect
3131
);
3232

3333
bool parse_scripts(DefinitionManager const& definition_manager);
@@ -44,7 +44,8 @@ namespace OpenVic {
4444
bool add_decision(
4545
std::string_view identifier, bool alert, bool news, std::string_view news_title, std::string_view news_desc_long,
4646
std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture,
47-
ConditionScript&& potential, ConditionScript&& allow, ConditionalWeight&& ai_will_do, EffectScript&& effect
47+
ConditionScript&& potential, ConditionScript&& allow, ConditionalWeightFactorMul&& ai_will_do,
48+
EffectScript&& effect
4849
);
4950

5051
bool load_decision_file(ast::NodeCPtr root);

src/openvic-simulation/misc/Event.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
using namespace OpenVic;
77
using namespace OpenVic::NodeTools;
88

9-
Event::EventOption::EventOption(std::string_view new_name, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance)
10-
: name { new_name }, effect { std::move(new_effect) }, ai_chance { std::move(new_ai_chance) } {}
9+
Event::EventOption::EventOption(
10+
std::string_view new_name, EffectScript&& new_effect, ConditionalWeightFactorMul&& new_ai_chance
11+
) : name { new_name }, effect { std::move(new_effect) }, ai_chance { std::move(new_ai_chance) } {}
1112

1213
bool Event::EventOption::parse_scripts(DefinitionManager const& definition_manager) {
1314
bool ret = true;
@@ -21,7 +22,7 @@ Event::Event(
2122
std::string_view new_image, event_type_t new_type, bool new_triggered_only, bool new_major, bool new_fire_only_once,
2223
bool new_allows_multiple_instances, bool new_news, std::string_view new_news_title, std::string_view new_news_desc_long,
2324
std::string_view new_news_desc_medium, std::string_view new_news_desc_short, bool new_election,
24-
IssueGroup const* new_election_issue_group, ConditionScript&& new_trigger, ConditionalWeight&& new_mean_time_to_happen,
25+
IssueGroup const* new_election_issue_group, ConditionScript&& new_trigger, ConditionalWeightTime&& new_mean_time_to_happen,
2526
EffectScript&& new_immediate, std::vector<EventOption>&& new_options
2627
) : HasIdentifier { new_identifier }, title { new_title }, description { new_description }, image { new_image },
2728
type { new_type }, triggered_only { new_triggered_only }, major { new_major }, fire_only_once { new_fire_only_once },
@@ -50,7 +51,7 @@ bool EventManager::register_event(
5051
Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances, bool news,
5152
std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium,
5253
std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group, ConditionScript&& trigger,
53-
ConditionalWeight&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
54+
ConditionalWeightTime&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
5455
) {
5556
if (identifier.empty()) {
5657
Logger::error("Invalid event ID - empty!");
@@ -141,7 +142,7 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
141142
news = false, election = false;
142143
IssueGroup const* election_issue_group = nullptr;
143144
ConditionScript trigger { initial_scope, COUNTRY, NO_SCOPE };
144-
ConditionalWeight mean_time_to_happen { initial_scope, COUNTRY, NO_SCOPE };
145+
ConditionalWeightTime mean_time_to_happen { initial_scope, COUNTRY, NO_SCOPE };
145146
EffectScript immediate;
146147
std::vector<Event::EventOption> options;
147148

@@ -165,7 +166,7 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
165166
"option", ONE_OR_MORE, [&options, initial_scope](ast::NodeCPtr node) -> bool {
166167
std::string_view name;
167168
EffectScript effect;
168-
ConditionalWeight ai_chance {
169+
ConditionalWeightFactorMul ai_chance {
169170
initial_scope,
170171
COUNTRY,
171172
COUNTRY
@@ -174,7 +175,7 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
174175
bool ret = expect_dictionary_keys_and_default(
175176
key_value_success_callback, /* Option effects, passed to the EffectScript below */
176177
"name", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(name)),
177-
"ai_chance", ZERO_OR_ONE, ai_chance.expect_conditional_weight(ConditionalWeight::FACTOR)
178+
"ai_chance", ZERO_OR_ONE, ai_chance.expect_conditional_weight()
178179
)(node);
179180

180181
ret &= effect.expect_script()(node);
@@ -183,7 +184,7 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
183184
return ret;
184185
},
185186
"trigger", ZERO_OR_ONE, trigger.expect_script(),
186-
"mean_time_to_happen", ZERO_OR_ONE, mean_time_to_happen.expect_conditional_weight(ConditionalWeight::TIME),
187+
"mean_time_to_happen", ZERO_OR_ONE, mean_time_to_happen.expect_conditional_weight(),
187188
"immediate", ZERO_OR_MORE, immediate.expect_script()
188189
)(value);
189190
ret &= register_event(

src/openvic-simulation/misc/Event.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ namespace OpenVic {
2222
private:
2323
std::string PROPERTY(name);
2424
EffectScript PROPERTY(effect);
25-
ConditionalWeight PROPERTY(ai_chance);
25+
ConditionalWeightFactorMul PROPERTY(ai_chance);
2626

27-
EventOption(std::string_view new_name, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance);
27+
EventOption(std::string_view new_name, EffectScript&& new_effect, ConditionalWeightFactorMul&& new_ai_chance);
2828

2929
bool parse_scripts(DefinitionManager const& definition_manager);
3030

@@ -55,7 +55,7 @@ namespace OpenVic {
5555
IssueGroup const* PROPERTY(election_issue_group);
5656

5757
ConditionScript PROPERTY(trigger);
58-
ConditionalWeight PROPERTY(mean_time_to_happen);
58+
ConditionalWeightTime PROPERTY(mean_time_to_happen);
5959
EffectScript PROPERTY(immediate);
6060

6161
std::vector<EventOption> PROPERTY(options);
@@ -66,7 +66,8 @@ namespace OpenVic {
6666
bool new_fire_only_once, bool new_allows_multiple_instances, bool new_news, std::string_view new_news_title,
6767
std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
6868
bool new_election, IssueGroup const* new_election_issue_group, ConditionScript&& new_trigger,
69-
ConditionalWeight&& new_mean_time_to_happen, EffectScript&& new_immediate, std::vector<EventOption>&& new_options
69+
ConditionalWeightTime&& new_mean_time_to_happen, EffectScript&& new_immediate,
70+
std::vector<EventOption>&& new_options
7071
);
7172

7273
bool parse_scripts(DefinitionManager const& definition_manager);
@@ -100,7 +101,7 @@ namespace OpenVic {
100101
Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances,
101102
bool news, std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium,
102103
std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group, ConditionScript&& trigger,
103-
ConditionalWeight&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
104+
ConditionalWeightTime&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
104105
);
105106

106107
bool add_on_action(std::string_view identifier, OnAction::weight_map_t&& new_weighted_events);

src/openvic-simulation/misc/SongChance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using namespace OpenVic;
44
using namespace OpenVic::NodeTools;
55

66
SongChance::SongChance(
7-
size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance
7+
size_t new_index, std::string_view new_filename, ConditionalWeightFactorMul&& new_chance
88
) : HasIdentifier { std::to_string(new_index) }, file_name { new_filename }, chance { std::move(new_chance) } {}
99

1010
bool SongChance::parse_scripts(DefinitionManager const& definition_manager) {
@@ -24,11 +24,11 @@ bool SongChanceManager::load_songs_file(ast::NodeCPtr root) {
2424
return false;
2525
}
2626
std::string_view name {};
27-
ConditionalWeight chance { COUNTRY, COUNTRY, NO_SCOPE };
27+
ConditionalWeightFactorMul chance { COUNTRY, COUNTRY, NO_SCOPE };
2828

2929
bool ret = expect_dictionary_keys(
3030
"name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
31-
"chance", ONE_EXACTLY, chance.expect_conditional_weight(ConditionalWeight::FACTOR)
31+
"chance", ONE_EXACTLY, chance.expect_conditional_weight()
3232
)(value);
3333

3434
ret &= song_chances.add_item({ song_chances.size(), name, std::move(chance) });

src/openvic-simulation/misc/SongChance.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace OpenVic {
1212

1313
private:
1414
std::string PROPERTY(file_name);
15-
ConditionalWeight PROPERTY(chance);
15+
ConditionalWeightFactorMul PROPERTY(chance);
1616

17-
SongChance(size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance);
17+
SongChance(size_t new_index, std::string_view new_filename, ConditionalWeightFactorMul&& new_chance);
1818

1919
bool parse_scripts(DefinitionManager const& definition_manager);
2020

src/openvic-simulation/politics/Ideology.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ IdeologyGroup::IdeologyGroup(std::string_view new_identifier) : HasIdentifier {
99

1010
Ideology::Ideology(
1111
std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
12-
bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeight&& new_add_political_reform,
13-
ConditionalWeight&& new_remove_political_reform, ConditionalWeight&& new_add_social_reform,
14-
ConditionalWeight&& new_remove_social_reform, ConditionalWeight&& new_add_military_reform,
15-
ConditionalWeight&& new_add_economic_reform
12+
bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeightBase&& new_add_political_reform,
13+
ConditionalWeightBase&& new_remove_political_reform, ConditionalWeightBase&& new_add_social_reform,
14+
ConditionalWeightBase&& new_remove_social_reform, ConditionalWeightBase&& new_add_military_reform,
15+
ConditionalWeightBase&& new_add_economic_reform
1616
) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, uncivilised { new_uncivilised },
1717
can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date },
1818
add_political_reform { std::move(new_add_political_reform) },
@@ -42,9 +42,9 @@ bool IdeologyManager::add_ideology_group(std::string_view identifier) {
4242

4343
bool IdeologyManager::add_ideology(
4444
std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, bool can_reduce_militancy,
45-
Date spawn_date, ConditionalWeight&& add_political_reform, ConditionalWeight&& remove_political_reform,
46-
ConditionalWeight&& add_social_reform, ConditionalWeight&& remove_social_reform, ConditionalWeight&& add_military_reform,
47-
ConditionalWeight&& add_economic_reform
45+
Date spawn_date, ConditionalWeightBase&& add_political_reform, ConditionalWeightBase&& remove_political_reform,
46+
ConditionalWeightBase&& add_social_reform, ConditionalWeightBase&& remove_social_reform,
47+
ConditionalWeightBase&& add_military_reform, ConditionalWeightBase&& add_economic_reform
4848
) {
4949
if (identifier.empty()) {
5050
Logger::error("Invalid ideology identifier - empty!");
@@ -88,25 +88,25 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
8888
colour_t colour = colour_t::null();
8989
bool uncivilised = true, can_reduce_militancy = false;
9090
Date spawn_date;
91-
ConditionalWeight add_political_reform { COUNTRY, COUNTRY, NO_SCOPE };
92-
ConditionalWeight remove_political_reform { COUNTRY, COUNTRY, NO_SCOPE };
93-
ConditionalWeight add_social_reform { COUNTRY, COUNTRY, NO_SCOPE };
94-
ConditionalWeight remove_social_reform { COUNTRY, COUNTRY, NO_SCOPE };
95-
ConditionalWeight add_military_reform { COUNTRY, COUNTRY, NO_SCOPE };
96-
ConditionalWeight add_economic_reform { COUNTRY, COUNTRY, NO_SCOPE };
91+
ConditionalWeightBase add_political_reform { COUNTRY, COUNTRY, NO_SCOPE };
92+
ConditionalWeightBase remove_political_reform { COUNTRY, COUNTRY, NO_SCOPE };
93+
ConditionalWeightBase add_social_reform { COUNTRY, COUNTRY, NO_SCOPE };
94+
ConditionalWeightBase remove_social_reform { COUNTRY, COUNTRY, NO_SCOPE };
95+
ConditionalWeightBase add_military_reform { COUNTRY, COUNTRY, NO_SCOPE };
96+
ConditionalWeightBase add_economic_reform { COUNTRY, COUNTRY, NO_SCOPE };
9797

9898
bool ret = expect_dictionary_keys(
9999
"uncivilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(uncivilised)),
100100
"color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
101101
"date", ZERO_OR_ONE, expect_date(assign_variable_callback(spawn_date)),
102102
"can_reduce_militancy", ZERO_OR_ONE, expect_bool(assign_variable_callback(can_reduce_militancy)),
103-
"add_political_reform", ONE_EXACTLY, add_political_reform.expect_conditional_weight(ConditionalWeight::BASE),
103+
"add_political_reform", ONE_EXACTLY, add_political_reform.expect_conditional_weight(),
104104
"remove_political_reform", ONE_EXACTLY,
105-
remove_political_reform.expect_conditional_weight(ConditionalWeight::BASE),
106-
"add_social_reform", ONE_EXACTLY, add_social_reform.expect_conditional_weight(ConditionalWeight::BASE),
107-
"remove_social_reform", ONE_EXACTLY, remove_social_reform.expect_conditional_weight(ConditionalWeight::BASE),
108-
"add_military_reform", ZERO_OR_ONE, add_military_reform.expect_conditional_weight(ConditionalWeight::BASE),
109-
"add_economic_reform", ZERO_OR_ONE, add_economic_reform.expect_conditional_weight(ConditionalWeight::BASE)
105+
remove_political_reform.expect_conditional_weight(),
106+
"add_social_reform", ONE_EXACTLY, add_social_reform.expect_conditional_weight(),
107+
"remove_social_reform", ONE_EXACTLY, remove_social_reform.expect_conditional_weight(),
108+
"add_military_reform", ZERO_OR_ONE, add_military_reform.expect_conditional_weight(),
109+
"add_economic_reform", ZERO_OR_ONE, add_economic_reform.expect_conditional_weight()
110110
)(value);
111111

112112
ret &= add_ideology(

src/openvic-simulation/politics/Ideology.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ namespace OpenVic {
2626
const bool PROPERTY_CUSTOM_PREFIX(uncivilised, is);
2727
const bool PROPERTY(can_reduce_militancy);
2828
const Date PROPERTY(spawn_date);
29-
ConditionalWeight PROPERTY(add_political_reform);
30-
ConditionalWeight PROPERTY(remove_political_reform);
31-
ConditionalWeight PROPERTY(add_social_reform);
32-
ConditionalWeight PROPERTY(remove_social_reform);
33-
ConditionalWeight PROPERTY(add_military_reform);
34-
ConditionalWeight PROPERTY(add_economic_reform);
29+
ConditionalWeightBase PROPERTY(add_political_reform);
30+
ConditionalWeightBase PROPERTY(remove_political_reform);
31+
ConditionalWeightBase PROPERTY(add_social_reform);
32+
ConditionalWeightBase PROPERTY(remove_social_reform);
33+
ConditionalWeightBase PROPERTY(add_military_reform);
34+
ConditionalWeightBase PROPERTY(add_economic_reform);
3535

3636
// TODO - willingness to repeal/pass reforms (and its modifiers)
3737

3838
Ideology(
3939
std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
40-
bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeight&& new_add_political_reform,
41-
ConditionalWeight&& new_remove_political_reform, ConditionalWeight&& new_add_social_reform,
42-
ConditionalWeight&& new_remove_social_reform, ConditionalWeight&& new_add_military_reform,
43-
ConditionalWeight&& new_add_economic_reform
40+
bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeightBase&& new_add_political_reform,
41+
ConditionalWeightBase&& new_remove_political_reform, ConditionalWeightBase&& new_add_social_reform,
42+
ConditionalWeightBase&& new_remove_social_reform, ConditionalWeightBase&& new_add_military_reform,
43+
ConditionalWeightBase&& new_add_economic_reform
4444
);
4545

4646
bool parse_scripts(DefinitionManager const& definition_manager);
@@ -59,10 +59,10 @@ namespace OpenVic {
5959

6060
bool add_ideology(
6161
std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised,
62-
bool can_reduce_militancy, Date spawn_date, ConditionalWeight&& add_political_reform,
63-
ConditionalWeight&& remove_political_reform, ConditionalWeight&& add_social_reform,
64-
ConditionalWeight&& remove_social_reform, ConditionalWeight&& add_military_reform,
65-
ConditionalWeight&& add_economic_reform
62+
bool can_reduce_militancy, Date spawn_date, ConditionalWeightBase&& add_political_reform,
63+
ConditionalWeightBase&& remove_political_reform, ConditionalWeightBase&& add_social_reform,
64+
ConditionalWeightBase&& remove_social_reform, ConditionalWeightBase&& add_military_reform,
65+
ConditionalWeightBase&& add_economic_reform
6666
);
6767

6868
bool load_ideology_file(ast::NodeCPtr root);

0 commit comments

Comments
 (0)