-Use the following strategy to fight an outnumbered foe at your settlement. If you know that you cannot defend your walls because there is too much ground to cover and you forces will be too thin to stop them, put all your armies in the central plaza of the city. According to their location, put your light infantry blocking the path of where they would go after the walls break through. Remember that you want to make a small chokepoint so that they can fight only one way and not surround you. After that, place your heavy infantry behind the light infantry and put your cavalry on the flanks so that you can attack them at the sides. When they attack and are charging at you infantry, order all the infantry (including heavy infantry) to charge. Then, have your cavalry cut the enemy's retreat and attack their flanks. If done right, their front and rear will be attacked, allowing you to crush them. Note: This cannot be done against human players.
-Always have at least two units in your settlement garrison that can form a phalanx. The more the better, but two is the minimum you should have if you want to keep your settlements safe from attack. Mercenary Hoplites are available to all factions and are very effective at defending settlements. From where the enemy breaches the walls (be it through the gate or from the walls), there will usually be two roads leading from their position to the middle of your settlement. The enemy will divide their forces to send down both these roads. By placing your phalanx troops in the center of the road, backed up by other infantry, you can create a wall of pikes that cannot be flanked. Any unit that is not also in phalanx formation will be reduced to a small group of routing cowards in no time, even elephants. If you find that the enemy has many phalanx troops, do not worry. Place your phalanx wall slightly further back in the center of the settlement. Place a unit of cavalry, preferably heavy cavalry, in a position so that when the enemy phalanx emerges into the center of the settlement, their flank becomes exposed. After that, smack your cavalry into the flank and the unit will be destroyed in seconds. Timing is essential in this strategy. If you charge too soon, your cavalry will end up being mobbed by enemy troops. If you charge too late, the enemy can maneuver towards your cavalry. Even if the enemy has overwhelming forces, you can guarantee that even if they do manage to wipe out your garrison, their own force will be so badly damaged that they probably will not be able to hold the settlement for long.