feat: comprehensive research + building detail APIs
Research system: - GET /api/state/research/detail: station status, active tech, research points - POST /api/action/research_cancel [techId]: cancel specific or all active research - Improved research queueing with proper prerequisite checks Building detail/interaction: - GET /api/state/building_detail?x=&y=: full single-building detail (health, automation, storage contents, materials, power, recipes) - POST /api/action/set_building_priority: set priority 1-9 per building - POST /api/action/set_automation: enable/disable automation input - Enhanced building list with health/damage info CLI: research_detail, research_cancel, building_detail, set_building_priority, set_automation
This commit is contained in:
100
tools/oni_api.py
100
tools/oni_api.py
@ -851,6 +851,86 @@ def cmd_cancel_errand(args):
|
||||
result = api_post('/api/action/cancel_errand', {"x": int(args[0]), "y": int(args[1])})
|
||||
_print_feedback(result)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Research Enhancements
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def cmd_research_detail(args):
|
||||
"""Detailed research status. Usage: research_detail"""
|
||||
data = api_get('/api/state/research/detail')
|
||||
if 'error' in data:
|
||||
print(f"Error: {data['error']}")
|
||||
return
|
||||
print("=== Research Status ===")
|
||||
print(f" Research Station: {'✓' if data.get('researchStationOperational') else '✗'} "
|
||||
f"(built={data.get('hasResearchStation', False)})")
|
||||
print(f" Super Computer: {'✓' if data.get('hasSuperComputer') else '✗'}")
|
||||
active = data.get('activeResearch', [])
|
||||
if active:
|
||||
for a in active:
|
||||
print(f" Active: {a.get('name', '?')} ({a.get('progress', 0)*100:.0f}%)")
|
||||
else:
|
||||
print(f" Active: none {'[all complete]' if data.get('researchComplete') else '[idle]'}")
|
||||
stations = data.get('stations', [])
|
||||
if stations:
|
||||
print(f" Stations: {len(stations)}")
|
||||
for s in stations:
|
||||
op = 'ON' if s.get('isOperational') else 'OFF'
|
||||
print(f" {s.get('name', '?')} at ({s.get('x', '?')},{s.get('y', '?')}) [{op}]")
|
||||
|
||||
def cmd_research_cancel(args):
|
||||
"""Cancel research. Usage: research_cancel [techId]"""
|
||||
payload = {"techId": args[0]} if args else {}
|
||||
result = api_post('/api/action/research_cancel', payload)
|
||||
_print_feedback(result)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Building Detail
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def cmd_building_detail(args):
|
||||
"""Detailed info about a building. Usage: building_detail <x> <y>"""
|
||||
if len(args) < 2:
|
||||
print("Usage: building_detail <x> <y>")
|
||||
return
|
||||
data = api_get(f"/api/state/building_detail?x={args[0]}&y={args[1]}")
|
||||
if 'error' in data:
|
||||
print(f"Error: {data['error']}")
|
||||
return
|
||||
print(f"Building: {data.get('name', '?')} ({data.get('id', '?')})")
|
||||
print(f" Position: ({data.get('x', '?')},{data.get('y', '?')}) size={data.get('width')}x{data.get('height')}")
|
||||
print(f" Operational: {'ON' if data.get('isOperational') else 'OFF'}")
|
||||
print(f" Powered: {'YES' if data.get('isPowered') else 'NO'} {data.get('powerWatt', 0)}W")
|
||||
print(f" Health: {data.get('health', '?')}/{data.get('maxHealth', '?')}")
|
||||
storage = data.get('storageItems', [])
|
||||
if storage:
|
||||
print(f" Storage: {data.get('storageMass', 0):.0f}/{data.get('storageCapacity', 0):.0f} kg")
|
||||
for s in storage[:5]:
|
||||
print(f" {s.get('name', '?')}: {s.get('mass', 0):.1f} kg")
|
||||
print(f" Automation: {'YES' if data.get('hasAutomation') else 'NO'}")
|
||||
print(f" Materials: {', '.join(data.get('material', []))}")
|
||||
|
||||
def cmd_set_building_priority(args):
|
||||
"""Set a building's priority. Usage: set_building_priority <x> <y> <priority>"""
|
||||
if len(args) < 3:
|
||||
print("Usage: set_building_priority <x> <y> <priority 1-9>")
|
||||
return
|
||||
result = api_post('/api/action/set_building_priority', {
|
||||
"x": int(args[0]), "y": int(args[1]), "priority": int(args[2])
|
||||
})
|
||||
_print_feedback(result)
|
||||
|
||||
def cmd_set_automation(args):
|
||||
"""Toggle automation on a building. Usage: set_automation <x> <y> <on|off>"""
|
||||
if len(args) < 3:
|
||||
print("Usage: set_automation <x> <y> <on|off>")
|
||||
return
|
||||
enabled = args[2].lower() in ('on', 'true', '1', 'yes')
|
||||
result = api_post('/api/action/set_automation', {
|
||||
"x": int(args[0]), "y": int(args[1]), "enabled": enabled
|
||||
})
|
||||
_print_feedback(result)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Screenshot / Camera
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -1020,6 +1100,11 @@ COMMANDS = {
|
||||
'set_recipe': cmd_set_recipe,
|
||||
'empty': cmd_empty,
|
||||
'cancel_errand': cmd_cancel_errand,
|
||||
'research_detail': cmd_research_detail,
|
||||
'research_cancel': cmd_research_cancel,
|
||||
'building_detail': cmd_building_detail,
|
||||
'set_building_priority': cmd_set_building_priority,
|
||||
'set_automation': cmd_set_automation,
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -1058,16 +1143,21 @@ if __name__ == '__main__':
|
||||
print(" registry techs [f] List all tech IDs with unlocks")
|
||||
print(" registry priorities Show priority level meanings")
|
||||
print("")
|
||||
print("=== Research / Buildable ===")
|
||||
print(" buildable [filter] List buildings unlocked by current research")
|
||||
print(" research Show research tree progress")
|
||||
print(" research_detail Detailed research status (active tech / stations)")
|
||||
print(" research_select <id> Select tech to research")
|
||||
print(" research_cancel [id] Cancel research (all or specific tech)")
|
||||
print("")
|
||||
print("=== Building Interaction ===")
|
||||
print(" building_detail <x> <y> Full detail for a building (health/contents/automation)")
|
||||
print(" toggle <x> <y> Toggle building on/off")
|
||||
print(" set_recipe <x> <y> <id> Set building recipe")
|
||||
print(" empty <x> <y> Empty building storage")
|
||||
print(" cancel_errand <x> <y> Cancel errands at building")
|
||||
print("")
|
||||
print("=== Research / Buildable ===")
|
||||
print(" buildable [filter] List buildings unlocked by current research")
|
||||
print(" research_select <id> Select tech to research")
|
||||
print(" research Show research tree progress")
|
||||
print(" set_building_priority <x> <y> <p> Set building priority 1-9")
|
||||
print(" set_automation <x> <y> on|off Toggle automation input")
|
||||
print("")
|
||||
print("=== Game Speed Control ===")
|
||||
print(" pause [reason] Pause the game (AI should always pause before ops)")
|
||||
|
||||
Reference in New Issue
Block a user