• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java TradeRoute类的典型用法和代码示例

java 1次浏览

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

TradeRoute类属于net.sf.freecol.common.model包,在下文中一共展示了TradeRoute类的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setCurrentStop

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Set a unit stop.
 *
 * @param serverPlayer The {@code ServerPlayer} that owns the unit.
 * @param unit The {@code Unit} to set the destination for.
 * @param index The stop index.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet setCurrentStop(ServerPlayer serverPlayer, Unit unit,
                                int index) {
    TradeRoute tr = unit.getTradeRoute();
    if (tr == null) {
        return serverPlayer.clientError("Unit has no trade route to set stop for.");
    } else if (index < 0 || index >= tr.getStopCount()) {
        return serverPlayer.clientError("Stop index out of range [0.."
            + tr.getStopCount() + "]: " + index);
    }

    unit.setCurrentStop(index);

    // Others can not see a stop change.
    return new ChangeSet().add(See.only(serverPlayer), unit);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:24,
代码来源:InGameController.java

示例2: updateTradeRoute

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Update a trade route for a player.
 *
 * @param serverPlayer The {@code ServerPlayer} to set trade
 *     routes for.
 * @param tradeRoute An uninterned {@code TradeRoute} to update.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet updateTradeRoute(ServerPlayer serverPlayer,
                                  TradeRoute tradeRoute) {
    final Game game = getGame();
    String name;
    StringTemplate fail;
    TradeRoute tr;
    if (tradeRoute == null || tradeRoute.getId() == null
        || (name = tradeRoute.getName()) == null) {
        return serverPlayer.clientError("Bogus route");
    } else if ((fail = tradeRoute.verify()) != null) {
        return serverPlayer.clientError(Messages.message(fail));
    } else if ((tr = game.getFreeColGameObject(tradeRoute.getId(),
                TradeRoute.class)) == null) {
        return serverPlayer.clientError("Not an existing trade route: "
            + tradeRoute.getId());
    }
    tr.copyIn(tradeRoute);
    return new ChangeSet().add(See.only(serverPlayer), tr);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:28,
代码来源:InGameController.java

示例3: csLoseLocation

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Hook for when a player loses access to a location for whatever
 * reason.  Useful for disabling trade routes.
 *
 * @param loc The {@code Location} that was lost.
 * @param cs A {@code ChangeSet} to update.
 */
public void csLoseLocation(Location loc, ChangeSet cs) {
    for (TradeRoute tr : transform(getTradeRoutes(),
                                   r -> r.removeMatchingStops(loc))) {
        for (Unit u : tr.getAssignedUnits()) {
            u.setTradeRoute(null);
            cs.add(See.only(this), u);
        }
        cs.addMessage(this,
            new ModelMessage(ModelMessage.MessageType.GOODS_MOVEMENT,
                "combat.tradeRouteSuspended", this)
                .addName("%route%", tr.getName())
                .addStringTemplate("%stop%", loc.getLocationLabel()));
        cs.add(See.only(this), tr);
    }
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:23,
代码来源:ServerPlayer.java

示例4: serverHandler

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ChangeSet serverHandler(FreeColServer freeColServer,
                               ServerPlayer serverPlayer) {
    final String tradeRouteId = getStringAttribute(TRADE_ROUTE_TAG);
    
    TradeRoute tradeRoute;
    try {
        tradeRoute = serverPlayer.getOurFreeColGameObject(tradeRouteId, 
            TradeRoute.class);
    } catch (Exception e) {
        return serverPlayer.clientError(e.getMessage());
    }

    // Proceed to delete.
    return igc(freeColServer)
        .deleteTradeRoute(serverPlayer, tradeRoute);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:21,
代码来源:DeleteTradeRouteMessage.java

示例5: setCurrentStop

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Set a unit stop.
 *
 * @param serverPlayer The {@code ServerPlayer} that owns the unit.
 * @param unit The {@code Unit} to set the destination for.
 * @param index The stop index.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet setCurrentStop(ServerPlayer serverPlayer, Unit unit,
                                int index) {
    TradeRoute tr = unit.getTradeRoute();
    if (tr == null) {
        return serverPlayer.clientError("Unit has no trade route to set stop for.");
    } else if (index < 0 || index >= tr.getStops().size()) {
        return serverPlayer.clientError("Stop index out of range [0.."
            + tr.getStops().size() + "]: " + index);
    }

    unit.setCurrentStop(index);

    // Others can not see a stop change.
    return new ChangeSet().add(See.only(serverPlayer), unit);
}
 

开发者ID:wintertime,
项目名称:FreeCol,
代码行数:24,
代码来源:InGameController.java

示例6: updateTradeRoute

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Update a trade route for a player.
 *
 * @param serverPlayer The {@code ServerPlayer} to set trade
 *     routes for.
 * @param tradeRoute An uninterned {@code TradeRoute} to update.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet updateTradeRoute(ServerPlayer serverPlayer,
                                  TradeRoute tradeRoute) {
    final Game game = getGame();
    String name;
    StringTemplate fail;
    TradeRoute tr;
    if (tradeRoute == null || tradeRoute.getId() == null
        || (name = tradeRoute.getName()) == null) {
        return serverPlayer.clientError("Bogus route");
    } else if ((fail = tradeRoute.verify()) != null) {
        return serverPlayer.clientError(Messages.message(fail));
    } else if ((tr = game.getFreeColGameObject(tradeRoute.getId(),
                TradeRoute.class)) == null) {
        return serverPlayer.clientError("Not an existing trade route: "
            + tradeRoute.getId());
    }
    tr.setId(tradeRoute.getId());
    tr.copyIn(tradeRoute);

    // Have to update the whole player alas.
    return new ChangeSet().add(See.only(serverPlayer), serverPlayer);
}
 

开发者ID:wintertime,
项目名称:FreeCol,
代码行数:31,
代码来源:InGameController.java

示例7: update

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
public void update() {
    removeAll();

    for (Unit unit : portPanel.getUnitList()) {
        if (accepts(unit)) {

            UnitLabel unitLabel = new UnitLabel(portPanel.getFreeColClient(), unit, portPanel.getGUI());
            TradeRoute tradeRoute = unit.getTradeRoute();
            if (tradeRoute != null) {
                unitLabel.setDescriptionLabel(Messages.message(Messages.getLabel(unit))
                                              + " (" + tradeRoute.getName() + ")");
            }
            if (editable) {
                unitLabel.setTransferHandler(portPanel.getTransferHandler());
                unitLabel.addMouseListener(portPanel.getPressListener());
            }
            add(unitLabel);
        }
    }

    selectLabel();
    revalidate();
    repaint();
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:25,
代码来源:UnitPanel.java

示例8: assignTradeRoute

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Assign a trade route to a unit.
 *
 * @param serverPlayer The <code>ServerPlayer</code> that owns the unit.
 * @param unit The unit <code>Unit</code> to assign to.
 * @param tradeRoute The <code>TradeRoute</code> to assign.
 * @return An <code>Element</code> encapsulating this action.
 */
public Element assignTradeRoute(ServerPlayer serverPlayer, Unit unit,
                                TradeRoute tradeRoute) {
    unit.setTradeRoute(tradeRoute);
    unit.setDestination(null);
    if (tradeRoute != null) {
        List<Stop> stops = tradeRoute.getStops();
        int found = -1;
        for (int i = 0; i < stops.size(); i++) {
            if (unit.getLocation() == stops.get(i).getLocation()) {
                found = i;
                break;
            }
        }
        if (found < 0) found = 0;
        unit.setCurrentStop(found);
    }

    // Only visible to the player
    return new ChangeSet().add(See.only(serverPlayer), unit)
        .build(serverPlayer);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:30,
代码来源:InGameController.java

示例9: handle

点赞 3

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Handle a "updateTradeRoute"-message.
 *
 * @param server The <code>FreeColServer</code> handling the message.
 * @param connection The <code>Connection</code> message was received on.
 *
 * @return An update containing the updateTradeRouted unit,
 *         or an error <code>Element</code> on failure.
 */
public Element handle(FreeColServer server, Connection connection) {
    ServerPlayer serverPlayer = server.getPlayer(connection);

    if (tradeRoute == null || tradeRoute.getId() == null
        || !SetTradeRoutesMessage.hasPrefix(tradeRoute)) {
        return DOMMessage.clientError("Bogus route");
    }

    String id = SetTradeRoutesMessage.removePrefix(tradeRoute);
    TradeRoute realRoute;
    try {
        realRoute = serverPlayer.getFreeColGameObject(id, TradeRoute.class);
    } catch (Exception e) {
        return DOMMessage.clientError(e.getMessage());
    }

    realRoute.updateFrom(tradeRoute);
    tradeRoute.dispose();
    return null;
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:30,
代码来源:UpdateTradeRouteMessage.java

示例10: askAssignTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Ask the server to assign a trade route.
 *
 * @param unit The {@code Unit} to assign to.
 * @param tradeRoute The {@code TradeRoute} to assign.
 * @return True if the assignment succeeds.
 */
private boolean askAssignTradeRoute(Unit unit, TradeRoute tradeRoute) {
    if (tradeRoute == unit.getTradeRoute()) return true;

    if (tradeRoute != null && unit.getTradeRoute() != null) {
        if (!getGUI().confirmClearTradeRoute(unit)) return false;
    }

    return askServer().assignTradeRoute(unit, tradeRoute)
        && unit.getTradeRoute() == tradeRoute;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:18,
代码来源:InGameController.java

示例11: moveHighSeas

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的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);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:36,
代码来源:InGameController.java

示例12: assignTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Assigns a trade route to a unit.
 *
 * Called from EuropePanel.DestinationPanel, TradeRoutePanel(),
 * TradeRoutePanel.newRoute
 *
 * @param unit The {@code Unit} to assign a trade route to.
 * @param tradeRoute The {@code TradeRoute} to assign.
 * @return True if the route was successfully assigned.
 */
public boolean assignTradeRoute(Unit unit, TradeRoute tradeRoute) {
    if (unit == null) return false;

    UnitWas unitWas = new UnitWas(unit);
    boolean ret = askAssignTradeRoute(unit, tradeRoute);
    if (ret) {
        unitWas.fireChanges();
        updateGUI(null);
    }
    return ret;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:22,
代码来源:InGameController.java

示例13: newTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Gets a new trade route for a player.
 *
 * Called from TradeRoutePanel.newRoute.  Relies on new trade routes
 * being added at the end of the trade route list.
 *
 * @param player The {@code Player} to get a new trade route for.
 * @return A new {@code TradeRoute}.
 */
public TradeRoute newTradeRoute(Player player) {
    if (player == null) return null;

    final int n = player.getTradeRouteCount();
    return (askServer().newTradeRoute()
        && player.getTradeRouteCount() == n + 1)
        ? player.getNewestTradeRoute()
        : null;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:19,
代码来源:InGameController.java

示例14: updateList

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Update the list of routes displayed.
 *
 * @param selectRoute An optional {@code TradeRoute} to select.
 */
private void updateList(TradeRoute selectRoute) {
    final Player player = getMyPlayer();

    // Create a sorted list of routes.
    // We are deliberately *not* sorting the player's list.
    List<TradeRoute> routes = new ArrayList<>();
    for (TradeRoute tr : player.getTradeRoutes()) {
        StringTemplate st = tr.verify();
        if (st == null) {
            routes.add(tr);
        } else {
            igc().deleteTradeRoute(tr);
            logger.warning("Dropped trade route: " + Messages.message(st));
        }
    }
    routes.sort(tradeRouteComparator);

    // Update the counts
    this.counts.clear();
    for (Unit u : player.getUnitList()) {
        TradeRoute tradeRoute = u.getTradeRoute();
        if (tradeRoute != null && routes.contains(tradeRoute)) {
            Integer i = counts.get(tradeRoute);
            int value = (i == null) ? 0 : i;
            counts.put(tradeRoute, value + 1);
        }
    }

    // Then add the routes to the list model.
    this.listModel.clear();
    for (TradeRoute route : routes) {
        this.listModel.addElement(route);
    }

    // Select the route if given.
    if (selectRoute != null && this.tradeRoutes != null) {
        this.tradeRoutes.setSelectedValue(selectRoute, true);
    }
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:45,
代码来源:TradeRoutePanel.java

示例15: actionPerformed

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent ae) {
    final String command = ae.getActionCommand();
    if (null == command) return;
    if (command.equals(OK)) {
        final TradeRoute route = getRoute();
        if (this.unit != null && route != null) {
            igc().assignTradeRoute(this.unit, route);
        }
    }
    super.actionPerformed(ae);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:16,
代码来源:TradeRoutePanel.java

示例16: update

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Update this unit panel.
 */
public void update() {
    removeAll();

    if (portPanel != null) {
        for (Unit unit : transform(portPanel.getUnitList(),
                                   u -> accepts(u))) {
            UnitLabel unitLabel
                = new UnitLabel(portPanel.getFreeColClient(), unit);
            TradeRoute tradeRoute = unit.getTradeRoute();
            if (tradeRoute != null) {
                unitLabel.setDescriptionLabel(unit
                    .getDescription(Unit.UnitLabelType.NATIONAL)
                    + " (" + tradeRoute.getName() + ")");
            }
            if (editable) {
                unitLabel.setTransferHandler(portPanel.getTransferHandler());
                unitLabel.addMouseListener(portPanel.getPressListener());
            }
            add(unitLabel);
        }
    }

    selectLabel();
    revalidate();
    repaint();
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:30,
代码来源:UnitPanel.java

示例17: confirmClearTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * If a unit has a trade route, get confirmation that it is
 * ok to clear it and set a destination.
 *
 * @param unit The {@code Unit} to check.
 * @return Whether it is acceptable to set a destination for this unit.
 */
public boolean confirmClearTradeRoute(Unit unit) {
    TradeRoute tr = unit.getTradeRoute();
    if (tr == null) return true;
    StringTemplate template = StringTemplate
        .template("clearTradeRoute.text")
        .addStringTemplate("%unit%",
            unit.getLabel(Unit.UnitLabelType.NATIONAL))
        .addName("%route%", tr.getName());
    return confirm(unit.getTile(), template, unit, "yes", "no");
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:18,
代码来源:GUI.java

示例18: assignTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Assign a trade route to a unit.
 *
 * @param serverPlayer The {@code ServerPlayer} that owns the unit.
 * @param unit The unit {@code Unit} to assign to.
 * @param tradeRoute The {@code TradeRoute} to assign.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet assignTradeRoute(ServerPlayer serverPlayer, Unit unit,
                                  TradeRoute tradeRoute) {
    // If clearing a trade route and the unit is at sea, set
    // the destination to the next stop.  Otherwise just clear
    // the destination.
    TradeRouteStop stop;
    unit.setDestination((tradeRoute == null && unit.isAtSea()
            && (stop = unit.getStop()) != null) ? stop.getLocation()
        : null);
    unit.setTradeRoute(tradeRoute);
    if (tradeRoute != null) {
        List<TradeRouteStop> stops = tradeRoute.getStopList();
        int found = -1;
        for (int i = 0; i < stops.size(); i++) {
            if (Map.isSameLocation(unit.getLocation(),
                                   stops.get(i).getLocation())) {
                found = i;
                break;
            }
        }
        if (found < 0) found = 0;
        unit.setCurrentStop(found);
    }

    // Only visible to the player
    return new ChangeSet().add(See.only(serverPlayer), unit);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:36,
代码来源:InGameController.java

示例19: deleteTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Delete a trade route.
 *
 * @param serverPlayer The {@code ServerPlayer} to delete a trade
 *     route for.
 * @param tradeRoute The {@code TradeRoute} to delete.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet deleteTradeRoute(ServerPlayer serverPlayer,
                                  TradeRoute tradeRoute) {
    List<Unit> dropped = serverPlayer.removeTradeRoute(tradeRoute);

    // Trade route change is entirely internal
    ChangeSet cs = new ChangeSet();
    cs.add(See.only(serverPlayer), serverPlayer); // FIXME: big update
    if (!dropped.isEmpty()) cs.add(See.only(serverPlayer), dropped);
    return cs;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:19,
代码来源:InGameController.java

示例20: newTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Get a new trade route.
 *
 * @return The new {@code TradeRoute}.
 */
public TradeRoute newTradeRoute() {
    TradeRoute route = new TradeRoute(getGame(), getNameForTradeRoute(),
                                      this);
    addTradeRoute(route);
    return route;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:12,
代码来源:ServerPlayer.java

示例21: UpdateTradeRouteMessage

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Create a new {@code UpdateTradeRouteMessage} from a stream.
 *
 * @param game The {@code Game} this message belongs to.
 * @param xr The {@code FreeColXMLReader} to read from.
 * @exception XMLStreamException if there is a problem reading the stream.
 */
public UpdateTradeRouteMessage(Game game, FreeColXMLReader xr)
    throws XMLStreamException {
    this(null);

    FreeColXMLReader.ReadScope rs
        = xr.replaceScope(FreeColXMLReader.ReadScope.NOINTERN);
    TradeRoute tradeRoute = null;
    try {
        while (xr.moreTags()) {
            String tag = xr.getLocalName();
            if (TradeRoute.TAG.equals(tag)) {
                if (tradeRoute == null) {
                    tradeRoute = xr.readFreeColObject(game, TradeRoute.class);
                } else {
                    expected(TAG, tag);
                }
            } else {
                expected(TradeRoute.TAG, tag);
            }
            xr.expectTag(tag);
        }
        xr.expectTag(TAG);
    } finally {
        xr.replaceScope(rs);
    }
    appendChild(tradeRoute);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:35,
代码来源:UpdateTradeRouteMessage.java

示例22: serverHandler

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ChangeSet serverHandler(FreeColServer freeColServer,
                               ServerPlayer serverPlayer) {
    TradeRoute tradeRoute = getTradeRoute();
    if (tradeRoute == null) {
        return serverPlayer.clientError("No trade route to update.");
    }
    
    return igc(freeColServer)
        .updateTradeRoute(serverPlayer, tradeRoute);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:15,
代码来源:UpdateTradeRouteMessage.java

示例23: NewTradeRouteMessage

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Create a new {@code NewTradeRouteMessage} from a stream.
 *
 * @param game The {@code Game} this message belongs to.
 * @param xr The {@code FreeColXMLReader} to read from.
 * @exception XMLStreamException if there is a problem reading the stream.
 */
public NewTradeRouteMessage(Game game, FreeColXMLReader xr)
    throws XMLStreamException {
    this(null);

    FreeColXMLReader.ReadScope rs
        = xr.replaceScope(FreeColXMLReader.ReadScope.NOINTERN);
    TradeRoute tradeRoute = null;
    try {
        while (xr.moreTags()) {
            String tag = xr.getLocalName();
            if (TradeRoute.TAG.equals(tag)) {
                if (tradeRoute == null) {
                    tradeRoute = xr.readFreeColObject(game, TradeRoute.class);
                } else {
                    expected(TAG, tag);
                }
            } else {
                expected(TradeRoute.TAG, tag);
            }
            xr.expectTag(tag);
        }
        xr.expectTag(TAG);
    } finally {
        xr.replaceScope(rs);
    }
    appendChild(tradeRoute);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:35,
代码来源:NewTradeRouteMessage.java

示例24: clientHandler

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void clientHandler(FreeColClient freeColClient) {
    final Game game = freeColClient.getGame();
    final TradeRoute tr = getTradeRoute();

    if (tr == null) return;
    tr.intern();

    igc(freeColClient).newTradeRouteHandler(tr);
    clientGeneric(freeColClient);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:15,
代码来源:NewTradeRouteMessage.java

示例25: serverHandler

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ChangeSet serverHandler(FreeColServer freeColServer,
                               ServerPlayer serverPlayer) {
    final String unitId = getStringAttribute(UNIT_TAG);
    final String indexString = getStringAttribute(INDEX_TAG);

    ServerUnit serverUnit;
    try {
        serverUnit = serverPlayer.getOurFreeColGameObject(unitId, ServerUnit.class);
    } catch (Exception e) {
        return serverPlayer.clientError(e.getMessage());
    }
    TradeRoute tr = serverUnit.getTradeRoute();
    if (tr == null) {
        return serverPlayer.clientError("Unit has no trade route: "
            + unitId);
    }

    int count;
    try {
        count = Integer.parseInt(indexString);
    } catch (NumberFormatException nfe) {
        return serverPlayer.clientError("Stop index is not an integer: " +
            indexString);
    }
    if (count < 0 || count >= tr.getStopCount()) {
        return serverPlayer.clientError("Invalid stop index: "
            + indexString);
    }

    // Valid, set.
    return igc(freeColServer)
        .setCurrentStop(serverPlayer, serverUnit, count);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:38,
代码来源:SetCurrentStopMessage.java

示例26: assignTradeRoute

点赞 2

import net.sf.freecol.common.model.TradeRoute; //导入依赖的package包/类
/**
 * Assign a trade route to a unit.
 *
 * @param serverPlayer The {@code ServerPlayer} that owns the unit.
 * @param unit The unit {@code Unit} to assign to.
 * @param tradeRoute The {@code TradeRoute} to assign.
 * @return A {@code ChangeSet} encapsulating this action.
 */
public ChangeSet assignTradeRoute(ServerPlayer serverPlayer, Unit unit,
                                  TradeRoute tradeRoute) {
    // If clearing a trade route and the unit is at sea, set
    // the destination to the next stop.  Otherwise just clear
    // the destination.
    TradeRouteStop stop;
    unit.setDestination((tradeRoute == null && unit.isAtSea()
            && (stop = unit.getStop()) != null) ? stop.getLocation()
        : null);
    unit.setTradeRoute(tradeRoute);
    if (tradeRoute != null) {
        List<TradeRouteStop> stops = tradeRoute.getStops();
        int found = -1;
        for (int i = 0; i < stops.size(); i++) {
            if (Map.isSameLocation(unit.getLocation(),
                                   stops.get(i).getLocation())) {
                found = i;
                break;
            }
        }
        if (found < 0) found = 0;
        unit.setCurrentStop(found);
    }

    // Only visible to the player
    return new ChangeSet().add(See.only(serverPlayer), unit);
}
 

开发者ID:wintertime,
项目名称:FreeCol,
代码行数:36,
代码来源:InGameController.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)