问题
I'm trying to read PUD file format, that belong to the warcraft 2 game map.
In the explanation of file structure, there is small phrases I don't understand it.
What is this mean (16 longs, 110 words) ?
Here is an example
16 longs -------> Units and buildings allowed. (16 players)
units bit order:
0000000000000000000000000000000x bit0: footman/grunt
000000000000000000000000000000x0 bit1: peasant/peon
00000000000000000000000000000x00 bit2: ballista/catapult
0000000000000000000000000000x000 bit3: knight/ogre
000000000000000000000000000x0000 bit4: archer/axe thrower
00000000000000000000000000x00000 bit5: mage/death knights
0000000000000000000000000x000000 bit6: tanker
000000000000000000000000x0000000 bit7: destroyer
00000000000000000000000x00000000 bit8: transport
0000000000000000000000x000000000 bit9: battleship/juggernault
000000000000000000000x0000000000 bit10: submarine/turtle
00000000000000000000x00000000000 bit11: flying machine/balloon
0000000000000000000x000000000000 bit12: gryphon/dragon
000000000000000000x0000000000000 bit13: unused/unused
00000000000000000x00000000000000 bit14: demo. squad/sapper
0000000000000000x000000000000000 bit15: aviary/roost
000000000000000x0000000000000000 bit16: farm
00000000000000x00000000000000000 bit17: barracks
0000000000000x000000000000000000 bit18: lumber mill
000000000000x0000000000000000000 bit19: stables/mound
00000000000x00000000000000000000 bit20: mage tower/temple
0000000000x000000000000000000000 bit21: foundry
000000000x0000000000000000000000 bit22: refinery
00000000x00000000000000000000000 bit23: inventor/alchemist
0000000x000000000000000000000000 bit24: church/altar storms
000000x0000000000000000000000000 bit25: tower
00000x00000000000000000000000000 bit26: town hall/great hall
0000x000000000000000000000000000 bit27: keep/stronghold
000x0000000000000000000000000000 bit28: castle/fortress
00x00000000000000000000000000000 bit29: blacksmith
0x000000000000000000000000000000 bit30: shipyard
x0000000000000000000000000000000 bit31: unused
Is this mean 16 longs = 16*4Bytes = 64 or 16*32Bits = 512 or other.
Also the same thing with 110 words.
回答1:
They're referring to C types on a particular architecture. In C, long is a type of variable. Its size varies as a function of the compiler, but in this case it's a 32-bit value. Words are processor words, which are typically 32 bits in modern parlance. However, Warcraft 2 was written a long time ago and runs on 16-bit machines. As Sean pointed out in a comment, words are 16 bits in this context.
To answer the question in the comment:
16 longs = 16 * 32 bits = 512 bits = 64 bytes.
110 words = 110 * 16 bits = 1760 bits = 220 bytes.
回答2:
I've never known "16 longs, 110 words" to have any particular meaning other than long being 64 bit numbers, and words being 32 bit data. I would perform some experiments and see what values are contained in the first 16 8-byte chunks and then 110 4-byte chunks to see if values are relatively consistent.
If by looking at the word values, you see one bit on like in your table above, then presumably you're reading it correctly. However, generally speaking, there's no way to know for sure if you're right for these sorts of things, only ways to know if you're wrong.
Edit: Of course, the sizes have changed over the years and "long" may be 4 bytes, not 8. Likewise words would be 2 bytes, not 4.
来源:https://stackoverflow.com/questions/20340106/what-is-the-meaning-of-16-longs-and-110-words-when-reads-the-bits-from-a-fi