Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.67 KB | None | 0 0
  1. library UnitInRangeOfType requires AIDS, Event, Alloc
  2.     globals
  3.         private key EVENT_KEY
  4.         private key TRIGGER_KEY
  5.         private key RANGE_KEY
  6.         private key TYPE_KEY
  7.     endglobals
  8.    
  9.     private struct idlist extends array
  10.         public static integer count = 0
  11.        
  12.         private method OnDestroy takes nothing returns nothing
  13.             set thistype.count = thistype.count - 1
  14.         endmethod
  15.        
  16.         implement Alloc
  17.        
  18.         public integer id
  19.        
  20.         public static method create takes integer id returns thistype
  21.             local thistype this = thistype.allocate()
  22.            
  23.             set this.id = id
  24.             set thistype.count = thistype.count + 1
  25.            
  26.             return this            
  27.         endmethod
  28.     endstruct
  29.    
  30.     private struct data extends array
  31.         public static hashtable hash
  32.         public Event e
  33.        
  34.         //! runtextmacro AIDS()
  35.        
  36.         private static method AIDS_filter takes unit u returns boolean
  37.             local integer i = idlist.count
  38.             local boolean b = false
  39.             local integer id = GetUnitTypeId(u)
  40.            
  41.             loop
  42.                 exitwhen i == 0
  43.                 set b = b or ( id == idlist[i].id )
  44.                 set i = i - 1
  45.             endloop
  46.            
  47.             return b
  48.         endmethod
  49.        
  50.         private static method OnEvent takes nothing returns boolean
  51.             call FireEvent(Event(LoadInteger(data.hash, LoadInteger(thistype.hash, GetHandleId(GetTriggeringTrigger()), TYPE_KEY), EVENT_KEY)))
  52.             return false
  53.         endmethod
  54.        
  55.         private method AIDS_onCreate takes nothing returns nothing
  56.             local trigger t = CreateTrigger()
  57.             local integer i = GetUnitTypeId(this.unit)
  58.             set this.e = Event.create()
  59.            
  60.             call TriggerRegisterUnitInRange(t, this.unit, LoadReal(thistype.hash, i, RANGE_KEY), null)
  61.             call TriggerAddCondition(t, Condition(function thistype.OnEvent))
  62.             call SaveInteger(thistype.hash, GetHandleId(t), TYPE_KEY, i)
  63.         endmethod
  64.        
  65.         private static method AIDS_onInit takes nothing returns nothing
  66.             set hash = InitHashtable()
  67.         endmethod
  68.     endstruct
  69.    
  70.     function TriggerRegisterUnitInRangeOfType takes trigger whichTrigger, integer whichType, real range returns Event
  71.         local Event e
  72.        
  73.         if ( HaveSavedInteger(data.hash, whichType, EVENT_KEY) ) then
  74.             set e = LoadInteger(data.hash, whichType, EVENT_KEY)
  75.         else
  76.             set e = Event.create()
  77.             call SaveInteger(data.hash, whichType, EVENT_KEY, e)
  78.             call TriggerRegisterEvent(whichTrigger, e)
  79.         endif
  80.        
  81.         call idlist.create(whichType)
  82.         call SaveTriggerHandle(data.hash, whichType, TRIGGER_KEY, whichTrigger)
  83.         call SaveReal(data.hash, whichType, RANGE_KEY, range)
  84.        
  85.         return e
  86.     endfunction
  87. endlibrary
  88.  
  89. struct asdf extends array
  90.     private static method a takes nothing returns nothing
  91.         call BJDebugMsg("Test")
  92.     endmethod
  93.    
  94.     private static method onInit takes nothing returns nothing
  95.         local trigger t = CreateTrigger()
  96.         call CreateUnit(Player(0), 'hfoo', 0, 0, 0)
  97.         call CreateUnit(Player(0), 'hfoo', 0, 550, 0)
  98.         call CreateUnit(Player(0), 'hfoo', 0, -550, 0)
  99.         call CreateUnit(Player(0), 'hkni', 550, 0, 0)
  100.         call CreateUnit(Player(0), 'hkni', -550, 0, 0)
  101.         call TriggerRegisterUnitInRangeOfType(t, 'hfoo', 500)
  102.         call TriggerAddAction(t, function thistype.a)
  103.     endmethod
  104. endstruct
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement