1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | 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 |
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 2 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, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | |
25 | |
25 | #include <global.h> |
26 | #include <global.h> |
26 | |
|
|
27 | #ifndef WIN32 /* ---win32 exclude header */ |
|
|
28 | # include <unistd.h> |
27 | #include <unistd.h> |
29 | #endif /* win32 */ |
|
|
30 | |
28 | |
31 | /* |
29 | /* |
32 | * Pass a char array, returns a pointer to the region of the same name. |
30 | * Pass a char array, returns a pointer to the region of the same name. |
33 | * if it can't find a region of the same name it returns the first region |
31 | * if it can't find a region of the same name it returns the first region |
34 | * with the 'fallback' property set. |
32 | * with the 'fallback' property set. |
… | |
… | |
60 | return NULL; |
58 | return NULL; |
61 | } |
59 | } |
62 | |
60 | |
63 | /* This might need optimising at some point. */ |
61 | /* This might need optimising at some point. */ |
64 | region * |
62 | region * |
65 | get_region_by_map (mapstruct *m) |
63 | get_region_by_map (maptile *m) |
66 | { |
64 | { |
67 | return get_region_by_name (get_name_of_region_for_map (m)); |
65 | return get_region_by_name (get_name_of_region_for_map (m)); |
68 | } |
66 | } |
69 | |
67 | |
70 | /* |
68 | /* |
… | |
… | |
72 | * explicit check that it is, this is much nicer here than scattered throughout |
70 | * explicit check that it is, this is much nicer here than scattered throughout |
73 | * the map code. |
71 | * the map code. |
74 | */ |
72 | */ |
75 | |
73 | |
76 | const char * |
74 | const char * |
77 | get_name_of_region_for_map (const mapstruct *m) |
75 | get_name_of_region_for_map (const maptile *m) |
78 | { |
76 | { |
79 | region *reg; |
77 | region *reg; |
80 | |
78 | |
81 | if (m->region != NULL) |
79 | if (m->region) |
82 | return m->region->name; |
80 | return m->region->name; |
|
|
81 | |
83 | for (reg = first_region; reg != NULL; reg = reg->next) |
82 | for (reg = first_region; reg != NULL; reg = reg->next) |
84 | { |
83 | { |
85 | if (reg->fallback) |
84 | if (reg->fallback) |
86 | return reg->name; |
85 | return reg->name; |
87 | } |
86 | } |
|
|
87 | |
88 | LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", m->name); |
88 | LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", &m->name); |
89 | return "unknown"; |
89 | return "unknown"; |
90 | } |
90 | } |
91 | |
91 | |
92 | /* |
92 | /* |
93 | * Tries to find a region that 'name' corresponds to. |
93 | * Tries to find a region that 'name' corresponds to. |
… | |
… | |
237 | reg = get_region_by_map (op->map); |
237 | reg = get_region_by_map (op->map); |
238 | while (reg != NULL) |
238 | while (reg != NULL) |
239 | { |
239 | { |
240 | if (reg->jailmap) |
240 | if (reg->jailmap) |
241 | { |
241 | { |
242 | exit = get_object (); |
242 | exit = object::create (); |
243 | EXIT_PATH (exit) = reg->jailmap; |
243 | EXIT_PATH (exit) = reg->jailmap; |
244 | /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ |
244 | /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ |
245 | SET_FLAG (exit, FLAG_DAMNED); |
245 | SET_FLAG (exit, FLAG_DAMNED); |
246 | EXIT_X (exit) = reg->jailx; |
246 | EXIT_X (exit) = reg->jailx; |
247 | EXIT_Y (exit) = reg->jaily; |
247 | EXIT_Y (exit) = reg->jaily; |
… | |
… | |
291 | */ |
291 | */ |
292 | |
292 | |
293 | region * |
293 | region * |
294 | get_region_struct (void) |
294 | get_region_struct (void) |
295 | { |
295 | { |
296 | |
|
|
297 | region *reg; |
|
|
298 | |
|
|
299 | reg = (region *) CALLOC (1, sizeof (region)); |
|
|
300 | if (reg == NULL) |
|
|
301 | fatal (OUT_OF_MEMORY); |
|
|
302 | |
|
|
303 | memset (reg, '\0', sizeof (region)); |
|
|
304 | |
|
|
305 | return reg; |
296 | return new region; |
306 | } |
297 | } |
307 | |
298 | |
308 | /* |
299 | /* |
309 | * Reads/parses the region file, and copies into a linked list |
300 | * Reads/parses the region file, and copies into a linked list |
310 | * of region structs. |
301 | * of region structs. |
… | |
… | |
357 | */ |
348 | */ |
358 | if (!strcmp (key, "region")) |
349 | if (!strcmp (key, "region")) |
359 | { |
350 | { |
360 | *end = 0; |
351 | *end = 0; |
361 | newreg = get_region_struct (); |
352 | newreg = get_region_struct (); |
362 | newreg->name = strdup_local (value); |
353 | newreg->name = strdup (value); |
363 | } |
354 | } |
364 | else if (!strcmp (key, "parent")) |
355 | else if (!strcmp (key, "parent")) |
365 | { |
356 | { |
366 | /* |
357 | /* |
367 | * Note that this is in the initialisation code, so we don't actually |
358 | * Note that this is in the initialisation code, so we don't actually |
368 | * assign the pointer to the parent yet, because it might not have been |
359 | * assign the pointer to the parent yet, because it might not have been |
369 | * parsed. |
360 | * parsed. |
370 | */ |
361 | */ |
371 | *end = 0; |
362 | *end = 0; |
372 | newreg->parent_name = strdup_local (value); |
363 | newreg->parent_name = strdup (value); |
373 | } |
364 | } |
374 | else if (!strcmp (key, "longname")) |
365 | else if (!strcmp (key, "longname")) |
375 | { |
366 | { |
376 | *end = 0; |
367 | *end = 0; |
377 | newreg->longname = strdup_local (value); |
368 | newreg->longname = strdup (value); |
378 | } |
369 | } |
379 | else if (!strcmp (key, "jail")) |
370 | else if (!strcmp (key, "jail")) |
380 | { |
371 | { |
381 | /* jail entries are of the form: /path/to/map x y */ |
372 | /* jail entries are of the form: /path/to/map x y */ |
382 | char path[MAX_BUF]; |
373 | char path[MAX_BUF]; |
… | |
… | |
385 | if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) |
376 | if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) |
386 | { |
377 | { |
387 | LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); |
378 | LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); |
388 | continue; |
379 | continue; |
389 | } |
380 | } |
390 | newreg->jailmap = strdup_local (path); |
381 | newreg->jailmap = strdup (path); |
391 | newreg->jailx = x; |
382 | newreg->jailx = x; |
392 | newreg->jaily = y; |
383 | newreg->jaily = y; |
393 | } |
384 | } |
394 | else if (!strcmp (key, "msg")) |
385 | else if (!strcmp (key, "msg")) |
395 | { |
386 | { |
… | |
… | |
407 | * There may be regions with empty messages (eg, msg/endmsg |
398 | * There may be regions with empty messages (eg, msg/endmsg |
408 | * with nothing between). When maps are loaded, this is done |
399 | * with nothing between). When maps are loaded, this is done |
409 | * so better do it here too... |
400 | * so better do it here too... |
410 | */ |
401 | */ |
411 | if (msgpos != 0) |
402 | if (msgpos != 0) |
412 | newreg->msg = strdup_local (msgbuf); |
403 | newreg->msg = strdup (msgbuf); |
413 | |
404 | |
414 | /* we have to reset msgpos, or the next region will store both msg blocks. */ |
405 | /* we have to reset msgpos, or the next region will store both msg blocks. */ |
415 | msgpos = 0; |
406 | msgpos = 0; |
416 | } |
407 | } |
417 | else if (!strcmp (key, "fallback")) |
408 | else if (!strcmp (key, "fallback")) |
… | |
… | |
459 | reg->parent = get_region_by_name (reg->parent_name); |
450 | reg->parent = get_region_by_name (reg->parent_name); |
460 | parent_count++; |
451 | parent_count++; |
461 | } |
452 | } |
462 | region_count++; |
453 | region_count++; |
463 | } |
454 | } |
464 | LOG (llevDebug, "Assigned %u regions with %u parents.", region_count, parent_count); |
455 | LOG (llevDebug, "Assigned %u regions with %u parents.\n", region_count, parent_count); |
465 | } |
456 | } |