- Joined
- Apr 30, 2011
- Messages
- 359
JASS:
//========================================================================================
//
// Unit Type Filter
// -*- overcold_ice -*-
//
// -[*] Requirements:
// - JNGP
// - latest version of JassHelper
//
// -[*] Optional Requirements:
// - /*New*/Table
// [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url]
//
// For your unit type filter needs
// Provides all 27 types of UnitType filter to modify
// Those types' filter can be disabled, set to true or false
// If it's true, the filtered unit's IsUnitType value of it must be true also
// to make the filter returns true
// The same goes to false, both must be false to make the filter returns true
// This will be ignored if the type is disabled
// Each types is disabled by default, and false by default
//
// -[*] API:
//
// struct UnitTypeFilter extends array
// static method create takes nothing returns UnitTypeFilter
// method destroy takes nothing returns nothing
// allocator/deallocator for the struct
//
// method enableFilter takes unittype UnitType, boolean Enabled returns nothing
// enable/disable UnitTypeFilter of type UnitType
// method setFilter takes unittype UnitType, boolean Flag returns nothing
// set UnitTypeFilter of type UnitTypeFilterId to Flag
// if it's true, the filtered unit's IsUnitType must be true also to make
// the filter returns true
// the same goes to false, both must returns false to make the filter returns
// false
// method doFilter takes unit FilteredUnit returns boolean
// checks if every UnitTypes on the unit match the filter
// if it matches the filter, returns true
// otherwise, false
//
//========================================================================================
library UnitTypeFilter requires optional /*New*/Table
static if LIBRARY_Table then
private module Init
private static method onInit takes nothing returns nothing
set .table = TableArray [8192]
endmethod
endmodule
endif
struct UnitTypeFilter extends array
static if LIBRARY_Table then
private static TableArray table
else
private static hashtable ht = InitHashtable()
endif
private static integer c
private integer r
static method create takes nothing returns thistype
local thistype this = thistype(0).r
if this == 0 then
set .c = .c + 1
set this = .c
else
set thistype(0).r = this.r
endif
return this
endmethod
method enableFilter takes unittype f, boolean e returns nothing
static if LIBRARY_Table then
set .table [this].boolean [-GetHandleId(f)] = e
else
call SaveBoolean(.ht, this, -GetHandleId(f), e)
endif
endmethod
method setFilter takes unittype f, boolean b returns nothing
static if LIBRARY_Table then
set .table [this].boolean [GetHandleId(f)] = b
else
call SaveBoolean(.ht, this, GetHandleId(f), b)
endif
endmethod
method doFilter takes unit u returns boolean
local unittype ut
local integer id
local integer i = 0
loop
set ut = ConvertUnitType(i)
set id = GetHandleId(ut)
static if LIBRARY_Table then
if .table [this].boolean [-id] then
if IsUnitType(u, ut) != .table [this].boolean [id] then
set ut = null
return false
endif
endif
else
if LoadBoolean(.ht, this, -id) then
if IsUnitType(u, ut) != LoadBoolean(.ht, this, id) then
set ut = null
return false
endif
endif
endif
exitwhen i == 26
set i = i + 1
endloop
set ut = null
return true
endmethod
method destroy takes nothing returns nothing
static if LIBRARY_Table then
call .table [this].flush()
else
call FlushChildHashtable(.ht, this)
endif
set this.r = thistype(0).r
set thistype(0).r = this
endmethod
endstruct
endlibrary
Last edited: