本文整理汇总了Java中net.sf.freecol.common.model.Force.getSpaceRequired方法的典型用法代码示例。如果您正苦于以下问题:Java Force.getSpaceRequired方法的具体用法?Java Force.getSpaceRequired怎么用?Java Force.getSpaceRequired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Force
的用法示例。
在下文中一共展示了Force.getSpaceRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chooseForREF
import net.sf.freecol.common.model.Force; //导入方法依赖的package包/类
/**
* Gets units to be added to the Royal Expeditionary Force.
*
* @param random The {@code Random} number source to use.
* @return An addition to the Royal Expeditionary Force.
*/
public AbstractUnit chooseForREF(Random random) {
initializeCaches();
final Specification spec = getSpecification();
// Preserve some extra naval capacity so that not all the REF
// navy is completely loaded
// FIXME: magic number 2.5 * Manowar-capacity = 15
Force ref = getExpeditionaryForce();
boolean needNaval = ref.getCapacity()
< ref.getSpaceRequired() + 15;
List<UnitType> types = (needNaval) ? navalREFUnitTypes
: landREFUnitTypes;
if (types.isEmpty()) return null;
UnitType unitType = getRandomMember(logger, "Choose REF unit",
types, random);
Role role = (needNaval
|| !unitType.hasAbility(Ability.CAN_BE_EQUIPPED))
? spec.getDefaultRole()
: (randomInt(logger, "Choose land role", random, 3) == 0)
? refMountedRole
: refArmedRole;
int number = (needNaval) ? 1
: randomInt(logger, "Choose land#", random, 3) + 1;
AbstractUnit result = new AbstractUnit(unitType, role.getId(), number);
logger.info("Add to " + player.getDebugName()
+ " REF: capacity=" + ref.getCapacity()
+ " spaceRequired=" + ref.getSpaceRequired()
+ " => " + result);
return result;
}
示例2: updateInterventionForce
import net.sf.freecol.common.model.Force; //导入方法依赖的package包/类
/**
* Update the intervention force, adding land units depending on
* turns passed, and naval units sufficient to transport all land
* units.
*/
public void updateInterventionForce() {
Specification spec = getSpecification();
int interventionTurns = spec.getInteger(GameOptions.INTERVENTION_TURNS);
if (interventionTurns > 0) {
Force ivf = getInterventionForce();
int updates = getGame().getTurn().getNumber() / interventionTurns;
for (AbstractUnit unit : ivf.getLandUnitsList()) {
// add units depending on current turn
int value = unit.getNumber() + updates;
unit.setNumber(value);
}
ivf.updateSpaceAndCapacity();
while (ivf.getCapacity() < ivf.getSpaceRequired()) {
boolean progress = false;
// Under capacity? Add ships until all units can be
// transported at once.
for (AbstractUnit ship : transform(ivf.getNavalUnitsList(),
u -> u.getType(spec).canCarryUnits()
&& u.getType(spec).getSpace() > 0)) {
ship.setNumber(ship.getNumber() + 1);
progress = true;
}
if (!progress) break;
ivf.updateSpaceAndCapacity();
}
}
}