• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

BotL - Coding & Systems

Status
Not open for further replies.
Level 22
Joined
Sep 24, 2005
Messages
4,821
He meant a method man, the parameters are on his previous post hehe XD.

EDIT:A snippet (more of a template) of a looping trigger in vJASS, Linked List, just make a random example that shows a debug msg each 1 s, i'll need it for other things (PS: make it like: call LoopTest_Debug(string Msg, real FPS)
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
@Jad
JASS:
library DebugLoop requires LLAlloc
    globals
        private constant real FPS = 0.0312500
    endglobals
    
    struct Loop extends array
        private real temp
        private string s
        private static timer period = CreateTimer()
        //! runtextmacro LL_Alloc()
        
        static method periodic takes nothing returns nothing
            local thistype this = first
            loop
                exitwhen this == 0
                call BJDebugMsg(this.s)
                set this.temp = this.temp - FPS
                if this.temp <= 0 then
                    call this.unchain()
                    call this.deallocate()
                endif
                if empty() then
                    call PauseTimer(period)
                endif
                set this = this.next
            endloop
        endmethod
    
        static method Debug takes string msg, real duration returns nothing
            local thistype this = thistype.allocate()
            set this.temp = duration
            set this.s = msg
            if empty() then   
                call TimerStart(period, FPS, true, function thistype.periodic)
            endif
            call this.chain()
        endmethod
    endstruct
endlibrary
Using the last LL_Alloc.
I was too lazy to merge chain and allocate into a developped custom allocator ^^
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
You need the new library LLAlloc you can found in the group.
JASS:
library LLAlloc /*
************************************************************************************
*
*   module LL_Alloc
*
*       Description
*       -------------------------
*
*           This is an alternative allocation that allows you to use LinkedList
*           in your struct. Linked List for allocation, destruction, iteration.
*
*       Fields
*       -------------------------
*
*           private thistype next
*           private thistype prev
*           
*           private static integer count
*
*           debug private boolean check
*
*       Methods
*       -------------------------
*
*           static method allocate takes nothing returns thistype
*           method deallocate takes nothing returns nothing
*
*           method chain takes nothing returns nothing
*               ~Chain the instance in order to make the iteration iterate through it
*
*           method unchain takes nothing returns nothing
*               ~Unchain the instance in order to make the iteration not iterate anymore through it
*           
*           method operator first takes nothing returns thistype
*               ~Return the first one in the list to iterate
*
*           Example of usage
*           ~~~~~~~~~~~~~~~~~~
*
*            private struct Test extends array
*                Your
*                Parameters
*               
*               static timer period = CreateTimer()
*               implement LL_Alloc
*        
*                static method periodic takes nothing returns nothing
*                   local thistype this = first
*                   loop
*                       exitwhen this == 0
*                
*                       Do
*                       Your
*                       Stuff
*                       
*                       if you have to deallocate then
*                           Do
*                           Deallocate
*                           Stuff
*                           
*                           call this.unchain
*                           call this.deallocate (if you don't need the struct anymore)
*                       endif
*                       set this = this.next
*                   endloop
*               endmethod
*
*               static method create takes nothing returns thistype
*                   local thistype this = thistype.allocate()
*            
*                   Perform
*                   Create
*                    Stuff
*            
*                    return this
*               endmethod
*
*               method start takes nothing returns nothing
*                   if this.empty then
*                       call TimerStart(period, 0.0312500, true, function thistype.periodic)
*                   endif
*                   call this.chain
*               endmethod
*           endstruct
************************************************************************/
    //! textmacro LL_Alloc
        private thistype prev
        private thistype next
        private static integer count = 0
        debug private boolean check
        
        private method deallocate takes nothing returns nothing
            set this.prev = thistype(0).prev
            set thistype(0).prev = this
        endmethod
        
        private static method allocate takes nothing returns thistype
            local thistype this
            if thistype(0).prev == 0 then
                set count = count + 1
                debug if count > 8190 then
                    debug call BJDebugMsg("Linked List Module -> You're instanciating too much structs !!!")
                    debug return 0
                debug endif
                set this = count
            else
                set this = thistype(0).prev
                set thistype(0).prev = thistype(0).prev.prev
            endif
            debug set this.check = false
            return this
        endmethod
        
        private method chain takes nothing returns nothing
            debug if this.check then
                debug call BJDebugMsg("You're trying to chain an already chained unit")
                debug return
            debug endif
            debug set this.check = true
            if thistype(0).next != 0 then
                set thistype(0).next.prev = this
            endif
            set this.next = thistype(0).next
            set thistype(0).next = this
            set this.prev = thistype(0)
        endmethod
        
        private method unchain takes nothing returns nothing
            debug if not this.check then
                debug call BJDebugMsg("You're tring to unchain a non-chained unit")
                debug return
            debug endif
            debug set this.check = false
            if this.next != 0 then
                set this.next.prev = this.prev
            endif
            set this.prev.next = this.next
        endmethod
        
        private static method first takes nothing returns thistype
            return thistype(0).next
        endmethod
        
        private static method empty takes nothing returns boolean
            return thistype(0).next == 0
        endmethod
        //! endtextmacro
endlibrary

I switched to textmacros -> Far better ^^
 
Level 22
Joined
Sep 24, 2005
Messages
4,821

122581-albums6790-picture76610.png

It's called sorcery, mah boi Mal! Sorcery, I say!
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
okay, so i have this spell, that i am trying to make.. problem is that in-game, it shows the debug msg, trying to unchain a not chained thingie
so, what's wrong?

JASS:
library StormRage requires LLAlloc
    globals
        private constant real FPS = 0.050000000000
    endglobals
   
    private struct Loop extends array
        private real temp
        private unit u
        private static timer period = CreateTimer()
        //! runtextmacro LL_Alloc()
       
        static method periodic takes nothing returns nothing
            local thistype this = first
            loop
                exitwhen this == 0
                set this.temp = this.temp - FPS
                if this.temp <= 0 then
                    call GroupRemoveUnit(SR_Grp, this.u)
                    call this.unchain()
                    call this.deallocate()
                endif
                if empty() then
                    call PauseTimer(period)
                endif
                set this = this.next
            endloop
        endmethod
   
        static method Debug takes unit U, real duration returns nothing
            local thistype this = thistype.allocate()
            set this.temp = duration
            set this.u = U
            if empty() then  
                call TimerStart(period, FPS, true, function thistype.periodic)
            endif
            call this.chain()
        endmethod
        
        private static method cond takes nothing returns boolean
            local unit u
            if GetSpellAbilityId() == 'A009' then
                set u = GetTriggerUnit()
                call GroupAddUnit(SR_Grp,u)
                call Debug(u,10)
                call TimedStats.AddTimedStatBonus(u, SR_BONUS[GetUnitAbilityLevel(u, 'A009')]*GetHeroAgi(u, false)/100, 2, 10)
            endif
            return false
        endmethod
        
        private static method act takes nothing returns boolean
            local unit u
            local unit u1 = GetTriggerUnit()
            local real r
            if (GetIssuedOrderId() == OrderId("attack") or GetIssuedOrderId() == OrderId("smart")) and IsUnitInGroup(u1, SR_Grp) then
                set u = GetOrderTargetUnit()
                if u != null and SquareRoot(GetUnitX(u)*GetUnitX(u1) + GetUnitY(u)*GetUnitY(u1)) < (200+ SR_AOE_FACTOR[GetUnitAbilityLevel(u1,'A009')]*GetHeroAgi(u1,true)) then
                    set r = GetRandomReal(0,360)
                    call SetUnitX(u1, PolarProjectionX(GetUnitX(u), r, 100))
                    call SetUnitY(u1, PolarProjectionY(GetUnitY(u), r, 100))
                endif
                set u = null
            endif
            set u1 = null
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger(  )
            call TriggerRegisterAnyUnitEventBJ(t, ConvertPlayerUnitEvent(274))
            call TriggerAddCondition(t, Condition(function thistype.cond))
            set t = null
            //
            set t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
            call TriggerAddCondition(t, Condition(function thistype.act))    
            set t = null
        endmethod
    endstruct
endlibrary
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
JASS:
library LLAlloc /*
************************************************************************************
*
*   textmacro LL_Alloc()
*
*       Description
*       -------------------------
*
*           This is an alternative allocation that allows you to use LinkedList
*           in your struct. Linked List for allocation, destruction, iteration.
*
*       Fields
*       -------------------------
*
*           private thistype next
*           private thistype prev
*           
*           private static integer count
*
*       Methods
*       -------------------------
*
*           static method allocate takes nothing returns thistype
*           method deallocate takes nothing returns nothing
*
*           method chain takes nothing returns nothing
*               ~Chain the instance in order to make the iteration iterate through it
*
*           method unchain takes nothing returns nothing
*               ~Unchain the instance in order to make the iteration not iterate anymore through it
*           
*           method operator first takes nothing returns thistype
*               ~Return the first one in the list to iterate
*
*           Example of usage
*           ~~~~~~~~~~~~~~~~~~
*
*            private struct Test extends array
*                Your
*                Parameters
*               
*               static timer period = CreateTimer()
*               implement LL_Alloc
*        
*                static method periodic takes nothing returns nothing
*                   local thistype this = first
*                   loop
*                       exitwhen this == 0
*                
*                       Do
*                       Your
*                       Stuff
*                       
*                       if you have to deallocate then
*                           Do
*                           Deallocate
*                           Stuff
*                           
*                           call this.unchain
*                           call this.deallocate (if you don't need the struct anymore)
*                       endif
*                       set this = this.next
*                   endloop
*               endmethod
*
*               static method create takes nothing returns thistype
*                   local thistype this = thistype.allocate()
*            
*                   Perform
*                   Create
*                    Stuff
*            
*                    return this
*               endmethod
*
*               method start takes nothing returns nothing
*                   if this.empty then
*                       call TimerStart(period, 0.0312500, true, function thistype.periodic)
*                   endif
*                   call this.chain
*               endmethod
*           endstruct
************************************************************************/
    //! textmacro LL_Alloc
        private thistype prev
        private thistype next
        private static integer count = 0
        
        private method deallocate takes nothing returns nothing
            set this.prev = thistype(0).prev
            set thistype(0).prev = this
        endmethod
        
        private static method allocate takes nothing returns thistype
            local thistype this
            if thistype(0).prev == 0 then
                set count = count + 1
                set this = count
            else
                set this = thistype(0).prev
                set thistype(0).prev = thistype(0).prev.prev
            endif
            return this
        endmethod
        
        private method chain takes nothing returns nothing
            if thistype(0).next != 0 then
                set thistype(0).next.prev = this
            endif
            set this.next = thistype(0).next
            set thistype(0).next = this
            set this.prev = thistype(0)
        endmethod
        
        private method unchain takes nothing returns nothing
            if this.next != 0 then
                set this.next.prev = this.prev
            endif
            set this.prev.next = this.next
        endmethod
        
        private static method first takes nothing returns thistype
            return thistype(0).next
        endmethod
        
        private static method empty takes nothing returns boolean
            return thistype(0).next == 0
        endmethod
        //! endtextmacro
endlibrary
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
got some problems, with the following, there are 2 debugs, what i get is ONLY one negative number, and then (null)
while i think it should show something like:
10
9.5
9
8.5
etc.

JASS:
library StormRage requires LLAlloc
    globals
        private constant real FPS = 0.050000000000
    endglobals
   
    private struct Loop extends array
        private real temp
        private unit u
        private static timer period = CreateTimer()
        //! runtextmacro LL_Alloc()
       
        static method periodic takes nothing returns nothing
            local thistype this = first
            loop
                exitwhen this == 0
                set this.temp = this.temp - FPS
                call BJDebugMsg(R2S(this.temp))
                if this.temp-FPS <= 0 then
                    call BJDebugMsg(GetUnitName(this.u))
                    call GroupRemoveUnit(SR_Grp, this.u)
                    call this.unchain()
                    call this.deallocate()
                endif
                if empty() then
                    call PauseTimer(period)
                endif
                set this = this.next
            endloop
        endmethod
   
        static method Debug takes unit U, real duration returns nothing
            local thistype this = thistype.allocate()
            set this.temp = duration
            set this.u = U
            if empty() then  
                call TimerStart(period, FPS, true, function thistype.periodic)
            endif
            call this.chain()
        endmethod
        
        private static method cond takes nothing returns boolean
            local unit u
            if GetSpellAbilityId() == 'A009' then
                set u = GetTriggerUnit()
                call GroupAddUnit(SR_Grp,u)
                call Debug(u,10)
                call TimedStats.AddTimedStatBonus(u, SR_BONUS[GetUnitAbilityLevel(u, 'A009')]*GetHeroAgi(u, false)/100, 2, 10)
            endif
            return false
        endmethod
        
        private static method act takes nothing returns boolean
            local unit u
            local unit u1 = GetTriggerUnit()
            local real r
            if (GetIssuedOrderId() == OrderId("attack") or GetIssuedOrderId() == OrderId("smart")) and IsUnitInGroup(u1, SR_Grp) then
                set u = GetOrderTargetUnit()
                if u != null and SquareRoot(GetUnitX(u)*GetUnitX(u1) + GetUnitY(u)*GetUnitY(u1)) > (200+ SR_AOE_FACTOR[GetUnitAbilityLevel(u1,'A009')]*GetHeroAgi(u1,true)) then
                    set r = GetRandomReal(0,360)
            call BJDebugMsg("ROFL")
                    call SetUnitX(u1, PolarProjectionX(GetUnitX(u), r, 100))
                    call SetUnitY(u1, PolarProjectionY(GetUnitY(u), r, 100))
                endif
                set u = null
            endif
            set u1 = null
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger(  )
            local trigger t1 = CreateTrigger(  )
            call TriggerRegisterAnyUnitEventBJ(t, ConvertPlayerUnitEvent(274))
            call TriggerAddCondition(t, Condition(function thistype.cond))
            set t = null
            //
            set t1 = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t1, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
            call TriggerAddCondition(t1, Condition(function thistype.act))    
            set t1 = null
        endmethod
    endstruct
endlibrary
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
The spell is supposed to make the unit whenever he is issued an order targeting an enemy unit , he will move near him of the initial distance between them is less than a certain number, all that lasts 10 seconds

You can see the description in Hero Central, Illidan Sotrmrage submission (Ultimate)
 
Status
Not open for further replies.
Top