add findShipDef/findModuleDef/findRecipeDef to config structs and re-use them in the rest of the code base
This commit is contained in:
@@ -107,43 +107,6 @@ const BuildingDef* BuildingSystem::findBuildingDef(BuildingType type) const
|
||||
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
|
||||
{
|
||||
b.inputBuffer.counts.clear();
|
||||
@@ -237,7 +200,7 @@ void BuildingSystem::initShipyardBuffers(Building& b) const
|
||||
b.inputBuffer.caps.clear();
|
||||
b.outputBuffer.items.clear();
|
||||
b.outputBuffer.capacity = 0;
|
||||
const ShipDef* def = findShipDef(b.recipeId);
|
||||
const ShipDef* def = m_config.ships.findShipDef(b.recipeId);
|
||||
if (!def)
|
||||
{
|
||||
return;
|
||||
@@ -252,7 +215,7 @@ void BuildingSystem::initShipyardBuffers(Building& b) const
|
||||
{
|
||||
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
||||
{
|
||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
||||
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||
if (!modDef)
|
||||
{
|
||||
continue;
|
||||
@@ -646,7 +609,7 @@ void BuildingSystem::setRecipe(BuildingId id, const std::string& recipeId)
|
||||
}
|
||||
else
|
||||
{
|
||||
const RecipeDef* recipe = findRecipe(recipeId, building.type);
|
||||
const RecipeDef* recipe = m_config.recipes.findRecipeDef(recipeId, building.type);
|
||||
if (recipe)
|
||||
{
|
||||
initBuffers(building, *recipe);
|
||||
@@ -809,7 +772,7 @@ void BuildingSystem::tickConstruction(Tick currentTick)
|
||||
}
|
||||
else
|
||||
{
|
||||
const RecipeDef* recipe = findRecipe(building.recipeId, building.type);
|
||||
const RecipeDef* recipe = m_config.recipes.findRecipeDef(building.recipeId, building.type);
|
||||
if (recipe)
|
||||
{
|
||||
initBuffers(building, *recipe);
|
||||
@@ -1187,7 +1150,7 @@ void BuildingSystem::tickShipyardProduction(Tick currentTick)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const ShipDef* shipDef = findShipDef(building.recipeId);
|
||||
const ShipDef* shipDef = m_config.ships.findShipDef(building.recipeId);
|
||||
if (!shipDef)
|
||||
{
|
||||
continue;
|
||||
@@ -1252,7 +1215,7 @@ void BuildingSystem::tickShipyardProduction(Tick currentTick)
|
||||
{
|
||||
for (const PlacedModule& pm : building.shipLayout->placedModules)
|
||||
{
|
||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
||||
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||
if (modDef)
|
||||
{
|
||||
totalTime += modDef->productionTimeSeconds;
|
||||
@@ -1466,7 +1429,7 @@ BuildingSystem::gatherCandidateRecipes(const Building& b) const
|
||||
}
|
||||
else
|
||||
{
|
||||
const RecipeDef* recipe = findRecipe(b.recipeId, b.type);
|
||||
const RecipeDef* recipe = m_config.recipes.findRecipeDef(b.recipeId, b.type);
|
||||
if (recipe)
|
||||
{
|
||||
candidates.push_back(recipe);
|
||||
@@ -1495,7 +1458,7 @@ std::map<std::string, int>
|
||||
BuildingSystem::computeShipyardRequiredMaterials(const Building& b) const
|
||||
{
|
||||
std::map<std::string, int> requiredMaterials;
|
||||
const ShipDef* shipDef = findShipDef(b.recipeId);
|
||||
const ShipDef* shipDef = m_config.ships.findShipDef(b.recipeId);
|
||||
if (!shipDef)
|
||||
{
|
||||
return requiredMaterials;
|
||||
@@ -1508,7 +1471,7 @@ BuildingSystem::computeShipyardRequiredMaterials(const Building& b) const
|
||||
{
|
||||
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
||||
{
|
||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
||||
const ModuleDef* modDef = m_config.modules.findModuleDef(pm.moduleId);
|
||||
if (!modDef)
|
||||
{
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user