ai_error.hpp

Go to the documentation of this file.
00001 /* $Id: ai_error.hpp 20411 2010-08-08 10:59:30Z rubidium $ */
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:
00047   static const char *GetClassName() { return "AIError"; }
00048 
00052   enum ErrorCategories {
00053     ERR_CAT_NONE = 0, 
00054     ERR_CAT_GENERAL,  
00055     ERR_CAT_VEHICLE,  
00056     ERR_CAT_STATION,  
00057     ERR_CAT_BRIDGE,   
00058     ERR_CAT_TUNNEL,   
00059     ERR_CAT_TILE,     
00060     ERR_CAT_SIGN,     
00061     ERR_CAT_RAIL,     
00062     ERR_CAT_ROAD,     
00063     ERR_CAT_ORDER,    
00064     ERR_CAT_MARINE,   
00065     ERR_CAT_WAYPOINT, 
00066 
00071     ERR_CAT_BIT_SIZE = 8,
00072   };
00073 
00077   enum ErrorMessages {
00079     ERR_NONE = ERR_CAT_NONE << ERR_CAT_BIT_SIZE,  // []
00081     ERR_UNKNOWN,                                  // []
00083     ERR_PRECONDITION_FAILED,                      // []
00085     ERR_PRECONDITION_STRING_TOO_LONG,             // []
00087     ERR_NEWGRF_SUPPLIED_ERROR,                    // []
00088 
00090     ERR_GENERAL_BASE = ERR_CAT_GENERAL << ERR_CAT_BIT_SIZE,
00091 
00093     ERR_NOT_ENOUGH_CASH,                          // [STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY]
00094 
00096     ERR_LOCAL_AUTHORITY_REFUSES,                  // [STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS]
00097 
00099     ERR_ALREADY_BUILT,                            // [STR_ERROR_ALREADY_BUILT, STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST]
00100 
00102     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_GENERIC_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]
00103 
00105     ERR_OWNED_BY_ANOTHER_COMPANY,                 // [STR_ERROR_AREA_IS_OWNED_BY_ANOTHER, STR_ERROR_OWNED_BY]
00106 
00108     ERR_NAME_IS_NOT_UNIQUE,                       // [STR_ERROR_NAME_MUST_BE_UNIQUE]
00109 
00111     ERR_FLAT_LAND_REQUIRED,                       // [STR_ERROR_FLAT_LAND_REQUIRED]
00112 
00114     ERR_LAND_SLOPED_WRONG,                        // [STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION]
00115 
00117     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]
00118 
00120     ERR_SITE_UNSUITABLE,                          // [STR_ERROR_SITE_UNSUITABLE]
00121 
00123     ERR_TOO_CLOSE_TO_EDGE,                        // [STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP]
00124 
00126     ERR_STATION_TOO_SPREAD_OUT,                   // [STR_ERROR_STATION_TOO_SPREAD_OUT]
00127   };
00128 
00134   static ErrorCategories GetErrorCategory();
00135 
00140   static AIErrorType GetLastError();
00141 
00146   static char *GetLastErrorString();
00147 
00148 #ifndef EXPORT_SKIP
00149 
00155   static AIErrorType StringToError(StringID internal_string_id);
00156 
00163   static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg);
00164 
00171   static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message);
00172 #endif /* EXPORT_SKIP */
00173 
00174 private:
00175   typedef std::map<StringID, AIErrorType> AIErrorMap;
00176   typedef std::map<AIErrorType, const char *> AIErrorMapString;
00177 
00178   static AIErrorMap error_map;
00179   static AIErrorMapString error_map_string;
00180 };
00181 
00182 #endif /* AI_ERROR_HPP */

Generated on Sun May 15 19:20:05 2011 for OpenTTD by  doxygen 1.6.1