Name | Type | is_array | initial_value |
Lightning | lightning | Yes | |
LSE_Destructable | destructable | Yes | |
LSE_DestructableCounter | integer | No | |
LSE_Example_Lightning | trigger | No | |
LSE_GetDestructables | trigger | No | |
LSE_GetItems | trigger | No | |
LSE_GetUnits | trigger | No | |
LSE_Group | group | No | |
LSE_Item | item | Yes | |
LSE_ItemCounter | integer | No | |
LSE_Loc_1 | location | No | |
LSE_Loc_2 | location | No | |
LSE_Offset | real | No | |
LSE_Rect | rect | No | |
LSE_UnitCollisionFlag | boolean | No | |
Unit1 | unit | No | |
Unit2 | unit | No |
--Global Initialization 1.1 also hooks the InitCustomTriggers and RunInitializationTriggers functions
do
local gFuncs = {}
local tFuncs = {}
local iFuncs = {}
function onGlobalInit(func) --Runs once all variables are instantiated.
gFuncs[func] = func --Simplification thanks to TheReviewer and Zed on Hive Discord
end
function onTriggerInit(func) -- Runs once all InitTrig_ are called
tFuncs[func] = func
end
function onInitialization(func) -- Runs once all Map Initialization triggers are run
iFuncs[func] = func
end
local function runInitialization()
for k, f in pairs(iFuncs) do f() end
iFuncs = nil
end
local function runTriggerInit()
for k, f in pairs(tFuncs) do f() end
tFuncs = nil
local old = RunInitializationTriggers
if old then
function RunInitializationTriggers()
old()
runInitialization()
end
else
runInitialization()
end
end
local function runGlobalInit()
for k, f in pairs(gFuncs) do f() end
gFuncs = nil
local old = InitCustomTriggers
if old then
function InitCustomTriggers()
old()
runTriggerInit()
end
else
runTriggerInit()
end
end
local oldBliz = InitBlizzard
function InitBlizzard()
oldBliz()
local old = InitGlobals
if old then
function InitGlobals()
old()
runGlobalInit()
end
else
runGlobalInit()
end
end
end
--[[ LineSegmentEnumeration v2.2a
API:
function LineSegment.EnumUnits(number: ax, number: ay, number: bx, number: by, number: offset, boolean: checkCollision)
function LineSegment.EnumDestructables(number: ax, number: ay, number: bx, number: by, number: offset)
function LineSegment.EnumItems(number: ax, number: ay, number: bx, number: by, number: offset)
- returns the enumerated widgets as a table
]]--
LineSegment = {}
do
local RECT = Rect(0, 0, 0, 0)
local GROUP = CreateGroup()
local ox
local oy
local dx
local dy
local da
local db
local ui
local uj
local wdx
local wdy
local uui
local uuj
local function prepare_rect(ax, ay, bx, by, offset)
local x_max
local x_min
local y_max
local y_min
-- get center coordinates of rectangle
ox, oy = 0.5*(ax + bx), 0.5*(ay + by)
-- get rectangle major axis as vector
dx, dy = 0.5*(bx - ax), 0.5*(by - ay)
-- get half of rectangle length (da) and height (db)
da, db = math.sqrt(dx*dx + dy*dy), offset
-- get unit vector of the major axis
ui, uj = dx/da, dy/da
-- prepare bounding rect
if ax > bx then
x_min, x_max = bx - offset, ax + offset
else
x_min, x_max = ax - offset, bx + offset
end
if ay > by then
y_min, y_max = by - offset, ay + offset
else
y_min, y_max = ay - offset, by + offset
end
SetRect(RECT, x_min, y_min, x_max, y_max)
end
local function rect_contains_widget(w, offset)
wdx, wdy = GetWidgetX(w) - ox, GetWidgetY(w) - oy
dx, dy = wdx*ui + wdy*uj, wdx*(-uj) + wdy*ui
da, db = da + offset, db + offset
return dx*dx <= da*da and dy*dy <= db*db
end
local function widget_filter(w, offset)
if rect_contains_widget(w, offset) then
table.insert(LineSegment.enumed, w)
end
end
function LineSegment.EnumUnits(ax, ay, bx, by, offset, checkCollision)
prepare_rect(ax, ay, bx, by, offset)
GroupEnumUnitsInRect(GROUP, RECT)
local enumed = {}
LineSegment.enumed = enumed
for i = 1, BlzGroupGetSize(GROUP) do
local u = BlzGroupUnitAt(GROUP, i)
widget_filter(u, checkCollision and BlzGetUnitCollisionSize(u) or 0.)
end
return enumed
end
function LineSegment.EnumDestructables(ax, ay, bx, by, offset)
prepare_rect(ax, ay, bx, by, offset)
local enumed = {}
LineSegment.enumed = enumed
EnumDestructablesInRect(RECT, Filter(function ()
widget_filter(GetFilterDestructable(), 0.)
end))
return enumed
end
function LineSegment.EnumItems(ax, ay, bx, by, offset)
prepare_rect(ax, ay, bx, by, offset)
local enumed = {}
LineSegment.enumed = enumed
EnumItemsInRect(RECT, Filter(function ()
widget_filter(GetFilterItem(), 0.)
end))
return enumed
end
end
onTriggerInit(function ()
udg_LSE_GetUnits = CreateTrigger()
udg_LSE_GetDestructables = CreateTrigger()
udg_LSE_GetItems = CreateTrigger()
TriggerAddAction(udg_LSE_GetUnits, function ()
LineSegment.EnumUnits(GetLocationX(udg_LSE_Loc_1), GetLocationY(udg_LSE_Loc_1), GetLocationX(udg_LSE_Loc_2), GetLocationY(udg_LSE_Loc_2), udg_LSE_Offset, udg_LSE_UnitCollisionFlag)
for i = 1, #LineSegment.enumed do
GroupAddUnit(udg_LSE_Group, LineSegment.enumed[i])
end
LineSegment.enumed = nil
end)
TriggerAddAction(udg_LSE_GetDestructables, function ()
LineSegment.EnumDestructables(GetLocationX(udg_LSE_Loc_1), GetLocationY(udg_LSE_Loc_1), GetLocationX(udg_LSE_Loc_2), GetLocationY(udg_LSE_Loc_2), udg_LSE_Offset)
udg_LSE_DestructableCounter = 0
for i = 1, #LineSegment.enumed do
udg_LSE_DestructableCounter = udg_LSE_DestructableCounter + 1
udg_LSE_Destructable[udg_LSE_DestructableCounter] = LineSegment.enumed[i]
end
LineSegment.enumed = nil
end)
TriggerAddAction(udg_LSE_GetItems, function ()
LineSegment.EnumItems(GetLocationX(udg_LSE_Loc_1), GetLocationY(udg_LSE_Loc_1), GetLocationX(udg_LSE_Loc_2), GetLocationY(udg_LSE_Loc_2), udg_LSE_Offset)
udg_LSE_ItemCounter = 0
for i = 1, #LineSegment.enumed do
udg_LSE_ItemCounter = udg_LSE_ItemCounter + 1
udg_LSE_Item[udg_LSE_ItemCounter] = LineSegment.enumed[i]
end
LineSegment.enumed = nil
end)
end)
onInitialization(function ()
udg_LSE_Example_Lightning = CreateTrigger( )
TriggerAddAction( udg_LSE_Example_Lightning, function ()
local ax, ay = GetUnitX(udg_Unit1), GetUnitY(udg_Unit1)
local bx, by = GetUnitX(udg_Unit2), GetUnitY(udg_Unit2)
local angle = Atan2(by - ay, bx - ax)
local x1, y1 = ax + udg_LSE_Offset*Cos(angle + bj_PI*0.5), ay + udg_LSE_Offset*Sin(angle + bj_PI*0.5)
local x2, y2 = ax + udg_LSE_Offset*Cos(angle - bj_PI*0.5), ay + udg_LSE_Offset*Sin(angle - bj_PI*0.5)
MoveLightningEx(udg_Lightning[0], true, x1, y1, 0, x2, y2, 0)
x1, y1 = ax + udg_LSE_Offset*Cos(angle + bj_PI*0.5), ay + udg_LSE_Offset*Sin(angle + bj_PI*0.5)
x2, y2 = bx + udg_LSE_Offset*Cos(angle + bj_PI*0.5), by + udg_LSE_Offset*Sin(angle + bj_PI*0.5)
MoveLightningEx(udg_Lightning[1], true, x1, y1, 0, x2, y2, 0)
x1, y1 = bx + udg_LSE_Offset*Cos(angle - bj_PI*0.5), by + udg_LSE_Offset*Sin(angle - bj_PI*0.5)
x2, y2 = ax + udg_LSE_Offset*Cos(angle - bj_PI*0.5), ay + udg_LSE_Offset*Sin(angle - bj_PI*0.5)
MoveLightningEx(udg_Lightning[2], true, x1, y1, 0, x2, y2, 0)
x1, y1 = bx + udg_LSE_Offset*Cos(angle + bj_PI*0.5), by + udg_LSE_Offset*Sin(angle + bj_PI*0.5)
x2, y2 = bx + udg_LSE_Offset*Cos(angle - bj_PI*0.5), by + udg_LSE_Offset*Sin(angle - bj_PI*0.5)
MoveLightningEx(udg_Lightning[3], true, x1, y1, 0, x2, y2, 0)
end)
end)