1 /* 2 * This file is part of OpenTTD. 3 * 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. 4 * 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. 5 * 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/>. 6 */ 7 8 /** @file script_rail.hpp Everything to query and build rails. */ 9 10 #ifndef SCRIPT_RAIL_HPP 11 #define SCRIPT_RAIL_HPP 12 13 #include "script_tile.hpp" 14 #include "../../signal_type.h" 15 #include "../../track_type.h" 16 17 /** 18 * Class that handles all rail related functions. 19 * @api ai game 20 */ 21 class ScriptRail : public ScriptObject { 22 public: 23 /** 24 * All rail related error messages. 25 */ 26 enum ErrorMessages { 27 /** Base for rail building / maintaining errors */ 28 ERR_RAIL_BASE = ScriptError::ERR_CAT_RAIL << ScriptError::ERR_CAT_BIT_SIZE, 29 30 /** One-way roads cannot have crossings */ 31 ERR_CROSSING_ON_ONEWAY_ROAD, // [STR_ERROR_CROSSING_ON_ONEWAY_ROAD] 32 33 /** No suitable track could be found */ 34 ERR_UNSUITABLE_TRACK, // [STR_ERROR_NO_SUITABLE_RAILROAD_TRACK, STR_ERROR_THERE_IS_NO_RAILROAD_TRACK, STR_ERROR_THERE_ARE_NO_SIGNALS, STR_ERROR_THERE_IS_NO_STATION] 35 36 /** This railtype cannot have crossings */ 37 ERR_RAILTYPE_DISALLOWS_CROSSING, // [STR_ERROR_CROSSING_DISALLOWED_RAIL] 38 }; 39 40 /** 41 * Types of rail known to the game. 42 */ 43 enum RailType : byte { 44 /* Note: these values represent part of the in-game static values */ 45 RAILTYPE_INVALID = ::INVALID_RAILTYPE, ///< Invalid RailType. 46 }; 47 48 /** 49 * A bitmap with all possible rail tracks on a tile. 50 */ 51 enum RailTrack { 52 /* Note: these values represent part of the in-game TrackBits enum */ 53 RAILTRACK_NE_SW = ::TRACK_BIT_X, ///< Track along the x-axis (north-east to south-west). 54 RAILTRACK_NW_SE = ::TRACK_BIT_Y, ///< Track along the y-axis (north-west to south-east). 55 RAILTRACK_NW_NE = ::TRACK_BIT_UPPER, ///< Track in the upper corner of the tile (north). 56 RAILTRACK_SW_SE = ::TRACK_BIT_LOWER, ///< Track in the lower corner of the tile (south). 57 RAILTRACK_NW_SW = ::TRACK_BIT_LEFT, ///< Track in the left corner of the tile (west). 58 RAILTRACK_NE_SE = ::TRACK_BIT_RIGHT, ///< Track in the right corner of the tile (east). 59 RAILTRACK_INVALID = ::INVALID_TRACK_BIT, ///< Flag for an invalid track. 60 }; 61 62 /** 63 * Types of signal known to the game. 64 */ 65 enum SignalType { 66 /* Note: these values represent part of the in-game SignalType enum */ 67 SIGNALTYPE_NORMAL = ::SIGTYPE_NORMAL, ///< Normal signal. 68 SIGNALTYPE_ENTRY = ::SIGTYPE_ENTRY, ///< Entry presignal. 69 SIGNALTYPE_EXIT = ::SIGTYPE_EXIT, ///< Exit signal. 70 SIGNALTYPE_COMBO = ::SIGTYPE_COMBO, ///< Combo signal. 71 SIGNALTYPE_PBS = ::SIGTYPE_PBS, ///< Normal PBS signal. 72 SIGNALTYPE_PBS_ONEWAY = ::SIGTYPE_PBS_ONEWAY, ///< No-entry PBS signal. 73 74 SIGNALTYPE_TWOWAY = 8, ///< Bit mask for twoway signal. 75 SIGNALTYPE_NORMAL_TWOWAY = SIGNALTYPE_NORMAL | SIGNALTYPE_TWOWAY, ///< Normal twoway signal. 76 SIGNALTYPE_ENTRY_TWOWAY = SIGNALTYPE_ENTRY | SIGNALTYPE_TWOWAY, ///< Entry twoway signal. 77 SIGNALTYPE_EXIT_TWOWAY = SIGNALTYPE_EXIT | SIGNALTYPE_TWOWAY, ///< Exit twoway signal. 78 SIGNALTYPE_COMBO_TWOWAY = SIGNALTYPE_COMBO | SIGNALTYPE_TWOWAY, ///< Combo twoway signal. 79 80 SIGNALTYPE_NONE = 0xFF, ///< No signal. 81 }; 82 83 /** 84 * Types of rail-related objects in the game. 85 */ 86 enum BuildType { 87 BT_TRACK, ///< Build a track 88 BT_SIGNAL, ///< Build a signal 89 BT_DEPOT, ///< Build a depot 90 BT_STATION, ///< Build a station 91 BT_WAYPOINT, ///< Build a rail waypoint 92 }; 93 94 /** 95 * Get the name of a rail type. 96 * @param rail_type The rail type to get the name of. 97 * @pre IsRailTypeAvailable(rail_type). 98 * @return The name the rail type has. 99 * @note Since there is no string with only the name of the track, the text which 100 * is shown in the dropdown where you can chose a track type is returned. This 101 * means that the name could be something like "Maglev construction" instead 102 * of just "Maglev". 103 */ 104 static char *GetName(RailType rail_type); 105 106 /** 107 * Checks whether the given tile is actually a tile with rail that can be 108 * used to traverse a tile. This excludes rail depots but includes 109 * stations and waypoints. 110 * @param tile The tile to check. 111 * @pre ScriptMap::IsValidTile(tile). 112 * @return True if and only if the tile has rail. 113 */ 114 static bool IsRailTile(TileIndex tile); 115 116 /** 117 * Checks whether there is a road / rail crossing on a tile. 118 * @param tile The tile to check. 119 * @return True if and only if there is a road / rail crossing. 120 */ 121 static bool IsLevelCrossingTile(TileIndex tile); 122 123 /** 124 * Checks whether the given tile is actually a tile with a rail depot. 125 * @param tile The tile to check. 126 * @pre ScriptMap::IsValidTile(tile). 127 * @return True if and only if the tile has a rail depot. 128 */ 129 static bool IsRailDepotTile(TileIndex tile); 130 131 /** 132 * Checks whether the given tile is actually a tile with a rail station. 133 * @param tile The tile to check. 134 * @pre ScriptMap::IsValidTile(tile). 135 * @return True if and only if the tile has a rail station. 136 */ 137 static bool IsRailStationTile(TileIndex tile); 138 139 /** 140 * Checks whether the given tile is actually a tile with a rail waypoint. 141 * @param tile The tile to check. 142 * @pre ScriptMap::IsValidTile(tile). 143 * @return True if and only if the tile has a rail waypoint. 144 */ 145 static bool IsRailWaypointTile(TileIndex tile); 146 147 /** 148 * Check if a given RailType is available. 149 * @param rail_type The RailType to check for. 150 * @return True if this RailType can be used. 151 */ 152 static bool IsRailTypeAvailable(RailType rail_type); 153 154 /** 155 * Get the current RailType set for all ScriptRail functions. 156 * @return The RailType currently set. 157 */ 158 static RailType GetCurrentRailType(); 159 160 /** 161 * Set the RailType for all further ScriptRail functions. 162 * @param rail_type The RailType to set. 163 */ 164 static void SetCurrentRailType(RailType rail_type); 165 166 /** 167 * Check if a train build for a rail type can run on another rail type. 168 * @param engine_rail_type The rail type the train is build for. 169 * @param track_rail_type The type you want to check. 170 * @pre ScriptRail::IsRailTypeAvailable(engine_rail_type). 171 * @pre ScriptRail::IsRailTypeAvailable(track_rail_type). 172 * @return Whether a train build for 'engine_rail_type' can run on 'track_rail_type'. 173 * @note Even if a train can run on a RailType that doesn't mean that it'll be 174 * able to power the train. Use TrainHasPowerOnRail for that. 175 */ 176 static bool TrainCanRunOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type); 177 178 /** 179 * Check if a train build for a rail type has power on another rail type. 180 * @param engine_rail_type The rail type the train is build for. 181 * @param track_rail_type The type you want to check. 182 * @pre ScriptRail::IsRailTypeAvailable(engine_rail_type). 183 * @pre ScriptRail::IsRailTypeAvailable(track_rail_type). 184 * @return Whether a train build for 'engine_rail_type' has power on 'track_rail_type'. 185 */ 186 static bool TrainHasPowerOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type); 187 188 /** 189 * Get the RailType that is used on a tile. 190 * @param tile The tile to check. 191 * @pre ScriptTile::HasTransportType(tile, ScriptTile.TRANSPORT_RAIL). 192 * @return The RailType that is used on a tile. 193 */ 194 static RailType GetRailType(TileIndex tile); 195 196 /** 197 * Convert the tracks on all tiles within a rectangle to another RailType. 198 * @param start_tile One corner of the rectangle. 199 * @param end_tile The opposite corner of the rectangle. 200 * @param convert_to The RailType you want to convert the rails to. 201 * @pre ScriptMap::IsValidTile(start_tile). 202 * @pre ScriptMap::IsValidTile(end_tile). 203 * @pre IsRailTypeAvailable(convert_to). 204 * @game @pre Valid ScriptCompanyMode active in scope. 205 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 206 * @return Whether at least some rail has been converted successfully. 207 */ 208 static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, ScriptRail::RailType convert_to); 209 210 /** 211 * Gets the tile in front of a rail depot. 212 * @param depot The rail depot tile. 213 * @pre IsRailDepotTile(depot). 214 * @return The tile in front of the depot. 215 */ 216 static TileIndex GetRailDepotFrontTile(TileIndex depot); 217 218 /** 219 * Gets the direction of a rail station tile. 220 * @param tile The rail station tile. 221 * @pre IsRailStationTile(tile). 222 * @return The direction of the station (either RAILTRACK_NE_SW or RAILTRACK_NW_SE). 223 */ 224 static RailTrack GetRailStationDirection(TileIndex tile); 225 226 /** 227 * Builds a rail depot. 228 * @param tile Place to build the depot. 229 * @param front The tile exactly in front of the depot. 230 * @pre ScriptMap::IsValidTile(tile). 231 * @pre ScriptMap::IsValidTile(front). 232 * @pre 'tile' is not equal to 'front', but in a straight line of it. 233 * @pre IsRailTypeAvailable(GetCurrentRailType()). 234 * @game @pre Valid ScriptCompanyMode active in scope. 235 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED 236 * @exception ScriptError::ERR_AREA_NOT_CLEAR 237 * @return Whether the rail depot has been/can be build or not. 238 */ 239 static bool BuildRailDepot(TileIndex tile, TileIndex front); 240 241 /** 242 * Build a rail station. 243 * @param tile Place to build the station. 244 * @param direction The direction to build the station. 245 * @param num_platforms The number of platforms to build. 246 * @param platform_length The length of each platform. 247 * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. 248 * @pre IsRailTypeAvailable(GetCurrentRailType()). 249 * @pre ScriptMap::IsValidTile(tile). 250 * @pre direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW. 251 * @pre num_platforms > 0 && num_platforms <= 255. 252 * @pre platform_length > 0 && platform_length <= 255. 253 * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). 254 * @game @pre Valid ScriptCompanyMode active in scope. 255 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY 256 * @exception ScriptError::ERR_AREA_NOT_CLEAR 257 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED 258 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION 259 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS 260 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN 261 * @return Whether the station has been/can be build or not. 262 */ 263 static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id); 264 265 /** 266 * Build a NewGRF rail station. This calls callback 18 to let a NewGRF 267 * provide the station class / id to build, so we don't end up with 268 * only the default stations on the map. 269 * When no NewGRF provides a rail station, or an unbuildable rail station is 270 * returned by a NewGRF, this function will fall back to building a default 271 * non-NewGRF station as if ScriptRail::BuildRailStation was called. 272 * @param tile Place to build the station. 273 * @param direction The direction to build the station. 274 * @param num_platforms The number of platforms to build. 275 * @param platform_length The length of each platform. 276 * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. 277 * @param cargo_id The CargoID of the cargo that will be transported from / to this station. 278 * @param source_industry The IndustryType of the industry you'll transport goods from, ScriptIndustryType::INDUSTRYTYPE_UNKNOWN or ScriptIndustryType::INDUSTRYTYPE_TOWN. 279 * @param goal_industry The IndustryType of the industry you'll transport goods to, ScriptIndustryType::INDUSTRYTYPE_UNKNOWN or ScriptIndustryType::INDUSTRYTYPE_TOWN. 280 * @param distance The manhattan distance you'll transport the cargo over. 281 * @param source_station True if this is the source station, false otherwise. 282 * @pre IsRailTypeAvailable(GetCurrentRailType()). 283 * @pre ScriptMap::IsValidTile(tile). 284 * @pre direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW. 285 * @pre num_platforms > 0 && num_platforms <= 255. 286 * @pre platform_length > 0 && platform_length <= 255. 287 * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). 288 * @pre ScriptCargo::IsValidCargo(cargo_type) 289 * @pre source_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(source_industry). 290 * @pre goal_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(goal_industry). 291 * @game @pre Valid ScriptCompanyMode active in scope. 292 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY 293 * @exception ScriptError::ERR_AREA_NOT_CLEAR 294 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED 295 * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION 296 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS 297 * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN 298 * @return Whether the station has been/can be build or not. 299 */ 300 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); 301 302 /** 303 * Build a rail waypoint. 304 * @param tile Place to build the waypoint. 305 * @pre ScriptMap::IsValidTile(tile). 306 * @pre IsRailTile(tile). 307 * @pre GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE. 308 * @pre IsRailTypeAvailable(GetCurrentRailType()). 309 * @game @pre Valid ScriptCompanyMode active in scope. 310 * @exception ScriptError::ERR_FLAT_LAND_REQUIRED 311 * @return Whether the rail waypoint has been/can be build or not. 312 */ 313 static bool BuildRailWaypoint(TileIndex tile); 314 315 /** 316 * Remove all rail waypoint pieces within a rectangle on the map. 317 * @param tile One corner of the rectangle to clear. 318 * @param tile2 The opposite corner. 319 * @param keep_rail Whether to keep the rail after removal. 320 * @pre IsValidTile(tile). 321 * @pre IsValidTile(tile2). 322 * @game @pre Valid ScriptCompanyMode active in scope. 323 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 324 * @return Whether at least one tile has been/can be cleared or not. 325 */ 326 static bool RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail); 327 328 /** 329 * Remove all rail station platform pieces within a rectangle on the map. 330 * @param tile One corner of the rectangle to clear. 331 * @param tile2 The opposite corner. 332 * @param keep_rail Whether to keep the rail after removal. 333 * @pre IsValidTile(tile). 334 * @pre IsValidTile(tile2). 335 * @game @pre Valid ScriptCompanyMode active in scope. 336 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 337 * @return Whether at least one tile has been/can be cleared or not. 338 */ 339 static bool RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail); 340 341 /** 342 * Get all RailTracks on the given tile. 343 * @note A depot has no railtracks. 344 * @param tile The tile to check. 345 * @pre IsRailTile(tile). 346 * @return A bitmask of RailTrack with all RailTracks on the tile. 347 */ 348 static uint GetRailTracks(TileIndex tile); 349 350 /** 351 * Build rail on the given tile. 352 * @param tile The tile to build on. 353 * @param rail_track The RailTrack to build. 354 * @pre ScriptMap::IsValidTile(tile). 355 * @pre IsRailTypeAvailable(GetCurrentRailType()). 356 * @game @pre Valid ScriptCompanyMode active in scope. 357 * @exception ScriptError::ERR_AREA_NOT_CLEAR 358 * @exception ScriptError::ERR_LAND_SLOPED_WRONG 359 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS 360 * @exception ScriptRail::ERR_CROSSING_ON_ONEWAY_ROAD 361 * @exception ScriptError::ERR_ALREADY_BUILT 362 * @return Whether the rail has been/can be build or not. 363 * @note You can only build a single track with this function so do not 364 * use the values from RailTrack as bitmask. 365 */ 366 static bool BuildRailTrack(TileIndex tile, RailTrack rail_track); 367 368 /** 369 * Remove rail on the given tile. 370 * @param tile The tile to remove rail from. 371 * @param rail_track The RailTrack to remove. 372 * @pre ScriptMap::IsValidTile(tile). 373 * @pre (GetRailTracks(tile) & rail_track) != 0. 374 * @game @pre Valid ScriptCompanyMode active in scope. 375 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 376 * @return Whether the rail has been/can be removed or not. 377 * @note You can only remove a single track with this function so do not 378 * use the values from RailTrack as bitmask. 379 */ 380 static bool RemoveRailTrack(TileIndex tile, RailTrack rail_track); 381 382 /** 383 * Check if a tile connects two adjacent tiles. 384 * @param from The first tile to connect. 385 * @param tile The tile that is checked. 386 * @param to The second tile to connect. 387 * @pre from != to. 388 * @pre ScriptMap::DistanceManhattan(from, tile) == 1. 389 * @pre ScriptMap::DistanceManhattan(to, tile) == 1. 390 * @return True if 'tile' connects 'from' and 'to'. 391 */ 392 static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to); 393 394 /** 395 * Build a rail connection between two tiles. 396 * @param from The tile just before the tile to build on. 397 * @param tile The first tile to build on. 398 * @param to The tile just after the last tile to build on. 399 * @pre from != to. 400 * @pre ScriptMap::DistanceManhattan(from, tile) == 1. 401 * @pre ScriptMap::DistanceManhattan(to, tile) >= 1. 402 * @pre (abs(abs(ScriptMap::GetTileX(to) - ScriptMap::GetTileX(tile)) - 403 * abs(ScriptMap::GetTileY(to) - ScriptMap::GetTileY(tile))) <= 1) || 404 * (ScriptMap::GetTileX(from) == ScriptMap::GetTileX(tile) && ScriptMap::GetTileX(tile) == ScriptMap::GetTileX(to)) || 405 * (ScriptMap::GetTileY(from) == ScriptMap::GetTileY(tile) && ScriptMap::GetTileY(tile) == ScriptMap::GetTileY(to)). 406 * @pre IsRailTypeAvailable(GetCurrentRailType()). 407 * @game @pre Valid ScriptCompanyMode active in scope. 408 * @exception ScriptError::ERR_AREA_NOT_CLEAR 409 * @exception ScriptError::ERR_LAND_SLOPED_WRONG 410 * @exception ScriptRail::ERR_CROSSING_ON_ONEWAY_ROAD 411 * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS 412 * @exception ScriptError::ERR_ALREADY_BUILT 413 * @note Construction will fail if an obstacle is found between the start and end tiles. 414 * @return Whether the rail has been/can be build or not. 415 */ 416 static bool BuildRail(TileIndex from, TileIndex tile, TileIndex to); 417 418 /** 419 * Remove a rail connection between two tiles. 420 * @param from The tile just before the tile to remove rail from. 421 * @param tile The first tile to remove rail from. 422 * @param to The tile just after the last tile to remove rail from. 423 * @pre from != to. 424 * @pre ScriptMap::DistanceManhattan(from, tile) == 1. 425 * @pre ScriptMap::DistanceManhattan(to, tile) >= 1. 426 * @pre (abs(abs(ScriptMap::GetTileX(to) - ScriptMap::GetTileX(tile)) - 427 * abs(ScriptMap::GetTileY(to) - ScriptMap::GetTileY(tile))) <= 1) || 428 * (ScriptMap::GetTileX(from) == ScriptMap::GetTileX(tile) && ScriptMap::GetTileX(tile) == ScriptMap::GetTileX(to)) || 429 * (ScriptMap::GetTileY(from) == ScriptMap::GetTileY(tile) && ScriptMap::GetTileY(tile) == ScriptMap::GetTileY(to)). 430 * @game @pre Valid ScriptCompanyMode active in scope. 431 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 432 * @return Whether the rail has been/can be removed or not. 433 */ 434 static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to); 435 436 /** 437 * Get the SignalType of the signal on a tile or SIGNALTYPE_NONE if there is no signal. 438 * @pre ScriptMap::DistanceManhattan(tile, front) == 1. 439 * @param tile The tile that might have a signal. 440 * @param front The tile in front of 'tile'. 441 * @return The SignalType of the signal on 'tile' facing to 'front'. 442 */ 443 static SignalType GetSignalType(TileIndex tile, TileIndex front); 444 445 /** 446 * Build a signal on a tile. 447 * @param tile The tile to build on. 448 * @param front The tile in front of the signal. 449 * @param signal The SignalType to build. 450 * @pre ScriptMap::DistanceManhattan(tile, front) == 1. 451 * @pre IsRailTile(tile) && !IsRailStationTile(tile) && !IsRailWaypointTile(tile). 452 * @game @pre Valid ScriptCompanyMode active in scope. 453 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 454 * @return Whether the signal has been/can be build or not. 455 */ 456 static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal); 457 458 /** 459 * Remove a signal. 460 * @param tile The tile to remove the signal from. 461 * @param front The tile in front of the signal. 462 * @pre ScriptMap::DistanceManhattan(tile, front) == 1. 463 * @pre GetSignalType(tile, front) != SIGNALTYPE_NONE. 464 * @game @pre Valid ScriptCompanyMode active in scope. 465 * @exception ScriptRail::ERR_UNSUITABLE_TRACK 466 * @return Whether the signal has been/can be removed or not. 467 */ 468 static bool RemoveSignal(TileIndex tile, TileIndex front); 469 470 /** 471 * Get the baseprice of building a rail-related object. 472 * @param railtype the railtype that is build (on) 473 * @param build_type the type of object to build 474 * @pre IsRailTypeAvailable(railtype) 475 * @return The baseprice of building the given object. 476 */ 477 static Money GetBuildCost(RailType railtype, BuildType build_type); 478 479 /** 480 * Get the maximum speed of trains running on this railtype. 481 * @param railtype The railtype to get the maximum speed of. 482 * @pre IsRailTypeAvailable(railtype) 483 * @return The maximum speed trains can run on this railtype 484 * or 0 if there is no limit. 485 * @note The speed is in OpenTTD's internal speed unit. 486 * This is mph / 1.6, which is roughly km/h. 487 * To get km/h multiply this number by 1.00584. 488 */ 489 static int32 GetMaxSpeed(RailType railtype); 490 491 /** 492 * Get the maintenance cost factor of a railtype. 493 * @param railtype The railtype to get the maintenance factor of. 494 * @pre IsRailTypeAvailable(railtype) 495 * @return Maintenance cost factor of the railtype. 496 */ 497 static uint16 GetMaintenanceCostFactor(RailType railtype); 498 }; 499 500 #endif /* SCRIPT_RAIL_HPP */ 501