How does this work when there are multiple ambushers on the tile?
My observations from my current game seem to indicate that, contrary to all expectations, the game doesn't actually choose the best defender to take part in the combat. Instead it seems like the ambushers simply go in some specific, but not player-known, order. I had three ambushers on one tile, when two enemy units attempted to enter their tile. In the first combat, my Unit 2 took part and killed the enemy. In the second combat, Unit 2 again took part, and because he was severely weakened, he was defeated. Unit 3 then ambushed the second enemy and killed him. Unit 1 never even got a look in, despite the fact that he was the strongest of the three.
Per the standard rules of Civ combat, I'd expect that Unit 1 should have taken part in the first combat, and either Unit 2 or Unit 3 in the second (they were identical). As a result of this not happening, I unnecessarily lost a unit, and I'm struggling to explain why.
What happens is:
1) The 'attacker/unwitting ambushee' walks onto the tile not knowing the assassins are there.
2) The game detects a hidden ambush ready unit exists (3 of them)
3) Thus before the move function gets any further, the function is interrupted and the best defender, meaning unit with the best odds against the attacker, not necessarily the one with the best generic odds all around (perhaps some combat class factor made it possible to select the second unit first?) is 'revealed'.
4) At this point the revealed unit defends (though under special circumstances that instruct stealth combat modifiers and stealth strikes to apply for the defender and no first strikes, if there are any, to apply to either unit's benefit.)
5) In your example, that selected defender was unit 2. He killed the enemy.
6) At this point, Unit 2 is still revealed. Units 1 and 3 are still hidden.
7) Therefore when the second enemy walks in and attacks, Units 1 and 3 remain hidden and unseen because they will never reveal and ambush unless there are no other visible defense-capable units on the tile. Thus Unit 2, even heavily injured, being visible and capable of defense, is now a sitting duck target and is no longer gaining the stealth combat benefits either.
8)So normal battle takes place against Unit 2 and Unit 2 perishes in the fight. Then, as per normal, the combat ends with an attempt for the attacker to complete the move onto the tile.
9)Since there are still 2 hidden ambush-capable units on the tile, one more, Unit 3, reveals himself. And it sounds like he takes advantage of the wounded state of the unit that dispatched Unit 2, along with his fresh stealth combat modifiers and stealth strikes applying, and eats Unit 2's destroyer for breakfast. Here's to letting your wounded buddy get sacrificed as you get in position to pounce and eliminate any chance of harm to self!