This code is intended to provide an easy way for modders to define troops with guaranteed polearms. It borrows an existing flag and slot, but if for whatever reason you want troops that can't be arsed to move because they have too much wood feel free to use another flag that isn't already used by the engine. What you actually do with the slot is up to you - there are a number of OSP scripts already that make use of troop slots to guarantee their usage in a mission.
Nothing too fancy, just list processing with flags.
Code:
tf_guarantee_polearm = tf_unmoveable_in_party_window
Code:
slot_troop_polearm = 40
Code:
from process_troops import save_troops
...
scripts = [
#script_game_start:
# This script is called when a new game is started
# INPUT: none
("game_start",
save_troops() + [
...
Code:
import string
from module_info import *
from module_troops import *
#polearm
from header_troops import tf_hero, tf_unmoveable_in_party_window
from header_items import itp_type_polearm
from header_operations import troop_set_slot
from module_constants import slot_troop_polearm
from module_items import items
from process_common import *
#from process_operations import *
num_face_numeric_keys = 4
def save_troops():
#polearm
troop_polearm = []
troop_id = 0
file = open(export_dir + "troops.txt","w")
file.write("troopsfile version 2\n")
file.write("%d "%len(troops))
for troop in troops:
troop_len = len(troop)
if troop_len == 11:
troop[11:11] = [0, 0, 0, 0, 0]
elif troop_len == 12:
troop[12:12] = [0, 0, 0, 0]
elif troop_len == 13:
troop[13:13] = [0, 0, 0]
elif troop_len == 14:
troop[14:14] = [0, 0]
elif troop_len == 15:
troop[15:15] = [0]
#polearm
troop_flags = troop[3]
if troop_flags & tf_hero != tf_hero and troop_flags & tf_unmoveable_in_party_window == tf_unmoveable_in_party_window:
troop[3] ^= tf_unmoveable_in_party_window
troop_flags = 0
file.write("\ntrp_%s %s %s %s %d %d %d %d %d %d\n "%(convert_to_identifier(troop[0]),replace_spaces(troop[1]),replace_spaces(troop[2]), replace_spaces(str(troop[13])), troop[3],troop[4],troop[5], troop[6], troop[14], troop[15]))
inventory_list = troop[7]
for inventory_item in inventory_list:
if (isinstance(inventory_item,list))|(isinstance(inventory_item,tuple)):
file.write("%d %d "%(inventory_item[0],inventory_item[1]<<24))
item_id = inventory_item[0]
else:
file.write("%d 0 "%inventory_item)
item_id = inventory_item
#polearm
if troop_flags == 0 and items[item_id][3] & 0x000000ff == itp_type_polearm:
troop_polearm.append((troop_set_slot, troop_id, slot_troop_polearm, item_id))
# print troop[2] + " is using " + items[item_id][1]
troop_flags = 1
for i in xrange(64 - len(inventory_list)):
file.write("-1 0 ")
file.write("\n ")
attrib = troop[8]
strength = (attrib & 0xff)
agility = ((attrib >> 8)& 0xff)
intelligence = ((attrib >> 16)& 0xff)
charisma = ((attrib >> 24)& 0xff)
starting_level = (attrib >> level_bits) & level_mask
file.write(" %d %d %d %d %d\n"%(strength,agility,intelligence,charisma,starting_level))
wp_word = troop[9]
for wp in xrange(num_weapon_proficiencies):
wp_level = wp_word & 0x3FF
file.write(" %d"%wp_level)
wp_word = wp_word >> 10
file.write("\n")
skill_array = troop[10]
for i in xrange(num_skill_words):
file.write("%d "%((skill_array >> (i * 32)) & 0xffffffff))
file.write("\n ")
face_keys = [troop[11],troop[12]]
for fckey in (face_keys):
word_keys = []
for word_no in xrange(num_face_numeric_keys):
word_keys.append((fckey >> (64 * word_no)) & 0xFFFFFFFFFFFFFFFF)
for word_no in xrange(num_face_numeric_keys):
file.write("%d "%(word_keys[(num_face_numeric_keys -1) - word_no]))
file.write("\n")
troop_id += 1
...
module_troops said:["swadian_infantry_ai","Swadian Landsknecht","Swadian Landsknechts",tf_guarantee_polearm|tf_guarantee_boots|tf_guarantee_armor|tf_guarantee_helmet,0,0,fac_kingdom_1,
[itm_fighting_pick,itm_swadian_pike1,itm_swadian_cloth1,itm_swadian_cloth4,itm_white_hose,itm_leather_gloves,itm_hat1,itm_hat2,itm_swadian_cloth1,itm_swadian_cloth4,itm_white_hose,itm_leather_gloves],
def_attrib|level(14),wpex(175,155,165,100,150,100),knows_common|knows_power_strike_1|knows_weapon_master_2|knows_athletics_3,swadian_face_young_1, swadian_face_old_2],