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.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.18 by root, Sat Jan 27 23:59:29 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines