|
|
1 | /* |
|
|
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
|
|
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
|
|
9 | * under the terms of the GNU General Public License as published by the Free |
|
|
10 | * Software Foundation; either version 2 of the License, or (at your option) |
|
|
11 | * any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, but |
|
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
16 | * for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License along |
|
|
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
|
|
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
23 | */ |
|
|
24 | |
1 | /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
25 | /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
2 | |
26 | |
3 | /** |
27 | /** |
4 | * \file |
28 | * \file |
5 | * Sound-related functions. |
29 | * Sound-related functions. |
… | |
… | |
24 | void |
48 | void |
25 | play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) |
49 | play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) |
26 | { |
50 | { |
27 | char soundtype; |
51 | char soundtype; |
28 | |
52 | |
29 | if (!pl->socket->sound) |
53 | if (!pl->ns->sound) |
30 | return; |
54 | return; |
31 | |
55 | |
32 | /* Do some quick conversion to the sound type we want. */ |
56 | /* Do some quick conversion to the sound type we want. */ |
33 | if (soundnum >= SOUND_CAST_SPELL_0) |
57 | if (soundnum >= SOUND_CAST_SPELL_0) |
34 | { |
58 | { |
… | |
… | |
44 | << uint8 (x) |
68 | << uint8 (x) |
45 | << uint8 (y) |
69 | << uint8 (y) |
46 | << uint16 (soundnum) |
70 | << uint16 (soundnum) |
47 | << uint8 (soundtype); |
71 | << uint8 (soundtype); |
48 | |
72 | |
49 | pl->socket->send_packet (sl); |
73 | pl->ns->send_packet (sl); |
50 | } |
74 | } |
51 | |
|
|
52 | #define POW2(x) ((x) * (x)) |
|
|
53 | |
75 | |
54 | /** Plays some sound on map at x,y. */ |
76 | /** Plays some sound on map at x,y. */ |
55 | void |
77 | void |
56 | play_sound_map (maptile *map, int x, int y, short sound_num) |
78 | play_sound_map (maptile *map, int x, int y, short sound_num) |
57 | { |
79 | { |
58 | player *pl; |
|
|
59 | |
|
|
60 | if (sound_num >= NROF_SOUNDS) |
80 | if (sound_num >= NROF_SOUNDS) |
61 | { |
81 | { |
62 | LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); |
82 | LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); |
63 | return; |
83 | return; |
64 | } |
84 | } |
65 | |
85 | |
66 | for (pl = first_player; pl; pl = pl->next) |
86 | for_all_players (pl) |
67 | { |
87 | { |
68 | if (pl->ob->map == map) |
88 | if (pl->ob->map == map) |
69 | { |
89 | { |
70 | int distance = isqrt (POW2 (pl->ob->x - x) + POW2 (pl->ob->y - y)); |
90 | int distance = idistance (pl->ob->x - x, pl->ob->y - y); |
71 | |
91 | |
72 | if (distance <= MAX_SOUND_DISTANCE) |
92 | if (distance <= MAX_SOUND_DISTANCE) |
73 | { |
|
|
74 | play_sound_player_only (pl, sound_num, (sint8) (x - pl->ob->x), (sint8) (y - pl->ob->y)); |
93 | play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y); |
75 | } |
|
|
76 | } |
94 | } |
77 | } |
95 | } |
78 | } |
96 | } |