mirror of https://github.com/FreeCol/freecol.git
Extended negotiations to cover trade.
This commit is contained in:
parent
d92c34b68c
commit
fcadf29772
|
@ -893,7 +893,8 @@ public final class InGameController implements NetworkConstants {
|
|||
scoutForeignColony(unit, direction);
|
||||
break;
|
||||
case Unit.ENTER_SETTLEMENT_WITH_CARRIER_AND_GOODS:
|
||||
tradeWithSettlement(unit, direction);
|
||||
negotiate(unit, direction);
|
||||
//tradeWithSettlement(unit, direction);
|
||||
break;
|
||||
case Unit.EXPLORE_LOST_CITY_RUMOUR:
|
||||
exploreLostCityRumour(unit, direction);
|
||||
|
@ -937,11 +938,20 @@ public final class InGameController implements NetworkConstants {
|
|||
Map map = freeColClient.getGame().getMap();
|
||||
Settlement settlement = map.getNeighbourOrNull(direction, unit.getTile()).getSettlement();
|
||||
|
||||
Element spyElement = Message.createNewRootElement("spySettlement");
|
||||
spyElement.setAttribute("unit", unit.getID());
|
||||
spyElement.setAttribute("direction", String.valueOf(direction));
|
||||
Element reply = freeColClient.getClient().ask(spyElement);
|
||||
if (reply != null) {
|
||||
NodeList childNodes = reply.getChildNodes();
|
||||
settlement.readFromXMLElement((Element) childNodes.item(0));
|
||||
}
|
||||
|
||||
DiplomaticTrade agreement = freeColClient.getCanvas().showNegotiationDialog(unit, settlement, null);
|
||||
if (agreement != null) {
|
||||
unit.setMovesLeft(0);
|
||||
String nation = agreement.getRecipient().getNationAsString();
|
||||
Element reply = null;
|
||||
reply = null;
|
||||
|
||||
do {
|
||||
Element diplomaticElement = Message.createNewRootElement("diplomaticTrade");
|
||||
|
@ -984,7 +994,7 @@ public final class InGameController implements NetworkConstants {
|
|||
Colony colony = game.getMap().getNeighbourOrNull(direction,
|
||||
unit.getTile()).getColony();
|
||||
|
||||
Element spyElement = Message.createNewRootElement("spyColony");
|
||||
Element spyElement = Message.createNewRootElement("spySettlement");
|
||||
spyElement.setAttribute("unit", unit.getID());
|
||||
spyElement.setAttribute("direction", String.valueOf(direction));
|
||||
Element reply = freeColClient.getClient().ask(spyElement);
|
||||
|
|
|
@ -151,7 +151,7 @@ tradeItem.stance=Stance
|
|||
tradeItem.unit=Unit
|
||||
negotiationDialog.offer=Offer
|
||||
negotiationDialog.demand=Demand
|
||||
negotiationDialog.summary=This feature is still under development. Don't expect it to work yet.\n\nThe %nation% offer %offers% in return for %demands%.
|
||||
negotiationDialog.summary=The %nation% offer %offers% in return for %demands%.
|
||||
negotiationDialog.accept=Accept
|
||||
negotiationDialog.cancel=Cancel
|
||||
negotiationDialog.send=Send
|
||||
|
|
|
@ -179,17 +179,11 @@ public final class NegotiationDialog extends FreeColDialog implements ActionList
|
|||
|
||||
updateSummary();
|
||||
|
||||
List<Goods> tradeGoods = null;
|
||||
if (unit.isCarrier()) {
|
||||
tradeGoods = unit.getGoodsContainer().getGoods();
|
||||
}
|
||||
|
||||
|
||||
stance = new StanceTradeItemPanel(this, player, otherPlayer);
|
||||
goldDemand = new GoldTradeItemPanel(this, otherPlayer, foreignGold);
|
||||
goldOffer = new GoldTradeItemPanel(this, player, player.getGold());
|
||||
goodsDemand = new GoodsTradeItemPanel(this, otherPlayer, tradeGoods);
|
||||
goodsOffer = new GoodsTradeItemPanel(this, player, tradeGoods);
|
||||
goodsDemand = new GoodsTradeItemPanel(this, otherPlayer, settlement.getGoodsContainer().getGoods());
|
||||
goodsOffer = new GoodsTradeItemPanel(this, player, unit.getGoodsContainer().getGoods());
|
||||
colonyDemand = new ColonyTradeItemPanel(this, otherPlayer);
|
||||
colonyOffer = new ColonyTradeItemPanel(this, player);
|
||||
/** TODO: UnitTrade
|
||||
|
@ -197,7 +191,7 @@ public final class NegotiationDialog extends FreeColDialog implements ActionList
|
|||
unitOffer = new UnitTradeItemPanel(this, player);
|
||||
*/
|
||||
|
||||
int numberOfTradeItems = 5;
|
||||
int numberOfTradeItems = 4;
|
||||
int extraRows = 2; // headline and buttons
|
||||
|
||||
int[] widths = {200, 10, 300, 10, 200};
|
||||
|
@ -223,11 +217,13 @@ public final class NegotiationDialog extends FreeColDialog implements ActionList
|
|||
add(goldOffer, higConst.rc(row, offerColumn));
|
||||
add(summary, higConst.rcwh(row, summaryColumn, 1, 5));
|
||||
row += 2;
|
||||
add(goodsDemand, higConst.rc(row, demandColumn));
|
||||
add(goodsOffer, higConst.rc(row, offerColumn));
|
||||
row += 2;
|
||||
add(colonyDemand, higConst.rc(row, demandColumn));
|
||||
add(colonyOffer, higConst.rc(row, offerColumn));
|
||||
if (unit.isCarrier()) {
|
||||
add(goodsDemand, higConst.rc(row, demandColumn));
|
||||
add(goodsOffer, higConst.rc(row, offerColumn));
|
||||
} else {
|
||||
add(colonyDemand, higConst.rc(row, demandColumn));
|
||||
add(colonyOffer, higConst.rc(row, offerColumn));
|
||||
}
|
||||
row += 2;
|
||||
/** TODO: UnitTrade
|
||||
add(unitDemand, higConst.rc(row, demandColumn));
|
||||
|
@ -323,7 +319,8 @@ public final class NegotiationDialog extends FreeColDialog implements ActionList
|
|||
new String[][] {
|
||||
{"%colony%", ((ColonyTradeItem) item).getColony().getName()}});
|
||||
} else if (item instanceof GoodsTradeItem) {
|
||||
description = ((GoodsTradeItem) item).getGoods().getName();
|
||||
description = String.valueOf(((GoodsTradeItem) item).getGoods().getAmount()) + " " +
|
||||
((GoodsTradeItem) item).getGoods().getName();
|
||||
} else if (item instanceof UnitTradeItem) {
|
||||
description = ((UnitTradeItem) item).getUnit().getName();
|
||||
}
|
||||
|
@ -494,6 +491,10 @@ public final class NegotiationDialog extends FreeColDialog implements ActionList
|
|||
|
||||
private void updateColonyBox() {
|
||||
|
||||
if (!player.isEuropean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove all action listeners, so the update has no effect (except
|
||||
// updating the list).
|
||||
ActionListener[] listeners = colonyBox.getActionListeners();
|
||||
|
|
|
@ -874,9 +874,10 @@ public class Unit extends FreeColGameObject implements Location, Locatable, Owna
|
|||
* need to be a {@link #isCarrier() carrier} and have goods onboard.
|
||||
*/
|
||||
public boolean canTradeWith(Settlement settlement) {
|
||||
return (isCarrier() && goodsContainer.getGoodsCount() > 0
|
||||
&& getOwner().getStance(settlement.getOwner()) != Player.WAR && ((settlement instanceof IndianSettlement) || getOwner()
|
||||
.hasFather(FoundingFather.JAN_DE_WITT)));
|
||||
return (isCarrier() && goodsContainer.getGoodsCount() > 0 &&
|
||||
getOwner().getStance(settlement.getOwner()) != Player.WAR &&
|
||||
((settlement instanceof IndianSettlement) ||
|
||||
getOwner().hasFather(FoundingFather.JAN_DE_WITT)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -403,9 +403,9 @@ public final class InGameInputHandler extends InputHandler implements NetworkCon
|
|||
return selectFromFountainYouth(connection, element);
|
||||
}
|
||||
});
|
||||
register("spyColony", new NetworkRequestHandler() {
|
||||
register("spySettlement", new NetworkRequestHandler() {
|
||||
public Element handle(Connection connection, Element element) {
|
||||
return spyColony(connection, element);
|
||||
return spySettlement(connection, element);
|
||||
}
|
||||
});
|
||||
register("abandonColony", new NetworkRequestHandler() {
|
||||
|
@ -666,7 +666,7 @@ public final class InGameInputHandler extends InputHandler implements NetworkCon
|
|||
}
|
||||
|
||||
/**
|
||||
* Handles an "spyColony"-message from a client.
|
||||
* Handles an "spySettlement"-message from a client.
|
||||
*
|
||||
* @param connection The connection the message came from.
|
||||
* @param spyElement The element containing the request.
|
||||
|
@ -675,7 +675,7 @@ public final class InGameInputHandler extends InputHandler implements NetworkCon
|
|||
* @exception IllegalStateException If the request is not accepted by the
|
||||
* model.
|
||||
*/
|
||||
private Element spyColony(Connection connection, Element spyElement) {
|
||||
private Element spySettlement(Connection connection, Element spyElement) {
|
||||
FreeColServer freeColServer = getFreeColServer();
|
||||
ServerPlayer player = freeColServer.getPlayer(connection);
|
||||
// Get parameters:
|
||||
|
@ -697,14 +697,18 @@ public final class InGameInputHandler extends InputHandler implements NetworkCon
|
|||
throw new IllegalArgumentException("Could not find tile in direction " + direction + " from unit with ID "
|
||||
+ spyElement.getAttribute("unit"));
|
||||
}
|
||||
Colony colony = newTile.getColony();
|
||||
if (colony == null) {
|
||||
throw new IllegalArgumentException("There is no colony in direction " + direction + " from unit with ID "
|
||||
Settlement settlement = newTile.getSettlement();
|
||||
if (settlement == null) {
|
||||
throw new IllegalArgumentException("There is no settlement in direction " + direction + " from unit with ID "
|
||||
+ spyElement.getAttribute("unit"));
|
||||
}
|
||||
|
||||
Element reply = Message.createNewRootElement("foreignColony");
|
||||
reply.appendChild(colony.toXMLElement(player, reply.getOwnerDocument(), true, false));
|
||||
if (settlement instanceof Colony) {
|
||||
reply.appendChild(((Colony) settlement).toXMLElement(player, reply.getOwnerDocument(), true, false));
|
||||
} else if (settlement instanceof IndianSettlement) {
|
||||
reply.appendChild(((IndianSettlement) settlement).toXMLElement(player, reply.getOwnerDocument(), true, false));
|
||||
}
|
||||
for(Unit foreignUnit : newTile.getUnitList()) {
|
||||
reply.appendChild(foreignUnit.toXMLElement(player, reply.getOwnerDocument(), true, false));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue