ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/sounds.C
Revision: 1.13
Committed: Mon May 28 21:22:26 2007 UTC (16 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.12: +24 -0 lines
Log Message:
update copyrights in socket/*.C

File Contents

# Content
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
25 /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */
26
27 /**
28 * \file
29 * Sound-related functions.
30 *
31 * \date 2003-12-02
32 */
33
34 #include <global.h>
35 #include <sproto.h>
36 #include <sounds.h>
37
38 /**
39 * Maximum distance a player may hear a sound from.
40 * This is only used for new client/server sound. If the sound source
41 * on the map is farther away than this, we don't sent it to the client.
42 */
43 #define MAX_SOUND_DISTANCE 10
44
45 /**
46 * Plays a sound for specified player only
47 */
48 void
49 play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y)
50 {
51 char soundtype;
52
53 if (!pl->ns->sound)
54 return;
55
56 /* Do some quick conversion to the sound type we want. */
57 if (soundnum >= SOUND_CAST_SPELL_0)
58 {
59 soundtype = SOUND_SPELL;
60 soundnum -= SOUND_CAST_SPELL_0;
61 }
62 else
63 soundtype = SOUND_NORMAL;
64
65 packet sl;
66
67 sl << "sound "
68 << uint8 (x)
69 << uint8 (y)
70 << uint16 (soundnum)
71 << uint8 (soundtype);
72
73 pl->ns->send_packet (sl);
74 }
75
76 /** Plays some sound on map at x,y. */
77 void
78 play_sound_map (maptile *map, int x, int y, short sound_num)
79 {
80 if (sound_num >= NROF_SOUNDS)
81 {
82 LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num);
83 return;
84 }
85
86 for_all_players (pl)
87 {
88 if (pl->ob->map == map)
89 {
90 int distance = idistance (pl->ob->x - x, pl->ob->y - y);
91
92 if (distance <= MAX_SOUND_DISTANCE)
93 play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y);
94 }
95 }
96 }