Crossfire Server, Branches 1.12  R18729
maps.c
Go to the documentation of this file.
1 /* $Id: maps.c 11578 2009-02-23 22:02:27Z lalo $ */
2 
3 /* This program will generate ppm files from each of the weathermaps.
4  Mostly for debugging, but curious DM's might find it useful to see
5  the weather.
6 */
7 
8 #include <stdio.h>
9 #ifndef MIN
10 #define MIN(x, y) ((x) < (y) ? (x) : (y))
11 #endif
12 #ifndef MAX
13 #define MAX(x, y) ((x) > (y) ? (x) : (y))
14 #endif
15 
16 int main(void) {
17  int map[100][100];
18  int x, y;
19  int n, i, j, k, l, z, w, r, a;
20  FILE *fp, *lp;
21  int junk;
22  char fn[6];
23 
24  sprintf(fn, "winddirmap");
25  lp = fopen(fn, "r");
26  fp = fopen("winddirmap.ppm", "w");
27  fprintf(fp, "P3 %d %d 255\n", 100, 100);
28  for (j = 0; j < 100; j++) {
29  for (k = 0; k < 100; k++) {
30  fscanf(lp, "%d ", &map[j][k]);
31  junk = map[j][k];
32  fprintf(lp, "%d ", map[j][k]);
33  switch (junk) {
34  case 0: fprintf(fp, "255 255 255 "); break;
35  case 1: fprintf(fp, "0 0 0 "); break;
36  case 2: fprintf(fp, "0 0 127 "); break;
37  case 3: fprintf(fp, "0 0 255 "); break;
38  case 4: fprintf(fp, "127 127 255 "); break;
39  case 5: fprintf(fp, "127 127 127 "); break;
40  case 6: fprintf(fp, "127 255 127 "); break;
41  case 7: fprintf(fp, "0 255 0 "); break;
42  case 8: fprintf(fp, "0 127 0 "); break;
43  }
44  fprintf(fp, "\n");
45  fscanf(lp, "\n");
46  }
47  }
48  fclose(fp);
49  fclose(lp);
50 
51  sprintf(fn, "pressuremap");
52  lp = fopen(fn, "r");
53  fp = fopen("pressuremap.ppm", "w");
54  fprintf(fp, "P3 %d %d 255\n", 100, 100);
55  for (j = 0; j < 100; j++) {
56  for (k = 0; k < 100; k++) {
57  fscanf(lp, "%d ", &map[j][k]);
58  junk = map[j][k];
59  fprintf(lp, "%d ", map[j][k]);
60  if (junk < 1000)
61  fprintf(fp, "0 0 %d ", 255-(1000-junk)*3);
62  else
63  fprintf(fp, "0 %d 0 ", 255+(1000-junk)*3);
64  fprintf(fp, "\n");
65  fscanf(lp, "\n");
66  }
67  }
68  fclose(fp);
69  fclose(lp);
70 
71  sprintf(fn, "windspeedmap");
72  lp = fopen(fn, "r");
73  fp = fopen("windspeedmap.ppm", "w");
74  fprintf(fp, "P3 %d %d 255\n", 100, 100);
75  for (j = 0; j < 100; j++) {
76  for (k = 0; k < 100; k++) {
77  fscanf(lp, "%d ", &map[j][k]);
78  junk = map[j][k];
79  fprintf(lp, "%d ", map[j][k]);
80  fprintf(fp, "0 %d 0 ", junk*5);
81  fprintf(fp, "\n");
82  fscanf(lp, "\n");
83  }
84  }
85  fclose(fp);
86  fclose(lp);
87 
88  sprintf(fn, "humidmap");
89  lp = fopen(fn, "r");
90  fp = fopen("humidmap.ppm", "w");
91  fprintf(fp, "P3 %d %d 255\n", 100, 100);
92  for (j = 0; j < 100; j++) {
93  for (k = 0; k < 100; k++) {
94  fscanf(lp, "%d ", &map[j][k]);
95  junk = map[j][k];
96  fprintf(lp, "%d ", map[j][k]);
97  fprintf(fp, "0 0 %d ", 255-(junk*2));
98  fprintf(fp, "\n");
99  fscanf(lp, "\n");
100  }
101  }
102  fclose(fp);
103  fclose(lp);
104 
105  sprintf(fn, "temperaturemap");
106  lp = fopen(fn, "r");
107  fp = fopen("temperaturemap.ppm", "w");
108  fprintf(fp, "P3 %d %d 255\n", 100, 100);
109  for (j = 0; j < 100; j++) {
110  for (k = 0; k < 100; k++) {
111  fscanf(lp, "%d ", &map[j][k]);
112  junk = map[j][k];
113  fprintf(lp, "%d ", map[j][k]);
114  if (junk < 0)
115  fprintf(fp, "0 0 %d ", 255+junk*5);
116  else
117  fprintf(fp, "0 %d 0 ", junk*5);
118  fprintf(fp, "\n");
119  fscanf(lp, "\n");
120  }
121  }
122  fclose(fp);
123  fclose(lp);
124 
125  sprintf(fn, "skymap");
126  lp = fopen(fn, "r");
127  if (lp == NULL)
128  exit(0);
129  fp = fopen("skymap.ppm", "w");
130  fprintf(fp, "P3 %d %d 255\n", 100, 100);
131  for (j = 0; j < 100; j++) {
132  for (k = 0; k < 100; k++) {
133  fscanf(lp, "%d ", &map[j][k]);
134  junk = map[j][k];
135  fprintf(lp, "%d ", map[j][k]);
136  switch (junk) {
137  case 0: fprintf(fp, "0 0 255 "); break;
138  case 1: fprintf(fp, "230 230 230 "); break;
139  case 2: fprintf(fp, "170 170 170 "); break;
140  case 3: fprintf(fp, "120 120 120 "); break;
141  case 4: fprintf(fp, "80 80 80 "); break;
142  case 5: fprintf(fp, "40 40 40 "); break;
143  case 6: fprintf(fp, "10 10 10 "); break;
144  case 7: fprintf(fp, "0 255 0 "); break;
145  case 8: fprintf(fp, "255 0 0 "); break;
146  case 13: fprintf(fp, "230 230 255 "); break;
147  case 14: fprintf(fp, "170 170 255 "); break;
148  case 15: fprintf(fp, "120 120 255 "); break;
149  case 16: fprintf(fp, "80 80 255 "); break;
150  }
151  fprintf(fp, "\n");
152  fscanf(lp, "\n");
153  }
154  }
155  fclose(fp);
156  fclose(lp);
157 }
int main(void)
Definition: maps.c:16