Example #1
0
 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;
 }
Example #2
0
 @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);
   }
 }
Example #3
0
 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;
 }
Example #4
0
 private void meleeAttackUnit(Unit attackedUnit) {
   Direction direction = rtsWorld.getDirectionByPoints(unit.getPos(), attackedUnit.getPos());
   unit.setDirection(direction);
   unit.setAction(ActionType.MELEE_ATTACK);
 }