class Road
{
(…)
_min_distance = AIMap.GetMapSizeX() + AIMap.GetMapSizeY();
constructor
{
(…)
}
function InitializePath(sources, goals) {
local nsources = [];
foreach (node in sources) {
nsources.push([node, 0xFF]);
foreach (tile in goals) {
_min_distance = min(_min_distance, AIMap.DistanceManhattan(node, tile));
}
}
this._pathfinder.InitializePath(nsources, goals);
}
(…)
}
function Road::_Estimate(self, cur_tile, cur_direction, goal_tiles,
_AIMap = AIMap)
{
local min_cost = self._max_cost;
// /* As estimate we multiply the lowest possible cost for a single tile
// * with the minimum number of tiles we need to traverse. */
foreach (tile in goal_tiles) {
local distance = _AIMap.DistanceManhattan(cur_tile, tile);
if (distance > self._min_distance) {
distance += distance - self._min_distance;
}
min_cost = min(distance * self._cost_tile, min_cost);
}
return min_cost;
}