mob
proc
chase1()
chasing=0
if(dead)
walk(src,0)
walk_to(src,0)
icon_state="dead"
aware=0
else
for(var/mob/them in view(scope))
if(!them.dead&&!them.enemy&&!them.npc)
chasing=1
if(get_dist(src,them)>scope)
walk(src,0)
walk_to(src,0)
else if(get_dist(src,them)<=scopeattack&&!them.enemy&&!them.npc)
walk(src,0)
walk_to(src,0)
dir=get_dir(src,them)
attack()
else
walk_to(src,them)
if(!aware)
aware=1
if(size==3232) healthbar3232()
else if(size==9696) healthbar9696()
if(goblin||goblinspikes) them << 'goblin.ogg'
break
spawn(5)
walk(src,0)
walk_to(src,0)
if(!chasing)
if(aware)
if(size==3232) healthbar3232delete()
else if(size==9696) healthbar9696delete()
aware=0
chase1()
Problem description:
Lately I have started to notice a delay when testing my project, and have identified this as the problem. This proc is for AI mobs in-game. It makes them continuously check their surroundings for other mobs, and act accordingly depending on the outcome of their scan using for(). The quantity of enemies is currently in the hundreds, and the delay is now quite noticeable. If I don't do something about it, the delay will increase, burdening the game further.
Are there better ways to make a procedure like this? Is it possible to have a mob continuously check for other mobs without the contribution to delay?