wander()
set background = 1
var/list/spots = oview(3,src)
for(var/turf/t in spots)
if(t.density) spots -= t
var/turf/spot = pick(spots)
walk_to(src, spot, 0, 0, 2)
My current AI's are very inefficient with resources. I'm currently developing a zombie survival game, and as you can imagine, there will be many zombies in the world, wandering around. I already have functions handling a check whether or not a player is near, deactivating the AI's
wander()
function until a player is close, as to conserve resources.The problem lies in the fact that even with only 50 AI's running and making an attempt to attack my character, the game CPU far exceeds 100, peaking at about 210.
I've narrowed down the problem functions to this
wander()
proc. I know that the constant checking of oview()
along with omitting the dense turfs under the for()
loop is causing the massive latency. I also know that this method is probably the most inefficient method of sorting through lists, but I honestly don't know any others.What could be done to improve this code here?
2. You shouldn't have to be calling wander() every tick, that would be pretty wasteful.
3. Are there really 50 enemies all chasing and attacking you all at once? Or maybe, there are 50 in the world but only a few in range at a time? They shouldn't be doing anything if a player can't see them, somewhat.