diff options
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/Building.cpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/map/Building.hpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/map/Map.cpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/map/Map.hpp | 10 | ||||
-rw-r--r-- | src/openvic-simulation/map/Province.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/TerrainType.cpp | 105 | ||||
-rw-r--r-- | src/openvic-simulation/map/TerrainType.hpp | 6 |
7 files changed, 63 insertions, 83 deletions
diff --git a/src/openvic-simulation/map/Building.cpp b/src/openvic-simulation/map/Building.cpp index 6f4c099..d27c91a 100644 --- a/src/openvic-simulation/map/Building.cpp +++ b/src/openvic-simulation/map/Building.cpp @@ -229,22 +229,22 @@ bool BuildingManager::load_buildings_file(GoodManager const& good_manager, Produ ModifierValue modifiers; bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifiers), - "type", ONE_EXACTLY, expect_building_type_identifier(assign_variable_callback_pointer(type)), + "type", ONE_EXACTLY, expect_identifier(expect_building_type_identifier(assign_variable_callback_pointer(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_uint(max_level)), + "max_level", ONE_EXACTLY, expect_uint(assign_variable_callback(max_level)), "goods_cost", ONE_EXACTLY, good_manager.expect_good_decimal_map(move_variable_callback(goods_cost)), "cost", ZERO_OR_MORE, expect_fixed_point(assign_variable_callback(cost)), - "time", ONE_EXACTLY, expect_timespan(assign_variable_callback(build_time)), + "time", ONE_EXACTLY, expect_days(assign_variable_callback(build_time)), "visibility", ONE_EXACTLY, expect_bool(assign_variable_callback(visibility)), "onmap", ONE_EXACTLY, expect_bool(assign_variable_callback(on_map)), "default_enabled", ZERO_OR_ONE, expect_bool(assign_variable_callback(default_enabled)), - "production_type", ZERO_OR_ONE, production_type_manager.expect_production_type_identifier(assign_variable_callback_pointer(production_type)), + "production_type", ZERO_OR_ONE, expect_identifier(production_type_manager.expect_production_type_identifier(assign_variable_callback_pointer(production_type))), "pop_build_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(pop_build_factory)), "strategic_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(strategic_factory)), "advanced_factory", ZERO_OR_ONE, expect_bool(assign_variable_callback(advanced_factory)), - "fort_level", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint(fort_level)), - "naval_capacity", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint(naval_capacity)), + "fort_level", ZERO_OR_ONE, expect_uint(assign_variable_callback(fort_level)), + "naval_capacity", ZERO_OR_ONE, expect_uint(assign_variable_callback(naval_capacity)), "colonial_points", ZERO_OR_ONE, expect_list(expect_fixed_point([&colonial_points](fixed_point_t points) -> bool { colonial_points.push_back(points); return true; diff --git a/src/openvic-simulation/map/Building.hpp b/src/openvic-simulation/map/Building.hpp index 9b445bf..3f74c3d 100644 --- a/src/openvic-simulation/map/Building.hpp +++ b/src/openvic-simulation/map/Building.hpp @@ -27,7 +27,7 @@ namespace OpenVic { struct Building : HasIdentifier, ModifierValue { friend struct BuildingManager; - using level_t = int8_t; + using level_t = int16_t; private: BuildingType const& type; @@ -162,10 +162,10 @@ namespace OpenVic { BuildingManager(); bool add_building_type(std::string_view identifier); - IDENTIFIER_REGISTRY_ACCESSORS(BuildingType, building_type) + IDENTIFIER_REGISTRY_ACCESSORS(building_type) bool add_building(std::string_view identifier, BuildingType const* type, ARGS); - IDENTIFIER_REGISTRY_ACCESSORS(Building, building) + IDENTIFIER_REGISTRY_ACCESSORS(building) bool load_buildings_file(GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root); diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 386e7be..8362ff4 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -78,11 +78,16 @@ bool Map::set_water_province(std::string_view identifier) { } bool Map::set_water_province_list(std::vector<std::string_view> const& list) { + if (water_provinces.is_locked()) { + Logger::error("The map's water provinces have already been locked!"); + return false; + } bool ret = true; water_provinces.reserve(water_provinces.size() + list.size()); for (std::string_view const& identifier : list) { ret &= set_water_province(identifier); } + lock_water_provinces(); return ret; } diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp index 9c97960..a959158 100644 --- a/src/openvic-simulation/map/Map.hpp +++ b/src/openvic-simulation/map/Map.hpp @@ -70,8 +70,8 @@ namespace OpenVic { Map(); bool add_province(std::string_view identifier, colour_t colour); - IDENTIFIER_REGISTRY_ACCESSORS(Province, province) - IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(Province, province) + IDENTIFIER_REGISTRY_ACCESSORS(province) + IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(province) bool set_water_province(std::string_view identifier); bool set_water_province_list(std::vector<std::string_view> const& list); @@ -93,11 +93,11 @@ namespace OpenVic { TerrainTypeManager const& get_terrain_type_manager() const; bool add_region(std::string_view identifier, std::vector<std::string_view> const& province_identifiers); - IDENTIFIER_REGISTRY_ACCESSORS(Region, region) - IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(Region, region) + IDENTIFIER_REGISTRY_ACCESSORS(region) + IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(region) bool add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func); - IDENTIFIER_REGISTRY_ACCESSORS(Mapmode, mapmode) + IDENTIFIER_REGISTRY_ACCESSORS(mapmode) Mapmode const* get_mapmode_by_index(size_t index) const; static constexpr size_t MAPMODE_COLOUR_SIZE = 4; bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const; diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index 31b5d4c..c9b29ea 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -93,7 +93,7 @@ namespace OpenVic { bool load_positions(BuildingManager const& building_manager, ast::NodeCPtr root); bool add_building(BuildingInstance&& building_instance); - IDENTIFIER_REGISTRY_ACCESSORS(BuildingInstance, building) + IDENTIFIER_REGISTRY_ACCESSORS(building) void reset_buildings(); bool expand_building(std::string_view building_type_identifier); Good const* get_rgo() const; diff --git a/src/openvic-simulation/map/TerrainType.cpp b/src/openvic-simulation/map/TerrainType.cpp index 2438df6..ce0b7e7 100644 --- a/src/openvic-simulation/map/TerrainType.cpp +++ b/src/openvic-simulation/map/TerrainType.cpp @@ -49,7 +49,7 @@ bool TerrainTypeManager::add_terrain_type(std::string_view identifier, colour_t bool TerrainTypeManager::add_terrain_type_mapping(std::string_view identifier, TerrainType const* type, std::vector<TerrainTypeMapping::index_t>&& terrain_indicies, TerrainTypeMapping::index_t priority, bool has_texture) { - if (!terrain_types.is_locked()) { + if (!terrain_types_are_locked()) { Logger::error("Cannot register terrain type mappings until terrain types are locked!"); return false; } @@ -76,48 +76,53 @@ bool TerrainTypeManager::add_terrain_type_mapping(std::string_view identifier, T return ret; } -bool TerrainTypeManager::_load_terrain_type_categories(ModifierManager const& modifier_manager, ast::NodeCPtr root) { - const bool ret = expect_dictionary_reserve_length(terrain_types, - [this, &modifier_manager](std::string_view type_key, ast::NodeCPtr type_node) -> bool { - ModifierValue values; - colour_t colour = NULL_COLOUR; - bool is_water = false; - bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values), - "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), - "is_water", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_water)) - )(type_node); - ret &= add_terrain_type(type_key, colour, std::move(values), is_water); - return ret; - } - )(root); - terrain_types.lock(); - return ret; +node_callback_t TerrainTypeManager::_load_terrain_type_categories(ModifierManager const& modifier_manager) { + return [this, &modifier_manager](ast::NodeCPtr root) -> bool { + const bool ret = expect_dictionary_reserve_length(terrain_types, + [this, &modifier_manager](std::string_view type_key, ast::NodeCPtr type_node) -> bool { + ModifierValue values; + colour_t colour = NULL_COLOUR; + bool is_water = false; + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(values), + "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), + "is_water", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_water)) + )(type_node); + ret &= add_terrain_type(type_key, colour, std::move(values), is_water); + return ret; + } + )(root); + lock_terrain_types(); + return ret; + }; } bool TerrainTypeManager::_load_terrain_type_mapping(std::string_view mapping_key, ast::NodeCPtr mapping_value) { + if (terrain_texture_limit <= 0) { + Logger::error("Cannot define terrain type mapping before terrain texture limit: ", mapping_key); + return false; + } + if (!terrain_types_are_locked()) { + Logger::error("Cannot define terrain type mapping before categories: ", mapping_key); + return false; + } TerrainType const* type = nullptr; std::vector<TerrainTypeMapping::index_t> terrain_indicies; TerrainTypeMapping::index_t priority = 0; bool has_texture = true; bool ret = expect_dictionary_keys( - "type", ONE_EXACTLY, expect_terrain_type_identifier(assign_variable_callback_pointer(type)), - "color", ONE_EXACTLY, expect_list_reserve_length(terrain_indicies, expect_uint( - [&terrain_indicies](uint64_t val) -> bool { - if (val <= std::numeric_limits<TerrainTypeMapping::index_t>::max()) { - TerrainTypeMapping::index_t index = val; - if (std::find(terrain_indicies.begin(), terrain_indicies.end(), index) == terrain_indicies.end()) { - terrain_indicies.push_back(val); - return true; - } - Logger::error("Repeat terrain type mapping index: ", val); - return false; + "type", ONE_EXACTLY, expect_identifier(expect_terrain_type_identifier(assign_variable_callback_pointer(type))), + "color", ONE_EXACTLY, expect_list_reserve_length(terrain_indicies, expect_uint<TerrainTypeMapping::index_t>( + [&terrain_indicies](TerrainTypeMapping::index_t val) -> bool { + if (std::find(terrain_indicies.begin(), terrain_indicies.end(), val) == terrain_indicies.end()) { + terrain_indicies.push_back(val); + return true; } - Logger::error("Index too big for terrain type mapping index: ", val); + Logger::error("Repeat terrain type mapping index: ", val); return false; } )), - "priority", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint(priority)), + "priority", ZERO_OR_ONE, expect_uint(assign_variable_callback(priority)), "has_texture", ZERO_OR_ONE, expect_bool(assign_variable_callback(has_texture)) )(mapping_value); if (has_texture) { @@ -143,45 +148,15 @@ TerrainTypeMapping::index_t TerrainTypeManager::get_terrain_texture_limit() cons } bool TerrainTypeManager::load_terrain_types(ModifierManager const& modifier_manager, ast::NodeCPtr root) { - bool terrain = false, categories = false; - bool ret = expect_dictionary_and_length( + const bool ret = expect_dictionary_keys_and_length_and_default( [this](size_t size) -> size_t { terrain_type_mappings.reserve(size - 2); return size; }, - [this, &terrain, &categories, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { - if (key == "terrain") { - if (!terrain) { - terrain = true; - return expect_uint(assign_variable_callback_uint(terrain_texture_limit))(value); - } else { - Logger::error("Duplicate terrain key!"); - return false; - } - } else if (key == "categories") { - if (!categories) { - categories = true; - return _load_terrain_type_categories(modifier_manager, value); - } else { - Logger::error("Duplicate categories key!"); - return false; - } - } else if (terrain && categories) { - return _load_terrain_type_mapping(key, value); - } else { - Logger::error("Cannot define terrain type mapping before terrain and categories keys: ", key); - return false; - } - } + std::bind(&TerrainTypeManager::_load_terrain_type_mapping, this, std::placeholders::_1, std::placeholders::_2), + "terrain", ONE_EXACTLY, expect_uint(assign_variable_callback(terrain_texture_limit)), + "categories", ONE_EXACTLY, _load_terrain_type_categories(modifier_manager) )(root); - if (!terrain) { - Logger::error("Missing expected key: \"terrain\""); - ret = false; - } - if (!categories) { - Logger::error("Missing expected key: \"categories\""); - ret = false; - } - terrain_type_mappings.lock(); + lock_terrain_type_mappings(); return ret; } diff --git a/src/openvic-simulation/map/TerrainType.hpp b/src/openvic-simulation/map/TerrainType.hpp index 3b491ae..1353130 100644 --- a/src/openvic-simulation/map/TerrainType.hpp +++ b/src/openvic-simulation/map/TerrainType.hpp @@ -50,18 +50,18 @@ namespace OpenVic { TerrainTypeMapping::index_t terrain_texture_limit = 0, terrain_texture_count = 0; - bool _load_terrain_type_categories(ModifierManager const& modifier_manager, ast::NodeCPtr root); + NodeTools::node_callback_t _load_terrain_type_categories(ModifierManager const& modifier_manager); bool _load_terrain_type_mapping(std::string_view key, ast::NodeCPtr value); public: TerrainTypeManager(); bool add_terrain_type(std::string_view identifier, colour_t colour, ModifierValue&& values, bool is_water); - IDENTIFIER_REGISTRY_ACCESSORS(TerrainType, terrain_type) + IDENTIFIER_REGISTRY_ACCESSORS(terrain_type) bool add_terrain_type_mapping(std::string_view identifier, TerrainType const* type, std::vector<TerrainTypeMapping::index_t>&& terrain_indicies, TerrainTypeMapping::index_t priority, bool has_texture); - IDENTIFIER_REGISTRY_ACCESSORS(TerrainTypeMapping, terrain_type_mapping) + IDENTIFIER_REGISTRY_ACCESSORS(terrain_type_mapping) TerrainTypeMapping const* get_terrain_type_mapping_for(TerrainTypeMapping::index_t idx) const; |