… | |
… | |
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 |
… | |
… | |
1736 | |
1670 | |
1737 | // instead of crashing in the unlikely(?) case, try to return *something* |
1671 | // instead of crashing in the unlikely(?) case, try to return *something* |
1738 | return get_archetype ("blocked"); |
1672 | return get_archetype ("blocked"); |
1739 | } |
1673 | } |
1740 | |
1674 | |
|
|
1675 | /** |
|
|
1676 | * Maximum distance a player may hear a sound from. |
|
|
1677 | * This is only used for new client/server sound. If the sound source |
|
|
1678 | * on the map is farther away than this, we don't sent it to the client. |
|
|
1679 | */ |
|
|
1680 | #define MAX_SOUND_DISTANCE 10 |
|
|
1681 | |
|
|
1682 | void |
|
|
1683 | maptile::play_sound (faceidx sound, int x, int y) const |
|
|
1684 | { |
|
|
1685 | if (!sound) |
|
|
1686 | return; |
|
|
1687 | |
|
|
1688 | for_all_players (pl) |
|
|
1689 | if (pl->ob->map == this) |
|
|
1690 | if (client *ns = pl->ns) |
|
|
1691 | { |
|
|
1692 | int dx = x - pl->ob->x; |
|
|
1693 | int dy = y - pl->ob->y; |
|
|
1694 | |
|
|
1695 | int distance = idistance (dx, dy); |
|
|
1696 | |
|
|
1697 | if (distance <= MAX_SOUND_DISTANCE) |
|
|
1698 | ns->play_sound (sound, dx, dy); |
|
|
1699 | } |
|
|
1700 | } |
|
|
1701 | |