script_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 SCRIPT_RAIL_HPP
00013 #define SCRIPT_RAIL_HPP
00014 
00015 #include "script_tile.hpp"
00016 
00021 class ScriptRail : public ScriptObject {
00022 public:
00026   enum ErrorMessages {
00028     ERR_RAIL_BASE = ScriptError::ERR_CAT_RAIL << ScriptError::ERR_CAT_BIT_SIZE,
00029 
00031     ERR_CROSSING_ON_ONEWAY_ROAD,       // [STR_ERROR_CROSSING_ON_ONEWAY_ROAD]
00032 
00034     ERR_UNSUITABLE_TRACK,              // [STR_ERROR_NO_SUITABLE_RAILROAD_TRACK]
00035 
00037     ERR_RAILTYPE_DISALLOWS_CROSSING,   // [STR_ERROR_CROSSING_DISALLOWED]
00038   };
00039 
00043   enum RailType {
00044     /* Note: the values _are_ important as they represent an in-game value */
00045     RAILTYPE_INVALID  = 0xFF, 
00046   };
00047 
00051   enum RailTrack {
00052     /* Note: the values _are_ important as they represent an in-game value */
00053     RAILTRACK_NE_SW   = 1 << 0, 
00054     RAILTRACK_NW_SE   = 1 << 1, 
00055     RAILTRACK_NW_NE   = 1 << 2, 
00056     RAILTRACK_SW_SE   = 1 << 3, 
00057     RAILTRACK_NW_SW   = 1 << 4, 
00058     RAILTRACK_NE_SE   = 1 << 5, 
00059     RAILTRACK_INVALID = 0xFF,   
00060   };
00061 
00065   enum SignalType {
00066     /* Note: the values _are_ important as they represent an in-game value */
00067     SIGNALTYPE_NORMAL        = 0, 
00068     SIGNALTYPE_ENTRY         = 1, 
00069     SIGNALTYPE_EXIT          = 2, 
00070     SIGNALTYPE_COMBO         = 3, 
00071     SIGNALTYPE_PBS           = 4, 
00072     SIGNALTYPE_PBS_ONEWAY    = 5, 
00073     SIGNALTYPE_TWOWAY        = 8, 
00074     SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY, 
00075     SIGNALTYPE_ENTRY_TWOWAY  = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY,  
00076     SIGNALTYPE_EXIT_TWOWAY   = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY,   
00077     SIGNALTYPE_COMBO_TWOWAY  = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY,  
00078     SIGNALTYPE_NONE          = 0xFF, 
00079   };
00080 
00084   enum BuildType {
00085     BT_TRACK,    
00086     BT_SIGNAL,   
00087     BT_DEPOT,    
00088     BT_STATION,  
00089     BT_WAYPOINT, 
00090   };
00091 
00102   static char *GetName(RailType rail_type);
00103 
00112   static bool IsRailTile(TileIndex tile);
00113 
00119   static bool IsLevelCrossingTile(TileIndex tile);
00120 
00127   static bool IsRailDepotTile(TileIndex tile);
00128 
00135   static bool IsRailStationTile(TileIndex tile);
00136 
00143   static bool IsRailWaypointTile(TileIndex tile);
00144 
00150   static bool IsRailTypeAvailable(RailType rail_type);
00151 
00156   static RailType GetCurrentRailType();
00157 
00162   static void SetCurrentRailType(RailType rail_type);
00163 
00174   static bool TrainCanRunOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type);
00175 
00184   static bool TrainHasPowerOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type);
00185 
00192   static RailType GetRailType(TileIndex tile);
00193 
00205   static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, ScriptRail::RailType convert_to);
00206 
00213   static TileIndex GetRailDepotFrontTile(TileIndex depot);
00214 
00221   static RailTrack GetRailStationDirection(TileIndex tile);
00222 
00235   static bool BuildRailDepot(TileIndex tile, TileIndex front);
00236 
00258   static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id);
00259 
00291   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);
00292 
00303   static bool BuildRailWaypoint(TileIndex tile);
00304 
00314   static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
00315 
00325   static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
00326 
00334   static uint GetRailTracks(TileIndex tile);
00335 
00351   static bool BuildRailTrack(TileIndex tile, RailTrack rail_track);
00352 
00363   static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track);
00364 
00375   static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to);
00376 
00398   static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to);
00399 
00414   static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to);
00415 
00423   static SignalType GetSignalType(TileIndex tile, TileIndex front);
00424 
00435   static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal);
00436 
00445   static bool RemoveSignal(TileIndex tile, TileIndex front);
00446 
00454   static Money GetBuildCost(RailType railtype, BuildType build_type);
00455 
00466   static int32 GetMaxSpeed(RailType railtype);
00467 
00474   static uint16 GetMaintenanceCostFactor(RailType railtype);
00475 };
00476 
00477 #endif /* SCRIPT_RAIL_HPP */