Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_sound_c = 00003 * "$Id: sounds.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* Send bug reports to Raphael Quinet (quinet@montefiore.ulg.ac.be) */ 00007 00015 #include <global.h> 00016 #include <sproto.h> 00017 #include <sounds.h> 00018 00024 #define MAX_SOUND_DISTANCE 10 00025 00040 void play_sound_player_only(player *pl, sint8 sound_type, object *emitter, int dir, const char *action) { 00041 SockList sl; 00042 int volume = 50; 00043 sstring name; 00044 object *source; 00045 00046 if (pl->socket.sound&SND_MUTE || !(pl->socket.sound&SND_EFFECTS)) 00047 return; 00048 if (pl->socket.sounds_this_tick >= MAX_SOUNDS_TICK) 00049 return; 00050 if (!emitter->map && !(emitter->env && emitter->env->map)) 00051 return; 00052 00053 source = emitter->map ? emitter : emitter->env; 00054 00055 if ((RANDOM()%100) >= emitter->sound_chance) 00056 return; 00057 00058 pl->socket.sounds_this_tick = 0; 00059 00060 name = emitter->type == PLAYER ? emitter->race : emitter->name; 00061 if (!source) 00062 source = emitter; 00063 00064 SockList_Init(&sl); 00065 SockList_AddString(&sl, "sound2 "); 00066 SockList_AddChar(&sl, (sint8)(source->x-pl->ob->x)); 00067 SockList_AddChar(&sl, (sint8)(source->y-pl->ob->y)); 00068 SockList_AddChar(&sl, dir); 00069 SockList_AddChar(&sl, volume); 00070 SockList_AddChar(&sl, sound_type); 00071 SockList_AddLen8Data(&sl, action, strlen(action)); 00072 SockList_AddLen8Data(&sl, name, strlen(name)); 00073 Send_With_Handling(&pl->socket, &sl); 00074 SockList_Term(&sl); 00075 } 00076 00077 #define POW2(x) ((x)*(x)) 00078 00090 void play_sound_map(sint8 sound_type, object *emitter, int dir, const char *action) { 00091 player *pl; 00092 object *source; 00093 00094 if ((RANDOM()%100) >= emitter->sound_chance) 00095 return; 00096 00097 if (!emitter->map && !(emitter->env && emitter->env->map)) 00098 return; 00099 00100 source = emitter->map ? emitter : emitter->env; 00101 00102 for (pl = first_player; pl; pl = pl->next) { 00103 if (pl->ob->map == emitter->map) { 00104 int distance = isqrt(POW2(pl->ob->x-source->x)+POW2(pl->ob->y-source->y)); 00105 00106 if (distance <= MAX_SOUND_DISTANCE) { 00107 play_sound_player_only(pl, sound_type, emitter, dir, action); 00108 } 00109 } 00110 } 00111 } 00112 00121 void send_background_music(player *pl, const char *music) { 00122 SockList sl; 00123 00124 if (pl->socket.sound&SND_MUTE || !(pl->socket.sound&SND_MUSIC)) 00125 return; 00126 00127 SockList_Init(&sl); 00128 SockList_AddString(&sl, "music "); 00129 SockList_AddString(&sl, music == NULL ? "NONE" : music); 00130 Send_With_Handling(&pl->socket, &sl); 00131 SockList_Term(&sl); 00132 }