Problem description:
Good morning to all, the problem is that ia () is generating excessive consumption of resources of my pc.
this is de profile game:
Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
------------------------------------------------------ --------- --------- --------- ---------
/mob/enemy/New 7.047 2121.562 181.658 3
/mob/enemy/proc/combatIA 2181.531 2181.714 181.654 3
/obj/Del 8.149 8.149 8.202 4989
this is the code of my IA()
mob/enemy/New()
J_showbars(src)
J_update(src)
src.health=src.maxhealth
spawn(10) src.combatIA()
return ..()mob
ob/enemy
proc
combatIA()
while(src)
var/mob/closer = null
for(var/mob/M in oview(22,src))//Selecciona al objetivo más cercano
if(Frozen||froze||caught||captured||M.kawa||M.isdog||M.invisibility||M.NPC||Village==M.Village||istype(M,/mob/Animal/cat))
continue//estados
else
if(!closer)
closer=M
if(get_dist(M,src)<get_dist(closer,src))
closer=M
if(closer)
if(!Frozen&&!froze)
ai_check_dist(src,closer) //ataca si está a 1 cuadro
if(src.health>=(src.maxhealth*20)/100)//si esta a más de 30% de la vida:
walk_to(src,closer,1,3)
sleep(1)
if(prob(20)&&src.firing==0)
if(get_dist(src,closer) <= 1) ai_check_dist(src,closer)//si esta a menos de un cuadro ataca a tai
else jutsusIA(closer) //si no es asi :lleva a Jutsus.dm
else
if(prob(2))
health+=maxhealth*20/100
oview()<<"[src] regenera un 20% de su vida!!"
J_update(src)
else
walk_away(src,closer,10)//nuevo
if(prob(10))
if(istype(src,/mob/enemy/OSO))return
else Kawa(src)
spawn(20)walk(src,0)//nuevo
else //Si no hay nadie cerca, se cura lentamente.
if(health<maxhealth)
health+=(maxhealth*1/100)//se cura un 1% de la vida máxima
if(health>maxhealth) // si se pasa de curarse
health=maxhealth
J_update(src)
sleep(rand(4,6))
Thnaks for your help.
Ideally, you'd have the player activate the enemy when one comes into view of the other, then you'd set the enemy's target to that player and attack them from there, instead of constantly looking for players within a rather large view radius.