Adding support for buying nation specific units in Europe.

This commit is contained in:
Stian Grenborgen 2022-09-17 08:55:29 +02:00
parent 9f1e47af60
commit dd2094cae1
4 changed files with 17 additions and 8 deletions

View File

@ -39,6 +39,6 @@ public final class PurchasePanel extends NewUnitPanel {
super(freeColClient, new MigLayout("wrap 2", "[sg]", ""),
Messages.message("purchasePanel.clickOn"),
freeColClient.getGame().getSpecification()
.getUnitTypesPurchasedInEurope());
.getUnitTypesPurchasedInEurope(freeColClient.getMyPlayer()));
}
}

View File

@ -39,6 +39,6 @@ public final class TrainPanel extends NewUnitPanel {
super(freeColClient, new MigLayout("wrap 3", "[sg]", ""),
Messages.message("trainPanel.clickOn"),
freeColClient.getGame().getSpecification()
.getUnitTypesTrainedInEurope());
.getUnitTypesTrainedInEurope(freeColClient.getMyPlayer()));
}
}

View File

@ -1933,19 +1933,25 @@ public final class Specification implements OptionContainer {
/**
* Gets the unit types that can be trained in Europe.
*
* @param player The player that want to purchase the unit.
* @return A list of Europe-trainable {@code UnitType}s.
*/
public List<UnitType> getUnitTypesTrainedInEurope() {
return unitTypesTrainedInEurope;
public List<UnitType> getUnitTypesTrainedInEurope(Player player) {
return unitTypesTrainedInEurope.stream()
.filter(type -> type.isAvailableTo(player))
.collect(Collectors.toList());
}
/**
* Get the unit types that can be purchased in Europe.
* Get the unit types that can be purchased in Europe for a given player.
*
* @param player The player that want to purchase the unit.
* @return A list of Europe-purchasable {@code UnitType}s.
*/
public List<UnitType> getUnitTypesPurchasedInEurope() {
return unitTypesPurchasedInEurope;
public List<UnitType> getUnitTypesPurchasedInEurope(Player player) {
return unitTypesPurchasedInEurope.stream()
.filter(type -> type.isAvailableTo(player))
.collect(Collectors.toList());
}
/**

View File

@ -3802,6 +3802,9 @@ public final class InGameController extends Controller {
+ serverPlayer.getGold() + " < " + price
+ ") to train " + type);
}
if (!type.isAvailableTo(serverPlayer)) {
return serverPlayer.clientError("Unit type is not available for the player.");
}
final Game game = getGame();
final Specification spec = game.getSpecification();