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 (17 years 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

# User Rev Content
1 root 1.13 /*
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 elmex 1.1 /* 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 root 1.3 void
49     play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y)
50 elmex 1.1 {
51 root 1.3 char soundtype;
52 elmex 1.1
53 root 1.10 if (!pl->ns->sound)
54 root 1.3 return;
55 root 1.6
56 root 1.3 /* 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 elmex 1.1 }
62 root 1.3 else
63     soundtype = SOUND_NORMAL;
64 elmex 1.1
65 root 1.7 packet sl;
66 root 1.6
67     sl << "sound "
68     << uint8 (x)
69     << uint8 (y)
70     << uint16 (soundnum)
71     << uint8 (soundtype);
72    
73 root 1.10 pl->ns->send_packet (sl);
74 elmex 1.1 }
75    
76     /** Plays some sound on map at x,y. */
77 root 1.3 void
78 root 1.5 play_sound_map (maptile *map, int x, int y, short sound_num)
79 elmex 1.1 {
80 root 1.3 if (sound_num >= NROF_SOUNDS)
81     {
82     LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num);
83     return;
84 elmex 1.1 }
85    
86 root 1.11 for_all_players (pl)
87 root 1.3 {
88     if (pl->ob->map == map)
89     {
90 root 1.12 int distance = idistance (pl->ob->x - x, pl->ob->y - y);
91 root 1.3
92     if (distance <= MAX_SOUND_DISTANCE)
93 root 1.12 play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y);
94 root 1.2 }
95 elmex 1.1 }
96     }