Browse Source

supply: XIT ACT

raylu 3 weeks ago
parent
commit
ad1f63f78b
1 changed files with 37 additions and 2 deletions
  1. 37 2
      supply.py

+ 37 - 2
supply.py

@@ -1,6 +1,9 @@
 from __future__ import annotations
 
+import collections
 import dataclasses
+import json
+import math
 import sys
 import tomllib
 import typing
@@ -27,7 +30,7 @@ def main() -> None:
 		print(planet.name, f'consumes {vol_per_day:.1f}㎥, {weight_per_day:.1f}t per day')
 
 	load_more = True
-	optimal = dict.fromkeys(p.name for p in planets)
+	optimal: dict[str, dict[str, float]] = dict.fromkeys(p.name for p in planets) # pyright: ignore[reportAssignmentType]
 	target_days = round(target_days + 0.05, 1)
 	while load_more:
 		total_weight_used = total_volume_used = 0
@@ -43,7 +46,7 @@ def main() -> None:
 	print('supply for', round(target_days, 1), 'days')
 
 	for planet in planets:
-		print('\n' + planet.name)
+		print('\n' + cyan(planet.name))
 		for consumption in planet.net_consumption:
 			ticker = consumption['MaterialTicker']
 			avail = planet.inventory.get(ticker, 0)
@@ -54,6 +57,35 @@ def main() -> None:
 				print(f' | {need:8.1f}')
 			else:
 				print()
+	
+	combined_buy: dict[str, float] = collections.defaultdict(float)
+	for buy in optimal.values():
+		for ticker, amount in buy.items():
+			combined_buy[ticker] += amount
+	print(cyan('\nbuy:\n') + json.dumps({
+		'actions': [
+			{'name': 'BuyItems', 'type': 'CX Buy', 'group': 'A1', 'exchange': 'IC1',
+				'priceLimits': {}, 'buyPartial': False, 'useCXInv': True},
+			{'type': 'MTRA', 'name': 'TransferAction', 'group': 'A1',
+				'origin': 'Hortus Station Warehouse', 'dest': 'Configure on Execution'},
+		],
+		'global': {'name': 'supply ' + ' '.join(planet_names)},
+		'groups': [{
+			'type': 'Manual', 'name': 'A1', 'materials': {mat: math.ceil(amount) for mat, amount in combined_buy.items()}
+		}],
+	}))
+	for planet in planets:
+		buy = optimal[planet.name]
+		print(cyan(f'unload {planet.name}:\n') + json.dumps({
+			'actions': [
+				{'type': 'MTRA', 'name': 'TransferAction', 'group': 'A1',
+					'origin': 'Configure on Execution', 'dest': planet.name + ' Base'},
+			],
+			'global': {'name': 'unload ' + planet.name},
+			'groups': [{
+				'type': 'Manual', 'name': 'A1', 'materials': {mat: round(amount) for mat, amount in buy.items()}
+			}],
+		}))
 
 def get_fio_burn(planet_names: typing.Sequence[str]) -> typing.Iterator[FIOBurn]:
 	with open('config.toml', 'rb') as f:
@@ -71,6 +103,9 @@ def get_fio_burn(planet_names: typing.Sequence[str]) -> typing.Iterator[FIOBurn]
 		else:
 			raise ValueError(name + ' not found')
 
+def cyan(text: str) -> str:
+	return '\033[36m' + text + '\033[0m'
+
 class FIOBurn(typing.TypedDict):
 	PlanetName: str
 	PlanetNaturalId: str