First I hacked a few lines into the shared code, so AI's could register a callback. Then I stepped deeper into your code and it looks like Aegisbot.savedEvents has all I need. So I started a simple game and watched event tv in dbgView. What I understood is 'Create' is called when training starts, but it lacks the owner. 'TrainingFinished' is more useful and 'Destroy' is nice too. Similar to 'ConstructionFinished'.
What I want to achieve is what I call 'Groups' actually EntityCollections subclassed. Let's say the manager or mayor of a civic centre asks for more food. He launches a Group of 5 females and one field, all do not exist. So the group asks the major for females, once trained they get automatically assigned to the group choosing a place for the field and let them work. That part should work by push not by poll.
It would be simple (one possibility) if postcommand returns the ids of the future entities. All needed then is a dictionary/map with the ids as key and the callback as value. When 'TrainingFinished' comes in I would just dispatch the message via callback and the id to the Group which then takes care. When 'Destroy' comes in the Group asks for a new female and the entry got deleted from the map . Similar with 'Destroy' field.
I understand that is currently not possible, what I'm planning now, not tested, is polling idle entities not registered in a Group, check which Group has asked for these kind of entities and set up the dispatcher accordingly.
That way the mayor only deals with resource allocation and training entities. Groups ensure no idle workers. And on top I believe that system would also work nicely with armies. Another idea is that in easy mode the mayor does not launch e.g. repair groups listening at 'Attack' events.
Does that makes sense?
Btw, two questions: Is there any possibilitiy to communicate with the AI once the game runs? Maybe with chat commands, clicking at hot spots, mouse gestures, konami code, whatever? Just to trigger functions.
I've found the developer overlay, very useful, can an AI also draw shapes on the map, just for debugging? Or how can I use dumpimage? Google is of no help.