For the line of battles, I'm using the formation AI from The Hedge Knight. I wont change it anytime soon since I don't have the skills yet, and I have more than enough on my plate already.
Note that for formation, we can define some "formation pattern", but not how the AI will actually go from one to the other. This is not moddable. We can just hope the formations we defined are correctly placed and the AI will manage them well.
What were the units involded in the melee attack?