Skip to content
Home
Post Code
Jass (Warcraft III)
Wurst
GUI (Warcraft III)
Galaxy (StarCraft II)
GUI (StarCraft II)
C++
Java
Delphi
Text
Search Code
Compare Code
Uploads
Draw
Create New Drawing
View Drawings
Graph
Log in
[code]package CustomObjectIdGenerator int array id constant heroPrefix = [color=999999][i]'W'[/i][/color] constant nonheroPrefix = [color=999999][i]'%'[/i][/color] boolean helperActivator = initHelper[b]([/b][b])[/b] function initHelper[b]([/b][b])[/b] returns boolean for int i = [color=FFFF77]0[/color] to [color=FFFF77]2[/color] id[b][[/b]i[b]][/b] = [color=999999][i]'0'[/i][/color] return true function nextValid[b]([/b]int c[b])[/b] returns int int r = c + [color=FFFF77]1[/color] if r == [color=999999][i]'_' or r == ','or r == '"'or r == '\' or r == '-'[/i][/color] r++ if r == [color=999999][i]'_' or r == ','or r == '"'or r == '\' or r == '-'[/i][/color] r++ return r function fourChar[b]([/b]int a, int b, int c, int d[b])[/b] returns int return [b]([/b][b]([/b][b]([/b][b]([/b][b]([/b]a[b]*[/b][color=FFFF77]256[/color][b])[/b] + b[b])[/b][b]*[/b][color=FFFF77]256[/color][b])[/b]+c[b])[/b][b]*[/b][color=FFFF77]256[/color][b])[/b]+d function newId[b]([/b]int prefix[b])[/b] returns int if helperActivator for i = [color=FFFF77]0[/color] to [color=FFFF77]2[/color] if id[b][[/b]i[b]][/b] < [color=999999][i]'~'[/i][/color] id[b][[/b]i[b]][/b] = nextValid[b]([/b]id[b][[/b]i[b]][/b][b])[/b] for j = [color=FFFF77]0[/color] to i-[color=FFFF77]1[/color] id[b][[/b]j[b]][/b] = [color=999999][i]'!'[/i][/color] return fourChar[b]([/b]prefix, id[b][[/b][color=FFFF77]2[/color][b]][/b], id[b][[/b][color=FFFF77]1[/color][b]][/b], id[b][[/b][color=FFFF77]0[/color][b]][/b][b])[/b] error[b]([/b][color=77FF77]"No vaild id left"[/color][b])[/b] return [color=FFFF77]0[/color] public function genId[b]([/b][b])[/b] returns int return newId[b]([/b]nonheroPrefix[b])[/b] public function genHeroId[b]([/b][b])[/b] returns int return newId[b]([/b]heroPrefix[b])[/b] [/code]
select language
jass
java
delphi
C++
php
GSL
galaxy
> visualBasic
wurst
Text
Markdown
select style
default
> bbcode - default
Jasscraft
jasscraft html
visual
lightweight
lightweightNr
goto line:
Compare with:
text copy window
edit this code
post new code
package CustomObjectIdGenerator int array id constant heroPrefix = 'W' constant nonheroPrefix = '%' boolean helperActivator = initHelper() function initHelper() returns boolean for int i = 0 to 2 id[i] = '0' return true function nextValid(int c) returns int int r = c + 1 if r == '_' or r == ','or r == '"'or r == '\' or r == '-' r++ if r == '_' or r == ','or r == '"'or r == '\' or r == '-' r++ return r function fourChar(int a, int b, int c, int d) returns int return (((((a*256) + b)*256)+c)*256)+d function newId(int prefix) returns int if helperActivator for i = 0 to 2 if id[i] < '~' id[i] = nextValid(id[i]) for j = 0 to i-1 id[j] = '!' return fourChar(prefix, id[2], id[1], id[0]) error("No vaild id left") return 0 public function genId() returns int return newId(nonheroPrefix) public function genHeroId() returns int return newId(heroPrefix)