1 |
root |
1.3 |
|
2 |
elmex |
1.1 |
/* |
3 |
|
|
* static char *rcsid_sound_c = |
4 |
root |
1.3 |
* "$Id: sounds.C,v 1.2 2006-08-29 08:01:38 root Exp $"; |
5 |
elmex |
1.1 |
*/ |
6 |
|
|
|
7 |
|
|
/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* \file |
11 |
|
|
* Sound-related functions. |
12 |
|
|
* |
13 |
|
|
* \date 2003-12-02 |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
#include <global.h> |
17 |
|
|
#include <sproto.h> |
18 |
|
|
#include <sounds.h> |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* Maximum distance a player may hear a sound from. |
22 |
|
|
* This is only used for new client/server sound. If the sound source |
23 |
|
|
* on the map is farther away than this, we don't sent it to the client. |
24 |
|
|
*/ |
25 |
|
|
#define MAX_SOUND_DISTANCE 10 |
26 |
|
|
|
27 |
|
|
/** |
28 |
|
|
* Plays a sound for specified player only |
29 |
|
|
*/ |
30 |
root |
1.3 |
void |
31 |
|
|
play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) |
32 |
elmex |
1.1 |
{ |
33 |
root |
1.3 |
char soundtype; |
34 |
|
|
SockList sl; |
35 |
elmex |
1.1 |
|
36 |
root |
1.3 |
if (!pl->socket.sound) |
37 |
|
|
return; |
38 |
|
|
/* Do some quick conversion to the sound type we want. */ |
39 |
|
|
if (soundnum >= SOUND_CAST_SPELL_0) |
40 |
|
|
{ |
41 |
|
|
soundtype = SOUND_SPELL; |
42 |
|
|
soundnum -= SOUND_CAST_SPELL_0; |
43 |
elmex |
1.1 |
} |
44 |
root |
1.3 |
else |
45 |
|
|
soundtype = SOUND_NORMAL; |
46 |
elmex |
1.1 |
|
47 |
root |
1.3 |
sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
48 |
|
|
strcpy ((char *) sl.buf, "sound "); |
49 |
|
|
sl.len = strlen ((char *) sl.buf); |
50 |
|
|
SockList_AddChar (&sl, x); |
51 |
|
|
SockList_AddChar (&sl, y); |
52 |
|
|
SockList_AddShort (&sl, soundnum); |
53 |
|
|
SockList_AddChar (&sl, soundtype); |
54 |
|
|
Send_With_Handling (&pl->socket, &sl); |
55 |
|
|
free (sl.buf); |
56 |
elmex |
1.1 |
} |
57 |
|
|
|
58 |
|
|
#define POW2(x) ((x) * (x)) |
59 |
|
|
|
60 |
|
|
/** Plays some sound on map at x,y. */ |
61 |
root |
1.3 |
void |
62 |
|
|
play_sound_map (mapstruct *map, int x, int y, short sound_num) |
63 |
elmex |
1.1 |
{ |
64 |
root |
1.3 |
player *pl; |
65 |
elmex |
1.1 |
|
66 |
root |
1.3 |
if (sound_num >= NROF_SOUNDS) |
67 |
|
|
{ |
68 |
|
|
LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); |
69 |
|
|
return; |
70 |
elmex |
1.1 |
} |
71 |
|
|
|
72 |
root |
1.3 |
for (pl = first_player; pl; pl = pl->next) |
73 |
|
|
{ |
74 |
|
|
if (pl->ob->map == map) |
75 |
|
|
{ |
76 |
|
|
int distance = isqrt (POW2 (pl->ob->x - x) + POW2 (pl->ob->y - y)); |
77 |
|
|
|
78 |
|
|
if (distance <= MAX_SOUND_DISTANCE) |
79 |
|
|
{ |
80 |
|
|
play_sound_player_only (pl, sound_num, (sint8) (x - pl->ob->x), (sint8) (y - pl->ob->y)); |
81 |
root |
1.2 |
} |
82 |
|
|
} |
83 |
elmex |
1.1 |
} |
84 |
|
|
} |