OSP Code SP tf_guarantee_polearm

Users who are viewing this thread

[list type=decimal]
[*]At the top of module_troops we borrow a flag by the following declaration tf_guarantee_polearm = tf_unmoveable_in_party_window, so now we can use this flag to denote regular troops.
[*]Anywhere in module_constants we declare slot_troop_polearm = 40, this is an arbitrary constant so we can tell the game this troop has a special polearm allocated
[*]In process_troops.py we modify the existing function where it compiles module_troops into text files. Replace the entire top of the file until the end of the function save_troops()
[*]Having modified the function to also return a list of troops with polearms, we make sure these troops are assigned polearms at the start of the game. At the top of module_scripts, insert from process_troops import save_troops. Then, at the declaration of the first script "game_start" we prepend our list of troops to be assigned polearms
("game_start",
  save_troops() + [

[/list]
The hard part is then finding a trigger which will make troops conditionally use their polearms. My code's pretty dated and also ties in with a bunch of other crap, so you can't just plug and play with that
Code:
("init_agent_type", [
	(store_script_param_1, ":agent"),
	(store_script_param_2, ":troop"),
	(agent_set_slot, ":agent", slot_agent_polearm, 0), #clear to 0
	(try_begin),
	  (neg|troop_is_hero, ":troop"),
	  # (troop_get_xp, ":troop_xp", ":troop"),
	  # (troop_set_slot, ":troop", slot_troop_extra_xp_limit, ":troop_xp"),
	# (else_try),
	  (troop_get_slot, ":polearm", ":troop", slot_troop_polearm),
	 # (gt, ":polearm", 0),
	  (assign, ":end", ek_head), #4 cycles
	  (try_for_range, ":slot", ek_item_0, ek_head),
      (agent_get_item_slot, ":item", ":agent", ":slot"),
      (gt, ":item", 0), #might be -1
      (try_begin), #found guaranteed polearm
        (eq, ":item", ":polearm"), #one found already equipped
        (assign, ":end", 0),
      (else_try), #parse if polearm
        (eq, ":polearm", 0), #not filled
        (item_get_type, ":type", ":item"),
        (eq, ":type", itp_type_polearm),
        (try_begin),
          (troop_is_guarantee_horse, ":troop"), #is cavalry
          (item_slot_eq, ":item", slot_item_cant_on_horseback, 2), #couching lances
          (assign, ":end", 0),
        (else_try),
          (item_slot_eq, ":item", slot_item_cant_on_horseback, 1), #can't use on horseback
          (item_slot_ge, ":item", slot_item_length, 245), #long pikes
          (assign, ":end", 0),
        (try_end),
        (eq, ":end", 0),
        (assign, ":polearm", ":item"),
      (try_end),
      (try_end),
      #regardless of the case
       (agent_set_slot, ":agent", slot_agent_polearm, ":polearm"),
      #still not found
       (eq, ":end", ek_head),
       (gt, ":polearm", 0),
       (agent_equip_item, ":agent", ":polearm"),
      # (agent_set_wielded_item, ":agent", ":polearm"),
    (try_end),
  ]
 ),

#script_agent_check_backup
("agent_check_backup", [

	#do lance sorts
	(try_for_agents, ":agent"),
	# (try_begin),
	  # (assign, ":agent", "$dmod_current_agent"),
	  (agent_is_alive, ":agent"),
	  # (neq, ":agent", "$g_player_agent"),
      (agent_is_non_player, ":agent"),
      (agent_slot_eq, ":agent", slot_agent_target_x_pos, 0), # Not ladderman
	  (agent_get_slot, ":lance", ":agent", slot_agent_polearm),
	  (gt, ":lance", 0),
	  (agent_get_wielded_item, ":wielded", ":agent", 0), # Get wielded item.
	  (gt, ":wielded", 0), #not fisting
	  (item_get_type, ":type", ":wielded"),  #using melees
	  (is_between, ":type", itp_type_one_handed_wpn, itp_type_arrows),
	  (item_get_slot, ":type", ":lance", slot_item_cant_on_horseback), #polearm type
	  (try_begin),
		(agent_get_horse, ":horse", ":agent"),# They riding a horse?
		(try_begin),  # Still mounted lancer or pikeman
		  (this_or_next|ge, ":horse", 0),
		  (neq, ":type", 2),
		  (item_get_slot, ":distance", ":lance", slot_item_length),
		  (agent_get_position, pos1,  ":agent"),
		  (agent_get_team, ":team_no", ":agent"),
		  (try_for_agents,":cur_agent"),
			(gt, ":distance", 0),
			(agent_is_alive, ":cur_agent"),
			(agent_is_human, ":cur_agent"),
			(agent_get_team, ":agent_team", ":cur_agent"),
			(teams_are_enemies, ":agent_team", ":team_no"),
			(agent_get_position, pos2, ":cur_agent"),
			(get_distance_between_positions,":cur_dist",pos2,pos1),
			(lt, ":cur_dist", ":distance"),
			(assign, ":distance", -1), #found at least 1 within 2xrange of weapon
		  (try_end),
		  (agent_get_combat_state, ":cs", ":agent"),
		  (try_begin),
			(eq, ":distance", -1), #found within range
			(gt, ":cs", 3),
			(eq, ":wielded", ":lance"),
			(call_script, "script_agent_equip_backup", ":agent"),
		  (else_try),
			(gt, ":distance", 0), #some distance outside weapon reach
			(le, ":cs", 3),
			(neq, ":wielded", ":lance"), # Enemies farther than 5 meters and/or not fighting, and not using lance?
			# (str_store_item_name, s0, ":lance"),
			# (str_store_item_name, s1, ":wielded"),
			# (str_store_agent_name, s2, ":agent"),
			# (display_message, "@{s2} switching back to {s0} from {s1}", message_negative),
			(agent_set_wielded_item, ":agent", ":lance", 0), # Then equip it!
		  (try_end),
		(else_try),
		  (le, ":horse", 0), # Isn't riding a horse.
		  (neq, ":type", 1), #not unusable on horseback
		  (eq, ":wielded", ":lance"), #If the item wasn't actually usable, this wouldn't happen
		  (call_script, "script_agent_equip_backup", ":agent"),
		(try_end),
	  (try_end),
	(try_end),
  ]),
Code:
(
  ti_on_agent_spawn, 0, 0, [],
  [
    (store_trigger_param_1, ":agent_no"),
    (agent_is_human, ":agent_no"),
    (agent_get_troop_id, ":troop_no", ":agent_no"),
    (call_script, "script_init_agent_type", ":agent_no", ":troop_no"),
  ]),

(2.5,0,0, [],
  [
    (call_script, "script_agent_check_backup"),
  ]
)
 
again i follow your instructions which were perfectly laid out. ( thank you for that).

Different compiling errors depending on what i try to do... mostly things being undefined. My module is just unhappy with the script in module_scripts.

  File "C:\Users\Powers\Desktop\M&B\attempted edit\Module_system 1.158\module_sc
ripts.py", line 47648, in <module>
    (agent_set_slot, ":agent", slot_agent_polearm, 0), #clear to 0
NameError: name 'slot_agent_polearm' is not defined



Thanks again for all your help on this. I think its just too far over my head and I am going to have to let it go.
 
What I said in the previous post was to NOT plug and play - there are a lot of dependencies in the sample weapon switching code I had earlier, including checks for lances and weapon lengths as the determining factor in when to switch weapons. A more simple version can be found as follows (and probably should work)
Code:
slot_agent_polearm = 25
Code:
("init_agent_type", [
	(store_script_param_1, ":agent"),
	(store_script_param_2, ":troop"),
	(agent_set_slot, ":agent", slot_agent_polearm, 0), #clear to 0
	(try_begin),
	  (troop_get_slot, ":polearm", ":troop", slot_troop_polearm),
	  (gt, ":polearm", 0),
	  (agent_set_slot, ":agent", slot_agent_polearm, ":polearm"),
	  (agent_equip_item, ":agent", ":polearm"),
	(try_end),
  ]
 ),

#script_agent_check_backup
("agent_check_backup", [
	#do lance sorts
	(try_for_agents, ":agent"),
	  (agent_is_alive, ":agent"),
	  (agent_is_non_player, ":agent"),
	  (agent_get_slot, ":lance", ":agent", slot_agent_polearm),
	  (gt, ":lance", 0),
	  (agent_get_wielded_item, ":wielded", ":agent", 0), # Get wielded item.
	  (gt, ":wielded", 0), #not fisting
	  (item_get_type, ":type", ":wielded"),  #using melee weapons
	  (is_between, ":type", itp_type_one_handed_wpn, itp_type_arrows),
	  (assign, ":distance", 100),
	  (agent_get_position, pos1,  ":agent"),
	  (agent_get_team, ":team_no", ":agent"),
	  (try_for_agents,":cur_agent"),
		(gt, ":distance", 0),
		(agent_is_alive, ":cur_agent"),
		(agent_is_human, ":cur_agent"),
		(agent_get_team, ":agent_team", ":cur_agent"),
		(teams_are_enemies, ":agent_team", ":team_no"),
		(agent_get_position, pos2, ":cur_agent"),
		(get_distance_between_positions,":cur_dist",pos2,pos1),
		(lt, ":cur_dist", ":distance"),
		(assign, ":distance", -1),
	  (try_end),
	  (agent_get_combat_state, ":cs", ":agent"),
	  (try_begin),
		(gt, ":distance", 0), #some distance outside weapon reach
		(le, ":cs", 3),
		(neq, ":wielded", ":lance"), # Enemies farther than 5 meters and/or not fighting, and not using lance?
		(agent_set_wielded_item, ":agent", ":lance", 0), # Then equip it!
	  (try_end),
	(try_end),
]),
What this does is assign the item to the agent slot at spawn time. If there are no enemies within melee range pikemen will keep using whatever polearm they've been assigned. Within that 200 radius if there are enemies the native weapon switching should occur. Keep the same triggers in module_mission_templates (probably lead_charge and whatever missions pikemen show up in), although the first part can be merged within
Code:
common_battle_init_banner
.
 
Life_Erikson said:
Big leap forward. Thank you!

I put the "("init_troop_polearms", save_troops())," at the botom before the last bracket in module scripts and
put the "(call_script, "scipt_init_troop_polarms")," where the "save_troops() + [" was before as it seems that this is the only place where "game_start" is used in module_scripts.

But now MS puts out this:
Error in script: ('init_troop_ploearms', None)

I have the very same problem. Seems like the function has not returning value.

Code:
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    
    
  file.close()
 
Back
Top Bottom