summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-19 00:15:36 +0000
committerrubidium <rubidium@openttd.org>2009-02-19 00:15:36 +0000
commit29173de379eaa1f8c7a1a409ad0232a748172906 (patch)
tree76c1b93af5e93efa3bcc9984e1c04884640ea566
parent8aab3b09f5c6b569b2197c0163b8db1b47296c3b (diff)
downloadopenttd-29173de379eaa1f8c7a1a409ad0232a748172906.tar.xz
(svn r15518) -Fix [FS#2631]: use distance to closest station tile as estimate for YAPF too (NPF already does so). This makes it behave 'better' with wide stations.
-rw-r--r--src/npf.cpp30
-rw-r--r--src/pathfind.h32
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/yapf/yapf_destrail.hpp15
4 files changed, 35 insertions, 44 deletions
diff --git a/src/npf.cpp b/src/npf.cpp
index 9fbad2798..9b8b687a5 100644
--- a/src/npf.cpp
+++ b/src/npf.cpp
@@ -15,6 +15,7 @@
#include "tunnelbridge.h"
#include "pbs.h"
#include "settings_type.h"
+#include "pathfind.h"
static AyStar _npf_aystar;
@@ -83,35 +84,6 @@ static int32 NPFCalcZero(AyStar *as, AyStarNode *current, OpenListNode *parent)
return 0;
}
-/* Calcs the tile of given station that is closest to a given tile
- * for this we assume the station is a rectangle,
- * as defined by its top tile (st->train_tile) and its width/height (st->trainst_w, st->trainst_h)
- */
-static TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
-{
- const Station *st = GetStation(station);
-
- /* If the rail station is (temporarily) not present, use the station sign to drive near the station */
- if (!IsValidTile(st->train_tile)) return st->xy;
-
- uint minx = TileX(st->train_tile); // topmost corner of station
- uint miny = TileY(st->train_tile);
- uint maxx = minx + st->trainst_w - 1; // lowermost corner of station
- uint maxy = miny + st->trainst_h - 1;
- uint x;
- uint y;
-
- /* we are going the aim for the x coordinate of the closest corner
- * but if we are between those coordinates, we will aim for our own x coordinate */
- x = Clamp(TileX(tile), minx, maxx);
-
- /* same for y coordinate, see above comment */
- y = Clamp(TileY(tile), miny, maxy);
-
- /* return the tile of our target coordinates */
- return TileXY(x, y);
-}
-
/* Calcs the heuristic to the target station or tile. For train stations, it
* takes into account the direction of approach.
*/
diff --git a/src/pathfind.h b/src/pathfind.h
index d09b2a053..0a006190f 100644
--- a/src/pathfind.h
+++ b/src/pathfind.h
@@ -77,4 +77,36 @@ DECLARE_ENUM_AS_BIT_SET(PathfindFlags)
void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data);
void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc *enum_proc, void *data);
+
+/**
+ * Calculates the tile of given station that is closest to a given tile
+ * for this we assume the station is a rectangle,
+ * as defined by its top tile (st->train_tile) and its width/height (st->trainst_w, st->trainst_h)
+ * @param station The station to calculate the distance to
+ * @param tile The tile from where to calculate the distance
+ * @return The closest station tile to the given tile.
+ */
+static inline TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
+{
+ const Station *st = GetStation(station);
+
+ /* If the rail station is (temporarily) not present, use the station sign to drive near the station */
+ if (st->train_tile == INVALID_TILE) return st->xy;
+
+ uint minx = TileX(st->train_tile); // topmost corner of station
+ uint miny = TileY(st->train_tile);
+ uint maxx = minx + st->trainst_w - 1; // lowermost corner of station
+ uint maxy = miny + st->trainst_h - 1;
+
+ /* we are going the aim for the x coordinate of the closest corner
+ * but if we are between those coordinates, we will aim for our own x coordinate */
+ uint x = ClampU(TileX(tile), minx, maxx);
+
+ /* same for y coordinate, see above comment */
+ uint y = ClampU(TileY(tile), miny, maxy);
+
+ /* return the tile of our target coordinates */
+ return TileXY(x, y);
+}
+
#endif /* PATHFIND_H */
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index a7106e30f..cb3949b7f 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -7,7 +7,6 @@
#include "landscape.h"
#include "timetable.h"
#include "command_func.h"
-#include "pathfind.h"
#include "station_map.h"
#include "news_func.h"
#include "company_func.h"
@@ -30,6 +29,7 @@
#include "effectvehicle_func.h"
#include "settings_type.h"
#include "ai/ai.hpp"
+#include "pathfind.h"
#include "table/strings.h"
#include "table/sprites.h"
diff --git a/src/yapf/yapf_destrail.hpp b/src/yapf/yapf_destrail.hpp
index 624e5b974..25db5ded1 100644
--- a/src/yapf/yapf_destrail.hpp
+++ b/src/yapf/yapf_destrail.hpp
@@ -115,25 +115,12 @@ protected:
/// to access inherited path finder
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
- static TileIndex CalcStationCenterTile(StationID station)
- {
- const Station *st = GetStation(station);
-
- /* If the rail station is (temporarily) not present, use the station sign to drive near the station */
- if (!IsValidTile(st->train_tile)) return st->xy;
-
- uint x = TileX(st->train_tile) + st->trainst_w / 2;
- uint y = TileY(st->train_tile) + st->trainst_h / 2;
- // return the tile of our target coordinates
- return TileXY(x, y);
- }
-
public:
void SetDestination(const Vehicle *v)
{
switch (v->current_order.GetType()) {
case OT_GOTO_STATION:
- m_destTile = CalcStationCenterTile(v->current_order.GetDestination());
+ m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile);
m_dest_station_id = v->current_order.GetDestination();
m_destTrackdirs = INVALID_TRACKDIR_BIT;
break;