public ConfigurableGeneral(AiStatistics aiStatistics, Player player, MovableGrid movableGrid, ITaskScheduler taskScheduler, EPlayerType playerType) { this.aiStatistics = aiStatistics; this.player = player; this.taskScheduler = taskScheduler; this.movableGrid = movableGrid; this.attackerCountFactor = ATTACKER_COUNT_FACTOR_BY_PLAYER_TYPE[playerType.ordinal()]; }
@Override public String toString() { return Labels.getString("player-type-" + playerType.name()); } }
public static PlayerSetting[] createDefaultSettings(byte playerId, byte maxPlayers) { PlayerSetting[] playerSettings = new PlayerSetting[maxPlayers]; byte offsetToSkipHuman = 0; for (byte i = 0; i < playerSettings.length; i++) { if (i == playerId) { playerSettings[playerId] = new PlayerSetting(i); } else { EPlayerType aiType; aiType = EPlayerType.getTypeByIndex(i + offsetToSkipHuman); if (aiType == EPlayerType.HUMAN) { offsetToSkipHuman++; aiType = EPlayerType.getTypeByIndex(i + offsetToSkipHuman); } playerSettings[i] = new PlayerSetting(true, aiType, ECivilisation.ROMAN, i); } } System.out.println("created player settings: " + Arrays.toString(playerSettings)); return playerSettings; } }
public static PlayerSetting readFromStream(DataInputStream dis) throws IOException { dis.readShort(); // read version boolean available = dis.readBoolean(); if (available) { byte readTeamId = dis.readByte(); Byte teamId = readTeamId == -1 ? null : readTeamId; String civilizationName = dis.readUTF(); ECivilisation civilisation = civilizationName.isEmpty() ? null : ECivilisation.valueOf(civilizationName); String playerTypeName = dis.readUTF(); EPlayerType playerType = playerTypeName.isEmpty() ? null : EPlayerType.valueOf(playerTypeName); return new PlayerSetting(true, playerType, civilisation, teamId); } else { return new PlayerSetting(); } }
public AiExecutor(PlayerSetting[] playerSettings, MainGrid mainGrid, ITaskScheduler taskScheduler) { aiStatistics = new AiStatistics(mainGrid); aiStatistics.updateStatistics(); this.whatToDoAis = new ArrayList<>(); WhatToDoAiFactory aiFactory = new WhatToDoAiFactory(); for (byte playerId = 0; playerId < playerSettings.length; playerId++) { PlayerSetting playerSetting = playerSettings[playerId]; if (playerSetting.isAvailable() && playerSetting.getPlayerType().isAi()) { whatToDoAis.add(aiFactory.buildWhatToDoAi( playerSettings[playerId].getPlayerType(), playerSettings[playerId].getCivilisation(), aiStatistics, mainGrid.getPartitionsGrid().getPlayer(playerId), mainGrid, mainGrid.getMovableGrid(), taskScheduler)); } } }
public void writeTo(DataOutputStream dos) throws IOException { dos.writeShort(INITIAL_VERSION); dos.writeBoolean(available); if (available) { dos.writeByte(teamId == null ? -1 : teamId); dos.writeUTF(civilisation == null ? "" : civilisation.name()); dos.writeUTF(playerType == null ? "" : playerType.name()); } }
private void updateAiPlayerName() { if (typeComboBox.getSelectedItem() == null || civilisationComboBox.getSelectedItem() == null) { return; } if (EPlayerType.HUMAN != getPlayerType()) { ECivilisation civilisation = getCivilisation(); if (civilisation != null) { setPlayerName(Labels.getString("player-name-" + getCivilisation().name() + "-" + ((PlayerTypeUiWrapper) typeComboBox.getSelectedItem()).getPlayerType().name())); } else { setPlayerName(Labels.getString("player-name-random")); } setReady(true); } else { setReady(false); } }