add_item = deepcopy(orig_items)
for i in reversed(range(1,len(orig_items))):
itm_flags = add_item[i][3]
type = itm_flags & 0x000000ff
dmg = get_thrust_damage(add_item[i][6]) % 256
dmg_type = get_thrust_damage(add_item[i][6]) / 256
if type == itp_type_polearm and itm_flags & itp_couchable == 0 and dmg > 2 and dmg_type == pierce and itm_flags & itp_next_item_as_melee == 0 and add_item[i-1][3] & itp_next_item_as_melee == 0 :
#Above checks that it is a polearm with piercing thrust damage that isn't already involved in a 'X' toggled alt-weapon
orig_items[i][3] = orig_items[i][3] | itp_next_item_as_melee #flag native item as changeable
add_item[i][0] = add_item[i][0]+'_alt' #add *_alt to the new item's name
itm_flags = itm_flags & ~itp_merchandise #disallow from merch list
itm_flags = itm_flags | itp_crush_through #add crush-through a la WFaS
if (get_swing_damage(add_item[i][6]) % 256 > 0): #if weapon wasn't already thrust-only
speed = get_speed_rating(add_item[i][6])
add_item[i][6] = add_item[i][6] & ~(ibf_armor_mask << iwf_speed_rating_bits) #clear speed
speed +=5 #boost speed by 5
add_item[i][6] = add_item[i][6] | spd_rtng(speed) #write increased speed
if itm_flags & itp_two_handed == 0:
add_item[i][4] = add_item[i][4] | itcf_thrust_onehanded #so that the polearms use 'bent elbow' with shields
add_item[i][4] = add_item[i][4] | itcf_thrust_twohanded #overhead thrust
add_item[i][6] = add_item[i][6] & ~(ibf_damage_mask << iwf_thrust_damage_bits) #erase damage
dmg -= 2 #reduce damage by 2
add_item[i][6] = add_item[i][6] | thrust_damage(dmg, pierce) #write reduced damage
orig_items.insert(i+1, add_item[i]) #add right after the native item, so it can be switched to