diff --git a/doc/README.AI_modules b/doc/README.AI_modules index d1d90b18b8..0db9f44c57 100644 --- a/doc/README.AI_modules +++ b/doc/README.AI_modules @@ -157,3 +157,68 @@ New in Freeciv 2.6: - Added want_to_explore, called for AI type of the unit owner, when it is about to autoexplore - Added currently unused 'reserved' pointers that we can populate with optional callbacks without need to change the mandatory capability of the modules + +7. AI callbacks on startup +----------------------------------- + +In a new game +------------- + +- server_state() is S_S_INITIAL +- gained_control() +- map_alloc() +- the map is created +- map_ready() +- server_state() is set to S_S_RUNNING +- tile_info() for each visible tile +- initial units and cities (if any) are created +- unit_created(), unit_got() are called for each starting unit +- city_created(), city_got() are called for each starting city (if any) +- game_start() + + + +When a savegame is being loaded +------------------------------- + +The game loading sequence is: + +- server_state() is S_S_INITIAL +- map_alloc() +- map loaded +- players loaded, calling player_load(), player_load_relations() +- gained_control() (during load of AI-controlled player) +- cities and units loaded, calling city_load() and unit_load() +- unit_created(), unit_got() for all units +- city_created(), city_got() for all cities +- map_ready() +- server_state() goes to S_S_RUNNING + +Note that gained_control(), player_load(), player_load_relations(), +city_load() and unit_load() are called while the savefile is being +loaded - they allow the AI module to gather extra information from the +savefile, but the game is not yet in a consistent state (i.e. cities +and units are not all loaded) + +When a player is switched to AI or to away mode during game +----------------------------------------------------------- + +- server_state() is S_S_RUNNING +- gained_control() +- restart_phase() + +Note that at present, AI gets calls for game events for each player +that has its ai_type, whether or not the PLRF_AI flag is actually set +for that player. So while a game is going on with human players, the +AI is still getting called. + +This may change at some point in the future. So it is better if, in +gained_control(), the AI initialises whatever information it needs to +track based on the current game state, rather than relying on having +it already. + +When a player is switched to AI or to away mode before game +----------------------------------------------------------- + +- server_state() is S_S_INITIAL +- gained_control()