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