wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > Misc. Tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-13-2008, 06:44 PM   #1
ADOLF
User from USSR
 
Join Date: Jan 2007
Posts: 127

Submissions (3)

ADOLF will become famous soon enough (36)ADOLF will become famous soon enough (36)

Send a message via ICQ to ADOLF
Default The Type integer

Integer type and rawcode as its instance

***Translation by ArchWorm***

Theory

Integer type in jass is a long signed int meaning each of them takes 32 bits: 31 for a number and one for a sign. In Jass integer can be presented in 8 (octimal), 10 (decimal), 16 (hexadecimal) and 256(ASCII) notation.

I'll explain this briefly (if you are familiar with various notations you can go straight to the practics). In a decimal notation we increment greater order when the lesser one becomes more than or equal to 10(9+1=10). This applies to other notations as well, corrected that they "trigger" on their own bases. Meaning we change greater order after getting 8 in octimal and 16 in hexadecimal. By the way, we use only ten figures, so how to write figure ten, figure eleven and so on? In hexadecimal notation figures representing numbers greater than 9 are replaced with capital latin letters. So, "A" means "10", "B" means "11" et cetera(You can go further and advance it up to 36-based notation). ASCII follows the same idea, but it uses chars' codes instead. For reference look into this table(taken from WEU documentation):

Zoom (requires log in)

If zero is placed before an integer number that number is written in octimal. (local integer i=012 // 10 in deciman) Hexadecimals use 0x in the same way. (local integer i=0x0f // 15 in dec)And if a number is marked by inverted commas you have rawcode ASCII notation. (local integer i='A' // 67 dec). If you want to translate number from one notation to another you can use WinCalc (switched to engineering mode). Translation to ASCII is simple as well: you can translate every "figure" using charcode table and afterwards write resulting codes as they follow. For example, 'A0a1': 'A' = 0x41, '0' = 0x30, 'a' = 0x61, '1' = 0x31, so 'A0a1' means 0x41306131 or 1093689649.

Note that each rawcode is nothing but an integer, and therefore we can do any kind of mathematical operations with them. Look forward for examples.

In Jass there is no possibility to present number in binary notation, but it is very important for us to know about it. As you might have understood, binary notation follows the same rules as octimal, decimal and hexadecimal: greater order (which is called here bit) appears when we get 2 or more in lesser: 1bin+1bin == 10bin (2dec). Now let's go back to our 32-bit integer:

Code:
0x 7    a    9    8    0    1    f    0
   0111 1010 1001 1000 0000 0001 1111 0000

I shall notice, that the first bit is a sign bit, it determines whether number is positive (0) or negative (1). Positive numbers range from 0x00000000 (0dec) to 0x7fffffff (2147483647dec), negative range from 0xffffffff (-1dec) to 0x80000000 (-2147483648dec). When switching sign we have to change all bits' values to their opposites and have to add 1.

In examples I will use single bytes so it is simplier to understand:

Code:
  0000 0001 // +1dec
  1111 1110 // inv
  1111 1111 // -1dec

Now, although in JASS there are no bitwise shift operations, it is possible to mimic them with the help of division and multiplication.

Code:
  1000 1000 // *10bin  (<<)
1 0001 0000 // /100bin (>>)
  0000 0100

Bits that do not fit the result will be considered lost. Now, with the help of two shifts we can receive any bits we need:

Code:
  0110 1101 // *1000
  0110 0000 // /100000
  0000 0011

We caught some problems with the sign bit:

Code:
  0111 1100 // *1000
  1110 0000 // 1110 0000bin - -20dec

  1110 0000 // but we can change value a bit
 +1000 0000
  _____ _____
1 0110 0000

We also can use separator bit to be sure that after our multiplication sign bit is equal to 0:

Code:
  0vv- vvvv

  v - our values

I shall add that multiplication / division on 10bin, 100bin, 1000bin is also left shift/right shift on 1, 2, 3 bits(2^1 == 2 dec == 10 bin; 2^2 == 4 dec == 100 bin; 2^3 == 8 dec == 1000 bin; 2^n == shift on n bits).
That's all for theory, now I'll show examples of how to get it working.

Practics

For example, there are some simple problems with their solution.

Bonus gold
We have to add bonus gold depending on killer's stats (for example the unit has item or ability adding +50 % gold from creeps), and thus on a map there is simply a heap of creeps, each of them can drop completely different quantity of gold. There is a function creating texttag, it takes how much gold we add. Let's assume two variants, in the first 1 <=minGold <=maxGold <80000000, in the second 1 <=minGold <=MaxGold <=75

Adding item
We have a map containing 60 types of custom heroes. When hero achieves level 25 there pops a specific artifact at its feet.

Private unit data

It is necessary to memorize for ingame units how many ennemies and heroes they killed, and also on which side they battle (for example light or darkness). Presumably the unit cannot kill more 2000 units, cannot kill more than 500 heroes, and is either good or evil. There is presumably a lot of recipient units. The main condition of a problem - we cannot use cache nor variables nor arrays (only local scope).

Solution of problems

Solution of problems



Bonus gold

Collapse JASS:
globals
 real array goldMin
 real array goldMax
 // Two arrays in which and
 // The information on gold will be stored
endglobals

function Init takes nothing returns nothing
 set goldMin[0x00]=1
 set goldMin[0x01]=25
 set goldMin[0x02]=12
 set goldMin[0x03]=85
 set goldMin[0x04]=10
 set goldMin[...n]=n

 set goldMax[0x00]=5
 set goldMax[0x01]=28
 set goldMax[0x02]=15
 set goldMax[0x03]=285
 set goldMax[0x04]=12
 set goldMax[...n]=n
endfunction

Now, the part of a file is designated as 0x00, meaning 0x75303030-0x75303030 (i.e. ' u000 '-'u000 '), 0x01 == 0x7530303 1 -0x75303030 (' u001 '-'u000 ')

It's quite a simple variant, the only thing that is necessary to keep in mind is that rawcodes have to be close to each other: <raw code>-0x75303030 < 8190 (maximum size of a array, 0x75303030 in our case)

Now, for the implementation:

Collapse JASS:
 function AddGlod takes real x, real y, player p, integer gold returns nothing

 ...

 local integer i=GetUnitTypeId(GetDyingUnit())
 call AddGold(<x>, <y>, <player>, GetRandomInt(goldMin[i-0x75303030], goldMax[i-0x75303030])*<factor>)

I think it rather convenient and simple to compare to the majority of objects or of properties. And now we shall try to use rawcode itself for carrying information in it:

Code:
  0000 0000 0000 0000 0000 0000 0000 0000
  ---- ---- xaaa aaaa xbbb bbbb ---- ----

a - min gold, b - max.

Collapse JASS:
 function AddGlod takes real x, real y, player p, integer gold returns nothing

 ...
 local integer i=GetUnitTypeId(GetDyingUnit())
 call AddGold(<x>, <y>, <player>, GetRandomInt(i*0x00000100/0x01000000-0x00000030, i*0x00010000/0x01000000-0x00000030)*<factor>

For a unit 'h1<0' it will give from 1 to 12, and for 'u\{1' - from 44 to 75 gold. In rawcode we can freely use chars from 0x30 to 0x7b, I think it is a simple enough and elegant decision;)

Adding item

Collapse JASS:
 ...
 call CreateItem(GetUnitTypeId(<hero>)+0x01000000, GetUnitX(<hero>), GetUnitY(<hero>))
 ...

Too simple? Yes, it will work be even for a pair of hundreds heroes, single condition is that item's rawcode must be more hero's rawcode by 0x01000000, i.e. for the hero 'H000' the item 'I000', for 'H005' - 'I005' will be created. But it's quite a work to make them fit, I'd say.

Private unit data

Now, as you might have guessed we shall try to keep in unit's UserData three values at once:

Code:
  0000 0000 0000 0000 0000 0000 0000 0000
  -AAA AAAA AAAA -BBB BBBB BB-C ---- ----

A - creeps counter, value from 0 to 2047, B - hero counter, from 0 to 511, and C - bool is this unit holy (1==holy, 0==evil)

Collapse JASS:
//increases creeps counter on 1
function IncCC takes unit u returns nothing
 call SetUnitUserData(u, GetUnitUserData(u)+0x00100000)
endfunction

//how many creeps this unit has killed
function GetCC takes unit u returns integer
 return GetUnitUserData(u)/0x00100000
endfunction

//increases hero counter on 1
function IncHC takes unit u returns nothing
 call SetUnitUserData(u, GetUnitUserData(u)+0x00000400)
endfunction

//how many heroes this unit has killed
function GetHC takes unit u returns integer
 return GetUnitUserData(u)*0x00001000/0x00400000
endfunction

function MakeUnitEvil takes unit u returns nothing
 local integer i=GetUnitUserData(u)
 if i*0x00400000/0x40000000==0x01then
  call SetUnitUserData(u, i-0x00000100)
 endif
endfunction

function MakeUnitHoly takes unit u returns nothing
 local integer i=GetUnitUserData(u)
 if i*0x00400000/0x40000000==0x00then
  call SetUnitUserData(u, i+0x00000100)
 endif
endfunction

function GetUnitPropensity takes unit u returns nothing
 return GetUnitUserData(u)*0x00400000/0x40000000
endfunction

Well, like everything genial it is simple xD. Also I shall add that in units UserData it is possible to place two structures and two boolean:

Code:
  0000 0000 0000 0000 0000 0000 0000 0000
  -AAA AAAA AAAA AA-B BBBB BBBB BBBB -C-D

Well I think that's all, maybe given examples are a little bit banal, but I hope they helped you to understand the idea.

Attached Images
File Type: gif asciitable.GIF (31.1 KB, 791 views)
__________________

Last edited by ADOLF : 05-03-2009 at 09:33 PM.
ADOLF is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-15-2008, 05:20 PM   #2
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

We're going to need the English version before approving it.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-15-2008, 09:43 PM   #3
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

xD
Quote:
Decision of tasks
solving or something...

but yes Vex is right... i also have problems to read software translated text =)

+ it's kind a math lesson.
__________________
Toadcop is offline   Reply With Quote
Old 04-16-2008, 12:35 PM   #4
ADOLF
User from USSR
 
Join Date: Jan 2007
Posts: 127

Submissions (3)

ADOLF will become famous soon enough (36)ADOLF will become famous soon enough (36)

Send a message via ICQ to ADOLF
Default

Quote:
English version
with it at me bad (i think you already it have noticed) =/

ok, i shall try to ask familiar who can help with translation
+
If who that will want to help with translation - write to me... i shall be grateful)
__________________
ADOLF is offline   Reply With Quote
Old 04-16-2008, 10:46 PM   #5
Toadcop
BuranX
 
Toadcop's Avatar
 
Join Date: Jul 2006
Posts: 1,886

Submissions (4)

Toadcop is just really nice (299)Toadcop is just really nice (299)

Approved Map: TcXSpell Making Session 10 Winner

Send a message via ICQ to Toadcop
Default

Quote:
If who that will want to help with translation - write to me... i shall be grateful)
you will send him 100$ ? :P
// search better at Russ forums for help ;)
__________________
Toadcop is offline   Reply With Quote
Old 05-05-2008, 06:09 PM   #6
ADOLF
User from USSR
 
Join Date: Jan 2007
Posts: 127

Submissions (3)

ADOLF will become famous soon enough (36)ADOLF will become famous soon enough (36)

Send a message via ICQ to ADOLF
Default

translation is updated - thank to ArchWorm)
how now?)
__________________
ADOLF is offline   Reply With Quote
Old 05-08-2008, 06:03 AM   #7
PurgeandFire111
User
 
PurgeandFire111's Avatar
 
Join Date: Dec 2006
Posts: 253

PurgeandFire111 will become famous soon enough (58)PurgeandFire111 will become famous soon enough (58)

Default

I find this tutorial helpful, and I understand it. :) I am still a little confused on some areas, but I mainly read the tutorial fast. :P

Good job, +rep. I hope I'll find some uses of this. ;)
PurgeandFire111 is offline   Reply With Quote
Old 05-08-2008, 09:18 AM   #8
PitzerMike
Alcopops
 
PitzerMike's Avatar


Tools & Tutorials Moderator
 
Join Date: Jan 2003
Posts: 2,794

Submissions (12)

PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)

Approved Map: Pitzer's Minesweeper

Default

Yes, I approve.
__________________
Zoom (requires log in)
PitzerMike is offline   Reply With Quote
Old 05-08-2008, 11:51 AM   #9
ADOLF
User from USSR
 
Join Date: Jan 2007
Posts: 127

Submissions (3)

ADOLF will become famous soon enough (36)ADOLF will become famous soon enough (36)

Send a message via ICQ to ADOLF
Default

yes, thanks
but imho this tutorial about jass... hmm
misk: "Contains tutorials that do not fit into one of the above catagories" though it to solve to you)
__________________
ADOLF is offline   Reply With Quote
Old 05-08-2008, 03:52 PM   #10
ArchWorm
User
 
ArchWorm's Avatar
 
Join Date: May 2006
Posts: 249

ArchWorm is on a distinguished road (14)

Send a message via ICQ to ArchWorm
Default

The text still seems somewhat awkward to me. Let's hope it's but my self-criticism. Seeing it approved quite proves it.

But tell me, have you understood anything around the problems? I hardly could make them readable so I fear they are good for nothing.
__________________
Nuclear Arbitor: this is ur map so if u don't like what ppl say ignore them and make it any way. they'll laugh in ur face and tell u it still sucks afterwards if they don't like it but they're not making it.
ArchWorm is offline   Reply With Quote
Old 01-09-2009, 03:15 PM   #11
Furby
User
 
Furby's Avatar
 
Join Date: Oct 2008
Posts: 26

Submissions (1)

Furby has little to show at this moment (7)

Send a message via ICQ to Furby Send a message via AIM to Furby Send a message via MSN to Furby
Default

local integer 0x0f // 15 in dec ? I think it should be local integer i=0x0f // 15 in dec
__________________
Living in the fantasy, that would be a life.
Furby is offline   Reply With Quote
Old 03-03-2009, 05:34 AM   #12
cosmicat
Probably AFK
 
cosmicat's Avatar
 
Join Date: Feb 2009
Posts: 635

cosmicat will become famous soon enough (71)cosmicat will become famous soon enough (71)cosmicat will become famous soon enough (71)

Default

8-symbol number systems are octal, not "octimal". Very helpful guide, though.

Dec(25) = Oct(31)

Last edited by cosmicat : 03-03-2009 at 05:37 AM.
cosmicat is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 03:23 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2018, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services