mirror of https://github.com/FreeCol/freecol.git
Massive goods update. Colonies generate goods and put it into a brand-new warehouse. Europe now has a market with which goods can be bought and sold. MapGenerator updated to give a variety of tile types. "goods" directory created in data.images for holding new goods images from the Resources model. Other misc tweaks.
This commit is contained in:
parent
06b8073d41
commit
e7f03c566b
|
@ -257,6 +257,11 @@ public final class InGameController {
|
|||
}
|
||||
|
||||
Client client = freeColClient.getClient();
|
||||
|
||||
if (unit.isCarrier()) {
|
||||
logger.warning("Trying to load a carrier onto another carrier.");
|
||||
return;
|
||||
}
|
||||
|
||||
unit.boardShip(carrier);
|
||||
|
||||
|
@ -285,6 +290,91 @@ public final class InGameController {
|
|||
client.send(leaveShipElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a cargo onto a carrier.
|
||||
*
|
||||
* @param goods The goods which are going aboard the carrier.
|
||||
* @param carrier The carrier.
|
||||
*/
|
||||
public void loadCargo(Goods goods, Unit carrier) {
|
||||
if (carrier == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
Client client = freeColClient.getClient();
|
||||
|
||||
goods.Load(carrier);
|
||||
|
||||
Element loadCargoElement = Message.createNewRootElement("loadCargo");
|
||||
loadCargoElement.setAttribute("goods", goods.getID());
|
||||
loadCargoElement.setAttribute("carrier", carrier.getID());
|
||||
|
||||
client.send(loadCargoElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unload cargo. This method should only be invoked if the unit carrying the
|
||||
* cargo is in a harbour.
|
||||
*
|
||||
* @param unit The goods which are going to leave the ship where it is located.
|
||||
*/
|
||||
public void unloadCargo(Goods goods) {
|
||||
Client client = freeColClient.getClient();
|
||||
|
||||
goods.Unload();
|
||||
|
||||
Element leaveShipElement = Message.createNewRootElement("unloadCargo");
|
||||
leaveShipElement.setAttribute("goods", goods.getID());
|
||||
|
||||
logger.warning("Sending unloadCargoElement");
|
||||
client.send(leaveShipElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Buys goods in Europe.
|
||||
*
|
||||
* @param unit The unit who is going to board the carrier.
|
||||
* @param carrier The carrier.
|
||||
* @param player The player doing the buying.
|
||||
*/
|
||||
public void buyGoods(int type, Unit carrier, Player player) {
|
||||
if (carrier == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
Client client = freeColClient.getClient();
|
||||
|
||||
if (carrier.getSpaceLeft() <= 0) return;
|
||||
|
||||
(player.getGame().getMarket().buy(type, 100, player)).setLocation(carrier);
|
||||
|
||||
Element buyGoodsElement = Message.createNewRootElement("buyGoods");
|
||||
buyGoodsElement.setAttribute("type", Integer.toString(type));
|
||||
buyGoodsElement.setAttribute("carrier", carrier.getID());
|
||||
buyGoodsElement.setAttribute("player", player.getID());
|
||||
|
||||
client.send(buyGoodsElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sells goods in Europe.
|
||||
*
|
||||
* @param goods The goods to be sold.
|
||||
* @param player The player selling the goods.
|
||||
*/
|
||||
public void sellGoods(Goods goods, Player player) {
|
||||
Client client = freeColClient.getClient();
|
||||
|
||||
player.getGame().getMarket().sell(goods, player);
|
||||
|
||||
Element sellGoodsElement = Message.createNewRootElement("sellGoods");
|
||||
sellGoodsElement.setAttribute("goods", goods.getID());
|
||||
sellGoodsElement.setAttribute("player", player.getID());
|
||||
|
||||
client.send(sellGoodsElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a <code>Unit</code> to a <code>WorkLocation</code>.
|
||||
|
@ -320,7 +410,24 @@ public final class InGameController {
|
|||
client.send(putOutsideColonyElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the worktype of this <code>Unit</code>.
|
||||
* @param unit The <code>Unit</code>
|
||||
* @param workType The new work type.
|
||||
*/
|
||||
public void changeWorkType(Unit unit, int workType) {
|
||||
Client client = freeColClient.getClient();
|
||||
|
||||
unit.setWorkType(workType);
|
||||
|
||||
Element changeWorkTypeElement = Message.createNewRootElement("changeWorkType");
|
||||
changeWorkTypeElement.setAttribute("unit", unit.getID());
|
||||
changeWorkTypeElement.setAttribute("worktype", Integer.toString(workType));
|
||||
|
||||
client.send(changeWorkTypeElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Moves the specified unit in the "high seas" in a specified direction.
|
||||
* This may result in an ordinary move or a move to europe.
|
||||
|
|
|
@ -685,7 +685,12 @@ public final class Canvas extends JLayeredPane {
|
|||
return gui;
|
||||
}
|
||||
|
||||
|
||||
/** Returns the freeColClient.
|
||||
* @returns The <code>freeColClient</code> associated with this <code>Canvas</code>.
|
||||
*/
|
||||
public FreeColClient getClient() {
|
||||
return freeColClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure that old chat messages are removed in time.
|
||||
|
@ -772,4 +777,5 @@ public final class Canvas extends JLayeredPane {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -162,6 +162,25 @@ public final class ImageLibrary extends ImageProvider {
|
|||
INDIAN_SETTLEMENT_INCA = 3,
|
||||
|
||||
INDIAN_COUNT = 4;
|
||||
|
||||
public static final int GOODS_FOOD = 0,
|
||||
GOODS_SUGAR = 1,
|
||||
GOODS_TOBACCO = 2,
|
||||
GOODS_COTTON = 3,
|
||||
GOODS_FURS = 4,
|
||||
GOODS_LUMBER = 5,
|
||||
GOODS_ORE = 6,
|
||||
GOODS_SILVER = 7,
|
||||
GOODS_HORSES = 8,
|
||||
GOODS_RUM = 9,
|
||||
GOODS_CIGARS = 10,
|
||||
GOODS_CLOTH = 11,
|
||||
GOODS_COATS = 12,
|
||||
GOODS_TRADE_GOODS = 13,
|
||||
GOODS_TOOLS = 14,
|
||||
GOODS_MUSKETS = 15,
|
||||
|
||||
GOODS_COUNT = 16;
|
||||
|
||||
/**
|
||||
* The filename of the graphical representation of a specific unit is the following:
|
||||
|
@ -181,6 +200,8 @@ public final class ImageLibrary extends ImageProvider {
|
|||
colonyName = new String("Colony"),
|
||||
indianDirectory = new String("indians/"),
|
||||
indianName = new String("Indians"),
|
||||
goodsDirectory = new String("goods/"),
|
||||
goodsName = new String("Goods"),
|
||||
extension = new String(".png");
|
||||
private final String dataDirectory;
|
||||
|
||||
|
@ -192,7 +213,8 @@ public final class ImageLibrary extends ImageProvider {
|
|||
terrain2, // Holds Vectors that hold ImageIcon objects
|
||||
misc, // Holds ImageIcon objects
|
||||
colonies, //Holds ImageIcon objects
|
||||
indians; //Holds ImageIcon objects
|
||||
indians, //Holds ImageIcon objects
|
||||
goods; //Holds ImageIcon objects
|
||||
private Vector[] unitButtons; //Holds the unit-order buttons
|
||||
private Hashtable colorChips; // Color is key, BufferedImage is value
|
||||
|
||||
|
@ -243,6 +265,7 @@ public final class ImageLibrary extends ImageProvider {
|
|||
loadUnitButtons(gc, resourceLocator, doLookup);
|
||||
loadColonies(gc, resourceLocator, doLookup);
|
||||
loadIndians(gc, resourceLocator, doLookup);
|
||||
loadGoods(gc, resourceLocator, doLookup);
|
||||
loadColorChips(gc);
|
||||
}
|
||||
|
||||
|
@ -526,6 +549,50 @@ public final class ImageLibrary extends ImageProvider {
|
|||
indians.add(tempImage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the goods-images from file into memory.
|
||||
* @param gc The GraphicsConfiguration is needed to create images that are compatible with the
|
||||
* local environment.
|
||||
* @param resourceLocator The class that is used to locate data files.
|
||||
* @param doLookup Must be set to 'false' if the path to the image files
|
||||
* has been manually provided by the user. If set to 'true' then a
|
||||
* lookup will be done to search for image files from net.sf.freecol,
|
||||
* in this case the images need to be placed in net/sf/freecol/images.
|
||||
* @throws FreeColException If one of the data files could not be found.
|
||||
*/
|
||||
private void loadGoods(GraphicsConfiguration gc, Class resourceLocator, boolean doLookup) throws FreeColException {
|
||||
goods = new Vector(GOODS_COUNT);
|
||||
|
||||
for (int i = 0; i < GOODS_COUNT; i++) {
|
||||
String filePath = dataDirectory + path + goodsDirectory + goodsName + i + extension;
|
||||
ImageIcon tempImage;
|
||||
if (doLookup) {
|
||||
URL url = resourceLocator.getResource(filePath);
|
||||
if (url == null) {
|
||||
throw new FreeColException("The data file \"" + filePath + "\" could not be found.");
|
||||
}
|
||||
tempImage = new ImageIcon(url);
|
||||
} else {
|
||||
File tmpFile = new File(filePath);
|
||||
if ((tmpFile == null) || !tmpFile.exists() || !tmpFile.isFile() || !tmpFile.canRead()) {
|
||||
throw new FreeColException("The data file \"" + filePath + "\" could not be found.");
|
||||
}
|
||||
tempImage = new ImageIcon(filePath);
|
||||
}
|
||||
goods.add(tempImage);
|
||||
}
|
||||
|
||||
/*
|
||||
If all units are patched together in one graphics file then this is the way to load
|
||||
them into different images:
|
||||
|
||||
Image unitsImage = new ImageIcon(url).getImage();
|
||||
BufferedImage tempImage = gc.createCompatibleImage(42, 63, Transparency.TRANSLUCENT);
|
||||
tempImage.getGraphics().drawImage(unitsImage, 0, 0, null);
|
||||
units.add(tempImage);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates color chip images and stores them in memory. Color chips
|
||||
|
@ -665,6 +732,24 @@ public final class ImageLibrary extends ImageProvider {
|
|||
public Image getIndianSettlementImage(int index) {
|
||||
return ((ImageIcon) indians.get(index)).getImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the goods-image at the given index.
|
||||
* @param index The index of the goods-image to return.
|
||||
* @return The goods-image at the given index.
|
||||
*/
|
||||
public Image getGoodsImage(int index) {
|
||||
return ((ImageIcon) goods.get(index)).getImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the goods-image at the given index.
|
||||
* @param index The index of the goods-image to return.
|
||||
* @return The goods-image at the given index.
|
||||
*/
|
||||
public ImageIcon getGoodsImageIcon(int index) {
|
||||
return ((ImageIcon) goods.get(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the colony image at the given index
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.sf.freecol.common.model.ColonyTile;
|
|||
import net.sf.freecol.common.FreeColException;
|
||||
//import net.sf.freecol.common.model.Player;
|
||||
import net.sf.freecol.common.model.Unit;
|
||||
import net.sf.freecol.common.model.Goods;
|
||||
import net.sf.freecol.client.gui.Canvas;
|
||||
import net.sf.freecol.client.gui.GUI;
|
||||
import net.sf.freecol.client.gui.ImageLibrary;
|
||||
|
@ -57,9 +58,11 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
private final JLabel cargoLabel;
|
||||
private final JLabel goldLabel;
|
||||
private final JLabel warehouseLabel;
|
||||
private final OutsideColonyPanel outsideColonyPanel;
|
||||
private final InPortPanel inPortPanel;
|
||||
private final CargoPanel cargoPanel;
|
||||
private final WarehousePanel warehousePanel;
|
||||
private final TilePanel tilePanel;
|
||||
private final BuildingsPanel buildingsPanel;
|
||||
private final DefaultTransferHandler defaultTransferHandler;
|
||||
|
@ -87,36 +90,43 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
outsideColonyPanel = new OutsideColonyPanel(this);
|
||||
inPortPanel = new InPortPanel();
|
||||
cargoPanel = new CargoPanel(this);
|
||||
warehousePanel = new WarehousePanel(this);
|
||||
tilePanel = new TilePanel(this);
|
||||
buildingsPanel = new BuildingsPanel(this);
|
||||
|
||||
outsideColonyPanel.setBackground(Color.WHITE);
|
||||
inPortPanel.setBackground(Color.WHITE);
|
||||
cargoPanel.setBackground(Color.WHITE);
|
||||
warehousePanel.setBackground(Color.WHITE);
|
||||
buildingsPanel.setBackground(Color.WHITE);
|
||||
|
||||
defaultTransferHandler = new DefaultTransferHandler(this);
|
||||
outsideColonyPanel.setTransferHandler(defaultTransferHandler);
|
||||
inPortPanel.setTransferHandler(defaultTransferHandler);
|
||||
cargoPanel.setTransferHandler(defaultTransferHandler);
|
||||
warehousePanel.setTransferHandler(defaultTransferHandler);
|
||||
|
||||
pressListener = new DragListener(this);
|
||||
releaseListener = new DropListener();
|
||||
outsideColonyPanel.addMouseListener(releaseListener);
|
||||
inPortPanel.addMouseListener(releaseListener);
|
||||
cargoPanel.addMouseListener(releaseListener);
|
||||
warehousePanel.addMouseListener(releaseListener);
|
||||
|
||||
outsideColonyPanel.setLayout(new GridLayout(0 , 2));
|
||||
inPortPanel.setLayout(new GridLayout(0 , 2));
|
||||
cargoPanel.setLayout(new GridLayout(1 , 0));
|
||||
warehousePanel.setLayout(new GridLayout(1 , 0));
|
||||
|
||||
cargoLabel = new JLabel("<html><strike>Cargo</strike></html>");
|
||||
goldLabel = new JLabel("Gold: 0");
|
||||
warehouseLabel = new JLabel("Goods");
|
||||
|
||||
JButton exitButton = new JButton("Close");
|
||||
JScrollPane outsideColonyScroll = new JScrollPane(outsideColonyPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
|
||||
inPortScroll = new JScrollPane(inPortPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
|
||||
cargoScroll = new JScrollPane(cargoPanel, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
|
||||
warehouseScroll = new JScrollPane(warehousePanel, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
|
||||
tilesScroll = new JScrollPane(tilePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
|
||||
buildingsScroll = new JScrollPane(buildingsPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
JLabel outsideColonyLabel = new JLabel("In front of colony"),
|
||||
|
@ -128,12 +138,14 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
outsideColonyScroll.setSize(200, 100);
|
||||
inPortScroll.setSize(200, 100);
|
||||
cargoScroll.setSize(410, 96);
|
||||
warehouseScroll.setSize(620, 120);
|
||||
tilesScroll.setSize(390, 200);
|
||||
buildingsScroll.setSize(400,200);
|
||||
outsideColonyLabel.setSize(200, 20);
|
||||
inPortLabel.setSize(200, 20);
|
||||
cargoLabel.setSize(410, 20);
|
||||
goldLabel.setSize(100, 20);
|
||||
warehouseLabel.setSize(100, 20);
|
||||
tilesLabel.setSize(100, 20);
|
||||
buildingsLabel.setSize(300, 20);
|
||||
|
||||
|
@ -141,11 +153,13 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
outsideColonyScroll.setLocation(640, 300);
|
||||
inPortScroll.setLocation(640, 450);
|
||||
cargoScroll.setLocation(220, 370);
|
||||
warehouseScroll.setLocation(10, 470);
|
||||
tilesScroll.setLocation(10, 40);
|
||||
buildingsScroll.setLocation(400, 40);
|
||||
outsideColonyLabel.setLocation(640, 275);
|
||||
inPortLabel.setLocation(640, 425);
|
||||
cargoLabel.setLocation(220, 345);
|
||||
warehouseLabel.setLocation(10, 445);
|
||||
goldLabel.setLocation(15, 345);
|
||||
tilesLabel.setLocation(10, 10);
|
||||
buildingsLabel.setLocation(400, 10);
|
||||
|
@ -160,11 +174,13 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
add(outsideColonyScroll);
|
||||
add(inPortScroll);
|
||||
add(cargoScroll);
|
||||
add(warehouseScroll);
|
||||
add(tilesScroll);
|
||||
add(buildingsScroll);
|
||||
add(outsideColonyLabel);
|
||||
add(inPortLabel);
|
||||
add(cargoLabel);
|
||||
add(warehouseLabel);
|
||||
add(goldLabel);
|
||||
add(tilesLabel);
|
||||
add(buildingsLabel);
|
||||
|
@ -203,6 +219,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
//
|
||||
|
||||
cargoPanel.removeAll();
|
||||
warehousePanel.removeAll();
|
||||
outsideColonyPanel.removeAll();
|
||||
inPortPanel.removeAll();
|
||||
tilePanel.removeAll();
|
||||
|
@ -235,6 +252,24 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
setSelectedUnit(lastCarrier);
|
||||
|
||||
//
|
||||
// Warehouse panel:
|
||||
//
|
||||
|
||||
Iterator goodsIterator = colony.getGoodsIterator();
|
||||
while (goodsIterator.hasNext()) {
|
||||
Goods goods = (Goods) goodsIterator.next();
|
||||
|
||||
GoodsLabel goodsLabel = new GoodsLabel(goods, parent);
|
||||
goodsLabel.setTransferHandler(defaultTransferHandler);
|
||||
goodsLabel.addMouseListener(pressListener);
|
||||
|
||||
warehousePanel.add(goodsLabel, false);
|
||||
}
|
||||
|
||||
warehousePanel.revalidate();
|
||||
|
||||
setSelectedUnit(lastCarrier);
|
||||
|
||||
//
|
||||
// Units in buildings:
|
||||
|
@ -341,6 +376,18 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
cargoPanel.add(label, false);
|
||||
}
|
||||
|
||||
Iterator goodsIterator = selUnit.getGoodsIterator();
|
||||
while (goodsIterator.hasNext()) {
|
||||
Goods g = (Goods) goodsIterator.next();
|
||||
|
||||
GoodsLabel label = new GoodsLabel(g, parent);
|
||||
label.setTransferHandler(defaultTransferHandler);
|
||||
label.addMouseListener(pressListener);
|
||||
|
||||
cargoPanel.add(label, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updateCargoLabel();
|
||||
|
@ -357,6 +404,19 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
return cargoPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the <code>warehousePanel</code>-object in use.
|
||||
*/
|
||||
public final WarehousePanel getWarehousePanel() {
|
||||
return warehousePanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the <code>tilePanel</code>-object in use.
|
||||
*/
|
||||
public final TilePanel getTilePanel() {
|
||||
return tilePanel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -534,6 +594,63 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* A panel that holds goods that represent cargo that is inside the
|
||||
* Colony.
|
||||
*/
|
||||
public final class WarehousePanel extends JPanel {
|
||||
private final ColonyPanel colonyPanel;
|
||||
|
||||
/**
|
||||
* Creates this CargoPanel.
|
||||
* @param colonyPanel The panel that holds this CargoPanel.
|
||||
*/
|
||||
public WarehousePanel(ColonyPanel colonyPanel) {
|
||||
this.colonyPanel = colonyPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a component to this CargoPanel and makes sure that the unit
|
||||
* or good that the component represents gets modified so that it is
|
||||
* on board the currently selected ship.
|
||||
* @param comp The component to add to this CargoPanel.
|
||||
* @param editState Must be set to 'true' if the state of the component
|
||||
* that is added (which should be a dropped component representing a Unit or
|
||||
* good) should be changed so that the underlying unit or goods are
|
||||
* on board the currently selected ship.
|
||||
* @return The component argument.
|
||||
*/
|
||||
public Component add(Component comp, boolean editState) {
|
||||
if (editState) {
|
||||
if (comp instanceof GoodsLabel) {
|
||||
Goods g = ((GoodsLabel)comp).getGoods();
|
||||
((GoodsLabel) comp).setSmall(false);
|
||||
//inGameController.unloadCargo(g, selectedUnit.getUnit());
|
||||
colonyPanel.getWarehousePanel().revalidate();
|
||||
colonyPanel.getCargoPanel().revalidate();
|
||||
} else {
|
||||
logger.warning("An invalid component got dropped on this WarehousePanel.");
|
||||
}
|
||||
}
|
||||
|
||||
Component c = add(comp);
|
||||
|
||||
refresh();
|
||||
return c;
|
||||
}
|
||||
|
||||
public void remove(Component comp) {
|
||||
if (comp instanceof GoodsLabel) {
|
||||
Goods g = ((GoodsLabel)comp).getGoods();
|
||||
//inGameController.leaveShip(unit);
|
||||
|
||||
super.remove(comp);
|
||||
colonyPanel.getWarehousePanel().revalidate();
|
||||
colonyPanel.getCargoPanel().revalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A panel that holds units and goods that represent Units and cargo that are
|
||||
* on board the currently selected ship.
|
||||
|
@ -564,8 +681,20 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
if (editState) {
|
||||
if (comp instanceof UnitLabel) {
|
||||
Unit unit = ((UnitLabel)comp).getUnit();
|
||||
((UnitLabel) comp).setSmall(false);
|
||||
inGameController.boardShip(unit, selectedUnit.getUnit());
|
||||
if (!unit.isCarrier()) // No, you cannot load ships onto other ships.
|
||||
{
|
||||
((UnitLabel) comp).setSmall(false);
|
||||
inGameController.boardShip(unit, selectedUnit.getUnit());
|
||||
} else {
|
||||
return comp;
|
||||
}
|
||||
} else if (comp instanceof GoodsLabel) {
|
||||
Goods g = ((GoodsLabel)comp).getGoods();
|
||||
((GoodsLabel) comp).setSmall(false);
|
||||
logger.warning("Attempting to load cargo.");
|
||||
inGameController.loadCargo(g, selectedUnit.getUnit());
|
||||
colonyPanel.getWarehousePanel().revalidate();
|
||||
colonyPanel.getCargoPanel().revalidate();
|
||||
} else {
|
||||
logger.warning("An invalid component got dropped on this CargoPanel.");
|
||||
}
|
||||
|
@ -583,12 +712,17 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
inGameController.leaveShip(unit);
|
||||
|
||||
super.remove(comp);
|
||||
} else if (comp instanceof GoodsLabel) {
|
||||
Goods g = ((GoodsLabel)comp).getGoods();
|
||||
inGameController.unloadCargo(g);
|
||||
super.remove(comp);
|
||||
colonyPanel.getWarehousePanel().revalidate();
|
||||
colonyPanel.getCargoPanel().revalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A panel that displays the tiles in the immediate area around the colony.
|
||||
*/
|
||||
|
@ -633,6 +767,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
private ColonyTile colonyTile;
|
||||
private int x;
|
||||
private int y;
|
||||
private JLabel staticGoodsLabel;
|
||||
|
||||
public ASingleTilePanel(ColonyTile colonyTile, int x, int y) {
|
||||
this.colonyTile = colonyTile;
|
||||
|
@ -649,7 +784,21 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
unitLabel.addMouseListener(pressListener);
|
||||
|
||||
add(unitLabel);
|
||||
|
||||
staticGoodsLabel = new JLabel(parent.getImageProvider().getGoodsImageIcon(unit.getWorkType()));
|
||||
staticGoodsLabel.setText(Integer.toString(unit.getFarmedPotential(unit.getWorkType(), colonyTile.getWorkTile())));
|
||||
add(staticGoodsLabel);
|
||||
}
|
||||
|
||||
if (colonyTile.isColonyCenterTile())
|
||||
{
|
||||
staticGoodsLabel = new JLabel(parent.getImageProvider().getGoodsImageIcon(Goods.FOOD));
|
||||
staticGoodsLabel.setText(Integer.toString(colonyTile.getTile().potential(Goods.FOOD)));
|
||||
add(staticGoodsLabel);
|
||||
staticGoodsLabel = new JLabel(parent.getImageProvider().getGoodsImageIcon(colonyTile.getTile().secondaryGoods()));
|
||||
staticGoodsLabel.setText(Integer.toString(colonyTile.getTile().potential(colonyTile.getTile().secondaryGoods())));
|
||||
add(staticGoodsLabel);
|
||||
}
|
||||
|
||||
setTransferHandler(defaultTransferHandler);
|
||||
addMouseListener(releaseListener);
|
||||
|
@ -687,6 +836,14 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
inGameController.work(unit, colonyTile);
|
||||
|
||||
((UnitLabel) comp).setSmall(false);
|
||||
|
||||
if (staticGoodsLabel != null) {
|
||||
super.remove(staticGoodsLabel);
|
||||
staticGoodsLabel = null;
|
||||
}
|
||||
staticGoodsLabel = new JLabel(parent.getImageProvider().getGoodsImageIcon(unit.getWorkType()));
|
||||
staticGoodsLabel.setText(Integer.toString(unit.getFarmedPotential(unit.getWorkType(), colonyTile.getWorkTile())));
|
||||
add(staticGoodsLabel);
|
||||
} else {
|
||||
logger.warning("An invalid component got dropped on this CargoPanel.");
|
||||
}
|
||||
|
@ -697,6 +854,14 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
refresh();
|
||||
return c;
|
||||
}
|
||||
|
||||
public void remove(Component comp) {
|
||||
if (comp instanceof UnitLabel) {
|
||||
super.remove(staticGoodsLabel);
|
||||
staticGoodsLabel = null;
|
||||
}
|
||||
super.remove(comp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import javax.swing.TransferHandler;
|
|||
|
||||
import net.sf.freecol.common.model.Europe;
|
||||
import net.sf.freecol.common.model.Unit;
|
||||
import net.sf.freecol.common.model.Goods;
|
||||
|
||||
/**
|
||||
* The transferhandler that is capable of creating ImageSelection objects.
|
||||
|
@ -58,7 +59,7 @@ public final class DefaultTransferHandler extends TransferHandler {
|
|||
* flavor that is indicated by the second parameter, 'false' otherwise.
|
||||
*/
|
||||
public boolean canImport(JComponent comp, DataFlavor flavor[]) {
|
||||
if (!(comp instanceof UnitLabel) && !(comp instanceof JPanel) && !(comp instanceof JLabel)) {
|
||||
if (!(comp instanceof UnitLabel) && !(comp instanceof GoodsLabel) && !(comp instanceof MarketLabel) && !(comp instanceof JPanel) && !(comp instanceof JLabel)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < flavor.length; i++) {
|
||||
|
@ -79,6 +80,10 @@ public final class DefaultTransferHandler extends TransferHandler {
|
|||
public Transferable createTransferable(JComponent comp) {
|
||||
if (comp instanceof UnitLabel) {
|
||||
return new ImageSelection((UnitLabel)comp);
|
||||
} else if (comp instanceof GoodsLabel) {
|
||||
return new ImageSelection((GoodsLabel)comp);
|
||||
} else if (comp instanceof MarketLabel) {
|
||||
return new ImageSelection((MarketLabel)comp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -102,9 +107,8 @@ public final class DefaultTransferHandler extends TransferHandler {
|
|||
logger.warning("Data flavor is not supported!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure we don't drop onto other UnitLabels.
|
||||
|
||||
// Make sure we don't drop onto other Labels.
|
||||
if (comp instanceof UnitLabel) {
|
||||
|
||||
/*
|
||||
|
@ -134,8 +138,16 @@ public final class DefaultTransferHandler extends TransferHandler {
|
|||
} catch (ClassCastException e) {}
|
||||
|
||||
}
|
||||
} else if ((comp instanceof GoodsLabel) || (comp instanceof MarketLabel)) {
|
||||
try {
|
||||
comp = (JComponent)comp.getParent();
|
||||
} catch (ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (data instanceof UnitLabel) {
|
||||
|
||||
// Check if the unit can be dragged to comp.
|
||||
|
||||
Unit unit = ((UnitLabel)data).getUnit();
|
||||
|
@ -199,7 +211,65 @@ public final class DefaultTransferHandler extends TransferHandler {
|
|||
comp.revalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (data instanceof GoodsLabel) {
|
||||
|
||||
// Check if the unit can be dragged to comp.
|
||||
|
||||
//Goods g = ((GoodsLabel)data).getGoods();
|
||||
|
||||
// Import the data.
|
||||
|
||||
|
||||
if (comp instanceof JLabel) {
|
||||
logger.warning("Oops, I thought we didn't have to write this part.");
|
||||
return true;
|
||||
} else if (comp instanceof JPanel) {
|
||||
data.getParent().remove(data);
|
||||
|
||||
if (comp instanceof ColonyPanel.WarehousePanel) {
|
||||
((ColonyPanel.WarehousePanel)comp).add(data, true);
|
||||
} else if (comp instanceof ColonyPanel.CargoPanel) {
|
||||
((ColonyPanel.CargoPanel)comp).add(data, true);
|
||||
} else if (comp instanceof EuropePanel.MarketPanel) {
|
||||
((EuropePanel.MarketPanel)comp).add(data, true);
|
||||
} else {
|
||||
logger.warning("The receiving component is of an invalid type.");
|
||||
return false;
|
||||
}
|
||||
|
||||
comp.revalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (data instanceof MarketLabel) {
|
||||
|
||||
// Check if the unit can be dragged to comp.
|
||||
|
||||
//Goods g = ((GoodsLabel)data).getGoods();
|
||||
|
||||
// Import the data.
|
||||
|
||||
|
||||
if (comp instanceof JLabel) {
|
||||
logger.warning("Oops, I thought we didn't have to write this part.");
|
||||
return true;
|
||||
} else if (comp instanceof JPanel) {
|
||||
// Be not removing MarketLabels from their home. -sjm
|
||||
//data.getParent().remove(data);
|
||||
|
||||
if (comp instanceof EuropePanel.CargoPanel) {
|
||||
((EuropePanel.CargoPanel)comp).add(data, true);
|
||||
} else {
|
||||
logger.warning("The receiving component is of an invalid type.");
|
||||
return false;
|
||||
}
|
||||
|
||||
comp.revalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
logger.warning("The dragged component is of an invalid type.");
|
||||
} catch (UnsupportedFlavorException ignored) {
|
||||
} catch (IOException ignored) {}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.swing.JPopupMenu;
|
|||
import javax.swing.TransferHandler;
|
||||
|
||||
import net.sf.freecol.common.model.Unit;
|
||||
import net.sf.freecol.common.model.ColonyTile;
|
||||
|
||||
/**
|
||||
* A DragListener should be attached to Swing components that have a
|
||||
|
@ -89,6 +90,41 @@ public final class DragListener extends MouseAdapter {
|
|||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
|
||||
if (tempUnit.getLocation() instanceof ColonyTile) {
|
||||
menuItem = new JMenuItem("Be a Farmer");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_FOOD));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be a Sugar Planter");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_SUGAR));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be a Tobacco Planter");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_TOBACCO));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be a Cotton Planter");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_COTTON));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be a Fur Trapper");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_FURS));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be a Lumberjack");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_LUMBER));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be an Ore Miner");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_ORE));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
menuItem = new JMenuItem("Be a Silver Miner");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_SILVER));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
menu.show(comp, e.getX(), e.getY());
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -30,6 +30,7 @@ import net.sf.freecol.common.model.Game;
|
|||
import net.sf.freecol.common.model.Europe;
|
||||
import net.sf.freecol.common.model.Player;
|
||||
import net.sf.freecol.common.model.Unit;
|
||||
import net.sf.freecol.common.model.Goods;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -89,6 +90,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
private final InPortPanel inPortPanel;
|
||||
private final DocksPanel docksPanel;
|
||||
private final CargoPanel cargoPanel;
|
||||
private final MarketPanel marketPanel;
|
||||
private final RecruitPanel recruitPanel;
|
||||
private final PurchasePanel purchasePanel;
|
||||
private final TrainPanel trainPanel;
|
||||
|
@ -117,6 +119,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
inPortPanel = new InPortPanel();
|
||||
docksPanel = new DocksPanel(this);
|
||||
cargoPanel = new CargoPanel(this);
|
||||
marketPanel = new MarketPanel(this);
|
||||
recruitPanel = new RecruitPanel(this);
|
||||
purchasePanel = new PurchasePanel(this);
|
||||
trainPanel = new TrainPanel(this);
|
||||
|
@ -133,6 +136,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
inPortPanel.setTransferHandler(defaultTransferHandler);
|
||||
docksPanel.setTransferHandler(defaultTransferHandler);
|
||||
cargoPanel.setTransferHandler(defaultTransferHandler);
|
||||
marketPanel.setTransferHandler(defaultTransferHandler);
|
||||
|
||||
pressListener = new DragListener(this);
|
||||
MouseListener releaseListener = new DropListener();
|
||||
|
@ -141,6 +145,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
inPortPanel.addMouseListener(releaseListener);
|
||||
docksPanel.addMouseListener(releaseListener);
|
||||
cargoPanel.addMouseListener(releaseListener);
|
||||
marketPanel.addMouseListener(releaseListener);
|
||||
|
||||
toAmericaPanel.setLayout(new GridLayout(0 , 2));
|
||||
toEuropePanel.setLayout(new GridLayout(0 , 2));
|
||||
|
@ -159,7 +164,8 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
toEuropeScroll = new JScrollPane(toEuropePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
|
||||
inPortScroll = new JScrollPane(inPortPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
|
||||
docksScroll = new JScrollPane(docksPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
|
||||
cargoScroll = new JScrollPane(cargoPanel, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
cargoScroll = new JScrollPane(cargoPanel, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
|
||||
marketScroll = new JScrollPane(marketPanel, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
JLabel toAmericaLabel = new JLabel("Going to America"),
|
||||
toEuropeLabel = new JLabel("Going to Europe"),
|
||||
inPortLabel = new JLabel("In port"),
|
||||
|
@ -174,6 +180,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
inPortScroll.setSize(200, 300);
|
||||
docksScroll.setSize(200, 300);
|
||||
cargoScroll.setSize(410, 96);
|
||||
marketScroll.setSize(620, 114);
|
||||
toAmericaLabel.setSize(200, 20);
|
||||
toEuropeLabel.setSize(200, 20);
|
||||
inPortLabel.setSize(200, 20);
|
||||
|
@ -190,6 +197,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
inPortScroll.setLocation(430, 35);
|
||||
docksScroll.setLocation(640, 250);
|
||||
cargoScroll.setLocation(220, 370);
|
||||
marketScroll.setLocation(10, 476);
|
||||
toAmericaLabel.setLocation(10, 10);
|
||||
toEuropeLabel.setLocation(220, 10);
|
||||
inPortLabel.setLocation(430, 10);
|
||||
|
@ -218,6 +226,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
add(inPortScroll);
|
||||
add(docksScroll);
|
||||
add(cargoScroll);
|
||||
add(marketScroll);
|
||||
add(toAmericaLabel);
|
||||
add(toEuropeLabel);
|
||||
add(inPortLabel);
|
||||
|
@ -326,6 +335,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
toEuropePanel.removeAll();
|
||||
inPortPanel.removeAll();
|
||||
cargoPanel.removeAll();
|
||||
marketPanel.removeAll();
|
||||
docksPanel.removeAll();
|
||||
|
||||
//
|
||||
|
@ -350,6 +360,15 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
toAmericaPanel.add(unitLabel, false);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Goods.NUMBER_OF_TYPES; i++)
|
||||
{
|
||||
MarketLabel marketLabel = new MarketLabel(i, game.getMarket(), parent);
|
||||
marketLabel.setTransferHandler(defaultTransferHandler);
|
||||
marketLabel.addMouseListener(pressListener);
|
||||
((JPanel)marketPanel).add(marketLabel);
|
||||
}
|
||||
|
||||
|
||||
setSelectedUnit(null);
|
||||
goldLabel.setText("Gold: " + freeColClient.getMyPlayer().getGold());
|
||||
|
@ -383,6 +402,17 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
cargoPanel.add(label, false);
|
||||
}
|
||||
|
||||
Iterator goodsIterator = selUnit.getGoodsIterator();
|
||||
while (goodsIterator.hasNext()) {
|
||||
Goods g = (Goods) goodsIterator.next();
|
||||
|
||||
GoodsLabel label = new GoodsLabel(g, parent);
|
||||
label.setTransferHandler(defaultTransferHandler);
|
||||
label.addMouseListener(pressListener);
|
||||
|
||||
cargoPanel.add(label, false);
|
||||
}
|
||||
}
|
||||
|
||||
updateCargoLabel();
|
||||
|
@ -714,6 +744,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
europePanel.refresh();
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -877,8 +908,18 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
if (comp instanceof UnitLabel) {
|
||||
Unit unit = ((UnitLabel)comp).getUnit();
|
||||
inGameController.boardShip(unit, selectedUnit.getUnit());
|
||||
}
|
||||
else {
|
||||
} else if (comp instanceof MarketLabel) {
|
||||
if ((freeColClient.getMyPlayer().getGold() >= (game.getMarket().costToBuy(((MarketLabel)comp).getType()) * 100))) {
|
||||
inGameController.buyGoods(((MarketLabel)comp).getType(), selectedUnit.getUnit(), freeColClient.getMyPlayer());
|
||||
}
|
||||
updateCargoLabel();
|
||||
goldLabel.setText("Gold: " + freeColClient.getMyPlayer().getGold());
|
||||
goldLabel.repaint(0, 0, goldLabel.getWidth(), goldLabel.getHeight());
|
||||
europePanel.getMarketPanel().revalidate();
|
||||
revalidate();
|
||||
europePanel.refresh();
|
||||
return comp;
|
||||
} else {
|
||||
logger.warning("An invalid component got dropped on this CargoPanel.");
|
||||
}
|
||||
}
|
||||
|
@ -889,6 +930,53 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A panel that shows goods available for purchase in Europe.
|
||||
*/
|
||||
public final class MarketPanel extends JPanel {
|
||||
private final EuropePanel europePanel;
|
||||
|
||||
/**
|
||||
* Creates this MarketPanel.
|
||||
* @param europePanel The panel that holds this CargoPanel.
|
||||
*/
|
||||
public MarketPanel(EuropePanel europePanel) {
|
||||
this.europePanel = europePanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a GoodsLabel is dropped here, sell the goods.
|
||||
* @param comp The component to add to this MarketPanel.
|
||||
* @param editState Must be set to 'true' if the state of the component
|
||||
* that is added (which should be a dropped component representing goods)
|
||||
* should be sold.
|
||||
* @return The component argument.
|
||||
*/
|
||||
public Component add(Component comp, boolean editState) {
|
||||
if (editState) {
|
||||
if (comp instanceof GoodsLabel) {
|
||||
//getGame().getMarket().sell(((GoodsLabel)comp).getGoods(), freeColClient.getMyPlayer());
|
||||
inGameController.sellGoods(((GoodsLabel)comp).getGoods(), freeColClient.getMyPlayer());
|
||||
updateCargoLabel();
|
||||
goldLabel.setText("Gold: " + freeColClient.getMyPlayer().getGold());
|
||||
goldLabel.repaint(0, 0, goldLabel.getWidth(), goldLabel.getHeight());
|
||||
europePanel.getCargoPanel().revalidate();
|
||||
revalidate();
|
||||
europePanel.refresh();
|
||||
return comp;
|
||||
}
|
||||
else {
|
||||
logger.warning("An invalid component got dropped on this MarketPanel.");
|
||||
}
|
||||
}
|
||||
europePanel.refresh();
|
||||
return comp;
|
||||
}
|
||||
public void remove(Component comp) {
|
||||
// Don't remove the marketLabel.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a pointer to the <code>cargoPanel</code>-object in use.
|
||||
|
@ -897,9 +985,13 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
return cargoPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the <code>marketPanel</code>-object in use.
|
||||
*/
|
||||
public final MarketPanel getMarketPanel() {
|
||||
return marketPanel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The panel that allows a user to recruit people in Europe.
|
||||
|
|
|
@ -32,6 +32,20 @@ public abstract class ImageProvider {
|
|||
*/
|
||||
public abstract Image getTerrainImage(int type, int x, int y);
|
||||
|
||||
/**
|
||||
* Should return the Image of the graphic with the given type.
|
||||
* @param index The type of the graphic of which we need the Image.
|
||||
* @return The Image of the graphic with the given type.
|
||||
*/
|
||||
public abstract Image getGoodsImage(int type);
|
||||
|
||||
/**
|
||||
* Should return the Image of the graphic with the given type.
|
||||
* @param index The type of the graphic of which we need the Image.
|
||||
* @return The Image of the graphic with the given type.
|
||||
*/
|
||||
public abstract ImageIcon getGoodsImageIcon(int type);
|
||||
|
||||
/**
|
||||
* Should return the Image of the graphic with the given type.
|
||||
* @param index The type of the graphic of which we need the Image.
|
||||
|
|
|
@ -38,7 +38,7 @@ public final class ImageSelection implements Transferable {
|
|||
* the data is not of the given flavor.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor) {
|
||||
if (isDataFlavorSupported(flavors[0])) {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return label;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.sf.freecol.common.model.Goods;
|
|||
import net.sf.freecol.common.model.Unit;
|
||||
import net.sf.freecol.client.gui.Canvas;
|
||||
|
||||
import net.sf.freecol.client.control.InGameController;
|
||||
|
||||
/**
|
||||
* This label holds Unit data in addition to the JLabel data, which makes
|
||||
|
@ -30,12 +31,22 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
public static final int ARM = 0,
|
||||
MOUNT = 1,
|
||||
TOOLS = 2,
|
||||
DRESS = 3;
|
||||
DRESS = 3,
|
||||
WORKTYPE_FOOD = 4,
|
||||
WORKTYPE_SUGAR = 5,
|
||||
WORKTYPE_TOBACCO = 6,
|
||||
WORKTYPE_COTTON = 7,
|
||||
WORKTYPE_FURS = 8,
|
||||
WORKTYPE_LUMBER = 9,
|
||||
WORKTYPE_ORE = 10,
|
||||
WORKTYPE_SILVER = 11;
|
||||
|
||||
private final Unit unit;
|
||||
private final Canvas parent;
|
||||
private boolean selected;
|
||||
|
||||
private InGameController inGameController;
|
||||
|
||||
/**
|
||||
* Initializes this JLabel with the given unit data.
|
||||
* @param unit The Unit that this JLabel will visually represent.
|
||||
|
@ -46,6 +57,8 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
this.unit = unit;
|
||||
this.parent = parent;
|
||||
selected = false;
|
||||
|
||||
this.inGameController = parent.getClient().getInGameController();
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,7 +69,7 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
*/
|
||||
public UnitLabel(Unit unit, Canvas parent, boolean isSmall) {
|
||||
this(unit, parent);
|
||||
setSmall(true);
|
||||
setSmall(isSmall);
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,11 +142,36 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
case DRESS:
|
||||
//parent.dressAsMissionary(unit);
|
||||
break;
|
||||
case WORKTYPE_FOOD:
|
||||
inGameController.changeWorkType(unit, Goods.FOOD);
|
||||
break;
|
||||
case WORKTYPE_SUGAR:
|
||||
inGameController.changeWorkType(unit, Goods.SUGAR);
|
||||
break;
|
||||
case WORKTYPE_TOBACCO:
|
||||
inGameController.changeWorkType(unit, Goods.TOBACCO);
|
||||
break;
|
||||
case WORKTYPE_COTTON:
|
||||
inGameController.changeWorkType(unit, Goods.COTTON);
|
||||
break;
|
||||
case WORKTYPE_FURS:
|
||||
inGameController.changeWorkType(unit, Goods.FURS);
|
||||
break;
|
||||
case WORKTYPE_LUMBER:
|
||||
inGameController.changeWorkType(unit, Goods.LUMBER);
|
||||
break;
|
||||
case WORKTYPE_ORE:
|
||||
inGameController.changeWorkType(unit, Goods.ORE);
|
||||
break;
|
||||
case WORKTYPE_SILVER:
|
||||
inGameController.changeWorkType(unit, Goods.SILVER);
|
||||
break;
|
||||
default:
|
||||
logger.warning("Invalid action");
|
||||
}
|
||||
setIcon(parent.getImageProvider().getUnitImageIcon(parent.getImageProvider().getUnitGraphicsType(unit)));
|
||||
repaint(0, 0, getWidth(), getHeight());
|
||||
|
||||
|
||||
// TODO: Refresh the gold label when goods have prices.
|
||||
//goldLabel.repaint(0, 0, goldLabel.getWidth(), goldLabel.getHeight());
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.sf.freecol.common.model;
|
|||
|
||||
import net.sf.freecol.common.model.Colony;
|
||||
import net.sf.freecol.common.model.Unit;
|
||||
import net.sf.freecol.common.model.Goods;
|
||||
|
||||
import net.sf.freecol.common.FreeColException;
|
||||
|
||||
|
@ -342,7 +343,72 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
* Prepares this <code>Building</code> for a new turn.
|
||||
*/
|
||||
public void newTurn() {
|
||||
|
||||
int goodsInput = 0;
|
||||
int goodsOutput = 0;
|
||||
int goodsInputType = -1;
|
||||
int goodsOutputType = -1;
|
||||
|
||||
Goods thepackage;
|
||||
|
||||
if (level == NOT_BUILT) return; // Don't do anything if the building does not exist.
|
||||
|
||||
// Figure out what's produced here and what it requires to do so.
|
||||
switch(type) {
|
||||
case BLACKSMITH:
|
||||
goodsInputType = Goods.ORE;
|
||||
goodsOutputType = Goods.TOOLS;
|
||||
break;
|
||||
case TOBACCONIST:
|
||||
goodsInputType = Goods.TOBACCO;
|
||||
goodsOutputType = Goods.CIGARS;
|
||||
break;
|
||||
case WEAVER:
|
||||
goodsInputType = Goods.COTTON;
|
||||
goodsOutputType = Goods.CLOTH;
|
||||
break;
|
||||
case DISTILLER:
|
||||
goodsInputType = Goods.SUGAR;
|
||||
goodsOutputType = Goods.RUM;
|
||||
break;
|
||||
case FUR_TRADER:
|
||||
goodsInputType = Goods.FURS;
|
||||
goodsOutputType = Goods.COATS;
|
||||
break;
|
||||
case ARMORY:
|
||||
goodsInputType = Goods.TOOLS;
|
||||
goodsOutputType = Goods.MUSKETS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (goodsOutputType < 0) return;
|
||||
|
||||
Iterator unitIterator = getUnitIterator();
|
||||
while (unitIterator.hasNext())
|
||||
{
|
||||
goodsOutput += ((Unit) unitIterator.next()).getProducedAmount(goodsOutputType);
|
||||
}
|
||||
goodsInput = goodsOutput;
|
||||
goodsOutput *= level;
|
||||
goodsInput *= ((level > SHOP) ? SHOP : level); // Factories don't need the extra 3 units.
|
||||
if (colony.getGoodsCount(goodsInputType) < goodsInput) // Not enough goods to do this?
|
||||
{
|
||||
goodsInput = colony.getGoodsCount(goodsInputType);
|
||||
if (level < FACTORY) {
|
||||
goodsOutput = goodsInput;
|
||||
} else {
|
||||
goodsOutput = (goodsInput * 3) / 2;
|
||||
}
|
||||
}
|
||||
if (goodsOutput <= 0) return;
|
||||
|
||||
// Actually produce the goods.
|
||||
colony.removeAmountAndTypeOfGoods(goodsInputType, goodsInput);
|
||||
thepackage = new Goods(getGame(), null, goodsOutputType, goodsOutput);
|
||||
thepackage.setLocation(colony);
|
||||
//colony.add(thepackage);
|
||||
getGame().mustRestartNewTurn = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import net.sf.freecol.common.FreeColException;
|
|||
* The latter represents the tiles around the <code>Colony</code> where working is
|
||||
* possible.
|
||||
*/
|
||||
public final class Colony extends Settlement {
|
||||
public final class Colony extends Settlement implements Location {
|
||||
private static final Logger logger = Logger.getLogger(Colony.class.getName());
|
||||
|
||||
public static final String COPYRIGHT = "Copyright (C) 2003 The FreeCol Team";
|
||||
|
@ -33,7 +33,7 @@ public final class Colony extends Settlement {
|
|||
/** Places a unit may work. Either a <code>Building</code> or a <code>ColonyTile</code>. */
|
||||
private ArrayList workLocations = new ArrayList();
|
||||
|
||||
|
||||
private GoodsContainer goodsContainer;
|
||||
|
||||
|
||||
|
||||
|
@ -48,6 +48,8 @@ public final class Colony extends Settlement {
|
|||
public Colony(Game game, Player owner, String name, Tile tile) {
|
||||
super(game, owner, tile);
|
||||
|
||||
goodsContainer = new GoodsContainer(game, this);
|
||||
|
||||
this.name = name;
|
||||
|
||||
workLocations.add(new ColonyTile(getGame(), this, tile));
|
||||
|
@ -171,7 +173,14 @@ public final class Colony extends Settlement {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a <code>Tile</code> of this<code>Colony</code>
|
||||
* @return The <code>Tile</code>.
|
||||
*/
|
||||
public Tile getTile() {
|
||||
return tile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a <code>Tile</code> from the neighbourhood of this <code>Colony</code>
|
||||
* @return The <code>Tile</code>.
|
||||
|
@ -235,6 +244,8 @@ public final class Colony extends Settlement {
|
|||
return;
|
||||
}
|
||||
}
|
||||
} else if (locatable instanceof Goods) {
|
||||
goodsContainer.addGoods((Goods)locatable);
|
||||
} else {
|
||||
logger.warning("Tried to add an unrecognized 'Locatable' to a 'Colony'.");
|
||||
}
|
||||
|
@ -255,6 +266,8 @@ public final class Colony extends Settlement {
|
|||
return;
|
||||
}
|
||||
}
|
||||
} else if (locatable instanceof Goods) {
|
||||
goodsContainer.removeGoods((Goods)locatable);
|
||||
} else {
|
||||
logger.warning("Tried to remove an unrecognized 'Locatable' from a 'Colony'.");
|
||||
}
|
||||
|
@ -279,11 +292,42 @@ public final class Colony extends Settlement {
|
|||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of one type of Goods at this Colony.
|
||||
*
|
||||
* @param type The type of goods to look for.
|
||||
* @return The amount of this type of Goods at this Location.
|
||||
*/
|
||||
public int getGoodsCount(int type) {
|
||||
return goodsContainer.getGoodsCount(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total amount of all types of Goods at this Colony.
|
||||
* @return The total amount of all types of Goods at this Location.
|
||||
*/
|
||||
public int getTotalGoodsCount() {
|
||||
return goodsContainer.getTotalGoodsCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a specified amount of a type of Goods from this containter.
|
||||
*
|
||||
* @param type The type of Goods to remove from this container.
|
||||
* @param amount The amount of Goods to remove from this container.
|
||||
* @return The goods that have been removed from this container (if any).
|
||||
*/
|
||||
public Goods removeAmountAndTypeOfGoods(int type, int amount) {
|
||||
return goodsContainer.removeAmountAndTypeOfGoods(type, amount);
|
||||
}
|
||||
|
||||
public Iterator getUnitIterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Iterator getGoodsIterator() {
|
||||
return goodsContainer.getGoodsIterator();
|
||||
}
|
||||
|
||||
public boolean contains(Locatable locatable) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -343,6 +387,8 @@ public final class Colony extends Settlement {
|
|||
while (workLocationIterator.hasNext()) {
|
||||
colonyElement.appendChild(((FreeColGameObject) workLocationIterator.next()).toXMLElement(player, document));
|
||||
}
|
||||
|
||||
colonyElement.appendChild(goodsContainer.toXMLElement(player, document));
|
||||
|
||||
return colonyElement;
|
||||
}
|
||||
|
@ -379,7 +425,15 @@ public final class Colony extends Settlement {
|
|||
} else {
|
||||
workLocations.add(new Building(getGame(), childElement));
|
||||
}
|
||||
}
|
||||
} else if (childElement.getTagName().equals(GoodsContainer.getXMLElementTagName())) {
|
||||
GoodsContainer gc = (GoodsContainer) getGame().getFreeColGameObject(childElement.getAttribute("ID"));
|
||||
|
||||
if (gc != null) {
|
||||
goodsContainer.readFromXMLElement(childElement);
|
||||
} else {
|
||||
goodsContainer = new GoodsContainer(getGame(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ public class ColonyTile extends FreeColGameObject implements WorkLocation {
|
|||
private Unit unit;
|
||||
private boolean colonyCenterTile;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new <code>ColonyTile</code>.
|
||||
*
|
||||
|
@ -221,7 +219,22 @@ public class ColonyTile extends FreeColGameObject implements WorkLocation {
|
|||
* Prepares this <code>ColonyTile</code> for a new turn.
|
||||
*/
|
||||
public void newTurn() {
|
||||
|
||||
if ((getUnit() == null) && !(isColonyCenterTile())) return; // Produce nothing if there's nobody to work the terrain.
|
||||
if (!(isColonyCenterTile())) {
|
||||
int amount = getUnit().getFarmedPotential(getUnit().getWorkType(), workTile);
|
||||
Goods g = new Goods(getGame(), null, getUnit().getWorkType(), amount);
|
||||
g.setLocation(colony);
|
||||
} else {
|
||||
int amount1 = workTile.potential(Goods.FOOD);
|
||||
Goods g = new Goods(getGame(), null, Goods.FOOD, amount1);
|
||||
g.setLocation(colony);
|
||||
int type2 = workTile.secondaryGoods();
|
||||
int amount2 = workTile.potential(type2);
|
||||
g = new Goods(getGame(), null, type2, amount2);
|
||||
g.setLocation(colony);
|
||||
}
|
||||
//colony.add(g);
|
||||
getGame().mustRestartNewTurn = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ abstract public class FreeColGameObject {
|
|||
private String id;
|
||||
private Game game;
|
||||
|
||||
|
||||
//UGLY HACK to fix iterator issue involving goods, colonies, and new turns.
|
||||
public boolean hasDoneNewTurn;
|
||||
|
||||
|
||||
|
||||
|
@ -38,6 +39,8 @@ abstract public class FreeColGameObject {
|
|||
*/
|
||||
public FreeColGameObject(Game game) {
|
||||
this.game = game;
|
||||
|
||||
hasDoneNewTurn = false;
|
||||
|
||||
if (game != null) {
|
||||
//game.setFreeColGameObject(id, this);
|
||||
|
|
|
@ -44,10 +44,11 @@ public class Game extends FreeColGameObject {
|
|||
|
||||
/** Indicates wether or not this object may give ID's */
|
||||
private boolean canGiveID;
|
||||
|
||||
/* The market for Europe. */
|
||||
private Market market;
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean mustRestartNewTurn;
|
||||
|
||||
/**
|
||||
* Creates a new game model.
|
||||
|
@ -55,6 +56,7 @@ public class Game extends FreeColGameObject {
|
|||
public Game() {
|
||||
super(null);
|
||||
|
||||
// market = new Market(this);
|
||||
currentPlayer = null;
|
||||
canGiveID = true;
|
||||
}
|
||||
|
@ -71,8 +73,20 @@ public class Game extends FreeColGameObject {
|
|||
readFromXMLElement(element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns this Game's Market.
|
||||
* @return This game's Market.
|
||||
*/
|
||||
public Market getMarket() {
|
||||
return market;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this game's Market.
|
||||
*/
|
||||
public void reinitialiseMarket() {
|
||||
market = new Market(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a unique ID to identify a <code>FreeColGameObject</code>.
|
||||
|
@ -396,9 +410,25 @@ public class Game extends FreeColGameObject {
|
|||
public void newTurn() {
|
||||
Iterator iterator = getFreeColGameObjectIterator();
|
||||
|
||||
mustRestartNewTurn = true;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
FreeColGameObject freeColGameObject = (FreeColGameObject) iterator.next();
|
||||
freeColGameObject.newTurn();
|
||||
freeColGameObject.hasDoneNewTurn = false;
|
||||
}
|
||||
|
||||
while (mustRestartNewTurn)
|
||||
{
|
||||
mustRestartNewTurn = false;
|
||||
iterator = getFreeColGameObjectIterator();
|
||||
while ((iterator.hasNext()) && (!mustRestartNewTurn)) {
|
||||
FreeColGameObject freeColGameObject = (FreeColGameObject) iterator.next();
|
||||
if (!freeColGameObject.hasDoneNewTurn)
|
||||
{
|
||||
freeColGameObject.hasDoneNewTurn = true;
|
||||
freeColGameObject.newTurn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,6 +454,10 @@ public class Game extends FreeColGameObject {
|
|||
gameElement.appendChild(p.toXMLElement(player, document));
|
||||
}
|
||||
|
||||
if (market != null) {
|
||||
gameElement.appendChild(market.toXMLElement(player, document));
|
||||
}
|
||||
|
||||
if (currentPlayer != null) {
|
||||
gameElement.setAttribute("currentPlayer", currentPlayer.getID());
|
||||
}
|
||||
|
@ -469,6 +503,17 @@ public class Game extends FreeColGameObject {
|
|||
}
|
||||
}
|
||||
|
||||
if (gameElement.hasAttribute("market")) {
|
||||
Element marketElement = (Element) gameElement.getElementsByTagName("market").item(0);
|
||||
if (market != null) {
|
||||
market.readFromXMLElement(marketElement);
|
||||
} else {
|
||||
market = new Market(this, marketElement);
|
||||
}
|
||||
} else {
|
||||
market = new Market(this);
|
||||
}
|
||||
|
||||
if (gameElement.hasAttribute("currentPlayer")) {
|
||||
currentPlayer = getPlayerByID(gameElement.getAttribute("currentPlayer"));
|
||||
} else {
|
||||
|
|
|
@ -77,13 +77,14 @@ public final class Goods extends FreeColGameObject implements Locatable {
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the location of the goods.
|
||||
* @param location The new location of the goods,
|
||||
*/
|
||||
public void setLocation(Location location) {
|
||||
this.location.remove(this);
|
||||
if ((this.location != null)) {
|
||||
this.location.remove(this);
|
||||
}
|
||||
|
||||
if (location != null) {
|
||||
location.add(this);
|
||||
|
@ -107,9 +108,32 @@ public final class Goods extends FreeColGameObject implements Locatable {
|
|||
* @return The amount.
|
||||
*/
|
||||
public int getTakeSpace() {
|
||||
return 1;
|
||||
return (((amount - 1) / 100) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value <code>amount</code>.
|
||||
* @return The current value of amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value <code>amount</code>.
|
||||
* @param a The new value for amount.
|
||||
*/
|
||||
public void setAmount(int a) {
|
||||
amount = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value <code>type</code>. Note that type of goods should NEVER change.
|
||||
* @return The current value of type.
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the <code>Goods</code> for a new turn.
|
||||
|
@ -117,7 +141,41 @@ public final class Goods extends FreeColGameObject implements Locatable {
|
|||
public void newTurn() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the cargo onto a carrier that is on the same tile.
|
||||
*
|
||||
* @param carrier The carrier this unit shall embark.
|
||||
* @exception IllegalStateException If the carrier is on another tile than this unit.
|
||||
*/
|
||||
public void Load(Unit carrier) {
|
||||
if ((getLocation() == null) || (getLocation().getTile() == carrier.getTile())) {
|
||||
setLocation(carrier);
|
||||
} else {
|
||||
throw new IllegalStateException("It is not allowed to board a ship on another tile.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unload the goods from the ship. This method should only be invoked if the ship is in a harbour.
|
||||
*
|
||||
* @exception IllegalStateException If not in harbour.
|
||||
* @exception ClassCastException If not located on a ship.
|
||||
*/
|
||||
public void Unload() {
|
||||
Location l = ((Unit) getLocation()).getLocation();
|
||||
|
||||
logger.warning("Unloading cargo from a ship.");
|
||||
if (l instanceof Europe) {
|
||||
//TODO: sell the goods. But for now...
|
||||
setLocation(l);
|
||||
} else if (l.getTile().getSettlement() != null && l.getTile().getSettlement() instanceof Colony) {
|
||||
setLocation(l.getTile().getSettlement());
|
||||
} else {
|
||||
throw new IllegalStateException("Goods may only leave a ship while in a harbour.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all references to this object.
|
||||
|
|
|
@ -350,7 +350,22 @@ public final class Tile extends FreeColGameObject implements Location {
|
|||
forested = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether the tile is plowed or not.
|
||||
* @param Value new value for forested
|
||||
*/
|
||||
public void setPlowed(boolean value) {
|
||||
plowed = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the tile has a road or not.
|
||||
* @param Value new value for forested
|
||||
*/
|
||||
public void setRoad(boolean value) {
|
||||
road = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the tile has a bonus or not.
|
||||
* @param Value new value for bonus
|
||||
|
@ -563,8 +578,68 @@ public final class Tile extends FreeColGameObject implements Location {
|
|||
public boolean canAdd(Locatable locatable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The potential of this tile to produce a certain type of goods.
|
||||
*
|
||||
* @param goods The type of goods to check the potential for.
|
||||
* @return The normal potential of this tile to produce that amount of goods.
|
||||
*/
|
||||
public int potential (int goods)
|
||||
{
|
||||
// Please someone tell me they want to put this data into a separate file... -sjm
|
||||
// Twelve tile types, sixteen goods types, and forested/unforested.
|
||||
int potentialtable[][][] =
|
||||
{
|
||||
// Food Sugar Tobac Cotton Furs Wood Ore Silver Horses Rum Cigars Cloth Coats T.G. Tools Musket
|
||||
{{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Unexp
|
||||
{{5,3}, {0,0}, {0,0}, {2,1}, {0,3}, {0,6}, {1,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Plains
|
||||
{{3,2}, {0,0}, {3,1}, {0,0}, {0,2}, {0,4}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Grasslands
|
||||
{{3,2}, {0,0}, {0,0}, {3,1}, {0,2}, {0,6}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Prairie
|
||||
{{4,3}, {3,1}, {0,0}, {0,0}, {0,2}, {0,4}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Savannah
|
||||
{{3,2}, {0,0}, {0,0}, {0,0}, {0,2}, {0,4}, {2,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Marsh
|
||||
{{3,2}, {2,1}, {2,1}, {0,0}, {0,1}, {0,4}, {2,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Swamp
|
||||
{{2,2}, {0,0}, {0,0}, {1,1}, {0,2}, {0,2}, {2,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Desert
|
||||
{{3,2}, {0,0}, {0,0}, {0,0}, {0,3}, {0,4}, {2,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Tundra
|
||||
{{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Arctic
|
||||
{{4,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}}, // Ocean
|
||||
{{4,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}} // High seas
|
||||
};
|
||||
|
||||
int basepotential = potentialtable[type][goods][(forested ? 1 : 0)];
|
||||
if (basepotential > 0) {
|
||||
if (plowed) basepotential++;
|
||||
if (road) basepotential++;
|
||||
}
|
||||
|
||||
return basepotential;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The type of secondary good this tile produces best (used for Town Commons squares).
|
||||
* @returns The type of secondary good best produced by this tile.
|
||||
*/
|
||||
public int secondaryGoods()
|
||||
{
|
||||
if (isForested()) return Goods.FURS;
|
||||
switch(getType()) {
|
||||
case PLAINS:
|
||||
case PRAIRIE:
|
||||
return Goods.COTTON;
|
||||
case GRASSLANDS:
|
||||
return Goods.TOBACCO;
|
||||
case SAVANNAH:
|
||||
return Goods.SUGAR;
|
||||
case MARSH:
|
||||
case SWAMP:
|
||||
case DESERT:
|
||||
case TUNDRA:
|
||||
case ARCTIC:
|
||||
default:
|
||||
return Goods.ORE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares this <code>Tile</code> for a new turn.
|
||||
*/
|
||||
|
@ -610,8 +685,7 @@ public final class Tile extends FreeColGameObject implements Location {
|
|||
|
||||
return tileElement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialize this object from an XML-representation of this object.
|
||||
*
|
||||
|
|
|
@ -104,10 +104,11 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
private int numberOfTools;
|
||||
private Player owner;
|
||||
private UnitContainer unitContainer;
|
||||
private GoodsContainer goodsContainer;
|
||||
private Location entryLocation;
|
||||
private Location location;
|
||||
|
||||
|
||||
private int workType; // What type of goods this unit produces in its occupation.
|
||||
|
||||
/**
|
||||
* Initiate a new <code>Unit</code> of a specified type with the state set
|
||||
|
@ -139,6 +140,7 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
super(game);
|
||||
|
||||
unitContainer = new UnitContainer(game, this);
|
||||
goodsContainer = new GoodsContainer(game, this);
|
||||
|
||||
setLocation(location);
|
||||
|
||||
|
@ -153,6 +155,7 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
|
||||
state = s;
|
||||
workLeft = -1;
|
||||
workType = Goods.FOOD;
|
||||
|
||||
if (type == VETERAN_SOLDIER) {
|
||||
armed = true;
|
||||
|
@ -277,6 +280,26 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
return getMoveType(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of goods this unit is producing in its current occupation.
|
||||
* @return The type of goods this unit would produce.
|
||||
*/
|
||||
public int getWorkType() {
|
||||
if (getLocation() instanceof Building) {
|
||||
// TODO: code me.
|
||||
return 0;
|
||||
} else {
|
||||
return workType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of goods this unit is producing in its current occupation.
|
||||
* @param type The type of goods to attempt to produce.
|
||||
*/
|
||||
public void setWorkType(int type) {
|
||||
workType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of a move that is made when moving to the
|
||||
|
@ -503,8 +526,7 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
if (locatable instanceof Unit) {
|
||||
unitContainer.addUnit((Unit) locatable);
|
||||
} else if (locatable instanceof Goods) {
|
||||
// TODO: Implement:
|
||||
logger.warning("Tried to use unimplemeneted feature in 'Unit': add(goods)");
|
||||
goodsContainer.addGoods((Goods) locatable);
|
||||
} else {
|
||||
logger.warning("Tried to add an unrecognized 'Locatable' to a unit.");
|
||||
}
|
||||
|
@ -523,8 +545,7 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
if (locatable instanceof Unit) {
|
||||
unitContainer.removeUnit((Unit) locatable);
|
||||
} else if (locatable instanceof Goods) {
|
||||
// TODO: Implement:
|
||||
logger.warning("Tried to use unimplemeneted feature in 'Unit': remove(goods)");
|
||||
goodsContainer.removeGoods((Goods) locatable);
|
||||
} else {
|
||||
logger.warning("Tried to remove an unrecognized 'Locatable' from a unit.");
|
||||
}
|
||||
|
@ -550,6 +571,8 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
if (isCarrier()) {
|
||||
if (locatable instanceof Unit) {
|
||||
return unitContainer.contains((Unit) locatable);
|
||||
} else if (locatable instanceof Goods) {
|
||||
return goodsContainer.contains((Goods) locatable);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -588,6 +611,23 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the storage room of all Goods at this location.
|
||||
* @return The total storage room of all Goods at this location.
|
||||
*/
|
||||
public int getGoodsSpace() {
|
||||
if (isCarrier()) {
|
||||
int space = 0;
|
||||
Iterator goodsIterator = goodsContainer.getGoodsIterator();
|
||||
while (goodsIterator.hasNext()) {
|
||||
space += ((Goods) goodsIterator.next()).getTakeSpace();
|
||||
}
|
||||
return space;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -630,7 +670,20 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a <code>Iterator</code> of every <code>Unit</code> directly located on this
|
||||
* <code>Location</code>.
|
||||
*
|
||||
* @return The <code>Iterator</code>.
|
||||
*/
|
||||
public Iterator getGoodsIterator() {
|
||||
if (isCarrier()) {
|
||||
return goodsContainer.getGoodsIterator();
|
||||
} else { // TODO: Make a better solution:
|
||||
return (new ArrayList()).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this <code>Unit</code> to work in the
|
||||
* specified <code>WorkLocation</code>.
|
||||
|
@ -1094,6 +1147,21 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
case FORTIFY:
|
||||
workLeft = -1;
|
||||
break;
|
||||
case BUILD_ROAD:
|
||||
case PLOW:
|
||||
switch(getTile().getType()) {
|
||||
case Tile.DESERT:
|
||||
case Tile.PLAINS:
|
||||
case Tile.PRAIRIE:
|
||||
case Tile.GRASSLANDS:
|
||||
case Tile.SAVANNAH: workLeft = ((getTile().isForested()) ? 4 : 3); break;
|
||||
case Tile.MARSH: workLeft = ((getTile().isForested()) ? 6 : 5); break;
|
||||
case Tile.SWAMP: workLeft = 7; break;
|
||||
case Tile.ARCTIC:
|
||||
case Tile.TUNDRA: workLeft = 4; break;
|
||||
default: workLeft = -1; break;
|
||||
}
|
||||
if (s == BUILD_ROAD) workLeft /= 2;
|
||||
case TO_EUROPE:
|
||||
if ((state == ACTIVE) && (!(location instanceof Europe))) {
|
||||
workLeft = 3;
|
||||
|
@ -1146,7 +1214,8 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
}
|
||||
|
||||
// Do the HARD work of moving this unit to europe:
|
||||
setEntryLocation(getLocation());
|
||||
if (!(getLocation() instanceof Europe)) // Perpetual europedom bug fixed.. -sjm
|
||||
setEntryLocation(getLocation());
|
||||
setState(TO_EUROPE);
|
||||
setLocation(getOwner().getEurope());
|
||||
}
|
||||
|
@ -1177,9 +1246,12 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
switch (s) {
|
||||
case ACTIVE:
|
||||
return true;
|
||||
case IN_COLONY:
|
||||
case PLOW:
|
||||
if (!((getTile().isForested()) || !(getTile().isPlowed()))) return false;
|
||||
case BUILD_ROAD:
|
||||
if ((s == BUILD_ROAD) && (getTile().hasRoad())) return false;
|
||||
if (getNumberOfTools() < 20) return false;
|
||||
case IN_COLONY:
|
||||
if (isNaval()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1266,7 +1338,7 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
* @return The amount of units/goods than can be moved onto this Unit.
|
||||
*/
|
||||
public int getSpaceLeft() {
|
||||
return getInitialSpaceLeft() - getUnitCount();
|
||||
return getInitialSpaceLeft() - (getUnitCount() + getGoodsSpace());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1334,6 +1406,15 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
switch (state) {
|
||||
case TO_EUROPE: break;
|
||||
case TO_AMERICA: setLocation(getEntryLocation()); break;
|
||||
case BUILD_ROAD: getTile().setRoad(true); numberOfTools -= 20; break;
|
||||
case PLOW:
|
||||
if (getTile().isForested()) {
|
||||
getTile().setForested(false);
|
||||
} else {
|
||||
getTile().setPlowed(true);
|
||||
}
|
||||
numberOfTools -= 20;
|
||||
break;
|
||||
default: logger.warning("Unkown work completed. State: " + state);
|
||||
}
|
||||
|
||||
|
@ -1538,14 +1619,123 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
return (Colony) location;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a type of goods to produce in a building, returns the unit's potential to do so.
|
||||
* @param goods The type of goods to be produced.
|
||||
* @return The potential amount of goods to be manufactured.
|
||||
*/
|
||||
public int getProducedAmount(int goods)
|
||||
{
|
||||
switch (type) {
|
||||
case MASTER_DISTILLER:
|
||||
if (goods == Goods.RUM) return 6;
|
||||
return 3;
|
||||
case MASTER_WEAVER:
|
||||
if (goods == Goods.CLOTH) return 6;
|
||||
return 3;
|
||||
case MASTER_TOBACCONIST:
|
||||
if (goods == Goods.CIGARS) return 6;
|
||||
return 3;
|
||||
case MASTER_FUR_TRADER:
|
||||
if (goods == Goods.COATS) return 6;
|
||||
return 3;
|
||||
case MASTER_BLACKSMITH:
|
||||
if (goods == Goods.TOOLS) return 6;
|
||||
return 3;
|
||||
case MASTER_GUNSMITH:
|
||||
if (goods == Goods.MUSKETS) return 6;
|
||||
return 3;
|
||||
case INDENTURED_SERVANT:
|
||||
return 2;
|
||||
case PETTY_CRIMINAL:
|
||||
case INDIAN_CONVERT:
|
||||
return 1;
|
||||
default: // Beats me who or what is working here, but he doesn't get a bonus.
|
||||
if (isColonist())
|
||||
return 3;
|
||||
else
|
||||
return 0; // Can't work if you're not a colonist.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a type of goods to produce in the field and a tile, returns the unit's potential to produce goods.
|
||||
* @param goods The type of goods to be produced.
|
||||
* @param tile The tile which is being worked.
|
||||
* @return The potential amount of goods to be farmed.
|
||||
*/
|
||||
public int getFarmedPotential(int goods, Tile tile)
|
||||
{
|
||||
int base = tile.potential(goods);
|
||||
switch (type) {
|
||||
case EXPERT_FARMER:
|
||||
if ((goods == Goods.FOOD) && ((tile.getType() != Tile.OCEAN) && (tile.getType() != Tile.HIGH_SEAS))) {
|
||||
//TODO: Special tile stuff. He gets +6/+4 for wheat/deer tiles respectively...
|
||||
base += 2;
|
||||
}
|
||||
break;
|
||||
case EXPERT_FISHERMAN:
|
||||
if ((goods == Goods.FOOD) && ((tile.getType() == Tile.OCEAN) || (tile.getType() == Tile.HIGH_SEAS))) {
|
||||
//TODO: Special tile stuff. He gets +6 for a fishery tile.
|
||||
base += 2;
|
||||
}
|
||||
break;
|
||||
case EXPERT_FUR_TRAPPER:
|
||||
if (goods == Goods.FURS) {
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case EXPERT_SILVER_MINER:
|
||||
if (goods == Goods.SILVER) {
|
||||
//TODO: Mountain should be +1, not *2, but mountain didn't exist at type of writing.
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case EXPERT_LUMBER_JACK:
|
||||
if (goods == Goods.LUMBER) {
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case EXPERT_ORE_MINER:
|
||||
if (goods == Goods.ORE) {
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case MASTER_SUGAR_PLANTER:
|
||||
if (goods == Goods.SUGAR) {
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case MASTER_COTTON_PLANTER:
|
||||
if (goods == Goods.COTTON) {
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case MASTER_TOBACCO_PLANTER:
|
||||
if (goods == Goods.TOBACCO) {
|
||||
base *= 2;
|
||||
}
|
||||
break;
|
||||
case INDIAN_CONVERT:
|
||||
if ((goods == Goods.FOOD) || (goods == Goods.SUGAR) || (goods == Goods.COTTON) || (goods == Goods.TOBACCO) || (goods == Goods.FURS)) {
|
||||
base += 1;
|
||||
}
|
||||
break;
|
||||
default: // Beats me who or what is working here, but he doesn't get a bonus.
|
||||
break;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all references to this object.
|
||||
*/
|
||||
public void dispose() {
|
||||
if (isCarrier()) {
|
||||
unitContainer.dispose();
|
||||
goodsContainer.dispose();
|
||||
}
|
||||
|
||||
if (location != null) {
|
||||
|
@ -1597,10 +1787,14 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
if (isCarrier()) {
|
||||
if (getOwner().equals(player)) {
|
||||
unitElement.appendChild(unitContainer.toXMLElement(player, document));
|
||||
unitElement.appendChild(goodsContainer.toXMLElement(player, document));
|
||||
} else {
|
||||
UnitContainer emptyUnitContainer = new UnitContainer(getGame(), this);
|
||||
emptyUnitContainer.setID(unitContainer.getID());
|
||||
unitElement.appendChild(emptyUnitContainer.toXMLElement(player, document));
|
||||
GoodsContainer emptyGoodsContainer = new GoodsContainer(getGame(), this);
|
||||
emptyGoodsContainer.setID(unitContainer.getID());
|
||||
unitElement.appendChild(emptyGoodsContainer.toXMLElement(player, document));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1641,6 +1835,12 @@ public final class Unit extends FreeColGameObject implements Location, Locatable
|
|||
} else {
|
||||
unitContainer = new UnitContainer(getGame(), this, unitContainerElement);
|
||||
}
|
||||
Element goodsContainerElement = (Element) unitElement.getElementsByTagName(GoodsContainer.getXMLElementTagName()).item(0);
|
||||
if (goodsContainer != null) {
|
||||
goodsContainer.readFromXMLElement(goodsContainerElement);
|
||||
} else {
|
||||
goodsContainer = new GoodsContainer(getGame(), this, goodsContainerElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,9 @@ public final class Message {
|
|||
}
|
||||
x.printStackTrace();
|
||||
System.out.println();
|
||||
System.out.println("The bad message is as follows:");
|
||||
System.out.println(msg);
|
||||
System.out.println("--END--");
|
||||
} catch (ParserConfigurationException pce) {
|
||||
// Parser with specified options can't be built
|
||||
pce.printStackTrace();
|
||||
|
@ -140,7 +142,11 @@ public final class Message {
|
|||
* @return The type of this Message.
|
||||
*/
|
||||
public String getType() {
|
||||
return document.getDocumentElement().getTagName();
|
||||
if (document != null)
|
||||
if (document.getDocumentElement() != null)
|
||||
return document.getDocumentElement().getTagName();
|
||||
|
||||
return new String("invalid");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -144,7 +144,11 @@ final class ReceivingThread extends Thread {
|
|||
}
|
||||
|
||||
// START DEBUG-LINES:
|
||||
System.out.println(msg);
|
||||
if (msg.getType().equals("invalid")) {
|
||||
System.out.println("--INVALID MESSAGE RECIEVED--");
|
||||
} else {
|
||||
System.out.println(msg);
|
||||
}
|
||||
System.out.println();
|
||||
System.out.flush();
|
||||
// END DEBUB
|
||||
|
@ -167,7 +171,7 @@ final class ReceivingThread extends Thread {
|
|||
logger.warning("Could not find networkReplyId=" + msg.getAttribute("networkReplyId"));
|
||||
}
|
||||
|
||||
} else { // == this is not a reply-message:
|
||||
} else if (!msg.getType().equals("invalid")) { // == this is not a reply-message:
|
||||
connection.handleAndSendReply(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,14 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
reply = boardShip(connection, element);
|
||||
} else if (type.equals("leaveShip")) {
|
||||
reply = leaveShip(connection, element);
|
||||
} else if (type.equals("loadCargo")) {
|
||||
reply = loadCargo(connection, element);
|
||||
} else if (type.equals("unloadCargo")) {
|
||||
reply = unloadCargo(connection, element);
|
||||
} else if (type.equals("buyGoods")) {
|
||||
reply = buyGoods(connection, element);
|
||||
} else if (type.equals("sellGoods")) {
|
||||
reply = sellGoods(connection, element);
|
||||
} else if (type.equals("moveToEurope")) {
|
||||
reply = moveToEurope(connection, element);
|
||||
} else if (type.equals("moveToAmerica")) {
|
||||
|
@ -79,6 +87,8 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
reply = trainUnitInEurope(connection, element);
|
||||
} else if (type.equals("work")) {
|
||||
reply = work(connection, element);
|
||||
} else if (type.equals("worktype")) {
|
||||
reply = workType(connection, element);
|
||||
} else if (type.equals("putOutsideColony")) {
|
||||
reply = putOutsideColony(connection, element);
|
||||
} else if (type.equals("endTurn")) {
|
||||
|
@ -226,6 +236,11 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
Unit carrier = (Unit) game.getFreeColGameObject(boardShipElement.getAttribute("carrier"));
|
||||
|
||||
Tile oldTile = unit.getTile();
|
||||
|
||||
if (unit.isCarrier()) {
|
||||
logger.warning("Tried to load a carrier onto another carrier.");
|
||||
return null;
|
||||
}
|
||||
|
||||
unit.boardShip(carrier);
|
||||
|
||||
|
@ -276,7 +291,121 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a "loadCargo"-message from a client.
|
||||
*
|
||||
* @param connection The connection the message came from.
|
||||
* @param loadCargoElement The element containing the request.
|
||||
*/
|
||||
private Element loadCargo(Connection connection, Element loadCargoElement) {
|
||||
Game game = freeColServer.getGame();
|
||||
ServerPlayer player = freeColServer.getPlayer(connection);
|
||||
|
||||
Goods goods = (Goods) game.getFreeColGameObject(loadCargoElement.getAttribute("goods"));
|
||||
Unit carrier = (Unit) game.getFreeColGameObject(loadCargoElement.getAttribute("carrier"));
|
||||
|
||||
|
||||
Tile oldTile;
|
||||
if (goods.getLocation() != null) {
|
||||
oldTile = goods.getLocation().getTile();
|
||||
} else {
|
||||
oldTile = null;
|
||||
}
|
||||
|
||||
goods.Load(carrier);
|
||||
|
||||
Iterator enemyPlayerIterator = game.getPlayerIterator();
|
||||
while (enemyPlayerIterator.hasNext()) {
|
||||
ServerPlayer enemyPlayer = (ServerPlayer) enemyPlayerIterator.next();
|
||||
|
||||
if (player.equals(enemyPlayer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
if (enemyPlayer.canSee(oldTile)) {
|
||||
Element removeElement = Message.createNewRootElement("remove");
|
||||
|
||||
Element removeGoods = removeElement.getOwnerDocument().createElement("removeObject");
|
||||
removeGoods.setAttribute("ID", goods.getID());
|
||||
removeElement.appendChild(removeGoods);
|
||||
|
||||
enemyPlayer.getConnection().send(removeElement);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warning("Could not send message to: " + enemyPlayer.getName() + " with connection " + enemyPlayer.getConnection());
|
||||
}
|
||||
}
|
||||
|
||||
if (oldTile != null) {
|
||||
sendUpdatedTileToAll(oldTile, player);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles an "unloadCargo"-message from a client.
|
||||
*
|
||||
* @param connection The connection the message came from.
|
||||
* @param unloadCargoElement The element containing the request.
|
||||
*/
|
||||
private Element unloadCargo(Connection connection, Element unloadCargoElement) {
|
||||
Game game = freeColServer.getGame();
|
||||
ServerPlayer player = freeColServer.getPlayer(connection);
|
||||
|
||||
Goods goods = (Goods) game.getFreeColGameObject(unloadCargoElement.getAttribute("goods"));
|
||||
|
||||
goods.Unload();
|
||||
Tile newTile = goods.getLocation().getTile();
|
||||
|
||||
sendUpdatedTileToAll(newTile, player);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a "buyGoods"-message from a client.
|
||||
*
|
||||
* @param connection The connection the message came from.
|
||||
* @param boardShipElement The element containing the request.
|
||||
*/
|
||||
private Element buyGoods(Connection connection, Element buyGoodsElement) {
|
||||
Game game = freeColServer.getGame();
|
||||
ServerPlayer player = freeColServer.getPlayer(connection);
|
||||
|
||||
int type = Integer.parseInt(buyGoodsElement.getAttribute("type"));
|
||||
Unit carrier = (Unit) game.getFreeColGameObject(buyGoodsElement.getAttribute("carrier"));
|
||||
Player theplayer = (Player) game.getFreeColGameObject(buyGoodsElement.getAttribute("player"));
|
||||
|
||||
if (theplayer.getGold() >= (game.getMarket().costToBuy(type) * 100)) {
|
||||
(game.getMarket().buy(type, 100, theplayer)).setLocation(carrier);
|
||||
} else {
|
||||
logger.warning("A client is buying goods, but does not have enough money to do so???");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles a "sellGoods"-message from a client.
|
||||
*
|
||||
* @param connection The connection the message came from.
|
||||
* @param leaveShipElement The element containing the request.
|
||||
*/
|
||||
private Element sellGoods(Connection connection, Element sellGoodsElement) {
|
||||
Game game = freeColServer.getGame();
|
||||
ServerPlayer player = freeColServer.getPlayer(connection);
|
||||
|
||||
Goods goods = (Goods) game.getFreeColGameObject(sellGoodsElement.getAttribute("goods"));
|
||||
Player theplayer = (Player) game.getFreeColGameObject(sellGoodsElement.getAttribute("player"));
|
||||
|
||||
game.getMarket().sell(goods, theplayer);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a "moveToEurope"-message from a client.
|
||||
*
|
||||
|
@ -291,29 +420,6 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
|
||||
Tile oldTile = unit.getTile();
|
||||
unit.moveToEurope();
|
||||
|
||||
Iterator enemyPlayerIterator = game.getPlayerIterator();
|
||||
while (enemyPlayerIterator.hasNext()) {
|
||||
ServerPlayer enemyPlayer = (ServerPlayer) enemyPlayerIterator.next();
|
||||
|
||||
if (player.equals(enemyPlayer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
if (enemyPlayer.canSee(oldTile)) {
|
||||
Element removeElement = Message.createNewRootElement("remove");
|
||||
|
||||
Element removeUnit = removeElement.getOwnerDocument().createElement("removeObject");
|
||||
removeUnit.setAttribute("ID", unit.getID());
|
||||
removeElement.appendChild(removeUnit);
|
||||
|
||||
enemyPlayer.getConnection().send(removeElement);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warning("Could not send message to: " + enemyPlayer.getName() + " with connection " + enemyPlayer.getConnection());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -439,6 +545,23 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a "worktype"-request from a client.
|
||||
*
|
||||
* @param connection The connection the message came from.
|
||||
* @param workElement The element containing the request.
|
||||
*/
|
||||
private Element workType(Connection connection, Element workElement) {
|
||||
Game game = freeColServer.getGame();
|
||||
|
||||
Unit unit = (Unit) game.getFreeColGameObject(workElement.getAttribute("unit"));
|
||||
int workType = Integer.parseInt(workElement.getAttribute("worktype"));
|
||||
|
||||
unit.setWorkType(workType);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles a "putOutsideColony"-request from a client.
|
||||
|
|
|
@ -103,6 +103,8 @@ public final class PreGameController {
|
|||
|
||||
game.setMap(map);
|
||||
|
||||
game.reinitialiseMarket(); // Do this here because game is restarting. -sjm
|
||||
|
||||
Iterator playerIterator = game.getPlayerIterator();
|
||||
while (playerIterator.hasNext()) {
|
||||
ServerPlayer player = (ServerPlayer) playerIterator.next();
|
||||
|
|
|
@ -155,26 +155,61 @@ public class MapGenerator {
|
|||
|
||||
protected class TerrainGenerator {
|
||||
|
||||
private static final int DISTANCE_TO_LAND_FROM_HIGH_SEAS = 6;
|
||||
private static final int DISTANCE_TO_LAND_FROM_HIGH_SEAS = 4;
|
||||
private static final int MAX_DISTANCE_TO_EDGE = 12;
|
||||
|
||||
private boolean[][] landMap;
|
||||
|
||||
private Random tileType;
|
||||
|
||||
|
||||
TerrainGenerator(boolean[][] landMap) {
|
||||
this.landMap = landMap;
|
||||
}
|
||||
|
||||
private int getRandomTileType(int percent) {
|
||||
// Do by percent +- 10.
|
||||
int min = (percent - 10);
|
||||
int max = (percent + 10);
|
||||
if (min < 0) min = 0;
|
||||
if (max > 99) max = 99;
|
||||
int thisValue = tileType.nextInt(max - min) + min;
|
||||
thisValue /= 10; // Gives a number from 0-3.
|
||||
int minWoD = 0;
|
||||
int maxWoD = 99;
|
||||
int dryOrWet = tileType.nextInt(maxWoD - minWoD) + minWoD;
|
||||
dryOrWet /= 33;
|
||||
switch(thisValue) {
|
||||
case 0: return Tile.ARCTIC;
|
||||
case 1: case 2: switch (dryOrWet) {
|
||||
case 0: return Tile.TUNDRA;
|
||||
case 1: default: return Tile.TUNDRA;
|
||||
case 2: return Tile.MARSH;
|
||||
}
|
||||
case 3: case 4: case 5: case 6: default: switch (dryOrWet) {
|
||||
case 0: return Tile.PLAINS;
|
||||
case 1: default: return Tile.PRAIRIE;
|
||||
case 2: return Tile.SWAMP;
|
||||
}
|
||||
case 7: case 8: case 9: switch (dryOrWet) {
|
||||
case 0: return Tile.GRASSLANDS;
|
||||
case 1: default: return Tile.SAVANNAH;
|
||||
case 2: return Tile.DESERT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map createMap() {
|
||||
Vector columns = new Vector(width);
|
||||
tileType = new Random();
|
||||
for (int i = 0; i < width; i++) {
|
||||
Vector v = new Vector(height);
|
||||
for (int j = 0; j < height; j++) {
|
||||
Tile t;
|
||||
|
||||
if (landMap[i][j]) {
|
||||
t = new Tile(game, Tile.GRASSLANDS, i, j);
|
||||
t = new Tile(game, getRandomTileType(((Math.min(j, height - j) * 100) / height)), i, j);
|
||||
if ((t.getType() != t.ARCTIC) && (tileType.nextInt(3) > 0)) t.setForested(true);
|
||||
} else {
|
||||
t = new Tile(game, Tile.OCEAN, i, j);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue