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.40 by root, Wed Dec 31 17:35:37 2008 UTC vs.
Revision 1.42 by root, Thu Jan 1 20:49:48 2009 UTC

43 * if it can't find a matching name /or/ a fallback region it logs an info message 43 * if it can't find a matching name /or/ a fallback region it logs an info message
44 * message and returns NULL 44 * message and returns NULL
45 * used by the map parsing code. 45 * used by the map parsing code.
46 */ 46 */
47region * 47region *
48region::find (const char *name) 48region::find (shstr_cmp name)
49{ 49{
50 for_all_regions (rgn) 50 for_all_regions (rgn)
51 if (!strcmp (rgn->name, name)) 51 if (rgn->name == name)
52 return rgn; 52 return rgn;
53 53
54 LOG (llevError, "region called %s requested, but not found, using fallback.\n", name); 54 LOG (llevError, "region called %s requested, but not found, using fallback.\n", &name);
55
56 return default_region ();
57}
58
59/*
60 * Tries to find a region that 'name' corresponds to.
61 * It looks, in order, for:
62 * an exact match to region name (case insensitive)
63 * an exact match to longname (case insensitive)
64 * a substring that matches to the longname (eg Kingdom)
65 * a substring that matches to the region name (eg nav)
66 * if it can find none of these it returns the first parentless region
67 * (there should be only one of these - the top level one)
68 * If we got a NULL, then just return the top level region
69 *
70 */
71region *
72region::find_fuzzy (const char *name)
73{
74 if (!name)
75 return default_region ();
76
77 char *p = strchr (name, '\n');
78 if (p)
79 *p = '\0';
80
81 for_all_regions (rgn)
82 if (!strcasecmp (rgn->name, name))
83 return rgn;
84
85 for_all_regions (rgn)
86 if (rgn->longname)
87 if (!strcasecmp (rgn->longname, name))
88 return rgn;
89
90 for_all_regions (rgn)
91 if (rgn->longname)
92 {
93 if (strstr (rgn->longname, name))
94 return rgn;
95 }
96
97 for_all_regions (rgn)
98 if (rgn->longname)
99 {
100 /*
101 * This is not a bug, we want the region that is most identifiably a discrete
102 * area in the game, eg if we have 'scor', we want to return 'scorn' and not
103 * 'scornarena', regardless of their order on the list so we only look at those
104 * regions with a longname set.
105 */
106 if (strstr (rgn->name, name))
107 return rgn;
108 }
109
110 for_all_regions (rgn)
111 {
112 if (strstr (rgn->name, name))
113 return rgn;
114 }
115 55
116 return default_region (); 56 return default_region ();
117} 57}
118 58
119void 59void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines