Guest User

Untitled

a guest
Apr 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. function Canal::_GetOtherDepotChainEnd(tile)
  2. {
  3. assert(AIMarine.IsWaterDepotTile(tile));
  4.  
  5. local offsets = [AIMap.GetTileIndex(0, 1), AIMap.GetTileIndex(0, -1),
  6. AIMap.GetTileIndex(1, 0), AIMap.GetTileIndex(-1, 0)];
  7.  
  8. local end_tile = tile;
  9. foreach (offset in offsets) {
  10. local next_tile = tile + offset;
  11. local cur_tile = tile;
  12. while (AIMarine.IsWaterDepotTile(next_tile) && AIMarine.AreWaterTilesConnected(cur_tile, next_tile)) {
  13. end_tile = next_tile;
  14. next_tile += offset;
  15. cur_tile += offset;
  16. }
  17. }
  18.  
  19. return end_tile;
  20. }
  21.  
  22. function Canal::_GetOtherDepotTile(tile)
  23. {
  24. assert(AIMarine.IsWaterDepotTile(tile));
  25.  
  26. local end1 = this._GetOtherDepotChainEnd(tile);
  27. local end2 = this._GetOtherDepotChainEnd(end1);
  28.  
  29. if (end1 > end2) {
  30. local swap = end1;
  31. end1 = end2;
  32. end2 = swap;
  33. }
  34.  
  35. local length = AIMap.DistanceManhattan(end1, end2) + 1;
  36.  
  37. local offset = AIMap.GetTileIndex(1, 0);
  38. if (AIMap.GetTileX(end1) == AIMap.GetTileX(end2)) {
  39. offset = AIMap.GetTileIndex(0, 1);
  40. }
  41.  
  42. local next_tile = end1 + offset;
  43. do {
  44. if (AIMarine.IsWaterDepotTile(next_tile) && AIMarine.AreWaterTilesConnected(end1, next_tile)) {
  45. if (end1 == tile) {
  46. return next_tile;
  47. } else if (next_tile == tile) {
  48. return end1;
  49. }
  50. end1 += 2 * offset;
  51. next_tile += 2 * offset;
  52. length -=2;
  53. }
  54. } while (length != 0);
  55. }
Add Comment
Please, Sign In to add comment