Loading

Paste #puskquvt9

  1. class Road
  2. {
  3. ()
  4.  
  5.     _min_distance = AIMap.GetMapSizeX() + AIMap.GetMapSizeY();
  6.  
  7.     constructor
  8.     {
  9.     ()
  10.     }
  11.  
  12.     function InitializePath(sources, goals) {
  13.         local nsources = [];
  14.  
  15.         foreach (node in sources) {
  16.             nsources.push([node, 0xFF]);
  17.             foreach (tile in goals) {
  18.                 _min_distance = min(_min_distance, AIMap.DistanceManhattan(node, tile));
  19.             }
  20.         }
  21.         this._pathfinder.InitializePath(nsources, goals);
  22.     }
  23.     ()
  24. }
  25.  
  26. function Road::_Estimate(self, cur_tile, cur_direction, goal_tiles,
  27.         _AIMap = AIMap)
  28. {
  29.     local min_cost = self._max_cost;
  30. //  /* As estimate we multiply the lowest possible cost for a single tile
  31. //   * with the minimum number of tiles we need to traverse. */
  32.     foreach (tile in goal_tiles) {
  33.         local distance = _AIMap.DistanceManhattan(cur_tile, tile);
  34.         if (distance > self._min_distance) {
  35.             distance += distance - self._min_distance;
  36.         }
  37.         min_cost = min(distance * self._cost_tile, min_cost);
  38.     }
  39.     return min_cost;
  40. }

Comments