With all the talk about formations, I reckon this is the right time for this. Since Highlander's code is long, somewhat buggy, and slow to act, I made my own formation script. It supports as many men in formation at once as m+b can handle, they react quicker, and will never give any error messages, in addition to being somewhat more user friendly. Best of all, it can even be used to make a wedge. The wedge will not be usefull for now, but with cavalry being scriptable in the new version, it will be soon.
The efficient, improved formation code:
("formation",
[(get_player_agent_no,reg(10)),
(agent_get_position,1,reg(10)),
(assign,":collumn",1),
(position_move_x,1,
100),
(try_for_agents,reg(5)),
(agent_is_ally,reg(5)),
(agent_is_alive,reg(5)),
(agent_is_human,reg(5)),
(agent_set_scripted_destination,reg(5),1),
(position_move_x,1,
100),
(try_begin),
(eq,":collumn",
10),
(position_move_x,1,-
10*
100),
(position_move_y,1,-
100),
(assign,":collumn",1),
(else_try),
(val_add,":collumn",1),
(end_try),
(end_try)]),
Red: distance between agents left and right.
Blue: distance between agents front and back.
Green: number of men in one row.
Screenie with more men than the current formation code supports:
The wedge formation code:
("formation_wedge",
[(get_player_agent_no,reg(10)),
(agent_get_position,1,reg(10)),
(assign,":collumn",1),
(assign,":nc",3),
(position_move_x,1,-
100),
(position_move_y,1,-
100),
(try_for_agents,reg(5)),
(agent_is_ally,reg(5)),
(agent_is_alive,reg(5)),
(agent_is_human,reg(5)),
(agent_set_scripted_destination,reg(5),1),
(try_begin),
(eq,":collumn",":nc"),
(val_mul,":nc",-100),
(position_move_x,1,":nc"),
(position_move_y,1,-
100),
(assign,":collumn",1),
(val_div,":nc",-100),
(val_add,":nc",2),
(else_try),
(position_move_x,1,
100),
(val_add,":collumn",1),
(end_try),
(end_try)]),
Red: distance side to side.
Blue: distance front to back.
This will need to be modified for cavalry with the new version. To use this, set up a trigger in module_mission_templates.py under the "lead_charge" mission which will call this script every tenth of a second when the conditions are right, thus moving the formation according to the player. It becomes a bit rough when moving, but its really not all that bad.
Screenie:
To get enemies to form a line:
("ai_formation",
[(assign,"$formed",1),(try_for_agents,reg(5)),
(agent_is_alive, reg(5)),
(neg|agent_is_ally,reg(5)),
(agent_is_human, reg(5)),
(agent_get_position,1,reg(5)),
(try_end),
(assign,":collumn",1),
(position_move_x,1,75),
(try_for_agents,reg(5)),
(neg|agent_is_ally,reg(5)),
(agent_is_alive,reg(5)),
(agent_is_human,reg(5)),
(agent_set_scripted_destination,reg(5),1),
(position_move_x,1,75),
(try_begin),
(eq,":collumn",10),
(position_move_x,1,-10*75),
(position_move_y,1,-50),
(assign,":collumn",1),
(else_try),
(val_add,":collumn",1),
(end_try),
(end_try)]),
Give the enemies a weapon which will call this script. The distances are slightly different from the formation above, but works the same way. It picks a random enemy infantryman and uses him as the starting point for the formation.
When formations clash
: