# AIError Class Reference

Class that handles all error related functions. More...

`#include <ai_error.hpp>`

Inheritance diagram for AIError:

## Public Types

enum | ErrorCategories { ERR_CAT_NONE = 0, ERR_CAT_GENERAL, ERR_CAT_VEHICLE, ERR_CAT_STATION, ERR_CAT_BRIDGE, ERR_CAT_TUNNEL, ERR_CAT_TILE, ERR_CAT_SIGN, ERR_CAT_RAIL, ERR_CAT_ROAD, ERR_CAT_ORDER, ERR_CAT_MARINE, ERR_CAT_BIT_SIZE = 8 }
| All categories errors can be divided in. More...

enum

ErrorMessages {
ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE, ERR_UNKNOWN, ERR_PRECONDITION_FAILED, ERR_PRECONDITION_STRING_TOO_LONG,
ERR_NEWGRF_SUPPLIED_ERROR, ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE, ERR_NOT_ENOUGH_CASH, ERR_LOCAL_AUTHORITY_REFUSES,
ERR_ALREADY_BUILT, ERR_AREA_NOT_CLEAR, ERR_OWNED_BY_ANOTHER_COMPANY, ERR_NAME_IS_NOT_UNIQUE,
ERR_FLAT_LAND_REQUIRED, ERR_LAND_SLOPED_WRONG, ERR_VEHICLE_IN_THE_WAY, ERR_SITE_UNSUITABLE,
ERR_TOO_CLOSE_TO_EDGE, ERR_STATION_TOO_SPREAD_OUT
}

| All general related error messages. More...

## Static Public Member Functions

static const char * | GetClassName ()
static ErrorCategories | GetErrorCategory ()
| Check the membership of the last thrown error.
static AIErrorType | GetLastError ()
| Get the last error.
static char * | GetLastErrorString ()
| Get the last error in string format (for human readability).
static AIErrorType | StringToError (StringID internal_string_id)
| Get the error based on the OpenTTD StringID.
static void | RegisterErrorMap (StringID internal_string_id, AIErrorType ai_error_msg)
| Map an internal OpenTTD error message to it's NoAI equivalent.
static void | RegisterErrorMapString (AIErrorType ai_error_msg, const char *message)
| Map an internal OpenTTD error message to it's NoAI equivalent.

## Private Types

typedef std::map< StringID, AIErrorType > | AIErrorMap
typedef std::map< AIErrorType, const char * > | AIErrorMapString

## Static Private Attributes

static AIErrorMap | error_map = AIError::AIErrorMap()
static AIErrorMapString | error_map_string = AIError::AIErrorMapString()

## Detailed Description

Class that handles all error related functions.

Definition at line 37 of file ai_error.hpp.

## Member Enumeration Documentation

enum AIError::ErrorCategories

All categories errors can be divided in.

Enumerator:

  ERR_CAT_NONE | Error messages not related to any category.
  ERR_CAT_GENERAL | Error messages related to general things.
  ERR_CAT_VEHICLE | Error messages related to building / maintaining vehicles.
  ERR_CAT_STATION | Error messages related to building / maintaining stations.
  ERR_CAT_BRIDGE | Error messages related to building / removing bridges.
  ERR_CAT_TUNNEL | Error messages related to building / removing tunnels.
  ERR_CAT_TILE | Error messages related to raising / lowering and demolishing tiles.
  ERR_CAT_SIGN | Error messages related to building / removing signs.
  ERR_CAT_RAIL | Error messages related to building / maintaining rails.
  ERR_CAT_ROAD | Error messages related to building / maintaining roads.
  ERR_CAT_ORDER | Error messages related to managing orders.
  ERR_CAT_MARINE | Error messages related to building / removing ships, docks and channels.
  ERR_CAT_BIT_SIZE | DO NOT USE! The error bitsize determines how many errors can be stored in a category and what the offsets are of all categories.

Definition at line 44 of file ai_error.hpp.

enum AIError::ErrorMessages

All general related error messages.

Enumerator:

  ERR_NONE | Initial error value.
  ERR_UNKNOWN | If an error occured and the error wasn't mapped.
  ERR_PRECONDITION_FAILED | If a precondition is not met.
  ERR_PRECONDITION_STRING_TOO_LONG | A string supplied was too long.
  ERR_NEWGRF_SUPPLIED_ERROR | An error returned by a NewGRF. No possibility to get the exact error in an AI readable format
  ERR_GENERAL_BASE | Base for general errors.
  ERR_NOT_ENOUGH_CASH | Not enough cash to perform the previous action.
  ERR_LOCAL_AUTHORITY_REFUSES | Local authority won't allow the previous action.
  ERR_ALREADY_BUILT | The piece of infrastructure you tried to build is already in place.
  ERR_AREA_NOT_CLEAR | Area isn't clear, try to demolish the building on it.
  ERR_OWNED_BY_ANOTHER_COMPANY | Area / property is owned by another company.
  ERR_NAME_IS_NOT_UNIQUE | The name given is not unique for the object type.
  ERR_FLAT_LAND_REQUIRED | The building you want to build requires flat land.
  ERR_LAND_SLOPED_WRONG | Land is sloped in the wrong direction for this build action.
  ERR_VEHICLE_IN_THE_WAY | A vehicle is in the way.
  ERR_SITE_UNSUITABLE | Site is unsuitable.
  ERR_TOO_CLOSE_TO_EDGE | Too close to the edge of the map.
  ERR_STATION_TOO_SPREAD_OUT | Station is too spread out.

Definition at line 68 of file ai_error.hpp.

## Member Function Documentation

AIError::ErrorCategories AIError::GetErrorCategory | ( |  | ) | `[static]`

Check the membership of the last thrown error.

Returns:
  The category the error belongs to.

Note:
  The last throw error can be aquired by calling GetLastError().

Definition at line 57 of file ai_error.cpp.

References ERR_CAT_BIT_SIZE, and GetLastError().

AIErrorType AIError::GetLastError | ( |  | ) | `[static]`

Get the last error.

Returns:
  An ErrorMessages enum value.

Reimplemented from AIObject.

Definition at line 11 of file ai_error.cpp.

References AIObject::GetLastError().

Referenced by GetErrorCategory(), and GetLastErrorString().

char * AIError::GetLastErrorString | ( |  | ) | `[static]`

Get the last error in string format (for human readability).

Returns:
  An ErrorMessage enum item, as string.

Definition at line 16 of file ai_error.cpp.

References GetLastError().

AIErrorType AIError::StringToError | ( | StringID | internal_string_id | ) | `[static]`

Get the error based on the OpenTTD StringID.

Note:
  DO NOT INVOKE THIS METHOD YOURSELF!

Parameters:

  | internal_string_id | The string to convert.

Returns:
  The NoAI equivalent error message.

Definition at line 21 of file ai_error.cpp.

References ERR_NEWGRF_SUPPLIED_ERROR, ERR_UNKNOWN, and GB().

Referenced by AIObject::DoCommand().

void AIError::RegisterErrorMap | ( | StringID | internal_string_id,
|  | AIErrorType | ai_error_msg |
| ) |  |  | `[static]`

Map an internal OpenTTD error message to it's NoAI equivalent.

Note:
  DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated.

Parameters:

  | internal_string_id | The OpenTTD StringID used for an error.
  | ai_error_msg | The NoAI equivalent error message.

Definition at line 47 of file ai_error.cpp.

void AIError::RegisterErrorMapString | ( | AIErrorType | ai_error_msg,
|  | const char * | message |
| ) |  |  | `[static]`

Map an internal OpenTTD error message to it's NoAI equivalent.

Note:
  DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated.

Parameters:

  | ai_error_msg | The NoAI error message representation.
  | message | The string representation of this error message, used for debug purposes.

Definition at line 52 of file ai_error.cpp.

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

- src/ai/api/ai_error.hpp
- src/ai/api/ai_error.cpp