So, I already sort of expected this problem when I asked another question (how can I link to other threads?), now it has actually come up. It seems my implementation of squads doesn't allow for good coordination of orders (actions).
Right now my implementation of squads is that all units are automatically created with their own squad. So Initially each unit has its own one-unit-squad which can then be merged with other squads. Single units can also be removed from squads which puts them in a new squad of their own again.
Units/Objects are held in lists that the "game loop acts on", but there is no list of all squads, those are only accessible through units.
The behavior of the units is given by action objects that are passed to the action_manager of the class.
entity->getActionManager()->addAction(new move_action(coordinates(x,y)));
The actions step functions are then called by the units step function...
At the moment im working on a "flock" of small spacecraft. They have a "idle_move" action that makes them just move around slowly at their momentary position. Now I wanted to implement a flock_move action but am unable to simultaneously "terminate" the orders of the whole squad when the action is completed. The problem is, I am not issuing one movement command to the whole squad, I just give the identical order to every member of the squad. But those actions are basically independent of each other, which makes them hard to coordinate.
Now im not sure how to solve that problem? I could just stick with my version and try to find a condition that can be evaluated by every squad member and gives the same result. Or I could add some sort of communication system between the actions.
Another possibility would be to move the action management up to the squad object and have a step function of the squad iterate through it's members. The problem there is, that there is no obvious way to iterate through the squads. So maybe the actions should exist only on the level of the squad object, but be called from the individual unit? like in:
void Entity::step()
{
squad->execute_actions(this);
}
Did I miss some clever way to do this or is my squad/action system just a bad idea in general? should I implement squads different?