|
From: <mp...@us...> - 2012-09-01 00:17:50
|
Revision: 10118
http://freecol.svn.sourceforge.net/freecol/?rev=10118&view=rev
Author: mpope
Date: 2012-09-01 00:17:43 +0000 (Sat, 01 Sep 2012)
Log Message:
-----------
Clarify inheritance in Settlement/s.
Modified Paths:
--------------
freecol/trunk/src/net/sf/freecol/common/model/Colony.java
freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java
freecol/trunk/src/net/sf/freecol/common/model/Location.java
freecol/trunk/src/net/sf/freecol/common/model/Settlement.java
Modified: freecol/trunk/src/net/sf/freecol/common/model/Colony.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/Colony.java 2012-08-31 11:25:26 UTC (rev 10117)
+++ freecol/trunk/src/net/sf/freecol/common/model/Colony.java 2012-09-01 00:17:43 UTC (rev 10118)
@@ -312,34 +312,6 @@
/**
- * Gets the name of this <code>Settlement</code> for a particular player.
- *
- * @param player A <code>Player</code> to return the name for.
- * @return The name as a <code>String</code>.
- */
- public String getNameFor(Player player) {
- // Europeans can always work out the colony name.
- return getName();
- }
-
- /**
- * Gets the image key for this colony.
- *
- * @return The image key.
- */
- public String getImageKey() {
- if (isUndead()) return "undead";
-
- int count = getDisplayUnitCount();
- String key = (count <= 3) ? "small"
- : (count <= 7) ? "medium"
- : "large";
- String stockade = getStockadeKey();
- if (stockade != null) key += stockade;
- return "model.settlement." + key + ".image";
- }
-
- /**
* Is a building type able to be automatically built at no cost.
* True when the player has a modifier that collapses the cost to zero.
*
@@ -809,28 +781,6 @@
}
/**
- * Adds a <code>Locatable</code> to this Location.
- *
- * @param locatable The <code>Locatable</code> to add to this Location.
- */
- public boolean add(Locatable locatable) {
- return (locatable instanceof Unit) ? addUnit((Unit) locatable, null)
- : super.add(locatable);
- }
-
- /**
- * Removes a <code>Locatable</code> from this Location.
- *
- * @param locatable The <code>Locatable</code> to remove from this Location.
- * @return True if the remove succeeded.
- */
- public boolean remove(Locatable locatable) {
- return (locatable instanceof Unit) ? removeUnit((Unit) locatable)
- : super.remove(locatable);
- }
-
-
- /**
* Gets a work location within this colony to put a unit in.
*
* @param unit The <code>Unit</code> to place.
@@ -982,29 +932,6 @@
}
/**
- * Returns the amount of money necessary to maintain all of the
- * colony's buildings.
- *
- * @return an <code>int</code> value
- */
- public int getUpkeep() {
- int upkeep = 0;
- for (Building building : buildingMap.values()) {
- upkeep += building.getType().getUpkeep();
- }
- return upkeep;
- }
-
- /**
- * Gets the number of units inside this colony.
- *
- * @return The number of <code>Unit</code>s in this colony.
- */
- public int getUnitCount() {
- return (unitCount >= 0) ? unitCount : getWorkLocationUnitCount();
- }
-
- /**
* Gets the total number of units in the work locations.
*
* @return The number of <code>Unit</code>s in the work locations.
@@ -1039,38 +966,6 @@
}
/**
- * Gets a list of all units in working in this colony.
- *
- * @return A list of <code>Unit</code>s in this colony.
- */
- public List<Unit> getUnitList() {
- ArrayList<Unit> units = new ArrayList<Unit>();
- for (WorkLocation wl : getCurrentWorkLocations()) {
- units.addAll(wl.getUnitList());
- }
- return units;
- }
-
-
- public Iterator<Unit> getUnitIterator() {
- return getUnitList().iterator();
- }
-
- public boolean contains(Locatable locatable) {
- throw new UnsupportedOperationException();
- }
-
- public boolean canAdd(Locatable locatable) {
- if (locatable instanceof Unit && ((Unit) locatable).getOwner() == getOwner()) {
- return true;
- } else if (locatable instanceof Goods) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
* Returns true if this colony has a schoolhouse and the unit type is a
* skilled unit type with a skill level not exceeding the level of the
* schoolhouse. @see Building#canAdd
@@ -1173,51 +1068,7 @@
return student;
}
- /**
- * Gets the <code>Unit</code> that is currently defending this
- * <code>Colony</code>.
- * <p>
- * Note that this function will only return a unit working inside the colony.
- * Typically, colonies are also defended by units outside the colony on the same tile.
- * To consider units outside the colony as well, use (@see Tile#getDefendingUnit) instead.
- * <p>
- * Returns an arbitrary unarmed land unit unless Paul Revere is present
- * as founding father, in which case the unit can be armed as well.
- *
- * @param attacker The unit that would be attacking this colony.
- * @return The <code>Unit</code> that has been chosen to defend this
- * colony, or <code>null</code> if the colony belongs to another
- * player and client is not permitted to view contents.
- * @see Tile#getDefendingUnit(Unit)
- * @throws IllegalStateException if there are units in the colony
- */
- @Override
- public Unit getDefendingUnit(Unit attacker) {
- List<Unit> unitList = getUnitList();
- if (unitCount >= 0 && unitList.isEmpty()) {
- // There are units, but we don't see them
- return null;
- }
-
- Unit defender = null;
- float defencePower = -1.0f;
- for (Unit nextUnit : unitList) {
- float unitPower = getGame().getCombatModel()
- .getDefencePower(attacker, nextUnit);
- if (Unit.betterDefender(defender, defencePower,
- nextUnit, unitPower)) {
- defender = nextUnit;
- defencePower = unitPower;
- }
- }
- if (defender == null) {
- throw new IllegalStateException("Colony " + getName() + " contains no units!");
- } else {
- return defender;
- }
- }
-
/**
* Gets the best defender type available to this colony.
*
@@ -1253,16 +1104,6 @@
return defence;
}
- /**
- * Gets a ratio of defence power to colony size.
- * This is really arbitrary and needs tweaking.
- * Useful as a weighting multiplier for mission comparison.
- *
- * @return A ratio of defensive power to colony size.
- */
- public float getDefenceRatio() {
- return getTotalDefencePower() / (1 + getWorkLocationUnitCount());
- }
/**
* Determines whether this colony is sufficiently unprotected and
@@ -1368,21 +1209,6 @@
}
/**
- * Gets the plunder range for this colony.
- *
- * @param attacker An attacking <code>Unit</code>.
- * @return The plunder range.
- */
- public RandomRange getPlunderRange(Unit attacker) {
- if (canBePlundered()) {
- int upper = (owner.getGold() * (getUnitCount() + 1))
- / (owner.getColoniesPopulation() + 1);
- if (upper > 0) return new RandomRange(100, 1, upper+1, 1);
- }
- return null;
- }
-
- /**
* Returns a <code>List</code> with every unit type this colony may
* build.
*
@@ -1557,15 +1383,6 @@
}
/**
- * Returns the current SoL membership of the colony.
- *
- * @return The current SoL membership of the colony.
- */
- public int getSoL() {
- return sonsOfLiberty;
- }
-
- /**
* Calculates the current SoL membership of the colony based on
* the liberty value and colonists.
*/
@@ -1638,25 +1455,6 @@
}
/**
- * Returns the name of this location.
- *
- * @return The name of this location.
- */
- public StringTemplate getLocationName() {
- return StringTemplate.name(getName());
- }
-
- /**
- * Returns a suitable name for this colony for a particular player.
- *
- * @param player The <code>Player</code> to prepare the name for.
- * @return The name of this colony.
- */
- public StringTemplate getLocationNameFor(Player player) {
- return StringTemplate.name(getNameFor(player));
- }
-
- /**
* Gets the combined production of all food types.
*
* @return an <code>int</code> value
@@ -1670,21 +1468,6 @@
}
/**
- * Gets the total production of the given type of goods.
- *
- * @param goodsType The type of goods to get the production for.
- * @return The production of the given type of goods the current turn by all
- * of the <code>WorkLocation</code>s in the colony.
- */
- public int getTotalProductionOf(GoodsType goodsType) {
- int amount = 0;
- for (WorkLocation workLocation : getCurrentWorkLocations()) {
- amount += workLocation.getTotalProductionOf(goodsType);
- }
- return amount;
- }
-
- /**
* Gets a vacant <code>WorkLocation</code> for the given <code>Unit</code>.
*
* @param unit The <code>Unit</code>
@@ -2347,34 +2130,6 @@
}
}
- /**
- * Propagates a global change in tension down to a settlement.
- * No-op for European colonies.
- *
- * @param player The <code>Player</code> towards whom the alarm is felt.
- * @param addToAlarm The amount to add to the current alarm level.
- * @return True if the settlement alarm level changes as a result
- * of this change.
- */
- public boolean propagateAlarm(Player player, int addToAlarm) {
- return false;
- }
-
- /**
- * Returns the capacity of this colony's warehouse. All goods
- * above this limit, except Food, will be removed by the
- * end-of-turn processing.
- *
- * This will return 0 unless additive modifiers are present. This
- * is intentional.
- *
- * @return The capacity of this <code>Colony</code>'s warehouse.
- */
- public int getGoodsCapacity() {
- return (int) applyModifier(0f, "model.modifier.warehouseStorage",
- null, getGame().getTurn());
- }
-
public Building getWarehouse() {
// TODO: it should search for more than one building?
for (Building building : buildingMap.values()) {
@@ -2386,15 +2141,6 @@
}
/**
- * Returns just this Colony itself.
- *
- * @return this colony.
- */
- public Colony getColony() {
- return this;
- }
-
- /**
* Returns true when colony has a stockade
*
* @return whether the colony has a stockade
@@ -2754,6 +2500,234 @@
return bestExpert;
}
+
+ // Interface Location
+
+ // getId() inherited from FreeColGameObject
+ // Overrides the unit list operations.
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean add(Locatable locatable) {
+ if (locatable instanceof Unit) {
+ return addUnit((Unit)locatable, null);
+ }
+ return super.add(locatable);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean remove(Locatable locatable) {
+ if (locatable instanceof Unit) {
+ return removeUnit((Unit)locatable);
+ }
+ return super.remove(locatable);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean contains(Locatable locatable) {
+ if (locatable instanceof Unit) {
+ throw new UnsupportedOperationException(); // FIXME!
+ }
+ return super.contains(locatable);
+ }
+
+ /**
+ * Gets the unit count.
+ * Must handle the unitCount override for foreign colonies.
+ *
+ * @return The visible unit count.
+ */
+ @Override
+ public int getUnitCount() {
+ return (unitCount >= 0) ? unitCount : getUnitList().size();
+ }
+
+ /**
+ * Gets a list of all units in working in this colony.
+ *
+ * Totally ignores the unit list provided by the underlying UnitLocation.
+ *
+ * @return A list of <code>Unit</code>s in this colony.
+ */
+ @Override
+ public List<Unit> getUnitList() {
+ ArrayList<Unit> units = new ArrayList<Unit>();
+ for (WorkLocation wl : getCurrentWorkLocations()) {
+ units.addAll(wl.getUnitList());
+ }
+ return units;
+ }
+
+ /**
+ * Returns just this Colony itself.
+ *
+ * @return This colony.
+ */
+ @Override
+ public final Colony getColony() {
+ return this;
+ }
+
+ // UnitLocation routines
+ // getUnitCapacity inherited from UnitLocation
+ // getNoAddReason inherited from Settlement
+
+ // GoodsLocation routines
+
+ /**
+ * Returns the capacity of this colony's warehouse. All goods
+ * above this limit, except Food, will be removed by the
+ * end-of-turn processing.
+ *
+ * This will return 0 unless additive modifiers are present. This
+ * is intentional.
+ *
+ * @return The capacity of this <code>Colony</code>'s warehouse.
+ */
+ public int getGoodsCapacity() {
+ return (int) applyModifier(0f, "model.modifier.warehouseStorage",
+ null, getGame().getTurn());
+ }
+
+
+ // Settlement routines
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNameFor(Player player) {
+ // Europeans can always work out the colony name.
+ return getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getImageKey() {
+ if (isUndead()) return "undead";
+
+ int count = getDisplayUnitCount();
+ String key = (count <= 3) ? "small"
+ : (count <= 7) ? "medium"
+ : "large";
+ String stockade = getStockadeKey();
+ if (stockade != null) key += stockade;
+ return "model.settlement." + key + ".image";
+ }
+
+ /**
+ * Gets the <code>Unit</code> that is currently defending this
+ * <code>Colony</code>.
+ *
+ * Note that this function will only return a unit working inside
+ * the colony. Typically, colonies are also defended by units
+ * outside the colony on the same tile. To consider units outside
+ * the colony as well, use
+ * @see Tile#getDefendingUnit
+ * instead.
+ *
+ * Returns an arbitrary unarmed land unit unless Paul Revere
+ * is present as founding father, in which case the unit can be
+ * armed as well.
+ *
+ * @param attacker The unit that would be attacking this colony.
+ * @return The <code>Unit</code> that has been chosen to defend this
+ * colony, or <code>null</code> if the colony belongs to another
+ * player and client is not permitted to view contents.
+ * @see Tile#getDefendingUnit(Unit)
+ * @throws IllegalStateException if there are units in the colony
+ */
+ @Override
+ public Unit getDefendingUnit(Unit attacker) {
+ List<Unit> unitList = getUnitList();
+
+ if (unitCount >= 0 && unitList.isEmpty()) {
+ // There are units, but we don't see them
+ return null;
+ }
+
+ Unit defender = null;
+ float defencePower = -1.0f;
+ for (Unit nextUnit : unitList) {
+ float unitPower = getGame().getCombatModel()
+ .getDefencePower(attacker, nextUnit);
+ if (Unit.betterDefender(defender, defencePower,
+ nextUnit, unitPower)) {
+ defender = nextUnit;
+ defencePower = unitPower;
+ }
+ }
+ if (defender == null) {
+ throw new IllegalStateException("Colony " + getName()
+ + " contains no units!");
+ }
+ return defender;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getDefenceRatio() {
+ return getTotalDefencePower() / (1 + getWorkLocationUnitCount());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RandomRange getPlunderRange(Unit attacker) {
+ if (canBePlundered()) {
+ int upper = (owner.getGold() * (getUnitCount() + 1))
+ / (owner.getColoniesPopulation() + 1);
+ if (upper > 0) return new RandomRange(100, 1, upper+1, 1);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getSoL() {
+ return sonsOfLiberty;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getUpkeep() {
+ int upkeep = 0;
+ for (Building building : buildingMap.values()) {
+ upkeep += building.getType().getUpkeep();
+ }
+ return upkeep;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean propagateAlarm(Player player, int addToAlarm) {
+ return false; // No-op for European colonies.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTotalProductionOf(GoodsType goodsType) {
+ int amount = 0;
+ for (WorkLocation workLocation : getCurrentWorkLocations()) {
+ amount += workLocation.getTotalProductionOf(goodsType);
+ }
+ return amount;
+ }
+
+
// Serialization
/**
Modified: freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java 2012-08-31 11:25:26 UTC (rev 10117)
+++ freecol/trunk/src/net/sf/freecol/common/model/IndianSettlement.java 2012-09-01 00:17:43 UTC (rev 10118)
@@ -215,48 +215,23 @@
super(game, id);
}
- /**
- * Gets the name of this <code>Settlement</code> for a particular player.
- *
- * @param player A <code>Player</code> to return the name for.
- * @return The name as a <code>String</code>.
- */
- public String getNameFor(Player player) {
- return (hasContactedSettlement(player)) ? getName()
- : "indianSettlement.nameUnknown";
- }
/**
- * Gets the image key for this native settlement.
+ * Dispose of this native settlement.
*
- * @return The image key.
+ * @return A list of disposed objects.
*/
- public String getImageKey() {
- return getOwner().getNationID()
- + (isCapital() ? ".capital" : ".settlement")
- + ((getMissionary() == null) ? "" : ".mission")
- + ".image";
+ @Override
+ public List<FreeColGameObject> disposeList() {
+ // Orphan the units whose home settlement this is.
+ while (ownedUnits.size() > 0) {
+ ownedUnits.remove(0).setIndianSettlement(null);
+ }
+ return super.disposeList();
}
- /**
- * Returns a suitable (non-unique) name.
- * @return The name of this settlement.
- */
- public StringTemplate getLocationName() {
- return StringTemplate.name(getName());
- }
/**
- * Returns a suitable (non-unique) name for a particular player.
- *
- * @param player The <code>Player</code> to prepare the name for.
- * @return The name of this settlement.
- */
- public StringTemplate getLocationNameFor(Player player) {
- return StringTemplate.name(getNameFor(player));
- }
-
- /**
* Get the year of the last tribute.
*
* @return The year of the last tribute.
@@ -374,23 +349,6 @@
}
/**
- * Propagates a global change in tension down to a settlement.
- * Only apply the change if the settlement is aware of the player
- * causing alarm.
- *
- * @param player The <code>Player</code> towards whom the alarm is felt.
- * @param addToAlarm The amount to add to the current alarm level.
- * @return True if the alarm level changes as a result of this change.
- */
- public boolean propagateAlarm(Player player, int addToAlarm) {
- if (hasContactedSettlement(player)) {
- return changeAlarm(player, addToAlarm);
- }
- return false;
- }
-
-
- /**
* Returns true if a European player has spoken with the chief of
* this settlement.
*
@@ -612,58 +570,8 @@
}
- /**
- * Gets the <code>Unit</code> that is currently defending this
- * <code>IndianSettlement</code>.
- *
- * @param attacker The unit that would be attacking this
- * <code>IndianSettlement</code>.
- * @return The <code>Unit</code> that has been chosen to defend
- * this <code>IndianSettlement</code>.
- */
- @Override
- public Unit getDefendingUnit(Unit attacker) {
- Unit defender = null;
- float defencePower = -1.0f;
- for (Unit nextUnit : getUnitList()) {
- float unitPower = attacker.getGame().getCombatModel()
- .getDefencePower(attacker, nextUnit);
- if (Unit.betterDefender(defender, defencePower,
- nextUnit, unitPower)) {
- defender = nextUnit;
- defencePower = unitPower;
- }
- }
- return defender;
- }
/**
- * Gets the ratio between defence power and settlement size.
- *
- * @return A measure of the defence at this settlement.
- */
- public float getDefenceRatio() {
- return getUnitCount() * 2.0f / (getType().getMinimumSize()
- + getType().getMaximumSize());
- }
-
- /**
- * Gets the range of gold plunderable when this settlement is captured.
- */
- public RandomRange getPlunderRange(Unit attacker) {
- return getType().getPlunderRange(attacker);
- }
-
- /**
- * Gets the storage capacity of this settlement.
- *
- * @return The storage capacity of this settlement.
- */
- public int getGoodsCapacity() {
- return getType().getWarehouseCapacity();
- }
-
- /**
* Gets the amount of gold this <code>IndianSettlment</code>
* is willing to pay for the given <code>Goods</code>.
*
@@ -1033,44 +941,6 @@
}
/**
- * Gets the total production of a specified goods type for this settlement.
- *
- * @param type The <code>GoodsType</code> to produce.
- * @return The production potention for the goods type.
- */
- public int getTotalProductionOf(GoodsType type) {
- if (type.isRefined()) {
- if (type != goodsToMake()) return 0;
- // Pretend 1/3 of the units present make the item with
- // basic production of 3.
- return getUnitCount();
- }
-
- int potential = 0;
- int tiles = 1; // Always include center tile
-
- for (Tile workTile : getOwnedTiles()) {
- if (workTile != getTile() && !workTile.isOccupied()) {
- // TODO: make unitType brave
- potential += workTile.potential(type, null);
- tiles++;
- }
- }
-
- // When a native settlement has more tiles than units, pretend
- // that they produce from their entire area at reduced
- // efficiency.
- if (tiles > getUnitCount()) {
- potential *= (float) getUnitCount() / tiles;
- }
-
- // But always add full potential of the center tile.
- potential += getTile().potential(type, null);
-
- return potential;
- }
-
- /**
* Gets a random goods gift from this settlement.
*
* @param random A pseudo random number source.
@@ -1094,24 +964,6 @@
: Utils.getRandomMember(logger, "Gift type", goodsList, random);
}
- /**
- * Native settlements do not generate SoL.
- *
- * @return 0.
- */
- public int getSoL() {
- return 0;
- }
-
- /**
- * Native settlements do not require upkeep.
- *
- * @return 0
- */
- public int getUpkeep() {
- return 0;
- }
-
public boolean checkForNewMissionaryConvert() {
/* Increase convert progress and generate convert if needed. */
@@ -1135,22 +987,154 @@
return false;
}
+
+ // Interface location
+
+ // getId() inherited from FreeColGameObject
+ // canAdd, getUnitCount, getUnitList inherited from UnitLocation
+ // add, remove, contains inherited from GoodsLocation
+
/**
- * Dispose of this native settlement.
- *
- * @return A list of disposed objects.
+ * {@inheritDoc}
*/
@Override
- public List<FreeColGameObject> disposeList() {
- // Orphan the units whose home settlement this is.
- while (ownedUnits.size() > 0) {
- ownedUnits.remove(0).setIndianSettlement(null);
+ public final Colony getColony() {
+ return null; // A native settlement can never be a colony.
+ }
+
+ // UnitLocation routines
+ // getNoAddReason in Settlement is adequate
+
+ // GoodsLocation routines
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getGoodsCapacity() {
+ return getType().getWarehouseCapacity();
+ }
+
+
+ // Settlement routines
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNameFor(Player player) {
+ return (hasContactedSettlement(player)) ? getName()
+ : "indianSettlement.nameUnknown";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getImageKey() {
+ return getOwner().getNationID()
+ + (isCapital() ? ".capital" : ".settlement")
+ + ((getMissionary() == null) ? "" : ".mission")
+ + ".image";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Unit getDefendingUnit(Unit attacker) {
+ Unit defender = null;
+ float defencePower = -1.0f;
+ for (Unit nextUnit : getUnitList()) {
+ float unitPower = attacker.getGame().getCombatModel()
+ .getDefencePower(attacker, nextUnit);
+ if (Unit.betterDefender(defender, defencePower,
+ nextUnit, unitPower)) {
+ defender = nextUnit;
+ defencePower = unitPower;
+ }
}
- return super.disposeList();
+ return defender;
}
+ /**
+ * {@inheritDoc}
+ */
+ public float getDefenceRatio() {
+ return getUnitCount() * 2.0f / (getType().getMinimumSize()
+ + getType().getMaximumSize());
+ }
/**
+ * {@inheritDoc}
+ */
+ public RandomRange getPlunderRange(Unit attacker) {
+ return getType().getPlunderRange(attacker);
+ }
+
+ /**
+ * Native settlements do not generate SoL.
+ *
+ * @return 0.
+ */
+ public int getSoL() {
+ return 0;
+ }
+
+ /**
+ * Native settlements do not require upkeep.
+ *
+ * @return 0
+ */
+ public int getUpkeep() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean propagateAlarm(Player player, int addToAlarm) {
+ if (hasContactedSettlement(player)) {
+ return changeAlarm(player, addToAlarm);
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTotalProductionOf(GoodsType type) {
+ if (type.isRefined()) {
+ if (type != goodsToMake()) return 0;
+ // Pretend 1/3 of the units present make the item with
+ // basic production of 3.
+ return getUnitCount();
+ }
+
+ int potential = 0;
+ int tiles = 1; // Always include center tile
+
+ for (Tile workTile : getOwnedTiles()) {
+ if (workTile != getTile() && !workTile.isOccupied()) {
+ // TODO: make unitType brave
+ potential += workTile.potential(type, null);
+ tiles++;
+ }
+ }
+
+ // When a native settlement has more tiles than units, pretend
+ // that they produce from their entire area at reduced
+ // efficiency.
+ if (tiles > getUnitCount()) {
+ potential *= (float) getUnitCount() / tiles;
+ }
+
+ // But always add full potential of the center tile.
+ potential += getTile().potential(type, null);
+
+ return potential;
+ }
+
+
+ // Serialization
+
+ /**
* This method writes an XML-representation of this object to
* the given stream.
*
Modified: freecol/trunk/src/net/sf/freecol/common/model/Location.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/Location.java 2012-08-31 11:25:26 UTC (rev 10117)
+++ freecol/trunk/src/net/sf/freecol/common/model/Location.java 2012-09-01 00:17:43 UTC (rev 10118)
@@ -71,7 +71,8 @@
/**
* Removes a <code>Locatable</code> from this Location.
*
- * @param locatable The <code>Locatable</code> to remove from this Location.
+ * @param locatable The <code>Locatable</code> to remove from this
+ * Location.
* @return True if the locatable was removed.
*/
public boolean remove(Locatable locatable);
Modified: freecol/trunk/src/net/sf/freecol/common/model/Settlement.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/Settlement.java 2012-08-31 11:25:26 UTC (rev 10117)
+++ freecol/trunk/src/net/sf/freecol/common/model/Settlement.java 2012-09-01 00:17:43 UTC (rev 10118)
@@ -150,14 +150,6 @@
}
/**
- * Gets the name of this <code>Settlement</code> for a particular player.
- *
- * @param player A <code>Player</code> to return the name for.
- * @return The name as a <code>String</code>.
- */
- abstract public String getNameFor(Player player);
-
- /**
* Sets the name of this <code>Settlement</code>.
*
* @param newName The new name.
@@ -167,11 +159,6 @@
}
/**
- * Gets an image key for this settlement.
- */
- abstract public String getImageKey();
-
- /**
* Returns <code>true</code> if this is the Nation's capital.
*
* @return <code>true</code> if this is the Nation's capital.
@@ -179,8 +166,8 @@
public boolean isCapital() {
return getType().isCapital();
}
-
- /**
+
+ /**
* Sets the capital value.
*
* @param isCapital a <code>boolean</code> value
@@ -190,8 +177,7 @@
setType(owner.getNationType().getSettlementType(isCapital));
}
}
-
-
+
/**
* Get this settlement's feature container.
*
@@ -202,7 +188,6 @@
return featureContainer;
}
-
/**
* Gets this colony's line of sight.
* @return The line of sight offered by this
@@ -214,35 +199,7 @@
"model.modifier.lineOfSightBonus");
}
-
/**
- * Gets the <code>Unit</code> that is currently defending this
- * <code>Settlement</code>.
- *
- * @param attacker The unit be attacking this <code>Settlement</code>.
- * @return The <code>Unit</code> that has been chosen to defend
- * this <code>Settlement</code>.
- */
- abstract public Unit getDefendingUnit(Unit attacker);
-
- /**
- * Gets a measure of the ratio between defence at this settlement,
- * and the general settlement size.
- *
- * @return A ratio of defence power to settlement size.
- */
- abstract public float getDefenceRatio();
-
- /**
- * Gets the range of gold plunderable when this settlement is captured.
- *
- * @param attacker The <code>Unit</code> that takes the settlement.
- * @return A <code>RandomRange</code> encapsulating the range of plunder
- * available.
- */
- abstract public RandomRange getPlunderRange(Unit attacker);
-
- /**
* Gets an amount of plunder when this settlement is taken.
*
* @param attacker The <code>Unit</code> that takes the settlement.
@@ -256,26 +213,6 @@
}
/**
- * Gets the <code>Tile</code> where this <code>Settlement</code>
- * is located.
- *
- * @return The <code>Tile</code> where this
- * <code>Settlement</code> is located.
- */
- public Tile getTile() {
- return tile;
- }
-
- /**
- * Returns this Settlement.
- *
- * @return this Settlement
- */
- public Settlement getSettlement() {
- return this;
- }
-
- /**
* Put a prepared settlement onto the map.
*
* @param maximal If true, also claim all the tiles possible.
@@ -448,39 +385,6 @@
}
/**
- * Gets the current Sons of Liberty in this settlement.
- */
- public abstract int getSoL();
-
- /**
- * Returns the amount of money necessary to maintain all of the
- * settlement's buildings.
- *
- * @return an <code>int</code> value
- */
- public abstract int getUpkeep();
-
- /**
- * Propagates a global change in tension down to a settlement.
- * Only apply the change if the settlement is aware of the player
- * causing alarm.
- *
- * @param player The <code>Player</code> towards whom the alarm is felt.
- * @param addToAlarm The amount to add to the current alarm level.
- * @return True if the settlement alarm level changes as a result
- * of this change.
- */
- public abstract boolean propagateAlarm(Player player, int addToAlarm);
-
- /**
- * Gets the total production of the given type of goods in this settlement.
- *
- * @param goodsType The type of goods to get the production for.
- * @return The total production of the given type of goods.
- */
- public abstract int getTotalProductionOf(GoodsType goodsType);
-
- /**
* Returns the number of goods of a given type used by the settlement
* each turn.
*
@@ -512,7 +416,6 @@
return result;
}
-
/**
* Gives the food needed to keep all units alive in this Settlement.
*
@@ -577,6 +480,159 @@
}
/**
+ * Gets the storage capacity of this settlement.
+ *
+ * @return The storage capacity of this settlement.
+ * @see #getGoodsCapacity
+ */
+ public int getWarehouseCapacity() {
+ return getGoodsCapacity();
+ }
+
+
+ // Interface Location
+
+ // getId() inherited from FreeColGameObject
+ // canAdd, getUnitCount, getUnitList, getColony inherited from UnitLocation
+ // add, remove, contains inherited from GoodsLocation
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final Tile getTile() {
+ return tile;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final Settlement getSettlement() {
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public StringTemplate getLocationName() {
+ return StringTemplate.name(getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public StringTemplate getLocationNameFor(Player player) {
+ return StringTemplate.name(getNameFor(player));
+ }
+
+
+ // UnitLocation routines
+ // getUnitCapacity inherited default from UnitLocation
+
+ /**
+ * {@inheritDoc}
+ */
+ public NoAddReason getNoAddReason(Locatable locatable) {
+ if (locatable instanceof Unit) {
+ // Tighter ownership test now possible.
+ if (((Unit)locatable).getOwner() != getOwner()) {
+ return NoAddReason.OWNED_BY_ENEMY;
+ }
+ } else if (locatable instanceof Goods) {
+ // Goods can always be added to settlements. Any
+ // excess Goods will be removed during end-of-turn
+ // processing.
+ return NoAddReason.NONE;
+ }
+ return super.getNoAddReason(locatable);
+ }
+
+ // GoodsLocation routines
+ // No need to implement getGoodsCapacity here, yet.
+
+
+ // Settlement routines to be implemented by subclasses.
+
+ /**
+ * Gets the name of this <code>Settlement</code> for a particular player.
+ *
+ * @param player A <code>Player</code> to return the name for.
+ * @return The name as a <code>String</code>.
+ */
+ abstract public String getNameFor(Player player);
+
+ /**
+ * Gets an image key for this settlement.
+ */
+ abstract public String getImageKey();
+
+ /**
+ * Gets the <code>Unit</code> that is currently defending this
+ * <code>Settlement</code>.
+ *
+ * @param attacker The unit be attacking this <code>Settlement</code>.
+ * @return The <code>Unit</code> that has been chosen to defend
+ * this <code>Settlement</code>.
+ */
+ abstract public Unit getDefendingUnit(Unit attacker);
+
+ /**
+ * Gets a measure of the ratio between defence at this settlement,
+ * and the general settlement size.
+ *
+ * @return A ratio of defence power to settlement size.
+ */
+ abstract public float getDefenceRatio();
+
+ /**
+ * Gets the range of gold plunderable when this settlement is captured.
+ *
+ * @param attacker The <code>Unit</code> that takes the settlement.
+ * @return A <code>RandomRange</code> encapsulating the range of plunder
+ * available.
+ */
+ abstract public RandomRange getPlunderRange(Unit attacker);
+
+ /**
+ * Gets the current Sons of Liberty in this settlement.
+ */
+ abstract public int getSoL();
+
+ /**
+ * Returns the amount of money necessary to maintain all of the
+ * settlement's buildings.
+ *
+ * @return an <code>int</code> value
+ */
+ abstract public int getUpkeep();
+
+ /**
+ * Propagates a global change in tension down to a settlement.
+ * Only apply the change if the settlement is aware of the player
+ * causing alarm.
+ *
+ * @param player The <code>Player</code> towards whom the alarm is felt.
+ * @param addToAlarm The amount to add to the current alarm level.
+ * @return True if the settlement alarm level changes as a result
+ * of this change.
+ */
+ abstract public boolean propagateAlarm(Player player, int addToAlarm);
+
+ /**
+ * Gets the total production of the given type of goods in this settlement.
+ *
+ * @param goodsType The type of goods to get the production for.
+ * @return The total production of the given type of goods.
+ */
+ abstract public int getTotalProductionOf(GoodsType goodsType);
+
+
+ // Serialization
+
+ /**
* Write the attributes of this object to a stream.
*
* @param out The target stream.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|