Loading

Paste #p5in21sxi

  1. function Road::_Neighbours(self, path, cur_node)
  2. {
  3. (...)
  4.     bla bla
  5. ()
  6.     local bridges = self._GetTunnelsBridgesEfficient(path.GetParent().GetTile(), cur_node, self._GetDirectionEfficient(path.GetParent().GetTile(), cur_node, true) << 4);
  7.     foreach (tile in bridges) {
  8.         tiles.push(tile);
  9.     }
  10.  
  11.     return tiles;
  12. }
  13.  
  14. /**
  15.  * Get a list of all bridges and tunnels that can be built from the
  16.  * current tile. Tunnels will only be built if no terraforming
  17.  * is needed on both ends.
  18.  */
  19. function Road::_GetTunnelsBridgesEfficient(last_node, cur_node, bridge_dir,
  20.         _AIBridge = AIBridge, _AITile = AITile, _AIMap = AIMap, _AITunnel = AITunnel, _AIVehicle = AIVehicle)
  21. {
  22.     local tiles = [];
  23.  
  24.     for (local i = 2; i < this._max_bridge_length;) {
  25.         local target = cur_node + i * (cur_node - last_node);
  26.         local bridge_list = AIBridgeList_Length(++i);
  27.         if (!bridge_list.IsEmpty() && _AIBridge.BuildBridge(_AIVehicle.VT_ROAD, bridge_list.Begin(), cur_node, target)) {
  28.             tiles.push([target, bridge_dir]);
  29.         }
  30.     }
  31.  
  32.     local slope = _AITile.GetSlope(cur_node);
  33.     if (slope != _AITile.SLOPE_SW && slope != _AITile.SLOPE_NW && slope != _AITile.SLOPE_SE && slope != _AITile.SLOPE_NE) return tiles;
  34.     local other_tunnel_end = _AITunnel.GetOtherTunnelEnd(cur_node);
  35.     if (!_AIMap.IsValidTile(other_tunnel_end)) return tiles;
  36.  
  37.     local tunnel_length = _AIMap.DistanceManhattan(cur_node, other_tunnel_end);
  38.     if (_AITunnel.GetOtherTunnelEnd(other_tunnel_end) == cur_node && tunnel_length >= 2 &&
  39.             cur_node + (cur_node - other_tunnel_end) / tunnel_length == last_node && tunnel_length < _max_tunnel_length && _AITunnel.BuildTunnel(_AIVehicle.VT_ROAD, cur_node)) {
  40.         tiles.push([other_tunnel_end, bridge_dir]);
  41.     }
  42.     return tiles;
  43. }

Comments