• 🏆 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!

Multi Array

a simple library that converts 2d or 3d arrays to a 1d array.
please note that the max size is 8192^1/(dimensions)
that means you can have max a [90,90] or a [20,20,20] array

usefull for grid so you don't have to loop quadratic trough all things (good tutourial here: n-game technique)

JASS:
library MultiArray
    globals
        constant integer TWODIMENSIONMAX = 90 // 8192^(1/2)
        constant integer THREEDIMENSIONMAX = 20 // 8192^(1/3)
    endglobals
    
    function GetTwoDimensionArray takes integer x, integer y returns integer
        if x >= TWODIMENSIONMAX or y >= TWODIMENSIONMAX then
            debug call BJDebugMsg("Multi Array Error: Can not handle this size!")
            return 0
        elseif x < 0 or y <0 then
            debug call BJDebugMsg("Multi Array Error: One or more indexes are too small!")
            return 0
        endif
        return x+y*TWODIMENSIONMAX
    endfunction
    
    function GetThreeDimensionArray takes integer x, integer y, integer z returns integer
        if x >= THREEDIMENSIONMAX or y >= THREEDIMENSIONMAX or z >= THREEDIMENSIONMAX then
            debug call BJDebugMsg("Multi Array Error: Can not handle this size!")
            return 0
        elseif x < 0 or y <0 or z <0 then
            debug call BJDebugMsg("Multi Array Error: One or more indexes are too small!")
            return 0
        endif
        return (x+y*THREEDIMENSIONMAX)+z*(THREEDIMENSIONMAX*THREEDIMENSIONMAX)
    endfunction
endlibrary
 
Top