# ai_rail.hpp

Go to the documentation of this file.

    00001 /* $Id$ */
    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_tile.hpp"
    00016
    00020 class AIRail : public AIObject {
    00021 public:
    00023   static const char *GetClassName() { return "AIRail"; }
    00024
    00028   enum ErrorMessages {
    00030     ERR_RAIL_BASE = AIError::ERR_CAT_RAIL << AIError::ERR_CAT_BIT_SIZE,
    00031
    00033     ERR_CROSSING_ON_ONEWAY_ROAD,       // [STR_ERROR_CROSSING_ON_ONEWAY_ROAD]
    00034
    00036     ERR_UNSUITABLE_TRACK,              // [STR_ERROR_NO_SUITABLE_RAILROAD_TRACK]
    00037
    00039     ERR_RAILTYPE_DISALLOWS_CROSSING,   // [STR_ERROR_CROSSING_DISALLOWED]
    00040   };
    00041
    00045   enum RailType {
    00046     /* Note: the values _are_ important as they represent an in-game value */
    00047     RAILTYPE_INVALID  = 0xFF,
    00048   };
    00049
    00053   enum RailTrack {
    00054     /* Note: the values _are_ important as they represent an in-game value */
    00055     RAILTRACK_NE_SW   = 1 << 0,
    00056     RAILTRACK_NW_SE   = 1 << 1,
    00057     RAILTRACK_NW_NE   = 1 << 2,
    00058     RAILTRACK_SW_SE   = 1 << 3,
    00059     RAILTRACK_NW_SW   = 1 << 4,
    00060     RAILTRACK_NE_SE   = 1 << 5,
    00061     RAILTRACK_INVALID = 0xFF,
    00062   };
    00063
    00067   enum SignalType {
    00068     /* Note: the values _are_ important as they represent an in-game value */
    00069     SIGNALTYPE_NORMAL        = 0,
    00070     SIGNALTYPE_ENTRY         = 1,
    00071     SIGNALTYPE_EXIT          = 2,
    00072     SIGNALTYPE_COMBO         = 3,
    00073     SIGNALTYPE_PBS           = 4,
    00074     SIGNALTYPE_PBS_ONEWAY    = 5,
    00075     SIGNALTYPE_TWOWAY        = 8,
    00076     SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY,
    00077     SIGNALTYPE_ENTRY_TWOWAY  = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY,
    00078     SIGNALTYPE_EXIT_TWOWAY   = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY,
    00079     SIGNALTYPE_COMBO_TWOWAY  = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY,
    00080     SIGNALTYPE_NONE          = 0xFF,
    00081   };
    00082
    00086   enum BuildType {
    00087     BT_TRACK,
    00088     BT_SIGNAL,
    00089     BT_DEPOT,
    00090     BT_STATION,
    00091     BT_WAYPOINT,
    00092   };
    00093
    00104   static char *GetName(RailType rail_type);
    00105
    00114   static bool IsRailTile(TileIndex tile);
    00115
    00121   static bool IsLevelCrossingTile(TileIndex tile);
    00122
    00129   static bool IsRailDepotTile(TileIndex tile);
    00130
    00137   static bool IsRailStationTile(TileIndex tile);
    00138
    00145   static bool IsRailWaypointTile(TileIndex tile);
    00146
    00152   static bool IsRailTypeAvailable(RailType rail_type);
    00153
    00158   static RailType GetCurrentRailType();
    00159
    00164   static void SetCurrentRailType(RailType rail_type);
    00165
    00176   static bool TrainCanRunOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
    00177
    00186   static bool TrainHasPowerOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
    00187
    00194   static RailType GetRailType(TileIndex tile);
    00195
    00207   static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to);
    00208
    00215   static TileIndex GetRailDepotFrontTile(TileIndex depot);
    00216
    00223   static RailTrack GetRailStationDirection(TileIndex tile);
    00224
    00237   static bool BuildRailDepot(TileIndex tile, TileIndex front);
    00238
    00260   static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id);
    00261
    00292   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);
    00293
    00304   static bool BuildRailWaypoint(TileIndex tile);
    00305
    00315   static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
    00316
    00326   static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
    00327
    00335   static uint GetRailTracks(TileIndex tile);
    00336
    00352   static bool BuildRailTrack(TileIndex tile, RailTrack rail_track);
    00353
    00364   static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track);
    00365
    00376   static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to);
    00377
    00399   static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to);
    00400
    00415   static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to);
    00416
    00424   static SignalType GetSignalType(TileIndex tile, TileIndex front);
    00425
    00436   static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal);
    00437
    00446   static bool RemoveSignal(TileIndex tile, TileIndex front);
    00447
    00455   static Money GetBuildCost(RailType railtype, BuildType build_type);
    00456
    00467   static int32 GetMaxSpeed(RailType railtype);
    00468 };
    00469
    00470 #endif /* AI_RAIL_HPP */