ai_road.hpp

Go to the documentation of this file.
00001 /* $Id: ai_road.hpp 21888 2011-01-22 10:33:16Z rubidium $ */
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_ROAD_HPP
00013 #define AI_ROAD_HPP
00014 
00015 #include "ai_tile.hpp"
00016 
00020 class AIRoad : public AIObject {
00021 public:
00023   static const char *GetClassName() { return "AIRoad"; }
00024 
00028   enum ErrorMessages {
00030     ERR_ROAD_BASE = AIError::ERR_CAT_ROAD << AIError::ERR_CAT_BIT_SIZE,
00031 
00033     ERR_ROAD_WORKS_IN_PROGRESS,                   // [STR_ERROR_ROAD_WORKS_IN_PROGRESS]
00034 
00036     ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION,       // [STR_ERROR_DRIVE_THROUGH_DIRECTION]
00037 
00039     ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD,           // [STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD]
00040 
00041 
00043     ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, // [STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION]
00044   };
00045 
00049   enum RoadType {
00050     /* Values are important, as they represent the internal state of the game. */
00051     ROADTYPE_ROAD = 0, 
00052     ROADTYPE_TRAM = 1, 
00053 
00054     ROADTYPE_INVALID = -1, 
00055   };
00056 
00060   enum RoadVehicleType {
00061     ROADVEHTYPE_BUS,   
00062     ROADVEHTYPE_TRUCK, 
00063   };
00064 
00068   enum BuildType {
00069     BT_ROAD,       
00070     BT_DEPOT,      
00071     BT_BUS_STOP,   
00072     BT_TRUCK_STOP, 
00073   };
00074 
00081   static RoadVehicleType GetRoadVehicleTypeForCargo(CargoID cargo_type);
00082 
00091   static bool IsRoadTile(TileIndex tile);
00092 
00099   static bool IsRoadDepotTile(TileIndex tile);
00100 
00107   static bool IsRoadStationTile(TileIndex tile);
00108 
00116   static bool IsDriveThroughRoadStationTile(TileIndex tile);
00117 
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(AITile::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 
00268   static bool BuildRoad(TileIndex start, TileIndex end);
00269 
00295   static bool BuildOneWayRoad(TileIndex start, TileIndex end);
00296 
00318   static bool BuildRoadFull(TileIndex start, TileIndex end);
00319 
00346   static bool BuildOneWayRoadFull(TileIndex start, TileIndex end);
00347 
00360   static bool BuildRoadDepot(TileIndex tile, TileIndex front);
00361 
00384   static bool BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
00385 
00408   static bool BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id);
00409 
00425   static bool RemoveRoad(TileIndex start, TileIndex end);
00426 
00443   static bool RemoveRoadFull(TileIndex start, TileIndex end);
00444 
00454   static bool RemoveRoadDepot(TileIndex tile);
00455 
00465   static bool RemoveRoadStation(TileIndex tile);
00466 
00474   static Money GetBuildCost(RoadType roadtype, BuildType build_type);
00475 
00476 private:
00477 
00481   static bool _BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full);
00482 
00486   static bool _BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id);
00487 };
00488 
00489 #endif /* AI_ROAD_HPP */