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:
- GeometryLibBase
- Select Cohadar's jasshelper in JNGP 5e and up
Actual Code
Changelog:
1.0: Initial release.
Feel free to comment.
This small library allows users to get the units in a line. This line can be defined by 2 points or 2 widgets.
Requirements:
- GeometryLibBase
- Select Cohadar's jasshelper in JNGP 5e and up
Actual Code
1 /******************************************************************2 * GROUP UNITS IN LINE v1.0 *3 * By moyack *4 * 2012 *5 * =================================== *6 * Exclusive resource from wc3jass.com *7 * =================================== *8 ******************************************************************/9 library GetUnitsInLine requires GeometryLibBase
10 /* This library catch all the units in a line. This line however,11 can be defined in several ways, each one will offer a function for12 that purpose:13 * Between 2 points: GetUnitsInLine_byPoints()14 * Between 2 widgets: GetUnitsInLine_byWidgets()15 16 The first function takes as arguments a group variable and 4 reals17 which are the X/Y coordinates of the first and second point.18 19 The second function takes as arguments a group variable and 2 widgets,20 these widgets can be any combination of units, items and destructables.21 22 The group variable for both functions will store the units catched in23 the line defined by points or widgets, so it's advisable that this group 24 should be empty.25 */26 globals27 private constant real SPREAD = 30. // this value defines how wide is the line of units selected
28 private group G = CreateGroup()
29 endglobals30 31 public function byPoints takes group g, real x1, real y1, real x2, real y2 returns nothing
32 local unit u
33 local real a
34 local real b
35 local real x = 0.5 * (x1 + x2)
36 local real y = 0.5 * (y1 + y2)
37 if g == null then
38 return39 endif40 call GroupEnumUnitsInRange(G, x, y, GetDistance(x, y, x1, y1) + SPREAD, null)
41 for u in G
42 if x2 - x1 == 0. then // manages vertical lines
43 set x = x1
44 set y = GetUnitY(u)
45 else46 set x = GetUnitX(u)
47 set a = (y2 - y1) / (x2 - x1)
48 set b = -a * x1 + y1
49 set y = a * x + b
50 endif51 if IsUnitInRangeXY(u, x, y, SPREAD) then
52 call GroupAddUnit(g, u)
53 endif54 endfor55 endfunction56 57 public function byWidgets takes group g, widget A, widget B returns nothing
58 call byPoints(g, GetWidgetX(A), GetWidgetY(A), GetWidgetX(B), GetWidgetY(B))
59 endfunction60 61 endlibrary
Changelog:
1.0: Initial release.
Feel free to comment.
