diff options
Diffstat (limited to 'extension/src/openvic2/map/Building.cpp')
-rw-r--r-- | extension/src/openvic2/map/Building.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/extension/src/openvic2/map/Building.cpp b/extension/src/openvic2/map/Building.cpp index f453a0f..00e121b 100644 --- a/extension/src/openvic2/map/Building.cpp +++ b/extension/src/openvic2/map/Building.cpp @@ -3,10 +3,11 @@ #include <cassert> #include "openvic2/Logger.hpp" +#include "openvic2/map/Province.hpp" using namespace OpenVic2; -Building::Building(BuildingType const& new_type) : type{ new_type } {} +Building::Building(BuildingType const& new_type) : HasIdentifier{ new_type.get_identifier() }, type{ new_type } {} bool Building::_can_expand() const { return level < type.get_max_level(); @@ -45,6 +46,9 @@ return_t Building::expand() { return FAILURE; } +/* REQUIREMENTS: + * MAP-71, MAP-74, MAP-77 + */ void Building::update_state(Date const& today) { switch (expansion_state) { case ExpansionState::Preparing: @@ -84,13 +88,11 @@ Timespan BuildingType::get_build_time() const { return build_time; } +BuildingManager::BuildingManager() : building_types{ "building types" } {} + return_t BuildingManager::add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time) { - if (building_types_locked) { - Logger::error("The building type list has already been locked!"); - return FAILURE; - } if (identifier.empty()) { - Logger::error("Empty building type identifier!"); + Logger::error("Invalid building type identifier - empty!"); return FAILURE; } if (max_level < 0) { @@ -101,29 +103,22 @@ return_t BuildingManager::add_building_type(std::string const& identifier, Build Logger::error("Invalid building type build time: ", build_time); return FAILURE; } - BuildingType new_building_type{ identifier, max_level, build_time }; - BuildingType const* old_building_type = get_building_type_by_identifier(identifier); - if (old_building_type != nullptr) { - Logger::error("Duplicate building type identifiers: ", old_building_type->get_identifier(), " and ", identifier); - return FAILURE; - } - building_types.push_back(new_building_type); - return SUCCESS; + return building_types.add_item({ identifier, max_level, build_time }); } void BuildingManager::lock_building_types() { - building_types_locked = true; - Logger::info("Locked building types after registering ", building_types.size()); + building_types.lock(); } BuildingType const* BuildingManager::get_building_type_by_identifier(std::string const& identifier) const { - if (!identifier.empty()) - for (BuildingType const& building_type : building_types) - if (building_type.get_identifier() == identifier) return &building_type; - return nullptr; + return building_types.get_item_by_identifier(identifier); } -void BuildingManager::generate_province_buildings(std::vector<Building>& buildings) const { - for (BuildingType const& type : building_types) - buildings.push_back(Building{ type }); +return_t BuildingManager::generate_province_buildings(Province& province) const { + return_t ret = SUCCESS; + province.reset_buildings(); + for (BuildingType const& type : building_types.get_items()) + if (province.add_building(type) != SUCCESS) ret = FAILURE; + province.lock_buildings(); + return ret; } |