}
PathFinder pathFinder = realm.getPathFinder();
if (pathFinder == null) {
return new CommandResult(CommandResult.RESULT_ERROR, "PathFinder for realm is null.");
}
Path path = pathFinder.findPath(unit, coordinate, false);
if (path == null) {
String errorMessage = "There is not any path from unit's current location to target tile\n";
errorMessage = errorMessage + "Units location : " + unit.getCoordinate();
errorMessage = errorMessage + " Target coordinate :" + coordinate;
return new CommandResult(CommandResult.RESULT_ERROR, errorMessage);
}
int i = 0;
while ((unit.getMovementPoints() > 0) && (i < path.getLength())) {
Coordinate pathCoordinate = path.getStep(i);
MoveUnitCommand moveUnitCommand = new MoveUnitCommand(unit, pathCoordinate);
CommandResult moveCommandResult = Executor.getInstance().execute(moveUnitCommand);
if (moveCommandResult.getCode() == CommandResult.RESULT_ERROR) {
return new CommandResult(CommandResult.RESULT_ERROR, "A move command returned an error. Error : " + moveCommandResult.getText());
}