Переглянути джерело

shipbuilding: calculate number of buildings needed

raylu 1 тиждень тому
батько
коміт
5d3779c7eb
1 змінених файлів з 9 додано та 3 видалено
  1. 9 3
      ts/shipbuilding.ts

+ 9 - 3
ts/shipbuilding.ts

@@ -81,7 +81,7 @@ async function render() {
 	main.append(
 		renderAnalysis(analysisNodes),
 		element('p', {textContent: `total cost: ${formatWhole(cost)}`}),
-		renderProduction(expertiseGroups, production, prices),
+		renderProduction(expertiseGroups, production, prices, recipes),
 		renderBuyMaterials(buy),
 		renderShipbuilders(requiredMats, knownCompanies, companyProductionById),
 	);
@@ -234,16 +234,16 @@ function renderAnalysisNode(node: AnalysisNode, level = 0): HTMLElement {
 }
 
 function renderProduction(expertiseGroups: Record<string, string[]>, production: Production,
-		prices: Record<string, RawPrice>): HTMLElement {
+		prices: Record<string, RawPrice>, recipes: Record<string, Recipe>): HTMLElement {
 	const section = element('section');
 	section.append(element('h2', {textContent: 'production'}));
 
 	for (const [expertise, buildings] of Object.entries(expertiseGroups)) {
 		section.append(element('h3', {textContent: expertise}));
 		for (const building of buildings) {
-			const buildingRow = element('div', {className: 'building-row', textContent: building});
 			const buildingMats = element('div');
 			const mats = Object.entries(production[building]);
+			let buildingMins = 0;
 			for (const [index, [mat, amount]] of mats.entries()) {
 				const traded = prices[mat]?.AverageTraded30D ?? 0;
 				const span = element('span', {
@@ -253,7 +253,13 @@ function renderProduction(expertiseGroups: Record<string, string[]>, production:
 				buildingMats.append(span);
 				if (index < mats.length - 1)
 					buildingMats.append(document.createTextNode(' '));
+
+				const recipe = recipes[mat];
+				const outputPerRun = recipe.outputs.find((o) => o.material_ticker === mat)!.material_amount;
+				buildingMins += amount / outputPerRun * (recipe.time_ms / 1000 / 60);
 			}
+			const numBuildings = buildingMins / (24*60) / 5 / 1.605; // one ship every 5 days, 160.5% efficiency
+			const buildingRow = element('div', {className: 'building-row', textContent: `${formatFixed(numBuildings, 1)}x${building}`});
 			buildingRow.append(buildingMats);
 			section.append(buildingRow);
 		}