|
声明:本文为了叙述方便,所有过滤器在不指明情况下应理解为单位过滤器。
过滤器最根本的是一个returns boolean的函数
[jass]
type boolexpr extends handle
type filterfunc extends boolexpr
[/jass]
下面的函数接受一个code返回一个fiterfunc,理论上应该是return bug函数,但是war3中code和handle的句柄系统相分离,也可能不是。
[jass]
native Filter takes code func returns filterfunc
[/jass]
过滤器的工作其实就是用来检查每个送到过滤器的实例是否符合要求。
如单位过滤器就是用来检查单位是否符合要求,物品过滤器就检查物品...
过滤器有什么作用呢?
例如:下面的当触发让玩家输入"ga.wowar.com"后,给于该玩家的第一个英雄一本经验之书
[trigger]
新的触发器 001
事件
玩家 - 玩家 1 (红色) 当输入以下内容的聊天信息 ga.wowar.com, 匹配方式为 完全匹配
环境
动作
英雄 - 创建 经验之书 并且给 (First unit of group ((触发玩家) 的单位匹配条件 (((匹配的单位) 是 一个英雄) 等于 True (真))))
[/trigger]
该触发用到了bj中的过滤器,并没有自己写过滤器。但是已经能够不需要任何变量直接找到玩家的第一个英雄了。 另外做技能的时候希望技能的伤害范围呈半月型,扇形,或其他更怪的形状。需要用到过滤器。
做自定义的光环,也需要过滤器。
过滤器函数的质量当然是越快越好。
第一节完
总结:过滤器其实就是一个检查单位的函数。
过滤器的工作基础:
过滤器是工作在容器的基础上的。
有关的操作一般是“容器A到容器B之间应用过滤器”当然A和B也可能相等
什么意思呢?举个例子:把一杯(A)装了沙的水倒入另一个杯子B,中间用个加了滤纸的漏斗。
漏斗就是过滤器。漏斗的工作就是把从杯子A中流出的东西检验一下体积,体积大的就不允许通过。
一般情况下和容器相结合的还有适配器,适配器的工作就是确定容器中的东西按什么顺序出来。进入容器后放于哪里,适配器有栈适配器(后入先出),队列适配器(先入先出)...这些知识有兴趣的可以自己去了解。
在War3中过滤器我们已经知道了,它的本质是一种布尔函数(返回真假值的函数)。那么容器有是什么呢?
War3中的一个重要的容器就是unit group简称group中文叫单位组。
操作单位组需要的过滤器就叫单位过滤器。
认识过滤器和容器的API:
单位组容器API,里面有一些与适配器相关
[jass]
//============================================================================
// Group API
//
native CreateGroup takes nothing returns group
native DestroyGroup takes group whichGroup returns nothing
native GroupAddUnit takes group whichGroup, unit whichUnit returns nothing
native GroupRemoveUnit takes group whichGroup, unit whichUnit returns nothing
native GroupClear takes group whichGroup returns nothing
native GroupEnumUnitsOfType takes group whichGroup, string unitname, boolexpr filter returns nothing
native GroupEnumUnitsOfPlayer takes group whichGroup, player whichPlayer, boolexpr filter returns nothing
native GroupEnumUnitsOfTypeCounted takes group whichGroup, string unitname, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsInRect takes group whichGroup, rect r, boolexpr filter returns nothing
native GroupEnumUnitsInRectCounted takes group whichGroup, rect r, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsInRange takes group whichGroup, real x, real y, real radius, boolexpr filter returns nothing
native GroupEnumUnitsInRangeOfLoc takes group whichGroup, location whichLocation, real radius, boolexpr filter returns nothing
native GroupEnumUnitsInRangeCounted takes group whichGroup, real x, real y, real radius, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsInRangeOfLocCounted takes group whichGroup, location whichLocation, real radius, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsSelected takes group whichGroup, player whichPlayer, boolexpr filter returns nothing
native GroupImmediateOrder takes group whichGroup, string order returns boolean
native GroupImmediateOrderById takes group whichGroup, integer order returns boolean
native GroupPointOrder takes group whichGroup, string order, real x, real y returns boolean
native GroupPointOrderLoc takes group whichGroup, string order, location whichLocation returns boolean
native GroupPointOrderById takes group whichGroup, integer order, real x, real y returns boolean
native GroupPointOrderByIdLoc takes group whichGroup, integer order, location whichLocation returns boolean
native GroupTargetOrder takes group whichGroup, string order, widget targetWidget returns boolean
native GroupTargetOrderById takes group whichGroup, integer order, widget targetWidget returns boolean
// This will be difficult to support with potentially disjoint, cell-based regions
// as it would involve enumerating all the cells that are covered by a particularregion
// a better implementation would be a trigger that adds relevant units as they enter
// and removes them if they leave...
native ForGroup takes group whichGroup, code callback returns nothing
native FirstOfGroup takes group whichGroup returns unit
[/jass]
单位过滤器的入口和出口,即适配器的接口
[jass]
constant native GetFilterUnit takes nothing returns unit
constant native GetEnumUnit takes nothing returns unit
[/jass]
布尔函数API
[jass]
native And takes boolexpr operandA, boolexpr operandB returns boolexpr
native Or takes boolexpr operandA, boolexpr operandB returns boolexpr
native Not takes boolexpr operand returns boolexpr
native Condition takes code func returns conditionfunc
native DestroyCondition takes conditionfunc c returns nothing
native Filter takes code func returns filterfunc
native DestroyFilter takes filterfunc f returns nothing
native DestroyBoolExpr takes boolexpr e returns nothing
[/jass]
先写到这里
下次更新如何写过滤器和适配器 |
|