13 years
edited 8 years
Description
This small library allows users to get the units in a line. This line can be defined by 2 points or 2 widgets.
Requirements:
- /******************************************************************2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
This small library allows users to get the units in a line. This line can be defined by 2 points or 2 widgets.
Requirements:
- /******************************************************************
* GROUP UNITS IN LINE v1.0 ** By moyack ** 2012 ** =================================== ** Exclusive resource from wc3jass.com ** =================================== *******************************************************************/library GetUnitsInLine requires GeometryLibBase
/* This library catch all the units in a line. This line however,can be defined in several ways, each one will offer a function forthat purpose: * Between 2 points: GetUnitsInLine_byPoints() * Between 2 widgets: GetUnitsInLine_byWidgets() The first function takes as arguments a group variable and 4 reals which are the X/Y coordinates of the first and second point. The second function takes as arguments a group variable and 2 widgets, these widgets can be any combination of units, items and destructables. The group variable for both functions will store the units catched in the line defined by points or widgets, so it's advisable that this group should be empty.*/globalsprivate constant real SPREAD = 30. // this value defines how wide is the line of units selected
private group G = CreateGroup()
endglobalspublic function byPoints takes group g, real x1, real y1, real x2, real y2 returns nothing
local unit u
local real a
local real b
local real x = 0.5 * (x1 + x2)
local real y = 0.5 * (y1 + y2)
if g == null then
return endifcall GroupEnumUnitsInRange(G, x, y, GetDistance(x, y, x1, y1) + SPREAD, null)
for u in G
if x2 - x1 == 0. then // manages vertical lines
set x = x1
set y = GetUnitY(u)
elseset x = GetUnitX(u)
set a = (y2 - y1) / (x2 - x1)
set b = -a * x1 + y1
set y = a * x + b
endifif IsUnitInRangeXY(u, x, y, SPREAD) then
call GroupAddUnit(g, u)
endif endforendfunctionpublic function byWidgets takes group g, widget A, widget B returns nothing
call byPoints(g, GetWidgetX(A), GetWidgetY(A), GetWidgetX(B), GetWidgetY(B))
endfunctionendlibrary
