First, let's understand how a unit works
This is a fighters stats:
HP 90
Attack 3
Carry 25
Range 1st row
Position 1st row
Speed 8
Upkeep 1 per hour
Let's take it line by line:
HP: These are how much damage the unit will take before it dies.
Attack: This is how much damage a unit deals each time it attacks (See the unit damage modifier thread for more info. You will deal more or less than this number based on who you are hitting)
Carry: This is the amount of each resource the troop can take. It is divided for things like Iron and Gold.
Range: This unit can only attack units in this, or lower, rows. It cannot attack units in rows behind it, until that row is empty.
Position: This is the row the unit occupies (see above)
Speed: How fast it moves on the overland Map
Upkeep: Food cost per hour.
More on Range and Position:
Think of arranging all the troops into 4 ranks. In the first rank is swords, hoplites, gladiators, cavalry. Second is archers, knights, carts. Third is helopolis, Catapults, and Towers. Fourth is buildings.
If something has 'range first rank' it can ONLY target those first rank units listed above. It can't attack any of the second rank units unless all the first rank units are dead.
If a unit has 'second rank' range, it can target either of the first two ranks, but CANNOT target the third rank until all troops in ranks 1 and two are dead. Once all troops in the target rank are dead, you can target only the rank directly behind it. If all those troops are also all dead, you can target the rank behind that, and so on.
Troops with position above 1st rank are less likely to be attacked in combat. Buildings are Always attacked last (But not towers)
Unit Attack Priority
In addition to the above restrictions on what a unit CAN attack, there is also the question of what it WILL attack. Each unit will *always* attempt to attack the opposing unit that it deals the most damage to. That's the most total damage, and has nothing to do with if it is tactically sound
EDIT: This has changed just a little bit. Previously, units will attack at random as described above, and choose a new random target each time they attack. Now they choose a target, and keep attacking that target until that stack is dead, and then new targets are chosen. This makes previously loss-less fights (where the damage is spread out evenly) to be high casualty raids. For example, a city that deals 1000 damage to 100 level 5 cavalry used to kill 1 or 2. Now it'll kill 5 pretty much every time.
Units will attack whoever they can hurt the most in combat, and ignore the rest
Splash Damage
Some units do splash damage. This means they hit more than one stack at a time. Archers hit 3, towers hit 4 (base) and Helopolis hit 5. The additional targets for these units follows the targeting above. Note that towers deal more damage to archers than swordsmen. So if you attack with both swords and archers against an opponent, expect for your archers to die a lot. Don't send archers on raids against towered cities! Note that the Spiked Barricade upgrade increases the number of splash targets for all your buildings.
EDIT: The technology "Hanzo Formation" Helps your gladiators, swordsmen, and fighters shrug off some splash damage. This reduces the damage dealt to targets beyond the first. So if an archer attacks three targets, target 1 recieves 100%, target 2 receives 95%, and target 3 receives 95% (Hanzo level 1). This is a very good tech, especially for Gladiator based armies. This does NOT change the targeting priority of archers or other splash damage units. They will target just as if Hanzo Formation didn't exist.
