// Camouflage
// Coded by Zerzax as per Fulla's Request in Pyrogasm's Spell Request Thread
// Uses: Table
scope Camouflage initializer init
// Configuration Section
globals
private constant integer ABILITY_ID = 039;A002039;
private constant integer INVIS_ID = 039;A001039;
private constant integer PRELOAD_ID = 039;h000039;
// Timer Interval. Keep it large to minimize processing burdens.
private constant real INTERVAL = 0.10
endglobals
// Range of trees.
private function Range takes integer level returns real
return 100.00 + level * 55.00
endfunction
// How many times the timer must run while the unit is out of range.
private function FadeOut takes integer level returns integer
return 7 + R2I( 3.3 * level )
endfunction
// Acceptable destructable types (that are trees)
private function TreeTypes takes integer id returns boolean
return id == 039;ATtr039; or id == 039;BTtw039; or id == 039;KTtw039; or id == 039;YTft039; or id == 039;JTct039; or id == 039;YTst039; or id == 039;YTct039; or id == 039;YTwt039; or id == 039;JTwt039; or id == 039;JTwt039; or id == 039;FTtw039; or id == 039;CTtr039; or id == 039;ITtw039; or id == 039;NTtw039; or id == 039;OTtw039; or id == 039;ZTtw039; or id == 039;WTst039; or id == 039;LTlt039; or id == 039;GTsh039; or id == 039;Xtlt039; or id == 039;WTtw039; or id == 039;Attc039; or id == 039;BTtc039; or id == 039;CTtc039; or id == 039;ITtc039; or id == 039;NTtc039; or id == 039;ZTtc039;
endfunction
// End of config. No Touchie!
globals
private group Camouflaged = CreateGroup()
private rect TreeFinder = null
private HandleTable FadeCounter
private boolexpr TreeFilter = null
private boolean FoundTrees = false
endglobals
private function FindTree takes nothing returns boolean
return TreeTypes(GetDestructableTypeId(GetFilterDestructable()))
endfunction
private function FoundTree takes nothing returns nothing
set FoundTrees = true
endfunction
private function Enum takes nothing returns nothing
local unit camouflaged = GetEnumUnit()
local real cX = GetUnitX(camouflaged)
local real cY = GetUnitY(camouflaged)
local integer lvl = GetUnitAbilityLevel(camouflaged, ABILITY_ID)
local real range = Range(lvl)
call SetRect(TreeFinder, cX - range, cY - range, cX + range, cY + range)
call EnumDestructablesInRect(TreeFinder, TreeFilter, function FoundTree) // Enumerate.
if FoundTrees then // Then the current unit is in range.
set FoundTrees = false
if GetUnitAbilityLevel(camouflaged, INVIS_ID) == 0 then
call UnitAddAbility(camouflaged, INVIS_ID) // Add so he can fade in.
call SetUnitAbilityLevel(camouflaged, INVIS_ID, lvl)
else
set FadeCounter[camouflaged] = 0 // Restart fade-out process
endif
elseif GetUnitAbilityLevel(camouflaged, INVIS_ID) > 0 then // Start the fade proccess.
set FadeCounter[camouflaged] = FadeCounter[camouflaged] + 1
if FadeCounter[camouflaged] >= FadeOut(lvl) then
call UnitRemoveAbility(camouflaged, INVIS_ID) // Fully faded.
set FadeCounter[camouflaged] = 0
endif
endif
set camouflaged = null
endfunction
private function GroupEnum takes nothing returns nothing
call ForGroup(Camouflaged, function Enum) // Perform enum action on all learned units.
endfunction
private function LearnCondition2 takes nothing returns boolean
return (GetUnitAbilityLevel(GetEnumUnit(), ABILITY_ID) > 0)
endfunction
private function LearnCondition takes nothing returns boolean
return (GetUnitAbilityLevel(GetTriggerUnit(), ABILITY_ID) > 0)
endfunction
private function OnLearn2 takes nothing returns nothing
set FadeCounter[GetEnumUnit()] = 0
endfunction
private function OnLearn takes nothing returns nothing
local unit learn = GetTriggerUnit() // The hero has learned the ability.
if GetUnitAbilityLevel(learn, ABILITY_ID) > 0 then
call GroupAddUnit(Camouflaged, learn)
set FadeCounter[learn] = 0
endif
set learn = null
endfunction
private function init takes nothing returns nothing // Preload, trigger creation, handle creation.
local unit preload = CreateUnit(Player(15), PRELOAD_ID, 0,0,0)
local trigger t = CreateTrigger()
call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
call TriggerAddAction(t, function OnLearn)
call TriggerAddCondition(t, Condition(function LearnCondition))
call GroupEnumUnitsInRect(Camouflaged, bj_mapInitialPlayableArea, Condition(function LearnCondition2))
call ForGroup(Camouflaged, function OnLearn2)
set FadeCounter = HandleTable.create()
set TreeFinder = Rect(0,0,0,0)
set TreeFilter = Filter(function FindTree)
set Camouflaged = CreateGroup()
call TimerStart(CreateTimer(), INTERVAL, true, function GroupEnum)
call UnitAddAbility(preload, ABILITY_ID)
call UnitAddAbility(preload, INVIS_ID)
call UnitRemoveAbility(preload, ABILITY_ID)
call UnitRemoveAbility(preload, INVIS_ID)
call RemoveUnit(preload)
set preload = null
endfunction
endscope
// Camouflage
// Coded by Zerzax as per Fulla's Request in Pyrogasm's Spell Request Thread
// Uses: Table
scope Camouflage initializer init
// Configuration Section
globals
private constant integer ABILITY_ID = 039;A002039;
private constant integer INVIS_ID = 039;A001039;
private constant integer PRELOAD_ID = 039;h000039;
private constant integer RESEARCH_ID = 039;R000039;
// Timer Interval. Keep it large to minimize processing burdens.
private constant real INTERVAL = 0.10
endglobals
// Range of trees.
private function Range takes integer level returns real
return 100.00 + level * 55.00
endfunction
// How many times the timer must run while the unit is out of range.
private function FadeOut takes integer level returns integer
return 7 + R2I( 3.3 * level )
endfunction
// Acceptable destructable types (that are trees)
private function TreeTypes takes integer id returns boolean
return id == 039;ATtr039; or id == 039;BTtw039; or id == 039;KTtw039; or id == 039;YTft039; or id == 039;JTct039; or id == 039;YTst039; or id == 039;YTct039; or id == 039;YTwt039; or id == 039;JTwt039; or id == 039;JTwt039; or id == 039;FTtw039; or id == 039;CTtr039; or id == 039;ITtw039; or id == 039;NTtw039; or id == 039;OTtw039; or id == 039;ZTtw039; or id == 039;WTst039; or id == 039;LTlt039; or id == 039;GTsh039; or id == 039;Xtlt039; or id == 039;WTtw039; or id == 039;Attc039; or id == 039;BTtc039; or id == 039;CTtc039; or id == 039;ITtc039; or id == 039;NTtc039; or id == 039;ZTtc039;
endfunction
// End of config. No Touchie!
globals
private group Camouflaged = CreateGroup()
private rect TreeFinder = null
private HandleTable FadeCounter
private boolexpr TreeFilter = null
private boolean FoundTrees = false
endglobals
private function FindTree takes nothing returns boolean
return TreeTypes(GetDestructableTypeId(GetFilterDestructable()))
endfunction
private function FoundTree takes nothing returns nothing
set FoundTrees = true
endfunction
private function Enum takes nothing returns nothing
local unit camouflaged = GetEnumUnit()
local real cX = GetUnitX(camouflaged)
local real cY = GetUnitY(camouflaged)
local integer lvl = GetUnitAbilityLevel(camouflaged, ABILITY_ID)
local real range = Range(lvl)
if (not GetPlayerTechResearched(GetOwningPlayer(GetEnumUnit()), RESEARCH_ID, true)) then
set camouflaged = null
return
endif
call SetRect(TreeFinder, cX - range, cY - range, cX + range, cY + range)
call EnumDestructablesInRect(TreeFinder, TreeFilter, function FoundTree) // Enumerate.
if FoundTrees then // Then the current unit is in range.
set FoundTrees = false
if GetUnitAbilityLevel(camouflaged, INVIS_ID) == 0 then
call UnitAddAbility(camouflaged, INVIS_ID) // Add so he can fade in.
call SetUnitAbilityLevel(camouflaged, INVIS_ID, lvl)
else
set FadeCounter[camouflaged] = 0 // Restart fade-out process
endif
elseif GetUnitAbilityLevel(camouflaged, INVIS_ID) > 0 then // Start the fade proccess.
set FadeCounter[camouflaged] = FadeCounter[camouflaged] + 1
if FadeCounter[camouflaged] >= FadeOut(lvl) then
call UnitRemoveAbility(camouflaged, INVIS_ID) // Fully faded.
set FadeCounter[camouflaged] = 0
endif
endif
set camouflaged = null
endfunction
private function GroupEnum takes nothing returns nothing
call ForGroup(Camouflaged, function Enum) // Perform enum action on all learned units.
endfunction
private function LearnCondition2 takes nothing returns boolean
return (GetUnitAbilityLevel(GetEnumUnit(), ABILITY_ID) > 0)
endfunction
private function LearnCondition takes nothing returns boolean
return (GetUnitAbilityLevel(GetTriggerUnit(), ABILITY_ID) > 0)
endfunction
private function OnLearn2 takes nothing returns nothing
set FadeCounter[GetEnumUnit()] = 0
endfunction
private function OnLearn takes nothing returns nothing
local unit learn = GetTriggerUnit() // The hero has learned the ability.
if GetUnitAbilityLevel(learn, ABILITY_ID) > 0 then
call GroupAddUnit(Camouflaged, learn)
set FadeCounter[learn] = 0
endif
set learn = null
endfunction
private function init takes nothing returns nothing // Preload, trigger creation, handle creation.
local unit preload = CreateUnit(Player(15), PRELOAD_ID, 0,0,0)
local trigger t = CreateTrigger()
call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
call TriggerAddAction(t, function OnLearn)
call TriggerAddCondition(t, Condition(function LearnCondition))
set FadeCounter = HandleTable.create()
set TreeFinder = Rect(0,0,0,0)
set TreeFilter = Filter(function FindTree)
set Camouflaged = CreateGroup()
call TimerStart(CreateTimer(), INTERVAL, true, function GroupEnum)
call UnitAddAbility(preload, ABILITY_ID)
call UnitAddAbility(preload, INVIS_ID)
call UnitRemoveAbility(preload, ABILITY_ID)
call UnitRemoveAbility(preload, INVIS_ID)
call RemoveUnit(preload)
set preload = null
call GroupEnumUnitsInRect(Camouflaged, bj_mapInitialPlayableArea, Condition(function LearnCondition2))
call ForGroup(Camouflaged, function OnLearn2)
endfunction
endscope