project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Teamlist.java
changeset 7508 763d3961400b
parent 7504 ed1d52c5aa94
child 7550 3c4b4cb40f40
equal deleted inserted replaced
7504:ed1d52c5aa94 7508:763d3961400b
     1 package org.hedgewars.hedgeroid.netplay;
       
     2 
       
     3 import java.util.Collection;
       
     4 
       
     5 import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
       
     6 import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
       
     7 
       
     8 import android.util.Pair;
       
     9 
       
    10 public class Teamlist extends ObservableTreeMap<String, Pair<TeamInGame, Long>> {
       
    11 	private long nextId = 1;
       
    12 	
       
    13 	public void addTeamWithNewId(TeamInGame team) {
       
    14 		put(team.team.name, Pair.create(team, nextId++));
       
    15 	}
       
    16 	
       
    17 	public int getUnusedOrRandomColorIndex() {
       
    18 		Collection<Pair<TeamInGame, Long>> teams = getMap().values();
       
    19 		int[] illegalColors = new int[teams.size()];
       
    20 		int i=0;
       
    21 		for(Pair<TeamInGame, Long> item : teams) {
       
    22 			illegalColors[i] = item.first.ingameAttribs.colorIndex;
       
    23 			i++;
       
    24 		}
       
    25 		return TeamIngameAttributes.randomColorIndex(illegalColors);
       
    26 	}
       
    27 }