• 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.

[Solved] GetUnitRed/Green/Blue??

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,290
This is where SC2 is so good. One can just create a named actor to do the recolour and then remove that actor when you want to restore the colour and the colour then restores to whatever it should correctly be.

In WC3 you will need some tool to read all the tint values from the slk and object editor files and store them in data structures like arrays or hashtables. You then need to simulate all your colouration stacking mechanics with JASS triggers.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
This is where SC2 is so good. One can just create a named actor to do the recolour and then remove that actor when you want to restore the colour and the colour then restores to whatever it should correctly be.

In WC3 you will need some tool to read all the tint values from the slk and object editor files and store them in data structures like arrays or hashtables. You then need to simulate all your colouration stacking mechanics with JASS triggers.
I think one of Earth-Fury's old tools used to be able to read values from .slk files, but honestly who knows if any of that code still runs. WereElf could made a struct that stores the current RGB values for a model and then write wrappers to change them that writes the data to the appropriate struct (linked to the unit with a storage system, hash, or looked up using brute force search on a bigass array) before they get altered . If you only have a few units with colors pre-set in the object editor this is probably the quickest solution, but it will disallow you from setting unit colors in the object editor (you have to change the RGB values to whatever color you want when the unit enters the map, for example).

You could also just write your own lookup table for every unit's default RGB values if they're not 255/255/255/0 initially like this and just brute force search for it (not efficient but works/doesn't matter if you're not doing this too often)

JASS:
globals
    RGBA array UnitColors
    integer TotalUnits //How many different unit types there are in your game whose RGB values are stored by the system
endglobals

struct RGBA
    integer uid  //The rawcode of the unit this RGBA profile corresponds to
    integer R
    integer G
    integer B
    integer A

    method create takes integer UID, integer R, integer G, integer B, integer A
        //whatever is necessary
    endmethod
endstruct

...

//Init function looks something like this:
function Init takes nothing returns nothing
    UnitColors[1] = RGBA.create('Hpea',0,0,255,255)
    UnitColors[2] = RGBA.create('Hfoo',130,193,255,200)
    //etc....
    //This could be automated into a loop or with textmacos
endfunction
...

function GetOriginalRGBA takes integer UnitID returns RGBA
    local integer i = 0

    loop
        exitwhen i >= TotalUnits
        if UnitColors[i].uid == UnitID then
            return UnitColors[i]
        end
        set i = i+1
    endloop

    //If we get here we didn't find a match in our stored array
    return RGBA.createNew() //or some method
endfunction
I would probably initialize it (probably) with a whole bunch of textmacros and ObjectMerger calls to save typing shit out a billion times. Ultimately you still have to cache all the data beforehand and with a willingness to involve some vJASS that makes it all much easier to simplify and compact.
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,658
(You used "unit" instead of "integer".)

In that case, I would recommend a hashtable as looping through hundreds of integers would be much more cpu heavy.
call SaveInteger(.TABLE, unitId, 0, this) // to store the instance at RGBA.create()
local thistype this = LoadInteger(.TABLE, unitId, 0) // to load the instance at RGBA.getOriginalRGBA()

(Units also dont have an alpha from the OE iirc.)
 
Level 13
Joined
Jan 2, 2016
Messages
978
Thanks for all the answers.
I think I will save the unit's RGB value(s) into a hashtable, but instead of a struct - I will just save them as single integer. For example 255200100 would be 255 R 200 G 100 B.
And I will use the following formulas to get each value: R = RGB/1000000; G = RGB/1000 - (RBG/1000000)*1000; B = RGB - (RGB/1000)*1000
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
Thanks for all the answers.
I think I will save the unit's RGB value(s) into a hashtable, but instead of a struct - I will just save them as single integer. For example 255200100 would be 255 R 200 G 100 B.
And I will use the following formulas to get each value: R = RGB/1000000; G = RGB/1000 - (RBG/1000000)*1000; B = RGB - (RGB/1000)*1000
You could also save it represented by a hexadecimal, it is easier in my opinion. Example: Save integer, 0xFFF060 then extraction of each color would just be the same method, but just a different denominator.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Use better numbers:
JASS:
function toInt takes integer red, integer green, integer blue returns integer
    return red + green*256 + blue*256*256
endfunction
function getRed takes integer data returns integer
    return ModuloInteger(data, 256)
endfunction
function getGreen takes integer data returns integer
    return ModuloInteger(data/256, 256)
endfunction
function getBlue takes integer data returns integer
    return ModuloInteger(data/(256*256), 256)
endfunction

Not because it is better, but because it is cool.
 
Status
Not open for further replies.
Top