src/ai/api/ai_tile.cpp
author truebrain
Sat, 07 Jun 2008 23:05:36 +0000
branchnoai
changeset 10853 87f2238f47d4
parent 10848 7816f447a0ed
child 10855 90904faa1890
permissions -rw-r--r--
(svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     1
/* $Id$ */
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     2
9833
89a64246458f (svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents: 9814
diff changeset
     3
/** @file ai_tile.cpp Implementation of AITile. */
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     4
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     5
#include "ai_tile.hpp"
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
     6
#include "ai_map.hpp"
10848
7816f447a0ed (svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents: 10776
diff changeset
     7
#include "ai_town.hpp"
10339
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 10191
diff changeset
     8
#include "../../openttd.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9708
diff changeset
     9
#include "../../tile_map.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9708
diff changeset
    10
#include "../../map_func.h"
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    11
#include "../../variables.h"
9837
c9ec4f82e0d0 (svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents: 9834
diff changeset
    12
#include "../../station_func.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9708
diff changeset
    13
#include "../../command_type.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    14
#include "../../settings_type.h"
10853
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    15
#include "../../player_func.h"
9769
015b6674c8ad (svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents: 9737
diff changeset
    16
#include "../../road_map.h"
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    17
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: 9736
diff changeset
    18
/* static */ bool AITile::IsBuildable(TileIndex tile)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    19
{
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: 9769
diff changeset
    20
	if (!::IsValidTile(tile)) return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    21
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    22
	switch (::GetTileType(tile)) {
10853
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    23
		default: return false;
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    24
		case MP_CLEAR: return true;
9769
015b6674c8ad (svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents: 9737
diff changeset
    25
		case MP_ROAD:
015b6674c8ad (svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents: 9737
diff changeset
    26
			/* Depots aren't considered buildable */
015b6674c8ad (svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents: 9737
diff changeset
    27
			if (::GetRoadTileType(tile) == ROAD_TILE_DEPOT) return false;
10853
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    28
			if (CountBits(GetAllRoadBits(tile)) != 1) return false;
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    29
			if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) return true;
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    30
			if (IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) return true;
87f2238f47d4 (svn r13404) [NoAI] -Change [API CHANGE]: AITile::IsBuildable no longer returns 'true' on road, but only on a halve piece of road (as that is auto-removed). This should make this function return less 'true', and more sane results :)
truebrain
parents: 10848
diff changeset
    31
			return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    32
	}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    33
}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    34
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    35
/* static */ bool AITile::IsBuildableRectangle(TileIndex tile, uint width, uint height)
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    36
{
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    37
	uint tx, ty;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    38
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    39
	tx = AIMap::GetTileX(tile);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    40
	ty = AIMap::GetTileY(tile);
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    41
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    42
	for (uint x = tx; x < width + tx; x++) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    43
		for (uint y = ty; y < height + ty; y++) {
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    44
			if (!IsBuildable(AIMap::GetTileIndex(x, y))) return false;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    45
		}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    46
	}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    47
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    48
	return true;
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    49
}
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
    50
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: 9736
diff changeset
    51
/* static */ bool AITile::IsWater(TileIndex tile)
9698
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    52
{
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: 9769
diff changeset
    53
	if (!::IsValidTile(tile)) return false;
9698
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    54
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    55
	return ::GetTileType(tile) == MP_WATER;
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    56
}
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    57
10191
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    58
/* static */ bool AITile::IsSteepSlope(Slope slope)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    59
{
10191
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    60
	if (slope == SLOPE_INVALID) return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    61
10191
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    62
	return ::IsSteepSlope((::Slope)slope);
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    63
}
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    64
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    65
/* static */ bool AITile::IsHalftileSlope(Slope slope)
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    66
{
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    67
	if (slope == SLOPE_INVALID) return false;
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    68
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    69
	return ::IsHalftileSlope((::Slope)slope);
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    70
}
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    71
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    72
/* static */ AITile::Slope AITile::GetSlope(TileIndex tile)
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    73
{
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    74
	if (!::IsValidTile(tile)) return SLOPE_INVALID;
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    75
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    76
	return (Slope)::GetTileSlope(tile, NULL);
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    77
}
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    78
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    79
/* static */ AITile::Slope AITile::GetComplementSlope(Slope slope)
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    80
{
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    81
	if (slope == SLOPE_INVALID) return SLOPE_INVALID;
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    82
	if (IsSteepSlope(slope)) return SLOPE_INVALID;
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    83
	if (IsHalftileSlope(slope)) return SLOPE_INVALID;
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    84
da75d1460a4b (svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents: 10089
diff changeset
    85
	return (Slope)::ComplementSlope((::Slope)slope);
9700
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    86
}
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    87
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: 9736
diff changeset
    88
/* static */ int32 AITile::GetHeight(TileIndex tile)
9700
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    89
{
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: 9769
diff changeset
    90
	if (!::IsValidTile(tile)) return false;
9700
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    91
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    92
	return ::TileHeight(tile);
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    93
}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    94
10360
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
    95
/* static */ AICompany::CompanyIndex AITile::GetOwner(TileIndex tile)
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
    96
{
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
    97
	if (!::IsValidTile(tile)) return AICompany::INVALID_COMPANY;
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
    98
	if (::IsTileType(tile, MP_HOUSE)) return AICompany::INVALID_COMPANY;
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
    99
	if (::IsTileType(tile, MP_INDUSTRY)) return AICompany::INVALID_COMPANY;
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
   100
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
   101
	return AICompany::ResolveCompanyIndex((AICompany::CompanyIndex)(byte)::GetTileOwner(tile));
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
   102
}
3234cb59de55 (svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents: 10339
diff changeset
   103
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: 9736
diff changeset
   104
/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
   105
{
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: 9769
diff changeset
   106
	if (!::IsValidTile(tile)) return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
   107
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
   108
	AcceptedCargo accepts;
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10715
diff changeset
   109
	::GetAcceptanceAroundTiles(accepts, tile, width, height, _settings_game.station.modified_catchment ? radius : (uint)CA_UNMODIFIED);
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
   110
	return accepts[cargo_type];
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
   111
}
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   112
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: 9736
diff changeset
   113
/* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
9729
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
   114
{
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: 9769
diff changeset
   115
	if (!::IsValidTile(tile)) return false;
9729
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
   116
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
   117
	AcceptedCargo produced;
10776
07203fc29812 (svn r13326) [NoAI] -Sync with trunk r13264:13325
glx
parents: 10715
diff changeset
   118
	::GetProductionAroundTiles(produced, tile, width, height, _settings_game.station.modified_catchment ? radius : (uint)CA_UNMODIFIED);
9729
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
   119
	return produced[cargo_type];
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
   120
}
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
   121
9834
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   122
/* static */ int32 AITile::GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to)
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   123
{
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   124
	return AIMap::DistanceManhattan(tile_from, tile_to);
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   125
}
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   126
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   127
/* static */ int32 AITile::GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to)
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   128
{
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   129
	return AIMap::DistanceSquare(tile_from, tile_to);
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   130
}
9abe20fc83e5 (svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents: 9833
diff changeset
   131
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: 9736
diff changeset
   132
/* static */ bool AITile::RaiseTile(TileIndex tile, int32 slope)
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   133
{
10089
e351169bf3a5 (svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents: 9837
diff changeset
   134
	EnforcePrecondition(false, ::IsValidTile(tile));
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   135
10642
dbb8fd36a99c (svn r13186) [NoAI] -Fix: RaiseTile and LowerTile can now operate on water-tiles. Use with care!
truebrain
parents: 10360
diff changeset
   136
	return AIObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND, false);
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   137
}
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   138
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: 9736
diff changeset
   139
/* static */ bool AITile::LowerTile(TileIndex tile, int32 slope)
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   140
{
10089
e351169bf3a5 (svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents: 9837
diff changeset
   141
	EnforcePrecondition(false, ::IsValidTile(tile));
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   142
10642
dbb8fd36a99c (svn r13186) [NoAI] -Fix: RaiseTile and LowerTile can now operate on water-tiles. Use with care!
truebrain
parents: 10360
diff changeset
   143
	return AIObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND, false);
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
   144
}
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
   145
10089
e351169bf3a5 (svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents: 9837
diff changeset
   146
/* static */ bool AITile::DemolishTile(TileIndex tile)
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
   147
{
10089
e351169bf3a5 (svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents: 9837
diff changeset
   148
	EnforcePrecondition(false, ::IsValidTile(tile));
e351169bf3a5 (svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents: 9837
diff changeset
   149
e351169bf3a5 (svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents: 9837
diff changeset
   150
	return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
9814
be51ea0adc29 (svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents: 9801
diff changeset
   151
}
10848
7816f447a0ed (svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents: 10776
diff changeset
   152
7816f447a0ed (svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents: 10776
diff changeset
   153
/* static */ bool AITile::IsWithinTownInfluence(TileIndex tile, TownID town_id)
7816f447a0ed (svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents: 10776
diff changeset
   154
{
7816f447a0ed (svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents: 10776
diff changeset
   155
	return AITown::IsWithinTownInfluence(town_id, tile);
7816f447a0ed (svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents: 10776
diff changeset
   156
}