vJass модуль list

Добавлен , опубликован
Алгоритмы, Наработки и Способности
Способ реализации:
cJass
Тип:
Наработка
Модуль небольшой, который вывел из модуля дока, за что credits ему.
Использует interface теперь, и теперь можно запускать хоть методы, хоть функции вне него, короче как вам удобнее.
Также добавил пример использования функции.
Какие приемущества перед другими модулями?
  1. Невесомый, и может использоваться абсолютно в любой структуре, даже не в спеллах
  2. Можно использовать в структуре которая может инициилизировать несколько спеллов (грубо говоря у вас одна структура на все тригерные магии)
vJass
function interface push takes integer this returns nothing defaults nothing
//! nocjass
module list
    readonly static thistype array data
    readonly static integer count = 0
    boolean flush = false
    push    press

    method add takes nothing returns nothing
        set thistype.data[thistype.count] = this
        set thistype.count = thistype.count + 1
    endmethod
    
    method remove takes integer i returns nothing
        set thistype.count  = thistype.count - 1
        set thistype.data[i] = thistype.data[thistype.count]
    endmethod

    static method update takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i==thistype.count
            if thistype.data[i].flush then
                 call thistype.data[i].destroy()
                 call thistype.data[i].remove(i)
                 set i = i - 1
            else
                call thistype.data[i].press(thistype.data[i]).evaluate()
            endif
            set i = i + 1
        endloop
    endmethod

endmodule
//! endnocjass
cJass
function interface push takes integer this returns nothing defaults nothing
define <implement list>={
    readonly static thistype data[]
    readonly static integer count = 0
    boolean flush = false
    push     press
   
    nothing add(){thistype.data[thistype.count++] = this}
        
    nothing remove(integer i){thistype.data[i] = thistype.data[--thistype.count]}
        
    static nothing update(){
        integer i = 0
        whilenot(i == thistype.count){
        if (thistype.data[i].flush){
           thistype.data[i].destroy()
           thistype.data[i].remove(i--)
        } else {thistype.data[i].press(thistype.data[i]).evaluate()}i++}}
    }
}
Ну и собственно пример.
struct spell
    static timer tt=CreateTimer()
    unit cast
    unit targ
    real time
    implement list
endstruct

function onTimer takes spell this returns nothing
    set this.time = this.time - 0.04
    if this.time < 0.04 then
         if GetWidgetLife(this.targ)>.405 or GetWidgetLife(this.cast)>.405 then
             call SetUnitX(this.targ,GetUnitX(this.cast))
             call SetUnitY(this.targ,GetUnitY(this.cast))
         endif
         call this.remove(this)
         call this.destroy()
         if spell.count == 0 then
             call PauseTimer(spell.tt)
         endif
    endif
endfunction

function Cast takes nothing returns nothing
    local spell this = spell.create
    set this.cast = GetTriggerUnit()
    set this.targ = GetSpellTargetUnit()
    set this.time = GetUnitAbilityLevel(this.cast,GetSpellAbilityId())
    set this.push = onTimer
    call this.add()
    if spell.count==0 then
        call TimerStart(spell.tt,0.04,true,function this.update)
    endif
endfunction
Чтобы оставить комментарий, пожалуйста, войдите на сайт.