Entity Query Language
We’ve now merged the work Yaroslav Taben did last summer on a new entity filtering system. For a lack of better name we’re calling it the Entity Query Language.
Why is this needed?
A lot of the AI code in Cyphesis deals with selecting and acting on entities. Consider a “Flee” goal for example. This should be used by weak creatures to flee from dangerous creatures. As soon as a dangerous creature comes within range the creature to which the goal belongs to should turn tail and elope.
But how do we determine what constitutes a “dangerous creature”?
This is where the EQL comes in. As most other query languages it allows you to select a subset of a set of entities, given a number of criteria. The syntax is a bit similar to other query languages such as SQL. For our case we might want to avoid bears. The EQL then becomes
entity.type = types.bear
This would return a positive match for all bears. However, perhaps we only want to avoid those bears that have a mass of at least 50Kg? We’ll add another restriction
entity.type = types.bear && entity.mass >= 50
There are of course other dangerous animals. We also want to avoid wolves. These are more aggressive, so we don’t want to check their mass
(entity.type = types.bear && entity.mass >= 50) || (entity.type = types.wolf)
In this way we can create more and more complex rules for how the AI will interact with the surrounding. The query code is now pushed to Cyphesis master and most existing goals are being converted to start using it.