AI Class Reference

Main AI class. More...

#include <ai.hpp>

Public Types

enum  StartNext {
  START_NEXT_EASY = DAYS_IN_YEAR * 2, START_NEXT_MEDIUM = DAYS_IN_YEAR, START_NEXT_HARD = DAYS_IN_YEAR / 2, START_NEXT_MIN = 1,
  START_NEXT_MAX = 3600, START_NEXT_DEVIATION = 60
}
 

The default months AIs start after eachother.


Static Public Member Functions

static bool CanStartNew ()
 Is it possible to start a new AI company?
static void StartNew (CompanyID company, bool rerandomise_ai=true)
 Start a new AI company.
static void GameLoop ()
 Called every game-tick to let AIs do something.
static uint GetTick ()
 Get the current AI tick.
static void Stop (CompanyID company)
 Stop a company to be controlled by an AI.
static void Suspend (CompanyID company)
 Suspend an AI for the reminder of the current tick.
static void KillAll ()
 Kill any and all AIs we manage.
static void Initialize ()
 Initialize the AI system.
static void Uninitialize (bool keepConfig)
 Uninitialize the AI system.
static void ResetConfig ()
 Reset all AIConfigs, and make them reload their AIInfo.
static void NewEvent (CompanyID company, AIEvent *event)
 Queue a new event for an AI.
static void BroadcastNewEvent (AIEvent *event, CompanyID skip_company=MAX_COMPANIES)
 Broadcast a new event to all active AIs.
static void Save (CompanyID company)
 Save data from an AI to a savegame.
static void Load (CompanyID company, int version)
 Load data for an AI from a savegame.
static int GetStartNextTime ()
 Get the number of days before the next AI should start.
static char * GetConsoleList (char *p, const char *last, bool newest_only=false)
 Wrapper function for AIScanner::GetAIConsoleList.
static char * GetConsoleLibraryList (char *p, const char *last)
 Wrapper function for AIScanner::GetAIConsoleLibraryList.
static const AIInfoListGetInfoList ()
 Wrapper function for AIScanner::GetAIInfoList.
static const AIInfoListGetUniqueInfoList ()
 Wrapper function for AIScanner::GetUniqueAIInfoList.
static AIInfoFindInfo (const char *name, int version, bool force_exact_match)
 Wrapper function for AIScanner::FindInfo.
static bool ImportLibrary (const char *library, const char *class_name, int version, HSQUIRRELVM vm)
 Wrapper function for AIScanner::ImportLibrary.
static void Rescan ()
 Rescans all searchpaths for available AIs.
static bool HasAI (const struct ContentInfo *ci, bool md5sum)
 Wrapper function for AIScanner::HasAI.

Static Private Attributes

static uint frame_counter = 0
 Tick counter for the AI code.
static class AIScannerai_scanner = NULL
 AIScanner instance that is used to find AIs.

Detailed Description

Main AI class.

Contains all functions needed to start, stop, save and load AIs.

Definition at line 27 of file ai.hpp.


Member Function Documentation

bool AI::CanStartNew (  )  [static]

Is it possible to start a new AI company?

Returns:
True if a new AI company can be started.

Definition at line 28 of file ai_core.cpp.

References _network_server, _networking, _settings_game, GameSettings::ai, and AISettings::ai_in_multiplayer.

void AI::Rescan (  )  [static]

Rescans all searchpaths for available AIs.

If a used AI is no longer found it is removed from the config.

Definition at line 322 of file ai_core.cpp.

References AIScanner::RescanAIDir(), and ResetConfig().

Referenced by Uninitialize(), and NetworkContentDownloadStatusWindow::~NetworkContentDownloadStatusWindow().

void AI::ResetConfig (  )  [static]

Reset all AIConfigs, and make them reload their AIInfo.

If the AIInfo could no longer be found, an error is reported to the user.

Definition at line 166 of file ai_core.cpp.

References _settings_game, _settings_newgame, GameSettings::ai_config, AIConfig::ChangeAI(), COMPANY_FIRST, DEBUG, AIConfig::GetName(), AIConfig::HasAI(), MAX_COMPANIES, and AIConfig::ResetInfo().

Referenced by Rescan().

void AI::StartNew ( CompanyID  company,
bool  rerandomise_ai = true 
) [static]
void AI::Stop ( CompanyID  company  )  [static]

Stop a company to be controlled by an AI.

Parameters:
company The company from which the AI needs to detach.
Precondition:
Company::IsValidAiID(company)

Definition at line 96 of file ai_core.cpp.

References _current_company, _network_server, _networking, DeleteWindowById(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), InvalidateWindowData(), and Backup< T >::Restore().

Referenced by CmdCompanyCtrl(), and KillAll().

void AI::Suspend ( CompanyID  company  )  [static]

Suspend an AI for the reminder of the current tick.

If the AI is in a state when it cannot be suspended, it will continue to run until it can be suspended.

Parameters:
company The company for which the AI should be suspended.
Precondition:
Company::IsValidAiID(company)

Definition at line 112 of file ai_core.cpp.

References _current_company, _network_server, _networking, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), and Backup< T >::Restore().

Referenced by AIDebugWindow::OnInvalidateData().

void AI::Uninitialize ( bool  keepConfig  )  [static]

Uninitialize the AI system.

Parameters:
keepConfig Should we keep AIConfigs, or can we free that memory?

Definition at line 141 of file ai_core.cpp.

References _settings_game, _settings_newgame, GameSettings::ai_config, COMPANY_FIRST, KillAll(), MAX_COMPANIES, and Rescan().

Referenced by Initialize(), ShowHelp(), and ShutdownGame().


The documentation for this class was generated from the following files:

Generated on Thu Apr 14 00:48:52 2011 for OpenTTD by  doxygen 1.6.1