aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/military/Unit.cpp
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-01-07 01:26:53 +0100
committer GitHub <noreply@github.com>2024-01-07 01:26:53 +0100
commit199a1b7915f4c431e733cfe037608f1310972cb4 (patch)
treed4773ca6709c056baa5043669190100246986ea8 /src/openvic-simulation/military/Unit.cpp
parentb06b25bd2910818029ebbf1cd3014ef20a64e25b (diff)
parent91988fc96a2ea0cd5766a304e93629678d22777c (diff)
Merge pull request #120 from OpenVicProject/support_accepted_culture_in_unit
Support culture restrictions for units
Diffstat (limited to 'src/openvic-simulation/military/Unit.cpp')
-rw-r--r--src/openvic-simulation/military/Unit.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/openvic-simulation/military/Unit.cpp b/src/openvic-simulation/military/Unit.cpp
index 0862741..db04335 100644
--- a/src/openvic-simulation/military/Unit.cpp
+++ b/src/openvic-simulation/military/Unit.cpp
@@ -6,7 +6,7 @@
std::move(supply_cost)
#define LAND_ARGS \
- primary_culture, sprite_override, sprite_mount, sprite_mount_attach_node, reconnaissance, attack, defence, discipline, \
+ allowed_cultures, sprite_override, sprite_mount, sprite_mount_attach_node, reconnaissance, attack, defence, discipline, \
support, maneuver, siege
#define NAVY_ARGS \
@@ -26,7 +26,7 @@ Unit::Unit(
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 },
+) : Unit { identifier, type_t::LAND, UNIT_ARGS }, allowed_cultures { allowed_cultures }, 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 } {}
@@ -127,12 +127,14 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
switch (type) {
case Unit::type_t::LAND: {
- bool primary_culture = false;
+ bool is_restricted_to_primary_culture = false;
+ bool is_restricted_to_accepted_cultures = false;
std::string_view sprite_override {}, sprite_mount {}, sprite_mount_attach_node {};
fixed_point_t reconnaissance = 0, attack = 0, defence = 0, discipline = 0, support = 0, maneuver = 0, siege = 0;
ret &= add_key_map_entries(key_map,
- "primary_culture", ZERO_OR_ONE, expect_bool(assign_variable_callback(primary_culture)),
+ "primary_culture", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_restricted_to_primary_culture)),
+ "accepted_culture", ZERO_OR_ONE, expect_bool(assign_variable_callback(is_restricted_to_accepted_cultures)),
"sprite_override", ZERO_OR_ONE, expect_identifier(assign_variable_callback(sprite_override)),
"sprite_mount", ZERO_OR_ONE, expect_identifier(assign_variable_callback(sprite_mount)),
"sprite_mount_attach_node", ZERO_OR_ONE, expect_identifier(assign_variable_callback(sprite_mount_attach_node)),
@@ -145,6 +147,15 @@ bool UnitManager::load_unit_file(GoodManager const& good_manager, ast::NodeCPtr
"siege", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(siege))
);
+ LandUnit::allowed_cultures_t allowed_cultures;
+ if (is_restricted_to_accepted_cultures) {
+ allowed_cultures = LandUnit::allowed_cultures_t::ACCEPTED_CULTURES;
+ } else if (is_restricted_to_primary_culture) {
+ allowed_cultures = LandUnit::allowed_cultures_t::PRIMARY_CULTURE;
+ } else {
+ allowed_cultures = LandUnit::allowed_cultures_t::ALL_CULTURES;
+ }
+
ret &= expect_dictionary_key_map(key_map)(value);
ret &= add_land_unit(key, UNIT_ARGS, LAND_ARGS);