ID:2423028
 
Code:
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?
Here's an example on how i do it, if it helps.

proc/PVM(mob/A,mob/B,list/S=new)
if(!A || !B || (!A.client && !B.client) || A.combat || B.combat){return}
var T = A.GetLevel() >= B.GetLevel() ? 1 : 0
var mob/X, mob/Y, DMG, ACC, DEF, F // TIME
A.combat = TRUE
B.combat = TRUE
S.Add(A,B)
S << "MH: [B.MaxHit(B.slashing.level,B.equipment.GetStrength())]"
S << "[A.Name()] <u>vs</u> [B.Name()]</b>"
for()
T=!T
switch(T)
if(0){X=A;Y=B}
if(1){X=B;Y=A}
S << "\n<b>[X.Name()]</b>'s Turn!"
Yep byt you have just a two opponents, mobA nad mobB, but what if I have a lot of them? How grab them from list and ho check with one is fastest?
Using a single for(), you could add both teams together and sort the list via a stat every complete-iteration of the loop and just loop through a single list that has both teams sorted.