mob/Actor
var
tp
dex = 1
battle//debug
New(var/_name, var/_dex)
..()
if(_name) name=_name
if(_dex) dex=_dex
Battle
var
id
list/attackers = list()
list/defenders = list()
mob/Actor/curActor
New(var/list/_attackers, var/list/_defenders)
id = "Battle[(rand(1,9999))]"
attackers = _attackers
defenders = _defenders
GetActor()
proc/GetActor()
var/list/actors = attackers+defenders
//This part
for(var/mob/Actor/a in actors)
if(a.tp>=10)
curActor = a
break
a.tp+=a.dex
world<<"[a] - [a.tp]"
sleep(1)//debug
if(curActor)
world<<"Now is [curActor] Turn"
curActor.tp=0
curActor=null
else GetActor()
//////
mob/Actor/verb/_NewBattle()
src.dex=2 //debug
var/mob/Actor/A1 = new(_name="Slow Enemy", _dex=0.5)
var/mob/Actor/A2= new(_name="Enemy ", _dex=1)
var/mob/Actor/A3= new(_name="Fast Enemy 3 ", _dex=2)
battle = new /Battle(list(A1, A2, A3), list(src))
mob/Actor/verb/_EndTurn()
var/Battle/curBattle = src.battle
curBattle.GetActor()
Problem description:
Hello, i have question about performance, can anyone help me figure how to replace this ugly part where i use for() proc for taking a current Actor?
I'm sure i can replace this by using list and a little bit of math for calculate positions. Can anyone help me with this algoritm?
Maybe method with for loop is nice idea and ii don't have to change it?