]> git.pond.sub.org Git - empserver/blob - scripts/mapper/over.awk
Fix mapper to work with current code
[empserver] / scripts / mapper / over.awk
1 #!/bin/awk -f
2
3 # Parse report and generate pbmtext commands for each country
4 # Now generates new positions as an average of all sectors.
5
6 BEGIN {
7   if (scale=="") scale=1;
8   FS="[ \t\n,]+";
9 }
10
11 /^World size is [0-9]+ by [0-9]+\./ {
12   width = $4;
13   height= $6;
14   system("ppmmake white " (width+1)*scale " " height*scale " | ppmtopgm | pgmtopbm >over.pbm");
15 }
16
17 /.*#.*name.*tech.*research.*education.*happiness.*capital/ {
18   getline;
19   while (NF>4) {
20     if ($2>0 && $2<90) {
21       name[$2]=substr($0,8,15);
22       capx[$2]= $(NF-1);
23       capy[$2]= $NF;
24     }
25     getline;
26   }
27 }
28
29 /own +sect/ {
30   getline;
31   while (NF>2) {
32     if ($2 in name) {
33       if (!count[$2]) {
34         cx[$2] = $3;
35         cy[$2] = $4;
36       } else {
37         dx = $3 - cx[$2];
38         dy = $4 - cy[$2];
39         if (dx>=width/2) dx -= width;
40         if (dy>=height/2) dy -= height;
41         if (dx<-width/2) dx += width;
42         if (dy<-height/2) dy += height;
43         cx[$2] += dx/(1+count[$2]);
44         cy[$2] += dy/(1+count[$2]);
45       }
46       count[$2]++;
47     }
48     getline;
49   }
50 }
51
52
53 END {
54   for (i in name) {
55     if (count[i]) {
56       system("pbmtext \"" name[i] "\" | pnmcrop >text.pbm");
57       system("pnmfile text.pbm >text.size");
58       getline < "text.size";
59       close("text.size");
60       h=$NF;
61       w=$(NF-2);
62       x = cx[i] + width/2;
63       y = cy[i] + height/2;
64
65       while (x<0) x += width;
66       while (y<0) y += height;
67       while (x>=width) x -= width;
68       while (y>=height) y -= height;
69
70       x = int(x*scale);
71       y = int(y*scale);
72
73       x -= w/2;
74       y -= h/2;
75       if (x<0) x=0;
76       if (y<0) y=0;
77       if (x+w>=width*scale) x=width*scale-w-1;
78       if (y+h>=height*scale) y=height*scale-h-1;
79
80
81       system("pnmpaste text.pbm " x " " y " over.pbm > over2.pbm");
82       system("cp over2.pbm over.pbm");
83     }
84   }
85 }