feat: buildable list, building interaction API (toggle/set_recipe/empty/cancel)

New endpoints:
- GET /api/state/buildable: buildings filtered by completed research (unlocked/locked)
- POST /api/action/toggle: toggle building on/off (save power, control workflow)
- POST /api/action/set_recipe: set building recipe (e.g. Rock Crusher mode)
- POST /api/action/empty: empty building storage (drop all contents)
- POST /api/action/cancel_errand: cancel all errands at a building

Improved research: proper prerequisite validation, tech queueing, research station check

CLI: buildable [filter], toggle, set_recipe, empty, cancel_errand
Updated SKILL.md with new endpoint docs
This commit is contained in:
root
2026-05-22 09:32:49 +08:00
parent 80485d2a5a
commit 7a946aa555
3 changed files with 244 additions and 15 deletions

View File

@ -792,6 +792,65 @@ def _print_feedback(result):
if sug:
print(f" -> {sug}")
# ---------------------------------------------------------------------------
# Buildable / Research / Building Interaction
# ---------------------------------------------------------------------------
def cmd_buildable(args):
"""List all buildable buildings. Usage: buildable [filter]"""
filt = args[0].lower() if args else ""
data = api_get('/api/state/buildable')
if 'error' in data:
print(f"Error: {data['error']}")
return
total = data.get('total', 0)
unlocked = data.get('unlocked', 0)
print(f"Buildings: {unlocked}/{total} unlocked")
print()
for b in data.get('buildings', []):
name = b.get('name', '?')
bid = b.get('id', '')
if filt and filt not in name.lower() and filt not in bid.lower():
continue
mark = "✓" if b.get('unlocked') else "✗"
cat = b.get('category', '?')
pw = f" {b.get('powerCost', 0)}W" if b.get('powerCost', 0) > 0 else ""
print(f" [{mark}] {name:30s} {bid:30s} {cat:15s}{pw}")
def cmd_toggle(args):
"""Toggle building on/off. Usage: toggle <x> <y>"""
if len(args) < 2:
print("Usage: toggle <x> <y>")
return
result = api_post('/api/action/toggle', {"x": int(args[0]), "y": int(args[1])})
_print_feedback(result)
def cmd_set_recipe(args):
"""Set a building's recipe. Usage: set_recipe <x> <y> <recipeId>"""
if len(args) < 3:
print("Usage: set_recipe <x> <y> <recipeId>")
return
result = api_post('/api/action/set_recipe', {
"x": int(args[0]), "y": int(args[1]), "recipeId": args[2]
})
_print_feedback(result)
def cmd_empty(args):
"""Empty a building's storage. Usage: empty <x> <y>"""
if len(args) < 2:
print("Usage: empty <x> <y>")
return
result = api_post('/api/action/empty', {"x": int(args[0]), "y": int(args[1])})
_print_feedback(result)
def cmd_cancel_errand(args):
"""Cancel errands at a building. Usage: cancel_errand <x> <y>"""
if len(args) < 2:
print("Usage: cancel_errand <x> <y>")
return
result = api_post('/api/action/cancel_errand', {"x": int(args[0]), "y": int(args[1])})
_print_feedback(result)
# ---------------------------------------------------------------------------
# Screenshot / Camera
# ---------------------------------------------------------------------------
@ -956,6 +1015,11 @@ COMMANDS = {
'snapshot': cmd_snapshot,
'camera': cmd_camera,
'camera_status': cmd_camera_status,
'buildable': cmd_buildable,
'toggle': cmd_toggle,
'set_recipe': cmd_set_recipe,
'empty': cmd_empty,
'cancel_errand': cmd_cancel_errand,
}
if __name__ == '__main__':
@ -994,14 +1058,16 @@ if __name__ == '__main__':
print(" registry techs [f] List all tech IDs with unlocks")
print(" registry priorities Show priority level meanings")
print("")
print("=== Actions ===")
print(" dig <x> <y> <w> <h> Dig area")
print(" build <id> <x> <y> Place building")
print(" deconstruct <id> <x> <y> Remove building")
print(" prioritize <x> <y> <p> Set priority")
print(" research_select <id> Select tech to research")
print(" mop <x> <y> Mop liquid")
print(" harvest <x> <y> Harvest plant")
print("=== Building Interaction ===")
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("")
print("=== Game Speed Control ===")
print(" pause [reason] Pause the game (AI should always pause before ops)")