allow the probabilistic recipe output of the reprocessing plant to yield more than 1 item of a type per cycle
This commit is contained in:
@@ -2,12 +2,48 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
|
||||
#include "BuildingType.h"
|
||||
#include "ItemType.h"
|
||||
#include "ModulesConfig.h"
|
||||
#include "ShipsConfig.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Folds the output capacities one recipe implies into `caps`: twice each produced
|
||||
// item's per-cycle amount (REQ-MAT-OUTPUT-BUFFER). A Reprocessing Plant rolls exactly
|
||||
// one of its outputs per cycle (REQ-BLD-REPROCESSING), so its per-cycle amount for an
|
||||
// item is that one outcome's amount rather than a sum over the entries.
|
||||
//
|
||||
// Where a cap is already present the larger wins, which is how an auto-recipe building
|
||||
// unions the recipes of its type -- the same rule its input caps follow.
|
||||
void addOutputCaps(std::map<ItemType, int>& caps, BuildingType type,
|
||||
const RecipeDef& recipe)
|
||||
{
|
||||
std::map<ItemType, int> perCycle;
|
||||
for (const RecipeOutput& out : recipe.outputs)
|
||||
{
|
||||
const ItemType item{out.item};
|
||||
if (type == BuildingType::ReprocessingPlant)
|
||||
{
|
||||
perCycle[item] = std::max(perCycle[item], out.amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
perCycle[item] += out.amount;
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::pair<const ItemType, int>& entry : perCycle)
|
||||
{
|
||||
caps[entry.first] = std::max(caps[entry.first], 2 * entry.second);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void initBuffers(Building& b, const RecipeDef& recipe)
|
||||
{
|
||||
b.inputBuffer.counts.clear();
|
||||
@@ -20,29 +56,8 @@ void initBuffers(Building& b, const RecipeDef& recipe)
|
||||
}
|
||||
|
||||
b.outputBuffer.items.clear();
|
||||
if (b.type == BuildingType::ReprocessingPlant)
|
||||
{
|
||||
// 1× max-per-roll (REQ-MAT-OUTPUT-BUFFER-REPROCESSING).
|
||||
int maxAmount = 0;
|
||||
for (const RecipeOutput& out : recipe.outputs)
|
||||
{
|
||||
if (out.amount > maxAmount)
|
||||
{
|
||||
maxAmount = out.amount;
|
||||
}
|
||||
}
|
||||
b.outputBuffer.capacity = maxAmount;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2× per-cycle output.
|
||||
int totalAmount = 0;
|
||||
for (const RecipeOutput& out : recipe.outputs)
|
||||
{
|
||||
totalAmount += out.amount;
|
||||
}
|
||||
b.outputBuffer.capacity = 2 * totalAmount;
|
||||
}
|
||||
b.outputBuffer.caps.clear();
|
||||
addOutputCaps(b.outputBuffer.caps, b.type, recipe);
|
||||
}
|
||||
|
||||
void initAutoBuffers(const GameConfig& config, Building& b)
|
||||
@@ -50,12 +65,12 @@ void initAutoBuffers(const GameConfig& config, Building& b)
|
||||
b.inputBuffer.counts.clear();
|
||||
b.inputBuffer.caps.clear();
|
||||
|
||||
// Union the inputs of every recipe of this building type; the cap for each
|
||||
// item is twice the largest per-cycle requirement across those recipes.
|
||||
// Output capacity follows the same rules as initBuffers: the Reprocessing
|
||||
// Plant holds one cycle's max output (REQ-MAT-OUTPUT-BUFFER-REPROCESSING),
|
||||
// other auto buildings hold twice the largest per-cycle output.
|
||||
int outputCapacity = 0;
|
||||
b.outputBuffer.items.clear();
|
||||
b.outputBuffer.caps.clear();
|
||||
|
||||
// Union both sides over every recipe of this building type: the cap for each item is
|
||||
// twice the largest per-cycle amount across those recipes, on the input side as on
|
||||
// the output side (REQ-MAT-INPUT-BUFFER, REQ-MAT-OUTPUT-BUFFER).
|
||||
for (const RecipeDef& recipe : config.recipes.recipes)
|
||||
{
|
||||
if (recipe.building != b.type)
|
||||
@@ -71,36 +86,18 @@ void initAutoBuffers(const GameConfig& config, Building& b)
|
||||
std::max(b.inputBuffer.caps[type], 2 * ing.amount);
|
||||
}
|
||||
|
||||
if (b.type == BuildingType::ReprocessingPlant)
|
||||
{
|
||||
int maxAmount = 0;
|
||||
for (const RecipeOutput& out : recipe.outputs)
|
||||
{
|
||||
maxAmount = std::max(maxAmount, out.amount);
|
||||
}
|
||||
outputCapacity = std::max(outputCapacity, maxAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
int totalAmount = 0;
|
||||
for (const RecipeOutput& out : recipe.outputs)
|
||||
{
|
||||
totalAmount += out.amount;
|
||||
}
|
||||
outputCapacity = std::max(outputCapacity, 2 * totalAmount);
|
||||
}
|
||||
addOutputCaps(b.outputBuffer.caps, b.type, recipe);
|
||||
}
|
||||
|
||||
b.outputBuffer.items.clear();
|
||||
b.outputBuffer.capacity = outputCapacity;
|
||||
}
|
||||
|
||||
void initShipyardBuffers(const GameConfig& config, Building& b)
|
||||
{
|
||||
b.inputBuffer.counts.clear();
|
||||
b.inputBuffer.caps.clear();
|
||||
// A shipyard spawns a ship rather than producing items, so it holds no output
|
||||
// buffer at all (REQ-MAT-OUTPUT-BUFFER, REQ-BLD-SHIPYARD).
|
||||
b.outputBuffer.items.clear();
|
||||
b.outputBuffer.capacity = 0;
|
||||
b.outputBuffer.caps.clear();
|
||||
const ShipDef* def = config.ships.findShipDef(b.recipeId);
|
||||
if (!def)
|
||||
{
|
||||
@@ -133,11 +130,13 @@ void initShipyardBuffers(const GameConfig& config, Building& b)
|
||||
|
||||
void initSalvageBayBuffer(const GameConfig& config, Building& b)
|
||||
{
|
||||
// Salvage Bay has no recipe-driven buffer; its output-buffer holding size for
|
||||
// ship drop-off is config-defined (REQ-BLD-SALVAGE-BAY).
|
||||
// Salvage Bay has no recipe-driven buffer; scrap is the only thing it ever holds,
|
||||
// and that single buffer's holding size for ship drop-off is config-defined
|
||||
// (REQ-BLD-SALVAGE-BAY).
|
||||
b.outputBuffer.items.clear();
|
||||
b.outputBuffer.caps.clear();
|
||||
const BuildingDef* def = config.buildings.findBuildingDef(BuildingType::SalvageBay);
|
||||
b.outputBuffer.capacity =
|
||||
b.outputBuffer.caps[ItemType{"scrap"}] =
|
||||
(def && def->outputBufferCapacity) ? *def->outputBufferCapacity : 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user