ID:1733388
 
So I'm trying to make monsters respawn. Thing is atm its not really efficient. It creates a list consisting of every single mob. What is a better way to go about this?
mob/ai
var
species
genus
class

proc
spawnState()
var/obj/ai/respawner/aiRespawn = new /obj/ai/respawner
aiRespawn.aiSpawn = home_loc
aiRespawn.aiType = src.type
aiRespawn.aiGenus = genus
aiRespawn.aiSpecies = species

Del()
spawnState()
.=..()

var/list/aiTypes = list()
obj
ai
respawner
var
aiSpawn
aiType
aiGenus
aiSpecies


New()
set waitfor = 0
sleep(1200)
GenusC()
new aiType(aiSpawn)



proc
GenusC()
if(aiGenus == null) return
else
aiTypes = list()
for(var/a in typesof(/mob/ai/))
aiTypes += new a

if(prob(5))
for(var/mob/ai/b in aiTypes)
if(aiGenus == b.genus && b.class == 2)

aiType = b.type
aiTypes = list()
return


When the mob is going to be deleted it runs the spawn proc. Mobs in the same genus can spawn in the same spot, if their class is 2 they have a low chance of spawning though. To do that I have to create a list of every AI mob for every single respawn object. Will that create unnecessary lag? What is a better approach?

I realize I'm continually emptying and filling a global list. Would having the list be a tmp var and inititualizing it at start be all I needed to do?