AI Directives - Hirato/lamiae GitHub Wiki

This article is about controlling the AI. For more general RPG-subsystem stuff, see Scripting.

Note that this subsystem is woefully unfinished and unpolished and may be deprecated in the future

Basic Anatomy of a Directive

enum
{
	AI_MOVE = 1,
	AI_ALERT = 2,
	AI_ATTACK = 4,
	AI_ANIM = 8
};

struct directive
{
	int priority;
	...
	virtual bool match(directive *)=0;
	virtual bool update(rpgchar *d)=0;
};

Directives are basically sorted by priority, those with the highest and most critical priority are executed first.

If the directive can bring the AI into action, it marks off all applicable aiflags. If not, the directive is executed as best it can. Directives remain until they are finalised.

Adding a directive with matching parameters (eg, two attack directives on the same target) will update existing directive's details, such as where the AI thinks the target lurks and the priority.

For example, if the directive wanted the AI to move to (x, y, z), it will see if AI_MOVE has been flagged if true. If not it will mark the flag and set the destination to (x, y, z).

If I then added an attack directive with a lower priority for an entity at position (w, t, s), it would try to move to (w, t, s), but fail as another directive already flagged AI_MOVE as true. Instead it will flag AL_ALERT and AI_ATTACK as on with its focus on the target entity, if these flags are available. So it will watch the target like a hawk and strike whenever it's in range.

With a ranged weapon this means the AI will move towards (x, y, z) whilst taking potshots at the target.

Entities

See Entities for a full guide on the available entity types.

location:
	attr1: Tag
	attr2: Radius

The location entity is used to mark locations for certain directives. Including ones lines move, or wander.

Directives

Only a small subset of directives have been implemented and their implementations are basic at best. More directives and variants will emerge as they mature.

Animation

Attack

Move

Wander