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.14 by root, Sun Jul 1 05:00:21 2007 UTC

1/* 1/*
2 * static char *rcsid_sound_c = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * "$Id: sounds.C,v 1.1 2006/08/13 17:16:06 elmex Exp $"; 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
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
4 */ 22 */
5 23
6/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ 24/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */
7 25
8/** 26/**
24#define MAX_SOUND_DISTANCE 10 42#define MAX_SOUND_DISTANCE 10
25 43
26/** 44/**
27 * Plays a sound for specified player only 45 * Plays a sound for specified player only
28 */ 46 */
47void
29void play_sound_player_only(player *pl, short soundnum, sint8 x, sint8 y) 48play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y)
30{ 49{
31 char soundtype; 50 char soundtype;
32 SockList sl;
33 51
34 if (!pl->socket.sound) return; 52 if (!pl->ns->sound)
53 return;
54
35 /* Do some quick conversion to the sound type we want. */ 55 /* Do some quick conversion to the sound type we want. */
36 if (soundnum>=SOUND_CAST_SPELL_0) { 56 if (soundnum >= SOUND_CAST_SPELL_0)
57 {
37 soundtype=SOUND_SPELL; 58 soundtype = SOUND_SPELL;
38 soundnum -=SOUND_CAST_SPELL_0; 59 soundnum -= SOUND_CAST_SPELL_0;
39 } 60 }
61 else
40 else soundtype=SOUND_NORMAL; 62 soundtype = SOUND_NORMAL;
41 63
42 sl.buf=(unsigned char*)malloc(MAXSOCKBUF); 64 packet sl;
43 strcpy((char*)sl.buf, "sound "); 65
44 sl.len=strlen((char*)sl.buf); 66 sl << "sound "
45 SockList_AddChar(&sl, x); 67 << uint8 (x)
46 SockList_AddChar(&sl, y); 68 << uint8 (y)
47 SockList_AddShort(&sl, soundnum); 69 << uint16 (soundnum)
48 SockList_AddChar(&sl, soundtype); 70 << uint8 (soundtype);
49 Send_With_Handling(&pl->socket, &sl); 71
50 free(sl.buf); 72 pl->ns->send_packet (sl);
51} 73}
52 74
53#define POW2(x) ((x) * (x))
54
55/** Plays some sound on map at x,y. */ 75/** Plays some sound on map at x,y. */
76void
56void play_sound_map(mapstruct *map, int x, int y, short sound_num) 77play_sound_map (maptile *map, int x, int y, short sound_num)
57{ 78{
58 player *pl;
59
60 if (sound_num >= NROF_SOUNDS) { 79 if (sound_num >= NROF_SOUNDS)
80 {
61 LOG(llevError,"Tried to play an invalid sound num: %d\n", sound_num); 81 LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num);
62 return; 82 return;
63 } 83 }
64 84
65 for (pl = first_player; pl; pl = pl->next) { 85 for_all_players (pl)
86 {
66 if (pl->ob->map == map) { 87 if (pl->ob->map == map)
67 int distance=isqrt(POW2(pl->ob->x - x) + POW2(pl->ob->y - y)); 88 {
89 int distance = idistance (pl->ob->x - x, pl->ob->y - y);
68 90
69 if (distance<=MAX_SOUND_DISTANCE) { 91 if (distance <= MAX_SOUND_DISTANCE)
70 play_sound_player_only(pl, sound_num, ( sint8 )( x-pl->ob->x ), ( sint8 )( y-pl->ob->y )); 92 play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y);
71 } 93 }
72 }
73 } 94 }
74} 95}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines