Efficiency optimizations can come at a later stage, when I'm sure my AI setup works the way I want. So far I made a function to count all friendly units which match a given name using a loop, and it works (though when there are 2 Shards in game, periodic slowdowns are noticeable).
As for nils or empty strings or whatever returned instead of a unit name: currently they seem to crash lua and the AI stops (or at least the unit the queue of which contains that stops). So I have something like that (only build another factory if there are more than 3 times as much extractors as there are factories):
Code: Select all
local function ground_factory()
if countOwnUnits("mine")>(countOwnUnits("l_fact")*3) then
If I don't want to build the factory, I have to return some other valid unit name. I'd like to be able to return a nil or "" instead so the builder can just skip the item when it's not wanted. Currently I return the extractor which seems to be skipped if there are no unused metal spots anymore, but that doesn't seem like the best solution to me.