From 023860d53a90774dcdba84ad7c0dca3c944c9a49 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Mon, 12 Feb 2024 12:15:04 +0100 Subject: feat: unit instance type definition, renamed existing structs for consistency --- src/openvic-simulation/military/Deployment.cpp | 44 +++++++++++--------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'src/openvic-simulation/military/Deployment.cpp') diff --git a/src/openvic-simulation/military/Deployment.cpp b/src/openvic-simulation/military/Deployment.cpp index 4e2693d..903df3a 100644 --- a/src/openvic-simulation/military/Deployment.cpp +++ b/src/openvic-simulation/military/Deployment.cpp @@ -5,31 +5,25 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -Leader::Leader( - std::string_view new_name, Unit::branch_t new_branch, Date new_date, LeaderTrait const* new_personality, - LeaderTrait const* new_background, fixed_point_t new_prestige, std::string_view new_picture -) : name { new_name }, branch { new_branch }, date { new_date }, personality { new_personality }, background { new_background }, - prestige { new_prestige }, picture { new_picture } {} - -Regiment::Regiment(std::string_view new_name, LandUnit const* new_type, Province const* new_home) +RegimentDeployment::RegimentDeployment(std::string_view new_name, RegimentType const* new_type, Province const* new_home) : name { new_name }, type { new_type }, home { new_home } {} -Ship::Ship(std::string_view new_name, NavalUnit const* new_type) : name { new_name }, type { new_type } {} +ShipDeployment::ShipDeployment(std::string_view new_name, ShipType const* new_type) : name { new_name }, type { new_type } {} -Army::Army(std::string_view new_name, Province const* new_location, std::vector&& new_regiments) +ArmyDeployment::ArmyDeployment(std::string_view new_name, Province const* new_location, std::vector&& new_regiments) : name { new_name }, location { new_location }, regiments { std::move(new_regiments) } {} -Navy::Navy(std::string_view new_name, Province const* new_location, std::vector&& new_ships) +NavyDeployment::NavyDeployment(std::string_view new_name, Province const* new_location, std::vector&& new_ships) : name { new_name }, location { new_location }, ships { std::move(new_ships) } {} Deployment::Deployment( - std::string_view new_path, std::vector&& new_armies, std::vector&& new_navies, + std::string_view new_path, std::vector&& new_armies, std::vector&& new_navies, std::vector&& new_leaders ) : HasIdentifier { new_path }, armies { std::move(new_armies) }, navies { std::move(new_navies) }, leaders { std::move(new_leaders) } {} bool DeploymentManager::add_deployment( - std::string_view path, std::vector&& armies, std::vector&& navies, std::vector&& leaders + std::string_view path, std::vector&& armies, std::vector&& navies, std::vector&& leaders ) { if (path.empty()) { Logger::error("Attemped to load order of battle with no path! Something is very wrong!"); @@ -64,14 +58,14 @@ bool DeploymentManager::load_oob_file( return true; } } - std::vector armies; - std::vector navies; + std::vector armies; + std::vector navies; std::vector leaders; bool ret = expect_dictionary_keys_and_default( key_value_success_callback, // TODO: load SOI information "leader", ZERO_OR_MORE, [&leaders, &game_manager](ast::NodeCPtr node) -> bool { std::string_view leader_name {}; - Unit::branch_t leader_branch = Unit::branch_t::INVALID_BRANCH; + UnitType::branch_t leader_branch = UnitType::branch_t::INVALID_BRANCH; Date leader_date {}; LeaderTrait const* leader_personality = nullptr; LeaderTrait const* leader_background = nullptr; @@ -81,7 +75,7 @@ bool DeploymentManager::load_oob_file( bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(leader_name)), "date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(leader_date)), - "type", ONE_EXACTLY, UnitManager::expect_branch_identifier(assign_variable_callback(leader_branch)), + "type", ONE_EXACTLY, UnitTypeManager::expect_branch_identifier(assign_variable_callback(leader_branch)), "personality", ONE_EXACTLY, game_manager.get_military_manager().get_leader_trait_manager().expect_leader_trait_identifier_or_string( assign_variable_callback_pointer(leader_personality) @@ -116,7 +110,7 @@ bool DeploymentManager::load_oob_file( "army", ZERO_OR_MORE, [&armies, &game_manager](ast::NodeCPtr node) -> bool { std::string_view army_name {}; Province const* army_location = nullptr; - std::vector army_regiments {}; + std::vector army_regiments {}; const bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(army_name)), @@ -124,17 +118,17 @@ bool DeploymentManager::load_oob_file( game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(army_location)), "regiment", ONE_OR_MORE, [&game_manager, &army_regiments](ast::NodeCPtr node) -> bool { std::string_view regiment_name {}; - LandUnit const* regiment_type = nullptr; + RegimentType const* regiment_type = nullptr; Province const* regiment_home = nullptr; const bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(regiment_name)), - "type", ONE_EXACTLY, game_manager.get_military_manager().get_unit_manager() - .expect_land_unit_identifier(assign_variable_callback_pointer(regiment_type)), + "type", ONE_EXACTLY, game_manager.get_military_manager().get_unit_type_manager() + .expect_regiment_type_identifier(assign_variable_callback_pointer(regiment_type)), "home", ZERO_OR_ONE, game_manager.get_map() .expect_province_identifier(assign_variable_callback_pointer(regiment_home)) )(node); if (regiment_home == nullptr) { - Logger::warning("Regiment ", regiment_name, " has no home province!"); + Logger::warning("RegimentDeployment ", regiment_name, " has no home province!"); } army_regiments.emplace_back(regiment_name, regiment_type, regiment_home); return ret; @@ -148,7 +142,7 @@ bool DeploymentManager::load_oob_file( "navy", ZERO_OR_MORE, [&navies, &game_manager](ast::NodeCPtr node) -> bool { std::string_view navy_name {}; Province const* navy_location = nullptr; - std::vector navy_ships {}; + std::vector navy_ships {}; const bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(navy_name)), @@ -156,11 +150,11 @@ bool DeploymentManager::load_oob_file( game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(navy_location)), "ship", ONE_OR_MORE, [&game_manager, &navy_ships](ast::NodeCPtr node) -> bool { std::string_view ship_name {}; - NavalUnit const* ship_type = nullptr; + ShipType const* ship_type = nullptr; const bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(ship_name)), - "type", ONE_EXACTLY, game_manager.get_military_manager().get_unit_manager() - .expect_naval_unit_identifier(assign_variable_callback_pointer(ship_type)) + "type", ONE_EXACTLY, game_manager.get_military_manager().get_unit_type_manager() + .expect_ship_type_identifier(assign_variable_callback_pointer(ship_type)) )(node); navy_ships.emplace_back(ship_name, ship_type); return ret; -- cgit v1.2.3-56-ga3b1