Files
PuGa/tools/buildcost.py
T
dodoxandClaude Sonnet 5 bf15c709ea Add planet environment-extra materials to capex calcs; buildcost.py tool
Every building needs a planet-hazard material bundle on top of its normal
BuildingCosts (SEA for low pressure, HSE for high pressure, MGC for low
gravity, BL for high gravity, INS for cold, TSH for heat - area-scaled
where applicable), confirmed against live in-game build panels on Nike.
FIO's own BuildRequirements field is an unreliable superset across hazard
types, not a direct per-building list - don't use it directly.

- puga/planet.py::environment_extras(): the real threshold table.
- tools/buildcost.py: full construction material list for one building,
  optionally on a given planet.
- Wired into whatif.py/buy.py (via simulate(planet=...)) and scan.py's
  own bcost(), so their capex numbers stop silently omitting this.
- docs/mechanics.md: the rule, plus a separate forum-sourced note on the
  CX order-cancellation penalty.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-17 19:03:51 +02:00

50 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Full construction material list for one building, optionally on a specific planet (adds its
environment-extra materials via puga.planet.environment_extras() - SEA/HSE/MGC/BL/INS/TSH).
puga buildcost HB1
puga buildcost EXT --planet ZV-194a
puga buildcost PP1 --planet ZV-194a --amount 1
"""
import argparse, sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from puga import config, fio, market, prunplanner as pp, planet as planet_mod
def main():
ap = argparse.ArgumentParser()
ap.add_argument("building", help="building ticker, e.g. HB1, EXT, PP1")
ap.add_argument("--planet", help="planet natural id - adds its environment-extra materials")
ap.add_argument("--amount", type=int, default=1)
ap.add_argument("--cx", default=config.DEFAULT_CX)
a = ap.parse_args()
blds = {b["Ticker"]: b for b in fio.buildings()}
b = blds.get(a.building.upper())
if not b:
sys.exit(f"unknown building {a.building!r}")
need: dict[str, float] = {c["CommodityTicker"]: c["Amount"] for c in b["BuildingCosts"]}
need["MCG"] = need.get("MCG", 0) + 4 * b["AreaCost"]
if a.planet:
planet = pp._g(f"/data/planet/{a.planet}/", 3600)
for tk, qty in planet_mod.environment_extras(planet, b["AreaCost"]).items():
need[tk] = need.get(tk, 0) + qty
print(f"# {b['Ticker']} on {planet['planet_name']} ({a.planet}): pressure {planet['pressure']:.3f}, "
f"gravity {planet['gravity']:.2f}, temp {planet['temperature']:.1f}C")
total = 0.0
for tk, qty in sorted(need.items()):
qty *= a.amount
cost = market.walk(tk, a.cx, qty, "buy")
px = cost["total"] if not cost["short"] else None
total += px or 0
print(f"{tk:4} {qty:8.1f} {px:>10,.0f} AIC" if px is not None else f"{tk:4} {qty:8.1f} (short on {a.cx})")
print(f"total: {total:,.0f} AIC" if total else "")
if __name__ == "__main__":
main()