mirror of https://github.com/FreeCol/freecol.git
Sons of Liberty membership added into colonies with liberty bells contributing towards this total. Basic support for building construction added. TODO: add ability to select what is going to be built...
This commit is contained in:
parent
caab8d3ba0
commit
8ad71192a1
|
@ -58,6 +58,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
private final JLabel cargoLabel;
|
||||
private final JLabel goldLabel;
|
||||
private final JLabel solLabel;
|
||||
private final JLabel warehouseLabel;
|
||||
private final OutsideColonyPanel outsideColonyPanel;
|
||||
private final InPortPanel inPortPanel;
|
||||
|
@ -120,6 +121,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
|
||||
cargoLabel = new JLabel("<html><strike>Cargo</strike></html>");
|
||||
goldLabel = new JLabel("Gold: 0");
|
||||
solLabel = new JLabel("SOL: 0%, Tory: 100%");
|
||||
warehouseLabel = new JLabel("Goods");
|
||||
|
||||
JButton exitButton = new JButton("Close");
|
||||
|
@ -145,6 +147,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
inPortLabel.setSize(200, 20);
|
||||
cargoLabel.setSize(410, 20);
|
||||
goldLabel.setSize(100, 20);
|
||||
solLabel.setSize(160, 20);
|
||||
warehouseLabel.setSize(100, 20);
|
||||
tilesLabel.setSize(100, 20);
|
||||
buildingsLabel.setSize(300, 20);
|
||||
|
@ -160,6 +163,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
inPortLabel.setLocation(640, 425);
|
||||
cargoLabel.setLocation(220, 345);
|
||||
warehouseLabel.setLocation(10, 445);
|
||||
solLabel.setLocation(15, 325);
|
||||
goldLabel.setLocation(15, 345);
|
||||
tilesLabel.setLocation(10, 10);
|
||||
buildingsLabel.setLocation(400, 10);
|
||||
|
@ -181,6 +185,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
add(inPortLabel);
|
||||
add(cargoLabel);
|
||||
add(warehouseLabel);
|
||||
add(solLabel);
|
||||
add(goldLabel);
|
||||
add(tilesLabel);
|
||||
add(buildingsLabel);
|
||||
|
@ -284,6 +289,10 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
tilePanel.initialize();
|
||||
|
||||
goldLabel.setText("Gold: " + freeColClient.getMyPlayer().getGold());
|
||||
|
||||
solLabel.setText("SoL: " + colony.getSoL() + "% (" + ((colony.getUnitCount() * colony.getSoL()) / 100) +
|
||||
"), Tory: " + colony.getTory() + "% (" +
|
||||
(colony.getUnitCount() - ((colony.getUnitCount() * colony.getSoL()) / 100)) + ")");
|
||||
}
|
||||
|
||||
|
||||
|
@ -306,6 +315,14 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the SoL membership label.
|
||||
*/
|
||||
private void updateSoLLabel() {
|
||||
solLabel.setText("SoL: " + colony.getSoL() + "% (" + ((colony.getUnitCount() * colony.getSoL()) / 100) +
|
||||
"), Tory: " + colony.getTory() + "% (" +
|
||||
(colony.getUnitCount() - ((colony.getUnitCount() * colony.getSoL()) / 100)) + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently select unit.
|
||||
|
@ -524,6 +541,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
((UnitLabel) comp).setSmall(true);
|
||||
c = ((JPanel) getComponent(1)).add(comp);
|
||||
refresh();
|
||||
colonyPanel.updateSoLLabel();
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@ -571,6 +589,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
updateCargoLabel();
|
||||
Component c = add(comp);
|
||||
refresh();
|
||||
colonyPanel.updateSoLLabel();
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@ -685,6 +704,7 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
{
|
||||
((UnitLabel) comp).setSmall(false);
|
||||
inGameController.boardShip(unit, selectedUnit.getUnit());
|
||||
colonyPanel.updateSoLLabel();
|
||||
} else {
|
||||
return comp;
|
||||
}
|
||||
|
@ -844,6 +864,8 @@ public final class ColonyPanel extends JLayeredPane implements ActionListener {
|
|||
staticGoodsLabel = new JLabel(parent.getImageProvider().getGoodsImageIcon(unit.getWorkType()));
|
||||
staticGoodsLabel.setText(Integer.toString(unit.getFarmedPotential(unit.getWorkType(), colonyTile.getWorkTile())));
|
||||
add(staticGoodsLabel);
|
||||
|
||||
colonyPanel.updateSoLLabel();
|
||||
} else {
|
||||
logger.warning("An invalid component got dropped on this CargoPanel.");
|
||||
}
|
||||
|
|
|
@ -135,6 +135,13 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/* Sets the level of the building.
|
||||
* @param level The new level of the building.
|
||||
*/
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -338,7 +345,6 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
return units.iterator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this <code>Building</code> for a new turn.
|
||||
*/
|
||||
|
@ -387,6 +393,9 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
goodsOutputType = Goods.BELLS;
|
||||
goodsOutput = 1;
|
||||
break;
|
||||
case CARPENTER:
|
||||
goodsOutputType = Goods.HAMMERS;
|
||||
goodsInputType = Goods.LUMBER;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -395,7 +404,12 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
Iterator unitIterator = getUnitIterator();
|
||||
while (unitIterator.hasNext())
|
||||
{
|
||||
goodsOutput += ((Unit) unitIterator.next()).getProducedAmount(goodsOutputType);
|
||||
int productivity = ((Unit) unitIterator.next()).getProducedAmount(goodsOutputType);
|
||||
if (productivity > 0) {
|
||||
productivity += colony.getProductionBonus();
|
||||
if (productivity < 1) productivity = 1;
|
||||
}
|
||||
goodsOutput += productivity;
|
||||
}
|
||||
goodsInput = goodsOutput;
|
||||
goodsOutput *= (type == CHURCH) ? level + 1 : level;
|
||||
|
@ -417,10 +431,14 @@ public final class Building extends FreeColGameObject implements WorkLocation {
|
|||
return;
|
||||
} else if (goodsOutputType == Goods.BELLS) {
|
||||
colony.getOwner().incrementBells(goodsOutput);
|
||||
//TODO: SoL membership
|
||||
colony.addBells(goodsOutput);
|
||||
return;
|
||||
}
|
||||
colony.removeAmountAndTypeOfGoods(goodsInputType, goodsInput);
|
||||
if (goodsOutputType == Goods.HAMMERS) {
|
||||
colony.addHammers(goodsOutput);
|
||||
return;
|
||||
}
|
||||
thepackage = new Goods(getGame(), null, goodsOutputType, goodsOutput);
|
||||
thepackage.setLocation(colony);
|
||||
//colony.add(thepackage);
|
||||
|
|
|
@ -35,7 +35,9 @@ public final class Colony extends Settlement implements Location {
|
|||
|
||||
private GoodsContainer goodsContainer;
|
||||
|
||||
|
||||
private int hammers;
|
||||
private int bells;
|
||||
private int currentlyBuilding;
|
||||
|
||||
/**
|
||||
* Creates a new <code>Colony</code>.
|
||||
|
@ -51,6 +53,10 @@ public final class Colony extends Settlement implements Location {
|
|||
goodsContainer = new GoodsContainer(game, this);
|
||||
|
||||
this.name = name;
|
||||
|
||||
hammers = 0;
|
||||
bells = 0;
|
||||
currentlyBuilding = Building.DOCK;
|
||||
|
||||
workLocations.add(new ColonyTile(getGame(), this, tile));
|
||||
workLocations.add(new ColonyTile(getGame(), this, getGame().getMap().getNeighbourOrNull(Map.N, tile)));
|
||||
|
@ -408,7 +414,125 @@ public final class Colony extends Settlement implements Location {
|
|||
|
||||
return defender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the hammer count of the colony.
|
||||
* @param amount The number of hammers to add.
|
||||
*/
|
||||
public void addHammers(int amount) {
|
||||
int required = 0;
|
||||
int tools = 0;
|
||||
int requiredTable[][][] = {
|
||||
{{ 0, 0, 1},{ -1, -1, -1},{ -1, -1, -1},{ -1, -1, -1}}, // TOWNHALL
|
||||
{{ 0, 0, 1},{ 52, 0, 3},{ -1, -1, -1},{ -1, -1, -1}}, // CARPENTER
|
||||
{{ 0, 0, 1},{ 64, 20, 4},{240,100, 8},{ -1, -1, -1}}, // BLACKSMITH
|
||||
{{ 0, 0, 1},{ 64, 0, 4},{160, 20, 8},{ -1, -1, -1}}, // TOBACCONIST
|
||||
{{ 0, 0, 1},{ 64, 0, 4},{160, 20, 8},{ -1, -1, -1}}, // WEAVER
|
||||
{{ 0, 0, 1},{ 64, 0, 4},{160, 20, 8},{ -1, -1, -1}}, // DISTILLER
|
||||
{{ 0, 0, 1},{ 56, 0, 3},{160, 20, 6},{ -1, -1, -1}}, // FUR_TRADER
|
||||
{{ 64, 0, 3},{120,100, 4},{320,100, 8},{ -1, -1, -1}}, // STOCKADE
|
||||
{{ 52, 0, 1},{120, 50, 8},{240,100, 8},{ -1, -1, -1}}, // ARMORY
|
||||
{{ 52, 0, 1},{ 80, 50, 6},{240,100, 8},{ -1, -1, -1}}, // DOCK
|
||||
{{ 64, 0, 4},{160, 50, 8},{200,100, 10},{ -1, -1, -1}}, // SCHOOLHOUSE
|
||||
{{ 80, 0, 1},{ 80, 20, 1},{ -1, -1, -1},{ -1, -1, -1}}, // WAREHOUSE
|
||||
{{ 64, 0, 1},{ -1, -1, -1},{ -1, -1, -1},{ -1, -1, -1}}, // STABLES
|
||||
{{ 52, 0, 3},{176,100, 8},{ -1, -1, -1},{ -1, -1, -1}}, // CHURCH
|
||||
{{ 80, 0, 1},{120, 50, 4},{ -1, -1, -1},{ -1, -1, -1}}, // PRINTING_PRESS
|
||||
{{160, 50, 1},{ -1, -1, -1},{ -1, -1, -1},{ -1, -1, -1}} // CUSTOM_HOUSE
|
||||
};
|
||||
hammers += amount;
|
||||
int hammersRequired = requiredTable[currentlyBuilding][getBuilding(currentlyBuilding).getLevel() + 1][0];
|
||||
int toolsRequired = requiredTable[currentlyBuilding][getBuilding(currentlyBuilding).getLevel() + 1][1];
|
||||
if ((hammers >= hammersRequired) && (hammersRequired != -1)) {
|
||||
hammers = hammersRequired;
|
||||
if (getGoodsCount(Goods.TOOLS) >= toolsRequired) {
|
||||
//TODO: Adam Smith check for factory level buildings
|
||||
if (toolsRequired > 0) {
|
||||
removeAmountAndTypeOfGoods(Goods.TOOLS, requiredTable[currentlyBuilding][getBuilding(currentlyBuilding).getLevel() + 1][1]);
|
||||
hammers = 0;
|
||||
getBuilding(currentlyBuilding).setLevel(getBuilding(currentlyBuilding).getLevel() + 1);
|
||||
// TODO: some message about building something
|
||||
} else {
|
||||
//TODO: some error about not having enough tools
|
||||
}
|
||||
}
|
||||
} else if (hammersRequired == -1) {
|
||||
//TODO: some error about trying to build a nonexistent building
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hammer count of the colony.
|
||||
* @return The current hammer count of the colony.
|
||||
*/
|
||||
public int getHammers() {
|
||||
return hammers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the bell count of the colony.
|
||||
* @param amount The number of bells to add.
|
||||
*/
|
||||
public void addBells(int amount) {
|
||||
bells += amount;
|
||||
bells -= (getSoL() * getUnitCount()) / 100;
|
||||
if (bells >= ((getUnitCount() + 1) * 50)) {
|
||||
bells = ((getUnitCount() + 1) * 50) * 100;
|
||||
} else if (bells <= 0) {
|
||||
bells = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bell count of the colony.
|
||||
* @return The current bell count of the colony.
|
||||
*/
|
||||
public int getBells() {
|
||||
return bells;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SoL memebership of the colony
|
||||
* @return The current SoL membership of the colony.
|
||||
*/
|
||||
public int getSoL() {
|
||||
int membership = (bells * 2) / (getUnitCount() + 1);
|
||||
if (membership < 0) membership = 0;
|
||||
if (membership > 100) membership = 100;
|
||||
return membership;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Tory memebership of the colony
|
||||
* @return The current Tory membership of the colony.
|
||||
*/
|
||||
public int getTory() {
|
||||
return 100 - getSoL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the production bonus, if any, of the colony.
|
||||
* @return The current production bonus of the colony.
|
||||
*/
|
||||
public int getProductionBonus() {
|
||||
int bonus = 0;
|
||||
//TODO: account for difficulty levels in the 4 and 8below
|
||||
if ((getTory() * getUnitCount()) / 100 > 8) {
|
||||
bonus -= 2;
|
||||
} else if ((getTory() * getUnitCount()) / 100 > 4) {
|
||||
bonus -= 1;
|
||||
}
|
||||
|
||||
if (getSoL() == 100) {
|
||||
bonus += 2;
|
||||
} else if (getSoL() >= 50) {
|
||||
bonus += 1;
|
||||
}
|
||||
|
||||
return bonus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a string representation of the Colony. Currently this method
|
||||
* just returns the name of the <code>Colony</code>, but that may
|
||||
|
@ -452,6 +576,9 @@ public final class Colony extends Settlement implements Location {
|
|||
colonyElement.setAttribute("name", name);
|
||||
colonyElement.setAttribute("owner", owner.getID());
|
||||
colonyElement.setAttribute("tile", tile.getID());
|
||||
colonyElement.setAttribute("hammers", Integer.toString(hammers));
|
||||
colonyElement.setAttribute("bells", Integer.toString(bells));
|
||||
colonyElement.setAttribute("currentlyBuilding", Integer.toString(currentlyBuilding));
|
||||
|
||||
Iterator workLocationIterator = workLocations.iterator();
|
||||
while (workLocationIterator.hasNext()) {
|
||||
|
@ -474,6 +601,9 @@ public final class Colony extends Settlement implements Location {
|
|||
name = colonyElement.getAttribute("name");
|
||||
owner = (Player) getGame().getFreeColGameObject(colonyElement.getAttribute("owner"));
|
||||
tile = (Tile) getGame().getFreeColGameObject(colonyElement.getAttribute("tile"));
|
||||
hammers = Integer.parseInt(colonyElement.getAttribute("hammers"));
|
||||
bells = Integer.parseInt(colonyElement.getAttribute("bells"));
|
||||
currentlyBuilding = Integer.parseInt(colonyElement.getAttribute("currentlyBuilding"));
|
||||
|
||||
NodeList childNodes = colonyElement.getChildNodes();
|
||||
for (int i=0; i<childNodes.getLength(); i++) {
|
||||
|
|
|
@ -234,9 +234,13 @@ public class ColonyTile extends FreeColGameObject implements WorkLocation {
|
|||
}
|
||||
|
||||
if (!(isColonyCenterTile())) {
|
||||
int amount = getUnit().getFarmedPotential(getUnit().getWorkType(), workTile);
|
||||
int amount = getUnit().getFarmedPotential(getUnit().getWorkType(), workTile);
|
||||
if (amount > 0) {
|
||||
amount += colony.getProductionBonus();
|
||||
if (amount < 1) amount = 1;
|
||||
Goods g = new Goods(getGame(), null, getUnit().getWorkType(), amount);
|
||||
g.setLocation(colony);
|
||||
g.setLocation(colony);
|
||||
}
|
||||
} else {
|
||||
int amount1 = workTile.potential(Goods.FOOD);
|
||||
Goods g = new Goods(getGame(), null, Goods.FOOD, amount1);
|
||||
|
|
|
@ -38,7 +38,8 @@ public final class Goods extends FreeColGameObject implements Locatable {
|
|||
MUSKETS = 15,
|
||||
//FISH = 16; //Probably not needed except for graphical purposes -sjm
|
||||
BELLS = 17,
|
||||
CROSSES = 18;
|
||||
CROSSES = 18,
|
||||
HAMMERS = 19;
|
||||
|
||||
public static final int NUMBER_OF_TYPES = 16; // Anything past this point can't be stored -sjm
|
||||
|
||||
|
|
|
@ -829,4 +829,26 @@ public final class InGameInputHandler implements MessageHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendErrorToAll(String message, Player player) {
|
||||
Game game = freeColServer.getGame();
|
||||
|
||||
Iterator enemyPlayerIterator = game.getPlayerIterator();
|
||||
while (enemyPlayerIterator.hasNext()) {
|
||||
ServerPlayer enemyPlayer = (ServerPlayer) enemyPlayerIterator.next();
|
||||
|
||||
if ((player != null) && (player.equals(enemyPlayer))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Element errorElement = Message.createNewRootElement("error");
|
||||
errorElement.setAttribute("message", message);
|
||||
|
||||
enemyPlayer.getConnection().send(errorElement);
|
||||
} catch (IOException e) {
|
||||
logger.warning("Could not send message to: " + enemyPlayer.getName() + " with connection " + enemyPlayer.getConnection());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue