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