X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FWeapons.cpp;h=d250f1ee84676c50d008dbc35e4724ce22db42ac;hb=0b7253f3d99e4382008aff8b8e221e88ff40d3e9;hp=212bdb453d946de39ba3e2aa0961544e5ff14470;hpb=fb33deea78909d498c363d973cda2c5d0d334314;p=lugaru.git diff --git a/Source/Weapons.cpp b/Source/Weapons.cpp index 212bdb4..d250f1e 100644 --- a/Source/Weapons.cpp +++ b/Source/Weapons.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Awards.h" extern float multiplier; -extern int channels[100]; extern Terrain terrain; extern float gravity; extern int environment; @@ -47,14 +46,12 @@ extern bool osx; extern bool autoslomo; extern float camerashake; extern float woozy; -extern float terraindetail; extern float viewdistance; extern float blackout; extern int difficulty; extern bool freeze; extern int tutoriallevel; extern int numthrowkill; -extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); void Weapons::DoStuff(){ static int i,whichpatchx,whichpatchz,j,k,whichhit,m; @@ -85,18 +82,7 @@ void Weapons::DoStuff(){ oldowner[i]=owner[i]; } if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){ - float gLoc[3]; - float vel[3]; - gLoc[0]=tippoint[i].x; - gLoc[1]=tippoint[i].y; - gLoc[2]=tippoint[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true); - OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel); - OPENAL_SetVolume(channels[staffbreaksound], 256); - OPENAL_SetPaused(channels[staffbreaksound], false); + emit_sound_at(staffbreaksound, tippoint[i]); XYZ tempvel; XYZ speed; //speed=(tippoint[i]-oldtippoint[i])/multiplier/6; @@ -131,8 +117,8 @@ void Weapons::DoStuff(){ if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){ position[i]+=velocity[i]*multiplier; tippoint[i]+=velocity[i]*multiplier; - whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail); - whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail); + whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale); + whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale); if(whichpatchx>0&&whichpatchz>0&&whichpatchx0&&whichpatchz>0&&whichpatchx1){ - float gLoc[3]; - float vel[3]; - //int whichsound=clank1sound+abs(Random()%4); int whichsound; if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); - if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x; - gLoc[1]=position[i].y; - gLoc[2]=position[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); + emit_sound_at(whichsound, position[i], 128*findLengthfast(&bounceness)); } } start=oldtippoint[i]; @@ -515,22 +440,10 @@ void Weapons::DoStuff(){ tipvelocity[i]+=bounceness*elasticity; if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; - //int whichsound=clank1sound+abs(Random()%4); int whichsound; if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); - if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x; - gLoc[0]=position[i].x; - gLoc[1]=position[i].y; - gLoc[2]=position[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); + emit_sound_at(whichsound, position[i], 128*findLengthfast(&bounceness)); } } @@ -558,21 +471,10 @@ void Weapons::DoStuff(){ velocity[i]+=bounceness*elasticity; if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; - //int whichsound=clank1sound+abs(Random()%4); int whichsound; if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); - if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x; - gLoc[1]=mid.y; - gLoc[2]=mid.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); + emit_sound_at(whichsound, mid, 128*findLengthfast(&bounceness)); } position[i]+=(mid-oldmid2)*(20/(1+(float)m*10)); } @@ -599,21 +501,10 @@ void Weapons::DoStuff(){ tipvelocity[i]+=bounceness*elasticity; if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; - //int whichsound=clank1sound+abs(Random()%4); int whichsound; if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); - if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x; - gLoc[1]=mid.y; - gLoc[2]=mid.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); + emit_sound_at(whichsound, mid, 128*findLengthfast(&bounceness)); } tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10)); } @@ -682,25 +573,17 @@ void Weapons::DoStuff(){ else velocity[i]+=bounceness*elasticity; //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z); if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; int whichsound; if(terrain.getOpacity(position[i].x,position[i].z)>.2){ if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); } else whichsound=footstepsound+abs(Random()%2); - gLoc[0]=position[i].x; - gLoc[1]=position[i].y; - gLoc[2]=position[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + emit_sound_at(whichsound, position[i], + findLengthfast(&bounceness) + * (terrain.getOpacity(position[i].x,position[i].z) > .2 + ? 128. + : 32.)); if(terrain.getOpacity(position[i].x,position[i].z)<.2){ XYZ terrainlight; @@ -736,25 +619,17 @@ void Weapons::DoStuff(){ //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z); if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; int whichsound; if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){ if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); } else whichsound=footstepsound+abs(Random()%2); - gLoc[0]=tippoint[i].x; - gLoc[1]=tippoint[i].y; - gLoc[2]=tippoint[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + emit_sound_at(whichsound, tippoint[i], + findLengthfast(&bounceness) + * (terrain.getOpacity(tippoint[i].x,tippoint[i].z) > .2 + ? 128. + : 32.)); if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){ XYZ terrainlight; @@ -794,25 +669,17 @@ void Weapons::DoStuff(){ else velocity[i]+=bounceness*elasticity; if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; int whichsound; if(terrain.getOpacity(mid.x,mid.z)>.2){ if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); } else whichsound=footstepsound+abs(Random()%2); - gLoc[0]=mid.x; - gLoc[1]=mid.y; - gLoc[2]=mid.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + emit_sound_at(whichsound, mid, + findLengthfast(&bounceness) + * (terrain.getOpacity(position[i].x,position[i].z) > .2 + ? 128. + : 32.)); } position[i]+=(mid-oldmid)*20; } @@ -838,184 +705,20 @@ void Weapons::DoStuff(){ else tipvelocity[i]+=bounceness*elasticity; if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; int whichsound; if(terrain.getOpacity(mid.x,mid.z)>.2){ if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); } else whichsound=footstepsound+abs(Random()%2); - gLoc[0]=mid.x; - gLoc[1]=mid.y; - gLoc[2]=mid.z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); + emit_sound_at(whichsound, mid, + findLengthfast(&bounceness) + * (terrain.getOpacity(position[i].x,position[i].z) > .2 + ? 128. + : 32.)); } tippoint[i]+=(mid-oldmid)*20; } - /*XYZ mid; - mid=position[i]+tippoint[i]; - mid/=2; - if(position[i].y0)velocity[i]*=1-friction*frictionness; - else velocity[i]=0; - if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3; - else velocity[i]+=bounceness*elasticity; - - if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; - int whichsound; - if(terrain.getOpacity(mid.x,mid.z)>.2){ - if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); - if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); - } - else whichsound=footstepsound+abs(Random()%2); - gLoc[0]=position[i].x; - gLoc[1]=position[i].y; - gLoc[2]=position[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); - } - } - - if(tippoint[i].y0)tipvelocity[i]*=1-friction*frictionness; - else tipvelocity[i]=0; - if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3; - else tipvelocity[i]+=bounceness*elasticity; - - if(findLengthfast(&bounceness)>1){ - float gLoc[3]; - float vel[3]; - int whichsound; - if(terrain.getOpacity(mid.x,mid.z)>.2){ - if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2); - if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4); - } - else whichsound=footstepsound+abs(Random()%2); - gLoc[0]=tippoint[i].x; - gLoc[1]=tippoint[i].y; - gLoc[2]=tippoint[i].z; - vel[0]=0; - vel[1]=0; - vel[2]=0; - PlaySoundEx( whichsound, samp[whichsound], NULL, true); - OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel); - if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness)); - else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness)); - OPENAL_SetPaused(channels[whichsound], false); - } - }*/ - - //Fix terrain edge collision - /*start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - if(whichhit!=-1){ - XYZ tippoi,posit; - tippoi=tippoint[i]; - posit=position[i]; - - - while(whichhit!=-1){ - position[i].y+=.1; - tippoint[i].y+=.1; - velocity[i].y+=.1; - tipvelocity[i].y+=.1; - start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - if(whichhit!=-1) - closestpoint=colpoint*terrain.scale; - } - position[i].y-=.1; - tippoint[i].y-=.1; - velocity[i].y-=.1; - tipvelocity[i].y-=.1; - start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - while(whichhit!=-1){ - position[i].y+=.01; - tippoint[i].y+=.01; - velocity[i].y+=.01; - tipvelocity[i].y+=.01; - start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - if(whichhit!=-1) - closestpoint=colpoint*terrain.scale; - } - }*/ - /*if(whichhit!=-1){ - whichhit=terrain.lineTerrain(end,start,&closestswordpoint); - if(whichhit!=-1){ - colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2; - proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]); - if(proportion<=1){ - while(whichhit!=-1){ - position[i].y+=.1*proportion; - tippoint[i].y+=.1*(1-proportion); - velocity[i].y+=.1*proportion; - tipvelocity[i].y+=.1*(1-proportion); - start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - } - position[i].y-=.1*proportion; - tippoint[i].y-=.1*(1-proportion); - velocity[i].y-=.1*proportion; - tipvelocity[i].y-=.1*(1-proportion); - start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - while(whichhit!=-1){ - position[i].y+=.01*proportion; - tippoint[i].y+=.01*(1-proportion); - velocity[i].y+=.01*proportion; - tipvelocity[i].y+=.01*(1-proportion); - start=position[i]; - end=tippoint[i]; - whichhit=terrain.lineTerrain(start,end,&colpoint); - } - } - } - } - */ //Gravity velocity[i].y+=gravity*multiplier; tipvelocity[i].y+=gravity*multiplier;