project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/TeamInGame.java
branchhedgeroid
changeset 7857 2bc61f8841a1
parent 7584 7831c84cc644
equal deleted inserted replaced
7855:ddcdedd3330b 7857:2bc61f8841a1
       
     1 /*
       
     2  * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
       
     3  * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU General Public License
       
     7  * as published by the Free Software Foundation; either version 2
       
     8  * of the License, or (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18  */
       
    19 
       
    20 package org.hedgewars.hedgeroid.Datastructures;
       
    21 
       
    22 import java.util.Collection;
       
    23 import java.util.Comparator;
       
    24 
       
    25 /**
       
    26  * A team with per-game configuration. This is similar to the frontlib "team" structure,
       
    27  * except that it does not include weaponset and initial health, which are handled on a
       
    28  * per-game basis in the UI, but per-hog in the frontlib.
       
    29  */
       
    30 public final class TeamInGame {
       
    31 	public final Team team;
       
    32 	public final TeamIngameAttributes ingameAttribs;
       
    33 	
       
    34 	public TeamInGame(Team team, TeamIngameAttributes ingameAttribs) {
       
    35 		this.team = team;
       
    36 		this.ingameAttribs = ingameAttribs;
       
    37 	}
       
    38 	
       
    39 	public TeamInGame withAttribs(TeamIngameAttributes attribs) {
       
    40 		return new TeamInGame(team, attribs);
       
    41 	}
       
    42 	
       
    43 	public static int getUnusedOrRandomColorIndex(Collection<TeamInGame> teams) {
       
    44 		int[] illegalColors = new int[teams.size()];
       
    45 		int i=0;
       
    46 		for(TeamInGame team : teams) {
       
    47 			illegalColors[i] = team.ingameAttribs.colorIndex;
       
    48 			i++;
       
    49 		}
       
    50 		return TeamIngameAttributes.randomColorIndex(illegalColors);
       
    51 	}
       
    52 	
       
    53 	public static Comparator<TeamInGame> NAME_ORDER = new Comparator<TeamInGame>() {
       
    54 		public int compare(TeamInGame lhs, TeamInGame rhs) {
       
    55 			return Team.NAME_ORDER.compare(lhs.team, rhs.team);
       
    56 		}
       
    57 	};
       
    58 }