I have a few (ok it's a _lot_ more than a few, but that doesn't mean I'm any good) years coding experience in various languages, but I'm also a rank amateur when it comes to Warband. I'm still finding out things. For example I didn't even know that the slot system existed. Sad but true.CryptoCactus said:Yeah, hat, I have absolutely no problem with you or anyone else altering this code (like I say, it's 98% yours anyway :p), and besides that I'm *really* a rank amateur. I only did this because it annoyed me personally to have lancers be so goofy, so.. yeah. And then I thought I should share it.
So alter it, scrap it entirely, whatever works. I'll help with anything I can, but I don't know how much help I'll be.
I'm not convinced that there is a huge jump in performance that can be made with this script as it is. I think that it needs to be broken up into different versions for different situations, linked by using some globals to keep track of what has and hasn't been run. Maybe.CryptoCactus said:I had figured that it would be pretty laggy in bigger battles, especially on older machines. I built my computer a year or two back (it has an 8800GT, which was king to everything but the GTX at the time iirc), and it works fine for me on max sized (non-tweaked/non-battlesizer'd) battles, but beyond that I'm sure it'll start hiccuping.
But... I couldn't think of a better way to get it done at the time.
I agree.CryptoCactus said:Yeah, that's the problem. The conditions on the battlefield can change so often and so quickly I can't see any way to do something like this without running regular checks (and thus adding potential for lag).xenoargh said:I can see the point of yanking the lances from the troop before initiating a siege, but this situation comes up a lot on the battlefield.
One thing I did for my mod is to alter my module_items.py file to break items (especially weapons) up into groups eg. polearms, one handed swords, two handed swords, shields etc. This means that I can use the range commands to set a bunch of ranges in module_constants.py (currently you get ones like weapons_begin = "itm_wooden_stick" and weapons_end = "itm_wooden_shield") for each class, then you can just use something like (is_between, ":item_id", <group>_begin, <group>_end), to check to see if a given ":item_id" is part of the <group> eg. (is_between,":item_id",polearms_begin,polearms_end). You already use this method in the alterations you made to my script, but with the items sorted you can make more intelligent assumptions on the usefulness of one weapon over another. That was my original intention with the battle version of the script (before I got distracted) -- which would have been even better if you could determine who/what the NPC was targeting/fighting. The downside is sorting out the items file is a heck of a lot of editing. Mind you I went a bit over the top with mine... Anyway it comes in handy for other things such as making scripts for items that prevent players using them if they are too small, or too large (gnome and giant gear) while allowing you to still loot and sell them (although you can do that anyway without sorting the file out).CryptoCactus said:Somebody said:Also, your code will only find the first appropriate sidearm listed, and then quits the loop. And it doesn't check if it's one of 4 items (agent_has_item_equipped) that any agent can have, so it's fortunate that Native's troops work for their intended purposes.
Yeah, that's because of the limits of my knowledge. >_>
I actually noted agent_has_item_equipped, but I wasn't sure what exactly it meant by "equipped". Which sounds kinda stupid when I type it out. I mean I was thinking of wielded vs equipped.. eh, nevermind.
As for finding the first available sidearm and breaking the loop, yeah, I knew that wouldn't be the ideal situation (for instance if it finds a dagger before a greatsword or what have you), but I don't really know how to run through each item and choose the best one.
Sounds like a good idea. I honestly think you'll do a better job with taking this script to the next level so am going to leave it in your hands.CryptoCactus said:HEY. I just noticed agent_unequip_item. Could we use that to just strip any unhorsed units of their lances for the duration of the battle? Of course (and I'm kinda just editing this as I go along and talking it out to myself), if we had an agent that *only* had a lance, then they'd be helpless... hrm. Oh, wait, no, because we'd only remove the lance after we've gone through and checked for an alternate weapon, of course. Duh.
# LANCE USAGE BEGIN
common_lance_usage_horseback = (
# 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"),
# 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),
])
common_lance_usage_foot = (
# 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.
5, 0, 0, [],
[
# 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"),
(is_between, ":item", "itm_wooden_stick","itm_light_lance"),
(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
...
(agent_set_slot, ":agent_no", slot_agent_courage_score, ":initial_courage_score"),
]),
common_battle_init_banner,
# LANCE USAGE BEGIN
common_lance_usage_horseback,
common_lance_usage_foot,
# LANCE USAGE END
(ti_on_agent_killed_or_wounded, 0, 0, [],
...
common_lancer_fix = (0, 0, 3, [],
[
# Run through all active NPCs on the battlefield.
(try_for_agents, ":agent"),
(try_begin),
(agent_get_slot, ":not_lancer", ":agent", slot_agent_no_lance),
(eq, ":not_lancer", 0),#Stop right here, if this condition isn't met.
#If this is ambiguous, weed them out. This could also be done as a one-time event early.
(try_begin),
# Isn't a player.
(agent_is_non_player, ":agent"),
(agent_set_slot, ":agent", slot_agent_no_lance, 1),
(try_end),
(try_begin),
# Isn't a horse.
(agent_is_human, ":agent"),
(agent_set_slot, ":agent", slot_agent_no_lance, 1),
(try_end),
(try_begin),
# Hasn't been defeated.
(agent_is_alive, ":agent"),
(agent_set_slot, ":agent", slot_agent_no_lance, 1),
(try_end),
(try_begin),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
(agent_set_slot, ":agent", slot_agent_no_lance, 1),
(try_end),
(try_begin),
# Isn't riding a horse.
(le, ":horse", 0),
(agent_set_slot, ":agent", slot_agent_no_lance, 1),
(try_end),
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# Is it a lance?
(is_between, ":wielded", "itm_jousting_lance","itm_jam_poleaxe"),#end of lances +1
# 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"),
(eq, ":has_choice",0),#Stop if we've found a valid item
(troop_get_inventory_slot,":item",":troop",":i"),
(neg|is_between, ":item", "itm_jousting_lance","itm_jam_poleaxe"), # 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),
(try_for_range, ":slot", ek_item_0, ek_item_3),
(eq, ":has_choice", 0),#Stop if we've found a valid item
(troop_get_inventory_slot,":item",":troop",":slot"),
(neg|is_between, ":item", "itm_jousting_lance","itm_jam_poleaxe"), # 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),
(try_end),
(try_end),
# Equip their backup weapon.
(try_begin),
(eq, ":has_choice",1),
(agent_set_wielded_item, ":agent", ":item"),
(try_end),
(try_end),
(try_end),
])
common_lancer_usage_horseback = (
ti_on_agent_spawn, 0, 0, [],
[
(store_trigger_param_1, ":agent"),
(agent_get_troop_id, ":troop_no", ":agent_no"),
# Isn't a player.
(agent_is_non_player, ":agent"),
# Isn't a horse.
(agent_is_human, ":agent"),
# Hasn't been defeated. #Just spawned
#(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", lances_begin, lances_end),
# 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", lances_begin, lances_end), # adjust as needed
(agent_set_wielded_item, ":agent", ":item"),
(try_begin), # Get wielded item. Again.
(agent_get_wielded_item, ":wielded", ":agent", 0),
(eq, ":wielded", ":item"),
(agent_set_slot, ":agent", slot_agent_lance, ":item"),#do whatever with this slot (nonzero)
(assign, ":item", lances_end),#loop breaker (it's only 4 items, but w/e)
(try_end),
(try_end),
])
common_lance_usage_foot = (
# 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.
5, 0, 0, [],
[# Run through all active NPCs on the battle field.
(try_for_agents, ":agent"),
(agent_get_slot, ":lance", ":agent", slot_agent_lance),
(gt, ":lance", 0),#or whatever, agent_slot_ge would also work but then we won't have the actual lance id
# 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?
(eq, ":wielded", ":lance"),#troops never switch between two items of the same type
# Find non-lance item in inventory
(agent_get_troop_id, ":troop",":agent"),
(assign,":has_choice",0),
(try_begin),
(troop_is_hero, ":troop"),
(try_for_range, ":i", ek_item_0, ek_head),
(troop_get_inventory_slot,":item",":troop",":i"),
(is_between, ":item", weapons_begin, lances_begin),#adjust
#(agent_has_item_equipped, ":agent", ":item"),#always equipped
(assign,":has_choice",1),
(assign, ":i", ek_head),#loop breaker
(try_end),
(else_try),#regular troops
(troop_get_inventory_capacity,":cap",":troop"),
(try_for_range, ":i", 0, ":cap"),#not sure if reg. troops have equipped items (slots < 10), but w/e
(troop_get_inventory_slot,":item",":troop",":i"),
(is_between, ":item", weapons_begin, lances_begin),#adjust
(agent_has_item_equipped, ":agent", ":item"),#this step is essential,
(assign,":has_choice",1),#but I'm not sure if this would work or not
(assign, ":cap", 0),
(try_end),
(try_end),
(try_begin),# Equip their backup weapon.
(eq, ":has_choice",1),
(agent_set_wielded_item, ":agent", ":item"),
(agent_set_slot, ":agent", slot_agent_lance, 0),
(try_end),
(try_end),
])
You don't really need two scripts. If it's cut down to one quick check for bad Agent IDs, it's more than fast enough, for something that runs infrequently.If I use it in conjunction with the horseback code I posted above (common_lance_usage_horseback), it doesn't.
xenoargh said:Sorry about the comma, lol. Fixed.
You don't really need two scripts. If it's cut down to one quick check for bad Agent IDs, it's more than fast enough, for something that runs infrequently.If I use it in conjunction with the horseback code I posted above (common_lance_usage_horseback), it doesn't.
common_siege_yada_yada = (
...
)
common_lancer_fix = ...
common_lance_use_spawn = (
# Just after spawn, mark lancers using a slot.
# Force lancers to equip lances.
1, 0, ti_once, [], [(call_script, "script_lance_use_classify_agent")])
common_lance_use = (
# 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.
# For mounted lancers affect their Decision on weapon use, based on if the
# closest 3 enemies are within 5 meters and if currently attacking/defending.
2, 0, 0, [],
[# Run through all active NPCs on the battle field.
(try_for_agents, ":agent"),
# Hasn't been defeated.
(agent_is_alive, ":agent"),
(agent_get_slot, ":lance", ":agent", slot_agent_lance),
(gt, ":lance", 0), # Lancer?
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
(try_begin),
(le, ":horse", 0), # Isn't riding a horse.
(agent_set_slot, ":agent", slot_agent_lance, 0), # No longer a lancer
(eq, ":wielded", ":lance"), # Still using lance?
(call_script, "script_lance_use_backup_weapon", ":agent"), # Then equip a close weapon
(else_try),
# Still mounted
(agent_get_position, pos1, ":agent"),
(agent_get_team, ":team_no", ":agent"), # Find distance of nearest 3 enemies
(call_script, "script_get_closest3_distance_of_enemies_at_pos1", ":team_no", pos1),
(assign, ":avg_dist", reg0),
(try_begin),
(lt, ":avg_dist", 500), # Are the enemies within 5 meters?
(agent_get_combat_state, ":combat", ":agent"),
(gt, ":combat", 3), # Agent currently in combat? ...avoids switching before contact
(eq, ":wielded", ":lance"), # Still using lance?
(call_script, "script_lance_use_backup_weapon", ":agent"), # Then equip a close weapon
(else_try),
(neq, ":wielded", ":lance"), # Enemies farther than 5 meters and/or not fighting, and not using lance?
(agent_set_wielded_item, ":agent", ":lance"), # Then equip it!
(try_end),
(try_end),
(try_end),
])
lance_use_triggers = [
common_lance_use_spawn,
common_lance_use,
]
//...a number of lines further down...//
(
"lead_charge",mtf_battle_mode,charge,
"You lead your men to battle.",
[
//...more lines down...//
(call_script, "script_battle_tactic_apply"),
], []), #applying battle tactic
common_battle_order_panel,
common_battle_order_panel_tick,
] + lance_use_triggers,
),
(
"village_attack_bandits",mtf_battle_mode,charge,
"You lead your men to battle.",
//...the next mission...//
# script_lance_use_backup_weapon
# Input: arg1: agent
# Output: none
("lance_use_backup_weapon",
[
# Find non-lance/spear/bow item in inventory
(store_script_param_1, ":agent"),
(agent_get_troop_id, ":troop",":agent"),
(assign,":has_choice",0),
(try_begin),
(troop_is_hero, ":troop"),
(assign, ":end", ek_head),
(try_for_range, ":i", ek_item_0, ":end"),
(troop_get_inventory_slot,":item",":troop",":i"),
(gt, ":item", 0),
(item_get_type, ":weapontype", ":item"),
(is_between, ":weapontype", itp_type_one_handed_wpn, itp_type_polearm),#one or two handed
(assign,":has_choice",1),
(assign, ":end", ek_item_0),#loop breaker
(try_end),
(else_try),#regular troops
(troop_get_inventory_capacity,":cap",":troop"),
(try_for_range, ":i", 0, ":cap"),#not sure if reg. troops have equipped items (slots < 10), but w/e
(troop_get_inventory_slot,":item",":troop",":i"),
(gt, ":item", 0),
(item_get_type, ":weapontype", ":item"),
(is_between, ":weapontype", itp_type_one_handed_wpn, itp_type_polearm),#one or two handed
(agent_has_item_equipped, ":agent", ":item"),#this step is essential,
(assign,":has_choice",1),#but I'm not sure if this would work or not
(assign, ":cap", 0),
(try_end),
(try_end),
(try_begin),# Equip their backup weapon.
(eq, ":has_choice",1),
(agent_set_wielded_item, ":agent", ":item"),
(try_end),
]),
# script_lance_use_classify_agent
# Input: None
# Output: None
("lance_use_classify_agent", [
(try_for_agents, ":agent"),
(agent_is_alive, ":agent"),
# Isn't a player.
(agent_is_non_player, ":agent"),
# Isn't a horse.
(agent_is_human, ":agent"),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
(gt, ":horse", 0), # Is riding a horse.
# Not a horsearcher
(agent_get_troop_id, ":troop",":agent"),
(neg|troop_is_guarantee_ranged, ":troop"),
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
(try_begin),
(this_or_next|is_between, ":wielded", "itm_jousting_lance","itm_glaive"), # Is it a lance?
(is_between, ":wielded", "itm_light_lance","itm_pike"), # Is it a lance?
(agent_set_slot, ":agent", slot_agent_lance, ":wielded"),
(else_try),
# Force the NPC to wield a lance, but this will only happen if they
# actually have a lance equipped. Otherwise this does nothing.
(assign, ":end", "itm_glaive"), # adjust as needed
(try_for_range, ":item", "itm_jousting_lance",":end"),
(agent_has_item_equipped, ":agent", ":item"),
(agent_set_wielded_item, ":agent", ":item"),
(agent_set_slot, ":agent", slot_agent_lance, ":item"), #Mark lancers for later use
(assign, ":end", "itm_jousting_lance"),#loop breaker
(try_end),
(assign, ":end", "itm_pike"), # adjust as needed
(try_for_range, ":item", "itm_light_lance",":end"),
(agent_has_item_equipped, ":agent", ":item"),
(agent_set_wielded_item, ":agent", ":item"),
(agent_set_slot, ":agent", slot_agent_lance, ":item"), #Mark lancers for later use
(assign, ":end", "itm_light_lance"),#loop breaker
(try_end),
(try_end),
(try_end), #Agent Loop
]),
slot_agent_lance = 26
slot_agent_spear = 27
slot_agent_horsebow = 28
common_weapon_use_spawn = (
# Just after spawn, mark lancers, spears, horse archers using a slot.
# Force lancers to equip lances, horse archers to equip bows
1, 0, ti_once, [], [(call_script, "script_weapon_use_classify_agent")])
common_weapon_use = (
# 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.
# Check horse archers ammo, and if none left, switch to sword.
# For mounted lancers and foot spears, affect their Decision on weapon use,
# based on if closest 3 enemies are within 5 meters and if currently attacking/defending.
2, 0, 0, [],
[# Run through all active NPCs on the battle field.
(try_for_agents, ":agent"),
# Hasn't been defeated.
(agent_is_alive, ":agent"),
(try_begin),
(agent_get_slot, ":lance", ":agent", slot_agent_lance),
(gt, ":lance", 0), # Lancer?
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
(try_begin),
(le, ":horse", 0), # Isn't riding a horse.
(agent_set_slot, ":agent", slot_agent_lance, 0), # No longer a lancer
(eq, ":wielded", ":lance"), # Still using lance?
(call_script, "script_weapon_use_backup_weapon", ":agent"), # Then equip a close weapon
(else_try),
# Still mounted
(agent_get_position, pos1, ":agent"),
(agent_get_team, ":team_no", ":agent"), # Find distance of nearest 3 enemies
(call_script, "script_get_closest3_distance_of_enemies_at_pos1", ":team_no", pos1),
(assign, ":avg_dist", reg0),
(try_begin),
(lt, ":avg_dist", 500), # Are the enemies within 5 meters?
(agent_get_combat_state, ":combat", ":agent"),
(gt, ":combat", 3), # Agent currently in combat? ...avoids switching before contact
(eq, ":wielded", ":lance"), # Still using lance?
(call_script, "script_weapon_use_backup_weapon", ":agent"), # Then equip a close weapon
(else_try),
(neq, ":wielded", ":lance"), # Enemies farther than 5 meters and/or not fighting, and not using lance?
(agent_set_wielded_item, ":agent", ":lance"), # Then equip it!
(try_end),
(try_end),
(else_try),
(agent_get_slot, ":bow", ":agent", slot_agent_horsebow),
(gt, ":bow", 0), # Horse archer?
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# They have ammo left?
(agent_get_ammo, ":ammo", ":agent"),
(try_begin),
(le, ":ammo", 0), # No ammo left
(agent_set_slot, ":agent", slot_agent_horsebow, 0), # No longer a horse archer
(eq, ":wielded", ":bow"), # Still using bow?
(call_script, "script_weapon_use_backup_weapon", ":agent"), # Then equip a close weapon
(else_try),
(neq, ":wielded", ":bow"), # Still have ammo, and not using bow?
(agent_set_wielded_item, ":agent", ":bow"), # Then equip it!
(try_end),
(else_try),
(agent_get_slot, ":spear", ":agent", slot_agent_spear),
(gt, ":spear", 0), # Spear-Unit?
(agent_get_wielded_item, ":wielded", ":agent", 0), # Get wielded
(agent_get_position, pos1, ":agent"),
(agent_get_team, ":team_no", ":agent"), # Find distance of nearest 3 enemies
(call_script, "script_get_closest3_distance_of_enemies_at_pos1", ":team_no", pos1),
(assign, ":avg_dist", reg0),
(try_begin),
(lt, ":avg_dist", 500), # Are the enemies within 5 meters?
(agent_get_combat_state, ":combat", ":agent"),
(gt, ":combat", 3), # Agent currently in combat? ...avoids switching before contact
(eq, ":wielded", ":spear"), # Still using spear?
(call_script, "script_weapon_use_backup_weapon", ":agent"), # Then equip a close weapon
(else_try),
(neq, ":wielded", ":spear"), # Enemies farther than 5 meters and/or not fighting, and not using spear?
(agent_set_wielded_item, ":agent", ":spear"), # Then equip it!
(try_end),
(try_end),
(try_end),
])
weapon_use_triggers = [
common_weapon_use_spawn,
common_weapon_use,
]
# script_weapon_use_backup_weapon
# Input: arg1: agent
# Output: none
("weapon_use_backup_weapon",
[
# Find non-lance/spear/bow item in inventory
(store_script_param_1, ":agent"),
(agent_get_troop_id, ":troop",":agent"),
(assign,":has_choice",0),
(try_begin),
(troop_is_hero, ":troop"),
(assign, ":end", ek_head),
(try_for_range, ":i", ek_item_0, ":end"),
(troop_get_inventory_slot,":item",":troop",":i"),
(gt, ":item", 0),
(item_get_type, ":weapontype", ":item"),
(is_between, ":weapontype", itp_type_one_handed_wpn, itp_type_polearm),#one or two handed
(assign,":has_choice",1),
(assign, ":end", ek_item_0),#loop breaker
(try_end),
(else_try),#regular troops
(troop_get_inventory_capacity,":cap",":troop"),
(try_for_range, ":i", 0, ":cap"),#not sure if reg. troops have equipped items (slots < 10), but w/e
(troop_get_inventory_slot,":item",":troop",":i"),
(gt, ":item", 0),
(item_get_type, ":weapontype", ":item"),
(is_between, ":weapontype", itp_type_one_handed_wpn, itp_type_polearm),#one or two handed
(agent_has_item_equipped, ":agent", ":item"),#this step is essential,
(assign,":has_choice",1),#but I'm not sure if this would work or not
(assign, ":cap", 0),
(try_end),
(try_end),
(try_begin),# Equip their backup weapon.
(eq, ":has_choice",1),
(agent_set_wielded_item, ":agent", ":item"),
(try_end),
]),
# script_weapon_use_classify_agent
# Input: None
# Output: None
("weapon_use_classify_agent", [
(try_for_agents, ":agent"),
(agent_is_alive, ":agent"),
# Isn't a player.
(agent_is_non_player, ":agent"),
# Isn't a horse.
(agent_is_human, ":agent"),
(agent_get_troop_id, ":troop",":agent"),
# Get wielded item.
(agent_get_wielded_item, ":wielded", ":agent", 0),
# They riding a horse?
(agent_get_horse, ":horse", ":agent"),
(try_begin),
(gt, ":horse", 0), # Is riding a horse.
(neg|troop_is_guarantee_ranged, ":troop"), # Not a horsearcher
(try_begin),
(this_or_next|is_between, ":wielded", "itm_jousting_lance","itm_glaive"), # Is it a lance?
(is_between, ":wielded", "itm_light_lance","itm_pike"), # Is it a lance?
(agent_set_slot, ":agent", slot_agent_lance, ":wielded"),
(else_try),
# Force the NPC to wield a lance, but this will only happen if they
# actually have a lance equipped. Otherwise this does nothing.
(assign, ":end", "itm_glaive"), # adjust as needed
(try_for_range, ":item", "itm_jousting_lance",":end"),
(agent_has_item_equipped, ":agent", ":item"),
(agent_set_wielded_item, ":agent", ":item"),
(agent_set_slot, ":agent", slot_agent_lance, ":item"), #Mark lancers for later use
(assign, ":end", "itm_jousting_lance"),#loop breaker
(try_end),
(assign, ":end", "itm_pike"), # adjust as needed
(try_for_range, ":item", "itm_light_lance",":end"),
(agent_has_item_equipped, ":agent", ":item"),
(agent_set_wielded_item, ":agent", ":item"),
(agent_set_slot, ":agent", slot_agent_lance, ":item"), #Mark lancers for later use
(assign, ":end", "itm_light_lance"),#loop breaker
(try_end),
(try_end),
(else_try),
(gt, ":horse", 0), # Is riding a horse.
(troop_is_guarantee_ranged, ":troop"), # Is a horsearcher...redundant, but making sure
(try_begin),
(is_between, ":wielded", "itm_hunting_bow", "itm_crossbow"), # Is it a bow or a horse-useful crossbow?
(agent_set_slot, ":agent", slot_agent_horsebow, ":wielded"),
(else_try),
# Force the NPC to wield their bow, but this will only happen if they
# actually have a bow equipped. Otherwise this does nothing.
(assign, ":end", "itm_crossbow"), # adjust as needed
(try_for_range, ":item", "itm_hunting_bow",":end"),
(agent_has_item_equipped, ":agent", ":item"),
(agent_set_wielded_item, ":agent", ":item"),
(agent_set_slot, ":agent", slot_agent_horsebow, ":item"), #Mark horse archers for later use
(assign, ":end", "itm_hunting_bow"),#loop breaker
(try_end),
(try_end),
(else_try), #Agent not mounted
(le, ":horse", 0),
(try_begin),
(gt, ":wielded", 0), #Make sure it's not fists
(item_get_type, ":weapontype", ":wielded"),
(eq, ":weapontype", itp_type_polearm), # Is it a spear?
(agent_set_slot, ":agent", slot_agent_spear, ":item"), #Mark spearmen
(else_try), #Check if there's a spear equipped, if not wielded
(troop_get_inventory_capacity,":cap",":troop"),
(try_for_range, ":i", 0, ":cap"),#not sure if reg. troops have equipped items (slots < 10), but w/e
(troop_get_inventory_slot,":item",":troop",":i"),
(gt, ":item", 0),
(item_get_type, ":weapontype", ":item"),
(eq, ":weapontype", itp_type_polearm), # Is it a spear?
(agent_has_item_equipped, ":agent", ":item"),#this step is essential,
(agent_set_slot, ":agent", slot_agent_spear, ":item"), #Mark spearmen
(assign, ":cap", 0), #loop Break
(try_end),
(try_end),
(try_end), #Mounted or not
(try_end), #Agent Loop
]),