aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/units
diff options
context:
space:
mode:
author CptAlanSmith <123112708+CptAlanSmith@users.noreply.github.com>2023-09-23 20:25:15 +0200
committer GitHub <noreply@github.com>2023-09-23 20:25:15 +0200
commit005a8026bb424779a146e00cc48621ff1d72b807 (patch)
treedde15211e31d861b61711bf6aebdeb8713393d53 /src/openvic-simulation/units
parentebea2e473eefa3945508b0bf622a472b62d70d3b (diff)
Testing (#23)
* Fixes for building scons * Initial proof of concept auto-testing Shows how we can pull loaded data and display it back * Re-did headless Because hubert insisted it be done like this ;) * Auto-Testing Framework Basics * Requirements Calculations * Fix for messy merge (teach me to use merge tools) * Fixing up misc merge issues to fully reconcile with master changes * Re-added missing getters * Move of testing files due to folder reorgs * Use new accessors + int reading fix --------- Co-authored-by: Hop311 <hop3114@gmail.com>
Diffstat (limited to 'src/openvic-simulation/units')
-rw-r--r--src/openvic-simulation/units/Unit.cpp24
-rw-r--r--src/openvic-simulation/units/Unit.hpp11
2 files changed, 17 insertions, 18 deletions
diff --git a/src/openvic-simulation/units/Unit.cpp b/src/openvic-simulation/units/Unit.cpp
index ebf4985..f57e0a7 100644
--- a/src/openvic-simulation/units/Unit.cpp
+++ b/src/openvic-simulation/units/Unit.cpp
@@ -170,7 +170,7 @@ fixed_point_t NavalUnit::get_torpedo_attack() const {
return torpedo_attack;
}
-UnitManager::UnitManager(GoodManager& good_manager) : good_manager { good_manager }, units { "units" } {};
+UnitManager::UnitManager() : units { "units" } {}
bool UnitManager::_check_shared_parameters(const std::string_view identifier, UNIT_PARAMS) {
if (identifier.empty()) {
@@ -211,8 +211,8 @@ bool UnitManager::add_naval_unit(const std::string_view identifier, UNIT_PARAMS,
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 {
+bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr root) {
+ return NodeTools::expect_dictionary([this, &good_manager](std::string_view key, ast::NodeCPtr value) -> bool {
Unit::icon_t icon;
std::string_view category, type;
Unit::sprite_t sprite;
@@ -223,21 +223,21 @@ bool UnitManager::load_unit_file(ast::NodeCPtr root) {
//shared
bool ret = expect_dictionary_keys(ALLOW_OTHER_KEYS,
- "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)),
+ "icon", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("unit icon", 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)),
+ "priority", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("unit priority", 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))
+ "build_time", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("unit build time", build_time)),
+ "build_cost", ONE_EXACTLY, good_manager.expect_good_decimal_map(assign_variable_callback(build_cost)),
+ "supply_consumption", ONE_EXACTLY, expect_fixed_point(move_variable_callback(supply_consumption)),
+ "supply_cost", ONE_EXACTLY, good_manager.expect_good_decimal_map(move_variable_callback(supply_cost))
)(value);
if (category == "land") {
@@ -265,7 +265,7 @@ bool UnitManager::load_unit_file(ast::NodeCPtr root) {
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)),
+ "naval_icon", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("unit naval icon", 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)),
@@ -273,8 +273,8 @@ bool UnitManager::load_unit_file(ast::NodeCPtr root) {
"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)),
+ "min_port_level", ONE_EXACTLY, expect_uint(assign_variable_callback_uint("unit min port level", min_port_level)),
+ "limit_per_port", ONE_EXACTLY, expect_int(assign_variable_callback_int("unit limit per port", 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)),
diff --git a/src/openvic-simulation/units/Unit.hpp b/src/openvic-simulation/units/Unit.hpp
index c9d3434..507adbd 100644
--- a/src/openvic-simulation/units/Unit.hpp
+++ b/src/openvic-simulation/units/Unit.hpp
@@ -47,7 +47,7 @@ namespace OpenVic {
protected:
Unit(std::string_view identifier, std::string_view category, UNIT_PARAMS);
-
+
public:
Unit(Unit&&) = default;
@@ -98,7 +98,7 @@ namespace OpenVic {
struct NavalUnit : Unit {
friend struct UnitManager;
-
+
private:
const icon_t naval_icon;
const bool sail;
@@ -144,18 +144,17 @@ namespace OpenVic {
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);
+ UnitManager();
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);
+ bool load_unit_file(GoodManager const& good_manager, ast::NodeCPtr root);
};
} \ No newline at end of file