ai_error.hpp

Go to the documentation of this file.
00001 /* $Id: ai_error.hpp 18691 2010-01-02 16:47:32Z yexo $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef AI_ERROR_HPP
00013 #define AI_ERROR_HPP
00014 
00015 #include "ai_object.hpp"
00016 #include <map>
00017 
00023 #define EnforcePrecondition(returnval, condition)               \
00024   if (!(condition)) {                                           \
00025     AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED);   \
00026     return returnval;                                           \
00027   }
00028 
00035 #define EnforcePreconditionCustomError(returnval, condition, error_code)   \
00036   if (!(condition)) {                                                      \
00037     AIObject::SetLastError(error_code);                                    \
00038     return returnval;                                                      \
00039   }
00040 
00044 class AIError : public AIObject {
00045 public:
00046   static const char *GetClassName() { return "AIError"; }
00047 
00051   enum ErrorCategories {
00052     ERR_CAT_NONE = 0, 
00053     ERR_CAT_GENERAL,  
00054     ERR_CAT_VEHICLE,  
00055     ERR_CAT_STATION,  
00056     ERR_CAT_BRIDGE,   
00057     ERR_CAT_TUNNEL,   
00058     ERR_CAT_TILE,     
00059     ERR_CAT_SIGN,     
00060     ERR_CAT_RAIL,     
00061     ERR_CAT_ROAD,     
00062     ERR_CAT_ORDER,    
00063     ERR_CAT_MARINE,   
00064     ERR_CAT_WAYPOINT, 
00065 
00070     ERR_CAT_BIT_SIZE = 8,
00071   };
00072 
00076   enum ErrorMessages {
00078     ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE,  // []
00080     ERR_UNKNOWN,                                  // []
00082     ERR_PRECONDITION_FAILED,                      // []
00084     ERR_PRECONDITION_STRING_TOO_LONG,             // []
00086     ERR_NEWGRF_SUPPLIED_ERROR,                    // []
00087 
00089     ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE,
00090 
00092     ERR_NOT_ENOUGH_CASH,                          // [STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY]
00093 
00095     ERR_LOCAL_AUTHORITY_REFUSES,                  // [STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS]
00096 
00098     ERR_ALREADY_BUILT,                            // [STR_ERROR_ALREADY_BUILT, STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST]
00099 
00101     ERR_AREA_NOT_CLEAR,                           // [STR_ERROR_BUILDING_MUST_BE_DEMOLISHED, STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST, STR_ERROR_MUST_DEMOLISH_RAILROAD, STR_ERROR_MUST_DEMOLISH_AIRPORT_FIRST, STR_ERROR_MUST_DEMOLISH_CARGO_TRAM_STATION_FIRST, STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST, STR_ERROR_MUST_DEMOLISH_PASSENGER_TRAM_STATION_FIRST, STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST, STR_ERROR_BUOY_IN_THE_WAY, STR_ERROR_MUST_DEMOLISH_DOCK_FIRST, STR_ERROR_UNMOVABLE_OBJECT_IN_THE_WAY, STR_ERROR_COMPANY_HEADQUARTERS_IN, STR_ERROR_OBJECT_IN_THE_WAY, STR_ERROR_MUST_REMOVE_ROAD_FIRST, STR_ERROR_MUST_REMOVE_RAILROAD_TRACK, STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST, STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST, STR_ERROR_EXCAVATION_WOULD_DAMAGE]
00102 
00104     ERR_OWNED_BY_ANOTHER_COMPANY,                 // [STR_ERROR_AREA_IS_OWNED_BY_ANOTHER, STR_ERROR_OWNED_BY]
00105 
00107     ERR_NAME_IS_NOT_UNIQUE,                       // [STR_ERROR_NAME_MUST_BE_UNIQUE]
00108 
00110     ERR_FLAT_LAND_REQUIRED,                       // [STR_ERROR_FLAT_LAND_REQUIRED]
00111 
00113     ERR_LAND_SLOPED_WRONG,                        // [STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION]
00114 
00116     ERR_VEHICLE_IN_THE_WAY,                       // [STR_ERROR_TRAIN_IN_THE_WAY, STR_ERROR_ROAD_VEHICLE_IN_THE_WAY, STR_ERROR_SHIP_IN_THE_WAY, STR_ERROR_AIRCRAFT_IN_THE_WAY]
00117 
00119     ERR_SITE_UNSUITABLE,                          // [STR_ERROR_SITE_UNSUITABLE]
00120 
00122     ERR_TOO_CLOSE_TO_EDGE,                        // [STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP]
00123 
00125     ERR_STATION_TOO_SPREAD_OUT,                   // [STR_ERROR_STATION_TOO_SPREAD_OUT]
00126   };
00127 
00133   static ErrorCategories GetErrorCategory();
00134 
00139   static AIErrorType GetLastError();
00140 
00145   static char *GetLastErrorString();
00146 
00147 #ifndef EXPORT_SKIP
00148 
00154   static AIErrorType StringToError(StringID internal_string_id);
00155 
00162   static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg);
00163 
00170   static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
00171 #endif /* EXPORT_SKIP */
00172 
00173 private:
00174   typedef std::map<StringID, AIErrorType> AIErrorMap;
00175   typedef std::map<AIErrorType, const char *> AIErrorMapString;
00176 
00177   static AIErrorMap error_map;
00178   static AIErrorMapString error_map_string;
00179 };
00180 
00181 #endif /* AI_ERROR_HPP */

Generated on Sat Nov 20 20:59:00 2010 for OpenTTD by  doxygen 1.6.1