本文整理汇总了Java中net.sf.freecol.common.model.Tile.getOwningSettlement方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getOwningSettlement方法的具体用法?Java Tile.getOwningSettlement怎么用?Java Tile.getOwningSettlement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.getOwningSettlement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
示例2: changeState
import net.sf.freecol.common.model.Tile; //导入方法依赖的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;
}
示例3: 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;
}
示例4: 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;
}
示例5: work
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Change work location.
*
* @param serverPlayer The {@code ServerPlayer} that owns the unit.
* @param unit The {@code Unit} to change the work location of.
* @param workLocation The {@code WorkLocation} to change to.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet work(ServerPlayer serverPlayer, Unit unit,
WorkLocation workLocation) {
final Specification spec = getGame().getSpecification();
final Colony colony = workLocation.getColony();
colony.getGoodsContainer().saveState();
ChangeSet cs = new ChangeSet();
Tile tile = workLocation.getWorkTile();
if (tile != null && tile.getOwningSettlement() != colony) {
// Claim known free land (because canAdd() succeeded).
serverPlayer.csClaimLand(tile, colony, 0, cs);
}
colony.equipForRole(unit, spec.getDefaultRole(), 0);
// Check for upgrade.
UnitTypeChange uc = unit.getUnitChange(UnitChangeType.ENTER_COLONY);
if (uc != null && uc.appliesTo(unit)) {
unit.changeType(uc.to);//-vis: safe in colony
}
// Change the location.
// We could avoid updating the whole tile if we knew that this
// was definitely a move between locations and no student/teacher
// interaction occurred.
if (!unit.isInColony()) unit.getColony().getTile().cacheUnseen();//+til
unit.setLocation(workLocation);//-vis: safe/colony,-til if not in colony
cs.add(See.perhaps(), colony.getTile());
// Others can see colony change size
getGame().sendToOthers(serverPlayer, cs);
return cs;
}
示例6: invalidTileReason
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Why would a PioneeringMission be invalid with the given unit and tile.
*
* @param aiUnit The {@code AIUnit} to check.
* @param tile The {@code Tile} to check.
* @return A reason why the mission would be invalid, or null if
* none found.
*/
private static String invalidTileReason(AIUnit aiUnit, Tile tile) {
return (tile == null)
? Mission.TARGETINVALID
: (!hasTools(aiUnit))
? "unit-needs-tools"
: (getPlan(aiUnit, tile) == null
&& getBestPlan(aiUnit, tile) == null)
? "tile-has-no-plan"
: (tile.getOwningSettlement() != null)
? invalidTargetReason(tile.getOwningSettlement(),
aiUnit.getUnit().getOwner())
: null;
}
示例7: 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));
}
示例8: work
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Change work location.
*
* @param serverPlayer The {@code ServerPlayer} that owns the unit.
* @param unit The {@code Unit} to change the work location of.
* @param workLocation The {@code WorkLocation} to change to.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet work(ServerPlayer serverPlayer, Unit unit,
WorkLocation workLocation) {
final Specification spec = getGame().getSpecification();
final Colony colony = workLocation.getColony();
colony.getGoodsContainer().saveState();
ChangeSet cs = new ChangeSet();
Tile tile = workLocation.getWorkTile();
if (tile != null && tile.getOwningSettlement() != colony) {
// Claim known free land (because canAdd() succeeded).
serverPlayer.csClaimLand(tile, colony, 0, cs);
}
colony.equipForRole(unit, spec.getDefaultRole(), 0);
// Check for upgrade.
UnitTypeChange uc = unit.getUnitChange(UnitChangeType.ENTER_COLONY);
if (uc != null) unit.changeType(uc.to);//-vis: safe in colony
// Change the location.
// We could avoid updating the whole tile if we knew that this
// was definitely a move between locations and no student/teacher
// interaction occurred.
if (!unit.isInColony()) unit.getColony().getTile().cacheUnseen();//+til
unit.setLocation(workLocation);//-vis: safe/colony,-til if not in colony
cs.add(See.perhaps(), colony.getTile());
// Others can see colony change size
getGame().sendToOthers(serverPlayer, cs);
return cs;
}
示例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: updateTileImprovementPlans
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Creates a list of the {@code Tile}-improvements which will
* increase the production by this {@code Colony}.
*
* @see TileImprovementPlan
* @param lb A {@code LogBuilder} to log to.
*/
public void updateTileImprovementPlans(LogBuilder lb) {
List<TileImprovementPlan> newPlans = new ArrayList<>();
for (WorkLocation wl : transform(colony.getAvailableWorkLocations(),
w -> w instanceof ColonyTile)) {
Tile workTile = wl.getWorkTile();
ColonyTile colonyTile = (ColonyTile)wl;
if (workTile.getOwningSettlement() != colony
|| getPlanFor(workTile, newPlans) != null) continue;
// Require food for the center tile, but otherwise insist
// the tile is being used, and try to improve the
// production that is underway.
GoodsType goodsType;
if (colonyTile.isColonyCenterTile()) {
AbstractGoods food = find(wl.getProduction(),
AbstractGoods::isFoodType);
goodsType = (food == null) ? null : food.getType();
} else {
goodsType = (wl.isEmpty()) ? null : wl.getCurrentWorkType();
}
if (goodsType == null) continue;
TileImprovementPlan plan = getPlanFor(workTile,
tileImprovementPlans);
if (plan == null) {
TileImprovementType type = TileImprovementPlan
.getBestTileImprovementType(workTile, goodsType);
if (type != null) {
plan = new TileImprovementPlan(getAIMain(), workTile,
type, type.getImprovementValue(workTile, goodsType));
}
} else {
if (!plan.update(goodsType)) plan = null;
}
if (plan == null) continue;
// Defend against clearing the last forested tile.
TileType change = plan.getType().getChange(workTile.getType());
final Predicate<WorkLocation> forestPred = cwl ->
cwl instanceof ColonyTile
&& !((ColonyTile)cwl).isColonyCenterTile()
&& cwl.getWorkTile().isForested();
if (change != null
&& !change.isForested()
&& !colonyTile.isColonyCenterTile()
&& count(colony.getAvailableWorkLocations(), forestPred)
<= FOREST_MINIMUM) continue;
newPlans.add(plan); // Otherwise add the plan.
}
tileImprovementPlans.clear();
tileImprovementPlans.addAll(newPlans);
tileImprovementPlans.sort(ValuedAIObject.descendingValueComparator);
if (!tileImprovementPlans.isEmpty()) {
lb.add(", improve:");
for (TileImprovementPlan tip : tileImprovementPlans) {
lb.add(" ", tip.getTarget(), "-", tip.getType().getSuffix());
}
}
}