1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * 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 Affero GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
|
|
25 | |
24 | |
26 | #include <global.h> |
25 | #include <global.h> |
27 | #include <unistd.h> |
26 | #include <unistd.h> |
|
|
27 | |
|
|
28 | regionvec regions; |
|
|
29 | |
|
|
30 | region * |
|
|
31 | region::default_region () |
|
|
32 | { |
|
|
33 | for_all_regions (rgn) |
|
|
34 | if (rgn->fallback) |
|
|
35 | return rgn; |
|
|
36 | |
|
|
37 | return regions [0]; |
|
|
38 | } |
28 | |
39 | |
29 | /* |
40 | /* |
30 | * Pass a char array, returns a pointer to the region of the same name. |
41 | * 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 |
42 | * if it can't find a region of the same name it returns the first region |
32 | * with the 'fallback' property set. |
43 | * with the 'fallback' property set. |
33 | * if it can't find a matching name /or/ a fallback region it logs an info message |
44 | * if it can't find a matching name /or/ a fallback region it logs an info message |
34 | * message and returns NULL |
45 | * message and returns NULL |
35 | * used by the map parsing code. |
46 | * used by the map parsing code. |
36 | */ |
47 | */ |
37 | region * |
48 | region * |
38 | get_region_by_name (const char *region_name) |
49 | region::find (shstr_cmp name) |
39 | { |
50 | { |
40 | region *reg; |
51 | for_all_regions (rgn) |
41 | char *p = strchr (region_name, '\n'); |
52 | if (rgn->name == name) |
|
|
53 | return rgn; |
42 | |
54 | |
43 | if (p) |
55 | LOG (llevError, "region called %s requested, but not found, using fallback.\n", &name); |
44 | *p = '\0'; |
|
|
45 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
46 | if (!strcmp (reg->name, region_name)) |
|
|
47 | return reg; |
|
|
48 | |
56 | |
49 | for (reg = first_region; reg != NULL; reg = reg->next) |
57 | return default_region (); |
50 | { |
|
|
51 | if (reg->fallback) |
|
|
52 | { |
|
|
53 | LOG (llevDebug, "region called %s requested, but not found, fallback used.\n", region_name); |
|
|
54 | return reg; |
|
|
55 | } |
|
|
56 | } |
|
|
57 | LOG (llevInfo, "Got no region or fallback for region %s.\n", region_name); |
|
|
58 | return NULL; |
|
|
59 | } |
58 | } |
60 | |
59 | |
61 | /* This might need optimising at some point. */ |
60 | void |
62 | region * |
61 | region::do_destroy () |
63 | get_region_by_map (maptile *m) |
|
|
64 | { |
62 | { |
65 | return get_region_by_name (get_name_of_region_for_map (m)); |
63 | regions.erase (this); |
|
|
64 | |
|
|
65 | attachable::do_destroy (); |
|
|
66 | |
|
|
67 | refcnt_dec (); |
66 | } |
68 | } |
67 | |
69 | |
68 | /* |
70 | //+GPL |
69 | * 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 |
|
|
71 | * the map code. |
|
|
72 | */ |
|
|
73 | |
|
|
74 | const char * |
|
|
75 | get_name_of_region_for_map (const maptile *m) |
|
|
76 | { |
|
|
77 | region *reg; |
|
|
78 | |
|
|
79 | if (m->region) |
|
|
80 | return m->region->name; |
|
|
81 | |
|
|
82 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
83 | { |
|
|
84 | if (reg->fallback) |
|
|
85 | return reg->name; |
|
|
86 | } |
|
|
87 | |
|
|
88 | LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", &m->name); |
|
|
89 | return "unknown"; |
|
|
90 | } |
|
|
91 | |
|
|
92 | /* |
|
|
93 | * Tries to find a region that 'name' corresponds to. |
|
|
94 | * It looks, in order, for: |
|
|
95 | * an exact match to region name (case insensitive) |
|
|
96 | * an exact match to longname (case insensitive) |
|
|
97 | * a substring that matches to the longname (eg Kingdom) |
|
|
98 | * a substring that matches to the region name (eg nav) |
|
|
99 | * if it can find none of these it returns the first parentless region |
|
|
100 | * (there should be only one of these - the top level one) |
|
|
101 | * If we got a NULL, then just return the top level region |
|
|
102 | * |
|
|
103 | */ |
|
|
104 | region * |
|
|
105 | get_region_from_string (const char *name) |
|
|
106 | { |
|
|
107 | region *reg; |
|
|
108 | char *substr; |
|
|
109 | char *p; |
|
|
110 | |
|
|
111 | if (name == NULL) |
|
|
112 | { |
|
|
113 | for (reg = first_region; reg->parent != NULL; reg = reg->parent); |
|
|
114 | return reg; |
|
|
115 | } |
|
|
116 | p = strchr (name, '\n'); |
|
|
117 | if (p) |
|
|
118 | *p = '\0'; |
|
|
119 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
120 | if (!strcasecmp (reg->name, name)) |
|
|
121 | return reg; |
|
|
122 | |
|
|
123 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
124 | if (reg->longname != NULL) |
|
|
125 | { |
|
|
126 | if (!strcasecmp (reg->longname, name)) |
|
|
127 | return reg; |
|
|
128 | } |
|
|
129 | |
|
|
130 | substr = NULL; |
|
|
131 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
132 | if (reg->longname != NULL) |
|
|
133 | { |
|
|
134 | substr = strstr (reg->longname, name); |
|
|
135 | if (substr != NULL) |
|
|
136 | return reg; |
|
|
137 | } |
|
|
138 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
139 | if (reg->longname != NULL) |
|
|
140 | { |
|
|
141 | /* |
|
|
142 | * This is not a bug, we want the region that is most identifiably a discrete |
|
|
143 | * area in the game, eg if we have 'scor', we want to return 'scorn' and not |
|
|
144 | * 'scornarena', regardless of their order on the list so we only look at those |
|
|
145 | * regions with a longname set. |
|
|
146 | */ |
|
|
147 | substr = strstr (reg->name, name); |
|
|
148 | if (substr != NULL) |
|
|
149 | return reg; |
|
|
150 | } |
|
|
151 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
152 | { |
|
|
153 | substr = strstr (reg->name, name); |
|
|
154 | if (substr != NULL) |
|
|
155 | return reg; |
|
|
156 | } |
|
|
157 | /* if we are still here, we are going to have to give up, and give the top level region */ |
|
|
158 | for (reg = first_region; reg->parent != NULL; reg = reg->parent); |
|
|
159 | return reg; |
|
|
160 | } |
|
|
161 | |
71 | |
162 | /* |
72 | /* |
163 | * returns 1 if the player is in the region reg, or a child region thereof |
73 | * returns 1 if the player is in the region reg, or a child region thereof |
164 | * otherwise returns 0 |
74 | * otherwise returns 0 |
165 | * if passed a NULL region returns -1 |
75 | * if passed a NULL region returns -1 |
166 | */ |
76 | */ |
167 | |
77 | static int |
168 | int |
|
|
169 | region_is_child_of_region (const region * child, const region * r) |
78 | region_is_child_of_region (const region * child, const region * r) |
170 | { |
79 | { |
|
|
80 | if (!r) |
|
|
81 | return -1; |
171 | |
82 | |
172 | if (r == NULL) |
83 | if (!child) |
173 | return -1; |
|
|
174 | if (child == NULL) |
|
|
175 | return 0; |
84 | return 0; |
|
|
85 | |
176 | if (!strcmp (child->name, r->name)) |
86 | if (child->name == r->name) |
177 | return 1; |
87 | return 1; |
|
|
88 | |
178 | else if (child->parent != NULL) |
89 | if (child->parent) |
179 | return region_is_child_of_region (child->parent, r); |
90 | return region_is_child_of_region (child->parent, r); |
180 | else |
|
|
181 | return 0; |
|
|
182 | } |
|
|
183 | |
91 | |
184 | /* |
92 | return 0; |
185 | * the longname of a region is not a required field, any given region |
|
|
186 | * may want to not set it and use the parent's one instead. so, we: |
|
|
187 | * 1. check if a longname is set and if so return it. |
|
|
188 | * 2. check if there is a parent and try and call the function against that |
|
|
189 | * 3. return a obviously wrong string if we can't get a longname, this should |
|
|
190 | * never happen. We also log a debug message. |
|
|
191 | */ |
|
|
192 | const char * |
|
|
193 | get_region_longname (const region * r) |
|
|
194 | { |
|
|
195 | |
|
|
196 | if (r->longname != NULL) |
|
|
197 | return r->longname; |
|
|
198 | else if (r->parent != NULL) |
|
|
199 | return get_region_longname (r->parent); |
|
|
200 | else |
|
|
201 | { |
|
|
202 | LOG (llevDebug, "NOTICE region %s has no parent and no longname.\n", r->name); |
|
|
203 | return "no name can be found for the current region"; |
|
|
204 | } |
|
|
205 | } |
|
|
206 | |
|
|
207 | const char * |
|
|
208 | get_region_msg (const region * r) |
|
|
209 | { |
|
|
210 | if (r->msg != NULL) |
|
|
211 | return r->msg; |
|
|
212 | else if (r->parent != NULL) |
|
|
213 | return get_region_msg (r->parent); |
|
|
214 | else |
|
|
215 | { |
|
|
216 | LOG (llevDebug, "NOTICE region %s has no parent and no msg.\n", r->name); |
|
|
217 | return "no description can be found for the current region"; |
|
|
218 | } |
|
|
219 | } |
93 | } |
220 | |
94 | |
221 | /** Returns an object which is an exit through which the player represented by op should be |
95 | /** Returns an object which is an exit through which the player represented by op should be |
222 | * sent in order to be imprisoned. If there is no suitable place to which an exit can be |
96 | * sent in order to be imprisoned. If there is no suitable place to which an exit can be |
223 | * constructed, then NULL will be returned. The caller is responsible for freeing the object |
97 | * constructed, then NULL will be returned. The caller is responsible for freeing the object |
224 | * created by this function. |
98 | * created by this function. |
225 | */ |
99 | */ |
226 | object * |
100 | object * |
227 | get_jail_exit (object *op) |
101 | get_jail_exit (object *op) |
228 | { |
102 | { |
229 | region *reg; |
|
|
230 | object *exit; |
|
|
231 | |
|
|
232 | if (op->type != PLAYER) |
103 | if (op->type != PLAYER) |
233 | { |
104 | { |
234 | LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); |
105 | LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); |
235 | return NULL; |
106 | return NULL; |
236 | } |
107 | } |
237 | reg = get_region_by_map (op->map); |
108 | |
|
|
109 | region *reg = op->region (); |
238 | while (reg != NULL) |
110 | while (reg) |
239 | { |
111 | { |
240 | if (reg->jailmap) |
112 | if (reg->jailmap) |
241 | { |
113 | { |
242 | exit = object::create (); |
114 | object *exit = object::create (); |
243 | EXIT_PATH (exit) = reg->jailmap; |
115 | EXIT_PATH (exit) = reg->jailmap; |
244 | /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ |
116 | /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ |
245 | SET_FLAG (exit, FLAG_DAMNED); |
117 | SET_FLAG (exit, FLAG_DAMNED); |
246 | EXIT_X (exit) = reg->jailx; |
118 | EXIT_X (exit) = reg->jailx; |
247 | EXIT_Y (exit) = reg->jaily; |
119 | EXIT_Y (exit) = reg->jaily; |
248 | return exit; |
120 | return exit; |
249 | } |
121 | } |
250 | else |
122 | else |
251 | reg = reg->parent; |
123 | reg = reg->parent; |
252 | } |
124 | } |
|
|
125 | |
253 | LOG (llevDebug, "No suitable jailmap for region %s was found.\n", reg->name); |
126 | LOG (llevError, "No suitable jailmap for region %s was found.\n", ®->name); |
|
|
127 | |
254 | return NULL; |
128 | return 0; |
255 | } |
129 | } |
256 | |
130 | |
257 | /* |
131 | //-GPL |
258 | * First initialises the archtype hash-table (init_archetable()). |
132 | |
259 | * Reads and parses the archetype file (with the first and second-pass |
133 | region * |
260 | * functions). |
134 | region::read (object_thawer &f) |
261 | * Then initialises treasures by calling load_treasures(). |
|
|
262 | */ |
|
|
263 | void |
|
|
264 | init_regions (void) |
|
|
265 | { |
135 | { |
266 | FILE *fp; |
136 | assert (f.kw == KW_region); |
267 | char filename[MAX_BUF]; |
|
|
268 | int comp; |
|
|
269 | |
137 | |
270 | if (first_region != NULL) /* Only do this once */ |
138 | region *rgn = new region; |
271 | return; |
139 | rgn->refcnt_inc (); |
272 | |
140 | |
273 | sprintf (filename, "%s/%s/%s", settings.datadir, settings.mapdir, settings.regions); |
141 | f.get (rgn->name); |
274 | LOG (llevDebug, "Reading regions from %s...\n", filename); |
142 | f.next (); |
275 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
143 | |
|
|
144 | for (;;) |
276 | { |
145 | { |
277 | LOG (llevError, " Can't open regions file %s in init_regions.\n", filename); |
146 | switch (f.kw) |
278 | return; |
147 | { |
|
|
148 | case KW_parent: |
|
|
149 | rgn->parent = region::find (f.get_str ()); |
|
|
150 | break; |
|
|
151 | |
|
|
152 | case KW_msg: f.get_ml (KW_endmsg, rgn->msg); break; |
|
|
153 | case KW_longname: f.get (rgn->longname); break; |
|
|
154 | case KW_jail_map: f.get (rgn->jailmap); break; |
|
|
155 | case KW_jail_x: f.get (rgn->jailx); break; |
|
|
156 | case KW_jail_y: f.get (rgn->jaily); break; |
|
|
157 | case KW_portal_map: f.get (rgn->portalmap);break; |
|
|
158 | case KW_portal_x: f.get (rgn->portalx); break; |
|
|
159 | case KW_portal_y: f.get (rgn->portaly); break; |
|
|
160 | case KW_fallback: f.get (rgn->fallback); break; |
|
|
161 | case KW_chance: f.get (rgn->treasure_density); break; |
|
|
162 | |
|
|
163 | case KW_randomitems: |
|
|
164 | rgn->treasure = treasurelist::get (f.get_str ()); |
|
|
165 | break; |
|
|
166 | |
|
|
167 | case KW_end: |
|
|
168 | f.next (); |
|
|
169 | |
|
|
170 | // cannot use find as that will request the default region |
|
|
171 | for_all_regions (old) |
|
|
172 | if (old->name == rgn->name) |
|
|
173 | { |
|
|
174 | old->destroy (); |
|
|
175 | break; |
|
|
176 | } |
|
|
177 | |
|
|
178 | // just append |
|
|
179 | regions.push_back (rgn); |
|
|
180 | return rgn; |
|
|
181 | |
|
|
182 | case KW_ERROR: |
|
|
183 | rgn->set_key_text (f.kw_str, f.value); |
|
|
184 | //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D |
|
|
185 | break; |
|
|
186 | |
|
|
187 | default: |
|
|
188 | if (!f.parse_error ("region", rgn->name)) |
|
|
189 | { |
|
|
190 | rgn->destroy (); |
|
|
191 | return 0; |
|
|
192 | } |
|
|
193 | break; |
|
|
194 | } |
|
|
195 | |
|
|
196 | f.next (); |
279 | } |
197 | } |
280 | parse_regions (fp); |
|
|
281 | assign_region_parents (); |
|
|
282 | LOG (llevDebug, " done\n"); |
|
|
283 | |
|
|
284 | close_and_delete (fp, comp); |
|
|
285 | } |
198 | } |
286 | |
199 | |
287 | /* |
|
|
288 | * Allocates and zeros a region struct, this isn't free()'d anywhere, so might |
|
|
289 | * be a memory leak, but it shouldn't matter too much since it isn't called that |
|
|
290 | * often.... |
|
|
291 | */ |
|
|
292 | |
|
|
293 | region * |
|
|
294 | get_region_struct (void) |
|
|
295 | { |
|
|
296 | return new region; |
|
|
297 | } |
|
|
298 | |
|
|
299 | /* |
|
|
300 | * Reads/parses the region file, and copies into a linked list |
|
|
301 | * of region structs. |
|
|
302 | */ |
|
|
303 | void |
|
|
304 | parse_regions (FILE * fp) |
|
|
305 | { |
|
|
306 | region *newreg; |
|
|
307 | region *reg; |
|
|
308 | |
|
|
309 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], *key = NULL, *value, *end; |
|
|
310 | int msgpos = 0; |
|
|
311 | |
|
|
312 | newreg = NULL; |
|
|
313 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
|
|
314 | { |
|
|
315 | buf[HUGE_BUF - 1] = 0; |
|
|
316 | key = buf; |
|
|
317 | while (isspace (*key)) |
|
|
318 | key++; |
|
|
319 | if (*key == 0) |
|
|
320 | continue; /* empty line */ |
|
|
321 | value = strchr (key, ' '); |
|
|
322 | if (!value) |
|
|
323 | { |
|
|
324 | end = strchr (key, '\n'); |
|
|
325 | *end = 0; |
|
|
326 | } |
|
|
327 | else |
|
|
328 | { |
|
|
329 | *value = 0; |
|
|
330 | value++; |
|
|
331 | while (isspace (*value)) |
|
|
332 | value++; |
|
|
333 | end = strchr (value, '\n'); |
|
|
334 | } |
|
|
335 | |
|
|
336 | /* |
|
|
337 | * This is a bizzare mutated form of the map and archetype parser |
|
|
338 | * rolled into one. Key is the field name, value is what it should |
|
|
339 | * be set to. |
|
|
340 | * We've already done the work to null terminate key, |
|
|
341 | * and strip off any leading spaces for both of these. |
|
|
342 | * We have not touched the newline at the end of the line - |
|
|
343 | * these might be needed for some values. the end pointer |
|
|
344 | * points to the first of the newlines. |
|
|
345 | * value could be NULL! It would be easy enough to just point |
|
|
346 | * this to "" to prevent cores, but that would let more errors slide |
|
|
347 | * through. |
|
|
348 | */ |
|
|
349 | if (!strcmp (key, "region")) |
|
|
350 | { |
|
|
351 | *end = 0; |
|
|
352 | newreg = get_region_struct (); |
|
|
353 | newreg->name = strdup (value); |
|
|
354 | } |
|
|
355 | else if (!strcmp (key, "parent")) |
|
|
356 | { |
|
|
357 | /* |
|
|
358 | * Note that this is in the initialisation code, so we don't actually |
|
|
359 | * assign the pointer to the parent yet, because it might not have been |
|
|
360 | * parsed. |
|
|
361 | */ |
|
|
362 | *end = 0; |
|
|
363 | newreg->parent_name = strdup (value); |
|
|
364 | } |
|
|
365 | else if (!strcmp (key, "longname")) |
|
|
366 | { |
|
|
367 | *end = 0; |
|
|
368 | newreg->longname = strdup (value); |
|
|
369 | } |
|
|
370 | else if (!strcmp (key, "jail")) |
|
|
371 | { |
|
|
372 | /* jail entries are of the form: /path/to/map x y */ |
|
|
373 | char path[MAX_BUF]; |
|
|
374 | int x, y; |
|
|
375 | |
|
|
376 | if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) |
|
|
377 | { |
|
|
378 | LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); |
|
|
379 | continue; |
|
|
380 | } |
|
|
381 | newreg->jailmap = strdup (path); |
|
|
382 | newreg->jailx = x; |
|
|
383 | newreg->jaily = y; |
|
|
384 | } |
|
|
385 | else if (!strcmp (key, "msg")) |
|
|
386 | { |
|
|
387 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
|
|
388 | { |
|
|
389 | if (!strcmp (buf, "endmsg\n")) |
|
|
390 | break; |
|
|
391 | else |
|
|
392 | { |
|
|
393 | strcpy (msgbuf + msgpos, buf); |
|
|
394 | msgpos += strlen (buf); |
|
|
395 | } |
|
|
396 | } |
|
|
397 | /* |
|
|
398 | * There may be regions with empty messages (eg, msg/endmsg |
|
|
399 | * with nothing between). When maps are loaded, this is done |
|
|
400 | * so better do it here too... |
|
|
401 | */ |
|
|
402 | if (msgpos != 0) |
|
|
403 | newreg->msg = strdup (msgbuf); |
|
|
404 | |
|
|
405 | /* we have to reset msgpos, or the next region will store both msg blocks. */ |
|
|
406 | msgpos = 0; |
|
|
407 | } |
|
|
408 | else if (!strcmp (key, "fallback")) |
|
|
409 | { |
|
|
410 | *end = 0; |
|
|
411 | newreg->fallback = atoi (value); |
|
|
412 | } |
|
|
413 | else if (!strcmp (key, "end")) |
|
|
414 | { |
|
|
415 | /* Place this new region last on the list, if the list is empty put it first */ |
|
|
416 | for (reg = first_region; reg != NULL && reg->next != NULL; reg = reg->next); |
|
|
417 | |
|
|
418 | if (reg == NULL) |
|
|
419 | first_region = newreg; |
|
|
420 | else |
|
|
421 | reg->next = newreg; |
|
|
422 | newreg = NULL; |
|
|
423 | } |
|
|
424 | else if (!strcmp (key, "nomore")) |
|
|
425 | { |
|
|
426 | /* we have reached the end of the region specs.... */ |
|
|
427 | break; |
|
|
428 | } |
|
|
429 | else |
|
|
430 | { |
|
|
431 | /* we should never get here, if we have, then something is wrong */ |
|
|
432 | LOG (llevError, "Got unknown value in region file: %s %s\n", key, value); |
|
|
433 | } |
|
|
434 | } |
|
|
435 | if (!key || strcmp (key, "nomore")) |
|
|
436 | LOG (llevError, "Got premature eof on regions file!\n"); |
|
|
437 | } |
|
|
438 | |
|
|
439 | void |
|
|
440 | assign_region_parents (void) |
|
|
441 | { |
|
|
442 | region *reg; |
|
|
443 | uint32 parent_count = 0; |
|
|
444 | uint32 region_count = 0; |
|
|
445 | |
|
|
446 | for (reg = first_region; reg != NULL && reg->next != NULL; reg = reg->next) |
|
|
447 | { |
|
|
448 | if (reg->parent_name != NULL) |
|
|
449 | { |
|
|
450 | reg->parent = get_region_by_name (reg->parent_name); |
|
|
451 | parent_count++; |
|
|
452 | } |
|
|
453 | region_count++; |
|
|
454 | } |
|
|
455 | LOG (llevDebug, "Assigned %u regions with %u parents.\n", region_count, parent_count); |
|
|
456 | } |
|
|