int SD_PlayIt ( int sndnum, int angle, int distance, int pitch ) { int voice; uint8_t * snd; if (!(sounds[sndnum].flags & SD_WRITE)) { if (sounds[sndnum].count) { if (distance<=sounds[sndnum].prevdistance) FX_StopSound(sounds[sndnum].prevhandle); else return 0; } } if ( !FX_VoiceAvailable( sounds[sndnum].priority ) ) { return( 0 ); } sounds[sndnum].count++; snd=W_CacheLumpNum(SoundNumber(sndnum),PU_STATIC, CvtNull, 1); if ( *snd == 'C' ) { voice = FX_PlayVOC3D( snd, pitch, angle, distance, sounds[sndnum].priority, (unsigned long) sndnum ); } else { voice = FX_PlayWAV3D( snd, pitch, angle, distance, sounds[sndnum].priority, (unsigned long) sndnum ); } if ( voice < FX_Ok ) { SD_MakeCacheable( sndnum ); return 0; } NumBadSounds=0; if (!(sounds[sndnum].flags & SD_WRITE)) { sounds[sndnum].prevhandle=voice; sounds[sndnum].prevdistance=distance; } return voice; }
int xyzsound(short num,short i,long x,long y,long z) { long sndist, cx, cy, cz, j,k; short pitche,pitchs,cs; int voice, sndang, ca, pitch; // if(num != 358) return 0; if( num >= NUM_SOUNDS || FXDevice < 0 || ( (soundm[num]&8) && ud.lockout ) || SoundToggle == 0 || Sound[num].num > 3 || FX_VoiceAvailable(soundpr[num]) == 0 || (ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) || ps[myconnectindex].gm&MODE_MENU) return -1; if( soundm[num]&128 ) { sound(num); return 0; } if( soundm[num]&4 ) { if(VoiceToggle==0 || (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && ud.coop != 1) ) return -1; for(j=0;j<NUM_SOUNDS;j++) for(k=0;k<Sound[j].num;k++) if( (Sound[j].num > 0) && (soundm[j]&4) ) return -1; } cx = ps[screenpeek].oposx; cy = ps[screenpeek].oposy; cz = ps[screenpeek].oposz; cs = ps[screenpeek].cursectnum; ca = ps[screenpeek].ang+ps[screenpeek].look_ang; sndist = FindDistance3D((cx-x),(cy-y),(cz-z)>>4); if( i >= 0 && (soundm[num]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9 ) sndist = divscale14(sndist,(SHT+1)); pitchs = soundps[num]; pitche = soundpe[num]; j = klabs(pitche-pitchs); if(j) { if( pitchs < pitche ) pitch = pitchs + ( rand()%j ); else pitch = pitche + ( rand()%j ); } else pitch = pitchs; sndist += soundvo[num]; if(sndist < 0) sndist = 0; if( sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,SX,SY,SZ-(24<<8),SECT) ) sndist += sndist>>5; switch(num) { case PIPEBOMB_EXPLODE: case LASERTRIP_EXPLODE: case RPG_EXPLODE: if(sndist > (6144) ) sndist = 6144; if(sector[ps[screenpeek].cursectnum].lotag == 2) pitch -= 1024; break; default: if(sector[ps[screenpeek].cursectnum].lotag == 2 && (soundm[num]&4) == 0) pitch = -768; if( sndist > 31444 && PN != MUSICANDSFX) return -1; break; } if( Sound[num].num > 0 && PN != MUSICANDSFX ) { if( SoundOwner[num][0].i == i ) stopsound(num); else if( Sound[num].num > 1 ) stopsound(num); else if( badguy(&sprite[i]) && sprite[i].extra <= 0 ) stopsound(num); } if( PN == APLAYER && sprite[i].yvel == screenpeek ) { sndang = 0; sndist = 0; } else { sndang = 2048 + ca - getangle(cx-x,cy-y); sndang &= 2047; } if(Sound[num].ptr == 0) { if( loadsound(num) == 0 ) return 0; } else { if (Sound[num].lock < 200) Sound[num].lock = 200; else Sound[num].lock++; } if( soundm[num]&16 ) sndist = 0; if(sndist < ((255-LOUDESTVOLUME)<<6) ) sndist = ((255-LOUDESTVOLUME)<<6); if( soundm[num]&1 ) { if(Sound[num].num > 0) return -1; voice = FX_PlayLoopedAuto( Sound[num].ptr, soundsiz[num], 0, -1, pitch,sndist>>6,sndist>>6,0,soundpr[num],num); } else {
int xyzsound(short num,short i,int32_t x,int32_t y,int32_t z) { int32_t sndist, cx, cy, cz, j,k; short pitche,pitchs,cs; int voice, sndang, ca, pitch; if ( num >= NUM_SOUNDS || FXDevice == NumSoundCards || ( (soundm[num]&8) && ud.lockout ) || SoundToggle == 0 || Sound[num].num > 3 || FX_VoiceAvailable(soundpr[num]) == 0 || (ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) || ps[myconnectindex].gm&MODE_MENU) { return -1; } if ( soundm[num]&128 ) { sound(num); return 0; } if ( soundm[num]&4 ) { // FIX_00041: Toggle to hear the opponent sound in DM (like it used to be in v1.3d) if (VoiceToggle==0 || (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && /*ud.coop!=1 &&*/ !OpponentSoundToggle) ) { return -1; //xduke : 1.3d Style: makes opponent sound in DM as in COOP } for (j=0; j<NUM_SOUNDS; j++) for (k=0; k<Sound[j].num; k++) if ( (Sound[j].num > 0) && (soundm[j]&4) ) { return -1; } } cx = ps[screenpeek].oposx; cy = ps[screenpeek].oposy; cz = ps[screenpeek].oposz; cs = ps[screenpeek].cursectnum; ca = ps[screenpeek].ang+ps[screenpeek].look_ang; sndist = FindDistance3D((cx-x),(cy-y),(cz-z)>>4); if ( i >= 0 && (soundm[num]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9 ) { sndist = divscale14(sndist,(SHT+1)); } pitchs = soundps[num]; pitche = soundpe[num]; cx = klabs(pitche-pitchs); if (cx) { if ( pitchs < pitche ) { pitch = pitchs + ( rand()%cx ); } else { pitch = pitche + ( rand()%cx ); } } else { pitch = pitchs; } sndist += soundvo[num]; if (sndist < 0) { sndist = 0; } if ( sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,SX,SY,SZ-(24<<8),SECT) ) { sndist += sndist>>5; }
int32_t S_PlaySound3D(int32_t num, int32_t i, const vec3_t *pos) { int32_t j = VM_OnEventWithReturn(EVENT_SOUND, i, screenpeek, num); if (j == -1 && num != -1) // check that the user returned -1, but only if -1 wasn't playing already (in which case, warn) return -1; num = j; const DukePlayer_t *const myps = g_player[myconnectindex].ps; if ((unsigned)num > (unsigned)g_maxSoundPos || ((g_sounds[num].m & SF_ADULT) && ud.lockout) || !ud.config.SoundToggle || (unsigned)i >= MAXSPRITES || !FX_VoiceAvailable(g_sounds[num].pr) || (myps->timebeforeexit > 0 && myps->timebeforeexit <= GAMETICSPERSEC * 3) || (myps->gm & MODE_MENU)) return -1; int32_t voice; if (g_sounds[num].m & SF_DTAG) // Duke-Tag sound { if ((voice = S_PlaySound(num)) <= FX_Ok) return -1; j = 0; while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice != voice) j++; if (EDUKE32_PREDICT_FALSE(j >= MAXSOUNDINSTANCES)) { OSD_Printf(OSD_ERROR "%s %d: WTF?\n", __FILE__, __LINE__); return -1; } g_sounds[num].SoundOwner[j].ow = i; return voice; } // Duke talk if (g_sounds[num].m & SF_TALK) { if ((g_netServer || ud.multimode > 1) && PN == APLAYER && P_Get(i) != screenpeek) // other player sound { if (!(ud.config.VoiceToggle&4)) return -1; } else if (!(ud.config.VoiceToggle&1)) return -1; // don't play if any Duke talk sounds are already playing for (j=0; j<g_maxSoundPos; ++j) if ((g_sounds[j].m & SF_TALK) && g_sounds[j].num > 0) return -1; } int32_t sndist, sndang; int32_t explosionp = S_CalcDistAndAng(i, num, CAMERA(sect), CAMERA(ang), &CAMERA(pos), pos, &sndist, &sndang); int32_t pitch = S_GetPitch(num); const DukePlayer_t *peekps = g_player[screenpeek].ps; #ifdef SPLITSCREEN_MOD_HACKS if (g_fakeMultiMode==2) { // splitscreen HACK if (g_player[1].ps->i == i) peekps = g_player[1].ps; } #endif if (peekps->sound_pitch) pitch += peekps->sound_pitch; if (explosionp) { if (peekps->cursectnum > -1 && sector[peekps->cursectnum].lotag == ST_2_UNDERWATER) pitch -= 1024; } else { if (sndist > 32767 && PN != MUSICANDSFX && (g_sounds[num].m & (SF_LOOP|SF_MSFX)) == 0) return -1; if (peekps->cursectnum > -1 && sector[peekps->cursectnum].lotag == ST_2_UNDERWATER && (g_sounds[num].m & SF_TALK) == 0) pitch = -768; } if (g_sounds[num].num > 0 && PN != MUSICANDSFX) S_StopEnvSound(num, i); if (g_sounds[num].ptr == 0) { if (S_LoadSound(num) == 0) return -1; } else { if (g_soundlocks[num] < 200) g_soundlocks[num] = 200; else g_soundlocks[num]++; } j = S_GetSlot(num); if (j >= MAXSOUNDINSTANCES) { g_soundlocks[num]--; return -1; } { const int32_t repeatp = (g_sounds[num].m & SF_LOOP); const int32_t ambsfxp = S_IsAmbientSFX(i); if (repeatp && (g_sounds[num].m & SF_ONEINST_INTERNAL) && g_sounds[num].num > 0) { g_soundlocks[num]--; return -1; } if (repeatp && !ambsfxp) { voice = FX_PlayLoopedAuto(g_sounds[num].ptr, g_sounds[num].soundsiz, 0, -1, pitch, FX_VOLUME(sndist>>6), FX_VOLUME(sndist>>6), 0, // XXX: why is 'right' 0? g_sounds[num].pr, (num * MAXSOUNDINSTANCES) + j); } else {