src/ai/api/ai_tile.cpp
author truebrain
Sun, 24 Feb 2008 23:00:00 +0000
branchnoai
changeset 9756 7e637829cbd3
parent 9737 ee408edf3851
child 9769 015b6674c8ad
permissions -rw-r--r--
(svn r12241) [NoAI] -Fix r12236: global search/replace to the unreadable documentation! WHOHO! (tnx Progman)
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
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     3
/** @file ai_tile.cpp handles the functions of the AITile class */
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"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9708
diff changeset
     6
#include "../../tile_map.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9708
diff changeset
     7
#include "../../map_func.h"
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     8
#include "../../variables.h"
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
     9
#include "../../station.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9708
diff changeset
    10
#include "../../command_type.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    11
#include "../../settings_type.h"
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    12
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
    13
/* static */ bool AITile::IsBuildable(TileIndex tile)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    14
{
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    15
	/* 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
    16
	if (tile >= ::MapSize()) return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    17
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    18
	switch (::GetTileType(tile)) {
9728
d7bd32dc6c59 (svn r12151) [NoAI] -Fix: use the correct types for returned values
glx
parents: 9724
diff changeset
    19
		default: return true;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    20
		case MP_VOID:
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    21
		case MP_HOUSE:
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    22
		case MP_STATION:
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    23
		case MP_INDUSTRY:
9697
a6a9379988f6 (svn r10938) [NoAI] -Fix r10937: regression update
truelight
parents: 9658
diff changeset
    24
		case MP_UNMOVABLE:
9728
d7bd32dc6c59 (svn r12151) [NoAI] -Fix: use the correct types for returned values
glx
parents: 9724
diff changeset
    25
		case MP_WATER: return false;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    26
	}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    27
}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    28
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
    29
/* static */ bool AITile::IsWater(TileIndex tile)
9698
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    30
{
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    31
	/* Outside of the map */
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    32
	if (tile >= ::MapSize()) return false;
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    33
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    34
	return ::GetTileType(tile) == MP_WATER;
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    35
}
1d50fe99b7e9 (svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents: 9697
diff changeset
    36
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
    37
/* static */ int32 AITile::GetSlope(TileIndex tile)
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    38
{
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    39
	/* 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
    40
	if (tile >= ::MapSize()) return 0;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    41
9700
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    42
	return ::GetTileSlope(tile, NULL);
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    43
}
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    44
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
    45
/* static */ int32 AITile::GetHeight(TileIndex tile)
9700
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    46
{
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    47
	/* Outside of the map */
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    48
	if (tile >= ::MapSize()) return 0;
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    49
e442ce398e83 (svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents: 9698
diff changeset
    50
	return ::TileHeight(tile);
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    51
}
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    52
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
    53
/* 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
    54
{
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    55
	/* Outside of the map */
9728
d7bd32dc6c59 (svn r12151) [NoAI] -Fix: use the correct types for returned values
glx
parents: 9724
diff changeset
    56
	if (tile >= ::MapSize()) return 0;
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    57
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    58
	AcceptedCargo accepts;
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9735
diff changeset
    59
	::GetAcceptanceAroundTiles(accepts, tile, width, height, _patches.modified_catchment ? radius : (uint)CA_UNMODIFIED);
9617
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    60
	return accepts[cargo_type];
df9cedf12aab (svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff changeset
    61
}
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    62
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
    63
/* 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
    64
{
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    65
	/* Outside of the map */
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    66
	if (tile >= ::MapSize()) return 0;
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    67
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    68
	AcceptedCargo produced;
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9735
diff changeset
    69
	::GetProductionAroundTiles(produced, tile, width, height, _patches.modified_catchment ? radius : (uint)CA_UNMODIFIED);
9729
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    70
	return produced[cargo_type];
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    71
}
c264c78a3567 (svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents: 9728
diff changeset
    72
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
    73
/* 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
    74
{
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    75
	/* Outside of the map */
9728
d7bd32dc6c59 (svn r12151) [NoAI] -Fix: use the correct types for returned values
glx
parents: 9724
diff changeset
    76
	if (tile >= ::MapSize()) return false;
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
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: 9736
diff changeset
    78
	return AIObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND);
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    79
}
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    80
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
    81
/* 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
    82
{
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    83
	/* Outside of the map */
9728
d7bd32dc6c59 (svn r12151) [NoAI] -Fix: use the correct types for returned values
glx
parents: 9724
diff changeset
    84
	if (tile >= ::MapSize()) return false;
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    85
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
    86
	return AIObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND);
9708
a63a756fd080 (svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents: 9700
diff changeset
    87
}