aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-03-20 23:30:48 +0100
committer GitHub <noreply@github.com>2024-03-20 23:30:48 +0100
commiteece77afebf0e4d36b4c9ace3b1044f2c3da50f1 (patch)
treed5b186facf7c3a08e6ccf2e8261b7de054957a41 /src/openvic-simulation
parent2c892c99a6647be15ef23cabf6cc40f08769283d (diff)
parent023860d53a90774dcdba84ad7c0dca3c944c9a49 (diff)
Merge pull request #147 from OpenVicProject/military-units
Military unit instance
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r--src/openvic-simulation/country/Country.cpp4
-rw-r--r--src/openvic-simulation/country/Country.hpp4
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp18
-rw-r--r--src/openvic-simulation/military/Deployment.cpp44
-rw-r--r--src/openvic-simulation/military/Deployment.hpp70
-rw-r--r--src/openvic-simulation/military/Leader.cpp9
-rw-r--r--src/openvic-simulation/military/Leader.hpp23
-rw-r--r--src/openvic-simulation/military/MilitaryManager.hpp4
-rw-r--r--src/openvic-simulation/military/UnitInstance.cpp31
-rw-r--r--src/openvic-simulation/military/UnitInstance.hpp110
-rw-r--r--src/openvic-simulation/military/UnitType.cpp (renamed from src/openvic-simulation/military/Unit.cpp)210
-rw-r--r--src/openvic-simulation/military/UnitType.hpp (renamed from src/openvic-simulation/military/Unit.hpp)82
-rw-r--r--src/openvic-simulation/pop/Pop.cpp6
-rw-r--r--src/openvic-simulation/pop/Pop.hpp10
-rw-r--r--src/openvic-simulation/research/Invention.cpp8
-rw-r--r--src/openvic-simulation/research/Invention.hpp8
-rw-r--r--src/openvic-simulation/research/Technology.cpp6
-rw-r--r--src/openvic-simulation/research/Technology.hpp6
18 files changed, 400 insertions, 253 deletions
diff --git a/src/openvic-simulation/country/Country.cpp b/src/openvic-simulation/country/Country.cpp
index 2b022b0..604e11f 100644
--- a/src/openvic-simulation/country/Country.cpp
+++ b/src/openvic-simulation/country/Country.cpp
@@ -196,9 +196,9 @@ bool CountryManager::load_country_data_file(
),
"party", ZERO_OR_MORE, load_country_party(game_manager.get_politics_manager(), parties),
"unit_names", ZERO_OR_ONE,
- game_manager.get_military_manager().get_unit_manager().expect_unit_dictionary_reserve_length(
+ game_manager.get_military_manager().get_unit_type_manager().expect_unit_type_dictionary_reserve_length(
unit_names,
- [&unit_names](Unit const& unit, ast::NodeCPtr value) -> bool {
+ [&unit_names](UnitType const& unit, ast::NodeCPtr value) -> bool {
return name_list_callback(map_callback(unit_names, &unit))(value);
}
)
diff --git a/src/openvic-simulation/country/Country.hpp b/src/openvic-simulation/country/Country.hpp
index fd6fa7e..f115489 100644
--- a/src/openvic-simulation/country/Country.hpp
+++ b/src/openvic-simulation/country/Country.hpp
@@ -10,7 +10,7 @@
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
#include "openvic-simulation/dataloader/Dataloader.hpp"
-#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
#include "openvic-simulation/politics/Government.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/politics/Issue.hpp"
@@ -51,7 +51,7 @@ namespace OpenVic {
struct Country : HasIdentifierAndColour {
friend struct CountryManager;
- using unit_names_map_t = ordered_map<Unit const*, name_list_t>;
+ using unit_names_map_t = ordered_map<UnitType const*, name_list_t>;
using government_colour_map_t = ordered_map<GovernmentType const*, colour_t>;
private:
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 9df9725..d01f6ff 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -358,16 +358,16 @@ bool Dataloader::_load_pop_types(GameManager& game_manager) {
bool Dataloader::_load_units(GameManager& game_manager) const {
static constexpr std::string_view units_directory = "units";
- UnitManager& unit_manager = game_manager.get_military_manager().get_unit_manager();
+ UnitTypeManager& unit_type_manager = game_manager.get_military_manager().get_unit_type_manager();
const path_vector_t unit_files = lookup_files_in_dir(units_directory, ".txt");
- unit_manager.reserve_all_units(unit_files.size());
+ unit_type_manager.reserve_all_unit_types(unit_files.size());
bool ret = apply_to_files(
unit_files,
- [&game_manager, &unit_manager](fs::path const& file) -> bool {
- return unit_manager.load_unit_file(
+ [&game_manager, &unit_type_manager](fs::path const& file) -> bool {
+ return unit_type_manager.load_unit_type_file(
game_manager.get_economy_manager().get_good_manager(),
game_manager.get_map().get_terrain_type_manager(),
game_manager.get_modifier_manager(),
@@ -376,9 +376,9 @@ bool Dataloader::_load_units(GameManager& game_manager) const {
}
);
- unit_manager.lock_all_units();
+ unit_type_manager.lock_all_unit_types();
- if (!unit_manager.generate_modifiers(game_manager.get_modifier_manager())) {
+ if (!unit_type_manager.generate_modifiers(game_manager.get_modifier_manager())) {
Logger::error("Failed to generate unit-based modifiers!");
ret = false;
}
@@ -449,7 +449,7 @@ bool Dataloader::_load_technologies(GameManager& game_manager) {
[this, &game_manager, &technology_manager, &modifier_manager](fs::path const& file) -> bool {
return technology_manager.load_technologies_file(
modifier_manager,
- game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_military_manager().get_unit_type_manager(),
game_manager.get_economy_manager().get_building_type_manager(),
parse_defines_cached(file).get_file_node()
);
@@ -476,7 +476,7 @@ bool Dataloader::_load_inventions(GameManager& game_manager) {
[this, &game_manager, &invention_manager](fs::path const& file) -> bool {
return invention_manager.load_inventions_file(
game_manager.get_modifier_manager(),
- game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_military_manager().get_unit_type_manager(),
game_manager.get_economy_manager().get_building_type_manager(),
game_manager.get_crime_manager(),
parse_defines_cached(file).get_file_node()
@@ -932,7 +932,7 @@ bool Dataloader::load_defines(GameManager& game_manager) {
ret = false;
}
if (!game_manager.get_pop_manager().load_delayed_parse_pop_type_data(
- game_manager.get_military_manager().get_unit_manager(),
+ game_manager.get_military_manager().get_unit_type_manager(),
game_manager.get_politics_manager().get_issue_manager()
)) {
Logger::error("Failed to load delayed parse pop type data (promotion and issue weights)!");
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<Regiment>&& new_regiments)
+ArmyDeployment::ArmyDeployment(std::string_view new_name, Province const* new_location, std::vector<RegimentDeployment>&& 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<Ship>&& new_ships)
+NavyDeployment::NavyDeployment(std::string_view new_name, Province const* new_location, std::vector<ShipDeployment>&& new_ships)
: name { new_name }, location { new_location }, ships { std::move(new_ships) } {}
Deployment::Deployment(
- std::string_view new_path, std::vector<Army>&& new_armies, std::vector<Navy>&& new_navies,
+ std::string_view new_path, std::vector<ArmyDeployment>&& new_armies, std::vector<NavyDeployment>&& new_navies,
std::vector<Leader>&& 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<Army>&& armies, std::vector<Navy>&& navies, std::vector<Leader>&& leaders
+ std::string_view path, std::vector<ArmyDeployment>&& armies, std::vector<NavyDeployment>&& navies, std::vector<Leader>&& 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<Army> armies;
- std::vector<Navy> navies;
+ std::vector<ArmyDeployment> armies;
+ std::vector<NavyDeployment> navies;
std::vector<Leader> 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<Regiment> army_regiments {};
+ std::vector<RegimentDeployment> 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<Ship> navy_ships {};
+ std::vector<ShipDeployment> 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;
diff --git a/src/openvic-simulation/military/Deployment.hpp b/src/openvic-simulation/military/Deployment.hpp
index e774108..742914d 100644
--- a/src/openvic-simulation/military/Deployment.hpp
+++ b/src/openvic-simulation/military/Deployment.hpp
@@ -5,82 +5,62 @@
#include <vector>
#include "openvic-simulation/dataloader/Dataloader.hpp"
-#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/map/Province.hpp"
-#include "openvic-simulation/military/LeaderTrait.hpp"
-#include "openvic-simulation/military/Unit.hpp"
-#include "openvic-simulation/types/Date.hpp"
-#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+#include "openvic-simulation/military/Leader.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
namespace OpenVic {
- struct Leader {
+ struct RegimentDeployment {
private:
- std::string PROPERTY(name);
- Unit::branch_t PROPERTY(branch); /* type in defines */
- Date PROPERTY(date);
- LeaderTrait const* PROPERTY(personality);
- LeaderTrait const* PROPERTY(background);
- fixed_point_t PROPERTY(prestige);
- std::string PROPERTY(picture);
-
- public:
- 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
- );
- };
-
- struct Regiment {
- private:
- std::string PROPERTY(name);
- LandUnit const* PROPERTY(type);
+ std::string PROPERTY(name);
+ RegimentType const* PROPERTY(type);
Province const* PROPERTY(home);
public:
- Regiment(std::string_view new_name, LandUnit const* new_type, Province const* new_home);
+ RegimentDeployment(std::string_view new_name, RegimentType const* new_type, Province const* new_home);
};
- struct Ship {
+ struct ShipDeployment {
private:
- std::string PROPERTY(name);
- NavalUnit const* PROPERTY(type);
+ std::string PROPERTY(name);
+ ShipType const* PROPERTY(type);
public:
- Ship(std::string_view new_name, NavalUnit const* new_type);
+ ShipDeployment(std::string_view new_name, ShipType const* new_type);
};
- struct Army {
+ struct ArmyDeployment {
private:
- std::string PROPERTY(name);
- Province const* PROPERTY(location);
- std::vector<Regiment> PROPERTY(regiments);
+ std::string PROPERTY(name);
+ Province const* PROPERTY(location);
+ std::vector<RegimentDeployment> PROPERTY(regiments);
public:
- Army(std::string_view new_name, Province const* new_location, std::vector<Regiment>&& new_regiments);
+ ArmyDeployment(std::string_view new_name, Province const* new_location, std::vector<RegimentDeployment>&& new_regiments);
};
- struct Navy {
+ struct NavyDeployment {
private:
- std::string PROPERTY(name);
- Province const* PROPERTY(location);
- std::vector<Ship> PROPERTY(ships);
+ std::string PROPERTY(name);
+ Province const* PROPERTY(location);
+ std::vector<ShipDeployment> PROPERTY(ships);
public:
- Navy(std::string_view new_name, Province const* new_location, std::vector<Ship>&& new_ships);
+ NavyDeployment(std::string_view new_name, Province const* new_location, std::vector<ShipDeployment>&& new_ships);
};
struct Deployment : HasIdentifier {
friend std::unique_ptr<Deployment> std::make_unique<Deployment>(
- std::string_view&&, std::vector<OpenVic::Army>&&, std::vector<OpenVic::Navy>&&, std::vector<OpenVic::Leader>&&
+ std::string_view&&, std::vector<OpenVic::ArmyDeployment>&&, std::vector<OpenVic::NavyDeployment>&&, std::vector<OpenVic::Leader>&&
);
private:
- std::vector<Army> PROPERTY(armies);
- std::vector<Navy> PROPERTY(navies);
+ std::vector<ArmyDeployment> PROPERTY(armies);
+ std::vector<NavyDeployment> PROPERTY(navies);
std::vector<Leader> PROPERTY(leaders);
Deployment(
- std::string_view new_path, std::vector<Army>&& new_armies, std::vector<Navy>&& new_navies,
+ std::string_view new_path, std::vector<ArmyDeployment>&& new_armies, std::vector<NavyDeployment>&& new_navies,
std::vector<Leader>&& new_leaders
);
@@ -95,7 +75,7 @@ namespace OpenVic {
public:
bool add_deployment(
- std::string_view path, std::vector<Army>&& armies, std::vector<Navy>&& navies, std::vector<Leader>&& leaders
+ std::string_view path, std::vector<ArmyDeployment>&& armies, std::vector<NavyDeployment>&& navies, std::vector<Leader>&& leaders
);
bool load_oob_file(
diff --git a/src/openvic-simulation/military/Leader.cpp b/src/openvic-simulation/military/Leader.cpp
new file mode 100644
index 0000000..d6be36f
--- /dev/null
+++ b/src/openvic-simulation/military/Leader.cpp
@@ -0,0 +1,9 @@
+#include "Leader.hpp"
+
+using namespace OpenVic;
+
+Leader::Leader(
+ std::string_view new_name, UnitType::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 } {} \ No newline at end of file
diff --git a/src/openvic-simulation/military/Leader.hpp b/src/openvic-simulation/military/Leader.hpp
new file mode 100644
index 0000000..180fd39
--- /dev/null
+++ b/src/openvic-simulation/military/Leader.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "openvic-simulation/military/LeaderTrait.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
+
+namespace OpenVic {
+ struct Leader {
+ private:
+ std::string PROPERTY(name);
+ UnitType::branch_t PROPERTY(branch); /* type in defines */
+ Date PROPERTY(date);
+ LeaderTrait const* PROPERTY(personality);
+ LeaderTrait const* PROPERTY(background);
+ fixed_point_t PROPERTY(prestige);
+ std::string PROPERTY(picture);
+
+ public:
+ Leader(
+ std::string_view new_name, UnitType::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
+ );
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/military/MilitaryManager.hpp b/src/openvic-simulation/military/MilitaryManager.hpp
index 2efa3ea..343d789 100644
--- a/src/openvic-simulation/military/MilitaryManager.hpp
+++ b/src/openvic-simulation/military/MilitaryManager.hpp
@@ -2,13 +2,13 @@
#include "openvic-simulation/military/Deployment.hpp"
#include "openvic-simulation/military/LeaderTrait.hpp"
-#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
#include "openvic-simulation/military/Wargoal.hpp"
namespace OpenVic {
struct MilitaryManager {
private:
- UnitManager PROPERTY_REF(unit_manager);
+ UnitTypeManager PROPERTY_REF(unit_type_manager);
LeaderTraitManager PROPERTY_REF(leader_trait_manager);
DeploymentManager PROPERTY_REF(deployment_manager);
WargoalTypeManager PROPERTY_REF(wargoal_type_manager);
diff --git a/src/openvic-simulation/military/UnitInstance.cpp b/src/openvic-simulation/military/UnitInstance.cpp
new file mode 100644
index 0000000..7927b0f
--- /dev/null
+++ b/src/openvic-simulation/military/UnitInstance.cpp
@@ -0,0 +1,31 @@
+#include "UnitInstance.hpp"
+#include <vector>
+#include "openvic-simulation/military/UnitType.hpp"
+
+using namespace OpenVic;
+
+RegimentInstance::RegimentInstance(std::string_view new_name, RegimentType const& new_regiment_type, Pop& new_pop)
+ : UnitInstance { new_name, new_regiment_type }, pop { new_pop } {}
+
+ShipInstance::ShipInstance(std::string_view new_name, ShipType const& new_ship_type)
+ : UnitInstance { new_name, new_ship_type } {}
+
+MovementInfo::MovementInfo() : path {}, movement_progress {} {}
+
+//TODO: pathfinding logic
+MovementInfo::MovementInfo(Province const* starting_province, Province const* target_province)
+ : path { std::vector { starting_province, target_province } }, movement_progress { 0 } {}
+
+ArmyInstance::ArmyInstance(
+ std::string_view new_name,
+ std::vector<RegimentInstance*>&& new_units,
+ Leader const* new_leader,
+ Province const* new_position
+) : UnitInstanceGroup { new_name, UnitType::branch_t::LAND, std::move(new_units), new_leader, new_position } {}
+
+NavyInstance::NavyInstance(
+ std::string_view new_name,
+ std::vector<ShipInstance*>&& new_units,
+ Leader const* new_leader,
+ Province const* new_position
+) : UnitInstanceGroup { new_name, UnitType::branch_t::NAVAL, std::move(new_units), new_leader, new_position } {} \ No newline at end of file
diff --git a/src/openvic-simulation/military/UnitInstance.hpp b/src/openvic-simulation/military/UnitInstance.hpp
new file mode 100644
index 0000000..dcca18a
--- /dev/null
+++ b/src/openvic-simulation/military/UnitInstance.hpp
@@ -0,0 +1,110 @@
+#pragma once
+
+#include <concepts>
+#include <string_view>
+#include <vector>
+#include "openvic-simulation/map/Province.hpp"
+#include "openvic-simulation/military/Leader.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+
+namespace OpenVic {
+ template<std::derived_from<UnitType> T>
+ struct UnitInstance {
+ protected:
+ std::string PROPERTY(unit_name);
+ T const& PROPERTY(unit_type); //can't change
+
+ fixed_point_t PROPERTY_RW(organisation);
+ fixed_point_t PROPERTY_RW(morale);
+ fixed_point_t PROPERTY_RW(strength);
+
+ protected:
+ UnitInstance(std::string_view new_unit_name, T const& new_unit_type) :
+ unit_name { new_unit_name },
+ unit_type { new_unit_type },
+ organisation { new_unit_type.get_default_organisation() }, //TODO: modifiers
+ morale { 0 }, //TODO: modifiers
+ strength { new_unit_type.get_max_strength() } {}
+ public:
+ void set_unit_name(std::string_view new_unit_name) {
+ unit_name = new_unit_name;
+ }
+ };
+
+ struct RegimentInstance : UnitInstance<RegimentType> {
+ private:
+ Pop& PROPERTY(pop);
+
+ public:
+ RegimentInstance(std::string_view new_name, RegimentType const& new_regiment_type, Pop& new_pop);
+ };
+
+ struct ShipInstance : UnitInstance<ShipType> {
+ public:
+ ShipInstance(std::string_view new_name, ShipType const& new_ship_type);
+ };
+
+ struct MovementInfo {
+ private:
+ std::vector<Province const*> PROPERTY(path);
+ fixed_point_t PROPERTY(movement_progress);
+
+ public:
+ MovementInfo();
+ MovementInfo(Province const* starting_province, Province const* target_province); // contains/calls pathfinding logic
+ };
+
+ template<utility::is_derived_from_specialization_of<UnitInstance> I>
+ struct UnitInstanceGroup {
+ private:
+ std::string PROPERTY(name);
+ const UnitType::branch_t PROPERTY(branch);
+ std::vector<I*> PROPERTY(units);
+ Leader const* PROPERTY_RW(leader);
+ Province const* PROPERTY_RW(position);
+
+ MovementInfo PROPERTY_REF(movement_info);
+
+ protected:
+ UnitInstanceGroup(
+ std::string_view new_name,
+ UnitType::branch_t new_branch,
+ std::vector<I*>&& new_units,
+ Leader const* new_leader,
+ Province const* new_position
+ ) : name { new_name },
+ branch { new_branch },
+ units { std::move(new_units) },
+ leader { new_leader },
+ position { new_position } {}
+
+ public:
+ void set_name(std::string_view new_name) {
+ name = new_name;
+ }
+ };
+
+ struct ArmyInstance : UnitInstanceGroup<RegimentInstance> {
+ public:
+ ArmyInstance(
+ std::string_view new_name,
+ std::vector<RegimentInstance*>&& new_units,
+ Leader const* new_leader,
+ Province const* new_position
+ );
+ };
+
+ struct NavyInstance : UnitInstanceGroup<ShipInstance> {
+ private:
+ std::vector<ArmyInstance const*> PROPERTY(carried_armies);
+
+ public:
+ NavyInstance(
+ std::string_view new_name,
+ std::vector<ShipInstance*>&& new_ships,
+ Leader const* new_leader,
+ Province const* new_position
+ );
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/military/Unit.cpp b/src/openvic-simulation/military/UnitType.cpp
index 54fc763..1fafe35 100644
--- a/src/openvic-simulation/military/Unit.cpp
+++ b/src/openvic-simulation/military/UnitType.cpp
@@ -1,21 +1,21 @@
-#include "Unit.hpp"
+#include "UnitType.hpp"
#include "openvic-simulation/map/TerrainType.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
-using enum Unit::branch_t;
-using enum Unit::unit_type_t;
+using enum UnitType::branch_t;
+using enum UnitType::unit_category_t;
-Unit::Unit(
- std::string_view new_identifier, branch_t new_branch, unit_args_t& unit_args
+UnitType::UnitType(
+ std::string_view new_identifier, branch_t new_branch, unit_type_args_t& unit_args
) : HasIdentifier { new_identifier },
branch { new_branch },
icon { unit_args.icon },
sprite { unit_args.sprite },
active { unit_args.active },
- unit_type { unit_args.unit_type },
+ unit_category { unit_args.unit_category },
floating_flag { unit_args.floating_flag },
priority { unit_args.priority },
max_strength { unit_args.max_strength },
@@ -30,52 +30,52 @@ Unit::Unit(
supply_cost { std::move(unit_args.supply_cost) },
terrain_modifiers { std::move(unit_args.terrain_modifiers) } {}
-LandUnit::LandUnit(
- std::string_view new_identifier, unit_args_t& unit_args, land_unit_args_t const& land_unit_args
-) : Unit { new_identifier, LAND, unit_args },
- allowed_cultures { land_unit_args.allowed_cultures },
- sprite_override { land_unit_args.sprite_override },
- sprite_mount { land_unit_args.sprite_mount },
- sprite_mount_attach_node { land_unit_args.sprite_mount_attach_node },
- reconnaissance { land_unit_args.reconnaissance },
- attack { land_unit_args.attack },
- defence { land_unit_args.defence },
- discipline { land_unit_args.discipline },
- support { land_unit_args.support },
- maneuver { land_unit_args.maneuver },
- siege { land_unit_args.siege } {}
-
-NavalUnit::NavalUnit(
- std::string_view new_identifier, unit_args_t& unit_args, naval_unit_args_t const& naval_unit_args
-) : Unit { new_identifier, NAVAL, unit_args },
- naval_icon { naval_unit_args.naval_icon },
- sail { naval_unit_args.sail },
- transport { naval_unit_args.transport },
- capital { naval_unit_args.capital },
- colonial_points { naval_unit_args.colonial_points },
- build_overseas { naval_unit_args.build_overseas },
- min_port_level { naval_unit_args.min_port_level },
- limit_per_port { naval_unit_args.limit_per_port },
- supply_consumption_score { naval_unit_args.supply_consumption_score },
- hull { naval_unit_args.hull },
- gun_power { naval_unit_args.gun_power },
- fire_range { naval_unit_args.fire_range },
- evasion { naval_unit_args.evasion },
- torpedo_attack { naval_unit_args.torpedo_attack } {}
-
-void UnitManager::reserve_all_units(size_t size) {
- reserve_more_units(size);
- reserve_more_land_units(size);
- reserve_more_naval_units(size);
+RegimentType::RegimentType(
+ std::string_view new_identifier, unit_type_args_t& unit_args, regiment_type_args_t const& regiment_type_args
+) : UnitType { new_identifier, LAND, unit_args },
+ allowed_cultures { regiment_type_args.allowed_cultures },
+ sprite_override { regiment_type_args.sprite_override },
+ sprite_mount { regiment_type_args.sprite_mount },
+ sprite_mount_attach_node { regiment_type_args.sprite_mount_attach_node },
+ reconnaissance { regiment_type_args.reconnaissance },
+ attack { regiment_type_args.attack },
+ defence { regiment_type_args.defence },
+ discipline { regiment_type_args.discipline },
+ support { regiment_type_args.support },
+ maneuver { regiment_type_args.maneuver },
+ siege { regiment_type_args.siege } {}
+
+ShipType::ShipType(
+ std::string_view new_identifier, unit_type_args_t& unit_args, ship_type_args_t const& ship_type_args
+) : UnitType { new_identifier, NAVAL, unit_args },
+ naval_icon { ship_type_args.naval_icon },
+ sail { ship_type_args.sail },
+ transport { ship_type_args.transport },
+ capital { ship_type_args.capital },
+ colonial_points { ship_type_args.colonial_points },
+ build_overseas { ship_type_args.build_overseas },
+ min_port_level { ship_type_args.min_port_level },
+ limit_per_port { ship_type_args.limit_per_port },
+ supply_consumption_score { ship_type_args.supply_consumption_score },
+ hull { ship_type_args.hull },
+ gun_power { ship_type_args.gun_power },
+ fire_range { ship_type_args.fire_range },
+ evasion { ship_type_args.evasion },
+ torpedo_attack { ship_type_args.torpedo_attack } {}
+
+void UnitTypeManager::reserve_all_unit_types(size_t size) {
+ reserve_more_unit_types(size);
+ reserve_more_regiment_types(size);
+ reserve_more_ship_types(size);
}
-void UnitManager::lock_all_units() {
- units.lock();
- land_units.lock();
- naval_units.lock();
+void UnitTypeManager::lock_all_unit_types() {
+ unit_types.lock();
+ regiment_types.lock();
+ ship_types.lock();
}
-static bool _check_shared_parameters(std::string_view identifier, Unit::unit_args_t const& unit_args) {
+static bool _check_shared_parameters(std::string_view identifier, UnitType::unit_type_args_t const& unit_args) {
if (identifier.empty()) {
Logger::error("Invalid unit identifier - empty!");
return false;
@@ -86,7 +86,7 @@ static bool _check_shared_parameters(std::string_view identifier, Unit::unit_arg
return false;
}
- if (unit_args.unit_type == INVALID_UNIT_TYPE) {
+ if (unit_args.unit_category == INVALID_UNIT_CATEGORY) {
Logger::error("Invalid unit type for unit ", identifier, "!");
return false;
}
@@ -96,8 +96,8 @@ static bool _check_shared_parameters(std::string_view identifier, Unit::unit_arg
return true;
}
-bool UnitManager::add_land_unit(
- std::string_view identifier, Unit::unit_args_t& unit_args, LandUnit::land_unit_args_t const& land_unit_args
+bool UnitTypeManager::add_regiment_type(
+ std::string_view identifier, UnitType::unit_type_args_t& unit_args, RegimentType::regiment_type_args_t const& regiment_type_args
) {
if (!_check_shared_parameters(identifier, unit_args)) {
return false;
@@ -105,47 +105,47 @@ bool UnitManager::add_land_unit(
// TODO check that sprite_override, sprite_mount, and sprite_mount_attach_node exist
- if (naval_units.has_identifier(identifier)) {
+ if (ship_types.has_identifier(identifier)) {
Logger::error("Land unit ", identifier, " already exists as a naval unit!");
return false;
}
- bool ret = land_units.add_item({ identifier, unit_args, std::move(land_unit_args) });
+ bool ret = regiment_types.add_item({ identifier, unit_args, std::move(regiment_type_args) });
if (ret) {
- ret &= units.add_item(&land_units.get_items().back());
+ ret &= unit_types.add_item(&regiment_types.get_items().back());
}
return ret;
}
-bool UnitManager::add_naval_unit(
- std::string_view identifier, Unit::unit_args_t& unit_args, NavalUnit::naval_unit_args_t const& naval_unit_args
+bool UnitTypeManager::add_ship_type(
+ std::string_view identifier, UnitType::unit_type_args_t& unit_args, ShipType::ship_type_args_t const& ship_type_args
) {
if (!_check_shared_parameters(identifier, unit_args)) {
return false;
}
- if (naval_unit_args.naval_icon <= 0) {
- Logger::error("Invalid naval icon identifier - ", naval_unit_args.naval_icon, " (must be positive)");
+ if (ship_type_args.naval_icon <= 0) {
+ Logger::error("Invalid naval icon identifier - ", ship_type_args.naval_icon, " (must be positive)");
return false;
}
- if (naval_unit_args.supply_consumption_score <= 0) {
+ if (ship_type_args.supply_consumption_score <= 0) {
Logger::warning("Supply consumption score for ", identifier, " is not positive!");
}
- if (land_units.has_identifier(identifier)) {
+ if (regiment_types.has_identifier(identifier)) {
Logger::error("Naval unit ", identifier, " already exists as a land unit!");
return false;
}
- bool ret = naval_units.add_item({ identifier, unit_args, naval_unit_args });
+ bool ret = ship_types.add_item({ identifier, unit_args, ship_type_args });
if (ret) {
- ret &= units.add_item(&naval_units.get_items().back());
+ ret &= unit_types.add_item(&ship_types.get_items().back());
}
return ret;
}
-bool UnitManager::load_unit_file(
+bool UnitTypeManager::load_unit_type_file(
GoodManager const& good_manager, TerrainTypeManager const& terrain_type_manager, ModifierManager const& modifier_manager,
ast::NodeCPtr root
) {
@@ -153,7 +153,7 @@ bool UnitManager::load_unit_file(
std::string_view key, ast::NodeCPtr value
) -> bool {
- Unit::branch_t branch = INVALID_BRANCH;
+ UnitType::branch_t branch = INVALID_BRANCH;
bool ret = expect_key("type", expect_branch_identifier(assign_variable_callback(branch)))(value);
@@ -164,9 +164,9 @@ bool UnitManager::load_unit_file(
return false;
}
- Unit::unit_args_t unit_args {};
+ UnitType::unit_type_args_t unit_args {};
- static const string_map_t<Unit::unit_type_t> unit_type_map {
+ static const string_map_t<UnitType::unit_category_t> unit_type_map {
{ "infantry", INFANTRY },
{ "cavalry", CAVALRY },
{ "support", SUPPORT },
@@ -184,7 +184,7 @@ bool UnitManager::load_unit_file(
"sprite", ONE_EXACTLY, expect_identifier(assign_variable_callback(unit_args.sprite)),
"active", ZERO_OR_ONE, expect_bool(assign_variable_callback(unit_args.active)),
"unit_type", ONE_EXACTLY,
- expect_identifier(expect_mapped_string(unit_type_map, assign_variable_callback(unit_args.unit_type))),
+ expect_identifier(expect_mapped_string(unit_type_map, assign_variable_callback(unit_args.unit_category))),
"floating_flag", ONE_EXACTLY, expect_bool(assign_variable_callback(unit_args.floating_flag)),
"priority", ONE_EXACTLY, expect_uint(assign_variable_callback(unit_args.priority)),
"max_strength", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(unit_args.max_strength)),
@@ -214,64 +214,64 @@ bool UnitManager::load_unit_file(
switch (branch) {
case LAND: {
- LandUnit::land_unit_args_t land_unit_args {};
+ RegimentType::regiment_type_args_t regiment_type_args {};
bool is_restricted_to_primary_culture = false;
bool is_restricted_to_accepted_cultures = false;
ret &= add_key_map_entries(key_map,
"primary_culture", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_restricted_to_primary_culture)),
"accepted_culture", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_restricted_to_accepted_cultures)),
- "sprite_override", ZERO_OR_ONE, expect_identifier(assign_variable_callback(land_unit_args.sprite_override)),
- "sprite_mount", ZERO_OR_ONE, expect_identifier(assign_variable_callback(land_unit_args.sprite_mount)),
+ "sprite_override", ZERO_OR_ONE, expect_identifier(assign_variable_callback(regiment_type_args.sprite_override)),
+ "sprite_mount", ZERO_OR_ONE, expect_identifier(assign_variable_callback(regiment_type_args.sprite_mount)),
"sprite_mount_attach_node", ZERO_OR_ONE,
- expect_identifier(assign_variable_callback(land_unit_args.sprite_mount_attach_node)),
- "reconnaissance", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(land_unit_args.reconnaissance)),
- "attack", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(land_unit_args.attack)),
- "defence", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(land_unit_args.defence)),
- "discipline", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(land_unit_args.discipline)),
- "support", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(land_unit_args.support)),
- "maneuver", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(land_unit_args.maneuver)),
- "siege", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(land_unit_args.siege))
+ expect_identifier(assign_variable_callback(regiment_type_args.sprite_mount_attach_node)),
+ "reconnaissance", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(regiment_type_args.reconnaissance)),
+ "attack", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(regiment_type_args.attack)),
+ "defence", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(regiment_type_args.defence)),
+ "discipline", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(regiment_type_args.discipline)),
+ "support", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(regiment_type_args.support)),
+ "maneuver", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(regiment_type_args.maneuver)),
+ "siege", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(regiment_type_args.siege))
);
if (is_restricted_to_accepted_cultures) {
- land_unit_args.allowed_cultures = LandUnit::allowed_cultures_t::ACCEPTED_CULTURES;
+ regiment_type_args.allowed_cultures = RegimentType::allowed_cultures_t::ACCEPTED_CULTURES;
} else if (is_restricted_to_primary_culture) {
- land_unit_args.allowed_cultures = LandUnit::allowed_cultures_t::PRIMARY_CULTURE;
+ regiment_type_args.allowed_cultures = RegimentType::allowed_cultures_t::PRIMARY_CULTURE;
} else {
- land_unit_args.allowed_cultures = LandUnit::allowed_cultures_t::ALL_CULTURES;
+ regiment_type_args.allowed_cultures = RegimentType::allowed_cultures_t::ALL_CULTURES;
}
ret &= expect_dictionary_key_map_and_default(key_map, add_terrain_modifier)(value);
- ret &= add_land_unit(key, unit_args, land_unit_args);
+ ret &= add_regiment_type(key, unit_args, regiment_type_args);
return ret;
}
case NAVAL: {
- NavalUnit::naval_unit_args_t naval_unit_args {};
+ ShipType::ship_type_args_t ship_type_args {};
ret &= add_key_map_entries(key_map,
- "naval_icon", ONE_EXACTLY, expect_uint(assign_variable_callback(naval_unit_args.naval_icon)),
- "sail", ZERO_OR_ONE, expect_bool(assign_variable_callback(naval_unit_args.sail)),
- "transport", ZERO_OR_ONE, expect_bool(assign_variable_callback(naval_unit_args.transport)),
- "capital", ZERO_OR_ONE, expect_bool(assign_variable_callback(naval_unit_args.capital)),
- "colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(naval_unit_args.colonial_points)),
- "can_build_overseas", ZERO_OR_ONE, expect_bool(assign_variable_callback(naval_unit_args.build_overseas)),
- "min_port_level", ONE_EXACTLY, expect_uint(assign_variable_callback(naval_unit_args.min_port_level)),
- "limit_per_port", ONE_EXACTLY, expect_int(assign_variable_callback(naval_unit_args.limit_per_port)),
+ "naval_icon", ONE_EXACTLY, expect_uint(assign_variable_callback(ship_type_args.naval_icon)),
+ "sail", ZERO_OR_ONE, expect_bool(assign_variable_callback(ship_type_args.sail)),
+ "transport", ZERO_OR_ONE, expect_bool(assign_variable_callback(ship_type_args.transport)),
+ "capital", ZERO_OR_ONE, expect_bool(assign_variable_callback(ship_type_args.capital)),
+ "colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(ship_type_args.colonial_points)),
+ "can_build_overseas", ZERO_OR_ONE, expect_bool(assign_variable_callback(ship_type_args.build_overseas)),
+ "min_port_level", ONE_EXACTLY, expect_uint(assign_variable_callback(ship_type_args.min_port_level)),
+ "limit_per_port", ONE_EXACTLY, expect_int(assign_variable_callback(ship_type_args.limit_per_port)),
"supply_consumption_score", ZERO_OR_ONE,
- expect_fixed_point(assign_variable_callback(naval_unit_args.supply_consumption_score)),
- "hull", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(naval_unit_args.hull)),
- "gun_power", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(naval_unit_args.gun_power)),
- "fire_range", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(naval_unit_args.fire_range)),
- "evasion", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(naval_unit_args.evasion)),
- "torpedo_attack", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(naval_unit_args.torpedo_attack))
+ expect_fixed_point(assign_variable_callback(ship_type_args.supply_consumption_score)),
+ "hull", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(ship_type_args.hull)),
+ "gun_power", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(ship_type_args.gun_power)),
+ "fire_range", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(ship_type_args.fire_range)),
+ "evasion", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(ship_type_args.evasion)),
+ "torpedo_attack", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(ship_type_args.torpedo_attack))
);
ret &= expect_dictionary_key_map_and_default(key_map, add_terrain_modifier)(value);
- ret &= add_naval_unit(key, unit_args, naval_unit_args);
+ ret &= add_ship_type(key, unit_args, ship_type_args);
return ret;
}
@@ -283,10 +283,10 @@ bool UnitManager::load_unit_file(
})(root);
}
-bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) const {
+bool UnitTypeManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
- const auto generate_stat_modifiers = [&modifier_manager, &ret](std::string_view identifier, Unit::branch_t branch) -> void {
+ const auto generate_stat_modifiers = [&modifier_manager, &ret](std::string_view identifier, UnitType::branch_t branch) -> void {
const auto stat_modifier = [&modifier_manager, &ret, &identifier](
std::string_view suffix, bool is_positive_good, ModifierEffect::format_t format
) -> void {
@@ -324,19 +324,19 @@ bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) const {
stat_modifier("torpedo_attack", true, RAW_DECIMAL);
break;
default:
- /* Unreachable - units are only added via add_land_unit or add_naval_unit which set branch to LAND or NAVAL. */
+ /* Unreachable - unit types are only added via add_regiment_type or add_ship_type which set branch to LAND or NAVAL. */
Logger::error("Invalid branch for unit ", identifier, ": ", static_cast<int>(branch));
}
};
generate_stat_modifiers("army_base", LAND);
- for (LandUnit const& land_unit : get_land_units()) {
- generate_stat_modifiers(land_unit.get_identifier(), LAND);
+ for (RegimentType const& regiment_type : get_regiment_types()) {
+ generate_stat_modifiers(regiment_type.get_identifier(), LAND);
}
generate_stat_modifiers("navy_base", NAVAL);
- for (NavalUnit const& naval_unit : get_naval_units()) {
- generate_stat_modifiers(naval_unit.get_identifier(), NAVAL);
+ for (ShipType const& ship_type : get_ship_types()) {
+ generate_stat_modifiers(ship_type.get_identifier(), NAVAL);
}
return ret;
diff --git a/src/openvic-simulation/military/Unit.hpp b/src/openvic-simulation/military/UnitType.hpp
index d1ee3e3..201708e 100644
--- a/src/openvic-simulation/military/Unit.hpp
+++ b/src/openvic-simulation/military/UnitType.hpp
@@ -14,18 +14,18 @@ namespace OpenVic {
struct TerrainType;
struct TerrainTypeManager;
- struct Unit : HasIdentifier {
+ struct UnitType : HasIdentifier {
using icon_t = uint32_t;
using terrain_modifiers_t = ordered_map<TerrainType const*, ModifierValue>;
enum struct branch_t : uint8_t { INVALID_BRANCH, LAND, NAVAL };
- enum struct unit_type_t : uint8_t {
- INVALID_UNIT_TYPE, INFANTRY, CAVALRY, SUPPORT, SPECIAL, BIG_SHIP, LIGHT_SHIP, TRANSPORT
+ enum struct unit_category_t : uint8_t {
+ INVALID_UNIT_CATEGORY, INFANTRY, CAVALRY, SUPPORT, SPECIAL, BIG_SHIP, LIGHT_SHIP, TRANSPORT
};
- struct unit_args_t {
+ struct unit_type_args_t {
icon_t icon = 0;
- unit_type_t unit_type = unit_type_t::INVALID_UNIT_TYPE;
+ unit_category_t unit_category = unit_category_t::INVALID_UNIT_CATEGORY;
// TODO defaults for move_sound and select_sound
std::string_view sprite, move_sound, select_sound;
bool active = true, floating_flag = false;
@@ -36,8 +36,8 @@ namespace OpenVic {
Good::good_map_t build_cost, supply_cost;
terrain_modifiers_t terrain_modifiers;
- unit_args_t() = default;
- unit_args_t(unit_args_t&&) = default;
+ unit_type_args_t() = default;
+ unit_type_args_t(unit_type_args_t&&) = default;
};
private:
@@ -45,7 +45,7 @@ namespace OpenVic {
const icon_t PROPERTY(icon);
std::string PROPERTY(sprite);
const bool PROPERTY_CUSTOM_PREFIX(active, is);
- unit_type_t PROPERTY(unit_type);
+ unit_category_t PROPERTY(unit_category);
const bool PROPERTY_CUSTOM_PREFIX(floating_flag, has);
const uint32_t PROPERTY(priority);
@@ -66,27 +66,27 @@ namespace OpenVic {
protected:
/* Non-const reference unit_args so variables can be moved from it. */
- Unit(std::string_view new_identifier, branch_t new_branch, unit_args_t& unit_args);
+ UnitType(std::string_view new_identifier, branch_t new_branch, unit_type_args_t& unit_args);
public:
- Unit(Unit&&) = default;
+ UnitType(UnitType&&) = default;
};
- struct LandUnit : Unit {
- friend struct UnitManager;
+ struct RegimentType : UnitType {
+ friend struct UnitTypeManager;
enum struct allowed_cultures_t { ALL_CULTURES, ACCEPTED_CULTURES, PRIMARY_CULTURE };
- struct land_unit_args_t {
+ struct regiment_type_args_t {
allowed_cultures_t allowed_cultures = allowed_cultures_t::ALL_CULTURES;
std::string_view sprite_override, sprite_mount, sprite_mount_attach_node;
// TODO - represent these as modifier effects, so that they can be combined with tech, inventions,
- // leader bonuses, etc. and applied to unit instances all in one go (same for NavalUnits below)
+ // leader bonuses, etc. and applied to unit instances all in one go (same for ShipTypes below)
fixed_point_t reconnaissance = 0, attack = 0, defence = 0, discipline = 0, support = 0, maneuver = 0,
siege = 0;
- land_unit_args_t() = default;
- land_unit_args_t(land_unit_args_t&&) = default;
+ regiment_type_args_t() = default;
+ regiment_type_args_t(regiment_type_args_t&&) = default;
};
private:
@@ -102,25 +102,25 @@ namespace OpenVic {
const fixed_point_t PROPERTY(maneuver);
const fixed_point_t PROPERTY(siege);
- LandUnit(std::string_view new_identifier, unit_args_t& unit_args, land_unit_args_t const& land_unit_args);
+ RegimentType(std::string_view new_identifier, unit_type_args_t& unit_args, regiment_type_args_t const& regiment_type_args);
public:
- LandUnit(LandUnit&&) = default;
+ RegimentType(RegimentType&&) = default;
};
- struct NavalUnit : Unit {
- friend struct UnitManager;
+ struct ShipType : UnitType {
+ friend struct UnitTypeManager;
- struct naval_unit_args_t {
- Unit::icon_t naval_icon = 0;
+ struct ship_type_args_t {
+ UnitType::icon_t naval_icon = 0;
bool sail = false, transport = false, capital = false, build_overseas = false;
uint32_t min_port_level = 0;
int32_t limit_per_port = 0;
fixed_point_t colonial_points = 0, supply_consumption_score = 0, hull = 0, gun_power = 0, fire_range = 0,
evasion = 0, torpedo_attack = 0;
- naval_unit_args_t() = default;
- naval_unit_args_t(naval_unit_args_t&&) = default;
+ ship_type_args_t() = default;
+ ship_type_args_t(ship_type_args_t&&) = default;
};
private:
@@ -140,39 +140,39 @@ namespace OpenVic {
const fixed_point_t PROPERTY(evasion);
const fixed_point_t PROPERTY(torpedo_attack);
- NavalUnit(std::string_view new_identifier, unit_args_t& unit_args, naval_unit_args_t const& naval_unit_args);
+ ShipType(std::string_view new_identifier, unit_type_args_t& unit_args, ship_type_args_t const& ship_type_args);
public:
- NavalUnit(NavalUnit&&) = default;
+ ShipType(ShipType&&) = default;
};
- struct UnitManager {
+ struct UnitTypeManager {
private:
- IdentifierPointerRegistry<Unit> IDENTIFIER_REGISTRY(unit);
- IdentifierRegistry<LandUnit> IDENTIFIER_REGISTRY(land_unit);
- IdentifierRegistry<NavalUnit> IDENTIFIER_REGISTRY(naval_unit);
+ IdentifierPointerRegistry<UnitType> IDENTIFIER_REGISTRY(unit_type);
+ IdentifierRegistry<RegimentType> IDENTIFIER_REGISTRY(regiment_type);
+ IdentifierRegistry<ShipType> IDENTIFIER_REGISTRY(ship_type);
public:
- void reserve_all_units(size_t size);
- void lock_all_units();
+ void reserve_all_unit_types(size_t size);
+ void lock_all_unit_types();
- bool add_land_unit(
- std::string_view identifier, Unit::unit_args_t& unit_args, LandUnit::land_unit_args_t const& land_unit_args
+ bool add_regiment_type(
+ std::string_view identifier, UnitType::unit_type_args_t& unit_args, RegimentType::regiment_type_args_t const& regiment_type_args
);
- bool add_naval_unit(
- std::string_view identifier, Unit::unit_args_t& unit_args, NavalUnit::naval_unit_args_t const& naval_unit_args
+ bool add_ship_type(
+ std::string_view identifier, UnitType::unit_type_args_t& unit_args, ShipType::ship_type_args_t const& ship_type_args
);
- static NodeTools::Callback<std::string_view> auto expect_branch_str(NodeTools::Callback<Unit::branch_t> auto callback) {
- using enum Unit::branch_t;
- static const string_map_t<Unit::branch_t> branch_map { { "land", LAND }, { "naval", NAVAL }, { "sea", NAVAL } };
+ static NodeTools::Callback<std::string_view> auto expect_branch_str(NodeTools::Callback<UnitType::branch_t> auto callback) {
+ using enum UnitType::branch_t;
+ static const string_map_t<UnitType::branch_t> branch_map { { "land", LAND }, { "naval", NAVAL }, { "sea", NAVAL } };
return NodeTools::expect_mapped_string(branch_map, callback);
}
- static NodeTools::NodeCallback auto expect_branch_identifier(NodeTools::Callback<Unit::branch_t> auto callback) {
+ static NodeTools::NodeCallback auto expect_branch_identifier(NodeTools::Callback<UnitType::branch_t> auto callback) {
return NodeTools::expect_identifier(expect_branch_str(callback));
}
- bool load_unit_file(
+ bool load_unit_type_file(
GoodManager const& good_manager, TerrainTypeManager const& terrain_type_manager,
ModifierManager const& modifier_manager, ast::NodeCPtr root
);
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp
index 1701321..21aede8 100644
--- a/src/openvic-simulation/pop/Pop.cpp
+++ b/src/openvic-simulation/pop/Pop.cpp
@@ -1,6 +1,6 @@
#include "Pop.hpp"
-#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/politics/Issue.hpp"
#include "openvic-simulation/politics/Rebel.hpp"
@@ -436,13 +436,13 @@ bool PopManager::load_pop_type_file(
return ret;
}
-bool PopManager::load_delayed_parse_pop_type_data(UnitManager const& unit_manager, IssueManager const& issue_manager) {
+bool PopManager::load_delayed_parse_pop_type_data(UnitTypeManager const& unit_type_manager, IssueManager const& issue_manager) {
bool ret = true;
for (size_t index = 0; index < delayed_parse_nodes.size(); ++index) {
const auto [rebel_units, equivalent, promote_to_node, issues_node] = delayed_parse_nodes[index];
PopType* pop_type = pop_types.get_item_by_index(index);
- if (rebel_units != nullptr && !unit_manager.expect_unit_decimal_map(
+ if (rebel_units != nullptr && !unit_type_manager.expect_unit_type_decimal_map(
move_variable_callback(pop_type->rebel_units)
)(rebel_units)) {
Logger::error("Errors parsing rebel unit distribution for pop type ", pop_type, "!");
diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp
index cdecf44..c4e369f 100644
--- a/src/openvic-simulation/pop/Pop.hpp
+++ b/src/openvic-simulation/pop/Pop.hpp
@@ -15,8 +15,8 @@ namespace OpenVic {
struct PopManager;
struct PopType;
- struct Unit;
- struct UnitManager;
+ struct UnitType;
+ struct UnitTypeManager;
struct RebelType;
struct RebelManager;
struct Ideology;
@@ -97,7 +97,7 @@ namespace OpenVic {
};
using sprite_t = uint8_t;
- using rebel_units_t = fixed_point_map_t<Unit const*>;
+ using rebel_units_t = fixed_point_map_t<UnitType const*>;
using poptype_weight_map_t = ordered_map<PopType const*, ConditionalWeight>;
using ideology_weight_map_t = ordered_map<Ideology const*, ConditionalWeight>;
using issue_weight_map_t = ordered_map<Issue const*, ConditionalWeight>;
@@ -223,7 +223,7 @@ namespace OpenVic {
/* Using strata/stratas instead of stratum/strata to avoid confusion. */
IdentifierRegistry<Strata> IDENTIFIER_REGISTRY(strata);
IdentifierRegistry<PopType> IDENTIFIER_REGISTRY(pop_type);
- /* - rebel_units require Units which require on PopTypes (Unit->Map->Building->ProductionType->PopType).
+ /* - rebel_units require UnitTypes which require on PopTypes (UnitType->Map->Building->ProductionType->PopType).
* - equivalent and promote_to can't be parsed until after all PopTypes are registered.
* - issues require Issues to be loaded, which themselves depend on pop strata.
* To get around these circular dependencies, the nodes for these variables are stored here and parsed after the
@@ -296,7 +296,7 @@ namespace OpenVic {
std::string_view filestem, GoodManager const& good_manager, IdeologyManager const& ideology_manager,
ast::NodeCPtr root
);
- bool load_delayed_parse_pop_type_data(UnitManager const& unit_manager, IssueManager const& issue_manager);
+ bool load_delayed_parse_pop_type_data(UnitTypeManager const& unit_type_manager, IssueManager const& issue_manager);
bool load_pop_type_chances_file(ast::NodeCPtr root);
diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp
index 792dcba..0f92632 100644
--- a/src/openvic-simulation/research/Invention.cpp
+++ b/src/openvic-simulation/research/Invention.cpp
@@ -2,7 +2,7 @@
#include "openvic-simulation/economy/BuildingType.hpp"
#include "openvic-simulation/map/Crime.hpp"
-#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -40,11 +40,11 @@ bool InventionManager::add_invention(
}
bool InventionManager::load_inventions_file(
- ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingTypeManager const& building_type_manager,
+ ModifierManager const& modifier_manager, UnitTypeManager const& unit_type_manager, BuildingTypeManager const& building_type_manager,
CrimeManager const& crime_manager, ast::NodeCPtr root
) {
return expect_dictionary_reserve_length(
- inventions, [this, &modifier_manager, &unit_manager, &building_type_manager, &crime_manager](
+ inventions, [this, &modifier_manager, &unit_type_manager, &building_type_manager, &crime_manager](
std::string_view identifier, ast::NodeCPtr value) -> bool {
ModifierValue loose_modifiers;
ModifierValue modifiers;
@@ -68,7 +68,7 @@ bool InventionManager::load_inventions_file(
move_variable_callback(modifiers),
"gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)),
"gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)),
- "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier(set_callback_pointer(activated_units)),
+ "activate_unit", ZERO_OR_MORE, unit_type_manager.expect_unit_type_identifier(set_callback_pointer(activated_units)),
"activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier(
set_callback_pointer(activated_buildings)
),
diff --git a/src/openvic-simulation/research/Invention.hpp b/src/openvic-simulation/research/Invention.hpp
index 2b8100d..43a4e10 100644
--- a/src/openvic-simulation/research/Invention.hpp
+++ b/src/openvic-simulation/research/Invention.hpp
@@ -6,18 +6,18 @@
#include "openvic-simulation/types/OrderedContainers.hpp"
namespace OpenVic {
- struct Unit;
+ struct UnitType;
struct BuildingType;
struct Crime;
- struct UnitManager;
+ struct UnitTypeManager;
struct BuildingTypeManager;
struct CrimeManager;
struct Invention : Modifier {
friend struct InventionManager;
//TODO implement limit and chance
- using unit_set_t = ordered_set<Unit const*>;
+ using unit_set_t = ordered_set<UnitType const*>;
using building_set_t = ordered_set<BuildingType const*>;
using crime_set_t = ordered_set<Crime const*>;
@@ -54,7 +54,7 @@ namespace OpenVic {
);
bool load_inventions_file(
- ModifierManager const& modifier_manager, UnitManager const& unit_manager,
+ ModifierManager const& modifier_manager, UnitTypeManager const& unit_type_manager,
BuildingTypeManager const& building_type_manager, CrimeManager const& crime_manager, ast::NodeCPtr root
); // inventions/*.txt
diff --git a/src/openvic-simulation/research/Technology.cpp b/src/openvic-simulation/research/Technology.cpp
index 00b736c..027268e 100644
--- a/src/openvic-simulation/research/Technology.cpp
+++ b/src/openvic-simulation/research/Technology.cpp
@@ -144,10 +144,10 @@ bool TechnologyManager::load_technology_file_schools(
}
bool TechnologyManager::load_technologies_file(
- ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingTypeManager const& building_type_manager,
+ ModifierManager const& modifier_manager, UnitTypeManager const& unit_type_manager, BuildingTypeManager const& building_type_manager,
ast::NodeCPtr root
) {
- return expect_dictionary_reserve_length(technologies, [this, &modifier_manager, &unit_manager, &building_type_manager](
+ return expect_dictionary_reserve_length(technologies, [this, &modifier_manager, &unit_type_manager, &building_type_manager](
std::string_view tech_key, ast::NodeCPtr tech_value
) -> bool {
ModifierValue modifiers;
@@ -167,7 +167,7 @@ bool TechnologyManager::load_technologies_file(
"cost", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(cost)),
"unciv_military", ZERO_OR_ONE, expect_bool(assign_variable_callback(unciv_military)),
"unit", ZERO_OR_ONE, expect_uint(assign_variable_callback(unit)),
- "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier(set_callback_pointer(activated_units)),
+ "activate_unit", ZERO_OR_MORE, unit_type_manager.expect_unit_type_identifier(set_callback_pointer(activated_units)),
"activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier(
set_callback_pointer(activated_buildings)
),
diff --git a/src/openvic-simulation/research/Technology.hpp b/src/openvic-simulation/research/Technology.hpp
index aa47301..c67ebc0 100644
--- a/src/openvic-simulation/research/Technology.hpp
+++ b/src/openvic-simulation/research/Technology.hpp
@@ -3,7 +3,7 @@
#include <cstdint>
#include "openvic-simulation/economy/BuildingType.hpp"
-#include "openvic-simulation/military/Unit.hpp"
+#include "openvic-simulation/military/UnitType.hpp"
#include "openvic-simulation/misc/Modifier.hpp"
#include "openvic-simulation/scripts/ConditionalWeight.hpp"
#include "openvic-simulation/types/Date.hpp"
@@ -42,7 +42,7 @@ namespace OpenVic {
struct Technology : Modifier {
friend struct TechnologyManager;
- using unit_set_t = ordered_set<Unit const*>;
+ using unit_set_t = ordered_set<UnitType const*>;
using building_set_t = ordered_set<BuildingType const*>;
private:
@@ -100,7 +100,7 @@ namespace OpenVic {
/* Loaded from "technologies/.txt" files named after technology folders. */
bool load_technologies_file(
- ModifierManager const& modifier_manager, UnitManager const& unit_manager,
+ ModifierManager const& modifier_manager, UnitTypeManager const& unit_type_manager,
BuildingTypeManager const& building_type_manager, ast::NodeCPtr root
);