We are making game using Entity Systems. And we with my colleague have different opinions about what approach is better when doing AI.
Basically, he thinks that everything should be a system, where I'm not.
That is his way:
Systems:
- Sensor System (look for a target)
- Pathfinding System (find a path to a target which will be colliding between agents with high probability)
- Attack System (attack target if in attack range)
- Movement System (advance path to target, resolve colliding if can't advance)
There is my proposal:
Systems:
- Attack System (find a target with hp > 0, write to Target component and attack if in range)
- Movement System (find a path to target (if there isnt already) and advance)
Utility classes:
- Sensor
- Pathfinding
There is problem with first approach. For example, 10 units all choosed one target and attacked it (simly because it was closer). But in reality 3 units are sufficient to kill that target in an instant. So, why other 7 should attack this target too? When they choosed their target they doesn't known yet that 3 unit would suffice. They know now that target hp <= 0 but they can't choose another, because Sensor System finished his work already. If we want to fix it then problem will be in unreasonable complexity of Sensor system. Where in latter approach we simply wouldn't select target if hp already <= 0.
Similarly, in first approach pathfinding will find paths which are colliding between them. When one unit taken grid cell another can't take it. That means he must forget his path. But he can't build a new, because Pathfinding system already finished his work. So, he advances one cell in direction of target. In latter approach, we will build path in respect to new positions of units.
Maybe there are another problems in both approaches which we couldn't foresee. So, please say something if you know.
Which way are better (both clear code and good AI)? Maybe both are wrong then please advice what is right way to make it.