(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 :)
--- a/bin/ai/regression/regression.txt Sat Jun 07 22:57:00 2008 +0000
+++ b/bin/ai/regression/regression.txt Sat Jun 07 23:05:36 2008 +0000
@@ -5979,49 +5979,37 @@
41383 => 0
Buildable(): done
KeepValue(1): done
- Count(): 33
+ Count(): 23
BuildableRectangle(3, 3) ListDump:
- 42415 => 1
- 42414 => 1
- 42413 => 1
42410 => 1
- 42409 => 1
- 42159 => 1
- 42158 => 1
- 42157 => 1
- 42156 => 1
- 42153 => 1
- 41903 => 1
- 41902 => 1
- 41901 => 1
- 41900 => 1
- 41899 => 1
- 41897 => 1
41647 => 1
41646 => 1
- 41645 => 1
- 41644 => 1
- 41643 => 1
- 41641 => 1
41391 => 1
41390 => 1
41389 => 1
41388 => 1
41387 => 1
- 42408 => 0
- 42407 => 0
- 42151 => 0
- 41895 => 0
- 41639 => 0
- 41383 => 0
+ 42414 => 0
+ 42413 => 0
+ 42159 => 0
+ 42158 => 0
+ 42156 => 0
+ 41903 => 0
+ 41902 => 0
+ 41901 => 0
+ 41900 => 0
+ 41899 => 0
+ 41897 => 0
+ 41645 => 0
+ 41644 => 0
+ 41643 => 0
+ 41641 => 0
DistanceManhattanToTile(30000) ListDump:
- 42415 => 175
42414 => 174
42159 => 174
42413 => 173
42158 => 173
41903 => 173
- 42157 => 172
41902 => 172
41647 => 172
42156 => 171
@@ -6032,24 +6020,15 @@
41900 => 170
41645 => 170
41390 => 170
- 42409 => 169
41899 => 169
41644 => 169
41389 => 169
- 42408 => 168
- 42153 => 168
41643 => 168
41388 => 168
- 42407 => 167
41897 => 167
41387 => 167
- 42151 => 166
41641 => 166
- 41895 => 165
- 41639 => 164
- 41383 => 163
DistanceSquareToTile(30000) ListDump:
- 42415 => 18433
42159 => 18338
41903 => 18245
42414 => 18180
@@ -6059,7 +6038,6 @@
41902 => 17992
42413 => 17929
41646 => 17901
- 42157 => 17834
41390 => 17812
41901 => 17741
41645 => 17650
@@ -6072,86 +6050,52 @@
42410 => 17188
41643 => 17154
41387 => 17065
- 42409 => 16945
- 42153 => 16850
41897 => 16757
- 42408 => 16704
41641 => 16666
- 42407 => 16465
- 42151 => 16370
- 41895 => 16277
- 41639 => 16186
- 41383 => 16097
GetOwner() ListDump:
- 42415 => 9
42414 => 9
42413 => 9
42410 => 9
- 42409 => 9
- 42408 => 9
- 42407 => 9
42159 => 9
42158 => 9
- 42157 => 9
42156 => 9
- 42153 => 9
- 42151 => 9
41903 => 9
41902 => 9
41901 => 9
41900 => 9
41899 => 9
41897 => 9
- 41895 => 9
41647 => 9
41646 => 9
41645 => 9
41644 => 9
41643 => 9
41641 => 9
- 41639 => 9
41391 => 9
41390 => 9
41389 => 9
41388 => 9
41387 => 9
- 41383 => 9
CargoAcceptance(): done
KeepAboveValue(10): done
- Count(): 14
+ Count(): 6
ListDump:
- 41895 => 43
41897 => 41
- 41383 => 40
- 41639 => 37
- 42151 => 35
41641 => 35
- 42153 => 33
41899 => 29
41387 => 29
41643 => 26
- 42407 => 24
- 42409 => 22
- 42408 => 22
42410 => 13
RoadTile(): done
KeepValue(1): done
- Count(): 7
+ Count(): 0
ListDump:
- 42409 => 1
- 42408 => 1
- 42407 => 1
- 42151 => 1
- 41895 => 1
- 41639 => 1
- 41383 => 1
NeighbourRoadCount():done
KeepValue(1): done
- Count(): 1
+ Count(): 0
ListDump:
- 42409 => 1
Water(): done
- Count(): 46
+ Count(): 45
ListDump:
54941 => 1
54940 => 1
@@ -6198,7 +6142,6 @@
53911 => 0
53910 => 0
53909 => 0
- 42409 => 0
--TileList_IndustryAccepting--
Count(): 47
--- a/src/ai/api/ai_tile.cpp Sat Jun 07 22:57:00 2008 +0000
+++ b/src/ai/api/ai_tile.cpp Sat Jun 07 23:05:36 2008 +0000
@@ -12,6 +12,7 @@
#include "../../station_func.h"
#include "../../command_type.h"
#include "../../settings_type.h"
+#include "../../player_func.h"
#include "../../road_map.h"
/* static */ bool AITile::IsBuildable(TileIndex tile)
@@ -19,18 +20,15 @@
if (!::IsValidTile(tile)) return false;
switch (::GetTileType(tile)) {
- default: return true;
- case MP_VOID:
- case MP_HOUSE:
- case MP_STATION:
- case MP_INDUSTRY:
- case MP_UNMOVABLE:
- case MP_WATER: return false;
-
+ default: return false;
+ case MP_CLEAR: return true;
case MP_ROAD:
/* Depots aren't considered buildable */
if (::GetRoadTileType(tile) == ROAD_TILE_DEPOT) return false;
- return true;
+ if (CountBits(GetAllRoadBits(tile)) != 1) return false;
+ if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN)) return true;
+ if (IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) return true;
+ return false;
}
}
--- a/src/ai/api/ai_tile.hpp Sat Jun 07 22:57:00 2008 +0000
+++ b/src/ai/api/ai_tile.hpp Sat Jun 07 23:05:36 2008 +0000
@@ -70,7 +70,10 @@
* @param tile The tile to check on.
* @pre AIMap::IsValidTile(tile).
* @return True if it is buildable, false if not.
- * @note Road and rail are considered buildable.
+ * @note For trams you also might want to check for AIRoad::IsRoad(),
+ * as you can build tram-rails on road-tiles.
+ * @note For rail you also might want to check for AIRoad::IsRoad(),
+ * as in some cases you can build rails on road-tiles.
*/
static bool IsBuildable(TileIndex tile);
@@ -82,7 +85,6 @@
* @param height The height of the rectangle.
* @pre AIMap::IsValidTile(tile).
* @return True if it is buildable, false if not.
- * @note Road and rail are considered buildable.
*/
static bool IsBuildableRectangle(TileIndex tile, uint width, uint height);