• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java UnitLocation类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中net.sf.freecol.common.model.UnitLocation的典型用法代码示例。如果您正苦于以下问题:Java UnitLocation类的具体用法?Java UnitLocation怎么用?Java UnitLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

UnitLocation类属于net.sf.freecol.common.model包,在下文中一共展示了UnitLocation类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: embarkUnit

点赞 3

import net.sf.freecol.common.model.UnitLocation; //导入依赖的package包/类
/**
 * Embark a unit onto a carrier.
 * Checking that the locations are appropriate is not done here.
 *
 * @param serverPlayer The {@code ServerPlayer} embarking.
 * @param serverUnit The {@code ServerUnit} that is embarking.
 * @param carrier The {@code Unit} to embark onto.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet embarkUnit(ServerPlayer serverPlayer,
                            ServerUnit serverUnit, Unit carrier) {
    if (serverUnit.isNaval()) {
        return serverPlayer.clientError("Naval unit " + serverUnit.getId()
            + " can not embark.");
    }
    UnitLocation.NoAddReason reason = carrier.getNoAddReason(serverUnit);
    if (reason != UnitLocation.NoAddReason.NONE) {
        return serverPlayer.clientError("Carrier: " + carrier.getId()
            + " can not carry " + serverUnit.getId() + ": " + reason);
    }

    ChangeSet cs = new ChangeSet();
    serverUnit.csEmbark(carrier, cs);

    // Others might see the unit disappear, or the carrier capacity.
    getGame().sendToOthers(serverPlayer, cs);
    return cs;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:29,
代码来源:InGameController.java

示例2: equipForRole

点赞 3

import net.sf.freecol.common.model.UnitLocation; //导入依赖的package包/类
/**
 * Equips this AI unit for a particular role.
 *
 * The unit must be at a location where the required goods are available
 * (possibly requiring a purchase, which may fail due to lack of gold
 * or boycotts in effect).
 *
 * @param role The {@code Role} to equip for identifier.
 * @return True if the role change was successful.
 */
public boolean equipForRole(Role role) {
    final Player player = unit.getOwner();
    Location loc = Location.upLoc(unit.getLocation());
    if (!(loc instanceof UnitLocation)) return false;
    int count = role.getMaximumCount();
    if (count > 0) {
        for (; count > 0; count--) {
            List<AbstractGoods> req = unit.getGoodsDifference(role, count);
            try {
                int price = ((UnitLocation)loc).priceGoods(req);
                if (player.checkGold(price)) break;
            } catch (FreeColException fce) {
                continue;
            }
        }
        if (count <= 0) return false;
    }
    return AIMessage.askEquipForRole(this, role, count)
        && unit.getRole() == role && unit.getRoleCount() == count;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:31,
代码来源:AIUnit.java

示例3: embarkUnit

点赞 2

import net.sf.freecol.common.model.UnitLocation; //导入依赖的package包/类
/**
 * Embark a unit onto a carrier.
 * Checking that the locations are appropriate is not done here.
 *
 * @param serverPlayer The <code>ServerPlayer</code> embarking.
 * @param unit The <code>Unit</code> that is embarking.
 * @param carrier The <code>Unit</code> to embark onto.
 * @return An <code>Element</code> encapsulating this action.
 */
public Element embarkUnit(ServerPlayer serverPlayer, Unit unit,
                          Unit carrier) {
    if (unit.isNaval()) {
        return DOMMessage.clientError("Naval unit " + unit.getId()
            + " can not embark.");
    }
    UnitLocation.NoAddReason reason = carrier.getNoAddReason(unit);
    if (reason != UnitLocation.NoAddReason.NONE) {
        return DOMMessage.clientError("Carrier: " + carrier.getId()
            + " can not carry " + unit.getId() + ": " + reason.toString());
    }

    ChangeSet cs = new ChangeSet();

    Location oldLocation = unit.getLocation();
    unit.setLocation(carrier);
    unit.setMovesLeft(0);
    cs.add(See.only(serverPlayer), (FreeColGameObject)oldLocation);
    if (carrier.getLocation() != oldLocation) {
        cs.add(See.only(serverPlayer), carrier);
    }
    if (oldLocation instanceof Tile) {
        if (carrier.getTile() != (Tile)oldLocation) {
            cs.addMove(See.only(serverPlayer), unit, (Tile)oldLocation,
                       carrier.getTile());
        }
        cs.addDisappear(serverPlayer, (Tile)oldLocation, unit);
    }

    // Others might see the unit disappear, or the carrier capacity.
    sendToOthers(serverPlayer, cs);
    return cs.build(serverPlayer);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:43,
代码来源:InGameController.java

示例4: addRoleItems

点赞 2

import net.sf.freecol.common.model.UnitLocation; //导入依赖的package包/类
/**
 * Add menu items for role manipulation for a unit.
 *
 * Note "clear speciality" is here too to keep it well separated from
 * other items.
 *
 * @param unitLabel The {@code UnitLabel} specifying the unit.
 * @return True if menu items were added and a separator is now needed.
 */
private boolean addRoleItems(final UnitLabel unitLabel) {
    final Specification spec = freeColClient.getGame().getSpecification();
    final Unit unit = unitLabel.getUnit();
    final Role role = unit.getRole();
    final int roleCount = unit.getRoleCount();
    boolean separatorNeeded = false;

    UnitLocation uloc = (unit.isInEurope()) ? unit.getOwner().getEurope()
        : unit.getSettlement();
    if (uloc == null) return false;
    for (Role r : transform(unit.getAvailableRoles(null),
                            r2 -> r2 != role)) {
        JMenuItem newItem;
        if (r.isDefaultRole()) { // Always valid
            newItem = createRoleItem(unitLabel, role, roleCount, r, 0, 0);
        } else {
            newItem = null;
            for (int count = r.getMaximumCount(); count > 0; count--) {
                List<AbstractGoods> req = unit.getGoodsDifference(r, count);
                try {
                    int price = uloc.priceGoods(req);
                    if (unit.getOwner().checkGold(price)) {
                        newItem = createRoleItem(unitLabel, role, roleCount,
                                                 r, count, price);
                        break;
                    }
                } catch (FreeColException fce) {
                    continue;
                }
            }
        }
        if (newItem != null) {
            this.add(newItem);
            separatorNeeded = true;
        }
    }

    UnitTypeChange uc = unit.getUnitChange(UnitChangeType.CLEAR_SKILL);
    if (uc != null) {
        if (separatorNeeded) this.addSeparator();
        JMenuItem menuItem = Utility.localizedMenuItem("quickActionMenu.clearSpeciality",
            new ImageIcon(gui.getImageLibrary().getTinyUnitImage(uc.to)));
        menuItem.setActionCommand(UnitAction.CLEAR_SPECIALITY.toString());
        menuItem.addActionListener(unitLabel);
        this.add(menuItem);
        if (unit.getLocation() instanceof Building
            && !((Building)unit.getLocation()).canAddType(uc.to)) {
            menuItem.setEnabled(false);
        }
        separatorNeeded = true;
    }
    return separatorNeeded;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:63,
代码来源:QuickActionMenu.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)