script_road.hpp

Go to the documentation of this file.
00001 /* $Id: script_road.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_ROAD_HPP
00013 #define SCRIPT_ROAD_HPP
00014 
00015 #include "script_tile.hpp"
00016 
00021 class ScriptRoad : public ScriptObject {
00022 public:
00026   enum ErrorMessages {
00028     ERR_ROAD_BASE = ScriptError::ERR_CAT_ROAD << ScriptError::ERR_CAT_BIT_SIZE,
00029 
00031     ERR_ROAD_WORKS_IN_PROGRESS,                   // [STR_ERROR_ROAD_WORKS_IN_PROGRESS]
00032 
00034     ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION,       // [STR_ERROR_DRIVE_THROUGH_DIRECTION]
00035 
00037     ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD,           // [STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD]
00038 
00039 
00041     ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, // [STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION]
00042   };
00043 
00047   enum RoadType {
00048     /* Note: these values represent part of the in-game RoadType enum */
00049     ROADTYPE_ROAD    = ::ROADTYPE_ROAD,    
00050     ROADTYPE_TRAM    = ::ROADTYPE_TRAM,    
00051 
00052     /* Custom added value, only valid for this API */
00053     ROADTYPE_INVALID = -1,                 
00054   };
00055 
00059   enum RoadVehicleType {
00060     ROADVEHTYPE_BUS,   
00061     ROADVEHTYPE_TRUCK, 
00062   };
00063 
00067   enum BuildType {
00068     BT_ROAD,       
00069     BT_DEPOT,      
00070     BT_BUS_STOP,   
00071     BT_TRUCK_STOP, 
00072   };
00073 
00080   static RoadVehicleType GetRoadVehicleTypeForCargo(CargoID cargo_type);
00081 
00090   static bool IsRoadTile(TileIndex tile);
00091 
00098   static bool IsRoadDepotTile(TileIndex tile);
00099 
00106   static bool IsRoadStationTile(TileIndex tile);
00107 
00115   static bool IsDriveThroughRoadStationTile(TileIndex tile);
00116 
00123   static bool IsRoadTypeAvailable(RoadType road_type);
00124 
00129   static RoadType GetCurrentRoadType();
00130 
00135   static void SetCurrentRoadType(RoadType road_type);
00136 
00145   static bool HasRoadType(TileIndex tile, RoadType road_type);
00146 
00159   static bool AreRoadTilesConnected(TileIndex tile_from, TileIndex tile_to);
00160 
00190   static int32 CanBuildConnectedRoadParts(ScriptTile::Slope slope, struct Array *existing, TileIndex start, TileIndex end);
00191 
00211   static int32 CanBuildConnectedRoadPartsHere(TileIndex tile, TileIndex start, TileIndex end);
00212 
00220   static int32 GetNeighbourRoadCount(TileIndex tile);
00221 
00228   static TileIndex GetRoadDepotFrontTile(TileIndex depot);
00229 
00236   static TileIndex GetRoadStationFrontTile(TileIndex station);
00237 
00246   static TileIndex GetDriveThroughBackTile(TileIndex station);
00247 
00269   static bool BuildRoad(TileIndex start, TileIndex end);
00270 
00297   static bool BuildOneWayRoad(TileIndex start, TileIndex end);
00298 
00321   static bool BuildRoadFull(TileIndex start, TileIndex end);
00322 
00350   static bool BuildOneWayRoadFull(TileIndex start, TileIndex end);
00351 
00365   static bool BuildRoadDepot(TileIndex tile, TileIndex front);
00366 
00390   static bool BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
00391 
00415   static bool BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
00416 
00433   static bool RemoveRoad(TileIndex start, TileIndex end);
00434 
00452   static bool RemoveRoadFull(TileIndex start, TileIndex end);
00453 
00464   static bool RemoveRoadDepot(TileIndex tile);
00465 
00476   static bool RemoveRoadStation(TileIndex tile);
00477 
00485   static Money GetBuildCost(RoadType roadtype, BuildType build_type);
00486 
00493   static uint16 GetMaintenanceCostFactor(RoadType roadtype);
00494 
00495 private:
00496 
00500   static bool _BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full);
00501 
00505   static bool _BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id);
00506 };
00507 
00508 #endif /* SCRIPT_ROAD_HPP */