Handles the cases of forced repair (classic combat model) and volunatary repair (hitpoints model) differently.

This commit is contained in:
Stian Grenborgen 2023-01-18 22:24:11 +01:00
parent d20be439b8
commit 3291a5fb23
8 changed files with 17 additions and 13 deletions

View File

@ -167,7 +167,7 @@ public final class EuropePanel extends PortPanel {
*/
@Override
public boolean accepts(Unit unit) {
return unit.isNaval() && !unit.isDamaged();
return unit.isNaval() && !unit.isDamagedAndUnderForcedRepair();
}
/**

View File

@ -785,7 +785,7 @@ public class DebugUtils {
lb.add("\n->", label, "\n");
for (Unit u : units) {
lb.add("\n", u.getDescription(Unit.UnitLabelType.NATIONAL));
if (u.isDamaged()) {
if (u.isDamagedAndUnderForcedRepair()) {
lb.add(" (", Messages.message(u.getRepairLabel()), ")");
} else {
lb.add(" ");

View File

@ -1707,6 +1707,10 @@ public class Unit extends GoodsLocation
*
* @return True if under repair.
*/
public boolean isDamagedAndUnderForcedRepair() {
return isDamaged() && !getSpecification().hasAbility(Ability.HITPOINTS_COMBAT_MODEL);
}
public boolean isDamaged() {
return hitPoints < getMaximumHitPoints();
}
@ -2351,7 +2355,7 @@ public class Unit extends GoodsLocation
if (target == null) {
return (getOwner().canMoveToEurope()) ? MoveType.MOVE_HIGH_SEAS
: MoveType.MOVE_NO_EUROPE;
} else if (isDamaged()) {
} else if (isDamagedAndUnderForcedRepair()) {
return MoveType.MOVE_NO_REPAIR;
}
@ -2721,7 +2725,7 @@ public class Unit extends GoodsLocation
*/
public boolean isReadyToTrade() {
return !isDisposed()
&& !isDamaged()
&& !isDamagedAndUnderForcedRepair()
&& !isAtSea()
&& !isOnCarrier()
&& !isInColony()
@ -2738,7 +2742,7 @@ public class Unit extends GoodsLocation
*/
private boolean readyAndAble() {
return !isDisposed()
&& !isDamaged()
&& !isDamagedAndUnderForcedRepair()
&& !isAtSea()
&& !isOnCarrier()
&& !isInColony()
@ -3648,7 +3652,7 @@ public class Unit extends GoodsLocation
final TradeRoute tradeRoute = getTradeRoute();
StringTemplate ret;
if (player != null && player.owns(this)) {
if (isDamaged() && !getSpecification().hasAbility(Ability.HITPOINTS_COMBAT_MODEL)) {
if (isDamagedAndUnderForcedRepair()) {
if (full) {
ret = StringTemplate.label(":")
.add("model.unit.occupation.underRepair")

View File

@ -251,7 +251,7 @@ public abstract class UnitLocation extends FreeColGameObject implements Location
* @see Unit#isCarrier
*/
public boolean hasCarrierWithSpace(int space) {
return any(getUnits(), u -> u.isCarrier() && !u.isDamaged()
return any(getUnits(), u -> u.isCarrier() && !u.isDamagedAndUnderForcedRepair()
&& u.getSpaceLeft() >= space);
}

View File

@ -208,7 +208,7 @@ public abstract class Mission extends AIObject {
return (unit == null) ? "unit-null"
: (!unit.isInitialized()) ? "unit-uninitialized"
: (unit.isDisposed()) ? "unit-disposed"
: (unit.isDamaged()) ? "unit-under-repair"
: (unit.isDamagedAndUnderForcedRepair()) ? "unit-under-repair"
: null;
}

View File

@ -1023,7 +1023,7 @@ public class ServerUnit extends Unit implements TurnTaker {
if (isInMission()) {
getTile().updateIndianSettlement(owner);
setMovesLeft(0);
} else if (isDamaged() && !getSpecification().hasAbility(Ability.HITPOINTS_COMBAT_MODEL)) {
} else if (isDamagedAndUnderForcedRepair()) {
setMovesLeft(0);
} else {
setMovesLeft(getInitialMovesLeft());

View File

@ -112,7 +112,7 @@ public class TransportMissionTest extends FreeColTestCase {
// Verify that the outcome of the combat is a return to Europe
// for repairs and also invalidation of the transport mission
// as side effect.
assertTrue(galleon.isDamaged());
assertTrue(galleon.isDamagedAndUnderForcedRepair());
assertFalse(aiUnit.getMission().isValid());
// This will call AIPlayer.abortInvalidMissions() and change

View File

@ -512,7 +512,7 @@ public class InGameControllerTest extends FreeColTestCase {
assertEquals("Galleon should be loaded", 1,
galleon.getGoodsSpaceTaken());
assertFalse("Galleon should not be repairing",
galleon.isDamaged());
galleon.isDamagedAndUnderForcedRepair());
galleon.setDestination(tile3);
assertEquals("Wrong destination for Galleon",
tile3, galleon.getDestination());
@ -529,7 +529,7 @@ public class InGameControllerTest extends FreeColTestCase {
igc.combat(dutch, privateer, galleon, crs);
assertTrue("Galleon should be in Europe repairing",
galleon.isDamaged());
galleon.isDamagedAndUnderForcedRepair());
assertEquals("Galleon should be empty", 0,
galleon.getGoodsSpaceTaken());
assertNull("Galleon should no longer have a destination",
@ -868,7 +868,7 @@ public class InGameControllerTest extends FreeColTestCase {
assertTrue("Colony should not be disposed",
!colony.isDisposed());
assertTrue("Privateer should be under repair",
privateer.isDamaged());
privateer.isDamagedAndUnderForcedRepair());
assertEquals("Privateer should be in Europe", dutch.getEurope(),
privateer.getLocation());