(svn r9333) [NoAI] -Add: added DC_AUTO for DoCommand in AIRoad() to avoid building over existing structures we can remove
/* $Id$ */
/** @file ai_town.cpp handles the functions of the AIRoad class */
#include "ai_road.hpp"
#include "../../command.h"
#include "../../road_map.h"
#include "../../station_map.h"
bool AIRoad::IsRoadTile(TileIndex tile)
{
/* Outside of the map */
if (tile >= _map_size) return false;
return IsTileType(tile, MP_STREET) && GetRoadTileType(tile) != ROAD_TILE_DEPOT;
}
bool AIRoad::BuildRoad(TileIndex start, TileIndex end)
{
/* Outside of the map */
if (start >= _map_size || end >= _map_size || start == end) return false;
/* Not on one line */
if (TileX(start) != TileX(end) &&
TileY(start) != TileY(end)) return false;
return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | 3, DC_EXEC | DC_AUTO, CMD_BUILD_LONG_ROAD);
}
bool AIRoad::BuildRoadDepot(TileIndex tile, TileIndex front)
{
/* Outside of the map */
if (tile >= _map_size || tile == front) return false;
uint entrance_dir = (TileX(tile) == TileX(front)) ? (TileY(tile) < TileY(front) ? 3 : 1) : (TileX(tile) < TileX(front) ? 2: 0);
return this->DoCommand(tile, entrance_dir, 0, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD_DEPOT);
}
bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, bool bus, bool drive_through)
{
/* Outside of the map */
if (tile >= _map_size || tile == front) return false;
uint entrance_dir;
if (drive_through) {
entrance_dir = TileY(tile) != TileY(front);
} else {
entrance_dir = (TileX(tile) == TileX(front)) ? (TileY(tile) < TileY(front) ? 3 : 1) : (TileX(tile) < TileX(front) ? 2: 0);
}
return this->DoCommand(tile, entrance_dir, drive_through << 1 | bus, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD_STOP);
}
bool AIRoad::RemoveRoad(TileIndex start, TileIndex end)
{
/* Outside of the map */
if (start >= _map_size || end >= _map_size) return false;
/* Not on one line */
if (TileX(start) != TileX(end) &&
TileY(start) != TileY(end)) return false;
return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | 3, DC_EXEC, CMD_REMOVE_LONG_ROAD);
}
bool AIRoad::RemoveRoadDepot(TileIndex tile)
{
/* Outside of the map */
if (tile >= _map_size) return false;
/* Not a road depot tile */
if (!IsTileType(tile, MP_STREET) || GetRoadTileType(tile) != ROAD_TILE_DEPOT) return false;
return this->DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
}
bool AIRoad::RemoveRoadStation(TileIndex tile)
{
/* Outside of the map */
if (tile >= _map_size) return false;
/* Not a road station tile */
if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile)) return false;
return this->DoCommand(tile, 0, GetRoadStopType(tile), DC_EXEC, CMD_REMOVE_ROAD_STOP);
}