aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/research/Invention.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/research/Invention.cpp')
-rw-r--r--src/openvic-simulation/research/Invention.cpp99
1 files changed, 51 insertions, 48 deletions
diff --git a/src/openvic-simulation/research/Invention.cpp b/src/openvic-simulation/research/Invention.cpp
index eb4e342..381a249 100644
--- a/src/openvic-simulation/research/Invention.cpp
+++ b/src/openvic-simulation/research/Invention.cpp
@@ -1,23 +1,26 @@
#include "Invention.hpp"
-#include <algorithm>
-#include <cstring>
-#include <utility>
+
+#include "openvic-simulation/economy/BuildingType.hpp"
+#include "openvic-simulation/map/Crime.hpp"
+#include "openvic-simulation/military/Unit.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
Invention::Invention(
- std::string_view identifier, ModifierValue&& values, bool news, unit_set_t activated_units, building_set_t activated_buildings,
- crime_set_t enabled_crimes, bool unlock_gas_attack, bool unlock_gas_defence)
- : Modifier { identifier, std::move(values), 0 },
- news { news }, activated_units { std::move(activated_units) }, activated_buildings { std::move(activated_buildings) },
- enabled_crimes { std::move(enabled_crimes) }, unlock_gas_attack { unlock_gas_attack }, unlock_gas_defence { unlock_gas_defence } {} //TODO icon
+ std::string_view new_identifier, ModifierValue&& new_values, bool new_news, unit_set_t&& new_activated_units,
+ building_set_t&& new_activated_buildings, crime_set_t&& new_enabled_crimes, bool new_unlock_gas_attack,
+ bool new_unlock_gas_defence
+) : Modifier { new_identifier, std::move(new_values), 0 }, news { new_news },
+ activated_units { std::move(new_activated_units) }, activated_buildings { std::move(new_activated_buildings) },
+ enabled_crimes { std::move(new_enabled_crimes) }, unlock_gas_attack { new_unlock_gas_attack },
+ unlock_gas_defence { new_unlock_gas_defence } {} //TODO icon
InventionManager::InventionManager() : inventions { "inventions" } {}
bool InventionManager::add_invention(
- std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t activated_units,
- Invention::building_set_t activated_buildings, Invention::crime_set_t enabled_crimes,
+ std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t&& activated_units,
+ Invention::building_set_t&& activated_buildings, Invention::crime_set_t&& enabled_crimes,
bool unlock_gas_attack, bool unlock_gas_defence
) {
if (identifier.empty()) {
@@ -32,49 +35,49 @@ bool InventionManager::add_invention(
}
bool InventionManager::load_inventions_file(
- ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, ast::NodeCPtr root
+ ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingTypeManager const& building_type_manager,
+ CrimeManager const& crime_manager, ast::NodeCPtr root
) {
- return expect_dictionary_reserve_length(inventions, [this, &modifier_manager, &unit_manager, &building_manager](std::string_view identifier, ast::NodeCPtr value) -> bool {
- ModifierValue loose_modifiers;
- ModifierValue modifiers;
+ return expect_dictionary_reserve_length(
+ inventions, [this, &modifier_manager, &unit_manager, &building_type_manager, &crime_manager](
+ std::string_view identifier, ast::NodeCPtr value) -> bool {
+ ModifierValue loose_modifiers;
+ ModifierValue modifiers;
- Invention::unit_set_t activated_units;
- Invention::building_set_t activated_buildings;
- Invention::crime_set_t enabled_crimes;
+ Invention::unit_set_t activated_units;
+ Invention::building_set_t activated_buildings;
+ Invention::crime_set_t enabled_crimes;
- bool unlock_gas_attack = false;
- bool unlock_gas_defence = false;
- bool news = true; //defaults to true!
+ bool unlock_gas_attack = false;
+ bool unlock_gas_defence = false;
+ bool news = true; //defaults to true!
- bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(loose_modifiers),
- "news", ZERO_OR_ONE, expect_bool(assign_variable_callback(news)),
- "limit", ONE_EXACTLY, success_callback,
- "chance", ONE_EXACTLY, success_callback,
- "effect", ZERO_OR_ONE, modifier_manager.expect_modifier_value_and_keys(
- move_variable_callback(modifiers),
- "gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)),
- "gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)),
- "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier([this, &activated_units](Unit const& unit) -> bool {
- activated_units.insert(&unit);
- return true;
- }),
- "activate_building", ZERO_OR_MORE, building_manager.expect_building_type_identifier([this, &activated_buildings](BuildingType const& type) -> bool {
- activated_buildings.insert(&type);
- return true;
- }),
- "enable_crime", ZERO_OR_ONE, modifier_manager.expect_crime_modifier_identifier([this, &enabled_crimes](Crime const& crime) -> bool {
- enabled_crimes.insert(&crime);
- return true;
- }))
- )(value);
+ bool ret = modifier_manager.expect_modifier_value_and_keys(move_variable_callback(loose_modifiers),
+ "news", ZERO_OR_ONE, expect_bool(assign_variable_callback(news)),
+ "limit", ONE_EXACTLY, success_callback,
+ "chance", ONE_EXACTLY, success_callback,
+ "effect", ZERO_OR_ONE, modifier_manager.expect_modifier_value_and_keys(
+ move_variable_callback(modifiers),
+ "gas_attack", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_attack)),
+ "gas_defence", ZERO_OR_ONE, expect_bool(assign_variable_callback(unlock_gas_defence)),
+ "activate_unit", ZERO_OR_MORE, unit_manager.expect_unit_identifier(set_callback_pointer(activated_units)),
+ "activate_building", ZERO_OR_MORE, building_type_manager.expect_building_type_identifier(
+ set_callback_pointer(activated_buildings)
+ ),
+ "enable_crime", ZERO_OR_ONE, crime_manager.expect_crime_modifier_identifier(
+ set_callback_pointer(enabled_crimes)
+ )
+ )
+ )(value);
- modifiers += loose_modifiers;
+ modifiers += loose_modifiers;
- ret &= add_invention(
- identifier, std::move(modifiers), news, activated_units, activated_buildings, enabled_crimes,
- unlock_gas_attack, unlock_gas_defence
- );
+ ret &= add_invention(
+ identifier, std::move(modifiers), news, std::move(activated_units), std::move(activated_buildings),
+ std::move(enabled_crimes), unlock_gas_attack, unlock_gas_defence
+ );
- return ret;
- })(root);
+ return ret;
+ }
+ )(root);
} \ No newline at end of file