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.4 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.11 by root, Thu Dec 14 22:45:40 2006 UTC

1
2/*
3 * static char *rcsid_map_c =
4 * "$Id: region.C,v 1.4 2006/09/10 16:00:23 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30 24
31#include <global.h> 25#include <global.h>
32
33#ifndef WIN32 /* ---win32 exclude header */
34# include <unistd.h> 26#include <unistd.h>
35#endif /* win32 */
36 27
37/* 28/*
38 * 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.
39 * 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
40 * with the 'fallback' property set. 31 * with the 'fallback' property set.
66 return NULL; 57 return NULL;
67} 58}
68 59
69/* This might need optimising at some point. */ 60/* This might need optimising at some point. */
70region * 61region *
71get_region_by_map (mapstruct *m) 62get_region_by_map (maptile *m)
72{ 63{
73 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));
74} 65}
75 66
76/* 67/*
78 * 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
79 * the map code. 70 * the map code.
80 */ 71 */
81 72
82const char * 73const char *
83get_name_of_region_for_map (const mapstruct *m) 74get_name_of_region_for_map (const maptile *m)
84{ 75{
85 region *reg; 76 region *reg;
86 77
87 if (m->region != NULL) 78 if (m->region != NULL)
88 return m->region->name; 79 return m->region->name;
243 reg = get_region_by_map (op->map); 234 reg = get_region_by_map (op->map);
244 while (reg != NULL) 235 while (reg != NULL)
245 { 236 {
246 if (reg->jailmap) 237 if (reg->jailmap)
247 { 238 {
248 exit = get_object (); 239 exit = object::create ();
249 EXIT_PATH (exit) = reg->jailmap; 240 EXIT_PATH (exit) = reg->jailmap;
250 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ 241 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */
251 SET_FLAG (exit, FLAG_DAMNED); 242 SET_FLAG (exit, FLAG_DAMNED);
252 EXIT_X (exit) = reg->jailx; 243 EXIT_X (exit) = reg->jailx;
253 EXIT_Y (exit) = reg->jaily; 244 EXIT_Y (exit) = reg->jaily;
297 */ 288 */
298 289
299region * 290region *
300get_region_struct (void) 291get_region_struct (void)
301{ 292{
302
303 region *reg;
304
305 reg = (region *) CALLOC (1, sizeof (region));
306 if (reg == NULL)
307 fatal (OUT_OF_MEMORY);
308
309 memset (reg, '\0', sizeof (region));
310
311 return reg; 293 return new region;
312} 294}
313 295
314/* 296/*
315 * Reads/parses the region file, and copies into a linked list 297 * Reads/parses the region file, and copies into a linked list
316 * of region structs. 298 * of region structs.
363 */ 345 */
364 if (!strcmp (key, "region")) 346 if (!strcmp (key, "region"))
365 { 347 {
366 *end = 0; 348 *end = 0;
367 newreg = get_region_struct (); 349 newreg = get_region_struct ();
368 newreg->name = strdup_local (value); 350 newreg->name = strdup (value);
369 } 351 }
370 else if (!strcmp (key, "parent")) 352 else if (!strcmp (key, "parent"))
371 { 353 {
372 /* 354 /*
373 * Note that this is in the initialisation code, so we don't actually 355 * Note that this is in the initialisation code, so we don't actually
374 * assign the pointer to the parent yet, because it might not have been 356 * assign the pointer to the parent yet, because it might not have been
375 * parsed. 357 * parsed.
376 */ 358 */
377 *end = 0; 359 *end = 0;
378 newreg->parent_name = strdup_local (value); 360 newreg->parent_name = strdup (value);
379 } 361 }
380 else if (!strcmp (key, "longname")) 362 else if (!strcmp (key, "longname"))
381 { 363 {
382 *end = 0; 364 *end = 0;
383 newreg->longname = strdup_local (value); 365 newreg->longname = strdup (value);
384 } 366 }
385 else if (!strcmp (key, "jail")) 367 else if (!strcmp (key, "jail"))
386 { 368 {
387 /* jail entries are of the form: /path/to/map x y */ 369 /* jail entries are of the form: /path/to/map x y */
388 char path[MAX_BUF]; 370 char path[MAX_BUF];
391 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) 373 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3)
392 { 374 {
393 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); 375 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value);
394 continue; 376 continue;
395 } 377 }
396 newreg->jailmap = strdup_local (path); 378 newreg->jailmap = strdup (path);
397 newreg->jailx = x; 379 newreg->jailx = x;
398 newreg->jaily = y; 380 newreg->jaily = y;
399 } 381 }
400 else if (!strcmp (key, "msg")) 382 else if (!strcmp (key, "msg"))
401 { 383 {
413 * There may be regions with empty messages (eg, msg/endmsg 395 * There may be regions with empty messages (eg, msg/endmsg
414 * with nothing between). When maps are loaded, this is done 396 * with nothing between). When maps are loaded, this is done
415 * so better do it here too... 397 * so better do it here too...
416 */ 398 */
417 if (msgpos != 0) 399 if (msgpos != 0)
418 newreg->msg = strdup_local (msgbuf); 400 newreg->msg = strdup (msgbuf);
419 401
420 /* we have to reset msgpos, or the next region will store both msg blocks. */ 402 /* we have to reset msgpos, or the next region will store both msg blocks. */
421 msgpos = 0; 403 msgpos = 0;
422 } 404 }
423 else if (!strcmp (key, "fallback")) 405 else if (!strcmp (key, "fallback"))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines