I think it should work with formations, yes, although there would need to be a condition routed/not routed on every troop, so that you would not be able to put routed troops back in formation. I might add it later, as well as factors from party morale. First release is to tune the basic system and see what other factors would benefit it.
It would be fun to have different factions have different bonuses/penalties to cohesion, yeah. It would have to be done by looking at the parties involved I think, like the world-map morale, so far everything I've done is just at the level of the current battle.
Battle Morale, detailed explanation
Cohesion
Both sides in battle has a cohesion rating, the average health of the army. For example ten fresh troops have 100% cohesion. If two are killed, the cohesion rating drops to 80%. If four of the remaining eight are wounded to 50% health, the cohesion rating drops to 40%. The cohesion rating is continuously being tracked, and in general lower rating will cause the troops to rout and flee. A group of peasants has the same cohesion as a group of knights to start with, but because knights have more hitpoints and better armor, the peasants will lose cohesion much faster, and therefore run from the fight much sooner.
Bravery Bonus
If the player character is actively participating in battle and killing many enemies, his troops are inspired by his bravery and are less likely to abandon him. The cohesion rating of the player's troops receives a bonus equal to the number of enemies killed by the player in the ongoing battle.
Morale Check
Both sides have morale checks every 10 seconds. If the cohesion is below 80%, a check is made to see if the morale wavers. The chance of that happening is 5% at 80% cohesion up to 85% at 0% cohesion. So that as the battle goes on and cohesion of both sides drops due to wounds and casualties, morale of troops starts to waver more and more, as they become reluctant to continue the bloodbath.
Fleeing Troops
If the morale wavers, each troop decides whether to flee or not. The decision depends on their health. Those with full health will not flee (0% chance), and heavily wounded are more likely to flee (at 1% life the chance to flee is 33%). Player's Leadership score is a slight bonus. Overall this effect is small, only few wounded troops are likely to flee the battle every so often. The exact formula is for the chance of fleeing is
1/3 * (100 - ([troop's health] + [player's leadership]))
Routing
If the cohesion of one side becomes greater than the cohesion of another by 40 or more, the losing side is routed. A check for this is made every 5 seconds. This effect allows powerful blows to one of the sides, such as knight charges or archer volleys to rout the enemy. Or in case of an uneven matchup, when one side is easily winning the battle, the losing side will be rounted before they are all killed.
Once one of the sides is routed, every troop makes the decision to run or keep fighting. It is very similar to the fleeing decision, but with much greater chances of routing, even for troops with full health. Player's Leadership value is a significant bonus in this case.
The exact formula is for the chance of routing is
100 - (1/3*[troop's health] + [player's leadership])
Battle Cry
The player can attempt to rally his routed troops with a Battle Cry (press Y) every 60 seconds. Every troop makes a decision whether to rejoin the fight at the player's call or not, depending on his health. Those with full health will always rejoin the battle while heavily wounded troops are much less likely to do so. The player's Leadership level is a bonus in this case. The AI controlled troops will also rally periodically in battle.
The exact formula for chance to rally is
[troop's health] + [player's leadership]
Reinforcements
When reinforcements arrive in battle, they raise the cohesion of their side by virtue of new fresh troops being introduced, and are therefore important to keep an army from routing. The player can call for reinforcements (press U) in battle every 100 seconds, if there are fresh troops avalible in his party they will arrive shortly. However the enemy will also be reinforced at that time. In addition, I've made the automatic reinforcements arrive slightly sooner, when the remaining number of troops is not quite as low. And I allowed for one extra wave of reinforcements before the battle has to start anew.
Troop Health
Knowing troop health and cohesion can be important to be more aware of the situation on the battlefield, or to see if that valuable troop of yours is going to need your help if he is to come out of the melee alive. The player can display the health status of his troops, his bravery bonus to cohesion, and the cohesion of both sides at any time (press T). Green markers are shown above troops with 70%-100% health, yellow markers for 30%-69% health, and red markers are shown for heavily wounded troops and bodies of those fallen in battle.