src/ai/api/ai_road.cpp
author truebrain
Thu, 28 Feb 2008 01:11:23 +0000
branchnoai
changeset 9803 c86d5834fb11
parent 9801 03a3eebd7fb7
child 9833 89a64246458f
permissions -rw-r--r--
(svn r12309) [NoAI] -Codechange: optimize a little bit (a very small little bit, but every bit counts :) ) (glx)
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 "../../road_map.h"
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     7
#include "../../station_map.h"
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
     8
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
     9
/* static */ bool AIRoad::IsRoadTile(TileIndex tile)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    10
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    11
	if (!::IsValidTile(tile)) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    12
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
    13
	return (::IsTileType(tile, MP_ROAD) && ::GetRoadTileType(tile) != ROAD_TILE_DEPOT) ||
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    14
			IsDriveThroughRoadStationTile(tile);
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    15
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    16
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    17
/* static */ bool AIRoad::IsRoadDepotTile(TileIndex tile)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    18
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    19
	if (!::IsValidTile(tile)) return false;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    20
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
    21
	return ::IsTileType(tile, MP_ROAD) && ::GetRoadTileType(tile) == ROAD_TILE_DEPOT;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    22
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    23
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    24
/* static */ bool AIRoad::IsRoadStationTile(TileIndex tile)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    25
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    26
	if (!::IsValidTile(tile)) return false;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    27
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    28
	return ::IsRoadStopTile(tile);
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    29
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    30
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    31
/* static */ bool AIRoad::IsDriveThroughRoadStationTile(TileIndex tile)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    32
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    33
	if (!::IsValidTile(tile)) return false;
9551
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
	return ::IsDriveThroughStopTile(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
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    38
/* static */ bool AIRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    39
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    40
	if (!::IsValidTile(t1)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    41
	if (!::IsValidTile(t2)) return false;
9551
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
	/* Tiles not neighbouring */
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    44
	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
    45
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
    46
	RoadBits r1 = ::GetAnyRoadBits(t1, ROADTYPE_ROAD);
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
    47
	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
    48
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    49
	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
    50
	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
    51
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9694
diff changeset
    52
	return HasBit(r1, dir_1) && HasBit(r2, dir_2);
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
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    55
/* static */ int32 AIRoad::GetNeighbourRoadCount(TileIndex tile)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    56
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    57
	if (!::IsValidTile(tile)) return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    58
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    59
	int32 neighbour = 0;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    60
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
    61
	if (::IsTileType(tile + ::TileDiffXY(-1, 0), MP_ROAD) && ::GetRoadTileType(tile + ::TileDiffXY(-1, 0)) != ROAD_TILE_DEPOT) neighbour++;
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
    62
	if (::IsTileType(tile + ::TileDiffXY( 1, 0), MP_ROAD) && ::GetRoadTileType(tile + ::TileDiffXY( 1, 0)) != ROAD_TILE_DEPOT) neighbour++;
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
    63
	if (::IsTileType(tile + ::TileDiffXY( 0,-1), MP_ROAD) && ::GetRoadTileType(tile + ::TileDiffXY( 0,-1)) != ROAD_TILE_DEPOT) neighbour++;
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
    64
	if (::IsTileType(tile + ::TileDiffXY( 0, 1), MP_ROAD) && ::GetRoadTileType(tile + ::TileDiffXY( 0, 1)) != ROAD_TILE_DEPOT) neighbour++;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    65
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    66
	return neighbour;
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    67
}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents: 9556
diff changeset
    68
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    69
/* static */ TileIndex AIRoad::GetRoadDepotFrontTile(TileIndex depot)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    70
{
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    71
	if (!IsRoadDepotTile(depot)) return INVALID_TILE;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    72
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    73
	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
    74
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    75
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    76
/* static */ TileIndex AIRoad::GetRoadStationFrontTile(TileIndex station)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    77
{
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    78
	if (!IsRoadStationTile(station)) return INVALID_TILE;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    79
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    80
	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
    81
}
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    82
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    83
/* static */ TileIndex AIRoad::GetDriveThroughBackTile(TileIndex station)
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    84
{
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    85
	if (!IsDriveThroughRoadStationTile(station)) return INVALID_TILE;
9551
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    86
d015a5b4b0a8 (svn r9489) [NoAI] -Add: functions to query existance and direction of road stations and depots.
rubidium
parents: 9513
diff changeset
    87
	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
    88
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    89
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    90
/* static */ bool AIRoad::BuildRoad(TileIndex start, TileIndex end)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    91
{
9803
c86d5834fb11 (svn r12309) [NoAI] -Codechange: optimize a little bit (a very small little bit, but every bit counts :) ) (glx)
truebrain
parents: 9801
diff changeset
    92
	if (start == end) return false;
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    93
	if (!::IsValidTile(start)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
    94
	if (!::IsValidTile(end)) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    95
	/* Not on one line */
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    96
	if (TileX(start) != TileX(end) &&
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
    97
			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
    98
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
    99
	return AIObject::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
   100
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   101
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   102
/* static */ bool AIRoad::BuildRoadFull(TileIndex start, TileIndex end)
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
   103
{
9803
c86d5834fb11 (svn r12309) [NoAI] -Codechange: optimize a little bit (a very small little bit, but every bit counts :) ) (glx)
truebrain
parents: 9801
diff changeset
   104
	if (start == end) return false;
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   105
	if (!::IsValidTile(start)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   106
	if (!::IsValidTile(end)) return false;
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
	/* 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
   108
	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
   109
			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
   110
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   111
	return AIObject::DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_BUILD_LONG_ROAD);
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
   112
}
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
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   114
/* static */ bool AIRoad::BuildRoadDepot(TileIndex tile, TileIndex front)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   115
{
9803
c86d5834fb11 (svn r12309) [NoAI] -Codechange: optimize a little bit (a very small little bit, but every bit counts :) ) (glx)
truebrain
parents: 9801
diff changeset
   116
	if (tile == front) return false;
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   117
	if (!::IsValidTile(tile)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   118
	if (!::IsValidTile(front)) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   119
9504
de4993fa3d98 (svn r9395) [NoAI] -Fix r9331: some AIRoad() depot and station directions were wrong (Zuu)
glx
parents: 9503
diff changeset
   120
	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
   121
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   122
	return AIObject::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
   123
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   124
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   125
/* static */ 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
   126
{
9803
c86d5834fb11 (svn r12309) [NoAI] -Codechange: optimize a little bit (a very small little bit, but every bit counts :) ) (glx)
truebrain
parents: 9801
diff changeset
   127
	if (tile == front) return false;
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   128
	if (!::IsValidTile(tile)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   129
	if (!::IsValidTile(front)) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   130
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   131
	uint entrance_dir;
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   132
	if (drive_through) {
9482
5e0418292ecc (svn r9331) [NoAI] -Fix: AIRoad() had most directions wrong, should be okay now
truelight
parents: 9453
diff changeset
   133
		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
   134
	} else {
9504
de4993fa3d98 (svn r9395) [NoAI] -Fix r9331: some AIRoad() depot and station directions were wrong (Zuu)
glx
parents: 9503
diff changeset
   135
		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
   136
	}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   137
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   138
	return AIObject::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
   139
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   140
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   141
/* static */ bool AIRoad::RemoveRoad(TileIndex start, TileIndex end)
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
   142
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   143
	if (!::IsValidTile(start)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   144
	if (!::IsValidTile(end)) return false;
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
   145
	/* 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
   146
	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
   147
			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
   148
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   149
	return AIObject::DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ROADTYPE_ROAD << 3), CMD_REMOVE_LONG_ROAD);
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
   150
}
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
   151
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   152
/* static */ bool AIRoad::RemoveRoadFull(TileIndex start, TileIndex end)
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   153
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   154
	if (!::IsValidTile(start)) return false;
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   155
	if (!::IsValidTile(end)) return false;
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   156
	/* Not on one line */
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   157
	if (TileX(start) != TileX(end) &&
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   158
			TileY(start) != TileY(end)) return false;
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   159
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   160
	return AIObject::DoCommand(end, start, (TileY(start) != TileY(end) ? 4 : 0) | (start < end ? 2 : 1), CMD_REMOVE_LONG_ROAD);
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   161
}
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   162
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   163
/* static */ bool AIRoad::RemoveRoadDepot(TileIndex tile)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   164
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   165
	if (!::IsValidTile(tile)) return false;
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9659
diff changeset
   166
	if (!IsTileType(tile, MP_ROAD) || GetRoadTileType(tile) != ROAD_TILE_DEPOT) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   167
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   168
	return AIObject::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
   169
}
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   170
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   171
/* static */ bool AIRoad::RemoveRoadStation(TileIndex tile)
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   172
{
9801
03a3eebd7fb7 (svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents: 9737
diff changeset
   173
	if (!::IsValidTile(tile)) return false;
9453
727ff178a582 (svn r9283) [NoAI] -Add: API for adding/removing road, road depots and road stations.
rubidium
parents:
diff changeset
   174
	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
   175
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9723
diff changeset
   176
	return AIObject::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
   177
}