WB Coding How to export item type via python/process_item.py ?

Pitch

Sergeant at Arms
WBNWVCM&BWF&S
Best answers
4
Hello.
I'm looking for a way, how to export item type via python/process_item.py.

I am aware how to export item stats, name or price. however, I don't know how to find item type.

My modified function "write_items" in process_items.py looks like this:

Python:
def write_items(variable_list,variable_uses,tag_uses,quick_strings):
  mycursor = mydb.cursor()
  mycursor.execute("TRUNCATE TABLE items")
  itemkinds_file_name = export_dir + "item_kinds1.txt"
  ofile = open(itemkinds_file_name,"w")
  ofile.write("itemsfile version 3\n")
  ofile.write("%d\n"%len(items))
  for item in items:
    if (item[3] & itp_merchandise) > 0:
      id_no = find_object(items,convert_to_identifier(item[0]))
      add_tag_use(tag_uses,tag_item,id_no)
    ofile.write(" itm_%s %s %s %d "%(convert_to_identifier(item[0]),replace_spaces(item[1]),replace_spaces(item[1]),len(item[2])))
    item_variations = item[2]
    for item_variation in item_variations:
      mycursor = mydb.cursor()
 
      sql = "INSERT INTO items (name, weight, full_name, price) VALUES (%s, %s, %s, %s)"

      val = (item[0], get_weight(item[6]), item[1],  item[5])

      print(item[0], item[1], item[2], item[3], item[4], item[5], item[6])
      mycursor.execute(sql, val)
      mydb.commit()
 

    
      ofile.write(" %s %d "%(item_variation[0],item_variation[1]))
    ofile.write(" %d %d %d %d %f %d %d %d %d %d %d %d %d %d %d %d %d\n"%(item[3], item[4], item[5], item[7],
                                                   get_weight(item[6]),
                                                   get_abundance(item[6]),                 
                                                   get_head_armor(item[6]),
                                                   get_body_armor(item[6]),
                                                   get_leg_armor(item[6]),
                                                   get_difficulty(item[6]),
                                                   get_hit_points(item[6]),
                                                   get_speed_rating(item[6]),
                                                   get_missile_speed(item[6]),
                                                   get_weapon_length(item[6]),
                                                   get_max_ammo(item[6]),
                                                   get_thrust_damage(item[6]),
                                                   get_swing_damage(item[6]),
                                                               ))
    if (len(item) > 9):
      ofile.write(" %d\n"%(len(item[9])))
      for item_faction in item[9]:
        ofile.write(" %d"%item_faction)
      ofile.write("\n")
    else:
      ofile.write(" 0\n")
    trigger_list = []
    if (len(item) > 8):
      trigger_list = item[8]
    save_simple_triggers(ofile,trigger_list, variable_list,variable_uses,tag_uses,quick_strings)


  ofile.close()

So, question is - How to print/get item type?
 

kalarhan

Python Saint
Count
WBNWVCWF&S
Best answers
22
you need to work with the binary masks to extract the values, like

Code:
def head_armor(x):
  return (((bignum | x) & ibf_armor_mask) << ibf_head_armor_bits)
^ header_items.py

if you are unsure about how binary math works with Python you can check https://wiki.python.org/moin/BitManipulation

note how the masks for each type have different quantity of leading zeros, that way you can combine multiple values inside one value and extract them later

itp_type_polearm| itp_offset_lance|itp_primary|itp_no_blur|itp_wooden_parry
something like 0xAAAABBCCCDDDDDEEFF where AAAA, BB, ... FF represent different flags.
 

Pitch

Sergeant at Arms
WBNWVCM&BWF&S
Best answers
4
I don't really have deep knowledge in python. I rarely use it.

I can slight understand how it works

Python:
 ibf_head_armor_bits      = 0
ibf_armor_mask           = 0x00000000000000000000000ff

def get_head_armor(y):
   return (y >> ibf_head_armor_bits) & ibf_armor_mask

y = 134217744
#["blue_tourney_helmet","Blue Tourney Helmet",[("segmented_helm",0)],itp_type_head_armor,0,126, weight(2)|head_armor(16),imodbits_none],

print(get_head_armor(y))
# returns 16

But still, I don't know how to utilize these flags

Python:
#item flags
itp_type_horse           = 0x0000000000000001
itp_type_one_handed_wpn  = 0x0000000000000002
itp_type_two_handed_wpn  = 0x0000000000000003
itp_type_polearm         = 0x0000000000000004
itp_type_arrows          = 0x0000000000000005
itp_type_bolts           = 0x0000000000000006
itp_type_shield          = 0x0000000000000007
itp_type_bow             = 0x0000000000000008
itp_type_crossbow        = 0x0000000000000009
itp_type_thrown          = 0x000000000000000a
itp_type_goods           = 0x000000000000000b
itp_type_head_armor      = 0x000000000000000c
itp_type_body_armor      = 0x000000000000000d
itp_type_foot_armor      = 0x000000000000000e
itp_type_hand_armor      = 0x000000000000000f
itp_type_pistol          = 0x0000000000000010
itp_type_musket          = 0x0000000000000011
itp_type_bullets         = 0x0000000000000012
itp_type_animal          = 0x0000000000000013
itp_type_book            = 0x0000000000000014
What do you think, maybe directly processing module_items.py would be easier?

I would like to extract item name, code name of item, price, item type and maybe statistics.



EDIT:

What I did to solve my problem without going deep into the language, is doing something ugly (but works!).

Python:
itp_type_horse           = -1
itp_type_one_handed_wpn  = -2
itp_type_two_handed_wpn  = -3
itp_type_polearm = -4
itp_type_arrows          = -5
itp_type_bolts           = -6
itp_type_shield          = -7
itp_type_bow             = -8
itp_type_crossbow        = -9
itp_type_thrown          = -10
itp_type_goods           = -11
itp_type_head_armor      = -12
itp_type_body_armor      = -13
itp_type_foot_armor      = -14
itp_type_hand_armor      = -15
itp_type_pistol          = -16
itp_type_musket          = -17
itp_type_bullets         = -18
itp_type_animal          = -19
itp_type_book            = -20

for item in items:

      mycursor = mydb.cursor()




     

      if item[3] == -1:

        item[3] = 'itp_type_horse'

      if item[3] == -2:

        item[3] = 'itp_type_one_handed_wpn'

      if item[3] == -3:

        item[3] = 'itp_type_two_handed_wpn'

      if item[3] == -4:

        item[3] = 'itp_type_polearm'

      if item[3] == -5:

        item[3] = 'itp_type_arrows'

      if item[3] == -6:

        item[3] = 'itp_type_bolts'

      if item[3] == -7:

        item[3] = 'itp_type_shield'

      if item[3] == -8:

        item[3] = 'itp_type_bow'

      if item[3] == -9:

        item[3] = 'itp_type_crossbow'

      if item[3] == -10:

        item[3] = 'itp_type_thrown'

      if item[3] == -11:

        item[3] = 'itp_type_goods'

      if item[3] == -12:

        item[3] = 'itp_type_head_armor'

      if item[3] == -13:

        item[3] = 'itp_type_body_armor'

      if item[3] == -14:

        item[3] = 'itp_type_foot_armor'

      if item[3] == -15:

        item[3] = 'itp_type_hand_armor'

      if item[3] == -16:

        item[3] = 'itp_type_pistol'

      if item[3] == -17:

        item[3] = 'itp_type_musket'

      if item[3] == -18:

        item[3] = 'itp_type_bullets'

      if item[3] == -19:

        item[3] = 'itp_type_animal'

      if item[3] == -20:

        item[3] = 'itp_type_book'

   

      sql = "INSERT INTO items (name, type, full_name, price, body_armor) VALUES (%s, %s, %s, %s, %s)"



      val = (item[0], item[3], item[1],  item[5], get_body_armor(item[6]))

      mycursor.execute(sql, val)

      mydb.commit()
 
Last edited: