script_rail.hpp

Go to the documentation of this file.
00001 /* $Id: script_rail.hpp 23633 2011-12-19 21:05:36Z truebrain $ */
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 #include "../../signal_type.h"
00017 #include "../../track_type.h"
00018 
00023 class ScriptRail : public ScriptObject {
00024 public:
00028   enum ErrorMessages {
00030     ERR_RAIL_BASE = ScriptError::ERR_CAT_RAIL << ScriptError::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: these values represent part of the in-game static values */
00047     RAILTYPE_INVALID  = ::INVALID_RAILTYPE, 
00048   };
00049 
00053   enum RailTrack {
00054     /* Note: these values represent part of the in-game TrackBits enum */
00055     RAILTRACK_NE_SW   = ::TRACK_BIT_X,       
00056     RAILTRACK_NW_SE   = ::TRACK_BIT_Y,       
00057     RAILTRACK_NW_NE   = ::TRACK_BIT_UPPER,   
00058     RAILTRACK_SW_SE   = ::TRACK_BIT_LOWER,   
00059     RAILTRACK_NW_SW   = ::TRACK_BIT_LEFT,    
00060     RAILTRACK_NE_SE   = ::TRACK_BIT_RIGHT,   
00061     RAILTRACK_INVALID = ::INVALID_TRACK_BIT, 
00062   };
00063 
00067   enum SignalType {
00068     /* Note: these values represent part of the in-game SignalType enum */
00069     SIGNALTYPE_NORMAL        = ::SIGTYPE_NORMAL,     
00070     SIGNALTYPE_ENTRY         = ::SIGTYPE_ENTRY,      
00071     SIGNALTYPE_EXIT          = ::SIGTYPE_EXIT,       
00072     SIGNALTYPE_COMBO         = ::SIGTYPE_COMBO,      
00073     SIGNALTYPE_PBS           = ::SIGTYPE_PBS,        
00074     SIGNALTYPE_PBS_ONEWAY    = ::SIGTYPE_PBS_ONEWAY, 
00075 
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 
00082     SIGNALTYPE_NONE          = 0xFF, 
00083   };
00084 
00088   enum BuildType {
00089     BT_TRACK,    
00090     BT_SIGNAL,   
00091     BT_DEPOT,    
00092     BT_STATION,  
00093     BT_WAYPOINT, 
00094   };
00095 
00106   static char *GetName(RailType rail_type);
00107 
00116   static bool IsRailTile(TileIndex tile);
00117 
00123   static bool IsLevelCrossingTile(TileIndex tile);
00124 
00131   static bool IsRailDepotTile(TileIndex tile);
00132 
00139   static bool IsRailStationTile(TileIndex tile);
00140 
00147   static bool IsRailWaypointTile(TileIndex tile);
00148 
00154   static bool IsRailTypeAvailable(RailType rail_type);
00155 
00160   static RailType GetCurrentRailType();
00161 
00166   static void SetCurrentRailType(RailType rail_type);
00167 
00178   static bool TrainCanRunOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type);
00179 
00188   static bool TrainHasPowerOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type);
00189 
00196   static RailType GetRailType(TileIndex tile);
00197 
00210   static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, ScriptRail::RailType convert_to);
00211 
00218   static TileIndex GetRailDepotFrontTile(TileIndex depot);
00219 
00226   static RailTrack GetRailStationDirection(TileIndex tile);
00227 
00241   static bool BuildRailDepot(TileIndex tile, TileIndex front);
00242 
00265   static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id);
00266 
00299   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);
00300 
00312   static bool BuildRailWaypoint(TileIndex tile);
00313 
00324   static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
00325 
00336   static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail);
00337 
00345   static uint GetRailTracks(TileIndex tile);
00346 
00363   static bool BuildRailTrack(TileIndex tile, RailTrack rail_track);
00364 
00376   static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track);
00377 
00388   static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to);
00389 
00412   static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to);
00413 
00429   static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to);
00430 
00438   static SignalType GetSignalType(TileIndex tile, TileIndex front);
00439 
00451   static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal);
00452 
00462   static bool RemoveSignal(TileIndex tile, TileIndex front);
00463 
00471   static Money GetBuildCost(RailType railtype, BuildType build_type);
00472 
00483   static int32 GetMaxSpeed(RailType railtype);
00484 
00491   static uint16 GetMaintenanceCostFactor(RailType railtype);
00492 };
00493 
00494 #endif /* SCRIPT_RAIL_HPP */