diff options
author | zaaarf <zaaarf@proton.me> | 2023-09-28 15:40:34 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-09-28 15:40:34 +0200 |
commit | c541a249247b7fe3bdd4c62bce6638e875790f8a (patch) | |
tree | 8fe3545142245d287839728e561d3131fcc30157 /src/openvic-simulation/map/Building.cpp | |
parent | 7a8ac1cdb8e71a4166393ac06b1b60512db0ef8c (diff) |
feat: implemented building loading and missing parameters
Diffstat (limited to 'src/openvic-simulation/map/Building.cpp')
-rw-r--r-- | src/openvic-simulation/map/Building.cpp | 112 |
1 files changed, 102 insertions, 10 deletions
diff --git a/src/openvic-simulation/map/Building.cpp b/src/openvic-simulation/map/Building.cpp index f4b5034..29ee354 100644 --- a/src/openvic-simulation/map/Building.cpp +++ b/src/openvic-simulation/map/Building.cpp @@ -5,17 +5,19 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -Building::Building(std::string_view identifier, ARGS) : HasIdentifier { identifier }, type { type }, on_completion { on_completion }, - completion_size { completion_size }, max_level { max_level }, build_cost { build_cost }, build_time { build_time }, visibility { visibility }, on_map { on_map }, - default_enabled { default_enabled }, production_type { production_type }, pop_build_factory { pop_build_factory }, strategic_factory { strategic_factory }, - fort_level { fort_level }, naval_capacity { naval_capacity }, colonial_points { colonial_points }, in_province { in_province }, one_per_state { one_per_state }, - colonial_range { colonial_range }, infrastructure { infrastructure }, movement_cost { movement_cost }, spawn_railway_track { spawn_railway_track } {} +Building::Building(std::string_view identifier, ARGS) : HasIdentifier { identifier }, ModifierValue { std::move(modifiers) }, type { type }, + on_completion { on_completion }, completion_size { completion_size }, max_level { max_level }, goods_cost { goods_cost }, cost { cost }, build_time { build_time }, + visibility { visibility }, on_map { on_map }, default_enabled { default_enabled }, production_type { production_type }, pop_build_factory { pop_build_factory }, + strategic_factory { strategic_factory }, advanced_factory { advanced_factory }, fort_level { fort_level }, naval_capacity { naval_capacity }, + colonial_points { colonial_points }, in_province { in_province }, one_per_state { one_per_state }, colonial_range { colonial_range }, + infrastructure { infrastructure }, movement_cost { movement_cost }, local_ship_build { local_ship_build }, spawn_railway_track { spawn_railway_track }, + sail { sail }, steam { steam }, capital { capital }, port { port } {} BuildingType const& Building::get_type() const { return type; } -Building::sound_t Building::get_on_completion() const { +std::string_view Building::get_on_completion() const { return on_completion; } @@ -27,8 +29,12 @@ Building::level_t Building::get_max_level() const { return max_level; } -std::map<const Good*, fixed_point_t> const& Building::get_build_cost() const { - return build_cost; +std::map<const Good*, fixed_point_t> const& Building::get_goods_cost() const { + return goods_cost; +} + +fixed_point_t Building::get_cost() const { + return cost; } Timespan Building::get_build_time() const { @@ -59,6 +65,10 @@ bool Building::is_strategic_factory() const { return strategic_factory; } +bool Building::is_advanced_factory() const { + return advanced_factory; +} + Building::level_t Building::get_fort_level() const { return fort_level; } @@ -79,7 +89,7 @@ bool Building::is_one_per_state() const { return one_per_state; } -uint64_t Building::get_colonial_range() const { +fixed_point_t Building::get_colonial_range() const { return colonial_range; } @@ -174,6 +184,88 @@ bool BuildingManager::add_building_type(const std::string_view identifier) { return building_types.add_item({ identifier }); } +bool BuildingManager::add_building(std::string_view identifier, ARGS) { + if (identifier.empty()) { + Logger::error("Invalid building identifier - empty!"); + return false; + } + + return buildings.add_item({ + identifier, type, on_completion, completion_size, max_level, goods_cost, cost, build_time, visibility, on_map, default_enabled, + production_type, pop_build_factory, strategic_factory, advanced_factory, fort_level, naval_capacity, colonial_points, in_province, one_per_state, + colonial_range, infrastructure, movement_cost, local_ship_build, spawn_railway_track, sail, steam, capital, port, std::move(modifiers) + }); +} + +bool BuildingManager::load_buildings_file(GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root) { + bool ret = expect_dictionary([this, &good_manager, &production_type_manager, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { + std::string_view type, on_completion = "", production_type; + fixed_point_t completion_size = 0, cost = 0, infrastructure = 0, movement_cost = 0, colonial_range = 0, local_ship_build = 0; + Building::level_t max_level, fort_level = 0; + std::map<const Good*, fixed_point_t> goods_cost; + uint32_t build_days; + bool visibility, on_map, default_enabled, pop_build_factory, strategic_factory, advanced_factory, in_province, one_per_state, spawn_railway_track, sail, steam, capital, port; + default_enabled = pop_build_factory = strategic_factory = advanced_factory = in_province = one_per_state = spawn_railway_track = sail = steam = capital = port = false; + uint64_t naval_capacity = 0; + std::vector<uint64_t> colonial_points; + ModifierValue modifiers; + + bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(modifiers), + "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)), + "goods_cost", ONE_EXACTLY, good_manager.expect_good_decimal_map(assign_variable_callback(goods_cost)), + "cost", ZERO_OR_MORE, expect_fixed_point(assign_variable_callback(cost)), + "time", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("building build time", build_days)), + "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, expect_identifier(assign_variable_callback(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("building fort level", fort_level)), + "naval_capacity", ZERO_OR_ONE, expect_uint(assign_variable_callback_uint("building naval capacity", naval_capacity)), + "colonial_points", ZERO_OR_ONE, expect_list(expect_uint([&colonial_points](uint64_t points) -> bool { + return colonial_points.emplace_back(points); + })), "province", ZERO_OR_ONE, expect_bool(assign_variable_callback(in_province)), + "one_per_state", ZERO_OR_ONE, expect_bool(assign_variable_callback(one_per_state)), + "colonial_range", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(colonial_range)), + "infrastructure", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(infrastructure)), + "movement_cost", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(movement_cost)), + "local_ship_build", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(local_ship_build)), + "spawn_railway_track", ZERO_OR_ONE, expect_bool(assign_variable_callback(spawn_railway_track)), + "sail", ZERO_OR_ONE, expect_bool(assign_variable_callback(sail)), + "steam", ZERO_OR_ONE, expect_bool(assign_variable_callback(steam)), + "capital", ZERO_OR_ONE, expect_bool(assign_variable_callback(capital)), + "port", ZERO_OR_ONE, expect_bool(assign_variable_callback(port)) + )(value); + + BuildingType const* type_ref = building_types.get_item_by_identifier(type); + if (type_ref == nullptr) { + building_types.add_item({ type }); + type_ref = building_types.get_item_by_identifier(type); + } + + Timespan build_time = Timespan(build_days); + + ProductionType const* production_type_ref = production_type_manager.get_production_type_by_identifier(production_type); + + ret &= add_building( + key, *type_ref, on_completion, completion_size, max_level, goods_cost, cost, build_time, visibility, on_map, default_enabled, + production_type_ref, pop_build_factory, strategic_factory, advanced_factory, fort_level, naval_capacity, colonial_points, in_province, + one_per_state, colonial_range, infrastructure, movement_cost, local_ship_build, spawn_railway_track, sail, steam, capital, port, std::move(modifiers) + ); + + return ret; + })(root); + lock_building_types(); + lock_buildings(); + + return ret; +} + bool BuildingManager::generate_province_buildings(Province& province) const { province.reset_buildings(); if (!building_types.is_locked()) { @@ -188,4 +280,4 @@ bool BuildingManager::generate_province_buildings(Province& province) const { } province.lock_buildings(); return ret; -}
\ No newline at end of file +} |