本文整理汇总了Java中net.sf.freecol.common.model.Unit.UnitState类的典型用法代码示例。如果您正苦于以下问题:Java UnitState类的具体用法?Java UnitState怎么用?Java UnitState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitState类属于net.sf.freecol.common.model.Unit包,在下文中一共展示了UnitState类的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: moveAutoload
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Primitive to handle autoloading of a list of units onto a carrier.
*
* @param carrier The carrier {@code Unit} to load onto.
* @param embark A list of {@code Unit}s to load.
* @return True if automatic movement of the carrier can proceed.
*/
private boolean moveAutoload(Unit carrier, List<Unit> embark) {
boolean update = false;
for (Unit u : embark) {
if (!carrier.couldCarry(u)) continue;
try {
update |= askEmbark(u, carrier);
} finally {
if (u.getLocation() != carrier) {
changeState(u, UnitState.SKIPPED);
}
continue;
}
}
if (update) updateGUI(null);
// Boarding might have consumed the carrier moves.
return carrier.couldMove();
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:25,
代码来源:InGameController.java
示例2: changeWorkImprovementType
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Changes the work type of this {@code Unit}.
*
* Called from ImprovementAction.
*
* @param unit The {@code Unit}
* @param improvementType a {@code TileImprovementType} value
* @return True if the improvement was changed.
*/
public boolean changeWorkImprovementType(Unit unit,
TileImprovementType improvementType) {
if (!requireOurTurn() || unit == null || improvementType == null
|| !unit.hasTile()
|| !unit.checkSetState(UnitState.IMPROVING)
|| improvementType.isNatural()) return false;
// May need to claim the tile first
final Player player = getMyPlayer();
final Tile tile = unit.getTile();
UnitWas unitWas = new UnitWas(unit);
boolean ret = player.owns(tile)
|| askClaimTile(player, tile, unit, player.getLandPrice(tile));
if (ret) {
ret = askServer()
.changeWorkImprovementType(unit, improvementType)
&& unit.getWorkImprovement() != null
&& unit.getWorkImprovement().getType() == improvementType;
if (ret) {
unitWas.fireChanges();
}
updateGUI(null);
}
return ret;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:35,
代码来源:InGameController.java
示例3: clearOrders
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Clears the orders of the given unit.
* Make the unit active and set a null destination and trade route.
*
* Called from ClearOrdersAction, TilePopup, TradeRoutePanel, UnitLabel
*
* @param unit The {@code Unit} to clear the orders of
* @return boolean <b>true</b> if the orders were cleared
*/
public boolean clearOrders(Unit unit) {
if (!requireOurTurn() || unit == null) return false;
if (unit.getState() == UnitState.IMPROVING
&& !getGUI().confirm(unit.getTile(), StringTemplate
.template("clearOrders.text")
.addAmount("%turns%", unit.getWorkTurnsLeft()),
unit, "ok", "cancel")) {
return false;
}
UnitWas unitWas = new UnitWas(unit);
boolean ret = askClearGotoOrders(unit)
&& changeState(unit, UnitState.ACTIVE);
if (ret) {
unitWas.fireChanges();
updateGUI(null);
}
return ret;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:30,
代码来源:InGameController.java
示例4: moveUnit
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Moves the active unit in a specified direction. This may result in an
* attack, move... action.
*
* Called from MoveAction, CornerMapControls
*
* @param unit The {@code Unit} to move.
* @param direction The {@code Direction} in which to move
* the active unit.
* @return True if the unit may move further.
*/
public boolean moveUnit(Unit unit, Direction direction) {
if (!requireOurTurn() || unit == null
|| direction == null || !unit.hasTile()) return false;
if (!askClearGotoOrders(unit)) return false;
final Tile oldTile = unit.getTile();
UnitWas unitWas = new UnitWas(unit);
ColonyWas colonyWas = (unit.getColony() == null) ? null
: new ColonyWas(unit.getColony());
changeState(unit, UnitState.ACTIVE);
moveDirection(unit, direction, true);
boolean ret = unit.getTile() != oldTile
|| unitWas.fireChanges();
if (ret) {
if (colonyWas != null) colonyWas.fireChanges();
updateGUI(null);
if (!unit.couldMove() && unit.hasTile()) {
// Show colony panel if unit out of moves
Colony colony = unit.getTile().getColony();
if (colony != null) colonyPanel(colony, unit);
}
}
return ret;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:37,
代码来源:InGameController.java
示例5: doEndTurn
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Really end the turn.
*/
private void doEndTurn() {
// Clear active unit if any.
gui.setActiveUnit(null);
// Unskip all skipped, some may have been faked in-client.
// Server-side skipped units are set active in csNewTurn.
for (Unit unit : freeColClient.getMyPlayer().getUnits()) {
if (unit.getState() == UnitState.SKIPPED) {
unit.setState(UnitState.ACTIVE);
}
}
// Restart the selection cycle.
moveMode = MODE_NEXT_ACTIVE_UNIT;
turnsPlayed++;
// Clear outdated turn report messages.
turnReportMessages = null;
// Inform the server of end of turn.
askServer().endTurn();
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:26,
代码来源:InGameController.java
示例6: changeWorkImprovementType
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Changes the work type of this <code>Unit</code>.
*
* @param unit The <code>Unit</code>
* @param improvementType a <code>TileImprovementType</code> value
*/
public void changeWorkImprovementType(Unit unit,
TileImprovementType improvementType) {
if (!requireOurTurn()) return;
if (!unit.checkSetState(UnitState.IMPROVING)
|| improvementType.isNatural()) {
return; // Don't bother (and don't log, this is not exceptional)
}
Player player = freeColClient.getMyPlayer();
Tile tile = unit.getTile();
if (!player.owns(tile)) {
if (!claimTile(player, tile, unit, player.getLandPrice(tile), 0)
|| !player.owns(tile)) return;
}
if (askServer().changeWorkImprovementType(unit, improvementType)) {
;// Redisplay should work
}
nextActiveUnit();
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:28,
代码来源:InGameController.java
示例7: clearOrders
点赞 3
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Clears the orders of the given unit.
* Make the unit active and set a null destination and trade route.
*
* @param unit The <code>Unit</code> to clear the orders of
* @return boolean <b>true</b> if the orders were cleared
*/
public boolean clearOrders(Unit unit) {
if (!requireOurTurn() || unit == null
|| !unit.checkSetState(UnitState.ACTIVE)) return false;
if (unit.getState() == UnitState.IMPROVING
&& !gui.showConfirmDialog(unit.getTile(),
StringTemplate.template("model.unit.confirmCancelWork")
.addAmount("%turns%", unit.getWorkTurnsLeft()),
"yes", "no")) {
return false;
}
if (unit.getTradeRoute() != null) assignTradeRoute(unit, null);
clearGotoOrders(unit);
return askServer().changeState(unit, UnitState.ACTIVE);
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:24,
代码来源:InGameController.java
示例8: moveEmbark
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的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;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:41,
代码来源:InGameController.java
示例9: changeState
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Changes the state of this {@code Unit}.
*
* Called from FortifyAction, SentryAction, TilePopup, UnitLabel
*
* @param unit The {@code Unit}
* @param state The state of the unit.
* @return True if the state was changed.
*/
public boolean changeState(Unit unit, UnitState state) {
if (!requireOurTurn() || unit == null) return false;
if (unit.getState() == state) return true;
if (!unit.checkSetState(state)) return false;
// Check if this is a hostile fortification, and give the player
// a chance to confirm.
final Player player = getMyPlayer();
if (state == UnitState.FORTIFYING && unit.isOffensiveUnit()
&& !unit.isOwnerHidden()) {
Tile tile = unit.getTile();
if (tile != null && tile.getOwningSettlement() != null) {
Player enemy = tile.getOwningSettlement().getOwner();
if (player != enemy
&& player.getStance(enemy) != Stance.ALLIANCE
&& !getGUI().confirmHostileAction(unit, tile))
return false; // Aborted
}
}
UnitWas unitWas = new UnitWas(unit);
boolean ret = askServer().changeState(unit, state)
&& unit.getState() == state;
if (ret) {
unitWas.fireChanges();
updateGUI(null);
}
return ret;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:39,
代码来源:InGameController.java
示例10: joinColony
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Join the colony at a unit's current location.
*
* @param unit The {@code Unit} to use.
* @return True if the unit joined a colony.
*/
public boolean joinColony(Unit unit) {
final Tile tile = unit.getTile();
final Colony colony = (tile == null) ? null : tile.getColony();
boolean ret = colony != null && askServer().joinColony(unit, colony)
&& unit.getState() == UnitState.IN_COLONY;
if (ret) {
updateGUI(null);
colonyPanel(colony, unit);
}
return ret;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:18,
代码来源:InGameController.java
示例11: changeState
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Change a units state.
*
* @param serverPlayer The {@code ServerPlayer} that owns the unit.
* @param unit The {@code Unit} to change the state of.
* @param state The new {@code UnitState}.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet changeState(ServerPlayer serverPlayer, Unit unit,
UnitState state) {
ChangeSet cs = new ChangeSet();
Tile tile = unit.getTile();
boolean tileDirty = tile != null && tile.getIndianSettlement() != null;
if (state == UnitState.FORTIFYING && tile != null) {
ServerColony colony = (tile.getOwningSettlement() instanceof Colony)
? (ServerColony) tile.getOwningSettlement()
: null;
Player owner = (colony == null) ? null : colony.getOwner();
if (owner != null
&& owner != unit.getOwner()
&& serverPlayer.getStance(owner) != Stance.ALLIANCE
&& serverPlayer.getStance(owner) != Stance.PEACE) {
if (colony.isTileInUse(tile)) {
colony.csEvictUsers(unit, cs);
}
if (serverPlayer.getStance(owner) == Stance.WAR) {
tile.changeOwnership(null, null); // Clear owner if at war
tileDirty = true;
}
}
}
unit.setState(state);
if (tileDirty) {
cs.add(See.perhaps(), tile);
} else {
cs.add(See.perhaps(), (FreeColGameObject)unit.getLocation());
}
// Others might be able to see the unit.
getGame().sendToOthers(serverPlayer, cs);
return cs;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:45,
代码来源:InGameController.java
示例12: add
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean add(Locatable locatable) {
boolean result = super.add(locatable);
if (result && locatable instanceof Unit) {
Unit unit = (Unit) locatable;
unit.setState((unit.canCarryUnits()) ? UnitState.ACTIVE
: UnitState.SENTRY);
}
return result;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:14,
代码来源:Europe.java
示例13: changeState
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Changes the state of this <code>Unit</code>.
*
* @param unit The <code>Unit</code>
* @param state The state of the unit.
*/
public void changeState(Unit unit, UnitState state) {
if (!requireOurTurn()) return;
if (!unit.checkSetState(state)) {
return; // Don't bother (and don't log, this is not exceptional)
}
// Check if this is a hostile fortification, and give the player
// a chance to confirm.
Player player = freeColClient.getMyPlayer();
if (state == UnitState.FORTIFYING && unit.isOffensiveUnit()
&& !unit.hasAbility(Ability.PIRACY)) {
Tile tile = unit.getTile();
if (tile != null && tile.getOwningSettlement() != null) {
Player enemy = tile.getOwningSettlement().getOwner();
if (player != enemy
&& player.getStance(enemy) != Stance.ALLIANCE) {
if (!confirmHostileAction(unit, tile)) return; // Aborted
}
}
}
if (askServer().changeState(unit, state)) {
if (unit == gui.getActiveUnit() && !unit.couldMove()) {
nextActiveUnit();
} else {
gui.refresh();
}
}
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:37,
代码来源:InGameController.java
示例14: moveActiveUnit
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Moves the active unit in a specified direction. This may result in an
* attack, move... action.
*
* @param direction The direction in which to move the active unit.
*/
public void moveActiveUnit(Direction direction) {
Unit unit = gui.getActiveUnit();
if (unit != null && requireOurTurn()) {
unit.setState(UnitState.ACTIVE);
clearGotoOrders(unit);
move(unit, direction);
} // else: nothing: There is no active unit that can be moved.
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:15,
代码来源:InGameController.java
示例15: skipActiveUnit
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Skip a unit.
*/
public void skipActiveUnit() {
final Unit unit = gui.getActiveUnit();
if (unit != null && unit.getState() != UnitState.SKIPPED) {
unit.setState(UnitState.SKIPPED);
}
nextActiveUnit();
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:11,
代码来源:InGameController.java
示例16: changeState
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Change a units state.
*
* @param serverPlayer The <code>ServerPlayer</code> that owns the unit.
* @param unit The <code>Unit</code> to change the state of.
* @param state The new <code>UnitState</code>.
* @return An <code>Element</code> encapsulating this action.
*/
public Element changeState(ServerPlayer serverPlayer, Unit unit,
UnitState state) {
ChangeSet cs = new ChangeSet();
Tile tile;
if (state == UnitState.FORTIFYING && (tile = unit.getTile()) != null) {
ServerColony colony = (tile.getOwningSettlement() instanceof Colony)
? (ServerColony) tile.getOwningSettlement()
: null;
Player owner = (colony == null) ? null : colony.getOwner();
if (owner != null
&& owner != unit.getOwner()
&& serverPlayer.getStance(owner) != Stance.ALLIANCE
&& serverPlayer.getStance(owner) != Stance.PEACE) {
if (colony.isTileInUse(tile)) {
colony.csEvictUser(unit, cs);
}
}
}
unit.setState(state);
cs.add(See.perhaps(), (FreeColGameObject)unit.getLocation());
// Others might be able to see the unit.
sendToOthers(serverPlayer, cs);
return cs.build(serverPlayer);
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:36,
代码来源:InGameController.java
示例17: add
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Adds a <code>Locatable</code> to this Location.
*
* @param locatable The <code>Locatable</code> to add to this Location.
*/
public boolean add(Locatable locatable) {
boolean result = super.add(locatable);
if (result && locatable instanceof Unit) {
Unit unit = (Unit) locatable;
unit.setState((unit.canCarryUnits()) ? UnitState.ACTIVE
: UnitState.SENTRY);
}
return result;
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:15,
代码来源:Europe.java
示例18: moveToDestination
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Moves the given unit towards its destination/s if possible.
*
* @param unit The {@code Unit} to move.
* @param messages An optional list in which to retain any
* trade route {@code ModelMessage}s generated.
* @return True if automatic movement can proceed.
*/
private boolean moveToDestination(Unit unit, List<ModelMessage> messages) {
final Player player = getMyPlayer();
Location destination;
PathNode path;
if (!requireOurTurn()
|| unit.isAtSea()
|| unit.getMovesLeft() <= 0
|| unit.getState() == UnitState.SKIPPED) {
return true;
} else if (unit.getTradeRoute() != null) {
return followTradeRoute(unit, messages);
} else if ((destination = unit.getDestination()) == null) {
return true;
} else if (!changeState(unit, UnitState.ACTIVE)) {
return true;
} else if ((path = unit.findPath(destination)) == null) {
StringTemplate src = unit.getLocation()
.getLocationLabelFor(player);
StringTemplate dst = destination.getLocationLabelFor(player);
StringTemplate template = StringTemplate
.template("info.moveToDestinationFailed")
.addStringTemplate("%unit%",
unit.getLabel(Unit.UnitLabelType.NATIONAL))
.addStringTemplate("%location%", src)
.addStringTemplate("%destination%", dst);
getGUI().showInformationMessage(unit, template);
changeState(unit, UnitState.SKIPPED);
return false;
} else {
// Clear ordinary destinations if arrived.
getGUI().setActiveUnit(unit);
if (!movePath(unit, path)) return false;
if (unit.isAtLocation(destination)) {
if (!askClearGotoOrders(unit)) return false;
Colony colony = (unit.hasTile()) ? unit.getTile().getColony()
: null;
if (colony != null) {
if (!checkCashInTreasureTrain(unit)) colonyPanel(colony, unit);
return false;
}
}
return true;
}
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:55,
代码来源:InGameController.java
示例19: moveTile
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Move a unit in a specified direction on the map, following a
* move of MoveType.MOVE.
*
* @param unit The {@code Unit} to be moved.
* @param direction The direction in which to move the Unit.
* @return True if automatic movement of the unit can proceed.
*/
private boolean moveTile(Unit unit, Direction direction) {
final ClientOptions options = getClientOptions();
List<Unit> ul;
if (unit.canCarryUnits() && unit.hasSpaceLeft()
&& options.getBoolean(ClientOptions.AUTOLOAD_SENTRIES)
&& unit.isInColony()
&& !(ul = unit.getTile().getUnitList()).isEmpty()) {
// Autoload sentries if selected
if (!moveAutoload(unit,
transform(ul, Unit.sentryPred))) return false;
}
// Break up the goto to allow region naming to occur, BR#2707
final Tile newTile = unit.getTile().getNeighbourOrNull(direction);
boolean discover = newTile != null
&& newTile.getDiscoverableRegion() != null;
// Ask the server
if (!askServer().move(unit, direction)) {
// Can fail due to desynchronization. Skip this unit so
// we do not end up retrying indefinitely.
changeState(unit, UnitState.SKIPPED);
return false;
}
unit.getOwner().invalidateCanSeeTiles();
// Perform a short pause on an active unit's last move if the
// option is enabled.
if (unit.getMovesLeft() <= 0
&& options.getBoolean(ClientOptions.UNIT_LAST_MOVE_DELAY)) {
getGUI().paintImmediatelyCanvasInItsBounds();
Utils.delay(UNIT_LAST_MOVE_DELAY, "Last move delay interrupted.");
}
// Update the active unit and GUI.
boolean ret = !unit.isDisposed() && !checkCashInTreasureTrain(unit);
if (ret) {
final Tile tile = unit.getTile();
if (unit.isInColony()
&& unit.isCarrier()
&& unit.getTradeRoute() == null
&& Map.isSameLocation(tile, unit.getDestination())) {
// Bring up colony panel if non-trade-route carrier
// unit just arrived at a destination colony.
// Automatic movement should stop.
colonyPanel(tile.getColony(), unit);
ret = false;
} else {
; // Automatic movement can continue after successful move.
}
}
return ret && !discover;
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:62,
代码来源:InGameController.java
示例20: moveTo
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Moves the specified unit somewhere that requires crossing the high seas.
* Public because this is called from the TilePopup and the Europe panel.
*
* @param unit The <code>Unit</code> to be moved.
* @param destination The <code>Location</code> to be moved to.
* @return True if the unit can possibly move further.
* @throws IllegalArgumentException if destination or unit are null.
*/
public boolean moveTo(Unit unit, Location destination) {
if (!requireOurTurn()) return false;
// Sanity check current state.
if (unit == null || destination == null) {
throw new IllegalArgumentException("moveTo null argument");
} else if (destination instanceof Europe) {
if (unit.isInEurope()) {
gui.playSound("sound.event.illegalMove");
return false;
}
} else if (destination instanceof Map) {
if (unit.getTile() != null
&& unit.getTile().getMap() == destination) {
gui.playSound("sound.event.illegalMove");
return false;
}
} else if (destination instanceof Settlement) {
if (unit.getTile() != null) {
gui.playSound("sound.event.illegalMove");
return false;
}
}
// Autoload emigrants?
if (freeColClient.getClientOptions()
.getBoolean(ClientOptions.AUTOLOAD_EMIGRANTS)
&& unit.isInEurope()) {
for (Unit u : unit.getOwner().getEurope().getUnitList()) {
if (!u.isNaval()
&& u.getState() == UnitState.SENTRY
&& unit.canAdd(u)) {
boardShip(u, unit);
}
}
}
if (askServer().moveTo(unit, destination)) {
nextActiveUnit();
}
return false;
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:52,
代码来源:InGameController.java
示例21: moveToDestination
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Moves the given unit towards its destination/s if possible.
*
* @param unit The <code>Unit</code> to move.
* @return True if the unit reached its destination and has more moves
* to make.
*/
public boolean moveToDestination(Unit unit) {
Location destination;
if (!requireOurTurn()
|| unit.isAtSea()
|| unit.getMovesLeft() <= 0
|| unit.getState() == UnitState.SKIPPED) {
return false;
} else if (unit.getTradeRoute() != null) {
return followTradeRoute(unit);
} else if ((destination = unit.getDestination()) == null) {
return unit.getMovesLeft() > 0;
}
// Find a path to the destination and try to follow it.
final Player player = freeColClient.getMyPlayer();
PathNode path = unit.findPath(destination);
if (path == null) {
StringTemplate src = unit.getLocation()
.getLocationNameFor(player);
StringTemplate dst = destination.getLocationNameFor(player);
gui.showInformationMessage(unit,
StringTemplate.template("selectDestination.failed")
.addStringTemplate("%unit%", Messages.getLabel(unit))
.addStringTemplate("%location%", src)
.addStringTemplate("%destination%", dst));
return false;
}
gui.setActiveUnit(unit);
followPath(unit, path);
// Clear ordinary destinations if arrived.
if (destination != null && unit.isAtLocation(destination)) {
clearGotoOrders(unit);
// Check cash-in, and if the unit has moves left and was
// not set to SKIPPED by moveDirection, then return true
// to show that this unit could continue.
if (!checkCashInTreasureTrain(unit)
&& unit.getMovesLeft() > 0
&& unit.getState() != UnitState.SKIPPED) {
return true;
}
}
return false;
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:52,
代码来源:InGameController.java
示例22: moveMove
点赞 2
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Actually move a unit in a specified direction, following a move
* of MoveType.MOVE.
*
* @param unit The <code>Unit</code> to be moved.
* @param direction The direction in which to move the Unit.
* @return True if the unit can move further.
*/
private boolean moveMove(Unit unit, Direction direction) {
// If we are in a colony, or Europe, load sentries.
if (unit.canCarryUnits() && unit.hasSpaceLeft()
&& (unit.getColony() != null || unit.isInEurope())) {
for (Unit sentry : unit.getLocation().getUnitList()) {
if (sentry.getState() == UnitState.SENTRY) {
if (unit.canAdd(sentry)) {
boardShip(sentry, unit);
logger.finest("Unit " + unit.toString()
+ " loaded sentry " + sentry.toString());
} else {
logger.finest("Unit " + sentry.toString()
+ " is too big to board " + unit.toString());
}
}
}
}
// Ask the server
UnitWas unitWas = new UnitWas(unit);
if (!askServer().move(unit, direction)) return false;
unitWas.fireChanges();
final Tile tile = unit.getTile();
// Perform a short pause on an active unit's last move if
// the option is enabled.
ClientOptions options = freeColClient.getClientOptions();
if (unit.getMovesLeft() <= 0
&& options.getBoolean(ClientOptions.UNIT_LAST_MOVE_DELAY)) {
gui.paintImmediatelyCanvasInItsBounds();
try {
Thread.sleep(UNIT_LAST_MOVE_DELAY);
} catch (InterruptedException e) {} // Ignore
}
// Update the active unit and GUI.
if (unit.isDisposed() || checkCashInTreasureTrain(unit)) return false;
if (tile.getColony() != null
&& unit.isCarrier()
&& unit.getTradeRoute() == null
&& (unit.getDestination() == null
|| unit.getDestination().getTile() == tile.getTile())) {
gui.showColonyPanel(tile.getColony());
}
if (unit.getMovesLeft() <= 0) return false;
displayModelMessages(false);
if (!gui.onScreen(tile)) gui.setSelectedTile(tile, false);
return true;
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:59,
代码来源:InGameController.java
示例23: askChangeState
点赞 1
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* An AIUnit changes state.
*
* @param aiUnit The {@code AIUnit} to change the state of.
* @param state The new {@code UnitState}.
* @return True if the message was sent, and a non-error reply returned.
*/
public static boolean askChangeState(AIUnit aiUnit, UnitState state) {
return aiUnit.getAIOwner().askServer()
.changeState(aiUnit.getUnit(), state);
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:12,
代码来源:AIMessage.java
示例24: ChangeStateMessage
点赞 1
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Create a new {@code ChangeStateMessage} with the
* supplied unit and state.
*
* @param unit The {@code Unit} to change the state of.
* @param state The new state.
*/
public ChangeStateMessage(Unit unit, UnitState state) {
super(TAG, UNIT_TAG, unit.getId(), STATE_TAG, String.valueOf(state));
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:11,
代码来源:ChangeStateMessage.java
示例25: changeState
点赞 1
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* Server query-response for changing unit state.
*
* @param unit The {@code Unit} to change the state of.
* @param state The new {@code UnitState}.
* @return boolean <b>true</b> if the server interaction succeeded.
*/
public boolean changeState(Unit unit, UnitState state) {
return ask(new ChangeStateMessage(unit, state));
}
开发者ID:FreeCol,
项目名称:freecol,
代码行数:11,
代码来源:ServerAPI.java
示例26: askChangeState
点赞 1
import net.sf.freecol.common.model.Unit.UnitState; //导入依赖的package包/类
/**
* An AIUnit changes state.
*
* @param aiUnit The <code>AIUnit</code> to change the state of.
* @param state The new <code>UnitState</code>.
* @return True if the message was sent, and a non-error reply returned.
*/
public static boolean askChangeState(AIUnit aiUnit, UnitState state) {
return sendMessage(aiUnit.getAIOwner().getConnection(),
new ChangeStateMessage(aiUnit.getUnit(), state));
}
开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:12,
代码来源:AIMessage.java