1 |
/* |
2 |
* This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
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 |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation, either version 3 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
* |
21 |
* The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 |
*/ |
23 |
|
24 |
/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ |
25 |
|
26 |
/** |
27 |
* \file |
28 |
* Sound-related functions. |
29 |
* |
30 |
* \date 2003-12-02 |
31 |
*/ |
32 |
|
33 |
#include <global.h> |
34 |
#include <sproto.h> |
35 |
#include <sounds.h> |
36 |
|
37 |
/** |
38 |
* Maximum distance a player may hear a sound from. |
39 |
* This is only used for new client/server sound. If the sound source |
40 |
* on the map is farther away than this, we don't sent it to the client. |
41 |
*/ |
42 |
#define MAX_SOUND_DISTANCE 10 |
43 |
|
44 |
/** |
45 |
* Plays a sound for specified player only |
46 |
*/ |
47 |
void |
48 |
play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) |
49 |
{ |
50 |
char soundtype; |
51 |
|
52 |
if (!pl->ns->sound) |
53 |
return; |
54 |
|
55 |
/* Do some quick conversion to the sound type we want. */ |
56 |
if (soundnum >= SOUND_CAST_SPELL_0) |
57 |
{ |
58 |
soundtype = SOUND_SPELL; |
59 |
soundnum -= SOUND_CAST_SPELL_0; |
60 |
} |
61 |
else |
62 |
soundtype = SOUND_NORMAL; |
63 |
|
64 |
packet sl; |
65 |
|
66 |
sl << "sound " |
67 |
<< uint8 (x) |
68 |
<< uint8 (y) |
69 |
<< uint16 (soundnum) |
70 |
<< uint8 (soundtype); |
71 |
|
72 |
pl->ns->send_packet (sl); |
73 |
} |
74 |
|
75 |
/** Plays some sound on map at x,y. */ |
76 |
void |
77 |
play_sound_map (maptile *map, int x, int y, short sound_num) |
78 |
{ |
79 |
if (sound_num >= NROF_SOUNDS) |
80 |
{ |
81 |
LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); |
82 |
return; |
83 |
} |
84 |
|
85 |
for_all_players (pl) |
86 |
{ |
87 |
if (pl->ob->map == map) |
88 |
{ |
89 |
int distance = idistance (pl->ob->x - x, pl->ob->y - y); |
90 |
|
91 |
if (distance <= MAX_SOUND_DISTANCE) |
92 |
play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y); |
93 |
} |
94 |
} |
95 |
} |