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.17 by root, Thu Jan 25 03:54:44 2007 UTC

1
2/* 1/*
3 * static char *rcsid_map_c =
4 * "$Id: region.C,v 1.4 2006/09/10 16:00:23 root Exp $";
5 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
9 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
10 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
12 7 *
13 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
14 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
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21 *
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 23 */
29 24
30 25
31#include <global.h> 26#include <global.h>
32
33#ifndef WIN32 /* ---win32 exclude header */
34# include <unistd.h> 27#include <unistd.h>
35#endif /* win32 */
36 28
37/* 29/*
38 * Pass a char array, returns a pointer to the region of the same name. 30 * 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 31 * if it can't find a region of the same name it returns the first region
40 * with the 'fallback' property set. 32 * with the 'fallback' property set.
66 return NULL; 58 return NULL;
67} 59}
68 60
69/* This might need optimising at some point. */ 61/* This might need optimising at some point. */
70region * 62region *
71get_region_by_map (mapstruct *m) 63get_region_by_map (maptile *m)
72{ 64{
73 return get_region_by_name (get_name_of_region_for_map (m)); 65 return get_region_by_name (get_name_of_region_for_map (m));
74} 66}
75 67
76/* 68/*
78 * explicit check that it is, this is much nicer here than scattered throughout 70 * explicit check that it is, this is much nicer here than scattered throughout
79 * the map code. 71 * the map code.
80 */ 72 */
81 73
82const char * 74const char *
83get_name_of_region_for_map (const mapstruct *m) 75get_name_of_region_for_map (const maptile *m)
84{ 76{
85 region *reg; 77 region *reg;
86 78
87 if (m->region != NULL) 79 if (m->default_region)
88 return m->region->name; 80 return m->default_region->name;
81
89 for (reg = first_region; reg != NULL; reg = reg->next) 82 for (reg = first_region; reg; reg = reg->next)
90 { 83 {
91 if (reg->fallback) 84 if (reg->fallback)
92 return reg->name; 85 return reg->name;
93 } 86 }
87
94 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);
95 return "unknown"; 89 return "unknown";
96} 90}
97 91
98/* 92/*
99 * Tries to find a region that 'name' corresponds to. 93 * Tries to find a region that 'name' corresponds to.
243 reg = get_region_by_map (op->map); 237 reg = get_region_by_map (op->map);
244 while (reg != NULL) 238 while (reg != NULL)
245 { 239 {
246 if (reg->jailmap) 240 if (reg->jailmap)
247 { 241 {
248 exit = get_object (); 242 exit = object::create ();
249 EXIT_PATH (exit) = reg->jailmap; 243 EXIT_PATH (exit) = reg->jailmap;
250 /* 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 */
251 SET_FLAG (exit, FLAG_DAMNED); 245 SET_FLAG (exit, FLAG_DAMNED);
252 EXIT_X (exit) = reg->jailx; 246 EXIT_X (exit) = reg->jailx;
253 EXIT_Y (exit) = reg->jaily; 247 EXIT_Y (exit) = reg->jaily;
297 */ 291 */
298 292
299region * 293region *
300get_region_struct (void) 294get_region_struct (void)
301{ 295{
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; 296 return new region;
312} 297}
313 298
314/* 299/*
315 * Reads/parses the region file, and copies into a linked list 300 * Reads/parses the region file, and copies into a linked list
316 * of region structs. 301 * of region structs.
363 */ 348 */
364 if (!strcmp (key, "region")) 349 if (!strcmp (key, "region"))
365 { 350 {
366 *end = 0; 351 *end = 0;
367 newreg = get_region_struct (); 352 newreg = get_region_struct ();
368 newreg->name = strdup_local (value); 353 newreg->name = strdup (value);
369 } 354 }
370 else if (!strcmp (key, "parent")) 355 else if (!strcmp (key, "parent"))
371 { 356 {
372 /* 357 /*
373 * 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
374 * 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
375 * parsed. 360 * parsed.
376 */ 361 */
377 *end = 0; 362 *end = 0;
378 newreg->parent_name = strdup_local (value); 363 newreg->parent_name = strdup (value);
379 } 364 }
380 else if (!strcmp (key, "longname")) 365 else if (!strcmp (key, "longname"))
381 { 366 {
382 *end = 0; 367 *end = 0;
383 newreg->longname = strdup_local (value); 368 newreg->longname = strdup (value);
384 } 369 }
385 else if (!strcmp (key, "jail")) 370 else if (!strcmp (key, "jail"))
386 { 371 {
387 /* jail entries are of the form: /path/to/map x y */ 372 /* jail entries are of the form: /path/to/map x y */
388 char path[MAX_BUF]; 373 char path[MAX_BUF];
391 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) 376 if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3)
392 { 377 {
393 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); 378 LOG (llevError, "region.c: malformated regions entry: jail %s\n", value);
394 continue; 379 continue;
395 } 380 }
396 newreg->jailmap = strdup_local (path); 381 newreg->jailmap = strdup (path);
397 newreg->jailx = x; 382 newreg->jailx = x;
398 newreg->jaily = y; 383 newreg->jaily = y;
399 } 384 }
400 else if (!strcmp (key, "msg")) 385 else if (!strcmp (key, "msg"))
401 { 386 {
413 * There may be regions with empty messages (eg, msg/endmsg 398 * There may be regions with empty messages (eg, msg/endmsg
414 * with nothing between). When maps are loaded, this is done 399 * with nothing between). When maps are loaded, this is done
415 * so better do it here too... 400 * so better do it here too...
416 */ 401 */
417 if (msgpos != 0) 402 if (msgpos != 0)
418 newreg->msg = strdup_local (msgbuf); 403 newreg->msg = strdup (msgbuf);
419 404
420 /* 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. */
421 msgpos = 0; 406 msgpos = 0;
422 } 407 }
423 else if (!strcmp (key, "fallback")) 408 else if (!strcmp (key, "fallback"))
465 reg->parent = get_region_by_name (reg->parent_name); 450 reg->parent = get_region_by_name (reg->parent_name);
466 parent_count++; 451 parent_count++;
467 } 452 }
468 region_count++; 453 region_count++;
469 } 454 }
470 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);
471} 456}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines