# AIConfig Class Reference

AI settings for one company slot. More...

`#include <ai_config.hpp>`

## Public Types
enum | AISettingSource { AISS_DEFAULT, AISS_FORCE_NEWGAME, AISS_FORCE_GAME }
| Where to get the config from, either default (depends on current game mode) or force either newgame or normal. More...
## Public Member Functions
| AIConfig (const AIConfig *config)
| Create a new AI config that is a copy of an existing config.
| ~AIConfig ()
| Delete an AI configuration.
void | ChangeAI (const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
| Set another AI to be loaded in this slot.
bool | ResetInfo ()
| When ever the AI Scanner is reloaded, all infos become invalid.
class AIInfo * | GetInfo () const
| Get the AIInfo linked to this AIConfig.
const AIConfigItemList * | GetConfigList ()
| Get the config list for this AIConfig.
int | GetSetting (const char *name) const
| Get the value of a setting for this config.
void | SetSetting (const char *name, int value)
| Set the value of a setting for this config.
void | ResetSettings ()
| Reset all settings to their default value.
void | AddRandomDeviation ()
| Randomize all settings the AI requested to be randomized.
bool | HasAI () const
| Is this config attached to an AI?
bool | IsRandomAI () const
| Is the current AI a randomly chosen AI?
const char * | GetName () const
| Get the name of the AI.
int | GetVersion () const
| Get the version of the AI.
void | StringToSettings (const char *value)
| Convert a string which is stored in the config file or savegames to custom settings of this AI.
void | SettingsToString (char *string, size_t size) const
| Convert the custom settings to a string that can be stored in the config file or savegames.
## Static Public Member Functions
static AIConfig * | GetConfig (CompanyID company, AISettingSource source=AISS_DEFAULT)
| Get the config of a company.
## Private Types
typedef std::map< const char *, int, StringCompare > | SettingValueList
| List with name=>value pairs of all AI-specific settings.
## Private Attributes
const char * | name
| Name of the AI.
int | version
| Version of the AI.
class AIInfo * | info
| AIInfo object for related to this AI version.
SettingValueList | settings
| List with all setting=>value pairs that are configure for this AI.
AIConfigItemList * | config_list
| List with all settings defined by this AI.
bool | is_random_ai
| True if the AI in this slot was randomly chosen.

## Detailed Description

AI settings for one company slot.

Definition at line 24 of file ai_config.hpp.

## Member Enumeration Documentation

enum AIConfig::AISettingSource

Where to get the config from, either default (depends on current game mode) or force either newgame or normal.

Enumerator:

  AISS_DEFAULT | Get the AI config from the current game mode.
  AISS_FORCE_NEWGAME | Get the newgame AI config.
  AISS_FORCE_GAME | Get the AI config from the current game.

Definition at line 79 of file ai_config.hpp.

## Constructor & Destructor Documentation

AIConfig::AIConfig | ( | const AIConfig * | config | ) |

Create a new AI config that is a copy of an existing config.

Parameters:

  | config | The object to copy.

Definition at line 52 of file ai_config.cpp.

References AddRandomDeviation(), config_list, info, is_random_ai, name, settings, and version.

AIConfig::~AIConfig | ( |  | ) |

Delete an AI configuration.

Definition at line 66 of file ai_config.cpp.

References config_list, name, and ResetSettings().

## Member Function Documentation

void AIConfig::ChangeAI | ( | const char * | name,
|  | int | version = `-1`,
|  | bool | force_exact_match = `false`,
|  | bool | is_random = `false` |
| ) |  |  |

Set another AI to be loaded in this slot.

Parameters:

  | name | The name of the AI.
  | version | The version of the AI to load, or -1 of latest.
  | force_exact_match | If true try to find the exact same version as specified. If false any compatible version is ok.
  | is_random | Is the AI chosen randomly?

Definition at line 18 of file ai_config.cpp.

References _start_date_config, AddRandomDeviation(), AICONFIG_RANDOM, config_list, AI::FindInfo(), AIInfo::GetConfigList(), GetSetting(), ScriptFileInfo::GetVersion(), info, SetSetting(), and settings.

Referenced by AI::ResetConfig(), and AI::StartNew().

int AIConfig::GetSetting | ( | const char * | name | ) | const

Get the value of a setting for this config.

It might fallback to his 'info' to find the default value (if not set or if not-custom difficulty level).

Returns:
  The (default) value of the setting, or -1 if the setting was not found.

Definition at line 106 of file ai_config.cpp.

References DifficultySettings::diff_level, GameSettings::difficulty, GetGameSettings(), AIInfo::GetSettingDefaultValue(), info, and settings.

Referenced by ChangeAI(), AISettingsWindow::DrawWidget(), AIController::GetSetting(), AI::GetStartNextTime(), and AISettingsWindow::OnClick().

bool AIConfig::ResetInfo | ( |  | ) |

When ever the AI Scanner is reloaded, all infos become invalid.

This function tells AIConfig about this.

Returns:
  `true` if the reset was successful, `false` if the AI was no longer found.

Definition at line 78 of file ai_config.cpp.

References AI::FindInfo(), info, and name.

Referenced by AI::ResetConfig().

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

- src/ai/ai_config.hpp
- src/ai/ai_config.cpp