summaryrefslogtreecommitdiff
path: root/src/yapf/yapf_common.hpp
diff options
context:
space:
mode:
authorKUDr <kudr@openttd.org>2007-07-15 11:45:38 +0000
committerKUDr <kudr@openttd.org>2007-07-15 11:45:38 +0000
commitd71d48434dee0c4f9435a25d15aefe4ee1e41b91 (patch)
treebae1861670a97c0f24e67a5fc511e59727e3768a /src/yapf/yapf_common.hpp
parent6474a5a95759641feb93edf7cc34c2f58bb23eb2 (diff)
downloadopenttd-d71d48434dee0c4f9435a25d15aefe4ee1e41b91.tar.xz
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
-The fix in cost calculation uncovered bug in estimate calculation. Ships now use the same estimate algorithm as trains.
Diffstat (limited to 'src/yapf/yapf_common.hpp')
-rw-r--r--src/yapf/yapf_common.hpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/yapf/yapf_common.hpp b/src/yapf/yapf_common.hpp
index ed6b8782a..8c5257e94 100644
--- a/src/yapf/yapf_common.hpp
+++ b/src/yapf/yapf_common.hpp
@@ -134,13 +134,26 @@ public:
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
inline bool PfCalcEstimate(Node& n)
{
- int dx = delta(TileX(n.GetTile()), TileX(m_destTile));
- int dy = delta(TileY(n.GetTile()), TileY(m_destTile));
- assert(dx >= 0 && dy >= 0);
- int dd = min(dx, dy);
+ static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
+ static int dg_dir_to_y_offs[] = {0, 1, 0, -1};
+ if (PfDetectDestination(n)) {
+ n.m_estimate = n.m_cost;
+ return true;
+ }
+
+ TileIndex tile = n.GetTile();
+ DiagDirection exitdir = TrackdirToExitdir(n.GetTrackdir());
+ int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
+ int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
+ int x2 = 2 * TileX(m_destTile);
+ int y2 = 2 * TileY(m_destTile);
+ int dx = abs(x1 - x2);
+ int dy = abs(y1 - y2);
+ int dmin = min(dx, dy);
int dxy = abs(dx - dy);
- int d = 14 * dd + 10 * dxy;
- n.m_estimate = n.m_cost + d /*+ d / 8*/;
+ int d = dmin * 7 + (dxy - 1) * (10 / 2);
+ n.m_estimate = n.m_cost + d;
+ assert(n.m_estimate >= n.m_parent->m_estimate);
return true;
}
};