From 37cdd775ac738b2a1264e32471385376e5a34f3a Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 3 Jun 2024 23:39:34 +0100 Subject: Province const/mutable separation + State cleanup --- src/openvic-simulation/military/Deployment.cpp | 27 ++++++++++++---------- src/openvic-simulation/military/Deployment.hpp | 29 ++++++++++++++++-------- src/openvic-simulation/military/UnitInstance.cpp | 13 ++++++----- src/openvic-simulation/military/UnitInstance.hpp | 28 ++++++++++++++++------- 4 files changed, 61 insertions(+), 36 deletions(-) (limited to 'src/openvic-simulation/military') diff --git a/src/openvic-simulation/military/Deployment.cpp b/src/openvic-simulation/military/Deployment.cpp index 1f8b820..4550108 100644 --- a/src/openvic-simulation/military/Deployment.cpp +++ b/src/openvic-simulation/military/Deployment.cpp @@ -5,18 +5,19 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; -RegimentDeployment::RegimentDeployment(std::string_view new_name, RegimentType const& new_type, Province const* new_home) - : name { new_name }, type { new_type }, home { new_home } {} +RegimentDeployment::RegimentDeployment( + std::string_view new_name, RegimentType const& new_type, ProvinceDefinition const* new_home +) : name { new_name }, type { new_type }, home { new_home } {} ShipDeployment::ShipDeployment(std::string_view new_name, ShipType const& new_type) : name { new_name }, type { new_type } {} ArmyDeployment::ArmyDeployment( - std::string_view new_name, Province const* new_location, std::vector&& new_regiments + std::string_view new_name, ProvinceDefinition const* new_location, std::vector&& new_regiments ) : name { new_name }, location { new_location }, regiments { std::move(new_regiments) } {} NavyDeployment::NavyDeployment( - std::string_view new_name, Province const* new_location, std::vector&& new_ships + std::string_view new_name, ProvinceDefinition const* new_location, std::vector&& new_ships ) : name { new_name }, location { new_location }, ships { std::move(new_ships) } {} Deployment::Deployment( @@ -120,24 +121,25 @@ 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; + ProvinceDefinition const* army_location = nullptr; std::vector army_regiments {}; const bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(army_name)), - "location", ONE_EXACTLY, - game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(army_location)), + "location", ONE_EXACTLY, game_manager.get_map().expect_province_definition_identifier( + assign_variable_callback_pointer(army_location) + ), "regiment", ONE_OR_MORE, [&game_manager, &army_regiments](ast::NodeCPtr node) -> bool { std::string_view regiment_name {}; RegimentType const* regiment_type = nullptr; - Province const* regiment_home = nullptr; + ProvinceDefinition 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_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)) + .expect_province_definition_identifier(assign_variable_callback_pointer(regiment_home)) )(node); if (regiment_home == nullptr) { @@ -163,13 +165,14 @@ 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; + ProvinceDefinition const* navy_location = nullptr; std::vector navy_ships {}; const bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(navy_name)), - "location", ONE_EXACTLY, - game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(navy_location)), + "location", ONE_EXACTLY, game_manager.get_map().expect_province_definition_identifier( + assign_variable_callback_pointer(navy_location) + ), "ship", ONE_OR_MORE, [&game_manager, &navy_ships](ast::NodeCPtr node) -> bool { std::string_view ship_name {}; ShipType const* ship_type = nullptr; diff --git a/src/openvic-simulation/military/Deployment.hpp b/src/openvic-simulation/military/Deployment.hpp index 8966397..6f4c21f 100644 --- a/src/openvic-simulation/military/Deployment.hpp +++ b/src/openvic-simulation/military/Deployment.hpp @@ -4,26 +4,30 @@ #include #include -#include "openvic-simulation/dataloader/Dataloader.hpp" -#include "openvic-simulation/map/Province.hpp" #include "openvic-simulation/military/Leader.hpp" -#include "openvic-simulation/military/UnitType.hpp" +#include "openvic-simulation/types/HasIdentifier.hpp" +#include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { + struct ProvinceDefinition; + struct RegimentType; + struct RegimentDeployment { friend struct DeploymentManager; private: std::string PROPERTY(name); RegimentType const& PROPERTY(type); - Province const* PROPERTY(home); + ProvinceDefinition const* PROPERTY(home); - RegimentDeployment(std::string_view new_name, RegimentType const& new_type, Province const* new_home); + RegimentDeployment(std::string_view new_name, RegimentType const& new_type, ProvinceDefinition const* new_home); public: RegimentDeployment(RegimentDeployment&&) = default; }; + struct ShipType; + struct ShipDeployment { friend struct DeploymentManager; @@ -42,11 +46,11 @@ namespace OpenVic { private: std::string PROPERTY(name); - Province const* PROPERTY(location); + ProvinceDefinition const* PROPERTY(location); std::vector PROPERTY(regiments); ArmyDeployment( - std::string_view new_name, Province const* new_location, std::vector&& new_regiments + std::string_view new_name, ProvinceDefinition const* new_location, std::vector&& new_regiments ); public: @@ -58,10 +62,12 @@ namespace OpenVic { private: std::string PROPERTY(name); - Province const* PROPERTY(location); + ProvinceDefinition const* PROPERTY(location); std::vector PROPERTY(ships); - NavyDeployment(std::string_view new_name, Province const* new_location, std::vector&& new_ships); + NavyDeployment( + std::string_view new_name, ProvinceDefinition const* new_location, std::vector&& new_ships + ); public: NavyDeployment(NavyDeployment&&) = default; @@ -84,6 +90,9 @@ namespace OpenVic { Deployment(Deployment&&) = default; }; + struct GameManager; + class Dataloader; + struct DeploymentManager { private: IdentifierRegistry IDENTIFIER_REGISTRY(deployment); @@ -102,4 +111,4 @@ namespace OpenVic { size_t get_missing_oob_file_count() const; }; -} // namespace OpenVic +} diff --git a/src/openvic-simulation/military/UnitInstance.cpp b/src/openvic-simulation/military/UnitInstance.cpp index fcb9e3b..1cd0813 100644 --- a/src/openvic-simulation/military/UnitInstance.cpp +++ b/src/openvic-simulation/military/UnitInstance.cpp @@ -4,7 +4,8 @@ #include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/map/Map.hpp" -#include "openvic-simulation/military/UnitType.hpp" +#include "openvic-simulation/map/ProvinceInstance.hpp" +#include "openvic-simulation/military/Deployment.hpp" using namespace OpenVic; @@ -17,7 +18,7 @@ ShipInstance::ShipInstance(std::string_view new_name, ShipType const& new_ship_t MovementInfo::MovementInfo() : path {}, movement_progress {} {} //TODO: pathfinding logic -MovementInfo::MovementInfo(Province const* starting_province, Province const* target_province) +MovementInfo::MovementInfo(ProvinceInstance const* starting_province, ProvinceInstance const* target_province) : path { starting_province, target_province }, movement_progress { 0 } {} ArmyInstance::ArmyInstance( @@ -27,7 +28,7 @@ ArmyInstance::ArmyInstance( CountryInstance* new_country ) : UnitInstanceGroup { new_name, UnitType::branch_t::LAND, std::move(new_units), new_leader, new_country } {} -void ArmyInstance::set_position(Province* new_position) { +void ArmyInstance::set_position(ProvinceInstance* new_position) { if (position != new_position) { if (position != nullptr) { position->remove_army(*this); @@ -46,7 +47,7 @@ NavyInstance::NavyInstance( CountryInstance* new_country ) : UnitInstanceGroup { new_name, UnitType::branch_t::NAVAL, std::move(new_units), new_leader, new_country } {} -void NavyInstance::set_position(Province* new_position) { +void NavyInstance::set_position(ProvinceInstance* new_position) { if (position != new_position) { if (position != nullptr) { position->remove_navy(*this); @@ -116,7 +117,7 @@ bool UnitInstanceManager::generate_army(Map& map, CountryInstance& country, Army armies.push_back({ army_deployment.get_name(), std::move(army_regiments), nullptr, &country }); - armies.back().set_position(map.remove_province_const(army_deployment.get_location())); + armies.back().set_position(map.get_province_instance_from_const(army_deployment.get_location())); return ret; } @@ -162,7 +163,7 @@ bool UnitInstanceManager::generate_navy(Map& map, CountryInstance& country, Navy navies.push_back({ navy_deployment.get_name(), std::move(navy_ships), nullptr, &country }); - navies.back().set_position(map.remove_province_const(navy_deployment.get_location())); + navies.back().set_position(map.get_province_instance_from_const(navy_deployment.get_location())); return ret; } diff --git a/src/openvic-simulation/military/UnitInstance.hpp b/src/openvic-simulation/military/UnitInstance.hpp index e3d541a..a3a53d0 100644 --- a/src/openvic-simulation/military/UnitInstance.hpp +++ b/src/openvic-simulation/military/UnitInstance.hpp @@ -1,14 +1,14 @@ #pragma once #include +#include #include #include -#include "openvic-simulation/map/Province.hpp" -#include "openvic-simulation/military/Deployment.hpp" #include "openvic-simulation/military/Leader.hpp" #include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" +#include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { template T> @@ -37,6 +37,8 @@ namespace OpenVic { } }; + struct Pop; + struct RegimentInstance : UnitInstance { friend struct UnitInstanceManager; @@ -59,14 +61,17 @@ namespace OpenVic { ShipInstance(ShipInstance&&) = default; }; + struct ProvinceInstance; + struct MovementInfo { private: - std::vector PROPERTY(path); + std::vector PROPERTY(path); fixed_point_t PROPERTY(movement_progress); public: MovementInfo(); - MovementInfo(Province const* starting_province, Province const* target_province); // contains/calls pathfinding logic + // contains/calls pathfinding logic + MovementInfo(ProvinceInstance const* starting_province, ProvinceInstance const* target_province); }; struct CountryInstance; @@ -82,7 +87,7 @@ namespace OpenVic { MovementInfo PROPERTY_REF(movement_info); protected: - Province* PROPERTY_ACCESS(position, protected); + ProvinceInstance* PROPERTY_ACCESS(position, protected); CountryInstance* PROPERTY_ACCESS(country, protected); UnitInstanceGroup( @@ -140,7 +145,7 @@ namespace OpenVic { )->first; } - virtual void set_position(Province* new_position) = 0; + virtual void set_position(ProvinceInstance* new_position) = 0; }; struct ArmyInstance : UnitInstanceGroup { @@ -157,7 +162,7 @@ namespace OpenVic { public: ArmyInstance(ArmyInstance&&) = default; - void set_position(Province* new_position) override; + void set_position(ProvinceInstance* new_position) override; }; struct NavyInstance : UnitInstanceGroup { @@ -176,9 +181,16 @@ namespace OpenVic { public: NavyInstance(NavyInstance&&) = default; - void set_position(Province* new_position) override; + void set_position(ProvinceInstance* new_position) override; }; + struct RegimentDeployment; + struct ShipDeployment; + struct Map; + struct ArmyDeployment; + struct NavyDeployment; + struct Deployment; + struct UnitInstanceManager { private: std::deque PROPERTY(regiments); -- cgit v1.2.3-56-ga3b1