import re
# Setup vars below (please adjust, if necessary)
# ==============================================
# File paths
txt_file_path = './item_kinds1.txt'
csv_file_path = './item_kinds1.csv'
bbc_file_path = './item_kinds1.bbc'
# Patterns
pattern_line = 'itm\S+'
# BBC headers
header_horse = "[spoiler=Horses]\n"
footer_horse = "[/spoiler]\n"
header_one = "[spoiler=One Handed]\n"
footer_one = "[/spoiler]\n"
header_two = "[spoiler=Two Handed]\n"
footer_two = "[/spoiler]\n"
header_polearm = "[spoiler=Polearms]\n"
footer_polearm = "[/spoiler]\n"
header_bow = "[spoiler=Bows]\n"
footer_bow = "[/spoiler]\n"
header_xbow = "[spoiler=Xbows]\n"
footer_xbow = "[/spoiler]\n"
header_arrow = "[spoiler=Arrows]\n"
footer_arrow = "[/spoiler]\n"
header_bolt = "[spoiler=Bolts]\n"
footer_bolt = "[/spoiler]\n"
header_throwing = "[spoiler=Throwing Weapons]\n"
footer_throwing = "[/spoiler]\n"
header_shield = "[spoiler=Shields]\n"
footer_shield = "[/spoiler]\n"
header_hand = "[spoiler=Hand Armour]\n"
footer_hand = "[/spoiler]\n"
header_foot = "[spoiler=Foot Armour]\n"
footer_foot = "[/spoiler]\n"
header_head = "[spoiler=Head Armour]\n"
footer_head = "[/spoiler]\n"
header_body = "[spoiler=Body Armour]\n"
footer_body = "[/spoiler]\n"
# Module system script vars below (please don't modify)
# =====================================================
# 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
##itp_attach_left_item = 0x000000100
##itp_attach_left_hand = 0x000000200
##itp_attach_forearm = 0x000000300
##itp_attach_armature = 0x000000f00
itp_force_attach_left_hand = 0x0000000000000100
itp_force_attach_right_hand = 0x0000000000000200
itp_force_attach_left_forearm = 0x0000000000000300
itp_attach_armature = 0x0000000000000f00
itp_attachment_mask = 0x0000000000000f00
itp_unique = 0x0000000000001000
itp_always_loot = 0x0000000000002000
##itp_melee = 0x000002000
itp_no_parry = 0x0000000000004000
##itp_spear = 0x000008000 #obsolete
itp_default_ammo = 0x0000000000008000
itp_merchandise = 0x0000000000010000
itp_wooden_attack = 0x0000000000020000
itp_wooden_parry = 0x0000000000040000
itp_food = 0x0000000000080000
#itp_bow = 0x0000000000000010
#itp_shield = 0x0000000000000020
#itp_javelin = 0x0000000000000040
#itp_crossbow = 0x0000000000000080
itp_cant_reload_on_horseback = 0x0000000000100000
itp_two_handed = 0x0000000000200000
itp_primary = 0x0000000000400000
itp_secondary = 0x0000000000800000
itp_covers_legs = 0x0000000001000000
itp_doesnt_cover_hair = 0x0000000001000000
itp_can_penetrate_shield = 0x0000000001000000
itp_consumable = 0x0000000002000000
itp_bonus_against_shield = 0x0000000004000000
itp_penalty_with_shield = 0x0000000008000000
itp_cant_use_on_horseback = 0x0000000010000000
itp_civilian = 0x0000000020000000
itp_next_item_as_melee = 0x0000000020000000
itp_fit_to_head = 0x0000000040000000
itp_offset_lance = 0x0000000040000000
itp_covers_head = 0x0000000080000000
itp_couchable = 0x0000000080000000
itp_crush_through = 0x0000000100000000
#itp_knock_back = 0x0000000200000000 being used?
itp_remove_item_on_use = 0x0000000400000000
itp_unbalanced = 0x0000000800000000
itp_covers_beard = 0x0000001000000000 #remove beard mesh
itp_no_pick_up_from_ground = 0x0000002000000000
itp_can_knock_down = 0x0000004000000000
itp_extra_penetration = 0x0000100000000000
itp_has_bayonet = 0x0000200000000000
itp_cant_reload_while_moving = 0x0000400000000000
itp_ignore_gravity = 0x0000800000000000
itp_ignore_friction = 0x0001000000000000
# Item capabilities
itcf_thrust_onehanded = 0x0000000000000001
itcf_overswing_onehanded = 0x0000000000000002
itcf_slashright_onehanded = 0x0000000000000004
itcf_slashleft_onehanded = 0x0000000000000008
itcf_thrust_twohanded = 0x0000000000000010
itcf_overswing_twohanded = 0x0000000000000020
itcf_slashright_twohanded = 0x0000000000000040
itcf_slashleft_twohanded = 0x0000000000000080
itcf_thrust_polearm = 0x0000000000000100
itcf_overswing_polearm = 0x0000000000000200
itcf_slashright_polearm = 0x0000000000000400
itcf_slashleft_polearm = 0x0000000000000800
itcf_shoot_bow = 0x0000000000001000
itcf_shoot_javelin = 0x0000000000002000
itcf_shoot_crossbow = 0x0000000000004000
itcf_throw_stone = 0x0000000000010000
itcf_throw_knife = 0x0000000000020000
itcf_throw_axe = 0x0000000000030000
itcf_throw_javelin = 0x0000000000040000
itcf_shoot_pistol = 0x0000000000070000
itcf_shoot_musket = 0x0000000000080000
itcf_shoot_mask = 0x00000000000ff000
itcf_horseback_thrust_onehanded = 0x0000000000100000
itcf_horseback_overswing_right_onehanded = 0x0000000000200000
itcf_horseback_overswing_left_onehanded = 0x0000000000400000
itcf_horseback_slashright_onehanded = 0x0000000000800000
itcf_horseback_slashleft_onehanded = 0x0000000001000000
itcf_thrust_onehanded_lance = 0x0000000004000000
itcf_thrust_onehanded_lance_horseback = 0x0000000008000000
itcf_carry_mask = 0x00000007f0000000
itcf_carry_sword_left_hip = 0x0000000010000000
itcf_carry_axe_left_hip = 0x0000000020000000
itcf_carry_dagger_front_left = 0x0000000030000000
itcf_carry_dagger_front_right = 0x0000000040000000
itcf_carry_quiver_front_right = 0x0000000050000000
itcf_carry_quiver_back_right = 0x0000000060000000
itcf_carry_quiver_right_vertical = 0x0000000070000000
itcf_carry_quiver_back = 0x0000000080000000
itcf_carry_revolver_right = 0x0000000090000000
itcf_carry_pistol_front_left = 0x00000000a0000000
itcf_carry_bowcase_left = 0x00000000b0000000
itcf_carry_mace_left_hip = 0x00000000c0000000
itcf_carry_axe_back = 0x0000000100000000
itcf_carry_sword_back = 0x0000000110000000
itcf_carry_kite_shield = 0x0000000120000000
itcf_carry_round_shield = 0x0000000130000000
itcf_carry_buckler_left = 0x0000000140000000
itcf_carry_crossbow_back = 0x0000000150000000
itcf_carry_bow_back = 0x0000000160000000
itcf_carry_spear = 0x0000000170000000
itcf_carry_board_shield = 0x0000000180000000
itcf_carry_katana = 0x0000000210000000
itcf_carry_wakizashi = 0x0000000220000000
itcf_show_holster_when_drawn = 0x0000000800000000
itcf_reload_pistol = 0x0000007000000000
itcf_reload_musket = 0x0000008000000000
itcf_reload_mask = 0x000000f000000000
itcf_parry_forward_onehanded = 0x0000010000000000
itcf_parry_up_onehanded = 0x0000020000000000
itcf_parry_right_onehanded = 0x0000040000000000
itcf_parry_left_onehanded = 0x0000080000000000
itcf_parry_forward_twohanded = 0x0000100000000000
itcf_parry_up_twohanded = 0x0000200000000000
itcf_parry_right_twohanded = 0x0000400000000000
itcf_parry_left_twohanded = 0x0000800000000000
itcf_parry_forward_polearm = 0x0001000000000000
itcf_parry_up_polearm = 0x0002000000000000
itcf_parry_right_polearm = 0x0004000000000000
itcf_parry_left_polearm = 0x0008000000000000
itcf_horseback_slash_polearm = 0x0010000000000000
itcf_force_64_bits = 0x8000000000000000
# Combined capabilities
itc_cleaver = itcf_force_64_bits | (itcf_overswing_onehanded|itcf_slashright_onehanded|itcf_slashleft_onehanded |
itcf_horseback_slashright_onehanded|itcf_horseback_slashleft_onehanded)
itc_dagger = itc_cleaver | itcf_thrust_onehanded
itc_parry_onehanded = itcf_force_64_bits | itcf_parry_forward_onehanded| itcf_parry_up_onehanded | itcf_parry_right_onehanded |itcf_parry_left_onehanded
itc_longsword = itc_dagger | itc_parry_onehanded
itc_scimitar = itc_cleaver | itc_parry_onehanded
itc_parry_two_handed = itcf_force_64_bits | itcf_parry_forward_twohanded | itcf_parry_up_twohanded | itcf_parry_right_twohanded | itcf_parry_left_twohanded
itc_cut_two_handed = itcf_force_64_bits | (itcf_slashright_twohanded | itcf_slashleft_twohanded | itcf_overswing_twohanded |
itcf_horseback_slashright_onehanded|itcf_horseback_slashleft_onehanded)
itc_greatsword = itc_cut_two_handed | itcf_thrust_twohanded | itc_parry_two_handed |itcf_thrust_onehanded_lance
itc_nodachi = itc_cut_two_handed | itc_parry_two_handed
itc_bastardsword = itc_cut_two_handed | itcf_thrust_twohanded | itc_parry_two_handed |itc_dagger
itc_morningstar = itc_cut_two_handed | itc_parry_two_handed |itc_cleaver
itc_parry_polearm = itcf_parry_forward_polearm | itcf_parry_up_polearm | itcf_parry_right_polearm | itcf_parry_left_polearm
itc_poleaxe = itc_parry_polearm| itcf_overswing_polearm |itcf_thrust_polearm|itcf_slashright_polearm|itcf_slashleft_polearm
itc_staff = itc_parry_polearm| itcf_thrust_onehanded_lance |itcf_thrust_onehanded_lance_horseback| itcf_overswing_polearm |itcf_thrust_polearm|itcf_slashright_polearm|itcf_slashleft_polearm
itc_spear = itc_parry_polearm| itcf_thrust_onehanded_lance |itcf_thrust_onehanded_lance_horseback | itcf_thrust_polearm
itc_cutting_spear = itc_spear|itcf_overswing_polearm
itc_pike = itcf_thrust_onehanded_lance |itcf_thrust_onehanded_lance_horseback | itcf_thrust_polearm
itc_guandao = itc_parry_polearm|itcf_overswing_polearm|itcf_thrust_polearm|itcf_slashright_polearm|itcf_slashleft_polearm|itcf_horseback_slashright_onehanded|itcf_horseback_slashleft_onehanded|itcf_horseback_slash_polearm
itc_greatlance = itcf_thrust_onehanded_lance |itcf_thrust_onehanded_lance_horseback| itcf_thrust_polearm
# Start processing items
# ======================
txt_file = open(txt_file_path, 'r')
csv_file = open(csv_file_path, 'w')
bbc_file = open(bbc_file_path, 'w')
items = { 'horse': [], 'one': [], 'two': [], 'polearm': [], 'arrow': [], 'bolt': [] , 'shield': [], 'bow': [], 'xbow': [], 'throwing': [], 'head': [], 'body': [], 'foot': [], 'hand': []}
for line in txt_file:
# Check if it's an item line at all
if not re.match(' itm_*', line):
continue
# Split up the line at the spaces
words = line.split()
# Check if the flags field is at pos 6, otherwise skip this item
if words[6].isdigit():
flags = long(words[6])
else:
continue
# Create an item as dictionary
item = {}
item['name'] = words[1].replace('_', ' ')
# Check item type and add to dictionary
if flags & itp_type_book == itp_type_book:
continue
elif flags & itp_type_animal == itp_type_animal:
continue
elif flags & itp_type_bullets == itp_type_bullets:
continue
elif flags & itp_type_musket == itp_type_musket:
continue
elif flags & itp_type_pistol == itp_type_pistol:
continue
elif flags & itp_type_hand_armor == itp_type_hand_armor:
item['type'] = 'hand'
elif flags & itp_type_foot_armor == itp_type_foot_armor:
item['type'] = 'foot'
elif flags & itp_type_body_armor == itp_type_body_armor:
item['type'] = 'body'
elif flags & itp_type_head_armor == itp_type_head_armor:
item['type'] = 'head'
elif flags & itp_type_goods == itp_type_goods:
continue
elif flags & itp_type_thrown == itp_type_thrown:
item['type'] = 'throwing'
elif flags & itp_type_crossbow == itp_type_crossbow:
item['type'] = 'xbow'
elif flags & itp_type_bow == itp_type_bow:
item['type'] = 'bow'
elif flags & itp_type_shield == itp_type_shield:
item['type'] = 'shield'
elif flags & itp_type_bolts == itp_type_bolts:
item['type'] = 'bolt'
elif flags & itp_type_arrows == itp_type_arrows:
item['type'] = 'arrow'
elif flags & itp_type_polearm == itp_type_polearm:
item['type'] = 'polearm'
elif flags & itp_type_two_handed_wpn == itp_type_two_handed_wpn:
item['type'] = 'two'
elif flags & itp_type_one_handed_wpn == itp_type_one_handed_wpn:
item['type'] = 'one'
elif flags & itp_type_horse == itp_type_horse:
item['type'] = 'horse'
else:
continue
# Check item abilities like knockdown etc.
abilities = []
if flags & itp_bonus_against_shield == itp_bonus_against_shield:
abilities.append('Bonus against shields')
if flags & itp_penalty_with_shield == itp_penalty_with_shield:
abilities.append('Penalty with shield')
if flags & itp_cant_use_on_horseback == itp_cant_use_on_horseback:
abilities.append('Can\'t use on horseback')
if (flags & itp_couchable == itp_couchable) and (item['type'] == 'polearm'):
abilities.append('Couchable')
if flags & itp_crush_through == itp_crush_through:
abilities.append('Crushthrough')
if flags & itp_unbalanced == itp_unbalanced:
abilities.append('Unbalanced')
if flags & itp_can_knock_down == itp_can_knock_down:
abilities.append('Knockdown')
# Add abilities to item
item['abilities'] = abilities
# Process capabilites
#TODO capabilities = long(words[7])
# Get fields for regular weapons
if item['type'] in ['one', 'two', 'polearm']:
item['gold'] = words[8]
item['weight'] = str(round(float(words[10]), 1))
item['requirement'] = words[15]
item['speed'] = words[17]
item['length'] = words[19]
swing = int(words[22])
swing_type = 'cut'
if (swing >= 512):
swing -= 512
swing_type = 'blunt'
if (swing >= 256):
swing -= 256
swing_type = 'pierce'
item['swing_dmg'] = str(swing)
item['swing_type'] = swing_type
thrust = int(words[21])
thrust_type = 'cut'
if (thrust >= 512):
thrust -= 512
thrust_type = 'blunt'
if (thrust >= 256):
thrust -= 256
thrust_type = 'pierce'
item['thrust_dmg'] = str(thrust)
item['thrust_type'] = thrust_type
items[item['type']].append(item)
# Write header for one-handed weapons
csv_file.write("type,name,gold,weight,requirement,speed,length,swing_dmg,swing_type,thrust_dmg,thrust_type\n")
for i in items['one']:
# Build complete csv item string
item_string = i['type'] + ',' + i['name'] + ',' + i['gold'] + ',' + i['weight'] + ',' + i['requirement'] + ',' + i['speed'] + ',' + i['length'] + ',' + i['swing_dmg'] + ',' + i['swing_type'] + ',' + i['thrust_dmg'] + ',' + i['thrust_type']
# Write csv item string to file
csv_file.write(item_string + "\n")
#bbc_file.write(len(fields) + "\n")
Place it in cRPG's module folder and run it to produce a .csv and .bbc file with details. It's not complete yet, just posting it so other ppl can contribute (maybe some with more python knowledge and/or more time). Currently, it extracts all data of onehanded weapons and writes them to a csv file.