Implement config-driven unlock groups so that multiple things can be unlocked at once (including buildings)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Building.h"
|
||||
#include "BuildingSystem.h"
|
||||
#include "BuildingType.h"
|
||||
@@ -20,11 +22,24 @@ static GameConfig loadConfig()
|
||||
return ConfigLoader::loadFromDirectory(CONFIG_DIR);
|
||||
}
|
||||
|
||||
// A ship starts unlocked iff no unlock group grants it (REQ-LOCK-EXPLICIT).
|
||||
static bool startsUnlocked(const GameConfig& cfg, const std::string& shipId)
|
||||
{
|
||||
for (const UnlockGroupDef& group : cfg.unlocks.groups)
|
||||
{
|
||||
if (std::find(group.ships.begin(), group.ships.end(), shipId) != group.ships.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const ShipDef* findAvailableSchematic(const GameConfig& cfg)
|
||||
{
|
||||
for (const ShipDef& def : cfg.ships.ships)
|
||||
{
|
||||
if (def.unlockAtStationLevel == -1 && !def.schematic.materials.empty())
|
||||
if (startsUnlocked(cfg, def.id) && !def.schematic.materials.empty())
|
||||
{
|
||||
return &def;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user