5 #define MAX(x,y) ((x)>(y)?(x):(y))
17 #define MAP_FORMAT "world_%03d_%03d"
69 {
"deep_sea",
"0 0 127 "},
71 {
"shallow_sea",
"0 0 255 "},
72 {
"swamp",
"12 161 64 "},
73 {
"deep_swamp",
"155 175 164 "},
74 {
"grass",
"0 255 0 "},
75 {
"desert",
"222 218 135 "},
76 {
"brush",
"1 144 1 "},
77 {
"evergreens",
"0 128 0 "},
78 {
"jungle_1",
"0 176 0 "},
79 {
"tree",
"4 133 01 "},
80 {
"evergreen",
"20 209 0 "},
81 {
"woods",
"4 115 01 "},
82 {
"woods_2",
"1 182 02 "},
83 {
"woods_3",
"4 153 02 "},
84 {
"hills",
"166 160 70 "},
85 {
"hills_rocky",
"166 155 70 "},
86 {
"steppe",
"150 97 34 "},
87 {
"mountain",
"183 190 190 "},
88 {
"mountain2",
"191 196 185 "},
89 {
"mountain4",
"215 215 215 "},
91 {
"beach",
"232 228 165 "},
92 {
"mountain5",
"255 255 255 "},
99 int x,
y,n,
q, nx, ny,r1,r2,ax=0,ay=0, j, k;
107 for (
x=0;
x<mapx;
x++) {
108 for (
y=0;
y<mapy;
y++) {
127 for (n=0; n<(mapx * mapy) / 100; n++) {
131 }
while ( terrain[
x +
y * mapx] ==
None);
134 if (nx > mapx) nx=mapx;
136 if (ny > mapy) ny = mapy;
139 for (
x = nx-40;
x<nx;
x++) {
140 for (
y=ny-40;
y<ny;
y++) {
141 if (terrain[
x +
y * mapx] !=
None)
continue;
146 if ( (
x < (nx -30) ||
y < (ny - 30) ||
x > (nx -10) ||
y > (ny - 10)) &&
147 random() % 2)
continue;
150 terrain[
x +
y * mapx] =
Swamp + (r1 % 2);
156 terrain[
x +
y * mapx] =
Grass + (r1 % 3);
160 terrain[
x +
y * mapx] =
Hills + (r2 % 3);
169 else fprintf(stderr,
"altitude %d did not get filled in?\n",
altitude[
y][
x]);
177 for (
x=0;
x<mapx;
x++) {
178 for (
y=0;
y<mapy;
y++) {
179 if (terrain[
x +
y * mapx] !=
None)
continue;
182 terrain[
x +
y * mapx] =
Swamp + (r1 % 2);
188 terrain[
x +
y * mapx] =
Grass + (r1 % 3);
192 terrain[
x +
y * mapx] =
Hills + (r2 % 3);
202 fprintf(stderr,
"Filled in %d spaces\n",n);
205 fprintf(stderr,
"Warning - generated map does not evenly tile.\n");
213 if ((fp=fopen(
name,
"w"))==NULL) {
214 fprintf(stderr,
"unable to open %s\n",
name);
217 fprintf(fp,
"arch map\n");
218 fprintf(fp,
"name %s\n",
name);
220 fprintf(fp,
"height %d\n",
MAP_SIZE);
222 fprintf(fp,
"outdoor 1\n");
227 fprintf(fp,
"tile_path_1 ");
232 fprintf(fp,
"tile_path_2 ");
237 fprintf(fp,
"tile_path_3 ");
242 fprintf(fp,
"tile_path_4 ");
247 for (
x = 0;
x<50;
x++) {
248 for (
y = 0;
y < 50;
y++) {
249 q = terrain[
x + ax + (
y + ay)* mapx];
251 fprintf(fp,
"x %d\n",
x);
252 fprintf(fp,
"y %d\n",
y);
254 if (
q< -32000)
q = -32000;
255 if (
q > 32000)
q = 32000;
256 fprintf(fp,
"elevation %d\n",
q);
264 fp = fopen(
"cmap",
"w");
265 fprintf(fp,
"P3 %d %d 255\n", mapy, mapx);
266 for (
y=0;
y < mapy;
y++) {
267 for (
x=0;
x < mapx;
x++) {
279 int x,
y, max_x=500, max_y=500, seed, land=300000, npasses=40, newalt, wpasses=50, water=50000;
280 int n, i, j, k,
l,
z, w,
r,
a, write_maps=0;
287 while ((
c = getopt(argc, argv,
"x:y:X:Y:s:l:n:w:p:m"))!=-1) {
292 fprintf(stderr,
"-l must be at least 11\n");
298 water = atoi(optarg);
300 fprintf(stderr,
"-w must be at least 1\n");
306 wpasses = atoi(optarg);
308 fprintf(stderr,
"-w must be at least 1\n");
314 npasses = atoi(optarg);
316 fprintf(stderr,
"-n must be at least 10\n");
322 max_x = atoi(optarg);
326 max_y = atoi(optarg);
346 fprintf(stderr,
"Max X and Y size is %d\n",
MAX_SIZE);
350 fprintf(stderr,
"Making %d X %d map, seed %d, land %d, passes = %d\n", max_x, max_y, seed, land, npasses);
351 fprintf(stderr,
"wpasses =%d, water=%d\n", wpasses, water);
352 fprintf(stderr,
"-x %d -y %d -X %d -Y %d -s %d -p %d -n %d -w %d -l %d\n",
353 max_x, max_y,
startx,
starty, seed, wpasses, npasses, water, land);
357 for (
x=20;
x < max_x-20;
x++)
358 for (
y=20;
y < max_y-20;
y++)
361 for (
x=0;
x<max_x;
x++) {
362 for (
y=0;
y<20;
y++) {
368 for (
y=10;
y<max_y-10;
y++) {
369 for (
x=0;
x<20;
x++) {
377 for (
l=0;
l<npasses;
l++) {
389 n = random()%500+800;
392 if (
l> (npasses * 15) / 20) {
405 fprintf(stderr,
"did not find free space within %d tries\n", tries);
412 for (k=1; k< land ; k++) {
415 case 0:
if (
x<max_x-1)
x++;
else x -= random() % (max_x/2);
break;
416 case 1:
if (
y<max_y-1)
y++;
else y -= random() % (max_y/2);
break;
417 case 2:
if (
x)
x--;
else x+= random() % (max_x/2);
break;
418 case 3:
if (
y)
y--;
else y+= random() % (max_y/2);
break;
421 if (random()%k < 100)
431 for (
l=0;
l<wpasses;
l++) {
433 n = random()%1500-2000;
442 for (k=1; k< water ; k++) {
445 case 0:
if (
x<max_x-1)
x++;
break;
446 case 1:
if (
y<max_y-1)
y++;
break;
447 case 2:
if (
x)
x--;
break;
448 case 3:
if (
y)
y--;
break;
451 if (random()%k < 100)
463 for (
x=2;
x<max_x-2;
x++) {
464 for (
y=2;
y<max_y - 2;
y++) {
473 for (
x=max_x-2;
x>2;
x--) {
474 for (
y=max_y-2;
y>2;
y--) {
493 for (k=0; k<40; k++) {
494 for (
x=2;
x<max_x-2;
x++) {
495 for (
y=2;
y<max_y -2;
y++) {
504 for (
x=max_x-2;
x>2;
x--) {
505 for (
y=max_y-2;
y>2;
y--) {
520 fp = fopen(
"lmap",
"w");
521 lp = fopen(
"pmap",
"w");
522 fprintf(fp,
"P3 %d %d 255\n", max_y, max_x);
523 for (j=0; j < max_x; j++) {
524 for (k=0; k < max_y; k++) {
528 fprintf(fp,
"0 0 127 ");
535 fprintf(fp,
"0 0 192 ");
537 fprintf(fp,
"0 0 255 ");
538 else if (junk < 1000)
539 fprintf(fp,
"0 240 0 ");
540 else if (junk < 2000)
541 fprintf(fp,
"0 220 0 ");
542 else if (junk < 3000)
543 fprintf(fp,
"0 200 0 ");
544 else if (junk < 4000)
545 fprintf(fp,
"0 180 0 ");
546 else if (junk < 5000)
547 fprintf(fp,
"0 160 0 ");
548 else if (junk < 6000)
549 fprintf(fp,
"255 130 71 ");
550 else if (junk < 8000)
551 fprintf(fp,
"238 121 66 ");
552 else if (junk < 10000)
553 fprintf(fp,
"205 104 57 ");
554 else if (junk < 12000)
555 fprintf(fp,
"139 71 38 ");
557 fprintf(fp,
"255 255 255 ");