Implement config-driven unlock groups so that multiple things can be unlocked at once (including buildings)

This commit is contained in:
2026-07-22 21:34:59 +02:00
parent a8a6a04f1e
commit a9082c57f3
36 changed files with 1005 additions and 543 deletions

View File

@@ -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;
}