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