Civilians use the same AI as aliens.
Good hint. I was wondering why they just stood there and did nothing. My AI simply didn't know what to do with them. So I needed to let them be controlled by regular AI instead.
I tried some different approaches yesterday, broke an important part of my code thinking I didn't need it and now am trying to find a more performant replacement.
First thing I tried was doing a lof-evaluation for the entire map. Well, no. It's way too slow.
I also realized that doing lof-calculations in both directions is not needed, as except for some fringe cases it usually should be the same both ways.
Then I wanted to make safety more valuable than being able to lof more than one opponent and divided the position-score by the number of lof from it. The advantage was that the aliens then took really neat covered positions.
The disadvantage was that the backup for the spotter was really shitty.
Then I wrote a really cheap (since no pathfinding is needed) way for hiding in cases where no lof can be obtained anyways. Using that same algorithm when TU's are too low to still fire as a means for hiding after shooting, this pretty much lead to the castle-defense-behavior that was described here earlier.
It works particularly well when fighting over buildings with windows.
I've seen two major disadvantages with it. For UFOs, especially with a narrow design like the large scout, it's not that great as they can't look outside and tend block each other and thus could be singled out.
The other one is that it makes the entire spotter/sniper-dynamic completely useless. It also allows me to safely run my units through open terrain as long as it's far enough from buildings.
Regardless of efficiency, it feels a bit too predictable and dull to fight against.
What I also tried was charging a unit that was already lofed by one of my units with everything. Charging a lofed unit is a lot saver than charging a hidden unit. Simply because we are pretty much guaranteed to get into firing-range on our turn, which allows to pelt it with everyone. And as opposed as to the single-spotter-approach, the loss of our spotter isn't as bad.
The big problem here is that my original approach to charging a unit was quite costly in terms of pathfinding. I had already removed that costly code as it was just ugly and if you pathfind directly on the unit you want to go to, it breaks once it gets into vision. And by breaks I mean it takes a really long time and then just has no result anyways because you obviously can't find a path to a tile that's blocked.
Workaround was to try and pathfind to tiles near the target-unit. But that can be even slower if tiles are tried and then discarded anyways because they might also be blocked.
I think I might have to dabble into pathfinding itself, which is a bit of a scary prospect. What I want is a pathfinding function, that, if it couldn't get a path to the destination, returns whatever path brought it closest to the target and maybe also ignores when a path is blocked by a unit instead of a solid obstacle.
That way I wouldn't need hacky and very processing-time-intense workarounds to basically achieve the same as that function would. I think it would reopen possibilities I have discarded for being too time intense.