90 } |
90 } |
91 } |
91 } |
92 |
92 |
93 /* static */ int32 AIStation::GetDistanceManhattanToTile(StationID station_id, TileIndex tile) |
93 /* static */ int32 AIStation::GetDistanceManhattanToTile(StationID station_id, TileIndex tile) |
94 { |
94 { |
|
95 if (!IsValidStation(station_id)) return -1; |
|
96 |
95 return AIMap::DistanceManhattan(tile, GetLocation(station_id)); |
97 return AIMap::DistanceManhattan(tile, GetLocation(station_id)); |
96 } |
98 } |
97 |
99 |
98 /* static */ int32 AIStation::GetDistanceSquareToTile(StationID station_id, TileIndex tile) |
100 /* static */ int32 AIStation::GetDistanceSquareToTile(StationID station_id, TileIndex tile) |
99 { |
101 { |
|
102 if (!IsValidStation(station_id)) return -1; |
|
103 |
100 return AIMap::DistanceSquare(tile, GetLocation(station_id)); |
104 return AIMap::DistanceSquare(tile, GetLocation(station_id)); |
101 } |
105 } |
102 |
106 |
103 /* static */ bool AIStation::IsWithinTownInfluence(StationID station_id, TownID town_id) |
107 /* static */ bool AIStation::IsWithinTownInfluence(StationID station_id, TownID town_id) |
104 { |
108 { |
|
109 if (!IsValidStation(station_id)) return false; |
|
110 |
105 return AITown::IsWithinTownInfluence(town_id, GetLocation(station_id)); |
111 return AITown::IsWithinTownInfluence(town_id, GetLocation(station_id)); |
106 } |
112 } |
|
113 |
|
114 /* static */ bool AIStation::HasRoadType(StationID station_id, AIRoad::RoadType road_type) |
|
115 { |
|
116 if (!IsValidStation(station_id)) return false; |
|
117 if (!AIRoad::IsRoadTypeAvailable(road_type)) return false; |
|
118 |
|
119 ::RoadTypes r = RoadTypeToRoadTypes((::RoadType)road_type); |
|
120 |
|
121 for (const RoadStop *rs = ::GetStation(station_id)->GetPrimaryRoadStop(ROADSTOP_BUS); rs != NULL; rs = rs->next) { |
|
122 if ((::GetRoadTypes(rs->xy) & r) != 0) return true; |
|
123 } |
|
124 for (const RoadStop *rs = ::GetStation(station_id)->GetPrimaryRoadStop(ROADSTOP_TRUCK); rs != NULL; rs = rs->next) { |
|
125 if ((::GetRoadTypes(rs->xy) & r) != 0) return true; |
|
126 } |
|
127 |
|
128 return false; |
|
129 } |