1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_map_c = |
|
|
4 | * "$Id: region.C,v 1.4 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | 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 |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | 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> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | |
24 | |
31 | #include <global.h> |
25 | #include <global.h> |
32 | |
|
|
33 | #ifndef WIN32 /* ---win32 exclude header */ |
|
|
34 | # include <unistd.h> |
26 | #include <unistd.h> |
35 | #endif /* win32 */ |
|
|
36 | |
27 | |
37 | /* |
28 | /* |
38 | * 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. |
39 | * 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 |
40 | * with the 'fallback' property set. |
31 | * with the 'fallback' property set. |
… | |
… | |
66 | return NULL; |
57 | return NULL; |
67 | } |
58 | } |
68 | |
59 | |
69 | /* This might need optimising at some point. */ |
60 | /* This might need optimising at some point. */ |
70 | region * |
61 | region * |
71 | get_region_by_map (mapstruct *m) |
62 | get_region_by_map (maptile *m) |
72 | { |
63 | { |
73 | 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)); |
74 | } |
65 | } |
75 | |
66 | |
76 | /* |
67 | /* |
… | |
… | |
78 | * 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 |
79 | * the map code. |
70 | * the map code. |
80 | */ |
71 | */ |
81 | |
72 | |
82 | const char * |
73 | const char * |
83 | get_name_of_region_for_map (const mapstruct *m) |
74 | get_name_of_region_for_map (const maptile *m) |
84 | { |
75 | { |
85 | region *reg; |
76 | region *reg; |
86 | |
77 | |
87 | if (m->region != NULL) |
78 | if (m->region) |
88 | return m->region->name; |
79 | return m->region->name; |
|
|
80 | |
89 | for (reg = first_region; reg != NULL; reg = reg->next) |
81 | for (reg = first_region; reg != NULL; reg = reg->next) |
90 | { |
82 | { |
91 | if (reg->fallback) |
83 | if (reg->fallback) |
92 | return reg->name; |
84 | return reg->name; |
93 | } |
85 | } |
|
|
86 | |
94 | 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); |
95 | return "unknown"; |
88 | return "unknown"; |
96 | } |
89 | } |
97 | |
90 | |
98 | /* |
91 | /* |
99 | * Tries to find a region that 'name' corresponds to. |
92 | * Tries to find a region that 'name' corresponds to. |
… | |
… | |
243 | reg = get_region_by_map (op->map); |
236 | reg = get_region_by_map (op->map); |
244 | while (reg != NULL) |
237 | while (reg != NULL) |
245 | { |
238 | { |
246 | if (reg->jailmap) |
239 | if (reg->jailmap) |
247 | { |
240 | { |
248 | exit = get_object (); |
241 | exit = object::create (); |
249 | EXIT_PATH (exit) = reg->jailmap; |
242 | EXIT_PATH (exit) = reg->jailmap; |
250 | /* 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 */ |
251 | SET_FLAG (exit, FLAG_DAMNED); |
244 | SET_FLAG (exit, FLAG_DAMNED); |
252 | EXIT_X (exit) = reg->jailx; |
245 | EXIT_X (exit) = reg->jailx; |
253 | EXIT_Y (exit) = reg->jaily; |
246 | EXIT_Y (exit) = reg->jaily; |
… | |
… | |
297 | */ |
290 | */ |
298 | |
291 | |
299 | region * |
292 | region * |
300 | get_region_struct (void) |
293 | get_region_struct (void) |
301 | { |
294 | { |
302 | |
|
|
303 | region *reg; |
|
|
304 | |
|
|
305 | reg = (region *) CALLOC (1, sizeof (region)); |
|
|
306 | if (reg == NULL) |
|
|
307 | fatal (OUT_OF_MEMORY); |
|
|
308 | |
|
|
309 | memset (reg, '\0', sizeof (region)); |
|
|
310 | |
|
|
311 | return reg; |
295 | return new region; |
312 | } |
296 | } |
313 | |
297 | |
314 | /* |
298 | /* |
315 | * Reads/parses the region file, and copies into a linked list |
299 | * Reads/parses the region file, and copies into a linked list |
316 | * of region structs. |
300 | * of region structs. |
… | |
… | |
363 | */ |
347 | */ |
364 | if (!strcmp (key, "region")) |
348 | if (!strcmp (key, "region")) |
365 | { |
349 | { |
366 | *end = 0; |
350 | *end = 0; |
367 | newreg = get_region_struct (); |
351 | newreg = get_region_struct (); |
368 | newreg->name = strdup_local (value); |
352 | newreg->name = strdup (value); |
369 | } |
353 | } |
370 | else if (!strcmp (key, "parent")) |
354 | else if (!strcmp (key, "parent")) |
371 | { |
355 | { |
372 | /* |
356 | /* |
373 | * 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 |
374 | * 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 |
375 | * parsed. |
359 | * parsed. |
376 | */ |
360 | */ |
377 | *end = 0; |
361 | *end = 0; |
378 | newreg->parent_name = strdup_local (value); |
362 | newreg->parent_name = strdup (value); |
379 | } |
363 | } |
380 | else if (!strcmp (key, "longname")) |
364 | else if (!strcmp (key, "longname")) |
381 | { |
365 | { |
382 | *end = 0; |
366 | *end = 0; |
383 | newreg->longname = strdup_local (value); |
367 | newreg->longname = strdup (value); |
384 | } |
368 | } |
385 | else if (!strcmp (key, "jail")) |
369 | else if (!strcmp (key, "jail")) |
386 | { |
370 | { |
387 | /* jail entries are of the form: /path/to/map x y */ |
371 | /* jail entries are of the form: /path/to/map x y */ |
388 | char path[MAX_BUF]; |
372 | char path[MAX_BUF]; |
… | |
… | |
391 | if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) |
375 | if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) |
392 | { |
376 | { |
393 | LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); |
377 | LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); |
394 | continue; |
378 | continue; |
395 | } |
379 | } |
396 | newreg->jailmap = strdup_local (path); |
380 | newreg->jailmap = strdup (path); |
397 | newreg->jailx = x; |
381 | newreg->jailx = x; |
398 | newreg->jaily = y; |
382 | newreg->jaily = y; |
399 | } |
383 | } |
400 | else if (!strcmp (key, "msg")) |
384 | else if (!strcmp (key, "msg")) |
401 | { |
385 | { |
… | |
… | |
413 | * There may be regions with empty messages (eg, msg/endmsg |
397 | * There may be regions with empty messages (eg, msg/endmsg |
414 | * with nothing between). When maps are loaded, this is done |
398 | * with nothing between). When maps are loaded, this is done |
415 | * so better do it here too... |
399 | * so better do it here too... |
416 | */ |
400 | */ |
417 | if (msgpos != 0) |
401 | if (msgpos != 0) |
418 | newreg->msg = strdup_local (msgbuf); |
402 | newreg->msg = strdup (msgbuf); |
419 | |
403 | |
420 | /* 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. */ |
421 | msgpos = 0; |
405 | msgpos = 0; |
422 | } |
406 | } |
423 | else if (!strcmp (key, "fallback")) |
407 | else if (!strcmp (key, "fallback")) |
… | |
… | |
465 | reg->parent = get_region_by_name (reg->parent_name); |
449 | reg->parent = get_region_by_name (reg->parent_name); |
466 | parent_count++; |
450 | parent_count++; |
467 | } |
451 | } |
468 | region_count++; |
452 | region_count++; |
469 | } |
453 | } |
470 | 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); |
471 | } |
455 | } |