Advertisement
Guest User

AoE_Skillshot_Position

a guest
Jan 28th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. ---Begin AOE skill shot position ---
  2.  
  3. --Credit to Monogato. Modified by Dienofail--
  4.  
  5. require 'VPrediction'
  6.  
  7. local VP = VPrediction()
  8.  
  9. function GetCenter(points)
  10. local sum_x = 0
  11. local sum_z = 0
  12.  
  13. for i = 1, #points do
  14. sum_x = sum_x + points[i].x
  15. sum_z = sum_z + points[i].z
  16. end
  17.  
  18. local center = {x = sum_x / #points, y = 0, z = sum_z / #points}
  19.  
  20. return center
  21. end
  22.  
  23. function ContainsThemAll(circle, points)
  24. local radius_sqr = circle.radius*circle.radius
  25. local contains_them_all = true
  26. local i = 1
  27.  
  28. while contains_them_all and i <= #points do
  29. contains_them_all = GetDistanceSqr(points[i], circle.center) <= radius_sqr
  30. i = i + 1
  31. end
  32.  
  33. return contains_them_all
  34. end
  35.  
  36. -- The first element (which is gonna be main_target) is untouchable.
  37. function FarthestFromPositionIndex(points, position)
  38. local index = 2
  39. local actual_dist_sqr
  40. local max_dist_sqr = GetDistanceSqr(points[index], position)
  41.  
  42. for i = 3, #points do
  43. actual_dist_sqr = GetDistanceSqr(points[i], position)
  44. if actual_dist_sqr > max_dist_sqr then
  45. index = i
  46. max_dist_sqr = actual_dist_sqr
  47. end
  48. end
  49.  
  50. return index
  51. end
  52.  
  53. function RemoveWorst(targets, position)
  54. local worst_target = FarthestFromPositionIndex(targets, position)
  55.  
  56. table.remove(targets, worst_target)
  57.  
  58. return targets
  59. end
  60.  
  61. function GetInitialTargets(radius, main_target)
  62. local targets = {main_target}
  63. local diameter_sqr = 4 * radius * radius
  64.  
  65. for i=1, heroManager.iCount do
  66. target = heroManager:GetHero(i)
  67. if target.networkID ~= main_target.networkID and ValidTarget(target) and GetDistanceSqr(main_target, target) < diameter_sqr then table.insert(targets, target) end
  68. end
  69.  
  70. return targets
  71. end
  72.  
  73. function GetPredictedInitialTargets(radius, main_target, delay, speed, col) --col is true or false
  74. --if VIP_USER and not vip_target_predictor then vip_target_predictor = TargetPredictionVIP(nil, nil, delay/1000) end
  75. local predicted_main_target = VP:GetPredictedPos(main_target, delay, speed, myHero, col)
  76. local predicted_targets = {predicted_main_target}
  77. local diameter_sqr = 4 * radius * radius
  78.  
  79. for i=1, heroManager.iCount do
  80. target = heroManager:GetHero(i)
  81. if ValidTarget(target) then
  82. predicted_target = VP:GetPredictedPos(target, delay, speed, myHero, col)
  83. if target.networkID ~= main_target.networkID and GetDistanceSqr(predicted_main_target, predicted_target) < diameter_sqr then table.insert(predicted_targets, predicted_target) end
  84. end
  85. end
  86.  
  87. return predicted_targets
  88. end
  89.  
  90. -- I don´t need range since main_target is gonna be close enough. You can add it if you do.
  91. function GetAoESpellPosition(radius, main_target, delay, speed)
  92. local targets = GetPredictedInitialTargets(radius, main_target, delay, speed)
  93. local position = GetCenter(targets)
  94. local best_pos_found = true
  95. local circle = Circle(position, radius)
  96. circle.center = position
  97.  
  98. if #targets > 2 then best_pos_found = ContainsThemAll(circle, targets) end
  99.  
  100. while not best_pos_found do
  101. targets = RemoveWorst(targets, position)
  102. position = GetCenter(targets)
  103. circle.center = position
  104. best_pos_found = ContainsThemAll(circle, targets)
  105. end
  106.  
  107. return position
  108. end
  109.  
  110. function GetAoEBounces(radius, main_target, delay, speed)
  111. local targets = GetPredictedInitialTargets(radius, main_target, delay, speed)
  112. return #targets
  113. end
  114. --- End AOE skill shot position
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement