Add import level to ExportData and WarehouseDialog.

This commit is contained in:
Michael Pope 2015-06-12 10:00:12 +09:30 committed by Mike Pope
parent d8047bf768
commit 91f54ec287
6 changed files with 98 additions and 19 deletions

View File

@ -3577,7 +3577,8 @@ victory.yes=Quit
# WarehouseDialog
warehouseDialog.export.shortDescription=Whether to export this kind of goods.
warehouseDialog.export=Export
warehouseDialog.exportLevel.shortDescription=Do not export anything below this level.
warehouseDialog.importLevel.shortDescription=Import goods below this level.
warehouseDialog.exportLevel.shortDescription=Export goods above this level.
warehouseDialog.highLevel.shortDescription=Warn me when stock exceeds this percentage of capacity.
warehouseDialog.lowLevel.shortDescription=Warn me when stock drops below this percentage of capacity.
warehouseDialog.name=Warehouse

View File

@ -1854,12 +1854,15 @@ exactly what each unit with a trade route is doing, enable the
\texttt{Goods Movement} message type, but beware that there can be
many messages of this type.
There is also an ``Enhanced Trade Routes'' game option, which if
enabled attempts to maximimze the amount of goods being transported,
taking account of the consumption at the destination and expected time
to arrive there (although this is imperfect as it can be defeated by
unplanned interuptions to the path of the transporting unit). This
feature is new, and should be considered experimental.
There is also an `Enhanced Trade Routes' game option, which if enabled
attempts to maximimze the amount of goods being transported, taking
account of the consumption at the destination and expected time to
arrive there (although this is imperfect as it can be defeated by
unplanned interuptions to the path of the transporting unit).
Furthermore, this option enables an additional `Import Level' setting
on the warehouse dialog, that allows you to specify the maximum amount
of goods that will be imported to the colony. This feature is new,
and should be considered experimental.
\hypertarget{Resources}{\section{Special Resources}}

View File

@ -31,6 +31,7 @@
<xs:attribute name="exported" type="xs:boolean" use="required" />
<xs:attribute name="highLevel" type="xs:int" use="required" />
<xs:attribute name="lowLevel" type="xs:int" use="required" />
<xs:attribute name="importLevel" type="xs:int" use="required" />
<xs:attribute name="exportLevel" type="xs:int" use="required" />
</xs:complexType>
</xs:element>

View File

@ -38,6 +38,7 @@ import net.sf.freecol.common.i18n.Messages;
import net.sf.freecol.common.model.Ability;
import net.sf.freecol.common.model.Colony;
import net.sf.freecol.common.model.ExportData;
import net.sf.freecol.common.model.GameOptions;
import net.sf.freecol.common.model.Goods;
import net.sf.freecol.common.model.GoodsType;
@ -120,6 +121,8 @@ public final class WarehouseDialog extends FreeColConfirmDialog {
private final JSpinner highLevel;
private final JSpinner importLevel;
private final JSpinner exportLevel;
@ -127,6 +130,8 @@ public final class WarehouseDialog extends FreeColConfirmDialog {
GoodsType goodsType) {
super("WarehouseGoodsPanelUI");
final boolean enhancedTradeRoutes = colony.getSpecification()
.getBoolean(GameOptions.ENHANCED_TRADE_ROUTES);
this.colony = colony;
this.goodsType = goodsType;
final int capacity = colony.getWarehouseCapacity();
@ -145,7 +150,7 @@ public final class WarehouseDialog extends FreeColConfirmDialog {
GoodsLabel goodsLabel = new GoodsLabel(
freeColClient.getGUI(), goods);
goodsLabel.setHorizontalAlignment(JLabel.LEADING);
add(goodsLabel, "span 1 2");
add(goodsLabel, "span 1 3");
// low level settings
String str;
@ -164,6 +169,19 @@ public final class WarehouseDialog extends FreeColConfirmDialog {
"warehouseDialog.highLevel.shortDescription");
add(highLevel);
if (enhancedTradeRoutes) { // import level settings
int importInit = exportData.getEffectiveImportLevel(capacity);
SpinnerNumberModel importLevelModel
= new SpinnerNumberModel(importInit, 0,
(goodsType.limitIgnored()) ? maxCapacity : capacity, 1);
importLevel = new JSpinner(importLevelModel);
Utility.localizeToolTip(importLevel,
"warehouseDialog.importLevel.shortDescription");
add(importLevel);
} else {
importLevel = null;
}
// export checkbox
export = new JCheckBox(Messages.message("warehouseDialog.export"),
exportData.getExported());
@ -191,17 +209,22 @@ public final class WarehouseDialog extends FreeColConfirmDialog {
.getNumber().intValue();
int highLevelValue = ((SpinnerNumberModel)highLevel.getModel())
.getNumber().intValue();
int importLevelValue = (importLevel == null) ? -1
: ((SpinnerNumberModel)importLevel.getModel())
.getNumber().intValue();
int exportLevelValue = ((SpinnerNumberModel)exportLevel.getModel())
.getNumber().intValue();
ExportData exportData = colony.getExportData(goodsType);
int importValue = exportData.getEffectiveImportLevel(colony.getWarehouseCapacity());
boolean changed = (export.isSelected() != exportData.getExported())
|| (lowLevelValue != exportData.getLowLevel())
|| (highLevelValue != exportData.getHighLevel())
|| (importLevel != null && importLevelValue != importValue)
|| (exportLevelValue != exportData.getExportLevel());
exportData.setExported(export.isSelected());
exportData.setLowLevel(lowLevelValue);
exportData.setHighLevel(highLevelValue);
exportData.setImportLevel(importLevelValue);
exportData.setExportLevel(exportLevelValue);
if (changed) {
freeColClient.getInGameController()

View File

@ -230,7 +230,7 @@ public class Colony extends Settlement implements Nameable, TradeLocation {
public ExportData getExportData(final GoodsType goodsType) {
ExportData result = exportData.get(goodsType.getId());
if (result == null) {
result = new ExportData(goodsType);
result = new ExportData(goodsType, getWarehouseCapacity());
setExportData(result);
}
return result;
@ -2746,7 +2746,8 @@ public class Colony extends Settlement implements Nameable, TradeLocation {
final int present = Math.max(0, getGoodsCount(goodsType)
+ turns * getNetProductionOf(goodsType));
int capacity = getWarehouseCapacity();
final ExportData ed = getExportData(goodsType);
int capacity = ed.getEffectiveImportLevel(getWarehouseCapacity());
return Math.max(0, capacity - present);
}
@ -3004,7 +3005,7 @@ public class Colony extends Settlement implements Nameable, TradeLocation {
} else if (ExportData.getXMLElementTagName().equals(tag)) {
ExportData data = new ExportData(xr);
exportData.put(data.getId(), data);
setExportData(data);
} else {
super.readChild(xr);

View File

@ -43,7 +43,14 @@ public class ExportData extends FreeColObject {
/** The low water mark for the goods type. */
private int lowLevel = LOW_LEVEL_DEFAULT;
/** The amount of goods to retain, goods beyond this amount are exported. */
/**
* The amount of goods to import to, do not import when this is present.
*/
private int importLevel = -1;
/**
* The amount of goods to retain, goods beyond this amount are exported.
*/
private int exportLevel = EXPORT_LEVEL_DEFAULT;
/** Whether to export or not. */
@ -54,9 +61,11 @@ public class ExportData extends FreeColObject {
* Creates a new <code>ExportData</code> instance with default settings.
*
* @param goodsType The <code>GoodsType</code> this data refers to.
* @param importLevel The import level to use.
*/
public ExportData(GoodsType goodsType) {
public ExportData(GoodsType goodsType, int importLevel) {
setId(goodsType.getId());
setImportLevel(importLevel);
}
/**
@ -85,7 +94,7 @@ public class ExportData extends FreeColObject {
* @return The high water mark.
*/
public final int getHighLevel() {
return highLevel;
return this.highLevel;
}
/**
@ -105,7 +114,7 @@ public class ExportData extends FreeColObject {
* @return The low water mark.
*/
public final int getLowLevel() {
return lowLevel;
return this.lowLevel;
}
/**
@ -119,13 +128,44 @@ public class ExportData extends FreeColObject {
return this;
}
/**
* Get the import level.
*
* @return The import level.
*/
public final int getImportLevel() {
return this.importLevel;
}
/**
* Get the effective import level given the warehouse capacity to default
* to when the actual import level is invalid.
*
* @param capacity The warehouse capacity.
* @return The effective import level.
*/
public final int getEffectiveImportLevel(int capacity) {
return (this.importLevel >= 0) ? this.importLevel : capacity;
}
/**
* Set the import level.
*
* @param newImportLevel The new import level value.
* @return This export data.
*/
public final ExportData setImportLevel(final int newImportLevel) {
this.importLevel = newImportLevel;
return this;
}
/**
* Get the export level.
*
* @return The export level.
*/
public final int getExportLevel() {
return exportLevel;
return this.exportLevel;
}
/**
@ -140,14 +180,19 @@ public class ExportData extends FreeColObject {
}
/**
* Is the goods type of this export data to be exported?
* Can the goods type of this export data to be exported?
*
* @return True if this goods type is to be exported.
*/
public final boolean getExported() {
return exported;
return this.exported;
}
/**
* Set export status of the goods type of this export data.
*
* @param newExport The new export status.
*/
public final void setExported(final boolean newExport) {
this.exported = newExport;
}
@ -157,6 +202,7 @@ public class ExportData extends FreeColObject {
private static final String EXPORTED_TAG = "exported";
private static final String EXPORT_LEVEL_TAG = "exportLevel";
private static final String IMPORT_LEVEL_TAG = "importLevel";
private static final String HIGH_LEVEL_TAG = "highLevel";
private static final String LOW_LEVEL_TAG = "lowLevel";
@ -174,6 +220,8 @@ public class ExportData extends FreeColObject {
xw.writeAttribute(LOW_LEVEL_TAG, lowLevel);
xw.writeAttribute(IMPORT_LEVEL_TAG, importLevel);
xw.writeAttribute(EXPORT_LEVEL_TAG, exportLevel);
}
@ -190,6 +238,8 @@ public class ExportData extends FreeColObject {
lowLevel = xr.getAttribute(LOW_LEVEL_TAG, LOW_LEVEL_DEFAULT);
importLevel = xr.getAttribute(IMPORT_LEVEL_TAG, -1);
exportLevel = xr.getAttribute(EXPORT_LEVEL_TAG, EXPORT_LEVEL_DEFAULT);
}