gov.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. import {cachedFetchJSON} from './cache';
  2. const renderTarget = document.querySelector('#gov')!;
  3. const planetInput = document.querySelector('#planet') as HTMLInputElement;
  4. const popSelect = document.querySelector('#pop') as HTMLSelectElement;
  5. function serializeToHash(planet: string, pop: Pop): void {
  6. const params = new URLSearchParams({'planet': planet, 'pop': pop});
  7. document.location.hash = params.toString();
  8. }
  9. function deserializeFromHash(): {planet: string, pop: Pop} | null {
  10. const params = new URLSearchParams(document.location.hash.substring(1));
  11. const planet = params.get('planet');
  12. const pop = params.get('pop');
  13. if (planet && pop && ['pio', 'set', 'tec', 'eng', 'sci'].includes(pop)) {
  14. planetInput.value = planet;
  15. popSelect.value = pop;
  16. return {planet, pop: pop as Pop};
  17. } else
  18. return null;
  19. }
  20. document.querySelector('form')!.addEventListener('submit', async (event) => {
  21. event.preventDefault();
  22. const planet = planetInput.value;
  23. const pop = popSelect.value as Pop;
  24. if (planet && pop) {
  25. await render(planet, pop);
  26. serializeToHash(planet, pop);
  27. }
  28. });
  29. {
  30. const deserialized = deserializeFromHash();
  31. if (deserialized)
  32. void render(deserialized.planet, deserialized.pop);
  33. }
  34. async function render(planetName: string, pop: Pop) {
  35. const loader = document.querySelector('#loader') as HTMLElement;
  36. loader.style.display = 'block';
  37. renderTarget.innerHTML = '';
  38. try {
  39. await _render(planetName, pop);
  40. } catch (e) {
  41. console.error(e);
  42. renderTarget.textContent = (e as Error).message;
  43. }
  44. loader.style.display = 'none';
  45. }
  46. async function _render(planetName: string, pop: Pop) {
  47. const encodedPlanetName = encodeURIComponent(planetName);
  48. const [planet, siteCounts, infras, allPrices]: [Planet, SiteCount[], Infrastructure[], Price[]] = await Promise.all([
  49. cachedFetchJSON(`https://api.fnar.net/planet/${encodedPlanetName}?include_population_reports=true`),
  50. cachedFetchJSON(`https://api.fnar.net/planet/sitecount?planet=${encodedPlanetName}`),
  51. cachedFetchJSON(`https://api.fnar.net/infrastructure?infrastructure=${encodedPlanetName}&include_upkeeps=true`),
  52. cachedFetchJSON('https://api.prunplanner.org/data/exchanges'),
  53. ]);
  54. let lastPOPR = null;
  55. for (const report of planet.PopulationReports) {
  56. if (!lastPOPR || report.SimulationPeriod > lastPOPR.SimulationPeriod)
  57. lastPOPR = report;
  58. }
  59. if (lastPOPR === null) {
  60. renderTarget.textContent = `no POPR for ${planetName}`;
  61. return;
  62. }
  63. const lastPOPRts = Math.floor(new Date(lastPOPR.ReportTimestamp).getTime() / 1000);
  64. const nextPOPRts = lastPOPRts + 7 * 24 * 60 * 60;
  65. let currentPop = 0, lowerPop = 0;
  66. if (pop == 'pio')
  67. currentPop = lastPOPR.NextPopulationPioneer;
  68. else if (pop == 'set') {
  69. currentPop = lastPOPR.NextPopulationSettler;
  70. lowerPop = lastPOPR.NextPopulationPioneer;
  71. }
  72. else if (pop == 'tec') {
  73. currentPop = lastPOPR.NextPopulationTechnician;
  74. lowerPop = lastPOPR.NextPopulationSettler;
  75. }
  76. else if (pop == 'eng') {
  77. currentPop = lastPOPR.NextPopulationEngineer;
  78. lowerPop = lastPOPR.NextPopulationTechnician;
  79. }
  80. else if (pop == 'sci') {
  81. currentPop = lastPOPR.NextPopulationScientist;
  82. lowerPop = lastPOPR.NextPopulationEngineer;
  83. }
  84. const siteCount = siteCounts[0].Count;
  85. const totalNeeds: Record<Need, number> = {
  86. 'safety': calcTotalNeeds(lastPOPR, 'safety'),
  87. 'health': calcTotalNeeds(lastPOPR, 'health'),
  88. 'comfort': calcTotalNeeds(lastPOPR, 'comfort'),
  89. 'culture': calcTotalNeeds(lastPOPR, 'culture'),
  90. 'education': calcTotalNeeds(lastPOPR, 'education'),
  91. };
  92. const totalPop = lastPOPR.NextPopulationPioneer + lastPOPR.NextPopulationSettler +
  93. lastPOPR.NextPopulationTechnician + lastPOPR.NextPopulationEngineer + lastPOPR.NextPopulationScientist;
  94. const currentPOPIFilled: POPIFill = new Map();
  95. for (const infra of infras) {
  96. const filled = calcPOPIFilled(infra);
  97. if (filled !== null)
  98. currentPOPIFilled.set(infra.Type, {tier: infra.CurrentLevel, numMats: filled});
  99. }
  100. const prices: Map<string, number> = new Map();
  101. for (const price of allPrices)
  102. if (price.exchange_code === 'IC1')
  103. prices.set(price.ticker, price.vwap_30d || price.ask);
  104. else if (price.exchange_code === 'UNIVERSE' && prices.get(price.ticker) === 0) // UNIVERSE always comes after IC1
  105. prices.set(price.ticker, price.vwap_30d);
  106. renderTarget.innerHTML = `last POPR: ${lastPOPR.ReportTimestamp} (${lastPOPRts})
  107. <br>next POPR: ${new Date(nextPOPRts * 1000).toISOString()} (${nextPOPRts})
  108. <table>
  109. <tr>
  110. <th></th>
  111. <th>pio</th>
  112. <th>set</th>
  113. <th>tec</th>
  114. <th>eng</th>
  115. <th>sci</th>
  116. </tr>
  117. <tr>
  118. <th>population</th>
  119. <td>${lastPOPR.NextPopulationPioneer}<br>${formatDelta(lastPOPR.PopulationDifferencePioneer)}</td>
  120. <td>${lastPOPR.NextPopulationSettler}<br>${formatDelta(lastPOPR.PopulationDifferenceSettler)}</td>
  121. <td>${lastPOPR.NextPopulationTechnician}<br>${formatDelta(lastPOPR.PopulationDifferenceTechnician)}</td>
  122. <td>${lastPOPR.NextPopulationEngineer}<br>${formatDelta(lastPOPR.PopulationDifferenceEngineer)}</td>
  123. <td>${lastPOPR.NextPopulationScientist}<br>${formatDelta(lastPOPR.PopulationDifferenceScientist)}</td>
  124. </tr>
  125. <tr>
  126. <th>unemployed</th>
  127. <td>${unemployed(lastPOPR.NextPopulationPioneer, lastPOPR.PopulationDifferencePioneer, lastPOPR.OpenJobsPioneer, lastPOPR.UnemploymentRatePioneer)}</td>
  128. <td>${unemployed(lastPOPR.NextPopulationSettler, lastPOPR.PopulationDifferenceSettler, lastPOPR.OpenJobsSettler, lastPOPR.UnemploymentRateSettler)}</td>
  129. <td>${unemployed(lastPOPR.NextPopulationTechnician, lastPOPR.PopulationDifferenceTechnician, lastPOPR.OpenJobsTechnician, lastPOPR.UnemploymentRateTechnician)}</td>
  130. <td>${unemployed(lastPOPR.NextPopulationEngineer, lastPOPR.PopulationDifferenceEngineer, lastPOPR.OpenJobsEngineer, lastPOPR.UnemploymentRateEngineer)}</td>
  131. <td>${unemployed(lastPOPR.NextPopulationScientist, lastPOPR.PopulationDifferenceScientist, lastPOPR.OpenJobsScientist, lastPOPR.UnemploymentRateScientist)}</td>
  132. </tr>
  133. </table>
  134. <h2>needs</h2>
  135. ${siteCount} bases
  136. <table>
  137. <tr>
  138. <th></th>
  139. <th>safety</th>
  140. <th>health</th>
  141. <th>comfort</th>
  142. <th>culture</th>
  143. <th>education</th>
  144. </tr>
  145. <tr>
  146. <td>last POPR</td>
  147. <td>${formatPct(lastPOPR.NeedFulfillmentSafety)}</td>
  148. <td>${formatPct(lastPOPR.NeedFulfillmentHealth)}</td>
  149. <td>${formatPct(lastPOPR.NeedFulfillmentComfort)}</td>
  150. <td>${formatPct(lastPOPR.NeedFulfillmentCulture)}</td>
  151. <td>${formatPct(lastPOPR.NeedFulfillmentEducation)}</td>
  152. </tr>
  153. <tr>
  154. <td>total needed</td>
  155. <td>${formatNum(totalNeeds['safety'])}</td>
  156. <td>${formatNum(totalNeeds['health'])}</td>
  157. <td>${formatNum(totalNeeds['comfort'])}</td>
  158. <td>${formatNum(totalNeeds['culture'])}</td>
  159. <td>${formatNum(totalNeeds['education'])}</td>
  160. </tr>
  161. </table>
  162. <h2>current POPI</h2>
  163. <table>
  164. <tr>
  165. ${infras.map((infra) => {
  166. if (infra.CurrentLevel === 0)
  167. return '';
  168. const fill = currentPOPIFilled.get(infra.Type)!;
  169. return `<tr>
  170. <td>${infra.Type} T${infra.CurrentLevel}</td>
  171. <td>${fill.numMats}/${infra.Upkeeps.length}</td>
  172. </tr>`;
  173. }).join('')}
  174. </tr>
  175. </table>
  176. current projected ${pop.toUpperCase()} happiness:
  177. ${formatPct(projectedHappiness(pop, totalNeeds, siteCount, currentPOPIFilled, null))}
  178. <h2>options</h2>
  179. <table class="options">
  180. <tr>
  181. <th>config</th>
  182. <th>projected happiness</th>
  183. <th>projected change</th>
  184. <th>cost/day</th>
  185. <th>unit cost</th>
  186. </tr>
  187. ${paretoFront(pop, totalNeeds, siteCount, currentPOPIFilled, currentPop, lowerPop, totalPop, prices).map((result) => {
  188. let unitCost = '';
  189. if (result.cost > 0)
  190. unitCost = formatNum(result.cost / result.change);
  191. return `<tr>
  192. <td>
  193. ${[...result.config.entries()].map(([building, fill]) => {
  194. let currentBuildingFill = currentPOPIFilled.get(building)!.numMats;
  195. let className = '';
  196. if (fill.numMats > currentBuildingFill) className = 'positive';
  197. else if (fill.numMats < currentBuildingFill) className = 'negative';
  198. return `${building}: <span class="${className}">${fill.numMats}</span>`;
  199. }).join('<br>')}
  200. ${result.govProgram !== null ? `<br>${result.govProgram}` : ''}
  201. </td>
  202. <td>${formatPct(result.happiness)}</td>
  203. <td>${formatDelta(result.change)}</td>
  204. <td>${formatNum(result.cost)}</td>
  205. <td>${unitCost}</td>
  206. </tr>`;
  207. }).join('')}
  208. </table>
  209. `;
  210. }
  211. const formatNum = new Intl.NumberFormat(undefined, {maximumFractionDigits: 2}).format;
  212. const formatPct = new Intl.NumberFormat(undefined, {style: 'percent', maximumFractionDigits: 2}).format;
  213. function formatDelta(n: number, withPlus: boolean = true): string {
  214. if (n > 0)
  215. return `<span class="positive">${withPlus ? '+' : ''}${formatNum(n)}</span>`;
  216. else if (n < 0)
  217. return `<span class="negative">${formatNum(n)}</span>`;
  218. else
  219. return n.toString();
  220. }
  221. function unemployed(people: number, change: number, openJobs: number, unemploymentRate: number): string {
  222. let nextUnemployed;
  223. if (openJobs <= people + change) {
  224. let prevUnemploymentRate = unemploymentRate;
  225. if (openJobs > 0)
  226. if (people - change > 0)
  227. prevUnemploymentRate = -openJobs / (people - change);
  228. else
  229. prevUnemploymentRate = -1
  230. const prevUnemployed = prevUnemploymentRate * (people - change);
  231. nextUnemployed = prevUnemployed + change;
  232. } else
  233. nextUnemployed = -openJobs + change;
  234. return formatDelta(Math.round(nextUnemployed), false);
  235. }
  236. function calcTotalNeeds(popReport: POPR, need: Need): number {
  237. return popReport.NextPopulationPioneer * NEEDS.pio[need]
  238. + popReport.NextPopulationSettler * NEEDS.set[need]
  239. + popReport.NextPopulationTechnician * NEEDS.tec[need]
  240. + popReport.NextPopulationEngineer * NEEDS.eng[need]
  241. + popReport.NextPopulationScientist * NEEDS.sci[need];
  242. }
  243. function calcPOPIFilled(infra: Infrastructure): number | null {
  244. if (infra.CurrentLevel === 0)
  245. return null;
  246. let filled = 0;
  247. for (const upkeep of infra.Upkeeps) {
  248. const nextConsumptionAmount = upkeep.StoreCapacity / 30 * upkeep.Duration; // # capacity is always 30 days
  249. if (upkeep.Stored >= nextConsumptionAmount)
  250. filled++;
  251. }
  252. return filled;
  253. }
  254. function paretoFront(pop: Pop, totalNeeds: Record<Need, number>, siteCount: number, currentPOPIFilled: POPIFill,
  255. currentPop: number, lowerPop: number, totalPop: number, prices: Map<string, number>):
  256. {config: POPIFill, govProgram: GovProgram | null, happiness: number, change: number, cost: number}[] {
  257. const results: {config: POPIFill, govProgram: GovProgram | null, happiness: number, change: number, cost: number}[] = [];
  258. let education = 0;
  259. if (pop !== 'pio') {
  260. education = EDUCATION[pop];
  261. education += (currentPOPIFilled.get('PLANETARY_BROADCASTING_HUB')?.tier ?? 0) * 0.001;
  262. education += (currentPOPIFilled.get('LIBRARY')?.tier ?? 0) * 0.002;
  263. education += (currentPOPIFilled.get('UNIVERSITY')?.tier ?? 0) * 0.004;
  264. }
  265. const govPrograms: (GovProgram | null)[] = [null];
  266. govPrograms.push(...(Object.keys(GOV_PROGRAMS) as GovProgram[]));
  267. for (const config of popiFillCombinations(currentPOPIFilled)) {
  268. for (const govProgram of govPrograms) {
  269. const happiness = projectedHappiness(pop, totalNeeds, siteCount, config, govProgram);
  270. let change = 0;
  271. if (happiness > 0.7 && ['pio', 'set', 'tec'].includes(pop))
  272. change = currentPop * (happiness - 0.7);
  273. else if (happiness < 0.5)
  274. change = 0.8 * currentPop * (happiness - 0.5);
  275. if (govProgram === 'pio immigration' && pop === 'pio') change += 500;
  276. else if (govProgram === 'set immigration' && pop === 'set') change += 200;
  277. else if (govProgram === 'tec immigration' && pop === 'tec') change += 100;
  278. else if (govProgram === 'eng immigration' && pop === 'eng') change += 50;
  279. else if (govProgram === 'sci immigration' && pop === 'sci') change += 25;
  280. if (pop !== 'pio') {
  281. let eduIn = lowerPop * education * happiness;
  282. if (govProgram === 'education I') eduIn *= 1.5;
  283. else if (govProgram === 'education II') eduIn *= 1.75;
  284. else if (govProgram === 'education III') eduIn *= 2;
  285. change += eduIn;
  286. }
  287. // TODO: education out
  288. let cost = calcCost(config, prices);
  289. if (govProgram !== null) {
  290. const program = GOV_PROGRAMS[govProgram];
  291. cost += (program.baseCost + program.popCost * totalPop) / 7;
  292. }
  293. // is any result better than this one?
  294. if (results.some((result) => (result.change >= change && result.cost < cost) ||
  295. (result.change > change && result.cost <= cost)))
  296. continue;
  297. // are any results worse than this one?
  298. for (let i = results.length - 1; i >= 0; i--)
  299. if ((results[i].change <= change && results[i].cost > cost) ||
  300. (results[i].change < change && results[i].cost >= cost))
  301. results.splice(i, 1);
  302. results.push({config, govProgram, happiness, change, cost});
  303. }
  304. }
  305. return results;
  306. }
  307. function* popiFillCombinations(currentPOPIFilled: POPIFill): Generator<POPIFill> {
  308. const entries = [...currentPOPIFilled.keys()];
  309. function* helper(index: number, current: POPIFill): Generator<POPIFill> {
  310. if (index === entries.length) {
  311. yield new Map(current);
  312. return;
  313. }
  314. const building = entries[index];
  315. const tier = currentPOPIFilled.get(building)!.tier;
  316. const maxBuildingMats = Object.keys(POPI[building].mats).length;
  317. for (let i = 0; i <= maxBuildingMats; i++) {
  318. current.set(building, {tier, numMats: i});
  319. yield* helper(index + 1, current);
  320. }
  321. }
  322. yield* helper(0, new Map());
  323. }
  324. function projectedHappiness(pop: Pop, totalNeeds: Record<Need, number>, siteCount: number, popiFilled: POPIFill,
  325. govProgram: GovProgram | null): number {
  326. let totalProvided: Record<Need, number> = {'safety': 50 * siteCount, 'health': 50 * siteCount,
  327. 'comfort': 0, 'culture': 0, 'education': 0};
  328. for (const [building, fill] of popiFilled.entries()) {
  329. const {needs} = POPI[building];
  330. const maxBuildingMats = Object.keys(POPI[building].mats).length;
  331. for (const {need, supplied} of needs) {
  332. const provided = fill.numMats / maxBuildingMats * fill.tier * supplied;
  333. totalProvided[need] += provided;
  334. }
  335. }
  336. const satisfaction: Map<Need, number> = new Map(); // percentage of needs fulfilled
  337. for (const _need in totalProvided) {
  338. const need = _need as Need;
  339. satisfaction.set(need, Math.min(totalProvided[need] / totalNeeds[need], 1));
  340. }
  341. const safetyHealthCap = Math.min(satisfaction.get('safety')!, satisfaction.get('health')!);
  342. if (satisfaction.get('comfort')! > safetyHealthCap)
  343. satisfaction.set('comfort', safetyHealthCap);
  344. if (satisfaction.get('culture')! > safetyHealthCap)
  345. satisfaction.set('culture', safetyHealthCap);
  346. const comfortCultureCap = Math.min(satisfaction.get('comfort')!, satisfaction.get('culture')!);
  347. if (satisfaction.get('education')! > comfortCultureCap)
  348. satisfaction.set('education', comfortCultureCap);
  349. const weights = NEEDS[pop];
  350. let happiness = 1 - Object.values(weights).reduce((sum, weight) => sum + weight, 0); // assume 100% life support
  351. for (const [need, s] of satisfaction.entries())
  352. happiness += weights[need] * s;
  353. if (govProgram === 'festivities I')
  354. happiness += 0.05;
  355. else if (govProgram === 'festivities II')
  356. happiness += 0.1;
  357. else if (govProgram === 'festivities III')
  358. happiness += 0.2;
  359. return Math.min(happiness, 1);
  360. }
  361. function calcCost(config: POPIFill, prices: Map<string, number>): number {
  362. let cost = 0;
  363. for (const [building, fill] of config.entries()) {
  364. const {mats} = POPI[building];
  365. const matPrices: {ticker: string, costPerDay: number}[] = [];
  366. for (const [mat, amount] of Object.entries(mats)) {
  367. const matCost = prices.get(mat)!;
  368. if (!matCost)
  369. throw new Error('no price for ' + mat);
  370. matPrices.push({ticker: mat, costPerDay: matCost * amount});
  371. }
  372. matPrices.sort((a, b) => a.costPerDay - b.costPerDay);
  373. for (let i = 0; i < fill.numMats; i++)
  374. cost += matPrices[i].costPerDay * fill.tier;
  375. }
  376. return cost;
  377. }
  378. const NEEDS: Record<Pop, Record<Need, number>> = {
  379. 'pio': {'safety': 0.25, 'health': 0.15, 'comfort': 0.03, 'culture': 0.02, 'education': 0.01},
  380. 'set': {'safety': 0.30, 'health': 0.20, 'comfort': 0.03, 'culture': 0.03, 'education': 0.03},
  381. 'tec': {'safety': 0.20, 'health': 0.30, 'comfort': 0.20, 'culture': 0.10, 'education': 0.05},
  382. 'eng': {'safety': 0.10, 'health': 0.15, 'comfort': 0.35, 'culture': 0.20, 'education': 0.10},
  383. 'sci': {'safety': 0.10, 'health': 0.10, 'comfort': 0.20, 'culture': 0.25, 'education': 0.30},
  384. }
  385. const POPI: Record<POPIBuilding, {needs: {need: Need, supplied: number}[], mats: Record<string, number>}> = {
  386. 'SAFETY_STATION': {
  387. needs: [{need: 'safety', supplied: 2500}],
  388. mats: {'DW': 10, 'OFF': 10, 'SUN': 2},
  389. },
  390. 'SECURITY_DRONE_POST': {
  391. needs: [{need: 'safety', supplied: 5000}],
  392. mats: {'POW': 1, 'RAD': 0.47, 'CCD': 0.07, 'SUD': 0.07},
  393. },
  394. 'EMERGENCY_CENTER': {
  395. needs: [{need: 'safety', supplied: 1000}, {need: 'health', supplied: 1000}],
  396. mats: {'PK': 2, 'POW': 0.4, 'BND': 4, 'RED': 0.07, 'BSC': 0.07},
  397. },
  398. 'INFIRMARY': {
  399. needs: [{need: 'health', supplied: 2500}],
  400. mats: {'OFF': 10, 'TUB': 6.67, 'STR': 0.67},
  401. },
  402. 'HOSPITAL': {
  403. needs: [{need: 'health', supplied: 5000}],
  404. mats: {'PK': 2, 'SEQ': 0.4, 'BND': 4, 'SDR': 0.07, 'RED': 0.07, 'BSC': 0.13},
  405. },
  406. 'WELLNESS_CENTER': {
  407. needs: [{need: 'health', supplied: 1000}, {need: 'comfort', supplied: 1000}],
  408. mats: {'KOM': 4, 'OLF': 2, 'DW': 6, 'DEC': 0.67, 'PFE': 2.67, 'SOI': 6.67},
  409. },
  410. 'WILDLIFE_PARK': {
  411. needs: [{need: 'comfort', supplied: 2500}],
  412. mats: {'DW': 10, 'FOD': 6, 'PFE': 2, 'SOI': 3.33, 'DEC': 0.33},
  413. },
  414. 'ARCADES': {
  415. needs: [{need: 'comfort', supplied: 5000}],
  416. mats: {'POW': 2, 'MHP': 2, 'OLF': 4, 'BID': 0.2, 'HOG': 0.2, 'EDC': 0.2},
  417. },
  418. 'ART_CAFE': {
  419. needs: [{need: 'comfort', supplied: 1000}, {need: 'culture', supplied: 1000}],
  420. mats: {'MHP': 1, 'HOG': 1, 'UTS': 0.67, 'DEC': 0.67},
  421. },
  422. 'ART_GALLERY': {
  423. needs: [{need: 'culture', supplied: 2500}],
  424. mats: {'MHP': 1, 'HOG': 1, 'UTS': 0.67, 'DEC': 0.67},
  425. },
  426. 'THEATER': {
  427. needs: [{need: 'culture', supplied: 5000}],
  428. mats: {'POW': 1.4, 'MHP': 2, 'HOG': 1.4, 'OLF': 4, 'BID': 0.33, 'DEC': 0.67},
  429. },
  430. 'PLANETARY_BROADCASTING_HUB': {
  431. needs: [{need: 'culture', supplied: 1000}, {need: 'education', supplied: 1000}],
  432. mats: {'OFF': 10, 'MHP': 1, 'SP': 1.33, 'AAR': 0.67, 'EDC': 0.27, 'IDC': 0.13},
  433. },
  434. 'LIBRARY': {
  435. needs: [{need: 'education', supplied: 2500}],
  436. mats: {'MHP': 1, 'HOG': 1, 'CD': 0.33, 'DIS': 0.33, 'BID': 0.2},
  437. },
  438. 'UNIVERSITY': {
  439. needs: [{need: 'education', supplied: 5000}],
  440. mats: {'COF': 10, 'REA': 10, 'TUB': 10, 'BID': 0.33, 'HD': 0.67, 'IDC': 0.2},
  441. },
  442. };
  443. const EDUCATION: Record<Exclude<Pop, 'pio'>, number> = {
  444. 'set': 0.025,
  445. 'tec': 0.02,
  446. 'eng': 0.0125,
  447. 'sci': 0.0075,
  448. }
  449. const GOV_PROGRAMS: Record<GovProgram, {baseCost: number, popCost: number}> = {
  450. 'festivities I': {baseCost: 5000, popCost: 0.125},
  451. 'festivities II': {baseCost: 10000, popCost: 0.25},
  452. 'festivities III': {baseCost: 20000, popCost: 0.5},
  453. 'education I': {baseCost: 5000, popCost: 0.15},
  454. 'education II': {baseCost: 10000, popCost: 0.25},
  455. 'education III': {baseCost: 20000, popCost: 0.4},
  456. 'pio immigration': {baseCost: 10000, popCost: 0},
  457. 'set immigration': {baseCost: 25000, popCost: 0},
  458. 'tec immigration': {baseCost: 50000, popCost: 0},
  459. 'eng immigration': {baseCost: 80000, popCost: 0},
  460. 'sci immigration': {baseCost: 125000, popCost: 0},
  461. }
  462. type Pop = 'pio' | 'set' | 'tec' | 'eng' | 'sci';
  463. type Need = 'safety' | 'health' | 'comfort' | 'culture' | 'education';
  464. type POPIBuilding = 'SAFETY_STATION' | 'SECURITY_DRONE_POST' | 'EMERGENCY_CENTER' | 'INFIRMARY' | 'HOSPITAL' |
  465. 'WELLNESS_CENTER' | 'WILDLIFE_PARK' | 'ARCADES' | 'ART_CAFE' | 'ART_GALLERY' | 'THEATER' |
  466. 'PLANETARY_BROADCASTING_HUB' | 'LIBRARY' | 'UNIVERSITY';
  467. type POPIFill = Map<POPIBuilding, {tier: number, numMats: number}>;
  468. type GovProgram = 'festivities I' | 'festivities II' | 'festivities III' | 'education I' | 'education II' | 'education III' |
  469. 'pio immigration' | 'set immigration' | 'tec immigration' | 'eng immigration' | 'sci immigration';
  470. interface Planet {
  471. PopulationReports: POPR[]
  472. }
  473. interface POPR {
  474. SimulationPeriod: number;
  475. ReportTimestamp: string;
  476. NeedFulfillmentSafety: number;
  477. NeedFulfillmentHealth: number;
  478. NeedFulfillmentComfort: number;
  479. NeedFulfillmentCulture: number;
  480. NeedFulfillmentEducation: number;
  481. NextPopulationPioneer: number;
  482. NextPopulationSettler: number;
  483. NextPopulationTechnician: number;
  484. NextPopulationEngineer: number;
  485. NextPopulationScientist: number;
  486. PopulationDifferencePioneer: number;
  487. PopulationDifferenceSettler: number;
  488. PopulationDifferenceTechnician: number;
  489. PopulationDifferenceEngineer: number;
  490. PopulationDifferenceScientist: number;
  491. OpenJobsPioneer: number;
  492. OpenJobsSettler: number;
  493. OpenJobsTechnician: number;
  494. OpenJobsEngineer: number;
  495. OpenJobsScientist: number;
  496. UnemploymentRatePioneer: number;
  497. UnemploymentRateSettler: number;
  498. UnemploymentRateTechnician: number;
  499. UnemploymentRateEngineer: number;
  500. UnemploymentRateScientist: number;
  501. }
  502. interface SiteCount {
  503. Count: number;
  504. }
  505. interface Infrastructure {
  506. Type: POPIBuilding;
  507. CurrentLevel: number;
  508. Upkeeps: {Stored: number, StoreCapacity: number, 'Duration': number}[];
  509. }
  510. interface Price {
  511. ticker: string
  512. exchange_code: string
  513. vwap_30d: number
  514. ask: number
  515. }