Skip to content

Latest commit

 

History

History
132 lines (103 loc) · 3.55 KB

File metadata and controls

132 lines (103 loc) · 3.55 KB

0aid - AI Mod for 0 A.D.

Co-authored by:

Two-Mod Architecture

We use two separate mods for crash resilience:

Mod Purpose If 0aid crashes...
0aid AI assist logic Disables itself
zeroab Toggle button UI Still works!

This way, if you break 0aid.js, the button still works to re-enable it.

Project Structure

/var/srv/0aid/
├── mod.json                 # 0aid mod metadata
├── gui/
│   └── session/
│       └── 0aid.js          # Main AI assist code
├── zeroab/                  # Separate button mod
│   ├── mod.json
│   └── gui/
│       └── session/
│           ├── zeroab.js    # Button logic
│           └── zeroab.xml   # Button UI
├── autociv/                 # Reference: autociv mod patterns
├── extracted/               # Reference: extracted 0 A.D. components
└── layout.md                # This file

Setup (One-Time, Both Machines)

1. Flatpak Filesystem Access

flatpak override --user --filesystem=/var/srv/0aid com.play0ad.zeroad

2. Create Symlinks to Mods Folder

# Main mod
ln -sfn /var/srv/0aid ~/.var/app/com.play0ad.zeroad/data/0ad/mods/0aid

# Button mod
ln -sfn /var/srv/0aid/zeroab ~/.var/app/com.play0ad.zeroad/data/0ad/mods/zeroab

3. Git Config

git config --global --add safe.directory /var/srv/0aid

Testing the Mods

Launch 0 A.D.

flatpak run com.play0ad.zeroad

Enable Both Mods

  1. Main Menu -> Settings -> Mod Selection
  2. Enable both "0aid" and "Zero AI Button"
  3. Click "Save Configuration"
  4. Restart when prompted

Test During Gameplay

  • Start a single-player game
  • Console shows: [0aid] Loaded! and [zeroab] Loaded!
  • Button appears in top-right showing "0aid: ON"
  • Click button to toggle, or use console commands

Crash Protection

How It Works

  1. 0aid.js wraps its main loop in try/catch
  2. If an error occurs, it logs it and increments error count
  3. After 3 errors, 0aid disables itself
  4. The game keeps running!
  5. Fix your code, then re-enable via button or console

Error Types

Error Type What Happens Recovery
Runtime error 0aid catches it, logs, may disable Click button or zeroaid_Enable()
Syntax error JS won't parse, mod fails to load Fix code, hot-reload retries
Infinite loop Game freezes Must restart game

Console Commands (F9)

zeroaid_Enable()      // Re-enable after errors
zeroaid_Disable()     // Turn off
zeroaid_Toggle()      // Toggle on/off
zeroaid_ToggleAuto()  // Toggle auto-assign villagers

Hot Reload

Edit gui/session/0aid.js while playing - changes reload automatically!

  1. Keep game running
  2. Edit code in your editor
  3. Save file
  4. Check console (F9) for errors
  5. If errors, fix and save again
  6. If disabled, click button to re-enable

Collaboration with Zed

When using Zed's real-time collaboration:

  • Both see edits instantly in the editor
  • Files save to the host's machine only
  • Whoever runs the game sees hot-reload
  • Commit & push so other machine can pull

Workflow:

  1. Host shares Zed project
  2. Both edit together
  3. Host tests in-game
  4. Commit & push when working
  5. Other machine: git pull

Reference