diff options
author | hop311 <hop3114@gmail.com> | 2023-10-13 00:05:49 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-10-13 00:05:49 +0200 |
commit | 6b3d2315225468e03bef30e942263fe9b8fc06fa (patch) | |
tree | fbcc59a1637cd13a0024ed1c8ff17dcf2e1a6ed7 /src | |
parent | e50c67eb1aaa54f5fb31425f81616bea4e6b880a (diff) |
Further cleanup and rearrangement
Diffstat (limited to 'src')
21 files changed, 162 insertions, 178 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp index 69adaac..1c4efb3 100644 --- a/src/openvic-simulation/GameManager.cpp +++ b/src/openvic-simulation/GameManager.cpp @@ -6,94 +6,6 @@ GameManager::GameManager(state_updated_func_t state_updated_callback) : clock { [this]() { tick(); }, [this]() { update_state(); } }, state_updated { state_updated_callback } {} -Map& GameManager::get_map() { - return map; -} - -Map const& GameManager::get_map() const { - return map; -} - -BuildingManager& GameManager::get_building_manager() { - return building_manager; -} - -BuildingManager const& GameManager::get_building_manager() const { - return building_manager; -} - -GoodManager& GameManager::get_good_manager() { - return good_manager; -} - -GoodManager const& GameManager::get_good_manager() const { - return good_manager; -} - -GovernmentTypeManager& GameManager::get_government_type_manager() { - return government_type_manager; -} - -GovernmentTypeManager const& GameManager::get_government_type_manager() const { - return government_type_manager; -} - -PopManager& GameManager::get_pop_manager() { - return pop_manager; -} - -PopManager const& GameManager::get_pop_manager() const { - return pop_manager; -} - -IdeologyManager& GameManager::get_ideology_manager() { - return ideology_manager; -} - -IdeologyManager const& GameManager::get_ideology_manager() const { - return ideology_manager; -} - -IssueManager& GameManager::get_issue_manager() { - return issue_manager; -} - -IssueManager const& GameManager::get_issue_manager() const { - return issue_manager; -} - -ProductionTypeManager& GameManager::get_production_type_manager() { - return production_type_manager; -} - -ProductionTypeManager const& GameManager::get_production_type_manager() const { - return production_type_manager; -} - -UnitManager& GameManager::get_unit_manager() { - return unit_manager; -} - -UnitManager const& GameManager::get_unit_manager() const { - return unit_manager; -} - -ModifierManager& GameManager::get_modifier_manager() { - return modifier_manager; -} - -ModifierManager const& GameManager::get_modifier_manager() const { - return modifier_manager; -} - -GameAdvancementHook& GameManager::get_clock() { - return clock; -} - -GameAdvancementHook const& GameManager::get_clock() const { - return clock; -} - void GameManager::set_needs_update() { needs_update = true; } @@ -120,8 +32,8 @@ bool GameManager::setup() { session_start = time(nullptr); clock.reset(); today = { 1836 }; - good_manager.reset_to_defaults(); - bool ret = map.setup(good_manager, building_manager, pop_manager); + economy_manager.get_good_manager().reset_to_defaults(); + bool ret = map.setup(economy_manager.get_building_manager(), pop_manager); set_needs_update(); return ret; } diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp index 8982e21..6e6c0b8 100644 --- a/src/openvic-simulation/GameManager.hpp +++ b/src/openvic-simulation/GameManager.hpp @@ -1,13 +1,11 @@ #pragma once #include "openvic-simulation/GameAdvancementHook.hpp" -#include "openvic-simulation/economy/Good.hpp" -#include "openvic-simulation/politics/Government.hpp" -#include "openvic-simulation/economy/ProductionType.hpp" +#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/economy/EconomyManager.hpp" #include "openvic-simulation/map/Map.hpp" -#include "openvic-simulation/politics/Ideology.hpp" -#include "openvic-simulation/politics/Issue.hpp" -#include "openvic-simulation/units/Unit.hpp" +#include "openvic-simulation/military/MilitaryManager.hpp" +#include "openvic-simulation/politics/PoliticsManager.hpp" namespace OpenVic { struct GameManager { @@ -15,15 +13,11 @@ namespace OpenVic { private: Map map; - BuildingManager building_manager; - GoodManager good_manager; - GovernmentTypeManager government_type_manager; - PopManager pop_manager; - IdeologyManager ideology_manager; - IssueManager issue_manager; - ProductionTypeManager production_type_manager; - UnitManager unit_manager; + EconomyManager economy_manager; + MilitaryManager military_manager; ModifierManager modifier_manager; + PoliticsManager politics_manager; + PopManager pop_manager; GameAdvancementHook clock; time_t session_start; /* SS-54, as well as allowing time-tracking */ @@ -38,28 +32,13 @@ namespace OpenVic { public: GameManager(state_updated_func_t state_updated_callback); - Map& get_map(); - Map const& get_map() const; - BuildingManager& get_building_manager(); - BuildingManager const& get_building_manager() const; - GoodManager& get_good_manager(); - GoodManager const& get_good_manager() const; - GovernmentTypeManager& get_government_type_manager(); - GovernmentTypeManager const& get_government_type_manager() const; - PopManager& get_pop_manager(); - PopManager const& get_pop_manager() const; - IdeologyManager& get_ideology_manager(); - IdeologyManager const& get_ideology_manager() const; - IssueManager& get_issue_manager(); - IssueManager const& get_issue_manager() const; - ProductionTypeManager& get_production_type_manager(); - ProductionTypeManager const& get_production_type_manager() const; - UnitManager& get_unit_manager(); - UnitManager const& get_unit_manager() const; - ModifierManager& get_modifier_manager(); - ModifierManager const& get_modifier_manager() const; - GameAdvancementHook& get_clock(); - GameAdvancementHook const& get_clock() const; + REF_GETTERS(map) + REF_GETTERS(economy_manager) + REF_GETTERS(military_manager) + REF_GETTERS(modifier_manager) + REF_GETTERS(politics_manager) + REF_GETTERS(pop_manager) + REF_GETTERS(clock) bool setup(); diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp index 5aadd79..4e5b860 100644 --- a/src/openvic-simulation/Modifier.cpp +++ b/src/openvic-simulation/Modifier.cpp @@ -131,7 +131,7 @@ bool ModifierManager::setup_modifier_effects() { return ret; } -node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue&&> modifier_callback, key_value_callback_t default_callback) const { +node_callback_t ModifierManager::expect_modifier_value_and_default(callback_t<ModifierValue&&> modifier_callback, key_value_callback_t default_callback) const { return [this, modifier_callback, default_callback](ast::NodeCPtr root) -> bool { ModifierValue modifier; bool ret = expect_dictionary( @@ -154,9 +154,13 @@ node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue& }; } -node_callback_t ModifierManager::_expect_modifier_value_and_keys(callback_t<ModifierValue&&> modifier_callback, key_map_t&& key_map) const { +node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue&&> modifier_callback) const { + return expect_modifier_value_and_default(modifier_callback, key_value_invalid_callback); +} + +node_callback_t ModifierManager::expect_modifier_value_and_key_map_and_default(callback_t<ModifierValue&&> modifier_callback, key_value_callback_t default_callback, key_map_t&& key_map) const { return [this, modifier_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { - bool ret = expect_modifier_value( + bool ret = expect_modifier_value_and_default( modifier_callback, dictionary_keys_callback(key_map, key_value_invalid_callback) )(node); ret &= check_key_map_counts(key_map); @@ -164,6 +168,10 @@ node_callback_t ModifierManager::_expect_modifier_value_and_keys(callback_t<Modi }; } +node_callback_t ModifierManager::expect_modifier_value_and_key_map(callback_t<ModifierValue&&> modifier_callback, key_map_t&& key_map) const { + return expect_modifier_value_and_key_map_and_default(modifier_callback, key_value_invalid_callback, std::move(key_map)); +} + namespace OpenVic { //so the compiler shuts up std::ostream& operator<<(std::ostream& stream, ModifierValue const& value) { for (ModifierValue::effect_map_t::value_type const& effect : value.values) { diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp index 0c4e636..2e1b03a 100644 --- a/src/openvic-simulation/Modifier.hpp +++ b/src/openvic-simulation/Modifier.hpp @@ -92,17 +92,6 @@ namespace OpenVic { IdentifierRegistry<ModifierEffect> modifier_effects; IdentifierRegistry<Modifier> modifiers; - NodeTools::node_callback_t _expect_modifier_value_and_keys(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_map_t&& key_map) const; - - template<typename... Args> - NodeTools::node_callback_t _expect_modifier_value_and_keys( - NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_map_t&& key_map, - std::string_view key, NodeTools::dictionary_entry_t::expected_count_t expected_count, NodeTools::node_callback_t callback, - Args... args) const { - NodeTools::add_key_map_entry(key_map, key, expected_count, callback); - return _expect_modifier_value_and_keys(modifier_callback, std::move(key_map), args...); - } - public: ModifierManager(); @@ -114,11 +103,28 @@ namespace OpenVic { bool setup_modifier_effects(); - NodeTools::node_callback_t expect_modifier_value(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback) const; + NodeTools::node_callback_t expect_modifier_value_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback) const; + NodeTools::node_callback_t expect_modifier_value(NodeTools::callback_t<ModifierValue&&> modifier_callback) const; + + NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map) const; + NodeTools::node_callback_t expect_modifier_value_and_key_map(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_map_t&& key_map) const; template<typename... Args> + NodeTools::node_callback_t expect_modifier_value_and_key_map_and_default( + NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback, NodeTools::key_map_t&& key_map, + std::string_view key, NodeTools::dictionary_entry_t::expected_count_t expected_count, NodeTools::node_callback_t callback, + Args... args) const { + NodeTools::add_key_map_entry(key_map, key, expected_count, callback); + return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, std::move(key_map), args...); + } + + template<typename... Args> + NodeTools::node_callback_t expect_modifier_value_and_keys_and_default(NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback, Args... args) const { + return expect_modifier_value_and_key_map_and_default(modifier_callback, default_callback, {}, args...); + } + template<typename... Args> NodeTools::node_callback_t expect_modifier_value_and_keys(NodeTools::callback_t<ModifierValue&&> modifier_callback, Args... args) const { - return _expect_modifier_value_and_keys(modifier_callback, {}, args...); + return expect_modifier_value_and_key_map_and_default(modifier_callback, NodeTools::key_value_invalid_callback, {}, args...); } }; } diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index bd634ce..718218f 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -436,6 +436,14 @@ v2script::Parser Dataloader::parse_defines(fs::path const& path) { return _run_ovdl_parser<v2script::Parser, &_v2script_parse>(path); } +static bool _lua_parse(v2script::Parser& parser) { + return parser.lua_defines_parse(); +} + +static ovdl::v2script::Parser parse_lua_defines(fs::path const& path) { + return _run_ovdl_parser<v2script::Parser, &_lua_parse>(path); +} + static bool _csv_parse(csv::Windows1252Parser& parser) { return parser.parse_csv(); } @@ -527,17 +535,20 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di Logger::error("Failed to load map default file!"); } - if (!map.load_province_definitions(parse_csv(lookup_file(map_directory / definitions)).get_lines())) { + if (!map.load_province_definitions( + parse_csv(lookup_file(map_directory / definitions)).get_lines())) { Logger::error("Failed to load province definitions file!"); ret = false; } - if (!map.load_province_positions(game_manager.get_building_manager(), parse_defines(lookup_file(map_directory / positions)).get_file_node())) { + if (!map.load_province_positions( + game_manager.get_economy_manager().get_building_manager(), parse_defines(lookup_file(map_directory / positions)).get_file_node())) { Logger::error("Failed to load province positions file!"); ret = false; } - if (!map.load_region_file(parse_defines(lookup_file(map_directory / region)).get_file_node())) { + if (!map.load_region_file( + parse_defines(lookup_file(map_directory / region)).get_file_node())) { Logger::error("Failed to load region file!"); ret = false; } @@ -547,17 +558,22 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di ret = false; } - if (!map.get_terrain_type_manager().load_terrain_types(game_manager.get_modifier_manager(), parse_defines(lookup_file(map_directory / terrain_definition)).get_file_node())) { + if (!map.get_terrain_type_manager().load_terrain_types( + game_manager.get_modifier_manager(), + parse_defines(lookup_file(map_directory / terrain_definition)).get_file_node())) { Logger::error("Failed to load terrain types!"); ret = false; } - if (!map.load_map_images(lookup_file(map_directory / provinces), lookup_file(map_directory / terrain), false)) { + if (!map.load_map_images( + lookup_file(map_directory / provinces), + lookup_file(map_directory / terrain), false)) { Logger::error("Failed to load map images!"); ret = false; } - if (!map.generate_and_load_province_adjacencies(parse_csv(lookup_file(map_directory / adjacencies)).get_lines())) { + if (!map.generate_and_load_province_adjacencies( + parse_csv(lookup_file(map_directory / adjacencies)).get_lines())) { Logger::error("Failed to generate and load province adjacencies!"); ret = false; } @@ -586,7 +602,8 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to set up modifier effects!"); ret = false; } - if (!game_manager.get_good_manager().load_goods_file(parse_defines(lookup_file(goods_file)).get_file_node())) { + if (!game_manager.get_economy_manager().get_good_manager().load_goods_file( + parse_defines(lookup_file(goods_file)).get_file_node())) { Logger::error("Failed to load goods!"); ret = false; } @@ -594,40 +611,43 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load pop types!"); ret = false; } - if (!game_manager.get_pop_manager().get_culture_manager().load_graphical_culture_type_file(parse_defines(lookup_file(graphical_culture_type_file)).get_file_node())) { + if (!game_manager.get_pop_manager().get_culture_manager().load_graphical_culture_type_file( + parse_defines(lookup_file(graphical_culture_type_file)).get_file_node())) { Logger::error("Failed to load graphical culture types!"); ret = false; } - if (!game_manager.get_pop_manager().get_culture_manager().load_culture_file(parse_defines(lookup_file(culture_file)).get_file_node())) { + if (!game_manager.get_pop_manager().get_culture_manager().load_culture_file( + parse_defines(lookup_file(culture_file)).get_file_node())) { Logger::error("Failed to load cultures!"); ret = false; } - if (!game_manager.get_pop_manager().get_religion_manager().load_religion_file(parse_defines(lookup_file(religion_file)).get_file_node())) { + if (!game_manager.get_pop_manager().get_religion_manager().load_religion_file( + parse_defines(lookup_file(religion_file)).get_file_node())) { Logger::error("Failed to load religions!"); ret = false; } - if (!game_manager.get_ideology_manager().load_ideology_file(parse_defines(lookup_file(ideology_file)).get_file_node())) { + if (!game_manager.get_politics_manager().get_ideology_manager().load_ideology_file( + parse_defines(lookup_file(ideology_file)).get_file_node())) { Logger::error("Failed to load ideologies!"); ret = false; } - if (!game_manager.get_government_type_manager().load_government_types_file(game_manager.get_ideology_manager(), parse_defines(lookup_file(governments_file)).get_file_node())) { + if (!game_manager.get_politics_manager().load_government_types_file( + parse_defines(lookup_file(governments_file)).get_file_node())) { Logger::error("Failed to load government types!"); ret = false; } - if (!game_manager.get_issue_manager().load_issues_file(parse_defines(lookup_file(issues_file)).get_file_node())) { + if (!game_manager.get_politics_manager().get_issue_manager().load_issues_file( + parse_defines(lookup_file(issues_file)).get_file_node())) { Logger::error("Failed to load issues!"); ret = false; } - if (!game_manager.get_production_type_manager().load_production_types_file( - game_manager.get_good_manager(), + if (!game_manager.get_economy_manager().load_production_types_file( game_manager.get_pop_manager(), parse_defines(lookup_file(production_types_file)).get_file_node())) { Logger::error("Failed to load production types!"); ret = false; } - if (!game_manager.get_building_manager().load_buildings_file( - game_manager.get_good_manager(), - game_manager.get_production_type_manager(), + if (!game_manager.get_economy_manager().load_buildings_file( game_manager.get_modifier_manager(), parse_defines(lookup_file(buildings_file)).get_file_node())) { Logger::error("Failed to load buildings!"); @@ -637,7 +657,8 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load map!"); ret = false; } - if (!_load_units(game_manager.get_unit_manager(), game_manager.get_good_manager(), units_directory)) { + if (!_load_units(game_manager.get_military_manager().get_unit_manager(), + game_manager.get_economy_manager().get_good_manager(), units_directory)) { Logger::error("Failed to load units!"); ret = false; } diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp index 30eed6e..c4cd7c7 100644 --- a/src/openvic-simulation/dataloader/Dataloader.hpp +++ b/src/openvic-simulation/dataloader/Dataloader.hpp @@ -29,6 +29,7 @@ namespace OpenVic { public: static ovdl::v2script::Parser parse_defines(fs::path const& path); + static ovdl::v2script::Parser parse_lua_defines(fs::path const& path); static ovdl::csv::Windows1252Parser parse_csv(fs::path const& path); Dataloader() = default; diff --git a/src/openvic-simulation/map/Building.cpp b/src/openvic-simulation/economy/Building.cpp index d27c91a..d27c91a 100644 --- a/src/openvic-simulation/map/Building.cpp +++ b/src/openvic-simulation/economy/Building.cpp diff --git a/src/openvic-simulation/map/Building.hpp b/src/openvic-simulation/economy/Building.hpp index 3f74c3d..3f74c3d 100644 --- a/src/openvic-simulation/map/Building.hpp +++ b/src/openvic-simulation/economy/Building.hpp diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp new file mode 100644 index 0000000..05dfc91 --- /dev/null +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "openvic-simulation/economy/Building.hpp" +#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/economy/ProductionType.hpp" + +namespace OpenVic { + struct EconomyManager { + private: + BuildingManager building_manager; + GoodManager good_manager; + ProductionTypeManager production_type_manager; + public: + REF_GETTERS(building_manager) + REF_GETTERS(good_manager) + REF_GETTERS(production_type_manager) + + inline bool load_production_types_file(PopManager const& pop_manager, ast::NodeCPtr root) { + return production_type_manager.load_production_types_file(good_manager, pop_manager, root); + } + + inline bool load_buildings_file(ModifierManager const& modifier_manager, ast::NodeCPtr root) { + return building_manager.load_buildings_file(good_manager, production_type_manager, modifier_manager, root); + } + }; +} diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index b2d94c3..01d45be 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -138,7 +138,7 @@ node_callback_t ProductionTypeManager::_expect_employed_pop_list(GoodManager con return false; \ } -bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS, GoodManager& good_manager) { +bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS, GoodManager const& good_manager) { if (identifier.empty()) { Logger::error("Invalid production type identifier - empty!"); return false; @@ -186,7 +186,7 @@ bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS, GoodManage "mine", ZERO_OR_ONE, expect_bool(assign_variable_callback(mine)) \ ) -bool ProductionTypeManager::load_production_types_file(GoodManager& good_manager, PopManager& pop_manager, ast::NodeCPtr root) { +bool ProductionTypeManager::load_production_types_file(GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root) { size_t expected_types = 0; // pass 1: find and store template identifiers diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp index fdb0010..420e70e 100644 --- a/src/openvic-simulation/economy/ProductionType.hpp +++ b/src/openvic-simulation/economy/ProductionType.hpp @@ -103,9 +103,9 @@ namespace OpenVic { public: ProductionTypeManager(); - bool add_production_type(PRODUCTION_TYPE_ARGS, GoodManager& good_manager); + bool add_production_type(PRODUCTION_TYPE_ARGS, GoodManager const& good_manager); IDENTIFIER_REGISTRY_ACCESSORS(production_type) - bool load_production_types_file(GoodManager& good_manager, PopManager& pop_manager, ast::NodeCPtr root); + bool load_production_types_file(GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root); }; }
\ No newline at end of file diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 8362ff4..acd882e 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -276,7 +276,7 @@ Pop::pop_size_t Map::get_total_map_population() const { return total_map_population; } -bool Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager) { +bool Map::setup(BuildingManager const& building_manager, PopManager const& pop_manager) { bool ret = true; for (Province& province : provinces.get_items()) { province.clear_pops(); diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp index a959158..578b471 100644 --- a/src/openvic-simulation/map/Map.hpp +++ b/src/openvic-simulation/map/Map.hpp @@ -102,7 +102,7 @@ namespace OpenVic { static constexpr size_t MAPMODE_COLOUR_SIZE = 4; bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const; - bool setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager); + bool setup(BuildingManager const& building_manager, PopManager const& pop_manager); void update_highest_province_population(); Pop::pop_size_t get_highest_province_population() const; diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index c9b29ea..d925898 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -2,7 +2,7 @@ #include <cassert> -#include "openvic-simulation/map/Building.hpp" +#include "openvic-simulation/economy/Building.hpp" #include "openvic-simulation/pop/Pop.hpp" namespace OpenVic { @@ -55,7 +55,6 @@ namespace OpenVic { fvec2_t navalbase; fixed_point_t navalbase_rotation; }; - static constexpr index_t NULL_INDEX = 0, MAX_INDEX = std::numeric_limits<index_t>::max(); diff --git a/src/openvic-simulation/military/MilitaryManager.hpp b/src/openvic-simulation/military/MilitaryManager.hpp new file mode 100644 index 0000000..36b5010 --- /dev/null +++ b/src/openvic-simulation/military/MilitaryManager.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "openvic-simulation/military/Unit.hpp" + +namespace OpenVic { + struct MilitaryManager { + private: + UnitManager unit_manager; + public: + REF_GETTERS(unit_manager) + }; +} diff --git a/src/openvic-simulation/units/Unit.cpp b/src/openvic-simulation/military/Unit.cpp index 3da24da..3da24da 100644 --- a/src/openvic-simulation/units/Unit.cpp +++ b/src/openvic-simulation/military/Unit.cpp diff --git a/src/openvic-simulation/units/Unit.hpp b/src/openvic-simulation/military/Unit.hpp index 65e6259..65e6259 100644 --- a/src/openvic-simulation/units/Unit.hpp +++ b/src/openvic-simulation/military/Unit.hpp diff --git a/src/openvic-simulation/politics/Government.hpp b/src/openvic-simulation/politics/Government.hpp index 3bc754c..c72dae6 100644 --- a/src/openvic-simulation/politics/Government.hpp +++ b/src/openvic-simulation/politics/Government.hpp @@ -39,4 +39,4 @@ namespace OpenVic { bool load_government_types_file(IdeologyManager const& ideology_manager, ast::NodeCPtr root); }; -} // namespace OpenVic +} // namespace OpenVic diff --git a/src/openvic-simulation/politics/PoliticsManager.hpp b/src/openvic-simulation/politics/PoliticsManager.hpp new file mode 100644 index 0000000..9072d72 --- /dev/null +++ b/src/openvic-simulation/politics/PoliticsManager.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "openvic-simulation/politics/Government.hpp" +#include "openvic-simulation/politics/Ideology.hpp" +#include "openvic-simulation/politics/Issue.hpp" + +namespace OpenVic { + struct PoliticsManager { + private: + GovernmentTypeManager government_type_manager; + IdeologyManager ideology_manager; + IssueManager issue_manager; + public: + REF_GETTERS(government_type_manager) + REF_GETTERS(ideology_manager) + REF_GETTERS(issue_manager) + + inline bool load_government_types_file(ast::NodeCPtr root) { + return government_type_manager.load_government_types_file(ideology_manager, root); + } + }; +} diff --git a/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp b/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp index c74c5e9..d1a857f 100644 --- a/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp +++ b/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp @@ -505,7 +505,7 @@ namespace OpenVic { void check_base_price(std::string identifier, std::string target_value, std::string req_name) { // Get string of base_price from goods manager - fixed_point_t base_price_fp = get_game_manager()->get_good_manager().get_good_by_identifier(identifier)->get_base_price(); + fixed_point_t base_price_fp = get_game_manager()->get_economy_manager().get_good_manager().get_good_by_identifier(identifier)->get_base_price(); std::stringstream ss; ss << std::fixed << std::setprecision(1) << base_price_fp.to_double(); // Use a single digit floating point of the value std::string base_price = ss.str(); diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index 4e13813..aea5728 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -6,6 +6,10 @@ #include "openvic-simulation/dataloader/NodeTools.hpp" #include "openvic-simulation/utility/Logger.hpp" +#define REF_GETTERS(var) \ + constexpr decltype(var)& get_##var() { return var; } \ + constexpr decltype(var) const& get_##var() const { return var; } + namespace OpenVic { /* * Base class for objects with a non-empty string identifier, @@ -179,13 +183,7 @@ namespace OpenVic { return get_item_by_index(index) != nullptr; } - std::vector<storage_type>& get_items() { - return items; - } - - std::vector<storage_type> const& get_items() const { - return items; - } + REF_GETTERS(items) std::vector<std::string_view> get_item_identifiers() const { std::vector<std::string_view> identifiers; |