ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/sounds.C
(Generate patch)

Comparing deliantra/server/socket/sounds.C (file contents):
Revision 1.2 by root, Tue Aug 29 08:01:38 2006 UTC vs.
Revision 1.4 by root, Thu Sep 14 22:34:06 2006 UTC

1/*
2 * static char *rcsid_sound_c =
3 * "$Id: sounds.C,v 1.2 2006/08/29 08:01:38 root Exp $";
4 */
5
6/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ 1/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */
7 2
8/** 3/**
9 * \file 4 * \file
10 * Sound-related functions. 5 * Sound-related functions.
24#define MAX_SOUND_DISTANCE 10 19#define MAX_SOUND_DISTANCE 10
25 20
26/** 21/**
27 * Plays a sound for specified player only 22 * Plays a sound for specified player only
28 */ 23 */
24void
29void play_sound_player_only(player *pl, short soundnum, sint8 x, sint8 y) 25play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y)
30{ 26{
31 char soundtype; 27 char soundtype;
32 SockList sl; 28 SockList sl;
33 29
34 if (!pl->socket.sound) return; 30 if (!pl->socket.sound)
31 return;
35 /* Do some quick conversion to the sound type we want. */ 32 /* Do some quick conversion to the sound type we want. */
36 if (soundnum>=SOUND_CAST_SPELL_0) { 33 if (soundnum >= SOUND_CAST_SPELL_0)
34 {
37 soundtype=SOUND_SPELL; 35 soundtype = SOUND_SPELL;
38 soundnum -=SOUND_CAST_SPELL_0; 36 soundnum -= SOUND_CAST_SPELL_0;
39 } 37 }
38 else
40 else soundtype=SOUND_NORMAL; 39 soundtype = SOUND_NORMAL;
41 40
42 sl.buf=(unsigned char*)malloc(MAXSOCKBUF); 41 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
43 strcpy((char*)sl.buf, "sound "); 42 strcpy ((char *) sl.buf, "sound ");
44 sl.len=strlen((char*)sl.buf); 43 sl.len = strlen ((char *) sl.buf);
45 SockList_AddChar(&sl, x); 44 SockList_AddChar (&sl, x);
46 SockList_AddChar(&sl, y); 45 SockList_AddChar (&sl, y);
47 SockList_AddShort(&sl, soundnum); 46 SockList_AddShort (&sl, soundnum);
48 SockList_AddChar(&sl, soundtype); 47 SockList_AddChar (&sl, soundtype);
49 Send_With_Handling(&pl->socket, &sl); 48 Send_With_Handling (&pl->socket, &sl);
50 free(sl.buf); 49 free (sl.buf);
51} 50}
52 51
53#define POW2(x) ((x) * (x)) 52#define POW2(x) ((x) * (x))
54 53
55/** Plays some sound on map at x,y. */ 54/** Plays some sound on map at x,y. */
55void
56void play_sound_map(mapstruct *map, int x, int y, short sound_num) 56play_sound_map (mapstruct *map, int x, int y, short sound_num)
57{ 57{
58 player *pl; 58 player *pl;
59 59
60 if (sound_num >= NROF_SOUNDS) { 60 if (sound_num >= NROF_SOUNDS)
61 {
61 LOG(llevError,"Tried to play an invalid sound num: %d\n", sound_num); 62 LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num);
62 return; 63 return;
63 } 64 }
64 65
65 for (pl = first_player; pl; pl = pl->next) { 66 for (pl = first_player; pl; pl = pl->next)
67 {
66 if (pl->ob->map == map) { 68 if (pl->ob->map == map)
69 {
67 int distance=isqrt(POW2(pl->ob->x - x) + POW2(pl->ob->y - y)); 70 int distance = isqrt (POW2 (pl->ob->x - x) + POW2 (pl->ob->y - y));
68 71
69 if (distance<=MAX_SOUND_DISTANCE) { 72 if (distance <= MAX_SOUND_DISTANCE)
73 {
70 play_sound_player_only(pl, sound_num, ( sint8 )( x-pl->ob->x ), ( sint8 )( y-pl->ob->y )); 74 play_sound_player_only (pl, sound_num, (sint8) (x - pl->ob->x), (sint8) (y - pl->ob->y));
71 } 75 }
72 } 76 }
73 } 77 }
74} 78}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines