9 package micropolisj.engine;
13 import static micropolisj.engine.TileConstants.*;
27 static enum CreateIsland
33 CreateIsland createIsland = CreateIsland.SELDOM;
37 assert engine != null;
39 this.map = engine.
map;
79 void generateMap(
long r)
83 if (createIsland == CreateIsland.SELDOM)
85 if (PRNG.nextInt(100) < 10)
92 if (createIsland == CreateIsland.ALWAYS)
138 final int ISLAND_RADIUS = 18;
142 for (
int y = 0; y < WORLD_Y; y++)
144 for (
int x = 0; x < WORLD_X; x++)
150 for (
int y = 5; y < WORLD_Y - 5; y++)
152 for (
int x = 5; x < WORLD_X - 5; x++)
158 for (
int x = 0; x < WORLD_X - 5; x += 2)
161 mapY =
erand(ISLAND_RADIUS+1);
163 mapY = (WORLD_Y - 10) -
erand(ISLAND_RADIUS+1);
171 for (
int y = 0; y < WORLD_Y - 5; y += 2)
174 mapX =
erand(ISLAND_RADIUS+1);
176 mapX = (WORLD_X - 10) -
erand(ISLAND_RADIUS+1);
180 mapX = (WORLD_X - 6);
187 for (
int y = 0; y < map.length; y++)
189 for (
int x = 0; x < map[y].length; x++)
205 xStart = 40 + PRNG.nextInt(
getWidth() - 79);
206 yStart = 33 + PRNG.nextInt(
getHeight() - 66);
216 lim1 = PRNG.nextInt(11);
218 lim1 = lakeLevel / 2;
220 for (
int t = 0; t < lim1; t++)
222 int x = PRNG.nextInt(
getWidth() - 20) + 10;
223 int y = PRNG.nextInt(
getHeight() - 19) + 10;
224 int lim2 = PRNG.nextInt(13) + 2;
226 for (
int z = 0; z < lim2; z++)
228 mapX = x - 6 + PRNG.nextInt(13);
229 mapY = y - 6 + PRNG.nextInt(13);
231 if (PRNG.nextInt(5) != 0)
241 dir = lastDir = PRNG.nextInt(4);
246 dir = lastDir = lastDir ^ 4;
251 lastDir = PRNG.nextInt(4);
265 r1 = curveLevel + 10;
266 r2 = curveLevel + 100;
272 if (PRNG.nextInt(r1+1) < 10)
278 if (PRNG.nextInt(r2+1) > 90)
282 if (PRNG.nextInt(r2+1) > 90)
301 r1 = curveLevel + 10;
302 r2 = curveLevel + 100;
308 if (PRNG.nextInt(r1+1) < 10)
314 if (PRNG.nextInt(r2+1) > 90)
318 if (PRNG.nextInt(r2+1) > 90)
327 static final char [][] BRMatrix =
new char[][] {
328 { 0, 0, 0, 3, 3, 3, 0, 0, 0 },
329 { 0, 0, 3, 2, 2, 2, 3, 0, 0 },
330 { 0, 3, 2, 2, 2, 2, 2, 3, 0 },
331 { 3, 2, 2, 2, 2, 2, 2, 2, 3 },
332 { 3, 2, 2, 2, 4, 2, 2, 2, 3 },
333 { 3, 2, 2, 2, 2, 2, 2, 2, 3 },
334 { 0, 3, 2, 2, 2, 2, 2, 3, 0 },
335 { 0, 0, 3, 2, 2, 2, 3, 0, 0 },
336 { 0, 0, 0, 3, 3, 3, 0, 0, 0 }
341 for (
int x = 0; x < 9; x++)
343 for (
int y = 0; y < 9; y++)
350 static final char [][] SRMatrix =
new char[][] {
351 { 0, 0, 3, 3, 0, 0 },
352 { 0, 3, 2, 2, 3, 0 },
353 { 3, 2, 2, 2, 2, 3 },
354 { 3, 2, 2, 2, 2, 3 },
355 { 0, 3, 2, 2, 3, 0 },
361 for (
int x = 0; x < 6; x++)
363 for (
int y = 0; y < 6; y++)
370 private void putOnMap(
char mapChar,
int xoff,
int yoff)
375 int xloc = mapX + xoff;
376 int yloc = mapY + yoff;
381 char tmp = map[yloc][xloc];
385 if (tmp == RIVER && mapChar != CHANNEL)
390 map[yloc][xloc] = mapChar;
393 static final char [] REdTab =
new char[] {
394 RIVEDGE + 8, RIVEDGE + 8, RIVEDGE + 12, RIVEDGE + 10,
395 RIVEDGE + 0, RIVER, RIVEDGE + 14, RIVEDGE + 12,
396 RIVEDGE + 4, RIVEDGE + 6, RIVER, RIVEDGE + 8,
397 RIVEDGE + 2, RIVEDGE + 4, RIVEDGE + 0, RIVER
402 for (
int mapY = 0; mapY < map.length; mapY++)
404 for (
int mapX = 0; mapX < map[mapY].length; mapX++)
406 if (map[mapY][mapX] == REDGE)
410 for (
int z = 0; z < 4; z++)
413 int xtem = mapX + DX[z];
414 int ytem = mapY + DY[z];
416 ((map[ytem][xtem] & LOMASK) != DIRT) &&
417 (((map[ytem][xtem] & LOMASK) < WOODS_LOW) ||
418 ((map[ytem][xtem] & LOMASK) > WOODS_HIGH)))
424 char temp = REdTab[bitindex & 15];
425 if ((temp != RIVER) && PRNG.nextInt(2) != 0)
427 map[mapY][mapX] = temp;
439 amount = PRNG.nextInt(101) + 50;
443 amount = treeLevel + 3;
446 for (
int x = 0; x < amount; x++)
448 int xloc = PRNG.nextInt(
getWidth());
462 dis = PRNG.nextInt(151) + 50;
466 dis = PRNG.nextInt(101 + (treeLevel*2)) + 50;
472 for (
int z = 0; z < dis; z++)
474 int dir = PRNG.nextInt(8);
480 if ((map[mapY][mapX] & LOMASK) == DIRT)
482 map[mapY][mapX] = WOODS;
487 static final int [] DIRECTION_TABX =
new int[] { 0, 1, 1, 1, 0, -1, -1, -1 };
488 static final int [] DIRECTION_TABY =
new int[] { -1, -1, 0, 1, 1, 1, 0, -1 };
492 mapX += DIRECTION_TABX[dir];
493 mapY += DIRECTION_TABY[dir];
496 static final int [] DX =
new int[] { -1, 0, 1, 0 };
497 static final int [] DY =
new int[] { 0, 1, 0, -1 };
498 static final char [] TEdTab =
new char[] {
507 for (
int mapY = 0; mapY < map.length; mapY++)
509 for (
int mapX = 0; mapX < map[mapY].length; mapX++)
511 if (isTree(map[mapY][mapX]))
514 for (
int z = 0; z < 4; z++)
517 int xtem = mapX + DX[z];
518 int ytem = mapY + DY[z];
520 isTree(map[ytem][xtem]))
525 char temp = TEdTab[bitindex & 15];
530 if (((mapX + mapY) & 1) != 0)
535 map[mapY][mapX] = temp;
539 map[mapY][mapX] = temp;