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

Comparing deliantra/server/common/region.C (file contents):
Revision 1.8 by pippijn, Mon Dec 11 19:46:46 2006 UTC vs.
Revision 1.15 by pippijn, Sat Jan 6 14:42:29 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 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 9 it under the terms of the GNU General Public License as published by
73const char * 74const char *
74get_name_of_region_for_map (const maptile *m) 75get_name_of_region_for_map (const maptile *m)
75{ 76{
76 region *reg; 77 region *reg;
77 78
78 if (m->region != NULL) 79 if (m->region)
79 return m->region->name; 80 return m->region->name;
81
80 for (reg = first_region; reg != NULL; reg = reg->next) 82 for (reg = first_region; reg != NULL; reg = reg->next)
81 { 83 {
82 if (reg->fallback) 84 if (reg->fallback)
83 return reg->name; 85 return reg->name;
84 } 86 }
87
85 LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", m->name); 88 LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", &m->name);
86 return "unknown"; 89 return "unknown";
87} 90}
88 91
89/* 92/*
90 * Tries to find a region that 'name' corresponds to. 93 * Tries to find a region that 'name' corresponds to.
234 reg = get_region_by_map (op->map); 237 reg = get_region_by_map (op->map);
235 while (reg != NULL) 238 while (reg != NULL)
236 { 239 {
237 if (reg->jailmap) 240 if (reg->jailmap)
238 { 241 {
239 exit = get_object (); 242 exit = object::create ();
240 EXIT_PATH (exit) = reg->jailmap; 243 EXIT_PATH (exit) = reg->jailmap;
241 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ 244 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */
242 SET_FLAG (exit, FLAG_DAMNED); 245 SET_FLAG (exit, FLAG_DAMNED);
243 EXIT_X (exit) = reg->jailx; 246 EXIT_X (exit) = reg->jailx;
244 EXIT_Y (exit) = reg->jaily; 247 EXIT_Y (exit) = reg->jaily;
288 */ 291 */
289 292
290region * 293region *
291get_region_struct (void) 294get_region_struct (void)
292{ 295{
293
294 region *reg;
295
296 reg = (region *) CALLOC (1, sizeof (region));
297 if (reg == NULL)
298 fatal (OUT_OF_MEMORY);
299
300 memset (reg, '\0', sizeof (region));
301
302 return reg; 296 return new region;
303} 297}
304 298
305/* 299/*
306 * Reads/parses the region file, and copies into a linked list 300 * Reads/parses the region file, and copies into a linked list
307 * of region structs. 301 * of region structs.
354 */ 348 */
355 if (!strcmp (key, "region")) 349 if (!strcmp (key, "region"))
356 { 350 {
357 *end = 0; 351 *end = 0;
358 newreg = get_region_struct (); 352 newreg = get_region_struct ();
359 newreg->name = strdup_local (value); 353 newreg->name = strdup (value);
360 } 354 }
361 else if (!strcmp (key, "parent")) 355 else if (!strcmp (key, "parent"))
362 { 356 {
363 /* 357 /*
364 * Note that this is in the initialisation code, so we don't actually 358 * Note that this is in the initialisation code, so we don't actually
365 * assign the pointer to the parent yet, because it might not have been 359 * assign the pointer to the parent yet, because it might not have been
366 * parsed. 360 * parsed.
367 */ 361 */
368 *end = 0; 362 *end = 0;
369 newreg->parent_name = strdup_local (value); 363 newreg->parent_name = strdup (value);
370 } 364 }
371 else if (!strcmp (key, "longname")) 365 else if (!strcmp (key, "longname"))
372 { 366 {
373 *end = 0; 367 *end = 0;
374 newreg->longname = strdup_local (value); 368 newreg->longname = strdup (value);
375 } 369 }
376 else if (!strcmp (key, "jail")) 370 else if (!strcmp (key, "jail"))
377 { 371 {
378 /* jail entries are of the form: /path/to/map x y */ 372 /* jail entries are of the form: /path/to/map x y */
379 char path[MAX_BUF]; 373 char path[MAX_BUF];
382 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) 376 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3)
383 { 377 {
384 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); 378 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value);
385 continue; 379 continue;
386 } 380 }
387 newreg->jailmap = strdup_local (path); 381 newreg->jailmap = strdup (path);
388 newreg->jailx = x; 382 newreg->jailx = x;
389 newreg->jaily = y; 383 newreg->jaily = y;
390 } 384 }
391 else if (!strcmp (key, "msg")) 385 else if (!strcmp (key, "msg"))
392 { 386 {
404 * There may be regions with empty messages (eg, msg/endmsg 398 * There may be regions with empty messages (eg, msg/endmsg
405 * with nothing between). When maps are loaded, this is done 399 * with nothing between). When maps are loaded, this is done
406 * so better do it here too... 400 * so better do it here too...
407 */ 401 */
408 if (msgpos != 0) 402 if (msgpos != 0)
409 newreg->msg = strdup_local (msgbuf); 403 newreg->msg = strdup (msgbuf);
410 404
411 /* we have to reset msgpos, or the next region will store both msg blocks. */ 405 /* we have to reset msgpos, or the next region will store both msg blocks. */
412 msgpos = 0; 406 msgpos = 0;
413 } 407 }
414 else if (!strcmp (key, "fallback")) 408 else if (!strcmp (key, "fallback"))
456 reg->parent = get_region_by_name (reg->parent_name); 450 reg->parent = get_region_by_name (reg->parent_name);
457 parent_count++; 451 parent_count++;
458 } 452 }
459 region_count++; 453 region_count++;
460 } 454 }
461 LOG (llevDebug, "Assigned %u regions with %u parents.", region_count, parent_count); 455 LOG (llevDebug, "Assigned %u regions with %u parents.\n", region_count, parent_count);
462} 456}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines