# ai_error.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_error.hpp 15481 2009-02-14 20:03:06Z yexo $ */
    00002
    00005 #ifndef AI_ERROR_HPP
    00006 #define AI_ERROR_HPP
    00007
    00008 #include "ai_object.hpp"
    00009 #include <map>
    00010
    00016 #define EnforcePrecondition(returnval, condition)               \
    00017   if (!(condition)) {                                           \
    00018     AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED);   \
    00019     return returnval;                                           \
    00020   }
    00021
    00028 #define EnforcePreconditionCustomError(returnval, condition, error_code)   \
    00029   if (!(condition)) {                                                      \
    00030     AIObject::SetLastError(error_code);                                    \
    00031     return returnval;                                                      \
    00032   }
    00033
    00037 class AIError : public AIObject {
    00038 public:
    00039   static const char *GetClassName() { return "AIError"; }
    00040
    00044   enum ErrorCategories {
    00045     ERR_CAT_NONE = 0,
    00046     ERR_CAT_GENERAL,
    00047     ERR_CAT_VEHICLE,
    00048     ERR_CAT_STATION,
    00049     ERR_CAT_BRIDGE,
    00050     ERR_CAT_TUNNEL,
    00051     ERR_CAT_TILE,
    00052     ERR_CAT_SIGN,
    00053     ERR_CAT_RAIL,
    00054     ERR_CAT_ROAD,
    00055     ERR_CAT_ORDER,
    00056     ERR_CAT_MARINE,
    00057
    00062     ERR_CAT_BIT_SIZE = 8,
    00063   };
    00064
    00068   enum ErrorMessages {
    00070     ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE,  // []
    00072     ERR_UNKNOWN,                                  // []
    00074     ERR_PRECONDITION_FAILED,                      // []
    00076     ERR_PRECONDITION_STRING_TOO_LONG,             // []
    00078     ERR_NEWGRF_SUPPLIED_ERROR,                    // []
    00079
    00081     ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE,
    00082
    00084     ERR_NOT_ENOUGH_CASH,                          // [STR_0003_NOT_ENOUGH_CASH_REQUIRES]
    00085
    00087     ERR_LOCAL_AUTHORITY_REFUSES,                  // [STR_2009_LOCAL_AUTHORITY_REFUSES]
    00088
    00090     ERR_ALREADY_BUILT,                            // [STR_1007_ALREADY_BUILT, STR_5007_MUST_DEMOLISH_BRIDGE_FIRST]
    00091
    00093     ERR_AREA_NOT_CLEAR,                           // [STR_2004_BUILDING_MUST_BE_DEMOLISHED, STR_5007_MUST_DEMOLISH_BRIDGE_FIRST, STR_300B_MUST_DEMOLISH_RAILROAD, STR_300E_MUST_DEMOLISH_AIRPORT_FIRST, STR_MUST_DEMOLISH_CARGO_TRAM_STATION, STR_3047_MUST_DEMOLISH_TRUCK_STATION, STR_MUST_DEMOLISH_PASSENGER_TRAM_STATION, STR_3046_MUST_DEMOLISH_BUS_STATION, STR_306A_BUOY_IN_THE_WAY, STR_304D_MUST_DEMOLISH_DOCK_FIRST, STR_4800_IN_THE_WAY, STR_5804_COMPANY_HEADQUARTERS_IN, STR_5800_OBJECT_IN_THE_WAY, STR_1801_MUST_REMOVE_ROAD_FIRST, STR_1008_MUST_REMOVE_RAILROAD_TRACK, STR_5007_MUST_DEMOLISH_BRIDGE_FIRST, STR_5006_MUST_DEMOLISH_TUNNEL_FIRST, STR_1002_EXCAVATION_WOULD_DAMAGE]
    00094
    00096     ERR_OWNED_BY_ANOTHER_COMPANY,                 // [STR_1024_AREA_IS_OWNED_BY_ANOTHER, STR_013B_OWNED_BY]
    00097
    00099     ERR_NAME_IS_NOT_UNIQUE,                       // [STR_NAME_MUST_BE_UNIQUE]
    00100
    00102     ERR_FLAT_LAND_REQUIRED,                       // [STR_0007_FLAT_LAND_REQUIRED]
    00103
    00105     ERR_LAND_SLOPED_WRONG,                        // [STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION]
    00106
    00108     ERR_VEHICLE_IN_THE_WAY,                       // [STR_8803_TRAIN_IN_THE_WAY, STR_9000_ROAD_VEHICLE_IN_THE_WAY, STR_980E_SHIP_IN_THE_WAY, STR_A015_AIRCRAFT_IN_THE_WAY]
    00109
    00111     ERR_SITE_UNSUITABLE,                          // [STR_0239_SITE_UNSUITABLE, STR_304B_SITE_UNSUITABLE]
    00112
    00114     ERR_TOO_CLOSE_TO_EDGE,                        // [STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP]
    00115
    00117     ERR_STATION_TOO_SPREAD_OUT,                   // [STR_306C_STATION_TOO_SPREAD_OUT]
    00118   };
    00119
    00125   static ErrorCategories GetErrorCategory();
    00126
    00131   static AIErrorType GetLastError();
    00132
    00137   static char *GetLastErrorString();
    00138
    00139 #ifndef EXPORT_SKIP
    00140
    00146   static AIErrorType StringToError(StringID internal_string_id);
    00147
    00154   static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg);
    00155
    00162   static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
    00163 #endif /* EXPORT_SKIP */
    00164
    00165 private:
    00166   typedef std::map<StringID, AIErrorType> AIErrorMap;
    00167   typedef std::map<AIErrorType, const char *> AIErrorMapString;
    00168
    00169   static AIErrorMap error_map;
    00170   static AIErrorMapString error_map_string;
    00171 };
    00172
    00173 #endif /* AI_ERROR_HPP */