Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef SCRIPT_ERROR_HPP
00013 #define SCRIPT_ERROR_HPP
00014
00015 #include "script_object.hpp"
00016 #include <map>
00017
00023 #define EnforcePrecondition(returnval, condition) \
00024 if (!(condition)) { \
00025 ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_FAILED); \
00026 return returnval; \
00027 }
00028
00035 #define EnforcePreconditionCustomError(returnval, condition, error_code) \
00036 if (!(condition)) { \
00037 ScriptObject::SetLastError(error_code); \
00038 return returnval; \
00039 }
00040
00045 class ScriptError : public ScriptObject {
00046 public:
00050 enum ErrorCategories {
00051 ERR_CAT_NONE = 0,
00052 ERR_CAT_GENERAL,
00053 ERR_CAT_VEHICLE,
00054 ERR_CAT_STATION,
00055 ERR_CAT_BRIDGE,
00056 ERR_CAT_TUNNEL,
00057 ERR_CAT_TILE,
00058 ERR_CAT_SIGN,
00059 ERR_CAT_RAIL,
00060 ERR_CAT_ROAD,
00061 ERR_CAT_ORDER,
00062 ERR_CAT_MARINE,
00063 ERR_CAT_WAYPOINT,
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 ScriptErrorType GetLastError();
00139
00144 static char *GetLastErrorString();
00145
00152 static ScriptErrorType StringToError(StringID internal_string_id);
00153
00160 static void RegisterErrorMap(StringID internal_string_id, ScriptErrorType ai_error_msg);
00161
00168 static void RegisterErrorMapString(ScriptErrorType ai_error_msg, const char *message);
00169
00170 private:
00171 typedef std::map<StringID, ScriptErrorType> ScriptErrorMap;
00172 typedef std::map<ScriptErrorType, const char *> ScriptErrorMapString;
00173
00174 static ScriptErrorMap error_map;
00175 static ScriptErrorMapString error_map_string;
00176 };
00177
00178 #endif