Browse Source

shipbuilding: show mats to extract

raylu 5 months ago
parent
commit
68668b5582
1 changed files with 17 additions and 11 deletions
  1. 17 11
      ts/shipbuilding.ts

+ 17 - 11
ts/shipbuilding.ts

@@ -4,7 +4,8 @@ const BUY = new Set([
 	// definitely buy
 	// definitely buy
 	'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
 	'C', 'FLX', 'H', 'H2O', 'HAL', 'HCP', 'HE', 'LST', 'MG', 'N', 'NA', 'NCS', 'NS', 'O', 'PE', 'PG', 'S', 'TCL', 'THF',
 	// maybe buy
 	// 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
 	// import
 	'AAR', 'AWF', 'CAP', 'CF',
 	'AAR', 'AWF', 'CAP', 'CF',
 	// skip
 	// skip
@@ -30,6 +31,7 @@ const blueprint = {
 const shipbuilders = [
 const shipbuilders = [
 	'CraftsmanThirteen',
 	'CraftsmanThirteen',
 	'EvoV',
 	'EvoV',
+	'MapReduce',
 	'SurvivorBob',
 	'SurvivorBob',
 	'TRUEnterprises',
 	'TRUEnterprises',
 ];
 ];
@@ -53,11 +55,12 @@ async function render() {
 			.map((price) => [price.MaterialTicker, price]));
 			.map((price) => [price.MaterialTicker, price]));
 
 
 	const production: Production = {};
 	const production: Production = {};
+	const extract: Record<string, number> = {};
 	const buy: Record<string, number> = {};
 	const buy: Record<string, number> = {};
 	const analysisNodes: AnalysisNode[] = [];
 	const analysisNodes: AnalysisNode[] = [];
 	let cost = 0;
 	let cost = 0;
 	for (const [mat, amount] of Object.entries(blueprint)) {
 	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;
 		cost += matCost;
 		analysisNodes.push(node);
 		analysisNodes.push(node);
 	}
 	}
@@ -82,17 +85,18 @@ async function render() {
 		renderAnalysis(analysisNodes),
 		renderAnalysis(analysisNodes),
 		element('p', {textContent: `total cost: ${formatWhole(cost)}`}),
 		element('p', {textContent: `total cost: ${formatWhole(cost)}`}),
 		renderProduction(expertiseGroups, production, prices, recipes),
 		renderProduction(expertiseGroups, production, prices, recipes),
-		renderBuyMaterials(buy),
+		renderMatList('extract', extract),
+		renderMatList('buy', buy),
 		renderShipbuilders(requiredMats, knownCompanies, companyProductionById),
 		renderShipbuilders(requiredMats, knownCompanies, companyProductionById),
 	);
 	);
 }
 }
 
 
-function renderBuyMaterials(buy: Record<string, number>): HTMLElement {
+function renderMatList(header: string, mats: Record<string, number>): HTMLElement {
 	const section = element('section');
 	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', {
 	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;
 	return section;
 }
 }
@@ -169,7 +173,7 @@ async function recipeForMats(): Promise<Record<string, Recipe>> {
 	return matRecipe;
 	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 } {
 		prices: Record<string, RawPrice>, recipes: Record<string, Recipe>): { cost: number, node: AnalysisNode } {
 	const price = prices[mat];
 	const price = prices[mat];
 	if (!price)
 	if (!price)
@@ -186,8 +190,10 @@ function analyzeMat(mat: string, amount: number, production: Production, buy: Re
 	}
 	}
 
 
 	const recipe = recipes[mat];
 	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;
 	const building = recipe.building_ticker;
 	if (!production[building])
 	if (!production[building])
@@ -200,7 +206,7 @@ function analyzeMat(mat: string, amount: number, production: Production, buy: Re
 	const children: AnalysisNode[] = [];
 	const children: AnalysisNode[] = [];
 	for (const inputMat of recipe.inputs) {
 	for (const inputMat of recipe.inputs) {
 		const inputAmount = inputMat.material_amount * amount / recipe.outputs[0].material_amount;
 		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;
 		totalCost += cost;
 		children.push(node);
 		children.push(node);
 	}
 	}