converting from item_kinds decimal to individual flags?

Users who are viewing this thread

kefka95

Squire
Does anyone know how to convert from the compiled item_kinds decimal representation of flags to the individual flags themselves?  I know how to come up with the decimal number given the flags (ie, by adding the hex values of the constants), but I don't know how to do it the other way around.

For example, I know that 4194309 represents itp_type_arrows + itp_primary.  If I were given the 4194309 without any foreknowledge of what flags that represented, how would I figure out that that number breaks down to itp_type_arrows + itp_primary?  The game can obviously do it, and other editors can as well, but I'm too slow to figure it out myself.  I'm sure there's some "mathy" way of doing it, but that's not exactly my strong suit :mrgreen:.

Any help would be appreciated!
 
It's pretty straight-forward. Looking at header_items.py reveals that itp_type_arrows is given as a hex value of 0x0000000000000005. Itp_primary is given as a hex value of 0x0000000000400000. Converting these values to decimal (f.ex. using this site) gives us values 5 and 4194304. Using bitwise calculation (here) we get 5 (bitwise or) 4194304 = 4194309.
 
Harmast said:
It's pretty straight-forward. Looking at header_items.py reveals that itp_type_arrows is given as a hex value of 0x0000000000000005. Itp_primary is given as a hex value of 0x0000000000400000. Converting these values to decimal (f.ex. using this site) gives us values 5 and 4194304. Using bitwise calculation (here) we get 5 (bitwise or) 4194304 = 4194309.

I understand how to do that part of the conversion, but I don't know how to do the reverse.  Again, this is assuming that we have no idea what the flags are ahead of time.  Let's say there's a decimal that represents 4 or 5 different flags.  Surely there's a better way than just going through every single possible combination of constants until you randomly come across the right number?
 
Ah, right. As you say, it's not so easy, especially with multiple flags. Trying different combinations is the only way. I suppose it wouldn't be too much of a hassle to code a small tool to come up with the combination, given the values from item_header.py.
 
Unless I'm totally getting the wrong idea, I don't see why it would be difficult - simply convert the decimal value 4194309 to hex, and you get 0x0000400005, which breaks down to 0x0000400000 and 0x0000000005, which you simply need to then look up. You have to know the context though, to get the right flags, since ISTR they are recycled by context.
 
Convert it to binary. The least significant byte will determine the weapon type, ie. one-handed, polearm, two-handed, etc.
The nibble after that will be the force_left_hand/right_hand_armature. The flags afterward are all set bitwise, so in order relative to the beginning of the third nibble:

itp_cant_reload_on_horseback: bit 1
itp_two_handed: bit 2
itp_primary: bit 3
itp_secondary: bit 4
itp_covers_legs: bit 5
itp_doesnt_cover_hair: bit 6
itp_can_penetrate_shield: bit 7
itp_consumable: bit 8
itp_bonus_against_shield: bit 9
itp_penalty_with_shield: bit 10
itp_cant_use_on_horseback: bit 11
itp_civilian : bit 12
itp_next_item_as_melee: bit 13
itp_fit_to_head: bit 14
itp_offset_lance : bit 15
itp_covers_head: bit 16
itp_couchable: bit 17
itp_crush_through: bit 18
#itp_knock_back: bit 19
itp_remove_item_on_use: bit 20
itp_unbalanced: bit 21

itp_covers_beard: bit 22
itp_no_pick_up_from_ground : bit 23
itp_can_knock_down: bit  24
itp_extra_penetration: bit 25
itp_has_bayonet: bit 26
itp_cant_reload_while_moving : bit 27
itp_ignore_gravity : bit 28
itp_ignore_friction: bit 29
 
sirinan said:
Unless I'm totally getting the wrong idea, I don't see why it would be difficult - simply convert the decimal value 4194309 to hex, and you get 0x0000400005, which breaks down to 0x0000400000 and 0x0000000005, which you simply need to then look up. You have to know the context though, to get the right flags, since ISTR they are recycled by context.

This only works if you know which two flags are involved ahead of time (in which case there's no reason to do the conversion, since you would already know).  Think of a decimal that encompasses, say, 7 different flags.  Assuming you have no idea which 7 flags are contained in that decimal, the question is how would you figure out which flags are involved short of trying every single possible combination of numbers?

MadocComadrin said:
Convert it to binary. The least significant byte will determine the weapon type, ie. one-handed, polearm, two-handed, etc.
The nibble after that will be the force_left_hand/right_hand_armature. The flags afterward are all set bitwise, so in order relative to the beginning of the third nibble:

itp_cant_reload_on_horseback: bit 1
itp_two_handed: bit 2
itp_primary: bit 3
itp_secondary: bit 4
itp_covers_legs: bit 5
itp_doesnt_cover_hair: bit 6
itp_can_penetrate_shield: bit 7
itp_consumable: bit 8
itp_bonus_against_shield: bit 9
itp_penalty_with_shield: bit 10
itp_cant_use_on_horseback: bit 11
itp_civilian : bit 12
itp_next_item_as_melee: bit 13
itp_fit_to_head: bit 14
itp_offset_lance : bit 15
itp_covers_head: bit 16
itp_couchable: bit 17
itp_crush_through: bit 18
#itp_knock_back: bit 19
itp_remove_item_on_use: bit 20
itp_unbalanced: bit 21

itp_covers_beard: bit 22
itp_no_pick_up_from_ground : bit 23
itp_can_knock_down: bit  24
itp_extra_penetration: bit 25
itp_has_bayonet: bit 26
itp_cant_reload_while_moving : bit 27
itp_ignore_gravity : bit 28
itp_ignore_friction: bit 29

Thanks Madoc, I think this is what I was looking for.
 
Back
Top Bottom