--- deliantra/server/socket/sounds.C 2007/07/01 05:00:21 1.14 +++ deliantra/server/socket/sounds.C 2007/07/26 00:27:09 1.15 @@ -34,6 +34,8 @@ #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 @@ -41,55 +43,80 @@ */ #define MAX_SOUND_DISTANCE 10 -/** +// the hashtable +typedef std::tr1::unordered_map + < + const char *, + faceidx, + str_hash, + str_equal, + slice_allocator< std::pair > + > HT; + +static HT ht; + +faceidx +sound_find (const char *str) +{ + auto (i, ht.find (str)); + + return i == ht.end () + ? 0 + : i->second; +} + +void +sound_set (const char *str, faceidx face) +{ + auto (i, ht.find (str)); + + if (i != ht.end ()) + i->second = face; + else + ht.insert (std::make_pair (strdup (str), face)); +} + +/* * Plays a sound for specified player only */ void -play_sound_player_only (player *pl, short soundnum, sint8 x, sint8 y) +client::play_sound (faceidx sound, int dx, int dy) { - char soundtype; - - if (!pl->ns->sound) + if (!sound) return; - /* Do some quick conversion to the sound type we want. */ - if (soundnum >= SOUND_CAST_SPELL_0) + if (this->sound) { - soundtype = SOUND_SPELL; - soundnum -= SOUND_CAST_SPELL_0; + // gcfclient compatibility + + packet sl ("sound"); + + sl << uint8 (dx) + << uint8 (dy) + << uint16 (sound) + << uint8 (SOUND_NORMAL); + + send_packet (sl); } - else - soundtype = SOUND_NORMAL; + else if (fx_want [FT_SOUND]) + { + // cfplus + send_face (sound); + flush_fx (); - packet sl; + packet sl ("sc"); - sl << "sound " - << uint8 (x) - << uint8 (y) - << uint16 (soundnum) - << uint8 (soundtype); + uint8 *len = sl.cur; - pl->ns->send_packet (sl); -} + sl << uint8 (0) // group length + << uint8 (0) // type == one-time effect + << ber32 (sound) + << sint8 (dx) + << sint8 (dy); -/** 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; - } + *len = sl.cur - len; // patch in group length - 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); - } + send_packet (sl); } } +