diff options
Diffstat (limited to 'src')
24 files changed, 165 insertions, 84 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp index cd5da59..1df6e90 100644 --- a/src/openvic-simulation/InstanceManager.cpp +++ b/src/openvic-simulation/InstanceManager.cpp @@ -80,6 +80,7 @@ bool InstanceManager::setup() { definition_manager.get_research_manager().get_technology_manager().get_technologies(), definition_manager.get_research_manager().get_invention_manager().get_inventions(), definition_manager.get_politics_manager().get_ideology_manager().get_ideologies(), + definition_manager.get_politics_manager().get_government_type_manager().get_government_types(), definition_manager.get_pop_manager().get_pop_types() ); diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp index 0b27b78..3c2e7bb 100644 --- a/src/openvic-simulation/country/CountryInstance.cpp +++ b/src/openvic-simulation/country/CountryInstance.cpp @@ -16,6 +16,7 @@ CountryInstance::CountryInstance( decltype(technologies)::keys_t const& technology_keys, decltype(inventions)::keys_t const& invention_keys, decltype(upper_house)::keys_t const& ideology_keys, + decltype(government_flag_overrides)::keys_t const& government_type_keys, decltype(pop_type_distribution)::keys_t const& pop_type_keys ) : /* Main attributes */ country_definition { new_country_definition }, @@ -52,6 +53,8 @@ CountryInstance::CountryInstance( ruling_party { nullptr }, upper_house { &ideology_keys }, reforms {}, + government_flag_overrides { &government_type_keys }, + flag_government_type { nullptr }, suppression_points { 0 }, infamy { 0 }, plurality { 0 }, @@ -300,7 +303,7 @@ bool CountryInstance::apply_history_to_country(CountryHistoryEntry const* entry, for (std::string const& flag : entry->get_global_flags()) { // TODO - set global flag } - // entry->get_government_flag_overrides(); + government_flag_overrides.write_non_empty_values(entry->get_government_flag_overrides()); for (Decision const* decision : entry->get_decisions()) { // TODO - take decision } @@ -393,6 +396,16 @@ void CountryInstance::update_gamestate() { colour = ERROR_COLOUR; } + if (government_type != nullptr) { + flag_government_type = government_flag_overrides[*government_type]; + + if (flag_government_type == nullptr) { + flag_government_type = government_type; + } + } else { + flag_government_type = nullptr; + } + // Order of updates might need to be changed/functions split up to account for dependencies _update_production(); _update_budget(); @@ -421,12 +434,15 @@ bool CountryInstanceManager::generate_country_instances( decltype(CountryInstance::technologies)::keys_t const& technology_keys, decltype(CountryInstance::inventions)::keys_t const& invention_keys, decltype(CountryInstance::upper_house)::keys_t const& ideology_keys, + decltype(CountryInstance::government_flag_overrides)::keys_t const& government_type_keys, decltype(CountryInstance::pop_type_distribution)::keys_t const& pop_type_keys ) { reserve_more(country_instances, country_definition_manager.get_country_definition_count()); for (CountryDefinition const& country_definition : country_definition_manager.get_country_definitions()) { - country_instances.add_item({ &country_definition, technology_keys, invention_keys, ideology_keys, pop_type_keys }); + country_instances.add_item({ + &country_definition, technology_keys, invention_keys, ideology_keys, government_type_keys, pop_type_keys + }); } return true; diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp index 5b26f7f..f4baf2d 100644 --- a/src/openvic-simulation/country/CountryInstance.hpp +++ b/src/openvic-simulation/country/CountryInstance.hpp @@ -78,6 +78,8 @@ namespace OpenVic { IndexedMap<Ideology, fixed_point_t> PROPERTY(upper_house); std::vector<Reform const*> PROPERTY(reforms); // TODO: should be map of reform groups to active reforms: must set defaults & validate applied history // TODO - national issue support distribution (for just voters and for everyone) + IndexedMap<GovernmentType, GovernmentType const*> PROPERTY(government_flag_overrides); + GovernmentType const* PROPERTY(flag_government_type); fixed_point_t PROPERTY(suppression_points); fixed_point_t PROPERTY(infamy); fixed_point_t PROPERTY(plurality); @@ -127,8 +129,11 @@ namespace OpenVic { UNIT_BRANCHED_GETTER(get_leaders, generals, admirals); CountryInstance( - CountryDefinition const* new_country_definition, decltype(technologies)::keys_t const& technology_keys, - decltype(inventions)::keys_t const& invention_keys, decltype(upper_house)::keys_t const& ideology_keys, + CountryDefinition const* new_country_definition, + decltype(technologies)::keys_t const& technology_keys, + decltype(inventions)::keys_t const& invention_keys, + decltype(upper_house)::keys_t const& ideology_keys, + decltype(government_flag_overrides)::keys_t const& government_type_keys, decltype(pop_type_distribution)::keys_t const& pop_type_keys ); @@ -198,6 +203,7 @@ namespace OpenVic { decltype(CountryInstance::technologies)::keys_t const& technology_keys, decltype(CountryInstance::inventions)::keys_t const& invention_keys, decltype(CountryInstance::upper_house)::keys_t const& ideology_keys, + decltype(CountryInstance::government_flag_overrides)::keys_t const& government_type_keys, decltype(CountryInstance::pop_type_distribution)::keys_t const& pop_type_keys ); diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 63571c7..1be040f 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -831,7 +831,7 @@ bool Dataloader::_load_song_chances(DefinitionManager& definition_manager) { bool ret = true; SongChanceManager& song_chance_manager = definition_manager.get_song_chance_manager(); - if(path.empty()) { + if (path.empty()) { Logger::info("No Songs.txt file to load"); song_chance_manager.lock_song_chances(); return true; @@ -1096,7 +1096,7 @@ bool Dataloader::load_defines(DefinitionManager& definition_manager) { Logger::error("Failed to load diplomatic actions!"); ret = false; } - if(!definition_manager.get_script_manager().get_condition_manager().setup_conditions(definition_manager)) { + if (!definition_manager.get_script_manager().get_condition_manager().setup_conditions(definition_manager)) { Logger::error("Failed to set up conditions!"); ret = false; } @@ -1131,6 +1131,7 @@ bool Dataloader::parse_scripts(DefinitionManager& definition_manager) const { PARSE_SCRIPTS("decision", definition_manager.get_decision_manager()); PARSE_SCRIPTS("event", definition_manager.get_event_manager()); PARSE_SCRIPTS("song chance", definition_manager.get_song_chance_manager()); + PARSE_SCRIPTS("national focus", definition_manager.get_politics_manager().get_national_focus_manager()); return ret; } diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 945e5e8..79fb0ea 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -540,7 +540,7 @@ namespace OpenVic { template<typename Key, typename Value, typename... MapArgs> Callback<Value> auto map_callback( - tsl::ordered_map<Key const*, Value, MapArgs...>& map, Key const* key, bool warn = false + tsl::ordered_map<Key, Value, MapArgs...>& map, Key key, bool warn = false ) { return [&map, key, warn](Value value) -> bool { if (map.emplace(key, std::move(value)).second) { diff --git a/src/openvic-simulation/economy/GoodDefinition.cpp b/src/openvic-simulation/economy/GoodDefinition.cpp index 104764b..892592d 100644 --- a/src/openvic-simulation/economy/GoodDefinition.cpp +++ b/src/openvic-simulation/economy/GoodDefinition.cpp @@ -1,20 +1,28 @@ #include "GoodDefinition.hpp" -#include <cassert> - using namespace OpenVic; using namespace OpenVic::NodeTools; GoodCategory::GoodCategory(std::string_view new_identifier) : HasIdentifier { new_identifier } {} GoodDefinition::GoodDefinition( - std::string_view new_identifier, colour_t new_colour, index_t new_index, GoodCategory const& new_category, - price_t new_base_price, bool new_available_from_start, bool new_tradeable, bool new_money, bool new_overseas_penalty -) : HasIdentifierAndColour { new_identifier, new_colour, false }, HasIndex { new_index }, category { new_category }, - base_price { new_base_price }, available_from_start { new_available_from_start }, tradeable { new_tradeable }, - money { new_money }, overseas_penalty { new_overseas_penalty } { - assert(base_price > NULL_PRICE); -} + std::string_view new_identifier, + colour_t new_colour, + index_t new_index, + GoodCategory const& new_category, + price_t new_base_price, + bool new_available_from_start, + bool new_tradeable, + bool new_money, + bool new_overseas_penalty +) : HasIdentifierAndColour { new_identifier, new_colour, false }, + HasIndex { new_index }, + category { new_category }, + base_price { new_base_price }, + available_from_start { new_available_from_start }, + tradeable { new_tradeable }, + money { new_money }, + overseas_penalty { new_overseas_penalty } {} bool GoodDefinitionManager::add_good_category(std::string_view identifier) { if (identifier.empty()) { diff --git a/src/openvic-simulation/interface/GFXSprite.cpp b/src/openvic-simulation/interface/GFXSprite.cpp index 992a1ff..8acb8d4 100644 --- a/src/openvic-simulation/interface/GFXSprite.cpp +++ b/src/openvic-simulation/interface/GFXSprite.cpp @@ -6,9 +6,9 @@ using namespace OpenVic::NodeTools; Font::Font( std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname, std::string_view new_charset, - uint32_t new_height + uint32_t new_height, colour_codes_t&& new_colour_codes ) : HasIdentifierAndAlphaColour { new_identifier, new_colour, false }, fontname { new_fontname }, charset { new_charset }, - height { new_height } {} + height { new_height }, colour_codes { std::move(new_colour_codes) } {} node_callback_t Sprite::expect_sprites(length_callback_t length_callback, callback_t<std::unique_ptr<Sprite>&&> callback) { return expect_dictionary_keys_and_length( diff --git a/src/openvic-simulation/interface/GFXSprite.hpp b/src/openvic-simulation/interface/GFXSprite.hpp index 49691c1..cee8c42 100644 --- a/src/openvic-simulation/interface/GFXSprite.hpp +++ b/src/openvic-simulation/interface/GFXSprite.hpp @@ -11,16 +11,19 @@ namespace OpenVic::GFX { struct Font : HasIdentifierAndAlphaColour { friend class OpenVic::UIManager; + using colour_codes_t = ordered_map<char, colour_t>; + private: std::string PROPERTY(fontname); std::string PROPERTY(charset); uint32_t PROPERTY(height); + colour_codes_t PROPERTY(colour_codes); - // TODO - colorcodes, effect + // TODO - effect Font( std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname, - std::string_view new_charset, uint32_t new_height + std::string_view new_charset, uint32_t new_height, colour_codes_t&& new_colour_codes ); public: diff --git a/src/openvic-simulation/interface/GUI.cpp b/src/openvic-simulation/interface/GUI.cpp index 87e3624..4f42b86 100644 --- a/src/openvic-simulation/interface/GUI.cpp +++ b/src/openvic-simulation/interface/GUI.cpp @@ -184,12 +184,10 @@ bool Text::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map, UIManag "maxWidth", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(max_size.x)), "maxHeight", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(max_size.y)), "borderSize", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(border_size)), + "textureFile", ZERO_OR_ONE, expect_string(assign_variable_callback_string(texture_file), true), "fixedsize", ZERO_OR_ONE, success_callback, - "allwaystransparent", ZERO_OR_ONE, success_callback, - - // Add warning about redundant key? - "textureFile", ZERO_OR_ONE, success_callback + "allwaystransparent", ZERO_OR_ONE, success_callback ); return ret; } diff --git a/src/openvic-simulation/interface/GUI.hpp b/src/openvic-simulation/interface/GUI.hpp index 4e1b062..a86d432 100644 --- a/src/openvic-simulation/interface/GUI.hpp +++ b/src/openvic-simulation/interface/GUI.hpp @@ -203,8 +203,9 @@ namespace OpenVic::GUI { GFX::Font const* PROPERTY(font); fvec2_t PROPERTY(max_size); /* Defines keys: maxWidth, maxHeight */ fvec2_t PROPERTY(border_size); + std::string PROPERTY(texture_file); - // TODO - fixedsize, textureFile + // TODO - fixedsize protected: Text(); diff --git a/src/openvic-simulation/interface/UI.cpp b/src/openvic-simulation/interface/UI.cpp index ea871de..03166b1 100644 --- a/src/openvic-simulation/interface/UI.cpp +++ b/src/openvic-simulation/interface/UI.cpp @@ -8,7 +8,8 @@ using namespace OpenVic::GFX; using namespace OpenVic::GUI; bool UIManager::add_font( - std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset, uint32_t height + std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset, uint32_t height, + Font::colour_codes_t&& colour_codes ) { if (identifier.empty()) { Logger::error("Invalid font identifier - empty!"); @@ -22,23 +23,48 @@ bool UIManager::add_font( Logger::error("Invalid fontname for font ", identifier, " - empty!"); return false; } - return fonts.add_item({ identifier, colour, fontname, charset, height }, duplicate_warning_callback); + const bool ret = fonts.add_item( + { identifier, colour, fontname, charset, height, std::move(colour_codes) }, + duplicate_warning_callback + ); + + if (universal_colour_codes.empty() && ret) { + GFX::Font::colour_codes_t const& loaded_colour_codes = get_fonts().back().get_colour_codes(); + if (!loaded_colour_codes.empty()) { + universal_colour_codes = loaded_colour_codes; + Logger::info("Loaded universal colour codes from font: \"", identifier, "\""); + } + } + + return ret; } bool UIManager::_load_font(ast::NodeCPtr node) { std::string_view identifier, fontname, charset; colour_argb_t colour = colour_argb_t::null(); uint32_t height = 0; + Font::colour_codes_t colour_codes; + bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(identifier)), "fontname", ONE_EXACTLY, expect_string(assign_variable_callback(fontname)), "color", ONE_EXACTLY, expect_colour_hex(assign_variable_callback(colour)), "charset", ZERO_OR_ONE, expect_string(assign_variable_callback(charset)), "height", ZERO_OR_ONE, expect_uint(assign_variable_callback(height)), - "colorcodes", ZERO_OR_ONE, success_callback, + "colorcodes", ZERO_OR_ONE, expect_dictionary( + [&colour_codes](std::string_view key, ast::NodeCPtr value) -> bool { + if (key.size() != 1) { + Logger::error("Invalid colour code key: \"", key, "\" (expected single character)"); + return false; + } + return expect_colour(map_callback(colour_codes, key.front()))(value); + } + ), "effect", ZERO_OR_ONE, success_callback )(node); - ret &= add_font(identifier, colour, fontname, charset, height); + + ret &= add_font(identifier, colour, fontname, charset, height, std::move(colour_codes)); + return ret; } diff --git a/src/openvic-simulation/interface/UI.hpp b/src/openvic-simulation/interface/UI.hpp index 9aec96c..8ba7745 100644 --- a/src/openvic-simulation/interface/UI.hpp +++ b/src/openvic-simulation/interface/UI.hpp @@ -8,6 +8,7 @@ namespace OpenVic { class UIManager { NamedInstanceRegistry<GFX::Sprite> IDENTIFIER_REGISTRY(sprite); IdentifierRegistry<GFX::Font> IDENTIFIER_REGISTRY(font); + GFX::Font::colour_codes_t PROPERTY(universal_colour_codes); NamedInstanceRegistry<GFX::Object> IDENTIFIER_REGISTRY(object); NamedInstanceRegistry<GUI::Scene, UIManager const&> IDENTIFIER_REGISTRY(scene); @@ -18,7 +19,7 @@ namespace OpenVic { public: bool add_font( std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset, - uint32_t height + uint32_t height, GFX::Font::colour_codes_t&& colour_codes ); void lock_gfx_registries(); diff --git a/src/openvic-simulation/map/Mapmode.cpp b/src/openvic-simulation/map/Mapmode.cpp index cab67d1..f951a05 100644 --- a/src/openvic-simulation/map/Mapmode.cpp +++ b/src/openvic-simulation/map/Mapmode.cpp @@ -1,7 +1,5 @@ #include "Mapmode.hpp" -#include <cassert> - #include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/map/MapDefinition.hpp" #include "openvic-simulation/map/MapInstance.hpp" @@ -13,10 +11,12 @@ using namespace OpenVic; using namespace OpenVic::colour_literals; Mapmode::Mapmode( - std::string_view new_identifier, index_t new_index, colour_func_t new_colour_func -) : HasIdentifier { new_identifier }, HasIndex { new_index }, colour_func { new_colour_func } { - assert(colour_func != nullptr); -} + std::string_view new_identifier, + index_t new_index, + colour_func_t new_colour_func +) : HasIdentifier { new_identifier }, + HasIndex { new_index }, + colour_func { new_colour_func } {} const Mapmode Mapmode::ERROR_MAPMODE { "mapmode_error", 0, [](MapInstance const&, ProvinceInstance const& province) -> base_stripe_t { diff --git a/src/openvic-simulation/map/ProvinceDefinition.cpp b/src/openvic-simulation/map/ProvinceDefinition.cpp index 4f34c1e..14828e8 100644 --- a/src/openvic-simulation/map/ProvinceDefinition.cpp +++ b/src/openvic-simulation/map/ProvinceDefinition.cpp @@ -8,13 +8,23 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; ProvinceDefinition::ProvinceDefinition( - std::string_view new_identifier, colour_t new_colour, index_t new_index -) : HasIdentifierAndColour { new_identifier, new_colour, true }, HasIndex { new_index }, region { nullptr }, - climate { nullptr }, continent { nullptr }, on_map { false }, water { false }, coastal { false }, - port { false }, port_adjacent_province { nullptr }, default_terrain_type { nullptr }, adjacencies {}, centre {}, - positions {} { - assert(index != NULL_INDEX); -} + std::string_view new_identifier, + colour_t new_colour, + index_t new_index +) : HasIdentifierAndColour { new_identifier, new_colour, true }, + HasIndex { new_index }, + region { nullptr }, + climate { nullptr }, + continent { nullptr }, + on_map { false }, + water { false }, + coastal { false }, + port { false }, + port_adjacent_province { nullptr }, + default_terrain_type { nullptr }, + adjacencies {}, + centre {}, + positions {} {} bool ProvinceDefinition::operator==(ProvinceDefinition const& other) const { return this == &other; diff --git a/src/openvic-simulation/military/UnitInstanceGroup.cpp b/src/openvic-simulation/military/UnitInstanceGroup.cpp index 07736f3..65ecf5b 100644 --- a/src/openvic-simulation/military/UnitInstanceGroup.cpp +++ b/src/openvic-simulation/military/UnitInstanceGroup.cpp @@ -155,7 +155,6 @@ UnitInstanceGroupBranched<UnitType::branch_t::NAVAL>::UnitInstanceGroupBranched( std::vector<ShipInstance*>&& new_units ) : UnitInstanceGroup { new_name, std::move(new_units) } {} - fixed_point_t UnitInstanceGroupBranched<UnitType::branch_t::NAVAL>::get_total_consumed_supply() const { fixed_point_t total_consumed_supply = 0; diff --git a/src/openvic-simulation/military/UnitType.cpp b/src/openvic-simulation/military/UnitType.cpp index fb65bf8..11f7221 100644 --- a/src/openvic-simulation/military/UnitType.cpp +++ b/src/openvic-simulation/military/UnitType.cpp @@ -151,7 +151,7 @@ bool UnitTypeManager::load_unit_type_file( ) { using namespace std::string_view_literals; auto type_symbol = parser.find_intern("type"sv); - if(!type_symbol) { + if (!type_symbol) { Logger::error("type could not be interned."); } diff --git a/src/openvic-simulation/misc/SongChance.cpp b/src/openvic-simulation/misc/SongChance.cpp index 4a99362..94fb571 100644 --- a/src/openvic-simulation/misc/SongChance.cpp +++ b/src/openvic-simulation/misc/SongChance.cpp @@ -3,18 +3,16 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -SongChance::SongChance(size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance): -HasIdentifier { std::to_string(new_index) }, -file_name { new_filename }, -chance { std::move(new_chance) } -{} +SongChance::SongChance( + size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance +) : HasIdentifier { std::to_string(new_index) }, file_name { new_filename }, chance { std::move(new_chance) } {} bool SongChance::parse_scripts(DefinitionManager const& definition_manager) { return chance.parse_scripts(definition_manager); } bool SongChanceManager::load_songs_file(ast::NodeCPtr root) { - bool ret = true; + bool ret = true; ret &= expect_dictionary_reserve_length( song_chances, @@ -28,15 +26,15 @@ bool SongChanceManager::load_songs_file(ast::NodeCPtr root) { bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(name)), - "chance", ONE_EXACTLY, chance.expect_conditional_weight(ConditionalWeight::BASE) + "chance", ONE_EXACTLY, chance.expect_conditional_weight(ConditionalWeight::FACTOR) )(value); - ret &= song_chances.add_item({song_chances.size(), name, std::move(chance) }); + ret &= song_chances.add_item({ song_chances.size(), name, std::move(chance) }); return ret; } )(root); - if(song_chances.size() == 0) { + if (song_chances.size() == 0) { Logger::error("No songs found in Songs.txt"); return false; } @@ -50,4 +48,4 @@ bool SongChanceManager::parse_scripts(DefinitionManager const& definition_manage ret &= songChance.parse_scripts(definition_manager); } return ret; -}
\ No newline at end of file +} diff --git a/src/openvic-simulation/misc/SongChance.hpp b/src/openvic-simulation/misc/SongChance.hpp index f92af7a..dc7d929 100644 --- a/src/openvic-simulation/misc/SongChance.hpp +++ b/src/openvic-simulation/misc/SongChance.hpp @@ -1,19 +1,23 @@ #pragma once -#include <openvic-simulation/types/IdentifierRegistry.hpp> -#include <openvic-simulation/scripts/ConditionalWeight.hpp> +#include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/scripts/ConditionalWeight.hpp" namespace OpenVic { /*For music/Songs.txt if it exists*/ struct SongChanceManager; + struct SongChance : HasIdentifier { - private: friend struct SongChanceManager; + + private: std::string PROPERTY(file_name); ConditionalWeight PROPERTY(chance); + SongChance(size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance); + bool parse_scripts(DefinitionManager const& definition_manager); - + public: SongChance(SongChance&&) = default; }; diff --git a/src/openvic-simulation/misc/SoundEffect.cpp b/src/openvic-simulation/misc/SoundEffect.cpp index df3196b..b32d353 100644 --- a/src/openvic-simulation/misc/SoundEffect.cpp +++ b/src/openvic-simulation/misc/SoundEffect.cpp @@ -20,7 +20,7 @@ bool SoundEffectManager::_load_sound_define(std::string_view sfx_identifier, ast Logger::error("Invalid sound identifier - empty!"); return false; } - if(file.empty()) { + if (file.empty()) { Logger::error("Invalid sound file name - empty!"); return false; } @@ -35,4 +35,4 @@ bool SoundEffectManager::load_sound_defines_file(ast::NodeCPtr root) { return _load_sound_define(key,value); } )(root); -}
\ No newline at end of file +} diff --git a/src/openvic-simulation/misc/SoundEffect.hpp b/src/openvic-simulation/misc/SoundEffect.hpp index 7f18dce..35d05dc 100644 --- a/src/openvic-simulation/misc/SoundEffect.hpp +++ b/src/openvic-simulation/misc/SoundEffect.hpp @@ -1,29 +1,31 @@ #pragma once -#include <openvic-simulation/types/fixed_point/FixedPoint.hpp> -#include <openvic-simulation/types/IdentifierRegistry.hpp> +#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" +#include "openvic-simulation/types/IdentifierRegistry.hpp" namespace OpenVic { /*For interface/Sound.sfx */ struct SoundEffectManager; + struct SoundEffect : HasIdentifier { - private: friend struct SoundEffectManager; + + private: std::string PROPERTY(file); fixed_point_t PROPERTY(volume); + SoundEffect(std::string_view new_identifier, std::string_view new_file, fixed_point_t new_volume); - + public: SoundEffect(SoundEffect&&) = default; }; - + struct SoundEffectManager { - private: - IdentifierRegistry<SoundEffect> IDENTIFIER_REGISTRY(sound_effect); + IdentifierRegistry<SoundEffect> IDENTIFIER_REGISTRY(sound_effect); bool _load_sound_define(std::string_view sfx_identifier, ast::NodeCPtr root); public: bool load_sound_defines_file(ast::NodeCPtr root); }; -}
\ No newline at end of file +} diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index c421de3..6dd0d1f 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -40,9 +40,7 @@ Pop::Pop(PopBase const& pop_base, decltype(ideologies)::keys_t const& ideology_k savings { 0 }, life_needs_fulfilled { 0 }, everyday_needs_fulfilled { 0 }, - luxury_needs_fulfilled { 0 } { - assert(size > 0); -} + luxury_needs_fulfilled { 0 } {} void Pop::setup_pop_test_values(IssueManager const& issue_manager) { /* Returns +/- range% of size. */ @@ -198,11 +196,7 @@ PopType::PopType( migration_target { std::move(new_migration_target) }, promote_to { std::move(new_promote_to) }, ideologies { std::move(new_ideologies) }, - issues { std::move(new_issues) } { - assert(sprite > 0); - assert(max_size >= 0); - assert(merge_max_size >= 0); -} + issues { std::move(new_issues) } {} bool PopType::parse_scripts(DefinitionManager const& definition_manager) { bool ret = true; diff --git a/src/openvic-simulation/pop/Religion.cpp b/src/openvic-simulation/pop/Religion.cpp index 3fa81bf..2283821 100644 --- a/src/openvic-simulation/pop/Religion.cpp +++ b/src/openvic-simulation/pop/Religion.cpp @@ -1,7 +1,5 @@ #include "Religion.hpp" -#include <cassert> - #include "openvic-simulation/types/Colour.hpp" using namespace OpenVic; @@ -10,10 +8,15 @@ using namespace OpenVic::NodeTools; ReligionGroup::ReligionGroup(std::string_view new_identifier) : HasIdentifier { new_identifier } {} Religion::Religion( - std::string_view new_identifier, colour_t new_colour, ReligionGroup const& new_group, icon_t new_icon, bool new_pagan -) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, icon { new_icon }, pagan { new_pagan } { - assert(icon > 0); -} + std::string_view new_identifier, + colour_t new_colour, + ReligionGroup const& new_group, + icon_t new_icon, + bool new_pagan +) : HasIdentifierAndColour { new_identifier, new_colour, false }, + group { new_group }, + icon { new_icon }, + pagan { new_pagan } {} bool ReligionManager::add_religion_group(std::string_view identifier) { if (identifier.empty()) { diff --git a/src/openvic-simulation/types/IndexedMap.hpp b/src/openvic-simulation/types/IndexedMap.hpp index 30cf5cd..5682c0e 100644 --- a/src/openvic-simulation/types/IndexedMap.hpp +++ b/src/openvic-simulation/types/IndexedMap.hpp @@ -169,6 +169,16 @@ namespace OpenVic { return true; } + constexpr void write_non_empty_values(IndexedMap const& other) { + const size_t count = std::min(container_t::size(), other.size()); + for (size_t index = 0; index < count; ++index) { + value_t const& value = other[index]; + if (value) { + container_t::operator[](index) = value; + } + } + } + fixed_point_map_t<key_t const *> to_fixed_point_map() const requires(std::same_as<value_t, fixed_point_t>) { diff --git a/src/openvic-simulation/types/Vector.hpp b/src/openvic-simulation/types/Vector.hpp index 7ed952a..d318c2f 100644 --- a/src/openvic-simulation/types/Vector.hpp +++ b/src/openvic-simulation/types/Vector.hpp @@ -14,7 +14,7 @@ namespace OpenVic { T x, y; constexpr vec2_t() = default; - constexpr vec2_t(T new_val) : x { new_val }, y { new_val } {} + explicit constexpr vec2_t(T new_val) : x { new_val }, y { new_val } {} constexpr vec2_t(T new_x, T new_y) : x { new_x }, y { new_y } {} constexpr vec2_t(vec2_t const&) = default; |