aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation
diff options
context:
space:
mode:
author zaaarf <me@zaaarf.foo>2023-12-05 10:16:27 +0100
committer zaaarf <me@zaaarf.foo>2023-12-05 10:16:27 +0100
commitfa2ca50905f327713207069cf9a2e66cf6c00076 (patch)
treea6c82c543d5fc52183ca1363e171dbd4cc161943 /src/openvic-simulation
parent444a27726695478e44e0166e75df1f354b6432d5 (diff)
feat: implemented invention dataloading
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r--src/openvic-simulation/GameManager.hpp5
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp57
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp2
-rw-r--r--src/openvic-simulation/economy/Good.cpp14
-rw-r--r--src/openvic-simulation/military/Unit.cpp7
-rw-r--r--src/openvic-simulation/misc/Modifier.cpp49
-rw-r--r--src/openvic-simulation/misc/Modifier.hpp2
-rw-r--r--src/openvic-simulation/politics/Rebel.cpp14
-rw-r--r--src/openvic-simulation/politics/Rebel.hpp6
-rw-r--r--src/openvic-simulation/research/Invention.cpp80
-rw-r--r--src/openvic-simulation/research/Invention.hpp55
-rw-r--r--src/openvic-simulation/research/ResearchManager.hpp12
-rw-r--r--src/openvic-simulation/research/Technology.cpp (renamed from src/openvic-simulation/tech/Technology.cpp)22
-rw-r--r--src/openvic-simulation/research/Technology.hpp (renamed from src/openvic-simulation/tech/Technology.hpp)7
14 files changed, 284 insertions, 48 deletions
diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp
index ed17c30..0e8eb2b 100644
--- a/src/openvic-simulation/GameManager.hpp
+++ b/src/openvic-simulation/GameManager.hpp
@@ -11,7 +11,8 @@
#include "openvic-simulation/misc/Define.hpp"
#include "openvic-simulation/politics/PoliticsManager.hpp"
#include "openvic-simulation/pop/Pop.hpp"
-#include "openvic-simulation/tech/Technology.hpp"
+#include "openvic-simulation/research/Technology.hpp"
+#include "research/ResearchManager.hpp"
namespace OpenVic {
struct GameManager {
@@ -25,7 +26,7 @@ namespace OpenVic {
ModifierManager PROPERTY_REF(modifier_manager);
PoliticsManager PROPERTY_REF(politics_manager);
HistoryManager PROPERTY_REF(history_manager);
- TechnologyManager PROPERTY_REF(technology_manager);
+ ResearchManager PROPERTY_REF(research_manager);
PopManager PROPERTY_REF(pop_manager);
CountryManager PROPERTY_REF(country_manager);
UIManager PROPERTY_REF(ui_manager);
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 6bf43f6..ef0b398 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -648,10 +648,30 @@ bool Dataloader::_load_goods(GameManager& game_manager) const {
return ret;
}
+bool Dataloader::_load_rebel_types(GameManager& game_manager) const {
+ static constexpr std::string_view rebel_types_file = "common/rebel_types.txt";
+
+ PoliticsManager& politics_manager = game_manager.get_politics_manager();
+ RebelManager& rebel_manager = politics_manager.get_rebel_manager();
+
+ bool ret = rebel_manager.load_rebels_file(
+ politics_manager.get_ideology_manager(),
+ politics_manager.get_government_type_manager(),
+ parse_defines(lookup_file(rebel_types_file)).get_file_node()
+ );
+
+ if(!rebel_manager.generate_modifiers(game_manager.get_modifier_manager())) {
+ Logger::error("Failed to generate rebel type-based modifiers!");
+ ret &= false;
+ }
+
+ return ret;
+}
+
bool Dataloader::_load_technologies(GameManager& game_manager) const {
static constexpr std::string_view technology_file = "common/technology.txt";
- TechnologyManager& technology_manager = game_manager.get_technology_manager();
+ TechnologyManager& technology_manager = game_manager.get_research_manager().get_technology_manager();
bool ret = true;
@@ -694,6 +714,28 @@ bool Dataloader::_load_technologies(GameManager& game_manager) const {
return ret;
}
+bool Dataloader::_load_inventions(GameManager& game_manager) const {
+ static constexpr std::string_view inventions_directory = "inventions";
+
+ InventionManager& invention_manager = game_manager.get_research_manager().get_invention_manager();
+
+ bool ret = apply_to_files(
+ lookup_files_in_dir(inventions_directory, ".txt"),
+ [&game_manager, &invention_manager](fs::path const& file) -> bool {
+ return invention_manager.load_inventions_file(
+ game_manager.get_modifier_manager(),
+ game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_economy_manager().get_building_manager(),
+ parse_defines(file).get_file_node()
+ );
+ }
+ );
+
+ invention_manager.lock_inventions();
+
+ return ret;
+}
+
bool Dataloader::_load_history(GameManager& game_manager, bool unused_history_file_warnings) const {
/* Country History */
@@ -910,7 +952,6 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
static constexpr std::string_view event_modifiers_file = "common/event_modifiers.txt";
static constexpr std::string_view static_modifiers_file = "common/static_modifiers.txt";
static constexpr std::string_view triggered_modifiers_file = "common/triggered_modifiers.txt";
- static constexpr std::string_view rebel_types_file = "common/rebel_types.txt";
bool ret = true;
@@ -1001,6 +1042,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load buildings!");
ret = false;
}
+ if (!_load_rebel_types(game_manager)) {
+ Logger::error("Failed to load rebel types!");
+ ret = false;
+ }
if (!_load_technologies(game_manager)) {
ret = false;
}
@@ -1028,6 +1073,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load triggered modifiers!");
ret = false;
}
+ if (!_load_inventions(game_manager)) {
+ Logger::error("Failed to load inventions!");
+ ret = false;
+ }
if (!_load_map_dir(game_manager)) {
Logger::error("Failed to load map!");
ret = false;
@@ -1056,10 +1105,6 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load countries!");
ret = false;
}
- if (!game_manager.get_politics_manager().load_rebels_file(parse_defines(lookup_file(rebel_types_file)).get_file_node())) {
- Logger::error("Failed to load rebel types!");
- ret = false;
- }
if (!_load_history(game_manager, false)) {
Logger::error("Failed to load history!");
ret = false;
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index a2e377b..f0a0678 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -28,7 +28,9 @@ namespace OpenVic {
bool _load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager) const;
bool _load_units(GameManager& game_manager) const;
bool _load_goods(GameManager& game_manager) const;
+ bool _load_rebel_types(GameManager& game_manager) const;
bool _load_technologies(GameManager& game_manager) const;
+ bool _load_inventions(GameManager& game_manager) const;
bool _load_map_dir(GameManager& game_manager) const;
bool _load_history(GameManager& game_manager, bool unused_history_file_warnings) const;
diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp
index 2aa5d42..02c4f0b 100644
--- a/src/openvic-simulation/economy/Good.cpp
+++ b/src/openvic-simulation/economy/Good.cpp
@@ -99,16 +99,20 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) {
#define GOOD_MODIFIER(name) \
modifier_manager.register_complex_modifier(name); \
for (Good const& good : this->get_goods()) { \
- std::string modifier_name = name; \
- modifier_name += "_"; \
- modifier_name += good.get_identifier(); \
- ret &= modifier_manager.add_modifier_effect(modifier_name, true, ModifierEffect::format_t::PROPORTION_DECIMAL); \
+ ret &= modifier_manager.add_modifier_effect( \
+ StringUtils::append_string_views(name, "_", good.get_identifier()), \
+ true, \
+ ModifierEffect::format_t::PROPORTION_DECIMAL \
+ ); \
}
bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) {
bool ret = true;
GOOD_MODIFIER("factory_goods_output");
+ GOOD_MODIFIER("factory_goods_throughput");
GOOD_MODIFIER("rgo_goods_output");
GOOD_MODIFIER("rgo_size");
return ret;
-} \ No newline at end of file
+}
+
+#undef GOOD_MODIFIER \ No newline at end of file
diff --git a/src/openvic-simulation/military/Unit.cpp b/src/openvic-simulation/military/Unit.cpp
index 7995aeb..ed3d37b 100644
--- a/src/openvic-simulation/military/Unit.cpp
+++ b/src/openvic-simulation/military/Unit.cpp
@@ -191,12 +191,11 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
}
#define STAT_MODIFIER(name, positive_good, format) \
- ret &= modifier_manager.add_modifier_effect(base_name + name, positive_good, ModifierEffect::format_t::format)
+ ret &= modifier_manager.add_modifier_effect(StringUtils::append_string_views(identifier, "_", name), positive_good, ModifierEffect::format_t::format)
bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) {
std::function<bool(std::string_view, Unit::type_t)> generate_stat_modifiers = [this, &modifier_manager](std::string_view identifier, Unit::type_t type) -> bool {
modifier_manager.register_complex_modifier(identifier);
- std::string base_name = std::string(identifier) + "_";
bool ret = true;
STAT_MODIFIER("default_organisation", true, RAW_DECIMAL);
@@ -237,4 +236,6 @@ bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) {
ret &= generate_stat_modifiers(unit.get_identifier(), unit.get_type());
return ret;
-} \ No newline at end of file
+}
+
+#undef STAT_MODIFIER \ No newline at end of file
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp
index 6ad14aa..87a6b65 100644
--- a/src/openvic-simulation/misc/Modifier.cpp
+++ b/src/openvic-simulation/misc/Modifier.cpp
@@ -1,4 +1,5 @@
#include "Modifier.hpp"
+#include <string>
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -196,6 +197,17 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("dig_in_cap", true, INT);
ret &= add_modifier_effect("max_national_focus", true, INT);
ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL);
+ ret &= add_modifier_effect("land_attrition", false);
+ ret &= add_modifier_effect("naval_attrition", false);
+ ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL);
+ ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL);
+ ret &= add_modifier_effect("colonial_prestige", true);
+ ret &= add_modifier_effect("soldier_to_pop_loss", true);
+ ret &= add_modifier_effect("pop_growth", true);
+ ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL);
+ ret &= add_modifier_effect("suppression_points_modifier", true);
+ ret &= add_modifier_effect("colonial_life_rating", false, INT);
+ ret &= add_modifier_effect("seperatism", false); //paradox typo
/* Province Modifier Effects */
ret &= add_modifier_effect("assimilation_rate", true);
@@ -359,7 +371,7 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
key_value_callback_t ModifierManager::_modifier_effect_callback(
ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator
) const {
- std::function<bool(ModifierEffect const*, ast::NodeCPtr)> add_modifier_cb = [this, &modifier, effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool {
+ const auto add_modifier_cb = [this, &modifier, effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool {
if (effect_validator(*effect)) {
if (!modifier.values.contains(effect)) {
return expect_fixed_point(assign_variable_callback(modifier.values[effect]))(value);
@@ -373,23 +385,32 @@ key_value_callback_t ModifierManager::_modifier_effect_callback(
}
};
- return [this, &modifier, default_callback, effect_validator, add_modifier_cb](std::string_view key, ast::NodeCPtr value) -> bool {
+ const auto add_flattened_modifier_cb = [this, add_modifier_cb](std::string_view prefix, std::string_view key, ast::NodeCPtr value) -> bool {
+ const std::string flat_identifier = StringUtils::append_string_views(prefix, "_", key);
+ ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier);
+ if (effect != nullptr) {
+ return add_modifier_cb(effect, value);
+ } else {
+ Logger::error("Could not find flattened modifier: ", flat_identifier);
+ return false;
+ }
+ };
+
+ return [this, default_callback, add_modifier_cb, add_flattened_modifier_cb](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierEffect const* effect = get_modifier_effect_by_identifier(key);
if (effect != nullptr && value->is_type<ast::IdentifierNode>()) {
return add_modifier_cb(effect, value);
} else if (complex_modifiers.contains(key) && value->is_derived_from<ast::AbstractListNode>()) {
- return expect_dictionary([this, &key, &add_modifier_cb, &default_callback](std::string_view identifier, ast::NodeCPtr node) -> bool {
- std::string flat_identifier = std::string(key);
- flat_identifier += "_";
- flat_identifier += identifier;
- ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier);
- if(effect != nullptr) {
- return add_modifier_cb(effect, node);
- } else {
- Logger::error("Could not find flattened modifier: ", flat_identifier);
- return false;
- }
- })(value);
+ if (key == "rebel_org_gain") { //because of course there's a special one
+ std::string_view faction_identifier;
+ ast::NodeCPtr value_node = nullptr;
+ bool ret = expect_dictionary_keys(
+ "faction", ONE_EXACTLY, expect_identifier(assign_variable_callback(faction_identifier)),
+ "value", ONE_EXACTLY, assign_variable_callback(value_node)
+ )(value);
+ ret &= add_flattened_modifier_cb(key, faction_identifier, value_node);
+ return ret;
+ } else return expect_dictionary(std::bind(add_flattened_modifier_cb, key, std::placeholders::_1, std::placeholders::_2))(value);
} else return default_callback(key, value);
};
}
diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp
index 9665e07..f3678d9 100644
--- a/src/openvic-simulation/misc/Modifier.hpp
+++ b/src/openvic-simulation/misc/Modifier.hpp
@@ -11,7 +11,7 @@ namespace OpenVic {
PROPORTION_DECIMAL, /* An unscaled fraction/ratio, with 1 being "full"/"whole" */
PERCENTAGE_DECIMAL, /* A fraction/ratio scaled so that 100 is "full"/"whole" */
RAW_DECIMAL, /* A continuous quantity, e.g. attack strength */
- INT /* A discrete quantity, e.g. building count limit */
+ INT /* A discrete quantity, e.g. building count limit */
};
friend std::unique_ptr<ModifierEffect> std::make_unique<ModifierEffect>(std::string_view&&, bool&&, format_t&&);
diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp
index e58b3de..ec39c9e 100644
--- a/src/openvic-simulation/politics/Rebel.cpp
+++ b/src/openvic-simulation/politics/Rebel.cpp
@@ -142,4 +142,18 @@ bool RebelManager::load_rebels_file(
lock_rebel_types();
return ret;
+}
+
+bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) {
+ bool ret = true;
+
+ modifier_manager.register_complex_modifier("rebel_org_gain");
+
+ ret &= modifier_manager.add_modifier_effect("rebel_org_gain_all", false);
+
+ for (RebelType const& rebel_type : get_rebel_types()) {
+ std::string modifier_name = StringUtils::append_string_views("rebel_org_gain_", rebel_type.get_identifier());
+ ret &= modifier_manager.add_modifier_effect(modifier_name, false);
+ }
+ return ret;
} \ No newline at end of file
diff --git a/src/openvic-simulation/politics/Rebel.hpp b/src/openvic-simulation/politics/Rebel.hpp
index f012829..ba7b33f 100644
--- a/src/openvic-simulation/politics/Rebel.hpp
+++ b/src/openvic-simulation/politics/Rebel.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "openvic-simulation/misc/Modifier.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
@@ -78,8 +79,7 @@ namespace OpenVic {
bool reinforcing, bool general, bool smart, bool unit_transfer, fixed_point_t occupation_mult
);
- bool load_rebels_file(
- IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root
- );
+ bool load_rebels_file(IdeologyManager const& ideology_manager, GovernmentTypeManager const& government_type_manager, ast::NodeCPtr root);
+ bool generate_modifiers(ModifierManager& modifier_manager);
};
} \ No newline at end of file
diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp
new file mode 100644
index 0000000..eb4e342
--- /dev/null
+++ b/src/openvic-simulation/research/Invention.cpp
@@ -0,0 +1,80 @@
+#include "Invention.hpp"
+#include <algorithm>
+#include <cstring>
+#include <utility>
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+Invention::Invention(
+ std::string_view identifier, ModifierValue&& values, bool news, unit_set_t activated_units, building_set_t activated_buildings,
+ crime_set_t enabled_crimes, bool unlock_gas_attack, bool unlock_gas_defence)
+ : Modifier { identifier, std::move(values), 0 },
+ news { news }, activated_units { std::move(activated_units) }, activated_buildings { std::move(activated_buildings) },
+ enabled_crimes { std::move(enabled_crimes) }, unlock_gas_attack { unlock_gas_attack }, unlock_gas_defence { unlock_gas_defence } {} //TODO icon
+
+InventionManager::InventionManager() : inventions { "inventions" } {}
+
+bool InventionManager::add_invention(
+ std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t activated_units,
+ Invention::building_set_t activated_buildings, Invention::crime_set_t enabled_crimes,
+ bool unlock_gas_attack, bool unlock_gas_defence
+) {
+ if (identifier.empty()) {
+ Logger::error("Invalid invention identifier - empty!");
+ return false;
+ }
+
+ return inventions.add_item({
+ identifier, std::move(values), news, std::move(activated_units), std::move(activated_buildings),
+ std::move(enabled_crimes), unlock_gas_attack, unlock_gas_defence
+ });
+}
+
+bool InventionManager::load_inventions_file(
+ ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, ast::NodeCPtr root
+) {
+ return expect_dictionary_reserve_length(inventions, [this, &modifier_manager, &unit_manager, &building_manager](std::string_view identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue loose_modifiers;
+ ModifierValue modifiers;
+
+ Invention::unit_set_t activated_units;
+ Invention::building_set_t activated_buildings;
+ Invention::crime_set_t enabled_crimes;
+
+ bool unlock_gas_attack = false;
+ bool unlock_gas_defence = false;
+ bool news = true; //defaults to true!
+
+ bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(loose_modifiers),
+ "news", ZERO_OR_ONE, expect_bool(assign_variable_callback(news)),
+ "limit", ONE_EXACTLY, success_callback,
+ "chance", ONE_EXACTLY, success_callback,
+ "effect", ZERO_OR_ONE, modifier_manager.expect_modifier_value_and_keys(
+ move_variable_callback(modifiers),
+ "gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)),
+ "gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)),
+ "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier([this, &activated_units](Unit const& unit) -> bool {
+ activated_units.insert(&unit);
+ return true;
+ }),
+ "activate_building", ZERO_OR_MORE, building_manager.expect_building_type_identifier([this, &activated_buildings](BuildingType const& type) -> bool {
+ activated_buildings.insert(&type);
+ return true;
+ }),
+ "enable_crime", ZERO_OR_ONE, modifier_manager.expect_crime_modifier_identifier([this, &enabled_crimes](Crime const& crime) -> bool {
+ enabled_crimes.insert(&crime);
+ return true;
+ }))
+ )(value);
+
+ modifiers += loose_modifiers;
+
+ ret &= add_invention(
+ identifier, std::move(modifiers), news, activated_units, activated_buildings, enabled_crimes,
+ unlock_gas_attack, unlock_gas_defence
+ );
+
+ return ret;
+ })(root);
+} \ No newline at end of file
diff --git a/src/openvic-simulation/research/Invention.hpp b/src/openvic-simulation/research/Invention.hpp
new file mode 100644
index 0000000..321d982
--- /dev/null
+++ b/src/openvic-simulation/research/Invention.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include "openvic-simulation/economy/BuildingType.hpp"
+#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/misc/Modifier.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include <string_view>
+#include <unordered_set>
+
+namespace OpenVic {
+ struct Invention : Modifier {
+ friend struct InventionManager;
+ //TODO implement limit and chance
+ using unit_set_t = std::unordered_set<Unit const*>;
+ using building_set_t = std::unordered_set<BuildingType const*>;
+ using crime_set_t = std::unordered_set<Crime const*>;
+
+ private:
+ const bool PROPERTY_CUSTOM_PREFIX(news, is);
+ unit_set_t PROPERTY(activated_units);
+ building_set_t PROPERTY(activated_buildings);
+ crime_set_t PROPERTY(enabled_crimes);
+ const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_attack, will);
+ const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_defence, will);
+
+ Invention(
+ std::string_view identifier, ModifierValue&& values, bool news, unit_set_t activated_units,
+ building_set_t activated_buildings, crime_set_t enabled_crimes, bool unlock_gas_attack,
+ bool unlock_gas_defence
+ );
+
+ public:
+ Invention(Invention&&) = default;
+ };
+
+ struct InventionManager {
+ IdentifierRegistry<Invention> inventions;
+
+ public:
+ InventionManager();
+
+ bool add_invention(
+ std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t activated_units,
+ Invention::building_set_t activated_buildings, Invention::crime_set_t enabled_crimes, bool unlock_gas_attack,
+ bool unlock_gas_defence
+ );
+
+ IDENTIFIER_REGISTRY_ACCESSORS(invention);
+
+ bool load_inventions_file(
+ ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager,
+ ast::NodeCPtr root
+ ); // inventions/*.txt
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/research/ResearchManager.hpp b/src/openvic-simulation/research/ResearchManager.hpp
new file mode 100644
index 0000000..d402a34
--- /dev/null
+++ b/src/openvic-simulation/research/ResearchManager.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "openvic-simulation/research/Invention.hpp"
+#include "openvic-simulation/research/Technology.hpp"
+
+namespace OpenVic {
+ struct ResearchManager {
+ private:
+ TechnologyManager PROPERTY_REF(technology_manager);
+ InventionManager PROPERTY_REF(invention_manager);
+ };
+}
diff --git a/src/openvic-simulation/tech/Technology.cpp b/src/openvic-simulation/research/Technology.cpp
index 1234ff3..07faaa3 100644
--- a/src/openvic-simulation/tech/Technology.cpp
+++ b/src/openvic-simulation/research/Technology.cpp
@@ -9,7 +9,7 @@ TechnologyArea::TechnologyArea(std::string_view new_identifier, TechnologyFolder
: HasIdentifier { new_identifier }, folder { new_folder } {}
Technology::Technology(
- std::string_view new_identifier, TechnologyArea const& new_area, year_t new_year, fixed_point_t new_cost,
+ std::string_view new_identifier, TechnologyArea const& new_area, Date::year_t new_year, fixed_point_t new_cost,
bool new_unciv_military, uint8_t new_unit, unit_set_t&& new_activated_units, building_set_t&& new_activated_buildings,
ModifierValue&& new_values
) : Modifier { new_identifier, std::move(new_values), 0 }, area { new_area }, year { new_year }, cost { new_cost },
@@ -47,7 +47,7 @@ bool TechnologyManager::add_technology_area(std::string_view identifier, Technol
}
bool TechnologyManager::add_technology(
- std::string_view identifier, TechnologyArea const* area, Technology::year_t year, fixed_point_t cost, bool unciv_military,
+ std::string_view identifier, TechnologyArea const* area, Date::year_t year, fixed_point_t cost, bool unciv_military,
uint8_t unit, Technology::unit_set_t&& activated_units, Technology::building_set_t&& activated_buildings,
ModifierValue&& values
) {
@@ -115,7 +115,7 @@ bool TechnologyManager::load_technologies_file(ModifierManager const& modifier_m
return expect_dictionary_reserve_length(technologies, [this, &modifier_manager, &unit_manager, &building_manager](std::string_view tech_key, ast::NodeCPtr tech_value) -> bool {
ModifierValue modifiers;
TechnologyArea const* area = nullptr;
- Technology::year_t year = 0;
+ Date::year_t year = 0;
fixed_point_t cost = 0;
bool unciv_military = false;
uint8_t unit = 0;
@@ -149,17 +149,19 @@ bool TechnologyManager::load_technologies_file(ModifierManager const& modifier_m
})(root);
}
+#define TECH_MODIFIER(NAME, POS) ret &= modifier_manager.add_modifier_effect(NAME, POS, ModifierEffect::format_t::PROPORTION_DECIMAL)
+#define UNCIV_TECH_MODIFIER(NAME) TECH_MODIFIER(NAME, false); TECH_MODIFIER(StringUtils::append_string_views("self_", NAME), false);
bool TechnologyManager::generate_modifiers(ModifierManager& modifier_manager) {
bool ret = true;
- ret &= modifier_manager.add_modifier_effect("unciv_military_modifier", true);
- ret &= modifier_manager.add_modifier_effect("unciv_economic_modifier", true);
- ret &= modifier_manager.add_modifier_effect("self_unciv_economic_modifier", true);
- ret &= modifier_manager.add_modifier_effect("self_unciv_military_modifier", true);
+ UNCIV_TECH_MODIFIER("unciv_military_modifier");
+ UNCIV_TECH_MODIFIER("unciv_economic_modifier");
for (TechnologyFolder const& folder : get_technology_folders()) {
- std::string folder_name = std::string(folder.get_identifier()) + "_research_bonus";
- ret &= modifier_manager.add_modifier_effect(folder_name, true);
+ TECH_MODIFIER(StringUtils::append_string_views(folder.get_identifier(), "_research_bonus"), true);
}
+
return ret;
-} \ No newline at end of file
+}
+#undef UNCIV_TECH_MODIFIER
+#undef TECH_MODIFIER \ No newline at end of file
diff --git a/src/openvic-simulation/tech/Technology.hpp b/src/openvic-simulation/research/Technology.hpp
index 6f50f01..0939369 100644
--- a/src/openvic-simulation/tech/Technology.hpp
+++ b/src/openvic-simulation/research/Technology.hpp
@@ -32,13 +32,12 @@ namespace OpenVic {
struct Technology : Modifier {
friend struct TechnologyManager;
- using year_t = Date::year_t;
using unit_set_t = std::unordered_set<Unit const*>;
using building_set_t = std::unordered_set<BuildingType const*>;
private:
TechnologyArea const& PROPERTY(area);
- const year_t PROPERTY(year);
+ const Date::year_t PROPERTY(year);
const fixed_point_t PROPERTY(cost);
const bool PROPERTY(unciv_military);
const uint8_t PROPERTY(unit);
@@ -48,7 +47,7 @@ namespace OpenVic {
//TODO: implement rules/modifiers and ai_chance
Technology(
- std::string_view new_identifier, TechnologyArea const& new_area, year_t new_year, fixed_point_t new_cost,
+ std::string_view new_identifier, TechnologyArea const& new_area, Date::year_t new_year, fixed_point_t new_cost,
bool new_unciv_military, uint8_t new_unit, unit_set_t&& new_activated_units,
building_set_t&& new_activated_buildings, ModifierValue&& new_values
);
@@ -80,7 +79,7 @@ namespace OpenVic {
IDENTIFIER_REGISTRY_ACCESSORS(technology_area)
bool add_technology(
- std::string_view identifier, TechnologyArea const* area, Technology::year_t year, fixed_point_t cost,
+ std::string_view identifier, TechnologyArea const* area, Date::year_t year, fixed_point_t cost,
bool unciv_military, uint8_t unit, Technology::unit_set_t&& activated_units,
Technology::building_set_t&& activated_buildings, ModifierValue&& values);
IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(technology, technologies)