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