mirror of https://github.com/OpenTTD/OpenTTD.git
(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.
This commit is contained in:
parent
6474a5a957
commit
d71d48434d
|
@ -134,13 +134,26 @@ public:
|
||||||
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
inline bool PfCalcEstimate(Node& n)
|
inline bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
int dx = delta(TileX(n.GetTile()), TileX(m_destTile));
|
static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||||
int dy = delta(TileY(n.GetTile()), TileY(m_destTile));
|
static int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||||
assert(dx >= 0 && dy >= 0);
|
if (PfDetectDestination(n)) {
|
||||||
int dd = min(dx, dy);
|
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 dxy = abs(dx - dy);
|
||||||
int d = 14 * dd + 10 * dxy;
|
int d = dmin * 7 + (dxy - 1) * (10 / 2);
|
||||||
n.m_estimate = n.m_cost + d /*+ d / 8*/;
|
n.m_estimate = n.m_cost + d;
|
||||||
|
assert(n.m_estimate >= n.m_parent->m_estimate);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,10 @@ public:
|
||||||
// base tile cost depending on distance
|
// base tile cost depending on distance
|
||||||
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
|
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;
|
||||||
// additional penalty for curves
|
// additional penalty for curves
|
||||||
if (n.m_parent != NULL && n.GetTrackdir() != n.m_parent->GetTrackdir()) c += 3;
|
if (n.m_parent != NULL && n.GetTrackdir() != NextTrackdir(n.m_parent->GetTrackdir())) {
|
||||||
|
/* new trackdir does not match the next one when going straight */
|
||||||
|
c += 10;
|
||||||
|
}
|
||||||
// apply it
|
// apply it
|
||||||
n.m_cost = n.m_parent->m_cost + c;
|
n.m_cost = n.m_parent->m_cost + c;
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue