So, first of all, the above is the "true surrender" mode, as requested by SolariusScorch.
I am still working on the "anti bug hunt" mode, which will be something different... these 2 are not to be confused.
How the surrender mode works:
If during enemy turn all enemy units that are still standing (i.e. are not dead, are not unconscious and "have not fled"**) either panic or berserk... and all of them are capable of surrendering (the new "canSurrender: true" flag), the battle game automatically ends... in a very similar fashion to what happens with psi-capture.
If at least one of the remaining units didn't panic or berserk (this can happen even with morale=1), no surrender.
If at least one of the remaining units is not capable of surrendering (by default nobody is capable, mod needs to define that), no surrender.
** fled units are the ones who you haven't killed in the first part of a 2-part mission (e.g. TFTD base attack)
Automatically surrender when panicking is less than ideal, but - baby steps
As requested by SS.
How does it work, exactly? Are units which surrender stunned, or do you have to kill/stun everyone who's not surrendering before the rest surrenders?
No, they are not stunned.
Yes, you have to kill/stun everyone who is not surrendering... only if all remaining standing enemy units surrender, mission ends.
No need to penalize this, you should get full capture score.
Over my dead body
I wanted to give 0 points actually, but that leads to some other problems.
No work, no score.
EDIT: and you actually get more points now, because normally you would get minus points for killing/stunning them, right?
Objection - the enemy has no way of knowing that. How about use simple outnumbering rules (surrender only if the player has more conscious units than AI)?
It's impossible to make good rules for automatic surrender... the current one is acceptable IMO, because it almost never happens (unless you start tweaking bravery stats).
All these more complicated rules belong to the "anti bug hunt" mode, which can be more forgiving to false positives, since it doesn't end mission automatically... only tells you where the bugs are hiding (approximately).