当前位置: 首页>>代码示例>>Java>>正文


Java Force.getSpaceRequired方法代码示例

本文整理汇总了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;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:37,代码来源:Monarch.java

示例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();
        }
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:34,代码来源:Monarch.java


注:本文中的net.sf.freecol.common.model.Force.getSpaceRequired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。