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.6 by root, Thu Sep 14 22:34:00 2006 UTC vs.
Revision 1.13 by root, Sun Dec 31 21:02:04 2006 UTC

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 23
24 24
25#include <global.h> 25#include <global.h>
26
27#ifndef WIN32 /* ---win32 exclude header */
28# include <unistd.h> 26#include <unistd.h>
29#endif /* win32 */
30 27
31/* 28/*
32 * Pass a char array, returns a pointer to the region of the same name. 29 * Pass a char array, returns a pointer to the region of the same name.
33 * if it can't find a region of the same name it returns the first region 30 * if it can't find a region of the same name it returns the first region
34 * with the 'fallback' property set. 31 * with the 'fallback' property set.
60 return NULL; 57 return NULL;
61} 58}
62 59
63/* This might need optimising at some point. */ 60/* This might need optimising at some point. */
64region * 61region *
65get_region_by_map (mapstruct *m) 62get_region_by_map (maptile *m)
66{ 63{
67 return get_region_by_name (get_name_of_region_for_map (m)); 64 return get_region_by_name (get_name_of_region_for_map (m));
68} 65}
69 66
70/* 67/*
72 * explicit check that it is, this is much nicer here than scattered throughout 69 * explicit check that it is, this is much nicer here than scattered throughout
73 * the map code. 70 * the map code.
74 */ 71 */
75 72
76const char * 73const char *
77get_name_of_region_for_map (const mapstruct *m) 74get_name_of_region_for_map (const maptile *m)
78{ 75{
79 region *reg; 76 region *reg;
80 77
81 if (m->region != NULL) 78 if (m->region)
82 return m->region->name; 79 return m->region->name;
80
83 for (reg = first_region; reg != NULL; reg = reg->next) 81 for (reg = first_region; reg != NULL; reg = reg->next)
84 { 82 {
85 if (reg->fallback) 83 if (reg->fallback)
86 return reg->name; 84 return reg->name;
87 } 85 }
86
88 LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", m->name); 87 LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", &m->name);
89 return "unknown"; 88 return "unknown";
90} 89}
91 90
92/* 91/*
93 * Tries to find a region that 'name' corresponds to. 92 * Tries to find a region that 'name' corresponds to.
237 reg = get_region_by_map (op->map); 236 reg = get_region_by_map (op->map);
238 while (reg != NULL) 237 while (reg != NULL)
239 { 238 {
240 if (reg->jailmap) 239 if (reg->jailmap)
241 { 240 {
242 exit = get_object (); 241 exit = object::create ();
243 EXIT_PATH (exit) = reg->jailmap; 242 EXIT_PATH (exit) = reg->jailmap;
244 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ 243 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */
245 SET_FLAG (exit, FLAG_DAMNED); 244 SET_FLAG (exit, FLAG_DAMNED);
246 EXIT_X (exit) = reg->jailx; 245 EXIT_X (exit) = reg->jailx;
247 EXIT_Y (exit) = reg->jaily; 246 EXIT_Y (exit) = reg->jaily;
291 */ 290 */
292 291
293region * 292region *
294get_region_struct (void) 293get_region_struct (void)
295{ 294{
296
297 region *reg;
298
299 reg = (region *) CALLOC (1, sizeof (region));
300 if (reg == NULL)
301 fatal (OUT_OF_MEMORY);
302
303 memset (reg, '\0', sizeof (region));
304
305 return reg; 295 return new region;
306} 296}
307 297
308/* 298/*
309 * Reads/parses the region file, and copies into a linked list 299 * Reads/parses the region file, and copies into a linked list
310 * of region structs. 300 * of region structs.
357 */ 347 */
358 if (!strcmp (key, "region")) 348 if (!strcmp (key, "region"))
359 { 349 {
360 *end = 0; 350 *end = 0;
361 newreg = get_region_struct (); 351 newreg = get_region_struct ();
362 newreg->name = strdup_local (value); 352 newreg->name = strdup (value);
363 } 353 }
364 else if (!strcmp (key, "parent")) 354 else if (!strcmp (key, "parent"))
365 { 355 {
366 /* 356 /*
367 * Note that this is in the initialisation code, so we don't actually 357 * Note that this is in the initialisation code, so we don't actually
368 * assign the pointer to the parent yet, because it might not have been 358 * assign the pointer to the parent yet, because it might not have been
369 * parsed. 359 * parsed.
370 */ 360 */
371 *end = 0; 361 *end = 0;
372 newreg->parent_name = strdup_local (value); 362 newreg->parent_name = strdup (value);
373 } 363 }
374 else if (!strcmp (key, "longname")) 364 else if (!strcmp (key, "longname"))
375 { 365 {
376 *end = 0; 366 *end = 0;
377 newreg->longname = strdup_local (value); 367 newreg->longname = strdup (value);
378 } 368 }
379 else if (!strcmp (key, "jail")) 369 else if (!strcmp (key, "jail"))
380 { 370 {
381 /* jail entries are of the form: /path/to/map x y */ 371 /* jail entries are of the form: /path/to/map x y */
382 char path[MAX_BUF]; 372 char path[MAX_BUF];
385 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) 375 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3)
386 { 376 {
387 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); 377 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value);
388 continue; 378 continue;
389 } 379 }
390 newreg->jailmap = strdup_local (path); 380 newreg->jailmap = strdup (path);
391 newreg->jailx = x; 381 newreg->jailx = x;
392 newreg->jaily = y; 382 newreg->jaily = y;
393 } 383 }
394 else if (!strcmp (key, "msg")) 384 else if (!strcmp (key, "msg"))
395 { 385 {
407 * There may be regions with empty messages (eg, msg/endmsg 397 * There may be regions with empty messages (eg, msg/endmsg
408 * with nothing between). When maps are loaded, this is done 398 * with nothing between). When maps are loaded, this is done
409 * so better do it here too... 399 * so better do it here too...
410 */ 400 */
411 if (msgpos != 0) 401 if (msgpos != 0)
412 newreg->msg = strdup_local (msgbuf); 402 newreg->msg = strdup (msgbuf);
413 403
414 /* we have to reset msgpos, or the next region will store both msg blocks. */ 404 /* we have to reset msgpos, or the next region will store both msg blocks. */
415 msgpos = 0; 405 msgpos = 0;
416 } 406 }
417 else if (!strcmp (key, "fallback")) 407 else if (!strcmp (key, "fallback"))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines