The Formation code.
I've looked at this script and found a solution to avoid repeating "(call_script,"script_formation_repeat")". Let's have a look :
("formation_start",
[(get_player_agent_no,reg(10)),
(agent_get_position,1,reg(10)),
(assign,"$agents",0), #initialization of the agents counter
(try_for_range,reg(20),1,100), #reset of the player dummy-slots
(agent_set_slot,reg(10),reg(20),0),
(try_end),
(try_for_agents,reg(5)),
(assign,reg(0),0),
#Not the player
(neq, reg(5), reg(10)),
#Not Dead
(agent_is_alive, reg(5)),
#Not a Horse?
(agent_is_human, reg(5)),
#If the Selected Troop is an Ally
(agent_is_ally,reg(5)),
(val_add,"$agents",1), #increment the counter
(assign,reg(1),1),
(try_begin),
(assign,reg(20),1), #reg(20) is the agent number to use every position only once
(agent_get_slot,reg(21),reg(10),reg(20)), #player agent used as a dummy not to make several agent use one position
(eq,reg(21),0), #number isn't used, yet
(assign,reg(1),reg(20)),
(assign,reg(3),reg(1)),
(val_mul,reg(3),100),
(copy_position,reg(1),1),
(position_move_x,reg(1),reg(3)), #number 1 = 100 metres right to the player agent 2= 200 etc...
(agent_set_scripted_destination,reg(5),reg(1)), #tells the agent to run there
(agent_set_slot,reg(5),1,reg(1)), #tells the agent which position he has - only important if you want to do somethink else with the script, it would work without it right now.
(agent_set_slot,reg(10),reg(20),1), #tells the game that the number is used, by using the player slots.
(else_try),
(try_for_range,reg(1),1,"$agents"), #loop call !
(call_script,"script_formation_repeat"),
(try_end),
(try_end),
(try_end),
]),
("formation_repeat",
[ (val_add,reg(20),1), # adds 1 to the agent number
(agent_get_slot,reg(21),reg(10),reg(20)),
(eq,reg(21),0), # again, is the number already used?
(assign,reg(1),reg(20)), #just copying the number to use it somewhere else...
(assign,reg(3),reg(1)), #again copying
(assign,reg(4),0), #assigns the row of this agent to 0
#-#-#-#-#-#-#-#-#-#
(try_for_range,reg(15),1,100), #this try-code assigns the right row.
(assign,reg(17),reg(15)),
(assign,reg(16),reg(15)),
(val_mul,reg(15),5), #number of troops in one line
(val_mul,reg(16),5), #has to be the same as above
(val_add,reg(16),5), #has to be the same as above
(gt,reg(3),reg(15)),
(le,reg(3),reg(16)),
(assign,reg(15),reg(17)),
(val_mul,reg(15),6), #number of troops in one line + 1
(val_sub,reg(3),reg(15)),
(assign,reg(4),reg(17)),
(try_end),
#delete these lines to get a 1 line formation
#-#-#-#-#-#-#-#-#-#
(val_mul,reg(3),100),
(val_mul,reg(4),200),
(copy_position,reg(1),1),
(position_move_x,reg(1),reg(3)),
(position_move_y,reg(1),reg(4)),
(agent_set_scripted_destination,reg(5),reg(1)),
(agent_set_slot,reg(5),1,reg(1)),
(agent_set_slot,reg(10),reg(20),1),
]),
The agents number has no importance. "formation_start" simply count them and call "formation_repeat" as many times as needed.
Edit : corrected some syntax errors. Thanks Dwinny !