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.13 by root, Sun Dec 31 10:28:36 2006 UTC vs.
Revision 1.14 by root, Sun Dec 31 17:17:23 2006 UTC

18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 20
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22*/
23
24 23
25#include <global.h> 24#include <global.h>
26#include <random_map.h> 25#include <random_map.h>
27#include <dirent.h> 26#include <dirent.h>
28#include <sys/stat.h> 27#include <sys/stat.h>
29#include <unistd.h> 28#include <unistd.h>
30#include "../include/autoconf.h" 29#include "../include/autoconf.h"
31
32 30
33static int 31static int
34pointer_strcmp (const void *p1, const void *p2) 32pointer_strcmp (const void *p1, const void *p2)
35{ 33{
36 const char *s1 = *(const char **) p1; 34 const char *s1 = *(const char **) p1;
110 else /* otherwise, just use the dirname. We'll pick a random stylefile. */ 108 else /* otherwise, just use the dirname. We'll pick a random stylefile. */
111 sprintf (style_file_path, "%s", dirname); 109 sprintf (style_file_path, "%s", dirname);
112 110
113 /* is what we were given a directory, or a file? */ 111 /* is what we were given a directory, or a file? */
114 sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path); 112 sprintf (style_file_full_path, "%s/maps%s", settings.datadir, style_file_path);
113
115 if (stat (style_file_full_path, &file_stat) == 0 && !S_ISDIR (file_stat.st_mode)) 114 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); 115 style_map = maptile::load_map_sync (style_file_path);
117 116
118 if (!style_map) /* maybe we were given a directory! */ 117 if (!style_map) /* maybe we were given a directory! */
119 { 118 {
217 * Change the logic on getting the random space - shouldn't make 216 * Change the logic on getting the random space - shouldn't make
218 * any difference, but this seems clearer to me. 217 * any difference, but this seems clearer to me.
219 */ 218 */
220 do 219 do
221 { 220 {
222 limit++; 221 if (limit++ >= 1000)
222 return create_singularity ("pick_random_object");
223
223 x = RANDOM () % style->width; 224 x = RANDOM () % style->width;
224 y = RANDOM () % style->height; 225 y = RANDOM () % style->height;
225 new_obj = GET_MAP_OB (style, x, y); 226 new_obj = GET_MAP_OB (style, x, y);
226 } 227 }
227 while (new_obj == NULL && limit < 1000); 228 while (!new_obj);
228 229
229 if (new_obj->head)
230 return new_obj->head; 230 return new_obj->head_ ();
231 else
232 return new_obj;
233} 231}
234 232

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines