# ai_rail.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_rail.hpp 18987 2010-02-02 22:27:03Z terkhen $ */
    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   };
    00042
    00046   enum RailType {
    00047     /* Note: the values _are_ important as they represent an in-game value */
    00048     RAILTYPE_INVALID  = 0xFF,
    00049   };
    00050
    00054   enum RailTrack {
    00055     /* Note: the values _are_ important as they represent an in-game value */
    00056     RAILTRACK_NE_SW   = 1 << 0,
    00057     RAILTRACK_NW_SE   = 1 << 1,
    00058     RAILTRACK_NW_NE   = 1 << 2,
    00059     RAILTRACK_SW_SE   = 1 << 3,
    00060     RAILTRACK_NW_SW   = 1 << 4,
    00061     RAILTRACK_NE_SE   = 1 << 5,
    00062     RAILTRACK_INVALID = 0xFF,
    00063   };
    00064
    00068   enum SignalType {
    00069     /* Note: the values _are_ important as they represent an in-game value */
    00070     SIGNALTYPE_NORMAL        = 0,
    00071     SIGNALTYPE_ENTRY         = 1,
    00072     SIGNALTYPE_EXIT          = 2,
    00073     SIGNALTYPE_COMBO         = 3,
    00074     SIGNALTYPE_PBS           = 4,
    00075     SIGNALTYPE_PBS_ONEWAY    = 5,
    00076     SIGNALTYPE_TWOWAY        = 8,
    00077     SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY,
    00078     SIGNALTYPE_ENTRY_TWOWAY  = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY,
    00079     SIGNALTYPE_EXIT_TWOWAY   = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY,
    00080     SIGNALTYPE_COMBO_TWOWAY  = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY,
    00081     SIGNALTYPE_NONE          = 0xFF,
    00082   };
    00083
    00087   enum BuildType {
    00088     BT_TRACK,
    00089     BT_SIGNAL,
    00090     BT_DEPOT,
    00091     BT_STATION,
    00092     BT_WAYPOINT,
    00093   };
    00094
    00103   static bool IsRailTile(TileIndex tile);
    00104
    00110   static bool IsLevelCrossingTile(TileIndex tile);
    00111
    00118   static bool IsRailDepotTile(TileIndex tile);
    00119
    00126   static bool IsRailStationTile(TileIndex tile);
    00127
    00134   static bool IsRailWaypointTile(TileIndex tile);
    00135
    00141   static bool IsRailTypeAvailable(RailType rail_type);
    00142
    00147   static RailType GetCurrentRailType();
    00148
    00153   static void SetCurrentRailType(RailType rail_type);
    00154
    00165   static bool TrainCanRunOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
    00166
    00175   static bool TrainHasPowerOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type);
    00176
    00183   static RailType GetRailType(TileIndex tile);
    00184
    00196   static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to);
    00197
    00204   static TileIndex GetRailDepotFrontTile(TileIndex depot);
    00205
    00212   static RailTrack GetRailStationDirection(TileIndex tile);
    00213
    00226   static bool BuildRailDepot(TileIndex tile, TileIndex front);
    00227
    00249   static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id);
    00250
    00279   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);
    00280
    00291   static bool BuildRailWaypoint(TileIndex tile);
    00292
    00302   static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
    00303
    00313   static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
    00314
    00322   static uint GetRailTracks(TileIndex tile);
    00323
    00339   static bool BuildRailTrack(TileIndex tile, RailTrack rail_track);
    00340
    00351   static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track);
    00352
    00363   static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to);
    00364
    00386   static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to);
    00387
    00402   static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to);
    00403
    00411   static SignalType GetSignalType(TileIndex tile, TileIndex front);
    00412
    00423   static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal);
    00424
    00433   static bool RemoveSignal(TileIndex tile, TileIndex front);
    00434
    00442   static Money GetBuildCost(RailType railtype, BuildType build_type);
    00443 };
    00444
    00445 #endif /* AI_RAIL_HPP */