Simulation Loop
Understanding the tick-based execution model.
The Main Loop
Each tick follows this sequence:
Update NPCs: Execute NPC AI behaviors
Agent Perception: Update fog of war, detect entities
Agent Decision: Evaluate goals, plan actions
Execute Actions: Process all queued actions
Update Systems: Trading, respawns, market prices
Database Logging: Save snapshots and events
Advance Time: Increment tick counter
Tick Timing
1 tick = 1 simulation time unit
60 ticks = 1 simulation minute (by convention)
Real-time execution controlled by
tick_rate
config
Action Execution
Actions can be:
Instant: Complete in 1 tick (e.g., MoveAction)
Progressive: Take multiple ticks (e.g., GatherAction)
Interruptible: Can be cancelled
Goal Management
Each agent maintains a priority queue of goals:
Evaluate all goals for utility
Select highest-utility achievable goal
Request next action from goal
Queue action for execution
Monitor goal completion
When goals complete or fail, agents re-evaluate.
System Updates
- Trading System
Process pending trades
Expire old offers
Match buyers and sellers
- Respawn Manager
Track dead entities
Spawn entities after delay
Place in safe zones
- Market
Update prices based on trades
Calculate supply/demand
Database Persistence
Snapshots saved at intervals:
Agent state (position, health, inventory)
World state (resource levels, active entities)
Analytics metrics (economy, social networks)
All actions and events logged for analysis.