Răsfoiți Sursa

shipbuilding: show mats to extract

raylu 1 săptămână în urmă
părinte
comite
68668b5582
1 a modificat fișierele cu 17 adăugiri și 11 ștergeri
  1. 17 11
      ts/shipbuilding.ts

+ 17 - 11
ts/shipbuilding.ts

@@ -4,7 +4,8 @@ const BUY = new Set([
 	// definitely buy
 	'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
 	// maybe buy
-	'AIR', 'AU', 'BE', 'BRM', 'CU', 'FAN', 'FC', 'FE', 'HCC', 'HD', 'LDI', 'LI', 'MFK', 'MWF', 'REA', 'RG', 'RGO', 'ROM', 'SFK', 'SI', 'STL', 'TI', 'TPU',
+	'AIR', 'AU', 'BE', 'BRM', 'BOR', 'BTS', 'CU', 'FAN', 'FC', 'FE', 'HCC', 'HD', 'LDI', 'LI', 'MFK', 'MWF',
+	'REA', 'RG', 'RGO', 'ROM', 'SFK', 'SI', 'STL', 'TCO', 'TPU',
 	// import
 	'AAR', 'AWF', 'CAP', 'CF',
 	// skip
@@ -30,6 +31,7 @@ const blueprint = {
 const shipbuilders = [
 	'CraftsmanThirteen',
 	'EvoV',
+	'MapReduce',
 	'SurvivorBob',
 	'TRUEnterprises',
 ];
@@ -53,11 +55,12 @@ async function render() {
 			.map((price) => [price.MaterialTicker, price]));
 
 	const production: Production = {};
+	const extract: Record<string, number> = {};
 	const buy: Record<string, number> = {};
 	const analysisNodes: AnalysisNode[] = [];
 	let cost = 0;
 	for (const [mat, amount] of Object.entries(blueprint)) {
-		const { cost: matCost, node } = analyzeMat(mat, amount, production, buy, prices, recipes);
+		const { cost: matCost, node } = analyzeMat(mat, amount, production, extract, buy, prices, recipes);
 		cost += matCost;
 		analysisNodes.push(node);
 	}
@@ -82,17 +85,18 @@ async function render() {
 		renderAnalysis(analysisNodes),
 		element('p', {textContent: `total cost: ${formatWhole(cost)}`}),
 		renderProduction(expertiseGroups, production, prices, recipes),
-		renderBuyMaterials(buy),
+		renderMatList('extract', extract),
+		renderMatList('buy', buy),
 		renderShipbuilders(requiredMats, knownCompanies, companyProductionById),
 	);
 }
 
-function renderBuyMaterials(buy: Record<string, number>): HTMLElement {
+function renderMatList(header: string, mats: Record<string, number>): HTMLElement {
 	const section = element('section');
-	section.append(element('h2', {textContent: 'buy'}));
-	const mats = Object.entries(buy).sort(([a], [b]) => a.localeCompare(b));
+	section.append(element('h2', {textContent: header}));
+	const matsSorted = Object.entries(mats).sort(([a], [b]) => a.localeCompare(b));
 	section.append(element('p', {
-		textContent: mats.map(([mat, amount]) => `${formatAmount(amount)}x${mat}`).join(', '),
+		textContent: matsSorted.map(([mat, amount]) => `${formatAmount(amount)}x${mat}`).join(', '),
 	}));
 	return section;
 }
@@ -169,7 +173,7 @@ async function recipeForMats(): Promise<Record<string, Recipe>> {
 	return matRecipe;
 }
 
-function analyzeMat(mat: string, amount: number, production: Production, buy: Record<string, number>,
+function analyzeMat(mat: string, amount: number, production: Production, extract: Record<string, number>, buy: Record<string, number>,
 		prices: Record<string, RawPrice>, recipes: Record<string, Recipe>): { cost: number, node: AnalysisNode } {
 	const price = prices[mat];
 	if (!price)
@@ -186,8 +190,10 @@ function analyzeMat(mat: string, amount: number, production: Production, buy: Re
 	}
 
 	const recipe = recipes[mat];
-	if (!recipe)
-		return { cost: 0, node: { text: `${formatAmount(amount)}x${mat} make (unknown recipe)`, children: [] } };
+	if (!recipe) {
+		extract[mat] = (extract[mat] ?? 0) + amount;
+		return { cost: 0, node: { text: `${formatAmount(amount)}x${mat} extract`, children: [] } };
+	}
 
 	const building = recipe.building_ticker;
 	if (!production[building])
@@ -200,7 +206,7 @@ function analyzeMat(mat: string, amount: number, production: Production, buy: Re
 	const children: AnalysisNode[] = [];
 	for (const inputMat of recipe.inputs) {
 		const inputAmount = inputMat.material_amount * amount / recipe.outputs[0].material_amount;
-		const {cost, node} = analyzeMat(inputMat.material_ticker, inputAmount, production, buy, prices, recipes);
+		const {cost, node} = analyzeMat(inputMat.material_ticker, inputAmount, production, extract, buy, prices, recipes);
 		totalCost += cost;
 		children.push(node);
 	}