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 "../waypoint_base.h" 00016 00026 static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile, StationType station_type) 00027 { 00028 const BaseStation *st = BaseStation::Get(station); 00029 TileArea ta; 00030 st->GetTileArea(&ta, station_type); 00031 00032 /* If the rail station is (temporarily) not present, use the station sign to drive near the station */ 00033 if (ta.tile == INVALID_TILE) return st->xy; 00034 00035 uint minx = TileX(ta.tile); // topmost corner of station 00036 uint miny = TileY(ta.tile); 00037 uint maxx = minx + ta.w - 1; // lowermost corner of station 00038 uint maxy = miny + ta.h - 1; 00039 00040 /* we are going the aim for the x coordinate of the closest corner 00041 * but if we are between those coordinates, we will aim for our own x coordinate */ 00042 uint x = ClampU(TileX(tile), minx, maxx); 00043 00044 /* same for y coordinate, see above comment */ 00045 uint y = ClampU(TileY(tile), miny, maxy); 00046 00047 /* return the tile of our target coordinates */ 00048 return TileXY(x, y); 00049 } 00050 00051 #endif /* PATHFINDER_FUNC_H */