I'm afraid I have to take back my previous statement.
IL-2's internal logic doesn't allow us to change aircraft positions in wings/groups/formations.
IL-2 strictly insists that airplanes need to take a position inside a formation according to their squadron/flight/airplane number.
The lowest number is always the leader, no matter what.
Even if in code the leader/wingman designations get changed, IL-2 tries to arrange the formation according to the strict number scheme.
Therefore e.g. in a four-ship formation (1-2-3-4), if the leader gets damaged, we can't swap positions to make it another four-ship (2-1-3-4).
The utmost we can do is to check whether the leader is still capable of maneuvering (which unfortunately is still "true" from IL-2's point of view even when the plane is inevitably spiraling to ground) and if not, remove the plane from the formation.
A series of tests involving 3- and 4-ship formations with fighters, twin-engine bombers, and four-engine bombers, yielded disappointing results.
At each position "swap" inside a flight, the whole formation breaks apart.
Fighters and twin-engine bombers manage to rejoin some sort of "random" formation (the pattern simply is wrong as all offsets get messed up).
Four-engine bombers never ever find back to any sort of formation, they will start spreading all across the map.
Mike