Mechanical press !

This commit is contained in:
2026-10-15 13:07:09 -03:00
parent b43e8fe8b8
commit c7a2392591
15 changed files with 403 additions and 86 deletions
+14
View File
@@ -92,3 +92,17 @@ export function parse_processing(
if (json?.heat_requirement !== undefined) problems.push(`${type.id} can't have a heat_requirement`);
return problems.length > 0 ? { problems } : { ingredients, results };
}
// the first recipe that takes the item, like a machine's getRecipe
export function processing_for(recipes: ProcessingRecipe[], item: Id): ProcessingRecipe | undefined {
return recipes.find((recipe) => recipe.ingredients[0]?.includes(item));
}
// what one go of a recipe makes: each result, with each of its count kept by its chance, like rollResults
export function roll_results(recipe: ProcessingRecipe, random = Math.random): { id: Id; count: number }[] {
return recipe.results.flatMap(({ id, count, chance }) => {
let kept = count;
if (chance < 1) { for (let i = 0; i < count; i++) if (random() > chance) kept--; }
return kept > 0 ? [{ id, count: kept }] : [];
});
}