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.15 by pippijn, Sat Jan 6 14:42:29 2007 UTC vs.
Revision 1.18 by root, Sat Jan 27 23:59: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) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 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
9 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
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 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,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 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
19 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23*/ 23 */
24
25 24
26#include <global.h> 25#include <global.h>
27#include <unistd.h> 26#include <unistd.h>
27
28region *
29region::default_region ()
30{
31 for (region *reg = first_region; reg; reg = reg->next)
32 if (reg->fallback)
33 return reg;
34
35 return first_region;
36}
28 37
29/* 38/*
30 * Pass a char array, returns a pointer to the region of the same name. 39 * Pass a char array, returns a pointer to the region of the same name.
31 * if it can't find a region of the same name it returns the first region 40 * if it can't find a region of the same name it returns the first region
32 * with the 'fallback' property set. 41 * with the 'fallback' property set.
33 * if it can't find a matching name /or/ a fallback region it logs an info message 42 * if it can't find a matching name /or/ a fallback region it logs an info message
34 * message and returns NULL 43 * message and returns NULL
35 * used by the map parsing code. 44 * used by the map parsing code.
36 */ 45 */
37region * 46region *
38get_region_by_name (const char *region_name) 47region::find (const char *name)
39{ 48{
40 region *reg;
41 char *p = strchr (region_name, '\n');
42
43 if (p)
44 *p = '\0';
45 for (reg = first_region; reg != NULL; reg = reg->next) 49 for (region *reg = first_region; reg; reg = reg->next)
46 if (!strcmp (reg->name, region_name)) 50 if (!strcmp (reg->name, name))
47 return reg; 51 return reg;
48 52
49 for (reg = first_region; reg != NULL; reg = reg->next)
50 {
51 if (reg->fallback)
52 {
53 LOG (llevDebug, "region called %s requested, but not found, fallback used.\n", region_name); 53 LOG (llevError, "region called %s requested, but not found, using fallback.\n", name);
54 return reg; 54
55 } 55 return default_region ();
56 }
57 LOG (llevInfo, "Got no region or fallback for region %s.\n", region_name);
58 return NULL;
59} 56}
60 57
61/* This might need optimising at some point. */ 58/* This might need optimising at some point. */
62region * 59region *
63get_region_by_map (maptile *m) 60get_region_by_map (maptile *m)
64{ 61{
65 return get_region_by_name (get_name_of_region_for_map (m)); 62 return region::find (get_name_of_region_for_map (m));
66} 63}
67 64
68/* 65/*
69 * Since we won't assume all maps have a region set properly, we need an 66 * Since we won't assume all maps have a region set properly, we need an
70 * explicit check that it is, this is much nicer here than scattered throughout 67 * explicit check that it is, this is much nicer here than scattered throughout
74const char * 71const char *
75get_name_of_region_for_map (const maptile *m) 72get_name_of_region_for_map (const maptile *m)
76{ 73{
77 region *reg; 74 region *reg;
78 75
79 if (m->region) 76 if (m->default_region)
80 return m->region->name; 77 return m->default_region->name;
81 78
82 for (reg = first_region; reg != NULL; reg = reg->next) 79 for (reg = first_region; reg; reg = reg->next)
83 { 80 {
84 if (reg->fallback) 81 if (reg->fallback)
85 return reg->name; 82 return reg->name;
86 } 83 }
87 84
445 442
446 for (reg = first_region; reg != NULL && reg->next != NULL; reg = reg->next) 443 for (reg = first_region; reg != NULL && reg->next != NULL; reg = reg->next)
447 { 444 {
448 if (reg->parent_name != NULL) 445 if (reg->parent_name != NULL)
449 { 446 {
450 reg->parent = get_region_by_name (reg->parent_name); 447 reg->parent = region::find (reg->parent_name);
451 parent_count++; 448 parent_count++;
452 } 449 }
450
453 region_count++; 451 region_count++;
454 } 452 }
453
455 LOG (llevDebug, "Assigned %u regions with %u parents.\n", region_count, parent_count); 454 LOG (llevDebug, "Assigned %u regions with %u parents.\n", region_count, parent_count);
456} 455}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines