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