# ai_rail.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_rail.hpp 20095 2010-07-08 19:59:13Z 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_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:
    00024   static const char *GetClassName() { return "AIRail"; }
    00025
    00029   enum ErrorMessages {
    00031     ERR_RAIL_BASE = AIError::ERR_CAT_RAIL << AIError::ERR_CAT_BIT_SIZE,
    00032
    00034     ERR_CROSSING_ON_ONEWAY_ROAD,       // [STR_ERROR_CROSSING_ON_ONEWAY_ROAD]
    00035
    00037     ERR_UNSUITABLE_TRACK,              // [STR_ERROR_NO_SUITABLE_RAILROAD_TRACK]
    00038
    00040     ERR_NONUNIFORM_STATIONS_DISABLED,  // [STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED]
    00041
    00043     ERR_RAILTYPE_DISALLOWS_CROSSING,   // [STR_ERROR_CROSSING_DISALLOWED]
    00044   };
    00045
    00049   enum RailType {
    00050     /* Note: the values _are_ important as they represent an in-game value */
    00051     RAILTYPE_INVALID  = 0xFF,
    00052   };
    00053
    00057   enum RailTrack {
    00058     /* Note: the values _are_ important as they represent an in-game value */
    00059     RAILTRACK_NE_SW   = 1 << 0,
    00060     RAILTRACK_NW_SE   = 1 << 1,
    00061     RAILTRACK_NW_NE   = 1 << 2,
    00062     RAILTRACK_SW_SE   = 1 << 3,
    00063     RAILTRACK_NW_SW   = 1 << 4,
    00064     RAILTRACK_NE_SE   = 1 << 5,
    00065     RAILTRACK_INVALID = 0xFF,
    00066   };
    00067
    00071   enum SignalType {
    00072     /* Note: the values _are_ important as they represent an in-game value */
    00073     SIGNALTYPE_NORMAL        = 0,
    00074     SIGNALTYPE_ENTRY         = 1,
    00075     SIGNALTYPE_EXIT          = 2,
    00076     SIGNALTYPE_COMBO         = 3,
    00077     SIGNALTYPE_PBS           = 4,
    00078     SIGNALTYPE_PBS_ONEWAY    = 5,
    00079     SIGNALTYPE_TWOWAY        = 8,
    00080     SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY,
    00081     SIGNALTYPE_ENTRY_TWOWAY  = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY,
    00082     SIGNALTYPE_EXIT_TWOWAY   = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY,
    00083     SIGNALTYPE_COMBO_TWOWAY  = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY,
    00084     SIGNALTYPE_NONE          = 0xFF,
    00085   };
    00086
    00090   enum BuildType {
    00091     BT_TRACK,
    00092     BT_SIGNAL,
    00093     BT_DEPOT,
    00094     BT_STATION,
    00095     BT_WAYPOINT,
    00096   };
    00097
    00106   static bool IsRailTile(TileIndex tile);
    00107
    00113   static bool IsLevelCrossingTile(TileIndex tile);
    00114
    00121   static bool IsRailDepotTile(TileIndex tile);
    00122
    00129   static bool IsRailStationTile(TileIndex tile);
    00130
    00137   static bool IsRailWaypointTile(TileIndex tile);
    00138
    00144   static bool IsRailTypeAvailable(RailType rail_type);
    00145
    00150   static RailType GetCurrentRailType();
    00151
    00156   static void SetCurrentRailType(RailType rail_type);
    00157
    00168   static bool TrainCanRunOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
    00169
    00178   static bool TrainHasPowerOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
    00179
    00186   static RailType GetRailType(TileIndex tile);
    00187
    00199   static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to);
    00200
    00207   static TileIndex GetRailDepotFrontTile(TileIndex depot);
    00208
    00215   static RailTrack GetRailStationDirection(TileIndex tile);
    00216
    00229   static bool BuildRailDepot(TileIndex tile, TileIndex front);
    00230
    00252   static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id);
    00253
    00282   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);
    00283
    00294   static bool BuildRailWaypoint(TileIndex tile);
    00295
    00305   static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
    00306
    00316   static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
    00317
    00325   static uint GetRailTracks(TileIndex tile);
    00326
    00342   static bool BuildRailTrack(TileIndex tile, RailTrack rail_track);
    00343
    00354   static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track);
    00355
    00366   static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to);
    00367
    00389   static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to);
    00390
    00405   static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to);
    00406
    00414   static SignalType GetSignalType(TileIndex tile, TileIndex front);
    00415
    00426   static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal);
    00427
    00436   static bool RemoveSignal(TileIndex tile, TileIndex front);
    00437
    00445   static Money GetBuildCost(RailType railtype, BuildType build_type);
    00446
    00457   static int32 GetMaxSpeed(RailType railtype);
    00458 };
    00459
    00460 #endif /* AI_RAIL_HPP */