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.11 by root, Wed Dec 27 13:13:47 2006 UTC vs.
Revision 1.12 by root, Sat Dec 30 10:16:11 2006 UTC

106 * isn't, and difficult is -1, it returns a random style map. 106 * isn't, and difficult is -1, it returns a random style map.
107 * Otherwise, it tries to match the difficulty given with a style 107 * Otherwise, it tries to match the difficulty given with a style
108 * file, named style_name_# where # is an integer 108 * file, named style_name_# where # is an integer
109 */ 109 */
110 110
111/* remove extern, so visible to command_style_map_info function */
112maptile *styles = NULL;
113
114
115maptile * 111maptile *
116load_style_map (char *style_name) 112load_style_map (char *style_name)
117{ 113{
118 maptile *style_map; 114 maptile *style_map = maptile::find_map (style_name, 0);
119
120 /* Given a file. See if its in memory */
121 for (style_map = styles; style_map; style_map = style_map->next)
122 if (!strcmp (style_name, style_map->path))
123 return style_map;
124
125 style_map = load_original_map (style_name, MAP_STYLE);
126
127 /* Remove it from global list, put it on our local list */
128 if (style_map)
129 {
130 style_map->unlink (); 115 style_map->load ();
131
132 style_map->next = styles;
133 styles = style_map;
134 }
135
136 return style_map; 116 return style_map;
137} 117}
138 118
139maptile * 119maptile *
140find_style (const char *dirname, const char *stylename, int difficulty) 120find_style (const char *dirname, const char *stylename, int difficulty)
238 } 218 }
239 return style_map; 219 return style_map;
240 220
241} 221}
242 222
243
244/* picks a random object from a style map. 223/* picks a random object from a style map.
245 * Redone by MSW so it should be faster and not use static 224 * Redone by MSW so it should be faster and not use static
246 * variables to generate tables. 225 * variables to generate tables.
247 */ 226 */
248object * 227object *
263 x = RANDOM () % style->width; 242 x = RANDOM () % style->width;
264 y = RANDOM () % style->height; 243 y = RANDOM () % style->height;
265 new_obj = GET_MAP_OB (style, x, y); 244 new_obj = GET_MAP_OB (style, x, y);
266 } 245 }
267 while (new_obj == NULL && limit < 1000); 246 while (new_obj == NULL && limit < 1000);
247
268 if (new_obj->head) 248 if (new_obj->head)
269 return new_obj->head; 249 return new_obj->head;
270 else 250 else
271 return new_obj; 251 return new_obj;
272} 252}
273 253
274
275void
276free_style_maps (void)
277{
278 maptile *next;
279 int style_maps = 0;
280
281 /* delete_map will try to free it from the linked list,
282 * but won't find it, so we need to do it ourselves
283 */
284 while (styles)
285 {
286 next = styles->next;
287 delete_map (styles);
288 styles = next;
289 style_maps++;
290 }
291 LOG (llevDebug, "free_style_maps: Freed %d maps\n", style_maps);
292}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines