コード例 #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;
 }
コード例 #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);
   }
 }
コード例 #3
0
 private boolean validePathPicked() {
   List<Point> path = unit.getMoveBehavior().getPath();
   if (path == null) {
     return true;
   }
   Point lastPointPath = path.get(path.size() - 1);
   if (AStarMoveBehavior.getManhattanDistance(unit.getPos(), attackedUnit.getPos())
       <= (AStarMoveBehavior.getManhattanDistance(lastPointPath, attackedUnit.getPos()))) {
     return false;
   }
   return true;
 }
コード例 #4
0
 @Override
 public void update() {
   if (attackedUnit != null) {
     findAndAttackNearbyEnemy();
     attackingUnit();
   } else {
     unit.getMoveBehavior().update();
   }
   if (!unit.getAction().equals(ActionType.NOTHING)) {
     return;
   }
   findAndAttackNearbyEnemy();
 }
コード例 #5
0
 private Point getClosestOpenPointToAttackedUnit() {
   List<Point> availablePointsToMove = new ArrayList<Point>();
   fillAvailablePointsToMoveNearAttackedUnit(availablePointsToMove);
   Point openPoint = null;
   for (Point point : availablePointsToMove) {
     if (openPoint == null
         || Point.getManhattanDistance(openPoint, unit.getPos())
             > Point.getManhattanDistance(point, unit.getPos())) {
       openPoint = point;
     }
   }
   return openPoint;
 }
コード例 #6
0
 private void attackingUnit() {
   if (attackedUnit.isDead()) {
     attackedUnit = null;
     unit.setAction(ActionType.NOTHING);
     return;
   }
   MoveBehavior moveBehavior = unit.getMoveBehavior();
   if (((AStarMoveBehavior) moveBehavior)
           .getManhattanDistance(attackedUnit.getPos(), unit.getPos(), false)
       == 1) {
     meleeAttackUnit(attackedUnit);
   } else {
     goToAttackedUnit(moveBehavior);
   }
 }
コード例 #7
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;
 }
コード例 #8
0
 @Override
 public void setUnit(Unit unit) {
   this.unit = unit;
   this.rtsWorld = unit.getRtsWorld();
 }
コード例 #9
0
 private void meleeAttackUnit(Unit attackedUnit) {
   Direction direction = rtsWorld.getDirectionByPoints(unit.getPos(), attackedUnit.getPos());
   unit.setDirection(direction);
   unit.setAction(ActionType.MELEE_ATTACK);
 }