rubidium@9453: /* $Id$ */ rubidium@9453: truebrain@9829: /** @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@10091: #include "ai_error.hpp" rubidium@9453: rubidium@9453: /** rubidium@9453: * Class that handles all road related functions. rubidium@9453: */ rubidium@9453: class AIRoad : public AIObject { rubidium@9453: public: truelight@9529: static const char *GetClassName() { return "AIRoad"; } truelight@9529: truebrain@10096: /** truebrain@10096: * All road related error messages. truebrain@10096: */ rubidium@10091: enum ErrorMessages { rubidium@10091: /** Base for road building / maintaining errors */ rubidium@10091: ERR_ROAD_BASE = AIError::ERR_CAT_ROAD << AIError::ERR_CAT_BIT_SIZE, rubidium@10091: rubidium@10091: /** Road works are in progress */ rubidium@10091: ERR_ROAD_WORKS_IN_PROGRESS, // [STR_ROAD_WORKS_IN_PROGRESS] rubidium@10091: rubidium@10091: /** Drive through is in the wrong direction */ rubidium@10091: ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION, // [STR_DRIVE_THROUGH_ERROR_DIRECTION] rubidium@10091: rubidium@10091: /** Drive through roads can't be build on town owned roads */ rubidium@10091: ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD, // [STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD] rubidium@10091: rubidium@10091: rubidium@10091: /** One way roads can't have junctions */ rubidium@10091: ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, // [STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION] rubidium@10091: }; rubidium@10091: truelight@9529: /** truebrain@9838: * Checks whether the given tile is actually a tile with road that can be truebrain@9838: * used to traverse a tile. This excludes road depots and 'normal' road truebrain@9838: * stations, but includes drive through stations. truebrain@9838: * @param tile The tile to check. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if and only if the tile has road. rubidium@9453: */ truebrain@9737: static bool IsRoadTile(TileIndex tile); rubidium@9453: rubidium@9453: /** rubidium@9551: * Checks whether the given tile is actually a tile with a road depot. truebrain@9838: * @param tile The tile to check. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if and only if the tile has a road depot. rubidium@9551: */ truebrain@9737: static bool IsRoadDepotTile(TileIndex tile); rubidium@9551: rubidium@9551: /** rubidium@9551: * Checks whether the given tile is actually a tile with a road station. truebrain@9838: * @param tile The tile to check. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if and only if the tile has a road station. rubidium@9551: */ truebrain@9737: static bool IsRoadStationTile(TileIndex tile); rubidium@9551: rubidium@9551: /** rubidium@9551: * Checks whether the given tile is actually a tile with a drive through truebrain@9838: * road station. truebrain@9838: * @param tile The tile to check. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if and only if the tile has a drive through road station. rubidium@9551: */ truebrain@9737: static bool IsDriveThroughRoadStationTile(TileIndex tile); rubidium@9551: rubidium@9551: /** rubidium@9551: * Checks whether the given tiles are directly connected, i.e. whether truebrain@9838: * a road vehicle can travel from the center of the first tile to the truebrain@9838: * center of the second tile. truebrain@9838: * @param tile_from The source tile. truebrain@9838: * @param tile_to The destination tile. truebrain@9838: * @pre AIMap::IsValidTile(tile_from). truebrain@9838: * @pre AIMap::IsValidTile(tile_to). truebrain@9838: * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles. truebrain@9838: * @return True if and only if a road vehicle can go from tile_from to tile_to. rubidium@9551: */ truebrain@9838: static bool AreRoadTilesConnected(TileIndex tile_from, TileIndex tile_to); rubidium@9551: rubidium@9551: /** truelight@9617: * Count how many neighbours are road. truebrain@9838: * @param tile The tile to check on. truebrain@9801: * @pre AIMap::IsValidTile(tile). 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. truebrain@9838: * @param depot The road depot tile. rubidium@9551: * @pre IsRoadDepotTile(depot). truebrain@9838: * @return The tile in front of the depot. rubidium@9551: */ truebrain@9737: static TileIndex GetRoadDepotFrontTile(TileIndex depot); rubidium@9551: rubidium@9551: /** rubidium@9551: * Gets the tile in front of a road station. truebrain@9838: * @param station The road station tile. rubidium@9551: * @pre IsRoadStationTile(station). truebrain@9838: * @return The tile in front of the road station. rubidium@9551: */ truebrain@9737: static TileIndex GetRoadStationFrontTile(TileIndex station); rubidium@9551: rubidium@9551: /** rubidium@9551: * Gets the tile at the back of a drive through road station. truebrain@9838: * So, one side of the drive through station is retrieved with truebrain@9838: * GetTileInFrontOfStation, the other with this function. truebrain@9838: * @param station The road station tile. rubidium@9551: * @pre IsDriveThroughRoadStationTile(station). truebrain@9838: * @return The tile at the back of the drive through road station. rubidium@9551: */ truebrain@9737: static TileIndex GetDriveThroughBackTile(TileIndex station); rubidium@9551: rubidium@9551: /** truebrain@9838: * Builds a road from the center of tile start to the center of tile end. truebrain@9838: * @param start The start tile of the road. truebrain@9838: * @param end The end tile of the road. truebrain@9838: * @pre 'start' is not equal to 'end'. truebrain@9801: * @pre AIMap::IsValidTile(start). truebrain@9801: * @pre AIMap::IsValidTile(end). truebrain@9838: * @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@10091: * @exception AIError::ERR_ALREADY_BUILT rubidium@10091: * @exception AIError::ERR_LAND_SLOPED_WRONG rubidium@10091: * @exception AIError::ERR_AREA_NOT_CLEAR rubidium@10091: * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS rubidium@10091: * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS rubidium@10094: * @exception AIError::ERR_VEHICLE_IN_THE_WAY truebrain@9838: * @return Whether the road has been/can be build or not. rubidium@9453: */ truebrain@9737: static bool BuildRoad(TileIndex start, TileIndex end); rubidium@9453: rubidium@9453: /** truebrain@9838: * Builds a road from the edge of tile start to the edge of tile end (both truebrain@9838: * included). truebrain@9838: * @param start The start tile of the road. truebrain@9838: * @param end The end tile of the road. truebrain@9838: * @pre 'start' is not equal to 'end'. truebrain@9801: * @pre AIMap::IsValidTile(start). truebrain@9801: * @pre AIMap::IsValidTile(end). truebrain@9838: * @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). rubidium@10091: * @exception AIError::ERR_ALREADY_BUILT rubidium@10091: * @exception AIError::ERR_LAND_SLOPED_WRONG rubidium@10091: * @exception AIError::ERR_AREA_NOT_CLEAR rubidium@10091: * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS rubidium@10091: * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS rubidium@10094: * @exception AIError::ERR_VEHICLE_IN_THE_WAY truebrain@9838: * @return Whether the road has been/can be build or not. glx@9659: */ truebrain@9737: static bool BuildRoadFull(TileIndex start, TileIndex end); glx@9659: glx@9659: /** rubidium@9453: * Builds a road depot. truebrain@9838: * @param tile Place to build the depot. truebrain@9838: * @param front The tile exactly in front of the depot. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9801: * @pre AIMap::IsValidTile(front). truebrain@9838: * @pre Tile is not equal to front. rubidium@10091: * @exception AIError::ERR_FLAT_LAND_REQUIRED rubidium@10091: * @exception AIError::ERR_AREA_NOT_CLEAR truebrain@9838: * @return Whether the road depot has been/can be build or not. rubidium@9453: */ truebrain@9737: static bool BuildRoadDepot(TileIndex tile, TileIndex front); rubidium@9453: rubidium@9453: /** rubidium@9453: * Builds a road bus or truck station. truebrain@9838: * @param tile Place to build the depot. truebrain@9838: * @param front The tile exactly in front of the station. rubidium@9453: * For drive-through stations either entrance side can be used. truebrain@9838: * @param truck Whether to build a truck (true) or bus (false) station. truebrain@9838: * @param drive_through Whether to make the station drive through or not. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9801: * @pre AIMap::IsValidTile(front). truebrain@9838: * @pre 'tile' is not equal to 'front'. rubidium@10091: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10091: * @exception AIError::ERR_AREA_NOT_CLEAR rubidium@10091: * @exception AIError::ERR_FLAT_LAND_REQUIRED rubidium@10091: * @exception AIRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION rubidium@10091: * @exception AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD rubidium@10094: * @exception AIError:ERR_VEHICLE_IN_THE_WAY rubidium@10094: * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION rubidium@10094: * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS rubidium@10094: * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN truebrain@9838: * @return Whether the station has been/can be build or not. rubidium@9453: */ truebrain@9737: static bool BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through); rubidium@9453: rubidium@9453: /** truebrain@9838: * Removes a road from the center of tile start to the center of tile end. truebrain@9838: * @param start The start tile of the road. truebrain@9838: * @param end The end tile of the road. truebrain@9801: * @pre AIMap::IsValidTile(start). truebrain@9801: * @pre AIMap::IsValidTile(end). truebrain@9838: * @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@10091: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10094: * @exception AIError::ERR_VEHICLE_IN_THE_WAY rubidium@10091: * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS truebrain@9838: * @return Whether the road has been/can be removed or not. rubidium@9453: */ truebrain@9737: static bool RemoveRoad(TileIndex start, TileIndex end); rubidium@9453: rubidium@9453: /** truebrain@9838: * Removes a road from the edge of tile start to the edge of tile end (both truebrain@9838: * included). truebrain@9838: * @param start The start tile of the road. truebrain@9838: * @param end The end tile of the road. truebrain@9801: * @pre AIMap::IsValidTile(start). truebrain@9801: * @pre AIMap::IsValidTile(end). truebrain@9838: * @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). rubidium@10091: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10094: * @exception AIError::ERR_VEHICLE_IN_THE_WAY rubidium@10091: * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS truebrain@9838: * @return Whether the road has been/can be removed or not. glx@9659: */ truebrain@9737: static bool RemoveRoadFull(TileIndex start, TileIndex end); glx@9659: glx@9659: /** rubidium@9453: * Removes a road depot. truebrain@9838: * @param tile Place to remove the depot from. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @pre Tile is a road depot. rubidium@10091: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10094: * @exception AIError::ERR_VEHICLE_IN_THE_WAY truebrain@9838: * @return Whether the road depot has been/can be removed or not. rubidium@9453: */ truebrain@9737: static bool RemoveRoadDepot(TileIndex tile); rubidium@9453: rubidium@9453: /** rubidium@9453: * Removes a road bus or truck station. truebrain@9838: * @param tile Place to remove the station from. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @pre Tile is a road station. rubidium@10091: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10094: * @exception AIError::ERR_VEHICLE_IN_THE_WAY truebrain@9838: * @return Whether the station has been/can be removed or not. rubidium@9453: */ truebrain@9737: static bool RemoveRoadStation(TileIndex tile); rubidium@9453: }; rubidium@9453: rubidium@9453: #endif /* AI_ROAD_HPP */