00001 /* $Id$ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 00006 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00007 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 00008 */ 00009 00012 #ifndef PATHFINDER_FUNC_H 00013 #define PATHFINDER_FUNC_H 00014 00015 #include "../station_base.h" 00016 #include "../waypoint_base.h" 00017 00027 static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type) 00028 { 00029 const BaseStation *st = BaseStation::Get(station); 00030 TileArea ta; 00031 st->GetTileArea(&ta, station_type); 00032 00033 /* If the rail station is (temporarily) not present, use the station sign to drive near the station */ 00034 if (ta.tile == INVALID_TILE) return st->xy; 00035 00036 uint minx = TileX(ta.tile); // topmost corner of station 00037 uint miny = TileY(ta.tile); 00038 uint maxx = minx + ta.w - 1; // lowermost corner of station 00039 uint maxy = miny + ta.h - 1; 00040 00041 /* we are going the aim for the x coordinate of the closest corner 00042 * but if we are between those coordinates, we will aim for our own x coordinate */ 00043 uint x = ClampU(TileX(tile), minx, maxx); 00044 00045 /* same for y coordinate, see above comment */ 00046 uint y = ClampU(TileY(tile), miny, maxy); 00047 00048 /* return the tile of our target coordinates */ 00049 return TileXY(x, y); 00050 } 00051 00052 #endif /* PATHFINDER_FUNC_H */