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.cpp12
-rw-r--r--src/openvic-simulation/military/Deployment.hpp11
-rw-r--r--src/openvic-simulation/military/LeaderTrait.cpp8
-rw-r--r--src/openvic-simulation/military/LeaderTrait.hpp16
-rw-r--r--src/openvic-simulation/military/MilitaryManager.hpp2
-rw-r--r--src/openvic-simulation/military/Unit.cpp50
-rw-r--r--src/openvic-simulation/military/Unit.hpp16
7 files changed, 50 insertions, 65 deletions
diff --git a/src/openvic-simulation/military/Deployment.cpp b/src/openvic-simulation/military/Deployment.cpp
index 441142d..5b3aa77 100644
--- a/src/openvic-simulation/military/Deployment.cpp
+++ b/src/openvic-simulation/military/Deployment.cpp
@@ -6,10 +6,9 @@ using namespace OpenVic;
using namespace OpenVic::NodeTools;
Deployment::Deployment(
- std::string_view new_path, std::vector<Army>&& new_armies,
- std::vector<Navy>&& 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) } {}
+ std::string_view new_path, std::vector<Army>&& new_armies, std::vector<Navy>&& 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) } {}
const std::vector<Army>& Deployment::get_armies() const {
return armies;
@@ -25,8 +24,9 @@ const std::vector<Leader>& Deployment::get_leaders() const {
DeploymentManager::DeploymentManager() : deployments { "deployments" } {}
-bool DeploymentManager::add_deployment(std::string_view path, std::vector<Army>&& armies,
- std::vector<Navy>&& navies, std::vector<Leader>&& leaders) {
+bool DeploymentManager::add_deployment(
+ std::string_view path, std::vector<Army>&& armies, std::vector<Navy>&& navies, std::vector<Leader>&& leaders
+) {
if (path.empty()) {
Logger::error("Attemped to load order of battle with no path! Something is very wrong!");
return false;
diff --git a/src/openvic-simulation/military/Deployment.hpp b/src/openvic-simulation/military/Deployment.hpp
index 9eb0a72..34cf82a 100644
--- a/src/openvic-simulation/military/Deployment.hpp
+++ b/src/openvic-simulation/military/Deployment.hpp
@@ -56,8 +56,10 @@ namespace OpenVic {
const std::vector<Navy> navies;
const std::vector<Leader> leaders;
- Deployment(std::string_view new_path, std::vector<Army>&& new_armies,
- std::vector<Navy>&& new_navies, std::vector<Leader>&& new_leaders);
+ Deployment(
+ std::string_view new_path, std::vector<Army>&& new_armies, std::vector<Navy>&& new_navies,
+ std::vector<Leader>&& new_leaders
+ );
public:
const std::vector<Army>& get_armies() const;
@@ -72,8 +74,9 @@ namespace OpenVic {
public:
DeploymentManager();
- bool add_deployment(std::string_view path, std::vector<Army>&& armies,
- std::vector<Navy>&& navies, std::vector<Leader>&& leaders);
+ bool add_deployment(
+ std::string_view path, std::vector<Army>&& armies, std::vector<Navy>&& navies, std::vector<Leader>&& leaders
+ );
IDENTIFIER_REGISTRY_ACCESSORS(deployment);
bool load_oob_file(GameManager& game_manager, std::string_view path, ast::NodeCPtr root);
diff --git a/src/openvic-simulation/military/LeaderTrait.cpp b/src/openvic-simulation/military/LeaderTrait.cpp
index 81c6ccc..df87e4e 100644
--- a/src/openvic-simulation/military/LeaderTrait.cpp
+++ b/src/openvic-simulation/military/LeaderTrait.cpp
@@ -24,8 +24,9 @@ ModifierValue const& LeaderTrait::get_modifiers() const {
LeaderTraitManager::LeaderTraitManager() : leader_traits { "leader trait" } {}
-bool LeaderTraitManager::add_leader_trait(std::string_view identifier,
- LeaderTrait::trait_type_t type, ModifierValue&& modifiers) {
+bool LeaderTraitManager::add_leader_trait(
+ std::string_view identifier, LeaderTrait::trait_type_t type, ModifierValue&& modifiers
+) {
if (identifier.empty()) {
Logger::error("Invalid leader trait identifier - empty!");
return false;
@@ -39,7 +40,8 @@ bool LeaderTraitManager::load_leader_traits_file(ModifierManager const& modifier
const auto trait_callback = [this, &modifier_manager](LeaderTrait::trait_type_t type) -> key_value_callback_t {
return [this, &modifier_manager, type](std::string_view trait_identifier, ast::NodeCPtr value) -> bool {
ModifierValue modifiers;
- bool ret = modifier_manager.expect_whitelisted_modifier_value(move_variable_callback(modifiers), allowed_modifiers)(value);
+ bool ret =
+ modifier_manager.expect_whitelisted_modifier_value(move_variable_callback(modifiers), allowed_modifiers)(value);
ret &= add_leader_trait(trait_identifier, type, std::move(modifiers));
return ret;
};
diff --git a/src/openvic-simulation/military/LeaderTrait.hpp b/src/openvic-simulation/military/LeaderTrait.hpp
index d885057..e61a1fc 100644
--- a/src/openvic-simulation/military/LeaderTrait.hpp
+++ b/src/openvic-simulation/military/LeaderTrait.hpp
@@ -14,13 +14,9 @@ namespace OpenVic {
struct LeaderTrait : HasIdentifier {
friend struct LeaderTraitManager;
- enum class trait_type_t {
- PERSONALITY,
- BACKGROUND
- };
+ enum class trait_type_t { PERSONALITY, BACKGROUND };
private:
-
const trait_type_t type;
/*
* Allowed modifiers for leaders:
@@ -51,15 +47,7 @@ namespace OpenVic {
private:
IdentifierRegistry<LeaderTrait> leader_traits;
inline static const string_set_t allowed_modifiers = {
- "attack",
- "defence",
- "morale",
- "organisation",
- "reconnaissance",
- "speed",
- "attrition",
- "experience",
- "reliability"
+ "attack", "defence", "morale", "organisation", "reconnaissance", "speed", "attrition", "experience", "reliability"
};
public:
diff --git a/src/openvic-simulation/military/MilitaryManager.hpp b/src/openvic-simulation/military/MilitaryManager.hpp
index 57ba8d1..0e7e1b1 100644
--- a/src/openvic-simulation/military/MilitaryManager.hpp
+++ b/src/openvic-simulation/military/MilitaryManager.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "openvic-simulation/military/LeaderTrait.hpp"
#include "openvic-simulation/military/Deployment.hpp"
+#include "openvic-simulation/military/LeaderTrait.hpp"
#include "openvic-simulation/military/Unit.hpp"
namespace OpenVic {
diff --git a/src/openvic-simulation/military/Unit.cpp b/src/openvic-simulation/military/Unit.cpp
index f079ee9..1b5f2d2 100644
--- a/src/openvic-simulation/military/Unit.cpp
+++ b/src/openvic-simulation/military/Unit.cpp
@@ -2,23 +2,24 @@
#define UNIT_ARGS \
icon, sprite, active, unit_type, floating_flag, priority, max_strength, default_organisation, maximum_speed, \
- weighted_value, move_sound, select_sound, build_time, std::move(build_cost), supply_consumption, std::move(supply_cost)
+ weighted_value, move_sound, select_sound, build_time, std::move(build_cost), supply_consumption, \
+ std::move(supply_cost)
#define LAND_ARGS \
- primary_culture, sprite_override, sprite_mount, sprite_mount_attach_node, \
- reconnaissance, attack, defence, discipline, support, maneuver, siege
+ primary_culture, sprite_override, sprite_mount, sprite_mount_attach_node, reconnaissance, attack, defence, discipline, \
+ support, maneuver, siege
#define NAVY_ARGS \
- naval_icon, sail, transport, capital, colonial_points, build_overseas, min_port_level, \
- limit_per_port, supply_consumption_score, hull, gun_power, fire_range, evasion, torpedo_attack
+ naval_icon, sail, transport, capital, colonial_points, build_overseas, min_port_level, limit_per_port, \
+ supply_consumption_score, hull, gun_power, fire_range, evasion, torpedo_attack
using namespace OpenVic;
using namespace OpenVic::NodeTools;
Unit::Unit(
std::string_view identifier, type_t type, UNIT_PARAMS
-) : HasIdentifier { identifier }, icon { icon }, type { type }, sprite { sprite }, active { active },
- unit_type { unit_type }, floating_flag { floating_flag }, priority { priority }, max_strength { max_strength },
+) : HasIdentifier { identifier }, icon { icon }, type { type }, sprite { sprite }, active { active }, unit_type { unit_type },
+ floating_flag { floating_flag }, priority { priority }, max_strength { max_strength },
default_organisation { default_organisation }, maximum_speed { maximum_speed }, weighted_value { weighted_value },
move_sound { move_sound }, select_sound { select_sound }, build_time { build_time }, build_cost { std::move(build_cost) },
supply_consumption { supply_consumption }, supply_cost { std::move(supply_cost) } {}
@@ -93,10 +94,10 @@ Good::good_map_t const& Unit::get_supply_cost() const {
LandUnit::LandUnit(
std::string_view identifier, UNIT_PARAMS, LAND_PARAMS
-) : Unit { identifier, type_t::LAND, UNIT_ARGS }, primary_culture { primary_culture },
- sprite_override { sprite_override }, sprite_mount { sprite_mount }, sprite_mount_attach_node { sprite_mount_attach_node },
- reconnaissance { reconnaissance }, attack { attack }, defence { defence }, discipline { discipline }, support { support },
- maneuver { maneuver }, siege { siege } {}
+) : Unit { identifier, type_t::LAND, UNIT_ARGS }, primary_culture { primary_culture }, sprite_override { sprite_override },
+ sprite_mount { sprite_mount }, sprite_mount_attach_node { sprite_mount_attach_node }, reconnaissance { reconnaissance },
+ attack { attack }, defence { defence }, discipline { discipline }, support { support }, maneuver { maneuver },
+ siege { siege } {}
bool LandUnit::get_primary_culture() const {
return primary_culture;
@@ -144,11 +145,11 @@ fixed_point_t LandUnit::get_siege() const {
NavalUnit::NavalUnit(
std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS
-) : Unit { identifier, type_t::NAVAL, UNIT_ARGS }, naval_icon { naval_icon }, sail { sail },
- transport { transport }, capital { capital }, colonial_points { colonial_points },
- build_overseas { build_overseas }, min_port_level { min_port_level }, limit_per_port { limit_per_port },
- supply_consumption_score { supply_consumption_score }, hull { hull }, gun_power { gun_power },
- fire_range { fire_range }, evasion { evasion }, torpedo_attack { torpedo_attack } {};
+) : Unit { identifier, type_t::NAVAL, UNIT_ARGS }, naval_icon { naval_icon }, sail { sail }, transport { transport },
+ capital { capital }, colonial_points { colonial_points }, build_overseas { build_overseas },
+ min_port_level { min_port_level }, limit_per_port { limit_per_port },
+ supply_consumption_score { supply_consumption_score }, hull { hull }, gun_power { gun_power }, fire_range { fire_range },
+ evasion { evasion }, torpedo_attack { torpedo_attack } {};
NavalUnit::icon_t NavalUnit::get_naval_icon() const {
return naval_icon;
@@ -220,7 +221,7 @@ bool UnitManager::_check_shared_parameters(std::string_view identifier, UNIT_PAR
return false;
}
- //TODO check that icon and sprite exist
+ // TODO check that icon and sprite exist
return true;
}
@@ -238,7 +239,7 @@ bool UnitManager::add_naval_unit(std::string_view identifier, UNIT_PARAMS, NAVY_
return false;
}
- //TODO: check that icon and sounds exist
+ // TODO: check that icon and sounds exist
return units.add_item(NavalUnit { identifier, UNIT_ARGS, NAVY_ARGS });
}
@@ -256,11 +257,8 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
Good::good_map_t build_cost, supply_cost;
using enum Unit::type_t;
- static const string_map_t<Unit::type_t> type_map = {
- { "land", LAND }, { "naval", NAVAL }
- };
- bool ret =
- expect_key("type", expect_identifier(expect_mapped_string(type_map, assign_variable_callback(type))))(value);
+ static const string_map_t<Unit::type_t> type_map = { { "land", LAND }, { "naval", NAVAL } };
+ bool ret = expect_key("type", expect_identifier(expect_mapped_string(type_map, assign_variable_callback(type))))(value);
if (!ret) {
Logger::error("Failed to read type for unit: ", key);
@@ -268,7 +266,7 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
}
key_map_t key_map;
- //shared
+ // shared
ret &= add_key_map_entries(key_map,
"icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)),
"type", ONE_EXACTLY, success_callback,
@@ -347,9 +345,7 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
return ret;
}
- default:
- Logger::error("Unknown unit type for ", key, ": ", static_cast<int>(type));
- return false;
+ default: Logger::error("Unknown unit type for ", key, ": ", static_cast<int>(type)); return false;
}
})(root);
}
diff --git a/src/openvic-simulation/military/Unit.hpp b/src/openvic-simulation/military/Unit.hpp
index d1dcc8f..acfc8b8 100644
--- a/src/openvic-simulation/military/Unit.hpp
+++ b/src/openvic-simulation/military/Unit.hpp
@@ -10,11 +10,10 @@
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#define UNIT_PARAMS \
- Unit::icon_t icon, std::string_view sprite, bool active, std::string_view unit_type, \
- bool floating_flag, uint32_t priority, fixed_point_t max_strength, fixed_point_t default_organisation, \
- fixed_point_t maximum_speed, fixed_point_t weighted_value, std::string_view move_sound, \
- std::string_view select_sound, Timespan build_time, Good::good_map_t &&build_cost, \
- fixed_point_t supply_consumption, Good::good_map_t &&supply_cost
+ Unit::icon_t icon, std::string_view sprite, bool active, std::string_view unit_type, bool floating_flag, \
+ uint32_t priority, fixed_point_t max_strength, fixed_point_t default_organisation, fixed_point_t maximum_speed, \
+ fixed_point_t weighted_value, std::string_view move_sound, std::string_view select_sound, Timespan build_time, \
+ Good::good_map_t&& build_cost, fixed_point_t supply_consumption, Good::good_map_t&& supply_cost
#define LAND_PARAMS \
bool primary_culture, std::string_view sprite_override, std::string_view sprite_mount, \
@@ -30,10 +29,7 @@ namespace OpenVic {
struct Unit : HasIdentifier {
using icon_t = uint32_t;
- enum struct type_t {
- LAND,
- NAVAL
- };
+ enum struct type_t { LAND, NAVAL };
private:
const type_t type;
@@ -175,4 +171,4 @@ namespace OpenVic {
bool load_unit_file(GoodManager const& good_manager, ast::NodeCPtr root);
};
-} \ No newline at end of file
+}