author | rubidium |
Tue, 17 Jun 2008 22:37:09 +0000 | |
branch | noai |
changeset 11001 | 716595242a19 |
parent 10934 | 1232882bfe7a |
child 11048 | 186fcb00d2a5 |
permissions | -rw-r--r-- |
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" |
10933
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
10 |
#include "../../tile_cmd.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9708
diff
changeset
|
11 |
#include "../../map_func.h" |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
12 |
#include "../../variables.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9834
diff
changeset
|
13 |
#include "../../station_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9708
diff
changeset
|
14 |
#include "../../command_type.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
15 |
#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
|
16 |
#include "../../player_func.h" |
9769
015b6674c8ad
(svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents:
9737
diff
changeset
|
17 |
#include "../../road_map.h" |
10931
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
18 |
#include "../../water_map.h" |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
19 |
|
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
|
20 |
/* static */ bool AITile::IsBuildable(TileIndex tile) |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
21 |
{ |
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
|
22 |
if (!::IsValidTile(tile)) return false; |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
23 |
|
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
24 |
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
|
25 |
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
|
26 |
case MP_CLEAR: return true; |
10930
8e2c924c7077
(svn r13483) [NoAI] -Fix: oops... IsBuildable thought trees were not buildable, silly of course (tnx Yexo)
truebrain
parents:
10855
diff
changeset
|
27 |
case MP_TREES: return true; |
10934
1232882bfe7a
(svn r13487) [NoAI] -Fix: tram bits are not to be considered buildable in any case.
rubidium
parents:
10933
diff
changeset
|
28 |
case MP_WATER: return IsCoast(tile); |
9769
015b6674c8ad
(svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents:
9737
diff
changeset
|
29 |
case MP_ROAD: |
10934
1232882bfe7a
(svn r13487) [NoAI] -Fix: tram bits are not to be considered buildable in any case.
rubidium
parents:
10933
diff
changeset
|
30 |
/* Tram bits aren't considered buildable */ |
1232882bfe7a
(svn r13487) [NoAI] -Fix: tram bits are not to be considered buildable in any case.
rubidium
parents:
10933
diff
changeset
|
31 |
if (::GetRoadTypes(tile) != ROADTYPES_ROAD) return false; |
9769
015b6674c8ad
(svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents:
9737
diff
changeset
|
32 |
/* Depots aren't considered buildable */ |
015b6674c8ad
(svn r12259) [NoAI] -Fix: depots were considered buildable (tnx Progman)
truebrain
parents:
9737
diff
changeset
|
33 |
if (::GetRoadTileType(tile) == ROAD_TILE_DEPOT) return false; |
10934
1232882bfe7a
(svn r13487) [NoAI] -Fix: tram bits are not to be considered buildable in any case.
rubidium
parents:
10933
diff
changeset
|
34 |
if (CountBits(::GetRoadBits(tile, ROADTYPE_ROAD)) != 1) return false; |
1232882bfe7a
(svn r13487) [NoAI] -Fix: tram bits are not to be considered buildable in any case.
rubidium
parents:
10933
diff
changeset
|
35 |
if (::IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) return true; |
1232882bfe7a
(svn r13487) [NoAI] -Fix: tram bits are not to be considered buildable in any case.
rubidium
parents:
10933
diff
changeset
|
36 |
if (::IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) return true; |
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
|
37 |
return false; |
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 |
} |
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
40 |
|
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
41 |
/* 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
|
42 |
{ |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
43 |
uint tx, ty; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
44 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
45 |
tx = AIMap::GetTileX(tile); |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
46 |
ty = AIMap::GetTileY(tile); |
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 |
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
|
49 |
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
|
50 |
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
|
51 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
52 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
53 |
|
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
54 |
return true; |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
55 |
} |
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
56 |
|
10931
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
57 |
/* static */ bool AITile::IsWaterTile(TileIndex tile) |
9698
1d50fe99b7e9
(svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents:
9697
diff
changeset
|
58 |
{ |
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
|
59 |
if (!::IsValidTile(tile)) return false; |
9698
1d50fe99b7e9
(svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents:
9697
diff
changeset
|
60 |
|
10931
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
61 |
return ::IsTileType(tile, MP_WATER) && !::IsCoast(tile); |
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
62 |
} |
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
63 |
|
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
64 |
/* static */ bool AITile::IsCoastTile(TileIndex tile) |
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
65 |
{ |
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
66 |
if (!::IsValidTile(tile)) return false; |
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
67 |
|
df70e29d4c23
(svn r13484) [NoAI] -Fix [API CHANGE]: AITile::IsBuildable() now returns 'true' on coast tiles
truebrain
parents:
10930
diff
changeset
|
68 |
return ::IsTileType(tile, MP_WATER) && ::IsCoast(tile); |
9698
1d50fe99b7e9
(svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents:
9697
diff
changeset
|
69 |
} |
1d50fe99b7e9
(svn r10939) [NoAI] -Add: added AITileList valuator Water
truelight
parents:
9697
diff
changeset
|
70 |
|
10191
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
71 |
/* static */ bool AITile::IsSteepSlope(Slope slope) |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
72 |
{ |
10191
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
73 |
if (slope == SLOPE_INVALID) return false; |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
74 |
|
10191
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
75 |
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
|
76 |
} |
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 |
/* 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
|
79 |
{ |
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
80 |
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
|
81 |
|
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
82 |
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
|
83 |
} |
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 |
/* 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
|
86 |
{ |
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
87 |
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
|
88 |
|
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
89 |
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
|
90 |
} |
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
91 |
|
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
92 |
/* 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
|
93 |
{ |
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
|
da75d1460a4b
(svn r12722) [NoAI] -Add (or -Feature for yorick): added AITile::IsSteepSlope(), AITile::IsHalftileSlope() and AITile::GetComplementSlope()
truebrain
parents:
10089
diff
changeset
|
98 |
return (Slope)::ComplementSlope((::Slope)slope); |
9700
e442ce398e83
(svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents:
9698
diff
changeset
|
99 |
} |
e442ce398e83
(svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents:
9698
diff
changeset
|
100 |
|
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
|
101 |
/* static */ int32 AITile::GetHeight(TileIndex tile) |
9700
e442ce398e83
(svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents:
9698
diff
changeset
|
102 |
{ |
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
|
103 |
if (!::IsValidTile(tile)) return false; |
9700
e442ce398e83
(svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents:
9698
diff
changeset
|
104 |
|
e442ce398e83
(svn r10941) [NoAI] -Add: added AITile::GetHeight and AITileList valuator Height
truelight
parents:
9698
diff
changeset
|
105 |
return ::TileHeight(tile); |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
106 |
} |
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
107 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10853
diff
changeset
|
108 |
/* static */ AICompany::CompanyID AITile::GetOwner(TileIndex tile) |
10360
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
109 |
{ |
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
|
10855
90904faa1890
(svn r13406) [NoAI] -Change [API CHANGE]: renamed CompanyIndex to CompanyID and AICompany::ResolveCompanyIndex() to AICompany::ResolveCompanyID(), to be more consistant with the rest of the API
truebrain
parents:
10853
diff
changeset
|
114 |
return AICompany::ResolveCompanyID((AICompany::CompanyID)(byte)::GetTileOwner(tile)); |
10360
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
115 |
} |
3234cb59de55
(svn r12901) [NoAI] -Add: added AITown.IsWithinTownRadius, AIStation.IsWithinTownRadius and AITile.GetOwner (Yexo)
truebrain
parents:
10339
diff
changeset
|
116 |
|
10933
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
117 |
/* static */ bool AITile::HasTransportType(TileIndex tile, TransportType transport_type) |
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
118 |
{ |
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
119 |
if (!::IsValidTile(tile)) return false; |
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
120 |
|
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
121 |
return GB(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX), 0, 16) != 0; |
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
122 |
} |
57aa2e01942c
(svn r13486) [NoAI] -Add: function to determine what TransportTypes a tile holds.
rubidium
parents:
10931
diff
changeset
|
123 |
|
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
|
124 |
/* 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
|
125 |
{ |
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
|
126 |
if (!::IsValidTile(tile)) return false; |
9617
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
127 |
|
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
128 |
AcceptedCargo accepts; |
10776 | 129 |
::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
|
130 |
return accepts[cargo_type]; |
df9cedf12aab
(svn r9786) [NoAI] -Fix: NeighbourRoad -> NeighbourRoadCount
truelight
parents:
diff
changeset
|
131 |
} |
9708
a63a756fd080
(svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents:
9700
diff
changeset
|
132 |
|
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
|
133 |
/* 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
|
134 |
{ |
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
|
135 |
if (!::IsValidTile(tile)) return false; |
9729
c264c78a3567
(svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents:
9728
diff
changeset
|
136 |
|
c264c78a3567
(svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents:
9728
diff
changeset
|
137 |
AcceptedCargo produced; |
10776 | 138 |
::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
|
139 |
return produced[cargo_type]; |
c264c78a3567
(svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents:
9728
diff
changeset
|
140 |
} |
c264c78a3567
(svn r12152) [NoAI] -Add [FS#1772]: add AITile.GetCargoProduction() function (Morloth)
glx
parents:
9728
diff
changeset
|
141 |
|
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
|
142 |
/* 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
|
143 |
{ |
9abe20fc83e5
(svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents:
9833
diff
changeset
|
144 |
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
|
145 |
} |
9abe20fc83e5
(svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents:
9833
diff
changeset
|
146 |
|
9abe20fc83e5
(svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents:
9833
diff
changeset
|
147 |
/* 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
|
148 |
{ |
9abe20fc83e5
(svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents:
9833
diff
changeset
|
149 |
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
|
150 |
} |
9abe20fc83e5
(svn r12497) [NoAI] -Change [API CHANGE]: AIMap.DemolishTile -> AITile.DemolishTile (that makes much more sense, doesn't it? ;))
truebrain
parents:
9833
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:
9736
diff
changeset
|
152 |
/* 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
|
153 |
{ |
10089
e351169bf3a5
(svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
154 |
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
|
155 |
|
10642
dbb8fd36a99c
(svn r13186) [NoAI] -Fix: RaiseTile and LowerTile can now operate on water-tiles. Use with care!
truebrain
parents:
10360
diff
changeset
|
156 |
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
|
157 |
} |
a63a756fd080
(svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
truelight
parents:
9700
diff
changeset
|
158 |
|
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
|
159 |
/* 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
|
160 |
{ |
10089
e351169bf3a5
(svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
161 |
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
|
162 |
|
10642
dbb8fd36a99c
(svn r13186) [NoAI] -Fix: RaiseTile and LowerTile can now operate on water-tiles. Use with care!
truebrain
parents:
10360
diff
changeset
|
163 |
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
|
164 |
} |
9814
be51ea0adc29
(svn r12411) [NoAI] -Change [API CHANGE]: order of params of CargoIncome is changed
truebrain
parents:
9801
diff
changeset
|
165 |
|
10089
e351169bf3a5
(svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
166 |
/* 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
|
167 |
{ |
10089
e351169bf3a5
(svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
168 |
EnforcePrecondition(false, ::IsValidTile(tile)); |
e351169bf3a5
(svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
169 |
|
e351169bf3a5
(svn r12613) [NoAI] -Add: support for GetLastError in AITile. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
170 |
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
|
171 |
} |
10848
7816f447a0ed
(svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents:
10776
diff
changeset
|
172 |
|
7816f447a0ed
(svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents:
10776
diff
changeset
|
173 |
/* 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
|
174 |
{ |
7816f447a0ed
(svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents:
10776
diff
changeset
|
175 |
return AITown::IsWithinTownInfluence(town_id, tile); |
7816f447a0ed
(svn r13399) [NoAI] -Add: added AITile::IsWithinTownInfluence (on request by Finaldeath)
glx
parents:
10776
diff
changeset
|
176 |
} |