1 | /* |
1 | /* |
2 | * static char *rcsid_sound_c = |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
3 | * "$Id: sounds.C,v 1.2 2006/08/29 08:01:38 root Exp $"; |
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> |
4 | */ |
23 | */ |
5 | |
24 | |
6 | /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
25 | /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
7 | |
26 | |
8 | /** |
27 | /** |
… | |
… | |
24 | #define MAX_SOUND_DISTANCE 10 |
43 | #define MAX_SOUND_DISTANCE 10 |
25 | |
44 | |
26 | /** |
45 | /** |
27 | * Plays a sound for specified player only |
46 | * Plays a sound for specified player only |
28 | */ |
47 | */ |
|
|
48 | void |
29 | void 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) |
30 | { |
50 | { |
31 | char soundtype; |
51 | char soundtype; |
32 | SockList sl; |
|
|
33 | |
52 | |
34 | if (!pl->socket.sound) return; |
53 | if (!pl->ns->sound) |
|
|
54 | return; |
|
|
55 | |
35 | /* Do some quick conversion to the sound type we want. */ |
56 | /* Do some quick conversion to the sound type we want. */ |
36 | if (soundnum>=SOUND_CAST_SPELL_0) { |
57 | if (soundnum >= SOUND_CAST_SPELL_0) |
|
|
58 | { |
37 | soundtype=SOUND_SPELL; |
59 | soundtype = SOUND_SPELL; |
38 | soundnum -=SOUND_CAST_SPELL_0; |
60 | soundnum -= SOUND_CAST_SPELL_0; |
39 | } |
61 | } |
|
|
62 | else |
40 | else soundtype=SOUND_NORMAL; |
63 | soundtype = SOUND_NORMAL; |
41 | |
64 | |
42 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
65 | packet sl; |
43 | strcpy((char*)sl.buf, "sound "); |
66 | |
44 | sl.len=strlen((char*)sl.buf); |
67 | sl << "sound " |
45 | SockList_AddChar(&sl, x); |
68 | << uint8 (x) |
46 | SockList_AddChar(&sl, y); |
69 | << uint8 (y) |
47 | SockList_AddShort(&sl, soundnum); |
70 | << uint16 (soundnum) |
48 | SockList_AddChar(&sl, soundtype); |
71 | << uint8 (soundtype); |
49 | Send_With_Handling(&pl->socket, &sl); |
72 | |
50 | free(sl.buf); |
73 | pl->ns->send_packet (sl); |
51 | } |
74 | } |
52 | |
75 | |
53 | #define POW2(x) ((x) * (x)) |
|
|
54 | |
|
|
55 | /** Plays some sound on map at x,y. */ |
76 | /** Plays some sound on map at x,y. */ |
|
|
77 | void |
56 | void play_sound_map(mapstruct *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) |
|
|
81 | { |
61 | 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); |
62 | return; |
83 | return; |
63 | } |
84 | } |
64 | |
85 | |
65 | for (pl = first_player; pl; pl = pl->next) { |
86 | for_all_players (pl) |
|
|
87 | { |
66 | if (pl->ob->map == map) { |
88 | if (pl->ob->map == map) |
|
|
89 | { |
67 | 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); |
68 | |
91 | |
69 | if (distance<=MAX_SOUND_DISTANCE) { |
92 | if (distance <= MAX_SOUND_DISTANCE) |
70 | 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); |
71 | } |
|
|
72 | } |
94 | } |
73 | } |
95 | } |
74 | } |
96 | } |