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.7 by root, Thu Dec 14 22:45:40 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 115 style_map->load ();
120 /* Given a file. See if its in memory */
121 for (style_map = styles; style_map != NULL; style_map = style_map->next)
122 {
123 if (!strcmp (style_name, style_map->path))
124 return style_map;
125 }
126 style_map = load_original_map (style_name, MAP_STYLE);
127 /* Remove it from global list, put it on our local list */
128 if (style_map)
129 {
130 maptile *tmp;
131
132 if (style_map == first_map)
133 first_map = style_map->next;
134 else
135 {
136 for (tmp = first_map; tmp && tmp->next != style_map; tmp = tmp->next);
137 if (tmp)
138 tmp->next = style_map->next;
139 }
140 style_map->next = styles;
141 styles = style_map;
142 }
143 return style_map; 116 return style_map;
144} 117}
145 118
146maptile * 119maptile *
147find_style (const char *dirname, const char *stylename, int difficulty) 120find_style (const char *dirname, const char *stylename, int difficulty)
245 } 218 }
246 return style_map; 219 return style_map;
247 220
248} 221}
249 222
250
251/* picks a random object from a style map. 223/* picks a random object from a style map.
252 * 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
253 * variables to generate tables. 225 * variables to generate tables.
254 */ 226 */
255object * 227object *
265 * any difference, but this seems clearer to me. 237 * any difference, but this seems clearer to me.
266 */ 238 */
267 do 239 do
268 { 240 {
269 limit++; 241 limit++;
270 x = RANDOM () % MAP_WIDTH (style); 242 x = RANDOM () % style->width;
271 y = RANDOM () % MAP_HEIGHT (style); 243 y = RANDOM () % style->height;
272 new_obj = get_map_ob (style, x, y); 244 new_obj = GET_MAP_OB (style, x, y);
273 } 245 }
274 while (new_obj == NULL && limit < 1000); 246 while (new_obj == NULL && limit < 1000);
247
275 if (new_obj->head) 248 if (new_obj->head)
276 return new_obj->head; 249 return new_obj->head;
277 else 250 else
278 return new_obj; 251 return new_obj;
279} 252}
280 253
281
282void
283free_style_maps (void)
284{
285 maptile *next;
286 int style_maps = 0;
287
288 /* delete_map will try to free it from the linked list,
289 * but won't find it, so we need to do it ourselves
290 */
291 while (styles)
292 {
293 next = styles->next;
294 delete_map (styles);
295 styles = next;
296 style_maps++;
297 }
298 LOG (llevDebug, "free_style_maps: Freed %d maps\n", style_maps);
299}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines