- Joined
- Jun 21, 2012
- Messages
- 431
I have time that I do not upload something here...
This library is similar to The Filtering System but with less code and more understandable, or I think so:
This library is similar to The Filtering System but with less code and more understandable, or I think so:
JASS:
library UnitFilter
//* =========================================================================== *
//* UnitFilter *
//* ¯¯¯¯¯¯¯¯¯¯ *
//* v0.1.1.2 *
//* by Trigger.edge *
//* *
//* struct UnitFilter extends array *
//* *
//* - method pass takes unit target, player source returns boolean *
//* *
//* How to use: *
//* ¯¯¯¯¯¯¯¯¯¯ *
//* local UnitFilter uf = UF_NOT_ENEMY + UF_STRUCTURE + UF_OR_MAGIC_IMMUNE*
//* *
//* if uf.pass(target_unit, source_player) then *
//* // actions *
//* endif *
//* *
//* =========================================================================== */
native UnitAlive takes unit id returns boolean
/*
UnitFilter globals
*/
//! textmacro UF_baseFilters takes FILTER_NAME,FILTER_SIZE_1,FILTER_SIZE_2,FILTER_SIZE_3,FILTER_SIZE_4
constant integer UF_AND_$FILTER_NAME$=$FILTER_SIZE_1$
constant integer UF_NOT_$FILTER_NAME$=$FILTER_SIZE_2$
constant integer UF_OR_$FILTER_NAME$=$FILTER_SIZE_3$
constant integer UF_OR_NOT_$FILTER_NAME$=$FILTER_SIZE_4$
//! endtextmacro
globals
//! runtextmacro UF_baseFilters( "ALLY ", "0x1" , "0x2" , "0x4" , "0x8" )
//! runtextmacro UF_baseFilters( "ALIVE ", "0x10" , "0x12" , "0x14" , "0x18" )
//! runtextmacro UF_baseFilters( "HERO ", "0x20" , "0x22" , "0x24" , "0x28" )
//! runtextmacro UF_baseFilters( "STRUCTURE ", "0x30" , "0x32" , "0x34" , "0x38" )
//! runtextmacro UF_baseFilters( "MAGIC_IMMUNE ", "0x40" , "0x42" , "0x44" , "0x48" )
//! runtextmacro UF_baseFilters( "ILLUSION ", "0x50" , "0x52", "0x54", "0x58" )
//! runtextmacro UF_baseFilters( "SUMMONED ", "0x60" , "0x62", "0x64", "0x68" )
//! runtextmacro UF_baseFilters( "STUNNED ", "0x70" , "0x72", "0x74", "0x78" )
//! runtextmacro UF_baseFilters( "VISIBLE ", "0x80" , "0x82", "0x84", "0x88" )
//! runtextmacro UF_baseFilters( "INVISIBLE ", "0x90" , "0x92", "0x94", "0x98" )
//! runtextmacro UF_baseFilters( "FOGGED ", "0x100", "0x102", "0x104", "0x108" )
//! runtextmacro UF_baseFilters( "MASKED ", "0x110", "0x112", "0x114", "0x118" )
//! runtextmacro UF_baseFilters( "PAUSED ", "0x120", "0x122", "0x124", "0x128" )
//! runtextmacro UF_baseFilters( "SELECTED ", "0x130", "0x132", "0x134", "0x138" )
//! runtextmacro UF_baseFilters( "FLYING ", "0x140", "0x142", "0x144", "0x148" )
//! runtextmacro UF_baseFilters( "GROUND ", "0x150", "0x152", "0x154", "0x158" )
//! runtextmacro UF_baseFilters( "MELEE_ATTACKER ", "0x160", "0x162", "0x164", "0x168" )
//! runtextmacro UF_baseFilters( "RANGED_ATTACKER", "0x170", "0x172", "0x174", "0x178" )
//! runtextmacro UF_baseFilters( "POLYMORPHED ", "0x180", "0x182", "0x184", "0x188" )
//! runtextmacro UF_baseFilters( "SLEEPING ", "0x190", "0x192", "0x194", "0x198" )
//! runtextmacro UF_baseFilters( "ETHEREAL ", "0x200", "0x202", "0x204", "0x208" )
//! runtextmacro UF_baseFilters( "UNDEAD ", "0x210", "0x212", "0x214", "0x218" )
//! runtextmacro UF_baseFilters( "MECHANICAL ", "0x220", "0x222", "0x224", "0x228" )
//! runtextmacro UF_baseFilters( "PEON ", "0x230", "0x232", "0x234", "0x238" )
//! runtextmacro UF_baseFilters( "TOWNHALL ", "0x240", "0x242", "0x244", "0x248" )
endglobals
/*
Textmacros operators: AND, NOT, OR, OR_NOT
*/
//! textmacro UF_bitwise takes BOOLEAN,AND_FILTER_SIZE,NOT_FILTER_SIZE,OR_FILTER_SIZE,OR_NOT_FILTER_SIZE
if(this>=$AND_FILTER_SIZE$)then
if(not $BOOLEAN$)then
return false
endif
set this=this-$AND_FILTER_SIZE$
endif
if(this>=$NOT_FILTER_SIZE$)then
if($BOOLEAN$)then
return false
endif
set this=this-$NOT_FILTER_SIZE$
endif
if(this>=$OR_FILTER_SIZE$)then
if($BOOLEAN$)then
return true
endif
set this=this-$OR_FILTER_SIZE$
endif
if(this>=$OR_NOT_FILTER_SIZE$)then
if(not $BOOLEAN$)then
return true
endif
set this=this-$OR_NOT_FILTER_SIZE$
endif
//! endtextmacro
struct UnitFilter extends array
method pass takes unit target, player source returns boolean
if(0x200<=this)then
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_TOWNHALL) ", "0x240", "0x242", "0x244", "0x248" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_PEON) ", "0x230", "0x232", "0x234", "0x238" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_MECHANICAL) ", "0x220", "0x222", "0x224", "0x228" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_UNDEAD) ", "0x210", "0x212", "0x214", "0x218" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_ETHEREAL) ", "0x200", "0x202", "0x204", "0x208" )
endif
if(0x150<=this)then
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_SLEEPING) ", "0x190", "0x192", "0x194", "0x198" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_POLYMORPHED) ", "0x180", "0x182", "0x184", "0x188" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_RANGED_ATTACKER)", "0x170", "0x172", "0x174", "0x178" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_MELEE_ATTACKER) ", "0x160", "0x162", "0x164", "0x168" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_GROUND) ", "0x150", "0x152", "0x154", "0x158" )
endif
if(0x100<=this)then
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_FLYING) ", "0x140", "0x142", "0x144", "0x148" )
//! runtextmacro UF_bitwise( "IsUnitSelected(target,source) ", "0x130", "0x132", "0x134", "0x138" )
//! runtextmacro UF_bitwise( "IsUnitPaused(target) ", "0x120", "0x122", "0x124", "0x128" )
//! runtextmacro UF_bitwise( "IsUnitMasked(target,source) ", "0x110", "0x112", "0x114", "0x118" )
//! runtextmacro UF_bitwise( "IsUnitFogged(target,source) ", "0x100", "0x102", "0x104", "0x108" )
endif
if(0x50<=this)then
//! runtextmacro UF_bitwise( "IsUnitInvisible(target,source) ", "0x90", "0x92", "0x94", "0x98" )
//! runtextmacro UF_bitwise( "IsUnitVisible(target,source) ", "0x80", "0x82", "0x84", "0x88" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_STUNNED) ", "0x70", "0x72", "0x74", "0x78" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_SUMMONED) ", "0x60", "0x62", "0x64", "0x68" )
//! runtextmacro UF_bitwise( "IsUnitIllusion(target) ", "0x50", "0x52", "0x54", "0x58" )
endif
if(0x01<=this)then
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_MAGIC_IMMUNE) ", "0x40", "0x42", "0x44", "0x48" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_STRUCTURE) ", "0x30", "0x32", "0x34", "0x38" )
//! runtextmacro UF_bitwise( "IsUnitType(target,UNIT_TYPE_HERO) ", "0x20", "0x22", "0x24", "0x28" )
//! runtextmacro UF_bitwise( "UnitAlive(target) ", "0x10", "0x12", "0x14", "0x18" )
//! runtextmacro UF_bitwise( "IsUnitEnemy(target,source) ", "0x1", "0x2", "0x4", "0x8" )
endif
return true
endmethod
endstruct
endlibrary
Last edited: