Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /**
  2. * Get the aqueduct that can be built from the current
  3. * tile. Aqueducts are only build on sloped tiles.
  4. */
  5. function Canal::_GetAqueduct(last_node, cur_node, aqueduct_dir)
  6. {
  7. local slope = AITile.GetSlope(cur_node);
  8. local offset;
  9. if (slope == AITile.SLOPE_NE) {
  10. offset = AIMap.GetTileIndex(-1, 0);
  11. } else if (slope == AITile.SLOPE_SE) {
  12. offset = AIMap.GetTileIndex(0, 1);
  13. } else if (slope == AITile.SLOPE_NW) {
  14. offset = AIMap.GetTileIndex(0, -1);
  15. } else if (slope == AITile.SLOPE_SW) {
  16. offset = AIMap.GetTileIndex(1, 0);
  17. } else {
  18. return [];
  19. }
  20.  
  21. if (last_node != cur_node + offset) {
  22. return [];
  23. }
  24.  
  25. local s_min_height = AITile.GetMinHeight(cur_node);
  26. local s_max_height = AITile.GetMaxHeight(cur_node);
  27. for (local i = 1; i < this._max_aqueduct_length; i++) {
  28. local next_tile = cur_node + i * (cur_node - last_node);
  29. local aqueduct = AIBridge.BuildBridge(AIVehicle.VT_WATER, 0, cur_node, next_tile);
  30. if (!AIMap.IsValidTile(next_tile)) {
  31. return [];
  32. }
  33. local e_max_height = AITile.GetMaxHeight(next_tile);
  34. if (e_max_height < s_max_height) {
  35. continue;
  36. }
  37. local e_min_height = AITile.GetMinHeight(next_tile);
  38. if (e_max_height > s_max_height || e_min_height < s_min_height) {
  39. return [];
  40. }
  41. if (AIBridge.BuildBridge(AIVehicle.VT_WATER, 0, cur_node, next_tile)) {
  42. return [next_tile, aqueduct_dir, AITileList()];
  43. } else {
  44. return [];
  45. }
  46. }
  47.  
  48. return [];
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement