ソースを参照

supply: don't buy materials supplied by other planets

raylu 4 週間 前
コミット
a33423d373
1 ファイル変更7 行追加10 行削除
  1. 7 10
      supply.py

+ 7 - 10
supply.py

@@ -84,17 +84,19 @@ def main() -> None:
 			for p in cache.get('https://refined-prun.github.io/refined-prices/all.json') if p['ExchangeCode'] == 'IC1'}
 
 	warehouse = warehouse_inventory()
+	from_cx: dict[str, int] = collections.defaultdict(int)
 	total_cost = 0
 	for i, planet in enumerate(planets):
 		print('\n' + cyan(planet.name))
 		supply_config = config.supply_config(planet.name)
+		planet_buy = optimal[planet.name]
 		for consumption in planet.net_consumption:
 			ticker = consumption['MaterialTicker']
 			avail = planet.inventory.get(ticker, 0)
 			daily_consumption = consumption['net_consumption']
 			days = avail / daily_consumption
 			print(f'{ticker:>3}: {avail:5d} ({daily_consumption:8.2f}/d) {days:4.1f} d', end='')
-			if need := optimal[planet.name].get(ticker): # pyright: ignore[reportOptionalMemberAccess]
+			if need := planet_buy.get(ticker): # pyright: ignore[reportOptionalMemberAccess]
 				if ticker in supply_config.ignore_materials:
 					print(f' | {need:5.0f} (ignored)')
 				else:
@@ -105,6 +107,8 @@ def main() -> None:
 							need -= min(need, avail)
 							exporter.inventory[ticker] -= max(avail - need, 0)
 							sources.append(f'{exporter.name}: {avail}')
+					if need:
+						from_cx[ticker] += need # count from_cx before subtracting warehouse
 					if avail := warehouse.get(ticker, 0):
 						need -= min(need, avail)
 						warehouse[ticker] -= max(avail - need, 0)
@@ -115,14 +119,7 @@ def main() -> None:
 			else:
 				print()
 	print(f'\ntotal cost: {total_cost:,}')
-
-	combined_buy: dict[str, int] = collections.defaultdict(int)
-	for planet_name, buy in optimal.items():
-		supply_config = config.supply_config(planet_name)
-		for ticker, amount in buy.items():
-			if ticker not in supply_config.ignore_materials:
-				combined_buy[ticker] += amount
-	print(cyan('\nbuy:\n') + json.dumps({
+	print(cyan('\nload at CX:\n') + json.dumps({
 		'actions': [
 			{'name': 'BuyItems', 'type': 'CX Buy', 'group': 'A1', 'exchange': 'IC1',
 				'priceLimits': {}, 'buyPartial': False, 'useCXInv': True},
@@ -131,7 +128,7 @@ def main() -> None:
 		],
 		'global': {'name': 'supply ' + ' '.join(args.planets)},
 		'groups': [{
-			'type': 'Manual', 'name': 'A1', 'materials': {mat: amount for mat, amount in combined_buy.items()}
+			'type': 'Manual', 'name': 'A1', 'materials': {mat: amount for mat, amount in from_cx.items()}
 		}],
 	}))
 	for planet in planets: