aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp3
-rw-r--r--src/openvic-simulation/units/Unit.cpp134
-rw-r--r--src/openvic-simulation/units/Unit.hpp58
3 files changed, 94 insertions, 101 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 55dbf8a..7cd955d 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -163,7 +163,8 @@ bool Dataloader::_load_units(UnitManager& unit_manager, fs::path const& units_di
}
);
unit_manager.lock_units();
- return ret;}
+ return ret;
+}
bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const {
Map& map = game_manager.map;
diff --git a/src/openvic-simulation/units/Unit.cpp b/src/openvic-simulation/units/Unit.cpp
index 63053c1..0ec4aa1 100644
--- a/src/openvic-simulation/units/Unit.cpp
+++ b/src/openvic-simulation/units/Unit.cpp
@@ -2,7 +2,10 @@
#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, supply_consumption_score
+ 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;
@@ -11,8 +14,7 @@ Unit::Unit(std::string_view identifier, std::string_view category, UNIT_PARAMS)
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 },
- supply_consumption_score { supply_consumption_score } {}
+ 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;
@@ -46,7 +48,7 @@ uint32_t Unit::get_default_organisation() const {
return default_organisation;
}
-uint32_t Unit::get_maximum_speed() const {
+fixed_point_t Unit::get_maximum_speed() const {
return maximum_speed;
}
@@ -70,47 +72,43 @@ std::map<const Good*, fixed_point_t> Unit::get_supply_cost() const {
return supply_cost;
}
-uint32_t Unit::get_supply_consumption_score() const {
- return supply_consumption_score;
-}
-
LandUnit::LandUnit(std::string_view identifier, UNIT_PARAMS, LAND_PARAMS) : Unit { identifier, "land", UNIT_ARGS },
- reconnaisance { reconnaisance }, attack { attack }, defence { defence }, discipline { discipline }, support { support },
+ reconnaissance { reconnaissance }, attack { attack }, defence { defence }, discipline { discipline }, support { support },
maneuver { maneuver }, siege { siege } {}
-uint32_t LandUnit::get_reconnaisance() const {
- return reconnaisance;
+fixed_point_t LandUnit::get_reconnaissance() const {
+ return reconnaissance;
}
-uint32_t LandUnit::get_attack() const {
+fixed_point_t LandUnit::get_attack() const {
return attack;
}
-uint32_t LandUnit::get_defence() const {
+fixed_point_t LandUnit::get_defence() const {
return defence;
}
-uint32_t LandUnit::get_discipline() const {
+fixed_point_t LandUnit::get_discipline() const {
return discipline;
}
-uint32_t LandUnit::get_support() const {
+fixed_point_t LandUnit::get_support() const {
return support;
}
-uint32_t LandUnit::get_maneuver() const {
+fixed_point_t LandUnit::get_maneuver() const {
return maneuver;
}
-uint32_t LandUnit::get_siege() const {
+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 }, 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 }, hull { hull }, gun_power { gun_power }, fire_range { fire_range }, evasion { evasion },
- torpedo_attack { torpedo_attack } {};
+ 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;
@@ -148,6 +146,10 @@ int32_t NavalUnit::get_limit_per_port() const {
return limit_per_port;
}
+uint32_t NavalUnit::get_supply_consumption_score() const {
+ return supply_consumption_score;
+}
+
uint32_t NavalUnit::get_hull() const {
return hull;
}
@@ -160,7 +162,7 @@ fixed_point_t NavalUnit::get_fire_range() const {
return fire_range;
}
-uint32_t NavalUnit::get_evasion() const {
+fixed_point_t NavalUnit::get_evasion() const {
return evasion;
}
@@ -168,7 +170,7 @@ uint32_t NavalUnit::get_torpedo_attack() const {
return torpedo_attack;
}
-UnitManager::UnitManager(GoodManager& game_manager) : good_manager { good_manager }, units { "units " } {};
+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()) {
@@ -196,9 +198,7 @@ bool UnitManager::add_land_unit(const std::string_view identifier, UNIT_PARAMS,
return false;
}
- return units.add_item(LandUnit {
- identifier, UNIT_ARGS, reconnaisance, attack, defence, discipline, support, maneuver, siege
- });
+ return units.add_item(LandUnit { identifier, UNIT_ARGS, LAND_ARGS });
}
bool UnitManager::add_naval_unit(const std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS) {
@@ -208,92 +208,82 @@ bool UnitManager::add_naval_unit(const std::string_view identifier, UNIT_PARAMS,
//TODO: check that icon and sounds exist
- return units.add_item(NavalUnit {
- identifier, UNIT_ARGS, naval_icon, sail, transport, move_sound, select_sound, colonial_points,
- build_overseas, min_port_level, limit_per_port, hull, gun_power, fire_range, evasion, torpedo_attack
- });
+ 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;
+ std::string_view category, type;
Unit::sprite_t sprite;
- bool active, floating_flag;
- std::string_view type;
- uint32_t priority, max_strength, default_organisation, maximum_speed, build_time, supply_consumption_score;
- fixed_point_t weighted_value, supply_consumption;
+ bool active = true, floating_flag;
+ uint32_t priority, max_strength, default_organisation, build_time;
+ fixed_point_t maximum_speed, weighted_value, supply_consumption;
std::map<const Good*, fixed_point_t> build_cost, supply_cost;
//shared
- bool ret = expect_dictionary_keys(
+ bool ret = expect_dictionary_keys(ALLOW_OTHER_KEYS,
"icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)),
- "type", ONE_EXACTLY, expect_string(assign_variable_callback(category)),
- "sprite", ONE_EXACTLY, expect_string(assign_variable_callback(sprite)),
- "active", ONE_EXACTLY, expect_bool(assign_variable_callback(active)),
- "unit_type", ONE_EXACTLY, expect_string(assign_variable_callback(type)),
+ "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_uint(assign_variable_callback(max_strength)),
"default_organisation", ONE_EXACTLY, expect_uint(assign_variable_callback(default_organisation)),
- "maximum_speed", ONE_EXACTLY, expect_uint(assign_variable_callback(maximum_speed)),
+ "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)),
- "supply_consumption_score", ONE_EXACTLY, expect_uint(assign_variable_callback(supply_consumption_score))
+ "supply_cost", ONE_EXACTLY, good_manager.expect_goods_map(assign_variable_callback(supply_cost))
)(value);
if (category == "land") {
- uint32_t reconnaisance, attack, defence, discipline, support, maneuver, siege;
-
- ret &= expect_dictionary_keys(
- "reconnaisance", ONE_EXACTLY, expect_uint(assign_variable_callback(reconnaisance)),
- "attack", ONE_EXACTLY, expect_uint(assign_variable_callback(attack)),
- "defence", ONE_EXACTLY, expect_uint(assign_variable_callback(defence)),
- "discipline", ONE_EXACTLY, expect_uint(assign_variable_callback(discipline)),
- "support", ONE_EXACTLY, expect_uint(assign_variable_callback(support)),
- "maneuver", ONE_EXACTLY, expect_uint(assign_variable_callback(maneuver)),
- "siege", ONE_EXACTLY, expect_uint(assign_variable_callback(siege))
+ 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,
- reconnaisance, attack, defence, discipline, support, maneuver, siege
- );
+ 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, build_overseas;
- Unit::sound_t move_sound, select_sound;
- uint32_t min_port_level, hull, gun_power, evasion, colonial_points = 0, torpedo_attack = 0; //probably?
+ 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, supply_consumption_score, hull, gun_power, colonial_points = 0, torpedo_attack = 0;
int32_t limit_per_port;
- fixed_point_t fire_range;
+ fixed_point_t fire_range, evasion;
- ret &= expect_dictionary_keys(
+ 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)),
- "move_sound", ONE_EXACTLY, expect_string(assign_variable_callback(move_sound)),
- "select_sound", ONE_EXACTLY, expect_string(assign_variable_callback(select_sound)),
+ "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_uint(assign_variable_callback(colonial_points)),
- "can_build_overseas", ONE_EXACTLY, expect_bool(assign_variable_callback(build_overseas)),
+ "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_uint(assign_variable_callback(supply_consumption_score)),
"hull", ONE_EXACTLY, expect_uint(assign_variable_callback(hull)),
"gun_power", ONE_EXACTLY, expect_uint(assign_variable_callback(gun_power)),
"fire_range", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(fire_range)),
- "evasion", ONE_EXACTLY, expect_uint(assign_variable_callback(evasion)),
+ "evasion", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(evasion)),
"torpedo_attack", ZERO_OR_ONE, expect_uint(assign_variable_callback(torpedo_attack))
)(value);
- ret &= add_naval_unit(
- key, UNIT_ARGS,
- naval_icon, sail, transport, move_sound, select_sound, colonial_points, build_overseas, min_port_level,
- limit_per_port, hull, gun_power, fire_range, evasion, torpedo_attack
- );
+ ret &= add_naval_unit(key, UNIT_ARGS, NAVY_ARGS);
return ret;
} else return false;
diff --git a/src/openvic-simulation/units/Unit.hpp b/src/openvic-simulation/units/Unit.hpp
index ccda35e..e95650e 100644
--- a/src/openvic-simulation/units/Unit.hpp
+++ b/src/openvic-simulation/units/Unit.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <cstdint>
-#include <string>
#include <string_view>
#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
@@ -11,14 +10,15 @@
#define UNIT_PARAMS Unit::icon_t icon, Unit::sprite_t sprite, bool active, std::string_view type, \
bool floating_flag, uint32_t priority, uint32_t max_strength, uint32_t default_organisation, \
- uint32_t maximum_speed, fixed_point_t weighted_value, uint32_t build_time, \
+ 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, uint32_t supply_consumption_score
-#define LAND_PARAMS uint32_t reconnaisance, uint32_t attack, uint32_t defence, uint32_t discipline, uint32_t support, \
- uint32_t maneuver, uint32_t siege
-#define NAVY_PARAMS Unit::icon_t naval_icon, bool sail, bool transport, Unit::sound_t move_sound, Unit::sound_t select_sound, \
- uint32_t colonial_points, bool build_overseas, uint32_t min_port_level, int32_t limit_per_port, \
- uint32_t hull, uint32_t gun_power, fixed_point_t fire_range, uint32_t evasion, uint32_t torpedo_attack
+ 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, uint32_t colonial_points, bool build_overseas, uint32_t min_port_level, \
+ int32_t limit_per_port, uint32_t supply_consumption_score, uint32_t hull, uint32_t gun_power, \
+ fixed_point_t fire_range, fixed_point_t evasion, uint32_t torpedo_attack
namespace OpenVic {
struct Unit : HasIdentifier {
@@ -37,14 +37,13 @@ namespace OpenVic {
const uint32_t priority;
const uint32_t max_strength;
const uint32_t default_organisation;
- const uint32_t maximum_speed;
+ 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;
- const uint32_t supply_consumption_score;
protected:
Unit(std::string_view identifier, std::string_view category, UNIT_PARAMS);
@@ -62,40 +61,39 @@ namespace OpenVic {
uint32_t get_priority() const;
uint32_t get_max_strength() const;
uint32_t get_default_organisation() const;
- uint32_t get_maximum_speed() 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> get_build_cost() const;
fixed_point_t get_supply_consumption() const;
std::map<const Good*, fixed_point_t> get_supply_cost() const;
- uint32_t get_supply_consumption_score() const;
};
struct LandUnit : Unit {
friend struct UnitManager;
private:
- const uint32_t reconnaisance;
- const uint32_t attack;
- const uint32_t defence;
- const uint32_t discipline;
- const uint32_t support;
- const uint32_t maneuver;
- const uint32_t siege;
+ 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;
- uint32_t get_reconnaisance() const;
- uint32_t get_attack() const;
- uint32_t get_defence() const;
- uint32_t get_discipline() const;
- uint32_t get_support() const;
- uint32_t get_maneuver() const;
- uint32_t get_siege() const;
+ 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 {
@@ -105,17 +103,19 @@ namespace OpenVic {
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 uint32_t colonial_points;
const bool build_overseas;
const uint32_t min_port_level;
const int32_t limit_per_port;
+ const uint32_t supply_consumption_score;
const uint32_t hull;
const uint32_t gun_power;
const fixed_point_t fire_range;
- const uint32_t evasion;
+ const fixed_point_t evasion;
const uint32_t torpedo_attack;
NavalUnit(std::string_view identifier, UNIT_PARAMS, NAVY_PARAMS);
@@ -126,17 +126,19 @@ namespace OpenVic {
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;
uint32_t get_colonial_points() const;
bool can_build_overseas() const;
uint32_t get_min_port_level() const;
int32_t get_limit_per_port() const;
+ uint32_t get_supply_consumption_score() const;
uint32_t get_hull() const;
uint32_t get_gun_power() const;
fixed_point_t get_fire_range() const;
- uint32_t get_evasion() const;
+ fixed_point_t get_evasion() const;
uint32_t get_torpedo_attack() const;
};