1 | /* |
|
|
2 | * static char *rcsid_sound_c = |
|
|
3 | * "$Id: sounds.C,v 1.2 2006/08/29 08:01:38 root Exp $"; |
|
|
4 | */ |
|
|
5 | |
|
|
6 | /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
1 | /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
7 | |
2 | |
8 | /** |
3 | /** |
9 | * \file |
4 | * \file |
10 | * Sound-related functions. |
5 | * Sound-related functions. |
… | |
… | |
24 | #define MAX_SOUND_DISTANCE 10 |
19 | #define MAX_SOUND_DISTANCE 10 |
25 | |
20 | |
26 | /** |
21 | /** |
27 | * Plays a sound for specified player only |
22 | * Plays a sound for specified player only |
28 | */ |
23 | */ |
|
|
24 | void |
29 | void play_sound_player_only(player *pl, short soundnum, sint8 x, sint8 y) |
25 | play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) |
30 | { |
26 | { |
31 | char soundtype; |
27 | char soundtype; |
32 | SockList sl; |
|
|
33 | |
28 | |
34 | if (!pl->socket.sound) return; |
29 | if (!pl->ns->sound) |
|
|
30 | return; |
|
|
31 | |
35 | /* Do some quick conversion to the sound type we want. */ |
32 | /* Do some quick conversion to the sound type we want. */ |
36 | if (soundnum>=SOUND_CAST_SPELL_0) { |
33 | if (soundnum >= SOUND_CAST_SPELL_0) |
|
|
34 | { |
37 | soundtype=SOUND_SPELL; |
35 | soundtype = SOUND_SPELL; |
38 | soundnum -=SOUND_CAST_SPELL_0; |
36 | soundnum -= SOUND_CAST_SPELL_0; |
39 | } |
37 | } |
|
|
38 | else |
40 | else soundtype=SOUND_NORMAL; |
39 | soundtype = SOUND_NORMAL; |
41 | |
40 | |
42 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
41 | packet sl; |
43 | strcpy((char*)sl.buf, "sound "); |
42 | |
44 | sl.len=strlen((char*)sl.buf); |
43 | sl << "sound " |
45 | SockList_AddChar(&sl, x); |
44 | << uint8 (x) |
46 | SockList_AddChar(&sl, y); |
45 | << uint8 (y) |
47 | SockList_AddShort(&sl, soundnum); |
46 | << uint16 (soundnum) |
48 | SockList_AddChar(&sl, soundtype); |
47 | << uint8 (soundtype); |
49 | Send_With_Handling(&pl->socket, &sl); |
48 | |
50 | free(sl.buf); |
49 | pl->ns->send_packet (sl); |
51 | } |
50 | } |
52 | |
51 | |
53 | #define POW2(x) ((x) * (x)) |
52 | #define POW2(x) ((x) * (x)) |
54 | |
53 | |
55 | /** Plays some sound on map at x,y. */ |
54 | /** Plays some sound on map at x,y. */ |
|
|
55 | void |
56 | void play_sound_map(mapstruct *map, int x, int y, short sound_num) |
56 | play_sound_map (maptile *map, int x, int y, short sound_num) |
57 | { |
57 | { |
58 | player *pl; |
|
|
59 | |
|
|
60 | if (sound_num >= NROF_SOUNDS) { |
58 | if (sound_num >= NROF_SOUNDS) |
|
|
59 | { |
61 | LOG(llevError,"Tried to play an invalid sound num: %d\n", sound_num); |
60 | LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); |
62 | return; |
61 | return; |
63 | } |
62 | } |
64 | |
63 | |
65 | for (pl = first_player; pl; pl = pl->next) { |
64 | for_all_players (pl) |
|
|
65 | { |
66 | if (pl->ob->map == map) { |
66 | if (pl->ob->map == map) |
|
|
67 | { |
67 | int distance=isqrt(POW2(pl->ob->x - x) + POW2(pl->ob->y - y)); |
68 | int distance = isqrt (POW2 (pl->ob->x - x) + POW2 (pl->ob->y - y)); |
68 | |
69 | |
69 | if (distance<=MAX_SOUND_DISTANCE) { |
70 | if (distance <= MAX_SOUND_DISTANCE) |
|
|
71 | { |
70 | play_sound_player_only(pl, sound_num, ( sint8 )( x-pl->ob->x ), ( sint8 )( y-pl->ob->y )); |
72 | play_sound_player_only (pl, sound_num, (sint8) (x - pl->ob->x), (sint8) (y - pl->ob->y)); |
71 | } |
73 | } |
72 | } |
74 | } |
73 | } |
75 | } |
74 | } |
76 | } |