-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented invention dataloading
- Loading branch information
Showing
13 changed files
with
283 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "Invention.hpp" | ||
#include <algorithm> | ||
#include <cstring> | ||
#include <utility> | ||
|
||
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, 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) }, unlock_gas_attack { unlock_gas_attack }, unlock_gas_defence { 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, bool unlock_gas_attack, bool unlock_gas_defence) { | ||
if (identifier.empty()) { | ||
Logger::error("Invalid invention identifier - empty!"); | ||
return false; | ||
} | ||
|
||
return inventions.add_item({ identifier, std::move(values), news, std::move(activated_units), std::move(activated_buildings), unlock_gas_attack, unlock_gas_defence }); | ||
} | ||
|
||
bool InventionManager::load_inventions_file(ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_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; | ||
|
||
Invention::unit_set_t activated_units; | ||
Invention::building_set_t activated_buildings; | ||
Invention::crime_set_t enabled_crimes; | ||
|
||
bool unlock_gas_attack = true; | ||
bool unlock_gas_defence = true; | ||
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); | ||
|
||
modifiers += loose_modifiers; | ||
|
||
ret &= add_invention(identifier, std::move(modifiers), news, activated_units, activated_buildings, unlock_gas_attack, unlock_gas_defence); | ||
|
||
return ret; | ||
})(root); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include "openvic-simulation/economy/BuildingType.hpp" | ||
#include "openvic-simulation/military/Unit.hpp" | ||
#include "openvic-simulation/misc/Modifier.hpp" | ||
#include "openvic-simulation/types/IdentifierRegistry.hpp" | ||
#include <string_view> | ||
#include <unordered_set> | ||
|
||
namespace OpenVic { | ||
struct Invention : Modifier { | ||
friend struct InventionManager; | ||
//TODO implement limit and chance | ||
using unit_set_t = std::unordered_set<Unit const*>; | ||
using building_set_t = std::unordered_set<BuildingType const*>; | ||
using crime_set_t = std::unordered_set<Crime const*>; | ||
|
||
private: | ||
const bool PROPERTY_CUSTOM_PREFIX(news, is); | ||
unit_set_t PROPERTY(activated_units); | ||
building_set_t PROPERTY(activated_buildings); | ||
crime_set_t PROPERTY(enabled_crimes); | ||
const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_attack, will); | ||
const bool PROPERTY_CUSTOM_PREFIX(unlock_gas_defence, will); | ||
|
||
Invention( | ||
std::string_view identifier, ModifierValue&& values, bool news, unit_set_t activated_units, | ||
building_set_t activated_buildings, bool unlock_gas_attack, bool unlock_gas_defence | ||
); | ||
|
||
public: | ||
Invention(Invention&&) = default; | ||
}; | ||
|
||
struct InventionManager { | ||
IdentifierRegistry<Invention> inventions; | ||
|
||
public: | ||
InventionManager(); | ||
|
||
bool add_invention( | ||
std::string_view identifier, ModifierValue&& values, bool news, Invention::unit_set_t activated_units, | ||
Invention::building_set_t activated_buildings, bool unlock_gas_attack, bool unlock_gas_defence | ||
); | ||
|
||
IDENTIFIER_REGISTRY_ACCESSORS(invention); | ||
|
||
bool load_inventions_file(ModifierManager const& modifier_manager, UnitManager const& unit_manager, BuildingManager const& building_manager, ast::NodeCPtr root); // inventions/*.txt | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "openvic-simulation/research/Invention.hpp" | ||
#include "openvic-simulation/research/Technology.hpp" | ||
|
||
namespace OpenVic { | ||
struct ResearchManager { | ||
private: | ||
TechnologyManager PROPERTY_REF(technology_manager); | ||
InventionManager PROPERTY_REF(invention_manager); | ||
}; | ||
} |
Oops, something went wrong.