aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/military')
-rw-r--r--src/openvic-simulation/military/Deployment.cpp27
-rw-r--r--src/openvic-simulation/military/Deployment.hpp29
-rw-r--r--src/openvic-simulation/military/UnitInstance.cpp13
-rw-r--r--src/openvic-simulation/military/UnitInstance.hpp28
4 files changed, 61 insertions, 36 deletions
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<RegimentDeployment>&& new_regiments
+ std::string_view new_name, ProvinceDefinition const* new_location, std::vector<RegimentDeployment>&& 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<ShipDeployment>&& new_ships
+ std::string_view new_name, ProvinceDefinition const* new_location, std::vector<ShipDeployment>&& 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<RegimentDeployment> 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<ShipDeployment> 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 <string_view>
#include <vector>
-#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<RegimentDeployment> PROPERTY(regiments);
ArmyDeployment(
- std::string_view new_name, Province const* new_location, std::vector<RegimentDeployment>&& new_regiments
+ std::string_view new_name, ProvinceDefinition const* new_location, std::vector<RegimentDeployment>&& new_regiments
);
public:
@@ -58,10 +62,12 @@ namespace OpenVic {
private:
std::string PROPERTY(name);
- Province const* PROPERTY(location);
+ ProvinceDefinition const* PROPERTY(location);
std::vector<ShipDeployment> PROPERTY(ships);
- NavyDeployment(std::string_view new_name, Province const* new_location, std::vector<ShipDeployment>&& new_ships);
+ NavyDeployment(
+ std::string_view new_name, ProvinceDefinition const* new_location, std::vector<ShipDeployment>&& new_ships
+ );
public:
NavyDeployment(NavyDeployment&&) = default;
@@ -84,6 +90,9 @@ namespace OpenVic {
Deployment(Deployment&&) = default;
};
+ struct GameManager;
+ class Dataloader;
+
struct DeploymentManager {
private:
IdentifierRegistry<Deployment> 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 <concepts>
+#include <string>
#include <string_view>
#include <vector>
-#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<std::derived_from<UnitType> T>
@@ -37,6 +37,8 @@ namespace OpenVic {
}
};
+ struct Pop;
+
struct RegimentInstance : UnitInstance<RegimentType> {
friend struct UnitInstanceManager;
@@ -59,14 +61,17 @@ namespace OpenVic {
ShipInstance(ShipInstance&&) = default;
};
+ struct ProvinceInstance;
+
struct MovementInfo {
private:
- std::vector<Province const*> PROPERTY(path);
+ std::vector<ProvinceInstance const*> 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<RegimentInstance> {
@@ -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<ShipInstance> {
@@ -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<RegimentInstance> PROPERTY(regiments);