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