[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
[*]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"),
]
)