ID:157362
 
Just wondering how this could be improved, or how it could be wrong seeing as I'm not at a point where I can test it:

Flexible Turn System:

Battle_Control_Basic
var
list
team_a = new
team_b = new
both_teams = new

New(list/playersa,list/playersb)

//place players on respective teams.
both_teams.Add(team_a, team_b)
for(var/mob/m in playersa)
team_a += m
for(var/mob/m in playersb)
team_b += m

//decide which players of either team goes first.
var/list/turn_order = new //determines what order turns are in
var/mob_with_lowest_speed
var/copy_of_both_teams = both_teams
while(turn_order.len < both_teams)
for(var/mob/m in copy_of_both_teams)
if(!mob_with_lowest_speed || m.speed < mob_with_lowest_speed)
mob_with_lowest_speed = m
turn_order += mob_with_lowest_speed
copy_of_both_teams -= mob_with_lowest_speed
mob_with_lowest_speed = null
//run through again determining order of players...

//now that team turn taking is determined, initiate turns in that order

turn_initiate(turn_order)


proc
turn_initiate(list/turn_order)
//to be continued....


Is this effective?

Also, how should I go from here?
Looping through playersa/b (which don't follow your naming conventions?) is unnecessary, as you could just add the lists directly to team_a/b.
'both_teams.Add(team_a, team_b)' should either be after the for loops, or it should be listing playersa/b.
'var/copy_of_both_teams = both_teams' should be defined as a list, and then have both_teams added to it. Otherwise BYOND gets flunky and treats them as the same list.
'while(turn_order.len < both_teams)' I'd do as while(copy_of_both_teams.len), but it should work like you have it.
mob_with_lowest_speed should be defined as a mob, and 'if(... m.speed < mob_with_lowest_speed)' should be checking their speed, not the actual mob.
It would probably be better to have turn_order defined on the datum, instead of passing it around.
In response to Falacy
Thanks-

Some of those mistakes I can easily see, and I see the redundancy of the code too :p

Also there's some silly mistakes that would have been weeded out with testing, but as for the list advice, that's great.

What do you mean turn order defined as a datum?
In response to Speedro
Speedro wrote:
What do you mean turn order defined as a datum?

Not as a datum... On the Battle_Control_Basic datum. Like where you have both_teams.
In response to Falacy
Ah, I see.


Also I'm not to familiar with swapping lists.

In my case, when the turn is over the person who went goes to the bottom of the list and everyone else is bumped up one. Are (n-1)! factorials able to be used? Would this even apply or am I being dumb? How would I go about this without retyping the line over and over if possible?

    proc
turn_initiate()
//for a quick test:
world << "It is [turn_order[1]]'s turn!"

//fill in this their options...

//onto ending turn:
//Not to clear on this:
turn_order.Swap(1,turn_order.len)
for(var/x = 1, x++)
var/value2 = turn_order.len - x
turn_order.Swap(x,value2)


Yeah, I really have no idea what I'm doing.
In response to Speedro
I would just remove and re-add whoever just went. That will put them at the end of the list.
var/mob/T=turn_order[1]
world << "It is [T]'s turn!"
turn_order-=T
turn_order+=T