[System] BuffGenerator

Level 4
Joined
Jun 9, 2011
Messages
91
Buff Generator version 3.3.0

This system allows rapid and easy buff development.


System code:
JASS:
library BuffGen /* v3.3.0.0
************************************************************************************************
*    BUFF GENERATOR by Bills
*
*     This system allows rapid and easy buff development.
*
************************************************************************************************
*
*   */ uses /*
*   
*       */ UnitIndexer /*   hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
*       */ Event /*         hiveworkshop.com/forums/jass-resources-412/snippet-event-186555/
*       */ CTL /*           hiveworkshop.com/forums/jass-resources-412/snippet-constant-timer-loop-32-a-201381/
*       */ TimerUtils /*    wc3c.net/showthread.php?t=101322
*       */ Table /*         hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*
***************************************************************************************************
*
*    Functions
*
*        function UnitAddBuff takes unit whichUnit, Buff whichBuff, real duration returns boolean
*            - returns true if added the buff
*
*        function UnitRemoveBuff takes unit wichUnit, Buff whichBuff returns boolean
*            - returns true if removed the buff
*
*        function UnitRemoveAllBuffs takes unit wichUnit returns nothing
*            - removes all buffs of unit
*
*        function UnitHasBuff takes unit wichUnit, Buff whichBuff returns boolean
*            - returns true if unit has the buff
*
*        function SetUnitBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns nothing
*            - sets the duration of buff
*
*        function AddUnitBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns nothing
*            - increments the duration of buff
*
*        function GetUnitBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns real
*            - returns the duration of buff
*
*        function CountBuffsOnUnit takes unit whichUnit returns integer
*            - returns de amount of buffs that unit have
*
*******************************************************************************************
*
*   struct Buff extends array
*
*        static constant real TIMEOUT=0.03125
*            - Useful to the method onPeriodic
*        static Event START
*            - fires when a buff is added
*        static Event FINISH
*            - fires when a buff is removed
*
*        Event Responses
*            - function GetEventBuff takes nothing returns Buff
*            - function GetBuffEventUnit takes nothing returns unit
*            - function GetBuffEventUnitId takes nothing returns integer
*
*        function TriggerRegisterBuffEvent takes trigger t, Event e returns nothing
*            - Jass wrapper of EVENT.registerTrigger(trigger)
*
*        function RegisterBuffEvent takes boolexpr b, Event e returns nothing
*            - Jass wrapper of EVENT.register(boolexpr)
*
*****************************************************************************
*
*    module BuffStruct
*
*        static method operator buff takes nothing returns Buff
*            - returns the Buff generated by implementation of this module
*
*        (interface)
*
*            private static constant integer AURAID = 'AURA'
*                (required) - this is a tornado slow aura
*            private static constant integer BUFFID = 'BUFF'
*                (required) - this is the buff of aura
*
*            private method onApply takes nothing returns nothing
*                (optional) - called all times that AddBuff is called
*
*            private method onRemove takes nothing returns nothing
*                (optional) - called all times that RemoveBuff is called
*
*            private method onFinish takes nothing returns nothing
*                (optional) - called only when the buff finish completely your duration
*
*            private method onPeriodic takes nothing returns nothing
*                (optional) - called 32 times per second
*                
*            Notes:
*                - "thistype this" represents the index of buffed unit in all methods above.
*                - If you do not want to use AURAID or/and BUFFID, just set it with 0 (zero).
*
********************************************************************************
*
*    ForEachBuff Modules
*
*        allows the method ForEachBuff takes unit enumUnit returns nothing
*
*        module ForEachBuff (optional)
*            - declare local variables here
*        module ForEachBuffLoop ( not optional)
*            - run loop code
*        module ForEachBuffNull (optional)
*            - null locals
*        module ForEachBuffEnd (not optional)
*
*        Example of ForEachBuff
*            - struct Test extends array
*                    private static unit targ
*                    implement ForEachBuff
*                        local unit target = targ[GetUnitUserData(GetTriggerUnit())]
*                    implement ForEachBuffLoop
*                        // deals 50 damage on target for each buff on enumUnit
*                        call UnitDamageTarget(enumUnit, target, 50, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
*                    implement ForEachBuffNull
*                        set target=null
*                    implement ForEachBuffEnd
*
*                    static method onCast takes nothing returns boolean
*                        set targ[GetUnitUserData(GetTriggerUnit())] = GetSpellTargetUnit()
*                        call ForEachBuff(GetTriggerUnit())
*                        return false
*                    endmethod
*              endstruct
*
************************************************************************************/
    globals
        private integer total = 0 //Buff counter
        private integer array ID //Buff indexer
        private integer array aid //ability id
        private integer array bid //buff id
        private integer array bc
        private Table array t
        private Event array e
        private integer array ed1 // event data
        private integer array ed2 // other event data
        private boolean ee=true
        private unit eu=null
        private Buff eb=0
    endglobals
    
    private module M
        private static method onInit takes nothing returns nothing
            set START = Event.create()
            set FINISH = Event.create()
        endmethod
    endmodule
    
    struct Buff extends array
        readonly static constant real TIMEOUT = 0.031250000
        readonly static Event START
        readonly static Event FINISH
        implement M
    endstruct

    private function InitBuff takes integer auraid, integer buffid, code func returns integer
        local integer id = total + 1
        set total = id
        set e[id] = Event.create()
        call e[id].register(Filter(func))
        set t[id] = Table.create()
        set aid[id] = auraid
        set bid[id] = buffid
        return id
    endfunction
    
    function UnitHasBuff takes unit u, Buff b returns boolean
        return t[b].boolean[GetUnitUserData(u)]
    endfunction

    function UnitRemoveBuff takes unit u, Buff b returns boolean
        debug if u == null or b <= 0 or integer(b) > total then
            debug call BJDebugMsg("[Buff Generator] Error: invalid arguments on RemoveBuff")
            debug return false
        debug endif
        if UnitHasBuff(u,b) then
            set t[b].boolean[GetUnitUserData(u)] = false
            if UnitMakeAbilityPermanent(u,false,aid[b]) then
                call UnitRemoveAbility(u,aid[b])
                call UnitRemoveAbility(u,bid[b])
            endif
            set ed1[b] = GetUnitUserData(u)
            set ed2[b] = 2
            call e[b].fire()
            if ee then
                set eu = u
                set eb = b
                call Buff.FINISH.fire()
            endif
            return true
        endif
        return false
    endfunction
    
    function UnitAddBuff takes unit u, Buff b, real dur returns boolean
        local integer i
        static if DEBUG_MODE then
            if (u == null or b <= 0 or integer(b) > total) then
                call BJDebugMsg("[Buff Generator] Error: invalid arguments on AddBuff")
                return false
            endif
        endif
        if UnitHasBuff(u,b) then
            call UnitRemoveBuff(u,b)
            call UnitAddBuff(u,b,dur)
        else
            set i = GetUnitUserData(u)
            set t[b].boolean[i] = true
            if UnitAddAbility(u,aid[b]) then
                call UnitMakeAbilityPermanent(u,true,aid[b])
            endif
            set t[b].real[i] = dur
            set ed1[b] = i
            set ed2[b] = 1
            call e[b].fire()
            if ee then
                set eu = u
                set eb = b
                call Buff.START.fire()
            endif
            return true
        endif
        return false
    endfunction

    function UnitRemoveAllBuffs takes unit u returns nothing
        local Buff i=total
        loop
            exitwhen i == 0
            call UnitRemoveBuff(u,i)
            set i = i - 1
        endloop
    endfunction
    
    function SetUnitBuffDuration takes unit u, Buff b, real dur returns nothing
        local integer i = GetUnitUserData(u)
        if UnitHasBuff(u,b) then
            set t[b].real[i] = dur
            if not (t[b].timer[i] == null) then
                set ed1[b] = i
                set ed2[b] = 3
                call e[b].fire()
            endif
        endif
    endfunction

    function GetUnitBuffDuration takes unit u, Buff b returns real
        local integer i = GetUnitUserData(u)
        if UnitHasBuff(u,b) then
            if t[b].timer[i] == null then
                return t[b].real[i]
            else
                return TimerGetRemaining(t[b].timer[i])
            endif
        endif
        return 0.
    endfunction

    function AddUnitBuffDuration takes unit u, Buff b, real dur returns nothing
        call SetUnitBuffDuration(u,b,GetUnitBuffDuration(u,b)+dur)
    endfunction
    
    function CountBuffsOnUnit takes unit u returns integer
        return bc[GetUnitUserData(u)]
    endfunction
    
    function TriggerRegisterBuffEvent takes trigger t, Event e returns nothing
        call e.registerTrigger(t)
    endfunction

    function RegisterBuffEvent takes boolexpr t, Event e returns nothing
        call e.register(t)
    endfunction
    
    function GetBuffEventUnit takes nothing returns unit
        return eu
    endfunction

    function GetBuffEventUnitId takes nothing returns integer
        return GetUnitUserData(eu)
    endfunction
    
    function GetEventBuff takes nothing returns Buff
        return eb
    endfunction
    
    module BuffStruct
        static method operator buff takes nothing returns Buff
            return ID[thistype.typeid]
        endmethod
        
        static if thistype.onPeriodic.exists then
            private integer index
            private thistype T
            implement CTL
                local real d
            implement CTLExpire
                set d = t[ID[thistype.typeid]].real[index]-Buff.TIMEOUT
                call thistype(index).onPeriodic()
                if d <= 0.00 then
                    call UnitRemoveBuff(GetUnitById(index),ID[thistype.typeid])
                    static if thistype.onFinish.exists then
                        call thistype(index).onFinish()
                    endif
                else
                    set t[ID[thistype.typeid]].real[index] = d
                endif
            implement CTLNull
            implement CTLEnd
        else
            private static method exp takes nothing returns nothing
                local integer i = GetTimerData(GetExpiredTimer())
                call UnitRemoveBuff(GetUnitById(i),ID[thistype.typeid])
                static if thistype.onFinish.exists then
                    call thistype(i).onFinish()
                endif
            endmethod
        endif

        private static method m takes nothing returns nothing
            local integer i = ed1[ID[thistype.typeid]] //unit id
            local integer j = ed2[ID[thistype.typeid]] //data
            local thistype this = thistype(i)
            if j == 1 then
                static if thistype.onPeriodic.exists then
                    set T = create()
                    set T.index = i
                else
                    set t[ID[thistype.typeid]].timer[i]=NewTimerEx(i)
                    call TimerStart(t[ID[thistype.typeid]].timer[i],t[ID[thistype.typeid]].real[i],false,function thistype.exp)
                endif
                static if thistype.onApply.exists then
                    call onApply()
                endif
                set bc[i]= bc[i] + 1
            elseif j==2 then
                static if thistype.onPeriodic.exists then
                    call T.destroy()
                else
                    call ReleaseTimer(t[ID[thistype.typeid]].timer[i])
                endif
                static if thistype.onRemove.exists then
                    call onRemove()
                endif
                set bc[i] = bc[i] - 1
            elseif j==3 then
                static if not thistype.onPeriodic.exists then
                    call ReleaseTimer(t[ID[thistype.typeid]].timer[i])
                    set t[ID[thistype.typeid]].timer[i] = NewTimerEx(i)
                    call TimerStart(t[ID[thistype.typeid]].timer[i],t[ID[thistype.typeid]].real[i],false,function thistype.exp)
                endif
            endif
        endmethod

        private static method onInit takes nothing returns nothing
            set ID[thistype.typeid] = InitBuff(AURAID,BUFFID,function thistype.m)
        endmethod
    endmodule

    // ForEachBuff Modules
    module ForEachBuff
        static method ForEachBuff takes unit enumUnit returns nothing
            local Buff this = total
    endmodule
    module ForEachBuffLoop
            implement ForEachBuff
            loop
                exitwhen this == 0
                if UnitHasBuff(enumUnit,this) then
    endmodule
    module ForEachBuffNull
                endif
                set this = this - 1
            endloop
    endmodule
    module ForEachBuffEnd
        implement ForEachBuffNull
        endmethod
    endmodule
endlibrary

Exemple Usage
JASS:
// stackable buff example
library Demos uses BuffGen, Bonus

	struct Innerfire extends array
		// increases attack damage by 50 (statckable). Lasts 10 seconds.

		private static constant integer AURAID = 'AXXX' // required
		private static constant integer BUFFID = 'BXXX' // required

		private integer stack // stack count
		private static integer MAX=5 // stack max
		private boolean toStack // stack condition

		private method onApply takes nothing returns nothing
			if stack<MAX then
				set stack=stack+1
				call AddUnitBonus(GetUnitById(this),BONUS_DAMAGE,50*stack) // apply new bonus
			endif
		endmethod

		private method onRemove takes nothing returns nothing
			call AddUnitBonus(GetUnitById(this),BONUS_DAMAGE,-50*stack) // remove actual bonus
			if not toStack then // before of onApply, is ever called onRemove. Why the buff is replaced.
				set stack=0
			endif
		endmethod

		implement BuffStruct // module implementation

		// code of spell
		private static method onCast takes nothing returns boolean
			local unit spellTarget=GetSpellTargetUnit()
			local thistype this=GetUnitUserData(spellTarget)
			
			set toStack=true
			call UnitAddBuff(spellTarget,thistype.buff,10)
			set toStack=false
			
			set spellTarget=null
			return false
		endmethod
	endstruct

endlibrary
JASS:
struct Example extends array
	//implement ForEachBuff // it's optional
	implement ForEachBuffLoop
		// decreases the duration of each buff in 10 seconds
		call AddUnitBuffDuration(enumUnit,this,-10)
	//implement ForEachBuffNull // it's optional
	implement ForEachBuffEnd

	static method onCast takes nothing returns boolean
		call ForEachBuff(GetTriggerUnit())
		return false
	endmethod
endstruct
 

Attachments

  • BuffGenerator 3.3.0.w3x
    67.7 KB · Views: 291
Last edited:
You should combine the API with the system. Just place the functions at the end and list them in the documentation with a few statements that describe each function.

function interface BuffFunc takes unit u returns nothing
function interface EnumFunc takes unit u, Buff B returns nothing

God no.

JASS:
        public BuffFunc a // onApply method
        public BuffFunc r // onRemove method
        public BuffFunc f // onFinish method
        public BuffFunc p // onPeriodic method

Just use boolexprs instead.
You can store the parameters in static variables and the user would call something like GetBuffUnit() or something.

Instead of a textmacro, use modules.
They're way better.

JASS:
struct Bloodlust extends array

    implement BuffGenStruct
endstruct

Also, you need to follow Jass convention:
readonly static Buff EventBuff = 0 //buff of event fired
readonly static unit EventUnit = null // unit of event fired
->
readonly static Buff eventBuff = 0 //buff of event fired
readonly static unit eventUnit = null // unit of event fired

JASS:
    //! textmacro BUFF takes NAME
        globals
            Buff $NAME$=0
        endglobals
        struct $NAME$_BuffStruct extends array
            private static method b_set takes Buff b returns nothing
                set $NAME$=b
            endmethod
            private static method operator this takes nothing returns Buff
                return $NAME$
            endmethod
    //! endtextmacro

>.> Something is definitely wrong here.



This looks very similar to Nestharus' AuraStruct.
 
This looks very similar to Nestharus' AuraStruct.

Except that they do completely different things. ;P

First off, I'd like to say good job with this system. :) Definitely useful as a replacement to BuffStruct if you don't need the auto-gen.

JASS:
        method isMagical takes nothing returns boolean
            if t==BUFF_TYPE_MAGICAL then
                return true
            endif
            return false
        endmethod

        method isPhysical takes nothing returns boolean
            if t==BUFF_TYPE_PHYSICAL then
                return true
            endif
            return false
        endmethod

Those can be simply:
JASS:
method isMagical takes nothing returns boolean
    return t == BUFF_TYPE_MAGICAL
endmethod

method isPhysical takes nothing returns boolean
    return t == BUFF_TYPE_PHYSICAL
endmethod

---

This system could also be improved with the use of an indexer. It isn't exactly necessary since most maps will have about 8-9 buffs active at any one time max (so you don't have to make this change), but you could make multiple lists, assign a head to each unit who currently has a buff(s). That way, when you loop through/enumerate, you don't have to loop through the entire list of buffs on all units, but rather just through the buffs on a specific unit. (making it slightly more efficient) As I said, it isn't necessary, but it can add a bit of efficiency. :)

----

Also, you should put in the documentation that all buffs must have a duration of 0 if the user wants the duration to be dynamic.

----

Also, can't you create a variable to store the list of a unit? That way, you don't have to keep searching for the list of the unit. (list.g is a slow search that you constantly call)
 
Level 7
Joined
Oct 11, 2008
Messages
303
Using Index system, most of your method could be operator
E105.png
 
Level 6
Joined
Jun 20, 2011
Messages
249
This could definitely could use LinkedListModule because currently it iterates through the whole list to find the unit's buff and this can be avoided by creating a new head per unit custom value.
Good job, you might want to find a way to delete those function interfaces though
 
JASS:
        method getType takes nothing returns integer
            return t
        endmethod

        method isMagical takes nothing returns boolean
            if t==BUFF_TYPE_MAGICAL then
                return true
            endif
            return false
        endmethod

        method isPhysical takes nothing returns boolean
            if t==BUFF_TYPE_PHYSICAL then
                return true
            endif
            return false
        endmethod

->

JASS:
method operator type takes nothing returns integer
    return this.t
endmethod

method operator magical takes nothing returns boolean
    return this.t == BUFF_TYPE_MAGICAL
endmethod

method operator physical takes nothing returns boolean
    return this.t == BUFF_TYPE_PHYSICAL
endmethod

I like these better :3

I also suggest that you change the duration methods to operators too.
Same for the pause methods.

Operators are imba. Vexorian needs to balance them :ogre_hurrhurr:
 
Level 4
Joined
Jun 9, 2011
Messages
91
Thanks for all suggestions. I am thinking about a way of leaving it more dynamic.

@Edit
Updated

Minor updates
JASS:
        method operator type takes nothing returns integer
            return t
        endmethod
		
        method isMagical takes nothing returns boolean
            return t==BUFF_TYPE_MAGICAL
        endmethod

        method isPhysical takes nothing returns boolean
            return t==BUFF_TYPE_PHYSICAL
        endmethod

@Edit2

I'm not wanting to implement new requirements on my system, but i want to improve it.
I will implement the idea of PurgeandFire111 to make a list for each unit...
 
Last edited:
Level 7
Joined
Oct 11, 2008
Messages
303
This is generate by only your BG + requirements.
JASS:
globals
//globals from Alloc:
constant boolean LIBRARY_Alloc=true
//endglobals from Alloc
//globals from Event:
constant boolean LIBRARY_Event=true
real Event___eventv= 0
//endglobals from Event
//globals from WorldBounds:
constant boolean LIBRARY_WorldBounds=true
//endglobals from WorldBounds
//globals from UnitIndexer:
constant boolean LIBRARY_UnitIndexer=true
constant integer ABILITIES_UNIT_INDEXER= 'A003'
trigger UnitIndexer___q=CreateTrigger()
trigger UnitIndexer___l=CreateTrigger()
unit array UnitIndexer___e
integer UnitIndexer___r=0
integer UnitIndexer___y=0
integer UnitIndexer___o=0
boolean UnitIndexer___a=false
integer array UnitIndexer___n
integer array UnitIndexer___p
integer array UnitIndexer___lc
//endglobals from UnitIndexer
//globals from BuffGen:
constant boolean LIBRARY_BuffGen=true
        //STANDARD BUFF TYPES:
constant integer BUFF_TYPE_DEFAULT=0
constant integer BUFF_TYPE_MAGICAL=1
constant integer BUFF_TYPE_PHYSICAL=2
        //constant integer BUFF_TYPE_NEW = Previous + 1
        // You are free to create new types,
        // only declare new constant integer variables with a different value.
//endglobals from BuffGen
    // Generated
trigger gg_trg_BuffGen_Struct= null
trigger gg_trg_World_Bounds= null
trigger gg_trg_Alloc= null
trigger gg_trg_Unit_Indexer= null
trigger gg_trg_Event= null


//JASSHelper struct globals:
constant integer si__Event=1
integer s__Event_count= 0
trigger array s__Event_trig
boolexpr array s__Event_bc
constant integer si__WorldBounds=2
real s__WorldBounds_maxX
real s__WorldBounds_maxY
real s__WorldBounds_minX
real s__WorldBounds_minY
real s__WorldBounds_centerX
real s__WorldBounds_centerY
rect s__WorldBounds_world
region s__WorldBounds_worldRegion
constant integer si__UnitIndexer___PreLoader=3
constant integer si__UnitIndex=4
constant integer si__UnitIndexer=5
integer s__UnitIndexer_INDEX
integer s__UnitIndexer_DEINDEX
boolean s__UnitIndexer_enabled=true
constant integer si__Buff=6
constant real s__Buff_TIMEOUT=.031250000
integer s__Buff_START=0
integer s__Buff_FINISH=0
integer s__Buff_eventBuff=0
unit s__Buff_eventUnit=null
integer s__Buff_cB=0
boolean s__Buff_e= true
integer array s__Buff_aI
integer array s__Buff_bI
integer array s__Buff_t
integer array s__Buff_a
integer array s__Buff_r
integer array s__Buff_f
integer array s__Buff_p
constant integer si__BuffGen___list=7
integer s__BuffGen___list_Alloc__instanceCount= 0
integer array s__BuffGen___list_Alloc__recycle
integer s__BuffGen___list_c=0
integer array s__BuffGen___list_next
integer array s__BuffGen___list_prev
integer array s__BuffGen___list_b
unit array s__BuffGen___list_u
real array s__BuffGen___list_d
integer array s__BuffGen___list_p
trigger st__Buff_apply
trigger st__Buff_D
trigger st__Buff_remove
trigger st__Buff_release
trigger st__Buff__staticgetindex
trigger st__BuffGen___list_create
trigger st__BuffGen___list_destroy
trigger st__BuffGen___list__get_head
trigger st__BuffGen___list_g
trigger array st___prototype4
trigger array st___prototype9
unit f__arg_unit1
real f__arg_real1
integer f__arg_integer1
integer f__arg_this
boolean f__result_boolean
integer f__result_integer

endglobals


//Generated method caller for BuffGen___list.create
function sc__BuffGen___list_create takes nothing returns integer
    call TriggerEvaluate(st__BuffGen___list_create)
 return f__result_integer
endfunction

//Generated method caller for BuffGen___list.destroy
function sc__BuffGen___list_destroy takes integer this returns nothing
    set f__arg_this=this
    call TriggerEvaluate(st__BuffGen___list_destroy)
endfunction

//Generated method caller for BuffGen___list._get_head
function sc__BuffGen___list__get_head takes nothing returns integer
    call TriggerEvaluate(st__BuffGen___list__get_head)
 return f__result_integer
endfunction

//Generated method caller for BuffGen___list.g
function sc__BuffGen___list_g takes unit u,integer b returns integer
    set f__arg_unit1=u
    set f__arg_integer1=b
    call TriggerEvaluate(st__BuffGen___list_g)
 return f__result_integer
endfunction

//Generated method caller for Buff.apply
function sc__Buff_apply takes integer this,unit u,real duration returns nothing
    set f__arg_this=this
    set f__arg_unit1=u
    set f__arg_real1=duration
    call TriggerEvaluate(st__Buff_apply)
endfunction

//Generated method caller for Buff.D
function sc__Buff_D takes nothing returns nothing
    call TriggerEvaluate(st__Buff_D)
endfunction

//Generated method caller for Buff.remove
function sc__Buff_remove takes integer this,unit u returns nothing
    set f__arg_this=this
    set f__arg_unit1=u
    call TriggerEvaluate(st__Buff_remove)
endfunction

//Generated method caller for Buff.release
function sc__Buff_release takes integer this,unit u returns boolean
    set f__arg_this=this
    set f__arg_unit1=u
    call TriggerEvaluate(st__Buff_release)
 return f__result_boolean
endfunction

//Generated method caller for Buff._staticgetindex
function sc__Buff__staticgetindex takes unit u returns integer
            return GetUnitUserData(u)
endfunction
function sc___prototype4_execute takes integer i,integer a1 returns nothing
    set f__arg_integer1=a1

    call TriggerExecute(st___prototype4[i])
endfunction
function sc___prototype4_evaluate takes integer i,integer a1 returns nothing
    set f__arg_integer1=a1

    call TriggerEvaluate(st___prototype4[i])

endfunction
function sc___prototype9_execute takes integer i,unit a1,integer a2 returns nothing
    set f__arg_unit1=a1
    set f__arg_integer1=a2

    call TriggerExecute(st___prototype9[i])
endfunction
function sc___prototype9_evaluate takes integer i,unit a1,integer a2 returns nothing
    set f__arg_unit1=a1
    set f__arg_integer1=a2

    call TriggerEvaluate(st___prototype9[i])

endfunction

//library Alloc:

//library Alloc ends
//library Event:
//2.0.1.1
/////////////////////////////////////////////////////////////////////////
    //function CreateEvent takes nothing returns integer
    //function TriggerRegisterEvent takes trigger t, integer ev returns nothing
    //function RegisterEvent takes boolexpr c, integer ev returns nothing
    //function FireEvent takes integer ev returns nothing
    
    //struct Event extends array
        //static method create takes nothing returns thistype
        //method registerTrigger takes trigger t returns nothing
        //method register takes boolexpr c returns nothing
        //method fire takes nothing returns nothing
/////////////////////////////////////////////////////////////////////////
        function s__Event_create takes nothing returns integer
            set s__Event_count=s__Event_count + 1
            return s__Event_count
        endfunction
        function s__Event_registerTrigger takes integer this,trigger t returns nothing
            call TriggerRegisterVariableEvent(t, "Event___eventv", EQUAL, this)
        endfunction
        function s__Event_register takes integer this,boolexpr c returns nothing
            if ( null == s__Event_bc[this] ) then
                set s__Event_bc[this]=c
                set s__Event_trig[this]=CreateTrigger()
            else
                set s__Event_bc[this]=Or(s__Event_bc[this], c)
                call TriggerClearConditions(s__Event_trig[this])
            endif
            call TriggerAddCondition(s__Event_trig[this], s__Event_bc[this])
        endfunction
        function s__Event_fire takes integer this returns nothing
            set Event___eventv=0
            set Event___eventv=this
            call TriggerEvaluate(s__Event_trig[this])
        endfunction
    function CreateEvent takes nothing returns integer
        return s__Event_create()
    endfunction
    function TriggerRegisterEvent takes trigger t,integer ev returns nothing
        call s__Event_registerTrigger(ev,t)
    endfunction
    function RegisterEvent takes boolexpr c,integer ev returns nothing
        call s__Event_register(ev,c)
    endfunction
    function FireEvent takes integer ev returns nothing
        call s__Event_fire(ev)
    endfunction

//library Event ends
//library WorldBounds:
    //struct WorldBounds extends array

    //static readonly rect world
    //  same as GetWorldBounds()
    
    //static readonly region worldRegion
    //  contains world for triggers
    
    //static readonly real maxX
    //static readonly real maxY
    //static readonly real minX
    //static readonly real minY
    //static readonly real centerX
    //static readonly real centerY
    
//Implemented from module WorldBounds___WorldBoundInit:
        function s__WorldBounds_WorldBounds___WorldBoundInit__onInit takes nothing returns nothing
            set s__WorldBounds_world=GetWorldBounds()
            set s__WorldBounds_maxX=GetRectMaxX(s__WorldBounds_world)
            set s__WorldBounds_maxY=GetRectMaxY(s__WorldBounds_world)
            set s__WorldBounds_minX=GetRectMinX(s__WorldBounds_world)
            set s__WorldBounds_minY=GetRectMinY(s__WorldBounds_world)
            set s__WorldBounds_centerX=( s__WorldBounds_maxX + s__WorldBounds_minX ) / 2
            set s__WorldBounds_centerY=( s__WorldBounds_minY + s__WorldBounds_maxY ) / 2
            set s__WorldBounds_worldRegion=CreateRegion()
            call RegionAddRect(s__WorldBounds_worldRegion, s__WorldBounds_world)
        endfunction

//library WorldBounds ends
//library UnitIndexer:

    function GetIndexedUnitId takes nothing returns integer
        return UnitIndexer___o
    endfunction
    function GetIndexedUnit takes nothing returns unit
        return UnitIndexer___e[UnitIndexer___o]
    endfunction
//ignored textmacro command: UNIT_LIST_LIB()
        function s__UnitIndexer___PreLoader_run takes nothing returns nothing
            call DestroyTimer(GetExpiredTimer())
            set UnitIndexer___a=true
        endfunction
        function s__UnitIndexer___PreLoader_eval takes trigger t returns nothing
            local integer f=UnitIndexer___n[0]
            local integer d=UnitIndexer___o
            loop
                exitwhen 0 == f
                if ( IsTriggerEnabled(t) ) then
                    set UnitIndexer___o=f
                    if ( TriggerEvaluate(t) ) then
                        call TriggerExecute(t)
                    endif
                else
                    exitwhen true
                endif
                set f=UnitIndexer___n[f]
            endloop
            set UnitIndexer___o=d
        endfunction
        function s__UnitIndexer___PreLoader_evalb takes boolexpr c returns nothing
            local trigger t=CreateTrigger()
            local integer f=UnitIndexer___n[0]
            local integer d=UnitIndexer___o
            call TriggerAddCondition(t, c)
            loop
                exitwhen 0 == f
                set UnitIndexer___o=f
                call TriggerEvaluate(t)
                set f=UnitIndexer___n[f]
            endloop
            call DestroyTrigger(t)
            set t=null
            set UnitIndexer___o=d
        endfunction
//ignored textmacro command: UNIT_EVENT_MACRO()
        function s__UnitIndex_lock takes integer this returns nothing
             if ( null != UnitIndexer___e[this] ) then
                set UnitIndexer___lc[this]=UnitIndexer___lc[this] + 1
             else
                 call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT INDEXER ERROR: ATTEMPT TO LOCK NULL INDEX")
             endif
        endfunction
        function s__UnitIndex_unlock takes integer this returns nothing
             if ( 0 < UnitIndexer___lc[this] ) then
                set UnitIndexer___lc[this]=UnitIndexer___lc[this] - 1
                if ( 0 == UnitIndexer___lc[this] and null == UnitIndexer___e[this] ) then
                    set UnitIndexer___n[this]=UnitIndexer___y
                    set UnitIndexer___y=this
                endif
             else
                 call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT INDEXER ERROR: ATTEMPT TO UNLOCK UNLOCKED INDEX")
             endif
        endfunction
        function s__UnitIndexer_onEnter takes nothing returns boolean
            local unit Q=GetFilterUnit()
            local integer i
            local integer d=UnitIndexer___o
            if ( s__UnitIndexer_enabled and Q != UnitIndexer___e[GetUnitUserData(Q)] ) then
                if ( 0 == UnitIndexer___y ) then
                    set UnitIndexer___r=UnitIndexer___r + 1
                    set i=UnitIndexer___r
                else
                    set i=UnitIndexer___y
                    set UnitIndexer___y=UnitIndexer___n[UnitIndexer___y]
                endif
                call UnitAddAbility(Q, ABILITIES_UNIT_INDEXER)
                call UnitMakeAbilityPermanent(Q, true, ABILITIES_UNIT_INDEXER)
                call SetUnitUserData(Q, i)
                set UnitIndexer___e[i]=Q
//#                 static if not LIBRARY_UnitList then
                        if ( not UnitIndexer___a ) then
                            set UnitIndexer___p[i]=UnitIndexer___p[0]
                            set UnitIndexer___n[UnitIndexer___p[0]]=i
                            set UnitIndexer___n[i]=0
                            set UnitIndexer___p[0]=i
                        endif
//#                 else
//#                     set UnitIndexer___p[i]=UnitIndexer___p[0]
//#                     set UnitIndexer___n[UnitIndexer___p[0]]=i
//#                     set UnitIndexer___n[i]=0
//#                     set UnitIndexer___p[0]=i
//#                     call GroupAddUnit(g,UnitIndexer___e[i])
//#                 endif
                set UnitIndexer___o=i
                call FireEvent(s__UnitIndexer_INDEX)
                set UnitIndexer___o=d
            endif
            set Q=null
            return false
        endfunction
        function s__UnitIndexer_onLeave takes nothing returns boolean
//#             static if LIBRARY_UnitEvent then
//#             else
                    local unit u=GetFilterUnit()
                    local integer i=GetUnitUserData(u)
                    local integer d=UnitIndexer___o
                    if ( 0 == GetUnitAbilityLevel(u, ABILITIES_UNIT_INDEXER) and u == UnitIndexer___e[i] ) then
//#                     static if not LIBRARY_UnitList then
                            if ( not UnitIndexer___a ) then
                                set UnitIndexer___n[UnitIndexer___p[i]]=UnitIndexer___n[i]
                                set UnitIndexer___p[UnitIndexer___n[i]]=UnitIndexer___p[i]
                            endif
//#                     else
//#                         set UnitIndexer___n[UnitIndexer___p[i]]=UnitIndexer___n[i]
//#                         set UnitIndexer___p[UnitIndexer___n[i]]=UnitIndexer___p[i]
//#                         call GroupRemoveUnit(g,UnitIndexer___e[i])
//#                     endif
                        set UnitIndexer___o=i
                        call FireEvent(s__UnitIndexer_DEINDEX)
                        set UnitIndexer___o=d
                        if ( 0 == UnitIndexer___lc[i] ) then
                            set UnitIndexer___n[i]=UnitIndexer___y
                            set UnitIndexer___y=i
                        endif
                        set UnitIndexer___e[i]=null
                    endif
                    set u=null
//#             endif
            return false
        endfunction
//Implemented from module UnitIndexer___UnitIndexerInit:
        function s__UnitIndexer_UnitIndexer___UnitIndexerInit__onInit takes nothing returns nothing
            local integer i=15
            local boolexpr bc=Condition(function s__UnitIndexer_onLeave)
            local boolexpr bc2=Condition(function s__UnitIndexer_onEnter)
            local group g=CreateGroup()
            local player l__UnitIndexer___p
            set s__UnitIndexer_INDEX=CreateEvent()
            set s__UnitIndexer_DEINDEX=CreateEvent()
            call TriggerRegisterEnterRegion(UnitIndexer___q, s__WorldBounds_worldRegion, bc2)
            loop
                set l__UnitIndexer___p=Player(i)
                call TriggerRegisterPlayerUnitEvent(UnitIndexer___l, l__UnitIndexer___p, EVENT_PLAYER_UNIT_ISSUED_ORDER, bc)
                call SetPlayerAbilityAvailable(l__UnitIndexer___p, ABILITIES_UNIT_INDEXER, false)
                call GroupEnumUnitsOfPlayer(g, l__UnitIndexer___p, bc2)
                exitwhen 0 == i
                set i=i - 1
            endloop
            call DestroyGroup(g)
            set bc=null
            set g=null
            set bc2=null
            set l__UnitIndexer___p=null
            call TimerStart(CreateTimer(), 0, false, function s__UnitIndexer___PreLoader_run)
        endfunction
//ignored textmacro command: UNIT_EVENT_MACRO_2()
    function RegisterUnitIndexEvent takes boolexpr c,integer ev returns nothing
        call RegisterEvent(c , ev)
        if ( not UnitIndexer___a and ev == s__UnitIndexer_INDEX and 0 != UnitIndexer___n[0] ) then
            call s__UnitIndexer___PreLoader_evalb(c)
        endif
    endfunction
    function TriggerRegisterUnitIndexEvent takes trigger t,integer ev returns nothing
        call TriggerRegisterEvent(t , ev)
        if ( not UnitIndexer___a and ev == s__UnitIndexer_INDEX and 0 != UnitIndexer___n[0] ) then
            call s__UnitIndexer___PreLoader_eval(t)
        endif
    endfunction
    function GetUnitById takes integer W returns unit
        return UnitIndexer___e[W]
    endfunction
    function GetUnitId takes unit u returns integer
        return GetUnitUserData(u)
    endfunction
    function IsUnitIndexed takes unit u returns boolean
        return u == UnitIndexer___e[GetUnitUserData(u)]
    endfunction
    function IsUnitDeindexing takes unit u returns boolean
        return IsUnitIndexed(u) and 0 == GetUnitAbilityLevel(u, ABILITIES_UNIT_INDEXER)
    endfunction

//library UnitIndexer ends
//library BuffGen:


//processed: 	function interface BuffGen___Method takes integer this returns nothing
//processed: 	function interface EnumFunc takes unit u, Buff B returns nothing


		//constructor
  function s__Buff_create takes integer AuraId,integer BuffId,integer BuffType returns integer
   local integer this
			set s__Buff_cB=s__Buff_cB + 1
			set this=s__Buff_cB
			set s__Buff_aI[this]=AuraId
			set s__Buff_bI[this]=BuffId
            set s__Buff_t[this]=BuffType
			if this == 1 then
                 call BJDebugMsg("[BuffGen] System Actived!")
				call TimerStart(CreateTimer(), s__Buff_TIMEOUT, true, function sc__Buff_D)
			endif
			return this
  endfunction
		
  function s__Buff_isOn takes integer this,unit u returns boolean
			return GetUnitAbilityLevel(u, s__Buff_aI[this]) > 0
  endfunction

        //Deprecated (use apply with duration zero)... for backwards compatability only.
  function s__Buff_add takes integer this,unit u returns nothing
             call BJDebugMsg("[Buff Gen] Using deprecated method enumBuffs, please use method apply with duration zero")
			call sc__Buff_apply(this,u , 0)
  endfunction

  function s__Buff_apply takes integer this,unit u,real duration returns nothing
   local integer l=sc__BuffGen___list_g(u , this)
    if u == null then
     call BJDebugMsg("[BG ERROR] null units can't be buffed")
     return
    endif
			call sc__Buff_release(this,u)
			call sc___prototype4_evaluate(s__Buff_a[this],GetUnitUserData(u))
			if l == 0 then
				set l=sc__BuffGen___list_create()
			endif
			set s__BuffGen___list_u[l]=u
			set s__BuffGen___list_b[l]=this
			if UnitAddAbility(u, s__Buff_aI[this]) then
				call UnitMakeAbilityPermanent(u, true, s__Buff_aI[this])
    else
     call BJDebugMsg("[Buff Instance " + I2S(this) + " ERROR] Using invalid aura raw code")
			endif
			if duration <= 0.00 then //if duration is zero or negative, pause buff... adds a permanent buff
				set s__BuffGen___list_p[l]=s__BuffGen___list_p[l] + 1
			else
				set s__BuffGen___list_p[l]=0
				set s__BuffGen___list_d[l]=duration
			endif
			if s__Buff_e then //if events are enabled, fire START event
                set s__Buff_eventBuff=this
				set s__Buff_eventUnit=u
				call s__Event_fire(s__Buff_START)
			endif
  endfunction

		//Duration Loop
  function s__Buff_D takes nothing returns nothing
   local integer l=sc__BuffGen___list__get_head()
			loop
				exitwhen l == 0
				if s__BuffGen___list_p[l] == 0 then //if not paused
					set s__BuffGen___list_d[l]=s__BuffGen___list_d[l] - s__Buff_TIMEOUT
					call sc___prototype4_evaluate(s__Buff_p[s__BuffGen___list_b[l]],GetUnitUserData(s__BuffGen___list_u[l])) //call onPeriodic
					if s__BuffGen___list_d[l] <= 0.00 then
						call sc___prototype4_evaluate(s__Buff_f[s__BuffGen___list_b[l]],GetUnitUserData(s__BuffGen___list_u[l])) //call onFinish
						call sc__Buff_remove(s__BuffGen___list_b[l],s__BuffGen___list_u[l]) //remove buff
					endif
				endif
				set l=s__BuffGen___list_next[l]
			endloop
  endfunction
		
  function s__Buff_remove takes integer this,unit u returns nothing
			if sc__Buff_release(this,u) then //release effects of buff
				call sc__BuffGen___list_destroy(sc__BuffGen___list_g(u , this))
			endif
  endfunction
		
  function s__Buff_removeAll takes unit u returns nothing
   local integer i=s__Buff_cB
			loop
				exitwhen i == 0
				call s__Buff_remove((i),u)
				set i=i - 1
			endloop
  endfunction
		
		//used to refresh buff
  function s__Buff_release takes integer this,unit u returns boolean
			if GetUnitAbilityLevel(u, s__Buff_aI[this]) > 0 then
				call UnitMakeAbilityPermanent(u, false, s__Buff_aI[this])
				call UnitRemoveAbility(u, s__Buff_aI[this])
				call UnitRemoveAbility(u, s__Buff_bI[this])
				call sc___prototype4_evaluate(s__Buff_r[this],GetUnitUserData(u))
				if s__Buff_e then //if events are enabled, fire FINISH event
					set s__Buff_eventBuff=this
                    set s__Buff_eventUnit=u
                    call s__Event_fire(s__Buff_FINISH)
				endif
				return true
			endif
			return false
  endfunction

        function s__Buff__get_type takes integer this returns integer
            return s__Buff_t[this]
        endfunction
		
        function s__Buff_isMagical takes integer this returns boolean
            return s__Buff_t[this] == BUFF_TYPE_MAGICAL
        endfunction

        function s__Buff_isPhysical takes integer this returns boolean
            return s__Buff_t[this] == BUFF_TYPE_PHYSICAL
        endfunction
		
  function s__Buff_addDuration takes integer this,unit u,real incr returns nothing
   local integer l= sc__BuffGen___list_g(u , this)
			set s__BuffGen___list_d[l]=s__BuffGen___list_d[l] + incr
  endfunction
		
  function s__Buff_setDuration takes integer this,unit u,real new returns nothing
			set s__BuffGen___list_d[sc__BuffGen___list_g(u , this)]=new
  endfunction

  function s__Buff_getDuration takes integer this,unit u returns real
			if GetUnitAbilityLevel(u, s__Buff_aI[this]) > 0 then
				return s__BuffGen___list_d[sc__BuffGen___list_g(u , this)]
			endif
			return 0.00
  endfunction

  function s__Buff_isPaused takes integer this,unit u returns boolean
			if GetUnitAbilityLevel(u, s__Buff_aI[this]) > 0 then
				return s__BuffGen___list_p[sc__BuffGen___list_g(u , this)] > 0
			endif
			return false
  endfunction

  function s__Buff_pause takes integer this,unit u returns nothing
   local integer l=sc__BuffGen___list_g(u , this)
			set s__BuffGen___list_p[l]=s__BuffGen___list_p[l] + 1
  endfunction

  function s__Buff_unpause takes integer this,unit u returns nothing
   local integer l= sc__BuffGen___list_g(u , this)
			if s__BuffGen___list_p[l] > 0 then
				set s__BuffGen___list_p[l]=s__BuffGen___list_p[l] - 1
			endif
  endfunction

  function s__Buff_countBuffs takes integer this returns integer
   local integer i=s__Buff_cB
   local integer c=0
            local unit u
			if s__BuffGen___list_c == 0 then
				return 0
			endif
            set u=GetUnitById(this)
			loop
				exitwhen i == 0
				if GetUnitAbilityLevel(u, s__Buff_aI[(i)]) > 0 then
					set c=c + 1
				endif
				set i=i - 1
			endloop
            set u=null
			return c //total buffs on "unit u"
  endfunction

  function s__Buff__get_totalBuffs takes nothing returns integer
			return s__BuffGen___list_c //total buffs of system actives
  endfunction
        
        function s__Buff_enableEvent takes boolean flag returns nothing
			set s__Buff_e=flag
  endfunction
        
  function s__Buff_forEachBuff takes integer this,integer callback returns nothing
   local integer i= s__Buff_cB
            local unit u
            if s__BuffGen___list_c == 0 then
				return
			endif
            set u=GetUnitById(this)
			loop
				exitwhen i == 0
				if GetUnitAbilityLevel(u, s__Buff_aI[(i)]) > 0 then
					call sc___prototype9_evaluate(callback,u , (i))
				endif
				set i=i - 1
			endloop
            set u=null
  endfunction

		//Deprecated (use forEachBuff)... for backwards compatability only.
  function s__Buff_enumBuffs takes unit u,integer callback returns nothing
    call BJDebugMsg("[Buff Gen] Using deprecated method enumBuffs, please use method forEachBuff")
			call s__Buff_forEachBuff(sc__Buff__staticgetindex(u),callback)
  endfunction
		
        function s__Buff__staticgetindex takes unit u returns integer
            return GetUnitUserData(u)
        endfunction
        
//Implemented from module BuffGen___I:
  function s__Buff_BuffGen___I__onInit takes nothing returns nothing
			set s__Buff_START=s__Event_create()
			set s__Buff_FINISH=s__Event_create()
  endfunction


	// linked list
//Implemented from module Alloc:
    
        function s__BuffGen___list_allocate takes nothing returns integer
            local integer this
    
            if ( s__BuffGen___list_Alloc__recycle[(0)] == 0 ) then
                 if ( s__BuffGen___list_Alloc__instanceCount == 8190 ) then
                     call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Alloc ERROR: Attempted to allocate too many instances!")
                     return 0
                 endif
                set s__BuffGen___list_Alloc__instanceCount=s__BuffGen___list_Alloc__instanceCount + 1
                set this=s__BuffGen___list_Alloc__instanceCount
            else
                set this=s__BuffGen___list_Alloc__recycle[(0)]
                set s__BuffGen___list_Alloc__recycle[(0)]=s__BuffGen___list_Alloc__recycle[s__BuffGen___list_Alloc__recycle[(0)]]
            endif

             set s__BuffGen___list_Alloc__recycle[this]=- 1
    
            return this
        endfunction
    
        function s__BuffGen___list_deallocate takes integer this returns nothing
             if ( s__BuffGen___list_Alloc__recycle[this] != - 1 ) then
                 call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Alloc ERROR: Attempted to deallocate an invalid instance at [" + I2S(this) + "]!")
                 return
             endif

            set s__BuffGen___list_Alloc__recycle[this]=s__BuffGen___list_Alloc__recycle[(0)]
            set s__BuffGen___list_Alloc__recycle[(0)]=this
        endfunction

  function s__BuffGen___list_create takes nothing returns integer
   local integer this=s__BuffGen___list_allocate()
			set s__BuffGen___list_c=s__BuffGen___list_c + 1
			set s__BuffGen___list_prev[s__BuffGen___list_next[(0)]]=this
            set s__BuffGen___list_next[this]=s__BuffGen___list_next[(0)]
            set s__BuffGen___list_next[(0)]=this
			set s__BuffGen___list_prev[this]=(0)
			//default values
			set s__BuffGen___list_u[this]=null
			set s__BuffGen___list_b[this]=0
			set s__BuffGen___list_d[this]=0
			set s__BuffGen___list_p[this]=0
			return this
  endfunction

  function s__BuffGen___list_destroy takes integer this returns nothing
			call s__BuffGen___list_deallocate(this)
            set s__BuffGen___list_next[s__BuffGen___list_prev[this]]=s__BuffGen___list_next[this]
			set s__BuffGen___list_prev[s__BuffGen___list_next[this]]=s__BuffGen___list_prev[this]
            set s__BuffGen___list_c=s__BuffGen___list_c - 1
  endfunction
		
        function s__BuffGen___list__get_head takes nothing returns integer
            //thistype(0) indicates the beginning and the end of the list
			return s__BuffGen___list_next[(0)]
        endfunction
        
		//method get note; it returns a note that contains "unit u" and " Buff b"
  function s__BuffGen___list_g takes unit u,integer b returns integer
   local integer l=s__BuffGen___list__get_head()
			loop
				exitwhen l == 0
				if s__BuffGen___list_u[l] == u and s__BuffGen___list_b[l] == b then
					return l
				endif
				set l=s__BuffGen___list_next[l]
			endloop
			// return 0 if which note don't exists
			return 0
  endfunction
	

//library BuffGen ends
//===========================================================================
// 
// Buff Generator System v1.5
// 
//   Warcraft III map script
//   Generated by the Warcraft III World Editor
//   Date: Tue Nov 22 02:05:48 2011
//   Map Author: Luiz P. "Bills"
// 
//===========================================================================

//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************


function InitGlobals takes nothing returns nothing
endfunction

//***************************************************************************
//*
//*  Unit Creation
//*
//***************************************************************************

//===========================================================================
function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p= Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u=CreateUnit(p, 'ogru', 628.2, - 442.4, 168.846)
    set u=CreateUnit(p, 'Obla', 676.1, - 554.7, 178.886)
    call SetHeroLevel(u, 10, false)
    call SetUnitState(u, UNIT_STATE_MANA, 540)
    set u=CreateUnit(p, 'Oshd', 803.1, - 584.2, 174.146)
    call SetHeroLevel(u, 10, false)
    call SetUnitState(u, UNIT_STATE_MANA, 585)
    set u=CreateUnit(p, 'ogru', 535.1, - 608.1, 168.846)
    set u=CreateUnit(p, 'hpea', 572.4, - 519.6, 342.147)
endfunction

//===========================================================================
function CreateNeutralHostile takes nothing returns nothing
    local player p= Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u=CreateUnit(p, 'nvl2', - 361.6, - 172.9, 339.883)
    set u=CreateUnit(p, 'nvil', - 164.4, - 97.1, 218.206)
    set u=CreateUnit(p, 'nvl2', - 284.4, - 201.8, 180.213)
    set u=CreateUnit(p, 'nvl2', - 451.5, - 884.2, 320.458)
    set u=CreateUnit(p, 'nvl2', - 348.4, - 869.8, 252.990)
    set u=CreateUnit(p, 'nvil', - 363.5, - 994.1, 97.601)
    set u=CreateUnit(p, 'nvlw', - 323.9, - 985.0, 126.507)
    set u=CreateUnit(p, 'nvlw', - 128.5, - 122.5, 207.264)
endfunction

//===========================================================================
function CreatePlayerBuildings takes nothing returns nothing
endfunction

//===========================================================================
function CreatePlayerUnits takes nothing returns nothing
    call CreateUnitsForPlayer0()
endfunction

//===========================================================================
function CreateAllUnits takes nothing returns nothing
    call CreatePlayerBuildings()
    call CreateNeutralHostile()
    call CreatePlayerUnits()
endfunction

//***************************************************************************
//*
//*  Custom Script Code
//*
//***************************************************************************
//TESH.scrollpos=0
//TESH.alwaysfold=0

//***************************************************************************
//*
//*  Triggers
//*
//***************************************************************************

//===========================================================================
// Trigger: BuffGen Struct
//===========================================================================
//TESH.scrollpos=473
//TESH.alwaysfold=0
//===========================================================================
// Trigger: World Bounds
//===========================================================================
//TESH.scrollpos=0
//TESH.alwaysfold=0
// Trigger: Alloc
//===========================================================================
//TESH.scrollpos=58
//TESH.alwaysfold=0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ Alloc ~~ By Sevion ~~ Version 1.09 ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//  What is Alloc?
//         - Alloc implements an intuitive allocation method for array structs
//
//    =Pros=
//         - Efficient.
//         - Simple.
//         - Less overhead than regular structs.
//
//    =Cons=
//         - Must use array structs (hardly a con).
//         - Must manually call OnDestroy.
//         - Must use Delegates for inheritance.
//         - No default values for variables (use onInit instead).
//         - No array members (use another Alloc struct as a linked list or type declaration).
//
//    Methods:
//         - struct.allocate()
//         - struct.deallocate()
//
//           These methods are used just as they should be used in regular structs.
//
//    Modules:
//         - Alloc
//           Implements the most basic form of Alloc. Includes only create and destroy
//           methods.
//
//  Details:
//         - Less overhead than regular structs
//
//         - Use array structs when using Alloc. Put the implement at the top of the struct.
//
//         - Alloc operates almost exactly the same as default structs in debug mode with the exception of onDestroy.
//
//  How to import:
//         - Create a trigger named Alloc.
//         - Convert it to custom text and replace the whole trigger text with this.
//
//  Thanks:
//         - Nestharus for the method of allocation and suggestions on further merging.
//         - Bribe for suggestions like the static if and method names.
//         - PurgeandFire111 for some suggestions like the merging of Alloc and AllocX as well as OnDestroy stuff.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//===========================================================================
// Trigger: Unit Indexer
//===========================================================================
//TESH.scrollpos=0
//TESH.alwaysfold=0
// Trigger: Event
//===========================================================================
//TESH.scrollpos=22
//TESH.alwaysfold=0
function InitCustomTriggers takes nothing returns nothing
    //Function not found: call InitTrig_BuffGen_Struct()
    //Function not found: call InitTrig_World_Bounds()
    //Function not found: call InitTrig_Alloc()
    //Function not found: call InitTrig_Unit_Indexer()
    //Function not found: call InitTrig_Event()
endfunction

//***************************************************************************
//*
//*  Players
//*
//***************************************************************************

function InitCustomPlayerSlots takes nothing returns nothing

    // Player 0
    call SetPlayerStartLocation(Player(0), 0)
    call SetPlayerColor(Player(0), ConvertPlayerColor(0))
    call SetPlayerRacePreference(Player(0), RACE_PREF_HUMAN)
    call SetPlayerRaceSelectable(Player(0), true)
    call SetPlayerController(Player(0), MAP_CONTROL_USER)

endfunction

function InitCustomTeams takes nothing returns nothing
    // Force: TRIGSTR_002
    call SetPlayerTeam(Player(0), 0)

endfunction

//***************************************************************************
//*
//*  Main Initialization
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call SetCameraBounds(- 1280.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), - 1536.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 1280.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 1024.0 - GetCameraMargin(CAMERA_MARGIN_TOP), - 1280.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 1024.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 1280.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), - 1536.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM))
    call SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
    call NewSoundEnvironment("Default")
    call SetAmbientDaySound("LordaeronSummerDay")
    call SetAmbientNightSound("LordaeronSummerNight")
    call SetMapMusic("Music", true, 0)
    call CreateAllUnits()
    call InitBlizzard()

call ExecuteFunc("jasshelper__initstructs795776031")

    call InitGlobals()
    call InitCustomTriggers()

endfunction

//***************************************************************************
//*
//*  Map Configuration
//*
//***************************************************************************

function config takes nothing returns nothing
    call SetMapName("TRIGSTR_054")
    call SetMapDescription("TRIGSTR_055")
    call SetPlayers(1)
    call SetTeams(1)
    call SetGamePlacement(MAP_PLACEMENT_USE_MAP_SETTINGS)

    call DefineStartLocation(0, 704.0, - 576.0)

    // Player setup
    call InitCustomPlayerSlots()
    call SetPlayerSlotAvailable(Player(0), MAP_CONTROL_USER)
    call InitGenericPlayerSlots()
endfunction




//Struct method generated initializers/callers:
function sa__BuffGen___list_create takes nothing returns boolean

   local integer this=s__BuffGen___list_allocate()
			set s__BuffGen___list_c=s__BuffGen___list_c + 1
			set s__BuffGen___list_prev[s__BuffGen___list_next[(0)]]=this
            set s__BuffGen___list_next[this]=s__BuffGen___list_next[(0)]
            set s__BuffGen___list_next[(0)]=this
			set s__BuffGen___list_prev[this]=(0)
			set s__BuffGen___list_u[this]=null
			set s__BuffGen___list_b[this]=0
			set s__BuffGen___list_d[this]=0
			set s__BuffGen___list_p[this]=0
set f__result_integer= this
   return true
endfunction
function sa__BuffGen___list_destroy takes nothing returns boolean
local integer this=f__arg_this
			call s__BuffGen___list_deallocate(this)
            set s__BuffGen___list_next[s__BuffGen___list_prev[this]]=s__BuffGen___list_next[this]
			set s__BuffGen___list_prev[s__BuffGen___list_next[this]]=s__BuffGen___list_prev[this]
            set s__BuffGen___list_c=s__BuffGen___list_c - 1
   return true
endfunction
function sa__BuffGen___list__get_head takes nothing returns boolean

set f__result_integer= s__BuffGen___list_next[(0)]
   return true
endfunction
function sa__BuffGen___list_g takes nothing returns boolean
    set f__result_integer=s__BuffGen___list_g(f__arg_unit1,f__arg_integer1)
   return true
endfunction
function sa__Buff_apply takes nothing returns boolean
    call s__Buff_apply(f__arg_this,f__arg_unit1,f__arg_real1)
   return true
endfunction
function sa__Buff_D takes nothing returns boolean

   local integer l=sc__BuffGen___list__get_head()
			loop
				exitwhen l == 0
				if s__BuffGen___list_p[l] == 0 then //if not paused
					set s__BuffGen___list_d[l]=s__BuffGen___list_d[l] - s__Buff_TIMEOUT
					call sc___prototype4_evaluate(s__Buff_p[s__BuffGen___list_b[l]],GetUnitUserData(s__BuffGen___list_u[l])) //call onPeriodic
					if s__BuffGen___list_d[l] <= 0.00 then
						call sc___prototype4_evaluate(s__Buff_f[s__BuffGen___list_b[l]],GetUnitUserData(s__BuffGen___list_u[l])) //call onFinish
						call sc__Buff_remove(s__BuffGen___list_b[l],s__BuffGen___list_u[l]) //remove buff
					endif
				endif
				set l=s__BuffGen___list_next[l]
			endloop
   return true
endfunction
function sa__Buff_remove takes nothing returns boolean
    call s__Buff_remove(f__arg_this,f__arg_unit1)
   return true
endfunction
function sa__Buff_release takes nothing returns boolean
    set f__result_boolean=s__Buff_release(f__arg_this,f__arg_unit1)
   return true
endfunction
function sa__Buff__staticgetindex takes nothing returns boolean
    set f__result_integer=s__Buff__staticgetindex(f__arg_unit1)
   return true
endfunction

function jasshelper__initstructs795776031 takes nothing returns nothing
    set st__BuffGen___list_create=CreateTrigger()
    call TriggerAddCondition(st__BuffGen___list_create,Condition( function sa__BuffGen___list_create))
    set st__BuffGen___list_destroy=CreateTrigger()
    call TriggerAddCondition(st__BuffGen___list_destroy,Condition( function sa__BuffGen___list_destroy))
    set st__BuffGen___list__get_head=CreateTrigger()
    call TriggerAddCondition(st__BuffGen___list__get_head,Condition( function sa__BuffGen___list__get_head))
    set st__BuffGen___list_g=CreateTrigger()
    call TriggerAddCondition(st__BuffGen___list_g,Condition( function sa__BuffGen___list_g))
    set st__Buff_apply=CreateTrigger()
    call TriggerAddCondition(st__Buff_apply,Condition( function sa__Buff_apply))
    set st__Buff_D=CreateTrigger()
    call TriggerAddCondition(st__Buff_D,Condition( function sa__Buff_D))
    set st__Buff_remove=CreateTrigger()
    call TriggerAddCondition(st__Buff_remove,Condition( function sa__Buff_remove))
    set st__Buff_release=CreateTrigger()
    call TriggerAddCondition(st__Buff_release,Condition( function sa__Buff_release))
    set st__Buff__staticgetindex=CreateTrigger()
    call TriggerAddCondition(st__Buff__staticgetindex,Condition( function sa__Buff__staticgetindex))


call ExecuteFunc("s__WorldBounds_WorldBounds___WorldBoundInit__onInit")



call ExecuteFunc("s__UnitIndexer_UnitIndexer___UnitIndexerInit__onInit")

call ExecuteFunc("s__Buff_BuffGen___I__onInit")




endfunction

And maybe you reorder your methods, because right now, you have lots of Evaluates things that can be avoid'ed.
 
Level 6
Joined
Jun 20, 2011
Messages
249
IMO you should remove the periodic stuff and let the user do it himself.
You constantly through all buffs created to check which ones belong to a unit, this can be avoided if you used the LinkedListModule i wrote.
Your documentation is missing some methods, such as create
The way you're using to remove buffs is incredibly inaccurate and slow, use TimerUtils instead.
 
Level 4
Joined
Jun 9, 2011
Messages
91
You constantly through all buffs created to check which ones belong to a unit, this can be avoided if you used the LinkedListModule i wrote.
I'm working in this.
Your documentation is missing some methods, such as create
In documentation is only the needful methods to the user.
The way you're using to remove buffs is incredibly inaccurate and slow, use TimerUtils instead.
why it is slow?
 
You wouldn't.
You'd give us modules or textmacros for looping through buffs.
The only thing you'd have to do is put them in a list.

JASS:
function DoIterateByUser takes nothing returns nothing
    implement ForEachBuff
    
    do whatever you want before iteration starts

    implement ForEachBuffLoop
        // iteration code here
        // You'd use a function like GetEnumBuff() to return the current buff
    implement ForEachBuffEnd

    user does whatever he wants
endfunction

Your modules would look like this:

JASS:
module ForEachBuff
    local Buff thisBuff = nextBuff[0]
endmodule

module ForEachBuffLoop
    loop
        exitwhen thisBuff == 0
        set CurrentLoopingBuff = thisBuff
endmodule

module ForEachBuffEnd
        set thisBuff = nextBuff[thisBuff]
    endloop
endmodule

You'd have a linked list with these as the arrays:
JASS:
private static Buff array nextBuff
private static Buff array prevBuff

You'd also have a global Buff called CurrentLoopingBuff
and a function:

JASS:
function GetEnumBuff takes nothing returns Buff
    return CurrentLoopingBuff
endfunction

for the user to use to get the new Buff he's working with.

Hope this helps :)
 
Level 4
Joined
Jun 9, 2011
Messages
91
Oh thanks mag, but I just evaluates a local trigger, look:

JASS:
method forEachBuff takes code callback returns nothing
			local integer i=cB
            local unit u=null
            local trigger t=null
            if List(this).c==0 then
				return
			elseif callback != null then
                set t=CreateTrigger()
            endif
            call TriggerAddCondition(t,Filter(callback))
            set u=GetUnitById(this)
			loop
				exitwhen i==0
				if GetUnitAbilityLevel(u,thistype(i).aI)>0 then
                    set eventUnit=u
                    set eventBuff=thistype(i)
					call TriggerEvaluate(t)
				endif
				set i=i-1
			endloop
            call TriggerClearConditions(t)
            call DestroyTrigger(t)
            set t=null
            set u=null
		endmethod
 
Level 31
Joined
Jul 10, 2007
Messages
6,307
.... the trigger evaluation in a loop is extremely bad


Also, you never use something like Alloc for a linked list. You can save a variable with a linked list by doing special allocation as well as have access to range operations. For example, when a unit is deindexed, the destroy would be 2 lines of code rather than a huge loop, unless ofc you want to run on destroy events ; P.



Modules are the best way to handle buffs... each type of custom buff should be in its own struct that implements a module. By doing this, you increase the speed by a drastic amount.


Abstract what you can, but try to avoid masses of trigger evaluations like you have right now.
 
Level 6
Joined
Jun 20, 2011
Messages
249
It wouldn't matter because that system doesn't exist at the hive because our standards are way higher.

"Dang it Joe, hes asking for BuffStruct, but there are two of em"
"I bet hes asking for the good one Phil"
"And who that be"
"The one at THW"
 
JASS:
set d=t[id].real[index]
                set d=d-TIMEOUT
->
set d = t[id].real[index] - TIMEOUT

The only con I see here is the large module :p

Also, you don't need to subtract one from the index in array ed everytime :/
I also don't like how you're using it for a fake-2Darray :/
You can replace it with 2 arrays remove all the index math and you'll be fine ^.^
It'll even be faster and cleaner :D
 
Top