aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/units/Unit.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/units/Unit.hpp')
-rw-r--r--src/openvic-simulation/units/Unit.hpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/openvic-simulation/units/Unit.hpp b/src/openvic-simulation/units/Unit.hpp
index b105afc..9653526 100644
--- a/src/openvic-simulation/units/Unit.hpp
+++ b/src/openvic-simulation/units/Unit.hpp
@@ -1,16 +1,20 @@
#pragma once
#include <cstdint>
+#include <set>
#include <string>
#include <string_view>
+#include <unordered_set>
#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, UnitType 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, std::map<const Good*, fixed_point_t> build_cost, fixed_point_t supply_consumption, \
+#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, \
+ 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
@@ -19,32 +23,17 @@
uint32_t hull, uint32_t gun_power, fixed_point_t fire_range, uint32_t evasion, uint32_t torpedo_attack
namespace OpenVic {
- enum UnitCategory {
- NAVAL,
- LAND
- };
-
- enum UnitType {
- INFANTRY, //guard, infantry, irregular
- CAVALRY, //cavalry, cuirassier, dragoon, hussar, plane
- SUPPORT, //artillery
- SPECIAL, //engineer, tank
- TRANSPORT, //clipper transport, steam transport
- LIGHT_SHIP, //commerce raider, cruiser, frigate
- BIG_SHIP //battleship, dreadnought, ironclad, manowar, monitor
- };
-
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 UnitCategory category; //type
const sprite_t sprite;
const bool active;
- const UnitType type; //unit_type
+ const std::string_view type;
const bool floating_flag;
const uint32_t priority;
@@ -60,16 +49,16 @@ namespace OpenVic {
const uint32_t supply_consumption_score;
protected:
- Unit(std::string_view identifier, UnitCategory category, UNIT_PARAMS);
+ Unit(std::string_view identifier, std::string_view category, UNIT_PARAMS);
public:
Unit(Unit&&) = default;
icon_t get_icon() const;
- UnitCategory get_category() const;
+ std::string_view get_category() const;
sprite_t get_sprite() const;
bool is_active() const;
- UnitType get_type() const;
+ std::string_view get_type() const;
bool has_floating_flag() const;
uint32_t get_priority() const;
@@ -120,10 +109,10 @@ namespace OpenVic {
const bool transport;
const sound_t move_sound;
const sound_t select_sound;
- const uint32_t colonial_points; //some
- const bool build_overseas; //can_build_overseas
+ const uint32_t colonial_points;
+ const bool build_overseas;
const uint32_t min_port_level;
- const int32_t limit_per_port; //-1 is unlimited
+ const int32_t limit_per_port;
const uint32_t hull;
const uint32_t gun_power;
@@ -155,15 +144,26 @@ namespace OpenVic {
struct UnitManager {
private:
+ GoodManager& good_manager;
IdentifierRegistry<Unit> units;
- bool _check_superclass_parameters(const std::string_view identifier, UnitCategory cat, UNIT_PARAMS);
+ bool _check_shared_parameters(const std::string_view identifier, UNIT_PARAMS);
public:
- UnitManager();
-
- bool add_land_unit(const std::string_view identifier, UnitCategory cat, UNIT_PARAMS, LAND_PARAMS);
- bool add_naval_unit(const std::string_view identifier, UnitCategory cat, UNIT_PARAMS, NAVY_PARAMS);
+ const std::unordered_set<std::string_view> allowed_unit_types { //TODO is this useful?
+ "infantry", //guard, infantry, irregular
+ "cavalry", //cavalry, cuirassier, dragoon, hussar, plane
+ "support", //artillery
+ "special", //engineer, tank
+ "transport", //clipper transport, steam transport
+ "light_ship", //commerce raider, cruiser, frigate
+ "big_ship" //battleship, dreadnought, ironclad, manowar, monitor
+ };
+
+ 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);