mirror of https://github.com/FreeCol/freecol.git
Bugfixes.
This commit is contained in:
parent
8776a617ae
commit
efd946350b
|
@ -43,6 +43,7 @@ import java.io.IOException;
|
|||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public final class FreeColClient {
|
|||
|
||||
|
||||
/**
|
||||
* Creates a new <code>FreeColClient</code>. Creates the control
|
||||
* Creates a new <code>FreeColClient</code>. Creates the control
|
||||
* objects and starts the GUI.
|
||||
*/
|
||||
public FreeColClient(boolean windowed, ImageLibrary imageLibrary, MusicLibrary musicLibrary, SfxLibrary sfxLibrary) {
|
||||
|
@ -97,6 +97,7 @@ public final class FreeColClient {
|
|||
|
||||
// Gui:
|
||||
startGUI(windowed, imageLibrary, musicLibrary, sfxLibrary);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,8 +108,6 @@ public final class FreeColClient {
|
|||
* Starts the GUI by creating and displaying the GUI-objects.
|
||||
*/
|
||||
private void startGUI(boolean windowed, ImageLibrary lib, MusicLibrary musicLibrary, SfxLibrary sfxLibrary) {
|
||||
// TODO: Show splash-screen
|
||||
|
||||
if (musicLibrary != null) {
|
||||
musicPlayer = new SoundPlayer(false, true, true);
|
||||
} else {
|
||||
|
@ -127,11 +126,12 @@ public final class FreeColClient {
|
|||
if (GraphicsEnvironment.isHeadless()) {
|
||||
logger.info("It seems that the GraphicsEnvironment is headless!");
|
||||
}
|
||||
|
||||
|
||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||
|
||||
if (windowed) {
|
||||
frame = new WindowedFrame();
|
||||
} else {
|
||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||
if (!gd.isFullScreenSupported()) {
|
||||
logger.warning("It seems that full screen mode is not supported for this GraphicsDevice! Using windowed mode instead.");
|
||||
|
||||
|
@ -154,11 +154,11 @@ public final class FreeColClient {
|
|||
|
||||
frame.getContentPane().add(canvas);
|
||||
|
||||
if (!windowed) {
|
||||
frame.repaint();
|
||||
}
|
||||
|
||||
frame.setVisible(true);
|
||||
|
||||
if (!windowed) {
|
||||
((FullScreenFrame) frame).display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ public final class InGameController {
|
|||
|
||||
unit.move(direction);
|
||||
|
||||
if (unit.getTile().getSettlement() != null) {
|
||||
if (unit.getTile().getSettlement() != null && unit.isCarrier()) {
|
||||
canvas.showColonyPanel((Colony) unit.getTile().getSettlement());
|
||||
} else if (unit.getMovesLeft() > 0) {
|
||||
gui.setActiveUnit(unit);
|
||||
|
@ -482,10 +482,15 @@ public final class InGameController {
|
|||
|
||||
if (unit.getLocation() instanceof ColonyTile || unit.getLocation() instanceof Building) {
|
||||
if (!putOutsideColony(unit)) {
|
||||
unit.setMissionary(false);
|
||||
unit.setArmed(false);
|
||||
unit.setMounted(false);
|
||||
unit.setNumberOfTools(0);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (carrier != null) {
|
||||
boardShip(unit, carrier);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.w3c.dom.Element;
|
|||
import java.util.logging.Logger;
|
||||
import java.util.Iterator;
|
||||
import java.awt.Color;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
|
||||
|
||||
|
@ -120,6 +121,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
|
||||
// TODO: Refresh only the updated tiles:
|
||||
freeColClient.getCanvas().refresh();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -144,8 +146,8 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
logger.warning("Could not find 'FreeColGameObject' with ID: " + element.getAttribute("ID"));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Refresh only the updated tiles:
|
||||
|
||||
// TODO: Refresh only the updated tiles:
|
||||
freeColClient.getCanvas().refresh();
|
||||
return null;
|
||||
}
|
||||
|
@ -160,14 +162,14 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
private Element opponentMove(Element opponentMoveElement) {
|
||||
Game game = freeColClient.getGame();
|
||||
Map map = game.getMap();
|
||||
|
||||
|
||||
Player currentPlayer = freeColClient.getMyPlayer();
|
||||
|
||||
int direction = Integer.parseInt(opponentMoveElement.getAttribute("direction"));
|
||||
|
||||
if (!opponentMoveElement.hasAttribute("tile")) {
|
||||
Unit unit = (Unit) game.getFreeColGameObject(opponentMoveElement.getAttribute("unit"));
|
||||
|
||||
|
||||
if (unit == null) {
|
||||
//throw new NullPointerException();
|
||||
logger.warning("Could not find the 'unit' in 'opponentMove'.");
|
||||
|
@ -184,7 +186,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
|
||||
NodeList nl = opponentMoveElement.getElementsByTagName(Unit.getXMLElementTagName());
|
||||
Unit unit = new Unit(game, (Element) nl.item(0));
|
||||
|
||||
|
||||
if (game.getFreeColGameObject(tileID) == null) {
|
||||
logger.warning("Could not find tile with id: " + tileID);
|
||||
}
|
||||
|
@ -193,7 +195,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles an "opponentAttack"-message.
|
||||
|
@ -211,19 +213,19 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
Unit unit = (Unit) game.getFreeColGameObject(opponentAttackElement.getAttribute("unit"));
|
||||
Unit defender = map.getNeighbourOrNull(direction, unit.getTile()).getDefendingUnit(unit);
|
||||
Player player = unit.getOwner();
|
||||
|
||||
|
||||
if (result == Unit.ATTACKER_LOSS) {
|
||||
unit.loseAttack();
|
||||
} else {
|
||||
unit.winAttack(defender);
|
||||
}
|
||||
|
||||
|
||||
freeColClient.getCanvas().refresh();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles a "setCurrentPlayer"-message.
|
||||
*
|
||||
|
@ -250,7 +252,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void removeUnitsOutsideLOS() {
|
||||
Player player = freeColClient.getMyPlayer();
|
||||
Map map = freeColClient.getGame().getMap();
|
||||
|
@ -288,7 +290,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
*/
|
||||
private Element newTurn(Element newTurnElement) {
|
||||
freeColClient.getGame().newTurn();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -303,7 +305,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
Game game = freeColClient.getGame();
|
||||
Player player = (Player) game.getFreeColGameObject(element.getAttribute("player"));
|
||||
player.setDead(true);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -316,7 +318,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
*/
|
||||
private Element createUnit(Element element) {
|
||||
Game game = freeColClient.getGame();
|
||||
|
||||
|
||||
Location location = (Location) game.getFreeColGameObject(element.getAttribute("location"));
|
||||
Unit unit = new Unit(game, (Element) element.getChildNodes().item(0));
|
||||
|
||||
|
@ -324,10 +326,10 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
// in order to make it possible to produce units
|
||||
// other places than the colonies.
|
||||
((Colony) location).createUnit(unit);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles an "error"-message.
|
||||
|
|
|
@ -21,9 +21,9 @@ public final class FullScreenFrame extends JFrame {
|
|||
private final BufferStrategy bufferStrategy;
|
||||
private Canvas canvas;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The constructor to use.
|
||||
|
@ -31,12 +31,13 @@ public final class FullScreenFrame extends JFrame {
|
|||
public FullScreenFrame(GraphicsDevice gd) {
|
||||
super(gd.getDefaultConfiguration());
|
||||
logger.info("FullScreenFrame's JFrame created.");
|
||||
|
||||
|
||||
setUndecorated(true);
|
||||
//setIgnoreRepaint(true);
|
||||
|
||||
gd.setFullScreenWindow(this);
|
||||
logger.info("Switched to full screen mode.");
|
||||
|
||||
createBufferStrategy(2);
|
||||
bufferStrategy = getBufferStrategy();
|
||||
|
||||
|
@ -46,8 +47,8 @@ public final class FullScreenFrame extends JFrame {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setCanvas(Canvas canvas) {
|
||||
this.canvas = canvas;
|
||||
|
@ -61,20 +62,20 @@ public final class FullScreenFrame extends JFrame {
|
|||
public void display() {
|
||||
if (bufferStrategy != null) {
|
||||
Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
|
||||
|
||||
|
||||
if (!bufferStrategy.contentsLost()) {
|
||||
super.paint(g);
|
||||
/*if (canvas != null) {
|
||||
canvas.paintComponent(g);
|
||||
}*/
|
||||
|
||||
|
||||
bufferStrategy.show();
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draws this frame on the screen. Should never be called manually. It will be
|
||||
* called by Swing whenever needed.
|
||||
|
@ -83,7 +84,7 @@ public final class FullScreenFrame extends JFrame {
|
|||
public void paint(Graphics g) {
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds a component to this FullScreenFrame.
|
||||
|
@ -92,4 +93,5 @@ public final class FullScreenFrame extends JFrame {
|
|||
public void addComponent(JComponent c) {
|
||||
canvas.add(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
unitLabel.addMouseListener(pressListener);
|
||||
|
||||
//if (((unit.getState() == Unit.ACTIVE) || (unit.getState() == Unit.SENTRY)) && (!unit.isNaval())) {
|
||||
if (!unit.isNaval() && !unit.isType(Unit.WAGON_TRAIN)) {
|
||||
if (!unit.isCarrier()) {
|
||||
outsideColonyPanel.add(unitLabel, false);
|
||||
} else {
|
||||
inPortPanel.add(unitLabel);
|
||||
|
@ -310,7 +310,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
public void reinitialize() {
|
||||
initialize(colony, game);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the label that is placed above the cargo panel. It shows the name
|
||||
|
@ -334,15 +334,19 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
*/
|
||||
private void updateSoLLabel() {
|
||||
solLabel.setText("SoL: " + colony.getSoL() + "% (" + ((colony.getUnitCount() * colony.getSoL()) / 100) +
|
||||
"), Tory: " + colony.getTory() + "% (" +
|
||||
"), Tory: " + colony.getTory() + "% (" +
|
||||
(colony.getUnitCount() - ((colony.getUnitCount() * colony.getSoL()) / 100)) + ")");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the building progress label.
|
||||
*/
|
||||
private void updateProgressLabel() {
|
||||
progressLabel.setText("Hammers: " + colony.getHammers() + "/" + colony.getBuilding(colony.getCurrentlyBuilding()).getNextHammers());
|
||||
if (colony.getCurrentlyBuilding() < Colony.BUILDING_UNIT_ADDITION) {
|
||||
progressLabel.setText("Hammers: " + colony.getHammers() + "/" + colony.getBuilding(colony.getCurrentlyBuilding()).getNextHammers());
|
||||
} else {
|
||||
progressLabel.setText("Hammers: " + colony.getHammers() + "/" + Unit.getNextHammers(colony.getCurrentlyBuilding() - Colony.BUILDING_UNIT_ADDITION));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -777,6 +781,10 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
* @return The component argument.
|
||||
*/
|
||||
public Component add(Component comp, boolean editState) {
|
||||
if (selectedUnit == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (editState) {
|
||||
if (comp instanceof UnitLabel) {
|
||||
comp.getParent().remove(comp);
|
||||
|
@ -1006,12 +1014,12 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
public BuildingBox(ColonyPanel colonyPanel) {
|
||||
super();
|
||||
this.colonyPanel = colonyPanel;
|
||||
|
||||
|
||||
buildingBoxListener = new BuildingBoxListener(this, colonyPanel);
|
||||
super.addActionListener(buildingBoxListener);
|
||||
super.setRenderer(new BuildingBoxRenderer());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the BuildingBox such that it contains the appropriate buildings.
|
||||
*/
|
||||
|
@ -1029,13 +1037,13 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
" (" +
|
||||
Integer.toString(colonyPanel.getColony().getBuilding(i).getNextHammers()) +
|
||||
" hammers");
|
||||
|
||||
|
||||
if (colonyPanel.getColony().getBuilding(i).getNextTools() > 0) {
|
||||
theText += ", " + Integer.toString(colony.getBuilding(i).getNextTools()) + " tools";
|
||||
}
|
||||
|
||||
theText += ")";
|
||||
|
||||
|
||||
BuildingBoxItem nextItem = new BuildingBoxItem(theText, i);
|
||||
this.addItem(nextItem);
|
||||
if (i == colonyPanel.getColony().getCurrentlyBuilding()) {
|
||||
|
@ -1043,18 +1051,36 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
String theText = new String(Unit.getName(Unit.WAGON_TRAIN) +
|
||||
" (" + Unit.getNextHammers(Unit.WAGON_TRAIN) + " hammers");
|
||||
|
||||
if (Unit.getNextTools(Unit.WAGON_TRAIN) > 0) {
|
||||
theText += ", " + Integer.toString(Unit.getNextTools(Unit.WAGON_TRAIN)) + " tools";
|
||||
}
|
||||
|
||||
theText += ")";
|
||||
|
||||
int i = Unit.WAGON_TRAIN + Colony.BUILDING_UNIT_ADDITION;
|
||||
BuildingBoxItem wagonTrainItem = new BuildingBoxItem(theText, i);
|
||||
addItem(wagonTrainItem);
|
||||
if (i == colonyPanel.getColony().getCurrentlyBuilding()) {
|
||||
toSelect = wagonTrainItem;
|
||||
}
|
||||
|
||||
this.setSelectedItem(toSelect);
|
||||
super.addActionListener(buildingBoxListener);
|
||||
colonyPanel.updateProgressLabel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a type of building, and the text of the next building in that type.
|
||||
*/
|
||||
public final class BuildingBoxItem {
|
||||
private final String text;
|
||||
private final int type;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the text and the type.
|
||||
*/
|
||||
|
@ -1062,7 +1088,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
this.text = text;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the text associated with this item.
|
||||
* @returns The text associated with this item.
|
||||
|
@ -1070,7 +1096,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the building type associated with that item.
|
||||
* @returns The building type associated with this item.
|
||||
|
@ -1079,15 +1105,15 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The ActionListener for the BuildingBox.
|
||||
*/
|
||||
public final class BuildingBoxListener implements ActionListener {
|
||||
|
||||
|
||||
private ColonyPanel colonyPanel;
|
||||
private BuildingBox buildingBox;
|
||||
|
||||
|
||||
/**
|
||||
* Sets up this BuildingBoxListener's buildingBox and colonyPanel.
|
||||
*/
|
||||
|
@ -1096,7 +1122,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
this.buildingBox = buildingBox;
|
||||
this.colonyPanel = colonyPanel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the ColonyPanel's Colony's type of building.
|
||||
*/
|
||||
|
@ -1105,7 +1131,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
colonyPanel.updateProgressLabel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The ListCellRenderer for the BuildingBox.
|
||||
*/
|
||||
|
@ -1118,7 +1144,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
setHorizontalAlignment(LEFT);
|
||||
setVerticalAlignment(CENTER);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Displays the string associated with the BuildingBoxItem.
|
||||
*/
|
||||
|
@ -1128,7 +1154,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
|
||||
|
||||
if (isSelected) {
|
||||
setBackground(list.getSelectionBackground());
|
||||
setForeground(list.getSelectionForeground());
|
||||
|
@ -1136,15 +1162,15 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
setBackground(list.getBackground());
|
||||
setForeground(list.getForeground());
|
||||
}
|
||||
|
||||
|
||||
if (value instanceof BuildingBoxItem) {
|
||||
setText(((BuildingBoxItem)value).getText());
|
||||
} else {
|
||||
super.setText("---INVALID ITEM---");
|
||||
}
|
||||
|
||||
|
||||
setFont(list.getFont());
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,64 +47,17 @@ public final class DragListener extends MouseAdapter {
|
|||
*/
|
||||
public void mousePressed(MouseEvent e) {
|
||||
JComponent comp = (JComponent)e.getSource();
|
||||
|
||||
|
||||
//Does not work on some platforms:
|
||||
//if (e.isPopupTrigger() && (comp instanceof UnitLabel)) {
|
||||
if (e.getButton() == MouseEvent.BUTTON3 && (comp instanceof UnitLabel)) {
|
||||
UnitLabel unitLabel = (UnitLabel)comp;
|
||||
Unit tempUnit = unitLabel.getUnit();
|
||||
|
||||
// if (!tempUnit.isCarrier()) {
|
||||
if (tempUnit.isColonist()) {
|
||||
JPopupMenu menu = new JPopupMenu("Unit");
|
||||
JMenuItem menuItem;
|
||||
|
||||
if (!tempUnit.isPioneer() && !tempUnit.isMissionary()) {
|
||||
if (tempUnit.isArmed()) {
|
||||
menuItem = new JMenuItem("Disarm");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Arm");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.ARM));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (!tempUnit.isPioneer() && !tempUnit.isMissionary()) {
|
||||
if (tempUnit.isMounted()) {
|
||||
menuItem = new JMenuItem("Remove Horses");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Mount");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.MOUNT));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (!tempUnit.isArmed() && !tempUnit.isMounted() && !tempUnit.isMissionary()) {
|
||||
if (tempUnit.isPioneer()) {
|
||||
menuItem = new JMenuItem("Remove Tools");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Equip with Tools");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.TOOLS));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (!tempUnit.isArmed() && !tempUnit.isMounted() && !tempUnit.isPioneer() && (tempUnit.getLocation()
|
||||
instanceof Europe || tempUnit.getTile() != null && tempUnit.getTile().getColony().getBuilding(Building.CHURCH).isBuilt())) {
|
||||
|
||||
if (tempUnit.isMissionary()) {
|
||||
menuItem = new JMenuItem("Take Off Silly Clothes");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Dress as Missionaries");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.DRESS));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (tempUnit.getLocation() instanceof ColonyTile) {
|
||||
menuItem = new JMenuItem("Be a Farmer");
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_FOOD));
|
||||
|
@ -138,6 +91,54 @@ public final class DragListener extends MouseAdapter {
|
|||
menuItem.setActionCommand(String.valueOf(UnitLabel.WORKTYPE_SILVER));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
|
||||
menu.addSeparator();
|
||||
}
|
||||
|
||||
|
||||
if (!tempUnit.isPioneer() && !tempUnit.isMissionary() && tempUnit.canArm()) {
|
||||
if (tempUnit.isArmed()) {
|
||||
menuItem = new JMenuItem("Disarm");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Arm");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.ARM));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (!tempUnit.isPioneer() && !tempUnit.isMissionary() && tempUnit.canMount()) {
|
||||
if (tempUnit.isMounted()) {
|
||||
menuItem = new JMenuItem("Remove Horses");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Mount");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.MOUNT));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (!tempUnit.isArmed() && !tempUnit.isMounted() && !tempUnit.isMissionary() && tempUnit.canEquipWithTools()) {
|
||||
if (tempUnit.isPioneer()) {
|
||||
menuItem = new JMenuItem("Remove Tools");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Equip with Tools");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.TOOLS));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
if (!tempUnit.isArmed() && !tempUnit.isMounted() && !tempUnit.isPioneer() && tempUnit.canDressAsMissionary()) {
|
||||
|
||||
if (tempUnit.isMissionary()) {
|
||||
menuItem = new JMenuItem("Take Off Silly Clothes");
|
||||
} else {
|
||||
menuItem = new JMenuItem("Dress as Missionaries");
|
||||
}
|
||||
menuItem.setActionCommand(String.valueOf(UnitLabel.DRESS));
|
||||
menuItem.addActionListener(unitLabel);
|
||||
menu.add(menuItem);
|
||||
}
|
||||
|
||||
menu.show(comp, e.getX(), e.getY());
|
||||
|
@ -146,7 +147,7 @@ public final class DragListener extends MouseAdapter {
|
|||
TransferHandler handler = comp.getTransferHandler();
|
||||
handler.exportAsDrag(comp, e, TransferHandler.COPY);
|
||||
|
||||
if ((comp instanceof UnitLabel) && (((UnitLabel)comp).getUnit().isNaval())) {
|
||||
if ((comp instanceof UnitLabel) && (((UnitLabel)comp).getUnit().isCarrier())) {
|
||||
if (parentPanel instanceof EuropePanel) {
|
||||
((EuropePanel) parentPanel).setSelectedUnit((UnitLabel)comp);
|
||||
} else if (parentPanel instanceof ColonyPanel) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import javax.swing.JButton;
|
|||
import javax.swing.JLabel;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.border.BevelBorder;
|
||||
|
||||
|
@ -345,6 +346,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
// Place new components on the panels.
|
||||
//
|
||||
|
||||
UnitLabel carrier = null;
|
||||
Iterator unitIterator = europe.getUnitIterator();
|
||||
while (unitIterator.hasNext()) {
|
||||
Unit unit = (Unit) unitIterator.next();
|
||||
|
@ -356,6 +358,7 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
if (((unit.getState() == Unit.ACTIVE) || (unit.getState() == Unit.SENTRY)) && (!unit.isNaval())) {
|
||||
docksPanel.add(unitLabel, false);
|
||||
} else if (unit.getState() == Unit.ACTIVE) {
|
||||
carrier = unitLabel;
|
||||
inPortPanel.add(unitLabel);
|
||||
} else if (unit.getState() == Unit.TO_EUROPE) {
|
||||
toEuropePanel.add(unitLabel, false);
|
||||
|
@ -371,14 +374,24 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
((JPanel)marketPanel).add(marketLabel);
|
||||
}
|
||||
|
||||
|
||||
setSelectedUnit(null);
|
||||
setSelectedUnit(carrier);
|
||||
updateGoldLabel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the gold label.
|
||||
*/
|
||||
public void updateGoldLabel() {
|
||||
goldLabel.setText("Gold: " + freeColClient.getMyPlayer().getGold());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reinitializes the panel, but keeps the currently selected unit.
|
||||
*/
|
||||
public void reinitialize() {
|
||||
UnitLabel selectedUnit = this.selectedUnit;
|
||||
final UnitLabel selectedUnit = this.selectedUnit;
|
||||
initialize(europe, game);
|
||||
setSelectedUnit(selectedUnit);
|
||||
}
|
||||
|
@ -881,9 +894,9 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A panel that holds units and goods that represent Units and cargo that are
|
||||
|
@ -916,6 +929,10 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
* @return The component argument.
|
||||
*/
|
||||
public Component add(Component comp, boolean editState) {
|
||||
if (selectedUnit == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (editState) {
|
||||
if (comp instanceof UnitLabel) {
|
||||
comp.getParent().remove(comp);
|
||||
|
@ -1106,13 +1123,11 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
public void initialize() {
|
||||
if ((game != null) && (freeColClient.getMyPlayer() != null)) {
|
||||
price.setText(Integer.toString(freeColClient.getMyPlayer().getRecruitPrice()) + " gold");
|
||||
try {
|
||||
person1.setText(Unit.getName(europe.getRecruitable(1)));
|
||||
person2.setText(Unit.getName(europe.getRecruitable(2)));
|
||||
person3.setText(Unit.getName(europe.getRecruitable(3)));
|
||||
} catch (FreeColException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
person1.setText(Unit.getName(europe.getRecruitable(1)));
|
||||
person2.setText(Unit.getName(europe.getRecruitable(2)));
|
||||
person3.setText(Unit.getName(europe.getRecruitable(3)));
|
||||
|
||||
|
||||
if (freeColClient.getMyPlayer().getRecruitPrice() > freeColClient.getMyPlayer().getGold()) {
|
||||
person1.setEnabled(false);
|
||||
|
@ -1157,18 +1172,12 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
frigateLabel = new JLabel(Integer.toString(Unit.getPrice(Unit.FRIGATE)));
|
||||
JButton cancel = new JButton("Cancel");
|
||||
|
||||
try {
|
||||
artilleryButton = new JButton(Unit.getName(Unit.ARTILLERY));
|
||||
caravelButton = new JButton(Unit.getName(Unit.CARAVEL));
|
||||
merchantmanButton = new JButton(Unit.getName(Unit.MERCHANTMAN));
|
||||
galleonButton = new JButton(Unit.getName(Unit.GALLEON));
|
||||
privateerButton = new JButton(Unit.getName(Unit.PRIVATEER));
|
||||
frigateButton = new JButton(Unit.getName(Unit.FRIGATE));
|
||||
}
|
||||
catch (FreeColException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
artilleryButton = new JButton(Unit.getName(Unit.ARTILLERY));
|
||||
caravelButton = new JButton(Unit.getName(Unit.CARAVEL));
|
||||
merchantmanButton = new JButton(Unit.getName(Unit.MERCHANTMAN));
|
||||
galleonButton = new JButton(Unit.getName(Unit.GALLEON));
|
||||
privateerButton = new JButton(Unit.getName(Unit.PRIVATEER));
|
||||
frigateButton = new JButton(Unit.getName(Unit.FRIGATE));
|
||||
|
||||
question.setSize(300, 20);
|
||||
question2.setSize(300, 20);
|
||||
|
@ -1347,28 +1356,23 @@ public final class EuropePanel extends JLayeredPane implements ActionListener {
|
|||
veteranSoldierLabel = new JLabel(Integer.toString(Unit.getPrice(Unit.VETERAN_SOLDIER)));
|
||||
JButton cancel = new JButton("Cancel");
|
||||
|
||||
try {
|
||||
expertOreMinerButton = new JButton(Unit.getName(Unit.EXPERT_ORE_MINER));
|
||||
expertLumberJackButton = new JButton(Unit.getName(Unit.EXPERT_LUMBER_JACK));
|
||||
masterGunsmithButton = new JButton(Unit.getName(Unit.MASTER_GUNSMITH));
|
||||
expertSilverMinerButton = new JButton(Unit.getName(Unit.EXPERT_SILVER_MINER));
|
||||
masterFurTraderButton = new JButton(Unit.getName(Unit.MASTER_FUR_TRADER));
|
||||
masterCarpenterButton = new JButton(Unit.getName(Unit.MASTER_CARPENTER));
|
||||
expertFishermanButton = new JButton(Unit.getName(Unit.EXPERT_FISHERMAN));
|
||||
masterBlacksmithButton = new JButton(Unit.getName(Unit.MASTER_BLACKSMITH));
|
||||
expertFarmerButton = new JButton(Unit.getName(Unit.EXPERT_FARMER));
|
||||
masterDistillerButton = new JButton(Unit.getName(Unit.MASTER_DISTILLER));
|
||||
hardyPioneerButton = new JButton(Unit.getName(Unit.HARDY_PIONEER));
|
||||
masterTobacconistButton = new JButton(Unit.getName(Unit.MASTER_TOBACCONIST));
|
||||
masterWeaverButton = new JButton(Unit.getName(Unit.MASTER_WEAVER));
|
||||
jesuitMissionaryButton = new JButton(Unit.getName(Unit.JESUIT_MISSIONARY));
|
||||
firebrandPreacherButton = new JButton(Unit.getName(Unit.FIREBRAND_PREACHER));
|
||||
elderStatesmanButton = new JButton(Unit.getName(Unit.ELDER_STATESMAN));
|
||||
veteranSoldierButton = new JButton(Unit.getName(Unit.VETERAN_SOLDIER));
|
||||
} catch (FreeColException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
expertOreMinerButton = new JButton(Unit.getName(Unit.EXPERT_ORE_MINER));
|
||||
expertLumberJackButton = new JButton(Unit.getName(Unit.EXPERT_LUMBER_JACK));
|
||||
masterGunsmithButton = new JButton(Unit.getName(Unit.MASTER_GUNSMITH));
|
||||
expertSilverMinerButton = new JButton(Unit.getName(Unit.EXPERT_SILVER_MINER));
|
||||
masterFurTraderButton = new JButton(Unit.getName(Unit.MASTER_FUR_TRADER));
|
||||
masterCarpenterButton = new JButton(Unit.getName(Unit.MASTER_CARPENTER));
|
||||
expertFishermanButton = new JButton(Unit.getName(Unit.EXPERT_FISHERMAN));
|
||||
masterBlacksmithButton = new JButton(Unit.getName(Unit.MASTER_BLACKSMITH));
|
||||
expertFarmerButton = new JButton(Unit.getName(Unit.EXPERT_FARMER));
|
||||
masterDistillerButton = new JButton(Unit.getName(Unit.MASTER_DISTILLER));
|
||||
hardyPioneerButton = new JButton(Unit.getName(Unit.HARDY_PIONEER));
|
||||
masterTobacconistButton = new JButton(Unit.getName(Unit.MASTER_TOBACCONIST));
|
||||
masterWeaverButton = new JButton(Unit.getName(Unit.MASTER_WEAVER));
|
||||
jesuitMissionaryButton = new JButton(Unit.getName(Unit.JESUIT_MISSIONARY));
|
||||
firebrandPreacherButton = new JButton(Unit.getName(Unit.FIREBRAND_PREACHER));
|
||||
elderStatesmanButton = new JButton(Unit.getName(Unit.ELDER_STATESMAN));
|
||||
veteranSoldierButton = new JButton(Unit.getName(Unit.VETERAN_SOLDIER));
|
||||
|
||||
question.setSize(300, 20);
|
||||
question2.setSize(300, 20);
|
||||
|
|
|
@ -131,7 +131,7 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
public void paintComponent(Graphics g) {
|
||||
if (selected) {
|
||||
setEnabled(true);
|
||||
} else if (unit.isNaval()) {
|
||||
} else if (unit.isCarrier()) {
|
||||
setEnabled(false);
|
||||
} else {
|
||||
setEnabled(true);
|
||||
|
@ -198,9 +198,7 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
inGameController.equipUnit(unit, Goods.HORSES, ((unit.isMounted()) ? 0 : 50));
|
||||
break;
|
||||
case TOOLS:
|
||||
if (!unit.isArmed() && !unit.isMounted()) {
|
||||
inGameController.equipUnit(unit, Goods.TOOLS, ((unit.isPioneer()) ? 0 : 100));
|
||||
}
|
||||
inGameController.equipUnit(unit, Goods.TOOLS, ((unit.isPioneer()) ? 0 : 100));
|
||||
break;
|
||||
case DRESS:
|
||||
inGameController.equipUnit(unit, Goods.CROSSES, ((unit.isMissionary()) ? 0 : 1));
|
||||
|
@ -237,26 +235,26 @@ public final class UnitLabel extends JLabel implements ActionListener {
|
|||
Component uc = getParent();
|
||||
while (uc != null) {
|
||||
if (uc instanceof ColonyPanel) {
|
||||
((ColonyPanel) uc).reinitialize();
|
||||
if (unit.getTile() != null && unit.getTile().getColony() == null) {
|
||||
parent.remove(uc);
|
||||
parent.showMapControls();
|
||||
} else {
|
||||
((ColonyPanel) uc).reinitialize();
|
||||
}
|
||||
|
||||
break;
|
||||
} else if (uc instanceof EuropePanel) {
|
||||
((EuropePanel) uc).reinitialize();
|
||||
//((EuropePanel) uc).reinitialize();
|
||||
EuropePanel ep = (EuropePanel) uc;
|
||||
ep.updateGoldLabel();
|
||||
break;
|
||||
}
|
||||
|
||||
uc = uc.getParent();
|
||||
}
|
||||
|
||||
if (unit.getTile() != null && unit.getTile().getColony() == null) {
|
||||
parent.remove(uc);
|
||||
parent.showMapControls();
|
||||
}
|
||||
|
||||
repaint(0, 0, getWidth(), getHeight());
|
||||
|
||||
|
||||
// TODO: Refresh the gold label when goods have prices.
|
||||
//goldLabel.repaint(0, 0, goldLabel.getWidth(), goldLabel.getHeight());
|
||||
//repaint(0, 0, getWidth(), getHeight());
|
||||
//uc.refresh();
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
|
|
|
@ -26,6 +26,7 @@ public final class Colony extends Settlement implements Location {
|
|||
public static final String LICENSE = "http://www.gnu.org/licenses/gpl.html";
|
||||
public static final String REVISION = "$Revision$";
|
||||
|
||||
public static final int BUILDING_UNIT_ADDITION = 1000;
|
||||
|
||||
/** The name of the colony. */
|
||||
private String name;
|
||||
|
@ -37,6 +38,13 @@ public final class Colony extends Settlement implements Location {
|
|||
|
||||
private int hammers;
|
||||
private int bells;
|
||||
|
||||
/**
|
||||
* The type of the "Building" that is beeing built,
|
||||
* or if <code>currentlyBuilding >= BUILDING_UNIT_ADDITION</code>
|
||||
* the type of the <code>Unit</code> (+BUILDING_UNIT_ADDITION)
|
||||
* that is currently beeing build
|
||||
*/
|
||||
private int currentlyBuilding;
|
||||
|
||||
/**
|
||||
|
@ -131,7 +139,7 @@ public final class Colony extends Settlement implements Location {
|
|||
while (unitIterator.hasNext()) {
|
||||
((Unit)unitIterator.next()).setOwner(owner);
|
||||
}
|
||||
|
||||
|
||||
Iterator tileUnitIterator = getTile().getUnitIterator();
|
||||
while (tileUnitIterator.hasNext()) {
|
||||
Unit target = (Unit) tileUnitIterator.next();
|
||||
|
@ -290,7 +298,7 @@ public final class Colony extends Settlement implements Location {
|
|||
|
||||
logger.warning("Could not find a 'WorkLocation' for " + locatable + " in " + this);
|
||||
} else {
|
||||
getTile().add(locatable);
|
||||
locatable.setLocation(getTile());
|
||||
}
|
||||
} else if (locatable instanceof Goods) {
|
||||
goodsContainer.addGoods((Goods)locatable);
|
||||
|
@ -429,6 +437,12 @@ public final class Colony extends Settlement implements Location {
|
|||
int required = 0;
|
||||
int tools = 0;
|
||||
|
||||
// Building a unit:
|
||||
if (currentlyBuilding >= BUILDING_UNIT_ADDITION) {
|
||||
hammers += amount;
|
||||
return;
|
||||
}
|
||||
|
||||
if (getBuilding(currentlyBuilding).getNextPop() > getUnitCount()) {
|
||||
// TODO: Show error: not enough colonists to build the given building.
|
||||
return;
|
||||
|
@ -458,13 +472,14 @@ public final class Colony extends Settlement implements Location {
|
|||
|
||||
/**
|
||||
* Adds the given unit to this colony. If <code>unit.isColonist()</code>
|
||||
* then 300 food is removed, else hammers is set to 0.
|
||||
* then 300 food is removed, else hammers and tools are removed.
|
||||
*/
|
||||
public void createUnit(Unit unit) {
|
||||
if (unit.isColonist()) {
|
||||
removeGoods(Goods.FOOD, 300);
|
||||
} else {
|
||||
hammers = 0;
|
||||
removeGoods(Goods.TOOLS, Unit.getNextTools(unit.getType()));
|
||||
}
|
||||
|
||||
unit.setLocation(this);
|
||||
|
|
|
@ -322,11 +322,16 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
}
|
||||
|
||||
// Check for an 'attack' instead of 'move'.
|
||||
if ((target.getUnitCount() > 0) &&
|
||||
if ((target.getUnitCount() > 0) &&
|
||||
(target.getDefendingUnit(this) != null) &&
|
||||
(target.getDefendingUnit(this).getNation() != getNation())
|
||||
&& ((target.isLand() && !isNaval()) || (isNaval() && !target.isLand()))) {
|
||||
return ATTACK;
|
||||
|
||||
if (getOffensePower(target.getDefendingUnit(this)) == 0) {
|
||||
return ILLEGAL_MOVE;
|
||||
} else {
|
||||
return ATTACK;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for disembark.
|
||||
|
@ -371,7 +376,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
return MOVE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the amount of space this <code>Unit</code> takes when put on a carrier.
|
||||
*
|
||||
|
@ -525,9 +530,8 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
*/
|
||||
public void add(Locatable locatable) {
|
||||
if (isCarrier()) {
|
||||
|
||||
if (locatable instanceof Unit) {
|
||||
if (getSpaceLeft() <= 0) {
|
||||
if (getSpaceLeft() <= 0 || getType() == WAGON_TRAIN) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
@ -603,6 +607,10 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
*/
|
||||
public boolean canAdd(Locatable locatable) {
|
||||
if (isCarrier()) {
|
||||
if (getType() == WAGON_TRAIN && locatable instanceof Unit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getSpaceLeft() >= locatable.getTakeSpace();
|
||||
} else {
|
||||
return false;
|
||||
|
@ -656,7 +664,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
* @return The <code>Iterator</code>.
|
||||
*/
|
||||
public Iterator getUnitIterator() {
|
||||
if (isCarrier()) {
|
||||
if (isCarrier() && getType() != WAGON_TRAIN) {
|
||||
return unitContainer.getUnitIterator();
|
||||
} else { // TODO: Make a better solution:
|
||||
return (new ArrayList()).iterator();
|
||||
|
@ -742,6 +750,45 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this unit can be armed in the current location.
|
||||
*/
|
||||
public boolean canArm() {
|
||||
return isArmed() || getGoodsDumpLocation() != null && getGoodsDumpLocation().getGoodsCount(Goods.MUSKETS) >= 50 ||
|
||||
(location instanceof Europe || location instanceof Unit && ((Unit) location).getLocation() instanceof Europe) &&
|
||||
getOwner().getGold() >= getGame().getMarket().getBidPrice(Goods.MUSKETS, 50);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this unit can be mounted in the current location.
|
||||
*/
|
||||
public boolean canMount() {
|
||||
return isMounted() || getGoodsDumpLocation() != null && getGoodsDumpLocation().getGoodsCount(Goods.HORSES) >= 50 ||
|
||||
(location instanceof Europe || location instanceof Unit && ((Unit) location).getLocation() instanceof Europe)
|
||||
&& getOwner().getGold() >= getGame().getMarket().getBidPrice(Goods.HORSES, 50);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this unit can be equiped with tools in the current location.
|
||||
*/
|
||||
public boolean canEquipWithTools() {
|
||||
return isPioneer() || getGoodsDumpLocation() != null && getGoodsDumpLocation().getGoodsCount(Goods.TOOLS) >= 20 ||
|
||||
(location instanceof Europe || location instanceof Unit && ((Unit) location).getLocation() instanceof Europe)
|
||||
&& getOwner().getGold() >= getGame().getMarket().getBidPrice(Goods.TOOLS, 20);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this unit can be dressed as a missionary at the current location.
|
||||
*/
|
||||
public boolean canDressAsMissionary() {
|
||||
return isMissionary() || ((location instanceof Europe || location instanceof Unit && ((Unit) location).getLocation()
|
||||
instanceof Europe) || getTile() != null && getTile().getColony().getBuilding(Building.CHURCH).isBuilt());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the armed attribute of this unit.
|
||||
|
@ -758,7 +805,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
if (isPioneer()) {
|
||||
setNumberOfTools(0);
|
||||
}
|
||||
|
||||
|
||||
if (isMissionary()) {
|
||||
setMissionary(false);
|
||||
}
|
||||
|
@ -1026,10 +1073,9 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
* otherwise.
|
||||
*/
|
||||
public static boolean isCarrier(int type) {
|
||||
if ((type == CARAVEL) || (type == GALLEON) || (type == FRIGATE) || (type == MAN_O_WAR) || (type == MERCHANTMAN) || (type == PRIVATEER)) {
|
||||
if ((type == CARAVEL) || (type == GALLEON) || (type == FRIGATE) || (type == MAN_O_WAR) || (type == MERCHANTMAN) || (type == PRIVATEER) || (type == WAGON_TRAIN)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1111,9 +1157,9 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
* value can be used when communicating with the user.
|
||||
*
|
||||
* @return The given unit type as a String
|
||||
* @throws FreeColException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static String getName(int someType) throws FreeColException {
|
||||
public static String getName(int someType) {
|
||||
// TODO: Use i18n:
|
||||
|
||||
switch (someType) {
|
||||
|
@ -1198,7 +1244,7 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
case MILKMAID:
|
||||
return "Milkmaid";
|
||||
default:
|
||||
throw new FreeColException("Unit has an invalid type.");
|
||||
throw new IllegalArgumentException("Unit has an invalid type.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1576,12 +1622,14 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
return 4;
|
||||
case PRIVATEER:
|
||||
return 2;
|
||||
case WAGON_TRAIN:
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Move the given unit to the front of this carrier (make sure
|
||||
* it'll be the first unit in this unit's unit list).
|
||||
|
@ -1913,29 +1961,29 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
base_power++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int modified_power = base_power;
|
||||
|
||||
|
||||
//TODO: <1 move point movement penalty
|
||||
|
||||
|
||||
if (isNaval()) {
|
||||
if (getGoodsCount() > 0) {
|
||||
modified_power -= ((base_power * getGoodsCount()) / 8); // -12.5% penalty for every unit of cargo.
|
||||
}
|
||||
return modified_power;
|
||||
}
|
||||
|
||||
|
||||
if (getState() == FORTIFY) {
|
||||
modified_power += (base_power / 2); // 50% fortify bonus
|
||||
}
|
||||
|
||||
if ((getTile() != null) && (getTile().getSettlement() != null) && (getTile().getSettlement() instanceof Colony) ) {
|
||||
Colony colony = ((Colony)getTile().getSettlement());
|
||||
switch(colony.getBuilding(Building.STOCKADE).getLevel()) {
|
||||
case Building.NOT_BUILT:
|
||||
default:
|
||||
if (getState() == FORTIFY) {
|
||||
modified_power += base_power; // 50% colony bonus + 50% fortify bonus = 100% bonus
|
||||
} else {
|
||||
modified_power += (base_power / 2); // 50% colony bonus
|
||||
}
|
||||
break;
|
||||
modified_power += (base_power / 2); // 50% colony bonus
|
||||
break;
|
||||
case Building.HOUSE:
|
||||
modified_power += base_power; // 100% stockade bonus
|
||||
break;
|
||||
|
@ -1952,7 +2000,12 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
// Terrain defensive bonus.
|
||||
modified_power += ((base_power * getTile().defenseBonus()) / 100);
|
||||
}
|
||||
|
||||
|
||||
// Indian settlement defensive bonus.
|
||||
if (getTile() != null && getTile().getSettlement() != null && getTile().getSettlement() instanceof IndianSettlement) {
|
||||
modified_power += (base_power / 2); // 50% bonus
|
||||
}
|
||||
|
||||
if ((getType() == ARTILLERY) || (getType() == DAMAGED_ARTILLERY)) {
|
||||
if ((attacker.getType() == BRAVE) && (getTile().getSettlement() != null)) {
|
||||
modified_power += base_power; // 100% defense bonus against an Indian raid
|
||||
|
@ -1961,8 +2014,8 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
modified_power -= ((base_power * 3) / 4); // -75% Artillery in the Open penalty
|
||||
}
|
||||
}
|
||||
|
||||
return base_power;
|
||||
|
||||
return modified_power;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1978,7 +2031,11 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
base_power = 1;
|
||||
break;
|
||||
case VETERAN_SOLDIER:
|
||||
base_power = 2;
|
||||
if (isArmed()) {
|
||||
base_power = 2;
|
||||
} else {
|
||||
base_power = 0;
|
||||
}
|
||||
break;
|
||||
case COLONIAL_REGULAR:
|
||||
base_power = 3;
|
||||
|
@ -2305,6 +2362,24 @@ public class Unit extends FreeColGameObject implements Location, Locatable {
|
|||
return base;
|
||||
}
|
||||
|
||||
|
||||
public static int getNextHammers(int type) {
|
||||
if (type == WAGON_TRAIN) {
|
||||
return 40;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int getNextTools(int type) {
|
||||
if (type == WAGON_TRAIN) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all references to this object.
|
||||
|
|
|
@ -224,8 +224,9 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
int total_probability = attack_power + defender.getDefensePower(unit);
|
||||
int result = Unit.ATTACKER_LOSS; // Assume this until otherwise calculated.
|
||||
|
||||
if ((attackCalculator.nextInt(total_probability)) <= attack_power) {
|
||||
if ((attackCalculator.nextInt(total_probability+1)) <= attack_power) {
|
||||
result = Unit.ATTACKER_WIN;
|
||||
} else {
|
||||
}
|
||||
|
||||
// Inform the other players (other then the player attacking) about the attack:
|
||||
|
@ -810,7 +811,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
Element newTurnElement = Message.createNewRootElement("newTurn");
|
||||
freeColServer.getServer().sendToAll(newTurnElement, null);
|
||||
|
||||
createColonistsInColonies();
|
||||
createUnitsInColonies();
|
||||
}
|
||||
|
||||
game.setCurrentPlayer(nextPlayer);
|
||||
|
@ -833,9 +834,10 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
|
||||
|
||||
/**
|
||||
* Creates a colonist in every colony having more than 300 food.
|
||||
* Creates a colonist in every colony having more than 300 food
|
||||
* and builds a unit if choosen and completed.
|
||||
*/
|
||||
private void createColonistsInColonies() {
|
||||
private void createUnitsInColonies() {
|
||||
Game game = freeColServer.getGame();
|
||||
Map map = game.getMap();
|
||||
|
||||
|
@ -849,7 +851,7 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
Element createUnitElement = Message.createNewRootElement("createUnit");
|
||||
createUnitElement.setAttribute("location", colony.getID());
|
||||
createUnitElement.appendChild(unit.toXMLElement(colony.getOwner(), createUnitElement.getOwnerDocument()));
|
||||
|
||||
|
||||
colony.createUnit(unit);
|
||||
|
||||
ServerPlayer player = ((ServerPlayer) colony.getOwner());
|
||||
|
@ -860,6 +862,31 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
logger.warning("Could not send message to: " + player.getName() + " with connection " + player.getConnection());
|
||||
}
|
||||
}
|
||||
|
||||
if (tile.getColony() != null && tile.getColony().getCurrentlyBuilding() >= Colony.BUILDING_UNIT_ADDITION) {
|
||||
int unitType = tile.getColony().getCurrentlyBuilding() - Colony.BUILDING_UNIT_ADDITION;
|
||||
|
||||
if (Unit.getNextHammers(unitType) <= tile.getColony().getHammers() &&
|
||||
Unit.getNextTools(unitType) <= tile.getColony().getGoodsCount(Goods.TOOLS)) {
|
||||
|
||||
Colony colony = tile.getColony();
|
||||
Unit unit = new Unit(game, null, colony.getOwner(), unitType, Unit.ACTIVE);
|
||||
|
||||
Element createUnitElement = Message.createNewRootElement("createUnit");
|
||||
createUnitElement.setAttribute("location", colony.getID());
|
||||
createUnitElement.appendChild(unit.toXMLElement(colony.getOwner(), createUnitElement.getOwnerDocument()));
|
||||
|
||||
colony.createUnit(unit);
|
||||
|
||||
ServerPlayer player = ((ServerPlayer) colony.getOwner());
|
||||
|
||||
try {
|
||||
player.getConnection().send(createUnitElement);
|
||||
} catch (IOException e) {
|
||||
logger.warning("Could not send message to: " + player.getName() + " with connection " + player.getConnection());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue