private List<Point> fillAvailablePointsToMoveNearAttackedUnit(List<Point> availablePointsToMove) { Point testPoint; testPoint = attackedUnit.getPos().getCopy(); testPoint.setY(testPoint.getY() + 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } testPoint = attackedUnit.getPos().getCopy(); testPoint.setX(testPoint.getX() + 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } testPoint = attackedUnit.getPos().getCopy(); testPoint.setY(testPoint.getY() - 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } testPoint = attackedUnit.getPos().getCopy(); testPoint.setX(testPoint.getX() - 1); if (rtsWorld.canMoveToPoint(testPoint, false)) { availablePointsToMove.add(testPoint); } Collections.shuffle(availablePointsToMove); return availablePointsToMove; }
@Override public void actionOnPoint(Point point) { Unit enemyUnit = rtsWorld.getEnemyUnitInPoint(point, unit.getPlayer()); if (enemyUnit != null) { attackedUnit = enemyUnit; } else { attackedUnit = null; unit.getMoveBehavior().setDestMovePoint(point, false); } }
private void findAndAttackNearbyEnemy() { Unit candidatUnit = null; for (Unit curUnit : rtsWorld.getUnits()) { if (curUnit.getPlayer() != unit.getPlayer()) { if (AStarMoveBehavior.getManhattanDistance(unit.getPos(), curUnit.getPos()) < getFindEnemyDistance() && (candidatUnit == null || AStarMoveBehavior.getManhattanDistance(unit.getPos(), curUnit.getPos()) < AStarMoveBehavior.getManhattanDistance( unit.getPos(), candidatUnit.getPos()))) { candidatUnit = curUnit; } /* if (getEuclideDistance(unit.getPos(), curUnit.getPos()) < getFindEnemyDistance() && (candidatUnit == null || getEuclideDistance(unit.getPos(), curUnit.getPos()) < (getEuclideDistance(unit.getPos(), candidatUnit.getPos())))) { candidatUnit = curUnit; }*/ } } if (candidatUnit != null) attackedUnit = candidatUnit; }
private void meleeAttackUnit(Unit attackedUnit) { Direction direction = rtsWorld.getDirectionByPoints(unit.getPos(), attackedUnit.getPos()); unit.setDirection(direction); unit.setAction(ActionType.MELEE_ATTACK); }