Public Types | Static Public Member Functions | Private Types | Static Private Attributes

ScriptError Class Reference

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

#include <script_error.hpp>

Inheritance diagram for ScriptError:
ScriptObject SimpleCountedObject

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_WAYPOINT, 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_PRECONDITION_INVALID_COMPANY, 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 ErrorCategories GetErrorCategory ()
 Check the membership of the last thrown error.
static ScriptErrorType GetLastError ()
 Get the last error.
static char * GetLastErrorString ()
 Get the last error in string format (for human readability).
static ScriptErrorType StringToError (StringID internal_string_id)
 Get the error based on the OpenTTD StringID.
static void RegisterErrorMap (StringID internal_string_id, ScriptErrorType ai_error_msg)
 Map an internal OpenTTD error message to its NoAI equivalent.
static void RegisterErrorMapString (ScriptErrorType ai_error_msg, const char *message)
 Map an internal OpenTTD error message to its NoAI equivalent.

Private Types

typedef std::map< StringID,
ScriptErrorType
ScriptErrorMap
 The type for mapping between error (internal OpenTTD) StringID to the AI error type.
typedef std::map
< ScriptErrorType, const char * > 
ScriptErrorMapString
 The type for mapping between error type and textual representation.

Static Private Attributes

static ScriptErrorMap error_map = ScriptError::ScriptErrorMap()
 The mapping between error (internal OpenTTD) StringID to the AI error type.
static ScriptErrorMapString error_map_string = ScriptError::ScriptErrorMapString()
 The mapping between error type and textual representation.

Detailed Description

Class that handles all error related functions.

ai game

Definition at line 45 of file script_error.hpp.


Member Enumeration Documentation

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_WAYPOINT 

Error messages related to building / maintaining waypoints.

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 50 of file script_error.hpp.

All general related error messages.

Enumerator:
ERR_NONE 

Initial error value.

ERR_UNKNOWN 

If an error occurred 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_PRECONDITION_INVALID_COMPANY 

The company you use is invalid.

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 75 of file script_error.hpp.


Member Function Documentation

ScriptError::ErrorCategories ScriptError::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 65 of file script_error.cpp.

References ERR_CAT_BIT_SIZE, and GetLastError().

ScriptErrorType ScriptError::GetLastError (  )  [static]

Get the last error.

Returns:
An ErrorMessages enum value.

Reimplemented from ScriptObject.

Definition at line 19 of file script_error.cpp.

Referenced by GetErrorCategory(), and GetLastErrorString().

char * ScriptError::GetLastErrorString (  )  [static]

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

Returns:
An ErrorMessage enum item, as string.

Definition at line 24 of file script_error.cpp.

References error_map_string, and GetLastError().

void ScriptError::RegisterErrorMap ( StringID  internal_string_id,
ScriptErrorType  ai_error_msg 
) [static]

Map an internal OpenTTD error message to its NoAI equivalent.

-all

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

Definition at line 55 of file script_error.cpp.

References error_map.

void ScriptError::RegisterErrorMapString ( ScriptErrorType  ai_error_msg,
const char *  message 
) [static]

Map an internal OpenTTD error message to its NoAI equivalent.

-all

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

Definition at line 60 of file script_error.cpp.

References error_map_string.

ScriptErrorType ScriptError::StringToError ( StringID  internal_string_id  )  [static]

Get the error based on the OpenTTD StringID.

-all

Parameters:
internal_string_id The string to convert.
Returns:
The NoAI equivalent error message.

Definition at line 29 of file script_error.cpp.

References ERR_UNKNOWN, error_map, and GB().

Referenced by ScriptObject::DoCommand(), and ScriptInstance::DoCommandCallback().


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