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.1 by elmex, Sun Aug 13 17:16:06 2006 UTC vs.
Revision 1.12 by root, Mon Jan 15 01:39:42 2007 UTC

1/*
2 * static char *rcsid_sound_c =
3 * "$Id: sounds.C,v 1.1 2006/08/13 17:16:06 elmex 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;
33 28
34 if (!pl->socket.sound) return; 29 if (!pl->ns->sound)
30 return;
31
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 packet sl;
43 strcpy((char*)sl.buf, "sound "); 42
44 sl.len=strlen((char*)sl.buf); 43 sl << "sound "
45 SockList_AddChar(&sl, x); 44 << uint8 (x)
46 SockList_AddChar(&sl, y); 45 << uint8 (y)
47 SockList_AddShort(&sl, soundnum); 46 << uint16 (soundnum)
48 SockList_AddChar(&sl, soundtype); 47 << uint8 (soundtype);
49 Send_With_Handling(&pl->socket, &sl); 48
50 free(sl.buf); 49 pl->ns->send_packet (sl);
51} 50}
52 51
53#define POW2(x) ((x) * (x))
54
55/** Plays some sound on map at x,y. */ 52/** Plays some sound on map at x,y. */
53void
56void play_sound_map(mapstruct *map, int x, int y, short sound_num) 54play_sound_map (maptile *map, int x, int y, short sound_num)
57{ 55{
58 player *pl;
59
60 if (sound_num >= NROF_SOUNDS) { 56 if (sound_num >= NROF_SOUNDS)
57 {
61 LOG(llevError,"Tried to play an invalid sound num: %d\n", sound_num); 58 LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num);
62 return; 59 return;
63 } 60 }
64 61
65 for (pl = first_player; pl; pl = pl->next) { 62 for_all_players (pl)
63 {
66 if (pl->ob->map == map) { 64 if (pl->ob->map == map)
67 int distance=isqrt(POW2(pl->ob->x - x) + POW2(pl->ob->y - y)); 65 {
66 int distance = idistance (pl->ob->x - x, pl->ob->y - y);
68 67
69 if (distance<=MAX_SOUND_DISTANCE) { 68 if (distance <= MAX_SOUND_DISTANCE)
70 play_sound_player_only(pl, sound_num, ( sint8 )( x-pl->ob->x ), ( sint8 )( y-pl->ob->y )); 69 play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y);
71 } 70 }
72 }
73 } 71 }
74} 72}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines