diff options
author | hop311 <hop3114@gmail.com> | 2023-11-14 22:47:35 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2023-11-16 20:38:34 +0100 |
commit | 886b8b8f396438fc2b7da7d2508f2064d14150a8 (patch) | |
tree | eeed419a7d97ecb58adf63a17eb9184db3e5ed7a /src | |
parent | 8271b1519e095ee3e7245cde2f0b54561c3ec619 (diff) |
Misc changes
Diffstat (limited to 'src')
34 files changed, 338 insertions, 314 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp index ed450de..397b729 100644 --- a/src/openvic-simulation/GameManager.cpp +++ b/src/openvic-simulation/GameManager.cpp @@ -170,12 +170,12 @@ bool GameManager::load_hardcoded_defines() { BuildingInstance const* railroad = province.get_building_by_identifier("railroad"); if (railroad != nullptr) { colour_t val = fraction_to_colour_byte(railroad->get_level(), - railroad->get_building().get_max_level() + 1, 0.5f, 1.0f); + railroad->get_building_type().get_max_level() + 1, 0.5f, 1.0f); switch (railroad->get_expansion_state()) { - case ExpansionState::CannotExpand: + case BuildingInstance::ExpansionState::CannotExpand: val <<= 16; break; - case ExpansionState::CanExpand: + case BuildingInstance::ExpansionState::CanExpand: break; default: val <<= 8; diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp index 3ac9de3..cd86716 100644 --- a/src/openvic-simulation/GameManager.hpp +++ b/src/openvic-simulation/GameManager.hpp @@ -1,7 +1,7 @@ #pragma once #include "openvic-simulation/GameAdvancementHook.hpp" -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/country/Country.hpp" #include "openvic-simulation/economy/EconomyManager.hpp" #include "openvic-simulation/history/HistoryManager.hpp" diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index 1675543..d4f9be7 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -3,77 +3,77 @@ using namespace OpenVic; bool CountryInstance::add_accepted_culture(Culture const* new_accepted_culture) { - if(std::find(accepted_cultures.begin(), accepted_cultures.end(), new_accepted_culture) != accepted_cultures.end()) { - Logger::warning("Attempted to add accepted culture ", new_accepted_culture->get_identifier(), " to country ", base_country->get_identifier(), ": already present!"); - return false; - } - accepted_cultures.push_back(new_accepted_culture); - return true; + if(std::find(accepted_cultures.begin(), accepted_cultures.end(), new_accepted_culture) != accepted_cultures.end()) { + Logger::warning("Attempted to add accepted culture ", new_accepted_culture->get_identifier(), " to country ", base_country->get_identifier(), ": already present!"); + return false; + } + accepted_cultures.push_back(new_accepted_culture); + return true; } bool CountryInstance::remove_accepted_culture(Culture const* culture_to_remove) { - auto existing_entry = std::find(accepted_cultures.begin(), accepted_cultures.end(), culture_to_remove); - if (existing_entry == accepted_cultures.end()) { - Logger::warning("Attempted to remove accepted culture ", culture_to_remove->get_identifier(), " from country ", base_country->get_identifier(), ": not present!"); - return false; - } - accepted_cultures.erase(existing_entry); - return true; + auto existing_entry = std::find(accepted_cultures.begin(), accepted_cultures.end(), culture_to_remove); + if (existing_entry == accepted_cultures.end()) { + Logger::warning("Attempted to remove accepted culture ", culture_to_remove->get_identifier(), " from country ", base_country->get_identifier(), ": not present!"); + return false; + } + accepted_cultures.erase(existing_entry); + return true; } void CountryInstance::add_to_upper_house(Ideology const* party, fixed_point_t popularity) { - upper_house[party] = popularity; + upper_house[party] = popularity; } bool CountryInstance::remove_from_upper_house(Ideology const* party) { - return upper_house.erase(party) == 1; + return upper_house.erase(party) == 1; } bool CountryInstance::add_reform(Reform const* new_reform) { - if (std::find(reforms.begin(), reforms.end(), new_reform) != reforms.end()) { - Logger::warning("Attempted to add reform ", new_reform->get_identifier(), " to country ", base_country->get_identifier(), ": already present!"); - return false; - } - reforms.push_back(new_reform); - return true; + if (std::find(reforms.begin(), reforms.end(), new_reform) != reforms.end()) { + Logger::warning("Attempted to add reform ", new_reform->get_identifier(), " to country ", base_country->get_identifier(), ": already present!"); + return false; + } + reforms.push_back(new_reform); + return true; } bool CountryInstance::remove_reform(Reform const* reform_to_remove) { - auto existing_entry = std::find(reforms.begin(), reforms.end(), reform_to_remove); - if (existing_entry == reforms.end()) { - Logger::warning("Attempted to remove reform ", reform_to_remove->get_identifier(), " from country ", base_country->get_identifier(), ": not present!"); - return false; - } - reforms.erase(existing_entry); - return true; + auto existing_entry = std::find(reforms.begin(), reforms.end(), reform_to_remove); + if (existing_entry == reforms.end()) { + Logger::warning("Attempted to remove reform ", reform_to_remove->get_identifier(), " from country ", base_country->get_identifier(), ": not present!"); + return false; + } + reforms.erase(existing_entry); + return true; } -void CountryInstance::apply_history_to_country(CountryHistoryMap const& history, Date date) { - auto entries = history.get_entries_up_to(date); +bool CountryInstance::apply_history_to_country(CountryHistoryMap const& history, Date date) { + accepted_cultures.clear(); + upper_house.clear(); + reforms.clear(); - accepted_cultures.clear(); - upper_house.clear(); - reforms.clear(); - - for (CountryHistoryEntry const* entry : entries) { - if (entry->get_primary_culture()) primary_culture = *entry->get_primary_culture(); - for (const auto culture : entry->get_accepted_cultures()) { - add_accepted_culture(culture); - } - if (entry->get_religion()) religion = *entry->get_religion(); - if (entry->get_ruling_party()) ruling_party = *entry->get_ruling_party(); - if (entry->get_last_election()) last_election = *entry->get_last_election(); - for (const auto& party : entry->get_upper_house()) { - add_to_upper_house(party.first, party.second); - } - if (entry->get_capital()) capital = *entry->get_capital(); - if (entry->get_government_type()) government_type = *entry->get_government_type(); - if (entry->get_plurality()) plurality = *entry->get_plurality(); - if (entry->get_national_value()) national_value = *entry->get_national_value(); - if (entry->get_civilised()) civilised = *entry->get_civilised(); - if (entry->get_prestige()) prestige = *entry->get_prestige(); - for (const auto reform : entry->get_reforms()) { - add_reform(reform); - } - } -}
\ No newline at end of file + bool ret = true; + for (CountryHistoryEntry const* entry : history.get_entries_up_to(date)) { + if (entry->get_primary_culture()) primary_culture = *entry->get_primary_culture(); + for (Culture const* culture : entry->get_accepted_cultures()) { + ret &= add_accepted_culture(culture); + } + if (entry->get_religion()) religion = *entry->get_religion(); + if (entry->get_ruling_party()) ruling_party = *entry->get_ruling_party(); + if (entry->get_last_election()) last_election = *entry->get_last_election(); + for (auto const& [ideology, popularity] : entry->get_upper_house()) { + add_to_upper_house(ideology, popularity); + } + if (entry->get_capital()) capital = *entry->get_capital(); + if (entry->get_government_type()) government_type = *entry->get_government_type(); + if (entry->get_plurality()) plurality = *entry->get_plurality(); + if (entry->get_national_value()) national_value = *entry->get_national_value(); + if (entry->get_civilised()) civilised = *entry->get_civilised(); + if (entry->get_prestige()) prestige = *entry->get_prestige(); + for (Reform const* reform : entry->get_reforms()) { + ret &= add_reform(reform); + } + } + return ret; +} diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp index 99461b5..98c6e90 100644 --- a/src/openvic-simulation/country/CountryInstance.hpp +++ b/src/openvic-simulation/country/CountryInstance.hpp @@ -6,34 +6,34 @@ #include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { - /* Representation of an existing country that is currently in-game. */ - struct CountryInstance { - private: - Country const* PROPERTY_RW(base_country); - Culture const* PROPERTY_RW(primary_culture); - std::vector<Culture const*> PROPERTY(accepted_cultures); - Religion const* PROPERTY_RW(religion); - CountryParty const* PROPERTY_RW(ruling_party); - Date PROPERTY_RW(last_election); - fixed_point_map_t<Ideology const*> PROPERTY(upper_house); - Province const* PROPERTY_RW(capital); - GovernmentType const* PROPERTY_RW(government_type); - fixed_point_t PROPERTY_RW(plurality); - NationalValue const* PROPERTY_RW(national_value); - bool PROPERTY_RW(civilised); - fixed_point_t PROPERTY_RW(prestige); - std::vector<Reform const*> PROPERTY(reforms); // TODO: should be map of reform groups to active reforms: must set defaults & validate applied history - // TODO: Military units + OOBs; will probably need an extensible deployment class + /* Representation of an existing country that is currently in-game. */ + struct CountryInstance { + private: + Country const* PROPERTY_RW(base_country); + Culture const* PROPERTY_RW(primary_culture); + std::vector<Culture const*> PROPERTY(accepted_cultures); + Religion const* PROPERTY_RW(religion); + CountryParty const* PROPERTY_RW(ruling_party); + Date PROPERTY_RW(last_election); + fixed_point_map_t<Ideology const*> PROPERTY(upper_house); + Province const* PROPERTY_RW(capital); + GovernmentType const* PROPERTY_RW(government_type); + fixed_point_t PROPERTY_RW(plurality); + NationalValue const* PROPERTY_RW(national_value); + bool PROPERTY_RW(civilised); + fixed_point_t PROPERTY_RW(prestige); + std::vector<Reform const*> PROPERTY(reforms); // TODO: should be map of reform groups to active reforms: must set defaults & validate applied history + // TODO: Military units + OOBs; will probably need an extensible deployment class - public: - bool add_accepted_culture(Culture const* new_accepted_culture); - bool remove_accepted_culture(Culture const* culture_to_remove); - /* Add or modify a party in the upper house. */ - void add_to_upper_house(Ideology const* party, fixed_point_t popularity); - bool remove_from_upper_house(Ideology const* party); - bool add_reform(Reform const* new_reform); - bool remove_reform(Reform const* reform_to_remove); + public: + bool add_accepted_culture(Culture const* new_accepted_culture); + bool remove_accepted_culture(Culture const* culture_to_remove); + /* Add or modify a party in the upper house. */ + void add_to_upper_house(Ideology const* party, fixed_point_t popularity); + bool remove_from_upper_house(Ideology const* party); + bool add_reform(Reform const* new_reform); + bool remove_reform(Reform const* reform_to_remove); - void apply_history_to_country(CountryHistoryMap const& history, Date date); - }; + bool apply_history_to_country(CountryHistoryMap const& history, Date date); + }; } // namespace OpenVic diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index f55ffaf..f86fab6 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -849,6 +849,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const { static const std::string religion_file = "common/religion.txt"; static const std::string leader_traits_file = "common/traits.txt"; static const std::string cb_types_file = "common/cb_types.txt"; + static const std::string crime_modifiers_file = "common/crime.txt"; + static const std::string event_modifiers_file = "common/event_modifiers.txt"; + static const std::string static_modifiers_file = "common/static_modifiers.txt"; + static const std::string triggered_modifiers_file = "common/triggered_modifiers.txt"; bool ret = true; @@ -860,6 +864,30 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to set up modifier effects!"); ret = false; } + if (!game_manager.get_modifier_manager().load_crime_modifiers( + parse_defines(lookup_file(crime_modifiers_file)).get_file_node() + )) { + Logger::error("Failed to load crime modifiers!"); + ret = false; + } + if (!game_manager.get_modifier_manager().load_event_modifiers( + parse_defines(lookup_file(event_modifiers_file)).get_file_node() + )) { + Logger::error("Failed to load event modifiers!"); + ret = false; + } + if (!game_manager.get_modifier_manager().load_static_modifiers( + parse_defines(lookup_file(static_modifiers_file)).get_file_node() + )) { + Logger::error("Failed to load static modifiers!"); + ret = false; + } + if (!game_manager.get_modifier_manager().load_triggered_modifiers( + parse_defines(lookup_file(triggered_modifiers_file)).get_file_node() + )) { + Logger::error("Failed to load triggered modifiers!"); + ret = false; + } if (!game_manager.get_define_manager().load_defines_file(parse_lua_defines(lookup_file(defines_file)).get_file_node())) { Logger::error("Failed to load defines!"); ret = false; diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index c412f33..19f5dd7 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -206,7 +206,11 @@ node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) { node_callback_t NodeTools::expect_assign(key_value_callback_t callback) { return _expect_type<ast::AssignNode>([callback](ast::AssignNode const& assign_node) -> bool { - return callback(assign_node._name, assign_node._initializer.get()); + const bool ret = callback(assign_node._name, assign_node._initializer.get()); + if (!ret) { + Logger::error("Callback failed for assign node with key: ", assign_node._name); + } + return ret; }); } diff --git a/src/openvic-simulation/economy/BuildingInstance.cpp b/src/openvic-simulation/economy/BuildingInstance.cpp new file mode 100644 index 0000000..417cdda --- /dev/null +++ b/src/openvic-simulation/economy/BuildingInstance.cpp @@ -0,0 +1,52 @@ +#include "BuildingInstance.hpp" + +using namespace OpenVic; + +BuildingInstance::BuildingInstance(BuildingType const& new_building_type, level_t new_level) + : HasIdentifier { building_type.get_identifier() }, building_type { new_building_type }, level { new_level }, + expansion_state { ExpansionState::CannotExpand } {} + +bool BuildingInstance::_can_expand() const { + return level < building_type.get_max_level(); +} + +void BuildingInstance::set_level(BuildingInstance::level_t new_level) { + level = new_level; +} + +bool BuildingInstance::expand() { + if (expansion_state == ExpansionState::CanExpand) { + expansion_state = ExpansionState::Preparing; + expansion_progress = 0.0f; + return true; + } + return false; +} + +/* REQUIREMENTS: + * MAP-71, MAP-74, MAP-77 + */ +void BuildingInstance::update_state(Date today) { + switch (expansion_state) { + case ExpansionState::Preparing: + start_date = today; + end_date = start_date + building_type.get_build_time(); + break; + case ExpansionState::Expanding: + expansion_progress = static_cast<double>(today - start_date) / static_cast<double>(end_date - start_date); + break; + default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand; + } +} + +void BuildingInstance::tick(Date today) { + if (expansion_state == ExpansionState::Preparing) { + expansion_state = ExpansionState::Expanding; + } + if (expansion_state == ExpansionState::Expanding) { + if (end_date <= today) { + level++; + expansion_state = ExpansionState::CannotExpand; + } + } +} diff --git a/src/openvic-simulation/economy/BuildingInstance.hpp b/src/openvic-simulation/economy/BuildingInstance.hpp new file mode 100644 index 0000000..9fc9df1 --- /dev/null +++ b/src/openvic-simulation/economy/BuildingInstance.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "openvic-simulation/economy/BuildingType.hpp" + +namespace OpenVic { + + struct BuildingInstance : HasIdentifier { // used in the actual game + using level_t = BuildingType::level_t; + + enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding }; + + private: + BuildingType const& PROPERTY(building_type); + + level_t PROPERTY(level); + ExpansionState PROPERTY(expansion_state); + Date PROPERTY(start_date) + Date PROPERTY(end_date); + float PROPERTY(expansion_progress); + + bool _can_expand() const; + + public: + BuildingInstance(BuildingType const& new_building_type, level_t new_level = 0); + BuildingInstance(BuildingInstance&&) = default; + + void set_level(level_t new_level); + + bool expand(); + void update_state(Date today); + void tick(Date today); + }; +} diff --git a/src/openvic-simulation/economy/Building.cpp b/src/openvic-simulation/economy/BuildingType.cpp index c5707ea..b80999a 100644 --- a/src/openvic-simulation/economy/Building.cpp +++ b/src/openvic-simulation/economy/BuildingType.cpp @@ -1,12 +1,10 @@ -#include "Building.hpp" +#include "BuildingType.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; -BuildingType::BuildingType(std::string_view new_identifier) : HasIdentifier { new_identifier } {} - -Building::Building( - std::string_view identifier, BuildingType const& type, ARGS +BuildingType::BuildingType( + std::string_view identifier, ARGS ) : HasIdentifier { identifier }, type { type }, modifier { std::move(modifier) }, on_completion { on_completion }, completion_size { completion_size }, max_level { max_level }, goods_cost { std::move(goods_cost) }, cost { cost }, build_time { build_time }, visibility { visibility }, on_map { on_map }, default_enabled { default_enabled }, @@ -16,81 +14,16 @@ Building::Building( colonial_range { colonial_range }, infrastructure { infrastructure }, spawn_railway_track { spawn_railway_track }, sail { sail }, steam { steam }, capital { capital }, port { port } {} -BuildingInstance::BuildingInstance(Building const& new_building, level_t new_level) - : HasIdentifier { building.get_identifier() }, building { new_building }, level { new_level }, - expansion_state { ExpansionState::CannotExpand } {} - -bool BuildingInstance::_can_expand() const { - return level < building.get_max_level(); -} - -void BuildingInstance::set_level(BuildingInstance::level_t new_level) { - level = new_level; -} - -bool BuildingInstance::expand() { - if (expansion_state == ExpansionState::CanExpand) { - expansion_state = ExpansionState::Preparing; - expansion_progress = 0.0f; - return true; - } - return false; -} +BuildingManager::BuildingManager() : building_types { "building types" } {} -/* REQUIREMENTS: - * MAP-71, MAP-74, MAP-77 - */ -void BuildingInstance::update_state(Date today) { - switch (expansion_state) { - case ExpansionState::Preparing: - start_date = today; - end_date = start_date + building.get_build_time(); - break; - case ExpansionState::Expanding: - expansion_progress = static_cast<double>(today - start_date) / static_cast<double>(end_date - start_date); - break; - default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand; - } -} - -void BuildingInstance::tick(Date today) { - if (expansion_state == ExpansionState::Preparing) { - expansion_state = ExpansionState::Expanding; - } - if (expansion_state == ExpansionState::Expanding) { - if (end_date <= today) { - level++; - expansion_state = ExpansionState::CannotExpand; - } - } -} - -BuildingManager::BuildingManager() : building_types { "building types" }, buildings { "buildings" } {} - -bool BuildingManager::add_building_type(std::string_view identifier) { - if (identifier.empty()) { - Logger::error("Invalid building type identifier - empty!"); - return false; - } - return building_types.add_item({ identifier }, duplicate_ignore_callback); -} - -bool BuildingManager::add_building(std::string_view identifier, BuildingType const* type, ARGS) { - if (!building_types.is_locked()) { - Logger::error("Cannot add buildings until building types are locked!"); - return false; - } +bool BuildingManager::add_building_type(std::string_view identifier, ARGS) { if (identifier.empty()) { Logger::error("Invalid building identifier - empty!"); return false; } - if (type == nullptr) { - Logger::error("Invalid building type for ", identifier, ": null"); - return false; - } - return buildings.add_item({ - identifier, *type, std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), + return building_types.add_item({ + identifier, type, std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), cost, build_time, visibility, on_map, default_enabled, production_type, pop_build_factory, strategic_factory, advanced_factory, fort_level, naval_capacity, std::move(colonial_points), in_province, one_per_state, colonial_range, infrastructure, spawn_railway_track, sail, steam, capital, port @@ -101,20 +34,14 @@ bool BuildingManager::load_buildings_file( GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager& modifier_manager, ast::NodeCPtr root ) { - bool ret = expect_dictionary_reserve_length(buildings, [this](std::string_view, ast::NodeCPtr value) -> bool { - return expect_key("type", expect_identifier( - std::bind(&BuildingManager::add_building_type, this, std::placeholders::_1) - ))(value); - })(root); - lock_building_types(); - - ret &= expect_dictionary( + const bool ret = expect_dictionary_reserve_length( + building_types, [this, &good_manager, &production_type_manager, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { - BuildingType const* type = nullptr; + std::string_view type; ProductionType const* production_type = nullptr; std::string_view on_completion; fixed_point_t completion_size = 0, cost = 0, infrastructure = 0, colonial_range = 0; - Building::level_t max_level = 0, fort_level = 0; + BuildingType::level_t max_level = 0, fort_level = 0; Good::good_map_t goods_cost; Timespan build_time; bool visibility = false, on_map = false, default_enabled = false, pop_build_factory = false; @@ -126,7 +53,7 @@ bool BuildingManager::load_buildings_file( ModifierValue modifier; bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifier), - "type", ONE_EXACTLY, expect_building_type_identifier(assign_variable_callback_pointer(type)), + "type", ONE_EXACTLY, expect_identifier(assign_variable_callback(type)), "on_completion", ZERO_OR_ONE, expect_identifier(assign_variable_callback(on_completion)), "completion_size", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(completion_size)), "max_level", ONE_EXACTLY, expect_uint(assign_variable_callback(max_level)), @@ -160,7 +87,7 @@ bool BuildingManager::load_buildings_file( "port", ZERO_OR_ONE, expect_bool(assign_variable_callback(port)) )(value); - ret &= add_building( + ret &= add_building_type( key, type, std::move(modifier), on_completion, completion_size, max_level, std::move(goods_cost), cost, build_time, visibility, on_map, default_enabled, production_type, pop_build_factory, strategic_factory, advanced_factory, fort_level, naval_capacity, std::move(colonial_points), in_province, one_per_state, @@ -170,16 +97,16 @@ bool BuildingManager::load_buildings_file( return ret; } )(root); - lock_buildings(); + lock_building_types(); - for (Building const& building : buildings.get_items()) { + for (BuildingType const& building_type : building_types.get_items()) { std::string max_modifier_prefix = "max_"; std::string min_modifier_prefix = "min_build_"; modifier_manager.add_modifier_effect( - max_modifier_prefix.append(building.get_identifier()), true, ModifierEffect::format_t::INT + max_modifier_prefix.append(building_type.get_identifier()), true, ModifierEffect::format_t::INT ); modifier_manager.add_modifier_effect( - min_modifier_prefix.append(building.get_identifier()), false, ModifierEffect::format_t::INT + min_modifier_prefix.append(building_type.get_identifier()), false, ModifierEffect::format_t::INT ); } diff --git a/src/openvic-simulation/economy/Building.hpp b/src/openvic-simulation/economy/BuildingType.hpp index ed1190b..a49c461 100644 --- a/src/openvic-simulation/economy/Building.hpp +++ b/src/openvic-simulation/economy/BuildingType.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/economy/Good.hpp" #include "openvic-simulation/economy/ProductionType.hpp" #include "openvic-simulation/types/Date.hpp" @@ -8,8 +8,8 @@ #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" #define ARGS \ - ModifierValue&& modifier, std::string_view on_completion, fixed_point_t completion_size, level_t max_level, \ - Good::good_map_t&& goods_cost, fixed_point_t cost, Timespan build_time, bool visibility, bool on_map, \ + std::string_view type, ModifierValue&& modifier, std::string_view on_completion, fixed_point_t completion_size, \ + level_t max_level, Good::good_map_t&& goods_cost, fixed_point_t cost, Timespan build_time, bool visibility, bool on_map, \ bool default_enabled, ProductionType const* production_type, bool pop_build_factory, bool strategic_factory, \ bool advanced_factory, level_t fort_level, uint64_t naval_capacity, std::vector<fixed_point_t>&& colonial_points, \ bool in_province, bool one_per_state, fixed_point_t colonial_range, fixed_point_t infrastructure, \ @@ -19,28 +19,18 @@ namespace OpenVic { struct BuildingManager; - struct BuildingType : HasIdentifier { - friend struct BuildingManager; - - private: - BuildingType(std::string_view new_identifier); - - public: - BuildingType(BuildingType&&) = default; - }; - /* REQUIREMENTS: * MAP-11, MAP-72, MAP-73 * MAP-12, MAP-75, MAP-76 * MAP-13, MAP-78, MAP-79 */ - struct Building : HasIdentifier { + struct BuildingType : HasIdentifier { friend struct BuildingManager; using level_t = int16_t; private: - BuildingType const& PROPERTY(type); + std::string PROPERTY(type); ModifierValue PROPERTY(modifier); std::string PROPERTY(on_completion); // probably sound played on completion fixed_point_t PROPERTY(completion_size); @@ -73,56 +63,24 @@ namespace OpenVic { bool PROPERTY(capital); // only in naval base bool PROPERTY(port); // only in naval base - Building(std::string_view identifier, BuildingType const& type, ARGS); - - public: - Building(Building&&) = default; - }; - - enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding }; - - struct BuildingInstance : HasIdentifier { // used in the actual game - friend struct BuildingManager; - using level_t = Building::level_t; - - private: - Building const& PROPERTY(building); - - level_t PROPERTY(level); - ExpansionState PROPERTY(expansion_state); - Date PROPERTY(start_date) - Date PROPERTY(end_date); - float PROPERTY(expansion_progress); - - bool _can_expand() const; + BuildingType(std::string_view identifier, ARGS); public: - BuildingInstance(Building const& new_building, level_t new_level = 0); - BuildingInstance(BuildingInstance&&) = default; - - void set_level(level_t new_level); - - bool expand(); - void update_state(Date today); - void tick(Date today); + BuildingType(BuildingType&&) = default; }; struct BuildingManager { - using level_t = Building::level_t; // this is getting ridiculous + using level_t = BuildingType::level_t; // this is getting ridiculous private: IdentifierRegistry<BuildingType> building_types; - IdentifierRegistry<Building> buildings; public: BuildingManager(); - bool add_building_type(std::string_view identifier); + bool add_building_type(std::string_view identifier, ARGS); IDENTIFIER_REGISTRY_ACCESSORS(building_type) - bool add_building(std::string_view identifier, BuildingType const* type, ARGS); - IDENTIFIER_REGISTRY_ACCESSORS(building) - bool load_buildings_file( GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager& modifier_manager, ast::NodeCPtr root diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp index 7445614..d53aa7e 100644 --- a/src/openvic-simulation/economy/EconomyManager.hpp +++ b/src/openvic-simulation/economy/EconomyManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/economy/Building.hpp" +#include "openvic-simulation/economy/BuildingType.hpp" #include "openvic-simulation/economy/Good.hpp" #include "openvic-simulation/economy/ProductionType.hpp" diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp index 2b1d694..4c1f7ba 100644 --- a/src/openvic-simulation/economy/Good.cpp +++ b/src/openvic-simulation/economy/Good.cpp @@ -64,7 +64,7 @@ bool GoodManager::add_good_category(std::string_view identifier) { } bool GoodManager::add_good( - std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price, + std::string_view identifier, colour_t colour, GoodCategory const& category, Good::price_t base_price, bool available_from_start, bool tradeable, bool money, bool overseas_penalty ) { if (identifier.empty()) { @@ -75,16 +75,12 @@ bool GoodManager::add_good( Logger::error("Invalid good colour for ", identifier, ": ", colour_to_hex_string(colour)); return false; } - if (category == nullptr) { - Logger::error("Invalid good category for ", identifier, ": null"); - return false; - } if (base_price <= Good::NULL_PRICE) { Logger::error("Invalid base price for ", identifier, ": ", base_price); return false; } return goods.add_item({ - identifier, colour, *category, base_price, available_from_start, + identifier, colour, category, base_price, available_from_start, tradeable, money, overseas_penalty }); } @@ -107,10 +103,8 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) { )(root); lock_good_categories(); goods.reserve(goods.size() + total_expected_goods); - ret &= expect_dictionary([this](std::string_view good_category_key, ast::NodeCPtr good_category_value) -> bool { - GoodCategory const* good_category = get_good_category_by_identifier(good_category_key); - - return expect_dictionary([this, good_category](std::string_view key, ast::NodeCPtr value) -> bool { + ret &= expect_good_category_dictionary([this](GoodCategory const& good_category, ast::NodeCPtr good_category_value) -> bool { + return expect_dictionary([this, &good_category](std::string_view key, ast::NodeCPtr value) -> bool { colour_t colour = NULL_COLOUR; Good::price_t base_price; bool available_from_start = true, tradeable = true; diff --git a/src/openvic-simulation/economy/Good.hpp b/src/openvic-simulation/economy/Good.hpp index bec5cca..805e6a5 100644 --- a/src/openvic-simulation/economy/Good.hpp +++ b/src/openvic-simulation/economy/Good.hpp @@ -73,7 +73,7 @@ namespace OpenVic { IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(good_category, good_categories) bool add_good( - std::string_view identifier, colour_t colour, GoodCategory const* category, Good::price_t base_price, + std::string_view identifier, colour_t colour, GoodCategory const& category, Good::price_t base_price, bool available_from_start, bool tradeable, bool money, bool overseas_penalty ); IDENTIFIER_REGISTRY_ACCESSORS(good) diff --git a/src/openvic-simulation/economy/ProductionType.cpp b/src/openvic-simulation/economy/ProductionType.cpp index 1c65c4d..6eb7ff9 100644 --- a/src/openvic-simulation/economy/ProductionType.cpp +++ b/src/openvic-simulation/economy/ProductionType.cpp @@ -145,7 +145,7 @@ node_callback_t ProductionTypeManager::_expect_employed_pop_list( return false; \ } -bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS, GoodManager const& good_manager) { +bool ProductionTypeManager::add_production_type(PRODUCTION_TYPE_ARGS) { if (identifier.empty()) { Logger::error("Invalid production type identifier - empty!"); return false; @@ -274,7 +274,7 @@ bool ProductionTypeManager::load_production_types_file( ret &= add_production_type( key, owner, employees, type, workforce, std::move(input_goods), output_goods, value, std::move(bonuses), - std::move(efficiency), coastal, farm, mine, good_manager + std::move(efficiency), coastal, farm, mine ); return ret; } diff --git a/src/openvic-simulation/economy/ProductionType.hpp b/src/openvic-simulation/economy/ProductionType.hpp index 802580b..13862a7 100644 --- a/src/openvic-simulation/economy/ProductionType.hpp +++ b/src/openvic-simulation/economy/ProductionType.hpp @@ -101,7 +101,7 @@ namespace OpenVic { public: ProductionTypeManager(); - bool add_production_type(PRODUCTION_TYPE_ARGS, GoodManager const& good_manager); + bool add_production_type(PRODUCTION_TYPE_ARGS); IDENTIFIER_REGISTRY_ACCESSORS(production_type) bool load_production_types_file(GoodManager const& good_manager, PopManager const& pop_manager, ast::NodeCPtr root); diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp index 379c7d1..991dfee 100644 --- a/src/openvic-simulation/history/ProvinceHistory.cpp +++ b/src/openvic-simulation/history/ProvinceHistory.cpp @@ -33,10 +33,10 @@ bool ProvinceHistoryMap::_load_history_entry( [this, &game_manager, &building_manager, &entry]( std::string_view key, ast::NodeCPtr value) -> bool { // used for province buildings like forts or railroads - Building const* building = building_manager.get_building_by_identifier(key); - if (building != nullptr) { - return expect_uint<Building::level_t>([&entry, building](Building::level_t level) -> bool { - entry.province_buildings[building] = level; + BuildingType const* building_type = building_manager.get_building_type_by_identifier(key); + if (building_type != nullptr) { + return expect_uint<BuildingType::level_t>([&entry, building_type](BuildingType::level_t level) -> bool { + entry.province_buildings[building_type] = level; return true; })(value); } @@ -83,17 +83,17 @@ bool ProvinceHistoryMap::_load_history_entry( return ret; }, "state_building", ZERO_OR_MORE, [&building_manager, &entry](ast::NodeCPtr node) -> bool { - Building const* building = nullptr; + BuildingType const* building_type = nullptr; uint8_t level = 0; const bool ret = expect_dictionary_keys( "level", ONE_EXACTLY, expect_uint(assign_variable_callback(level)), - "building", ONE_EXACTLY, building_manager.expect_building_identifier( - assign_variable_callback_pointer(building) + "building", ONE_EXACTLY, building_manager.expect_building_type_identifier( + assign_variable_callback_pointer(building_type) ), "upgrade", ZERO_OR_ONE, success_callback // doesn't appear to have an effect )(node); - entry.state_buildings[building] = level; + entry.state_buildings[building_type] = level; return ret; } )(root); diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp index d0136bb..e4adc08 100644 --- a/src/openvic-simulation/history/ProvinceHistory.hpp +++ b/src/openvic-simulation/history/ProvinceHistory.hpp @@ -5,7 +5,7 @@ #include <vector> #include "openvic-simulation/country/Country.hpp" -#include "openvic-simulation/economy/Building.hpp" +#include "openvic-simulation/economy/BuildingType.hpp" #include "openvic-simulation/economy/Good.hpp" #include "openvic-simulation/history/Bookmark.hpp" #include "openvic-simulation/history/HistoryMap.hpp" @@ -30,8 +30,8 @@ namespace OpenVic { std::optional<Good const*> PROPERTY(rgo); std::optional<Province::life_rating_t> PROPERTY(life_rating); std::optional<TerrainType const*> PROPERTY(terrain_type); - std::map<Building const*, Building::level_t> PROPERTY(province_buildings); - std::map<Building const*, Building::level_t> PROPERTY(state_buildings); + std::map<BuildingType const*, BuildingType::level_t> PROPERTY(province_buildings); + std::map<BuildingType const*, BuildingType::level_t> PROPERTY(state_buildings); fixed_point_map_t<Ideology const*> PROPERTY(party_loyalties); ProvinceHistoryEntry(Province const& new_province, Date new_date); diff --git a/src/openvic-simulation/interface/GUI.cpp b/src/openvic-simulation/interface/GUI.cpp index aeec136..61b8683 100644 --- a/src/openvic-simulation/interface/GUI.cpp +++ b/src/openvic-simulation/interface/GUI.cpp @@ -17,7 +17,7 @@ bool Element::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_m { "CENTER", CENTER } }; ret &= add_key_map_entries(key_map, - "position", ONE_EXACTLY, expect_ivec2(assign_variable_callback(position)), + "position", ONE_EXACTLY, expect_fvec2(assign_variable_callback(position)), "orientation", ZERO_OR_ONE, expect_string(expect_mapped_string(orientation_map, assign_variable_callback(orientation))), "Orientation", ZERO_OR_ONE, expect_string(expect_mapped_string(orientation_map, assign_variable_callback(orientation))) ); @@ -68,7 +68,7 @@ bool Window::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_ma ret &= Element::_fill_key_map(key_map, ui_manager); ret &= add_key_map_entries(key_map, "backGround", ZERO_OR_ONE, success_callback, // TODO - load as potential panel texture (almost always empty) - "size", ONE_EXACTLY, expect_ivec2(assign_variable_callback(size)), + "size", ONE_EXACTLY, expect_fvec2(assign_variable_callback(size)), "moveable", ONE_EXACTLY, expect_int_bool(assign_variable_callback(moveable)), "dontRender", ZERO_OR_ONE, success_callback, // always empty string? "horizontalBorder", ZERO_OR_ONE, success_callback, @@ -144,8 +144,8 @@ bool Text::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_mana ret &= add_key_map_entries(key_map, "text", ZERO_OR_ONE, expect_string(assign_variable_callback_string(text), true), "font", ONE_EXACTLY, expect_string(ui_manager.expect_font_str(assign_variable_callback_pointer(font))), - "maxWidth", ONE_EXACTLY, expect_uint(assign_variable_callback(max_size.x)), - "maxHeight", ONE_EXACTLY, expect_uint(assign_variable_callback(max_size.y)), + "maxWidth", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(max_size.x)), + "maxHeight", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(max_size.y)), "borderSize", ZERO_OR_ONE, success_callback, "fixedsize", ZERO_OR_ONE, success_callback, @@ -161,7 +161,7 @@ OverlappingElementsBox::OverlappingElementsBox() : size {} {} bool OverlappingElementsBox::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_manager) { bool ret = AlignedElement::_fill_key_map(key_map, ui_manager); ret &= add_key_map_entries(key_map, - "size", ONE_EXACTLY, expect_ivec2(assign_variable_callback(size)), + "size", ONE_EXACTLY, expect_fvec2(assign_variable_callback(size)), "spacing", ONE_EXACTLY, success_callback ); return ret; @@ -173,7 +173,7 @@ bool ListBox::_fill_key_map(NodeTools::key_map_t& key_map, UIManager const& ui_m bool ret = Element::_fill_key_map(key_map, ui_manager); ret &= add_key_map_entries(key_map, "backGround", ZERO_OR_ONE, success_callback, - "size", ONE_EXACTLY, expect_ivec2(assign_variable_callback(size)), + "size", ONE_EXACTLY, expect_fvec2(assign_variable_callback(size)), "spacing", ZERO_OR_ONE, success_callback, "scrollbartype", ZERO_OR_ONE, success_callback, // TODO - implement modable listbox scrollbars "borderSize", ZERO_OR_ONE, success_callback diff --git a/src/openvic-simulation/interface/GUI.hpp b/src/openvic-simulation/interface/GUI.hpp index 1a76ca0..f8434f6 100644 --- a/src/openvic-simulation/interface/GUI.hpp +++ b/src/openvic-simulation/interface/GUI.hpp @@ -17,7 +17,7 @@ namespace OpenVic::GUI { }; private: - ivec2_t PROPERTY(position); + fvec2_t PROPERTY(position); orientation_t PROPERTY(orientation); protected: @@ -65,7 +65,7 @@ namespace OpenVic::GUI { NamedInstanceRegistry<Element, UIManager const&> elements; - ivec2_t PROPERTY(size); + fvec2_t PROPERTY(size); bool PROPERTY(moveable); bool PROPERTY(fullscreen); // TODO - background, dontRender, horizontalBorder, verticalBorder @@ -179,7 +179,7 @@ namespace OpenVic::GUI { std::string PROPERTY(text); GFX::Font const* PROPERTY(font); - ivec2_t PROPERTY(max_size); // maxWidth, maxHeight + fvec2_t PROPERTY(max_size); // maxWidth, maxHeight // TODO - borderSize, fixedsize, textureFile @@ -198,7 +198,7 @@ namespace OpenVic::GUI { class OverlappingElementsBox final : public AlignedElement { friend std::unique_ptr<OverlappingElementsBox> std::make_unique<OverlappingElementsBox>(); - ivec2_t PROPERTY(size); + fvec2_t PROPERTY(size); // TODO - spacing @@ -217,7 +217,7 @@ namespace OpenVic::GUI { class ListBox final : public Element { friend std::unique_ptr<ListBox> std::make_unique<ListBox>(); - ivec2_t PROPERTY(size); + fvec2_t PROPERTY(size); // TODO - backGround, spacing, scrollbartype, borderSize diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index dad07a6..6df7537 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -624,6 +624,6 @@ bool Map::_generate_province_adjacencies() { bool Map::generate_and_load_province_adjacencies(std::vector<ovdl::csv::LineObject> const& additional_adjacencies) { bool ret = _generate_province_adjacencies(); - // TODO - read additional adjacencies + // TODO - DEV TASK: read additional adjacencies return ret; } diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 97e5192..c2d2da0 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -149,10 +149,10 @@ bool Province::reset(BuildingManager const& building_manager) { buildings.reset(); bool ret = true; if (!get_water()) { - if (building_manager.building_types_are_locked() && building_manager.buildings_are_locked()) { - for (Building const& building : building_manager.get_buildings()) { - if (building.get_in_province()) { - ret &= buildings.add_item({ building }); + if (building_manager.building_types_are_locked()) { + for (BuildingType const& building_type : building_manager.get_building_types()) { + if (building_type.get_in_province()) { + ret &= buildings.add_item({ building_type }); } } } else { diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index 0b7a5d9..af0bed4 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -2,7 +2,7 @@ #include <cassert> -#include "openvic-simulation/economy/Building.hpp" +#include "openvic-simulation/economy/BuildingInstance.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/country/Country.hpp" diff --git a/src/openvic-simulation/map/TerrainType.hpp b/src/openvic-simulation/map/TerrainType.hpp index 656c938..92f78dd 100644 --- a/src/openvic-simulation/map/TerrainType.hpp +++ b/src/openvic-simulation/map/TerrainType.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/misc/Modifier.hpp" namespace OpenVic { struct TerrainTypeManager; diff --git a/src/openvic-simulation/military/LeaderTrait.hpp b/src/openvic-simulation/military/LeaderTrait.hpp index 16b4201..34de44d 100644 --- a/src/openvic-simulation/military/LeaderTrait.hpp +++ b/src/openvic-simulation/military/LeaderTrait.hpp @@ -3,7 +3,7 @@ #include <cstdint> #include <string_view> -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/dataloader/NodeTools.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" diff --git a/src/openvic-simulation/military/Wargoal.cpp b/src/openvic-simulation/military/Wargoal.cpp index b493f22..4a00c38 100644 --- a/src/openvic-simulation/military/Wargoal.cpp +++ b/src/openvic-simulation/military/Wargoal.cpp @@ -117,7 +117,7 @@ bool WargoalTypeManager::load_wargoal_file(ast::NodeCPtr root) { }, "sprite_index", ONE_EXACTLY, expect_identifier(assign_variable_callback(sprite)), "war_name", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(war_name)), - "months", ONE_EXACTLY, expect_months(assign_variable_callback(available)), + "months", ZERO_OR_ONE, expect_months(assign_variable_callback(available)), "truce_months", ONE_EXACTLY, expect_months(assign_variable_callback(truce)), "is_triggered_only", ZERO_OR_ONE, expect_bool(assign_variable_callback(triggered_only)), "is_civil_war", ZERO_OR_ONE, expect_bool(assign_variable_callback(civil_war)), diff --git a/src/openvic-simulation/military/Wargoal.hpp b/src/openvic-simulation/military/Wargoal.hpp index b34d64f..ef8170f 100644 --- a/src/openvic-simulation/military/Wargoal.hpp +++ b/src/openvic-simulation/military/Wargoal.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/types/EnumBitfield.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/utility/Getters.hpp" diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp index f6e34e1..0386833 100644 --- a/src/openvic-simulation/Modifier.cpp +++ b/src/openvic-simulation/misc/Modifier.cpp @@ -100,7 +100,7 @@ Date ModifierInstance::get_expiry_date() const { return expiry_date; } -ModifierManager::ModifierManager() : modifier_effects { "modifier effects" }, modifiers { "modifiers" } {} +ModifierManager::ModifierManager() : modifier_effects { "modifier effects" }, event_modifiers { "event modifiers" } {} bool ModifierManager::add_modifier_effect(std::string_view identifier, bool positive_good, ModifierEffect::format_t format) { if (identifier.empty()) { @@ -112,7 +112,7 @@ bool ModifierManager::add_modifier_effect(std::string_view identifier, bool posi ); } -bool ModifierManager::add_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) { +bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) { if (identifier.empty()) { Logger::error("Invalid modifier effect identifier - empty!"); return false; @@ -121,7 +121,7 @@ bool ModifierManager::add_modifier(std::string_view identifier, ModifierValue&& Logger::error("Invalid modifier icon for ", identifier, ": ", icon); return false; } - return modifiers.add_item({ identifier, std::move(values), icon }); + return event_modifiers.add_item({ identifier, std::move(values), icon }, duplicate_warning_callback); } bool ModifierManager::setup_modifier_effects() { @@ -220,6 +220,7 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("local_factory_throughput", true); ret &= add_modifier_effect("local_repair", true); ret &= add_modifier_effect("local_rgo_output", true); + ret &= add_modifier_effect("local_RGO_output", true); ret &= add_modifier_effect("local_RGO_throughput", true); ret &= add_modifier_effect("local_ruling_party_support", true); ret &= add_modifier_effect("local_ship_build", false); @@ -254,6 +255,39 @@ bool ModifierManager::setup_modifier_effects() { return ret; } +bool ModifierManager::load_crime_modifiers(ast::NodeCPtr root) { + // TODO - DEV TASK: read crime modifiers + return true; +} + +bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) { + // TODO - DEV TASK: read event modifiers - example framework below + return true; + /*return expect_dictionary_reserve_length( + event_modifiers, + [this](std::string_view key, ast::NodeCPtr value) -> bool { + ModifierValue modifier_value; + Modifier::icon_t icon = 0; + bool ret = expect_modifier_value_and_keys( + move_variable_callback(modifier_value), + "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)) + )(value); + ret &= add_event_modifier(key, std::move(modifier_value), icon); + return ret; + } + )(root);*/ +} + +bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) { + // TODO - DEV TASK: read static modifiers + return true; +} + +bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) { + // TODO - DEV TASK: read triggered modifiers + return true; +} + key_value_callback_t ModifierManager::_modifier_effect_callback( ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator ) const { diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp index 084a0c2..e6ea54e 100644 --- a/src/openvic-simulation/Modifier.hpp +++ b/src/openvic-simulation/misc/Modifier.hpp @@ -106,7 +106,7 @@ namespace OpenVic { */ private: IdentifierInstanceRegistry<ModifierEffect> modifier_effects; - IdentifierRegistry<Modifier> modifiers; + IdentifierRegistry<Modifier> event_modifiers; /* effect_validator takes in ModifierEffect const& */ NodeTools::key_value_callback_t _modifier_effect_callback( @@ -123,11 +123,16 @@ namespace OpenVic { ); IDENTIFIER_REGISTRY_ACCESSORS(modifier_effect) - bool add_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); - IDENTIFIER_REGISTRY_ACCESSORS(modifier) + bool add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon); + IDENTIFIER_REGISTRY_ACCESSORS(event_modifier) bool setup_modifier_effects(); + bool load_crime_modifiers(ast::NodeCPtr root); + bool load_event_modifiers(ast::NodeCPtr root); + bool load_static_modifiers(ast::NodeCPtr root); + bool load_triggered_modifiers(ast::NodeCPtr root); + NodeTools::node_callback_t expect_validated_modifier_value_and_default( NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator diff --git a/src/openvic-simulation/politics/NationalFocus.hpp b/src/openvic-simulation/politics/NationalFocus.hpp index e7d1f90..396f8ec 100644 --- a/src/openvic-simulation/politics/NationalFocus.hpp +++ b/src/openvic-simulation/politics/NationalFocus.hpp @@ -2,7 +2,7 @@ #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/utility/Getters.hpp" -#include "openvic-simulation/Modifier.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" @@ -14,7 +14,7 @@ namespace OpenVic { struct NationalFocusGroup : HasIdentifier { friend struct NationalFocusManager; - + private: NationalFocusGroup(std::string_view new_identifier); }; @@ -39,8 +39,8 @@ namespace OpenVic { std::string_view new_identifier, uint8_t new_icon, NationalFocusGroup const& new_group, - ModifierValue&& new_modifiers, - pop_promotion_map_t&& new_encouraged_promotion, + ModifierValue&& new_modifiers, + pop_promotion_map_t&& new_encouraged_promotion, party_loyalty_map_t&& new_encouraged_loyalty, production_map_t&& new_encouraged_production ); @@ -64,8 +64,8 @@ namespace OpenVic { std::string_view identifier, uint8_t icon, NationalFocusGroup const& group, - ModifierValue&& modifiers, - NationalFocus::pop_promotion_map_t&& encouraged_promotion, + ModifierValue&& modifiers, + NationalFocus::pop_promotion_map_t&& encouraged_promotion, NationalFocus::party_loyalty_map_t&& encouraged_loyalty, NationalFocus::production_map_t&& encouraged_production ); diff --git a/src/openvic-simulation/politics/NationalValue.hpp b/src/openvic-simulation/politics/NationalValue.hpp index 09ef85e..625be36 100644 --- a/src/openvic-simulation/politics/NationalValue.hpp +++ b/src/openvic-simulation/politics/NationalValue.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/misc/Modifier.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" namespace OpenVic { diff --git a/src/openvic-simulation/pop/Culture.cpp b/src/openvic-simulation/pop/Culture.cpp index 47501e0..376e2a3 100644 --- a/src/openvic-simulation/pop/Culture.cpp +++ b/src/openvic-simulation/pop/Culture.cpp @@ -77,7 +77,7 @@ bool CultureManager::add_culture_group( } bool CultureManager::add_culture( - std::string_view identifier, colour_t colour, CultureGroup const* group, std::vector<std::string>&& first_names, + std::string_view identifier, colour_t colour, CultureGroup const& group, std::vector<std::string>&& first_names, std::vector<std::string>&& last_names ) { if (!culture_groups.is_locked()) { @@ -88,15 +88,11 @@ bool CultureManager::add_culture( Logger::error("Invalid culture identifier - empty!"); return false; } - if (group == nullptr) { - Logger::error("Null culture group for ", identifier); - return false; - } if (colour > MAX_COLOUR_RGB) { Logger::error("Invalid culture colour for ", identifier, ": ", colour_to_hex_string(colour)); return false; } - return cultures.add_item({ identifier, colour, *group, std::move(first_names), std::move(last_names) }); + return cultures.add_item({ identifier, colour, group, std::move(first_names), std::move(last_names) }); } bool CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) { @@ -131,7 +127,7 @@ bool CultureManager::_load_culture_group( } bool CultureManager::_load_culture( - CultureGroup const* culture_group, std::string_view culture_key, ast::NodeCPtr culture_node + CultureGroup const& culture_group, std::string_view culture_key, ast::NodeCPtr culture_node ) { colour_t colour = NULL_COLOUR; @@ -191,9 +187,8 @@ bool CultureManager::load_culture_file(ast::NodeCPtr root) { lock_culture_groups(); cultures.reserve(cultures.size() + total_expected_cultures); - ret &= expect_dictionary([this](std::string_view culture_group_key, ast::NodeCPtr culture_group_value) -> bool { - CultureGroup const* culture_group = get_culture_group_by_identifier(culture_group_key); - return expect_dictionary([this, culture_group](std::string_view key, ast::NodeCPtr value) -> bool { + ret &= expect_culture_group_dictionary([this](CultureGroup const& culture_group, ast::NodeCPtr culture_group_value) -> bool { + return expect_dictionary([this, &culture_group](std::string_view key, ast::NodeCPtr value) -> bool { static const string_set_t reserved_keys = { "leader", "unit", "union", "is_overseas" }; if (reserved_keys.contains(key)) { return true; diff --git a/src/openvic-simulation/pop/Culture.hpp b/src/openvic-simulation/pop/Culture.hpp index 402af0c..2abe77d 100644 --- a/src/openvic-simulation/pop/Culture.hpp +++ b/src/openvic-simulation/pop/Culture.hpp @@ -71,7 +71,7 @@ namespace OpenVic { size_t& total_expected_cultures, GraphicalCultureType const* default_unit_graphical_culture_type, std::string_view culture_group_key, ast::NodeCPtr culture_group_node ); - bool _load_culture(CultureGroup const* culture_group, std::string_view culture_key, ast::NodeCPtr node); + bool _load_culture(CultureGroup const& culture_group, std::string_view culture_key, ast::NodeCPtr node); public: CultureManager(); @@ -80,13 +80,13 @@ namespace OpenVic { IDENTIFIER_REGISTRY_ACCESSORS(graphical_culture_type) bool add_culture_group( - std::string_view identifier, std::string_view leader, GraphicalCultureType const* new_graphical_culture_type, + std::string_view identifier, std::string_view leader, GraphicalCultureType const* graphical_culture_type, bool is_overseas ); IDENTIFIER_REGISTRY_ACCESSORS(culture_group) bool add_culture( - std::string_view identifier, colour_t colour, CultureGroup const* group, std::vector<std::string>&& first_names, + std::string_view identifier, colour_t colour, CultureGroup const& group, std::vector<std::string>&& first_names, std::vector<std::string>&& last_names ); IDENTIFIER_REGISTRY_ACCESSORS(culture) diff --git a/src/openvic-simulation/pop/Religion.cpp b/src/openvic-simulation/pop/Religion.cpp index 99915c3..f52ed3e 100644 --- a/src/openvic-simulation/pop/Religion.cpp +++ b/src/openvic-simulation/pop/Religion.cpp @@ -37,7 +37,7 @@ bool ReligionManager::add_religion_group(std::string_view identifier) { } bool ReligionManager::add_religion( - std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan + std::string_view identifier, colour_t colour, ReligionGroup const& group, Religion::icon_t icon, bool pagan ) { if (!religion_groups.is_locked()) { Logger::error("Cannot register religions until religion groups are locked!"); @@ -47,10 +47,6 @@ bool ReligionManager::add_religion( Logger::error("Invalid religion identifier - empty!"); return false; } - if (group == nullptr) { - Logger::error("Null religion group for ", identifier); - return false; - } if (colour > MAX_COLOUR_RGB) { Logger::error("Invalid religion colour for ", identifier, ": ", colour_to_hex_string(colour)); return false; @@ -59,7 +55,7 @@ bool ReligionManager::add_religion( Logger::error("Invalid religion icon for ", identifier, ": ", icon); return false; } - return religions.add_item({ identifier, colour, *group, icon, pagan }); + return religions.add_item({ identifier, colour, group, icon, pagan }); } /* REQUIREMENTS: @@ -77,10 +73,8 @@ bool ReligionManager::load_religion_file(ast::NodeCPtr root) { )(root); lock_religion_groups(); religions.reserve(religions.size() + total_expected_religions); - ret &= expect_dictionary([this](std::string_view religion_group_key, ast::NodeCPtr religion_group_value) -> bool { - ReligionGroup const* religion_group = get_religion_group_by_identifier(religion_group_key); - - return expect_dictionary([this, religion_group](std::string_view key, ast::NodeCPtr value) -> bool { + ret &= expect_religion_group_dictionary([this](ReligionGroup const& religion_group, ast::NodeCPtr religion_group_value) -> bool { + return expect_dictionary([this, &religion_group](std::string_view key, ast::NodeCPtr value) -> bool { colour_t colour = NULL_COLOUR; Religion::icon_t icon = 0; bool pagan = false; diff --git a/src/openvic-simulation/pop/Religion.hpp b/src/openvic-simulation/pop/Religion.hpp index a47754d..4cc8403 100644 --- a/src/openvic-simulation/pop/Religion.hpp +++ b/src/openvic-simulation/pop/Religion.hpp @@ -52,7 +52,7 @@ namespace OpenVic { IDENTIFIER_REGISTRY_ACCESSORS(religion_group) bool add_religion( - std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan + std::string_view identifier, colour_t colour, ReligionGroup const& group, Religion::icon_t icon, bool pagan ); IDENTIFIER_REGISTRY_ACCESSORS(religion) |