1
/* $Id: ai_error.cpp 15299 2009-01-31 20:16:06Z smatz $ */
3
/** @file ai_error.cpp Implementation of AIError. */
5
#include "ai_error.hpp"
6
#include "../../core/bitmath_func.hpp"
8
AIError::AIErrorMap AIError::error_map = AIError::AIErrorMap();
9
AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString();
11
/* static */ AIErrorType AIError::GetLastError()
13
return AIObject::GetLastError();
16
/* static */ char *AIError::GetLastErrorString()
18
return strdup((*error_map_string.find(AIError::GetLastError())).second);
21
/* static */ AIErrorType AIError::StringToError(StringID internal_string_id)
23
uint index = GB(internal_string_id, 11, 5);
24
switch (GB(internal_string_id, 11, 5)) {
25
case 26: case 28: case 29: case 30: // NewGRF strings.
26
return ERR_NEWGRF_SUPPLIED_ERROR;
28
/* DO NOT SWAP case 14 and 4 because that will break StringToError due
29
* to the index dependency that relies on FALL THROUGHs. */
30
case 14: if (index < 0xE4) break; // Player name
31
case 4: if (index < 0xC0) break; // Town name
32
case 15: // Custom name
33
case 31: // Dynamic strings
34
/* These strings are 'random' and have no meaning.
35
* They actually shouldn't even be returned as error messages. */
42
AIErrorMap::iterator it = error_map.find(internal_string_id);
43
if (it == error_map.end()) return ERR_UNKNOWN;
47
/* static */ void AIError::RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg)
49
error_map[internal_string_id] = ai_error_msg;
52
/* static */ void AIError::RegisterErrorMapString(AIErrorType ai_error_msg, const char *message)
54
error_map_string[ai_error_msg] = message;
57
/* static */ AIError::ErrorCategories AIError::GetErrorCategory() {
58
return (AIError::ErrorCategories)(GetLastError() >> (uint)ERR_CAT_BIT_SIZE);