Loading

Paste #pkxot9vj7

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

Comments