… | |
… | |
23 | */ |
23 | */ |
24 | void |
24 | void |
25 | 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) |
26 | { |
26 | { |
27 | char soundtype; |
27 | char soundtype; |
28 | SockList sl; |
|
|
29 | |
28 | |
30 | if (!pl->socket.sound) |
29 | if (!pl->ns->sound) |
31 | return; |
30 | return; |
|
|
31 | |
32 | /* Do some quick conversion to the sound type we want. */ |
32 | /* Do some quick conversion to the sound type we want. */ |
33 | if (soundnum >= SOUND_CAST_SPELL_0) |
33 | if (soundnum >= SOUND_CAST_SPELL_0) |
34 | { |
34 | { |
35 | soundtype = SOUND_SPELL; |
35 | soundtype = SOUND_SPELL; |
36 | soundnum -= SOUND_CAST_SPELL_0; |
36 | soundnum -= SOUND_CAST_SPELL_0; |
37 | } |
37 | } |
38 | else |
38 | else |
39 | soundtype = SOUND_NORMAL; |
39 | soundtype = SOUND_NORMAL; |
40 | |
40 | |
41 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
41 | packet sl; |
42 | strcpy ((char *) sl.buf, "sound "); |
42 | |
43 | sl.len = strlen ((char *) sl.buf); |
43 | sl << "sound " |
44 | SockList_AddChar (&sl, x); |
44 | << uint8 (x) |
45 | SockList_AddChar (&sl, y); |
45 | << uint8 (y) |
46 | SockList_AddShort (&sl, soundnum); |
46 | << uint16 (soundnum) |
47 | SockList_AddChar (&sl, soundtype); |
47 | << uint8 (soundtype); |
48 | Send_With_Handling (&pl->socket, &sl); |
48 | |
49 | free (sl.buf); |
49 | pl->ns->send_packet (sl); |
50 | } |
50 | } |
51 | |
|
|
52 | #define POW2(x) ((x) * (x)) |
|
|
53 | |
51 | |
54 | /** Plays some sound on map at x,y. */ |
52 | /** Plays some sound on map at x,y. */ |
55 | void |
53 | void |
56 | play_sound_map (maptile *map, int x, int y, short sound_num) |
54 | play_sound_map (maptile *map, int x, int y, short sound_num) |
57 | { |
55 | { |
58 | player *pl; |
|
|
59 | |
|
|
60 | if (sound_num >= NROF_SOUNDS) |
56 | if (sound_num >= NROF_SOUNDS) |
61 | { |
57 | { |
62 | 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); |
63 | return; |
59 | return; |
64 | } |
60 | } |
65 | |
61 | |
66 | for (pl = first_player; pl; pl = pl->next) |
62 | for_all_players (pl) |
67 | { |
63 | { |
68 | if (pl->ob->map == map) |
64 | if (pl->ob->map == map) |
69 | { |
65 | { |
70 | 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); |
71 | |
67 | |
72 | if (distance <= MAX_SOUND_DISTANCE) |
68 | if (distance <= MAX_SOUND_DISTANCE) |
73 | { |
|
|
74 | 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); |
75 | } |
|
|
76 | } |
70 | } |
77 | } |
71 | } |
78 | } |
72 | } |