本文整理汇总了Java中net.sf.freecol.common.model.Tile.getDefendingUnit方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getDefendingUnit方法的具体用法?Java Tile.getDefendingUnit怎么用?Java Tile.getDefendingUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.getDefendingUnit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractTarget
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Extract a valid target for this mission from a path.
*
* @param aiUnit A {@code AIUnit} to perform the mission.
* @param path A {@code PathNode} to extract a target from,
* (uses the unit location if null).
* @return A target for this mission, or null if none found.
*/
public static Location extractTarget(AIUnit aiUnit, PathNode path) {
if (path == null) return null;
final Unit unit = aiUnit.getUnit();
final Player owner = unit.getOwner();
final Location loc = path.getLastNode().getLocation();
Settlement settlement = loc.getSettlement();
Tile tile = loc.getTile();
Unit other = (tile == null) ? null : tile.getDefendingUnit(unit);
return (loc instanceof Europe) ? loc
: (other != null
&& invalidUnitReason(aiUnit, other) == null) ? other
: (settlement != null
&& invalidTargetReason(settlement, owner) == null) ? settlement
: null;
}
示例2: confirmPreCombat
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Shows the pre-combat dialog if enabled, allowing the user to
* view the odds and possibly cancel the attack.
*
* @param attacker The attacking {@code Unit}.
* @param tile The target {@code Tile}.
* @return True to attack, false to abort.
*/
public boolean confirmPreCombat(Unit attacker, Tile tile) {
if (getClientOptions().getBoolean(ClientOptions.SHOW_PRECOMBAT)) {
Settlement settlement = tile.getSettlement();
// Don't tell the player how a settlement is defended!
FreeColGameObject defender = (settlement != null) ? settlement
: tile.getDefendingUnit(attacker);
return showPreCombatDialog(attacker, defender, tile);
}
return true;
}
示例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;
}
}
}
return result;
}
示例4: resolveBlockage
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* We have been blocked on the way to a target. Is it valid to
* attack the blockage, or should it just be avoided?
*
* @param aiUnit The {@code AIUnit} that was blocked.
* @param target The target {@code Location}.
* @return The blockage to attack, or null if not.
*/
public static Location resolveBlockage(AIUnit aiUnit, Location target) {
final Unit unit = aiUnit.getUnit();
PathNode path = unit.findPath(target);
Direction d = null;
if (path != null && path.next != null) {
Tile tile = path.next.getTile();
Settlement settlement = tile.getSettlement();
Location blocker = (settlement != null) ? settlement
: tile.getDefendingUnit(unit);
if (UnitSeekAndDestroyMission.invalidReason(aiUnit, blocker)
== null) return blocker;
}
return null;
}
示例5: isTargetValidForSeekAndDestroy
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Find out if a tile contains a suitable target for seek-and-destroy.
*
* FIXME: Package for access by a test only - necessary?
*
* @param attacker The attacking {@code Unit}.
* @param tile The {@code Tile} to attack into.
* @return True if an attack can be launched.
*/
public boolean isTargetValidForSeekAndDestroy(Unit attacker, Tile tile) {
// Insist the attacker exists.
if (attacker == null) return false;
Player attackerPlayer = attacker.getOwner();
// Determine the defending player.
Settlement settlement = tile.getSettlement();
Unit defender = tile.getDefendingUnit(attacker);
Player defenderPlayer = (settlement != null) ? settlement.getOwner()
: (defender != null) ? defender.getOwner()
: null;
// Insist there be a defending player.
if (defenderPlayer == null) return false;
// Can not attack our own units.
if (attackerPlayer == defenderPlayer) return false;
// If European, do not attack if not at war.
// If native, do not attack if not at war and at least content.
// Otherwise some attacks are allowed even if not at war.
boolean atWar = attackerPlayer.atWarWith(defenderPlayer);
if (attackerPlayer.isEuropean()) {
if (!atWar) return false;
} else if (attackerPlayer.isIndian()) {
if (!atWar && attackerPlayer.getTension(defenderPlayer)
.getLevel().compareTo(Tension.Level.CONTENT) <= 0) {
return false;
}
}
return attacker.canAttack(defender);
}
示例6: 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;
}
示例7: confirmHostileAction
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Check if an attack results in a transition from peace or cease fire to
* war and, if so, warn the player.
*
* @param attacker The potential attacking {@code Unit}.
* @param target The target {@code Tile}.
* @return True to attack, false to abort.
*/
public boolean confirmHostileAction(Unit attacker, Tile target) {
if (attacker.hasAbility(Ability.PIRACY)) {
// Privateers can attack and remain at peace
return true;
}
Player enemy;
if (target.hasSettlement()) {
enemy = target.getSettlement().getOwner();
} else if (target == attacker.getTile()) {
// Fortify on tile owned by another nation
enemy = target.getOwner();
if (enemy == null) return true;
} else {
Unit defender = target.getDefendingUnit(attacker);
if (defender == null) {
logger.warning("Attacking, but no defender - will try!");
return true;
}
if (defender.hasAbility(Ability.PIRACY)) {
// Privateers can be attacked and remain at peace
return true;
}
enemy = defender.getOwner();
}
String messageId;
switch (attacker.getOwner().getStance(enemy)) {
case WAR:
logger.finest("Player at war, no confirmation needed");
return true;
case CEASE_FIRE:
messageId = "confirmHostile.ceaseFire";
break;
case ALLIANCE:
messageId = "confirmHostile.alliance";
break;
case UNCONTACTED: case PEACE: default:
messageId = "confirmHostile.peace";
break;
}
return confirm(attacker.getTile(), StringTemplate
.template(messageId)
.addStringTemplate("%nation%", enemy.getNationLabel()),
attacker, "confirmHostile.yes", "cancel");
}