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.14 by root, Sun Dec 31 17:17:23 2006 UTC vs.
Revision 1.15 by root, Sun Dec 31 18:10:41 2006 UTC

181 min_dist = dist; 181 min_dist = dist;
182 min_index = i; 182 min_index = i;
183 } 183 }
184 } 184 }
185 } 185 }
186
186 /* presumably now we've found the "best" match for the 187 /* presumably now we've found the "best" match for the
187 difficulty. */ 188 difficulty. */
188 strcat (style_file_path, "/"); 189 strcat (style_file_path, "/");
189 strcat (style_file_path, namelist[min_index]); 190 strcat (style_file_path, namelist[min_index]);
190 style_map = maptile::load_map_sync (style_file_path); 191 style_map = maptile::load_map_sync (style_file_path);
193 for (i = 0; i < n; i++) 194 for (i = 0; i < n; i++)
194 free (namelist[i]); 195 free (namelist[i]);
195 196
196 free (namelist); 197 free (namelist);
197 } 198 }
199
200 if (style_map)
201 style_map->deactivate ();
198 202
199 return style_map; 203 return style_map;
200 204
201} 205}
202 206
205 * variables to generate tables. 209 * variables to generate tables.
206 */ 210 */
207object * 211object *
208pick_random_object (maptile *style) 212pick_random_object (maptile *style)
209{ 213{
210 int x, y, limit = 0;
211 object *new_obj;
212
213 /* while returning a null object will result in a crash, that 214 /* while returning a null object will result in a crash, that
214 * is actually preferable to an infinite loop. That is because 215 * is actually preferable to an infinite loop. That is because
215 * most servers will automatically restart in case of crash. 216 * most servers will automatically restart in case of crash.
216 * Change the logic on getting the random space - shouldn't make 217 * Change the logic on getting the random space - shouldn't make
217 * any difference, but this seems clearer to me. 218 * any difference, but this seems clearer to me.
218 */ 219 */
219 do 220 for (int i = 1000; --i; )
220 { 221 {
221 if (limit++ >= 1000) 222 object *new_obj = style->at (RANDOM () % style->width, RANDOM () % style->height).bot;
222 return create_singularity ("pick_random_object");
223 223
224 x = RANDOM () % style->width; 224 if (new_obj)
225 y = RANDOM () % style->height; 225 return new_obj->head_ ();
226 new_obj = GET_MAP_OB (style, x, y);
227 } 226 }
228 while (!new_obj);
229 227
230 return new_obj->head_ (); 228 return 0;
231} 229}
232 230

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines