/* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ /** * \file * Sound-related functions. * * \date 2003-12-02 */ #include #include #include /** * Maximum distance a player may hear a sound from. * This is only used for new client/server sound. If the sound source * on the map is farther away than this, we don't sent it to the client. */ #define MAX_SOUND_DISTANCE 10 /** * Plays a sound for specified player only */ void play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) { char soundtype; if (!pl->ns->sound) return; /* Do some quick conversion to the sound type we want. */ if (soundnum >= SOUND_CAST_SPELL_0) { soundtype = SOUND_SPELL; soundnum -= SOUND_CAST_SPELL_0; } else soundtype = SOUND_NORMAL; packet sl; 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 (maptile *map, int x, int y, short sound_num) { if (sound_num >= NROF_SOUNDS) { LOG (llevError, "Tried to play an invalid sound num: %d\n", sound_num); return; } for_all_players (pl) { if (pl->ob->map == map) { int distance = idistance (pl->ob->x - x, pl->ob->y - y); if (distance <= MAX_SOUND_DISTANCE) play_sound_player_only (pl, sound_num, x - pl->ob->x, y - pl->ob->y); } } }