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.ArrayList; 23 import java.util.Random; 24 25 import org.hedgewars.hedgeroid.frontlib.Flib; 26 27 public final class TeamIngameAttributes { 28 public static final int DEFAULT_HOG_COUNT = 4; 29 public static final int[] TEAM_COLORS; 30 31 static { 32 int[] teamColors = new int[Flib.INSTANCE.flib_get_teamcolor_count()]; 33 for(int i=0; i<teamColors.length; i++) { 34 teamColors[i] = Flib.INSTANCE.flib_get_teamcolor(i); 35 } 36 TEAM_COLORS = teamColors; 37 } 38 39 public final String ownerName; 40 public final int colorIndex, hogCount; 41 public final boolean remoteDriven; 42 TeamIngameAttributes(String ownerName, int colorIndex, int hogCount, boolean remoteDriven)43 public TeamIngameAttributes(String ownerName, int colorIndex, int hogCount, boolean remoteDriven) { 44 this.ownerName = ownerName; 45 this.colorIndex = colorIndex; 46 this.hogCount = hogCount; 47 this.remoteDriven = remoteDriven; 48 } 49 randomColorIndex(int[] illegalColors)50 public static int randomColorIndex(int[] illegalColors) { 51 Random rnd = new Random(); 52 ArrayList<Integer> legalcolors = new ArrayList<Integer>(); 53 for(int i=0; i<TEAM_COLORS.length; i++) { 54 legalcolors.add(i); 55 } 56 for(int illegalColor : illegalColors) { 57 legalcolors.remove(Integer.valueOf(illegalColor)); 58 } 59 if(legalcolors.isEmpty()) { 60 return rnd.nextInt(TEAM_COLORS.length); 61 } else { 62 return legalcolors.get(rnd.nextInt(legalcolors.size())); 63 } 64 } 65 withColorIndex(int colorIndex)66 public TeamIngameAttributes withColorIndex(int colorIndex) { 67 return new TeamIngameAttributes(ownerName, colorIndex, hogCount, remoteDriven); 68 } 69 withHogCount(int hogCount)70 public TeamIngameAttributes withHogCount(int hogCount) { 71 return new TeamIngameAttributes(ownerName, colorIndex, hogCount, remoteDriven); 72 } 73 74 @Override toString()75 public String toString() { 76 return "TeamIngameAttributes [ownerName=" + ownerName + ", colorIndex=" 77 + colorIndex + ", hogCount=" + hogCount + ", remoteDriven=" 78 + remoteDriven + "]"; 79 } 80 } 81