• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Making a list of unit-types - possible?

Status
Not open for further replies.
Level 13
Joined
Jan 2, 2016
Messages
978
I kind a want to make a list of unit-types, and instead of writing "unit-type equal to ... or .... or .... or .... or .... or ...." I want to write "is unit-type in the list".

I don't insist on doing it the way I poined out, ANY way to do it faster/easier will be apreciated.

I kind a have my eyes on "unitpool"s, I don't really know what they are, but the name at least sounds like something that can be used for my purposes.

EDIT: I kind a found a workaround:
JASS:
function UT_Comparison takes integer ut returns integer
    if ut == 'n00N' then
        return 1
    elseif ut == 'n002' or ut =='n00O' then
        return 2
    elseif ut == 'n00M' or ut == 'e005' then
        return 3
    endif
    return 0
endfunction

This way all of these units are in 1 group, and there are even sub-groups :)
my condition later is (i != 0) if I want to see if the unit is in the group, and I can do (i == 1) to see if it's in sub-group 1 :P
 
Last edited:
For only some checks the used way is okay. If it's planned to add some more
checks then hashtable could be used.

Hashtable is powerful and can be used for cases if you need to store higher integers like unit type ids.
The "index" of the unit type id can be saved in hashtable with key of unit type id. E.g.:
call SaveInteger(hash, 'hfoo', 0, 3)
..
local integer index = LoadInteger(hash, i, 0)
..
if "i" is 'hfoo' the loaded value will be "3".

Does this help?

What logic is there exact behind it? Maybe this is a work around even.. I'm not sure.
 
Well, the main idea is that I want one trigger to run only for certain unit-types, but I also want different settings for different sub-groups.
This is how the full trigger looks for now
JASS:
function UT_Comparison takes integer ut returns integer
    if ut == 'n00N' then
        return 1
    elseif ut == 'n002' or ut == 'n00O' then
        return 2
    elseif ut == 'n00M' or ut == 'e005' then
        return 3
    elseif ut == 'n00P' then
        return 4
    endif
    return 0
endfunction

function Cosmetics takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit c
    local integer i = UT_Comparison(GetUnitTypeId(u))
    if i != 0 then
        call SetUnitVertexColor( u , 100, 100, 100, 1 )
        set c = CreateUnit( GetOwningPlayer(u), 'n01F', x , y , 0.00 )
        if i == 3 then
            call SetUnitScalePercent( c , 100, 100, 100 )
        elseif i == 4 then
            call SetUnitScalePercent( c , 160, 160, 160 )
        endif
        call SetUnitAnimation( c , "birth" )
        call SaveUnitHandle(udg_Cosmetic_Table, GetHandleId(u), 0 , c)
    endif
    return false
endfunction

function Cosm_Removal1 takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local unit c
    local real x
    local real y
    local integer i = UT_Comparison(GetUnitTypeId(u))
    if i != 0 then
        set c = LoadUnitHandle(udg_Cosmetic_Table, GetHandleId(u), 0 )
        call RemoveUnit(c)
        call SetUnitVertexColorBJ( u , 100, 100, 100, 0.00 )
        if i == 1 then
            set x = GetUnitX(u) - 110
            set y = GetUnitY(u) + 25
            set c = CreateUnit( GetOwningPlayer(u), 'h00F', x, y, 270.00 )
            call SaveUnitHandle( udg_Cosmetic_Table, GetHandleId(u), 0 , c )
        endif
        call SaveBoolean( udg_Cosmetic_Table, GetHandleId(u), 1, true )
        set c = null
    endif
    set u = null
    return false
endfunction

function Cosm_Removal2 takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local unit c
    local real x
    local real y
    local effect e
    local integer i = UT_Comparison(GetUnitTypeId(u))
    if i != 0 then
        if LoadBoolean( udg_Cosmetic_Table, GetHandleId(u), 1 ) then
            if i == 1 then
                set c = LoadUnitHandle(udg_Cosmetic_Table, GetHandleId(u), 0 )
                set x = GetUnitX(c)
                set y = GetUnitY(c)
                call RemoveUnit(c)
                set e = AddSpecialEffect("Abilities\\Weapons\\GlaiveMissile\\GlaiveMissileTarget.mdl", x, y)
                call DestroyEffect(e)
                set e = null
            endif
        else
        set c = LoadUnitHandle(udg_Cosmetic_Table, GetHandleId(u), 0 )
        call RemoveUnit(c)
        call FlushChildHashtable(udg_Cosmetic_Table, GetHandleId(u))
        set c = null
        endif
    endif
    set u = null
    return false
endfunction

//===========================================================================
function InitTrig_Building_models takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger r = CreateTrigger()
    set gg_trg_Building_models = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Building_models, EVENT_PLAYER_UNIT_CONSTRUCT_START )
    call TriggerAddCondition( gg_trg_Building_models, Condition(function Cosmetics) )
    call TriggerRegisterAnyUnitEventBJ( r , EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterAnyUnitEventBJ( t , EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
    call TriggerRegisterAnyUnitEventBJ( r , EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL )
    call TriggerAddCondition( t , Condition(function Cosm_Removal1) )
    call TriggerAddCondition( r , Condition(function Cosm_Removal2) )
    set t = null
    set r = null
endfunction

I still got more unit-types to add to it, and I have an idea how to improve (a bit) what I've already made, but I have some side-work, so can't do it at the moment :P

This way of doing it seems to work pretty well tho..
 
If it's only the real for scaling that differs, then it might be directly saved into hashtable,
so no extra index is needed.

Like:
call SetUnitScalePercent( c , LoadRea(...), 0, 0 )

(for scaling, you don't need to touch the two letter arguments.. it's a weird implementation, only the first matters)

(also, why BJ for scaling? :D)
 
Well, that's not a bad idea, but it's not only for scaling. For Example '1' has a dummy unit to enchance its appearance after it's been built.
And I'm going to add one more building with this 'enchantment'.
And you mean "why BJ for the Vertex Color" - I tried it without the BJ, but then it still looks transparent (when the last digit is set to 0), but it works fine when it's BJ, so I left it like this.

EDIT: I'm also about to rotate the dummy unit by 90*i deg, for some 'variety' in the model.
 
Last edited:
Status
Not open for further replies.
Back
Top