project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/TeamIngameAttributes.java
author Medo <smaxein@googlemail.com>
Sat, 18 Aug 2012 00:47:51 +0200
changeset 7508 763d3961400b
parent 7485 0481bd74267c
child 7584 7831c84cc644
permissions -rw-r--r--
Hedgeroid: Frantic scrabbling toward the deadline - Added activities for weapon/scheme editors (unfinished) - Completed tablet version of netroom activity - Added map preview - Fixed default team files having the wrong names - Restructuring - Updated frontlib JNA bindings to respect the latest frontlib changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.Datastructures;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
import java.util.ArrayList;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
import java.util.Random;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
     6
import org.hedgewars.hedgeroid.frontlib.Flib;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
     7
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
public final class TeamIngameAttributes {
7485
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
     9
	public static final int DEFAULT_HOG_COUNT = 4;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    10
	public static final int[] TEAM_COLORS;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    11
	
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    12
	static {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    13
		int[] teamColors = new int[Flib.INSTANCE.flib_get_teamcolor_count()];
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    14
		for(int i=0; i<teamColors.length; i++) {
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    15
			teamColors[i] = Flib.INSTANCE.flib_get_teamcolor(i);
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    16
		}
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    17
		TEAM_COLORS = teamColors;
0481bd74267c Hedgeroid:
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    18
	}
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
	public final String ownerName;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
	public final int colorIndex, hogCount;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
	public final boolean remoteDriven;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
	public TeamIngameAttributes(String ownerName, int colorIndex, int hogCount, boolean remoteDriven) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
		this.ownerName = ownerName;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
		this.colorIndex = colorIndex;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
		this.hogCount = hogCount;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
		this.remoteDriven = remoteDriven;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    31
	public static int randomColorIndex(int[] illegalColors) {
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
		Random rnd = new Random();
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
		ArrayList<Integer> legalcolors = new ArrayList<Integer>();
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
		for(int i=0; i<TEAM_COLORS.length; i++) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
			legalcolors.add(i);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
		}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
		for(int illegalColor : illegalColors) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
			legalcolors.remove(Integer.valueOf(illegalColor));
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
		}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
		if(legalcolors.isEmpty()) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
			return rnd.nextInt(TEAM_COLORS.length);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
		} else {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
			return legalcolors.get(rnd.nextInt(legalcolors.size()));
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
		}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
	public TeamIngameAttributes withColorIndex(int colorIndex) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
		return new TeamIngameAttributes(ownerName, colorIndex, hogCount, remoteDriven);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	public TeamIngameAttributes withHogCount(int hogCount) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
		return new TeamIngameAttributes(ownerName, colorIndex, hogCount, remoteDriven);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
	@Override
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
	public String toString() {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
		return "TeamIngameAttributes [ownerName=" + ownerName + ", colorIndex="
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
				+ colorIndex + ", hogCount=" + hogCount + ", remoteDriven="
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
				+ remoteDriven + "]";
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
}