The map generator option for controlling the number of rivers to be generated now produced different results according to the selected value. Enabled generation of rivers that are only two tiles long (the previous limit was three). Map generator options are no longer stored nor loaded since this causes issues when changing the default options. It might be a good idea to support loading/saving of map generator options using the dialog.

This commit is contained in:
Stian Grenborgen 2023-04-23 15:33:36 +02:00
parent 9981570e24
commit 63fcca2f2a
6 changed files with 20 additions and 15 deletions

View File

@ -4797,12 +4797,12 @@
<!-- Option for setting the number of rivers on the map
The value indicates the number of land tile per river tile -->
<rangeOption id="model.option.riverNumber"
defaultValue="10" localizedLabels="true">
<rangeValue label="verySmall" value="20"/>
defaultValue="30" localizedLabels="true">
<rangeValue label="verySmall" value="5"/>
<rangeValue label="small" value="10"/>
<rangeValue label="medium" value="9"/>
<rangeValue label="large" value="8"/>
<rangeValue label="veryLarge" value="7"/>
<rangeValue label="medium" value="15"/>
<rangeValue label="large" value="20"/>
<rangeValue label="veryLarge" value="40"/>
</rangeOption>
<!-- Option for setting the number of mountains on the map
The value indicates the number of land tile per mountain tile -->

View File

@ -82,7 +82,6 @@ public final class MapGeneratorOptionsDialog extends OptionsDialog {
editable);
if (isEditable()) {
loadDefaultOptions();
// FIXME: The update should be solved by PropertyEvent.
final List<File> mapFiles = FreeColDirectories.getMapFileList();

View File

@ -1238,6 +1238,7 @@ public final class Specification implements OptionContainer {
}
gog.save(gof, null, true);
/*
String mtag = MapGeneratorOptions.TAG;
File mof = FreeColDirectories
.getOptionsFile(FreeColDirectories.MAP_GENERATOR_OPTIONS_FILE_NAME);
@ -1250,6 +1251,7 @@ public final class Specification implements OptionContainer {
mog = getOptionGroup(mtag);
}
mog.save(mof, null, true);
*/
return ret;
}

View File

@ -1300,7 +1300,7 @@ public final class Tile extends UnitLocation implements Named, Ownable {
public boolean isGoodRiverTile(TileImprovementType riverType) {
return riverType.isTileTypeAllowed(getType())
// check the river source/spring is not too close to the ocean
&& all(getSurroundingTiles(1, 2), Tile::isLand);
&& all(getSurroundingTiles(1, 1), Tile::isLand);
}
/**

View File

@ -110,7 +110,7 @@ public class MapGeneratorOptions {
/** Option for enabling generation of great rivers. */
public static final String ENABLE_GREAT_RIVERS = "mapGeneratorOptions.enableGreatRivers";
/** Option for setting the number of rivers on the map. */
/** Option for setting the number of river tiles on the map as a percentage of all possible tiles for a river. */
public static final String RIVER_NUMBER
= "model.option.riverNumber";

View File

@ -561,10 +561,7 @@ public class TerrainGenerator {
final Specification spec = game.getSpecification();
final OptionGroup mapOptions = game.getMapGeneratorOptions();
List<ServerRegion> result = new ArrayList<>();
final TileImprovementType riverType
= spec.getTileImprovementType("model.improvement.river");
final int number = getApproximateLandCount(game)
/ mapOptions.getRange(MapGeneratorOptions.RIVER_NUMBER);
final TileImprovementType riverType = spec.getTileImprovementType("model.improvement.river");
HashMap<Tile, River> riverMap = new HashMap<>();
List<River> rivers = new ArrayList<>();
@ -573,11 +570,19 @@ public class TerrainGenerator {
t -> tiles.add(t));
randomShuffle(logger, "Randomize river tiles", tiles, this.random);
final int absoluteMaximumRiverTiles = map.getTileList(t -> riverType.isTileTypeAllowed(t.getType())).size();
final int softMaximumRiverTiles = (absoluteMaximumRiverTiles * mapOptions.getRange(MapGeneratorOptions.RIVER_NUMBER)) / 100;
int counter = 0;
for (Tile tile : tiles) {
// Any river here yet?
if (riverMap.get(tile) != null)
if (riverMap.get(tile) != null) {
continue;
}
if (riverMap.size() > softMaximumRiverTiles) {
break;
}
ServerRegion riverRegion = new ServerRegion(game, RegionType.RIVER);
River river = new River(map, riverMap, riverRegion, this.random);
@ -586,12 +591,11 @@ public class TerrainGenerator {
river.getLength(), "\n");
result.add(riverRegion);
rivers.add(river);
if (++counter >= number) break;
} else {
lb.add("Failed to generate river at " + tile + ".\n");
}
}
lb.add("Created ", counter, " rivers of maximum ", number, "\n");
lb.add("Created ", counter, " rivers of maximum ", softMaximumRiverTiles, "\n");
for (River river : rivers) {
ServerRegion region = river.getRegion();