src/ai/api/ai_road.cpp
author glx
Sat, 14 Jul 2007 23:35:46 +0000
branchnoai
changeset 9659 ff5908205170
parent 9624 b71483f2330f
child 9694 e72987579514
permissions -rw-r--r--
(svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     1
/* $Id$ */
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     2
9513
258f78c74b0c (svn r9410) [NoAI] -Fix: some copy-paste mistakes...
rubidium
parents: 9504
diff changeset
     3
/** @file ai_road.cpp handles the functions of the AIRoad class */
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     4
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     5
#include "ai_road.hpp"
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     6
#include "../../command.h"
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     7
#include "../../road_map.h"
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     8
#include "../../station_map.h"
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     9
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    10
bool AIRoad::IsRoadTile(TileIndex tile)
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    11
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    12
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    13
	if (tile >= ::MapSize()) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    14
9556
65417763fa24 (svn r9494) [NoAI] -Fix: IsRoadTile returns true for all tiles that can be used to traverse a tile. This includes drive through road stops and excluded 'normal' road stations and road depots.
rubidium
parents: 9551
diff changeset
    15
	return (::IsTileType(tile, MP_STREET) && ::GetRoadTileType(tile) != ROAD_TILE_DEPOT) ||
65417763fa24 (svn r9494) [NoAI] -Fix: IsRoadTile returns true for all tiles that can be used to traverse a tile. This includes drive through road stops and excluded 'normal' road stations and road depots.
rubidium
parents: 9551
diff changeset
    16
			this->IsDriveThroughRoadStationTile(tile);
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    17
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    18
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    19
bool AIRoad::IsRoadDepotTile(TileIndex tile)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    20
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    21
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    22
	if (tile >= ::MapSize()) return false;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    23
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    24
	return ::IsTileType(tile, MP_STREET) && ::GetRoadTileType(tile) == ROAD_TILE_DEPOT;
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    25
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    26
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    27
bool AIRoad::IsRoadStationTile(TileIndex tile)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    28
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    29
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    30
	if (tile >= ::MapSize()) return false;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    31
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    32
	return ::IsRoadStopTile(tile);
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    33
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    34
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    35
bool AIRoad::IsDriveThroughRoadStationTile(TileIndex tile)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    36
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    37
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    38
	if (tile >= ::MapSize()) return false;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    39
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    40
	return ::IsDriveThroughStopTile(tile);
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    41
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    42
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    43
bool AIRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    44
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    45
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    46
	if (t1 >= ::MapSize() || t2 >= ::MapSize()) return false;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    47
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    48
	/* Tiles not neighbouring */
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    49
	if ((abs((int)::TileX(t1) - (int)::TileX(t2)) + abs((int)::TileY(t1) - (int)::TileY(t2))) != 1) return false;
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    50
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
    51
	RoadBits r1 = ::GetAnyRoadBits(t1, ROADTYPE_ROAD);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
    52
	RoadBits r2 = ::GetAnyRoadBits(t2, ROADTYPE_ROAD);
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    53
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    54
	DiagDirection dir_1 = (DiagDirection)((::TileX(t1) == ::TileX(t2)) ? (::TileY(t1) < ::TileY(t2) ? 2 : 0) : (::TileX(t1) < ::TileX(t2) ? 1 : 3));
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    55
	DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    56
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    57
	return HASBIT(r1, dir_1) && HASBIT(r2, dir_2);
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    58
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    59
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    60
int32 AIRoad::GetNeighbourRoadCount(TileIndex tile)
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    61
{
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    62
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    63
	if (tile >= ::MapSize()) return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    64
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    65
	int32 neighbour = 0;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    66
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    67
	if (::IsTileType(tile + ::TileDiffXY(-1, 0), MP_STREET) && ::GetRoadTileType(tile + ::TileDiffXY(-1, 0)) != ROAD_TILE_DEPOT) neighbour++;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    68
	if (::IsTileType(tile + ::TileDiffXY( 1, 0), MP_STREET) && ::GetRoadTileType(tile + ::TileDiffXY( 1, 0)) != ROAD_TILE_DEPOT) neighbour++;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    69
	if (::IsTileType(tile + ::TileDiffXY( 0,-1), MP_STREET) && ::GetRoadTileType(tile + ::TileDiffXY( 0,-1)) != ROAD_TILE_DEPOT) neighbour++;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    70
	if (::IsTileType(tile + ::TileDiffXY( 0, 1), MP_STREET) && ::GetRoadTileType(tile + ::TileDiffXY( 0, 1)) != ROAD_TILE_DEPOT) neighbour++;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    71
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    72
	return neighbour;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    73
}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    74
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    75
TileIndex AIRoad::GetRoadDepotFrontTile(TileIndex depot)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    76
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    77
	if (!this->IsRoadDepotTile(depot)) return INVALID_TILE;
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    78
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    79
	return depot + ::TileOffsByDiagDir(::GetRoadDepotDirection(depot));
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    80
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    81
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    82
TileIndex AIRoad::GetRoadStationFrontTile(TileIndex station)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    83
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    84
	if (!this->IsRoadStationTile(station)) return INVALID_TILE;
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    85
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    86
	return station + ::TileOffsByDiagDir(::GetRoadStopDir(station));
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    87
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    88
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    89
TileIndex AIRoad::GetDriveThroughBackTile(TileIndex station)
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    90
{
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    91
	if (!this->IsDriveThroughRoadStationTile(station)) return INVALID_TILE;
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    92
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    93
	return station + ::TileOffsByDiagDir(::ReverseDiagDir(::GetRoadStopDir(station)));
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    94
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    95
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    96
bool AIRoad::BuildRoad(TileIndex start, TileIndex end)
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    97
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    98
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
    99
	if (start >= ::MapSize() || end >= ::MapSize() || start == end) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   100
	/* Not on one line */
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   101
	if (TileX(start) != TileX(end) &&
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   102
			TileY(start) != TileY(end)) return false;
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   103
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   104
	return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_BUILD_LONG_ROAD);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   105
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   106
9659
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   107
bool AIRoad::BuildRoadFull(TileIndex start, TileIndex end)
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   108
{
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   109
	/* Outside of the map */
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   110
	if (start >= ::MapSize() || end >= ::MapSize() || start == end) return false;
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   111
	/* Not on one line */
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   112
	if (TileX(start) != TileX(end) &&
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   113
			TileY(start) != TileY(end)) return false;
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   114
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   115
	return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_BUILD_LONG_ROAD);
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   116
}
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   117
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   118
bool AIRoad::BuildRoadDepot(TileIndex tile, TileIndex front)
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   119
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   120
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
   121
	if (tile >= ::MapSize() || tile == front) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   122
9504
de4993fa3d98 (svn r9395) [NoAI] -Fix r9331: some AIRoad() depot and station directions were wrong (Zuu)
glx
parents: 9503
diff changeset
   123
	uint entrance_dir = (TileX(tile) == TileX(front)) ? (TileY(tile) < TileY(front) ? 1 : 3) : (TileX(tile) < TileX(front) ? 2 : 0);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   124
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   125
	return this->DoCommand(tile, entrance_dir, ROADTYPE_ROAD << 2, CMD_BUILD_ROAD_DEPOT);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   126
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   127
9503
821422c9ca59 (svn r9381) [NoAI] -Fix: inconsistency between documentation and actual behaviour (Zuu).
rubidium
parents: 9486
diff changeset
   128
bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, bool truck, bool drive_through)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   129
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   130
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
   131
	if (tile >= ::MapSize() || tile == front) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   132
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   133
	uint entrance_dir;
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   134
	if (drive_through) {
9482
5e0418292ecc (svn r9331) [NoAI] -Fix: AIRoad() had most directions wrong, should be okay now
truelight
parents: 9453
diff changeset
   135
		entrance_dir = TileY(tile) != TileY(front);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   136
	} else {
9504
de4993fa3d98 (svn r9395) [NoAI] -Fix r9331: some AIRoad() depot and station directions were wrong (Zuu)
glx
parents: 9503
diff changeset
   137
		entrance_dir = (TileX(tile) == TileX(front)) ? (TileY(tile) < TileY(front) ? 1 : 3) : (TileX(tile) < TileX(front) ? 2 : 0);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   138
	}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   139
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   140
	return this->DoCommand(tile, entrance_dir, (drive_through ? 2 : 0) | (truck ? 1 : 0) | (ROADTYPES_ROAD << 2), CMD_BUILD_ROAD_STOP);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   141
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   142
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   143
bool AIRoad::RemoveRoad(TileIndex start, TileIndex end)
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   144
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   145
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
   146
	if (start >= ::MapSize() || end >= ::MapSize()) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   147
	/* Not on one line */
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   148
	if (TileX(start) != TileX(end) &&
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   149
			TileY(start) != TileY(end)) return false;
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   150
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   151
	return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_REMOVE_LONG_ROAD);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   152
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   153
9659
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   154
bool AIRoad::RemoveRoadFull(TileIndex start, TileIndex end)
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   155
{
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   156
	/* Outside of the map */
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   157
	if (start >= ::MapSize() || end >= ::MapSize()) return false;
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   158
	/* Not on one line */
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   159
	if (TileX(start) != TileX(end) &&
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   160
			TileY(start) != TileY(end)) return false;
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   161
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   162
	return this->DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_REMOVE_LONG_ROAD);
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   163
}
ff5908205170 (svn r10568) [NoAI] -Add: {Build|Remove}RoadFull(). These functions have the same behaviour as {Build|Remove}Road(), except road is built/removed on both halves of ending tiles (ie build a sloped road on sloped tile instead half road with fundations)
glx
parents: 9624
diff changeset
   164
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   165
bool AIRoad::RemoveRoadDepot(TileIndex tile)
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   166
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   167
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
   168
	if (tile >= ::MapSize()) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   169
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   170
	/* Not a road depot tile */
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   171
	if (!IsTileType(tile, MP_STREET) || GetRoadTileType(tile) != ROAD_TILE_DEPOT) return false;
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   172
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9483
diff changeset
   173
	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   174
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   175
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   176
bool AIRoad::RemoveRoadStation(TileIndex tile)
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   177
{
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   178
	/* Outside of the map */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9617
diff changeset
   179
	if (tile >= ::MapSize()) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   180
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   181
	/* Not a road station tile */
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   182
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile)) return false;
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   183
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9483
diff changeset
   184
	return this->DoCommand(tile, 0, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP);
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   185
}