Loading

Paste #phrvnxhrz

  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::_GetTunnelsBridges(last_node, cur_node, bridge_dir)
  7. {
  8.     local tiles = [];
  9.  
  10.     for (local i = 2; i < this._max_bridge_length; i++) {
  11.         local bridge_list = AIBridgeList_Length(i + 1);
  12.         local target = cur_node + i * (cur_node - last_node);
  13.         if (!bridge_list.IsEmpty() && AIBridge.BuildBridge(AIVehicle.VT_ROAD, bridge_list.Begin(), cur_node, target)) {
  14.             tiles.push([target, bridge_dir]);
  15.         }
  16.     }
  17.  
  18.     local slope = AITile.GetSlope(cur_node);
  19.     if (slope != AITile.SLOPE_SW && slope != AITile.SLOPE_NW && slope != AITile.SLOPE_SE && slope != AITile.SLOPE_NE) return tiles;
  20.     local other_tunnel_end = AITunnel.GetOtherTunnelEnd(cur_node);
  21.     if (!AIMap.IsValidTile(other_tunnel_end)) return tiles;
  22.  
  23.     local tunnel_length = AIMap.DistanceManhattan(cur_node, other_tunnel_end);
  24.     local prev_tile = cur_node + (cur_node - other_tunnel_end) / tunnel_length;
  25.     if (AITunnel.GetOtherTunnelEnd(other_tunnel_end) == cur_node && tunnel_length >= 2 &&
  26.             prev_tile == 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