Naw, I got it (finally).
Firstly, thus:
Call this script in a ti_after_mission_start triggered mission_templates block:
That sets the Cavalry Division to use ranged weapons, which triggers the "horse archer" behaviors in any Agent that possesses a missile weapon, whether or not it has ammo at all. Unfortunately, it also triggers some sort of state-machine lockup, where it simply will not return to using its melee weapon even if it doesn't have any ammo left and will not respond to melee attacks (weirdly, it would if it still had ammo...).
Then, in a cyclic block:
This kicks all Agents in grc_cavalry that do not have ammo left into another Division, whose default mordr state is mordr_charge, if, and only if, they do not have any ammo and grc_cavalry's mordr state is currently mordr_charge. I had a horse check and other stuff in there, but frankly, it's a waste of CPU (not that this one's terribly expensive, since the Division handoff is one-time, one-way); if we've told the cavalry to charge, then we want the right behavior; if players wish to give different orders to grc_cavalry2, they can do so without upsetting the script logic in any way.
grc_cavalry2 is, IIRC, a non-standard module_constants designation, but it's Division 8, if anybody just wants to use the raw number.
Firstly, thus:
Call this script in a ti_after_mission_start triggered mission_templates block:
Code:
#This script sets all mounted Agents using the Cavalry slot to use missile weapons.
("mounted_agent_ai_initial_orders",
[
(try_for_range, ":team", 0, 5),
(team_give_order, ":team", grc_cavalry, mordr_use_ranged_weapons),
(team_give_order, ":team", grc_cavalry2, mordr_charge),
(try_end),
]),
Then, in a cyclic block:
Code:
#This script forces Agents that are horse-archers and no longer have any ammo...
#...to be moved into the Cavalry2 Division, which always defaults to Charge mordr.
#This prevents the Agents from sitting around doing nothing. Will hopefully be fixed in-engine by TW per bug report 4105.
("cf_mounted_agent_ai_fixer",
[
(try_for_agents, ":agent"),
(agent_is_human, ":agent"),
(agent_is_alive, ":agent"),
(agent_is_active, ":agent"),
(agent_get_troop_id, ":id", ":agent"),
(neq, ":id", "trp_player"),
(agent_get_ammo, ":ammo", ":agent", 1),
(agent_get_division, ":division", ":agent"),
(agent_get_team,":agent_team", ":agent"),
(team_get_movement_order, ":order_type", ":agent_team", grc_cavalry),
(try_begin),
(lt, ":ammo", 1),
(eq, ":division", grc_cavalry),
(eq, ":order_type", mordr_charge),
(agent_set_division, ":agent", grc_cavalry2),
(try_end),
(try_end),
]),
grc_cavalry2 is, IIRC, a non-standard module_constants designation, but it's Division 8, if anybody just wants to use the raw number.