mirror of https://github.com/FreeCol/freecol.git
Tighten REF naval unit addition and testing.
This commit is contained in:
parent
eb846f3d85
commit
9b1c599c3a
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue