~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/ai/api/ai_error.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ai_error.cpp 15299 2009-01-31 20:16:06Z smatz $ */
 
2
 
 
3
/** @file ai_error.cpp Implementation of AIError. */
 
4
 
 
5
#include "ai_error.hpp"
 
6
#include "../../core/bitmath_func.hpp"
 
7
 
 
8
AIError::AIErrorMap AIError::error_map = AIError::AIErrorMap();
 
9
AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString();
 
10
 
 
11
/* static */ AIErrorType AIError::GetLastError()
 
12
{
 
13
        return AIObject::GetLastError();
 
14
}
 
15
 
 
16
/* static */ char *AIError::GetLastErrorString()
 
17
{
 
18
        return strdup((*error_map_string.find(AIError::GetLastError())).second);
 
19
}
 
20
 
 
21
/* static */ AIErrorType AIError::StringToError(StringID internal_string_id)
 
22
{
 
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;
 
27
 
 
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. */
 
36
                        return ERR_UNKNOWN;
 
37
 
 
38
                default:
 
39
                        break;
 
40
        }
 
41
 
 
42
        AIErrorMap::iterator it = error_map.find(internal_string_id);
 
43
        if (it == error_map.end()) return ERR_UNKNOWN;
 
44
        return (*it).second;
 
45
}
 
46
 
 
47
/* static */ void AIError::RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg)
 
48
{
 
49
        error_map[internal_string_id] = ai_error_msg;
 
50
}
 
51
 
 
52
/* static */ void AIError::RegisterErrorMapString(AIErrorType ai_error_msg, const char *message)
 
53
{
 
54
        error_map_string[ai_error_msg] = message;
 
55
}
 
56
 
 
57
/* static */ AIError::ErrorCategories AIError::GetErrorCategory() {
 
58
        return (AIError::ErrorCategories)(GetLastError() >> (uint)ERR_CAT_BIT_SIZE);
 
59
}