aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/GameManager.cpp4
-rw-r--r--src/openvic-simulation/GameManager.hpp16
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp20
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp2
-rw-r--r--src/openvic-simulation/economy/Good.cpp19
-rw-r--r--src/openvic-simulation/economy/Good.hpp3
-rw-r--r--src/openvic-simulation/units/Unit.cpp291
-rw-r--r--src/openvic-simulation/units/Unit.hpp161
8 files changed, 506 insertions, 10 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index 4c8b55f..5067a65 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -1,11 +1,13 @@
#include "GameManager.hpp"
#include "openvic-simulation/utility/Logger.hpp"
+#include "units/Unit.hpp"
using namespace OpenVic;
GameManager::GameManager(state_updated_func_t state_updated_callback)
- : clock { [this]() { tick(); }, [this]() { update_state(); } },
+ : unit_manager { good_manager },
+ clock { [this]() { tick(); }, [this]() { update_state(); } },
state_updated { state_updated_callback } {}
void GameManager::set_needs_update() {
diff --git a/src/openvic-simulation/GameManager.hpp b/src/openvic-simulation/GameManager.hpp
index 70d8cf0..fa61eaf 100644
--- a/src/openvic-simulation/GameManager.hpp
+++ b/src/openvic-simulation/GameManager.hpp
@@ -1,10 +1,14 @@
#pragma once
-#include "GameAdvancementHook.hpp"
-#include "economy/Good.hpp"
-#include "map/Map.hpp"
-#include "politics/Ideology.hpp"
-#include "politics/Issue.hpp"
+#include "openvic-simulation/GameAdvancementHook.hpp"
+#include "openvic-simulation/economy/Good.hpp"
+#include "openvic-simulation/map/Map.hpp"
+#include "openvic-simulation/politics/Ideology.hpp"
+#include "openvic-simulation/politics/Issue.hpp"
+#include "openvic-simulation/GameAdvancementHook.hpp"
+#include "openvic-simulation/economy/Good.hpp"
+#include "openvic-simulation/map/Map.hpp"
+#include "openvic-simulation/units/Unit.hpp"
namespace OpenVic {
struct GameManager {
@@ -16,7 +20,7 @@ namespace OpenVic {
PopManager pop_manager;
IdeologyManager ideology_manager;
IssueManager issue_manager;
-
+ UnitManager unit_manager;
GameAdvancementHook clock;
private:
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index d0d9506..7cd955d 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -1,4 +1,5 @@
#include "Dataloader.hpp"
+#include <filesystem>
#include <openvic-dataloader/csv/Parser.hpp>
#include <openvic-dataloader/detail/CallbackOStream.hpp>
@@ -6,6 +7,7 @@
#include "openvic-simulation/GameManager.hpp"
#include "openvic-simulation/utility/Logger.hpp"
+#include "units/Unit.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -150,13 +152,20 @@ bool Dataloader::_load_pop_types(PopManager& pop_manager, fs::path const& pop_ty
return pop_manager.load_pop_type_file(file.stem().string(), _parse_defines(file).get_file_node());
}
);
- if (!ret) {
- Logger::error("Failed to load pop types!");
- }
pop_manager.lock_pop_types();
return ret;
}
+bool Dataloader::_load_units(UnitManager& unit_manager, fs::path const& units_directory) const {
+ const bool ret = apply_to_files_in_dir(units_directory, ".txt",
+ [&unit_manager](fs::path const& file) -> bool {
+ return unit_manager.load_unit_file(_parse_defines(file).get_file_node());
+ }
+ );
+ unit_manager.lock_units();
+ return ret;
+}
+
bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const {
Map& map = game_manager.map;
@@ -260,6 +269,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
static const fs::path ideology_file = "common/ideologies.txt";
static const fs::path issues_file = "common/issues.txt";
static const fs::path map_directory = "map";
+ static const fs::path units_directory = "units";
bool ret = true;
@@ -291,6 +301,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load issues!");
ret = false;
}
+ if (!_load_units(game_manager.unit_manager, units_directory)) {
+ Logger::error("Failed to load units!");
+ ret = false;
+ }
if (!_load_map_dir(game_manager, map_directory)) {
Logger::error("Failed to load map!");
ret = false;
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index 6741361..9e15102 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -5,6 +5,7 @@
#include <vector>
#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "units/Unit.hpp"
namespace OpenVic {
namespace fs = std::filesystem;
@@ -21,6 +22,7 @@ namespace OpenVic {
path_vector_t roots;
bool _load_pop_types(PopManager& pop_manager, fs::path const& pop_type_directory) const;
+ bool _load_units(UnitManager& unit_manager, fs::path const& units_directory) const;
bool _load_map_dir(GameManager& game_manager, fs::path const& map_directory) const;
public:
diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp
index f1da8bd..027fb5f 100644
--- a/src/openvic-simulation/economy/Good.cpp
+++ b/src/openvic-simulation/economy/Good.cpp
@@ -1,6 +1,11 @@
#include "Good.hpp"
#include <cassert>
+#include <map>
+#include <string_view>
+#include "dataloader/NodeTools.hpp"
+#include "openvic-dataloader/v2script/AbstractSyntaxTree.hpp"
+#include "types/fixed_point/FixedPoint.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -132,3 +137,17 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) {
lock_goods();
return ret;
}
+
+node_callback_t GoodManager::expect_goods_map(callback_t<std::map<Good const*, fixed_point_t>> cb) {
+ return [this, cb](ast::NodeCPtr node) -> bool {
+ std::map<Good const*, fixed_point_t> goods_map;
+ bool res = expect_good_dictionary([&goods_map](const Good & key, ast::NodeCPtr value) -> bool {
+ fixed_point_t good_value;
+ bool res = expect_fixed_point((assign_variable_callback(good_value)))(value);
+ goods_map.emplace(&key, good_value);
+ return res;
+ })(node);
+ res &= cb(goods_map);
+ return res;
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/economy/Good.hpp b/src/openvic-simulation/economy/Good.hpp
index 6c237b1..df92525 100644
--- a/src/openvic-simulation/economy/Good.hpp
+++ b/src/openvic-simulation/economy/Good.hpp
@@ -2,6 +2,7 @@
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-dataloader/v2script/AbstractSyntaxTree.hpp"
namespace OpenVic {
struct GoodManager;
@@ -75,5 +76,7 @@ namespace OpenVic {
void reset_to_defaults();
bool load_goods_file(ast::NodeCPtr root);
+
+ NodeTools::node_callback_t expect_goods_map(NodeTools::callback_t<std::map<Good const*, fixed_point_t>> cb);
};
}
diff --git a/src/openvic-simulation/units/Unit.cpp b/src/openvic-simulation/units/Unit.cpp
new file mode 100644
index 0000000..ebf4985
--- /dev/null
+++ b/src/openvic-simulation/units/Unit.cpp
@@ -0,0 +1,291 @@
+#include "Unit.hpp"
+
+#define UNIT_ARGS icon, sprite, active, type, floating_flag, priority, max_strength, \
+ default_organisation, maximum_speed, weighted_value, build_time, build_cost, supply_consumption, \
+ supply_cost
+#define LAND_ARGS reconnaissance, attack, defence, discipline, support, maneuver, siege
+#define NAVY_ARGS naval_icon, sail, transport, capital, move_sound, select_sound, 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, std::string_view category, UNIT_PARAMS) : HasIdentifier { identifier },
+ icon { icon }, category { category }, sprite { sprite }, active { active }, type { type },
+ floating_flag { floating_flag }, priority { priority }, max_strength { max_strength },
+ default_organisation { default_organisation }, maximum_speed { maximum_speed }, weighted_value { weighted_value },
+ build_time { build_time }, build_cost { build_cost }, supply_consumption { supply_consumption }, supply_cost { supply_cost } {}
+
+Unit::icon_t Unit::get_icon() const {
+ return icon;
+}
+
+Unit::sprite_t Unit::get_sprite() const {
+ return sprite;
+}
+
+bool Unit::is_active() const {
+ return active;
+}
+
+std::string_view Unit::get_type() const {
+ return type;
+}
+
+bool Unit::has_floating_flag() const {
+ return floating_flag;
+}
+
+uint32_t Unit::get_priority() const {
+ return priority;
+}
+
+fixed_point_t Unit::get_max_strength() const {
+ return max_strength;
+}
+
+fixed_point_t Unit::get_default_organisation() const {
+ return default_organisation;
+}
+
+fixed_point_t Unit::get_maximum_speed() const {
+ return maximum_speed;
+}
+
+uint32_t Unit::get_build_time() const {
+ return build_time;
+}
+
+fixed_point_t Unit::get_weighted_value() const {
+ return weighted_value;
+}
+
+std::map<const Good*, fixed_point_t> const& Unit::get_build_cost() const {
+ return build_cost;
+}
+
+fixed_point_t Unit::get_supply_consumption() const {
+ return supply_consumption;
+}
+
+std::map<const Good*, fixed_point_t> const& Unit::get_supply_cost() const {
+ return supply_cost;
+}
+
+LandUnit::LandUnit(std::string_view identifier, UNIT_PARAMS, LAND_PARAMS) : Unit { identifier, "land", UNIT_ARGS },
+ reconnaissance { reconnaissance }, attack { attack }, defence { defence }, discipline { discipline }, support { support },
+ maneuver { maneuver }, siege { siege } {}
+
+fixed_point_t LandUnit::get_reconnaissance() const {
+ return reconnaissance;
+}
+
+fixed_point_t LandUnit::get_attack() const {
+ return attack;
+}
+
+fixed_point_t LandUnit::get_defence() const {
+ return defence;
+}
+
+fixed_point_t LandUnit::get_discipline() const {
+ return discipline;
+}
+
+fixed_point_t LandUnit::get_support() const {
+ return support;
+}
+
+fixed_point_t LandUnit::get_maneuver() const {
+ return maneuver;
+}
+
+fixed_point_t LandUnit::get_siege() const {
+ return siege;
+}
+
+NavalUnit::NavalUnit(std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS) : Unit { identifier, "naval", UNIT_ARGS },
+ naval_icon { naval_icon }, sail { sail }, transport { transport }, capital { capital }, move_sound { move_sound },
+ select_sound { select_sound }, 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;
+}
+
+bool NavalUnit::can_sail() const {
+ return sail;
+}
+
+bool NavalUnit::is_transport() const {
+ return transport;
+}
+
+NavalUnit::sound_t NavalUnit::get_move_sound() const {
+ return move_sound;
+}
+
+NavalUnit::sound_t NavalUnit::get_select_sound() const {
+ return select_sound;
+}
+
+fixed_point_t NavalUnit::get_colonial_points() const {
+ return colonial_points;
+}
+
+bool NavalUnit::can_build_overseas() const {
+ return build_overseas;
+}
+
+uint32_t NavalUnit::get_min_port_level() const {
+ return min_port_level;
+}
+
+int32_t NavalUnit::get_limit_per_port() const {
+ return limit_per_port;
+}
+
+fixed_point_t NavalUnit::get_supply_consumption_score() const {
+ return supply_consumption_score;
+}
+
+fixed_point_t NavalUnit::get_hull() const {
+ return hull;
+}
+
+fixed_point_t NavalUnit::get_gun_power() const {
+ return gun_power;
+}
+
+fixed_point_t NavalUnit::get_fire_range() const {
+ return fire_range;
+}
+
+fixed_point_t NavalUnit::get_evasion() const {
+ return evasion;
+}
+
+fixed_point_t NavalUnit::get_torpedo_attack() const {
+ return torpedo_attack;
+}
+
+UnitManager::UnitManager(GoodManager& good_manager) : good_manager { good_manager }, units { "units" } {};
+
+bool UnitManager::_check_shared_parameters(const std::string_view identifier, UNIT_PARAMS) {
+ if (identifier.empty()) {
+ Logger::error("Invalid religion identifier - empty!");
+ return false;
+ }
+
+ if (sprite.empty()) {
+ Logger::error("Invalid sprite identifier - empty!");
+ return false;
+ }
+
+ if (type.empty()) {
+ Logger::error("Invalid unit type - empty!");
+ return false;
+ }
+
+ //TODO check that icon and sprite exist
+
+ return true;
+}
+
+bool UnitManager::add_land_unit(const std::string_view identifier, UNIT_PARAMS, LAND_PARAMS) {
+ if (!_check_shared_parameters(identifier, UNIT_ARGS)) {
+ return false;
+ }
+
+ return units.add_item(LandUnit { identifier, UNIT_ARGS, LAND_ARGS });
+}
+
+bool UnitManager::add_naval_unit(const std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS) {
+ if (!_check_shared_parameters(identifier, UNIT_ARGS)) {
+ return false;
+ }
+
+ //TODO: check that icon and sounds exist
+
+ return units.add_item(NavalUnit { identifier, UNIT_ARGS, NAVY_ARGS });
+}
+//TODO forgot fcking capital flag for naval units
+bool UnitManager::load_unit_file(ast::NodeCPtr root) {
+ return NodeTools::expect_dictionary([this](std::string_view key, ast::NodeCPtr value) -> bool {
+ Unit::icon_t icon;
+ std::string_view category, type;
+ Unit::sprite_t sprite;
+ bool active = true, floating_flag;
+ uint32_t priority, build_time;
+ fixed_point_t maximum_speed, max_strength, default_organisation, weighted_value, supply_consumption;
+ std::map<const Good*, fixed_point_t> build_cost, supply_cost;
+
+ //shared
+ bool ret = expect_dictionary_keys(ALLOW_OTHER_KEYS,
+ "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)),
+ "type", ONE_EXACTLY, expect_identifier(assign_variable_callback(category)),
+ "sprite", ONE_EXACTLY, expect_identifier(assign_variable_callback(sprite)),
+ "active", ZERO_OR_ONE, expect_bool(assign_variable_callback(active)),
+ "unit_type", ONE_EXACTLY, expect_identifier(assign_variable_callback(type)),
+ "floating_flag", ONE_EXACTLY, expect_bool(assign_variable_callback(floating_flag)),
+ "priority", ONE_EXACTLY, expect_uint(assign_variable_callback(priority)),
+ "max_strength", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(max_strength)),
+ "default_organisation", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(default_organisation)),
+ "maximum_speed", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(maximum_speed)),
+ "weighted_value", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(weighted_value)),
+ "build_time", ONE_EXACTLY, expect_uint(assign_variable_callback(build_time)),
+ "build_cost", ONE_EXACTLY, good_manager.expect_goods_map(assign_variable_callback(build_cost)),
+ "supply_consumption", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(supply_consumption)),
+ "supply_cost", ONE_EXACTLY, good_manager.expect_goods_map(assign_variable_callback(supply_cost))
+ )(value);
+
+ if (category == "land") {
+ fixed_point_t reconnaissance, attack, defence, discipline, support, maneuver, siege;
+
+ ret &= expect_dictionary_keys(ALLOW_OTHER_KEYS,
+ "reconnaissance", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(reconnaissance)),
+ "attack", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(attack)),
+ "defence", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(defence)),
+ "discipline", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(discipline)),
+ "support", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(support)),
+ "maneuver", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(maneuver)),
+ "siege", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(siege))
+ )(value);
+
+ ret &= add_land_unit(key, UNIT_ARGS, LAND_ARGS);
+
+ return ret;
+ } else if (category == "naval") {
+ Unit::icon_t naval_icon;
+ bool sail = false, transport = false, capital = false, build_overseas = false;
+ Unit::sound_t move_sound, select_sound; //TODO defaults for both
+ uint32_t min_port_level;
+ int32_t limit_per_port;
+ fixed_point_t fire_range, evasion, supply_consumption_score, hull, gun_power, colonial_points = 0, torpedo_attack = 0;
+
+ ret &= expect_dictionary_keys(ALLOW_OTHER_KEYS,
+ "naval_icon", ONE_EXACTLY, expect_uint(assign_variable_callback(naval_icon)),
+ "sail", ZERO_OR_ONE, expect_bool(assign_variable_callback(sail)),
+ "transport", ZERO_OR_ONE, expect_bool(assign_variable_callback(transport)),
+ "capital", ZERO_OR_ONE, expect_bool(assign_variable_callback(capital)),
+ "move_sound", ZERO_OR_ONE, expect_identifier(assign_variable_callback(move_sound)),
+ "select_sound", ZERO_OR_ONE, expect_identifier(assign_variable_callback(select_sound)),
+ "colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(colonial_points)),
+ "can_build_overseas", ZERO_OR_ONE, expect_bool(assign_variable_callback(build_overseas)),
+ "min_port_level", ONE_EXACTLY, expect_uint(assign_variable_callback(min_port_level)),
+ "limit_per_port", ONE_EXACTLY, expect_int(assign_variable_callback(limit_per_port)),
+ "supply_consumption_score", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(supply_consumption_score)),
+ "hull", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(hull)),
+ "gun_power", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(gun_power)),
+ "fire_range", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(fire_range)),
+ "evasion", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(evasion)),
+ "torpedo_attack", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(torpedo_attack))
+ )(value);
+
+ ret &= add_naval_unit(key, UNIT_ARGS, NAVY_ARGS);
+
+ return ret;
+ } else return false;
+ })(root);
+} \ No newline at end of file
diff --git a/src/openvic-simulation/units/Unit.hpp b/src/openvic-simulation/units/Unit.hpp
new file mode 100644
index 0000000..c9d3434
--- /dev/null
+++ b/src/openvic-simulation/units/Unit.hpp
@@ -0,0 +1,161 @@
+#pragma once
+
+#include <cstdint>
+#include <string_view>
+#include "openvic-simulation/economy/Good.hpp"
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/economy/Good.hpp"
+
+#define UNIT_PARAMS Unit::icon_t icon, Unit::sprite_t sprite, bool active, std::string_view 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, uint32_t build_time, \
+ std::map<const Good*, fixed_point_t> build_cost, fixed_point_t supply_consumption, \
+ std::map<const Good*, fixed_point_t> supply_cost
+#define LAND_PARAMS fixed_point_t reconnaissance, fixed_point_t attack, fixed_point_t defence, fixed_point_t discipline, \
+ fixed_point_t support, fixed_point_t maneuver, fixed_point_t siege
+#define NAVY_PARAMS Unit::icon_t naval_icon, bool sail, bool transport, bool capital, Unit::sound_t move_sound, \
+ Unit::sound_t select_sound, fixed_point_t colonial_points, bool build_overseas, uint32_t min_port_level, \
+ int32_t limit_per_port, fixed_point_t supply_consumption_score, fixed_point_t hull, fixed_point_t gun_power, \
+ fixed_point_t fire_range, fixed_point_t evasion, fixed_point_t torpedo_attack
+
+namespace OpenVic {
+ struct Unit : HasIdentifier {
+ using icon_t = uint32_t;
+ using sprite_t = std::string_view;
+ using sound_t = std::string_view;
+
+ private:
+ const std::string_view category;
+ const icon_t icon;
+ const sprite_t sprite;
+ const bool active;
+ const std::string_view type;
+ const bool floating_flag;
+
+ const uint32_t priority;
+ const fixed_point_t max_strength;
+ const fixed_point_t default_organisation;
+ const fixed_point_t maximum_speed;
+ const fixed_point_t weighted_value;
+
+ const uint32_t build_time;
+ const std::map<const Good*, fixed_point_t> build_cost;
+ const fixed_point_t supply_consumption;
+ const std::map<const Good*, fixed_point_t> supply_cost;
+
+ protected:
+ Unit(std::string_view identifier, std::string_view category, UNIT_PARAMS);
+
+ public:
+ Unit(Unit&&) = default;
+
+ icon_t get_icon() const;
+ std::string_view get_category() const;
+ sprite_t get_sprite() const;
+ bool is_active() const;
+ std::string_view get_type() const;
+ bool has_floating_flag() const;
+
+ uint32_t get_priority() const;
+ fixed_point_t get_max_strength() const;
+ fixed_point_t get_default_organisation() const;
+ fixed_point_t get_maximum_speed() const;
+ fixed_point_t get_weighted_value() const;
+
+ uint32_t get_build_time() const;
+ std::map<const Good*, fixed_point_t> const& get_build_cost() const;
+ fixed_point_t get_supply_consumption() const;
+ std::map<const Good*, fixed_point_t> const& get_supply_cost() const;
+ };
+
+ struct LandUnit : Unit {
+ friend struct UnitManager;
+
+ private:
+ const fixed_point_t reconnaissance;
+ const fixed_point_t attack;
+ const fixed_point_t defence;
+ const fixed_point_t discipline;
+ const fixed_point_t support;
+ const fixed_point_t maneuver;
+ const fixed_point_t siege;
+
+ LandUnit(std::string_view identifier, UNIT_PARAMS, LAND_PARAMS);
+
+ public:
+ LandUnit(LandUnit&&) = default;
+
+ fixed_point_t get_reconnaissance() const;
+ fixed_point_t get_attack() const;
+ fixed_point_t get_defence() const;
+ fixed_point_t get_discipline() const;
+ fixed_point_t get_support() const;
+ fixed_point_t get_maneuver() const;
+ fixed_point_t get_siege() const;
+ };
+
+ struct NavalUnit : Unit {
+ friend struct UnitManager;
+
+ private:
+ const icon_t naval_icon;
+ const bool sail;
+ const bool transport;
+ const bool capital;
+ const sound_t move_sound;
+ const sound_t select_sound;
+ const fixed_point_t colonial_points;
+ const bool build_overseas;
+ const uint32_t min_port_level;
+ const int32_t limit_per_port;
+ const fixed_point_t supply_consumption_score;
+
+ const fixed_point_t hull;
+ const fixed_point_t gun_power;
+ const fixed_point_t fire_range;
+ const fixed_point_t evasion;
+ const fixed_point_t torpedo_attack;
+
+ NavalUnit(std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS);
+
+ public:
+ NavalUnit(NavalUnit&&) = default;
+
+ icon_t get_naval_icon() const;
+ bool can_sail() const;
+ bool is_transport() const;
+ bool is_capital() const;
+ sound_t get_move_sound() const;
+ sound_t get_select_sound() const;
+ fixed_point_t get_colonial_points() const;
+ bool can_build_overseas() const;
+ uint32_t get_min_port_level() const;
+ int32_t get_limit_per_port() const;
+ fixed_point_t get_supply_consumption_score() const;
+
+ fixed_point_t get_hull() const;
+ fixed_point_t get_gun_power() const;
+ fixed_point_t get_fire_range() const;
+ fixed_point_t get_evasion() const;
+ fixed_point_t get_torpedo_attack() const;
+ };
+
+ struct UnitManager {
+ private:
+ GoodManager& good_manager;
+ IdentifierRegistry<Unit> units;
+
+ bool _check_shared_parameters(const std::string_view identifier, UNIT_PARAMS);
+
+ public:
+ UnitManager(GoodManager& good_manager);
+
+ bool add_land_unit(const std::string_view identifier, UNIT_PARAMS, LAND_PARAMS);
+ bool add_naval_unit(const std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS);
+ IDENTIFIER_REGISTRY_ACCESSORS(Unit, unit)
+
+ bool load_unit_file(ast::NodeCPtr root);
+ };
+} \ No newline at end of file