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