truebrain@9844: /* $Id$ */ truebrain@9844: truebrain@9844: /** @file ai_error.hpp Everything to query errors. */ truebrain@9844: truebrain@9844: #ifndef AI_ERROR_HPP truebrain@9844: #define AI_ERROR_HPP truebrain@9844: truebrain@9844: #include "ai_object.hpp" truebrain@9844: #include truebrain@9844: truebrain@9844: /** truebrain@9844: * Class that handles all error related functions. truebrain@9844: */ truebrain@9844: class AIError : public AIObject { truebrain@9844: public: truebrain@9844: static const char *GetClassName() { return "AIError"; } truebrain@9844: truebrain@9844: /** truebrain@9844: * All categories errors can be divided in. truebrain@9844: */ truebrain@9844: enum ErrorCategories { truebrain@9844: ERR_CAT_NONE = 0, //!< Error messages not related to any category. truebrain@9844: ERR_CAT_GENERAL, //!< Error messages related to general things. truebrain@9844: ERR_CAT_VEHICLE, //!< Error messages related to building / maintaining vehicles. truebrain@9844: truebrain@9844: /** truebrain@9844: * DO NOT USE! The error bitsize determines how many errors can be stored in truebrain@9844: * a category and what the offsets are of all categories. truebrain@9844: */ truebrain@9844: ERR_CAT_BIT_SIZE = 8, truebrain@9844: }; truebrain@9844: truebrain@9844: /** truebrain@9844: * General error messages (0x0100 - 0x0200). truebrain@9844: */ truebrain@9844: enum ErrorMessages { rubidium@9861: /** Initial error value */ rubidium@9861: ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE, // [] rubidium@9861: /** If an error occured and the error wasn't mapped */ rubidium@9861: ERR_UNKNOWN, // [] rubidium@9863: /** If a precondition is not met */ rubidium@9863: ERR_PRECONDITION_FAILED, // [] truebrain@9844: truebrain@9844: /** Base for general errors */ truebrain@9844: ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE, truebrain@9844: truebrain@9844: /** Not enough cash to perform the previous action */ truebrain@9844: ERR_NOT_ENOUGH_CASH, // [STR_0003_NOT_ENOUGH_CASH_REQUIRES] truebrain@9844: truebrain@9844: /** Local authority won't allow the previous action */ truebrain@9844: ERR_LOCAL_AUTHORITY_REFUSES, // [STR_2009_LOCAL_AUTHORITY_REFUSES] truebrain@9844: truebrain@9844: /** The piece of infrastructure you tried to build is already in place */ truebrain@9844: ERR_ALREADY_BUILT, // [STR_1007_ALREADY_BUILT] truebrain@9844: truebrain@9844: /** Area isn't clear, try to demolish the building on it */ truebrain@9844: ERR_AREA_NOT_CLEAR, // [STR_2004_BUILDING_MUST_BE_DEMOLISHED] truebrain@9844: truebrain@9844: /** Area is owned by another company */ truebrain@9844: ERR_AREA_IS_OWNED_BY_ANOTHER_COMPANY, // [STR_1024_AREA_IS_OWNED_BY_ANOTHER] truebrain@9844: }; truebrain@9844: truebrain@9844: /** truebrain@9844: * Check the membership of the last thrown error. truebrain@9844: * @return The category the error belongs to. truebrain@9844: * @note The last throw error can be aquired by calling GetLastError(). truebrain@9844: */ truebrain@9844: static ErrorCategories GetErrorCategory(); truebrain@9844: truebrain@9844: /** truebrain@9844: * Get the last error. truebrain@9844: * @return An ErrorMessages enum value. truebrain@9844: */ truebrain@9844: static uint GetLastError(); truebrain@9844: truebrain@9844: /** truebrain@9844: * Get the last error in string format (for human readability). truebrain@9844: * @return An ErrorMessage enum item, as string. truebrain@9844: */ truebrain@9844: static const char *GetLastErrorString(); truebrain@9844: truebrain@9844: /** rubidium@9863: * Get the error based on the OpenTTD StringID. rubidium@9863: * @note DO NOT INVOKE THIS METHOD YOURSELF! rubidium@9863: * @param internal_string_id The string to convert. rubidium@9863: * @return The NoAI equivalent error message. rubidium@9863: */ rubidium@9863: static uint StringToError(uint internal_string_id); rubidium@9863: rubidium@9863: /** truebrain@9844: * Map an internal OpenTTD error message to it's NoAI equivalent. truebrain@9844: * @note DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated. truebrain@9844: * @param internal_string_id The OpenTTD StringID used for an error. truebrain@9844: * @param ai_error_msg The NoAI equivalent error message. truebrain@9844: */ truebrain@9844: static void RegisterErrorMap(uint internal_string_id, uint ai_error_msg); truebrain@9844: truebrain@9844: /** truebrain@9844: * Map an internal OpenTTD error message to it's NoAI equivalent. truebrain@9844: * @note DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated. rubidium@9861: * @param ai_error_msg The NoAI error message representation. truebrain@9844: * @param message The string representation of this error message, used for debug purposes. truebrain@9844: */ rubidium@9861: static void RegisterErrorMapString(uint ai_error_msg, const char *message); truebrain@9844: truebrain@9844: private: truebrain@9844: typedef std::map AIErrorMap; truebrain@9844: typedef std::map AIErrorMapString; truebrain@9844: truebrain@9844: static AIErrorMap error_map; truebrain@9844: static AIErrorMapString error_map_string; truebrain@9844: }; truebrain@9844: truebrain@9844: #endif /* AI_ERROR_HPP */