- Joined
- Jan 14, 2005
- Messages
- 105
Hello, hoping someone can help me optimizing this trigger.
What this trigger is:
It periodically checks if the Hero "GetOwningPlayer(GetFilterUnit()) == Player(1)" is in 90 degrees in front of the enemy's unit "Enemy[a]" and there should be no pathing blocker in between "YTpc".
As you can see, it's pretty unoptimized, since I made it in a rush, and I don't know if it leaks. I tried cleaning every leak that I know, but there must still be something that I missed.
This is made in v1.31 btw.
What this trigger is:
It periodically checks if the Hero "GetOwningPlayer(GetFilterUnit()) == Player(1)" is in 90 degrees in front of the enemy's unit "Enemy[a]" and there should be no pathing blocker in between "YTpc".
As you can see, it's pretty unoptimized, since I made it in a rush, and I don't know if it leaks. I tried cleaning every leak that I know, but there must still be something that I missed.
This is made in v1.31 btw.
JASS:
function AILineofSightFunc01 takes nothing returns boolean
return GetDestructableTypeId(GetFilterDestructable()) == 'YTpc'
endfunction
function AILineofSightFunc02 takes nothing returns boolean
return GetOwningPlayer(GetFilterUnit()) == Player(1) and IsUnitVisible(GetFilterUnit(), Player(2))
endfunction
function Trig_AI_Line_of_Sight_B_Actions takes nothing returns nothing
local integer a
local integer b
local integer c
local integer i
local integer maxdistance
local location array l
local location k
local location m
local rect n
local real r
local destructable d
local group g
local boolean v
set a = udg_tempInt_1
set maxdistance = 10
set g = null
set m = GetUnitLoc(udg_Enemy[a])
set r = GetUnitFacing(udg_Enemy[a])
set i = 0 //number of locations checked all throughout
//check straight line first
set c = 1
loop
exitwhen c > maxdistance
//checking for obstacles
set k = PolarProjectionBJ(m, (c*100), r)
set n = RectFromCenterSizeBJ(k, 200, 200)
set d = null
set d = RandomDestructableInRectBJ(n, Condition(function AILineofSightFunc01))
if d == null then //if no obstacles found, continue searching
set i = i + 1
set l[i] = PolarProjectionBJ(m, (c*100), r)
else
set c = maxdistance
endif
call RemoveLocation(k)
call RemoveRect(n)
set c = c + 1
endloop
//check right side (negative 11.25 degrees * 4)
set b = 1
loop
exitwhen b > 4
set c = 1
loop
exitwhen c > maxdistance
set k = PolarProjectionBJ(m, (c*100), r-(b*11.25))
set n = RectFromCenterSizeBJ(k, 200, 200)
set d = null
set d = RandomDestructableInRectBJ(n, Condition(function AILineofSightFunc01))
if d == null then //if no obstacles found, continue searching
set i = i + 1
set l[i] = PolarProjectionBJ(m, (c*100), r-(b*11.25))
else
set c = maxdistance
endif
call RemoveLocation(k)
call RemoveRect(n)
set c = c + 1
endloop
set b = b + 1
endloop
//check left side (11.25 degrees * 4)
set b = 1
loop
exitwhen b > 4
set c = 1
loop
exitwhen c > maxdistance
set k = PolarProjectionBJ(m, (c*100), r+(b*11.25))
set n = RectFromCenterSizeBJ(k, 200, 200)
set d = null
set d = RandomDestructableInRectBJ(n, Condition(function AILineofSightFunc01))
if d == null then //if no obstacles found, continue searching
set i = i + 1
set l[i] = PolarProjectionBJ(m, (c*100), r+(b*11.25))
else
set c = maxdistance
endif
call RemoveLocation(k)
call RemoveRect(n)
set c = c + 1
endloop
set b = b + 1
endloop
call RemoveLocation(m)
set m = null
set k = null
set n = null
set d = null
set v = false
//Check all created locations
set b = 1
loop
exitwhen b > i
call GroupClear(g)
set g = GetUnitsInRangeOfLocMatching(40, l[b], Condition(function AILineofSightFunc02))
if IsUnitGroupEmptyBJ(g) == false then
set v = true //The AI found the hero!
endif
call DestroyGroup(g)
call RemoveLocation(l[b])
set l[b] = null
set b = b + 1
endloop
set g = null
//Check if the AI found the hero or not
if v then
call TriggerExecute( gg_trg___AI_Hostility )
else
call TriggerExecute( gg_trg___AI_Hostility_Reduce )
endif
endfunction
//===========================================================================
function InitTrig_AI_Line_of_Sight_B takes nothing returns nothing
set gg_trg_AI_Line_of_Sight_B = CreateTrigger( )
call TriggerAddAction( gg_trg_AI_Line_of_Sight_B, function Trig_AI_Line_of_Sight_B_Actions )
endfunction