本文整理汇总了Java中net.sf.freecol.common.model.Tile.getUnitList方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getUnitList方法的具体用法?Java Tile.getUnitList怎么用?Java Tile.getUnitList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.getUnitList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(ActionEvent ae) {
final Unit unit = getGUI().getActiveUnit();
final Tile tile = unit.getTile();
if (tile.getColony() != null) {
getGUI().showColonyPanel(tile.getColony(), unit);
} else if (unit.isOnCarrier()) {
getGUI().setActiveUnit(unit.getCarrier());
} else {
boolean activeUnitFound = false;
for (Unit u : tile.getUnitList()) {
if (u == unit) {
activeUnitFound = true;
} else if (activeUnitFound
&& u.getState() == Unit.UnitState.ACTIVE
&& u.getMovesLeft() > 0) {
getGUI().setActiveUnit(u);
return;
}
}
Unit active = find(tile.getUnits(),
u -> (u != unit
&& u.getState() == Unit.UnitState.ACTIVE
&& u.getMovesLeft() > 0));
if (active != null) getGUI().setActiveUnit(active);
}
}
示例2: findUnitInFront
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Gets the unit that should be displayed on the given tile.
*
* @param unitTile The {@code Tile} to check.
* @return The {@code Unit} to display or null if none found.
*/
private Unit findUnitInFront(Tile unitTile) {
Unit result;
if (unitTile == null || unitTile.isEmpty()) {
result = null;
} else if (activeUnit != null && activeUnit.getTile() == unitTile
&& !isOutForAnimation(activeUnit)) {
result = activeUnit;
} else if (unitTile.hasSettlement()) {
result = null;
} else if (activeUnit != null && activeUnit.isOffensiveUnit()) {
result = unitTile.getDefendingUnit(activeUnit);
} else {
// Find the unit with the most moves left, preferring active units.
result = null;
List<Unit> units = unitTile.getUnitList();
int bestScore = -1;
while (!units.isEmpty()) {
Unit u = units.remove(0);
if (isOutForAnimation(u)) continue;
boolean active = u.getState() == Unit.UnitState.ACTIVE;
int score = u.getMovesLeft() + ((active) ? 10000 : 0);
if (bestScore < score) {
bestScore = score;
result = u;
}
}
}
return result;
}
示例3: findUnitInFront
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Gets the unit that should be displayed on the given tile.
*
* @param unitTile The {@code Tile} to check.
* @return The {@code Unit} to display or null if none found.
*/
private Unit findUnitInFront(Tile unitTile) {
Unit result;
if (unitTile == null || unitTile.isEmpty()) {
result = null;
} else if (activeUnit != null && activeUnit.getTile() == unitTile
&& !isOutForAnimation(activeUnit)) {
result = activeUnit;
} else if (unitTile.hasSettlement()) {
result = null;
} else if (activeUnit != null && activeUnit.isOffensiveUnit()) {
result = unitTile.getDefendingUnit(activeUnit);
} else {
// Find the unit with the most moves left, preferring active units.
result = null;
List<Unit> units = unitTile.getUnitList();
int bestScore = -1;
while (!units.isEmpty()) {
Unit u = units.remove(0);
if (isOutForAnimation(u)) continue;
boolean active = u.getState() == Unit.UnitState.ACTIVE;
int score = u.getMovesLeft() + ((active) ? 10000 : 0);
if (bestScore < score) {
bestScore = score;
result = u;
}
if (!active) {
// Also consider units on carriers if the carrier itself
// is not active.
units.addAll(u.getUnitList());
}
}
}
return result;
}
示例4: buildColony
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Use the active unit to build a colony.
*
* Called from BuildColonyAction.
*
* @param unit The {@code Unit} to build the colony.
* @return True if a colony was built.
*/
public boolean buildColony(Unit unit) {
if (!requireOurTurn() || unit == null) return false;
// Check unit, which must be on the map and able to build.
final Tile tile = unit.getTile();
if (tile == null) return false;
if (!unit.canBuildColony()) {
getGUI().showInformationMessage(unit, StringTemplate
.template("buildColony.badUnit")
.addName("%unit%", unit.getName()));
return false;
}
// Join existing colony if present
if (joinColony(unit) || tile.getColony() != null) return false;
// Check for other impediments.
final Player player = getMyPlayer();
NoClaimReason reason = player.canClaimToFoundSettlementReason(tile);
switch (reason) {
case NONE:
case NATIVES: // Tile can still be claimed
break;
default:
getGUI().showInformationMessage(reason.getDescriptionKey());
return false;
}
// Show the warnings if applicable.
if (getClientOptions().getBoolean(ClientOptions.SHOW_COLONY_WARNINGS)) {
StringTemplate warnings = tile.getBuildColonyWarnings(unit);
if (!warnings.getReplacements().isEmpty()
&& !getGUI().confirm(tile, warnings,
unit, "buildColony.yes", "buildColony.no")) {
return false;
}
}
// Get and check the name.
String name = getGUI().getNewColonyName(player, tile);
if (name == null) return false;
// Claim tile from other owners before founding a settlement.
// Only native owners that we can steal, buy from, or use a
// bonus center tile exception should be possible by this point.
UnitWas unitWas = new UnitWas(unit);
boolean ret = player.owns(tile);
if (!ret) {
ret = askClaimTile(player, tile, unit, player.getLandPrice(tile));
if (!ret) NameCache.putSettlementName(player, name);
}
if (ret) {
ret = askServer().buildColony(name, unit)
&& tile.hasSettlement();
if (ret) {
sound("sound.event.buildingComplete");
player.invalidateCanSeeTiles();
unitWas.fireChanges();
// Check units present for treasure cash-in as they are now
// at a colony.
for (Unit u : tile.getUnitList()) checkCashInTreasureTrain(u);
colonyPanel((Colony)tile.getSettlement(), unit);
}
updateGUI(null);
}
return ret;
}