|
[jass]
library Filter
//Filter系统
/*提供一个通用的filter解决方案,包括包含参数的filter示例.
示例1:创建一个filter
参考function Alive 调用方式见test函数的*2
示例2:创建一个filter
参考function Filter_UnDummy 调用方式见test函数的*3
示例3:创建一个包含参数的filter
参考function Filter_Enemy 调用方式见test函数的*1
示例4:创建一个复数功能的filter
参考function Filter_Enemy_Alive
*/
//单位组选取存活的单位
public function Alive takes nothing returns boolean
return IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD)==false
endfunction
//单位组选取非蝗虫单位
private function UnDummy takes nothing returns boolean
return GetUnitAbilityLevel(GetFilterUnit(),'Aloc')==0
endfunction
function Filter_UnDummy takes nothing returns boolexpr
return Filter(function UnDummy)
endfunction
//单位组选取单位a的敌军单位
globals
private unit u
endglobals
private function Enemy takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(u))
endfunction
function Filter_Enemy takes unit a returns boolexpr
set u=a
return Filter(function Enemy)
endfunction
//单位组选取存活的敌军
function Filter_Enemy_Alive takes unit a returns boolexpr
return And(Filter_Enemy(a),function Alive)
endfunction
endlibrary
function test takes nothing returns nothing
call GroupEnumUnitsInRange(CreateGroup(),0,0,0,Filter_Enemy(GetTriggerUnit()))//*1
call GroupEnumUnitsInRect(CreateGroup(),bj_mapInitialPlayableArea,function Filter_Alive)//*2
call TriggerRegisterPlayerUnitEvent(CreateTrigger(),Player(0),EVENT_PLAYER_UNIT_DEATH,Filter_UnDummy())//*3
endfunction
[/jass]
|
|