|
|
1 | |
1 | /* |
2 | /* |
2 | * static char *rcsid_weather_c = |
3 | * static char *rcsid_weather_c = |
3 | * "$Id: weather.C,v 1.4 2006/09/08 04:52:20 pippijn Exp $"; |
4 | * "$Id: weather.C,v 1.6 2006/09/14 21:16:13 root Exp $"; |
4 | */ |
5 | */ |
|
|
6 | |
5 | /* |
7 | /* |
6 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
7 | |
9 | |
8 | Copyright (C) 2002 Tim Rightnour |
10 | Copyright (C) 2002 Tim Rightnour |
9 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
… | |
… | |
30 | |
32 | |
31 | #include <global.h> |
33 | #include <global.h> |
32 | #include <tod.h> |
34 | #include <tod.h> |
33 | #include <map.h> |
35 | #include <map.h> |
34 | #ifndef __CEXTRACT__ |
36 | #ifndef __CEXTRACT__ |
35 | #include <sproto.h> |
37 | # include <sproto.h> |
36 | #endif |
38 | #endif |
37 | |
39 | |
38 | extern unsigned long todtick; |
40 | extern unsigned long todtick; |
39 | extern weathermap_t **weathermap; |
41 | extern weathermap_t **weathermap; |
40 | |
42 | |
41 | static void dawn_to_dusk(const timeofday_t *tod); |
43 | static void dawn_to_dusk (const timeofday_t * tod); |
42 | static void write_skymap(void); |
44 | static void write_skymap (void); |
43 | static void write_pressuremap(void); |
45 | static void write_pressuremap (void); |
44 | static void read_pressuremap(void); |
46 | static void read_pressuremap (void); |
45 | static void init_pressure(void); |
47 | static void init_pressure (void); |
46 | static void write_winddirmap(void); |
48 | static void write_winddirmap (void); |
47 | static void read_winddirmap(void); |
49 | static void read_winddirmap (void); |
48 | static void write_windspeedmap(void); |
50 | static void write_windspeedmap (void); |
49 | static void read_windspeedmap(void); |
51 | static void read_windspeedmap (void); |
50 | static void init_wind(void); |
52 | static void init_wind (void); |
51 | static void write_gulfstreammap(void); |
53 | static void write_gulfstreammap (void); |
52 | static void read_gulfstreammap(void); |
54 | static void read_gulfstreammap (void); |
53 | static void init_gulfstreammap(void); |
55 | static void init_gulfstreammap (void); |
54 | static void write_humidmap(void); |
56 | static void write_humidmap (void); |
55 | static void read_humidmap(void); |
57 | static void read_humidmap (void); |
56 | static void write_elevmap(void); |
58 | static void write_elevmap (void); |
57 | static void read_elevmap(void); |
59 | static void read_elevmap (void); |
58 | static void write_watermap(void); |
60 | static void write_watermap (void); |
59 | static void read_watermap(void); |
61 | static void read_watermap (void); |
60 | static void init_humid_elev(void); |
62 | static void init_humid_elev (void); |
61 | static void write_temperaturemap(void); |
63 | static void write_temperaturemap (void); |
62 | static void read_temperaturemap(void); |
64 | static void read_temperaturemap (void); |
63 | static void init_temperature(void); |
65 | static void init_temperature (void); |
64 | static void write_rainfallmap(void); |
66 | static void write_rainfallmap (void); |
65 | static void read_rainfallmap(void); |
67 | static void read_rainfallmap (void); |
66 | static void init_rainfall(void); |
68 | static void init_rainfall (void); |
67 | static void init_weatheravoid (weather_avoids_t wa[]); |
69 | static void init_weatheravoid (weather_avoids_t wa[]); |
68 | static void perform_weather(void); |
70 | static void perform_weather (void); |
69 | static object *avoid_weather(int *av, mapstruct *m, int x, int y, int *gs, int grow); |
71 | static object *avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow); |
70 | static void calculate_temperature(mapstruct *m, int wx, int wy); |
72 | static void calculate_temperature (mapstruct *m, int wx, int wy); |
71 | static void let_it_snow(mapstruct *m, int wx, int wy); |
73 | static void let_it_snow (mapstruct *m, int wx, int wy); |
72 | static void singing_in_the_rain(mapstruct *m, int wx, int wy); |
74 | static void singing_in_the_rain (mapstruct *m, int wx, int wy); |
73 | static void plant_a_garden(mapstruct *m, int wx, int wy); |
75 | static void plant_a_garden (mapstruct *m, int wx, int wy); |
74 | static void change_the_world(mapstruct *m, int wx, int wy); |
76 | static void change_the_world (mapstruct *m, int wx, int wy); |
|
|
77 | |
75 | //static void feather_map(mapstruct *m, int wx, int wy); |
78 | //static void feather_map(mapstruct *m, int wx, int wy); |
76 | static const char *weathermap_to_worldmap_corner(int wx, int wy, int *x, int *y, int dir); |
79 | static const char *weathermap_to_worldmap_corner (int wx, int wy, int *x, int *y, int dir); |
77 | static int polar_distance(int x, int y, int equator); |
80 | static int polar_distance (int x, int y, int equator); |
78 | static void update_humid(void); |
81 | static void update_humid (void); |
79 | static int humid_tile(int x, int y); |
82 | static int humid_tile (int x, int y); |
80 | static void temperature_calc(int x, int y, const timeofday_t *tod); |
83 | static void temperature_calc (int x, int y, const timeofday_t * tod); |
81 | static int real_temperature(int x, int y); |
84 | static int real_temperature (int x, int y); |
82 | static void smooth_pressure(void); |
85 | static void smooth_pressure (void); |
83 | static void perform_pressure(void); |
86 | static void perform_pressure (void); |
84 | static void smooth_wind(void); |
87 | static void smooth_wind (void); |
85 | static void plot_gulfstream(void); |
88 | static void plot_gulfstream (void); |
86 | static void compute_sky(void); |
89 | static void compute_sky (void); |
87 | static void process_rain(void); |
90 | static void process_rain (void); |
88 | static void spin_globe(void); |
91 | static void spin_globe (void); |
89 | static void write_weather_images(void); |
92 | static void write_weather_images (void); |
90 | |
93 | |
91 | static int gulf_stream_speed[GULF_STREAM_WIDTH][WEATHERMAPTILESY]; |
94 | static int gulf_stream_speed[GULF_STREAM_WIDTH][WEATHERMAPTILESY]; |
92 | static int gulf_stream_dir[GULF_STREAM_WIDTH][WEATHERMAPTILESY]; |
95 | static int gulf_stream_dir[GULF_STREAM_WIDTH][WEATHERMAPTILESY]; |
93 | static int gulf_stream_start; |
96 | static int gulf_stream_start; |
94 | static int gulf_stream_direction; |
97 | static int gulf_stream_direction; |
95 | |
98 | |
96 | static const int season_timechange[5][HOURS_PER_DAY] = { |
99 | static const int season_timechange[5][HOURS_PER_DAY] = { |
|
|
100 | |
97 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 |
101 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 |
98 | 8 9 10 11 12 13 */ |
102 | 8 9 10 11 12 13 */ |
99 | {0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, |
103 | {0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, |
100 | 1, 1, 1, 1, 1, 1}, |
104 | 1, 1, 1, 1, 1, 1}, |
101 | {0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, 1, |
105 | {0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, 1, |
102 | 1, 1, 1, 1, 1, 0}, |
106 | 1, 1, 1, 1, 1, 0}, |
103 | {0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
107 | {0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
104 | 1, 1, 1, 1, 1, 0}, |
108 | 1, 1, 1, 1, 1, 0}, |
105 | {0, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
109 | {0, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
106 | 1, 1, 1, 1, 1, 0}, |
110 | 1, 1, 1, 1, 1, 0}, |
107 | {0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
111 | {0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
108 | 1, 1, 1, 1, 1, 0} |
112 | 1, 1, 1, 1, 1, 0} |
109 | }; |
113 | }; |
110 | |
114 | |
111 | static const int season_tempchange[HOURS_PER_DAY] = { |
115 | static const int season_tempchange[HOURS_PER_DAY] = { |
|
|
116 | |
112 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 |
117 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 |
113 | 8 9 10 11 12 13 */ |
118 | 8 9 10 11 12 13 */ |
114 | 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, |
119 | 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, |
115 | 1, 1, 1, 1, 1, 1}; |
120 | 1, 1, 1, 1, 1, 1 |
|
|
121 | }; |
116 | |
122 | |
117 | /* |
123 | /* |
118 | * The table below is used to set which tiles the weather will avoid |
124 | * The table below is used to set which tiles the weather will avoid |
119 | * processing. This keeps it from putting snow on snow, and putting snow |
125 | * processing. This keeps it from putting snow on snow, and putting snow |
120 | * on the ocean, and other things like that. |
126 | * on the ocean, and other things like that. |
121 | */ |
127 | */ |
122 | |
128 | |
123 | static weather_avoids_t weather_avoids[] = { |
129 | static weather_avoids_t weather_avoids[] = { |
124 | {"snow", 1, NULL}, |
130 | {"snow", 1, NULL}, |
125 | {"snow2", 1, NULL}, |
131 | {"snow2", 1, NULL}, |
126 | {"snow3", 1, NULL}, |
132 | {"snow3", 1, NULL}, |
127 | {"snow4", 1, NULL}, |
133 | {"snow4", 1, NULL}, |
128 | {"snow5", 1, NULL}, |
134 | {"snow5", 1, NULL}, |
129 | {"mountain1_snow", 1, NULL}, |
135 | {"mountain1_snow", 1, NULL}, |
130 | {"mountain2_snow", 1, NULL}, |
136 | {"mountain2_snow", 1, NULL}, |
131 | {"rain1", 1, NULL}, |
137 | {"rain1", 1, NULL}, |
132 | {"rain2", 1, NULL}, |
138 | {"rain2", 1, NULL}, |
133 | {"rain3", 1, NULL}, |
139 | {"rain3", 1, NULL}, |
134 | {"rain4", 1, NULL}, |
140 | {"rain4", 1, NULL}, |
135 | {"rain5", 1, NULL}, |
141 | {"rain5", 1, NULL}, |
136 | {"mountain1_rivlets", 1, NULL}, |
142 | {"mountain1_rivlets", 1, NULL}, |
137 | {"mountain2_rivlets", 1, NULL}, |
143 | {"mountain2_rivlets", 1, NULL}, |
138 | {"drifts", 0, NULL}, |
144 | {"drifts", 0, NULL}, |
139 | {"glacier", 0, NULL}, |
145 | {"glacier", 0, NULL}, |
140 | {"cforest1", 0, NULL}, |
146 | {"cforest1", 0, NULL}, |
141 | {"sea", 0, NULL}, |
147 | {"sea", 0, NULL}, |
142 | {"sea1", 0, NULL}, |
148 | {"sea1", 0, NULL}, |
143 | {"deep_sea", 0, NULL}, |
149 | {"deep_sea", 0, NULL}, |
144 | {"shallow_sea", 0, NULL}, |
150 | {"shallow_sea", 0, NULL}, |
145 | {"lava", 0, NULL}, |
151 | {"lava", 0, NULL}, |
146 | {"permanent_lava", 0, NULL}, |
152 | {"permanent_lava", 0, NULL}, |
147 | {NULL, 0, NULL} |
153 | {NULL, 0, NULL} |
148 | }; |
154 | }; |
149 | |
155 | |
150 | /* |
156 | /* |
151 | * this table is identical to the one above, except these are tiles to avoid |
157 | * this table is identical to the one above, except these are tiles to avoid |
152 | * when processing growth. IE, don't grow herbs in the ocean. The second |
158 | * when processing growth. IE, don't grow herbs in the ocean. The second |
153 | * field is unused. |
159 | * field is unused. |
154 | */ |
160 | */ |
155 | |
161 | |
156 | static weather_avoids_t growth_avoids[] = { |
162 | static weather_avoids_t growth_avoids[] = { |
157 | {"cobblestones", 0, NULL}, |
163 | {"cobblestones", 0, NULL}, |
158 | {"cobblestones2", 0, NULL}, |
164 | {"cobblestones2", 0, NULL}, |
159 | {"flagstone", 0, NULL}, |
165 | {"flagstone", 0, NULL}, |
160 | {"stonefloor2", 0, NULL}, |
166 | {"stonefloor2", 0, NULL}, |
161 | {"lava", 0, NULL}, |
167 | {"lava", 0, NULL}, |
162 | {"permanent_lava", 0, NULL}, |
168 | {"permanent_lava", 0, NULL}, |
163 | {"sea", 0, NULL}, |
169 | {"sea", 0, NULL}, |
164 | {"sea1", 0, NULL}, |
170 | {"sea1", 0, NULL}, |
165 | {"deep_sea", 0, NULL}, |
171 | {"deep_sea", 0, NULL}, |
166 | {"shallow_sea", 0, NULL}, |
172 | {"shallow_sea", 0, NULL}, |
167 | {"farmland", 0, NULL}, |
173 | {"farmland", 0, NULL}, |
168 | {"dungeon_magic", 0, NULL}, |
174 | {"dungeon_magic", 0, NULL}, |
169 | {"dungeon_floor", 0, NULL}, |
175 | {"dungeon_floor", 0, NULL}, |
170 | {"lake", 0, NULL}, |
176 | {"lake", 0, NULL}, |
171 | {"grasspond", 0, NULL}, |
177 | {"grasspond", 0, NULL}, |
172 | {NULL, 0, NULL} |
178 | {NULL, 0, NULL} |
173 | }; |
179 | }; |
174 | |
180 | |
175 | /* |
181 | /* |
176 | * The table below is used in let_it_snow() and singing_in_the_rain() to |
182 | * The table below is used in let_it_snow() and singing_in_the_rain() to |
177 | * decide what type of snow/rain/etc arch to put down. The first field is the |
183 | * decide what type of snow/rain/etc arch to put down. The first field is the |
… | |
… | |
180 | * NULL if none, used to stack over the snow after covering the tile. |
186 | * NULL if none, used to stack over the snow after covering the tile. |
181 | * The fourth field is 1 if you want to match arch->name, 0 to match ob->name. |
187 | * The fourth field is 1 if you want to match arch->name, 0 to match ob->name. |
182 | */ |
188 | */ |
183 | |
189 | |
184 | static weather_replace_t weather_replace[] = { |
190 | static weather_replace_t weather_replace[] = { |
185 | {"impossible_match", "snow5", NULL, 0}, |
191 | {"impossible_match", "snow5", NULL, 0}, |
186 | {"impossible_match2", "snow4", NULL, 0}, /* placeholders */ |
192 | {"impossible_match2", "snow4", NULL, 0}, /* placeholders */ |
187 | {"impossible_match3", "snow3", NULL, 0}, |
193 | {"impossible_match3", "snow3", NULL, 0}, |
188 | {"hills", "drifts", NULL, 0}, |
194 | {"hills", "drifts", NULL, 0}, |
189 | {"treed_hills", "drifts", "woods5", 1}, |
195 | {"treed_hills", "drifts", "woods5", 1}, |
190 | {"grass", "snow", NULL, 0}, |
196 | {"grass", "snow", NULL, 0}, |
191 | {"sand", "snow", NULL, 0}, |
197 | {"sand", "snow", NULL, 0}, |
192 | {"stones", "snow2", NULL, 0}, |
198 | {"stones", "snow2", NULL, 0}, |
193 | {"steppe", "snow2", NULL, 0}, |
199 | {"steppe", "snow2", NULL, 0}, |
194 | {"brush", "snow2", NULL, 0}, |
200 | {"brush", "snow2", NULL, 0}, |
195 | {"farmland", "snow3", NULL, 0}, |
201 | {"farmland", "snow3", NULL, 0}, |
196 | {"wasteland", "glacier", NULL, 0}, |
202 | {"wasteland", "glacier", NULL, 0}, |
197 | {"mountain", "mountain1_snow", NULL, 1}, |
203 | {"mountain", "mountain1_snow", NULL, 1}, |
198 | {"mountain2", "mountain2_snow", NULL, 1}, |
204 | {"mountain2", "mountain2_snow", NULL, 1}, |
199 | {"mountain4", "mountain2_snow", NULL, 1}, |
205 | {"mountain4", "mountain2_snow", NULL, 1}, |
200 | {"evergreens", "snow", "evergreens2", 1}, |
206 | {"evergreens", "snow", "evergreens2", 1}, |
201 | {"evergreen","snow", "tree5", 1}, |
207 | {"evergreen", "snow", "tree5", 1}, |
202 | {"tree", "snow", "tree3", 0}, |
208 | {"tree", "snow", "tree3", 0}, |
203 | {"woods", "snow3", "woods4", 1}, |
209 | {"woods", "snow3", "woods4", 1}, |
204 | {"woods_3", "snow", "woods5", 1}, |
210 | {"woods_3", "snow", "woods5", 1}, |
205 | {NULL, NULL, NULL, 0}, |
211 | {NULL, NULL, NULL, 0}, |
206 | }; |
212 | }; |
207 | |
213 | |
208 | /* |
214 | /* |
209 | * The table below is used to grow things on the map. See include/tod.h for |
215 | * The table below is used to grow things on the map. See include/tod.h for |
210 | * the meanings of all of the fields. |
216 | * the meanings of all of the fields. |
211 | */ |
217 | */ |
212 | |
218 | |
213 | static const weather_grow_t weather_grow[] = { |
219 | static const weather_grow_t weather_grow[] = { |
214 | /* herb, tile, random, rfmin, rfmax, humin, humax, tempmin, tempmax, elevmin, elevmax, season */ |
220 | /* herb, tile, random, rfmin, rfmax, humin, humax, tempmin, tempmax, elevmin, elevmax, season */ |
215 | {"mint", "grass", 10, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
221 | {"mint", "grass", 10, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
216 | {"rose_red", "grass", 15, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
222 | {"rose_red", "grass", 15, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
217 | {"rose_red", "hills", 15, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
223 | {"rose_red", "hills", 15, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
218 | {"mint", "brush", 8, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
224 | {"mint", "brush", 8, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 2}, |
219 | {"blackroot", "swamp", 15, 1.6, 2.0, 60, 100, 20, 30, -100, 1500, 0}, |
225 | {"blackroot", "swamp", 15, 1.6, 2.0, 60, 100, 20, 30, -100, 1500, 0}, |
220 | {"mushroom_1", "grass", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
226 | {"mushroom_1", "grass", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
221 | {"mushroom_2", "grass", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
227 | {"mushroom_2", "grass", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
222 | {"mushroom_1", "swamp", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
228 | {"mushroom_1", "swamp", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
223 | {"mushroom_2", "swamp", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
229 | {"mushroom_2", "swamp", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
224 | {"mushroom_1", "hills", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
230 | {"mushroom_1", "hills", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
225 | {"mushroom_2", "hills", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
231 | {"mushroom_2", "hills", 15, 1.6, 2.0, 60, 100, 3, 30, -100, 1500, 0}, |
226 | {"pipeweed", "farmland", 20, 1.0, 2.0, 30, 100, 10, 25, 100, 5000, 0}, |
232 | {"pipeweed", "farmland", 20, 1.0, 2.0, 30, 100, 10, 25, 100, 5000, 0}, |
227 | {"cabbage", "farmland", 10, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 0}, |
233 | {"cabbage", "farmland", 10, 1.0, 2.0, 30, 100, 10, 25, -100, 9999, 0}, |
228 | {"onion", "farmland", 10, 1.0, 2.0, 30, 100, 10, 25, 100, 9999, 0}, |
234 | {"onion", "farmland", 10, 1.0, 2.0, 30, 100, 10, 25, 100, 9999, 0}, |
229 | {"carrot", "farmland", 10, 1.0, 2.0, 30, 100, 10, 25, 100, 9999, 0}, |
235 | {"carrot", "farmland", 10, 1.0, 2.0, 30, 100, 10, 25, 100, 9999, 0}, |
230 | {"thorns", "brush", 15, 0.5, 1.3, 30, 100, 10, 25, -100, 9999, 0}, |
236 | {"thorns", "brush", 15, 0.5, 1.3, 30, 100, 10, 25, -100, 9999, 0}, |
231 | {"mountain_foilage", "mountain", 6, 1.0, 2.0, 25, 100, 5, 30, 0, 15999, 2}, |
237 | {"mountain_foilage", "mountain", 6, 1.0, 2.0, 25, 100, 5, 30, 0, 15999, 2}, |
232 | {NULL, NULL, 1, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0} |
238 | {NULL, NULL, 1, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0} |
233 | }; |
239 | }; |
234 | |
240 | |
235 | /* |
241 | /* |
236 | * The table below uses the same format as the one above. However this |
242 | * The table below uses the same format as the one above. However this |
237 | * table is used to change the layout of the worldmap itself. The tile |
243 | * table is used to change the layout of the worldmap itself. The tile |
238 | * parameter is a base tile to lay down underneath the herb tile. |
244 | * parameter is a base tile to lay down underneath the herb tile. |
239 | */ |
245 | */ |
240 | |
246 | |
241 | static const weather_grow_t weather_tile[] = { |
247 | static const weather_grow_t weather_tile[] = { |
242 | /* herb, tile, random, rfmin, rfmax, humin, humax, tempmin, tempmax, elevmin, elevmax */ |
248 | /* herb, tile, random, rfmin, rfmax, humin, humax, tempmin, tempmax, elevmin, elevmax */ |
243 | {"dunes", NULL, 2, 0.0, 0.03, 0, 20, 10, 99, 0, 4000, 0}, |
249 | {"dunes", NULL, 2, 0.0, 0.03, 0, 20, 10, 99, 0, 4000, 0}, |
244 | {"desert", NULL, 1, 0.0, 0.05, 0, 20, 10, 99, 0, 4000, 0}, |
250 | {"desert", NULL, 1, 0.0, 0.05, 0, 20, 10, 99, 0, 4000, 0}, |
245 | {"pstone_2", NULL, 1, 0.0, 0.05, 0, 20, -30, 10, 0, 4000, 0}, |
251 | {"pstone_2", NULL, 1, 0.0, 0.05, 0, 20, -30, 10, 0, 4000, 0}, |
246 | {"pstone_3", NULL, 1, 0.0, 0.05, 0, 20, -30, 10, 0, 4000, 0}, |
252 | {"pstone_3", NULL, 1, 0.0, 0.05, 0, 20, -30, 10, 0, 4000, 0}, |
247 | {"grassbrown", NULL, 1, 0.05, 1.0, 20, 80, -20, -3, 0, 5000, 0}, |
253 | {"grassbrown", NULL, 1, 0.05, 1.0, 20, 80, -20, -3, 0, 5000, 0}, |
248 | {"grass_br_gr", NULL, 1, 0.05, 1.0, 20, 80, -3, 5, 0, 5000, 0}, |
254 | {"grass_br_gr", NULL, 1, 0.05, 1.0, 20, 80, -3, 5, 0, 5000, 0}, |
249 | {"grass", NULL, 1, 0.05, 1.0, 20, 80, 5, 15, 0, 5000, 0}, |
255 | {"grass", NULL, 1, 0.05, 1.0, 20, 80, 5, 15, 0, 5000, 0}, |
250 | {"grassmedium", NULL, 1, 0.05, 1.0, 20, 80, 15, 25, 0, 5000, 0}, |
256 | {"grassmedium", NULL, 1, 0.05, 1.0, 20, 80, 15, 25, 0, 5000, 0}, |
251 | {"grassdark", NULL, 1, 0.05, 1.0, 20, 80, 25, 35, 0, 5000, 0}, |
257 | {"grassdark", NULL, 1, 0.05, 1.0, 20, 80, 25, 35, 0, 5000, 0}, |
252 | {"brush", NULL, 1, 0.2, 1.0, 25, 70, 0, 30, 500, 6000, 0}, |
258 | {"brush", NULL, 1, 0.2, 1.0, 25, 70, 0, 30, 500, 6000, 0}, |
253 | /* small */ |
259 | /* small */ |
254 | {"evergreens2", "brush", 1, 0.5, 1.8, 30, 90, -30, 24, 3000, 8000, 0}, |
260 | {"evergreens2", "brush", 1, 0.5, 1.8, 30, 90, -30, 24, 3000, 8000, 0}, |
255 | {"fernsdense", "brush", 1, 0.9, 2.5, 50, 100, 10, 35, 1000, 6000, 0}, |
261 | {"fernsdense", "brush", 1, 0.9, 2.5, 50, 100, 10, 35, 1000, 6000, 0}, |
256 | {"fernssparse", "brush", 1, 0.7, 2.0, 30, 90, -15, 35, 0, 4000, 0}, |
262 | {"fernssparse", "brush", 1, 0.7, 2.0, 30, 90, -15, 35, 0, 4000, 0}, |
257 | {"woods4", "brush", 1, 0.1, 0.8, 30, 60, -5, 25, 1000, 4500, 0}, |
263 | {"woods4", "brush", 1, 0.1, 0.8, 30, 60, -5, 25, 1000, 4500, 0}, |
258 | {"woods5", "brush", 1, 0.6, 1.5, 20, 70, -15, 20, 2000, 5500, 0}, |
264 | {"woods5", "brush", 1, 0.6, 1.5, 20, 70, -15, 20, 2000, 5500, 0}, |
259 | {"forestsparse", "brush", 1, 0.3, 1.5, 15, 60, -20, 25, 0, 4500, 0}, |
265 | {"forestsparse", "brush", 1, 0.3, 1.5, 15, 60, -20, 25, 0, 4500, 0}, |
260 | /* big */ |
266 | /* big */ |
261 | /* |
267 | /* |
262 | {"ytree_2", "brush", 2, 0.1, 0.6, 30, 60, 10, 25, 1000, 3500, 0}, |
268 | {"ytree_2", "brush", 2, 0.1, 0.6, 30, 60, 10, 25, 1000, 3500, 0}, |
263 | {"tree3", "grass", 2, 0.9, 2.5, 50, 100, 10, 35, 1000, 4000, 0}, |
269 | {"tree3", "grass", 2, 0.9, 2.5, 50, 100, 10, 35, 1000, 4000, 0}, |
264 | {"tree5", "grass", 2, 0.5, 1.5, 40, 90, -10, 24, 3000, 8000, 0}, |
270 | {"tree5", "grass", 2, 0.5, 1.5, 40, 90, -10, 24, 3000, 8000, 0}, |
265 | {"tree3", "grassmeduim", 2, 0.9, 2.5, 50, 100, 10, 35, 1000, 4000, 0}, |
271 | {"tree3", "grassmeduim", 2, 0.9, 2.5, 50, 100, 10, 35, 1000, 4000, 0}, |
266 | {"tree5", "grassmedium", 2, 0.5, 1.5, 40, 90, -10, 24, 3000, 8000, 0}, |
272 | {"tree5", "grassmedium", 2, 0.5, 1.5, 40, 90, -10, 24, 3000, 8000, 0}, |
267 | {"tree3", "grassdark", 2, 0.9, 2.5, 50, 100, 10, 35, 1000, 4000, 0}, |
273 | {"tree3", "grassdark", 2, 0.9, 2.5, 50, 100, 10, 35, 1000, 4000, 0}, |
268 | {"tree5", "grassdark", 2, 0.5, 1.5, 40, 90, -10, 24, 3000, 8000, 0},*/ |
274 | {"tree5", "grassdark", 2, 0.5, 1.5, 40, 90, -10, 24, 3000, 8000, 0}, */ |
269 | /* mountians */ |
275 | /* mountians */ |
270 | {"steppe", NULL, 1, 0.5, 1.3, 0, 30, -20, 35, 1000, 6000, 0}, |
276 | {"steppe", NULL, 1, 0.5, 1.3, 0, 30, -20, 35, 1000, 6000, 0}, |
271 | {"steppelight", NULL, 1, 0.0, 0.6, 0, 20, -50, 35, 0, 5000, 0}, |
277 | {"steppelight", NULL, 1, 0.0, 0.6, 0, 20, -50, 35, 0, 5000, 0}, |
272 | {"hills", NULL, 1, 0.1, 0.9, 20, 80, -10, 30, 5000, 8500, 0}, |
278 | {"hills", NULL, 1, 0.1, 0.9, 20, 80, -10, 30, 5000, 8500, 0}, |
273 | {"hills_rocky", NULL, 1, 0.0, 0.9, 0, 100, -50, 50, 5000, 8500, 0}, |
279 | {"hills_rocky", NULL, 1, 0.0, 0.9, 0, 100, -50, 50, 5000, 8500, 0}, |
274 | {"swamp", NULL, 1, 1.0, 9.9, 55, 80, 10, 50, 0, 1000, 0}, |
280 | {"swamp", NULL, 1, 1.0, 9.9, 55, 80, 10, 50, 0, 1000, 0}, |
275 | {"deep_swamp", NULL, 1, 1.0, 9.9, 80, 100, 10, 50, 0, 1000, 0}, |
281 | {"deep_swamp", NULL, 1, 1.0, 9.9, 80, 100, 10, 50, 0, 1000, 0}, |
276 | {"mountain", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 8000, 10000, 0}, |
282 | {"mountain", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 8000, 10000, 0}, |
277 | {"mountain2", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 9500, 11000, 0}, |
283 | {"mountain2", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 9500, 11000, 0}, |
278 | {"mountain4", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 10500, 12000, 0}, |
284 | {"mountain4", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 10500, 12000, 0}, |
279 | {"mountain5", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 11500, 13500, 0}, |
285 | {"mountain5", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 11500, 13500, 0}, |
280 | {"wasteland", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 13000, 99999, 0}, |
286 | {"wasteland", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 13000, 99999, 0}, |
281 | /* catchalls */ |
287 | /* catchalls */ |
282 | {"palms", "pstone_1", 1, 0.01, 0.1, 0, 30, 5, 99, 0, 4000, 0}, |
288 | {"palms", "pstone_1", 1, 0.01, 0.1, 0, 30, 5, 99, 0, 4000, 0}, |
283 | {"large_stones", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 6000, 8000, 0}, |
289 | {"large_stones", NULL, 1, 0.0, 9.9, 0, 100, -50, 50, 6000, 8000, 0}, |
284 | {"earth", NULL, 1, 0.0, 1.0, 0, 70, -30, 15, 0, 6000, 0}, |
290 | {"earth", NULL, 1, 0.0, 1.0, 0, 70, -30, 15, 0, 6000, 0}, |
285 | {"medium_stones", NULL, 1, 1.0, 3.0, 70, 100, -30, 10, 0, 4000, 0}, /*unsure*/ |
291 | {"medium_stones", NULL, 1, 1.0, 3.0, 70, 100, -30, 10, 0, 4000, 0}, /*unsure */ |
286 | {"earth", NULL, 1, 0.1, 0.9, 20, 80, -30, 30, 0, 4999, 0}, /* tundra */ |
292 | {"earth", NULL, 1, 0.1, 0.9, 20, 80, -30, 30, 0, 4999, 0}, /* tundra */ |
287 | {"swamp", NULL, 1, 1.0, 9.9, 50, 100, -30, 10, 0, 4000, 0},/* cold marsh */ |
293 | {"swamp", NULL, 1, 1.0, 9.9, 50, 100, -30, 10, 0, 4000, 0}, /* cold marsh */ |
288 | {"earth", NULL, 1, 0.0, 99.9, 0, 100, -99, 99, 0, 99999, 0}, /* debug */ |
294 | {"earth", NULL, 1, 0.0, 99.9, 0, 100, -99, 99, 0, 99999, 0}, /* debug */ |
289 | {NULL, NULL, 1, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0} |
295 | {NULL, NULL, 1, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0} |
290 | }; |
296 | }; |
291 | |
297 | |
292 | /* This stuff is for creating the images. */ |
298 | /* This stuff is for creating the images. */ |
293 | |
299 | |
294 | /* Colour offsets into pixel array. */ |
300 | /* Colour offsets into pixel array. */ |
… | |
… | |
301 | * 812 456 |
307 | * 812 456 |
302 | * 7 3 3 7 |
308 | * 7 3 3 7 |
303 | * 654 218 |
309 | * 654 218 |
304 | */ |
310 | */ |
305 | static const uint32 directions[] = { |
311 | static const uint32 directions[] = { |
306 | 0x0000FFFF, /* south */ |
312 | 0x0000FFFF, /* south */ |
307 | 0x000000FF, /* south west */ |
313 | 0x000000FF, /* south west */ |
308 | 0x00FF00FF, /* west */ |
314 | 0x00FF00FF, /* west */ |
309 | 0x00FFFFFF, /* north west */ |
315 | 0x00FFFFFF, /* north west */ |
310 | 0x00000000, /* north */ |
316 | 0x00000000, /* north */ |
311 | 0x00FF0000, /* north east */ |
317 | 0x00FF0000, /* north east */ |
312 | 0x00FFFF00, /* east */ |
318 | 0x00FFFF00, /* east */ |
313 | 0x0000FF00 /* south east */ |
319 | 0x0000FF00 /* south east */ |
314 | }; |
320 | }; |
315 | |
321 | |
316 | /* Colours used for weather types. */ |
322 | /* Colours used for weather types. */ |
317 | static const uint32 skies[] = { |
323 | static const uint32 skies[] = { |
318 | 0x000000FF, /* SKY_CLEAR 0 */ |
324 | 0x000000FF, /* SKY_CLEAR 0 */ |
319 | 0x000000BD, /* SKY_LIGHTCLOUD 1 */ |
325 | 0x000000BD, /* SKY_LIGHTCLOUD 1 */ |
320 | 0x0000007E, /* SKY_OVERCAST 2 */ |
326 | 0x0000007E, /* SKY_OVERCAST 2 */ |
321 | 0x0000FF00, /* SKY_LIGHT_RAIN 3 */ |
327 | 0x0000FF00, /* SKY_LIGHT_RAIN 3 */ |
322 | 0x0000BD00, /* SKY_RAIN 4 */ |
328 | 0x0000BD00, /* SKY_RAIN 4 */ |
323 | 0x00007E00, /* SKY_HEAVY_RAIN 5 */ |
329 | 0x00007E00, /* SKY_HEAVY_RAIN 5 */ |
324 | 0x00FFFF00, /* SKY_HURRICANE 6 */ |
330 | 0x00FFFF00, /* SKY_HURRICANE 6 */ |
|
|
331 | |
325 | /* wierd weather 7-12 */ |
332 | /* wierd weather 7-12 */ |
326 | 0x00FF0000, /* SKY_FOG 7 */ |
333 | 0x00FF0000, /* SKY_FOG 7 */ |
327 | 0x00FF00FF, /* SKY_HAIL 8 */ |
334 | 0x00FF00FF, /* SKY_HAIL 8 */ |
328 | 0x00000000, |
335 | 0x00000000, |
329 | 0x00000000, |
336 | 0x00000000, |
330 | 0x00000000, |
337 | 0x00000000, |
331 | 0x00000000, |
338 | 0x00000000, |
|
|
339 | |
332 | /* snow */ |
340 | /* snow */ |
333 | 0x003F3F3F, /* SKY_LIGHT_SNOW 13 */ |
341 | 0x003F3F3F, /* SKY_LIGHT_SNOW 13 */ |
334 | 0x007E7E7E, /* SKY_SNOW 14 */ |
342 | 0x007E7E7E, /* SKY_SNOW 14 */ |
335 | 0x00BDBDBD, /* SKY_HEAVY_SNOW 15 */ |
343 | 0x00BDBDBD, /* SKY_HEAVY_SNOW 15 */ |
336 | 0x00FFFFFF /* SKY_BLIZZARD 16 */ |
344 | 0x00FFFFFF /* SKY_BLIZZARD 16 */ |
337 | }; |
345 | }; |
338 | |
346 | |
339 | |
347 | |
340 | /* |
348 | /* |
341 | * Set the darkness level for a map. Requires the map pointer. |
349 | * Set the darkness level for a map. Requires the map pointer. |
342 | */ |
350 | */ |
343 | |
351 | |
|
|
352 | void |
344 | void set_darkness_map(mapstruct *m) |
353 | set_darkness_map (mapstruct *m) |
345 | { |
354 | { |
346 | int i; |
355 | int i; |
347 | timeofday_t tod; |
356 | timeofday_t tod; |
348 | |
357 | |
349 | if (!m->outdoor) |
358 | if (!m->outdoor) |
350 | return; |
359 | return; |
351 | |
360 | |
352 | get_tod(&tod); |
361 | get_tod (&tod); |
353 | m->darkness = 0; |
362 | m->darkness = 0; |
354 | for (i = HOURS_PER_DAY/2; i < HOURS_PER_DAY; i++) |
363 | for (i = HOURS_PER_DAY / 2; i < HOURS_PER_DAY; i++) |
355 | change_map_light(m, season_timechange[tod.season][i]); |
364 | change_map_light (m, season_timechange[tod.season][i]); |
356 | for (i = 0; i <= tod.hour; i++) |
365 | for (i = 0; i <= tod.hour; i++) |
357 | change_map_light(m, season_timechange[tod.season][i]); |
366 | change_map_light (m, season_timechange[tod.season][i]); |
358 | } |
367 | } |
359 | |
368 | |
360 | /* |
369 | /* |
361 | * Compute the darkness level for all maps in the game. Requires the |
370 | * Compute the darkness level for all maps in the game. Requires the |
362 | * time of day as an argument. |
371 | * time of day as an argument. |
363 | */ |
372 | */ |
364 | |
373 | |
|
|
374 | static void |
365 | static void dawn_to_dusk(const timeofday_t *tod) |
375 | dawn_to_dusk (const timeofday_t * tod) |
366 | { |
376 | { |
367 | mapstruct *m; |
377 | mapstruct *m; |
368 | |
378 | |
369 | /* If the light level isn't changing, no reason to do all |
379 | /* If the light level isn't changing, no reason to do all |
370 | * the work below. |
380 | * the work below. |
371 | */ |
381 | */ |
372 | if (season_timechange[tod->season][tod->hour] == 0) return; |
382 | if (season_timechange[tod->season][tod->hour] == 0) |
|
|
383 | return; |
373 | |
384 | |
374 | for(m=first_map;m!=NULL;m=m->next) { |
385 | for (m = first_map; m != NULL; m = m->next) |
|
|
386 | { |
375 | if (!m->outdoor) |
387 | if (!m->outdoor) |
376 | continue; |
388 | continue; |
377 | change_map_light(m, season_timechange[tod->season][tod->hour]); |
389 | change_map_light (m, season_timechange[tod->season][tod->hour]); |
378 | } |
390 | } |
379 | } |
391 | } |
380 | |
392 | |
381 | /* |
393 | /* |
382 | * This performs the basic function of advancing the clock one tick |
394 | * This performs the basic function of advancing the clock one tick |
… | |
… | |
384 | * saved on shutdown. Any time dependant functions should be called |
396 | * saved on shutdown. Any time dependant functions should be called |
385 | * from this function, and probably be passed tod as an argument. |
397 | * from this function, and probably be passed tod as an argument. |
386 | * Please don't modify tod in the dependant function. |
398 | * Please don't modify tod in the dependant function. |
387 | */ |
399 | */ |
388 | |
400 | |
|
|
401 | void |
389 | void tick_the_clock(void) |
402 | tick_the_clock (void) |
390 | { |
403 | { |
391 | timeofday_t tod; |
404 | timeofday_t tod; |
392 | |
405 | |
393 | todtick++; |
406 | todtick++; |
394 | if (todtick%20 == 0) |
407 | if (todtick % 20 == 0) |
395 | write_todclock(); |
408 | write_todclock (); |
396 | if (settings.dynamiclevel > 0) { |
409 | if (settings.dynamiclevel > 0) |
|
|
410 | { |
397 | if (todtick%21 == 0) |
411 | if (todtick % 21 == 0) |
398 | write_pressuremap(); |
412 | write_pressuremap (); |
399 | if (todtick%22 == 0) |
413 | if (todtick % 22 == 0) |
400 | write_winddirmap(); |
414 | write_winddirmap (); |
401 | if (todtick%23 == 0) |
415 | if (todtick % 23 == 0) |
402 | write_windspeedmap(); |
416 | write_windspeedmap (); |
403 | if (todtick%24 == 0) |
417 | if (todtick % 24 == 0) |
404 | write_humidmap(); |
418 | write_humidmap (); |
|
|
419 | |
405 | /* if (todtick%25 == 0) |
420 | /* if (todtick%25 == 0) |
406 | write_elevmap(); */ |
421 | write_elevmap(); */ |
407 | if (todtick%26 == 0) |
422 | if (todtick % 26 == 0) |
408 | write_temperaturemap(); |
423 | write_temperaturemap (); |
409 | if (todtick%27 == 0) |
424 | if (todtick % 27 == 0) |
410 | write_gulfstreammap(); |
425 | write_gulfstreammap (); |
411 | if (todtick%28 == 0) |
426 | if (todtick % 28 == 0) |
412 | write_skymap(); |
427 | write_skymap (); |
413 | if (todtick%29 == 0) |
428 | if (todtick % 29 == 0) |
414 | write_rainfallmap(); |
429 | write_rainfallmap (); |
415 | } |
430 | } |
416 | get_tod(&tod); |
431 | get_tod (&tod); |
417 | dawn_to_dusk(&tod); |
432 | dawn_to_dusk (&tod); |
418 | /* call the weather calculators, here, in order */ |
433 | /* call the weather calculators, here, in order */ |
419 | if (settings.dynamiclevel > 0) { |
434 | if (settings.dynamiclevel > 0) |
|
|
435 | { |
420 | perform_pressure(); /* pressure is the random factor */ |
436 | perform_pressure (); /* pressure is the random factor */ |
421 | smooth_wind(); /* calculate the wind. depends on pressure */ |
437 | smooth_wind (); /* calculate the wind. depends on pressure */ |
422 | plot_gulfstream(); |
438 | plot_gulfstream (); |
423 | update_humid(); |
439 | update_humid (); |
424 | init_temperature(); |
440 | init_temperature (); |
425 | compute_sky(); |
441 | compute_sky (); |
426 | if (tod.hour == 0) |
442 | if (tod.hour == 0) |
427 | process_rain(); |
443 | process_rain (); |
428 | } |
444 | } |
429 | /* perform_weather must follow calculators */ |
445 | /* perform_weather must follow calculators */ |
430 | perform_weather(); |
446 | perform_weather (); |
431 | if (settings.dynamiclevel > 0) { |
447 | if (settings.dynamiclevel > 0) |
|
|
448 | { |
432 | write_weather_images(); |
449 | write_weather_images (); |
433 | spin_globe(); |
450 | spin_globe (); |
434 | } |
451 | } |
435 | } |
452 | } |
436 | |
453 | |
437 | /* |
454 | /* |
438 | * This batch of routines reads and writes the various |
455 | * This batch of routines reads and writes the various |
439 | * weathermap structures. Each type of data is stored |
456 | * weathermap structures. Each type of data is stored |
… | |
… | |
447 | * calls the init function, to initialize that map. |
464 | * calls the init function, to initialize that map. |
448 | */ |
465 | */ |
449 | |
466 | |
450 | /* sky. We never read this map, only write it for debugging purposes */ |
467 | /* sky. We never read this map, only write it for debugging purposes */ |
451 | |
468 | |
452 | static void write_skymap(void) |
469 | static void |
|
|
470 | write_skymap (void) |
453 | { |
471 | { |
454 | char filename[MAX_BUF]; |
472 | char filename[MAX_BUF]; |
455 | FILE *fp; |
473 | FILE *fp; |
456 | int x, y; |
474 | int x, y; |
457 | |
475 | |
458 | sprintf(filename, "%s/skymap", settings.localdir); |
476 | sprintf (filename, "%s/skymap", settings.localdir); |
459 | if ((fp = fopen(filename, "w")) == NULL) { |
477 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
478 | { |
460 | LOG(llevError, "Cannot open %s for writing\n", filename); |
479 | LOG (llevError, "Cannot open %s for writing\n", filename); |
461 | return; |
480 | return; |
462 | } |
481 | } |
463 | for (x=0; x < WEATHERMAPTILESX; x++) { |
482 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
483 | { |
464 | for (y=0; y < WEATHERMAPTILESY; y++) |
484 | for (y = 0; y < WEATHERMAPTILESY; y++) |
465 | fprintf(fp, "%d ", weathermap[x][y].sky); |
485 | fprintf (fp, "%d ", weathermap[x][y].sky); |
466 | fprintf(fp, "\n"); |
486 | fprintf (fp, "\n"); |
467 | } |
487 | } |
468 | fclose(fp); |
488 | fclose (fp); |
469 | } |
489 | } |
470 | |
490 | |
471 | /* pressure */ |
491 | /* pressure */ |
472 | |
492 | |
|
|
493 | static void |
473 | static void write_pressuremap(void) |
494 | write_pressuremap (void) |
474 | { |
495 | { |
475 | char filename[MAX_BUF]; |
496 | char filename[MAX_BUF]; |
476 | FILE *fp; |
497 | FILE *fp; |
477 | int x, y; |
498 | int x, y; |
478 | |
499 | |
479 | sprintf(filename, "%s/pressuremap", settings.localdir); |
500 | sprintf (filename, "%s/pressuremap", settings.localdir); |
480 | if ((fp = fopen(filename, "w")) == NULL) { |
501 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
502 | { |
481 | LOG(llevError, "Cannot open %s for writing\n", filename); |
503 | LOG (llevError, "Cannot open %s for writing\n", filename); |
482 | return; |
504 | return; |
483 | } |
505 | } |
484 | for (x=0; x < WEATHERMAPTILESX; x++) { |
506 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
507 | { |
485 | for (y=0; y < WEATHERMAPTILESY; y++) |
508 | for (y = 0; y < WEATHERMAPTILESY; y++) |
486 | fprintf(fp, "%d ", weathermap[x][y].pressure); |
509 | fprintf (fp, "%d ", weathermap[x][y].pressure); |
487 | fprintf(fp, "\n"); |
510 | fprintf (fp, "\n"); |
488 | } |
511 | } |
489 | fclose(fp); |
512 | fclose (fp); |
490 | } |
513 | } |
491 | |
514 | |
|
|
515 | static void |
492 | static void read_pressuremap(void) |
516 | read_pressuremap (void) |
493 | { |
517 | { |
494 | char filename[MAX_BUF]; |
518 | char filename[MAX_BUF]; |
495 | FILE *fp; |
519 | FILE *fp; |
496 | int x, y; |
520 | int x, y; |
497 | |
521 | |
498 | sprintf(filename, "%s/pressuremap", settings.localdir); |
522 | sprintf (filename, "%s/pressuremap", settings.localdir); |
499 | LOG(llevDebug, "Reading pressure data from %s...", filename); |
523 | LOG (llevDebug, "Reading pressure data from %s...", filename); |
500 | if ((fp = fopen(filename, "r")) == NULL) { |
524 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
525 | { |
501 | LOG(llevError, "Cannot open %s for reading\n", filename); |
526 | LOG (llevError, "Cannot open %s for reading\n", filename); |
502 | LOG(llevDebug, "Initializing pressure maps..."); |
527 | LOG (llevDebug, "Initializing pressure maps..."); |
503 | init_pressure(); |
528 | init_pressure (); |
504 | write_pressuremap(); |
529 | write_pressuremap (); |
505 | LOG(llevDebug, "Done\n"); |
530 | LOG (llevDebug, "Done\n"); |
506 | return; |
531 | return; |
507 | } |
532 | } |
508 | for (x=0; x < WEATHERMAPTILESX; x++) { |
533 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
534 | { |
509 | for (y=0; y < WEATHERMAPTILESY; y++) { |
535 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
536 | { |
510 | fscanf(fp, "%hd ", &weathermap[x][y].pressure); |
537 | fscanf (fp, "%hd ", &weathermap[x][y].pressure); |
511 | if (weathermap[x][y].pressure < 960 || |
538 | if (weathermap[x][y].pressure < 960 || weathermap[x][y].pressure > 1040) |
512 | weathermap[x][y].pressure > 1040) |
|
|
513 | weathermap[x][y].pressure = rndm(960, 1040); |
539 | weathermap[x][y].pressure = rndm (960, 1040); |
514 | } |
540 | } |
515 | fscanf(fp, "\n"); |
541 | fscanf (fp, "\n"); |
516 | } |
542 | } |
517 | LOG(llevDebug, "Done.\n"); |
543 | LOG (llevDebug, "Done.\n"); |
518 | fclose(fp); |
544 | fclose (fp); |
519 | } |
545 | } |
520 | |
546 | |
521 | static void init_pressure(void) |
547 | static void |
|
|
548 | init_pressure (void) |
522 | { |
549 | { |
523 | int x, y; |
550 | int x, y; |
524 | int l, n, k, r; |
551 | int l, n, k, r; |
525 | |
552 | |
526 | for (x=0; x < WEATHERMAPTILESX; x++) |
553 | for (x = 0; x < WEATHERMAPTILESX; x++) |
527 | for (y=0; y < WEATHERMAPTILESY; y++) |
554 | for (y = 0; y < WEATHERMAPTILESY; y++) |
528 | weathermap[x][y].pressure = 1000; |
555 | weathermap[x][y].pressure = 1000; |
529 | |
556 | |
530 | for (l=0; l < PRESSURE_ITERATIONS; l++) { |
557 | for (l = 0; l < PRESSURE_ITERATIONS; l++) |
|
|
558 | { |
531 | x = rndm(0, WEATHERMAPTILESX-1); |
559 | x = rndm (0, WEATHERMAPTILESX - 1); |
532 | y = rndm(0, WEATHERMAPTILESY-1); |
560 | y = rndm (0, WEATHERMAPTILESY - 1); |
533 | n = rndm(PRESSURE_MIN, PRESSURE_MAX); |
561 | n = rndm (PRESSURE_MIN, PRESSURE_MAX); |
534 | for (k=1; k < PRESSURE_AREA; k++) { |
562 | for (k = 1; k < PRESSURE_AREA; k++) |
|
|
563 | { |
535 | r = rndm(0,3); |
564 | r = rndm (0, 3); |
536 | switch (r) { |
565 | switch (r) |
537 | case 0: if (x < WEATHERMAPTILESX-1) x++; break; |
|
|
538 | case 1: if (y < WEATHERMAPTILESY-1) y++; break; |
|
|
539 | case 2: if (x) x--; break; |
|
|
540 | case 3: if (y) y--; break; |
|
|
541 | } |
566 | { |
|
|
567 | case 0: |
|
|
568 | if (x < WEATHERMAPTILESX - 1) |
|
|
569 | x++; |
|
|
570 | break; |
|
|
571 | case 1: |
|
|
572 | if (y < WEATHERMAPTILESY - 1) |
|
|
573 | y++; |
|
|
574 | break; |
|
|
575 | case 2: |
|
|
576 | if (x) |
|
|
577 | x--; |
|
|
578 | break; |
|
|
579 | case 3: |
|
|
580 | if (y) |
|
|
581 | y--; |
|
|
582 | break; |
|
|
583 | } |
542 | weathermap[x][y].pressure = (weathermap[x][y].pressure+n)/2; |
584 | weathermap[x][y].pressure = (weathermap[x][y].pressure + n) / 2; |
543 | } |
585 | } |
544 | } |
586 | } |
545 | /* create random spikes in the pressure */ |
587 | /* create random spikes in the pressure */ |
546 | for (l=0; l < PRESSURE_SPIKES; l++) { |
588 | for (l = 0; l < PRESSURE_SPIKES; l++) |
|
|
589 | { |
547 | x = rndm(0, WEATHERMAPTILESX-1); |
590 | x = rndm (0, WEATHERMAPTILESX - 1); |
548 | y = rndm(0, WEATHERMAPTILESY-1); |
591 | y = rndm (0, WEATHERMAPTILESY - 1); |
549 | n = rndm(500, 2000); |
592 | n = rndm (500, 2000); |
550 | weathermap[x][y].pressure = n; |
593 | weathermap[x][y].pressure = n; |
551 | } |
594 | } |
552 | smooth_pressure(); |
595 | smooth_pressure (); |
553 | } |
596 | } |
554 | |
597 | |
555 | /* winddir */ |
598 | /* winddir */ |
556 | |
599 | |
|
|
600 | static void |
557 | static void write_winddirmap(void) |
601 | write_winddirmap (void) |
558 | { |
602 | { |
559 | char filename[MAX_BUF]; |
603 | char filename[MAX_BUF]; |
560 | FILE *fp; |
604 | FILE *fp; |
561 | int x, y; |
605 | int x, y; |
562 | |
606 | |
563 | sprintf(filename, "%s/winddirmap", settings.localdir); |
607 | sprintf (filename, "%s/winddirmap", settings.localdir); |
564 | if ((fp = fopen(filename, "w")) == NULL) { |
608 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
609 | { |
565 | LOG(llevError, "Cannot open %s for writing\n", filename); |
610 | LOG (llevError, "Cannot open %s for writing\n", filename); |
566 | return; |
611 | return; |
567 | } |
612 | } |
568 | for (x=0; x < WEATHERMAPTILESX; x++) { |
613 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
614 | { |
569 | for (y=0; y < WEATHERMAPTILESY; y++) |
615 | for (y = 0; y < WEATHERMAPTILESY; y++) |
570 | fprintf(fp, "%d ", weathermap[x][y].winddir); |
616 | fprintf (fp, "%d ", weathermap[x][y].winddir); |
571 | fprintf(fp, "\n"); |
617 | fprintf (fp, "\n"); |
572 | } |
618 | } |
573 | fclose(fp); |
619 | fclose (fp); |
574 | } |
620 | } |
575 | |
621 | |
|
|
622 | static void |
576 | static void read_winddirmap(void) |
623 | read_winddirmap (void) |
577 | { |
624 | { |
578 | char filename[MAX_BUF]; |
625 | char filename[MAX_BUF]; |
579 | FILE *fp; |
626 | FILE *fp; |
580 | int x, y, d; |
627 | int x, y, d; |
581 | |
628 | |
582 | sprintf(filename, "%s/winddirmap", settings.localdir); |
629 | sprintf (filename, "%s/winddirmap", settings.localdir); |
583 | LOG(llevDebug, "Reading wind direction data from %s...", filename); |
630 | LOG (llevDebug, "Reading wind direction data from %s...", filename); |
584 | if ((fp = fopen(filename, "r")) == NULL) { |
631 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
632 | { |
585 | LOG(llevError, "Cannot open %s for reading\n", filename); |
633 | LOG (llevError, "Cannot open %s for reading\n", filename); |
586 | LOG(llevDebug, "Initializing wind maps..."); |
634 | LOG (llevDebug, "Initializing wind maps..."); |
587 | init_wind(); |
635 | init_wind (); |
588 | write_winddirmap(); |
636 | write_winddirmap (); |
589 | LOG(llevDebug, "Done\n"); |
637 | LOG (llevDebug, "Done\n"); |
590 | return; |
638 | return; |
591 | } |
639 | } |
592 | for (x=0; x < WEATHERMAPTILESX; x++) { |
640 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
641 | { |
593 | for (y=0; y < WEATHERMAPTILESY; y++) { |
642 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
643 | { |
594 | fscanf(fp, "%d ", &d); |
644 | fscanf (fp, "%d ", &d); |
595 | weathermap[x][y].winddir = d; |
645 | weathermap[x][y].winddir = d; |
596 | if (weathermap[x][y].winddir < 1 || |
646 | if (weathermap[x][y].winddir < 1 || weathermap[x][y].winddir > 8) |
597 | weathermap[x][y].winddir > 8) |
|
|
598 | weathermap[x][y].winddir = rndm(1, 8); |
647 | weathermap[x][y].winddir = rndm (1, 8); |
599 | } |
648 | } |
600 | fscanf(fp, "\n"); |
649 | fscanf (fp, "\n"); |
601 | } |
650 | } |
602 | LOG(llevDebug, "Done.\n"); |
651 | LOG (llevDebug, "Done.\n"); |
603 | fclose(fp); |
652 | fclose (fp); |
604 | } |
653 | } |
605 | |
654 | |
606 | /* windspeed */ |
655 | /* windspeed */ |
607 | |
656 | |
|
|
657 | static void |
608 | static void write_windspeedmap(void) |
658 | write_windspeedmap (void) |
609 | { |
659 | { |
610 | char filename[MAX_BUF]; |
660 | char filename[MAX_BUF]; |
611 | FILE *fp; |
661 | FILE *fp; |
612 | int x, y; |
662 | int x, y; |
613 | |
663 | |
614 | sprintf(filename, "%s/windspeedmap", settings.localdir); |
664 | sprintf (filename, "%s/windspeedmap", settings.localdir); |
615 | if ((fp = fopen(filename, "w")) == NULL) { |
665 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
666 | { |
616 | LOG(llevError, "Cannot open %s for writing\n", filename); |
667 | LOG (llevError, "Cannot open %s for writing\n", filename); |
617 | return; |
668 | return; |
618 | } |
669 | } |
619 | for (x=0; x < WEATHERMAPTILESX; x++) { |
670 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
671 | { |
620 | for (y=0; y < WEATHERMAPTILESY; y++) |
672 | for (y = 0; y < WEATHERMAPTILESY; y++) |
621 | fprintf(fp, "%d ", weathermap[x][y].windspeed); |
673 | fprintf (fp, "%d ", weathermap[x][y].windspeed); |
622 | fprintf(fp, "\n"); |
674 | fprintf (fp, "\n"); |
623 | } |
675 | } |
624 | fclose(fp); |
676 | fclose (fp); |
625 | } |
677 | } |
626 | |
678 | |
|
|
679 | static void |
627 | static void read_windspeedmap(void) |
680 | read_windspeedmap (void) |
628 | { |
681 | { |
629 | char filename[MAX_BUF]; |
682 | char filename[MAX_BUF]; |
630 | FILE *fp; |
683 | FILE *fp; |
631 | int x, y, d; |
684 | int x, y, d; |
632 | |
685 | |
633 | sprintf(filename, "%s/windspeedmap", settings.localdir); |
686 | sprintf (filename, "%s/windspeedmap", settings.localdir); |
634 | LOG(llevDebug, "Reading wind speed data from %s...", filename); |
687 | LOG (llevDebug, "Reading wind speed data from %s...", filename); |
635 | if ((fp = fopen(filename, "r")) == NULL) { |
688 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
689 | { |
636 | LOG(llevError, "Cannot open %s for reading\n", filename); |
690 | LOG (llevError, "Cannot open %s for reading\n", filename); |
637 | LOG(llevDebug, "Initializing wind maps..."); |
691 | LOG (llevDebug, "Initializing wind maps..."); |
638 | init_wind(); |
692 | init_wind (); |
639 | write_windspeedmap(); |
693 | write_windspeedmap (); |
640 | LOG(llevDebug, "Done\n"); |
694 | LOG (llevDebug, "Done\n"); |
641 | return; |
695 | return; |
642 | } |
696 | } |
643 | for (x=0; x < WEATHERMAPTILESX; x++) { |
697 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
698 | { |
644 | for (y=0; y < WEATHERMAPTILESY; y++) { |
699 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
700 | { |
645 | fscanf(fp, "%d ", &d); |
701 | fscanf (fp, "%d ", &d); |
646 | weathermap[x][y].windspeed = d; |
702 | weathermap[x][y].windspeed = d; |
647 | if (weathermap[x][y].windspeed < 0 || |
703 | if (weathermap[x][y].windspeed < 0 || weathermap[x][y].windspeed > 120) |
648 | weathermap[x][y].windspeed > 120) |
|
|
649 | weathermap[x][y].windspeed = rndm(1, 30); |
704 | weathermap[x][y].windspeed = rndm (1, 30); |
650 | } |
705 | } |
651 | fscanf(fp, "\n"); |
706 | fscanf (fp, "\n"); |
652 | } |
707 | } |
653 | LOG(llevDebug, "Done.\n"); |
708 | LOG (llevDebug, "Done.\n"); |
654 | fclose(fp); |
709 | fclose (fp); |
655 | } |
710 | } |
656 | |
711 | |
657 | /* initialize the wind randomly. Does both direction and speed in one pass */ |
712 | /* initialize the wind randomly. Does both direction and speed in one pass */ |
658 | |
713 | |
659 | static void init_wind(void) |
714 | static void |
|
|
715 | init_wind (void) |
660 | { |
716 | { |
661 | int x, y; |
717 | int x, y; |
662 | |
718 | |
663 | for (x=0; x < WEATHERMAPTILESX; x++) |
719 | for (x = 0; x < WEATHERMAPTILESX; x++) |
664 | for (y=0; y < WEATHERMAPTILESY; y++) { |
720 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
721 | { |
665 | weathermap[x][y].winddir = rndm(1, 8); |
722 | weathermap[x][y].winddir = rndm (1, 8); |
666 | weathermap[x][y].windspeed = rndm(1, 10); |
723 | weathermap[x][y].windspeed = rndm (1, 10); |
|
|
724 | } |
|
|
725 | } |
|
|
726 | |
|
|
727 | /* gulf stream */ |
|
|
728 | |
|
|
729 | static void |
|
|
730 | write_gulfstreammap (void) |
|
|
731 | { |
|
|
732 | char filename[MAX_BUF]; |
|
|
733 | FILE *fp; |
|
|
734 | int x, y; |
|
|
735 | |
|
|
736 | sprintf (filename, "%s/gulfstreammap", settings.localdir); |
|
|
737 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
738 | { |
|
|
739 | LOG (llevError, "Cannot open %s for writing\n", filename); |
|
|
740 | return; |
|
|
741 | } |
|
|
742 | for (x = 0; x < GULF_STREAM_WIDTH; x++) |
|
|
743 | { |
|
|
744 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
745 | fprintf (fp, "%d ", gulf_stream_speed[x][y]); |
|
|
746 | fprintf (fp, "\n"); |
|
|
747 | } |
|
|
748 | for (x = 0; x < GULF_STREAM_WIDTH; x++) |
|
|
749 | { |
|
|
750 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
751 | fprintf (fp, "%d ", gulf_stream_dir[x][y]); |
|
|
752 | fprintf (fp, "\n"); |
|
|
753 | } |
|
|
754 | fclose (fp); |
|
|
755 | } |
|
|
756 | |
|
|
757 | static void |
|
|
758 | read_gulfstreammap (void) |
|
|
759 | { |
|
|
760 | char filename[MAX_BUF]; |
|
|
761 | FILE *fp; |
|
|
762 | int x, y; |
|
|
763 | |
|
|
764 | sprintf (filename, "%s/gulfstreammap", settings.localdir); |
|
|
765 | LOG (llevDebug, "Reading gulf stream data from %s...", filename); |
|
|
766 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
767 | { |
|
|
768 | LOG (llevError, "Cannot open %s for reading\n", filename); |
|
|
769 | LOG (llevDebug, "Initializing gulf stream maps..."); |
|
|
770 | init_gulfstreammap (); |
|
|
771 | write_gulfstreammap (); |
|
|
772 | LOG (llevDebug, "Done\n"); |
|
|
773 | return; |
|
|
774 | } |
|
|
775 | for (x = 0; x < GULF_STREAM_WIDTH; x++) |
|
|
776 | { |
|
|
777 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
778 | { |
|
|
779 | fscanf (fp, "%d ", &gulf_stream_speed[x][y]); |
|
|
780 | if (gulf_stream_speed[x][y] < 0 || gulf_stream_speed[x][y] > 120) |
|
|
781 | gulf_stream_speed[x][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
667 | } |
782 | } |
668 | } |
783 | fscanf (fp, "\n"); |
669 | |
|
|
670 | /* gulf stream */ |
|
|
671 | |
|
|
672 | static void write_gulfstreammap(void) |
|
|
673 | { |
|
|
674 | char filename[MAX_BUF]; |
|
|
675 | FILE *fp; |
|
|
676 | int x, y; |
|
|
677 | |
|
|
678 | sprintf(filename, "%s/gulfstreammap", settings.localdir); |
|
|
679 | if ((fp = fopen(filename, "w")) == NULL) { |
|
|
680 | LOG(llevError, "Cannot open %s for writing\n", filename); |
|
|
681 | return; |
|
|
682 | } |
784 | } |
683 | for (x=0; x < GULF_STREAM_WIDTH; x++) { |
785 | for (x = 0; x < GULF_STREAM_WIDTH; x++) |
|
|
786 | { |
684 | for (y=0; y < WEATHERMAPTILESY; y++) |
787 | for (y = 0; y < WEATHERMAPTILESY; y++) |
685 | fprintf(fp, "%d ", gulf_stream_speed[x][y]); |
788 | { |
686 | fprintf(fp, "\n"); |
|
|
687 | } |
|
|
688 | for (x=0; x < GULF_STREAM_WIDTH; x++) { |
|
|
689 | for (y=0; y < WEATHERMAPTILESY; y++) |
|
|
690 | fprintf(fp, "%d ", gulf_stream_dir[x][y]); |
|
|
691 | fprintf(fp, "\n"); |
|
|
692 | } |
|
|
693 | fclose(fp); |
|
|
694 | } |
|
|
695 | |
|
|
696 | static void read_gulfstreammap(void) |
|
|
697 | { |
|
|
698 | char filename[MAX_BUF]; |
|
|
699 | FILE *fp; |
|
|
700 | int x, y; |
|
|
701 | |
|
|
702 | sprintf(filename, "%s/gulfstreammap", settings.localdir); |
|
|
703 | LOG(llevDebug, "Reading gulf stream data from %s...", filename); |
|
|
704 | if ((fp = fopen(filename, "r")) == NULL) { |
|
|
705 | LOG(llevError, "Cannot open %s for reading\n", filename); |
|
|
706 | LOG(llevDebug, "Initializing gulf stream maps..."); |
|
|
707 | init_gulfstreammap(); |
|
|
708 | write_gulfstreammap(); |
|
|
709 | LOG(llevDebug, "Done\n"); |
|
|
710 | return; |
|
|
711 | } |
|
|
712 | for (x=0; x < GULF_STREAM_WIDTH; x++) { |
|
|
713 | for (y=0; y < WEATHERMAPTILESY; y++) { |
|
|
714 | fscanf(fp, "%d ", &gulf_stream_speed[x][y]); |
789 | fscanf (fp, "%d ", &gulf_stream_dir[x][y]); |
715 | if (gulf_stream_speed[x][y] < 0 || |
790 | if (gulf_stream_dir[x][y] < 0 || gulf_stream_dir[x][y] > 120) |
716 | gulf_stream_speed[x][y] > 120) |
791 | gulf_stream_dir[x][y] = rndm (1, 8); |
717 | gulf_stream_speed[x][y] = |
|
|
718 | rndm(GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED+10); |
|
|
719 | } |
792 | } |
720 | fscanf(fp, "\n"); |
793 | fscanf (fp, "\n"); |
|
|
794 | } |
|
|
795 | LOG (llevDebug, "Done.\n"); |
|
|
796 | fclose (fp); |
|
|
797 | } |
|
|
798 | |
|
|
799 | static void |
|
|
800 | init_gulfstreammap (void) |
|
|
801 | { |
|
|
802 | int x, y, tx; |
|
|
803 | |
|
|
804 | /* build a gulf stream */ |
|
|
805 | x = rndm (GULF_STREAM_WIDTH, WEATHERMAPTILESX - GULF_STREAM_WIDTH); |
|
|
806 | /* doth the great bob inhale or exhale? */ |
|
|
807 | gulf_stream_direction = rndm (0, 1); |
|
|
808 | gulf_stream_start = x; |
|
|
809 | |
|
|
810 | if (gulf_stream_direction) |
721 | } |
811 | { |
|
|
812 | for (y = WEATHERMAPTILESY - 1; y >= 0; y--) |
|
|
813 | { |
|
|
814 | switch (rndm (0, 6)) |
|
|
815 | { |
|
|
816 | case 0: |
|
|
817 | case 1: |
|
|
818 | case 2: |
722 | for (x=0; x < GULF_STREAM_WIDTH; x++) { |
819 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
723 | for (y=0; y < WEATHERMAPTILESY; y++) { |
820 | { |
724 | fscanf(fp, "%d ", &gulf_stream_dir[x][y]); |
821 | gulf_stream_speed[tx][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
725 | if (gulf_stream_dir[x][y] < 0 || |
822 | if (x == 0) |
726 | gulf_stream_dir[x][y] > 120) |
823 | gulf_stream_dir[tx][y] = 7; |
|
|
824 | else |
|
|
825 | { |
|
|
826 | gulf_stream_dir[tx][y] = 8; |
|
|
827 | if (tx == 0) |
|
|
828 | x--; |
|
|
829 | } |
|
|
830 | } |
|
|
831 | break; |
|
|
832 | case 3: |
|
|
833 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
|
|
834 | { |
|
|
835 | gulf_stream_speed[tx][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
727 | gulf_stream_dir[x][y] = rndm(1, 8); |
836 | gulf_stream_dir[tx][y] = 7; |
|
|
837 | } |
|
|
838 | break; |
|
|
839 | case 4: |
|
|
840 | case 5: |
|
|
841 | case 6: |
|
|
842 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
|
|
843 | { |
|
|
844 | gulf_stream_speed[tx][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
|
|
845 | if (x == WEATHERMAPTILESX - 1) |
|
|
846 | gulf_stream_dir[tx][y] = 7; |
|
|
847 | else |
|
|
848 | { |
|
|
849 | gulf_stream_dir[tx][y] = 6; |
|
|
850 | if (tx == 0) |
|
|
851 | x++; |
|
|
852 | } |
|
|
853 | } |
|
|
854 | break; |
|
|
855 | } |
728 | } |
856 | } |
729 | fscanf(fp, "\n"); |
|
|
730 | } |
857 | } |
731 | LOG(llevDebug, "Done.\n"); |
858 | else |
732 | fclose(fp); |
859 | { /* go right to left */ |
733 | } |
860 | for (y = 0; y < WEATHERMAPTILESY; y++) |
734 | |
861 | { |
735 | static void init_gulfstreammap(void) |
|
|
736 | { |
|
|
737 | int x, y, tx; |
|
|
738 | |
|
|
739 | /* build a gulf stream */ |
|
|
740 | x = rndm(GULF_STREAM_WIDTH, WEATHERMAPTILESX-GULF_STREAM_WIDTH); |
|
|
741 | /* doth the great bob inhale or exhale? */ |
|
|
742 | gulf_stream_direction = rndm(0, 1); |
|
|
743 | gulf_stream_start = x; |
|
|
744 | |
|
|
745 | if (gulf_stream_direction) { |
|
|
746 | for (y=WEATHERMAPTILESY-1; y >= 0; y--) { |
|
|
747 | switch(rndm(0, 6)) { |
862 | switch (rndm (0, 6)) |
|
|
863 | { |
748 | case 0: |
864 | case 0: |
749 | case 1: |
865 | case 1: |
750 | case 2: |
866 | case 2: |
751 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) { |
867 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
|
|
868 | { |
752 | gulf_stream_speed[tx][y] = rndm(GULF_STREAM_BASE_SPEED, |
869 | gulf_stream_speed[tx][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
753 | GULF_STREAM_BASE_SPEED+10); |
|
|
754 | if (x==0) |
870 | if (x == 0) |
755 | gulf_stream_dir[tx][y] = 7; |
871 | gulf_stream_dir[tx][y] = 3; |
756 | else { |
872 | else |
|
|
873 | { |
757 | gulf_stream_dir[tx][y] = 8; |
874 | gulf_stream_dir[tx][y] = 2; |
758 | if (tx == 0) |
875 | if (tx == 0) |
759 | x--; |
876 | x--; |
|
|
877 | } |
760 | } |
878 | } |
761 | } |
|
|
762 | break; |
879 | break; |
763 | case 3: |
880 | case 3: |
764 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) { |
881 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
|
|
882 | { |
765 | gulf_stream_speed[tx][y] = rndm(GULF_STREAM_BASE_SPEED, |
883 | gulf_stream_speed[tx][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
766 | GULF_STREAM_BASE_SPEED+10); |
|
|
767 | gulf_stream_dir[tx][y] = 7; |
884 | gulf_stream_dir[tx][y] = 3; |
768 | } |
885 | } |
769 | break; |
886 | break; |
770 | case 4: |
887 | case 4: |
771 | case 5: |
888 | case 5: |
772 | case 6: |
889 | case 6: |
773 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) { |
890 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
|
|
891 | { |
774 | gulf_stream_speed[tx][y] = rndm(GULF_STREAM_BASE_SPEED, |
892 | gulf_stream_speed[tx][y] = rndm (GULF_STREAM_BASE_SPEED, GULF_STREAM_BASE_SPEED + 10); |
775 | GULF_STREAM_BASE_SPEED+10); |
|
|
776 | if (x==WEATHERMAPTILESX-1) |
893 | if (x == WEATHERMAPTILESX - 1) |
777 | gulf_stream_dir[tx][y] = 7; |
894 | gulf_stream_dir[tx][y] = 3; |
778 | else { |
895 | else |
|
|
896 | { |
779 | gulf_stream_dir[tx][y] = 6; |
897 | gulf_stream_dir[tx][y] = 4; |
780 | if (tx == 0) |
898 | if (tx == 0) |
781 | x++; |
899 | x++; |
|
|
900 | } |
782 | } |
901 | } |
783 | } |
|
|
784 | break; |
902 | break; |
785 | } |
903 | } |
786 | } |
904 | } |
787 | } else { /* go right to left */ |
905 | } /* done */ |
|
|
906 | } |
|
|
907 | |
|
|
908 | /* humidity */ |
|
|
909 | |
|
|
910 | static void |
|
|
911 | write_humidmap (void) |
|
|
912 | { |
|
|
913 | char filename[MAX_BUF]; |
|
|
914 | FILE *fp; |
|
|
915 | int x, y; |
|
|
916 | |
|
|
917 | sprintf (filename, "%s/humidmap", settings.localdir); |
|
|
918 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
919 | { |
|
|
920 | LOG (llevError, "Cannot open %s for writing\n", filename); |
|
|
921 | return; |
|
|
922 | } |
|
|
923 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
924 | { |
788 | for (y=0; y < WEATHERMAPTILESY; y++) { |
925 | for (y = 0; y < WEATHERMAPTILESY; y++) |
789 | switch(rndm(0, 6)) { |
926 | fprintf (fp, "%d ", weathermap[x][y].humid); |
790 | case 0: |
927 | fprintf (fp, "\n"); |
791 | case 1: |
928 | } |
792 | case 2: |
929 | fclose (fp); |
793 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) { |
930 | } |
794 | gulf_stream_speed[tx][y] = rndm(GULF_STREAM_BASE_SPEED, |
931 | |
795 | GULF_STREAM_BASE_SPEED+10); |
932 | static void |
796 | if (x==0) |
933 | read_humidmap (void) |
797 | gulf_stream_dir[tx][y] = 3; |
934 | { |
798 | else { |
935 | char filename[MAX_BUF]; |
799 | gulf_stream_dir[tx][y] = 2; |
936 | FILE *fp; |
800 | if (tx == 0) |
937 | int x, y, d; |
801 | x--; |
938 | |
802 | } |
939 | sprintf (filename, "%s/humidmap", settings.localdir); |
803 | } |
940 | LOG (llevDebug, "Reading humidity data from %s...", filename); |
804 | break; |
941 | if ((fp = fopen (filename, "r")) == NULL) |
805 | case 3: |
942 | { |
806 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) { |
943 | LOG (llevError, "Cannot open %s for reading\n", filename); |
807 | gulf_stream_speed[tx][y] = rndm(GULF_STREAM_BASE_SPEED, |
944 | LOG (llevDebug, "Initializing humidity and elevation maps..."); |
808 | GULF_STREAM_BASE_SPEED+10); |
945 | init_humid_elev (); |
809 | gulf_stream_dir[tx][y] = 3; |
946 | write_elevmap (); |
810 | } |
947 | write_humidmap (); |
811 | break; |
948 | write_watermap (); |
812 | case 4: |
949 | LOG (llevDebug, "Done\n"); |
813 | case 5: |
950 | return; |
814 | case 6: |
951 | } |
815 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) { |
952 | for (x = 0; x < WEATHERMAPTILESX; x++) |
816 | gulf_stream_speed[tx][y] = rndm(GULF_STREAM_BASE_SPEED, |
953 | { |
817 | GULF_STREAM_BASE_SPEED+10); |
954 | for (y = 0; y < WEATHERMAPTILESY; y++) |
818 | if (x==WEATHERMAPTILESX-1) |
955 | { |
819 | gulf_stream_dir[tx][y] = 3; |
956 | fscanf (fp, "%d ", &d); |
820 | else { |
957 | weathermap[x][y].humid = d; |
821 | gulf_stream_dir[tx][y] = 4; |
958 | if (weathermap[x][y].humid < 0 || weathermap[x][y].humid > 100) |
822 | if (tx == 0) |
959 | weathermap[x][y].humid = rndm (0, 100); |
823 | x++; |
|
|
824 | } |
|
|
825 | } |
|
|
826 | break; |
|
|
827 | } |
|
|
828 | } |
960 | } |
829 | } /* done */ |
|
|
830 | } |
|
|
831 | |
|
|
832 | /* humidity */ |
|
|
833 | |
|
|
834 | static void write_humidmap(void) |
|
|
835 | { |
|
|
836 | char filename[MAX_BUF]; |
|
|
837 | FILE *fp; |
|
|
838 | int x, y; |
|
|
839 | |
|
|
840 | sprintf(filename, "%s/humidmap", settings.localdir); |
|
|
841 | if ((fp = fopen(filename, "w")) == NULL) { |
|
|
842 | LOG(llevError, "Cannot open %s for writing\n", filename); |
|
|
843 | return; |
|
|
844 | } |
|
|
845 | for (x=0; x < WEATHERMAPTILESX; x++) { |
|
|
846 | for (y=0; y < WEATHERMAPTILESY; y++) |
|
|
847 | fprintf(fp, "%d ", weathermap[x][y].humid); |
|
|
848 | fprintf(fp, "\n"); |
|
|
849 | } |
|
|
850 | fclose(fp); |
|
|
851 | } |
|
|
852 | |
|
|
853 | static void read_humidmap(void) |
|
|
854 | { |
|
|
855 | char filename[MAX_BUF]; |
|
|
856 | FILE *fp; |
|
|
857 | int x, y, d; |
|
|
858 | |
|
|
859 | sprintf(filename, "%s/humidmap", settings.localdir); |
|
|
860 | LOG(llevDebug, "Reading humidity data from %s...", filename); |
|
|
861 | if ((fp = fopen(filename, "r")) == NULL) { |
|
|
862 | LOG(llevError, "Cannot open %s for reading\n", filename); |
|
|
863 | LOG(llevDebug, "Initializing humidity and elevation maps..."); |
|
|
864 | init_humid_elev(); |
|
|
865 | write_elevmap(); |
|
|
866 | write_humidmap(); |
|
|
867 | write_watermap(); |
|
|
868 | LOG(llevDebug, "Done\n"); |
|
|
869 | return; |
|
|
870 | } |
|
|
871 | for (x=0; x < WEATHERMAPTILESX; x++) { |
|
|
872 | for (y=0; y < WEATHERMAPTILESY; y++) { |
|
|
873 | fscanf(fp, "%d ", &d); |
|
|
874 | weathermap[x][y].humid = d; |
|
|
875 | if (weathermap[x][y].humid < 0 || |
|
|
876 | weathermap[x][y].humid > 100) |
|
|
877 | weathermap[x][y].humid = rndm(0, 100); |
|
|
878 | } |
|
|
879 | fscanf(fp, "\n"); |
961 | fscanf (fp, "\n"); |
880 | } |
962 | } |
881 | LOG(llevDebug, "Done.\n"); |
963 | LOG (llevDebug, "Done.\n"); |
882 | fclose(fp); |
964 | fclose (fp); |
883 | } |
965 | } |
884 | |
966 | |
885 | /* average elevation */ |
967 | /* average elevation */ |
886 | |
968 | |
887 | static void write_elevmap(void) |
969 | static void |
|
|
970 | write_elevmap (void) |
888 | { |
971 | { |
889 | char filename[MAX_BUF]; |
972 | char filename[MAX_BUF]; |
890 | FILE *fp; |
973 | FILE *fp; |
891 | int x, y; |
974 | int x, y; |
892 | |
975 | |
893 | sprintf(filename, "%s/elevmap", settings.localdir); |
976 | sprintf (filename, "%s/elevmap", settings.localdir); |
894 | if ((fp = fopen(filename, "w")) == NULL) { |
977 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
978 | { |
895 | LOG(llevError, "Cannot open %s for writing\n", filename); |
979 | LOG (llevError, "Cannot open %s for writing\n", filename); |
896 | return; |
980 | return; |
897 | } |
981 | } |
898 | for (x=0; x < WEATHERMAPTILESX; x++) { |
982 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
983 | { |
899 | for (y=0; y < WEATHERMAPTILESY; y++) |
984 | for (y = 0; y < WEATHERMAPTILESY; y++) |
900 | fprintf(fp, "%d ", weathermap[x][y].avgelev); |
985 | fprintf (fp, "%d ", weathermap[x][y].avgelev); |
901 | fprintf(fp, "\n"); |
986 | fprintf (fp, "\n"); |
902 | } |
987 | } |
903 | fclose(fp); |
988 | fclose (fp); |
904 | } |
989 | } |
905 | |
990 | |
906 | static void read_elevmap(void) |
991 | static void |
|
|
992 | read_elevmap (void) |
907 | { |
993 | { |
908 | char filename[MAX_BUF]; |
994 | char filename[MAX_BUF]; |
909 | FILE *fp; |
995 | FILE *fp; |
910 | int x, y; |
996 | int x, y; |
911 | |
997 | |
912 | sprintf(filename, "%s/elevmap", settings.localdir); |
998 | sprintf (filename, "%s/elevmap", settings.localdir); |
913 | LOG(llevDebug, "Reading elevation data from %s...", filename); |
999 | LOG (llevDebug, "Reading elevation data from %s...", filename); |
914 | if ((fp = fopen(filename, "r")) == NULL) { |
1000 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1001 | { |
915 | LOG(llevError, "Cannot open %s for reading\n", filename); |
1002 | LOG (llevError, "Cannot open %s for reading\n", filename); |
916 | /* initializing these is expensive, and should have been done |
1003 | /* initializing these is expensive, and should have been done |
917 | by the humidity. It's not worth the wait to do it twice. */ |
1004 | by the humidity. It's not worth the wait to do it twice. */ |
918 | return; |
1005 | return; |
919 | } |
1006 | } |
920 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1007 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1008 | { |
921 | for (y=0; y < WEATHERMAPTILESY; y++) { |
1009 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1010 | { |
922 | fscanf(fp, "%d ", &weathermap[x][y].avgelev); |
1011 | fscanf (fp, "%d ", &weathermap[x][y].avgelev); |
923 | if (weathermap[x][y].avgelev < -10000 || |
1012 | if (weathermap[x][y].avgelev < -10000 || weathermap[x][y].avgelev > 15000) |
924 | weathermap[x][y].avgelev > 15000) |
|
|
925 | weathermap[x][y].avgelev = rndm(-1000, 10000); |
1013 | weathermap[x][y].avgelev = rndm (-1000, 10000); |
926 | } |
1014 | } |
927 | fscanf(fp, "\n"); |
1015 | fscanf (fp, "\n"); |
928 | } |
1016 | } |
929 | LOG(llevDebug, "Done.\n"); |
1017 | LOG (llevDebug, "Done.\n"); |
930 | fclose(fp); |
1018 | fclose (fp); |
931 | } |
1019 | } |
932 | |
1020 | |
933 | /* water % */ |
1021 | /* water % */ |
934 | |
1022 | |
|
|
1023 | static void |
935 | static void write_watermap(void) |
1024 | write_watermap (void) |
936 | { |
1025 | { |
937 | char filename[MAX_BUF]; |
1026 | char filename[MAX_BUF]; |
938 | FILE *fp; |
1027 | FILE *fp; |
939 | int x, y; |
1028 | int x, y; |
940 | |
1029 | |
941 | sprintf(filename, "%s/watermap", settings.localdir); |
1030 | sprintf (filename, "%s/watermap", settings.localdir); |
942 | if ((fp = fopen(filename, "w")) == NULL) { |
1031 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
1032 | { |
943 | LOG(llevError, "Cannot open %s for writing\n", filename); |
1033 | LOG (llevError, "Cannot open %s for writing\n", filename); |
944 | return; |
1034 | return; |
945 | } |
1035 | } |
946 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1036 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1037 | { |
947 | for (y=0; y < WEATHERMAPTILESY; y++) |
1038 | for (y = 0; y < WEATHERMAPTILESY; y++) |
948 | fprintf(fp, "%d ", weathermap[x][y].water); |
1039 | fprintf (fp, "%d ", weathermap[x][y].water); |
949 | fprintf(fp, "\n"); |
1040 | fprintf (fp, "\n"); |
950 | } |
1041 | } |
951 | fclose(fp); |
1042 | fclose (fp); |
952 | } |
1043 | } |
953 | |
1044 | |
954 | static void read_watermap(void) |
1045 | static void |
|
|
1046 | read_watermap (void) |
955 | { |
1047 | { |
956 | char filename[MAX_BUF]; |
1048 | char filename[MAX_BUF]; |
957 | FILE *fp; |
1049 | FILE *fp; |
958 | int x, y, d; |
1050 | int x, y, d; |
959 | |
1051 | |
960 | sprintf(filename, "%s/watermap", settings.localdir); |
1052 | sprintf (filename, "%s/watermap", settings.localdir); |
961 | LOG(llevDebug, "Reading water data from %s...", filename); |
1053 | LOG (llevDebug, "Reading water data from %s...", filename); |
962 | if ((fp = fopen(filename, "r")) == NULL) { |
1054 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1055 | { |
963 | LOG(llevError, "Cannot open %s for reading\n", filename); |
1056 | LOG (llevError, "Cannot open %s for reading\n", filename); |
964 | /* initializing these is expensive, and should have been done |
1057 | /* initializing these is expensive, and should have been done |
965 | by the humidity. It's not worth the wait to do it twice. */ |
1058 | by the humidity. It's not worth the wait to do it twice. */ |
966 | return; |
1059 | return; |
967 | } |
1060 | } |
968 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1061 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1062 | { |
969 | for (y=0; y < WEATHERMAPTILESY; y++) { |
1063 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1064 | { |
970 | fscanf(fp, "%d ", &d); |
1065 | fscanf (fp, "%d ", &d); |
971 | weathermap[x][y].water = d; |
1066 | weathermap[x][y].water = d; |
972 | if (weathermap[x][y].water > 100) |
1067 | if (weathermap[x][y].water > 100) |
973 | weathermap[x][y].water = rndm(0, 100); |
1068 | weathermap[x][y].water = rndm (0, 100); |
974 | } |
1069 | } |
975 | fscanf(fp, "\n"); |
1070 | fscanf (fp, "\n"); |
976 | } |
1071 | } |
977 | LOG(llevDebug, "Done.\n"); |
1072 | LOG (llevDebug, "Done.\n"); |
978 | fclose(fp); |
1073 | fclose (fp); |
979 | } |
1074 | } |
980 | |
1075 | |
981 | /* |
1076 | /* |
982 | * initialize both humidity and elevation |
1077 | * initialize both humidity and elevation |
983 | */ |
1078 | */ |
984 | |
1079 | |
|
|
1080 | static void |
985 | static void init_humid_elev(void) |
1081 | init_humid_elev (void) |
986 | { |
1082 | { |
987 | int x, y, tx, ty, nx, ny, ax, ay, j; |
1083 | int x, y, tx, ty, nx, ny, ax, ay, j; |
988 | int spwtx, spwty; |
1084 | int spwtx, spwty; |
989 | const char *mapname; |
1085 | const char *mapname; |
990 | long int elev; |
1086 | long int elev; |
991 | int water, space; |
1087 | int water, space; |
992 | mapstruct *m; |
1088 | mapstruct *m; |
993 | |
1089 | |
994 | /* handling of this is kinda nasty. For that reason, |
1090 | /* handling of this is kinda nasty. For that reason, |
995 | * we do the elevation here too. Not because it makes the |
1091 | * we do the elevation here too. Not because it makes the |
996 | * code cleaner, or makes handling easier, but because I do *not* |
1092 | * code cleaner, or makes handling easier, but because I do *not* |
997 | * want to maintain two of these nightmares. |
1093 | * want to maintain two of these nightmares. |
998 | */ |
1094 | */ |
999 | |
1095 | |
1000 | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
1096 | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
1001 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
1097 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
1002 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1098 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1099 | { |
1003 | for (y=0; y < WEATHERMAPTILESY; y++) { |
1100 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1101 | { |
1004 | water = 0; |
1102 | water = 0; |
1005 | elev = 0; |
1103 | elev = 0; |
1006 | nx = 0; |
1104 | nx = 0; |
1007 | ny = 0; |
1105 | ny = 0; |
1008 | space = 0; |
1106 | space = 0; |
1009 | |
1107 | |
1010 | /* top left */ |
1108 | /* top left */ |
1011 | mapname=weathermap_to_worldmap_corner(x, y, &tx, &ty, 8); |
1109 | mapname = weathermap_to_worldmap_corner (x, y, &tx, &ty, 8); |
1012 | m = load_original_map(mapname, 0); |
1110 | m = load_original_map (mapname, 0); |
1013 | if (m == NULL) |
1111 | if (m == NULL) |
1014 | continue; |
1112 | continue; |
1015 | m = load_overlay_map(mapname, m); |
1113 | m = load_overlay_map (mapname, m); |
1016 | if (m == NULL) |
1114 | if (m == NULL) |
1017 | continue; |
1115 | continue; |
1018 | for (nx = 0, ax = tx; ( nx < spwtx && (uint32) ax < settings.worldmaptilesizex && |
1116 | for (nx = 0, ax = tx; (nx < spwtx && (uint32) ax < settings.worldmaptilesizex && space < spwtx * spwty); ax++, nx++) |
1019 | space < spwtx * spwty); ax++, nx++) { |
1117 | { |
1020 | for (ny=0,ay=ty; (ny < spwty && (uint32) ay < settings.worldmaptilesizey && |
1118 | for (ny = 0, ay = ty; (ny < spwty && (uint32) ay < settings.worldmaptilesizey && space < spwtx * spwty); ay++, ny++, space++) |
1021 | space < spwtx*spwty); |
|
|
1022 | ay++,ny++,space++) |
|
|
1023 | if(GET_MAP_OB(m, ax, ay)){ |
1119 | if (GET_MAP_OB (m, ax, ay)) |
|
|
1120 | { |
1024 | if (QUERY_FLAG(GET_MAP_OB(m, ax, ay), FLAG_IS_WATER)) |
1121 | if (QUERY_FLAG (GET_MAP_OB (m, ax, ay), FLAG_IS_WATER)) |
1025 | water++; |
1122 | water++; |
1026 | elev += GET_MAP_OB(m, ax, ay)->elevation; |
1123 | elev += GET_MAP_OB (m, ax, ay)->elevation; |
1027 | } |
1124 | } |
1028 | } |
1125 | } |
1029 | delete_map(m); |
1126 | delete_map (m); |
1030 | |
1127 | |
1031 | /* bottom left */ |
1128 | /* bottom left */ |
1032 | mapname=weathermap_to_worldmap_corner(x, y, &tx, &ty, 6); |
1129 | mapname = weathermap_to_worldmap_corner (x, y, &tx, &ty, 6); |
1033 | m = load_original_map(mapname, 0); |
1130 | m = load_original_map (mapname, 0); |
1034 | if (m == NULL) |
1131 | if (m == NULL) |
1035 | continue; |
1132 | continue; |
1036 | m = load_overlay_map(mapname, m); |
1133 | m = load_overlay_map (mapname, m); |
1037 | if (m == NULL) |
1134 | if (m == NULL) |
1038 | continue; |
1135 | continue; |
1039 | j = ny; |
1136 | j = ny; |
1040 | for (nx = 0, ax = tx; (nx < spwtx && (uint32) ax < settings.worldmaptilesizex && |
1137 | for (nx = 0, ax = tx; (nx < spwtx && (uint32) ax < settings.worldmaptilesizex && space < spwtx * spwty); ax++, nx++) |
1041 | space < spwtx * spwty); ax++, nx++) { |
1138 | { |
1042 | for (ny=j,ay=MAX(0, ty - (spwty-1)); (ny < spwty && ay <= ty && |
1139 | for (ny = j, ay = MAX (0, ty - (spwty - 1)); (ny < spwty && ay <= ty && space < spwtx * spwty); space++, ay++, ny++) |
1043 | space < spwtx * spwty); |
|
|
1044 | space++,ay++,ny++) |
|
|
1045 | if(GET_MAP_OB(m, ax, ay)){ |
1140 | if (GET_MAP_OB (m, ax, ay)) |
|
|
1141 | { |
1046 | if (QUERY_FLAG(GET_MAP_OB(m, ax, ay), FLAG_IS_WATER)) |
1142 | if (QUERY_FLAG (GET_MAP_OB (m, ax, ay), FLAG_IS_WATER)) |
1047 | water++; |
1143 | water++; |
1048 | elev += GET_MAP_OB(m, ax, ay)->elevation; |
1144 | elev += GET_MAP_OB (m, ax, ay)->elevation; |
1049 | } |
1145 | } |
1050 | } |
1146 | } |
1051 | delete_map(m); |
1147 | delete_map (m); |
1052 | |
1148 | |
1053 | /* top right */ |
1149 | /* top right */ |
1054 | mapname=weathermap_to_worldmap_corner(x, y, &tx, &ty, 2); |
1150 | mapname = weathermap_to_worldmap_corner (x, y, &tx, &ty, 2); |
1055 | m = load_original_map(mapname, 0); |
1151 | m = load_original_map (mapname, 0); |
1056 | if (m == NULL) |
1152 | if (m == NULL) |
1057 | continue; |
1153 | continue; |
1058 | m = load_overlay_map(mapname, m); |
1154 | m = load_overlay_map (mapname, m); |
1059 | if (m == NULL) |
1155 | if (m == NULL) |
1060 | continue; |
1156 | continue; |
1061 | for (ax=MAX(0, tx - (spwtx-1)); (nx < spwtx && ax < tx && |
1157 | for (ax = MAX (0, tx - (spwtx - 1)); (nx < spwtx && ax < tx && space < spwtx * spwty); ax++, nx++) |
1062 | space < spwtx*spwty); ax++,nx++) { |
1158 | { |
1063 | for (ny = 0, ay = ty; (ny < spwty && (uint32) ay < settings.worldmaptilesizey && |
1159 | for (ny = 0, ay = ty; (ny < spwty && (uint32) ay < settings.worldmaptilesizey && space < spwtx * spwty); ay++, ny++, space++) |
1064 | space < spwtx*spwty); |
|
|
1065 | ay++,ny++,space++) |
|
|
1066 | if(GET_MAP_OB(m, ax, ay)){ |
1160 | if (GET_MAP_OB (m, ax, ay)) |
|
|
1161 | { |
1067 | if (QUERY_FLAG(GET_MAP_OB(m, ax, ay), FLAG_IS_WATER)) |
1162 | if (QUERY_FLAG (GET_MAP_OB (m, ax, ay), FLAG_IS_WATER)) |
1068 | water++; |
1163 | water++; |
1069 | elev += GET_MAP_OB(m, ax, ay)->elevation; |
1164 | elev += GET_MAP_OB (m, ax, ay)->elevation; |
1070 | } |
1165 | } |
1071 | } |
1166 | } |
1072 | delete_map(m); |
1167 | delete_map (m); |
1073 | |
1168 | |
1074 | /* bottom left */ |
1169 | /* bottom left */ |
1075 | mapname=weathermap_to_worldmap_corner(x, y, &tx, &ty, 4); |
1170 | mapname = weathermap_to_worldmap_corner (x, y, &tx, &ty, 4); |
1076 | m = load_original_map(mapname, 0); |
1171 | m = load_original_map (mapname, 0); |
1077 | if (m == NULL) |
1172 | if (m == NULL) |
1078 | continue; |
1173 | continue; |
1079 | m = load_overlay_map(mapname, m); |
1174 | m = load_overlay_map (mapname, m); |
1080 | if (m == NULL) |
1175 | if (m == NULL) |
1081 | continue; |
1176 | continue; |
1082 | for (nx=0,ax=MAX(0, tx - (spwtx-1)); (nx < spwtx && ax < tx && |
1177 | for (nx = 0, ax = MAX (0, tx - (spwtx - 1)); (nx < spwtx && ax < tx && space < spwtx * spwty); ax++, nx++) |
1083 | space < spwtx*spwty); ax++,nx++) { |
1178 | { |
1084 | for (ny=0,ay=MAX(0, ty - (spwty-1)); (ny < spwty && ay <= ty && |
1179 | for (ny = 0, ay = MAX (0, ty - (spwty - 1)); (ny < spwty && ay <= ty && space < spwtx * spwty); space++, ay++, ny++) |
1085 | space < spwtx*spwty); |
|
|
1086 | space++,ay++,ny++) |
|
|
1087 | if(GET_MAP_OB(m, ax, ay)){ |
1180 | if (GET_MAP_OB (m, ax, ay)) |
|
|
1181 | { |
1088 | if (QUERY_FLAG(GET_MAP_OB(m, ax, ay), FLAG_IS_WATER)) |
1182 | if (QUERY_FLAG (GET_MAP_OB (m, ax, ay), FLAG_IS_WATER)) |
1089 | water++; |
1183 | water++; |
1090 | elev += GET_MAP_OB(m, ax, ay)->elevation; |
1184 | elev += GET_MAP_OB (m, ax, ay)->elevation; |
1091 | } |
1185 | } |
1092 | } |
1186 | } |
1093 | delete_map(m); |
1187 | delete_map (m); |
1094 | /* jesus thats confusing as all hell */ |
1188 | /* jesus thats confusing as all hell */ |
1095 | weathermap[x][y].humid = water*100/(spwtx*spwty); |
1189 | weathermap[x][y].humid = water * 100 / (spwtx * spwty); |
1096 | weathermap[x][y].avgelev = elev/(spwtx*spwty); |
1190 | weathermap[x][y].avgelev = elev / (spwtx * spwty); |
1097 | weathermap[x][y].water = weathermap[x][y].humid; |
1191 | weathermap[x][y].water = weathermap[x][y].humid; |
1098 | } |
1192 | } |
1099 | } |
1193 | } |
1100 | |
1194 | |
1101 | /* and this does all the real work */ |
1195 | /* and this does all the real work */ |
1102 | for (x=0; x < WEATHERMAPTILESX; x++) |
1196 | for (x = 0; x < WEATHERMAPTILESX; x++) |
1103 | for (y=0; y < WEATHERMAPTILESY; y++) |
1197 | for (y = 0; y < WEATHERMAPTILESY; y++) |
1104 | weathermap[x][y].humid = humid_tile(x, y); |
1198 | weathermap[x][y].humid = humid_tile (x, y); |
1105 | } |
1199 | } |
1106 | |
1200 | |
1107 | /* temperature */ |
1201 | /* temperature */ |
1108 | |
1202 | |
|
|
1203 | static void |
1109 | static void write_temperaturemap(void) |
1204 | write_temperaturemap (void) |
1110 | { |
1205 | { |
1111 | char filename[MAX_BUF]; |
1206 | char filename[MAX_BUF]; |
1112 | FILE *fp; |
1207 | FILE *fp; |
1113 | int x, y; |
1208 | int x, y; |
1114 | |
1209 | |
1115 | sprintf(filename, "%s/temperaturemap", settings.localdir); |
1210 | sprintf (filename, "%s/temperaturemap", settings.localdir); |
1116 | if ((fp = fopen(filename, "w")) == NULL) { |
1211 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
1212 | { |
1117 | LOG(llevError, "Cannot open %s for writing\n", filename); |
1213 | LOG (llevError, "Cannot open %s for writing\n", filename); |
1118 | return; |
1214 | return; |
1119 | } |
1215 | } |
1120 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1216 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1217 | { |
1121 | for (y=0; y < WEATHERMAPTILESY; y++) |
1218 | for (y = 0; y < WEATHERMAPTILESY; y++) |
1122 | fprintf(fp, "%d ", weathermap[x][y].temp); |
1219 | fprintf (fp, "%d ", weathermap[x][y].temp); |
1123 | fprintf(fp, "\n"); |
1220 | fprintf (fp, "\n"); |
1124 | } |
1221 | } |
1125 | fclose(fp); |
1222 | fclose (fp); |
1126 | } |
1223 | } |
1127 | |
1224 | |
|
|
1225 | static void |
1128 | static void read_temperaturemap(void) |
1226 | read_temperaturemap (void) |
1129 | { |
1227 | { |
1130 | char filename[MAX_BUF]; |
1228 | char filename[MAX_BUF]; |
1131 | FILE *fp; |
1229 | FILE *fp; |
1132 | int x, y; |
1230 | int x, y; |
1133 | |
1231 | |
1134 | sprintf(filename, "%s/temperaturemap", settings.localdir); |
1232 | sprintf (filename, "%s/temperaturemap", settings.localdir); |
1135 | LOG(llevDebug, "Reading temperature data from %s...", filename); |
1233 | LOG (llevDebug, "Reading temperature data from %s...", filename); |
1136 | if ((fp = fopen(filename, "r")) == NULL) { |
1234 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1235 | { |
1137 | LOG(llevError, "Cannot open %s for reading\n", filename); |
1236 | LOG (llevError, "Cannot open %s for reading\n", filename); |
1138 | init_temperature(); |
1237 | init_temperature (); |
1139 | write_temperaturemap(); |
1238 | write_temperaturemap (); |
1140 | return; |
1239 | return; |
1141 | } |
1240 | } |
1142 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1241 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1242 | { |
1143 | for (y=0; y < WEATHERMAPTILESY; y++) { |
1243 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1244 | { |
1144 | fscanf(fp, "%hd ", &weathermap[x][y].temp); |
1245 | fscanf (fp, "%hd ", &weathermap[x][y].temp); |
1145 | if (weathermap[x][y].temp < -30 || |
1246 | if (weathermap[x][y].temp < -30 || weathermap[x][y].temp > 60) |
1146 | weathermap[x][y].temp > 60) |
|
|
1147 | weathermap[x][y].temp = rndm(-10, 40); |
1247 | weathermap[x][y].temp = rndm (-10, 40); |
1148 | } |
1248 | } |
1149 | fscanf(fp, "\n"); |
1249 | fscanf (fp, "\n"); |
1150 | } |
1250 | } |
1151 | LOG(llevDebug, "Done.\n"); |
1251 | LOG (llevDebug, "Done.\n"); |
1152 | fclose(fp); |
1252 | fclose (fp); |
1153 | } |
1253 | } |
1154 | |
1254 | |
|
|
1255 | static void |
1155 | static void init_temperature(void) |
1256 | init_temperature (void) |
1156 | { |
1257 | { |
1157 | int x, y; |
1258 | int x, y; |
1158 | timeofday_t tod; |
1259 | timeofday_t tod; |
1159 | |
1260 | |
1160 | get_tod(&tod); |
1261 | get_tod (&tod); |
1161 | for (x=0; x < WEATHERMAPTILESX; x++) |
1262 | for (x = 0; x < WEATHERMAPTILESX; x++) |
1162 | for (y=0; y < WEATHERMAPTILESY; y++) |
1263 | for (y = 0; y < WEATHERMAPTILESY; y++) |
1163 | temperature_calc(x, y, &tod); |
1264 | temperature_calc (x, y, &tod); |
1164 | } |
1265 | } |
1165 | |
1266 | |
1166 | /* rainfall */ |
1267 | /* rainfall */ |
1167 | |
1268 | |
|
|
1269 | static void |
1168 | static void write_rainfallmap(void) |
1270 | write_rainfallmap (void) |
1169 | { |
1271 | { |
1170 | char filename[MAX_BUF]; |
1272 | char filename[MAX_BUF]; |
1171 | FILE *fp; |
1273 | FILE *fp; |
1172 | int x, y; |
1274 | int x, y; |
1173 | |
1275 | |
1174 | sprintf(filename, "%s/rainfallmap", settings.localdir); |
1276 | sprintf (filename, "%s/rainfallmap", settings.localdir); |
1175 | if ((fp = fopen(filename, "w")) == NULL) { |
1277 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
1278 | { |
1176 | LOG(llevError, "Cannot open %s for writing\n", filename); |
1279 | LOG (llevError, "Cannot open %s for writing\n", filename); |
1177 | return; |
1280 | return; |
1178 | } |
1281 | } |
1179 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1282 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1283 | { |
1180 | for (y=0; y < WEATHERMAPTILESY; y++) |
1284 | for (y = 0; y < WEATHERMAPTILESY; y++) |
1181 | fprintf(fp, "%u ", weathermap[x][y].rainfall); |
1285 | fprintf (fp, "%u ", weathermap[x][y].rainfall); |
1182 | fprintf(fp, "\n"); |
1286 | fprintf (fp, "\n"); |
1183 | } |
1287 | } |
1184 | fclose(fp); |
1288 | fclose (fp); |
1185 | } |
1289 | } |
1186 | |
1290 | |
|
|
1291 | static void |
1187 | static void read_rainfallmap(void) |
1292 | read_rainfallmap (void) |
1188 | { |
1293 | { |
1189 | char filename[MAX_BUF]; |
1294 | char filename[MAX_BUF]; |
1190 | FILE *fp; |
1295 | FILE *fp; |
1191 | int x, y; |
1296 | int x, y; |
1192 | |
1297 | |
1193 | sprintf(filename, "%s/rainfallmap", settings.localdir); |
1298 | sprintf (filename, "%s/rainfallmap", settings.localdir); |
1194 | LOG(llevDebug, "Reading rainfall data from %s...", filename); |
1299 | LOG (llevDebug, "Reading rainfall data from %s...", filename); |
1195 | if ((fp = fopen(filename, "r")) == NULL) { |
1300 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1301 | { |
1196 | LOG(llevError, "Cannot open %s for reading\n", filename); |
1302 | LOG (llevError, "Cannot open %s for reading\n", filename); |
1197 | init_rainfall(); |
1303 | init_rainfall (); |
1198 | write_rainfallmap(); |
1304 | write_rainfallmap (); |
1199 | return; |
1305 | return; |
1200 | } |
1306 | } |
1201 | for (x=0; x < WEATHERMAPTILESX; x++) { |
1307 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
1308 | { |
1202 | for (y=0; y < WEATHERMAPTILESY; y++) { |
1309 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1310 | { |
1203 | fscanf(fp, "%u ", &weathermap[x][y].rainfall); |
1311 | fscanf (fp, "%u ", &weathermap[x][y].rainfall); |
1204 | } |
1312 | } |
1205 | fscanf(fp, "\n"); |
1313 | fscanf (fp, "\n"); |
1206 | } |
1314 | } |
1207 | LOG(llevDebug, "Done.\n"); |
1315 | LOG (llevDebug, "Done.\n"); |
1208 | fclose(fp); |
1316 | fclose (fp); |
1209 | } |
1317 | } |
1210 | |
1318 | |
1211 | static void init_rainfall(void) |
1319 | static void |
|
|
1320 | init_rainfall (void) |
1212 | { |
1321 | { |
1213 | int x, y; |
1322 | int x, y; |
1214 | int days; |
1323 | int days; |
1215 | |
1324 | |
1216 | for (x=0; x < WEATHERMAPTILESX; x++) |
1325 | for (x = 0; x < WEATHERMAPTILESX; x++) |
1217 | for (y=0; y < WEATHERMAPTILESY; y++) { |
1326 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1327 | { |
1218 | days = todtick / HOURS_PER_DAY; |
1328 | days = todtick / HOURS_PER_DAY; |
1219 | if (weathermap[x][y].humid < 10) |
1329 | if (weathermap[x][y].humid < 10) |
1220 | weathermap[x][y].rainfall = days / 20; |
1330 | weathermap[x][y].rainfall = days / 20; |
1221 | else if (weathermap[x][y].humid < 20) |
1331 | else if (weathermap[x][y].humid < 20) |
1222 | weathermap[x][y].rainfall = days / 15; |
1332 | weathermap[x][y].rainfall = days / 15; |
1223 | else if (weathermap[x][y].humid < 30) |
1333 | else if (weathermap[x][y].humid < 30) |
1224 | weathermap[x][y].rainfall = days / 10; |
1334 | weathermap[x][y].rainfall = days / 10; |
1225 | else if (weathermap[x][y].humid < 40) |
1335 | else if (weathermap[x][y].humid < 40) |
1226 | weathermap[x][y].rainfall = days / 5; |
1336 | weathermap[x][y].rainfall = days / 5; |
1227 | else if (weathermap[x][y].humid < 50) |
1337 | else if (weathermap[x][y].humid < 50) |
1228 | weathermap[x][y].rainfall = days / 2; |
1338 | weathermap[x][y].rainfall = days / 2; |
1229 | else if (weathermap[x][y].humid < 60) |
1339 | else if (weathermap[x][y].humid < 60) |
1230 | weathermap[x][y].rainfall = days; |
1340 | weathermap[x][y].rainfall = days; |
1231 | else if (weathermap[x][y].humid < 80) |
1341 | else if (weathermap[x][y].humid < 80) |
1232 | weathermap[x][y].rainfall = days * 2; |
1342 | weathermap[x][y].rainfall = days * 2; |
1233 | else |
1343 | else |
1234 | weathermap[x][y].rainfall = days * 3; |
1344 | weathermap[x][y].rainfall = days * 3; |
1235 | } |
1345 | } |
1236 | } |
1346 | } |
1237 | |
1347 | |
1238 | /* END of read/write/init */ |
1348 | /* END of read/write/init */ |
1239 | |
1349 | |
1240 | |
1350 | |
1241 | |
1351 | |
|
|
1352 | static void |
1242 | static void init_weatheravoid (weather_avoids_t wa[]){ |
1353 | init_weatheravoid (weather_avoids_t wa[]) |
1243 | int i; |
1354 | { |
|
|
1355 | int i; |
|
|
1356 | |
1244 | for (i=0; wa[i].name != NULL; i++) { |
1357 | for (i = 0; wa[i].name != NULL; i++) |
|
|
1358 | { |
1245 | wa[i].what=find_archetype(wa[i].name); |
1359 | wa[i].what = archetype::find (wa[i].name); |
1246 | } |
1360 | } |
1247 | } |
1361 | } |
1248 | |
1362 | |
1249 | static int wmperformstartx; |
1363 | static int wmperformstartx; |
1250 | static int wmperformstarty; |
1364 | static int wmperformstarty; |
1251 | |
1365 | |
… | |
… | |
1253 | * This function initializes the weather system. It should be called once, |
1367 | * This function initializes the weather system. It should be called once, |
1254 | * at game startup only. |
1368 | * at game startup only. |
1255 | */ |
1369 | */ |
1256 | |
1370 | |
1257 | |
1371 | |
|
|
1372 | void |
1258 | void init_weather(void) |
1373 | init_weather (void) |
1259 | { |
1374 | { |
1260 | int y, tx, ty; |
1375 | int y, tx, ty; |
1261 | char filename[MAX_BUF]; |
1376 | char filename[MAX_BUF]; |
1262 | FILE *fp; |
1377 | FILE *fp; |
1263 | |
1378 | |
1264 | /* all this stuff needs to be set, otherwise this function will cause |
1379 | /* all this stuff needs to be set, otherwise this function will cause |
1265 | * chaos and destruction. |
1380 | * chaos and destruction. |
1266 | */ |
1381 | */ |
1267 | if (settings.dynamiclevel < 1) |
1382 | if (settings.dynamiclevel < 1) |
1268 | return; |
1383 | return; |
1269 | if (settings.worldmapstartx < 1 || settings.worldmapstarty < 1 || |
1384 | if (settings.worldmapstartx < 1 || settings.worldmapstarty < 1 || |
1270 | settings.worldmaptilesx < 1 || settings.worldmaptilesy < 1 || |
1385 | settings.worldmaptilesx < 1 || settings.worldmaptilesy < 1 || settings.worldmaptilesizex < 1 || settings.worldmaptilesizex < 1) |
1271 | settings.worldmaptilesizex < 1 || settings.worldmaptilesizex < 1) |
|
|
1272 | return; |
1386 | return; |
1273 | /*prepare structures used for avoidance*/ |
1387 | /*prepare structures used for avoidance */ |
1274 | init_weatheravoid (weather_avoids); |
1388 | init_weatheravoid (weather_avoids); |
1275 | init_weatheravoid (growth_avoids); |
1389 | init_weatheravoid (growth_avoids); |
1276 | |
1390 | |
1277 | |
1391 | |
1278 | LOG(llevDebug, "Initializing the weathermap...\n"); |
1392 | LOG (llevDebug, "Initializing the weathermap...\n"); |
1279 | |
1393 | |
1280 | weathermap = (weathermap_t **)malloc(sizeof(weathermap_t *) * |
1394 | weathermap = (weathermap_t **) malloc (sizeof (weathermap_t *) * WEATHERMAPTILESX); |
1281 | WEATHERMAPTILESX); |
|
|
1282 | if (weathermap == NULL) |
1395 | if (weathermap == NULL) |
|
|
1396 | fatal (OUT_OF_MEMORY); |
|
|
1397 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
1398 | { |
|
|
1399 | weathermap[y] = (weathermap_t *) malloc (sizeof (weathermap_t) * WEATHERMAPTILESY); |
|
|
1400 | if (weathermap[y] == NULL) |
1283 | fatal(OUT_OF_MEMORY); |
1401 | fatal (OUT_OF_MEMORY); |
1284 | for (y=0; y < WEATHERMAPTILESY; y++) { |
|
|
1285 | weathermap[y] = (weathermap_t *)malloc(sizeof(weathermap_t) * |
|
|
1286 | WEATHERMAPTILESY); |
|
|
1287 | if (weathermap[y] == NULL) |
|
|
1288 | fatal(OUT_OF_MEMORY); |
|
|
1289 | } |
1402 | } |
1290 | /* now we load the values in the big worldmap weather array */ |
1403 | /* now we load the values in the big worldmap weather array */ |
1291 | /* do not re-order these */ |
1404 | /* do not re-order these */ |
1292 | read_pressuremap(); |
1405 | read_pressuremap (); |
1293 | read_winddirmap(); |
1406 | read_winddirmap (); |
1294 | read_windspeedmap(); |
1407 | read_windspeedmap (); |
1295 | read_gulfstreammap(); |
1408 | read_gulfstreammap (); |
1296 | read_watermap(); |
1409 | read_watermap (); |
1297 | read_humidmap(); |
1410 | read_humidmap (); |
1298 | read_elevmap(); /* elevation must allways follow humidity */ |
1411 | read_elevmap (); /* elevation must allways follow humidity */ |
1299 | read_temperaturemap(); |
1412 | read_temperaturemap (); |
1300 | gulf_stream_direction = rndm(0, 1); |
1413 | gulf_stream_direction = rndm (0, 1); |
1301 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) |
1414 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
1302 | for (ty=0; ty < WEATHERMAPTILESY-1; ty++) |
1415 | for (ty = 0; ty < WEATHERMAPTILESY - 1; ty++) |
1303 | if (gulf_stream_direction) |
1416 | if (gulf_stream_direction) |
1304 | switch (gulf_stream_dir[tx][ty]) { |
1417 | switch (gulf_stream_dir[tx][ty]) |
|
|
1418 | { |
|
|
1419 | case 2: |
1305 | case 2: gulf_stream_dir[tx][ty] = 6; break; |
1420 | gulf_stream_dir[tx][ty] = 6; |
|
|
1421 | break; |
|
|
1422 | case 3: |
1306 | case 3: gulf_stream_dir[tx][ty] = 7; break; |
1423 | gulf_stream_dir[tx][ty] = 7; |
|
|
1424 | break; |
|
|
1425 | case 4: |
1307 | case 4: gulf_stream_dir[tx][ty] = 8; break; |
1426 | gulf_stream_dir[tx][ty] = 8; |
1308 | } |
1427 | break; |
|
|
1428 | } |
1309 | else |
1429 | else |
1310 | switch (gulf_stream_dir[tx][ty]) { |
1430 | switch (gulf_stream_dir[tx][ty]) |
|
|
1431 | { |
|
|
1432 | case 6: |
1311 | case 6: gulf_stream_dir[tx][ty] = 2; break; |
1433 | gulf_stream_dir[tx][ty] = 2; |
|
|
1434 | break; |
|
|
1435 | case 7: |
1312 | case 7: gulf_stream_dir[tx][ty] = 3; break; |
1436 | gulf_stream_dir[tx][ty] = 3; |
|
|
1437 | break; |
|
|
1438 | case 8: |
1313 | case 8: gulf_stream_dir[tx][ty] = 4; break; |
1439 | gulf_stream_dir[tx][ty] = 4; |
1314 | } |
1440 | break; |
|
|
1441 | } |
1315 | gulf_stream_start = rndm(GULF_STREAM_WIDTH, WEATHERMAPTILESY-GULF_STREAM_WIDTH); |
1442 | gulf_stream_start = rndm (GULF_STREAM_WIDTH, WEATHERMAPTILESY - GULF_STREAM_WIDTH); |
1316 | read_rainfallmap(); |
1443 | read_rainfallmap (); |
1317 | |
1444 | |
1318 | LOG(llevDebug, "Done reading weathermaps\n"); |
1445 | LOG (llevDebug, "Done reading weathermaps\n"); |
1319 | sprintf(filename, "%s/wmapcurpos", settings.localdir); |
1446 | sprintf (filename, "%s/wmapcurpos", settings.localdir); |
1320 | LOG(llevDebug, "Reading current weather position from %s...", filename); |
1447 | LOG (llevDebug, "Reading current weather position from %s...", filename); |
1321 | if ((fp = fopen(filename, "r")) == NULL) { |
1448 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1449 | { |
1322 | LOG(llevError, "Can't open %s.\n", filename); |
1450 | LOG (llevError, "Can't open %s.\n", filename); |
1323 | wmperformstartx = -1; |
1451 | wmperformstartx = -1; |
1324 | return; |
1452 | return; |
1325 | } |
1453 | } |
1326 | fscanf(fp, "%d %d", &wmperformstartx, &wmperformstarty); |
1454 | fscanf (fp, "%d %d", &wmperformstartx, &wmperformstarty); |
1327 | LOG(llevDebug, "curposx=%d curposy=%d\n", wmperformstartx, wmperformstarty); |
1455 | LOG (llevDebug, "curposx=%d curposy=%d\n", wmperformstartx, wmperformstarty); |
1328 | fclose(fp); |
1456 | fclose (fp); |
1329 | if ((uint32) wmperformstartx > settings.worldmaptilesx) |
1457 | if ((uint32) wmperformstartx > settings.worldmaptilesx) |
1330 | wmperformstartx = -1; |
1458 | wmperformstartx = -1; |
1331 | if ((uint32) wmperformstarty > settings.worldmaptilesy) |
1459 | if ((uint32) wmperformstarty > settings.worldmaptilesy) |
1332 | wmperformstarty = 0; |
1460 | wmperformstarty = 0; |
1333 | } |
1461 | } |
1334 | |
1462 | |
1335 | /* |
1463 | /* |
1336 | * This routine slowly loads the world, patches it up due to the weather, |
1464 | * This routine slowly loads the world, patches it up due to the weather, |
1337 | * and saves it back to disk. In this way, the world constantly feels the |
1465 | * and saves it back to disk. In this way, the world constantly feels the |
… | |
… | |
1339 | * |
1467 | * |
1340 | * The main point of this is stuff like growing herbs, soil, decaying crap, |
1468 | * The main point of this is stuff like growing herbs, soil, decaying crap, |
1341 | * etc etc etc. Not actual *weather*, but weather *effects*. |
1469 | * etc etc etc. Not actual *weather*, but weather *effects*. |
1342 | */ |
1470 | */ |
1343 | |
1471 | |
|
|
1472 | static void |
1344 | static void perform_weather(void) |
1473 | perform_weather (void) |
1345 | { |
1474 | { |
1346 | mapstruct *m; |
1475 | mapstruct *m; |
1347 | char filename[MAX_BUF]; |
1476 | char filename[MAX_BUF]; |
1348 | FILE *fp; |
1477 | FILE *fp; |
1349 | |
1478 | |
1350 | if (!settings.dynamiclevel) |
1479 | if (!settings.dynamiclevel) |
1351 | return; |
1480 | return; |
1352 | |
1481 | |
1353 | /* move right to left, top to bottom */ |
1482 | /* move right to left, top to bottom */ |
1354 | if ((uint32) wmperformstartx + 1 == settings.worldmaptilesx) { |
1483 | if ((uint32) wmperformstartx + 1 == settings.worldmaptilesx) |
|
|
1484 | { |
1355 | wmperformstartx = 0; |
1485 | wmperformstartx = 0; |
1356 | wmperformstarty++; |
1486 | wmperformstarty++; |
|
|
1487 | } |
1357 | } else |
1488 | else |
1358 | wmperformstartx++; |
1489 | wmperformstartx++; |
1359 | if ((uint32) wmperformstarty == settings.worldmaptilesy) |
1490 | if ((uint32) wmperformstarty == settings.worldmaptilesy) |
1360 | wmperformstartx = wmperformstarty = 0; |
1491 | wmperformstartx = wmperformstarty = 0; |
1361 | |
|
|
1362 | sprintf(filename, "world/world_%d_%d", |
|
|
1363 | wmperformstartx + settings.worldmapstartx, |
|
|
1364 | wmperformstarty + settings.worldmapstarty); |
|
|
1365 | |
1492 | |
|
|
1493 | sprintf (filename, "world/world_%d_%d", wmperformstartx + settings.worldmapstartx, wmperformstarty + settings.worldmapstarty); |
|
|
1494 | |
1366 | m = ready_map_name(filename, 0); |
1495 | m = ready_map_name (filename, 0); |
1367 | if (m == NULL) |
1496 | if (m == NULL) |
1368 | return; /* hrmm */ |
1497 | return; /* hrmm */ |
1369 | |
1498 | |
1370 | /* for now, all we do is decay stuff. more to come */ |
1499 | /* for now, all we do is decay stuff. more to come */ |
1371 | decay_objects(m); |
1500 | decay_objects (m); |
1372 | weather_effect(filename); |
1501 | weather_effect (filename); |
1373 | |
1502 | |
1374 | /* done */ |
1503 | /* done */ |
1375 | new_save_map(m, 2); /* write the overlay */ |
1504 | new_save_map (m, 2); /* write the overlay */ |
1376 | m->in_memory = MAP_IN_MEMORY; /*reset this*/ |
1505 | m->in_memory = MAP_IN_MEMORY; /*reset this */ |
1377 | sprintf(filename, "%s/wmapcurpos", settings.localdir); |
1506 | sprintf (filename, "%s/wmapcurpos", settings.localdir); |
1378 | if ((fp = fopen(filename, "w")) == NULL) { |
1507 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
1508 | { |
1379 | LOG(llevError, "Cannot open %s for writing\n", filename); |
1509 | LOG (llevError, "Cannot open %s for writing\n", filename); |
1380 | return; |
1510 | return; |
1381 | } |
1511 | } |
1382 | |
1512 | |
1383 | if (players_on_map(m, TRUE) == 0) |
1513 | if (players_on_map (m, TRUE) == 0) |
1384 | delete_map(m); |
1514 | delete_map (m); |
1385 | |
1515 | |
1386 | fprintf(fp, "%d %d", wmperformstartx, wmperformstarty); |
1516 | fprintf (fp, "%d %d", wmperformstartx, wmperformstarty); |
1387 | fclose(fp); |
1517 | fclose (fp); |
1388 | } |
1518 | } |
1389 | |
1519 | |
1390 | /* |
1520 | /* |
1391 | * perform actual effect of weather. Should be called from perform_weather, |
1521 | * perform actual effect of weather. Should be called from perform_weather, |
1392 | * or when a map is loaded. (player enter map). Filename is the name of |
1522 | * or when a map is loaded. (player enter map). Filename is the name of |
… | |
… | |
1394 | * |
1524 | * |
1395 | * This is where things like snow, herbs, earthly rototilling, etc should |
1525 | * This is where things like snow, herbs, earthly rototilling, etc should |
1396 | * occur. |
1526 | * occur. |
1397 | */ |
1527 | */ |
1398 | |
1528 | |
|
|
1529 | void |
1399 | void weather_effect(const char *filename) |
1530 | weather_effect (const char *filename) |
1400 | { |
1531 | { |
1401 | mapstruct *m; |
1532 | mapstruct *m; |
1402 | int wx, wy, x, y; |
1533 | int wx, wy, x, y; |
1403 | |
1534 | |
1404 | /* if the dm shut off weather, go home */ |
1535 | /* if the dm shut off weather, go home */ |
1405 | if (settings.dynamiclevel < 1) |
1536 | if (settings.dynamiclevel < 1) |
1406 | return; |
1537 | return; |
1407 | |
1538 | |
1408 | m = ready_map_name(filename, 0); |
1539 | m = ready_map_name (filename, 0); |
1409 | if (!m->outdoor) |
1540 | if (!m->outdoor) |
1410 | return; |
1541 | return; |
1411 | |
1542 | |
1412 | x = 0; |
1543 | x = 0; |
1413 | y = 0; |
1544 | y = 0; |
1414 | /* for now, just bail if it's not the worldmap */ |
1545 | /* for now, just bail if it's not the worldmap */ |
1415 | if (worldmap_to_weathermap(x, y, &wx, &wy, m) != 0) |
1546 | if (worldmap_to_weathermap (x, y, &wx, &wy, m) != 0) |
1416 | return; |
1547 | return; |
1417 | /*First, calculate temperature*/ |
1548 | /*First, calculate temperature */ |
1418 | calculate_temperature(m, wx, wy); |
1549 | calculate_temperature (m, wx, wy); |
1419 | /* we change the world first, if needed */ |
1550 | /* we change the world first, if needed */ |
1420 | if (settings.dynamiclevel >= 5) { |
1551 | if (settings.dynamiclevel >= 5) |
|
|
1552 | { |
1421 | change_the_world(m, wx, wy); |
1553 | change_the_world (m, wx, wy); |
1422 | } |
1554 | } |
1423 | if (settings.dynamiclevel >= 2) { |
1555 | if (settings.dynamiclevel >= 2) |
|
|
1556 | { |
1424 | let_it_snow(m, wx, wy); |
1557 | let_it_snow (m, wx, wy); |
1425 | singing_in_the_rain(m, wx, wy); |
1558 | singing_in_the_rain (m, wx, wy); |
1426 | } |
1559 | } |
1427 | /* if (settings.dynamiclevel >= 4) { |
1560 | /* if (settings.dynamiclevel >= 4) { |
1428 | feather_map(m, wx, wy, filename); |
1561 | feather_map(m, wx, wy, filename); |
1429 | }*/ |
1562 | } */ |
1430 | if (settings.dynamiclevel >= 3) { |
1563 | if (settings.dynamiclevel >= 3) |
|
|
1564 | { |
1431 | plant_a_garden(m, wx, wy); |
1565 | plant_a_garden (m, wx, wy); |
1432 | } |
1566 | } |
1433 | } |
1567 | } |
1434 | |
1568 | |
1435 | /* |
1569 | /* |
1436 | * Check the current square to see if we should avoid this one for |
1570 | * Check the current square to see if we should avoid this one for |
… | |
… | |
1442 | * |
1576 | * |
1443 | * Returns the object pointer for any snow item it found, so you can |
1577 | * Returns the object pointer for any snow item it found, so you can |
1444 | * destroy/melt it. |
1578 | * destroy/melt it. |
1445 | */ |
1579 | */ |
1446 | |
1580 | |
|
|
1581 | static object * |
1447 | static object *avoid_weather(int *av, mapstruct *m, int x, int y, int *gs, int grow) |
1582 | avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow) |
1448 | { |
1583 | { |
1449 | int avoid, gotsnow, i, n; |
1584 | int avoid, gotsnow, i, n; |
1450 | |
1585 | |
1451 | object *tmp; |
1586 | object *tmp; |
|
|
1587 | |
1452 | avoid = 0; |
1588 | avoid = 0; |
1453 | gotsnow = 0; |
1589 | gotsnow = 0; |
1454 | if (grow) { |
1590 | if (grow) |
|
|
1591 | { |
1455 | for (tmp=GET_MAP_OB(m, x, y), n=0; tmp; tmp = tmp->above, n++) { |
1592 | for (tmp = GET_MAP_OB (m, x, y), n = 0; tmp; tmp = tmp->above, n++) |
|
|
1593 | { |
1456 | /* look for things like walls, holes, etc */ |
1594 | /* look for things like walls, holes, etc */ |
1457 | if (n) |
1595 | if (n) |
1458 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR) && |
1596 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !(tmp->material & M_ICE || tmp->material & M_LIQUID)) |
1459 | !(tmp->material & M_ICE || tmp->material & M_LIQUID)) |
1597 | gotsnow++; |
|
|
1598 | for (i = 0; growth_avoids[i].name != NULL; i++) |
|
|
1599 | { |
|
|
1600 | /*if (!strcmp(tmp->arch->name, growth_avoids[i].name)) { */ |
|
|
1601 | if (tmp->arch == growth_avoids[i].what) |
|
|
1602 | { |
|
|
1603 | avoid++; |
|
|
1604 | break; |
|
|
1605 | } |
|
|
1606 | } |
|
|
1607 | if (!strncmp (tmp->arch->name, "biglake_", 8)) |
|
|
1608 | { |
|
|
1609 | avoid++; |
|
|
1610 | break; |
|
|
1611 | } |
|
|
1612 | if (avoid) |
|
|
1613 | break; |
|
|
1614 | } |
|
|
1615 | } |
|
|
1616 | else |
|
|
1617 | { |
|
|
1618 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
|
|
1619 | { |
|
|
1620 | for (i = 0; weather_avoids[i].name != NULL; i++) |
|
|
1621 | { |
|
|
1622 | /*if (!strcmp(tmp->arch->name, weather_avoids[i].name)) { */ |
|
|
1623 | if (tmp->arch == weather_avoids[i].what) |
|
|
1624 | { |
|
|
1625 | if (weather_avoids[i].snow == 1) |
1460 | gotsnow++; |
1626 | gotsnow++; |
1461 | for (i=0; growth_avoids[i].name != NULL; i++) { |
1627 | else |
1462 | /*if (!strcmp(tmp->arch->name, growth_avoids[i].name)) {*/ |
|
|
1463 | if (tmp->arch== growth_avoids[i].what) { |
|
|
1464 | avoid++; |
1628 | avoid++; |
1465 | break; |
1629 | break; |
1466 | } |
1630 | } |
1467 | } |
1631 | } |
1468 | if (!strncmp(tmp->arch->name, "biglake_", 8)) { |
|
|
1469 | avoid++; |
|
|
1470 | break; |
|
|
1471 | } |
|
|
1472 | if (avoid) |
1632 | if (avoid || gotsnow) |
1473 | break; |
1633 | break; |
1474 | } |
1634 | } |
1475 | } else { |
|
|
1476 | for (tmp=GET_MAP_OB(m, x, y); tmp; tmp = tmp->above) { |
|
|
1477 | for (i=0; weather_avoids[i].name != NULL; i++) { |
|
|
1478 | /*if (!strcmp(tmp->arch->name, weather_avoids[i].name)) {*/ |
|
|
1479 | if (tmp->arch == weather_avoids[i].what) { |
|
|
1480 | if (weather_avoids[i].snow == 1) |
|
|
1481 | gotsnow++; |
|
|
1482 | else |
|
|
1483 | avoid++; |
|
|
1484 | break; |
|
|
1485 | } |
|
|
1486 | } |
|
|
1487 | if (avoid || gotsnow) |
|
|
1488 | break; |
|
|
1489 | } |
|
|
1490 | } |
1635 | } |
1491 | *gs = gotsnow; |
1636 | *gs = gotsnow; |
1492 | *av = avoid; |
1637 | *av = avoid; |
1493 | return tmp; |
1638 | return tmp; |
1494 | } |
1639 | } |
1495 | |
1640 | |
1496 | /* Temperature is used in a lot of weather function. |
1641 | /* Temperature is used in a lot of weather function. |
1497 | * This need to be precalculated before used. |
1642 | * This need to be precalculated before used. |
1498 | */ |
1643 | */ |
|
|
1644 | static void |
1499 | static void calculate_temperature(mapstruct *m, int wx, int wy){ |
1645 | calculate_temperature (mapstruct *m, int wx, int wy) |
|
|
1646 | { |
1500 | uint32 x, y; |
1647 | uint32 x, y; |
|
|
1648 | |
1501 | for (x = 0; x < settings.worldmaptilesizex; x++) { |
1649 | for (x = 0; x < settings.worldmaptilesizex; x++) |
|
|
1650 | { |
1502 | for (y=0; y < settings.worldmaptilesizey; y++) { |
1651 | for (y = 0; y < settings.worldmaptilesizey; y++) |
|
|
1652 | { |
1503 | weathermap[wx][wy].realtemp=real_world_temperature(x, y, m); |
1653 | weathermap[wx][wy].realtemp = real_world_temperature (x, y, m); |
1504 | } |
1654 | } |
1505 | } |
1655 | } |
1506 | } |
1656 | } |
1507 | |
1657 | |
1508 | /* |
1658 | /* |
1509 | * Process snow. m is the map we are currently processing. wx and wy are |
1659 | * Process snow. m is the map we are currently processing. wx and wy are |
1510 | * the weathermap coordinates for the weathermap square we want to work on. |
1660 | * the weathermap coordinates for the weathermap square we want to work on. |
1511 | * filename is the pathname for the current map. This should be called from |
1661 | * filename is the pathname for the current map. This should be called from |
1512 | * weather_effect() |
1662 | * weather_effect() |
1513 | */ |
1663 | */ |
1514 | |
1664 | |
|
|
1665 | static void |
1515 | static void let_it_snow(mapstruct *m, int wx, int wy) |
1666 | let_it_snow (mapstruct *m, int wx, int wy) |
1516 | { |
1667 | { |
1517 | int x, y, i; |
1668 | int x, y, i; |
1518 | uint32 nx, ny, j, d; |
1669 | uint32 nx, ny, j, d; |
1519 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1670 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1520 | const char *doublestack, *doublestack2; |
1671 | const char *doublestack, *doublestack2; |
1521 | object *ob, *tmp, *oldsnow, *topfloor; |
1672 | object *ob, *tmp, *oldsnow, *topfloor; |
1522 | archetype *at; |
1673 | archetype *at; |
1523 | |
1674 | |
1524 | for (nx = 0; nx < settings.worldmaptilesizex; nx++) { |
1675 | for (nx = 0; nx < settings.worldmaptilesizex; nx++) |
|
|
1676 | { |
1525 | for (ny=0; ny < settings.worldmaptilesizey; ny++) { |
1677 | for (ny = 0; ny < settings.worldmaptilesizey; ny++) |
|
|
1678 | { |
1526 | /* jitter factor */ |
1679 | /* jitter factor */ |
1527 | if (rndm(0, 2) > 0) { |
1680 | if (rndm (0, 2) > 0) |
|
|
1681 | { |
1528 | x=y=d=-1; |
1682 | x = y = d = -1; |
1529 | while (OUT_OF_REAL_MAP(m, x, y)) { |
1683 | while (OUT_OF_REAL_MAP (m, x, y)) |
|
|
1684 | { |
1530 | d++; |
1685 | d++; |
1531 | j=rndm(1, 8); |
1686 | j = rndm (1, 8); |
1532 | x = nx + freearr_x[j] * (rndm(0, 1) + rndm(0, 1) + rndm (0, 1) +1); |
1687 | x = nx + freearr_x[j] * (rndm (0, 1) + rndm (0, 1) + rndm (0, 1) + 1); |
1533 | y = ny + freearr_y[j] * (rndm(0, 1) + rndm(0, 1) + rndm (0, 1) +1); |
1688 | y = ny + freearr_y[j] * (rndm (0, 1) + rndm (0, 1) + rndm (0, 1) + 1); |
1534 | if (d > 15) { |
1689 | if (d > 15) |
|
|
1690 | { |
1535 | x = nx; |
1691 | x = nx; |
1536 | y = ny; |
1692 | y = ny; |
1537 | } |
1693 | } |
1538 | } |
1694 | } |
|
|
1695 | } |
1539 | } else { |
1696 | else |
|
|
1697 | { |
1540 | x = nx; |
1698 | x = nx; |
1541 | y = ny; |
1699 | y = ny; |
1542 | } |
1700 | } |
1543 | /* we use the unjittered coordinates */ |
1701 | /* we use the unjittered coordinates */ |
1544 | (void)worldmap_to_weathermap(nx, ny, &wx, &wy, m); |
1702 | (void) worldmap_to_weathermap (nx, ny, &wx, &wy, m); |
1545 | ob = NULL; |
1703 | ob = NULL; |
1546 | at = NULL; |
1704 | at = NULL; |
1547 | /* this will definately need tuning */ |
1705 | /* this will definately need tuning */ |
1548 | avoid = 0; |
1706 | avoid = 0; |
1549 | two = 0; |
1707 | two = 0; |
1550 | gotsnow = 0; |
1708 | gotsnow = 0; |
1551 | nodstk = 0; |
1709 | nodstk = 0; |
1552 | /*temp = real_world_temperature(x, y, m);*/ |
1710 | /*temp = real_world_temperature(x, y, m); */ |
1553 | temp = weathermap[wx][wy].realtemp; |
1711 | temp = weathermap[wx][wy].realtemp; |
1554 | sky = weathermap[wx][wy].sky; |
1712 | sky = weathermap[wx][wy].sky; |
1555 | if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG) |
1713 | if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG) |
1556 | sky += 10; /*let it snow*/ |
1714 | sky += 10; /*let it snow */ |
1557 | oldsnow = avoid_weather(&avoid, m, x, y, &gotsnow, 0); |
1715 | oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 0); |
1558 | if (!avoid) { |
1716 | if (!avoid) |
|
|
1717 | { |
1559 | if (sky >= SKY_LIGHT_SNOW && sky < SKY_HEAVY_SNOW) |
1718 | if (sky >= SKY_LIGHT_SNOW && sky < SKY_HEAVY_SNOW) |
1560 | at = find_archetype(weather_replace[0].special_snow); |
1719 | at = archetype::find (weather_replace[0].special_snow); |
1561 | if (sky >= SKY_HEAVY_SNOW) |
1720 | if (sky >= SKY_HEAVY_SNOW) |
1562 | at = find_archetype(weather_replace[1].special_snow); |
1721 | at = archetype::find (weather_replace[1].special_snow); |
1563 | if (sky >= SKY_LIGHT_SNOW) { |
1722 | if (sky >= SKY_LIGHT_SNOW) |
|
|
1723 | { |
1564 | /* the bottom floor of scorn is not IS_FLOOR */ |
1724 | /* the bottom floor of scorn is not IS_FLOOR */ |
1565 | topfloor=NULL; |
1725 | topfloor = NULL; |
1566 | for (tmp=GET_MAP_OB(m, x, y); tmp; |
1726 | for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above) |
1567 | topfloor = tmp,tmp = tmp->above) { |
1727 | { |
1568 | if (strcmp(tmp->arch->name, "dungeon_magic") != 0) |
1728 | if (strcmp (tmp->arch->name, "dungeon_magic") != 0) |
1569 | if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR)) |
1729 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1570 | break; |
1730 | break; |
1571 | } |
1731 | } |
1572 | /* topfloor should now be the topmost IS_FLOOR=1 */ |
1732 | /* topfloor should now be the topmost IS_FLOOR=1 */ |
1573 | if (topfloor == NULL) |
1733 | if (topfloor == NULL) |
1574 | continue; |
1734 | continue; |
1575 | if (tmp != NULL) |
1735 | if (tmp != NULL) |
1576 | nodstk++; |
1736 | nodstk++; |
1577 | /* something is wrong with that sector. just skip it */ |
1737 | /* something is wrong with that sector. just skip it */ |
1578 | found = 0; |
1738 | found = 0; |
1579 | for (i=0; weather_replace[i].tile != NULL; i++) { |
1739 | for (i = 0; weather_replace[i].tile != NULL; i++) |
|
|
1740 | { |
1580 | if (weather_replace[i].arch_or_name == 1) { |
1741 | if (weather_replace[i].arch_or_name == 1) |
|
|
1742 | { |
1581 | if (!strcmp(topfloor->arch->name, |
1743 | if (!strcmp (topfloor->arch->name, weather_replace[i].tile)) |
1582 | weather_replace[i].tile)) |
|
|
1583 | found++; |
1744 | found++; |
1584 | } else { |
|
|
1585 | if (!strcmp(topfloor->name, weather_replace[i].tile)) |
|
|
1586 | found++; |
|
|
1587 | } |
1745 | } |
|
|
1746 | else |
|
|
1747 | { |
|
|
1748 | if (!strcmp (topfloor->name, weather_replace[i].tile)) |
|
|
1749 | found++; |
|
|
1750 | } |
1588 | if (found) { |
1751 | if (found) |
|
|
1752 | { |
1589 | if (weather_replace[i].special_snow != NULL) |
1753 | if (weather_replace[i].special_snow != NULL) |
1590 | at = find_archetype(weather_replace[i].special_snow); |
1754 | at = archetype::find (weather_replace[i].special_snow); |
1591 | if (weather_replace[i].doublestack_arch != NULL |
1755 | if (weather_replace[i].doublestack_arch != NULL && !nodstk) |
1592 | && !nodstk) { |
1756 | { |
1593 | two++; |
1757 | two++; |
1594 | doublestack = weather_replace[i].doublestack_arch; |
1758 | doublestack = weather_replace[i].doublestack_arch; |
1595 | } |
1759 | } |
1596 | break; |
1760 | break; |
1597 | } |
1761 | } |
1598 | } |
1762 | } |
1599 | } |
1763 | } |
1600 | if (gotsnow && at) { |
1764 | if (gotsnow && at) |
|
|
1765 | { |
1601 | if (!strcmp(oldsnow->arch->name, at->name)) |
1766 | if (!strcmp (oldsnow->arch->name, at->name)) |
1602 | at = NULL; |
1767 | at = NULL; |
1603 | else { |
1768 | else |
|
|
1769 | { |
1604 | remove_ob(oldsnow); |
1770 | remove_ob (oldsnow); |
1605 | free_object(oldsnow); |
1771 | free_object (oldsnow); |
1606 | tmp=GET_MAP_OB(m, x, y); |
1772 | tmp = GET_MAP_OB (m, x, y); |
1607 | /* clean up the trees we put over the snow */ |
1773 | /* clean up the trees we put over the snow */ |
1608 | found = 0; |
1774 | found = 0; |
1609 | doublestack2 = NULL; |
1775 | doublestack2 = NULL; |
1610 | if (tmp) |
1776 | if (tmp) |
1611 | for (i=0; weather_replace[i].tile != NULL; i++) { |
1777 | for (i = 0; weather_replace[i].tile != NULL; i++) |
|
|
1778 | { |
1612 | if (weather_replace[i].doublestack_arch == NULL) |
1779 | if (weather_replace[i].doublestack_arch == NULL) |
1613 | continue; |
1780 | continue; |
1614 | if (weather_replace[i].arch_or_name == 1) { |
1781 | if (weather_replace[i].arch_or_name == 1) |
|
|
1782 | { |
1615 | if (!strcmp(tmp->arch->name, |
1783 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
1616 | weather_replace[i].tile)) |
|
|
1617 | found++; |
1784 | found++; |
|
|
1785 | } |
1618 | } else { |
1786 | else |
|
|
1787 | { |
1619 | if (!strcmp(tmp->name, weather_replace[i].tile)) |
1788 | if (!strcmp (tmp->name, weather_replace[i].tile)) |
1620 | found++; |
1789 | found++; |
1621 | } |
1790 | } |
1622 | if (found) { |
1791 | if (found) |
|
|
1792 | { |
1623 | tmp = tmp->above; |
1793 | tmp = tmp->above; |
1624 | doublestack2 = weather_replace[i].doublestack_arch; |
1794 | doublestack2 = weather_replace[i].doublestack_arch; |
1625 | break; |
1795 | break; |
1626 | } |
1796 | } |
1627 | } |
1797 | } |
1628 | if (tmp != NULL && doublestack2 != NULL) |
1798 | if (tmp != NULL && doublestack2 != NULL) |
1629 | if (strcmp(tmp->arch->name, doublestack2) == 0) { |
1799 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
|
|
1800 | { |
1630 | remove_ob(tmp); |
1801 | remove_ob (tmp); |
1631 | free_object(tmp); |
1802 | free_object (tmp); |
1632 | } |
1803 | } |
1633 | } |
1804 | } |
1634 | } |
1805 | } |
1635 | if (at != NULL) { |
1806 | if (at != NULL) |
|
|
1807 | { |
1636 | ob = arch_to_object (at); |
1808 | ob = arch_to_object (at); |
1637 | ob->x = x; |
1809 | ob->x = x; |
1638 | ob->y = y; |
1810 | ob->y = y; |
1639 | ob->material = M_ICE; |
1811 | ob->material = M_ICE; |
1640 | SET_FLAG(ob, FLAG_OVERLAY_FLOOR); |
1812 | SET_FLAG (ob, FLAG_OVERLAY_FLOOR); |
1641 | CLEAR_FLAG(ob, FLAG_IS_FLOOR); |
1813 | CLEAR_FLAG (ob, FLAG_IS_FLOOR); |
1642 | insert_ob_in_map(ob, m, ob, |
|
|
1643 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
1814 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
1644 | if (two) { |
1815 | if (two) |
|
|
1816 | { |
1645 | at = NULL; |
1817 | at = NULL; |
1646 | at = find_archetype(doublestack); |
1818 | at = archetype::find (doublestack); |
1647 | if (at != NULL) { |
1819 | if (at != NULL) |
|
|
1820 | { |
1648 | ob = arch_to_object (at); |
1821 | ob = arch_to_object (at); |
1649 | ob->x = x; |
1822 | ob->x = x; |
1650 | ob->y = y; |
1823 | ob->y = y; |
1651 | insert_ob_in_map(ob, m, ob, |
|
|
1652 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
1824 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
1653 | } |
1825 | } |
1654 | } |
1826 | } |
1655 | } |
1827 | } |
1656 | } |
1828 | } |
1657 | if (temp > 8 && GET_MAP_OB(m, x, y) !=NULL) { |
1829 | if (temp > 8 && GET_MAP_OB (m, x, y) != NULL) |
|
|
1830 | { |
1658 | /* melt some snow */ |
1831 | /* melt some snow */ |
1659 | for (tmp=GET_MAP_OB(m, x, y)->above; tmp; tmp = tmp->above) { |
1832 | for (tmp = GET_MAP_OB (m, x, y)->above; tmp; tmp = tmp->above) |
|
|
1833 | { |
1660 | avoid = 0; |
1834 | avoid = 0; |
1661 | for (i=0; weather_replace[i].tile != NULL; i++) { |
1835 | for (i = 0; weather_replace[i].tile != NULL; i++) |
|
|
1836 | { |
1662 | if (weather_replace[i].special_snow == NULL) |
1837 | if (weather_replace[i].special_snow == NULL) |
1663 | continue; |
1838 | continue; |
1664 | if (!strcmp(tmp->arch->name, weather_replace[i].special_snow)) |
1839 | if (!strcmp (tmp->arch->name, weather_replace[i].special_snow)) |
1665 | avoid++; |
1840 | avoid++; |
1666 | if (avoid) |
1841 | if (avoid) |
1667 | break; |
1842 | break; |
1668 | } |
1843 | } |
1669 | if (avoid) { |
1844 | if (avoid) |
|
|
1845 | { |
1670 | /* replace snow with a big puddle */ |
1846 | /* replace snow with a big puddle */ |
1671 | remove_ob(tmp); |
1847 | remove_ob (tmp); |
1672 | free_object(tmp); |
1848 | free_object (tmp); |
1673 | tmp=GET_MAP_OB(m, x, y); |
1849 | tmp = GET_MAP_OB (m, x, y); |
1674 | if (tmp &&(!strcmp(tmp->arch->name, "mountain"))){ |
1850 | if (tmp && (!strcmp (tmp->arch->name, "mountain"))) |
|
|
1851 | { |
1675 | at = find_archetype("mountain1_rivlets");} |
1852 | at = archetype::find ("mountain1_rivlets"); |
|
|
1853 | } |
1676 | else if ( tmp && (!strcmp(tmp->arch->name, "mountain2"))){ |
1854 | else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) |
|
|
1855 | { |
1677 | at = find_archetype("mountain2_rivlets");} |
1856 | at = archetype::find ("mountain2_rivlets"); |
|
|
1857 | } |
1678 | else if (tmp && (!strcmp(tmp->arch->name, "mountain4"))){ |
1858 | else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) |
|
|
1859 | { |
1679 | at = find_archetype("mountain2_rivlets");} |
1860 | at = archetype::find ("mountain2_rivlets"); |
|
|
1861 | } |
|
|
1862 | else |
|
|
1863 | { |
1680 | else {at = find_archetype("rain5");} |
1864 | at = archetype::find ("rain5"); |
|
|
1865 | } |
1681 | if (at != NULL) { |
1866 | if (at != NULL) |
|
|
1867 | { |
1682 | ob = arch_to_object (at); |
1868 | ob = arch_to_object (at); |
1683 | ob->x = x; |
1869 | ob->x = x; |
1684 | ob->y = y; |
1870 | ob->y = y; |
1685 | SET_FLAG(ob, FLAG_OVERLAY_FLOOR); |
1871 | SET_FLAG (ob, FLAG_OVERLAY_FLOOR); |
1686 | ob->material = M_LIQUID; |
1872 | ob->material = M_LIQUID; |
1687 | insert_ob_in_map(ob, m, ob, INS_NO_MERGE | |
1873 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
1688 | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
|
|
1689 | } |
1874 | } |
1690 | } |
1875 | } |
1691 | } |
1876 | } |
1692 | } |
1877 | } |
1693 | /* woo it's cold out */ |
1878 | /* woo it's cold out */ |
1694 | if (temp < -8) { |
1879 | if (temp < -8) |
|
|
1880 | { |
1695 | avoid = 0; |
1881 | avoid = 0; |
1696 | for (tmp=GET_MAP_OB(m, x, y); tmp; tmp = tmp->above) { |
1882 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
|
|
1883 | { |
1697 | if (!strcasecmp(tmp->name, "ice")) |
1884 | if (!strcasecmp (tmp->name, "ice")) |
1698 | avoid--; |
1885 | avoid--; |
1699 | } |
1886 | } |
1700 | tmp = GET_MAP_OB(m, x, y); |
1887 | tmp = GET_MAP_OB (m, x, y); |
1701 | if (tmp && (!strcasecmp(tmp->name, "sea"))) |
1888 | if (tmp && (!strcasecmp (tmp->name, "sea"))) |
1702 | avoid++; |
1889 | avoid++; |
1703 | else if (tmp && (!strcasecmp(tmp->name, "sea1"))) |
1890 | else if (tmp && (!strcasecmp (tmp->name, "sea1"))) |
1704 | avoid++; |
1891 | avoid++; |
1705 | else if (tmp && (!strcasecmp(tmp->name, "deep_sea"))) |
1892 | else if (tmp && (!strcasecmp (tmp->name, "deep_sea"))) |
1706 | avoid++; |
1893 | avoid++; |
1707 | else if (tmp && (!strcasecmp(tmp->name, "shallow_sea"))) |
1894 | else if (tmp && (!strcasecmp (tmp->name, "shallow_sea"))) |
1708 | avoid++; |
1895 | avoid++; |
1709 | if (avoid > 0) { |
1896 | if (avoid > 0) |
|
|
1897 | { |
1710 | at = find_archetype("ice"); |
1898 | at = archetype::find ("ice"); |
1711 | ob = arch_to_object (at); |
1899 | ob = arch_to_object (at); |
1712 | ob->x = x; |
1900 | ob->x = x; |
1713 | ob->y = y; |
1901 | ob->y = y; |
1714 | insert_ob_in_map(ob, m, ob, |
|
|
1715 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
1902 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
1716 | } |
1903 | } |
1717 | } |
1904 | } |
1718 | } |
1905 | } |
1719 | } |
1906 | } |
1720 | } |
1907 | } |
… | |
… | |
1724 | * the weathermap coordinates for the weathermap square we want to work on. |
1911 | * the weathermap coordinates for the weathermap square we want to work on. |
1725 | * filename is the pathname for the current map. This should be called from |
1912 | * filename is the pathname for the current map. This should be called from |
1726 | * weather_effect() |
1913 | * weather_effect() |
1727 | */ |
1914 | */ |
1728 | |
1915 | |
|
|
1916 | static void |
1729 | static void singing_in_the_rain(mapstruct *m, int wx, int wy) |
1917 | singing_in_the_rain (mapstruct *m, int wx, int wy) |
1730 | { |
1918 | { |
1731 | int x, y, i; |
1919 | int x, y, i; |
1732 | uint32 nx, ny, d, j; |
1920 | uint32 nx, ny, d, j; |
1733 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1921 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1734 | object *ob, *tmp, *oldsnow, *topfloor; |
1922 | object *ob, *tmp, *oldsnow, *topfloor; |
1735 | const char *doublestack, *doublestack2; |
1923 | const char *doublestack, *doublestack2; |
1736 | archetype *at; |
1924 | archetype *at; |
1737 | |
1925 | |
1738 | for (nx = 0; nx < settings.worldmaptilesizex; nx++) { |
1926 | for (nx = 0; nx < settings.worldmaptilesizex; nx++) |
|
|
1927 | { |
1739 | for (ny = 0; ny < settings.worldmaptilesizey; ny++) { |
1928 | for (ny = 0; ny < settings.worldmaptilesizey; ny++) |
|
|
1929 | { |
1740 | /* jitter factor */ |
1930 | /* jitter factor */ |
1741 | if (rndm(0, 2) > 0) { |
1931 | if (rndm (0, 2) > 0) |
|
|
1932 | { |
1742 | x=y=d=-1; |
1933 | x = y = d = -1; |
1743 | while (OUT_OF_REAL_MAP(m, x, y)) { |
1934 | while (OUT_OF_REAL_MAP (m, x, y)) |
|
|
1935 | { |
1744 | d++; |
1936 | d++; |
1745 | j=rndm(1, 8); |
1937 | j = rndm (1, 8); |
1746 | x = nx + freearr_x[j] * (rndm(0, 1) + rndm(0, 1) + rndm (0, 1) +1); |
1938 | x = nx + freearr_x[j] * (rndm (0, 1) + rndm (0, 1) + rndm (0, 1) + 1); |
1747 | y = ny + freearr_y[j] * (rndm(0, 1) + rndm(0, 1) + rndm (0, 1) +1); |
1939 | y = ny + freearr_y[j] * (rndm (0, 1) + rndm (0, 1) + rndm (0, 1) + 1); |
1748 | if (d > 15) { |
1940 | if (d > 15) |
|
|
1941 | { |
1749 | x = nx; |
1942 | x = nx; |
1750 | y = ny; |
1943 | y = ny; |
1751 | } |
1944 | } |
1752 | } |
1945 | } |
|
|
1946 | } |
1753 | } else { |
1947 | else |
|
|
1948 | { |
1754 | x = nx; |
1949 | x = nx; |
1755 | y = ny; |
1950 | y = ny; |
1756 | } |
1951 | } |
1757 | /* we use the unjittered coordinates */ |
1952 | /* we use the unjittered coordinates */ |
1758 | (void)worldmap_to_weathermap(nx, ny, &wx, &wy, m); |
1953 | (void) worldmap_to_weathermap (nx, ny, &wx, &wy, m); |
1759 | ob = NULL; |
1954 | ob = NULL; |
1760 | at = NULL; |
1955 | at = NULL; |
1761 | avoid = 0; |
1956 | avoid = 0; |
1762 | two = 0; |
1957 | two = 0; |
1763 | gotsnow = 0; |
1958 | gotsnow = 0; |
1764 | nodstk = 0; |
1959 | nodstk = 0; |
1765 | /*temp = real_world_temperature(x, y, m);*/ |
1960 | /*temp = real_world_temperature(x, y, m); */ |
1766 | temp = weathermap[wx][wy].realtemp; |
1961 | temp = weathermap[wx][wy].realtemp; |
1767 | sky = weathermap[wx][wy].sky; |
1962 | sky = weathermap[wx][wy].sky; |
1768 | /* it's probably allready snowing */ |
1963 | /* it's probably allready snowing */ |
1769 | if (temp < 0) |
1964 | if (temp < 0) |
1770 | continue; |
1965 | continue; |
1771 | oldsnow = avoid_weather(&avoid, m, x, y, &gotsnow, 0); |
1966 | oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 0); |
1772 | if (!avoid) { |
1967 | if (!avoid) |
|
|
1968 | { |
1773 | tmp=GET_MAP_OB(m, x, y); |
1969 | tmp = GET_MAP_OB (m, x, y); |
1774 | if (tmp && (!strcmp(tmp->arch->name, "mountain"))){ |
1970 | if (tmp && (!strcmp (tmp->arch->name, "mountain"))) |
|
|
1971 | { |
1775 | at = find_archetype("mountain1_rivlets"); break;} |
1972 | at = archetype::find ("mountain1_rivlets"); |
|
|
1973 | break; |
|
|
1974 | } |
1776 | else if (tmp && (!strcmp(tmp->arch->name, "mountain2"))){ |
1975 | else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) |
|
|
1976 | { |
1777 | at = find_archetype("mountain2_rivlets"); break;} |
1977 | at = archetype::find ("mountain2_rivlets"); |
|
|
1978 | break; |
|
|
1979 | } |
1778 | else if (tmp && (!strcmp(tmp->arch->name, "mountain4"))){ |
1980 | else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) |
|
|
1981 | { |
1779 | at = find_archetype("mountain2_rivlets"); break;} |
1982 | at = archetype::find ("mountain2_rivlets"); |
|
|
1983 | break; |
|
|
1984 | } |
1780 | if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN) { |
1985 | if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN) |
|
|
1986 | { |
1781 | switch (rndm(0, SKY_HAIL-sky)) { |
1987 | switch (rndm (0, SKY_HAIL - sky)) |
1782 | case 0: at = find_archetype("rain1"); break; |
1988 | { |
1783 | case 1: at = find_archetype("rain2"); break; |
1989 | case 0: |
|
|
1990 | at = archetype::find ("rain1"); |
|
|
1991 | break; |
|
|
1992 | case 1: |
|
|
1993 | at = archetype::find ("rain2"); |
|
|
1994 | break; |
|
|
1995 | default: |
1784 | default: at = NULL; |
1996 | at = NULL; |
1785 | } |
1997 | } |
1786 | } |
1998 | } |
1787 | if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE){ |
1999 | if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE) |
|
|
2000 | { |
1788 | switch (rndm(0, SKY_HAIL-sky)) { |
2001 | switch (rndm (0, SKY_HAIL - sky)) |
1789 | case 0: at = find_archetype("rain3"); break; |
2002 | { |
1790 | case 1: at = find_archetype("rain4"); break; |
2003 | case 0: |
1791 | case 2: at = find_archetype("rain5"); break; |
2004 | at = archetype::find ("rain3"); |
|
|
2005 | break; |
|
|
2006 | case 1: |
|
|
2007 | at = archetype::find ("rain4"); |
|
|
2008 | break; |
|
|
2009 | case 2: |
|
|
2010 | at = archetype::find ("rain5"); |
|
|
2011 | break; |
|
|
2012 | default: |
1792 | default: at = NULL; |
2013 | at = NULL; |
1793 | } |
2014 | } |
1794 | } |
2015 | } |
1795 | /* the bottom floor of scorn is not IS_FLOOR */ |
2016 | /* the bottom floor of scorn is not IS_FLOOR */ |
1796 | topfloor=NULL; |
2017 | topfloor = NULL; |
1797 | for (tmp=GET_MAP_OB(m, x, y); tmp; |
2018 | for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above) |
1798 | topfloor = tmp,tmp = tmp->above) { |
2019 | { |
1799 | if (strcmp(tmp->arch->name, "dungeon_magic") != 0) |
2020 | if (strcmp (tmp->arch->name, "dungeon_magic") != 0) |
1800 | if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR)) |
2021 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1801 | break; |
2022 | break; |
1802 | } |
2023 | } |
1803 | /* topfloor should now be the topmost IS_FLOOR=1 */ |
2024 | /* topfloor should now be the topmost IS_FLOOR=1 */ |
1804 | if (topfloor == NULL) |
2025 | if (topfloor == NULL) |
1805 | continue; |
2026 | continue; |
1806 | if (tmp != NULL) |
2027 | if (tmp != NULL) |
1807 | nodstk++; |
2028 | nodstk++; |
1808 | /* something is wrong with that sector. just skip it */ |
2029 | /* something is wrong with that sector. just skip it */ |
1809 | found = 0; |
2030 | found = 0; |
1810 | for (i=0; weather_replace[i].tile != NULL; i++) { |
2031 | for (i = 0; weather_replace[i].tile != NULL; i++) |
|
|
2032 | { |
1811 | if (weather_replace[i].arch_or_name == 1) { |
2033 | if (weather_replace[i].arch_or_name == 1) |
1812 | if (!strcmp(topfloor->arch->name, |
|
|
1813 | weather_replace[i].tile)) |
|
|
1814 | found++; |
|
|
1815 | } else { |
2034 | { |
1816 | if (!strcmp(topfloor->name, weather_replace[i].tile)) |
2035 | if (!strcmp (topfloor->arch->name, weather_replace[i].tile)) |
1817 | found++; |
2036 | found++; |
1818 | } |
2037 | } |
|
|
2038 | else |
|
|
2039 | { |
|
|
2040 | if (!strcmp (topfloor->name, weather_replace[i].tile)) |
|
|
2041 | found++; |
|
|
2042 | } |
1819 | if (found) { |
2043 | if (found) |
|
|
2044 | { |
1820 | if (weather_replace[i].doublestack_arch != NULL |
2045 | if (weather_replace[i].doublestack_arch != NULL && !nodstk) |
1821 | && !nodstk) { |
2046 | { |
1822 | two++; |
2047 | two++; |
1823 | doublestack = weather_replace[i].doublestack_arch; |
2048 | doublestack = weather_replace[i].doublestack_arch; |
1824 | } |
2049 | } |
1825 | break; |
2050 | break; |
1826 | } |
2051 | } |
1827 | } |
2052 | } |
1828 | if (gotsnow && at) { |
2053 | if (gotsnow && at) |
|
|
2054 | { |
1829 | if (!strcmp(oldsnow->arch->name, at->name)) |
2055 | if (!strcmp (oldsnow->arch->name, at->name)) |
1830 | at = NULL; |
2056 | at = NULL; |
1831 | else { |
2057 | else |
|
|
2058 | { |
1832 | tmp=GET_MAP_OB(m, x, y); |
2059 | tmp = GET_MAP_OB (m, x, y); |
1833 | remove_ob(oldsnow); |
2060 | remove_ob (oldsnow); |
1834 | /* clean up the trees we put over the snow */ |
2061 | /* clean up the trees we put over the snow */ |
1835 | found = 0; |
2062 | found = 0; |
1836 | doublestack2 = NULL; |
2063 | doublestack2 = NULL; |
1837 | for (i=0; weather_replace[i].tile != NULL; i++) { |
2064 | for (i = 0; weather_replace[i].tile != NULL; i++) |
|
|
2065 | { |
1838 | if (weather_replace[i].doublestack_arch == NULL) |
2066 | if (weather_replace[i].doublestack_arch == NULL) |
1839 | continue; |
2067 | continue; |
1840 | if (weather_replace[i].arch_or_name == 1) { |
2068 | if (weather_replace[i].arch_or_name == 1) |
|
|
2069 | { |
1841 | if (!strcmp(tmp->arch->name, |
2070 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
1842 | weather_replace[i].tile)) |
|
|
1843 | found++; |
2071 | found++; |
1844 | } else { |
|
|
1845 | if (!strcmp(tmp->name, weather_replace[i].tile)) |
|
|
1846 | found++; |
|
|
1847 | } |
2072 | } |
|
|
2073 | else |
|
|
2074 | { |
|
|
2075 | if (!strcmp (tmp->name, weather_replace[i].tile)) |
|
|
2076 | found++; |
|
|
2077 | } |
1848 | if (found) { |
2078 | if (found) |
|
|
2079 | { |
1849 | tmp = tmp->above; |
2080 | tmp = tmp->above; |
1850 | doublestack2 = weather_replace[i].doublestack_arch; |
2081 | doublestack2 = weather_replace[i].doublestack_arch; |
1851 | break; |
2082 | break; |
1852 | } |
2083 | } |
1853 | } |
2084 | } |
1854 | free_object(oldsnow); |
2085 | free_object (oldsnow); |
1855 | if (tmp != NULL && doublestack2 != NULL) |
2086 | if (tmp != NULL && doublestack2 != NULL) |
1856 | if (strcmp(tmp->arch->name, doublestack2) == 0) { |
2087 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
|
|
2088 | { |
1857 | remove_ob(tmp); |
2089 | remove_ob (tmp); |
1858 | free_object(tmp); |
2090 | free_object (tmp); |
1859 | } |
2091 | } |
1860 | } |
2092 | } |
1861 | } |
2093 | } |
1862 | if (at != NULL) { |
2094 | if (at != NULL) |
|
|
2095 | { |
1863 | ob = arch_to_object (at); |
2096 | ob = arch_to_object (at); |
1864 | ob->x = x; |
2097 | ob->x = x; |
1865 | ob->y = y; |
2098 | ob->y = y; |
1866 | SET_FLAG(ob, FLAG_OVERLAY_FLOOR); |
2099 | SET_FLAG (ob, FLAG_OVERLAY_FLOOR); |
1867 | ob->material = M_LIQUID; |
2100 | ob->material = M_LIQUID; |
1868 | insert_ob_in_map(ob, m, ob, |
|
|
1869 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2101 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
1870 | if (two) { |
2102 | if (two) |
|
|
2103 | { |
1871 | at = find_archetype(doublestack); |
2104 | at = archetype::find (doublestack); |
1872 | if (at != NULL) { |
2105 | if (at != NULL) |
|
|
2106 | { |
1873 | ob = arch_to_object (at); |
2107 | ob = arch_to_object (at); |
1874 | ob->x = x; |
2108 | ob->x = x; |
1875 | ob->y = y; |
2109 | ob->y = y; |
1876 | insert_ob_in_map(ob, m, ob, |
|
|
1877 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
2110 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
1878 | } |
2111 | } |
1879 | } |
2112 | } |
1880 | } |
2113 | } |
1881 | } |
2114 | } |
1882 | /* Things evaporate fast in the heat */ |
2115 | /* Things evaporate fast in the heat */ |
1883 | if (GET_MAP_OB(m, x, y) && temp > 8 && sky < SKY_OVERCAST && rndm(temp, 60) > 50) { |
2116 | if (GET_MAP_OB (m, x, y) && temp > 8 && sky < SKY_OVERCAST && rndm (temp, 60) > 50) |
|
|
2117 | { |
1884 | /* evaporate */ |
2118 | /* evaporate */ |
1885 | for (tmp=GET_MAP_OB(m, x, y)->above; tmp; tmp = tmp->above) { |
2119 | for (tmp = GET_MAP_OB (m, x, y)->above; tmp; tmp = tmp->above) |
|
|
2120 | { |
1886 | avoid = 0; |
2121 | avoid = 0; |
1887 | if (!strcmp(tmp->arch->name, "rain1")) |
2122 | if (!strcmp (tmp->arch->name, "rain1")) |
1888 | avoid++; |
2123 | avoid++; |
1889 | else if (!strcmp(tmp->arch->name, "rain2")) |
2124 | else if (!strcmp (tmp->arch->name, "rain2")) |
1890 | avoid++; |
2125 | avoid++; |
1891 | else if (!strcmp(tmp->arch->name, "rain3")) |
2126 | else if (!strcmp (tmp->arch->name, "rain3")) |
1892 | avoid++; |
2127 | avoid++; |
1893 | else if (!strcmp(tmp->arch->name, "rain4")) |
2128 | else if (!strcmp (tmp->arch->name, "rain4")) |
1894 | avoid++; |
2129 | avoid++; |
1895 | else if (!strcmp(tmp->arch->name, "rain5")) |
2130 | else if (!strcmp (tmp->arch->name, "rain5")) |
1896 | avoid++; |
2131 | avoid++; |
1897 | else if (!strcmp(tmp->arch->name, "mountain1_rivlets")) |
2132 | else if (!strcmp (tmp->arch->name, "mountain1_rivlets")) |
1898 | avoid++; |
2133 | avoid++; |
1899 | else if (!strcmp(tmp->arch->name, "mountain2_rivlets")) |
2134 | else if (!strcmp (tmp->arch->name, "mountain2_rivlets")) |
1900 | avoid++; |
2135 | avoid++; |
1901 | if (avoid) { |
2136 | if (avoid) |
|
|
2137 | { |
1902 | remove_ob(tmp); |
2138 | remove_ob (tmp); |
1903 | free_object(tmp); |
2139 | free_object (tmp); |
1904 | if (weathermap[wx][wy].humid < 100 && rndm(0, 50) == 0) |
2140 | if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0) |
1905 | weathermap[wx][wy].humid++; |
2141 | weathermap[wx][wy].humid++; |
1906 | tmp=GET_MAP_OB(m, x, y); |
2142 | tmp = GET_MAP_OB (m, x, y); |
1907 | /* clean up the trees we put over the rain */ |
2143 | /* clean up the trees we put over the rain */ |
1908 | found = 0; |
2144 | found = 0; |
1909 | doublestack2 = NULL; |
2145 | doublestack2 = NULL; |
1910 | for (i=0; weather_replace[i].tile != NULL; i++) { |
2146 | for (i = 0; weather_replace[i].tile != NULL; i++) |
|
|
2147 | { |
1911 | if (weather_replace[i].doublestack_arch == NULL) |
2148 | if (weather_replace[i].doublestack_arch == NULL) |
1912 | continue; |
2149 | continue; |
1913 | if (weather_replace[i].arch_or_name == 1) { |
2150 | if (weather_replace[i].arch_or_name == 1) |
|
|
2151 | { |
1914 | if (!strcmp(tmp->arch->name, |
2152 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
1915 | weather_replace[i].tile)) |
|
|
1916 | found++; |
2153 | found++; |
1917 | } else { |
|
|
1918 | if (!strcmp(tmp->name, weather_replace[i].tile)) |
|
|
1919 | found++; |
|
|
1920 | } |
2154 | } |
|
|
2155 | else |
|
|
2156 | { |
|
|
2157 | if (!strcmp (tmp->name, weather_replace[i].tile)) |
|
|
2158 | found++; |
|
|
2159 | } |
1921 | if (found) { |
2160 | if (found) |
|
|
2161 | { |
1922 | tmp = tmp->above; |
2162 | tmp = tmp->above; |
1923 | doublestack2 = weather_replace[i].doublestack_arch; |
2163 | doublestack2 = weather_replace[i].doublestack_arch; |
1924 | break; |
2164 | break; |
1925 | } |
2165 | } |
1926 | } |
2166 | } |
1927 | if (tmp != NULL && doublestack2 != NULL) |
2167 | if (tmp != NULL && doublestack2 != NULL) |
1928 | if (strcmp(tmp->arch->name, doublestack2) == 0) { |
2168 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
|
|
2169 | { |
1929 | remove_ob(tmp); |
2170 | remove_ob (tmp); |
1930 | free_object(tmp); |
2171 | free_object (tmp); |
1931 | } |
2172 | } |
1932 | break; |
2173 | break; |
1933 | } |
2174 | } |
1934 | } |
2175 | } |
1935 | } |
2176 | } |
1936 | } |
2177 | } |
1937 | } |
2178 | } |
… | |
… | |
1942 | * the weathermap coordinates for the weathermap square we want to work on. |
2183 | * the weathermap coordinates for the weathermap square we want to work on. |
1943 | * filename is the pathname for the current map. This should be called from |
2184 | * filename is the pathname for the current map. This should be called from |
1944 | * weather_effect() |
2185 | * weather_effect() |
1945 | */ |
2186 | */ |
1946 | |
2187 | |
|
|
2188 | static void |
1947 | static void plant_a_garden(mapstruct *m, int wx, int wy) |
2189 | plant_a_garden (mapstruct *m, int wx, int wy) |
1948 | { |
2190 | { |
1949 | uint32 x, y, i; |
2191 | uint32 x, y, i; |
1950 | int avoid, two, temp, sky, gotsnow, found, days; |
2192 | int avoid, two, temp, sky, gotsnow, found, days; |
1951 | object *ob, *tmp; |
2193 | object *ob, *tmp; |
1952 | archetype *at; |
2194 | archetype *at; |
1953 | |
2195 | |
1954 | days = todtick / HOURS_PER_DAY; |
2196 | days = todtick / HOURS_PER_DAY; |
1955 | for (x = 0; x < settings.worldmaptilesizex; x++) { |
2197 | for (x = 0; x < settings.worldmaptilesizex; x++) |
|
|
2198 | { |
1956 | for (y=0; y < settings.worldmaptilesizey; y++) { |
2199 | for (y = 0; y < settings.worldmaptilesizey; y++) |
|
|
2200 | { |
1957 | (void)worldmap_to_weathermap(x, y, &wx, &wy, m); |
2201 | (void) worldmap_to_weathermap (x, y, &wx, &wy, m); |
1958 | ob = NULL; |
2202 | ob = NULL; |
1959 | at = NULL; |
2203 | at = NULL; |
1960 | avoid = 0; |
2204 | avoid = 0; |
1961 | two = 0; |
2205 | two = 0; |
1962 | gotsnow = 0; |
2206 | gotsnow = 0; |
1963 | /*temp = real_world_temperature(x, y, m);*/ |
2207 | /*temp = real_world_temperature(x, y, m); */ |
1964 | temp = weathermap[wx][wy].realtemp; |
2208 | temp = weathermap[wx][wy].realtemp; |
1965 | sky = weathermap[wx][wy].sky; |
2209 | sky = weathermap[wx][wy].sky; |
1966 | (void)avoid_weather(&avoid, m, x, y, &gotsnow, 1); |
2210 | (void) avoid_weather (&avoid, m, x, y, &gotsnow, 1); |
1967 | if (!avoid) { |
2211 | if (!avoid) |
|
|
2212 | { |
1968 | found = 0; |
2213 | found = 0; |
1969 | for (i=0; weather_grow[i].herb != NULL; i++) { |
2214 | for (i = 0; weather_grow[i].herb != NULL; i++) |
|
|
2215 | { |
1970 | for (tmp=GET_MAP_OB(m, x, y); tmp; tmp = tmp->above) { |
2216 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
|
|
2217 | { |
1971 | if (strcmp(tmp->arch->name, weather_grow[i].herb) != 0) |
2218 | if (strcmp (tmp->arch->name, weather_grow[i].herb) != 0) |
1972 | continue; |
2219 | continue; |
1973 | /* we found there is a herb here allready */ |
2220 | /* we found there is a herb here allready */ |
1974 | found++; |
2221 | found++; |
1975 | if ((float)weathermap[wx][wy].rainfall/days < weather_grow[i].rfmin || |
2222 | if ((float) weathermap[wx][wy].rainfall / days < weather_grow[i].rfmin || |
1976 | (float)weathermap[wx][wy].rainfall/days > weather_grow[i].rfmax || |
2223 | (float) weathermap[wx][wy].rainfall / days > weather_grow[i].rfmax || |
1977 | weathermap[wx][wy].humid < weather_grow[i].humin || |
2224 | weathermap[wx][wy].humid < weather_grow[i].humin || |
1978 | weathermap[wx][wy].humid > weather_grow[i].humax || |
2225 | weathermap[wx][wy].humid > weather_grow[i].humax || |
1979 | temp < weather_grow[i].tempmin || |
2226 | temp < weather_grow[i].tempmin || |
1980 | temp > weather_grow[i].tempmax || |
|
|
1981 | rndm(0, MIN(weather_grow[i].random/2, 1)) == 0) { |
2227 | temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0) |
|
|
2228 | { |
1982 | /* the herb does not belong, randomly delete |
2229 | /* the herb does not belong, randomly delete |
1983 | herbs to prevent overgrowth. */ |
2230 | herbs to prevent overgrowth. */ |
1984 | remove_ob(tmp); |
2231 | remove_ob (tmp); |
1985 | free_object(tmp); |
2232 | free_object (tmp); |
1986 | break; |
2233 | break; |
1987 | } |
2234 | } |
1988 | } |
2235 | } |
1989 | /* don't doublestack herbs */ |
2236 | /* don't doublestack herbs */ |
1990 | if (found) |
2237 | if (found) |
1991 | continue; |
2238 | continue; |
1992 | /* add a random factor */ |
2239 | /* add a random factor */ |
1993 | if (rndm(1, weather_grow[i].random) != 1) |
2240 | if (rndm (1, weather_grow[i].random) != 1) |
1994 | continue; |
2241 | continue; |
1995 | /* we look up through two tiles for a matching tile */ |
2242 | /* we look up through two tiles for a matching tile */ |
1996 | if (weather_grow[i].tile != NULL && GET_MAP_OB(m, x, y) != NULL) { |
2243 | if (weather_grow[i].tile != NULL && GET_MAP_OB (m, x, y) != NULL) |
|
|
2244 | { |
1997 | if (strcmp(GET_MAP_OB(m, x, y)->arch->name, |
2245 | if (strcmp (GET_MAP_OB (m, x, y)->arch->name, weather_grow[i].tile) != 0) |
1998 | weather_grow[i].tile) != 0) { |
2246 | { |
1999 | if (GET_MAP_OB(m, x, y)->above != NULL) { |
2247 | if (GET_MAP_OB (m, x, y)->above != NULL) |
2000 | if (strcmp(GET_MAP_OB(m, x, y)->above->arch->name, |
|
|
2001 | weather_grow[i].tile) != 0) |
|
|
2002 | continue; |
|
|
2003 | } else |
2248 | { |
|
|
2249 | if (strcmp (GET_MAP_OB (m, x, y)->above->arch->name, weather_grow[i].tile) != 0) |
2004 | continue; |
2250 | continue; |
|
|
2251 | } |
|
|
2252 | else |
|
|
2253 | continue; |
2005 | } |
2254 | } |
2006 | } |
2255 | } |
2007 | if ((float)weathermap[wx][wy].rainfall/days < weather_grow[i].rfmin || |
2256 | if ((float) weathermap[wx][wy].rainfall / days < weather_grow[i].rfmin || |
2008 | (float)weathermap[wx][wy].rainfall/days > weather_grow[i].rfmax) |
2257 | (float) weathermap[wx][wy].rainfall / days > weather_grow[i].rfmax) |
2009 | continue; |
2258 | continue; |
2010 | if (weathermap[wx][wy].humid < weather_grow[i].humin || |
2259 | if (weathermap[wx][wy].humid < weather_grow[i].humin || weathermap[wx][wy].humid > weather_grow[i].humax) |
2011 | weathermap[wx][wy].humid > weather_grow[i].humax) |
|
|
2012 | continue; |
2260 | continue; |
2013 | if (temp < weather_grow[i].tempmin || |
2261 | if (temp < weather_grow[i].tempmin || temp > weather_grow[i].tempmax) |
2014 | temp > weather_grow[i].tempmax) |
|
|
2015 | continue; |
2262 | continue; |
2016 | if ((!GET_MAP_OB(m, x, y)) || |
2263 | if ((!GET_MAP_OB (m, x, y)) || |
2017 | GET_MAP_OB(m, x, y)->elevation < weather_grow[i].elevmin || |
2264 | GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin || |
2018 | GET_MAP_OB(m, x, y)->elevation > weather_grow[i].elevmax) |
2265 | GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax) |
2019 | continue; |
2266 | continue; |
2020 | /* we got this far.. must be a match */ |
2267 | /* we got this far.. must be a match */ |
2021 | at = find_archetype(weather_grow[i].herb); |
2268 | at = archetype::find (weather_grow[i].herb); |
2022 | break; |
2269 | break; |
2023 | } |
2270 | } |
2024 | if (at != NULL) { |
2271 | if (at != NULL) |
|
|
2272 | { |
2025 | ob = arch_to_object (at); |
2273 | ob = arch_to_object (at); |
2026 | ob->x = x; |
2274 | ob->x = x; |
2027 | ob->y = y; |
2275 | ob->y = y; |
2028 | /* XXX is this right? maybe.. */ |
2276 | /* XXX is this right? maybe.. */ |
2029 | SET_FLAG(ob, FLAG_OVERLAY_FLOOR); |
2277 | SET_FLAG (ob, FLAG_OVERLAY_FLOOR); |
2030 | insert_ob_in_map(ob, m, ob, |
|
|
2031 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2278 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2032 | } |
2279 | } |
2033 | } |
2280 | } |
2034 | } |
2281 | } |
2035 | } |
2282 | } |
2036 | } |
2283 | } |
… | |
… | |
2040 | * wx and wy are |
2287 | * wx and wy are |
2041 | * the weathermap coordinates for the weathermap square we want to work on. |
2288 | * the weathermap coordinates for the weathermap square we want to work on. |
2042 | * This should be called from weather_effect() |
2289 | * This should be called from weather_effect() |
2043 | */ |
2290 | */ |
2044 | |
2291 | |
|
|
2292 | static void |
2045 | static void change_the_world(mapstruct *m, int wx, int wy) |
2293 | change_the_world (mapstruct *m, int wx, int wy) |
2046 | { |
2294 | { |
2047 | int x, y, i; |
2295 | int x, y, i; |
2048 | uint32 nx, ny, j, d; |
2296 | uint32 nx, ny, j, d; |
2049 | int avoid, two, temp, sky, gotsnow, found, days; |
2297 | int avoid, two, temp, sky, gotsnow, found, days; |
2050 | object *ob, *tmp, *doublestack; |
2298 | object *ob, *tmp, *doublestack; |
2051 | archetype *at, *dat; |
2299 | archetype *at, *dat; |
2052 | |
2300 | |
2053 | days = todtick / HOURS_PER_DAY; |
2301 | days = todtick / HOURS_PER_DAY; |
2054 | for (nx = 0; nx < settings.worldmaptilesizex; nx++) { |
2302 | for (nx = 0; nx < settings.worldmaptilesizex; nx++) |
|
|
2303 | { |
2055 | for (ny = 0; ny < settings.worldmaptilesizey; ny++) { |
2304 | for (ny = 0; ny < settings.worldmaptilesizey; ny++) |
|
|
2305 | { |
2056 | /* jitter factor */ |
2306 | /* jitter factor */ |
2057 | if (rndm(0, 2) > 0) { |
2307 | if (rndm (0, 2) > 0) |
|
|
2308 | { |
2058 | x=y=d=-1; |
2309 | x = y = d = -1; |
2059 | while (OUT_OF_REAL_MAP(m, x, y)) { |
2310 | while (OUT_OF_REAL_MAP (m, x, y)) |
|
|
2311 | { |
2060 | d++; |
2312 | d++; |
2061 | j=rndm(1, 8); |
2313 | j = rndm (1, 8); |
2062 | x = nx + freearr_x[j] * (rndm(0, 1) + rndm(0, 1) + rndm (0, 1) +1); |
2314 | x = nx + freearr_x[j] * (rndm (0, 1) + rndm (0, 1) + rndm (0, 1) + 1); |
2063 | y = ny + freearr_y[j] * (rndm(0, 1) + rndm(0, 1) + rndm (0, 1) +1); |
2315 | y = ny + freearr_y[j] * (rndm (0, 1) + rndm (0, 1) + rndm (0, 1) + 1); |
2064 | if (d > 15) { |
2316 | if (d > 15) |
|
|
2317 | { |
2065 | x = nx; |
2318 | x = nx; |
2066 | y = ny; |
2319 | y = ny; |
2067 | } |
2320 | } |
2068 | } |
2321 | } |
|
|
2322 | } |
2069 | } else { |
2323 | else |
|
|
2324 | { |
2070 | x = nx; |
2325 | x = nx; |
2071 | y = ny; |
2326 | y = ny; |
2072 | } |
2327 | } |
2073 | /* we use the unjittered coordinates */ |
2328 | /* we use the unjittered coordinates */ |
2074 | (void)worldmap_to_weathermap(nx, ny, &wx, &wy, m); |
2329 | (void) worldmap_to_weathermap (nx, ny, &wx, &wy, m); |
2075 | ob = NULL; |
2330 | ob = NULL; |
2076 | at = NULL; |
2331 | at = NULL; |
2077 | dat = NULL; |
2332 | dat = NULL; |
2078 | avoid = 0; |
2333 | avoid = 0; |
2079 | two = 0; |
2334 | two = 0; |
2080 | gotsnow = 0; |
2335 | gotsnow = 0; |
2081 | /*temp = real_world_temperature(x, y, m);*/ |
2336 | /*temp = real_world_temperature(x, y, m); */ |
2082 | temp = weathermap[wx][wy].realtemp; |
2337 | temp = weathermap[wx][wy].realtemp; |
2083 | sky = weathermap[wx][wy].sky; |
2338 | sky = weathermap[wx][wy].sky; |
2084 | (void)avoid_weather(&avoid, m, x, y, &gotsnow, 1); |
2339 | (void) avoid_weather (&avoid, m, x, y, &gotsnow, 1); |
2085 | if (!avoid) { |
2340 | if (!avoid) |
|
|
2341 | { |
2086 | for (i=0; weather_tile[i].herb != NULL; i++) { |
2342 | for (i = 0; weather_tile[i].herb != NULL; i++) |
|
|
2343 | { |
2087 | found=0; |
2344 | found = 0; |
2088 | doublestack=NULL; |
2345 | doublestack = NULL; |
2089 | if (GET_MAP_OB(m, x, y)) |
2346 | if (GET_MAP_OB (m, x, y)) |
2090 | for (tmp=GET_MAP_OB(m, x, y)->above; tmp; tmp = tmp->above) { |
2347 | for (tmp = GET_MAP_OB (m, x, y)->above; tmp; tmp = tmp->above) |
|
|
2348 | { |
2091 | if (weather_tile[i].tile != NULL) |
2349 | if (weather_tile[i].tile != NULL) |
2092 | if (strcmp(tmp->arch->name, |
2350 | if (strcmp (tmp->arch->name, weather_tile[i].tile) == 0) |
2093 | weather_tile[i].tile) == 0) { |
2351 | { |
2094 | doublestack=tmp; |
2352 | doublestack = tmp; |
2095 | continue; |
2353 | continue; |
2096 | } |
2354 | } |
2097 | if (strcmp(tmp->arch->name, weather_tile[i].herb) != 0) |
2355 | if (strcmp (tmp->arch->name, weather_tile[i].herb) != 0) |
2098 | continue; |
2356 | continue; |
2099 | if ((float)weathermap[wx][wy].rainfall/days < weather_tile[i].rfmin || |
2357 | if ((float) weathermap[wx][wy].rainfall / days < weather_tile[i].rfmin || |
2100 | (float)weathermap[wx][wy].rainfall/days > weather_tile[i].rfmax || |
2358 | (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax || |
2101 | weathermap[wx][wy].humid < weather_tile[i].humin || |
2359 | weathermap[wx][wy].humid < weather_tile[i].humin || |
2102 | weathermap[wx][wy].humid > weather_tile[i].humax || |
2360 | weathermap[wx][wy].humid > weather_tile[i].humax || |
2103 | temp < weather_tile[i].tempmin || |
2361 | temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax) |
2104 | temp > weather_tile[i].tempmax) { |
2362 | { |
2105 | remove_ob(tmp); |
2363 | remove_ob (tmp); |
2106 | free_object(tmp); |
2364 | free_object (tmp); |
2107 | if (doublestack) { |
2365 | if (doublestack) |
|
|
2366 | { |
2108 | remove_ob(doublestack); |
2367 | remove_ob (doublestack); |
2109 | free_object(doublestack); |
2368 | free_object (doublestack); |
2110 | } |
2369 | } |
2111 | break; |
2370 | break; |
|
|
2371 | } |
2112 | } else { |
2372 | else |
|
|
2373 | { |
2113 | found++; /* there is one here allready. leave it */ |
2374 | found++; /* there is one here allready. leave it */ |
2114 | break; |
2375 | break; |
2115 | } |
2376 | } |
|
|
2377 | } |
|
|
2378 | if (found) |
|
|
2379 | break; |
|
|
2380 | /* add a random factor */ |
|
|
2381 | if (rndm (1, weather_tile[i].random) != 1) |
|
|
2382 | continue; |
|
|
2383 | if ((float) weathermap[wx][wy].rainfall / days < weather_tile[i].rfmin || |
|
|
2384 | (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax) |
|
|
2385 | continue; |
|
|
2386 | if (weathermap[wx][wy].humid < weather_tile[i].humin || weathermap[wx][wy].humid > weather_tile[i].humax) |
|
|
2387 | continue; |
|
|
2388 | if (temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax) |
|
|
2389 | continue; |
|
|
2390 | if ((!GET_MAP_OB (m, x, y)) || |
|
|
2391 | GET_MAP_OB (m, x, y)->elevation < weather_tile[i].elevmin || |
|
|
2392 | GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax) |
|
|
2393 | continue; |
|
|
2394 | /* we got this far.. must be a match */ |
|
|
2395 | if (GET_MAP_OB (m, x, y) && strcmp (GET_MAP_OB (m, x, y)->arch->name, weather_tile[i].herb) == 0) |
|
|
2396 | break; /* no sense in doubling up */ |
|
|
2397 | at = archetype::find (weather_tile[i].herb); |
|
|
2398 | break; |
|
|
2399 | } |
|
|
2400 | if (at != NULL) |
|
|
2401 | { |
|
|
2402 | if (weather_tile[i].tile != NULL && GET_MAP_OB (m, x, y) && |
|
|
2403 | strcmp (weather_tile[i].tile, GET_MAP_OB (m, x, y)->arch->name) != 0) |
|
|
2404 | dat = archetype::find (weather_tile[i].tile); |
|
|
2405 | if (dat != NULL) |
|
|
2406 | { |
|
|
2407 | ob = arch_to_object (dat); |
|
|
2408 | ob->x = x; |
|
|
2409 | ob->y = y; |
|
|
2410 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2116 | } |
2411 | } |
2117 | if (found) |
2412 | if (gotsnow == 0) |
2118 | break; |
|
|
2119 | /* add a random factor */ |
|
|
2120 | if (rndm(1, weather_tile[i].random) != 1) |
|
|
2121 | continue; |
|
|
2122 | if ((float)weathermap[wx][wy].rainfall/days < weather_tile[i].rfmin || |
|
|
2123 | (float)weathermap[wx][wy].rainfall/days > weather_tile[i].rfmax) |
|
|
2124 | continue; |
|
|
2125 | if (weathermap[wx][wy].humid < weather_tile[i].humin || |
|
|
2126 | weathermap[wx][wy].humid > weather_tile[i].humax) |
|
|
2127 | continue; |
|
|
2128 | if (temp < weather_tile[i].tempmin || |
|
|
2129 | temp > weather_tile[i].tempmax) |
|
|
2130 | continue; |
|
|
2131 | if ( (!GET_MAP_OB(m, x, y)) || |
|
|
2132 | GET_MAP_OB(m, x, y)->elevation < weather_tile[i].elevmin || |
|
|
2133 | GET_MAP_OB(m, x, y)->elevation > weather_tile[i].elevmax) |
|
|
2134 | continue; |
|
|
2135 | /* we got this far.. must be a match */ |
|
|
2136 | if (GET_MAP_OB(m, x, y) && strcmp(GET_MAP_OB(m, x, y)->arch->name, |
|
|
2137 | weather_tile[i].herb) == 0) |
|
|
2138 | break; /* no sense in doubling up */ |
|
|
2139 | at = find_archetype(weather_tile[i].herb); |
|
|
2140 | break; |
|
|
2141 | } |
|
|
2142 | if (at != NULL) { |
|
|
2143 | if (weather_tile[i].tile != NULL && GET_MAP_OB(m, x, y) && |
|
|
2144 | strcmp(weather_tile[i].tile, |
|
|
2145 | GET_MAP_OB(m, x, y)->arch->name) != 0) |
|
|
2146 | dat = find_archetype(weather_tile[i].tile); |
|
|
2147 | if (dat != NULL) { |
|
|
2148 | ob = arch_to_object (dat); |
|
|
2149 | ob->x = x; |
|
|
2150 | ob->y = y; |
|
|
2151 | insert_ob_in_map(ob, m, ob, |
|
|
2152 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
|
|
2153 | } |
2413 | { |
2154 | if (gotsnow == 0) { |
|
|
2155 | ob = arch_to_object (at); |
2414 | ob = arch_to_object (at); |
2156 | ob->x = x; |
2415 | ob->x = x; |
2157 | ob->y = y; |
2416 | ob->y = y; |
2158 | if (dat != NULL) |
2417 | if (dat != NULL) |
2159 | insert_ob_in_map(ob, m, ob, |
|
|
2160 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
2418 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
2161 | else |
2419 | else |
2162 | insert_ob_in_map(ob, m, ob, |
|
|
2163 | INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2420 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2164 | } |
2421 | } |
2165 | } |
2422 | } |
2166 | } |
2423 | } |
2167 | } |
2424 | } |
2168 | } |
2425 | } |
… | |
… | |
2174 | * wx and wy are |
2431 | * wx and wy are |
2175 | * the weathermap coordinates for the weathermap square we want to work on. |
2432 | * the weathermap coordinates for the weathermap square we want to work on. |
2176 | * This should be called from weather_effect() |
2433 | * This should be called from weather_effect() |
2177 | */ |
2434 | */ |
2178 | #if 0 |
2435 | #if 0 |
|
|
2436 | static void |
2179 | static void feather_map(mapstruct *m, int wx, int wy) |
2437 | feather_map (mapstruct *m, int wx, int wy) |
2180 | { |
2438 | { |
2181 | uint32 x, y, i, nx, ny, j; |
2439 | uint32 x, y, i, nx, ny, j; |
2182 | int avoid, two, gotsnow, nodstk; |
2440 | int avoid, two, gotsnow, nodstk; |
2183 | object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor; |
2441 | object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor; |
2184 | archetype *at; |
2442 | archetype *at; |
2185 | |
2443 | |
2186 | for (x = 0; x < settings.worldmaptilesizex; x++) { |
2444 | for (x = 0; x < settings.worldmaptilesizex; x++) |
|
|
2445 | { |
2187 | for (y = 0; y < settings.worldmaptilesizey; y++) { |
2446 | for (y = 0; y < settings.worldmaptilesizey; y++) |
|
|
2447 | { |
2188 | (void)worldmap_to_weathermap(x, y, &wx, &wy, m); |
2448 | (void) worldmap_to_weathermap (x, y, &wx, &wy, m); |
2189 | ob = NULL; |
2449 | ob = NULL; |
2190 | at = NULL; |
2450 | at = NULL; |
2191 | avoid = 0; |
2451 | avoid = 0; |
2192 | two = 0; |
2452 | two = 0; |
2193 | j = 0; |
2453 | j = 0; |
2194 | gotsnow = 0; |
2454 | gotsnow = 0; |
2195 | nodstk = 0; |
2455 | nodstk = 0; |
2196 | oldsnow = avoid_weather(&avoid, m, x, y, &gotsnow, 1); |
2456 | oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 1); |
2197 | if (avoid) |
2457 | if (avoid) |
2198 | continue; |
2458 | continue; |
2199 | if (rndm(0, 20) == 0) |
2459 | if (rndm (0, 20) == 0) |
2200 | continue; |
2460 | continue; |
2201 | // the bottom floor of scorn is not IS_FLOOR |
2461 | // the bottom floor of scorn is not IS_FLOOR |
2202 | topfloor=NULL; |
2462 | topfloor = NULL; |
2203 | for (tmp=GET_MAP_OB(m, x, y); tmp; |
2463 | for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above) |
2204 | topfloor = tmp,tmp = tmp->above) { |
2464 | { |
2205 | if (strcmp(tmp->arch->name, "dungeon_magic") != 0) |
2465 | if (strcmp (tmp->arch->name, "dungeon_magic") != 0) |
2206 | if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR) && |
2466 | if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (tmp, FLAG_OVERLAY_FLOOR)) |
2207 | !QUERY_FLAG(tmp, FLAG_OVERLAY_FLOOR)) |
|
|
2208 | break; |
2467 | break; |
2209 | } |
2468 | } |
2210 | // topfloor should now be the topmost IS_FLOOR=1 |
2469 | // topfloor should now be the topmost IS_FLOOR=1 |
2211 | if (topfloor == NULL) |
2470 | if (topfloor == NULL) |
2212 | continue; |
2471 | continue; |
2213 | if (tmp != NULL) |
2472 | if (tmp != NULL) |
2214 | nodstk++; |
2473 | nodstk++; |
2215 | // something is wrong with that sector. just skip it |
2474 | // something is wrong with that sector. just skip it |
2216 | |
2475 | |
2217 | j=rndm(1, 8); |
2476 | j = rndm (1, 8); |
2218 | nx = freearr_x[j]+x; |
2477 | nx = freearr_x[j] + x; |
2219 | ny = freearr_y[j]+y; |
2478 | ny = freearr_y[j] + y; |
2220 | if (OUT_OF_REAL_MAP(m, nx, ny)) |
2479 | if (OUT_OF_REAL_MAP (m, nx, ny)) |
2221 | continue; |
2480 | continue; |
2222 | oldsnow = avoid_weather(&avoid, m, nx, ny, &gotsnow, 1); |
2481 | oldsnow = avoid_weather (&avoid, m, nx, ny, &gotsnow, 1); |
2223 | if (avoid) |
2482 | if (avoid) |
2224 | continue; |
2483 | continue; |
2225 | ntopfloor=NULL; |
2484 | ntopfloor = NULL; |
2226 | for (ntmp=GET_MAP_OB(m, nx, ny); ntmp; |
2485 | for (ntmp = GET_MAP_OB (m, nx, ny); ntmp; ntopfloor = ntmp, ntmp = ntmp->above) |
2227 | ntopfloor = ntmp,ntmp = ntmp->above) { |
2486 | { |
2228 | if (strcmp(ntmp->arch->name, "dungeon_magic") != 0) |
2487 | if (strcmp (ntmp->arch->name, "dungeon_magic") != 0) |
2229 | if (!QUERY_FLAG(ntmp, FLAG_IS_FLOOR) && |
2488 | if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR)) |
2230 | !QUERY_FLAG(ntmp, FLAG_OVERLAY_FLOOR)) |
|
|
2231 | break; |
2489 | break; |
2232 | } |
2490 | } |
2233 | if (ntopfloor != NULL && QUERY_FLAG(ntopfloor, FLAG_IS_FLOOR)) { |
2491 | if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR)) |
|
|
2492 | { |
2234 | remove_ob(topfloor); |
2493 | remove_ob (topfloor); |
2235 | free_object(topfloor); |
2494 | free_object (topfloor); |
2236 | if (tmp != NULL) { |
2495 | if (tmp != NULL) |
|
|
2496 | { |
2237 | for (i=0; weather_tile[i].herb != NULL; i++) { |
2497 | for (i = 0; weather_tile[i].herb != NULL; i++) |
|
|
2498 | { |
2238 | if (strcmp(tmp->arch->name, weather_tile[i].herb) == 0) { |
2499 | if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0) |
|
|
2500 | { |
2239 | remove_ob(tmp); |
2501 | remove_ob (tmp); |
2240 | free_object(tmp); |
2502 | free_object (tmp); |
2241 | break; |
2503 | break; |
2242 | } |
2504 | } |
2243 | } |
2505 | } |
2244 | } |
2506 | } |
|
|
2507 | } |
2245 | } else { |
2508 | else |
|
|
2509 | { |
2246 | continue; |
2510 | continue; |
2247 | } |
2511 | } |
2248 | ob = arch_to_object (ntopfloor->arch); |
2512 | ob = arch_to_object (ntopfloor->arch); |
2249 | ob->x = x; |
2513 | ob->x = x; |
2250 | ob->y = y; |
2514 | ob->y = y; |
2251 | insert_ob_in_map(ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2515 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
2252 | if (ntmp != NULL && nodstk == 0) { |
2516 | if (ntmp != NULL && nodstk == 0) |
|
|
2517 | { |
2253 | for (i=0; weather_tile[i].herb != NULL; i++) { |
2518 | for (i = 0; weather_tile[i].herb != NULL; i++) |
|
|
2519 | { |
2254 | if (strcmp(ntmp->arch->name, weather_tile[i].herb) == 0) { |
2520 | if (strcmp (ntmp->arch->name, weather_tile[i].herb) == 0) |
|
|
2521 | { |
2255 | ob = arch_to_object (ntmp->arch); |
2522 | ob = arch_to_object (ntmp->arch); |
2256 | ob->x = x; |
2523 | ob->x = x; |
2257 | ob->y = y; |
2524 | ob->y = y; |
2258 | insert_ob_in_map(ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
2525 | insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP); |
2259 | break; |
2526 | break; |
2260 | } |
2527 | } |
2261 | } |
2528 | } |
2262 | } |
2529 | } |
2263 | } |
2530 | } |
2264 | } |
2531 | } |
… | |
… | |
2268 | /* provide wx and wy. Will fill in with weathermap coordinates. Requires |
2535 | /* provide wx and wy. Will fill in with weathermap coordinates. Requires |
2269 | the current mapname (must be a worldmap), and your coordinates on the |
2536 | the current mapname (must be a worldmap), and your coordinates on the |
2270 | map. returns -1 if you give it something it can't figure out. 0 normally. |
2537 | map. returns -1 if you give it something it can't figure out. 0 normally. |
2271 | */ |
2538 | */ |
2272 | |
2539 | |
|
|
2540 | int |
2273 | int worldmap_to_weathermap(int x, int y, int *wx, int *wy, mapstruct* m) |
2541 | worldmap_to_weathermap (int x, int y, int *wx, int *wy, mapstruct *m) |
2274 | { |
2542 | { |
2275 | int spwtx, spwty; |
2543 | int spwtx, spwty; |
2276 | uint32 fx, fy; |
2544 | uint32 fx, fy; |
2277 | uint32 nx, ny; |
2545 | uint32 nx, ny; |
2278 | char* filename=m->path; |
2546 | char *filename = m->path; |
|
|
2547 | |
2279 | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
2548 | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
2280 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
2549 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
2281 | |
2550 | |
2282 | while (*filename == '/') |
2551 | while (*filename == '/') |
2283 | *filename++; |
2552 | *filename++; |
2284 | |
2553 | |
2285 | fx = MAP_WORLDPARTX(m); |
2554 | fx = MAP_WORLDPARTX (m); |
2286 | fy = MAP_WORLDPARTY(m); |
2555 | fy = MAP_WORLDPARTY (m); |
2287 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
|
|
2288 | fx < settings.worldmapstartx || |
|
|
2289 | fy > settings.worldmapstarty + settings.worldmaptilesy || |
|
|
2290 | fy < settings.worldmapstarty){ |
|
|
2291 | LOG(llevDebug, "worldmap_to_weathermap(%s)\n", filename); |
|
|
2292 | sscanf(filename, "world/world_%d_%d", &fx, &fy); |
|
|
2293 | MAP_WORLDPARTX(m)=fx; |
|
|
2294 | MAP_WORLDPARTY(m)=fy; |
|
|
2295 | } |
|
|
2296 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
2556 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
2297 | fx < settings.worldmapstartx) |
2557 | fx < settings.worldmapstartx || fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) |
|
|
2558 | { |
|
|
2559 | LOG (llevDebug, "worldmap_to_weathermap(%s)\n", filename); |
|
|
2560 | sscanf (filename, "world/world_%d_%d", &fx, &fy); |
|
|
2561 | MAP_WORLDPARTX (m) = fx; |
|
|
2562 | MAP_WORLDPARTY (m) = fy; |
|
|
2563 | } |
|
|
2564 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || fx < settings.worldmapstartx) |
2298 | return -1; |
2565 | return -1; |
2299 | if (fy > settings.worldmapstarty + settings.worldmaptilesy || |
2566 | if (fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) |
2300 | fy < settings.worldmapstarty) |
|
|
2301 | return -1; |
2567 | return -1; |
2302 | fx -= settings.worldmapstartx; |
2568 | fx -= settings.worldmapstartx; |
2303 | fy -= settings.worldmapstarty; |
2569 | fy -= settings.worldmapstarty; |
2304 | |
2570 | |
2305 | nx = fx * settings.worldmaptilesizex + x; |
2571 | nx = fx * settings.worldmaptilesizex + x; |
2306 | ny = fy * settings.worldmaptilesizey + y; |
2572 | ny = fy * settings.worldmaptilesizey + y; |
2307 | |
2573 | |
2308 | *wx = nx/spwtx; |
2574 | *wx = nx / spwtx; |
2309 | *wy = ny/spwty; |
2575 | *wy = ny / spwty; |
2310 | |
2576 | |
2311 | return 0; |
2577 | return 0; |
2312 | } |
2578 | } |
2313 | |
2579 | |
2314 | /* provide x and y. Will fill in with the requested corner of the real |
2580 | /* provide x and y. Will fill in with the requested corner of the real |
2315 | * world map, given the current weathermap section. dir selects which |
2581 | * world map, given the current weathermap section. dir selects which |
2316 | * corner to return. Valid values are 2 4 6 8 for the corners. return |
2582 | * corner to return. Valid values are 2 4 6 8 for the corners. return |
2317 | * value is the name of the map that corner resides in. |
2583 | * value is the name of the map that corner resides in. |
2318 | */ |
2584 | */ |
2319 | |
2585 | |
|
|
2586 | static const char * |
2320 | static const char *weathermap_to_worldmap_corner(int wx, int wy, int *x, int *y, int dir) |
2587 | weathermap_to_worldmap_corner (int wx, int wy, int *x, int *y, int dir) |
2321 | { |
2588 | { |
2322 | int spwtx, spwty; |
2589 | int spwtx, spwty; |
2323 | int tx, ty, nx, ny; |
2590 | int tx, ty, nx, ny; |
2324 | static char mapname[ MAX_BUF ]; |
2591 | static char mapname[MAX_BUF]; |
2325 | |
2592 | |
2326 | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
2593 | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
2327 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
2594 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
2328 | switch (dir) { |
2595 | switch (dir) |
2329 | case 2: wx++; break; |
|
|
2330 | case 4: wx++; wy++; break; |
|
|
2331 | case 6: wy++; break; |
|
|
2332 | case 8: break; |
|
|
2333 | } |
2596 | { |
|
|
2597 | case 2: |
|
|
2598 | wx++; |
|
|
2599 | break; |
|
|
2600 | case 4: |
|
|
2601 | wx++; |
|
|
2602 | wy++; |
|
|
2603 | break; |
|
|
2604 | case 6: |
|
|
2605 | wy++; |
|
|
2606 | break; |
|
|
2607 | case 8: |
|
|
2608 | break; |
|
|
2609 | } |
2334 | if (wx > 0) |
2610 | if (wx > 0) |
2335 | tx = (wx*spwtx)-1; |
2611 | tx = (wx * spwtx) - 1; |
2336 | else |
2612 | else |
2337 | tx = wx; |
2613 | tx = wx; |
2338 | if (wy > 0) |
2614 | if (wy > 0) |
2339 | ty = (wy*spwty)-1; |
2615 | ty = (wy * spwty) - 1; |
2340 | else |
2616 | else |
2341 | ty = wy; |
2617 | ty = wy; |
2342 | |
2618 | |
2343 | nx = (tx / settings.worldmaptilesizex) + settings.worldmapstartx; |
2619 | nx = (tx / settings.worldmaptilesizex) + settings.worldmapstartx; |
2344 | ny = (ty / settings.worldmaptilesizey) + settings.worldmapstarty; |
2620 | ny = (ty / settings.worldmaptilesizey) + settings.worldmapstarty; |
2345 | snprintf(mapname, MAX_BUF, "world/world_%d_%d", nx, ny); |
2621 | snprintf (mapname, MAX_BUF, "world/world_%d_%d", nx, ny); |
2346 | |
2622 | |
2347 | *x = tx%settings.worldmaptilesizex; |
2623 | *x = tx % settings.worldmaptilesizex; |
2348 | *y = ty%settings.worldmaptilesizey; |
2624 | *y = ty % settings.worldmaptilesizey; |
2349 | return mapname; |
2625 | return mapname; |
2350 | } |
2626 | } |
2351 | |
2627 | |
2352 | /* |
2628 | /* |
2353 | * Calculates the distance to the nearest pole. x,y are the weathermap |
2629 | * Calculates the distance to the nearest pole. x,y are the weathermap |
2354 | * coordinates, equator is the current location of the equator. returns |
2630 | * coordinates, equator is the current location of the equator. returns |
2355 | * distance as an int. |
2631 | * distance as an int. |
2356 | */ |
2632 | */ |
2357 | |
2633 | |
2358 | |
2634 | |
|
|
2635 | static int |
2359 | static int polar_distance(int x, int y, int equator) |
2636 | polar_distance (int x, int y, int equator) |
2360 | { |
2637 | { |
2361 | if ((x+y) > equator) { /* south pole */ |
2638 | if ((x + y) > equator) |
|
|
2639 | { /* south pole */ |
2362 | x = WEATHERMAPTILESX - x; |
2640 | x = WEATHERMAPTILESX - x; |
2363 | y = WEATHERMAPTILESY - y; |
2641 | y = WEATHERMAPTILESY - y; |
2364 | return ((x+y)/2); |
2642 | return ((x + y) / 2); |
2365 | } else if ((x+y) < equator) { /* north pole */ |
2643 | } |
|
|
2644 | else if ((x + y) < equator) |
|
|
2645 | { /* north pole */ |
2366 | return ((x+y)/2); |
2646 | return ((x + y) / 2); |
2367 | } else { |
2647 | } |
|
|
2648 | else |
|
|
2649 | { |
2368 | return equator/2; |
2650 | return equator / 2; |
2369 | } |
2651 | } |
2370 | } |
2652 | } |
2371 | |
2653 | |
2372 | /* |
2654 | /* |
2373 | * update the humidity for all weathermap tiles. |
2655 | * update the humidity for all weathermap tiles. |
2374 | */ |
2656 | */ |
2375 | |
2657 | |
2376 | static void update_humid(void) |
2658 | static void |
|
|
2659 | update_humid (void) |
2377 | { |
2660 | { |
2378 | int x, y; |
2661 | int x, y; |
2379 | |
2662 | |
2380 | for (y=0; y < WEATHERMAPTILESY; y++) |
2663 | for (y = 0; y < WEATHERMAPTILESY; y++) |
2381 | for (x=0; x < WEATHERMAPTILESX; x++) |
2664 | for (x = 0; x < WEATHERMAPTILESX; x++) |
2382 | weathermap[x][y].humid = humid_tile(x, y); |
2665 | weathermap[x][y].humid = humid_tile (x, y); |
2383 | } |
2666 | } |
2384 | |
2667 | |
2385 | /* |
2668 | /* |
2386 | * calculate the humidity of this tile. x and y are the weathermap coordinates |
2669 | * calculate the humidity of this tile. x and y are the weathermap coordinates |
2387 | * we wish to calculate humidity for. Returns the humidity of the weathermap |
2670 | * we wish to calculate humidity for. Returns the humidity of the weathermap |
2388 | * square. |
2671 | * square. |
2389 | */ |
2672 | */ |
2390 | |
2673 | |
|
|
2674 | static int |
2391 | static int humid_tile(int x, int y) |
2675 | humid_tile (int x, int y) |
2392 | { |
2676 | { |
2393 | int ox, oy, humid; |
2677 | int ox, oy, humid; |
2394 | |
2678 | |
2395 | ox = x; |
2679 | ox = x; |
2396 | oy = y; |
2680 | oy = y; |
2397 | |
2681 | |
2398 | /* find the square the wind is coming from, without going out of bounds */ |
2682 | /* find the square the wind is coming from, without going out of bounds */ |
2399 | |
2683 | |
2400 | if (weathermap[x][y].winddir == 8 || weathermap[x][y].winddir <= 2) { |
2684 | if (weathermap[x][y].winddir == 8 || weathermap[x][y].winddir <= 2) |
|
|
2685 | { |
2401 | if (y != 0) |
2686 | if (y != 0) |
2402 | oy = y - 1; |
2687 | oy = y - 1; |
2403 | } |
2688 | } |
2404 | if (weathermap[x][y].winddir >= 6) { |
2689 | if (weathermap[x][y].winddir >= 6) |
|
|
2690 | { |
2405 | if (x != 0) |
2691 | if (x != 0) |
2406 | ox = x - 1; |
2692 | ox = x - 1; |
2407 | } |
2693 | } |
2408 | if (weathermap[x][y].winddir >= 4 && weathermap[x][y].winddir <= 6) { |
2694 | if (weathermap[x][y].winddir >= 4 && weathermap[x][y].winddir <= 6) |
|
|
2695 | { |
2409 | if (y < WEATHERMAPTILESY - 1) |
2696 | if (y < WEATHERMAPTILESY - 1) |
2410 | oy = y + 1; |
2697 | oy = y + 1; |
2411 | } |
2698 | } |
2412 | if (weathermap[x][y].winddir >= 2 && weathermap[x][y].winddir <= 4) { |
2699 | if (weathermap[x][y].winddir >= 2 && weathermap[x][y].winddir <= 4) |
|
|
2700 | { |
2413 | if (x < WEATHERMAPTILESX - 1) |
2701 | if (x < WEATHERMAPTILESX - 1) |
2414 | ox = x + 1; |
2702 | ox = x + 1; |
2415 | } |
2703 | } |
2416 | humid = (weathermap[x][y].humid * 2 + |
2704 | humid = (weathermap[x][y].humid * 2 + |
2417 | weathermap[ox][oy].humid * weathermap[ox][oy].windspeed + |
2705 | weathermap[ox][oy].humid * weathermap[ox][oy].windspeed + |
2418 | weathermap[x][y].water + rndm(0, 10)) / |
2706 | weathermap[x][y].water + rndm (0, 10)) / (weathermap[ox][oy].windspeed + 3) + rndm (0, 5); |
2419 | (weathermap[ox][oy].windspeed+3) + rndm(0, 5); |
|
|
2420 | if (humid < 0) |
2707 | if (humid < 0) |
2421 | humid = 1; |
2708 | humid = 1; |
2422 | if (humid > 100) |
2709 | if (humid > 100) |
2423 | humid = 100; |
2710 | humid = 100; |
2424 | return humid; |
2711 | return humid; |
2425 | } |
2712 | } |
2426 | |
2713 | |
2427 | /* |
2714 | /* |
2428 | * calculate temperature of the weathermap square x,y. Requires the current |
2715 | * calculate temperature of the weathermap square x,y. Requires the current |
2429 | * time of day in *tod. |
2716 | * time of day in *tod. |
2430 | */ |
2717 | */ |
2431 | |
2718 | |
|
|
2719 | static void |
2432 | static void temperature_calc(int x, int y, const timeofday_t *tod) |
2720 | temperature_calc (int x, int y, const timeofday_t * tod) |
2433 | { |
2721 | { |
2434 | int dist, equator, elev, n; |
2722 | int dist, equator, elev, n; |
2435 | float diff, tdiff; |
2723 | float diff, tdiff; |
2436 | |
2724 | |
2437 | equator = (WEATHERMAPTILESX + WEATHERMAPTILESY) / 4; |
2725 | equator = (WEATHERMAPTILESX + WEATHERMAPTILESY) / 4; |
2438 | diff = (float)(EQUATOR_BASE_TEMP - POLAR_BASE_TEMP) / (float)equator; |
2726 | diff = (float) (EQUATOR_BASE_TEMP - POLAR_BASE_TEMP) / (float) equator; |
2439 | tdiff = (float)SEASONAL_ADJUST / ((float)MONTHS_PER_YEAR / 2.0); |
2727 | tdiff = (float) SEASONAL_ADJUST / ((float) MONTHS_PER_YEAR / 2.0); |
2440 | equator *= 2; |
2728 | equator *= 2; |
2441 | n = 0; |
2729 | n = 0; |
2442 | /* we essentially move the equator during the season */ |
2730 | /* we essentially move the equator during the season */ |
2443 | if (tod->month > (MONTHS_PER_YEAR / 2)) { /* EOY */ |
2731 | if (tod->month > (MONTHS_PER_YEAR / 2)) |
|
|
2732 | { /* EOY */ |
2444 | n -= (int) (tod->month * tdiff); |
2733 | n -= (int) (tod->month * tdiff); |
2445 | } else { |
2734 | } |
|
|
2735 | else |
|
|
2736 | { |
2446 | n = (int) ((MONTHS_PER_YEAR - tod->month) * tdiff); |
2737 | n = (int) ((MONTHS_PER_YEAR - tod->month) * tdiff); |
2447 | } |
2738 | } |
2448 | dist = polar_distance(x-n/2, y-n/2, equator); |
2739 | dist = polar_distance (x - n / 2, y - n / 2, equator); |
2449 | |
2740 | |
2450 | /* now we have the base temp, unadjusted for time. Time adjustment |
2741 | /* now we have the base temp, unadjusted for time. Time adjustment |
2451 | is not recorded on the map, rather, it's done JIT. */ |
2742 | is not recorded on the map, rather, it's done JIT. */ |
2452 | weathermap[x][y].temp = (int)(dist * diff); |
2743 | weathermap[x][y].temp = (int) (dist * diff); |
2453 | /* just scrap these for now, its mostly ocean */ |
2744 | /* just scrap these for now, its mostly ocean */ |
2454 | if (weathermap[x][y].avgelev < 0) |
2745 | if (weathermap[x][y].avgelev < 0) |
2455 | elev = 0; |
2746 | elev = 0; |
2456 | else |
2747 | else |
2457 | elev = MAX(10000, weathermap[x][y].avgelev)/1000; |
2748 | elev = MAX (10000, weathermap[x][y].avgelev) / 1000; |
2458 | weathermap[x][y].temp -= elev; |
2749 | weathermap[x][y].temp -= elev; |
2459 | } |
2750 | } |
2460 | |
2751 | |
2461 | /* Compute the real (adjusted) temperature of a given weathermap tile. |
2752 | /* Compute the real (adjusted) temperature of a given weathermap tile. |
2462 | * This takes into account the wind, base temp, sunlight, and other fun |
2753 | * This takes into account the wind, base temp, sunlight, and other fun |
2463 | * things. Seasons are automatically handled by moving the equator. |
2754 | * things. Seasons are automatically handled by moving the equator. |
2464 | * Elevation is partially considered in the base temp. x and y are the |
2755 | * Elevation is partially considered in the base temp. x and y are the |
2465 | * weathermap coordinates. |
2756 | * weathermap coordinates. |
2466 | */ |
2757 | */ |
2467 | |
2758 | |
|
|
2759 | static int |
2468 | static int real_temperature(int x, int y) |
2760 | real_temperature (int x, int y) |
2469 | { |
2761 | { |
2470 | int i, temp; |
2762 | int i, temp; |
2471 | timeofday_t tod; |
2763 | timeofday_t tod; |
2472 | |
2764 | |
2473 | /* adjust for time of day */ |
2765 | /* adjust for time of day */ |
2474 | temp = weathermap[x][y].temp; |
2766 | temp = weathermap[x][y].temp; |
2475 | get_tod(&tod); |
2767 | get_tod (&tod); |
2476 | for (i = HOURS_PER_DAY/2; i < HOURS_PER_DAY; i++) { |
2768 | for (i = HOURS_PER_DAY / 2; i < HOURS_PER_DAY; i++) |
|
|
2769 | { |
2477 | temp += season_tempchange[i]; |
2770 | temp += season_tempchange[i]; |
2478 | /* high amounts of water has a buffering effect on the temp */ |
2771 | /* high amounts of water has a buffering effect on the temp */ |
2479 | if (weathermap[x][y].water > 33) |
2772 | if (weathermap[x][y].water > 33) |
2480 | i++; |
2773 | i++; |
2481 | } |
2774 | } |
2482 | for (i = 0; i <= tod.hour; i++) { |
2775 | for (i = 0; i <= tod.hour; i++) |
|
|
2776 | { |
2483 | temp += season_tempchange[i]; |
2777 | temp += season_tempchange[i]; |
2484 | if (weathermap[x][y].water > 33) |
2778 | if (weathermap[x][y].water > 33) |
2485 | i++; |
2779 | i++; |
2486 | } |
2780 | } |
2487 | |
2781 | |
2488 | /* windchill */ |
2782 | /* windchill */ |
2489 | for (i=1; i < weathermap[x][y].windspeed; i+=i) |
2783 | for (i = 1; i < weathermap[x][y].windspeed; i += i) |
2490 | temp--; |
2784 | temp--; |
2491 | |
2785 | |
2492 | return temp; |
2786 | return temp; |
2493 | } |
2787 | } |
2494 | |
2788 | |
2495 | /* Given a worldmap name, and x and y on that map, compute the temperature |
2789 | /* Given a worldmap name, and x and y on that map, compute the temperature |
2496 | for a specific square. Used to normalize elevation. |
2790 | for a specific square. Used to normalize elevation. |
2497 | */ |
2791 | */ |
2498 | |
2792 | |
|
|
2793 | int |
2499 | int real_world_temperature(int x, int y, mapstruct *m) |
2794 | real_world_temperature (int x, int y, mapstruct *m) |
2500 | { |
2795 | { |
2501 | int wx, wy, temp, eleva, elevb; |
2796 | int wx, wy, temp, eleva, elevb; |
2502 | object *op; |
2797 | object *op; |
|
|
2798 | |
2503 | /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path);*/ |
2799 | /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */ |
2504 | worldmap_to_weathermap(x, y, &wx, &wy, /*m->path*/m); |
2800 | worldmap_to_weathermap (x, y, &wx, &wy, /*m->path */ m); |
2505 | temp = real_temperature(wx, wy); |
2801 | temp = real_temperature (wx, wy); |
2506 | if (weathermap[wx][wy].avgelev < 0) |
2802 | if (weathermap[wx][wy].avgelev < 0) |
2507 | eleva = 0; |
2803 | eleva = 0; |
2508 | else |
2804 | else |
2509 | eleva = weathermap[x][y].avgelev; |
2805 | eleva = weathermap[x][y].avgelev; |
2510 | |
2806 | |
2511 | op= GET_MAP_OB(m, x, y); |
2807 | op = GET_MAP_OB (m, x, y); |
|
|
2808 | if (!op) |
2512 | if (!op) return eleva; |
2809 | return eleva; |
2513 | |
2810 | |
2514 | elevb = op->elevation; |
2811 | elevb = op->elevation; |
2515 | if (elevb < 0) |
2812 | if (elevb < 0) |
2516 | elevb = 0; |
2813 | elevb = 0; |
2517 | if (elevb > eleva) { |
2814 | if (elevb > eleva) |
|
|
2815 | { |
2518 | elevb -= eleva; |
2816 | elevb -= eleva; |
2519 | temp -= elevb/1000; |
2817 | temp -= elevb / 1000; |
2520 | } else { |
2818 | } |
|
|
2819 | else |
|
|
2820 | { |
2521 | elevb = eleva - elevb; |
2821 | elevb = eleva - elevb; |
2522 | temp += elevb/1000; |
2822 | temp += elevb / 1000; |
2523 | } |
2823 | } |
2524 | return temp; |
2824 | return temp; |
2525 | } |
2825 | } |
2526 | |
2826 | |
2527 | /* this code simply smooths the pressure map */ |
2827 | /* this code simply smooths the pressure map */ |
2528 | |
2828 | |
|
|
2829 | static void |
2529 | static void smooth_pressure(void) |
2830 | smooth_pressure (void) |
2530 | { |
2831 | { |
2531 | int x, y; |
2832 | int x, y; |
2532 | int k; |
2833 | int k; |
2533 | |
2834 | |
2534 | for (k=0; k < PRESSURE_ROUNDING_ITER; k++) { |
2835 | for (k = 0; k < PRESSURE_ROUNDING_ITER; k++) |
|
|
2836 | { |
2535 | for (x=2; x < WEATHERMAPTILESX-2; x++) { |
2837 | for (x = 2; x < WEATHERMAPTILESX - 2; x++) |
|
|
2838 | { |
2536 | for (y=2; y < WEATHERMAPTILESY-2; y++) { |
2839 | for (y = 2; y < WEATHERMAPTILESY - 2; y++) |
|
|
2840 | { |
2537 | weathermap[x][y].pressure = (weathermap[x][y].pressure * |
2841 | weathermap[x][y].pressure = (weathermap[x][y].pressure * |
2538 | PRESSURE_ROUNDING_FACTOR + weathermap[x-1][y].pressure + |
2842 | PRESSURE_ROUNDING_FACTOR + weathermap[x - 1][y].pressure + |
2539 | weathermap[x][y-1].pressure + weathermap[x-1][y-1].pressure + |
2843 | weathermap[x][y - 1].pressure + weathermap[x - 1][y - 1].pressure + |
2540 | weathermap[x+1][y].pressure + weathermap[x][y+1].pressure + |
2844 | weathermap[x + 1][y].pressure + weathermap[x][y + 1].pressure + |
2541 | weathermap[x+1][y+1].pressure + weathermap[x+1][y-1].pressure + |
2845 | weathermap[x + 1][y + 1].pressure + weathermap[x + 1][y - 1].pressure + |
2542 | weathermap[x-1][y+1].pressure) / (PRESSURE_ROUNDING_FACTOR+8); |
2846 | weathermap[x - 1][y + 1].pressure) / (PRESSURE_ROUNDING_FACTOR + 8); |
2543 | } |
2847 | } |
2544 | } |
2848 | } |
2545 | for (x=WEATHERMAPTILESX-2; x > 2; x--) { |
2849 | for (x = WEATHERMAPTILESX - 2; x > 2; x--) |
|
|
2850 | { |
2546 | for (y=WEATHERMAPTILESY-2; y > 2; y--) { |
2851 | for (y = WEATHERMAPTILESY - 2; y > 2; y--) |
|
|
2852 | { |
2547 | weathermap[x][y].pressure = (weathermap[x][y].pressure * |
2853 | weathermap[x][y].pressure = (weathermap[x][y].pressure * |
2548 | PRESSURE_ROUNDING_FACTOR + weathermap[x-1][y].pressure + |
2854 | PRESSURE_ROUNDING_FACTOR + weathermap[x - 1][y].pressure + |
2549 | weathermap[x][y-1].pressure + weathermap[x-1][y-1].pressure + |
2855 | weathermap[x][y - 1].pressure + weathermap[x - 1][y - 1].pressure + |
2550 | weathermap[x+1][y].pressure + weathermap[x][y+1].pressure + |
2856 | weathermap[x + 1][y].pressure + weathermap[x][y + 1].pressure + |
2551 | weathermap[x+1][y+1].pressure + weathermap[x+1][y-1].pressure + |
2857 | weathermap[x + 1][y + 1].pressure + weathermap[x + 1][y - 1].pressure + |
2552 | weathermap[x-1][y+1].pressure) / (PRESSURE_ROUNDING_FACTOR+8); |
2858 | weathermap[x - 1][y + 1].pressure) / (PRESSURE_ROUNDING_FACTOR + 8); |
2553 | } |
2859 | } |
2554 | } |
2860 | } |
2555 | } |
2861 | } |
2556 | |
2862 | |
2557 | for (x=0; x < WEATHERMAPTILESX; x++) |
2863 | for (x = 0; x < WEATHERMAPTILESX; x++) |
2558 | for (y=0; y < WEATHERMAPTILESY; y++) { |
2864 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
2865 | { |
2559 | weathermap[x][y].pressure = MIN(weathermap[x][y].pressure, PRESSURE_MAX); |
2866 | weathermap[x][y].pressure = MIN (weathermap[x][y].pressure, PRESSURE_MAX); |
2560 | weathermap[x][y].pressure = MAX(weathermap[x][y].pressure, PRESSURE_MIN); |
2867 | weathermap[x][y].pressure = MAX (weathermap[x][y].pressure, PRESSURE_MIN); |
2561 | } |
2868 | } |
2562 | |
2869 | |
2563 | } |
2870 | } |
2564 | |
2871 | |
2565 | /* |
2872 | /* |
2566 | * perform small randomizations in the pressure map. Then, apply the |
2873 | * perform small randomizations in the pressure map. Then, apply the |
2567 | * smoothing algorithim.. This causes the pressure to change very slowly |
2874 | * smoothing algorithim.. This causes the pressure to change very slowly |
2568 | */ |
2875 | */ |
2569 | |
2876 | |
|
|
2877 | static void |
2570 | static void perform_pressure(void) |
2878 | perform_pressure (void) |
2571 | { |
2879 | { |
2572 | int x, y, l, n, j, k; |
2880 | int x, y, l, n, j, k; |
2573 | |
2881 | |
2574 | /* create random spikes in the pressure */ |
2882 | /* create random spikes in the pressure */ |
2575 | for (l=0; l < PRESSURE_SPIKES; l++) { |
2883 | for (l = 0; l < PRESSURE_SPIKES; l++) |
|
|
2884 | { |
2576 | x = rndm(0, WEATHERMAPTILESX-1); |
2885 | x = rndm (0, WEATHERMAPTILESX - 1); |
2577 | y = rndm(0, WEATHERMAPTILESY-1); |
2886 | y = rndm (0, WEATHERMAPTILESY - 1); |
2578 | n = rndm(600, 1300); |
2887 | n = rndm (600, 1300); |
2579 | weathermap[x][y].pressure = n; |
2888 | weathermap[x][y].pressure = n; |
2580 | if (x > 5 && y > 5 && x < WEATHERMAPTILESX-5 && y < WEATHERMAPTILESY-5){ |
2889 | if (x > 5 && y > 5 && x < WEATHERMAPTILESX - 5 && y < WEATHERMAPTILESY - 5) |
|
|
2890 | { |
2581 | for (j=x-2; j<x+2; j++) |
2891 | for (j = x - 2; j < x + 2; j++) |
2582 | for (k=y-2; k<y+2; k++) { |
2892 | for (k = y - 2; k < y + 2; k++) |
|
|
2893 | { |
2583 | weathermap[j][k].pressure = n; |
2894 | weathermap[j][k].pressure = n; |
2584 | /* occasionally add a storm */ |
2895 | /* occasionally add a storm */ |
2585 | if (rndm(1, 20) == 1) |
2896 | if (rndm (1, 20) == 1) |
2586 | weathermap[j][k].humid = rndm(50, 80); |
2897 | weathermap[j][k].humid = rndm (50, 80); |
2587 | } |
2898 | } |
2588 | } |
2899 | } |
2589 | } |
2900 | } |
2590 | |
2901 | |
2591 | for (x=0; x < WEATHERMAPTILESX; x++) |
2902 | for (x = 0; x < WEATHERMAPTILESX; x++) |
2592 | for (y=0; y < WEATHERMAPTILESY; y++) |
2903 | for (y = 0; y < WEATHERMAPTILESY; y++) |
2593 | weathermap[x][y].pressure += rndm(-1, 4); |
2904 | weathermap[x][y].pressure += rndm (-1, 4); |
2594 | |
2905 | |
2595 | smooth_pressure(); |
2906 | smooth_pressure (); |
2596 | } |
2907 | } |
2597 | |
2908 | |
2598 | |
2909 | |
2599 | /* |
2910 | /* |
2600 | * is direction a similar to direction b? Find out in this exciting function |
2911 | * is direction a similar to direction b? Find out in this exciting function |
2601 | * below. Returns 1 if true, 0 for false. |
2912 | * below. Returns 1 if true, 0 for false. |
2602 | */ |
2913 | */ |
2603 | |
2914 | |
|
|
2915 | int |
2604 | int similar_direction(int a, int b) |
2916 | similar_direction (int a, int b) |
2605 | { |
2917 | { |
2606 | /* shortcut the obvious */ |
2918 | /* shortcut the obvious */ |
2607 | if (a == b) |
2919 | if (a == b) |
2608 | return 1; |
|
|
2609 | |
|
|
2610 | switch(a) { |
|
|
2611 | case 1: if (b <= 2 || b == 8) return 1; break; |
|
|
2612 | case 2: if (b > 0 && b < 4) return 1; break; |
|
|
2613 | case 3: if (b > 1 && b < 5) return 1; break; |
|
|
2614 | case 4: if (b > 2 && b < 6) return 1; break; |
|
|
2615 | case 5: if (b > 3 && b < 7) return 1; break; |
|
|
2616 | case 6: if (b > 4 && b < 8) return 1; break; |
|
|
2617 | case 7: if (b > 5) return 1; break; |
|
|
2618 | case 8: if (b > 6 || b == 1) return 1; break; |
|
|
2619 | } |
|
|
2620 | return 0; |
2920 | return 1; |
|
|
2921 | |
|
|
2922 | switch (a) |
|
|
2923 | { |
|
|
2924 | case 1: |
|
|
2925 | if (b <= 2 || b == 8) |
|
|
2926 | return 1; |
|
|
2927 | break; |
|
|
2928 | case 2: |
|
|
2929 | if (b > 0 && b < 4) |
|
|
2930 | return 1; |
|
|
2931 | break; |
|
|
2932 | case 3: |
|
|
2933 | if (b > 1 && b < 5) |
|
|
2934 | return 1; |
|
|
2935 | break; |
|
|
2936 | case 4: |
|
|
2937 | if (b > 2 && b < 6) |
|
|
2938 | return 1; |
|
|
2939 | break; |
|
|
2940 | case 5: |
|
|
2941 | if (b > 3 && b < 7) |
|
|
2942 | return 1; |
|
|
2943 | break; |
|
|
2944 | case 6: |
|
|
2945 | if (b > 4 && b < 8) |
|
|
2946 | return 1; |
|
|
2947 | break; |
|
|
2948 | case 7: |
|
|
2949 | if (b > 5) |
|
|
2950 | return 1; |
|
|
2951 | break; |
|
|
2952 | case 8: |
|
|
2953 | if (b > 6 || b == 1) |
|
|
2954 | return 1; |
|
|
2955 | break; |
|
|
2956 | } |
|
|
2957 | return 0; |
2621 | } |
2958 | } |
2622 | |
2959 | |
2623 | /* |
2960 | /* |
2624 | * It doesn't really smooth it as such. The main function of this is to |
2961 | * It doesn't really smooth it as such. The main function of this is to |
2625 | * apply the pressuremap to the wind direction and speed. Then, we run |
2962 | * apply the pressuremap to the wind direction and speed. Then, we run |
2626 | * a quick pass to update the windspeed. |
2963 | * a quick pass to update the windspeed. |
2627 | */ |
2964 | */ |
2628 | |
2965 | |
2629 | static void smooth_wind(void) |
2966 | static void |
|
|
2967 | smooth_wind (void) |
2630 | { |
2968 | { |
2631 | int x, y; |
2969 | int x, y; |
2632 | int tx, ty, dx, dy; |
2970 | int tx, ty, dx, dy; |
2633 | int minp; |
2971 | int minp; |
2634 | |
2972 | |
2635 | /* skip the outer squares.. it makes handling alot easier */ |
2973 | /* skip the outer squares.. it makes handling alot easier */ |
2636 | dx = 0; |
2974 | dx = 0; |
2637 | dy = 0; |
2975 | dy = 0; |
2638 | for (x=1; x < WEATHERMAPTILESX-1; x++) |
2976 | for (x = 1; x < WEATHERMAPTILESX - 1; x++) |
2639 | for (y=1; y < WEATHERMAPTILESY-1; y++) { |
2977 | for (y = 1; y < WEATHERMAPTILESY - 1; y++) |
|
|
2978 | { |
2640 | minp = PRESSURE_MAX + 1; |
2979 | minp = PRESSURE_MAX + 1; |
2641 | for (tx=-1; tx < 2; tx++) |
2980 | for (tx = -1; tx < 2; tx++) |
2642 | for (ty=-1; ty < 2; ty++) |
2981 | for (ty = -1; ty < 2; ty++) |
2643 | if (!(tx == 0 && ty == 0)) |
2982 | if (!(tx == 0 && ty == 0)) |
2644 | if (weathermap[x+tx][y+ty].pressure < minp) { |
2983 | if (weathermap[x + tx][y + ty].pressure < minp) |
|
|
2984 | { |
2645 | minp = weathermap[x+tx][y+ty].pressure; |
2985 | minp = weathermap[x + tx][y + ty].pressure; |
2646 | dx = tx; |
2986 | dx = tx; |
2647 | dy = ty; |
2987 | dy = ty; |
2648 | } |
2988 | } |
2649 | |
2989 | |
2650 | /* if the wind is strong, the pressure won't decay it completely */ |
2990 | /* if the wind is strong, the pressure won't decay it completely */ |
2651 | if (weathermap[x][y].windspeed > 5 && |
2991 | if (weathermap[x][y].windspeed > 5 && !similar_direction (weathermap[x][y].winddir, find_dir_2 (dx, dy))) |
2652 | !similar_direction(weathermap[x][y].winddir, find_dir_2(dx, dy))) { |
2992 | { |
2653 | weathermap[x][y].windspeed -= 2 * 2; |
2993 | weathermap[x][y].windspeed -= 2 * 2; |
2654 | } else { |
|
|
2655 | weathermap[x][y].winddir = find_dir_2(dx, dy); |
|
|
2656 | weathermap[x][y].windspeed = (sint8) ((weathermap[x][y].pressure - |
|
|
2657 | weathermap[x+dx][y+dy].pressure) * WIND_FACTOR); |
|
|
2658 | } |
2994 | } |
|
|
2995 | else |
|
|
2996 | { |
|
|
2997 | weathermap[x][y].winddir = find_dir_2 (dx, dy); |
|
|
2998 | weathermap[x][y].windspeed = (sint8) ((weathermap[x][y].pressure - weathermap[x + dx][y + dy].pressure) * WIND_FACTOR); |
|
|
2999 | } |
2659 | /* Add in sea breezes. */ |
3000 | /* Add in sea breezes. */ |
2660 | weathermap[x][y].windspeed += weathermap[x][y].water / 4; |
3001 | weathermap[x][y].windspeed += weathermap[x][y].water / 4; |
2661 | if (weathermap[x][y].windspeed < 0) |
3002 | if (weathermap[x][y].windspeed < 0) |
2662 | weathermap[x][y].windspeed = 0; |
3003 | weathermap[x][y].windspeed = 0; |
2663 | } |
3004 | } |
2664 | |
3005 | |
2665 | /* now, lets crank on the speed. When surrounding tiles all have |
3006 | /* now, lets crank on the speed. When surrounding tiles all have |
2666 | the same speed, inc ours. If it's chaos. drop it. |
3007 | the same speed, inc ours. If it's chaos. drop it. |
2667 | */ |
3008 | */ |
2668 | for (x=1; x < WEATHERMAPTILESX-1; x++) |
3009 | for (x = 1; x < WEATHERMAPTILESX - 1; x++) |
2669 | for (y=1; y < WEATHERMAPTILESY-1; y++) { |
3010 | for (y = 1; y < WEATHERMAPTILESY - 1; y++) |
|
|
3011 | { |
2670 | minp = 0; |
3012 | minp = 0; |
2671 | for (tx=-1; tx < 2; tx++) |
3013 | for (tx = -1; tx < 2; tx++) |
2672 | for (ty=-1; ty < 2; ty++) |
3014 | for (ty = -1; ty < 2; ty++) |
2673 | if (ty != 0 && ty != 0) |
3015 | if (ty != 0 && ty != 0) |
2674 | if (similar_direction(weathermap[x][y].winddir, |
3016 | if (similar_direction (weathermap[x][y].winddir, weathermap[x + tx][y + ty].winddir)) |
2675 | weathermap[x+tx][y+ty].winddir)) |
|
|
2676 | minp++; |
3017 | minp++; |
2677 | if (minp > 4) |
3018 | if (minp > 4) |
2678 | weathermap[x][y].windspeed++; |
3019 | weathermap[x][y].windspeed++; |
2679 | if (minp > 6) |
3020 | if (minp > 6) |
2680 | weathermap[x][y].windspeed += 2; |
3021 | weathermap[x][y].windspeed += 2; |
2681 | if (minp < 2) |
3022 | if (minp < 2) |
2682 | weathermap[x][y].windspeed--; |
3023 | weathermap[x][y].windspeed--; |
2683 | if (weathermap[x][y].windspeed < 0) |
3024 | if (weathermap[x][y].windspeed < 0) |
2684 | weathermap[x][y].windspeed = 0; |
3025 | weathermap[x][y].windspeed = 0; |
2685 | } |
3026 | } |
2686 | } |
3027 | } |
2687 | |
3028 | |
2688 | /* |
3029 | /* |
2689 | * Plot the gulfstream map over the wind map. This is done after the wind, |
3030 | * Plot the gulfstream map over the wind map. This is done after the wind, |
2690 | * to avoid the windsmoothing scrambling the jet stream. |
3031 | * to avoid the windsmoothing scrambling the jet stream. |
2691 | */ |
3032 | */ |
2692 | |
3033 | |
|
|
3034 | static void |
2693 | static void plot_gulfstream(void) |
3035 | plot_gulfstream (void) |
2694 | { |
3036 | { |
2695 | int x, y, tx; |
3037 | int x, y, tx; |
2696 | |
3038 | |
2697 | x = gulf_stream_start; |
3039 | x = gulf_stream_start; |
2698 | |
3040 | |
2699 | if (gulf_stream_direction) { |
3041 | if (gulf_stream_direction) |
|
|
3042 | { |
2700 | for (y=WEATHERMAPTILESY-1; y > 0; y--) { |
3043 | for (y = WEATHERMAPTILESY - 1; y > 0; y--) |
|
|
3044 | { |
2701 | for (tx=0; tx < GULF_STREAM_WIDTH && x+tx < WEATHERMAPTILESX; tx++) { |
3045 | for (tx = 0; tx < GULF_STREAM_WIDTH && x + tx < WEATHERMAPTILESX; tx++) |
|
|
3046 | { |
2702 | if (similar_direction(weathermap[x+tx][y].winddir, |
3047 | if (similar_direction (weathermap[x + tx][y].winddir, |
2703 | gulf_stream_dir[tx][y]) && |
|
|
2704 | weathermap[x+tx][y].windspeed < GULF_STREAM_BASE_SPEED-5) |
3048 | gulf_stream_dir[tx][y]) && weathermap[x + tx][y].windspeed < GULF_STREAM_BASE_SPEED - 5) |
2705 | weathermap[x+tx][y].windspeed += gulf_stream_speed[tx][y]; |
3049 | weathermap[x + tx][y].windspeed += gulf_stream_speed[tx][y]; |
2706 | else |
3050 | else |
2707 | weathermap[x+tx][y].windspeed = gulf_stream_speed[tx][y]; |
3051 | weathermap[x + tx][y].windspeed = gulf_stream_speed[tx][y]; |
2708 | weathermap[x+tx][y].winddir = gulf_stream_dir[tx][y]; |
3052 | weathermap[x + tx][y].winddir = gulf_stream_dir[tx][y]; |
2709 | if (tx == GULF_STREAM_WIDTH-1) { |
3053 | if (tx == GULF_STREAM_WIDTH - 1) |
|
|
3054 | { |
2710 | switch (gulf_stream_dir[tx][y]) { |
3055 | switch (gulf_stream_dir[tx][y]) |
|
|
3056 | { |
2711 | case 6: x--; break; |
3057 | case 6: |
|
|
3058 | x--; |
|
|
3059 | break; |
2712 | case 7: break; |
3060 | case 7: |
|
|
3061 | break; |
2713 | case 8: x++; ; break; |
3062 | case 8: |
|
|
3063 | x++;; |
|
|
3064 | break; |
2714 | } |
3065 | } |
2715 | } |
3066 | } |
2716 | if (x < 0) |
3067 | if (x < 0) |
2717 | x++; |
3068 | x++; |
2718 | if (x >= WEATHERMAPTILESX-GULF_STREAM_WIDTH) |
3069 | if (x >= WEATHERMAPTILESX - GULF_STREAM_WIDTH) |
2719 | x--; |
3070 | x--; |
2720 | } |
3071 | } |
2721 | } |
3072 | } |
2722 | } else { |
3073 | } |
|
|
3074 | else |
|
|
3075 | { |
2723 | for (y=0; y < WEATHERMAPTILESY-1; y++) { |
3076 | for (y = 0; y < WEATHERMAPTILESY - 1; y++) |
|
|
3077 | { |
2724 | for (tx=0; tx < GULF_STREAM_WIDTH && x+tx < WEATHERMAPTILESX; tx++) { |
3078 | for (tx = 0; tx < GULF_STREAM_WIDTH && x + tx < WEATHERMAPTILESX; tx++) |
|
|
3079 | { |
2725 | if (similar_direction(weathermap[x+tx][y].winddir, |
3080 | if (similar_direction (weathermap[x + tx][y].winddir, |
2726 | gulf_stream_dir[tx][y]) && |
|
|
2727 | weathermap[x+tx][y].windspeed < GULF_STREAM_BASE_SPEED-5) |
3081 | gulf_stream_dir[tx][y]) && weathermap[x + tx][y].windspeed < GULF_STREAM_BASE_SPEED - 5) |
2728 | weathermap[x+tx][y].windspeed += gulf_stream_speed[tx][y]; |
3082 | weathermap[x + tx][y].windspeed += gulf_stream_speed[tx][y]; |
2729 | else |
3083 | else |
2730 | weathermap[x+tx][y].windspeed = gulf_stream_speed[tx][y]; |
3084 | weathermap[x + tx][y].windspeed = gulf_stream_speed[tx][y]; |
2731 | weathermap[x+tx][y].winddir = gulf_stream_dir[tx][y]; |
3085 | weathermap[x + tx][y].winddir = gulf_stream_dir[tx][y]; |
2732 | if (tx == GULF_STREAM_WIDTH-1) { |
3086 | if (tx == GULF_STREAM_WIDTH - 1) |
|
|
3087 | { |
2733 | switch (gulf_stream_dir[tx][y]) { |
3088 | switch (gulf_stream_dir[tx][y]) |
|
|
3089 | { |
2734 | case 2: x++; break; |
3090 | case 2: |
|
|
3091 | x++; |
|
|
3092 | break; |
2735 | case 3: break; |
3093 | case 3: |
|
|
3094 | break; |
2736 | case 4: x--; break; |
3095 | case 4: |
|
|
3096 | x--; |
|
|
3097 | break; |
2737 | } |
3098 | } |
2738 | } |
3099 | } |
2739 | if (x < 0) |
3100 | if (x < 0) |
2740 | x++; |
3101 | x++; |
2741 | if (x >= WEATHERMAPTILESX-GULF_STREAM_WIDTH) |
3102 | if (x >= WEATHERMAPTILESX - GULF_STREAM_WIDTH) |
2742 | x--; |
3103 | x--; |
2743 | } |
3104 | } |
2744 | } |
3105 | } |
2745 | } |
3106 | } |
2746 | /* occasionally move the stream */ |
3107 | /* occasionally move the stream */ |
2747 | if (rndm(1, 500) == 1) { |
3108 | if (rndm (1, 500) == 1) |
|
|
3109 | { |
2748 | gulf_stream_direction = rndm(0, 1); |
3110 | gulf_stream_direction = rndm (0, 1); |
2749 | for (tx=0; tx < GULF_STREAM_WIDTH; tx++) |
3111 | for (tx = 0; tx < GULF_STREAM_WIDTH; tx++) |
2750 | for (y=0; y < WEATHERMAPTILESY-1; y++) |
3112 | for (y = 0; y < WEATHERMAPTILESY - 1; y++) |
2751 | if (gulf_stream_direction) |
3113 | if (gulf_stream_direction) |
2752 | switch (gulf_stream_dir[tx][y]) { |
3114 | switch (gulf_stream_dir[tx][y]) |
|
|
3115 | { |
|
|
3116 | case 2: |
2753 | case 2: gulf_stream_dir[tx][y] = 6; break; |
3117 | gulf_stream_dir[tx][y] = 6; |
|
|
3118 | break; |
|
|
3119 | case 3: |
2754 | case 3: gulf_stream_dir[tx][y] = 7; break; |
3120 | gulf_stream_dir[tx][y] = 7; |
|
|
3121 | break; |
|
|
3122 | case 4: |
2755 | case 4: gulf_stream_dir[tx][y] = 8; break; |
3123 | gulf_stream_dir[tx][y] = 8; |
2756 | } |
3124 | break; |
|
|
3125 | } |
2757 | else |
3126 | else |
2758 | switch (gulf_stream_dir[tx][y]) { |
3127 | switch (gulf_stream_dir[tx][y]) |
|
|
3128 | { |
|
|
3129 | case 6: |
2759 | case 6: gulf_stream_dir[tx][y] = 2; break; |
3130 | gulf_stream_dir[tx][y] = 2; |
|
|
3131 | break; |
|
|
3132 | case 7: |
2760 | case 7: gulf_stream_dir[tx][y] = 3; break; |
3133 | gulf_stream_dir[tx][y] = 3; |
|
|
3134 | break; |
|
|
3135 | case 8: |
2761 | case 8: gulf_stream_dir[tx][y] = 4; break; |
3136 | gulf_stream_dir[tx][y] = 4; |
2762 | } |
3137 | break; |
|
|
3138 | } |
2763 | } |
3139 | } |
2764 | if (rndm(1, 25) == 1) |
3140 | if (rndm (1, 25) == 1) |
2765 | gulf_stream_start += rndm(-1, 1); |
3141 | gulf_stream_start += rndm (-1, 1); |
2766 | if (gulf_stream_start >= WEATHERMAPTILESX-GULF_STREAM_WIDTH) |
3142 | if (gulf_stream_start >= WEATHERMAPTILESX - GULF_STREAM_WIDTH) |
2767 | gulf_stream_start--; |
3143 | gulf_stream_start--; |
2768 | if (gulf_stream_start < 1) |
3144 | if (gulf_stream_start < 1) |
2769 | gulf_stream_start++; |
3145 | gulf_stream_start++; |
2770 | |
3146 | |
2771 | } |
3147 | } |
2772 | |
3148 | |
2773 | /* |
3149 | /* |
2774 | * let the madness, begin. |
3150 | * let the madness, begin. |
… | |
… | |
2777 | * over all the weathermaps, and compare the various conditions we have |
3153 | * over all the weathermaps, and compare the various conditions we have |
2778 | * calculated up to now, to figure out what the sky conditions are for this |
3154 | * calculated up to now, to figure out what the sky conditions are for this |
2779 | * square. |
3155 | * square. |
2780 | */ |
3156 | */ |
2781 | |
3157 | |
2782 | static void compute_sky(void) |
3158 | static void |
|
|
3159 | compute_sky (void) |
2783 | { |
3160 | { |
2784 | int x, y; |
3161 | int x, y; |
2785 | int temp; |
3162 | int temp; |
2786 | |
3163 | |
2787 | for (x=0; x < WEATHERMAPTILESX; x++) { |
3164 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
3165 | { |
2788 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3166 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3167 | { |
2789 | temp = real_temperature(x, y); |
3168 | temp = real_temperature (x, y); |
2790 | if (weathermap[x][y].pressure < 980) { |
3169 | if (weathermap[x][y].pressure < 980) |
|
|
3170 | { |
2791 | if (weathermap[x][y].humid < 20) |
3171 | if (weathermap[x][y].humid < 20) |
2792 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
3172 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
2793 | else if (weathermap[x][y].humid < 30) |
3173 | else if (weathermap[x][y].humid < 30) |
2794 | weathermap[x][y].sky = SKY_OVERCAST; |
3174 | weathermap[x][y].sky = SKY_OVERCAST; |
2795 | else if (weathermap[x][y].humid < 40) |
3175 | else if (weathermap[x][y].humid < 40) |
2796 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
3176 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
2797 | else if (weathermap[x][y].humid < 55) |
3177 | else if (weathermap[x][y].humid < 55) |
2798 | weathermap[x][y].sky = SKY_RAIN; |
3178 | weathermap[x][y].sky = SKY_RAIN; |
2799 | else if (weathermap[x][y].humid < 70) |
3179 | else if (weathermap[x][y].humid < 70) |
2800 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
3180 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
2801 | else |
3181 | else |
2802 | weathermap[x][y].sky = SKY_HURRICANE; |
3182 | weathermap[x][y].sky = SKY_HURRICANE; |
2803 | if (weathermap[x][y].sky < SKY_HURRICANE && |
3183 | if (weathermap[x][y].sky < SKY_HURRICANE && weathermap[x][y].windspeed > 30) |
2804 | weathermap[x][y].windspeed > 30) |
|
|
2805 | weathermap[x][y].sky++; |
3184 | weathermap[x][y].sky++; |
2806 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
3185 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
2807 | weathermap[x][y].sky += 10; /*let it snow*/ |
3186 | weathermap[x][y].sky += 10; /*let it snow */ |
|
|
3187 | } |
2808 | } else if (weathermap[x][y].pressure < 1000) { |
3188 | else if (weathermap[x][y].pressure < 1000) |
|
|
3189 | { |
2809 | if (weathermap[x][y].humid < 10) |
3190 | if (weathermap[x][y].humid < 10) |
2810 | weathermap[x][y].sky = SKY_CLEAR; |
3191 | weathermap[x][y].sky = SKY_CLEAR; |
2811 | else if (weathermap[x][y].humid < 25) |
3192 | else if (weathermap[x][y].humid < 25) |
2812 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
3193 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
2813 | else if (weathermap[x][y].humid < 45) |
3194 | else if (weathermap[x][y].humid < 45) |
2814 | weathermap[x][y].sky = SKY_OVERCAST; |
3195 | weathermap[x][y].sky = SKY_OVERCAST; |
2815 | else if (weathermap[x][y].humid < 60) |
3196 | else if (weathermap[x][y].humid < 60) |
2816 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
3197 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
2817 | else if (weathermap[x][y].humid < 75) |
3198 | else if (weathermap[x][y].humid < 75) |
2818 | weathermap[x][y].sky = SKY_RAIN; |
3199 | weathermap[x][y].sky = SKY_RAIN; |
2819 | else |
3200 | else |
2820 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
3201 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
2821 | if (weathermap[x][y].sky < SKY_HURRICANE && |
3202 | if (weathermap[x][y].sky < SKY_HURRICANE && weathermap[x][y].windspeed > 30) |
2822 | weathermap[x][y].windspeed > 30) |
|
|
2823 | weathermap[x][y].sky++; |
3203 | weathermap[x][y].sky++; |
2824 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
3204 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
2825 | weathermap[x][y].sky += 10; /*let it snow*/ |
3205 | weathermap[x][y].sky += 10; /*let it snow */ |
2826 | if (temp > 0 && temp < 5 && weathermap[x][y].humid > 95 && |
3206 | if (temp > 0 && temp < 5 && weathermap[x][y].humid > 95 && weathermap[x][y].windspeed < 3) |
2827 | weathermap[x][y].windspeed < 3) |
|
|
2828 | weathermap[x][y].sky = SKY_FOG; /* rare */ |
3207 | weathermap[x][y].sky = SKY_FOG; /* rare */ |
2829 | if (temp > 0 && temp < 5 && weathermap[x][y].humid > 70 && |
3208 | if (temp > 0 && temp < 5 && weathermap[x][y].humid > 70 && weathermap[x][y].windspeed > 35) |
2830 | weathermap[x][y].windspeed > 35) |
|
|
2831 | weathermap[x][y].sky = SKY_HAIL; /* rare */ |
3209 | weathermap[x][y].sky = SKY_HAIL; /* rare */ |
|
|
3210 | } |
2832 | } else if (weathermap[x][y].pressure < 1020) { |
3211 | else if (weathermap[x][y].pressure < 1020) |
|
|
3212 | { |
2833 | if (weathermap[x][y].humid < 20) |
3213 | if (weathermap[x][y].humid < 20) |
2834 | weathermap[x][y].sky = SKY_CLEAR; |
3214 | weathermap[x][y].sky = SKY_CLEAR; |
2835 | else if (weathermap[x][y].humid < 30) |
3215 | else if (weathermap[x][y].humid < 30) |
2836 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
3216 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
2837 | else if (weathermap[x][y].humid < 40) |
3217 | else if (weathermap[x][y].humid < 40) |
2838 | weathermap[x][y].sky = SKY_OVERCAST; |
3218 | weathermap[x][y].sky = SKY_OVERCAST; |
2839 | else if (weathermap[x][y].humid < 55) |
3219 | else if (weathermap[x][y].humid < 55) |
2840 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
3220 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
2841 | else if (weathermap[x][y].humid < 70) |
3221 | else if (weathermap[x][y].humid < 70) |
2842 | weathermap[x][y].sky = SKY_RAIN; |
3222 | weathermap[x][y].sky = SKY_RAIN; |
2843 | else |
3223 | else |
2844 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
3224 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
2845 | if (weathermap[x][y].sky < SKY_HURRICANE && |
3225 | if (weathermap[x][y].sky < SKY_HURRICANE && weathermap[x][y].windspeed > 30) |
2846 | weathermap[x][y].windspeed > 30) |
|
|
2847 | weathermap[x][y].sky++; |
3226 | weathermap[x][y].sky++; |
2848 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
3227 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
2849 | weathermap[x][y].sky += 10; /*let it snow*/ |
3228 | weathermap[x][y].sky += 10; /*let it snow */ |
|
|
3229 | } |
2850 | } else { |
3230 | else |
|
|
3231 | { |
2851 | if (weathermap[x][y].humid < 35) |
3232 | if (weathermap[x][y].humid < 35) |
2852 | weathermap[x][y].sky = SKY_CLEAR; |
3233 | weathermap[x][y].sky = SKY_CLEAR; |
2853 | else if (weathermap[x][y].humid < 55) |
3234 | else if (weathermap[x][y].humid < 55) |
2854 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
3235 | weathermap[x][y].sky = SKY_LIGHTCLOUD; |
2855 | else if (weathermap[x][y].humid < 70) |
3236 | else if (weathermap[x][y].humid < 70) |
2856 | weathermap[x][y].sky = SKY_OVERCAST; |
3237 | weathermap[x][y].sky = SKY_OVERCAST; |
2857 | else if (weathermap[x][y].humid < 85) |
3238 | else if (weathermap[x][y].humid < 85) |
2858 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
3239 | weathermap[x][y].sky = SKY_LIGHT_RAIN; |
2859 | else if (weathermap[x][y].humid < 95) |
3240 | else if (weathermap[x][y].humid < 95) |
2860 | weathermap[x][y].sky = SKY_RAIN; |
3241 | weathermap[x][y].sky = SKY_RAIN; |
2861 | else |
3242 | else |
2862 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
3243 | weathermap[x][y].sky = SKY_HEAVY_RAIN; |
2863 | if (weathermap[x][y].sky < SKY_HURRICANE && |
3244 | if (weathermap[x][y].sky < SKY_HURRICANE && weathermap[x][y].windspeed > 30) |
2864 | weathermap[x][y].windspeed > 30) |
|
|
2865 | weathermap[x][y].sky++; |
3245 | weathermap[x][y].sky++; |
2866 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
3246 | if (temp <= 0 && weathermap[x][y].sky > SKY_OVERCAST) |
2867 | weathermap[x][y].sky += 10; /*let it snow*/ |
3247 | weathermap[x][y].sky += 10; /*let it snow */ |
2868 | } |
3248 | } |
2869 | } |
3249 | } |
2870 | } |
3250 | } |
2871 | } |
3251 | } |
2872 | |
3252 | |
2873 | /* |
3253 | /* |
2874 | * Keep track of how much rain has fallen in a given weathermap square. |
3254 | * Keep track of how much rain has fallen in a given weathermap square. |
2875 | */ |
3255 | */ |
2876 | |
3256 | |
2877 | static void process_rain(void) |
3257 | static void |
|
|
3258 | process_rain (void) |
2878 | { |
3259 | { |
2879 | int x, y, rain; |
3260 | int x, y, rain; |
2880 | |
3261 | |
2881 | for (x=0; x < WEATHERMAPTILESX; x++) |
3262 | for (x = 0; x < WEATHERMAPTILESX; x++) |
2882 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3263 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3264 | { |
2883 | rain = weathermap[x][y].sky; |
3265 | rain = weathermap[x][y].sky; |
2884 | if (rain >= SKY_LIGHT_SNOW) |
3266 | if (rain >= SKY_LIGHT_SNOW) |
2885 | rain -= 10; |
3267 | rain -= 10; |
2886 | if (rain > SKY_OVERCAST && rain < SKY_FOG) { |
3268 | if (rain > SKY_OVERCAST && rain < SKY_FOG) |
|
|
3269 | { |
2887 | rain -= SKY_OVERCAST; |
3270 | rain -= SKY_OVERCAST; |
2888 | weathermap[x][y].rainfall += rain; |
3271 | weathermap[x][y].rainfall += rain; |
2889 | } |
3272 | } |
2890 | } |
3273 | } |
2891 | } |
3274 | } |
2892 | |
3275 | |
2893 | /* |
3276 | /* |
2894 | * The world spinning drags the weather with it. |
3277 | * The world spinning drags the weather with it. |
2895 | * The equator is diagonal, and the poles are 45 degrees from north /south. |
3278 | * The equator is diagonal, and the poles are 45 degrees from north /south. |
2896 | * What the hell, lets spin the planet backwards. |
3279 | * What the hell, lets spin the planet backwards. |
2897 | */ |
3280 | */ |
2898 | |
3281 | |
2899 | static void spin_globe(void) |
3282 | static void |
|
|
3283 | spin_globe (void) |
2900 | { |
3284 | { |
2901 | int x, y; |
3285 | int x, y; |
2902 | int buffer_humid; |
3286 | int buffer_humid; |
2903 | int buffer_sky; |
3287 | int buffer_sky; |
2904 | |
3288 | |
2905 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3289 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3290 | { |
2906 | buffer_humid = weathermap[0][y].humid; |
3291 | buffer_humid = weathermap[0][y].humid; |
2907 | buffer_sky = weathermap[0][y].sky; |
3292 | buffer_sky = weathermap[0][y].sky; |
2908 | for (x=0; x < (WEATHERMAPTILESX - 1); x++) { |
3293 | for (x = 0; x < (WEATHERMAPTILESX - 1); x++) |
|
|
3294 | { |
2909 | weathermap[x][y].humid = weathermap[x + 1][y].humid; |
3295 | weathermap[x][y].humid = weathermap[x + 1][y].humid; |
2910 | weathermap[x][y].sky = weathermap[x + 1][y].sky; |
3296 | weathermap[x][y].sky = weathermap[x + 1][y].sky; |
2911 | } |
|
|
2912 | weathermap[WEATHERMAPTILESX - 1][y].humid = buffer_humid; |
|
|
2913 | weathermap[WEATHERMAPTILESX - 1][y].sky = buffer_sky; |
|
|
2914 | } |
3297 | } |
|
|
3298 | weathermap[WEATHERMAPTILESX - 1][y].humid = buffer_humid; |
|
|
3299 | weathermap[WEATHERMAPTILESX - 1][y].sky = buffer_sky; |
|
|
3300 | } |
2915 | } |
3301 | } |
2916 | |
3302 | |
2917 | /* |
3303 | /* |
2918 | * Dump all the weather data as an image. |
3304 | * Dump all the weather data as an image. |
2919 | * Writes two other files that are useful for creating animations and web pages. |
3305 | * Writes two other files that are useful for creating animations and web pages. |
2920 | */ |
3306 | */ |
2921 | |
3307 | |
|
|
3308 | static void |
2922 | static void write_weather_images(void) |
3309 | write_weather_images (void) |
2923 | { |
3310 | { |
2924 | char filename[MAX_BUF]; |
3311 | char filename[MAX_BUF]; |
2925 | FILE *fp; |
3312 | FILE *fp; |
2926 | int x, y; |
3313 | int x, y; |
2927 | sint32 min[10], max[10], realmaxwind; |
3314 | sint32 min[10], max[10], realmaxwind; |
2928 | uint32 avgrain, avgwind; |
3315 | uint32 avgrain, avgwind; |
2929 | double scale[10], realscalewind; |
3316 | double scale[10], realscalewind; |
2930 | uint8 pixels[3 * 3 * WEATHERMAPTILESX]; |
3317 | uint8 pixels[3 * 3 * WEATHERMAPTILESX]; |
2931 | sint64 total_rainfall = 0; |
3318 | sint64 total_rainfall = 0; |
2932 | sint64 total_wind = 0; |
3319 | sint64 total_wind = 0; |
2933 | |
3320 | |
2934 | min[0] = 0; max[0] = 100; |
3321 | min[0] = 0; |
2935 | min[1] = 0; max[1] = 0; |
3322 | max[0] = 100; |
2936 | min[2] = 0; max[2] = 0; |
3323 | min[1] = 0; |
2937 | min[3] = PRESSURE_MIN; max[3] = PRESSURE_MAX; |
3324 | max[1] = 0; |
2938 | min[4] = 0; max[4] = 0; |
3325 | min[2] = 0; |
2939 | min[5] = 1; max[5] = 8; |
3326 | max[2] = 0; |
2940 | min[6] = 0; max[6] = 100; |
3327 | min[3] = PRESSURE_MIN; |
2941 | min[7] = -45; max[7] = 45; |
3328 | max[3] = PRESSURE_MAX; |
2942 | min[8] = 0; max[8] = 16; |
3329 | min[4] = 0; |
2943 | min[9] = 0; max[9] = 0; |
3330 | max[4] = 0; |
|
|
3331 | min[5] = 1; |
|
|
3332 | max[5] = 8; |
|
|
3333 | min[6] = 0; |
|
|
3334 | max[6] = 100; |
|
|
3335 | min[7] = -45; |
|
|
3336 | max[7] = 45; |
|
|
3337 | min[8] = 0; |
|
|
3338 | max[8] = 16; |
|
|
3339 | min[9] = 0; |
|
|
3340 | max[9] = 0; |
2944 | for (x=0; x < WEATHERMAPTILESX; x++) { |
3341 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
3342 | { |
2945 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3343 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3344 | { |
|
|
3345 | |
2946 | /* min[0] = MIN(min[0], weathermap[x][y].water); */ |
3346 | /* min[0] = MIN(min[0], weathermap[x][y].water); */ |
2947 | min[1] = MIN(min[1], weathermap[x][y].avgelev); |
3347 | min[1] = MIN (min[1], weathermap[x][y].avgelev); |
2948 | min[2] = MIN((uint32) min[2], weathermap[x][y].rainfall); |
3348 | min[2] = MIN ((uint32) min[2], weathermap[x][y].rainfall); |
|
|
3349 | |
2949 | /* min[3] = MIN(min[3], weathermap[x][y].pressure); */ |
3350 | /* min[3] = MIN(min[3], weathermap[x][y].pressure); */ |
2950 | min[4] = MIN(min[4], weathermap[x][y].windspeed); |
3351 | min[4] = MIN (min[4], weathermap[x][y].windspeed); |
|
|
3352 | |
2951 | /* min[5] = MIN(min[5], weathermap[x][y].winddir); */ |
3353 | /* min[5] = MIN(min[5], weathermap[x][y].winddir); */ |
|
|
3354 | |
2952 | /* min[6] = MIN(min[6], weathermap[x][y].humid); */ |
3355 | /* min[6] = MIN(min[6], weathermap[x][y].humid); */ |
|
|
3356 | |
2953 | /* min[7] = MIN(min[7], real_temp[x][y]); */ |
3357 | /* min[7] = MIN(min[7], real_temp[x][y]); */ |
|
|
3358 | |
2954 | /* min[8] = MIN(min[8], weathermap[x][y].sky); */ |
3359 | /* min[8] = MIN(min[8], weathermap[x][y].sky); */ |
|
|
3360 | |
2955 | /* min[9] = MIN(min[9], weathermap[x][y].darkness); */ |
3361 | /* min[9] = MIN(min[9], weathermap[x][y].darkness); */ |
2956 | |
3362 | |
2957 | /* max[0] = MAX(max[0], weathermap[x][y].water); */ |
3363 | /* max[0] = MAX(max[0], weathermap[x][y].water); */ |
2958 | max[1] = MAX(max[1], weathermap[x][y].avgelev); |
3364 | max[1] = MAX (max[1], weathermap[x][y].avgelev); |
2959 | max[2] = MAX((uint32) max[2], weathermap[x][y].rainfall); |
3365 | max[2] = MAX ((uint32) max[2], weathermap[x][y].rainfall); |
|
|
3366 | |
2960 | /* max[3] = MAX(max[3], weathermap[x][y].pressure); */ |
3367 | /* max[3] = MAX(max[3], weathermap[x][y].pressure); */ |
2961 | max[4] = MAX(max[4], weathermap[x][y].windspeed); |
3368 | max[4] = MAX (max[4], weathermap[x][y].windspeed); |
|
|
3369 | |
2962 | /* max[5] = MAX(max[5], weathermap[x][y].winddir); */ |
3370 | /* max[5] = MAX(max[5], weathermap[x][y].winddir); */ |
|
|
3371 | |
2963 | /* max[6] = MAX(max[6], weathermap[x][y].humid); */ |
3372 | /* max[6] = MAX(max[6], weathermap[x][y].humid); */ |
|
|
3373 | |
2964 | /* max[7] = MAX(max[7], real_temp[x][y]); */ |
3374 | /* max[7] = MAX(max[7], real_temp[x][y]); */ |
|
|
3375 | |
2965 | /* max[8] = MAX(max[8], weathermap[x][y].sky); */ |
3376 | /* max[8] = MAX(max[8], weathermap[x][y].sky); */ |
|
|
3377 | |
2966 | /* max[9] = MAX(max[9], weathermap[x][y].darkness); */ |
3378 | /* max[9] = MAX(max[9], weathermap[x][y].darkness); */ |
2967 | total_rainfall += weathermap[x][y].rainfall; |
3379 | total_rainfall += weathermap[x][y].rainfall; |
2968 | total_wind += weathermap[x][y].windspeed; |
3380 | total_wind += weathermap[x][y].windspeed; |
2969 | } |
3381 | } |
2970 | } |
3382 | } |
2971 | avgrain = total_rainfall / (WEATHERMAPTILESX * WEATHERMAPTILESY); |
3383 | avgrain = total_rainfall / (WEATHERMAPTILESX * WEATHERMAPTILESY); |
2972 | avgwind = (total_wind / ((WEATHERMAPTILESX * WEATHERMAPTILESY) * 3 / 2)); |
3384 | avgwind = (total_wind / ((WEATHERMAPTILESX * WEATHERMAPTILESY) * 3 / 2)); |
2973 | max[2] = avgrain - 1; |
3385 | max[2] = avgrain - 1; |
2974 | realscalewind = 255.0l / (max[4] - min[4]); |
3386 | realscalewind = 255.0l / (max[4] - min[4]); |
2975 | realmaxwind = max[4]; |
3387 | realmaxwind = max[4]; |
2976 | max[4] = avgwind - 1; |
3388 | max[4] = avgwind - 1; |
2977 | for (x=0; x < 10; x++) |
3389 | for (x = 0; x < 10; x++) |
2978 | scale[x] = 255.0l / (max[x] - min[x]); |
3390 | scale[x] = 255.0l / (max[x] - min[x]); |
2979 | |
3391 | |
2980 | sprintf(filename, "%s/weather.ppm", settings.localdir); |
3392 | sprintf (filename, "%s/weather.ppm", settings.localdir); |
2981 | if ((fp = fopen(filename, "w")) == NULL) { |
3393 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
3394 | { |
2982 | LOG(llevError, "Cannot open %s for writing\n", filename); |
3395 | LOG (llevError, "Cannot open %s for writing\n", filename); |
2983 | return; |
3396 | return; |
2984 | } |
3397 | } |
2985 | fprintf(fp, "P6\n%d %d\n", 3 * WEATHERMAPTILESX, 3 * WEATHERMAPTILESY); |
3398 | fprintf (fp, "P6\n%d %d\n", 3 * WEATHERMAPTILESX, 3 * WEATHERMAPTILESY); |
2986 | fprintf(fp, "255\n"); |
3399 | fprintf (fp, "255\n"); |
2987 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3400 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3401 | { |
2988 | for (x=0; x < (3 * 3 * WEATHERMAPTILESX); x++) |
3402 | for (x = 0; x < (3 * 3 * WEATHERMAPTILESX); x++) |
2989 | pixels[x] = 0; |
3403 | pixels[x] = 0; |
2990 | for (x=0; x < WEATHERMAPTILESX; x++) { |
3404 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
3405 | { |
2991 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].water - min[0]) * scale[0]); |
3406 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].water - min[0]) * scale[0]); |
2992 | if (weathermap[x][y].avgelev >= 0) |
3407 | if (weathermap[x][y].avgelev >= 0) |
2993 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + GREEN)] = (uint8) ((weathermap[x][y].avgelev - min[1]) * scale[1]); |
3408 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + GREEN)] = (uint8) ((weathermap[x][y].avgelev - min[1]) * scale[1]); |
2994 | else |
3409 | else |
2995 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].avgelev - min[1]) * scale[1]); |
3410 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].avgelev - min[1]) * scale[1]); |
2996 | if (weathermap[x][y].rainfall >= avgrain) /* rainfall is rather spikey, this gives us more detail. */ |
3411 | if (weathermap[x][y].rainfall >= avgrain) /* rainfall is rather spikey, this gives us more detail. */ |
2997 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + RED)] = 255; |
3412 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + RED)] = 255; |
2998 | else |
3413 | else |
2999 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].rainfall - min[2]) * scale[2]); |
3414 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].rainfall - min[2]) * scale[2]); |
3000 | } |
3415 | } |
3001 | fwrite(pixels, sizeof(uint8), (3 * 3 * WEATHERMAPTILESX), fp); |
3416 | fwrite (pixels, sizeof (uint8), (3 * 3 * WEATHERMAPTILESX), fp); |
3002 | } |
3417 | } |
3003 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3418 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3419 | { |
3004 | for (x=0; x < WEATHERMAPTILESX; x++) { |
3420 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
3421 | { |
3005 | uint32 dir = directions[weathermap[x][y].winddir - 1]; |
3422 | uint32 dir = directions[weathermap[x][y].winddir - 1]; |
3006 | uint32 speed = weathermap[x][y].windspeed; |
3423 | uint32 speed = weathermap[x][y].windspeed; |
3007 | uint8 pressure = (uint8) ((weathermap[x][y].pressure - min[3]) * scale[3]); |
3424 | uint8 pressure = (uint8) ((weathermap[x][y].pressure - min[3]) * scale[3]); |
|
|
3425 | |
3008 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + RED)] = pressure; |
3426 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + RED)] = pressure; |
3009 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + GREEN)] = pressure; |
3427 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + GREEN)] = pressure; |
3010 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + BLUE)] = pressure; |
3428 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + BLUE)] = pressure; |
3011 | if (speed < avgwind) { |
3429 | if (speed < avgwind) |
|
|
3430 | { |
3012 | speed = (uint32) ((speed - min[4]) * scale[4]); |
3431 | speed = (uint32) ((speed - min[4]) * scale[4]); |
3013 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = speed; |
3432 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = speed; |
3014 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + GREEN)] = speed; |
3433 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + GREEN)] = speed; |
3015 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + BLUE)] = speed; |
3434 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + BLUE)] = speed; |
|
|
3435 | } |
3016 | } else { |
3436 | else |
|
|
3437 | { |
3017 | speed = (uint32) ((speed - realmaxwind) * realscalewind); |
3438 | speed = (uint32) ((speed - realmaxwind) * realscalewind); |
|
|
3439 | |
3018 | /* if (speed < 100)*/ |
3440 | /* if (speed < 100)*/ |
|
|
3441 | |
3019 | /* speed = 100;*/ |
3442 | /* speed = 100;*/ |
3020 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = speed; |
3443 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = speed; |
3021 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + GREEN)] = 0; |
3444 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + GREEN)] = 0; |
3022 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + BLUE)] = 0; |
3445 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + BLUE)] = 0; |
3023 | } |
3446 | } |
3024 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + RED)] = (uint8) ((dir & 0x00FF0000) >> 16); |
3447 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + RED)] = (uint8) ((dir & 0x00FF0000) >> 16); |
3025 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + GREEN)] = (uint8) ((dir & 0x0000FF00) >> 8); |
3448 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + GREEN)] = (uint8) ((dir & 0x0000FF00) >> 8); |
3026 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((dir & 0x000000FF)); |
3449 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((dir & 0x000000FF)); |
3027 | } |
3450 | } |
3028 | fwrite(pixels, sizeof(uint8), (3 * 3 * WEATHERMAPTILESX), fp); |
3451 | fwrite (pixels, sizeof (uint8), (3 * 3 * WEATHERMAPTILESX), fp); |
3029 | } |
3452 | } |
3030 | for (y=0; y < WEATHERMAPTILESY; y++) { |
3453 | for (y = 0; y < WEATHERMAPTILESY; y++) |
|
|
3454 | { |
3031 | for (x=0; x < (3 * 3 * WEATHERMAPTILESX); x++) |
3455 | for (x = 0; x < (3 * 3 * WEATHERMAPTILESX); x++) |
3032 | pixels[x] = 0; |
3456 | pixels[x] = 0; |
3033 | for (x=0; x < WEATHERMAPTILESX; x++) { |
3457 | for (x = 0; x < WEATHERMAPTILESX; x++) |
|
|
3458 | { |
3034 | uint32 dir = skies[weathermap[x][y].sky]; |
3459 | uint32 dir = skies[weathermap[x][y].sky]; |
|
|
3460 | |
3035 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].humid - min[6]) * scale[6]); |
3461 | pixels[3 * x + (0 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((weathermap[x][y].humid - min[6]) * scale[6]); |
3036 | /*pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = (uint8) ((real_temp[x][y] - min[7]) * scale[7]);*/ |
3462 | /*pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = (uint8) ((real_temp[x][y] - min[7]) * scale[7]); */ |
3037 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = 1; |
3463 | pixels[3 * x + (1 * WEATHERMAPTILESX * 3 + RED)] = 1; |
3038 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + RED)] = (uint8) ((dir & 0x00FF0000) >> 16); |
3464 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + RED)] = (uint8) ((dir & 0x00FF0000) >> 16); |
3039 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + GREEN)] = (uint8) ((dir & 0x0000FF00) >> 8); |
3465 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + GREEN)] = (uint8) ((dir & 0x0000FF00) >> 8); |
3040 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((dir & 0x000000FF)); |
3466 | pixels[3 * x + (2 * WEATHERMAPTILESX * 3 + BLUE)] = (uint8) ((dir & 0x000000FF)); |
3041 | |
3467 | |
3042 | } |
3468 | } |
3043 | fwrite(pixels, sizeof(uint8), (3 * 3 * WEATHERMAPTILESX), fp); |
3469 | fwrite (pixels, sizeof (uint8), (3 * 3 * WEATHERMAPTILESX), fp); |
3044 | } |
3470 | } |
3045 | fclose(fp); |
3471 | fclose (fp); |
3046 | |
3472 | |
3047 | sprintf(filename, "%s/todtick", settings.localdir); |
3473 | sprintf (filename, "%s/todtick", settings.localdir); |
3048 | if ((fp = fopen(filename, "w")) == NULL) { |
3474 | if ((fp = fopen (filename, "w")) == NULL) |
|
|
3475 | { |
3049 | LOG(llevError, "Cannot open %s for writing\n", filename); |
3476 | LOG (llevError, "Cannot open %s for writing\n", filename); |
3050 | return; |
3477 | return; |
3051 | } |
3478 | } |
3052 | fprintf(fp, "%lu", todtick); |
3479 | fprintf (fp, "%lu", todtick); |
3053 | fclose(fp); |
3480 | fclose (fp); |
3054 | } |
3481 | } |