tanis
|
|
« on: December 31, 2015, 12:03:11 AM » |
|
Hello everybody,
I've been struggling trying to design some good API for my AI logic. I'm looking for suggestions.
Here's the setup of my current game:
- Everything is managed by a plain ECS. - My enemies are made up of the following components: Input, Physics, Grid, Health, Inventory, Sprite, AIControl. - Input is the one that passes input data to other components, physics is just holding velocity, grid contains the coordinates on the tile map, health holds data like max health and current health, inventory holds references to entities like weapons, sprite has all the data about the sprites used for animating, AIControl is the actual holder of data like the mental state of the enemy, its action queue, sight range, current walking direction, etc... - My AI system is designed around two main structures: the mental state which is just an enumeration like idle, alerted, panicking, etc... and an action queue that holds a list of actions to perform in order, like wait, move, fire, etc...
This setup is working quite well with a single type of enemy. As an example just think of an enemy that can move on the ground and fire with its weapon. I have added the code to manage the mental states and actions to perform based on the current mental state so that if it's idle and it sees the player, it will turn to face the player, fire, wait for the weapon to recharge, fire again if the player is still in range and so on.
If I add a new kind of enemy, let's say an alien that doesn't fire but can charge at the player to hit it by proximity, the whole AI system needs an overhaul to either handle a new action (charge) or turn the fire action into the actual charge. Either way, I need to check whether the enemy can fire or can charge. I solved this by adding a new component to the alien which is just called Charge and that has no data, it's just an empty component that I use to tell that this kind of enemy can charge.
What I'm wondering about is whether this is a good design in the long run as I might add more and more kind of actions or if there's a better way to handle this kind of logic.
Thanks in advance!
|