mirror of https://github.com/FreeCol/freecol.git
Ensures that European starting units are not spawned on the same tile.
This commit is contained in:
parent
4f05e70000
commit
e7cecf5e26
|
@ -115,6 +115,17 @@ class EuropeanStartingPositionsGenerator {
|
||||||
return determineStartingTilesWithoutUsingPredeterminedPositions(map, europeanPlayers, playerStartingUnits);
|
return determineStartingTilesWithoutUsingPredeterminedPositions(map, europeanPlayers, playerStartingUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final java.util.Map<Player, Tile> startingPositions = determineStartingTilesUsingMapDefinedPositions(europeanPlayers, playerStartingUnits, game);
|
||||||
|
if (startingPositions.size() < playerStartingUnits.size()) {
|
||||||
|
logger.info("Unable to use map defined starting positions - possibly caused by overlapping nation areas.");
|
||||||
|
return determineStartingTilesWithoutUsingPredeterminedPositions(map, europeanPlayers, playerStartingUnits);
|
||||||
|
}
|
||||||
|
return startingPositions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private java.util.Map<Player, Tile> determineStartingTilesUsingMapDefinedPositions(List<Player> europeanPlayers, java.util.Map<Player, StartingUnits> playerStartingUnits, Game game) {
|
||||||
|
final Specification spec = game.getSpecification();
|
||||||
final int positionType = spec.getInteger(GameOptions.STARTING_POSITIONS);
|
final int positionType = spec.getInteger(GameOptions.STARTING_POSITIONS);
|
||||||
switch (positionType) {
|
switch (positionType) {
|
||||||
case GameOptions.STARTING_POSITIONS_CLASSIC:
|
case GameOptions.STARTING_POSITIONS_CLASSIC:
|
||||||
|
@ -160,9 +171,15 @@ class EuropeanStartingPositionsGenerator {
|
||||||
possibleStartingTiles = startingArea.getTiles();
|
possibleStartingTiles = startingArea.getTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
final int randomIndex = random.nextInt(possibleStartingTiles.size());
|
while (!possibleStartingTiles.isEmpty()) {
|
||||||
final Tile startingTile = possibleStartingTiles.get(randomIndex);
|
final int randomIndex = random.nextInt(possibleStartingTiles.size());
|
||||||
startingTiles.put(player, startingTile);
|
final Tile startingTile = possibleStartingTiles.get(randomIndex);
|
||||||
|
if (!startingTiles.values().contains(startingTile)) {
|
||||||
|
startingTiles.put(player, startingTile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
possibleStartingTiles.remove(randomIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return startingTiles;
|
return startingTiles;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue