(svn r13567) [NoAI] -Fix: it turns out AIStation::StationType didn't match ::StationType, as it matches (nameless) FACIL_ enum.. which has not the same order as ::StationTYpe.. things can be confusing from time to time :) noai
authortruebrain
Wed, 18 Jun 2008 20:14:48 +0000
branchnoai
changeset 11011 63df4d05c0bf
parent 11010 69532778abab
child 11012 2a79a3bbe92a
(svn r13567) [NoAI] -Fix: it turns out AIStation::StationType didn't match ::StationType, as it matches (nameless) FACIL_ enum.. which has not the same order as ::StationTYpe.. things can be confusing from time to time :)
bin/ai/regression/regression.txt
src/ai/api/ai_tilelist.cpp
--- a/bin/ai/regression/regression.txt	Wed Jun 18 19:58:44 2008 +0000
+++ b/bin/ai/regression/regression.txt	Wed Jun 18 20:14:48 2008 +0000
@@ -6602,10 +6602,10 @@
 --TileList_StationType--
   Count():             4
   Location ListDump:
-    33668 => 0
-    33416 => 0
-    33414 => 0
-    33412 => 0
+    33667 => 0
+    33415 => 0
+    33413 => 0
+    33411 => 0
 
 --Town--
   GetMaxTownID():    31
--- a/src/ai/api/ai_tilelist.cpp	Wed Jun 18 19:58:44 2008 +0000
+++ b/src/ai/api/ai_tilelist.cpp	Wed Jun 18 20:14:48 2008 +0000
@@ -157,10 +157,19 @@
 
 	const StationRect *rect = &::GetStation(station_id)->rect;
 
+	uint station_type_value = 0;
+	/* Convert AIStation::StationType to ::StationType, but do it in a
+	 *  bitmask, so we can scan for multiple entries at the same time. */
+	if ((station_type & AIStation::STATION_TRAIN) != 0)      station_type_value |= (1 << ::STATION_RAIL);
+	if ((station_type & AIStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK);
+	if ((station_type & AIStation::STATION_BUS_STOP) != 0)   station_type_value |= (1 << ::STATION_BUS);
+	if ((station_type & AIStation::STATION_AIRPORT) != 0)    station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG);
+	if ((station_type & AIStation::STATION_DOCK) != 0)       station_type_value |= (1 << ::STATION_DOCK)    | (1 << ::STATION_OILRIG);
+
 	BEGIN_TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top)) {
 		if (!::IsTileType(cur_tile, MP_STATION)) continue;
 		if (::GetStationIndex(cur_tile) != station_id) continue;
-		if (!HasBit(station_type, ::GetStationType(cur_tile))) continue;
+		if (!HasBit(station_type_value, ::GetStationType(cur_tile))) continue;
 		this->AddTile(cur_tile);
 	} END_TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top))
 }