Custom Behaviors
Addon mods can add new AI tasks and entity behaviors on top of the base VS entity system. Heartwood provides several built-in behaviors that addons can enable; you can also write new ones.
Built-in behaviors (from Fauna)
These behaviors are implemented in the Fauna addon and can serve as reference implementations:
| Behavior | Class | Description |
|---|---|---|
| Herd cohesion | AiTaskHerdCohesion | Keeps entities grouped within a radius |
| Graze | AiTaskGraze | Random idle wandering for herbivores |
| Return home | AiTaskReturnHome | Navigate back to assigned den/burrow |
| Use den | AiTaskUseDen | Enter and rest inside a den entrance block |
Built-in behaviors (from Wingspan)
| Behavior | Class | Description |
|---|---|---|
| Boids flocking | AiTaskBoidsFlock | Separation/cohesion/alignment flocking |
| Takeoff | AiTaskTakeoff | Launch from perch to air |
| Land | AiTaskLand | Descend from air to perch |
| Perch | AiTaskPerch | Idle on a surface |
| Feeder approach | AiTaskApproachFeeder | Walk/fly to a filled bird feeder |
| Hunt | AiTaskHuntBird | Predatory bird hunting smaller species |
Writing a custom AI task
AI tasks in VS extend AiTaskBase. See the VS modding wiki and vsessentialsmod source for examples.
csharp
public class AiTaskMyBehavior : AiTaskBase
{
public AiTaskMyBehavior(EntityAgent entity) : base(entity) { }
public override bool ShouldExecute() { /* when to activate */ }
public override void StartExecute() { /* on activation */ }
public override bool ContinueExecute(float dt) { /* return false to end */ }
}Register it in AssetsFinalize() so it's available for entity JSON:
csharp
api.RegisterEntityBehaviorClass("mymod:mybehavior", typeof(MyEntityBehavior));