1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
4 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | 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 |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
21 | * |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <random_map.h> |
26 | #include <random_map.h> |
27 | #include <dirent.h> |
27 | #include <dirent.h> |
28 | #include <sys/stat.h> |
28 | #include <sys/stat.h> |
… | |
… | |
111 | |
111 | |
112 | /* is what we were given a directory, or a file? */ |
112 | /* is what we were given a directory, or a file? */ |
113 | sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path); |
113 | sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path); |
114 | |
114 | |
115 | if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode)) |
115 | if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode)) |
116 | style_map = maptile::load_map_sync (style_file_path); |
116 | style_map = maptile::find_sync (style_file_path); |
117 | |
117 | |
118 | if (!style_map) /* maybe we were given a directory! */ |
118 | if (!style_map) /* maybe we were given a directory! */ |
119 | { |
119 | { |
120 | char **namelist; |
120 | char **namelist; |
121 | int n; |
121 | int n; |
… | |
… | |
149 | style_map = 0; |
149 | style_map = 0; |
150 | else |
150 | else |
151 | { |
151 | { |
152 | strcat (style_file_path, "/"); |
152 | strcat (style_file_path, "/"); |
153 | strcat (style_file_path, namelist[RANDOM () % n]); |
153 | strcat (style_file_path, namelist[RANDOM () % n]); |
154 | style_map = maptile::load_map_sync (style_file_path); |
154 | style_map = maptile::find_sync (style_file_path); |
155 | } |
155 | } |
156 | } |
156 | } |
157 | else |
157 | else |
158 | { /* find the map closest in difficulty */ |
158 | { /* find the map closest in difficulty */ |
159 | int min_dist = 32000, min_index = -1; |
159 | int min_dist = 32000, min_index = -1; |
… | |
… | |
187 | |
187 | |
188 | /* presumably now we've found the "best" match for the |
188 | /* presumably now we've found the "best" match for the |
189 | difficulty. */ |
189 | difficulty. */ |
190 | strcat (style_file_path, "/"); |
190 | strcat (style_file_path, "/"); |
191 | strcat (style_file_path, namelist[min_index]); |
191 | strcat (style_file_path, namelist[min_index]); |
192 | style_map = maptile::load_map_sync (style_file_path); |
192 | style_map = maptile::find_sync (style_file_path); |
193 | } |
193 | } |
194 | |
194 | |
195 | for (i = 0; i < n; i++) |
195 | for (i = 0; i < n; i++) |
196 | free (namelist[i]); |
196 | free (namelist[i]); |
197 | |
197 | |
198 | free (namelist); |
198 | free (namelist); |
199 | } |
199 | } |
200 | |
200 | |
201 | if (style_map) |
201 | if (style_map) |
|
|
202 | { |
|
|
203 | style_map->load_sync (); |
202 | style_map->deactivate (); |
204 | style_map->deactivate (); |
|
|
205 | } |
203 | |
206 | |
204 | return style_map; |
207 | return style_map; |
205 | |
208 | |
206 | } |
209 | } |
207 | |
210 | |