… | |
… | |
27 | #include "funcpoint.h" |
27 | #include "funcpoint.h" |
28 | |
28 | |
29 | #include "loader.h" |
29 | #include "loader.h" |
30 | |
30 | |
31 | #include "path.h" |
31 | #include "path.h" |
32 | |
|
|
33 | /* |
|
|
34 | * This makes a path absolute outside the world of Crossfire. |
|
|
35 | * In other words, it prepends LIBDIR/MAPDIR/ to the given path |
|
|
36 | * and returns the pointer to a static array containing the result. |
|
|
37 | * it really should be called create_mapname |
|
|
38 | */ |
|
|
39 | const char * |
|
|
40 | create_pathname (const char *name) |
|
|
41 | { |
|
|
42 | static char buf[8192]; |
|
|
43 | snprintf (buf, sizeof (buf), "%s/%s/%s", settings.datadir, settings.mapdir, name); |
|
|
44 | return buf; |
|
|
45 | } |
|
|
46 | |
|
|
47 | /* |
|
|
48 | * This function checks if a file with the given path exists. |
|
|
49 | * -1 is returned if it fails, otherwise the mode of the file |
|
|
50 | * is returned. |
|
|
51 | * It tries out all the compression suffixes listed in the uncomp[] array. |
|
|
52 | * |
|
|
53 | * If prepend_dir is set, then we call create_pathname (which prepends |
|
|
54 | * libdir & mapdir). Otherwise, we assume the name given is fully |
|
|
55 | * complete. |
|
|
56 | * Only the editor actually cares about the writablity of this - |
|
|
57 | * the rest of the code only cares that the file is readable. |
|
|
58 | * when the editor goes away, the call to stat should probably be |
|
|
59 | * replaced by an access instead (similar to the windows one, but |
|
|
60 | * that seems to be missing the prepend_dir processing |
|
|
61 | */ |
|
|
62 | int |
|
|
63 | check_path (const char *name, int prepend_dir) |
|
|
64 | { |
|
|
65 | char buf[MAX_BUF]; |
|
|
66 | |
|
|
67 | char *endbuf; |
|
|
68 | struct stat statbuf; |
|
|
69 | int mode = 0; |
|
|
70 | |
|
|
71 | if (prepend_dir) |
|
|
72 | assign (buf, create_pathname (name)); |
|
|
73 | else |
|
|
74 | assign (buf, name); |
|
|
75 | |
|
|
76 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
|
|
77 | * this method should be equivalant and is clearer. |
|
|
78 | * Can not use strcat because we need to cycle through |
|
|
79 | * all the names. |
|
|
80 | */ |
|
|
81 | endbuf = buf + strlen (buf); |
|
|
82 | |
|
|
83 | if (stat (buf, &statbuf)) |
|
|
84 | return -1; |
|
|
85 | if (!S_ISREG (statbuf.st_mode)) |
|
|
86 | return (-1); |
|
|
87 | |
|
|
88 | if (((statbuf.st_mode & S_IRGRP) && getegid () == statbuf.st_gid) || |
|
|
89 | ((statbuf.st_mode & S_IRUSR) && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IROTH)) |
|
|
90 | mode |= 4; |
|
|
91 | |
|
|
92 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
|
|
93 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
|
|
94 | mode |= 2; |
|
|
95 | |
|
|
96 | return (mode); |
|
|
97 | } |
|
|
98 | |
32 | |
99 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
33 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
100 | * one function that just returns a P_.. value (see map.h) |
34 | * one function that just returns a P_.. value (see map.h) |
101 | * it will also do map translation for tiled maps, returning |
35 | * it will also do map translation for tiled maps, returning |
102 | * new values into newmap, nx, and ny. Any and all of those |
36 | * new values into newmap, nx, and ny. Any and all of those |
… | |
… | |
421 | } |
355 | } |
422 | |
356 | |
423 | void |
357 | void |
424 | maptile::activate () |
358 | maptile::activate () |
425 | { |
359 | { |
426 | active = true; |
|
|
427 | |
|
|
428 | if (spaces) |
360 | if (spaces) |
429 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
361 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
430 | for (object *op = ms->bot; op; op = op->above) |
362 | for (object *op = ms->bot; op; op = op->above) |
431 | op->activate_recursive (); |
363 | op->activate_recursive (); |
432 | } |
364 | } |
433 | |
365 | |
434 | void |
366 | void |
435 | maptile::deactivate () |
367 | maptile::deactivate () |
436 | { |
368 | { |
437 | active = false; |
|
|
438 | |
|
|
439 | if (spaces) |
369 | if (spaces) |
440 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
370 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
441 | for (object *op = ms->bot; op; op = op->above) |
371 | for (object *op = ms->bot; op; op = op->above) |
442 | op->deactivate_recursive (); |
372 | op->deactivate_recursive (); |
443 | } |
373 | } |
… | |
… | |
746 | case KW_tile_path_1: thawer.get (tile_path [0]); break; |
676 | case KW_tile_path_1: thawer.get (tile_path [0]); break; |
747 | case KW_tile_path_2: thawer.get (tile_path [1]); break; |
677 | case KW_tile_path_2: thawer.get (tile_path [1]); break; |
748 | case KW_tile_path_3: thawer.get (tile_path [2]); break; |
678 | case KW_tile_path_3: thawer.get (tile_path [2]); break; |
749 | case KW_tile_path_4: thawer.get (tile_path [3]); break; |
679 | case KW_tile_path_4: thawer.get (tile_path [3]); break; |
750 | |
680 | |
|
|
681 | case KW_ERROR: |
|
|
682 | set_key (thawer.kw_str, thawer.value); |
|
|
683 | break; |
|
|
684 | |
751 | case KW_end: |
685 | case KW_end: |
752 | return true; |
686 | return true; |
753 | |
687 | |
754 | default: |
688 | default: |
755 | if (!thawer.parse_error ("map", 0)) |
689 | if (!thawer.parse_error ("map", 0)) |
… | |
… | |
876 | * Remove and free all objects in the given map. |
810 | * Remove and free all objects in the given map. |
877 | */ |
811 | */ |
878 | void |
812 | void |
879 | maptile::clear () |
813 | maptile::clear () |
880 | { |
814 | { |
881 | sfree (regions, size ()), regions = 0; |
815 | sfree (regions, size ()); regions = 0; |
882 | free (regionmap), regionmap = 0; |
816 | delete [] regionmap; regionmap = 0; |
883 | |
817 | |
884 | if (spaces) |
818 | if (spaces) |
885 | { |
819 | { |
886 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
820 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
887 | while (object *op = ms->bot) |
821 | while (object *op = ms->bot) |
… | |
… | |
1732 | |
1666 | |
1733 | // instead of crashing in the unlikely(?) case, try to return *something* |
1667 | // instead of crashing in the unlikely(?) case, try to return *something* |
1734 | return get_archetype ("blocked"); |
1668 | return get_archetype ("blocked"); |
1735 | } |
1669 | } |
1736 | |
1670 | |
|
|
1671 | void |
|
|
1672 | maptile::play_sound (faceidx sound, int x, int y) const |
|
|
1673 | { |
|
|
1674 | if (!sound) |
|
|
1675 | return; |
|
|
1676 | |
|
|
1677 | for_all_players (pl) |
|
|
1678 | if (pl->ob->map == this) |
|
|
1679 | if (client *ns = pl->ns) |
|
|
1680 | { |
|
|
1681 | int dx = x - pl->ob->x; |
|
|
1682 | int dy = y - pl->ob->y; |
|
|
1683 | |
|
|
1684 | int distance = idistance (dx, dy); |
|
|
1685 | |
|
|
1686 | if (distance <= MAX_SOUND_DISTANCE) |
|
|
1687 | ns->play_sound (sound, dx, dy); |
|
|
1688 | } |
|
|
1689 | } |
|
|
1690 | |