diff options
author | zaaarf <80046572+zaaarf@users.noreply.github.com> | 2023-09-24 14:33:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-24 14:33:01 +0200 |
commit | 33eeede65f7eede0e89420dbd8d83284ec6de2a7 (patch) | |
tree | dd88808bf2fe1a9ca017621162cd6aaee11df598 | |
parent | b0b6264b83514be9f47f4e24b2e3bd8a02b33e90 (diff) | |
parent | 6f8cdd4a4faa90fbc6dc492ee06d1ab28c191e98 (diff) |
Merge pull request #29 from OpenVicProject/fixes
Fixed pop type loading issue
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 1 | ||||
-rw-r--r-- | src/openvic-simulation/economy/Good.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/Building.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 16 | ||||
-rw-r--r-- | src/openvic-simulation/types/IdentifierRegistry.hpp | 10 |
5 files changed, 19 insertions, 12 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 1bdbf7a..4ff190f 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -1,5 +1,4 @@ #include "Dataloader.hpp" -#include <filesystem> #include <openvic-dataloader/csv/Parser.hpp> #include <openvic-dataloader/detail/CallbackOStream.hpp> diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp index 943db00..f1da8bd 100644 --- a/src/openvic-simulation/economy/Good.cpp +++ b/src/openvic-simulation/economy/Good.cpp @@ -1,8 +1,6 @@ #include "Good.hpp" #include <cassert> -#include <map> -#include <string_view> using namespace OpenVic; using namespace OpenVic::NodeTools; diff --git a/src/openvic-simulation/map/Building.hpp b/src/openvic-simulation/map/Building.hpp index d9b9e5e..d36dfd4 100644 --- a/src/openvic-simulation/map/Building.hpp +++ b/src/openvic-simulation/map/Building.hpp @@ -73,7 +73,7 @@ namespace OpenVic { struct BuildingManager { private: - IdentifierRegistry<BuildingType> building_types; // TODO: This needs a getter + IdentifierRegistry<BuildingType> building_types; public: BuildingManager(); diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index d74c6cf..d51233b 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -63,8 +63,8 @@ PopType::PopType(const std::string_view new_identifier, colour_t new_colour, is_artisan { new_is_artisan }, is_slave { new_is_slave } { assert(sprite > 0); - assert(max_size > 0); - assert(merge_max_size > 0); + assert(max_size >= 0); + assert(merge_max_size >= 0); } PopType::sprite_t PopType::get_sprite() const { @@ -131,11 +131,11 @@ bool PopManager::add_pop_type(const std::string_view identifier, colour_t colour Logger::error("Invalid pop type sprite index for ", identifier, ": ", sprite); return false; } - if (max_size <= 0) { + if (max_size < 0) { Logger::error("Invalid pop type max size for ", identifier, ": ", max_size); return false; } - if (merge_max_size <= 0) { + if (merge_max_size < 0) { Logger::error("Invalid pop type merge max size for ", identifier, ": ", merge_max_size); return false; } @@ -146,11 +146,11 @@ bool PopManager::add_pop_type(const std::string_view identifier, colour_t colour * POP-3, POP-4, POP-5, POP-6, POP-7, POP-8, POP-9, POP-10, POP-11, POP-12, POP-13, POP-14 */ bool PopManager::load_pop_type_file(const std::string_view filestem, ast::NodeCPtr root) { - colour_t colour; - PopType::strata_t strata; - PopType::sprite_t sprite; + colour_t colour = NULL_COLOUR; + PopType::strata_t strata = PopType::strata_t::POOR; + PopType::sprite_t sprite = 0; bool state_capital_only = false, is_artisan = false, is_slave = false, demote_migrant = false; - Pop::pop_size_t max_size, merge_max_size; + Pop::pop_size_t max_size = 0, merge_max_size = 0; bool ret = expect_dictionary_keys( "sprite", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("poptype sprite", sprite)), "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index f5606f2..414c96d 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -171,6 +171,14 @@ namespace OpenVic { return items; } + std::vector<std::string_view> get_item_identifiers() const { + std::vector<std::string_view> identifiers; + identifiers.reserve(items.size()); + for (identifier_index_map_t::value_type const& entry : identifier_index_map) { + identifiers.push_back(entry.first); + } + } + NodeTools::node_callback_t expect_item_identifier(NodeTools::callback_t<T&> callback) { return NodeTools::expect_identifier( [this, callback](std::string_view identifier) -> bool { @@ -238,6 +246,8 @@ namespace OpenVic { return plural.size(); } \ std::vector<type> const& get_##plural() const { \ return plural.get_items(); } \ + std::vector<std::string_view> get_##singular##_identifiers() const { \ + return plural.get_item_identifiers(); } \ NodeTools::node_callback_t expect_##singular##_identifier(NodeTools::callback_t<type const&> callback) const { \ return plural.expect_item_identifier(callback); } \ NodeTools::node_callback_t expect_##singular##_dictionary(NodeTools::callback_t<type const&, ast::NodeCPtr> callback) const { \ |