return !(unitService.getLocation(unit).absoluteDistanceTo(destination) > 1f);
}
@Override
public void executeImpl() {
Unit movingUnit = unitService.getUnits(unitService.getLocation(unit))
.iterator().next();
Collection<Unit> units = unitService.getUnits(destination);
if (units.isEmpty()) {
unitService.moveUnit(movingUnit, destination);
if (calculateAnnectionFrom()) {
messagingService
.addMessage(
userService.getUser(),
"City of " //$NON-NLS-1$
+ ((Dynasty) propertyService
.getOwnership(unit)).getName()
+ " is lost because no one defended it."); //$NON-NLS-1$
}
} else {
Unit otherUnit = units.iterator().next();
if (!dynasty.equals(propertyService.getOwnership(otherUnit))) {
int numberOfUnits = movingUnit.getNumberOfUnits();
int otherNumberOfUnits = otherUnit.getNumberOfUnits();
int casualties = 0;
int otherCasualties = 0;
for (int i = 1; i <= Math
.max(numberOfUnits, otherNumberOfUnits); i++) {
if (i > numberOfUnits) {
casualties += (Math.random() < 0.5f) ? 1 : 0;
} else if (i > otherNumberOfUnits) {
otherCasualties += (Math.random() < 0.5f) ? 1 : 0;
} else if (Math.random() < 0.5f) {
casualties += 1;
} else {
otherCasualties += 1;
}
}
messagingService
.addMessage(
userService.getUser(),
"Battle between " //$NON-NLS-1$
+ ((Dynasty) propertyService
.getOwnership(unit)).getName()
+ "(" + casualties + " casualties) and " //$NON-NLS-1$ //$NON-NLS-2$
+ ((Dynasty) propertyService
.getOwnership(otherUnit))
.getName() + "(" //$NON-NLS-1$
+ otherCasualties + " casualties)"); //$NON-NLS-1$
movingUnit.kill(casualties);
if (movingUnit.isDead()) {
unitService.removeUnit(movingUnit);
messagingService.addMessage(
userService.getUser(),
"Attacking unit of " //$NON-NLS-1$
+ ((Dynasty) propertyService
.getOwnership(unit)).getName()
+ " exploded in a fireball"); //$NON-NLS-1$
}
otherUnit.kill(otherCasualties);
if (otherUnit.isDead()) {
messagingService.addMessage(
userService.getUser(),
"Defending unit of " //$NON-NLS-1$
+ ((Dynasty) propertyService
.getOwnership(unit)).getName()