add findShipDef/findModuleDef/findRecipeDef to config structs and re-use them in the rest of the code base
This commit is contained in:
@@ -59,4 +59,18 @@ struct ModuleDef
|
|||||||
struct ModulesConfig
|
struct ModulesConfig
|
||||||
{
|
{
|
||||||
std::vector<ModuleDef> modules;
|
std::vector<ModuleDef> modules;
|
||||||
|
|
||||||
|
// Returns the definition for the given module id, or nullptr if the id has
|
||||||
|
// no entry in modules.toml.
|
||||||
|
const ModuleDef* findModuleDef(const std::string& id) const
|
||||||
|
{
|
||||||
|
for (const ModuleDef& def : modules)
|
||||||
|
{
|
||||||
|
if (def.id == id)
|
||||||
|
{
|
||||||
|
return &def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,4 +47,32 @@ struct RecipeDef
|
|||||||
struct RecipesConfig
|
struct RecipesConfig
|
||||||
{
|
{
|
||||||
std::vector<RecipeDef> recipes;
|
std::vector<RecipeDef> recipes;
|
||||||
|
|
||||||
|
// Returns the definition for the given recipe id, or nullptr if the id has
|
||||||
|
// no entry in recipes.toml.
|
||||||
|
const RecipeDef* findRecipeDef(const std::string& id) const
|
||||||
|
{
|
||||||
|
for (const RecipeDef& recipe : recipes)
|
||||||
|
{
|
||||||
|
if (recipe.id == id)
|
||||||
|
{
|
||||||
|
return &recipe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same, but additionally requires the recipe to belong to the given building
|
||||||
|
// type — recipe ids are only unique per building type.
|
||||||
|
const RecipeDef* findRecipeDef(const std::string& id, BuildingType building) const
|
||||||
|
{
|
||||||
|
for (const RecipeDef& recipe : recipes)
|
||||||
|
{
|
||||||
|
if (recipe.id == id && recipe.building == building)
|
||||||
|
{
|
||||||
|
return &recipe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,4 +49,18 @@ struct ShipDef
|
|||||||
struct ShipsConfig
|
struct ShipsConfig
|
||||||
{
|
{
|
||||||
std::vector<ShipDef> ships;
|
std::vector<ShipDef> ships;
|
||||||
|
|
||||||
|
// Returns the definition for the given ship schematic id, or nullptr if the
|
||||||
|
// id has no entry in ships.toml.
|
||||||
|
const ShipDef* findShipDef(const std::string& id) const
|
||||||
|
{
|
||||||
|
for (const ShipDef& def : ships)
|
||||||
|
{
|
||||||
|
if (def.id == id)
|
||||||
|
{
|
||||||
|
return &def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,35 +41,11 @@ ShipSystem::ShipSystem(const GameConfig& config, EntityAdmin& admin)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShipDef* ShipSystem::findShipDef(const std::string& schematicId) const
|
|
||||||
{
|
|
||||||
for (const ShipDef& def : m_config.ships.ships)
|
|
||||||
{
|
|
||||||
if (def.id == schematicId)
|
|
||||||
{
|
|
||||||
return &def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ModuleDef* ShipSystem::findModuleDef(const std::string& id) const
|
|
||||||
{
|
|
||||||
for (const ModuleDef& def : m_config.modules.modules)
|
|
||||||
{
|
|
||||||
if (def.id == id)
|
|
||||||
{
|
|
||||||
return &def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
entt::entity ShipSystem::spawn(const std::string& schematicId,
|
entt::entity ShipSystem::spawn(const std::string& schematicId,
|
||||||
QVector2D position, bool isEnemy,
|
QVector2D position, bool isEnemy,
|
||||||
const std::optional<ShipLayoutConfig>& layout)
|
const std::optional<ShipLayoutConfig>& layout)
|
||||||
{
|
{
|
||||||
const ShipDef* def = findShipDef(schematicId);
|
const ShipDef* def = m_config.ships.findShipDef(schematicId);
|
||||||
assert(def != nullptr);
|
assert(def != nullptr);
|
||||||
|
|
||||||
const float tickRate = static_cast<float>(kTickRateHz);
|
const float tickRate = static_cast<float>(kTickRateHz);
|
||||||
@@ -116,7 +92,7 @@ entt::entity ShipSystem::spawn(const std::string& schematicId,
|
|||||||
|
|
||||||
for (const PlacedModule& pm : modules)
|
for (const PlacedModule& pm : modules)
|
||||||
{
|
{
|
||||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||||
if (!modDef) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
if (!modDef) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
||||||
|
|
||||||
if (modDef->weaponCapability)
|
if (modDef->weaponCapability)
|
||||||
@@ -184,7 +160,7 @@ entt::entity ShipSystem::spawn(const std::string& schematicId,
|
|||||||
|
|
||||||
for (const PlacedModule& pm : modules)
|
for (const PlacedModule& pm : modules)
|
||||||
{
|
{
|
||||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||||
if (!modDef) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
if (!modDef) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
||||||
|
|
||||||
for (const ModuleStatModifier& sm : modDef->statModifiers)
|
for (const ModuleStatModifier& sm : modDef->statModifiers)
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ public:
|
|||||||
void setRetreatEnabled(bool enabled);
|
void setRetreatEnabled(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ShipDef* findShipDef(const std::string& schematicId) const;
|
|
||||||
const ModuleDef* findModuleDef(const std::string& id) const;
|
|
||||||
|
|
||||||
const GameConfig& m_config;
|
const GameConfig& m_config;
|
||||||
EntityAdmin& m_admin;
|
EntityAdmin& m_admin;
|
||||||
QVector2D m_rallyPoint;
|
QVector2D m_rallyPoint;
|
||||||
|
|||||||
@@ -107,43 +107,6 @@ const BuildingDef* BuildingSystem::findBuildingDef(BuildingType type) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RecipeDef* BuildingSystem::findRecipe(const std::string& id,
|
|
||||||
BuildingType type) const
|
|
||||||
{
|
|
||||||
for (const RecipeDef& recipe : m_config.recipes.recipes)
|
|
||||||
{
|
|
||||||
if (recipe.id == id && recipe.building == type)
|
|
||||||
{
|
|
||||||
return &recipe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ShipDef* BuildingSystem::findShipDef(const std::string& id) const
|
|
||||||
{
|
|
||||||
for (const ShipDef& def : m_config.ships.ships)
|
|
||||||
{
|
|
||||||
if (def.id == id)
|
|
||||||
{
|
|
||||||
return &def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ModuleDef* BuildingSystem::findModuleDef(const std::string& id) const
|
|
||||||
{
|
|
||||||
for (const ModuleDef& def : m_config.modules.modules)
|
|
||||||
{
|
|
||||||
if (def.id == id)
|
|
||||||
{
|
|
||||||
return &def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingSystem::initBuffers(Building& b, const RecipeDef& recipe) const
|
void BuildingSystem::initBuffers(Building& b, const RecipeDef& recipe) const
|
||||||
{
|
{
|
||||||
b.inputBuffer.counts.clear();
|
b.inputBuffer.counts.clear();
|
||||||
@@ -237,7 +200,7 @@ void BuildingSystem::initShipyardBuffers(Building& b) const
|
|||||||
b.inputBuffer.caps.clear();
|
b.inputBuffer.caps.clear();
|
||||||
b.outputBuffer.items.clear();
|
b.outputBuffer.items.clear();
|
||||||
b.outputBuffer.capacity = 0;
|
b.outputBuffer.capacity = 0;
|
||||||
const ShipDef* def = findShipDef(b.recipeId);
|
const ShipDef* def = m_config.ships.findShipDef(b.recipeId);
|
||||||
if (!def)
|
if (!def)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -252,7 +215,7 @@ void BuildingSystem::initShipyardBuffers(Building& b) const
|
|||||||
{
|
{
|
||||||
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
||||||
{
|
{
|
||||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||||
if (!modDef)
|
if (!modDef)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -646,7 +609,7 @@ void BuildingSystem::setRecipe(BuildingId id, const std::string& recipeId)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const RecipeDef* recipe = findRecipe(recipeId, building.type);
|
const RecipeDef* recipe = m_config.recipes.findRecipeDef(recipeId, building.type);
|
||||||
if (recipe)
|
if (recipe)
|
||||||
{
|
{
|
||||||
initBuffers(building, *recipe);
|
initBuffers(building, *recipe);
|
||||||
@@ -809,7 +772,7 @@ void BuildingSystem::tickConstruction(Tick currentTick)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const RecipeDef* recipe = findRecipe(building.recipeId, building.type);
|
const RecipeDef* recipe = m_config.recipes.findRecipeDef(building.recipeId, building.type);
|
||||||
if (recipe)
|
if (recipe)
|
||||||
{
|
{
|
||||||
initBuffers(building, *recipe);
|
initBuffers(building, *recipe);
|
||||||
@@ -1187,7 +1150,7 @@ void BuildingSystem::tickShipyardProduction(Tick currentTick)
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const ShipDef* shipDef = findShipDef(building.recipeId);
|
const ShipDef* shipDef = m_config.ships.findShipDef(building.recipeId);
|
||||||
if (!shipDef)
|
if (!shipDef)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -1252,7 +1215,7 @@ void BuildingSystem::tickShipyardProduction(Tick currentTick)
|
|||||||
{
|
{
|
||||||
for (const PlacedModule& pm : building.shipLayout->placedModules)
|
for (const PlacedModule& pm : building.shipLayout->placedModules)
|
||||||
{
|
{
|
||||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||||
if (modDef)
|
if (modDef)
|
||||||
{
|
{
|
||||||
totalTime += modDef->productionTimeSeconds;
|
totalTime += modDef->productionTimeSeconds;
|
||||||
@@ -1466,7 +1429,7 @@ BuildingSystem::gatherCandidateRecipes(const Building& b) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const RecipeDef* recipe = findRecipe(b.recipeId, b.type);
|
const RecipeDef* recipe = m_config.recipes.findRecipeDef(b.recipeId, b.type);
|
||||||
if (recipe)
|
if (recipe)
|
||||||
{
|
{
|
||||||
candidates.push_back(recipe);
|
candidates.push_back(recipe);
|
||||||
@@ -1495,7 +1458,7 @@ std::map<std::string, int>
|
|||||||
BuildingSystem::computeShipyardRequiredMaterials(const Building& b) const
|
BuildingSystem::computeShipyardRequiredMaterials(const Building& b) const
|
||||||
{
|
{
|
||||||
std::map<std::string, int> requiredMaterials;
|
std::map<std::string, int> requiredMaterials;
|
||||||
const ShipDef* shipDef = findShipDef(b.recipeId);
|
const ShipDef* shipDef = m_config.ships.findShipDef(b.recipeId);
|
||||||
if (!shipDef)
|
if (!shipDef)
|
||||||
{
|
{
|
||||||
return requiredMaterials;
|
return requiredMaterials;
|
||||||
@@ -1508,7 +1471,7 @@ BuildingSystem::computeShipyardRequiredMaterials(const Building& b) const
|
|||||||
{
|
{
|
||||||
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
||||||
{
|
{
|
||||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||||
if (!modDef)
|
if (!modDef)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -268,9 +268,6 @@ private:
|
|||||||
bool hasInputsToStart(const Building& b) const;
|
bool hasInputsToStart(const Building& b) const;
|
||||||
|
|
||||||
const BuildingDef* findBuildingDef(BuildingType type) const;
|
const BuildingDef* findBuildingDef(BuildingType type) const;
|
||||||
const RecipeDef* findRecipe(const std::string& id, BuildingType type) const;
|
|
||||||
const ShipDef* findShipDef(const std::string& id) const;
|
|
||||||
const ModuleDef* findModuleDef(const std::string& id) const;
|
|
||||||
void initBuffers(Building& b, const RecipeDef& recipe) const;
|
void initBuffers(Building& b, const RecipeDef& recipe) const;
|
||||||
// Buffers for an auto-recipe building (Smelter, Reprocessing Plant): input
|
// Buffers for an auto-recipe building (Smelter, Reprocessing Plant): input
|
||||||
// caps span the union of every recipe of the building's type; no player
|
// caps span the union of every recipe of the building's type; no player
|
||||||
|
|||||||
@@ -21,22 +21,9 @@ ShipStats calculateShipStats(const GameConfig& config,
|
|||||||
{
|
{
|
||||||
ShipStats result{};
|
ShipStats result{};
|
||||||
|
|
||||||
const ShipDef* shipDef = nullptr;
|
const ShipDef* shipDef = config.ships.findShipDef(shipId);
|
||||||
for (const ShipDef& d : config.ships.ships)
|
|
||||||
{
|
|
||||||
if (d.id == shipId) { shipDef = &d; break; }
|
|
||||||
}
|
|
||||||
if (!shipDef) { return result; }
|
if (!shipDef) { return result; }
|
||||||
|
|
||||||
auto findModuleDef = [&](const std::string& id) -> const ModuleDef*
|
|
||||||
{
|
|
||||||
for (const ModuleDef& d : config.modules.modules)
|
|
||||||
{
|
|
||||||
if (d.id == id) { return &d; }
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
const double tileSize = config.world.tileSize_m;
|
const double tileSize = config.world.tileSize_m;
|
||||||
|
|
||||||
// --- Base hull stats (convert from SI to display units) ------------------
|
// --- Base hull stats (convert from SI to display units) ------------------
|
||||||
@@ -67,7 +54,7 @@ ShipStats calculateShipStats(const GameConfig& config,
|
|||||||
|
|
||||||
for (const PlacedModule& pm : modules)
|
for (const PlacedModule& pm : modules)
|
||||||
{
|
{
|
||||||
const ModuleDef* def = findModuleDef(pm.moduleId);
|
const ModuleDef* def = config.modules.findModuleDef(pm.moduleId);
|
||||||
if (!def) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
if (!def) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
||||||
|
|
||||||
if (def->weaponCapability)
|
if (def->weaponCapability)
|
||||||
@@ -107,7 +94,7 @@ ShipStats calculateShipStats(const GameConfig& config,
|
|||||||
|
|
||||||
for (const PlacedModule& pm : modules)
|
for (const PlacedModule& pm : modules)
|
||||||
{
|
{
|
||||||
const ModuleDef* def = findModuleDef(pm.moduleId);
|
const ModuleDef* def = config.modules.findModuleDef(pm.moduleId);
|
||||||
if (!def) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
if (!def) { throw std::runtime_error("unknown module id '" + pm.moduleId + "'"); }
|
||||||
|
|
||||||
for (const ModuleStatModifier& sm : def->statModifiers)
|
for (const ModuleStatModifier& sm : def->statModifiers)
|
||||||
|
|||||||
@@ -335,15 +335,7 @@ double calculateShipThreatCost(const ThreatCostTable& table,
|
|||||||
const std::string& shipId,
|
const std::string& shipId,
|
||||||
const std::vector<PlacedModule>& modules)
|
const std::vector<PlacedModule>& modules)
|
||||||
{
|
{
|
||||||
const ShipDef* shipDef = nullptr;
|
const ShipDef* shipDef = config.ships.findShipDef(shipId);
|
||||||
for (const ShipDef& d : config.ships.ships)
|
|
||||||
{
|
|
||||||
if (d.id == shipId)
|
|
||||||
{
|
|
||||||
shipDef = &d;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shipDef == nullptr)
|
if (shipDef == nullptr)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
@@ -357,15 +349,7 @@ double calculateShipThreatCost(const ThreatCostTable& table,
|
|||||||
// Add module production times and material threats.
|
// Add module production times and material threats.
|
||||||
for (const PlacedModule& pm : modules)
|
for (const PlacedModule& pm : modules)
|
||||||
{
|
{
|
||||||
const ModuleDef* moduleDef = nullptr;
|
const ModuleDef* moduleDef = config.modules.findModuleDef(pm.moduleId);
|
||||||
for (const ModuleDef& d : config.modules.modules)
|
|
||||||
{
|
|
||||||
if (d.id == pm.moduleId)
|
|
||||||
{
|
|
||||||
moduleDef = &d;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (moduleDef == nullptr)
|
if (moduleDef == nullptr)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -12,15 +12,6 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
const RecipeDef* findRecipe(const RecipesConfig& recipes, const std::string& id)
|
|
||||||
{
|
|
||||||
for (const RecipeDef& recipe : recipes.recipes)
|
|
||||||
{
|
|
||||||
if (recipe.id == id) { return &recipe; }
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString grantKindLabel(SchematicType type)
|
QString grantKindLabel(SchematicType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
@@ -120,7 +111,7 @@ SchematicChoiceDialog::SchematicChoiceDialog(
|
|||||||
QLabel* recipeLabel = new QLabel(
|
QLabel* recipeLabel = new QLabel(
|
||||||
QString::fromStdString(toDisplayName(recipeId)), card);
|
QString::fromStdString(toDisplayName(recipeId)), card);
|
||||||
recipeLabel->setAlignment(Qt::AlignCenter);
|
recipeLabel->setAlignment(Qt::AlignCenter);
|
||||||
if (const RecipeDef* def = findRecipe(recipes, recipeId))
|
if (const RecipeDef* def = recipes.findRecipeDef(recipeId))
|
||||||
{
|
{
|
||||||
recipeLabel->setToolTip(buildRecipeTooltip(*def));
|
recipeLabel->setToolTip(buildRecipeTooltip(*def));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,14 +430,7 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
|||||||
// the cycle time and progress can be shown (REQ-UI-PRODUCTION-PROGRESS).
|
// the cycle time and progress can be shown (REQ-UI-PRODUCTION-PROGRESS).
|
||||||
if (!recipe && isAutoRecipeBuilding(b->type) && b->production.has_value())
|
if (!recipe && isAutoRecipeBuilding(b->type) && b->production.has_value())
|
||||||
{
|
{
|
||||||
for (const RecipeDef& r : m_config->recipes.recipes)
|
recipe = m_config->recipes.findRecipeDef(b->production->recipeId, b->type);
|
||||||
{
|
|
||||||
if (r.id == b->production->recipeId && r.building == b->type)
|
|
||||||
{
|
|
||||||
recipe = &r;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString bufText;
|
QString bufText;
|
||||||
@@ -465,18 +458,14 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
|||||||
{
|
{
|
||||||
for (const PlacedModule& pm : b->shipLayout->placedModules)
|
for (const PlacedModule& pm : b->shipLayout->placedModules)
|
||||||
{
|
{
|
||||||
for (const ModuleDef& modDef : m_config->modules.modules)
|
const ModuleDef* modDef =
|
||||||
|
m_config->modules.findModuleDef(pm.moduleId);
|
||||||
|
if (!modDef) { continue; }
|
||||||
|
for (const RecipeIngredient& ing : modDef->materials)
|
||||||
{
|
{
|
||||||
if (modDef.id == pm.moduleId)
|
if (ing.item == entry.first.id)
|
||||||
{
|
{
|
||||||
for (const RecipeIngredient& ing : modDef.materials)
|
perCycle += ing.amount;
|
||||||
{
|
|
||||||
if (ing.item == entry.first.id)
|
|
||||||
{
|
|
||||||
perCycle += ing.amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -545,13 +534,11 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b)
|
|||||||
{
|
{
|
||||||
for (const PlacedModule& pm : b->shipLayout->placedModules)
|
for (const PlacedModule& pm : b->shipLayout->placedModules)
|
||||||
{
|
{
|
||||||
for (const ModuleDef& modDef : m_config->modules.modules)
|
const ModuleDef* modDef =
|
||||||
|
m_config->modules.findModuleDef(pm.moduleId);
|
||||||
|
if (modDef)
|
||||||
{
|
{
|
||||||
if (modDef.id == pm.moduleId)
|
durationSeconds += modDef->productionTimeSeconds;
|
||||||
{
|
|
||||||
durationSeconds += modDef.productionTimeSeconds;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -633,21 +620,13 @@ void SelectedBuildingPanel::updateShipyardLayoutWidgets(
|
|||||||
const RecipeDef* SelectedBuildingPanel::findRecipe(const Building* b) const
|
const RecipeDef* SelectedBuildingPanel::findRecipe(const Building* b) const
|
||||||
{
|
{
|
||||||
if (b->recipeId.empty()) { return nullptr; }
|
if (b->recipeId.empty()) { return nullptr; }
|
||||||
for (const RecipeDef& r : m_config->recipes.recipes)
|
return m_config->recipes.findRecipeDef(b->recipeId, b->type);
|
||||||
{
|
|
||||||
if (r.id == b->recipeId && r.building == b->type) { return &r; }
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShipDef* SelectedBuildingPanel::findShipDef(const std::string& id) const
|
const ShipDef* SelectedBuildingPanel::findShipDef(const std::string& id) const
|
||||||
{
|
{
|
||||||
if (id.empty()) { return nullptr; }
|
if (id.empty()) { return nullptr; }
|
||||||
for (const ShipDef& s : m_config->ships.ships)
|
return m_config->ships.findShipDef(id);
|
||||||
{
|
|
||||||
if (s.id == id) { return &s; }
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectedBuildingPanel::handleEvent(std::shared_ptr<const TickAdvancedEvent> /*event*/)
|
void SelectedBuildingPanel::handleEvent(std::shared_ptr<const TickAdvancedEvent> /*event*/)
|
||||||
@@ -1088,15 +1067,14 @@ void SelectedBuildingPanel::buildEntityShip(entt::entity entity)
|
|||||||
admin.get<SelectedBehaviorComponent>(entity).winner);
|
admin.get<SelectedBehaviorComponent>(entity).winner);
|
||||||
m_entityStatsPanel->setDebugDrawEnabled(m_debugDraw);
|
m_entityStatsPanel->setDebugDrawEnabled(m_debugDraw);
|
||||||
|
|
||||||
for (const ShipDef& def : m_config->ships.ships)
|
const ShipDef* schematicDef =
|
||||||
|
m_config->ships.findShipDef(identity.schematicId);
|
||||||
|
if (schematicDef)
|
||||||
{
|
{
|
||||||
if (def.id == identity.schematicId)
|
const double threat = calculateShipThreatCost(
|
||||||
{
|
m_config->threatCosts, *m_config, schematicDef->id,
|
||||||
double threat = calculateShipThreatCost(
|
schematicDef->defaultModules);
|
||||||
m_config->threatCosts, *m_config, def.id, def.defaultModules);
|
m_entityStatsPanel->setThreatCost(threat);
|
||||||
m_entityStatsPanel->setThreatCost(threat);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_entityStatsPanel->show();
|
m_entityStatsPanel->show();
|
||||||
|
|||||||
@@ -243,14 +243,7 @@ private:
|
|||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
for (const ModuleDef& def : m_config->modules.modules)
|
return m_config->modules.findModuleDef(id);
|
||||||
{
|
|
||||||
if (def.id == id)
|
|
||||||
{
|
|
||||||
return &def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> rotateMask(const std::vector<std::string>& mask,
|
std::vector<std::string> rotateMask(const std::vector<std::string>& mask,
|
||||||
@@ -426,13 +419,10 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
|||||||
setModal(true);
|
setModal(true);
|
||||||
|
|
||||||
// Find the ship's layout grid.
|
// Find the ship's layout grid.
|
||||||
for (const ShipDef& def : config->ships.ships)
|
const ShipDef* shipDef = config->ships.findShipDef(shipId);
|
||||||
|
if (shipDef)
|
||||||
{
|
{
|
||||||
if (def.id == shipId)
|
m_shipLayout = shipDef->layout;
|
||||||
{
|
|
||||||
m_shipLayout = def.layout;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_rows = static_cast<int>(m_shipLayout.size());
|
m_rows = static_cast<int>(m_shipLayout.size());
|
||||||
@@ -706,11 +696,7 @@ void ShipLayoutDialog::rebuildOccupancy()
|
|||||||
for (int i = 0; i < static_cast<int>(m_placedModules.size()); ++i)
|
for (int i = 0; i < static_cast<int>(m_placedModules.size()); ++i)
|
||||||
{
|
{
|
||||||
const PlacedModule& pm = m_placedModules[i];
|
const PlacedModule& pm = m_placedModules[i];
|
||||||
const ModuleDef* def = nullptr;
|
const ModuleDef* def = m_config->modules.findModuleDef(pm.moduleId);
|
||||||
for (const ModuleDef& d : m_config->modules.modules)
|
|
||||||
{
|
|
||||||
if (d.id == pm.moduleId) { def = &d; break; }
|
|
||||||
}
|
|
||||||
if (!def)
|
if (!def)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -807,11 +793,7 @@ void ShipLayoutDialog::loadLayoutBlueprint(const std::vector<PlacedModule>& modu
|
|||||||
for (const PlacedModule& pm : modules)
|
for (const PlacedModule& pm : modules)
|
||||||
{
|
{
|
||||||
// Validate module type exists and is unlocked.
|
// Validate module type exists and is unlocked.
|
||||||
const ModuleDef* def = nullptr;
|
const ModuleDef* def = m_config->modules.findModuleDef(pm.moduleId);
|
||||||
for (const ModuleDef& d : m_config->modules.modules)
|
|
||||||
{
|
|
||||||
if (d.id == pm.moduleId) { def = &d; break; }
|
|
||||||
}
|
|
||||||
if (!def || m_unlockedModuleIds.count(def->id) == 0) { continue; }
|
if (!def || m_unlockedModuleIds.count(def->id) == 0) { continue; }
|
||||||
|
|
||||||
const std::vector<std::string> mask = rotatedMask(*def, pm.rotation);
|
const std::vector<std::string> mask = rotatedMask(*def, pm.rotation);
|
||||||
|
|||||||
Reference in New Issue
Block a user