You have to set your Defense Team in Training Grounds before anything. This way, when your city is under attack, you will have the best formation considering the boosts you have aquired so far.
During City Defense, your leader engages the enemy along with Defender Heroes and Brigades you have set as the Defense Team in Training Grounds. If both your Leader and Defender Heroes are unavailable, the remaining Heroes and Brigades in your City will be deployed automatically to engage the enemy.
How to set your Defense TeamEdit
Choosing Type of Troops and HeroesEdit
An important thing to look at when your are setting your defense team is what type of troops/heroes you will choose (cavalry/ranged/infantry). It depends on which of them has stronger effects at your city (this depends on your talents, gear and research). Go at Citty Effects (Leader's main page) > Soldier Type Boost. For example, if Ranged has better ATK, DEF and HP than other types of troops, when choosing heroes and brigades, you better choose ranged heroes and brigades.
Each hero has its own boost that affects either Army qualities or Brigade qualities, and the higher the Hero grade, the better the boosts. Hero skins and runes also improves hero boosts. You can see how heroes affects Army/Brigades qualities by looking the blue numbers under <Leader deployed> "army effect". Choose Hero that gives higher blue numbers (for the types of troops you are using, of course).
To choose your troop types, go for the same types as heroes, since those are the ones that have best boosts. If you have a hero that giver Infantry boosts, for example, choose mostly infantry troops so the boost is useful.
The best way to set up your troop type ratio is to deploy 0 troops of the type you have minimal boosts. Those are the ones you will be reinforced if you get rallied (we will explain in choosing formation). Then, chose a lower ratio for the type you have second best boosts, and the higher ratio for the type you have the best boosts.
The army formation determine which troop type goes in frontline (those protects the rest of the army) and which troop type goes in the back, during City Defense.
Choose your army formation based on the troop type you didn't deploy any troop, and then you ask for guild members to reinforce you with this type of troops. This way, their troops will take the first line and will protect yours. Their losses are small compared to yours if you take the first line.
Keep in mind that there is an sequence established by the game that determines that infantry always goes ahead of cavalry, and cavalry always goes ahead of ranged (which goeas ahead of infantry). This means, for example, that if you set Eager Berserkers (which is an infantry formation) to be your Army Formation, the second line of defense will be cavalry, and back line will be ranged. Another example: if you set Ready Sharpshooters to be your front line, the second line will be formed by infantry, and the back line by cavalry.
This is important because if you want to keep the max amount of your troops in the back, and the minimum amount of troops in the front, you have to take this into consideration.