// store
pnames[i] = text;
}
// create new scenario
ServerScenario scenario = new ServerScenario();
scenario.createEmptyMap(rows, columns);
scenario.setTitle(titleTextField.getText());
// check that if terrain_underlay is ocean also terrain_overlay is ocean
for (int i = 0; i < chunk; i++) {
if ((terrain_underlay[i] == 5) != (terrain_overlay[i] == 0)) {
updateStatus("terrain underlay and overlay differ in ocean description, will stop");
return;
}
}
// detect countries
Set<Integer> uc = new HashSet<>(20);
for (int i = 0; i < chunk; i++) {
if (terrain_underlay[i] != 5) {
uc.add(countries[i]);
}
}
updateStatus(String.format("contains %d nations", uc.size()));
// put countries into list and get names
XList<Nation> nations = scenario.getNations();
Map<Integer, Nation> nmap = new HashMap<>(30);
String[] nationNames = nationNamesTextField.getText().split(", ");
String[] nationColors = nationColorsTextField.getText().split(", ");
int id = 1;
for (Integer i : uc) {
String name = String.format("Nation %2d", id);
if (id <= nationNames.length) {
name = nationNames[id-1];
}
Nation nation = new Nation();
nation.setProperty(Nation.KEY_NAME, name);
if (id <= nationColors.length) {
nation.setProperty(Nation.KEY_COLOR, nationColors[id-1]);
}
nmap.put(i, nation);
nations.addElement(nation);
id++;
}
// detect provinces
Set<Integer> up = new HashSet<>(1_000);
for (int i = 0; i < chunk; i++) {
if (terrain_underlay[i] != 5) {
up.add(provinces[i]);
}
}
updateStatus(String.format("contains %d provinces", up.size()));
// generate province names
Map<Integer, String> pmap = new HashMap<>(Np);
id = 1;
for (Integer i : up) {
// String name = String.format("Province %d", id);
String name = pnames[i];
pmap.put(i, name);
id++;
}
// add provinces to scenario
Map<Integer, Province> ppmap = new HashMap<>(1_000);
Set<Integer> processed = new HashSet<>(1_000);
for (int i = 0; i < chunk; i++) {
if (terrain_underlay[i] != 5) {
if (!processed.contains(provinces[i])) {
Nation nation = nmap.get(countries[i]);
String name = pmap.get(provinces[i]);
Province province = scenario.createProvince(name);
nation.addProvince(province);
ppmap.put(provinces[i], province);
processed.add(provinces[i]);
}
}
}
// random number generator for scrubforest
Random rnd = new Random(42);
// set terrain
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
MapPosition pos = new MapPosition(row, column);
Tile tile = scenario.getTileAt(pos);
int i = column + row * columns;
// set terrains
// sea
if (terrain_underlay[i] == 5) {