mob
var
BossN
tmp/Boss=0
EnemyNPC
New()
. = ..()
spawn()
move()
proc
move()
while(src)
var/player_found = 0
for(var/mob/P in oview(6))
if(P.client&&!src.Frozen)
player_found = 1
step_towards(src,P)
if(!player_found)
if(src.Boss||src.QuestNPC)
src.SpAtt()
sleep(10)
sleep(5)
SpAtt()
for(var/mob/P in oview(7))
if(P.client)
src.target=P
if(src.rank=="Mega"||src.rank=="Mega Lv-2"||src.rank=="Mega Lv-3")
random=rand(1,4)
if(random==1)
src.SpAttack1P()
if(random==2||random==3)
src.SpAttack2P()
if(src.rank!="Mega"||src.rank!="Mega Lv-2"||src.rank!="Mega Lv-3")
src.SpAttack1P()
Bump(mob/M)
if(ismob(M))
if(M.client)
if(src.canattack)
AttackP(M)
Problem description:
This code is using a lot of CPU, I don't know why though. Dream Daemon already crashed a few times for unknown reasons. DD says it's running in Task Manager, but when I try to open it from my taskbar, it doesn't work. I check the Task Manager for the CPU usage of DD itself and it's usually around 40-45% then, with a memory usage of 200+- MB and going up. I ran a profile check and it gave me those results:
Is there anything so resource intensive in that part of code? If so, how would I make it more efficient?
Thanks in advance!
One thing I'm noticing, is that you aren't preserving any of the AI state at all. You are hunting for new targets every frame, even after you've found a target and started hunting it.
Preserve the state between calls of move(), also, you might want to disable any mobs that aren't within a certain range of players using some sort of a system that activates hostile enemies when a player enters a certain range of said enemy. This will cut down on target-seeking time a lot.
I really recommend you don't use an unterminated loop like you are, though. I'd recommend using spawn() to call the AI behavior from within the AI loop while the mob is active. The fact that you are sleep()ing is what's causing your Real Time CPU use to be so insanely high.