Tighten REF naval unit addition and testing.

This commit is contained in:
Mike Pope 2021-04-16 15:31:23 +09:30
parent eb846f3d85
commit 9b1c599c3a
2 changed files with 17 additions and 5 deletions

View File

@ -511,6 +511,19 @@ public final class Monarch extends FreeColGameObject implements Named {
return first(navalREFUnitTypes);
}
/**
* Should we add a naval unit to the REF next?
*
* Expand royal navy to +10% of required size to transport the land units.
*
* @return True if a naval unit should be added next.
*/
public boolean shouldAddNavalUnit() {
Force ref = getExpeditionaryForce();
// FIXME: Magic number
return (double)ref.getCapacity() < ref.getSpaceRequired() * 1.1;
}
/**
* Add units to the Royal Expeditionary Force.
*
@ -521,11 +534,8 @@ public final class Monarch extends FreeColGameObject implements Named {
initializeCaches();
final Specification spec = getSpecification();
Force ref = getExpeditionaryForce();
AbstractUnit result;
if ((double)ref.getCapacity() < ref.getSpaceRequired() * 1.1) {
// Expand navy to +10% of required size to transport the land units
// FIXME: Magic number
if (shouldAddNavalUnit()) {
List<UnitType> types = navalREFUnitTypes;
if (types.isEmpty()) return null;
result = new AbstractUnit(getRandomMember(logger, "Naval REF unit",
@ -544,6 +554,8 @@ public final class Monarch extends FreeColGameObject implements Named {
int number = randomInt(logger, "Choose land#", random, 3) + 1;
result = new AbstractUnit(unitType, role.getId(), number);
}
Force ref = getExpeditionaryForce();
ref.add(result);
logger.info("Add to " + player.getDebugName()
+ " REF: capacity=" + ref.getCapacity()

View File

@ -99,7 +99,7 @@ public class REFTest extends FreeColTestCase {
final Force exf = monarch.getExpeditionaryForce();
int done = 0;
while (done != 3) {
boolean naval = exf.getCapacity() < exf.getSpaceRequired();
boolean naval = monarch.shouldAddNavalUnit();
AbstractUnit au = monarch.addToREF(random);
assertNotNull("REF add", au);
if (naval) {