Snippet Conversion and Finding Snippet Pack

Nestharus

o-o
Reaction score
84
A variety of very helpful snippets. I came up with all of these on my own except for two. One of the two is a common modular conversion and the other is a common search =P.

I will continue to add to this list as I think up other good algorithms and what not ^_^.

Conversions
JASS:
Functions for converting numbers into ids for arrays
----------------------------------------------------------------
//r is some arbitrary real number
//base is the base and should be under 1
//This is the most accurate way : )
private function Real2Id takes real r, real base returns integer
    return R2I((r/base)-R2I((r/base)/8191)*8191)
endfunction

//If the real is less than or equal 1, it will return 1, etc.
private function Real2Id takes real r returns integer
    return R2I(r-R2I(r/8191)*8191)
endfunction

//The most simple converter ever : ).
private function Integer2Id takes integer i returns integer
    return i-R2I(i/8191)*8191
endfunction
----------------------------------------------------------------

//Nice conversion function from BS. It will convert what you put it into
//the specified base first and then it will round it up if the remainder is over 0 and then
//convert it back to standard base 10 giving you a number that fits perfectly : ). It's useful
//for building timers or going through a series of numbers that follow a pattern ^_^.
private function Convert takes real r, real base returns real
    local real converted
    local integer rounded
    if r > base then
        set converted = r/base
        set rounded = R2I(converted)
        return (R2I(converted-rounded+.999)+roundedTime)*base //this will round up if it's above the base
        //or
        return (R2I(converted-rounded)+roundedTime)*base //this will always round down if above the base
    endif
    return base
endfunction


Searches
JASS:
//This will either find a current variable or find a new one. Use id
//conversions to get the proper start id.
//This is meant to go through some sort of an array given a value to find.
//If it runs into 0, it knows that the value does not exist and returns
//a new id ^_^. Use a conversion function to get the id to start the
//search.
private function Find takes integer id, real find returns integer
    loop
        exitwhen var[id] == find or var[id] == 0
        set id = id + 1
    endloop
    return id
endfunction

//The Super Dynamic Arrays <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />.. bit complicated : P
//Jesus4Lyf uses arrays similar to this one : ).
nextCode refers to the next code to go to
lastCode refers to the previous code to go to
currentCode refers to the currentCode and uses the array&#039;s id so it is always accessible

the functions to use are
NextCode- For looping
RemoveCode- for removing from an array
StreamCodeList- for adding to an array

So why is this array so dynamic? Well, let&#039;s say you have a single array and you want
a multi dimensional array in it. Well, one way is to make it static, meaning you have a
set number of positions etc like 50 positions in the first dimension and 50 slots per thingie ^_^.
Well, this will make the array fully dynamic meaning it could be anything from a 1 dimensional array to a
2 dimensional array with 40 dimensions and 20 slots per thingie. Very useful for when you&#039;re not sure what
you want to do or you want to leave it open.

    private constant function CHECK_NEXT_CODE takes integer id returns boolean //checks to see if the next code exists
        return (nextCode[codeStackLoop[id]] &gt; 0)
    endfunction
    
    private function NextCode takes integer id returns integer //loops through the array from start to finish and back
        local integer result = codeStackLoop[id]
        if CHECK_NEXT_CODE(id) then
            set codeStackLoop[id] = nextCode[codeStackLoop[id]]
        elseif not CHECK_NEXT_CODE(id) then
            set codeStackLoop[id] = firstCode[id]
        endif
        return codeStack[result]
    endfunction
    
    private function AddToCodeStackQueu takes integer stack returns nothing //adds to a queu for freed array indexes
        set codeStackQueuIndex = codeStackQueuIndex + 1
        set codeStackQueu[codeStackQueuIndex] = stack
    endfunction
    
    private function RemoveCodeFromStack takes integer id, integer stack returns integer //removes an index from the array
        local integer recycled = currentCode[id]
        if stack &lt; currentCode[id] then
            set codeStack[stack] = codeStack[currentCode[id]]
            set codePointToStack[codeStack[stack]] = stack
        endif
        set nextCode[lastCode[currentCode[id]]] = 0
        set lastCode[currentCode[id]] = 0
        set currentCode[id] = currentCode[id] - 1
        return recycled
    endfunction
    
    private function RemoveCode takes integer id, integer codeId returns nothing //removes code from the array
        call AddToCodeStackQueu(RemoveCodeFromStack(id, codePointToStack[codeId]))
        set codePointToStack[codeId] = 0
    endfunction
    
    private function CodeStackIndex takes integer id returns integer //attempts to get a recycled index
        if codeStackQueuIndex &gt; 0 then
            set codeStackQueuIndex = codeStackQueuIndex - 1
            return codeStackQueu[codeStackQueuIndex+1]
        endif
        return 0
    endfunction
    
    private function GetCodeStackIndex takes integer id returns integer //gets an index
        local integer instancedIndex = CodeStackIndex(id)
        if instancedIndex == 0 then
            set codeStackIndex = codeStackIndex + 1
            return codeStackIndex
        endif
        return instancedIndex
    endfunction
    
    private function NewCode takes integer id returns integer //creates new index
        local integer instancedIndex = GetCodeStackIndex(id)
        set lastCode[instancedIndex] = nextCode[lastCode[currentCode[id]]]
        set nextCode[lastCode[instancedIndex]] = instancedIndex
        set currentCode[id] = instancedIndex
        return instancedIndex
    endfunction
    
    private function StreamCodeList takes integer codeId, integer id returns nothing //the main function that is called ^_^
        local integer instancedIndex
        if currentCode[id] &gt; 0 then
            set instancedIndex = NewCode(id)
        else
            set instancedIndex = GetCodeStackIndex(id)
            set firstCode[id] = instancedIndex
            set currentCode[id] = instancedIndex
            set lastCode[currentCode[id]] = instancedIndex
            set nextCode[currentCode[id]] = instancedIndex
            set codeStackLoop[id] = firstCode[id]
        endif
        set codeStack[instancedIndex] = codeId
        set codePointToStack[codeId] = instancedIndex
    endfunction
 

UndeadDragon

Super Moderator
Reaction score
447
Why did you comment the whole code?
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Delimited comments no less.
 

Nestharus

o-o
Reaction score
84
Not delimited, but those codes aren't standalone. They are algorithms and patterns that are useful in map design : ).

I guess I can uncomment them if it'll be easier to read : P.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
//If the real is less than or equal 1, it will return 1, etc.
No it doesn't. Anyone can see that all that function does is truncate.



Also:
-Why are these two groups of functions together?
-Document better. What is the use of the different modular conversion functions? Why do we need all of them? What is the search pack for? Has anyone really been far even as decided to use even go want to do look more like? Pretty much.
 

Nestharus

o-o
Reaction score
84
Why are these two groups of functions together?

Searchers and converters work hand in hand : ).

What is the use of the different modular conversion functions?

Whenever you want to convert them into some sort of Id? dif ones for dif types of Ids ^_^. I used the bigger one for converting time : ).

Why do we need all of them?

You don't =). It's just a whole slew of snippets that are common ^^.

What is the search pack for

Well, for searching. The first is a normal find function that can be used with the converters to get the search going as quickly as possible : ). The second splits arrays up dynamically and is uhm... while I was writing it originally I was like Oo. All I can say is next is next and last is last and current is current ^_^.

The 2 functions to be used with the super dynamic arrays are-
StreamCodeList (put something into the array)
RemoveCode(removes something from the array)
NextCode (loop through the array)
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Don't just answer my post, I mean write up some documentation. Say what this is FOR.


You obviously haven't put much effort into that, considering that your code even has 3 uncommented comment lines as basically the entire documentation.

JASS:

//The Super Dynamic Arrays <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />.. bit complicated : P
//Jesus4Lyf uses arrays similar to this one : ).
nextCode refers to the next code to go to
lastCode refers to the previous code to go to
currentCode refers to the currentCode and uses the array&#039;s id so it is always accessible





You also still haven't explained why your second conversion function does the exact same thing as return R2I(r). It doesn't even do that it says it does.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Has anyone really been far even as decided to use even go want to do look more like?
I'd have to agree. <3

JASS:
//The most simple converter ever : ).
private function Integer2Id takes integer i returns integer
    return i-R2I(i/8191)*8191
endfunction

If it's so simple, how did you frak it up?
JASS:
//Let&#039;s call it what it is!
private function ModuloPositiveIntBy8191 takes integer i returns integer
    return i-(i/8191)*8191
endfunction

I'm going to graveyard this because it doesn't serve a direct, simple purpose, it is just a collection of random code, each piece being strangely useless in its own right.

People should write these things themselves. Helps them understand it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top