package Player import NoWurst import Wurstunit import Unit import Annotations import String /** Use this array instead of Player() to avoid leaks */ public player array players public constant localPlayer = GetLocalPlayer() init initPlayerArray() @compiletime function initPlayerArray() for i = 0 to bj_MAX_PLAYER_SLOTS - 1 players[i] = Player(i) public function player.setGold(int val) this.setState(PLAYER_STATE_RESOURCE_GOLD, val) public function player.addGold(int val) this.addState(PLAYER_STATE_RESOURCE_GOLD, val) public function player.setLumber(int val) this.setState(PLAYER_STATE_RESOURCE_LUMBER, val) public function player.addLumber(int val) this.addState(PLAYER_STATE_RESOURCE_LUMBER, val) public function player.addState(playerstate state, int val) SetPlayerState(this, state, this.getState(state) + val) /** Clears the selection for the player, deselecting all widgets. */ public function player.clearSelection() if localPlayer == this ClearSelection() /** Get if Selection is enabled for local player. Returns always false for non-local player.*/ public function player.isSelectionEnabled() returns bool if localPlayer == this return BlzIsSelectionEnabled() return false /** Get if Selection Circle is enabled for local player. Returns always false for non-local player.*/ public function player.isSelectionCircleEnabled() returns bool if localPlayer == this return BlzIsSelectionCircleEnabled() return false /** Enable or disable player selections.*/ public function player.setSelectionsEnabled(bool enableSelection, bool enableSelectionCircle) if localPlayer == this BlzEnableSelections(enableSelection, enableSelectionCircle) /** Disable UI control for the player */ public function player.disableUserControl() this.setUserControl(false) /** Enable UI control for the player */ public function player.enableUserControl() this.setUserControl(true) public function player.getController() returns mapcontrol return GetPlayerController(this) public function player.getCurrentSupply() returns int return this.getState(PLAYER_STATE_RESOURCE_FOOD_USED) public function player.getGold() returns int return this.getState(PLAYER_STATE_RESOURCE_GOLD) public function player.getId() returns int return GetPlayerId(this) public function player.getLumber() returns int return this.getState(PLAYER_STATE_RESOURCE_LUMBER) public function player.getMaxSupply() returns int return this.getState(PLAYER_STATE_RESOURCE_FOOD_CAP) public function player.getName() returns string return this.getName(false) /** Reforged names have a number attached after a hash tag, like Bob#1234 */ public function player.getName(boolean removeHash) returns string return removeHash ? GetPlayerName(this).substring(0, GetPlayerName(this).indexOf("#")) : GetPlayerName(this) public function player.getSlotState() returns playerslotstate return GetPlayerSlotState(this) public function player.getStartLocation() returns vec2 return vec2(GetPlayerStartLocationX(this), GetPlayerStartLocationY(this)) public function player.getState(playerstate state) returns int return GetPlayerState(this, state) public function player.isAllyOf(player p) returns boolean return IsPlayerAlly(this, p) public function player.isEnemyOf(player p) returns boolean return IsPlayerEnemy(this, p) public function player.panCamToTimed(unit u, real time) if localPlayer == this PanCameraToTimed(u.getX(), u.getY(), time) public function player.select(unit u) if localPlayer == this SelectUnit(u, true) public function player.selectSingle(unit u) if localPlayer == this ClearSelection() SelectUnit(u, true) public function player.setAbilityAvailable(int abilityId, boolean avail) SetPlayerAbilityAvailable(this, abilityId, avail) public function player.setName(string name) SetPlayerName(this, name) public function player.setState(playerstate state, int val) SetPlayerState(this, state, val) public function player.subGold(int val) this.subState(PLAYER_STATE_RESOURCE_GOLD, val) public function player.subState(playerstate state, int val) SetPlayerState(this, state, this.getState(state) - val) /** Enables / disables user UI control for the player */ public function player.setUserControl(boolean enable) if localPlayer == this EnableUserControl(enable) public function player.unselect(unit u) if localPlayer == this SelectUnit(u, false) public function player.isIngame() returns boolean return this.getSlotState() == PLAYER_SLOT_STATE_PLAYING and this.getController() == MAP_CONTROL_USER public function player.decTechResearched(int techId, int levels) BlzDecPlayerTechResearched(this, techId, levels) public function player.forceStartLocation(int index) ForcePlayerStartLocation(this, index) public function player.getPlayerAlliance(player otherPlayer, alliancetype whichAllianceSetting) returns boolean return GetPlayerAlliance(this, otherPlayer, whichAllianceSetting) public function player.setPlayerAlliance(player otherPlayer, alliancetype whichAllianceSetting, boolean value) SetPlayerAlliance(this, otherPlayer, whichAllianceSetting, value) public function player.setTaxRate(player otherPlayer, playerstate whichResource, integer rate) SetPlayerTaxRate(this, otherPlayer, whichResource, rate) public function player.setRacePreference(racepreference whichRacePreference) SetPlayerRacePreference(this, whichRacePreference) public function player.setRaceSelectable(boolean value) SetPlayerRaceSelectable(this, value) public function player.getTeam() returns int return GetPlayerTeam(this) public function player.isSelectable() returns bool return GetPlayerSelectable(this) public function player.getTaxRate(player otherPlayer, playerstate whichResource) returns int return GetPlayerTaxRate(this, otherPlayer, whichResource) public function player.isRacePrefSet(racepreference preference) returns bool return IsPlayerRacePrefSet(this, preference) /** Get width and height of current Warcraft 3 client window. Returns vec2(0,0) for non-local player.*/ public function player.getScreenSize() returns vec2 return localPlayer == this ? vec2(I2R(BlzGetLocalClientWidth()), I2R(BlzGetLocalClientHeight())) : vec2(0,0) /** Check if client window is active. Will return false always for non-local player.*/ public function player.isScreenActive() returns bool return localPlayer == this ? BlzIsLocalClientActive() : false /** Return language locale for local player. Returns null for non-local player.*/ public function player.getLocale() returns string return localPlayer == this ? BlzGetLocale() : null /** Return if Target Indicator is enabled for local player. Returns false for non-local player.*/ public function player.isTargetIndicatorEnabled() returns bool return localPlayer == this ? BlzIsTargetIndicatorEnabled() : false /** Set if Target Indicator is enabled for local player.*/ public function player.setTargetIndicator(bool enableTargetIndicator) if localPlayer == this BlzEnableTargetIndicator(enableTargetIndicator) /** Enable or disable mouse cursor..*/ public function player.setCursorEnabled(bool enableCursor) if localPlayer == this BlzEnableCursor(enableCursor) /** Set cursor position on screen. Uses int values internally.*/ public function player.setPosCursor(vec2 pos) if localPlayer == this BlzSetMousePos(R2I(pos.x), R2I(pos.y)) /** Get unit focused by mouse cursor.*/ public function player.getCursorFocus() returns unit return localPlayer == this ? BlzGetMouseFocusUnit() : null public function player.setMinimapTerrainTex(string texFile) returns bool return localPlayer == this ? BlzChangeMinimapTerrainTex(texFile) : false public function player.sendSyncData(string prefix, string data) returns bool return BlzSendSyncData(prefix, data) public function player.showChatMessage(int recipient, string message) BlzDisplayChatMessage(this, recipient, message) /** Sets the maximum allowed hero amount for a player */ public function player.setHeroMaxAllowed(int amount) SetPlayerTechMaxAllowed(this, 'HERO', amount) public function player.hasVisibility(unit target) returns bool return IsUnitVisible(target, this) public function player.hasVisibility(vec2 pos) returns bool return IsVisibleToPlayer(pos.x, pos.y, this) @Test function testPlayer() let p = Player(0) assertTrue(p == Player(0))