当前位置: 首页>>代码示例>>Java>>正文


Java Tile.getFirstUnit方法代码示例

本文整理汇总了Java中net.sf.freecol.common.model.Tile.getFirstUnit方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getFirstUnit方法的具体用法?Java Tile.getFirstUnit怎么用?Java Tile.getFirstUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.freecol.common.model.Tile的用法示例。


在下文中一共展示了Tile.getFirstUnit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:25,代码来源:InGameController.java

示例2: csNativeFirstContact

import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
 * Initiate first contact between this European and native player.
 *
 * @param other The native {@code ServerPlayer}.
 * @param tile The {@code Tile} contact is made at if this is
 *     a first landing in the new world and it is owned by the
 *     other player.
 * @param cs A {@code ChangeSet} to update.
 */
public void csNativeFirstContact(ServerPlayer other, Tile tile,
                                 ChangeSet cs) {
    cs.add(See.only(this),
           new FirstContactMessage(this, other, tile));
    csChangeStance(Stance.PEACE, other, true, cs);
    if (tile != null) {
        // Establish a diplomacy session so that if the player
        // accepts the tile offer, we can verify that the offer
        // was made.
        DiplomacySession ds = new DiplomacySession(tile.getFirstUnit(),
            tile.getOwningSettlement(), FreeCol.getTimeout(false));
        ds.setAgreement(DiplomaticTrade
            .makePeaceTreaty(DiplomaticTrade.TradeContext.CONTACT,
                             this, other));
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:26,代码来源:ServerPlayer.java

示例3: getHighSeasGoalDecider

import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
 * Gets a GoalDecider to find the closest high seas tile to a target.
 * Used when arriving on the map from Europe.
 *
 * @return The high seas goal decider.
 */
public static GoalDecider getHighSeasGoalDecider() {
    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 tile = path.getTile();
            if (tile != null
                && tile.isExploredBy(u.getOwner())
                && tile.isDirectlyHighSeasConnected()
                && (tile.getFirstUnit() == null
                    || u.getOwner().owns(tile.getFirstUnit()))) {
                if (best == null || path.getCost() < best.getCost()) {
                    best = path;
                    return true;
                }
            }
            return false;
        }
    };
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:32,代码来源:GoalDeciders.java

示例4: getCost

import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
@Override
public int getCost(Unit unit, Location oldLocation,
                   Location newLocation, int movesLeft) {
    int cost = super.getCost(unit, oldLocation, newLocation, movesLeft);
    Tile tile = newLocation.getTile();
    if (cost != ILLEGAL_MOVE && cost != Map.INFINITY
        && tile != null) {
        final Unit defender = tile.getFirstUnit();
        if (defender != null
            && defender.getOwner() != unit.getOwner()) {
            return ILLEGAL_MOVE;
        } else if (unit.getTradeRoute() != null
            && tile.hasLostCityRumour()) {
            return ILLEGAL_MOVE;
        }
    }
    return cost;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:19,代码来源:CostDeciders.java

示例5: testIsMissionValid

import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
 * Tests validity of mission assignment
 */
public void testIsMissionValid() {
    Game game = setupPrivateerTestGame();
    Map map = game.getMap();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();

    Tile privateerTile = map.getTile(10, 9);
    Tile dutchGalleonTile = map.getTile(12, 9);

    Unit privateer = privateerTile.getFirstUnit();
    assertNotNull("Setup error, could not get privateer", privateer);
    Unit dutchGalleon = dutchGalleonTile.getFirstUnit();
    assertNotNull("Setup error, could not get galleon", dutchGalleon);

    AIPlayer aiPlayer = aiMain.getAIPlayer(privateer.getOwner());
    AIUnit privateerAI = aiMain.getAIUnit(privateer);
    assertNotNull("Setup error, could not get privateerAI", privateerAI);

    privateerAI.setMission(null);
    assertFalse("Privateer has no mission", privateerAI.hasMission());
    assertEquals("PrivateeringMission valid", null,
        PrivateerMission.invalidReason(privateerAI));
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:26,代码来源:PrivateerMissionTest.java

示例6: 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();
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:24,代码来源:InGameController.java

示例7: mouseClicked

import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void mouseClicked(MouseEvent e) {
    if (!e.getComponent().isEnabled()) return;

    // Only process clicks on Button1
    if (e.getButton() != MouseEvent.BUTTON1) return;

    final Tile tile = canvas.convertToMapTile(e.getX(), e.getY());
    if (tile == null) return;

    // Only process events that could not have been gotos.
    final Unit unit = getGUI().getActiveUnit();
    if (e.getClickCount() > 1
        || unit == null
        || unit.getTile() == tile
        || !canvas.isDrag(e.getX(), e.getY())) {
        if (tile.hasSettlement()) {
            getGUI().showTileSettlement(tile);
        } else if (unit == null || unit.getTile() != tile) {
            Unit other = tile.getFirstUnit();
            if (other != null && getMyPlayer().owns(other)) {
                getGUI().setActiveUnit(other);
                getGUI().changeViewMode(GUI.MOVE_UNITS_MODE);
            } else {
                getGUI().setSelectedTile(tile);
                getGUI().changeViewMode(GUI.VIEW_TERRAIN_MODE);
            }
        } else {
            getGUI().setSelectedTile(tile);
            getGUI().changeViewMode(GUI.VIEW_TERRAIN_MODE);
        }
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:36,代码来源:CanvasMouseListener.java

示例8: nativeFirstContact

import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
 * Handle first contact between European and native player.
 *
 * Note that we check for a diplomacy session, but only bother in
 * the case of tile!=null as that is the only possibility for some
 * benefit.
 *
 * @param serverPlayer The {@code ServerPlayer} making contact.
 * @param other The native {@code ServerPlayer} to contact.
 * @param tile A {@code Tile} on offer at first landing.
 * @param result Whether the initial peace treaty was accepted.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet nativeFirstContact(ServerPlayer serverPlayer,
                                    ServerPlayer other, Tile tile,
                                    boolean result) {
    ChangeSet cs = new ChangeSet();
    DiplomacySession session = null;
    if (tile != null) {
        Unit u = tile.getFirstUnit();
        Settlement s = tile.getOwningSettlement();
        if (u != null && s != null) {
            session = DiplomacySession.findContactSession(u, s);
        }
    }
    if (result) {
        if (tile != null) {
            if (session == null) {
                return serverPlayer.clientError("No diplomacy for: "
                    + tile.getId());
            }
            tile.cacheUnseen();//+til
            tile.changeOwnership(serverPlayer, null);//-til
            cs.add(See.perhaps(), tile);
        }
    } else {
        // Consider not accepting the treaty to be an insult and
        // ban missions.
        other.csModifyTension(serverPlayer,
            Tension.TENSION_ADD_MAJOR, cs);//+til
        other.addMissionBan(serverPlayer);
    }
    if (session != null) session.complete(result, cs);
    getGame().sendToOthers(serverPlayer, cs);
    return cs;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:47,代码来源:InGameController.java

示例9: 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;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:55,代码来源:ServerUnit.java


注:本文中的net.sf.freecol.common.model.Tile.getFirstUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。