VERY roughly:
1. if a unit can do a psi attack, and it has a semi-decent chance to succeed... it will use psi
2. otherwise, if a unit has a blaster launcher and enough waypoints... it will use a blaster
3. otherwise, in OXCE only, if a unit is a sniper and there are some spotted xcom units, it will try sniping
4. otherwise, if a unit has a grenade, and it's worth using, it will try using it
5. otherwise if a unit has any melee or ranged weapon:
- it will calculate melee attack efficiency based on various parameters and roll dice... if rolled, it will try melee first and ranged second, otherwise it will try only ranged
- if there are two ranged weapons, it will use the one that has ammo and a snap shot mode; if both have snap shot mode it will use the quicker one (less TU to shoot)