HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple Library for finding Unit Animation Num

01-30-2010, 04:17 PM#1
Dark_tengu
Hi guys,

I was just creating a library for finding the animation number of a unit. Since WC3 doesn't have a standard numbering system for all unit animations, I decided to make one (since I need it for my map). Because the only way for units to animate "walk" while being moving by trigger is by using the call SetUnitAnimationByIndex( "unit", index ), this should be useful for some programmers out there.

I just finished the basics of it and am wondering what else I should add to it. The basic idea is we populate a string array with raw codes followed by their animations. Since not all units have the same number of animations, the missing animations will be 99. Also, since units have different animations, I chose the most basic of them for usage. For example, the Crypt Lord has lots of animations, while the Archmage has very little.

Code:
library AnimationTable initializer Init
    globals
        private string array    ANIMATION[8]
    endglobals
    
    private function FillArray takes nothing returns nothing
        // standready, stand1, stand2, stand3, stand4, taunt, walk, attack1, attack2, spellthrow, spellslam, channel, death, dissipate
        // string str       =          "SR-S1-S2-S3-S4-TA-MV-A1-A2-ST-SS-SC-DE-DI"
        
        // humans, hero
        local string Hamg   = "Hamg" + "99-01-02-05-99-03-00-04-99-06-99-09-07-08"       // archmage
        local string Harf   = "Harf" + "03-01-02-99-99-07-11-04-05-08-99-09-06-10"       // arthas w. frostmourne
        local string Hblm   = "Hblm" + "99-00-01-03-99-99-02-04-05-06-08-07-09-10"       // bloodmage
        local string Hjai   = "Hjai" + "99-00-01-99-99-02-06-03-99-04-99-99-07-05"       // jaina
        local string Hlgr   = "Hlgr" + "09-01-02-03-04-99-00-05-06-10-99-99-07-12"       // lord garithos
        local string Hmkg   = "Hmkg" + "00-01-02-03-04-99-07-05-06-09-10-12-08-11"       // mountain king
        local string Hpal   = "Hpal" + "03-00-01-02-99-07-12-04-05-08-99-09-06-11"       // paladin
        local string Hvwd   = "Hvwd" + "12-00-01-02-03-11-08-05-06-07-99-99-04-09"       // slyvanus
        
        // humans, units
        local string hrif   = "hrif" + "07-00-01-02-99-99-06-03-99-08-99-99-04-99"       // rifleman
        
        // night elf
        local string Edem   = "Edem" + "04-00-01-02-03-99-08-05-06-09-11-12-07-10"       // demon hunter
        local string Ekee   = "Ekee" + "07-00-05-06-99-11-02-01-10-04-99-09-03-08"       // keeper of the groove
        local string Emoo   = "Emoo" + "04-00-02-03-99-99-06-05-99-01-99-99-07-08"       // priestess
        local string Ewar   = "Ewar" + "04-00-01-08-99-99-02-05-09-07-06-11-03-10"       // warden
        local string Emns   = "Emns" + "99-00-01-99-99-99-07-03-04-02-99-99-05-06"       // malfurion w.o stag
        local string Eevi   = "Eevi" + "03-00-01-02-99-99-07-04-05-11-09-12-06-10"       // illidan evil
        
        // orc
        local string Obla   = "Obla" + "09-07-00-01-04-10-06-02-08-99-03-12-05-11"       // blademaster
        local string Ofar   = "Ofar" + "03-00-01-99-99-99-02-05-99-08-04-99-06-07"       // farseer
        local string Ogrh   = "Ogrh" + "09-07-00-01-04-10-06-02-08-99-03-12-05-11"       // hellscream
        local string Otch   = "Otch" + "04-00-01-02-99-07-03-05-06-11-10-09-08-12"       // taruen chieftain
        local string Othr   = "Othr" + "99-00-01-99-99-99-02-03-99-04-99-99-05-06"       // thrall
        local string Oshd   = "Oshd" + "07-01-02-05-06-11-00-10-99-03-08-13-04-12"       // shadow hunter
        local string otau   = "otau" + "03-00-01-99-99-05-02-04-99-99-07-99-06-08"       // tauren
        
        // undead
        local string Ucrl   = "Ucrl" + "14-00-01-08-09-10-02-04-05-12-07-06-03-16"       // crypt lord
        local string Udea   = "Udea" + "06-02-01-99-99-99-00-04-99-03-99-99-05-07"       // death king
        local string Udre   = "Udre" + "00-01-02-03-99-99-05-09-10-04-06-99-07-08"       // dreadlord
        local string Ulic   = "Ulic" + "04-00-02-03-99-99-01-06-99-07-99-05-08-09"       // lich
        local string Ubal   = "Ubal" + "99-00-01-02-99-99-04-08-09-03-05-99-06-07"       // balnazaar
        local string Uwar   = "Uwar" + "99-00-01-99-99-99-02-06-07-08-03-99-04-99"       // Archimonde 
        
        /*
        // netural heroes
        local string Nalc   = "" + "99-00-01-02-11-06-04-03-05-07-99-08-09-10"       // alchemist
        local string Nbst   = "" + "09-01-02-99-99-99-00-04-06-05-03-99-07-08"       // beast master
        local string Nbrn   = "" + "09-00-01-02-03-99-08-06-07-04-99-99-05-10"       // dark ranger
        local string Nfir   = "" + "08-00-01-05-99-99-02-03-04-06-99-07-09-10"       // firelord
        local string Nngs   = "" + "02-00-99-99-99-99-01-03-99-05-99-99-04-13"       // naga sea witch
        local string Npbm   = "" + "09-01-02-99-99-99-00-05-06-04-03-10-07-08"       // panda brewmaster
        local string Nplh   = "" + "99-02-04-00-99-99-03-07-15-14-06-12-08-09"       // pit lord
        local string Ntin   = "" + "06-01-02-11-12-99-00-05-99-07-10-09-03-04"       // tinker
        
        // netural units
        local string nbwm   = "" + "04-00-02-99-99-99-03-01-99-99-99-06-05-99"       // dragon, black
        local string nadr   = "" + "04-00-02-99-99-99-03-01-99-99-99-06-05-99"       // dragon, blue
        local string nbzd   = "" + "04-00-02-99-99-99-03-01-99-99-99-06-05-99"       // dragon, bronze
        local string ngrd   = "" + "04-00-02-99-99-99-03-01-99-99-99-06-05-99"       // dragon, green
        local string nrwm   = "" + "04-00-02-99-99-99-03-01-99-99-99-06-05-99"       // dragon, red
        local string nhrh   = "" + "01-00-03-99-99-99-02-04-99-99-99-99-05-99"       // harpy witch
        local string nhyd   = "" + "99-01-06-07-99-99-00-02-09-03-04-99-05-99"       // hydra
        local string njg1   = "" + "04-00-01-02-99-99-07-05-06-99-03-99-08-99"       // jungle stalker
        local string ninf   = "" + "03-00-01-02-99-99-06-04-05-99-99-07-08-99"       // infernal
        local string ninm   = "" + "99-01-99-99-99-99-00-02-99-05-99-99-03-99"       // infernal canon canon
        local string nsgn   = "" + "99-00-99-99-99-99-01-04-03-02-99-06-08-99"       // sea giant
        local string nsko   = "" + "08-00-01-02-99-03-06-04-05-99-99-09-07-99"       // skeleton orc
        
        // netural naga
        string nwgs   = "" + "04-00-99-99-99-99-03-05-99-06-99-99-07-99"       // coutal
        
        // netural, speical
        string ngz1   = "" + "99-01-04-03-99-99-02-06-99-05-99-00-10-99"       // bear
        string nwe1   = "" + "02-00-04-99-99-99-06-07-99-99-99-99-05-99"       // hawk
        */
        
        local integer i
            
        // humans, hero
        set i = 0
        set ANIMATION[i] = Hamg + Harf + Hblm + Hjai + Hlgr + Hmkg + Hpal + Hvwd
        
        // humans, units
        set i = 1
        set ANIMATION[i] = hrif
        
        // night elf, hero
        set i = 2
        set ANIMATION[i] = Edem + Ekee + Emoo + Ewar + Emns + Eevi
        
        // night elf, unit
        set i = 3
        set ANIMATION[i] = ""
        
        // orc, hero
        set i = 4
        set ANIMATION[i] = Obla + Ofar + Ogrh + Otch + Othr + Oshd
        
        // orc, unit
        set i = 5
        set ANIMATION[i] = otau
        
        call SetUnitAnimationByIndex( unit, int )
        
        // netural, hero
        set i = 6
        set ANIMATION[i] = ""
        
        // netural, unit
        set i = 7
        set ANIMATION[i] = ""
        
        // undead, hero
        set i = 8
        set ANIMATION[i] = Ucrl + Udea + Udre + Ulic + Ubal + Uwar
        
        // undead, units
        set i = 9
        set ANIMATION[i] = ""
    endfunction
    
    struct Anim
        string strAnim
        
        static method create takes string strSource returns Anim
            local Anim dt       = Anim.allocate()
            local string        strCheck = ""
            local integer       intStart
            local integer       intEnd
            local integer       i
            local boolean       blReturn    = false
            local string        strError    = "99-99-99-99-99-99-99-99-99-99-99-99-99-99" 
            
            // checks the leading char
            set strCheck = SubString( strSource, 0, 1 )
            if strCheck == "H" then
                set i = 0
            elseif strCheck == "h" then
                set i = 1
            elseif strCheck == "E" then
                set i = 2
            elseif strCheck == "e" then
                set i = 3
            elseif strCheck == "O" then
                set i = 4
            elseif strCheck == "o" then
                set i = 5
            elseif strCheck == "N" then
                set i = 6
            elseif strCheck == "n" then
                set i = 7
            elseif strCheck == "U" then
                set i = 8
            elseif strCheck == "u" then
                set i = 9
            else
                set i = 99
            endif
            
            // starts the find at the first char
            set intStart = 0
            loop
                // ends the string find at 4, since the unit raw code = 4
                set intEnd = intStart + 4
                set strCheck = SubString( ANIMATION[i], intStart, intEnd )
                exitwhen blReturn == true or intStart >= StringLength( ANIMATION[i] )
                
                if strCheck == strSource then
                    // grabs the leading code
                    set dt.strAnim = SubString( ANIMATION[i], intEnd, intEnd + 41 )
                    set blReturn = true
                else 
                    // moves to the next instant of raw code
                    set intStart = intStart + 45
                endif
            endloop
            
            return dt
        endmethod
    
        method getAnim takes string strType returns integer
            local integer  i = 0
            local string   strHold
            
            // finds the animation command
            if strType == "standready" then 
                set i = 0
            elseif strType == "stand1" then
                set i = i + 3
            elseif strType == "stand2" then
                set i = i + 6
            elseif strType == "stand3" then
                set i = i + 9
            elseif strType == "stand4" then
                set i = i + 12
            elseif strType == "taunt" then
                set i = i + 15
            elseif strType == "walk" then
                set i = i + 18
            elseif strType == "attack1" then
                set i = i + 21
            elseif strType == "attack2" then
                set i = i + 24
            elseif strType == "spellthrow" then
                set i = i + 27
            elseif strType == "spellslam" then
                set i = i + 30
            elseif strType == "channel" then
                set i = i + 33
            elseif strType == "death" then
                set i = i + 36
            elseif strType == "dissipate" then
                set i = i + 39
            else
                return 99
            endif
            
            set strHold = SubString( .strAnim, i, i + 2 )
            
            return S2I( strHold )
        endmethod
    endstruct

    private function Init takes nothing returns nothing
        // fills in the string array
        call FillArray()  
    endfunction
endlibrary