src/ai/api/ai_error.hpp
author rubidium
Thu, 03 Apr 2008 22:32:28 +0000
branchnoai
changeset 9864 4a9b7b610b13
parent 9863 73647fe2e301
child 9865 f241472f09dc
permissions -rw-r--r--
(svn r12554) [NoAI] -Codechange: add more typing information.
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 {
9861
53fc03195e31 (svn r12544) [NoAI] -Codechange: do not force dependency on OTTD internal strings when defining errors.
rubidium
parents: 9844
diff changeset
    37
		/** Initial error value */
53fc03195e31 (svn r12544) [NoAI] -Codechange: do not force dependency on OTTD internal strings when defining errors.
rubidium
parents: 9844
diff changeset
    38
		ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE,  // []
53fc03195e31 (svn r12544) [NoAI] -Codechange: do not force dependency on OTTD internal strings when defining errors.
rubidium
parents: 9844
diff changeset
    39
		/** If an error occured and the error wasn't mapped */
53fc03195e31 (svn r12544) [NoAI] -Codechange: do not force dependency on OTTD internal strings when defining errors.
rubidium
parents: 9844
diff changeset
    40
		ERR_UNKNOWN,                                  // []
9863
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    41
		/** If a precondition is not met */
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    42
		ERR_PRECONDITION_FAILED,                      // []
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    43
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    44
		/** 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
    45
		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
    46
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    47
		/** 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
    48
		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
    49
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    50
		/** 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
    51
		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
    52
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    53
		/** 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
    54
		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
    55
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    56
		/** 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
    57
		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
    58
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    59
		/** 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
    60
		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
    61
	};
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    62
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
	 * 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
    65
	 * @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
    66
	 * @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
    67
	 */
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    68
	static ErrorCategories GetErrorCategory();
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
	/**
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    71
	 * 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
    72
	 * @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
    73
	 */
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
    74
	static AIErrorType GetLastError();
9844
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
	/**
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    77
	 * 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
    78
	 * @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
    79
	 */
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    80
	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
    81
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    82
	/**
9863
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    83
	 * Get the error based on the OpenTTD StringID.
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    84
	 * @note DO NOT INVOKE THIS METHOD YOURSELF!
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    85
	 * @param internal_string_id The string to convert.
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    86
	 * @return The NoAI equivalent error message.
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    87
	 */
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
    88
	static AIErrorType StringToError(StringID internal_string_id);
9863
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    89
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9861
diff changeset
    90
	/**
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    91
	 * 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
    92
	 * @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
    93
	 * @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
    94
	 * @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
    95
	 */
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
    96
	static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg);
9844
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
	/**
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
    99
	 * 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
   100
	 * @note DO NOT INVOKE THIS METHOD YOURSELF! The calls are autogenerated.
9861
53fc03195e31 (svn r12544) [NoAI] -Codechange: do not force dependency on OTTD internal strings when defining errors.
rubidium
parents: 9844
diff changeset
   101
	 * @param ai_error_msg The NoAI error message representation.
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   102
	 * @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
   103
	 */
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
   104
	static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   105
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   106
private:
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
   107
	typedef std::map<StringID, AIErrorType> AIErrorMap;
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
   108
	typedef std::map<AIErrorType, const char *> AIErrorMapString;
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   109
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   110
	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
   111
	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
   112
};
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   113
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents:
diff changeset
   114
#endif /* AI_ERROR_HPP */