本文整理汇总了Java中net.sf.freecol.common.model.Tile.getNeighbourOrNull方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getNeighbourOrNull方法的具体用法?Java Tile.getNeighbourOrNull怎么用?Java Tile.getNeighbourOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.getNeighbourOrNull方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveAttack
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Confirm attack or demand a tribute from a native settlement, following
* an attacking move.
*
* @param unit The {@code Unit} to perform the attack.
* @param direction The direction in which to attack.
* @return True if automatic movement of the unit can proceed (never).
*/
private boolean moveAttack(Unit unit, Direction direction) {
final Tile tile = unit.getTile();
final Tile target = tile.getNeighbourOrNull(direction);
final Unit u = target.getFirstUnit();
if (u == null || unit.getOwner().owns(u)) return false;
if (askClearGotoOrders(unit)
&& getGUI().confirmHostileAction(unit, target)
&& getGUI().confirmPreCombat(unit, target)) {
askServer().attack(unit, direction);
}
// Always return false, as the unit has either attacked and lost
// its remaining moves, or the move can not proceed because it is
// blocked.
return false;
}
示例2: moveTribute
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Demand a tribute.
*
* @param unit The {@code Unit} to perform the attack.
* @param amount An amount of tribute to demand.
* @param direction The direction in which to attack.
* @return True if automatic movement of the unit can proceed (never).
*/
private boolean moveTribute(Unit unit, int amount, Direction direction) {
final Game game = getGame();
Player player = unit.getOwner();
Tile tile = unit.getTile();
Tile target = tile.getNeighbourOrNull(direction);
Settlement settlement = target.getSettlement();
Player other = settlement.getOwner();
// Indians are easy and can use the basic tribute mechanism.
if (settlement.getOwner().isIndian()) {
askServer().demandTribute(unit, direction);
return false;
}
// Europeans might be human players, so we convert to a diplomacy
// dialog.
DiplomaticTrade agreement = DiplomaticTrade
.makePeaceTreaty(TradeContext.TRIBUTE, player, other);
agreement.add(new GoldTradeItem(game, other, player, amount));
return moveDiplomacy(unit, direction, agreement);
}
示例3: transform
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
@Override
public void transform(Tile tile) {
TileImprovementType riverType =
tile.getSpecification().getTileImprovementType("model.improvement.river");
if (riverType.isTileTypeAllowed(tile.getType())) {
if (!tile.hasRiver()) {
StringBuilder sb = new StringBuilder(64);
for (Direction direction : Direction.longSides) {
Tile t = tile.getNeighbourOrNull(direction);
TileImprovement otherRiver = (t == null) ? null
: t.getRiver();
if (t == null || (t.isLand() && otherRiver == null)) {
sb.append('0');
} else {
sb.append(magnitude);
}
}
tile.addRiver(magnitude, sb.toString());
} else {
tile.removeRiver();
}
}
}
示例4: getNationAt
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Convenience function to find the nation controlling an adjacent
* settlement. Intended to be called in contexts where we are
* expecting a settlement or unit to be there, such as when
* handling a particular move type.
*
* @param tile The {@code Tile} to start at.
* @param direction The {@code Direction} to step.
* @return The name of the nation controlling a settlement on the
* adjacent tile if any.
*/
private StringTemplate getNationAt(Tile tile, Direction direction) {
Tile newTile = tile.getNeighbourOrNull(direction);
Player player = null;
if (newTile.hasSettlement()) {
player = newTile.getSettlement().getOwner();
} else if (newTile.getFirstUnit() != null) {
player = newTile.getFirstUnit().getOwner();
} else { // should not happen
player = getGame().getUnknownEnemy();
}
return player.getNationLabel();
}
示例5: moveAttackSettlement
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Confirm attack or demand a tribute from a settlement, following
* an attacking move.
*
* @param unit The {@code Unit} to perform the attack.
* @param direction The direction in which to attack.
* @return True if automatic movement of the unit can proceed (never).
*/
private boolean moveAttackSettlement(Unit unit, Direction direction) {
final Tile tile = unit.getTile();
final Tile target = tile.getNeighbourOrNull(direction);
final Settlement settlement = target.getSettlement();
if (settlement == null
|| unit.getOwner().owns(settlement)) return false;
ArmedUnitSettlementAction act
= getGUI().getArmedUnitSettlementChoice(settlement);
if (act == null) return false; // Cancelled
switch (act) {
case SETTLEMENT_ATTACK:
if (getGUI().confirmHostileAction(unit, target)
&& getGUI().confirmPreCombat(unit, target)) {
askServer().attack(unit, direction);
Colony col = target.getColony();
if (col != null && unit.getOwner().owns(col)) {
colonyPanel(col, unit);
}
}
break;
case SETTLEMENT_TRIBUTE:
int amount = (settlement instanceof Colony)
? getGUI().confirmEuropeanTribute(unit, (Colony)settlement,
nationSummary(settlement.getOwner()))
: (settlement instanceof IndianSettlement)
? getGUI().confirmNativeTribute(unit, (IndianSettlement)settlement)
: -1;
if (amount > 0) return moveTribute(unit, amount, direction);
break;
default:
logger.warning("showArmedUnitSettlementDialog fail: " + act);
break;
}
return false;
}
示例6: moveEmbark
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Embarks the specified unit onto a carrier in a specified direction
* following a move of MoveType.EMBARK.
*
* @param unit The {@code Unit} that wishes to embark.
* @param direction The direction in which to embark.
* @return True if automatic movement of the unit can proceed (never).
*/
private boolean moveEmbark(Unit unit, Direction direction) {
if (unit.getColony() != null
&& !getGUI().confirmLeaveColony(unit)) return false;
final Tile sourceTile = unit.getTile();
final Tile destinationTile = sourceTile.getNeighbourOrNull(direction);
Unit carrier = null;
List<ChoiceItem<Unit>> choices
= transform(destinationTile.getUnits(),
u -> u.canAdd(unit),
u -> new ChoiceItem<>(u.getDescription(Unit.UnitLabelType.NATIONAL), u));
if (choices.isEmpty()) {
throw new RuntimeException("Unit " + unit.getId()
+ " found no carrier to embark upon.");
} else if (choices.size() == 1) {
carrier = choices.get(0).getObject();
} else {
carrier = getGUI().getChoice(unit.getTile(),
Messages.message("embark.text"), unit, "none", choices);
if (carrier == null) return false; // User cancelled
}
// Proceed to embark, skip if it did not work.
if (askClearGotoOrders(unit)
&& askServer().embark(unit, carrier, direction)
&& unit.getLocation() == carrier) {
unit.getOwner().invalidateCanSeeTiles();
} else {
changeState(unit, UnitState.SKIPPED);
}
return false;
}
示例7: moveHighSeas
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Moves a unit onto the "high seas" in a specified direction following
* a move of MoveType.MOVE_HIGH_SEAS.
* This may result in a move to Europe, no move, or an ordinary move.
*
* @param unit The {@code Unit} to be moved.
* @param direction The direction in which to move.
* @return True if automatic movement of the unit can proceed.
*/
private boolean moveHighSeas(Unit unit, Direction direction) {
// Confirm moving to Europe if told to move to a null tile
// (FIXME: can this still happen?), or if crossing the boundary
// between coastal and high sea. Otherwise just move.
final Tile oldTile = unit.getTile();
final Tile newTile = oldTile.getNeighbourOrNull(direction);
if (newTile == null
|| (!oldTile.isDirectlyHighSeasConnected()
&& newTile.isDirectlyHighSeasConnected())) {
TradeRouteStop stop;
if (unit.getTradeRoute() != null
&& (stop = unit.getStop()) != null
&& TradeRoute.isStopValid(unit, stop)
&& stop.getLocation() instanceof Europe) {
return moveTowardEurope(unit, (Europe)stop.getLocation());
} else if (unit.getDestination() instanceof Europe) {
return moveTowardEurope(unit, (Europe)unit.getDestination());
} else if (getGUI().confirm(oldTile, StringTemplate
.template("highseas.text")
.addAmount("%number%", unit.getSailTurns()),
unit, "highseas.yes", "highseas.no")) {
return moveTowardEurope(unit, unit.getOwner().getEurope());
}
}
return moveTile(unit, direction);
}
示例8: moveTileCursor
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Move the tile cursor.
*
* Called from MoveAction in terrain mode.
*
* @param direction The {@code Direction} to move the tile cursor.
* @return True if the tile cursor is moved.
*/
public boolean moveTileCursor(Direction direction) {
if (direction == null) return false;
final Tile tile = getGUI().getSelectedTile();
if (tile == null) return false;
final Tile newTile = tile.getNeighbourOrNull(direction);
if (newTile == null) return false;
getGUI().setSelectedTile(newTile);
return true;
}
示例9: displayUnknownTileBorder
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
void displayUnknownTileBorder(Graphics2D g, Tile tile) {
if (tile.isExplored()) {
for (Direction direction : Direction.values()) {
Tile borderingTile = tile.getNeighbourOrNull(direction);
if (borderingTile != null && !borderingTile.isExplored()) {
g.drawImage(lib.getBorderImage(
null, direction, tile.getX(), tile.getY()),
0, 0, null);
}
}
}
}
示例10: initialize
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Initialize the game data in this tiles panel.
*/
public void initialize() {
final Colony colony = getColony();
if (colony == null) return;
cleanup();
Tile tile = colony.getTile();
tiles[0][0] = tile.getNeighbourOrNull(Direction.N);
tiles[0][1] = tile.getNeighbourOrNull(Direction.NE);
tiles[0][2] = tile.getNeighbourOrNull(Direction.E);
tiles[1][0] = tile.getNeighbourOrNull(Direction.NW);
tiles[1][1] = tile;
tiles[1][2] = tile.getNeighbourOrNull(Direction.SE);
tiles[2][0] = tile.getNeighbourOrNull(Direction.W);
tiles[2][1] = tile.getNeighbourOrNull(Direction.SW);
tiles[2][2] = tile.getNeighbourOrNull(Direction.S);
int layer = 2;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
if (tiles[x][y] == null) {
logger.warning("Null tile for " + getColony()
+ " at " + x + "," + y);
continue;
}
ColonyTile colonyTile = colony.getColonyTile(tiles[x][y]);
if (colonyTile == null) {
logger.warning("Null colony tile for " + getColony()
+ " on " + tiles[x][y] + " at " + x + "," + y);
dump("TILES", colony.getColonyTiles());
continue;
}
ASingleTilePanel aSTP
= new ASingleTilePanel(colonyTile, x, y);
aSTP.initialize();
add(aSTP, Integer.valueOf(layer++));
}
}
update();
}
示例11: displayTileWithBeachAndBorder
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Displays the given Tile onto the given Graphics2D object at the
* location specified by the coordinates. Only base terrain will be drawn.
*
* @param g The Graphics2D object on which to draw the Tile.
* @param tile The Tile to draw.
*/
void displayTileWithBeachAndBorder(Graphics2D g, Tile tile) {
if (tile != null) {
TileType tileType = tile.getType();
int x = tile.getX();
int y = tile.getY();
// ATTENTION: we assume that all base tiles have the same size
g.drawImage(lib.getTerrainImage(tileType, x, y),
0, 0, null);
if (tile.isExplored()) {
if (!tile.isLand() && tile.getStyle() > 0) {
int edgeStyle = tile.getStyle() >> 4;
if (edgeStyle > 0) {
g.drawImage(lib.getBeachEdgeImage(edgeStyle, x, y),
0, 0, null);
}
int cornerStyle = tile.getStyle() & 15;
if (cornerStyle > 0) {
g.drawImage(lib.getBeachCornerImage(cornerStyle, x, y),
0, 0, null);
}
}
List<SortableImage> imageBorders = new ArrayList<>(8);
SortableImage si;
for (Direction direction : Direction.values()) {
Tile borderingTile = tile.getNeighbourOrNull(direction);
if (borderingTile != null && borderingTile.isExplored()) {
TileType borderingTileType = borderingTile.getType();
if (borderingTileType != tileType) {
if (!tile.isLand() && borderingTile.isLand()) {
// If there is a Coast image (eg. beach) defined, use it, otherwise skip
// Draw the grass from the neighboring tile, spilling over on the side of this tile
si = new SortableImage(
lib.getBorderImage(borderingTileType, direction, x, y),
borderingTileType.getIndex());
imageBorders.add(si);
TileImprovement river = borderingTile.getRiver();
if (river != null) {
int magnitude = river.getRiverConnection(
direction.getReverseDirection());
if (magnitude > 0) {
si = new SortableImage(
lib.getRiverMouthImage(direction,
magnitude, x, y),
-1);
imageBorders.add(si);
}
}
} else if (!tile.isLand() || borderingTile.isLand()) {
if (borderingTileType.getIndex() < tileType.getIndex() &&
!lib.getTerrainImage(tileType, 0, 0).equals(lib.getTerrainImage(borderingTileType, 0, 0))) {
// Draw land terrain with bordering land type, or ocean/high seas limit,
// if the tiles do not share same graphics (ocean & great river)
si = new SortableImage(
lib.getBorderImage(borderingTileType, direction, x, y),
borderingTileType.getIndex());
imageBorders.add(si);
}
}
}
}
}
for (SortableImage sorted : sort(imageBorders)) {
g.drawImage(sorted.image, 0, 0, null);
}
}
}
}
示例12: perhapsAddBonus
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Adds a terrain bonus with a probability determined by the
* {@code MapGeneratorOptions}.
*
* @param t The {@code Tile} to add bonuses to.
* @param generateBonus Generate the bonus or not.
*/
private void perhapsAddBonus(Tile t, boolean generateBonus) {
final Game game = t.getGame();
final OptionGroup mapOptions = game.getMapGeneratorOptions();
final Specification spec = game.getSpecification();
TileImprovementType fishBonusLandType
= spec.getTileImprovementType("model.improvement.fishBonusLand");
TileImprovementType fishBonusRiverType
= spec.getTileImprovementType("model.improvement.fishBonusRiver");
final int bonusNumber
= mapOptions.getRange(MapGeneratorOptions.BONUS_NUMBER);
if (t.isLand()) {
if (generateBonus
&& randomInt(logger, "Land Resource", random, 100) < bonusNumber) {
// Create random Bonus Resource
t.addResource(createResource(t));
}
} else {
int adjacentLand = 0;
boolean adjacentRiver = false;
for (Direction direction : Direction.values()) {
Tile otherTile = t.getNeighbourOrNull(direction);
if (otherTile != null && otherTile.isLand()) {
adjacentLand++;
if (otherTile.hasRiver()) {
adjacentRiver = true;
}
}
}
// In Col1, ocean tiles with less than 3 land neighbours
// produce 2 fish, all others produce 4 fish
if (adjacentLand > 2) {
t.add(new TileImprovement(game, t, fishBonusLandType, null));
}
// In Col1, the ocean tile in front of a river mouth would
// get an additional +1 bonus
// FIXME: This probably has some false positives, means
// river tiles that are NOT a river mouth next to this tile!
if (!t.hasRiver() && adjacentRiver) {
t.add(new TileImprovement(game, t, fishBonusRiverType, null));
}
if (t.getType().isHighSeasConnected()) {
if (generateBonus && adjacentLand > 1
&& randomInt(logger, "Sea resource", random,
10 - adjacentLand) == 0) {
t.addResource(createResource(t));
}
} else {
if (randomInt(logger, "Water resource", random, 100) < bonusNumber) {
// Create random Bonus Resource
t.addResource(createResource(t));
}
}
}
}
示例13: testUnitLumberDelivery
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
public void testUnitLumberDelivery() {
Game game = ServerTestHelper.startServerGame(getTestMap(savannahForest));
InGameController igc = ServerTestHelper.getInGameController();
Colony colony = getStandardColony(3);
ServerPlayer player = (ServerPlayer)colony.getOwner();
Tile tile = colony.getTile();
// Set up a hardy pioneer to clear the colony tile
Role pioneerRole = spec().getRole("model.role.pioneer");
ServerUnit hardyPioneer = new ServerUnit(game, tile, player,
pioneerType, pioneerRole);
igc.changeWorkImprovementType(player, hardyPioneer, clear);
// Verify initial state
assertEquals(8, hardyPioneer.getWorkLeft());
assertEquals(savannahForest, tile.getType());
assertEquals(colony, tile.getOwningSettlement());
// Almost finish clearing
ServerTestHelper.newTurn();
ServerTestHelper.newTurn();
ServerTestHelper.newTurn();
// Lumber should be delivered on this turn
colony.removeGoods(lumberType);
ServerTestHelper.newTurn();
assertEquals("Lumber delivery with hardy pioneer", 20 * 2,
colony.getGoodsCount(lumberType));
// Upgrade to lumber mill and full warehouse
assertTrue(none(colony.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION)));
colony.getBuilding(carpenterHouseType).upgrade();
colony.getBuilding(warehouseType).upgrade();
assertEquals(1,
count(colony.getModifiers(Modifier.TILE_TYPE_CHANGE_PRODUCTION)));
// Almost clear another tile
Tile tile2 = tile.getNeighbourOrNull(Direction.N);
assertEquals(colony, tile2.getOwningSettlement());
hardyPioneer.setLocation(tile2);
hardyPioneer.setMovesLeft(1);
igc.changeWorkImprovementType(player, hardyPioneer, clear);
ServerTestHelper.newTurn();
ServerTestHelper.newTurn();
ServerTestHelper.newTurn();
// Lumber should be delivered on this turn
colony.removeGoods(lumberType);
ServerTestHelper.newTurn();
assertEquals("Lumber delivered with hardy pioneer and mill",
20 * 2 * 3, colony.getGoodsCount(lumberType));
}