ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/sounds.C
Revision: 1.12
Committed: Mon Jan 15 01:39:42 2007 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_0, rel-2_1
Changes since 1.11: +2 -6 lines
Log Message:
more micro-optimisation, use idistance, min is faster than MIN

File Contents

# Content
1 /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */
2
3 /**
4 * \file
5 * Sound-related functions.
6 *
7 * \date 2003-12-02
8 */
9
10 #include <global.h>
11 #include <sproto.h>
12 #include <sounds.h>
13
14 /**
15 * Maximum distance a player may hear a sound from.
16 * This is only used for new client/server sound. If the sound source
17 * on the map is farther away than this, we don't sent it to the client.
18 */
19 #define MAX_SOUND_DISTANCE 10
20
21 /**
22 * Plays a sound for specified player only
23 */
24 void
25 play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y)
26 {
27 char soundtype;
28
29 if (!pl->ns->sound)
30 return;
31
32 /* Do some quick conversion to the sound type we want. */
33 if (soundnum >= SOUND_CAST_SPELL_0)
34 {
35 soundtype = SOUND_SPELL;
36 soundnum -= SOUND_CAST_SPELL_0;
37 }
38 else
39 soundtype = SOUND_NORMAL;
40
41 packet sl;
42
43 sl << "sound "
44 << uint8 (x)
45 << uint8 (y)
46 << uint16 (soundnum)
47 << uint8 (soundtype);
48
49 pl->ns->send_packet (sl);
50 }
51
52 /** Plays some sound on map at x,y. */
53 void
54 play_sound_map (maptile *map, int x, int y, short sound_num)
55 {
56 if (sound_num >= NROF_SOUNDS)
57 {
58 LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num);
59 return;
60 }
61
62 for_all_players (pl)
63 {
64 if (pl->ob->map == map)
65 {
66 int distance = idistance (pl->ob->x - x, pl->ob->y - y);
67
68 if (distance <= MAX_SOUND_DISTANCE)
69 play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y);
70 }
71 }
72 }