]> git.pond.sub.org Git - empserver/blob - scripts/mapper/pgmmap.awk
Import of Empire 4.2.12
[empserver] / scripts / mapper / pgmmap.awk
1 #!/bin/awk -f
2
3 #
4 #       Convert a deity dump file into a Portable GreyMap of country numbers
5 #
6
7 function abs(x) {
8   if (x>0) return x;
9   return -x;
10 }
11
12 /own +sect/ {
13   getline;
14   while (NF>2) {
15     own[$2]=$1;
16     des[$2]=substr($3,0,1);
17     if ($1>max) max=$1;
18     getline;
19   }
20 }
21
22 /own x y des/ {
23   getline;
24   while (NF>2) {
25     own[$2,$3]=$1;
26     des[$2,$3]=$4;
27     if ($1>max) max=$1;
28     if ($2 < left) left=$2;
29     if ($2 > right) right=$2;
30     if ($3 < top) top=$3;
31     if ($3 > bottom) bottom=$3;
32     getline;
33   }
34 }
35
36 /^World size is [0-9]+ by [0-9]+./ {
37   width = $4;
38   height= $6 + 0;
39   left=-width/2;
40   right=width/2-1;
41   top= -height/2;
42   bottom = height/2-1;
43 }
44
45 END {
46   printf("P2\n%d %d\n255\n",right-left+2,bottom-top+1);
47   for (y=top;y<=bottom;y++) {
48     printf("\n");
49     if (y%2) {
50       color=own[right,y];
51       if (color==0 && des[right,y]!=".") color=254;
52       printf("%d\n",color);
53     }
54     for (x=left + abs(y%2);x<=right;x+=2) {
55       color=own[x,y];
56       if (color==0 && des[x,y]!=".") color=254;
57       printf("%d %d\n",color,color);
58     }
59     if (!(y%2)) {
60       color=own[left,y];
61       if (color==0 && des[left,y]!=".") color=254;
62       printf("%d\n",color);
63     }
64   }
65 }
66