ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/style.C
(Generate patch)

Comparing deliantra/server/random_maps/style.C (file contents):
Revision 1.16 by root, Sun Dec 31 18:13:27 2006 UTC vs.
Revision 1.20 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1
1/* 2/*
2 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
3 4
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 6 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 7 Copyright (C) 1992 Frank Tore Johansen
6 8
7 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
94} 96}
95 97
96maptile * 98maptile *
97find_style (const char *dirname, const char *stylename, int difficulty) 99find_style (const char *dirname, const char *stylename, int difficulty)
98{ 100{
99 char style_file_path[256]; 101 char style_file_path[1024];
100 char style_file_full_path[256]; 102 char style_file_full_path[1024];
101 maptile *style_map = NULL; 103 maptile *style_map = NULL;
102 struct stat file_stat; 104 struct stat file_stat;
103 int i, only_subdirs = 0; 105 int i, only_subdirs = 0;
104 106
105 /* if stylename exists, set style_file_path to that file. */ 107 /* if stylename exists, set style_file_path to that file. */
110 112
111 /* is what we were given a directory, or a file? */ 113 /* is what we were given a directory, or a file? */
112 sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path); 114 sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path);
113 115
114 if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode)) 116 if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode))
115 style_map = maptile::load_map_sync (style_file_path); 117 style_map = maptile::find_sync (style_file_path);
116 118
117 if (!style_map) /* maybe we were given a directory! */ 119 if (!style_map) /* maybe we were given a directory! */
118 { 120 {
119 char **namelist; 121 char **namelist;
120 int n; 122 int n;
121 char style_dir_full_path[256]; 123 char style_dir_full_path[256];
122 124
148 style_map = 0; 150 style_map = 0;
149 else 151 else
150 { 152 {
151 strcat (style_file_path, "/"); 153 strcat (style_file_path, "/");
152 strcat (style_file_path, namelist[RANDOM () % n]); 154 strcat (style_file_path, namelist[RANDOM () % n]);
153 style_map = maptile::load_map_sync (style_file_path); 155 style_map = maptile::find_sync (style_file_path);
154 } 156 }
155 } 157 }
156 else 158 else
157 { /* find the map closest in difficulty */ 159 { /* find the map closest in difficulty */
158 int min_dist = 32000, min_index = -1; 160 int min_dist = 32000, min_index = -1;
186 188
187 /* presumably now we've found the "best" match for the 189 /* presumably now we've found the "best" match for the
188 difficulty. */ 190 difficulty. */
189 strcat (style_file_path, "/"); 191 strcat (style_file_path, "/");
190 strcat (style_file_path, namelist[min_index]); 192 strcat (style_file_path, namelist[min_index]);
191 style_map = maptile::load_map_sync (style_file_path); 193 style_map = maptile::find_sync (style_file_path);
192 } 194 }
193 195
194 for (i = 0; i < n; i++) 196 for (i = 0; i < n; i++)
195 free (namelist[i]); 197 free (namelist[i]);
196 198
197 free (namelist); 199 free (namelist);
198 } 200 }
199 201
200 if (style_map) 202 if (style_map)
203 {
204 style_map->load_sync ();
201 style_map->deactivate (); 205 style_map->deactivate ();
206 }
202 207
203 return style_map; 208 return style_map;
204 209
205} 210}
206 211
215 * is actually preferable to an infinite loop. That is because 220 * is actually preferable to an infinite loop. That is because
216 * most servers will automatically restart in case of crash. 221 * most servers will automatically restart in case of crash.
217 * Change the logic on getting the random space - shouldn't make 222 * Change the logic on getting the random space - shouldn't make
218 * any difference, but this seems clearer to me. 223 * any difference, but this seems clearer to me.
219 */ 224 */
220 for (int i = 1000; --i; ) 225 for (int i = 1000; --i;)
221 { 226 {
222 object *new_obj = style->at (RANDOM () % style->width, RANDOM () % style->height).bot; 227 object *new_obj = style->at (RANDOM () % style->width, RANDOM () % style->height).bot;
223 228
224 if (new_obj) 229 if (new_obj)
225 return new_obj->head_ (); 230 return new_obj->head_ ();
226 } 231 }
227 232
228 // instead of crashing in the unlikely case, try to return *something* 233 // instead of crashing in the unlikely case, try to return *something*
229 return get_archetype ("blocked"); 234 return get_archetype ("blocked");
230} 235}
231

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines