rubidium@9453: /* $Id$ */ rubidium@9453: rubidium@9595: /** @file ai_road.hpp Everything to query and build roads */ rubidium@9453: rubidium@9453: #ifndef AI_ROAD_HPP rubidium@9453: #define AI_ROAD_HPP rubidium@9453: rubidium@9453: #include "ai_object.hpp" rubidium@9453: rubidium@9453: /** rubidium@9453: * Class that handles all road related functions. rubidium@9453: * rubidium@9453: * Roads are always build from tile center to tile center. rubidium@9453: * Furthermore stations and depots need to be build on tiles rubidium@9453: * that already have road on them. For depots and non-drive rubidium@9453: * through stations that means that only one roadbit may be rubidium@9453: * built at the location. The advantage of this method is rubidium@9453: * that the AI does not need to think about pointing the rubidium@9453: * exit of the depots and roadstations towards the correct rubidium@9453: * direction. For drive-through roadstops this works about rubidium@9453: * the same, though they have to be built on straight roads. rubidium@9453: */ rubidium@9453: class AIRoad : public AIObject { rubidium@9453: public: rubidium@9453: /** truelight@9529: * The name of the class, needed by several sub-processes. truelight@9529: */ truelight@9529: static const char *GetClassName() { return "AIRoad"; } truelight@9529: truelight@9529: /** rubidium@9556: * Checks whether the given tile is actually a tile with road that rubidium@9556: * can be used to traverse a tile. This excludes road depots and rubidium@9556: * 'normal' road stations, but includes drive through stations. rubidium@9453: * @param tile the tile to check. rubidium@9453: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @return true if and only if the tile has road. rubidium@9453: */ rubidium@9453: bool IsRoadTile(TileIndex tile); rubidium@9453: rubidium@9453: /** rubidium@9551: * Checks whether the given tile is actually a tile with a road depot. rubidium@9551: * @param tile the tile to check. rubidium@9551: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9551: * @return true if and only if the tile has a road depot. rubidium@9551: */ rubidium@9551: bool IsRoadDepotTile(TileIndex tile); rubidium@9551: rubidium@9551: /** rubidium@9551: * Checks whether the given tile is actually a tile with a road station. rubidium@9551: * @param tile the tile to check. rubidium@9551: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9551: * @return true if and only if the tile has a road station. rubidium@9551: */ rubidium@9551: bool IsRoadStationTile(TileIndex tile); rubidium@9551: rubidium@9551: /** rubidium@9551: * Checks whether the given tile is actually a tile with a drive through rubidium@9551: * road station. rubidium@9551: * @param tile the tile to check. rubidium@9551: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9551: * @return true if and only if the tile has a drive through road station. rubidium@9551: */ rubidium@9551: bool IsDriveThroughRoadStationTile(TileIndex tile); rubidium@9551: rubidium@9551: /** rubidium@9551: * Checks whether the given tiles are directly connected, i.e. whether rubidium@9551: * a road vehicle can travel from the center of the first tile to the rubidium@9551: * center of the second tile. rubidium@9551: * @param t1 the source tile. rubidium@9551: * @param t2 the destination tile. rubidium@9551: * @pre t1 is always positive and smaller than AIMap::GetMapSize(). rubidium@9551: * @pre t2 is always positive and smaller than AIMap::GetMapSize(). rubidium@9551: * @pre t1 and t2 are directly neighbouring tiles. rubidium@9551: * @return true if and only if a road vehicle can go from t1 to t2. rubidium@9551: */ rubidium@9551: bool AreRoadTilesConnected(TileIndex t1, TileIndex t2); rubidium@9551: rubidium@9551: /** truelight@9617: * Count how many neighbours are road. truelight@9617: * @pre tile is always positive and smaller than AIMap::GetMapSize(). truelight@9617: * @param tile the tile to check on. truelight@9617: * @return 0 means no neighbour road; max value is 4. truelight@9617: */ truelight@9617: static int32 GetNeighbourRoadCount(TileIndex tile); truelight@9617: truelight@9617: /** rubidium@9551: * Gets the tile in front of a road depot. rubidium@9551: * @param depot the road depot tile. rubidium@9551: * @pre IsRoadDepotTile(depot). rubidium@9551: * @return the tile in front of the depot. rubidium@9551: */ rubidium@9551: TileIndex GetRoadDepotFrontTile(TileIndex depot); rubidium@9551: rubidium@9551: /** rubidium@9551: * Gets the tile in front of a road station. rubidium@9551: * @param station the road station tile. rubidium@9551: * @pre IsRoadStationTile(station). rubidium@9551: * @return the tile in front of the road station. rubidium@9551: */ rubidium@9551: TileIndex GetRoadStationFrontTile(TileIndex station); rubidium@9551: rubidium@9551: /** rubidium@9551: * Gets the tile at the back of a drive through road station. rubidium@9551: * So, one side of the drive through station is retrieved with rubidium@9551: * GetTileInFrontOfStation, the other with this function. rubidium@9551: * @param station the road station tile. rubidium@9551: * @pre IsDriveThroughRoadStationTile(station). rubidium@9551: * @return the tile at the back of the drive through road station. rubidium@9551: */ rubidium@9551: TileIndex GetDriveThroughBackTile(TileIndex station); rubidium@9551: rubidium@9551: /** rubidium@9453: * Builds a road from the center of tile start to the rubidium@9453: * center of tile end. rubidium@9453: * @param start the start tile of the road. rubidium@9453: * @param end the end tile of the road. rubidium@9453: * @pre start is not equal to end rubidium@9453: * @pre start is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre end is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre start and end are in a straight line, i.e. rubidium@9453: * AIMap::GetTileX(start) == AIMap::GetTileX(end) or rubidium@9453: * AIMap::GetTileY(start) == AIMap::GetTileY(end). rubidium@9453: * @return whether the road has been/can be build or not. rubidium@9453: */ rubidium@9453: bool BuildRoad(TileIndex start, TileIndex end); rubidium@9453: rubidium@9453: /** glx@9659: * Builds a road from the edge of tile start to the glx@9659: * edge of tile end (both included). glx@9659: * @param start the start tile of the road. glx@9659: * @param end the end tile of the road. glx@9659: * @pre start is not equal to end glx@9659: * @pre start is always positive and smaller than AIMap::GetMapSize(). glx@9659: * @pre end is always positive and smaller than AIMap::GetMapSize(). glx@9659: * @pre start and end are in a straight line, i.e. glx@9659: * AIMap::GetTileX(start) == AIMap::GetTileX(end) or glx@9659: * AIMap::GetTileY(start) == AIMap::GetTileY(end). glx@9659: * @return whether the road has been/can be build or not. glx@9659: */ glx@9659: bool BuildRoadFull(TileIndex start, TileIndex end); glx@9659: glx@9659: /** rubidium@9453: * Builds a road depot. rubidium@9453: * @param tile place to build the depot. rubidium@9453: * @param front the tile exactly in front of the depot rubidium@9453: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre front is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre tile is not equal to front rubidium@9453: * @return whether the road depot has been/can be build or not. rubidium@9453: */ rubidium@9453: bool BuildRoadDepot(TileIndex tile, TileIndex front); rubidium@9453: rubidium@9453: /** rubidium@9453: * Builds a road bus or truck station. rubidium@9453: * @param tile place to build the depot. rubidium@9453: * @param front the tile exactly in front of the station. rubidium@9453: * For drive-through stations either entrance side can be used. rubidium@9503: * @param truck whether to build a truck (true) or bus (false) station. rubidium@9453: * @param drive_through whether to make the station drive through or not. rubidium@9453: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre front is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre tile is not equal to front rubidium@9453: * @return whether the station has been/can be build or not. rubidium@9453: */ rubidium@9503: bool BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through); rubidium@9453: rubidium@9453: /** rubidium@9453: * Removes a road from the center of tile start to the rubidium@9453: * center of tile end. rubidium@9453: * @param start the start tile of the road. rubidium@9453: * @param end the end tile of the road. rubidium@9453: * @pre start is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre end is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre start and end are in a straight line, i.e. rubidium@9453: * AIMap::GetTileX(start) == AIMap::GetTileX(end) or rubidium@9453: * AIMap::GetTileY(start) == AIMap::GetTileY(end). rubidium@9453: * @return whether the road has been/can be removed or not. rubidium@9453: */ rubidium@9453: bool RemoveRoad(TileIndex start, TileIndex end); rubidium@9453: rubidium@9453: /** glx@9659: * Removes a road from the edge of tile start to the glx@9659: * edge of tile end (both included). glx@9659: * @param start the start tile of the road. glx@9659: * @param end the end tile of the road. glx@9659: * @pre start is always positive and smaller than AIMap::GetMapSize(). glx@9659: * @pre end is always positive and smaller than AIMap::GetMapSize(). glx@9659: * @pre start and end are in a straight line, i.e. glx@9659: * AIMap::GetTileX(start) == AIMap::GetTileX(end) or glx@9659: * AIMap::GetTileY(start) == AIMap::GetTileY(end). glx@9659: * @return whether the road has been/can be removed or not. glx@9659: */ glx@9659: bool RemoveRoadFull(TileIndex start, TileIndex end); glx@9659: glx@9659: /** rubidium@9453: * Removes a road depot. rubidium@9453: * @param tile place to remove the depot from. rubidium@9453: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre tile is a road depot. rubidium@9453: * @return whether the road depot has been/can be removed or not. rubidium@9453: */ rubidium@9453: bool RemoveRoadDepot(TileIndex tile); rubidium@9453: rubidium@9453: /** rubidium@9453: * Removes a road bus or truck station. rubidium@9453: * @param tile place to remove the station from. rubidium@9453: * @pre tile is always positive and smaller than AIMap::GetMapSize(). rubidium@9453: * @pre tile is a road station. rubidium@9453: * @return whether the station has been/can be removed or not. rubidium@9453: */ rubidium@9453: bool RemoveRoadStation(TileIndex tile); rubidium@9453: }; rubidium@9453: rubidium@9453: #endif /* AI_ROAD_HPP */