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