|
1 /* $Id$ */ |
|
2 |
|
3 /** @file ai_error.hpp Everything to query errors. */ |
|
4 |
|
5 #ifndef AI_ERROR_HPP |
|
6 #define AI_ERROR_HPP |
|
7 |
|
8 #include "ai_object.hpp" |
|
9 #include <map> |
|
10 |
|
11 /** |
|
12 * Class that handles all error related functions. |
|
13 */ |
|
14 class AIError : public AIObject { |
|
15 public: |
|
16 static const char *GetClassName() { return "AIError"; } |
|
17 |
|
18 /** |
|
19 * All categories errors can be divided in. |
|
20 */ |
|
21 enum ErrorCategories { |
|
22 ERR_CAT_NONE = 0, //!< Error messages not related to any category. |
|
23 ERR_CAT_GENERAL, //!< Error messages related to general things. |
|
24 ERR_CAT_VEHICLE, //!< Error messages related to building / maintaining vehicles. |
|
25 |
|
26 /** |
|
27 * DO NOT USE! The error bitsize determines how many errors can be stored in |
|
28 * a category and what the offsets are of all categories. |
|
29 */ |
|
30 ERR_CAT_BIT_SIZE = 8, |
|
31 }; |
|
32 |
|
33 /** |
|
34 * General error messages (0x0100 - 0x0200). |
|
35 */ |
|
36 enum ErrorMessages { |
|
37 ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE, //!< Initial error value |
|
38 ERR_UNKNOWN, //!< If an error occured and the error wasn't mapped |
|
39 |
|
40 /** Base for general errors */ |
|
41 ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE, |
|
42 |
|
43 /** Not enough cash to perform the previous action */ |
|
44 ERR_NOT_ENOUGH_CASH, // [STR_0003_NOT_ENOUGH_CASH_REQUIRES] |
|
45 |
|
46 /** Local authority won't allow the previous action */ |
|
47 ERR_LOCAL_AUTHORITY_REFUSES, // [STR_2009_LOCAL_AUTHORITY_REFUSES] |
|
48 |
|
49 /** The piece of infrastructure you tried to build is already in place */ |
|
50 ERR_ALREADY_BUILT, // [STR_1007_ALREADY_BUILT] |
|
51 |
|
52 /** Area isn't clear, try to demolish the building on it */ |
|
53 ERR_AREA_NOT_CLEAR, // [STR_2004_BUILDING_MUST_BE_DEMOLISHED] |
|
54 |
|
55 /** Area is owned by another company */ |
|
56 ERR_AREA_IS_OWNED_BY_ANOTHER_COMPANY, // [STR_1024_AREA_IS_OWNED_BY_ANOTHER] |
|
57 }; |
|
58 |
|
59 /** |
|
60 * Check the membership of the last thrown error. |
|
61 * @return The category the error belongs to. |
|
62 * @note The last throw error can be aquired by calling GetLastError(). |
|
63 */ |
|
64 static ErrorCategories GetErrorCategory(); |
|
65 |
|
66 /** |
|
67 * Get the last error. |
|
68 * @return An ErrorMessages enum value. |
|
69 */ |
|
70 static uint GetLastError(); |
|
71 |
|
72 /** |
|
73 * Get the last error in string format (for human readability). |
|
74 * @return An ErrorMessage enum item, as string. |
|
75 */ |
|
76 static const char *GetLastErrorString(); |
|
77 |
|
78 /** |
|
79 * Map an internal OpenTTD error message to it's NoAI equivalent. |
|
80 * @note DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated. |
|
81 * @param internal_string_id The OpenTTD StringID used for an error. |
|
82 * @param ai_error_msg The NoAI equivalent error message. |
|
83 */ |
|
84 static void RegisterErrorMap(uint internal_string_id, uint ai_error_msg); |
|
85 |
|
86 /** |
|
87 * Map an internal OpenTTD error message to it's NoAI equivalent. |
|
88 * @note DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated. |
|
89 * @param internal_string_id The OpenTTD StringID used for an error. |
|
90 * @param message The string representation of this error message, used for debug purposes. |
|
91 */ |
|
92 static void RegisterErrorMapString(uint internal_string_id, const char *message); |
|
93 |
|
94 private: |
|
95 typedef std::map<uint, uint> AIErrorMap; |
|
96 typedef std::map<uint, const char *> AIErrorMapString; |
|
97 |
|
98 static AIErrorMap error_map; |
|
99 static AIErrorMapString error_map_string; |
|
100 }; |
|
101 |
|
102 #endif /* AI_ERROR_HPP */ |