本文整理汇总了Java中net.sf.freecol.common.model.Tile.isLand方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.isLand方法的具体用法?Java Tile.isLand怎么用?Java Tile.isLand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.isLand方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
}
示例2: getEnemySettlementGoalDecider
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Get a goal decider that succeeds for settlements owned by one
* of a given list of enemies.
*
* @param enemies The list of enemy {@code Player}s.
* @return A suitable {@code GoalDecider}.
**/
public static GoalDecider getEnemySettlementGoalDecider(final Collection<Player> enemies) {
return new GoalDecider() {
private PathNode best = null;
@Override
public PathNode getGoal() { return best; }
@Override
public boolean hasSubGoals() { return false; }
@Override
public boolean check(Unit u, PathNode path) {
Tile t = path.getTile();
if (t == null || !t.isLand()) return false;
Settlement s = t.getSettlement();
if (s == null) return false;
if (enemies.contains(s.getOwner())) {
best = path;
return true;
}
return false;
}
};
}
示例3: findTileFor
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
private Tile findTileFor(Map map, int row, int start, boolean startAtSea,
LogBuilder lb) {
Tile tile = null;
Tile seas = null;
int offset = (start == 0) ? 1 : -1;
for (int x = start; 0 <= x && x < map.getWidth(); x += offset) {
tile = map.getTile(x, row);
if (tile.isDirectlyHighSeasConnected()) {
seas = tile;
} else if (tile.isLand()) {
return (startAtSea) ? seas : tile;
}
}
lb.add("No land in row ", row, ".\n");
return null;
}
示例4: drawToMap
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Draws the completed river to the map.
*
* @param sections A list of {@code RiverSection}s to draw.
*/
private void drawToMap(List<RiverSection> sections) {
RiverSection oldSection = null;
for (RiverSection section : sections) {
riverMap.put(section.getTile(), this);
if (oldSection != null) {
section.setBranch(oldSection.direction.getReverseDirection(),
oldSection.getSize());
}
Tile tile = section.getTile();
if (tile.isLand()) {
if (section.getSize() >= TileImprovement.FJORD_RIVER) {
TileType greatRiver = map.getSpecification().getTileType("model.tile.greatRiver");
tile.changeType(greatRiver);
// changing the type resets the improvements
//container.addRiver(section.getSize(), section.encodeStyle());
logger.fine("Added fjord (magnitude: " + section.getSize() +
") to tile: " + section.getTile());
} else if (section.getSize() > TileImprovement.NO_RIVER) {
String style = section.encodeStyle();
tile.addRiver(section.getSize(), style);
logger.fine("Added river"
+ "(magnitude: " + section.getSize()
+ " style: " + style);
}
region.addTile(tile);
oldSection = section;
}
}
}
示例5: scoreUnitPath
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Scores a potential attack on a unit.
*
* @param aiUnit The {@code AIUnit} to do the mission.
* @param path The {@code PathNode} to take to the settlement.
* @param defender The {@code Unit} to attack.
* @return A score of the desirability of the mission.
*/
private static int scoreUnitPath(AIUnit aiUnit, PathNode path,
Unit defender) {
if (invalidUnitReason(aiUnit, defender) != null) {
return Integer.MIN_VALUE;
}
final Unit unit = aiUnit.getUnit();
final Tile tile = path.getLastNode().getTile();
final int turns = path.getTotalTurns();
final CombatModel combatModel = unit.getGame().getCombatModel();
final double off = combatModel.getOffencePower(unit, defender);
final double def = combatModel.getDefencePower(unit, defender);
if (tile == null || off <= 0) return Integer.MIN_VALUE;
int value = 1020 - turns * 100;
value += 100 * (off - def);
// Add a big bonus for treasure trains on the tile.
// Do not cheat and look at the value.
value += 1000 * count(tile.getUnits(),
u -> u.canCarryTreasure() && u.getTreasureAmount() > 0);
if (defender.isNaval()) {
if (tile.isLand()) value += 500; // Easy win
} else {
if (defender.hasAbility(Ability.EXPERT_SOLDIER)
&& !defender.isArmed()) value += 100;
}
return ((MissionAIPlayer)aiUnit.getAIOwner()).adjustMission(
aiUnit, path, UnitSeekAndDestroyMission.class, value);
}
示例6: fillOcean
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Flood fill ocean regions.
*
* @param map The {@code Map} to fill in.
* @param tile A valid starting {@code Tile}.
* @param region A {@code ServerRegion} to fill with.
* @param bounds A {@code Rectangle} that bounds the filling.
* @return The number of tiles filled.
*/
private static int fillOcean(Map map, Tile tile, ServerRegion region,
Rectangle bounds) {
Queue<Tile> q = new LinkedList<>();
int n = 0;
boolean[][] visited = new boolean[map.getWidth()][map.getHeight()];
visited[tile.getX()][tile.getY()] = true;
q.add(tile);
while ((tile = q.poll()) != null) {
region.addTile(tile);
n++;
for (Direction direction : Direction.values()) {
Tile t = map.getAdjacentTile(tile, direction);
if (t != null
&& !visited[t.getX()][t.getY()]
&& bounds.contains(t.getX(), t.getY())) {
visited[t.getX()][t.getY()] = true;
if ((t.getRegion() == null || t.getRegion() == region)
&& !t.isLand()) {
q.add(t);
}
}
}
}
return n;
}
示例7: serverHandler
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ChangeSet serverHandler(FreeColServer freeColServer,
ServerPlayer serverPlayer) {
Unit unit;
try {
unit = getUnit(serverPlayer);
} catch (Exception e) {
return serverPlayer.clientError(e.getMessage());
}
Tile tile = unit.getTile();
if (tile == null) {
return serverPlayer.clientError("Unit is not on the map: "
+ unit.getId());
} else if (!tile.isLand()) {
return serverPlayer.clientError("Unit is not in the new world: "
+ unit.getId());
}
String newLandName = getNewLandName();
if (newLandName == null || newLandName.isEmpty()) {
return serverPlayer.clientError("Empty new land name");
}
// Set name.
return igc(freeColServer)
.setNewLandName(serverPlayer, unit, newLandName);
}
示例8: 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);
}
}
}
}
示例9: makeLostCityRumours
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Make lost city rumours on the given map.
*
* The number of rumours depends on the map size.
*
* @param map The {@code Map} to use.
* @param importMap An optional {@code Map} to import from.
* @param lb A {@code LogBuilder} to log to.
*/
private void makeLostCityRumours(Map map, Map importMap, LogBuilder lb) {
final Game game = map.getGame();
final boolean importRumours = game.getMapGeneratorOptions()
.getBoolean(MapGeneratorOptions.IMPORT_RUMOURS);
if (importMap != null && importRumours) {
// Rumours were read from the import game, no need to do more
return;
}
final int rumourNumber = game.getMapGeneratorOptions()
.getRange(MapGeneratorOptions.RUMOUR_NUMBER);
int number = getApproximateLandCount(game) / rumourNumber;
int counter = 0;
// FIXME: Remove temporary fix:
if (importMap != null) {
number = map.getWidth() * map.getHeight() * 25 / (100 * 35);
}
for (int i = 0; i < number; i++) {
for (int tries = 0; tries < 100; tries++) {
Tile t = map.getRandomLandTile(random);
if (t.isPolar()) continue; // No polar lost cities
if (t.isLand() && !t.hasLostCityRumour()
&& !t.hasSettlement() && t.getUnitCount() == 0) {
LostCityRumour r = new LostCityRumour(t.getGame(), t);
if (r.chooseType(null, random)
== LostCityRumour.RumourType.MOUNDS
&& t.getOwningSettlement() != null) {
r.setType(LostCityRumour.RumourType.MOUNDS);
}
t.addLostCityRumour(r);
counter++;
break;
}
}
}
lb.add("Created ", counter,
" lost city rumours of maximum ", number, ".\n");
}
示例10: testAttrition
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
public void testAttrition() {
final Game game = ServerTestHelper.startServerGame(getTestMap());
final InGameController igc = ServerTestHelper.getInGameController();
Colony colony = getStandardColony();
ServerPlayer player = (ServerPlayer)colony.getOwner();
Unit unit = new ServerUnit(game, colony.getTile(), player,
indianConvertType);
// Starts at zero attrition
assertEquals(0, unit.getAttrition());
// Should stay there because unit is at colony
ServerTestHelper.newTurn();
assertEquals(0, unit.getAttrition());
// Move the unit out, and attrition should start
for (Tile t : colony.getTile().getSurroundingTiles(1, 1)) {
if (t.isLand()) {
unit.setLocation(t);
break;
}
}
ServerTestHelper.newTurn();
assertEquals(1, unit.getAttrition());
// Normal unit is not subject to attrition
Unit colonist = new ServerUnit(game, unit.getTile(), player,
colonistType);
assertEquals(0, colonist.getAttrition());
ServerTestHelper.newTurn();
assertEquals(0, colonist.getAttrition());
// Run down the clock on the convert
while (unit.getAttrition() < unit.getType().getMaximumAttrition()) {
ServerTestHelper.newTurn();
}
assertFalse(unit.isDisposed());
ServerTestHelper.newTurn();
assertTrue(unit.isDisposed());
}
示例11: getSlowedBy
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* If a unit moves, check if an opposing naval unit slows it down.
* Note that the unit moves are reduced here.
*
* @param newTile The {@code Tile} the unit is moving to.
* @param random A pseudo-random number source.
* @return Either an enemy unit that causes a slowdown, or null if none.
*/
private Unit getSlowedBy(Tile newTile, Random random) {
final Player player = getOwner();
final Game game = getGame();
final CombatModel combatModel = game.getCombatModel();
final boolean pirate = hasAbility(Ability.PIRACY);
Unit attacker = null;
double attackPower = 0, totalAttackPower = 0;
if (!isNaval() || getMovesLeft() <= 0) return null;
for (Tile tile : newTile.getSurroundingTiles(1)) {
// Ships in settlements do not slow enemy ships, but:
// FIXME: should a fortress slow a ship?
Player enemy;
if (tile.isLand()
|| tile.getColony() != null
|| tile.getFirstUnit() == null
|| (enemy = tile.getFirstUnit().getOwner()) == player) continue;
for (Unit enemyUnit : transform(tile.getUnits(), u ->
(u.isNaval()
&& ((u.isOffensiveUnit() && player.atWarWith(enemy))
|| pirate || u.hasAbility(Ability.PIRACY))))) {
double power = combatModel.getOffencePower(enemyUnit, this);
totalAttackPower += power;
if (power > attackPower) {
attacker = enemyUnit;
attackPower = power;
}
}
}
if (attacker != null) {
double defencePower = combatModel.getDefencePower(attacker, this);
double totalProbability = totalAttackPower + defencePower;
if (randomInt(logger, "Slowed", random,
(int)Math.round(totalProbability + 1)) < totalAttackPower) {
int diff = Math.max(0,
(int)Math.round(totalAttackPower - defencePower));
int moves = Math.min(9, 3 + diff / 3);
setMovesLeft(getMovesLeft() - moves);
logger.info(getId() + " slowed by " + attacker.getId()
+ " by " + Integer.toString(moves) + " moves.");
} else {
attacker = null;
}
}
return attacker;
}
示例12: addNewUnitToTile
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Debug action to add a new unit to a tile.
*
* Called from tile popup menu.
*
* @param freeColClient The {@code FreeColClient} for the game.
* @param tile The {@code Tile} to add to.
*/
public static void addNewUnitToTile(final FreeColClient freeColClient,
Tile tile) {
final FreeColServer server = freeColClient.getFreeColServer();
final Game sGame = server.getGame();
final Specification sSpec = sGame.getSpecification();
final Player player = freeColClient.getMyPlayer();
final Player sPlayer = sGame.getFreeColGameObject(player.getId(),
Player.class);
final Tile sTile = sGame.getFreeColGameObject(tile.getId(), Tile.class);
final GUI gui = freeColClient.getGUI();
final Function<UnitType, ChoiceItem<UnitType>> mapper = ut ->
new ChoiceItem<UnitType>(Messages.getName(ut), ut);
UnitType unitChoice = gui.getChoice(null,
StringTemplate.template("prompt.selectUnitType"), "cancel",
transform(sSpec.getUnitTypeList(), alwaysTrue(), mapper,
Comparator.naturalOrder()));
if (unitChoice == null) return;
// Is there a server-unit with space left?
Unit sCarrier = (sTile.isLand() || unitChoice.isNaval()) ? null
: find(sTile.getUnitList(), u ->
u.isNaval() && u.getSpaceLeft() >= unitChoice.getSpaceTaken());
ServerUnit sUnit
= new ServerUnit(sGame, ((sCarrier != null) ? sCarrier : sTile),
sPlayer, unitChoice);//-vis(sPlayer)
((ServerPlayer)sPlayer).exploreForUnit(sUnit);
sUnit.setMovesLeft(sUnit.getInitialMovesLeft());
sPlayer.invalidateCanSeeTiles();//+vis(sPlayer)
reconnect(freeColClient);
// Note "game" is no longer valid after reconnect.
Unit unit = freeColClient.getGame()
.getFreeColGameObject(sUnit.getId(), Unit.class);
if (unit != null) {
gui.setActiveUnit(unit);
gui.refresh();
gui.resetMenuBar();
}
}
示例13: getDisembarkGoalDecider
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Goal decider to find the best land tile to disembark a unit that
* is planning to attack a given target.
*
* The result must be:
* - Unoccupied
* - Have at least one unoccupied high-seas-connected neighbour
* - Favour the best natural defence of the alternatives
* - Favour a short journey to the target
* - Prioritize not landing next to a hostile fort/fortress.
*
* @param target The target {@code Tile}.
* @return A suitable {@code GoalDecider}.
*/
public static GoalDecider getDisembarkGoalDecider(final Tile target) {
final double NO_DANGER_BONUS = 1000.0;
return new GoalDecider() {
private double bestScore = -1.0;
private PathNode goal = null;
@Override
public PathNode getGoal() { return goal; }
@Override
public boolean hasSubGoals() { return true; }
@Override
public boolean check(Unit u, PathNode pathNode) {
final Tile tile = pathNode.getTile();
if (tile == null || !tile.isLand() || !tile.isEmpty()
|| tile.hasSettlement()) return false;
final Player owner = u.getOwner();
final Map map = u.getGame().getMap();
final Predicate<Tile> dockPred = t ->
t.isHighSeasConnected() && !t.isLand();
final Predicate<Tile> dangerPred = t -> {
Settlement settlement = t.getSettlement();
return (settlement != null
&& !owner.owns(settlement)
&& settlement.hasAbility(Ability.BOMBARD_SHIPS)
&& (owner.atWarWith(settlement.getOwner())
|| u.hasAbility(Ability.PIRACY)));
};
final ToDoubleFunction<Tile> tileScorer = cacheDouble(t ->
(t.getDefenceValue() / (1.0 + map.getDistance(target, t))
+ ((none(t.getSurroundingTiles(1, 1), dangerPred))
? NO_DANGER_BONUS : 0.0)));
Tile best = maximize(tile.getSurroundingTiles(1, 1), dockPred,
Comparator.comparingDouble(tileScorer));
double score;
if (best != null
&& (score = tileScorer.applyAsDouble(best)) > bestScore) {
bestScore = score;
goal = pathNode;
return true;
}
return false;
}
};
}
示例14: 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));
}
}
}
}