Prechádzať zdrojové kódy

plan: estimate STL travel time

raylu 2 týždňov pred
rodič
commit
6cc8f0d4f1
1 zmenil súbory, kde vykonal 17 pridanie a 9 odobranie
  1. 17 9
      ts/plan.ts

+ 17 - 9
ts/plan.ts

@@ -62,7 +62,7 @@ async function _render(shareUUID: string, cx: string) {
 		cachedFetchJSON('https://api.prunplanner.org/data/materials/'),
 		cachedFetchJSON('/graph_data.json'),
 	]);
-	const planet: Planet = await cachedFetchJSON(`https://api.prunplanner.org/data/planet/${plan.plan_details.planet_natural_id}/`);
+	const planet: PPPlanet = await cachedFetchJSON(`https://api.prunplanner.org/data/planet/${plan.plan_details.planet_natural_id}/`);
 	const planExperts = new Map<Expertise, number>(plan.plan_details.plan_data.experts.map(
 			e => [e.type.toUpperCase() as Expertise, e.amount]));
 	const buildingExpertise = new Map<string, Expertise>(buildings.map(b => [b.building_ticker, b.expertise]));
@@ -71,7 +71,7 @@ async function _render(shareUUID: string, cx: string) {
 			.map((ex) => [ex.ticker, ex.sum_traded_7d / 7]));
 	const materials = new Map<string, Material>(materialList.map(m => [m.ticker, m]));
 
-	const oneWayHours = travel(graph.edges, planet.system_id, cx);
+	const oneWayHours = await travel(graph.edges, planet.system_id, planet.planet_natural_id, cx);
 
 	const planInput = new Counter();
 	const planOutput = new Counter();
@@ -132,12 +132,16 @@ async function _render(shareUUID: string, cx: string) {
 	}
 }
 
-function travel(edges: Edge[], system: string, cx: string): number | null {
+async function travel(edges: Edge[], system: string, planet_name: string, cx: string): Promise<number> {
 	const {parsecs, jumps} = ftlDistance(edges, system, cx);
-	if (jumps === 0)
-		return null;
-	// SCB JMPs at 4pc/hr. RCT CHRGs in 7m30s. 30m DEP, 1.5hr APP+(TO/LAND)
-	return Math.round(parsecs / 4 + (jumps - 1) * 0.125 + 2);
+	if (jumps === 0) { // STL
+		const planet: FIOPlanet = await cachedFetchJSON('https://api.fnar.net/planet/' + planet_name);
+		const km = planet.SemiMajorAxis / 1000;
+		// ENG at 750 SF usage (50% of an SSL) TRAs at ~300,000,000 km/h
+		return Math.ceil(km / 300_000_000);
+	} else // FTL
+		// SCB JMPs at 4pc/hr. RCT CHRGs in 7m30s. 30m DEP, 1.5hr APP+(TO/LAND)
+		return Math.ceil(parsecs / 4 + (jumps - 1) * 0.125 + 2);
 }
 
 /** dijkstra to find the shortest FTL route from system to CX */
@@ -188,7 +192,7 @@ function ftlDistance(edges: Edge[], system: string, cx: string): {parsecs: numbe
 }
 
 function calcBuilding(recipes: Map<string, Recipe>, building: PlanBuilding, cogc: boolean, experts: number,
-		planet: Planet): {input: Counter, output: Counter} {
+		planet: PPPlanet): {input: Counter, output: Counter} {
 	let efficiency = expertBonus[experts];
 	if (cogc)
 		efficiency *= 1.25;
@@ -321,7 +325,7 @@ interface Edge {
 	distance: number
 }
 
-interface Planet {
+interface PPPlanet {
 	planet_natural_id: string
 	system_id: string
 	fertility: number
@@ -330,3 +334,7 @@ interface Planet {
 		daily_extraction: number
 	}>
 }
+
+interface FIOPlanet {
+	SemiMajorAxis: number
+}