Compare commits

...

3 commits

Author SHA1 Message Date
e786cf2d7a ResearchTree: add functions to read OS and arch unlocks.
Now the set is complete.
2021-08-03 20:40:42 +02:00
1cd91e1aaa ResearchTree: use normal ints in range-based for.
They're smaller than references, and they're trivially-copiable. They
shouldn't be passed by reference. 🤦
2021-08-03 20:39:40 +02:00
be4d1029c5 ResearchTree: add a missing early return. 2021-08-03 20:38:19 +02:00
2 changed files with 51 additions and 2 deletions

View file

@ -381,9 +381,10 @@ void ResearchTree::generateArchTree() {
void ResearchTree::readEngineUnlocks(Containers::ArrayView<Int> engines, Containers::ArrayView<Int> gears) {
if(engines == nullptr || engines.size() == 0) {
Utility::Error{} << "Engines can't be empty";
return;
}
for(Int& engine : engines) {
for(Int engine : engines) {
if(_engineNodes.find(engine) != _engineNodes.end()) {
_engineNodes.at(engine).setState(Node::State::Unlocked);
}
@ -393,13 +394,59 @@ void ResearchTree::readEngineUnlocks(Containers::ArrayView<Int> engines, Contain
return;
}
for(Int& gear : gears) {
for(Int gear : gears) {
if(_engineNodes.find(gear) != _engineNodes.end()) {
_engineNodes.at(gear).setState(Node::State::Unlocked);
}
}
}
void ResearchTree::readOSUnlocks(Containers::ArrayView<Int> os, Containers::ArrayView<Int> modules) {
if(os == nullptr || os.size() == 0) {
Utility::Error{} << "OSes can't be empty";
return;
}
for(Int os_id : os) {
if(_osNodes.find(os_id) != _osNodes.end()) {
_osNodes.at(os_id).setState(Node::State::Unlocked);
}
}
if(modules == nullptr || modules.size() == 0) {
return;
}
for(Int module : modules) {
if(_osNodes.find(module) != _osNodes.end()) {
_osNodes.at(module).setState(Node::State::Unlocked);
}
}
}
void ResearchTree::readArchUnlocks(Containers::ArrayView<Int> archs, Containers::ArrayView<Int> techs) {
if(archs == nullptr || archs.size() == 0) {
Utility::Error{} << "Archs can't be empty";
return;
}
for(Int arch : archs) {
if(_archNodes.find(arch) != _archNodes.end()) {
_archNodes.at(arch).setState(Node::State::Unlocked);
}
}
if(techs == nullptr || techs.size() == 0) {
return;
}
for(Int tech : techs) {
if(_archNodes.find(tech) != _archNodes.end()) {
_archNodes.at(tech).setState(Node::State::Unlocked);
}
}
}
auto ResearchTree::getEngineRootNode() -> Node& {
return _engineNodes.at(VerseEngine);
}

View file

@ -99,6 +99,8 @@ class ResearchTree {
void generateArchTree();
void readEngineUnlocks(Containers::ArrayView<Int> engines, Containers::ArrayView<Int> gears = nullptr);
void readOSUnlocks(Containers::ArrayView<Int> os, Containers::ArrayView<Int> modules = nullptr);
void readArchUnlocks(Containers::ArrayView<Int> archs, Containers::ArrayView<Int> techs = nullptr);
auto getEngineRootNode() -> Node&;
auto getOSRootNode() -> Node&;