… | |
… | |
50 | for_all_regions (rgn) |
50 | for_all_regions (rgn) |
51 | if (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 | */ |
|
|
71 | region * |
|
|
72 | region::find_fuzzy (const char *name) |
|
|
73 | { |
|
|
74 | if (!name) |
|
|
75 | return default_region (); |
|
|
76 | |
|
|
77 | // TODO: bug, changes possibly const string |
|
|
78 | char *p = strchr (name, '\n'); |
|
|
79 | if (p) |
|
|
80 | *p = '\0'; |
|
|
81 | |
|
|
82 | for_all_regions (rgn) |
|
|
83 | if (rgn->name.eq_nc (name)) |
|
|
84 | return rgn; |
|
|
85 | |
|
|
86 | for_all_regions (rgn) |
|
|
87 | if (rgn->longname.eq_nc (name)) |
|
|
88 | return rgn; |
|
|
89 | |
|
|
90 | for_all_regions (rgn) |
|
|
91 | if (rgn->longname.contains (name)) |
|
|
92 | return rgn; |
|
|
93 | |
|
|
94 | for_all_regions (rgn) |
|
|
95 | /* |
|
|
96 | * This is not a bug, we want the region that is most identifiably a discrete |
|
|
97 | * area in the game, eg if we have 'scor', we want to return 'scorn' and not |
|
|
98 | * 'scornarena', regardless of their order on the list so we only look at those |
|
|
99 | * regions with a longname set. |
|
|
100 | */ |
|
|
101 | if (rgn->longname && rgn->name.contains (name)) |
|
|
102 | return rgn; |
|
|
103 | |
|
|
104 | for_all_regions (rgn) |
|
|
105 | if (rgn->name.contains (name)) |
|
|
106 | return rgn; |
|
|
107 | |
55 | |
108 | return default_region (); |
56 | return default_region (); |
109 | } |
57 | } |
110 | |
58 | |
111 | void |
59 | void |