本文整理汇总了Java中net.sf.freecol.common.model.Tile.changeOwnership方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.changeOwnership方法的具体用法?Java Tile.changeOwnership怎么用?Java Tile.changeOwnership使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.changeOwnership方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeState
import net.sf.freecol.common.model.Tile; //导入方法依赖的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;
}
示例2: 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;
}
示例3: csClaimLand
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Claim land.
*
* @param tile The {@code Tile} to claim.
* @param settlement The {@code Settlement} to claim for.
* @param price The price to pay for the land, which must agree
* with the owner valuation, unless negative which denotes stealing.
* @param cs A {@code ChangeSet} to update.
*/
public void csClaimLand(Tile tile, Settlement settlement, int price,
ChangeSet cs) {
ServerPlayer owner = (ServerPlayer)tile.getOwner();
Settlement ownerSettlement = tile.getOwningSettlement();
tile.cacheUnseen();//+til
tile.changeOwnership(this, settlement);//-vis(?),-til
// Update the tile and any now-angrier owners, and the player
// gold if a price was paid.
cs.add(See.perhaps(), tile);
if (price > 0) {
modifyGold(-price);
owner.modifyGold(price);
cs.addPartial(See.only(this), this,
"gold", String.valueOf(this.getGold()));
} else if (price < 0 && owner.isIndian()) {
ServerIndianSettlement sis = (ServerIndianSettlement)ownerSettlement;
if (sis == null) {
owner.csModifyTension(this, Tension.TENSION_ADD_LAND_TAKEN,
cs);
} else {
sis.csModifyAlarm(this, Tension.TENSION_ADD_LAND_TAKEN,
true, cs);
}
}
logger.finest(this.getName() + " claimed " + tile
+ " from " + ((owner == null) ? "no-one" : owner.getName())
+ ", price: " + ((price == 0) ? "free" : (price < 0) ? "stolen"
: price));
}
示例4: testHorseBreedingNoFoodAvail
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
public void testHorseBreedingNoFoodAvail() {
Game game = ServerTestHelper.startServerGame(getTestMap(desertType));
int initialBravesInCamp = 3;
FreeColTestCase.IndianSettlementBuilder builder = new FreeColTestCase.IndianSettlementBuilder(game);
IndianSettlement camp1 = builder.initialBravesInCamp(initialBravesInCamp).build();
IndianSettlement camp2 = builder.reset()
.settlementTile(camp1.getTile().getNeighbourOrNull(Direction.N)
.getNeighbourOrNull(Direction.N)).build();
//////////////////////
// Simulate that only the center tile is owned by camp 1
// Does not matter where camp 2 is, so we put it in the same tile as camp1
for (Tile t: camp1.getTile().getSurroundingTiles(camp1.getRadius())) {
t.changeOwnership(camp2.getOwner(), camp2);
}
//verify initial conditions
assertEquals(initialBravesInCamp, camp1.getUnitCount());
assertEquals(0, camp1.getGoodsCount(foodType));
int foodProduced = camp1.getTotalProductionOf(grainType);
int foodConsumed = camp1.getFoodConsumption();
assertEquals(2, brave.getConsumptionOf(foodType));
assertEquals(2 * camp1.getUnitCount(), foodConsumed);
assertTrue("Food Produced should be less the food consumed",foodProduced < foodConsumed);
//add horses
int initialHorses = 2;
camp1.addGoods(horsesType, initialHorses);
ServerTestHelper.newTurn();
int expectedHorsesBreeded = 0;
int horsesBreeded = camp1.getGoodsCount(horsesType) - initialHorses;
assertEquals("No horses should be bred",expectedHorsesBreeded,horsesBreeded);
}