ai_rail.hpp

Go to the documentation of this file.
00001 /* $Id: ai_rail.hpp 20288 2010-08-01 20:41:46Z 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_RAIL_HPP
00013 #define AI_RAIL_HPP
00014 
00015 #include "ai_object.hpp"
00016 #include "ai_error.hpp"
00017 #include "ai_tile.hpp"
00018 
00022 class AIRail : public AIObject {
00023 public:
00025   static const char *GetClassName() { return "AIRail"; }
00026 
00030   enum ErrorMessages {
00032     ERR_RAIL_BASE = AIError::ERR_CAT_RAIL << AIError::ERR_CAT_BIT_SIZE,
00033 
00035     ERR_CROSSING_ON_ONEWAY_ROAD,       // [STR_ERROR_CROSSING_ON_ONEWAY_ROAD]
00036 
00038     ERR_UNSUITABLE_TRACK,              // [STR_ERROR_NO_SUITABLE_RAILROAD_TRACK]
00039 
00041     ERR_NONUNIFORM_STATIONS_DISABLED,  // [STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED]
00042 
00044     ERR_RAILTYPE_DISALLOWS_CROSSING,   // [STR_ERROR_CROSSING_DISALLOWED]
00045   };
00046 
00050   enum RailType {
00051     /* Note: the values _are_ important as they represent an in-game value */
00052     RAILTYPE_INVALID  = 0xFF, 
00053   };
00054 
00058   enum RailTrack {
00059     /* Note: the values _are_ important as they represent an in-game value */
00060     RAILTRACK_NE_SW   = 1 << 0, 
00061     RAILTRACK_NW_SE   = 1 << 1, 
00062     RAILTRACK_NW_NE   = 1 << 2, 
00063     RAILTRACK_SW_SE   = 1 << 3, 
00064     RAILTRACK_NW_SW   = 1 << 4, 
00065     RAILTRACK_NE_SE   = 1 << 5, 
00066     RAILTRACK_INVALID = 0xFF,   
00067   };
00068 
00072   enum SignalType {
00073     /* Note: the values _are_ important as they represent an in-game value */
00074     SIGNALTYPE_NORMAL        = 0, 
00075     SIGNALTYPE_ENTRY         = 1, 
00076     SIGNALTYPE_EXIT          = 2, 
00077     SIGNALTYPE_COMBO         = 3, 
00078     SIGNALTYPE_PBS           = 4, 
00079     SIGNALTYPE_PBS_ONEWAY    = 5, 
00080     SIGNALTYPE_TWOWAY        = 8, 
00081     SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY, 
00082     SIGNALTYPE_ENTRY_TWOWAY  = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY,  
00083     SIGNALTYPE_EXIT_TWOWAY   = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY,   
00084     SIGNALTYPE_COMBO_TWOWAY  = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY,  
00085     SIGNALTYPE_NONE          = 0xFF, 
00086   };
00087 
00091   enum BuildType {
00092     BT_TRACK,    
00093     BT_SIGNAL,   
00094     BT_DEPOT,    
00095     BT_STATION,  
00096     BT_WAYPOINT, 
00097   };
00098 
00107   static bool IsRailTile(TileIndex tile);
00108 
00114   static bool IsLevelCrossingTile(TileIndex tile);
00115 
00122   static bool IsRailDepotTile(TileIndex tile);
00123 
00130   static bool IsRailStationTile(TileIndex tile);
00131 
00138   static bool IsRailWaypointTile(TileIndex tile);
00139 
00145   static bool IsRailTypeAvailable(RailType rail_type);
00146 
00151   static RailType GetCurrentRailType();
00152 
00157   static void SetCurrentRailType(RailType rail_type);
00158 
00169   static bool TrainCanRunOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
00170 
00179   static bool TrainHasPowerOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
00180 
00187   static RailType GetRailType(TileIndex tile);
00188 
00200   static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to);
00201 
00208   static TileIndex GetRailDepotFrontTile(TileIndex depot);
00209 
00216   static RailTrack GetRailStationDirection(TileIndex tile);
00217 
00230   static bool BuildRailDepot(TileIndex tile, TileIndex front);
00231 
00253   static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id);
00254 
00285   static bool BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station);
00286 
00297   static bool BuildRailWaypoint(TileIndex tile);
00298 
00308   static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
00309 
00319   static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
00320 
00328   static uint GetRailTracks(TileIndex tile);
00329 
00345   static bool BuildRailTrack(TileIndex tile, RailTrack rail_track);
00346 
00357   static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track);
00358 
00369   static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to);
00370 
00392   static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to);
00393 
00408   static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to);
00409 
00417   static SignalType GetSignalType(TileIndex tile, TileIndex front);
00418 
00429   static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal);
00430 
00439   static bool RemoveSignal(TileIndex tile, TileIndex front);
00440 
00448   static Money GetBuildCost(RailType railtype, BuildType build_type);
00449 
00460   static int32 GetMaxSpeed(RailType railtype);
00461 };
00462 
00463 #endif /* AI_RAIL_HPP */

Generated on Thu Dec 23 23:41:22 2010 for OpenTTD by  doxygen 1.6.1