ai_error.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef AI_ERROR_HPP
00013 #define AI_ERROR_HPP
00014
00015 #include "ai_object.hpp"
00016 #include <map>
00017
00023 #define EnforcePrecondition(returnval, condition) \
00024 if (!(condition)) { \
00025 AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED); \
00026 return returnval; \
00027 }
00028
00035 #define EnforcePreconditionCustomError(returnval, condition, error_code) \
00036 if (!(condition)) { \
00037 AIObject::SetLastError(error_code); \
00038 return returnval; \
00039 }
00040
00044 class AIError : public AIObject {
00045 public:
00046 static const char *GetClassName() { return "AIError"; }
00047
00051 enum ErrorCategories {
00052 ERR_CAT_NONE = 0,
00053 ERR_CAT_GENERAL,
00054 ERR_CAT_VEHICLE,
00055 ERR_CAT_STATION,
00056 ERR_CAT_BRIDGE,
00057 ERR_CAT_TUNNEL,
00058 ERR_CAT_TILE,
00059 ERR_CAT_SIGN,
00060 ERR_CAT_RAIL,
00061 ERR_CAT_ROAD,
00062 ERR_CAT_ORDER,
00063 ERR_CAT_MARINE,
00064
00069 ERR_CAT_BIT_SIZE = 8,
00070 };
00071
00075 enum ErrorMessages {
00077 ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE,
00079 ERR_UNKNOWN,
00081 ERR_PRECONDITION_FAILED,
00083 ERR_PRECONDITION_STRING_TOO_LONG,
00085 ERR_NEWGRF_SUPPLIED_ERROR,
00086
00088 ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE,
00089
00091 ERR_NOT_ENOUGH_CASH,
00092
00094 ERR_LOCAL_AUTHORITY_REFUSES,
00095
00097 ERR_ALREADY_BUILT,
00098
00100 ERR_AREA_NOT_CLEAR,
00101
00103 ERR_OWNED_BY_ANOTHER_COMPANY,
00104
00106 ERR_NAME_IS_NOT_UNIQUE,
00107
00109 ERR_FLAT_LAND_REQUIRED,
00110
00112 ERR_LAND_SLOPED_WRONG,
00113
00115 ERR_VEHICLE_IN_THE_WAY,
00116
00118 ERR_SITE_UNSUITABLE,
00119
00121 ERR_TOO_CLOSE_TO_EDGE,
00122
00124 ERR_STATION_TOO_SPREAD_OUT,
00125 };
00126
00132 static ErrorCategories GetErrorCategory();
00133
00138 static AIErrorType GetLastError();
00139
00144 static char *GetLastErrorString();
00145
00146 #ifndef EXPORT_SKIP
00147
00153 static AIErrorType StringToError(StringID internal_string_id);
00154
00161 static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg);
00162
00169 static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
00170 #endif
00171
00172 private:
00173 typedef std::map<StringID, AIErrorType> AIErrorMap;
00174 typedef std::map<AIErrorType, const char *> AIErrorMapString;
00175
00176 static AIErrorMap error_map;
00177 static AIErrorMapString error_map_string;
00178 };
00179
00180 #endif