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