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.17 by root, Thu Jan 25 03:54:44 2007 UTC vs.
Revision 1.18 by root, Sat Jan 27 23:59:29 2007 UTC

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 24
25
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
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