HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Reducing the numerical value of rawcodes

11-17-2008, 04:55 PM#1
the-thingy
Is there any relatively simple way to reduce the value for a rawcode (well, ANY unit rawcodes) to something that would make the value legitimate for an array OR is there any value I could oversize the arrays by so that they would be capable of handling any possibly unit rawcode? I'm try to make my own experience system, and it would be pretty handy if I could just refer to the unit's EXP given through something like
ExpData.ExpValue[GetUnitTypeId (whichUnit)]
11-17-2008, 05:12 PM#2
Ammorth
You we don't need the information 100 times a second, use table (script section).
11-17-2008, 05:16 PM#3
DioD
To reduce raw codes without any problem use only custom units based of same unit.

I recommend 'ucry' as base.

Then you will able to substract 'u000' from any raw code after substraction you will get short ID (1-2-3-4...for every custom unit used).

There is no need of 8000 units soo you will fit single array.
11-17-2008, 05:41 PM#4
the-thingy
Quote:
Originally Posted by Ammorth
You we don't need the information 100 times a second, use table (script section).
Bleh, why didn't I think of GC

Thanks

Quote:
Originally Posted by DioD
To reduce raw codes without any problem use only custom units based of same unit.

I recommend 'ucry' as base.

Then you will able to substract 'u000' from any raw code after substraction you will get short ID (1-2-3-4...for every custom unit used).

There is no need of 8000 units soo you will fit single array.
But creating a custom version of every single possible required unit (especially if a simple edit to the unit was all that was required, or if there was a large number of units) would be a bit excessive, right?
11-17-2008, 05:44 PM#5
chobibo
I agree with Diod
Collapse JASS:
globals
    constant integer OFFSET = 'u000'
endglobals

function GetUnitReference takes unit who returns integer
    return GetUnitTypeId(who)-OFFSET
endfunction

Just remember not to use predefined unit types from the object editor i.e. 'Hpal', use them only on your custom unit types.

EDIT
Quote:
But creating a custom version of every single possible required unit (especially if a simple edit to the unit was all that was required, or if there was a large number of units) would be a bit excessive, right?

But it's faster and more cleaner, anyways gamecache will work just fine.
11-18-2008, 03:41 AM#6
grim001
Or you can use the index of the string to store the data in an array.

Collapse JASS:
function GetStringIndex takes string s returns integer
    return s
    return 0
endfunction
11-18-2008, 05:41 AM#7
chobibo
I stand corrected, grim001's solution is the best thing to do, since the data is initialized at map initialization, you can use warcraft's internal string table to your advantage without worries.
11-18-2008, 07:18 AM#8
DioD
rb on string cause crush on loading saved game.
11-18-2008, 07:42 AM#9
grim001
yes, that method only works for multiplayer maps.
11-18-2008, 11:53 AM#10
Captain Griffen
Or you can use a basic hash table.

Collapse JASS:
function GetIndex takes integer id returns integer
    local integer i = id-(id/8191)*8191
    loop
        if id == IndexID[i] then
            return i
        endif
    endloop
endfunction

Assumes everything is setup at init and you never try to get the index of something not setup. Pretty much O(1).