aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation
diff options
context:
space:
mode:
author BrickPi <49528459+BrickPi@users.noreply.github.com>2023-10-15 21:51:46 +0200
committer GitHub <noreply@github.com>2023-10-15 21:51:46 +0200
commitd1125bf50be8fd415e2ce5179fdf446918e16d93 (patch)
tree401556d0b45378c670b9101606a4fd98a207de27 /src/openvic-simulation
parent3249e21104bab6002676abe00450e7bd3f682303 (diff)
parentaf4758d399a75485b9adfeb3058a526eec3c8a4d (diff)
Merge pull request #44 from OpenVicProject/leader-loading
Implement Trait Loading
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r--src/openvic-simulation/Modifier.cpp13
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp7
-rw-r--r--src/openvic-simulation/military/LeaderTrait.cpp60
-rw-r--r--src/openvic-simulation/military/LeaderTrait.hpp72
-rw-r--r--src/openvic-simulation/military/MilitaryManager.hpp3
5 files changed, 152 insertions, 3 deletions
diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp
index fc5dcaf..97ddd8f 100644
--- a/src/openvic-simulation/Modifier.cpp
+++ b/src/openvic-simulation/Modifier.cpp
@@ -123,6 +123,17 @@ bool ModifierManager::setup_modifier_effects() {
using enum ModifierEffect::format_t;
+ /* LEADER TRAIT MODIFIERS */
+ ret &= add_modifier_effect("attack", true, INT);
+ ret &= add_modifier_effect("defence", true, INT);
+ ret &= add_modifier_effect("reliability", true, RAW_DECIMAL);
+ ret &= add_modifier_effect("morale", true);
+ ret &= add_modifier_effect("organisation", true);
+ ret &= add_modifier_effect("speed", true);
+ ret &= add_modifier_effect("reconnaissance", true);
+ ret &= add_modifier_effect("experience", true);
+ ret &= add_modifier_effect("attrition", false, RAW_DECIMAL);
+ /* MISCELLANEOUS MODIFIERS */
ret &= add_modifier_effect("movement_cost", false);
ret &= add_modifier_effect("farm_rgo_size", true);
ret &= add_modifier_effect("farm_rgo_eff", true);
@@ -130,11 +141,9 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("mine_rgo_eff", true);
ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL);
ret &= add_modifier_effect("combat_width", false);
- ret &= add_modifier_effect("defence", true, RAW_DECIMAL);
ret &= add_modifier_effect("local_ship_build", false);
ret &= add_modifier_effect("research_points_modifier", true);
ret &= add_modifier_effect("local_rgo_output", true);
- ret &= add_modifier_effect("attrition", false, RAW_DECIMAL);
ret &= add_modifier_effect("immigrant_push", false);
ret &= add_modifier_effect("population_growth", true);
ret &= add_modifier_effect("local_RGO_throughput", true);
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 72e3113..15c7ce7 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -587,6 +587,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
static const fs::path units_directory = "units";
static const fs::path buildings_file = "common/buildings.txt";
+ static const fs::path bookmark_file = "common/bookmarks.txt";
static const fs::path culture_file = "common/cultures.txt";
static const fs::path goods_file = "common/goods.txt";
static const fs::path governments_file = "common/governments.txt";
@@ -595,7 +596,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
static const fs::path issues_file = "common/issues.txt";
static const fs::path production_types_file = "common/production_types.txt";
static const fs::path religion_file = "common/religion.txt";
- static const fs::path bookmark_file = "common/bookmarks.txt";
+ static const fs::path leader_traits_file = "common/traits.txt";
bool ret = true;
@@ -663,6 +664,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load units!");
ret = false;
}
+ if (!game_manager.get_military_manager().get_leader_trait_manager().load_leader_traits_file(game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node())) {
+ Logger::error("Failed to load leader traits!");
+ ret = false;
+ }
if (!game_manager.get_history_manager().load_bookmark_file(parse_defines(lookup_file(bookmark_file)).get_file_node())) {
Logger::error("Failed to load bookmarks!");
ret = false;
diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp
new file mode 100644
index 0000000..27f81c5
--- /dev/null
+++ b/src/openvic-simulation/military/LeaderTrait.cpp
@@ -0,0 +1,60 @@
+#include "LeaderTrait.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+LeaderTrait::LeaderTrait(std::string_view new_identifier, trait_type_t new_type, ModifierValue new_modifiers)
+ : HasIdentifier { new_identifier }, type { new_type }, modifiers { new_modifiers } {}
+
+trait_type_t LeaderTrait::get_trait_type() const {
+ return type;
+}
+
+bool LeaderTrait::is_personality_trait() const {
+ return type == trait_type_t::PERSONALITY;
+}
+
+bool LeaderTrait::is_background_trait() const {
+ return type == trait_type_t::BACKGROUND;
+}
+
+ModifierValue LeaderTrait::get_modifiers() const {
+ return modifiers;
+}
+
+LeaderTraitManager::LeaderTraitManager() : leader_traits { "leader_traits" } {}
+
+bool LeaderTraitManager::add_leader_trait(std::string_view identifier, trait_type_t type, ModifierValue modifiers) {
+ if (identifier.empty()) {
+ Logger::error("Invalid leader trait identifier - empty!");
+ return false;
+ }
+
+ return leader_traits.add_item({ identifier, type, modifiers });
+}
+
+bool LeaderTraitManager::load_leader_traits_file(ModifierManager& modifier_manager, ast::NodeCPtr root) {
+ bool ret = expect_dictionary_keys(
+ "personality", ONE_EXACTLY, expect_dictionary(
+ [this, &modifier_manager](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue modifiers;
+
+ bool ret = modifier_manager.expect_whitelisted_modifier_value(move_variable_callback(modifiers), allowed_modifiers)(value);
+ ret &= add_leader_trait(trait_identifier, trait_type_t::PERSONALITY, modifiers);
+ return ret;
+ }
+ ),
+ "background", ONE_EXACTLY, expect_dictionary(
+ [this, &modifier_manager](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue modifiers;
+
+ bool ret = modifier_manager.expect_whitelisted_modifier_value(move_variable_callback(modifiers), allowed_modifiers)(value);
+ ret &= add_leader_trait(trait_identifier, trait_type_t::BACKGROUND, modifiers);
+ return ret;
+ }
+ )
+ )(root);
+ lock_leader_traits();
+
+ return ret;
+} \ No newline at end of file
diff --git a/src/openvic-simulation/military/LeaderTrait.hpp b/src/openvic-simulation/military/LeaderTrait.hpp
new file mode 100644
index 0000000..f4445f6
--- /dev/null
+++ b/src/openvic-simulation/military/LeaderTrait.hpp
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <cstdint>
+#include <string_view>
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/Modifier.hpp"
+
+namespace OpenVic {
+ struct LeaderTraitManager;
+
+ enum class trait_type_t {
+ PERSONALITY,
+ BACKGROUND
+ };
+
+ struct LeaderTrait : HasIdentifier {
+ friend struct LeaderTraitManager;
+
+ private:
+
+ const trait_type_t type;
+ /*
+ * Allowed modifiers for leaders:
+ * attack - integer
+ * defence - integer
+ * morale - %
+ * organisation - %
+ * reconnaissance - %
+ * speed - %
+ * attrition - %, negative is good
+ * experience - %
+ * reliability - decimal, mil gain or loss for associated POPs
+ */
+ const ModifierValue modifiers;
+
+ LeaderTrait(std::string_view new_identifier, trait_type_t new_type, ModifierValue new_modifiers);
+
+ public:
+ LeaderTrait(LeaderTrait&&) = default;
+
+ trait_type_t get_trait_type() const;
+ bool is_personality_trait() const;
+ bool is_background_trait() const;
+ ModifierValue get_modifiers() const;
+ };
+
+ struct LeaderTraitManager {
+ private:
+ IdentifierRegistry<LeaderTrait> leader_traits;
+ const std::set<std::string, std::less<void>> allowed_modifiers = {
+ "attack",
+ "defence",
+ "morale",
+ "organisation",
+ "reconnaissance",
+ "speed",
+ "attrition",
+ "experience",
+ "reliability"
+ };
+
+ public:
+ LeaderTraitManager();
+
+ bool add_leader_trait(std::string_view identifier, trait_type_t type, ModifierValue modifiers);
+ IDENTIFIER_REGISTRY_ACCESSORS(leader_trait)
+
+ bool load_leader_traits_file(ModifierManager& modifier_manager, ast::NodeCPtr root);
+ };
+} // namespace OpenVic
diff --git a/src/openvic-simulation/military/MilitaryManager.hpp b/src/openvic-simulation/military/MilitaryManager.hpp
index 36b5010..fd8135d 100644
--- a/src/openvic-simulation/military/MilitaryManager.hpp
+++ b/src/openvic-simulation/military/MilitaryManager.hpp
@@ -1,12 +1,15 @@
#pragma once
#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/military/LeaderTrait.hpp"
namespace OpenVic {
struct MilitaryManager {
private:
UnitManager unit_manager;
+ LeaderTraitManager leader_trait_manager;
public:
REF_GETTERS(unit_manager)
+ REF_GETTERS(leader_trait_manager)
};
}