# LANCE USAGE BEGIN
# Force mounted NPCs to switch to their lance. This is called once at the
# start of the battle. If you want lancers to ALWAYS use lances on horseback,
# replace ti_once with 1. Otherwise they may switch to sword if bogged down
(0, 1, ti_once, [],
[
# Run through all active NPCs on the battle field.
(try_for_agents, ":agent"),
# Isn't a player.
(agent_is_non_player, ":agent"),
# Isn't a horse.
(agent_is_human, ":agent"),
# Hasn't been defeated.
(agent_is_alive, ":agent"),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
# Is riding a horse.
(gt, ":horse", 0),
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# Is it a lance?
(neg|is_between, ":wielded", "itm_light_lance","itm_pike"), # adjust as needed
# Force the NPC to wield the lance, but this will only happen if they
# actually have a lance in their inventory. Otherwise this does
# nothing.
(try_for_range,":item","itm_light_lance","itm_pike"), # adjust as needed
(agent_set_wielded_item, ":agent", ":item"),
(try_end),
(try_end),
]),
# Check to make sure there are no lance users on foot, if so force them to
# switch to their sword. This should also affect troops that were NEVER mounted,
# but are still equipped with lances, such as Taiga Bandits.
(0, 0, 1, [],
[
# Run through all active NPCs on the battle field.
(try_for_agents, ":agent"),
# Isn't a player.
(agent_is_non_player, ":agent"),
# Isn't a horse.
(agent_is_human, ":agent"),
# Hasn't been defeated.
(agent_is_alive, ":agent"),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
# Isn't riding a horse.
(le, ":horse", 0),
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# Is it a lance?
(is_between, ":wielded", "itm_light_lance","itm_pike"),
# Find non-lance item in inventory
(agent_get_troop_id, ":troop",":agent"),
(troop_get_inventory_capacity,":cap",":troop"),
(assign,":has_choice",0),
(try_for_range, ":i", 0, ":cap"),
(troop_get_inventory_slot,":item",":troop",":i"),
(neg|is_between, ":item", "itm_light_lance","itm_pike"), # adjust as needed
(neg|is_between, ":item", "itm_wooden_shield","itm_darts"), # not a shield - adjust as needed
(neg|is_between, ":item", "itm_hunting_bow","itm_torch"), # not ranged - adjust as needed
(assign,":has_choice",1),
(assign,":cap",0),
(try_end),
# Equip their backup weapon.
(try_begin),
(eq, ":has_choice",1),
(agent_set_wielded_item, ":agent", ":item"),
(try_end),
(try_end),
]),
# LANCE USAGE END