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

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

java 2次浏览

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

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

示例1: clearSpeciality

点赞 3

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Clear the specialty of a unit.
 *
 * FIXME: why not clear speciality in the open?  You can disband!
 * If we implement this remember to fix the visibility.
 *
 * @param serverPlayer The owner of the unit.
 * @param unit The {@code Unit} to clear the speciality of.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet clearSpeciality(ServerPlayer serverPlayer, Unit unit) {
    UnitTypeChange uc = unit.getUnitChange(UnitChangeType.CLEAR_SKILL);
    if (uc == null) {
        return serverPlayer.clientError("Can not clear unit speciality: "
            + unit.getId());
    }

    // There can be some restrictions that may prevent the
    // clearing of the speciality.  AFAICT the only ATM is that a
    // teacher can not lose its speciality, but this will need to
    // be revisited if we invent a work location that requires a
    // particular unit type.
    if (unit.getStudent() != null) {
        return serverPlayer.clientError("Can not clear speciality of a teacher.");
    }

    // Valid, change type.
    unit.changeType(uc.to);//-vis: safe in colony

    // Update just the unit, others can not see it as this only happens
    // in-colony.
    return new ChangeSet().add(See.only(serverPlayer), unit);
}
 

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

示例2: csPromoteUnit

点赞 3

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Promotes a unit.
 *
 * @param winner The {@code Unit} that won and should be promoted.
 * @param cs A {@code ChangeSet} to update.
 */
private void csPromoteUnit(Unit winner, ChangeSet cs) {
    ServerPlayer winnerPlayer = (ServerPlayer) winner.getOwner();
    StringTemplate winnerLabel = winner.getLabel();

    UnitTypeChange uc = winner.getUnitChange(UnitChangeType.PROMOTION);
    if (uc == null || uc.to == winner.getType()) {
        logger.warning("Promotion failed, type="
            + ((uc == null) ? "null" : "same type: " + uc.to));
        return;
    }
    winner.changeType(uc.to);//-vis(winnerPlayer)
    winnerPlayer.invalidateCanSeeTiles();//+vis(winnerPlayer)

    cs.addMessage(winnerPlayer,
        new ModelMessage(ModelMessage.MessageType.COMBAT_RESULT,
                         "combat.unitPromoted", winner)
            .addStringTemplate("%oldName%", winnerLabel)
            .addStringTemplate("%unit%", winner.getLabel()));
}
 

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

示例3: getUnitChange

点赞 3

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Get a unit change for this unit, including the ownership check.
 *
 * @param change The identifier for the required change type.
 * @param toType A {@code UnitType} to change to.
 * @param player The expected {@code Player} that will own the unit.
 * @return The {@code UnitChange} found, or null if the
 *     change is impossible.
 */
public UnitTypeChange getUnitChange(String change, UnitType toType,
                                    Player player) {
    if (player == null) {
        throw new RuntimeException("getUnitChange null player");
    }
    UnitChangeType uct = getSpecification().getUnitChangeType(change);
    if (uct != null && uct.getOwnerChange() != (player != getOwner())) {
        throw new RuntimeException("getUnitChange of " + this
            + " change=" + change
            + " getOwnerChange=" + uct.getOwnerChange()
            + " != player-change=" + (player != getOwner())
            + " player=" + player.getSuffix()
            + " owner=" + getOwner().getSuffix());
    }
    UnitTypeChange uc = (uct == null || !uct.appliesTo(this)) ? null
        : uct.getUnitChange(getType(), toType);
    return (uc == null || !uc.isAvailableTo(player)) ? null : uc;
}
 

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

示例4: getTeachingType

点赞 3

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Get the type that this unit type can be educated to by a
 * teacher unit type, if any.
 *
 * @param teacherType The {@code UnitType} of the teacher.
 * @return The {@code UnitType} that this unit type can be educated
 *     to by the teacher unit type, or null if education is not possible.
 */
public UnitType getTeachingType(UnitType teacherType) {
    final Specification spec = getSpecification();
    final UnitType taught = teacherType.getSkillTaught();
    final int taughtLevel = taught.getSkill();
    if (getSkill() >= taughtLevel) return null; // Fail fast

    // Is there an education change that gets this unit type to the
    // type taught by the teacher type?  If so, the taught type is valid
    // and should be returned at once.  Accumulate other intermediate
    // changes that do not reach the taught type level.
    List<UnitType> todo = new ArrayList<>();
    for (UnitTypeChange uc : spec.getUnitChanges(UnitChangeType.EDUCATION, this)) {
        if (uc.to == taught) return taught;
        if (uc.to.getSkill() < taughtLevel) todo.add(uc.to);
    }
    // Can the teacher teach any of the intermediate changes?  If so,
    // that change is valid.  Otherwise, education is not possible.
    for (UnitType ut : todo) {
        if (ut.getTeachingType(teacherType) != null) return ut;
    }
    return null;
}
 

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

示例5: Entry

点赞 3

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
public Entry(GoodsType g, WorkLocation w, Unit u) {
    goodsType = g;
    workLocation = w;
    unit = u;
    production = w.getProductionOf(u, g);
    GoodsType expertProduction = unit.getType().getExpertProduction();
    if (expertProduction != null) {
        if (expertProduction == goodsType) {
            isExpert = true;
        } else {
            isOtherExpert = true;
        }
    } else {
        for (UnitTypeChange change : unit.getType().getTypeChanges()) {
            if (change.asResultOf(ChangeType.EXPERIENCE)) {
                unitUpgrades = true;
                if (change.getNewUnitType().getExpertProduction() == goodsType) {
                    unitUpgradesToExpert = true;
                    break;
                }
            }
        }
    }
}
 

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

示例6: clearSpeciality

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Clear the speciality of a Unit, making it a Free Colonist.
 *
 * Called from UnitLabel
 *
 * @param unit The {@code Unit} to clear the speciality of.
 * @return True if the speciality was cleared.
 */
public boolean clearSpeciality(Unit unit) {
    if (!requireOurTurn() || unit == null) return false;

    UnitType oldType = unit.getType();
    UnitTypeChange uc = unit.getUnitChange(UnitChangeType.CLEAR_SKILL);
    UnitType newType = (uc == null) ? null : uc.to;
    if (newType == null) {
        getGUI().showInformationMessage(unit, StringTemplate
            .template("clearSpeciality.impossible")
            .addStringTemplate("%unit%",
                unit.getLabel(Unit.UnitLabelType.NATIONAL)));
        return false;
    }

    final Tile tile = (getGUI().isShowingSubPanel()) ? null : unit.getTile();
    if (!getGUI().confirm(tile, StringTemplate
            .template("clearSpeciality.areYouSure")
            .addStringTemplate("%oldUnit%",
                unit.getLabel(Unit.UnitLabelType.NATIONAL))
            .addNamed("%unit%", newType),
            unit, "ok", "cancel")) {
        return false;
    }

    // Try to clear.
    // Note that this routine is only called out of UnitLabel,
    // where the unit icon is always updated anyway.
    UnitWas unitWas = new UnitWas(unit);
    boolean ret = askServer().clearSpeciality(unit)
        && unit.getType() == newType;
    if (ret) {
        unitWas.fireChanges();
        updateGUI(null);
    }
    return ret;
}
 

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

示例7: work

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Change work location.
 *
 * @param serverPlayer The {@code ServerPlayer} that owns the unit.
 * @param unit The {@code Unit} to change the work location of.
 * @param workLocation The {@code WorkLocation} to change to.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet work(ServerPlayer serverPlayer, Unit unit,
                      WorkLocation workLocation) {
    final Specification spec = getGame().getSpecification();
    final Colony colony = workLocation.getColony();
    colony.getGoodsContainer().saveState();

    ChangeSet cs = new ChangeSet();
    Tile tile = workLocation.getWorkTile();
    if (tile != null && tile.getOwningSettlement() != colony) {
        // Claim known free land (because canAdd() succeeded).
        serverPlayer.csClaimLand(tile, colony, 0, cs);
    }

    colony.equipForRole(unit, spec.getDefaultRole(), 0);

    // Check for upgrade.
    UnitTypeChange uc = unit.getUnitChange(UnitChangeType.ENTER_COLONY);
    if (uc != null && uc.appliesTo(unit)) {
        unit.changeType(uc.to);//-vis: safe in colony
    }

    // Change the location.
    // We could avoid updating the whole tile if we knew that this
    // was definitely a move between locations and no student/teacher
    // interaction occurred.
    if (!unit.isInColony()) unit.getColony().getTile().cacheUnseen();//+til
    unit.setLocation(workLocation);//-vis: safe/colony,-til if not in colony
    cs.add(See.perhaps(), colony.getTile());
    // Others can see colony change size
    getGame().sendToOthers(serverPlayer, cs);
    return cs;
}
 

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

示例8: work

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Change work location.
 *
 * @param serverPlayer The {@code ServerPlayer} that owns the unit.
 * @param unit The {@code Unit} to change the work location of.
 * @param workLocation The {@code WorkLocation} to change to.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet work(ServerPlayer serverPlayer, Unit unit,
                      WorkLocation workLocation) {
    final Specification spec = getGame().getSpecification();
    final Colony colony = workLocation.getColony();
    colony.getGoodsContainer().saveState();

    ChangeSet cs = new ChangeSet();
    Tile tile = workLocation.getWorkTile();
    if (tile != null && tile.getOwningSettlement() != colony) {
        // Claim known free land (because canAdd() succeeded).
        serverPlayer.csClaimLand(tile, colony, 0, cs);
    }

    colony.equipForRole(unit, spec.getDefaultRole(), 0);

    // Check for upgrade.
    UnitTypeChange uc = unit.getUnitChange(UnitChangeType.ENTER_COLONY);
    if (uc != null) unit.changeType(uc.to);//-vis: safe in colony

    // Change the location.
    // We could avoid updating the whole tile if we knew that this
    // was definitely a move between locations and no student/teacher
    // interaction occurred.
    if (!unit.isInColony()) unit.getColony().getTile().cacheUnseen();//+til
    unit.setLocation(workLocation);//-vis: safe/colony,-til if not in colony
    cs.add(See.perhaps(), colony.getTile());
    // Others can see colony change size
    getGame().sendToOthers(serverPlayer, cs);
    return cs;
}
 

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

示例9: testUnitTypeChangeOnEnterColony

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Check upgrades on entering a colony.
 */
public void testUnitTypeChangeOnEnterColony() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));
    InGameController igc = ServerTestHelper.getInGameController();

    ServerPlayer dutch = (ServerPlayer) game.getPlayer("model.nation.dutch");
    Colony colony = getStandardColony();

    UnitType gardenerType = new UnitType("gardener", spec());
    gardenerType.setSkill(0);
    gardenerType.addAbility(new Ability("model.ability.person"));

    ChangeType enterColony = ChangeType.ENTER_COLONY;
    UnitTypeChange change = new UnitTypeChange();
    change.setNewUnitType(farmerType);
    change.getChangeTypes().put(enterColony, 100);
    List<UnitTypeChange> ch = gardenerType.getTypeChanges();
    ch.add(change);
    gardenerType.setTypeChanges(ch);

    assertTrue(gardenerType.canBeUpgraded(farmerType, enterColony));
    assertTrue(change.appliesTo(dutch));
    assertEquals(farmerType,
                 gardenerType.getTargetType(enterColony, dutch));

    Unit gardener = new ServerUnit(game, null, dutch, gardenerType);
    assertEquals(gardenerType, gardener.getType());
    assertEquals(farmerType,
        gardener.getType().getTargetType(enterColony, dutch));
    WorkLocation loc = colony.getVacantWorkLocationFor(gardener);
    assertNotNull(loc);
    gardener.setLocation(colony.getTile());

    igc.work(dutch, gardener, loc);
    assertEquals(farmerType, gardener.getType());
}
 

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

示例10: addRoleItems

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的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

示例11: csDemoteUnit

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Demotes a unit.
 *
 * @param winner The {@code Unit} that won.
 * @param loser The {@code Unit} that lost and should be demoted.
 * @param cs A {@code ChangeSet} to update.
 */
private void csDemoteUnit(Unit winner, Unit loser, ChangeSet cs) {
    final Specification spec = getSpecification();
    final ServerPlayer loserPlayer = (ServerPlayer)loser.getOwner();
    final StringTemplate loserNation = loser.getApparentOwnerName();
    final StringTemplate loserLocation = loser.getLocation()
        .getLocationLabelFor(loserPlayer);
    final StringTemplate loserLabel = loser.getLabel();
    final ServerPlayer winnerPlayer = (ServerPlayer)winner.getOwner();
    final StringTemplate winnerNation = winner.getApparentOwnerName();
    final StringTemplate winnerLocation = winner.getLocation()
        .getLocationLabelFor(winnerPlayer);
    final String suffix = loser.getType().getSuffix(); // pre-demotion value
    String key;
    
    UnitTypeChange uc = loser.getUnitChange(UnitChangeType.DEMOTION);
    if (uc == null || uc.to == loser.getType()) {
        logger.warning("Demotion failed, type="
            + ((uc == null) ? "null" : "same type: " + uc.to));
        return;
    }
    loser.changeType(uc.to);//-vis(loserPlayer)
    loserPlayer.invalidateCanSeeTiles();//+vis(loserPlayer)

    key = "combat.unitDemoted.enemy." + suffix;
    cs.addMessage(winnerPlayer,
        new ModelMessage(ModelMessage.MessageType.COMBAT_RESULT,
                         key, winner)
            .addDefaultId("combat.unitDemoted.enemy")
            .addStringTemplate("%location%", winnerLocation)
            .addStringTemplate("%unit%", winner.getLabel())
            .addStringTemplate("%enemyNation%", loserNation)
            .addStringTemplate("%oldName%", loserLabel)
            .addStringTemplate("%enemyUnit%", loser.getLabel()));
    key = "combat.unitDemoted.ours." + suffix;
    cs.addMessage(loserPlayer,
        new ModelMessage(ModelMessage.MessageType.COMBAT_RESULT,
                         key, loser)
            .addDefaultId("combat.unitDemoted.ours")
            .addStringTemplate("%location%", loserLocation)
            .addStringTemplate("%oldName%", loserLabel)
            .addStringTemplate("%unit%", loser.getLabel())
            .addStringTemplate("%enemyNation%", winnerNation)
            .addStringTemplate("%enemyUnit%", winner.getLabel()));
}
 

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

示例12: csChangeOwner

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Change the owner of a unit or dispose of it if the change is
 * impossible.  Move the unit to a new location if necessary.
 * Also handle disappearance of any carried units that will now be
 * invisible to the new owner.
 *
 * -vis(owner,newOwner)
 *
 * @param unit The {@code Unit} to change ownership of.
 * @param newOwner The new owning {@code ServerPlayer}.
 * @param change An optional accompanying change type.
 * @param loc A optional new {@code Location} for the unit.
 * @param cs A {@code ChangeSet} to update.
 * @return True if the new owner can have this unit.
 */
public boolean csChangeOwner(Unit unit, ServerPlayer newOwner,
                             String change, Location loc,
                             ChangeSet cs) {
    if (newOwner == this) return true; // No transfer needed

    final Specification spec = getSpecification();
    final Tile oldTile = unit.getTile();
    if (change != null) {
        UnitType mainType = unit.getType();
        UnitTypeChange uc;
        if ((uc = unit.getUnitChange(change, null, newOwner)) == null) {
            ; // mainType is unchanged
        } else if (uc.isAvailableTo(newOwner)) {
            mainType = uc.to;
        } else { // Can not have this unit.
            logger.warning("Change type/owner failed for " + unit
                + " -> " + newOwner + "(" + change + "/" +  uc + ")");
            ((ServerUnit)unit).csRemove(See.perhaps().always(this),
                oldTile, cs);
            return false;
        }

        for (Unit u : unit.getUnitList()) {
            if ((uc = u.getUnitChange(change, null, newOwner)) == null) {
                ; // no change for this passenger
            } else if (uc.isAvailableTo(newOwner)) {
                if (uc.to != u.getType() && !u.changeType(uc.to)) {
                    logger.warning("Type change failure: " + u
                        + " -> " + uc.to);
                }
            } else {
                logger.warning("Change type/owner failed for cargo " + u
                    + " -> " + newOwner + "(" + change + "/" + uc + ")");
                ((ServerUnit)u).csRemove(See.only(this), unit, cs);
            }
        }

        if (mainType != unit.getType() && !unit.changeType(mainType)) {
            logger.warning("Type change failure: " + unit
                + " -> " + mainType);
            return false;
        }
    }
    unit.changeOwner(newOwner);
    if (loc != null) unit.setLocation(loc);
    if (unit.isCarrier()) {
        cs.addRemoves(See.only(this), unit, unit.getUnitList());
    }
    cs.add(See.only(newOwner), newOwner.exploreForUnit(unit));
    return true;
}
 

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

示例13: ServerUnit

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Creates a new ServerUnit.
 *
 * -vis: Visibility issues depending on location.
 * -til: Changes appearance if unit goes into a colony.
 *
 * @param game The {@code Game} in which this unit belongs.
 * @param location The {@code Location} to place this at.
 * @param owner The {@code Player} owning this unit.
 * @param type The type of the unit.
 * @param role The role of the unit.
 */
public ServerUnit(Game game, Location location, Player owner,
                  UnitType type, Role role) {
    super(game);

    final Specification spec = getSpecification();
    this.type = type;
    this.owner = owner;
    this.state = UnitState.ACTIVE; // placeholder
    this.role = getSpecification().getDefaultRole(); // placeholder
    this.location = null;
    this.entryLocation = null;
    this.workLeft = -1;
    this.workType = null;
    this.movesLeft = getInitialMovesLeft();
    this.experienceType = null;
    this.experience = 0;
    this.workImprovement = null;
    this.student = this.teacher = null;
    this.turnsOfTraining = 0;
    this.indianSettlement = null;
    this.destination = null;
    this.tradeRoute = null;
    this.currentStop = -1;
    this.treasureAmount = 0;
    this.attrition = 0;
    this.visibleGoodsCount = -1;

    // Check for creation change
    UnitTypeChange uc = getUnitChange(UnitChangeType.CREATION);
    if (uc != null) this.type = uc.to;

    if (this.type.hasAbility(Ability.PERSON)) {
        this.nationality = owner.getNationId();
        this.ethnicity = nationality;
    } else {
        this.nationality = null;
        this.ethnicity = null;
    }
    this.hitPoints = this.type.getHitPoints();

    // Fix up role, state and location now other values are present.
    changeRole(role, role.getMaximumCount());
    setStateUnchecked(state);
    setLocation(location);//-vis(owner),-til
    if (getType().canCarryGoods()) {
        setGoodsContainer(new GoodsContainer(game, this));
    }

    this.owner.addUnit(this);
}
 

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

示例14: work

点赞 2

import net.sf.freecol.common.model.UnitTypeChange; //导入依赖的package包/类
/**
 * Change work location.
 *
 * @param serverPlayer The <code>ServerPlayer</code> that owns the unit.
 * @param unit The <code>Unit</code> to change the work location of.
 * @param workLocation The <code>WorkLocation</code> to change to.
 * @return An <code>Element</code> encapsulating this action.
 */
public Element work(ServerPlayer serverPlayer, Unit unit,
                    WorkLocation workLocation) {
    ChangeSet cs = new ChangeSet();
    Colony colony = workLocation.getColony();
    colony.getGoodsContainer().saveState();

    if (workLocation instanceof ColonyTile) {
        Tile tile = ((ColonyTile) workLocation).getWorkTile();
        if (tile.getOwningSettlement() != colony) {
            // Claim known free land (because canAdd() succeeded).
            serverPlayer.csClaimLand(tile, colony, 0, cs);
        }
    }

    // Remove any unit equipment
    if (!unit.getEquipment().isEmpty()) {
        ((ServerUnit)unit).csRemoveEquipment(colony,
            new HashSet<EquipmentType>(unit.getEquipment().keySet()),
            0, random, cs);

    }

    // Check for upgrade.
    UnitType oldType = unit.getType();
    UnitTypeChange change = oldType
        .getUnitTypeChange(ChangeType.ENTER_COLONY, unit.getOwner());
    if (change != null) {
        unit.setType(change.getNewUnitType());
    }

    // Change the location.
    // We could avoid updating the whole tile if we knew that this
    // was definitely a move between locations and no student/teacher
    // interaction occurred.
    unit.setLocation(workLocation);
    cs.add(See.perhaps(), colony.getTile());
    // Others can see colony change size
    sendToOthers(serverPlayer, cs);
    return cs.build(serverPlayer);
}
 

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


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