package Playercolor import NoWurst import Force import Player import Wurstunit public constant PLAYER_COLOR_BLACK_AGGRESSIVE = ConvertPlayerColor(24) public constant PLAYER_COLOR_UNKNOWN1 = ConvertPlayerColor(25) public constant PLAYER_COLOR_UNKNOWN2 = ConvertPlayerColor(26) public constant PLAYER_COLOR_BLACK_PASSIVE = ConvertPlayerColor(27) constant LOOKUP = [ PLAYER_COLOR_RED, PLAYER_COLOR_BLUE, PLAYER_COLOR_CYAN, PLAYER_COLOR_PURPLE, PLAYER_COLOR_YELLOW, PLAYER_COLOR_ORANGE, PLAYER_COLOR_GREEN, PLAYER_COLOR_PINK, PLAYER_COLOR_LIGHT_GRAY, PLAYER_COLOR_LIGHT_BLUE, PLAYER_COLOR_AQUA, PLAYER_COLOR_BROWN, PLAYER_COLOR_MAROON, PLAYER_COLOR_NAVY, PLAYER_COLOR_TURQUOISE, PLAYER_COLOR_VIOLET, PLAYER_COLOR_WHEAT, PLAYER_COLOR_PEACH, PLAYER_COLOR_MINT, PLAYER_COLOR_LAVENDER, PLAYER_COLOR_COAL, PLAYER_COLOR_SNOW, PLAYER_COLOR_EMERALD, PLAYER_COLOR_PEANUT, PLAYER_COLOR_BLACK_AGGRESSIVE, PLAYER_COLOR_UNKNOWN1, PLAYER_COLOR_UNKNOWN2, PLAYER_COLOR_BLACK_PASSIVE] public function player.setColor(playercolor color) SetPlayerColor(this, color) public function player.getColor() returns playercolor return GetPlayerColor(this) public function int.toPlayerColor() returns playercolor return LOOKUP[this] public function playercolor.toInt() returns int var value = 0 for i = 0 to bj_MAX_PLAYER_SLOTS - 1 if LOOKUP[i] == this value = i break return value /** Returns the player that had this color *at the start of the game*. Does not respect SetPlayerColor. */ public function playercolor.getPlayer() returns player return players[this.toInt()] /** Returns the players who are currently using this player color. Respects calls to SetPlayerColor */ public function playercolor.getPlayers() returns force let matchingPlayers = CreateForce() for i = 0 to bj_MAX_PLAYER_SLOTS - 1 if players[i].getColor() == this matchingPlayers.addPlayer(players[i]) return matchingPlayers @test public function testToInt() PLAYER_COLOR_RED.toInt().assertEquals(0) PLAYER_COLOR_PEANUT.toInt().assertEquals(23) @test public function testToPlayerColor() assertTrue((0).toPlayerColor() == PLAYER_COLOR_RED) assertTrue((23).toPlayerColor() == PLAYER_COLOR_PEANUT) @test public function testGetPlayer() assertTrue(PLAYER_COLOR_RED.getPlayer() == Player(0)) assertTrue(PLAYER_COLOR_PEANUT.getPlayer() == Player(23)) @test public function testGetPlayers() // Test some Player package methods that this file depends on (players[0] != null).assertTrue() players[0].setColor(PLAYER_COLOR_RED) (players[0].getColor() == PLAYER_COLOR_RED).assertTrue() // Test getting forces of players. let force1 = PLAYER_COLOR_RED.getPlayers() force1.containsPlayer(Player(0)).assertTrue() players[1].setColor(PLAYER_COLOR_BLUE) players[2].setColor(PLAYER_COLOR_BLUE) let force2 = PLAYER_COLOR_BLUE.getPlayers() force2.containsPlayer(Player(1)).assertTrue() force2.containsPlayer(Player(2)).assertTrue() force2.containsPlayer(Player(3)).assertFalse() let p = players[5] assertTrue(p.getColor() == null) p.setColor(PLAYER_COLOR_AQUA) assertTrue(p.getColor() == PLAYER_COLOR_AQUA)