Here's some more detail on the way it works now. Please chime in with recommendations if you think there seems to be something wrong with it.
Alien does their usual check for psi-attack or blaster-launch.
Then it uses a modified version of the sniper-code that uses an actual visibility check of their friends and doesn't cheat like the last version. Not cheating obviously makes it weaker in that sense.
Another modification is that when there's several potential targets the closest is preferred instead of a random one.
After that everything is entirely new code.
The first part is what I'd call the line-of-fire-checking-part. It looks up all tiles in range with enough TU reserved to still do an attack from where it can get a line of fire to x-com-soldiers. There's a huge score-bonus if that soldier is currently visible to a friend. It also traces back from all x-com-soldiers to get a divisor for how often it would be in their line of fire. Civilians get drastically reduced score for that. (I shall also do that for the sniper, target-selection I just realized).
So tiles from which many x-com-soldiers could be shot at will be preferred.
If no LOF was found, path-finding to that tile will be skipped since path finding is way more expensive than LOF-checking and we don't want to do it unnecessarily.
The path-finding is used to determine a score-factor based on distance to the preferred tile and also to make sure we don't pass on an unreachable tile as this results in an endless-loop.
There's 3 possible scenarios. The simplest one is the one where the unit finds a tile with a higher score in it's range. Then it simply just goes there.
Scenario 2 is that it realized it's already standing on the best tile in range. Then a check is performed to find the x-com-unit that is in lof of the most aliens. If at least 2 aliens can see the most visible one, the alien closest to it will be ordered to walk towards it. It basically becomes a spotter for the others. Note that none of that happens when there's no Lof. So you can't lure the aliens in an alley to set up your own traps.
If less than 2 aliens have a lof the unit will just stay where it is and face in the direction of the closest enemy is has lof to. Note that BA_TURN was not implemented before so I had to do it. AI couldn't turn without moving before. It was basically 1 line of code that was simply missing.
Scenario 3 is when the alien didn't find any tile to get a lof from.
In this case there's a 2 step process for what it does instead. First it asks it's friend who has the best LoF. If none of the friends does have any lof either, it asks them who can see the most tiles. (I had to change the code for that too, as this was only tracked for x-com-units but not aliens. And then I had to make sure the aliens don't reveal the map for the player, as this was done in the same function that stores the visible tiles to the unit.)
Whichever it was, it then will carefully (saving enough TUs for aimed) walk towards their position. In all the determinations of where to go there will be a check to avoid standing directly in the line of fire of other aliens. They still tend to end up quite close together, which makes them a good target for AoE. If you can find them before they kill you, that is.
I've done two test-battles. One of them went way better than the other. Having a lot of cover, in this case no less than 4 buildings, helped tremendously. I got really close to a pack of 4 aliens while getting there unseen.
I think the whole "move towards friend"-idea is probably mistaken. It discards other good opportunities and leads to vulnerabilty against AoE. My initial idea was to calculate a generalized score for everything. But that was hard to handle. So I went to this "look at my friends"-idea instead.
Now I'm thinking instead of combining the scores, I calculate two separate ones. When the first one is above zero it always wins. But if not, then the other will be a fallback-score. And that one could actually be about hiding. It still could consider visibility, how good it is visible for enemies, proximity to friends and also enemies in some way.
So the idea would be: If the X-Com soldiers expose themselves, we get into position to snipe them, send a spotter and then fire at them from all angles. But if the X-Com soldiers hide themselves, we do the same and let them come to us.
I realize that this is vastly different from my initial idea of how the aliens should play and really close to what Vakrug said from the beginning.