Loading

Paste #prqsbwaty

  1.     function InitializePath(source, goal) {
  2.         this._pathfinder.InitializePath([source, 0xFF], goal);
  3.         if (this._search_range != 0) {
  4.             local source_x = AIMap.GetTileX(source);
  5.             local source_y = AIMap.GetTileY(source);
  6.             local goal_x = AIMap.GetTileX(goal);
  7.             local goal_y = AIMap.GetTileY(goal);
  8.  
  9.             local N_x = source_x > goal_x ? goal_x : source_x;
  10.             local N_y = source_y > goal_y ? goal_y : source_y;
  11.             local S_x = source_x > goal_x ? source_x : goal_x;
  12.             local S_y = source_y > goal_y ? source_y : goal_y;
  13.  
  14.             local min_freeform = AIMap.IsValidTile(0) ? 0 : 1;
  15.             local max_freeform = min_freeform == 0 ? 3 : 2;
  16.  
  17.             this._min_x = N_x - this._search_range < min_freeform ? min_freeform : N_x - this._search_range;
  18.             this._min_y = N_y - this._search_range < min_freeform ? min_freeform : N_y - this._search_range;
  19.             this._max_x = S_x + this._search_range > AIMap.GetMapSizeX() - max_freeform ? AIMap.GetMapSizeX() - max_freeform : S_x + this._search_range;
  20.             this._max_y = S_y + this._search_range > AIMap.GetMapSizeY() - max_freeform ? AIMap.GetMapSizeY() - max_freeform : S_y + this._search_range;
  21.         }
  22.     }
  23.  
  24. function Road::_IsInsideRangeEfficient(self, cur_tile,
  25.         _AIMap = AIMap)
  26. {
  27.     if (!self._search_range) return true;
  28.     local cur_tile_x = _AIMap.GetTileX(cur_tile);
  29.     local cur_tile_y = _AIMap.GetTileY(cur_tile);
  30.     return cur_tile_x >= self._min_x && cur_tile_x <= self._max_x && cur_tile_y >= self._min_y && cur_tile_y <= self._max_y;
  31. }

Version history

Revision # Author Created at
pmfujrgil Anonymous 18 Aug 2019, 20:58:18 UTC Diff

Comments