--- deliantra/server/socket/sounds.C 2006/09/14 22:34:06 1.4 +++ deliantra/server/socket/sounds.C 2007/07/01 05:00:21 1.14 @@ -1,3 +1,26 @@ +/* + * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. + * + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen + * + * Crossfire TRT is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * The authors can be reached via e-mail to + */ + /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ /** @@ -25,10 +48,10 @@ play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) { char soundtype; - SockList sl; - if (!pl->socket.sound) + if (!pl->ns->sound) return; + /* Do some quick conversion to the sound type we want. */ if (soundnum >= SOUND_CAST_SPELL_0) { @@ -38,41 +61,35 @@ else soundtype = SOUND_NORMAL; - sl.buf = (unsigned char *) malloc (MAXSOCKBUF); - strcpy ((char *) sl.buf, "sound "); - sl.len = strlen ((char *) sl.buf); - SockList_AddChar (&sl, x); - SockList_AddChar (&sl, y); - SockList_AddShort (&sl, soundnum); - SockList_AddChar (&sl, soundtype); - Send_With_Handling (&pl->socket, &sl); - free (sl.buf); -} + packet sl; -#define POW2(x) ((x) * (x)) + sl << "sound " + << uint8 (x) + << uint8 (y) + << uint16 (soundnum) + << uint8 (soundtype); + + pl->ns->send_packet (sl); +} /** Plays some sound on map at x,y. */ void -play_sound_map (mapstruct *map, int x, int y, short sound_num) +play_sound_map (maptile *map, int x, int y, short sound_num) { - player *pl; - if (sound_num >= NROF_SOUNDS) { LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); return; } - for (pl = first_player; pl; pl = pl->next) + for_all_players (pl) { if (pl->ob->map == map) { - int distance = isqrt (POW2 (pl->ob->x - x) + POW2 (pl->ob->y - y)); + int distance = idistance (pl->ob->x - x, pl->ob->y - y); if (distance <= MAX_SOUND_DISTANCE) - { - play_sound_player_only (pl, sound_num, (sint8) (x - pl->ob->x), (sint8) (y - pl->ob->y)); - } + play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y); } } }