summary refs log tree commit diff
path: root/src/GameTick.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r--src/GameTick.cpp154
1 files changed, 57 insertions, 97 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 57b2efe..3088ae5 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -23,6 +23,7 @@
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
 #include "Game.h"
+#include "misc.h"
 
 extern float multiplier;
 extern int thirdperson;
@@ -1499,17 +1500,11 @@ void Game::Tick()
 											person[i].attacktarget=0;
 											person[i].attackframe=0;
 
-											auto stabpos = person[i].playercoords + flatfacing - camera.position;
-											ALfloat gLoc[] {
-												stabpos.x / 2 / soundscalefactor,
-												stabpos.y / 2 / soundscalefactor,
-												stabpos.z / 2 / soundscalefactor,
-											};
-
 											if(person[person[i].killtarget].type!=zombietype)
 											{
-												alSourcefv(gSourceID[knifeslashsound], AL_POSITION, gLoc);
-												alSourcePlay(gSourceID[knifeslashsound]);
+												auto stabpos = person[i].playercoords + flatfacing - camera.position;
+												playSound(gSourceID[knifeslashsound],
+													stabpos.x, stabpos.y, stabpos.z);
 												person[person[i].killtarget].bjoint1=&person[person[i].killtarget].skeleton.joints[person[person[i].killtarget].skeleton.jointlabels[neck]];
 												person[person[i].killtarget].bjoint2=&person[person[i].killtarget].skeleton.joints[person[person[i].killtarget].skeleton.jointlabels[neck]];
 												person[person[i].killtarget].bleeding=1;
@@ -1660,19 +1655,13 @@ void Game::Tick()
 		if(person[person[0].killtarget].skeleton.free<1&&person[0].killtarget!=0&&(person[0].aiming<1||person[0].whichgun==nogun||person[0].whichgun==knife||person[0].targetanimation==joganim)){
 			auto soundpos = person[0].playercoords + flatfacing
 				- camera.position;
-			float gLoc[] {
-				soundpos.x / 2 / soundscalefactor,
-				soundpos.y / 2 / soundscalefactor,
-				soundpos.z / 2 / soundscalefactor,
-			};
-
 			if (person[person[0].killtarget].type != zombietype) {
 				if (person[0].whichgun != knife) {
-					alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc);
-					alSourcePlay(gSourceID[headwhacksound]);
+					playSound(gSourceID[headwhacksound],
+						soundpos.x, soundpos.y, soundpos.z);
 				} else {
-					alSourcefv(gSourceID[knifeslashsound], AL_POSITION, gLoc);
-					alSourcePlay(gSourceID[knifeslashsound]);
+					playSound(gSourceID[knifeslashsound],
+						soundpos.x, soundpos.y, soundpos.z);
 
 					person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]];
 					person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]];
@@ -1709,55 +1698,53 @@ void Game::Tick()
 					person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=DoRotation(flatfacing,0,40,0)*50;
 					person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=person[0].velocity*2;
 				}
-			} else {
-				if(whacked==0){
-					whacked=1;
-					if (person[0].whichgun!=knife) {
-						alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc);
-						alSourcePlay(gSourceID[headwhacksound]);
-					} else {
-						alSourcefv(gSourceID[knifeslashsound], AL_POSITION, gLoc);
-						alSourcePlay(gSourceID[knifeslashsound]);
+			} else if (!whacked) {
+				whacked = true;
+				if (person[0].whichgun != knife) {
+					playSound(gSourceID[headwhacksound],
+						soundpos.x, soundpos.y, soundpos.z);
+				} else {
+					playSound(gSourceID[knifeslashsound],
+						soundpos.x, soundpos.y, soundpos.z);
 
-						person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]];
-						person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]];
+					person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]];
+					person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]];
 
-						person[person[0].killtarget].bleeddelay=1;
+					person[person[0].killtarget].bleeddelay=1;
 
-						person[0].bjoint1=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]];
-						person[0].bjoint2=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]];
+					person[0].bjoint1=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]];
+					person[0].bjoint2=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]];
 
-						person[0].bleeding=1;
-						person[0].bleeddelay=1;
+					person[0].bleeding=1;
+					person[0].bleeddelay=1;
 
-						velocity=DoRotation(flatfacing,0,70,0)*50+person[0].velocity*2;
-						velocity.y+=30;
+					velocity=DoRotation(flatfacing,0,70,0)*50+person[0].velocity*2;
+					velocity.y+=30;
 
-						sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.3, 2);
-						sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.2, 3);
-						sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.1, 4);
-					}
+					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.3, 2);
+					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.2, 3);
+					sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.1, 4);
+				}
 
-					person[person[0].killtarget].health-=200;
-					person[person[0].killtarget].maxhealth-=20;
-					person[person[0].killtarget].skeleton.free=1;
-					person[person[0].killtarget].longdead=1;
+				person[person[0].killtarget].health-=200;
+				person[person[0].killtarget].maxhealth-=20;
+				person[person[0].killtarget].skeleton.free=1;
+				person[person[0].killtarget].longdead=1;
 
-					for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){
-						person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0);
-						person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords;
-						person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position;
-						person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity;
+				for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){
+					person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0);
+					person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords;
+					person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position;
+					person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity;
 
-						person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5;
-						person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5;
-						person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5;
-					}
+					person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5;
+					person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5;
+					person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5;
+				}
 
-					if(person[0].whichgun!=knife){
-						person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=DoRotation(flatfacing,0,40,0)*50;
-						person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=person[0].velocity*2;
-					}
+				if(person[0].whichgun!=knife){
+					person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=DoRotation(flatfacing,0,40,0)*50;
+					person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=person[0].velocity*2;
 				}
 			}
 		}
@@ -1799,13 +1786,9 @@ void Game::Tick()
 
 	// Empty magazine
 	if (person[0].firing && person[0].ammo <= 0) {
-		float gLoc[] {
-			person[0].playercoords.x / soundscalefactor,
-			person[0].playercoords.y / soundscalefactor,
-			person[0].playercoords.z / soundscalefactor,
-		};
-		alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc);
-		alSourcePlay(gSourceID[clicksound]);
+		auto soundpos = person[0].playercoords - camera.position;
+		playSound(gSourceID[clicksound],
+			soundpos.x, soundpos.y, soundpos.z);
 		person[0].firing = false;
 	}
 
@@ -1941,12 +1924,6 @@ void Game::Tick()
 				camera.rotation -= rot;
 				camera.rotation2 -= rot2;
 
-				auto soundpos = start - camera.position;
-				ALfloat gLoc[] {
-					soundpos.x / 4 / soundscalefactor,
-					soundpos.y / 4 / soundscalefactor,
-					soundpos.z / 4 / soundscalefactor,
-				};
 				ALuint gunsound;
 				switch (person[j].whichgun) {
 				case sniperrifle:
@@ -1964,8 +1941,9 @@ void Game::Tick()
 				default: // assaultrifle
 					gunsound = gSourceID[machinegunsound];
 				}
-				alSourcefv(gunsound, AL_POSITION, gLoc);
-				alSourcePlay(gunsound);
+				auto soundpos = start - camera.position;
+				playSound(gunsound, soundpos.x,
+					soundpos.y, soundpos.z);
 			}
 
 			XYZ end {start + aim * 1000};
@@ -2098,9 +2076,6 @@ void Game::Tick()
 				if(m==0){
 
 					if(j==0&&slomo==2){
-
-						soundscalefactor=soundscalefactordefault;
-
 						alSourceStop(gSourceID[whichsong]);
 
 						alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0);
@@ -2428,17 +2403,10 @@ void Game::Tick()
 						: gSourceID[bodyhitsound];
 					auto hitpos = hitstruct.hitlocation
 						- camera.position;
-					ALfloat gLoc[] {
-						hitpos.x / soundscalefactor / 4,
-						hitpos.y / soundscalefactor / 4,
-						hitpos.z / soundscalefactor / 4,
-					};
-					ALfloat gain = thirdperson ? 0.1f : 1.0f;
-					alSourcef(hitsound, AL_MIN_GAIN, gain);
-					alSourcefv(hitsound, AL_POSITION, gLoc);
-					alSourcePlay(hitsound);
-				}//with wall
+					playSound(hitsound, hitpos.x, hitpos.y, hitpos.z);
+				}
 
+				// with wall
 				if(oldend==finalwallhit){
 
 					decals.MakeDecal(bullethole, finalwallhit,.7,hitnorm, hitpoly, model, hitmove, hitrotation);
@@ -2489,16 +2457,9 @@ void Game::Tick()
 
 					}
 
-					auto wallhitpos = finalwallhit
-						- camera.position;
-					ALfloat gLoc[] {
-						wallhitpos.x / soundscalefactor,
-						wallhitpos.y / soundscalefactor,
-						wallhitpos.z / soundscalefactor,
-					};
-					alSourcefv(gSourceID[wallhitsound],
-						AL_POSITION, gLoc);
-					alSourcePlay(gSourceID[wallhitsound]);
+					auto soundpos = finalwallhit - camera.position;
+					playSound(gSourceID[wallhitsound],
+						soundpos.x, soundpos.y, soundpos.z);
 				}
 
 				lastshot[0]=start;
@@ -3241,7 +3202,6 @@ void Game::Tick()
 	if(slomo==2){
 		psychicpower-=multiplier*15;
 		if(psychicpower<0){
-			soundscalefactor=soundscalefactordefault;
 			alSourceStop(gSourceID[whichsong]);
 			alSourcef(gSourceID[whichsong], AL_MIN_GAIN, 0);
 			alSourcef(gSourceID[whichsong], AL_MAX_GAIN, 0);