private boolean canSelectPlayer(IPlayer player) { return canSelectPlayer(player.getPlayerId()); }
private boolean isAlive(IPlayer player) { return isAlive(player.getPlayerId()); }
private int maximumAllowedCount(EBuildingType buildingType) { if (!limitByWeakestEnemy) { return Integer.MAX_VALUE; } List<IPlayer> enemies = aiStatistics.getAliveEnemiesOf(player); float sumOfBuildings = 0; for (IPlayer enemy : enemies) { sumOfBuildings += aiStatistics.getTotalNumberOfBuildingTypeForPlayer(buildingType, enemy.getPlayerId()); } return Math.max(1, (int) (sumOfBuildings / enemies.size())); }
private Color getColor(IMapObject object) { Color color = null; if (object instanceof IPlayerable) { color = context.getPlayerColor(((IPlayerable) object).getPlayer().getPlayerId()); } return color; }
private boolean hasSamePlayer(int x, int y, IPathCalculatable requester) { return partitionsGrid.getPlayerIdAt(x, y) == requester.getPlayer().getPlayerId(); }
public int getCountOfMovablesOfPlayer(IPlayer player, Set<EMovableType> types) { byte playerId = player.getPlayerId(); return stream(types).mapToInt(type -> getPositionsOfMovablesWithTypeForPlayer(playerId, type).size()).sum(); }
@Override public boolean isBlocked(IPathCalculatable requester, int x, int y) { if (requester.isShip()) { return !isWaterSafe(x, y); } return flagsGrid.isBlocked(x, y) || (requester.needsPlayersGround() && requester.getPlayer().getPlayerId() != partitionsGrid.getPlayerIdAt(x, y)); }
private boolean isDanger() { if (aiStatistics.getTotalNumberOfBuildingTypeForPlayer(BARRACK, playerId) < 1) { int numberOfSwordsmen = aiStatistics.getCountOfMovablesOfPlayer(player, EMovableType.SWORDSMEN); if (aiStatistics.getTotalNumberOfBuildingTypeForPlayer(TOWER, playerId) >= numberOfSwordsmen) { return true; } for (IPlayer enemy : aiStatistics.getAliveEnemiesOf(player)) { if (aiStatistics.getNumberOfBuildingTypeForPlayer(WEAPONSMITH, enemy.getPlayerId()) > 0) { return true; } } } return false; }
private ShortPoint2D getTargetEnemyDoorToAttack(IPlayer enemyToAttack) { List<ShortPoint2D> myMilitaryBuildings = aiStatistics.getBuildingPositionsOfTypesForPlayer(EBuildingType.MILITARY_BUILDINGS, player.playerId); ShortPoint2D myBaseAveragePoint = AiStatistics.calculateAveragePointFromList(myMilitaryBuildings); List<ShortPoint2D> enemyMilitaryBuildings = aiStatistics.getBuildingPositionsOfTypesForPlayer(EBuildingType.MILITARY_BUILDINGS, enemyToAttack.getPlayerId()); ShortPoint2D nearestEnemyBuildingPosition = AiStatistics.detectNearestPointFromList(myBaseAveragePoint, enemyMilitaryBuildings); return aiStatistics.getBuildingAt(nearestEnemyBuildingPosition).getDoor(); }
private ISelectable getSelectableAt(ShortPoint2D pos) { if (grid.isInBounds(pos)) { final IBuilding building = grid.getBuildingAt(pos.x, pos.y); if (building != null && canSelectPlayer(building.getPlayer().getPlayerId())) { return building; } else { final IGuiMovable selectableMovable = getSelectableMovable(pos.x, pos.y).orElse(null); if (selectableMovable != null) { return selectableMovable; } } } return null; }
final boolean isValidPosition(IPathCalculatable pathCalculatable, int x, int y) { if (pathCalculatable.isShip()) { return isNavigable(x, y); } return isInBounds(x, y) && !flagsGrid.isBlocked(x, y) && (!pathCalculatable.needsPlayersGround() || pathCalculatable.getPlayer().getPlayerId() == partitionsGrid.getPlayerIdAt(x, y)); }
@Override public void update() { buildingsToBuild.clear(); this.mapBuildingCounts = aiStatistics.getAiMapInformation().getBuildingCounts(player.getPlayerId()); addMinimalBuildingMaterialBuildings(); if (isVerySmallMap()) { addSmallWeaponProduction(); addFoodAndBuildingMaterialAndWeaponAndGoldIndustry(); addManaBuildings(); } else { addManaBuildings(); addFoodAndBuildingMaterialAndWeaponAndGoldIndustry(); addSecondToolSmith(); } }
private void selectPointType(PointAction action) { final ShortPoint2D actionPosition = action.getPosition(); final IGuiMovable selectedMovable = getSelectableMovable(actionPosition.x, actionPosition.y).orElse(null); if (selectedMovable == null) { // nothing found at the location setSelection(new SelectionSet()); return; } EMovableType selectedType = selectedMovable.getMovableType(); byte selectedPlayerId = selectedMovable.getPlayer().getPlayerId(); Set<EMovableType> selectableTypes; if (selectedType.isSwordsman()) { selectableTypes = EMovableType.SWORDSMEN; } else if (selectedType.isPikeman()) { selectableTypes = EMovableType.PIKEMEN; } else if (selectedType.isBowman()) { selectableTypes = EMovableType.BOWMEN; } else { selectableTypes = EnumSet.of(selectedType); } final List<ISelectable> selected = new LinkedList<>(); MapCircle.stream(actionPosition, SELECT_BY_TYPE_RADIUS) .filterBounds(grid.getWidth(), grid.getHeight()) .forEach((x, y) -> { final IGuiMovable movable = grid.getMovable(x, y); if (movable != null && selectableTypes.contains(movable.getMovableType()) && selectedPlayerId == movable.getPlayer().getPlayerId()) { selected.add(movable); } }); setSelection(new SelectionSet(selected)); }
private void selectArea(SelectAreaAction action) { final SelectionSet selectionSet = new SelectionSet(); action.getArea().stream().filterBounds(grid.getWidth(), grid.getHeight()).forEach((x, y) -> { final IGuiMovable movable = grid.getMovable(x, y); if (movable != null && canSelectPlayer(movable.getPlayer().getPlayerId())) { selectionSet.add(movable); } final IBuilding building = grid.getBuildingAt(x, y); if (building != null && canSelectPlayer(building.getPlayer().getPlayerId())) { selectionSet.add(building); } }); setSelection(selectionSet); }
@Override public void commandTroops(Set<Integer> soldiersWithOrders) { ensureAllTowersFullyMounted(); SoldierPositions soldierPositions = calculateSituation(player.playerId); if (aiStatistics.getEnemiesInTownOf(player.playerId).size() > 0) { defend(soldierPositions, soldiersWithOrders); } else if (existsAliveEnemy()) { IPlayer weakestEnemy = getWeakestEnemy(); SoldierPositions enemySoldierPositions = calculateSituation(weakestEnemy.getPlayerId()); boolean infantryWouldDie = wouldInfantryDie(enemySoldierPositions); if (attackIsPossible(soldierPositions, enemySoldierPositions, infantryWouldDie)) { attack(soldierPositions, infantryWouldDie, soldiersWithOrders); } } }
Color color = context.getPlayerColor(ship.getPlayer().getPlayerId()); float viewX = context.getOffsetX(); float viewY = context.getOffsetY();
IMovable settler = map.getMovableAt(x, y); if (settler != null && (displaySettlers == SettlersMode.ALL || settler.getMovableType().isPlayerControllable())) { settlerColor = context.getPlayerColor(settler.getPlayer().getPlayerId()).toShortColor(1); IBuilding.IOccupied occupyed = (IBuilding.IOccupied) building; if (occupyed.isOccupied()) { settlerColor = context.getPlayerColor(occupyed.getPlayer().getPlayerId()).toShortColor(1);
int i = getAnimationStep(x, y); int step = i % seq.length(); drawOnlyImage(seq.getImageSafe(step, () -> "mill-" + step), x, y, 0, context.getPlayerColor(building.getPlayer().getPlayerId()), color); ImageLink[] images = type.getImages(); if (images.length > 0) {
Color color = context.getPlayerColor(movable.getPlayer().getPlayerId());
Color color = context.getPlayerColor(movable.getPlayer().getPlayerId()); float shade = MapObjectDrawer.getColor(fogStatus); Image image;