當前位置: 首頁>>代碼示例>>Java>>正文


Java UnitChangeType類代碼示例

本文整理匯總了Java中net.sf.freecol.common.model.UnitChangeType的典型用法代碼示例。如果您正苦於以下問題:Java UnitChangeType類的具體用法?Java UnitChangeType怎麽用?Java UnitChangeType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UnitChangeType類屬於net.sf.freecol.common.model包,在下文中一共展示了UnitChangeType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: clearSpeciality

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的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

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的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: csAddConvert

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
/**
 * Add a new convert to this colony.
 *
 * @param brave The convert {@code Unit}.
 * @param cs A {@code ChangeSet} to update.
 */
public void csAddConvert(Unit brave, ChangeSet cs) {
    if (brave == null) return;
    ServerPlayer newOwner = (ServerPlayer)getOwner();
    ServerPlayer oldOwner = (ServerPlayer)brave.getOwner();
    if (oldOwner.csChangeOwner(brave, newOwner, UnitChangeType.CONVERSION, 
                               getTile(), cs)) { //-vis(other)
        brave.changeRole(getSpecification().getDefaultRole(), 0);
        for (Goods g : brave.getCompactGoodsList()) brave.removeGoods(g);
        brave.setMovesLeft(0);
        brave.setState(Unit.UnitState.ACTIVE);
        cs.addDisappear(newOwner, tile, brave);
        cs.add(See.only(newOwner), getTile());
        StringTemplate nation = oldOwner.getNationLabel();
        cs.addMessage(newOwner,
            new ModelMessage(MessageType.UNIT_ADDED,
                            "model.colony.newConvert", brave)
                .addStringTemplate("%nation%", nation)
                .addName("%colony%", getName()));
        newOwner.invalidateCanSeeTiles();//+vis(other)
        logger.fine("Convert at " + getName() + " for " + getName());
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:29,代碼來源:ServerColony.java

示例4: fixUnitChanges

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
private void fixUnitChanges() {
    if (compareVersion("0.116") > 0) return;

    // Unlike roles, we can not trust what is already there, as the changes
    // are deeper.  However we preserve the ENTER_COLONY change as that
    // comes in from the convertUpgrade mod.
    UnitChangeType enter = find(unitChangeTypeList,
        matchKeyEquals(UnitChangeType.ENTER_COLONY, UnitChangeType::getId));
    File uctf = FreeColDirectories.getCompatibilityFile(UNIT_CHANGE_TYPES_COMPAT_FILE_NAME);
    try (
         FileInputStream fis = new FileInputStream(uctf);
         ) {
        load(fis);
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to load unit changes.", e);
        return;
    }
    if (enter != null) {
        unitChangeTypeList.add(enter);
    }

    logger.info("Loading unit-changes backward compatibility fragment: "
        + UNIT_CHANGE_TYPES_COMPAT_FILE_NAME + " with changes: "
        + transform(getUnitChangeTypeList(), alwaysTrue(),
            UnitChangeType::getId, Collectors.joining(" ")));
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:27,代碼來源:Specification.java

示例5: testUnitTypeChangeOnEnterColony

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

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

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

    addUnitTypeChange(UnitChangeType.ENTER_COLONY, gardenerType, farmerType,
                      100, -1);

    assertEquals(farmerType,
        spec().getUnitChange(UnitChangeType.ENTER_COLONY, gardenerType).to);
    Unit gardener = new ServerUnit(game, null, dutch, gardenerType);
    assertEquals(gardenerType, gardener.getType());
    WorkLocation loc = colony.getWorkLocationFor(gardener);
    assertNotNull(loc);
    gardener.setLocation(colony.getTile());

    igc.work(dutch, gardener, loc);
    assertEquals(farmerType, gardener.getType());
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:29,代碼來源:InGameControllerTest.java

示例6: testCreation

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
public void testCreation() {
    Game game = getStandardGame();
    Player dutch = game.getPlayerByNationId("model.nation.dutch");

    UnitType gardenerType = new UnitType("gardener", spec());

    assertEquals(0, count(spec().getUnitChanges(UnitChangeType.CREATION,
                                                gardenerType)));
    
    addUnitTypeChange(UnitChangeType.CREATION, gardenerType, farmer,
                      100, -1);

    assertEquals(1, count(spec().getUnitChanges(UnitChangeType.CREATION,
                                                gardenerType)));
    assertNotNull(spec().getUnitChange(UnitChangeType.CREATION,
                                       gardenerType));
    assertNotNull(spec().getUnitChange(UnitChangeType.CREATION,
                                       gardenerType, farmer));

    Unit gardenerUnit = new ServerUnit(game, null, dutch, gardenerType);
    assertEquals(farmer, gardenerUnit.getType());

    spec().getUnitChangeType(UnitChangeType.CREATION)
        .deleteUnitChanges(gardenerType);
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:26,代碼來源:UnitChangeTypeTest.java

示例7: fixUnitChanges

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
private void fixUnitChanges() {
    // Unlike roles, we can not trust what is already there, as the changes
    // are deeper.

    if (compareVersion("0.116") > 0) return;

    unitChangeTypeList.clear();
    File uctf = FreeColDirectories.getCompatibilityFile(UNIT_CHANGE_TYPES_COMPAT_FILE_NAME);
    try (
         FileInputStream fis = new FileInputStream(uctf);
         ) {
        load(fis);
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to load unit changes.", e);
        return;
    }

    logger.info("Loading unit-changes backward compatibility fragment: "
        + UNIT_CHANGE_TYPES_COMPAT_FILE_NAME + " with changes: "
        + transform(getUnitChangeTypeList(), alwaysTrue(),
            UnitChangeType::getId, Collectors.joining(" ")));
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:23,代碼來源:Specification.java

示例8: moveLearnSkill

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
/**
 * Move a free colonist to a native settlement to learn a skill following
 * a move of MoveType.ENTER_INDIAN_SETTLEMENT_WITH_FREE_COLONIST.
 * The colonist does not physically get into the village, it will
 * just stay where it is and gain the skill.
 *
 * @param unit The {@code Unit} to learn the skill.
 * @param direction The direction in which the Indian settlement lies.
 * @return True if automatic movement of the unit can proceed (never).
 */
private boolean moveLearnSkill(Unit unit, Direction direction) {
    // Refresh knowledge of settlement skill.  It may have been
    // learned by another player.
    if (askClearGotoOrders(unit)
        && askServer().askSkill(unit, direction)) {
        IndianSettlement is
            = (IndianSettlement)getSettlementAt(unit.getTile(), direction);
        UnitType skill = is.getLearnableSkill();
        if (skill == null) {
            getGUI().showInformationMessage(is, "info.noMoreSkill");
        } else if (unit.getUnitChange(UnitChangeType.NATIVES) == null) {
            getGUI().showInformationMessage(is, StringTemplate
                .template("info.cantLearnSkill")
                .addStringTemplate("%unit%",
                    unit.getLabel(Unit.UnitLabelType.NATIONAL))
                .addNamed("%skill%", skill));
        } else if (getGUI().confirm(unit.getTile(), StringTemplate
                .template("learnSkill.text")
                .addNamed("%skill%", skill),
                unit, "learnSkill.yes", "learnSkill.no")) {
            if (askServer().learnSkill(unit, direction)) {
                if (unit.isDisposed()) {
                    getGUI().showInformationMessage(is, "learnSkill.die");
                } else if (unit.getType() != skill) {
                    getGUI().showInformationMessage(is, "learnSkill.leave");
                }
            }
        }
    }
    return false;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:42,代碼來源:InGameController.java

示例9: clearSpeciality

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的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

示例10: work

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的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

示例11: csCaptureConvert

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
/**
 * Extracts a convert from a native settlement.
 *
 * @param attacker The {@code Unit} that is attacking.
 * @param is The {@code IndianSettlement} under attack.
 * @param random A pseudo-random number source.
 * @param cs A {@code ChangeSet} to update.
 */
private void csCaptureConvert(Unit attacker, IndianSettlement is,
                              Random random, ChangeSet cs) {
    final Specification spec = getGame().getSpecification();
    ServerPlayer attackerPlayer = (ServerPlayer)attacker.getOwner();
    ServerPlayer nativePlayer = (ServerPlayer)is.getOwner();
    StringTemplate convertNation = nativePlayer.getNationLabel();
    List<Unit> units = is.getAllUnitsList();
    ServerUnit convert = (ServerUnit)getRandomMember(logger,
        "Choose convert", units, random);
    if (nativePlayer.csChangeOwner(convert, attackerPlayer,
                                   UnitChangeType.CONVERSION,
                                   attacker.getTile(),
                                   cs)) { //-vis(attackerPlayer)
        convert.changeRole(spec.getDefaultRole(), 0);
        for (Goods g : convert.getCompactGoodsList()) convert.removeGoods(g);
        convert.setMovesLeft(0);
        convert.setState(Unit.UnitState.ACTIVE);
        cs.add(See.only(nativePlayer), is.getTile());
        cs.addMessage(attackerPlayer,
            new ModelMessage(ModelMessage.MessageType.COMBAT_RESULT,
                             "combat.newConvertFromAttack", convert)
                .addStringTemplate("%unit%", attacker.getLabel())
                .addStringTemplate("%enemyNation%", convertNation)
                .addStringTemplate("%enemyUnit%", convert.getLabel()));
        attackerPlayer.invalidateCanSeeTiles();//+vis(attackerPlayer)
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:36,代碼來源:ServerPlayer.java

示例12: getNeededTurnsOfTraining

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
/**
 * Gets the number of turns a unit has to train to educate a student.
 * This value is only meaningful for units that can be put in a school.
 *
 * @param typeTeacher The teacher {@code UnitType}.
 * @param typeStudent the student {@code UnitType}.
 * @return The turns of training needed.
 */
public int getNeededTurnsOfTraining(UnitType typeTeacher,
                                    UnitType typeStudent) {
    UnitType learn = typeStudent.getTeachingType(typeTeacher);
    if (learn == null) {
        throw new RuntimeException("Can not learn: teacher=" + typeTeacher
            + " student=" + typeStudent);
    }
    return getUnitChange(UnitChangeType.EDUCATION, typeStudent, learn).turns;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:18,代碼來源:Specification.java

示例13: testEmptyScope

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
public void testEmptyScope() {
    UnitChangeType uct = spec().getUnitChangeType(UnitChangeType.EDUCATION);

    assertEquals("Education has no scopes", 0, count(uct.getScopes()));

    // empty scope applies to all players
    for (Player player : getStandardGame().getPlayerList(alwaysTrue())) {
        assertTrue("Empty scopes apply to all players",
                   uct.appliesTo(player));
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:12,代碼來源:UnitChangeTypeTest.java

示例14: testAbilityScope

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的package包/類
public void testAbilityScope() {
    Game game = getStandardGame();
    Player dutch = game.getPlayerByNationId("model.nation.dutch");
    Player inca = game.getPlayerByNationId("model.nation.inca");

    UnitType gardenerType = new UnitType("gardener", spec());
    gardenerType.setSkill(0);
    
    assertNull(gardenerType.getTeachingType(farmer));

    addUnitTypeChange(UnitChangeType.EDUCATION, gardenerType, farmer,
                      100, -1);

    assertEquals(farmer, gardenerType.getTeachingType(farmer));

    Scope scope = new Scope();
    scope.setAbilityId(Ability.NATIVE);
    spec().getUnitChangeType(UnitChangeType.EDUCATION).addScope(scope);
    
    assertEquals(farmer, gardenerType.getTeachingType(farmer));
    Unit gardenerUnit = new ServerUnit(game, null, dutch, gardenerType);
    assertNull(gardenerUnit.getTeachingType(farmer));

    scope.setMatchNegated(true);
    assertEquals(farmer, gardenerUnit.getTeachingType(farmer));

    spec().getUnitChangeType(UnitChangeType.EDUCATION)
        .removeScope(scope);
    spec().getUnitChangeType(UnitChangeType.EDUCATION)
        .deleteUnitChanges(gardenerType);
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:32,代碼來源:UnitChangeTypeTest.java

示例15: work

import net.sf.freecol.common.model.UnitChangeType; //導入依賴的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


注:本文中的net.sf.freecol.common.model.UnitChangeType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。