summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/GameTick.cpp151
-rw-r--r--src/Skeleton.cpp2
2 files changed, 58 insertions, 95 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 7f25e1b..0176144 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -1634,86 +1634,66 @@ void Game::Tick()
 		}
 	}
 
-	//Grenade
-	if(Button()&&person[0].whichgun==grenade&&person[0].ammo>0&&person[0].reloading<=0&&person[0].attackframe<0&&person[0].targetanimation!=crouchanim){
-		if(person[0].grenphase==0){
-			XYZ soundsource=DoRotation(person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]].position,0,person[0].playerrotation,0)+person[0].playercoords;
-			float gLoc[3];
-			gLoc[0]=soundsource.x/soundscalefactor;
-			gLoc[1]=soundsource.y/soundscalefactor;
-			gLoc[2]=soundsource.z/soundscalefactor;
-			alSourcefv(gSourceID[pinpullsound], AL_POSITION, gLoc);
-			alSourcePlay(gSourceID[pinpullsound]);
-			person[0].grenphase=1;
-		}
+	// Grenade
+	if (Button() && person[0].whichgun == grenade && person[0].ammo > 0
+	    && person[0].reloading <= 0 && person[0].attackframe < 0
+	    && person[0].targetanimation != crouchanim
+	    && person[0].grenphase == 0) {
+		person[0].grenphase = 1;
+		auto soundsrc = (DoRotation(person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]].position, 0, person[0].playerrotation, 0)
+			+ person[0].playercoords - camera.position) / soundscalefactor;
+		float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
+		alSourcefv(gSourceID[pinpullsound], AL_POSITION, gLoc);
+		alSourcePlay(gSourceID[pinpullsound]);
 	}
 
-	if((!Button())&&person[0].whichgun==grenade){
-		if(person[0].grenphase==1){
-			person[0].grenphase=0;
-			person[0].attackframe=0;
-			person[0].attacktarget=0;
-			person[0].killtarget=0;
-		}
+	if (!Button() && person[0].whichgun == grenade
+	    && person[0].grenphase == 1) {
+		person[0].grenphase = 0;
+		person[0].attackframe = 0;
+		person[0].attacktarget = 0;
+		person[0].killtarget = 0;
 	}
 
-	if(person[0].targetanimation==crouchanim){
-		if(person[0].grenphase==1){
-			person[0].grenphase=0;
-			XYZ soundsource=DoRotation(person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]].position,0,person[0].playerrotation,0)+person[0].playercoords;
-			float gLoc[3];
-			gLoc[0]=soundsource.x/soundscalefactor;
-			gLoc[1]=soundsource.y/soundscalefactor;
-			gLoc[2]=soundsource.z/soundscalefactor;
-			alSourcefv(gSourceID[pinreplacesound], AL_POSITION, gLoc);
-			alSourcePlay(gSourceID[pinreplacesound]);
-		}
+	if (person[0].targetanimation == crouchanim
+	    && person[0].grenphase == 1) {
+		person[0].grenphase = 0;
+		auto soundsrc = (DoRotation(person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]].position, 0, person[0].playerrotation, 0)
+			+ person[0].playercoords - camera.position) / soundscalefactor;
+		float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
+		alSourcefv(gSourceID[pinreplacesound], AL_POSITION, gLoc);
+		alSourcePlay(gSourceID[pinreplacesound]);
 	}
 
-	//Get gun
-	int temp;
-	int temp2;
-	bool switched=0;
-	if(Button()&&!oldbutton&&(person[0].aiming==0||person[0].whichgun==grenade||person[0].whichgun==nogun||person[0].whichgun==knife)&&person[0].currentanimation==crouchanim){
-
-		for(int i=0;i<max_people;i++){
-
-			if(!switched&&person[i].skeleton.free==1&&findDistancefast(person[0].playercoords,person[i].averageloc)<200){
-
-				float gLoc[3];
-
-				gLoc[0]=person[0].playercoords.x/soundscalefactor;
-
-				gLoc[1]=person[0].playercoords.y/soundscalefactor;
-
-				gLoc[2]=person[0].playercoords.z/soundscalefactor;
-
-				alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc);
-
-				alSourcePlay(gSourceID[clicksound]);
-
-				temp=person[0].whichgun;
-
-				temp2=person[0].ammo;
-
-				person[0].whichgun=person[i].whichgun;
-
-				person[0].ammo=person[i].ammo;
-
-				person[i].whichgun=temp;
-
-				person[i].ammo=temp2;
-
-				person[0].aiming=1;
+	// Get gun
+	if (Button() && !oldbutton && person[0].currentanimation == crouchanim
+	    && (person[0].aiming == 0 || person[0].whichgun == grenade
+	        || person[0].whichgun == knife || person[0].whichgun == nogun)) {
+		bool switched = false;
+		for (int i = 1; i < max_people && !switched; i++) {
+			if (!person[i].skeleton.free
+			    || findDistancefast(person[0].playercoords,
+			                        person[i].averageloc) > 200)
+				continue;
 
-				person[0].aimamount=0;
+			auto soundsrc = (person[0].playercoords
+				- camera.position) / soundscalefactor;
+			float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
+			alSourcefv(gSourceID[clicksound], AL_POSITION, gLoc);
+			alSourcePlay(gSourceID[clicksound]);
 
-				switched=1;
+			auto tmp_gun = person[0].whichgun;
+			person[0].whichgun = person[i].whichgun;
+			person[i].whichgun = tmp_gun;
 
-			}
+			auto tmp_ammo = person[0].ammo;
+			person[0].ammo = person[i].ammo;
+			person[i].ammo = tmp_ammo;
 
+			switched = true;
+			person[0].aiming = 1;
+			person[0].aimamount = 0;
 		}
-
 	}
 
 	//Throw
@@ -1987,7 +1967,7 @@ void Game::Tick()
 	           && person[0].whichgun != knife
 	           && person[0].whichgun != grenade) {
 		auto& coords = person[0].playercoords;
-		float gLoc[3] {
+		float gLoc[] {
 			coords.x / soundscalefactor,
 			coords.y / soundscalefactor,
 			coords.z / soundscalefactor,
@@ -2411,32 +2391,15 @@ void Game::Tick()
 
 					if(person[whichhit].type==zombietype)person[whichhit].maxhealth-=10;
 
-					if(whichhit==0){
-
-						bulletstrength=1;
-
-						person[0].health=100;
-
-						flashr=0;
-
-						flashg=0;
-
-						flashb=0;
-
-						flashamount=1;
-
-						float gLoc[3];
-
-						gLoc[0]=hitstruct.hitlocation.x/soundscalefactor;
-
-						gLoc[1]=hitstruct.hitlocation.y/soundscalefactor;
-
-						gLoc[2]=hitstruct.hitlocation.z/soundscalefactor;
-
+					if (whichhit == 0) {
+						bulletstrength = 1;
+						person[0].health = 100;
+						flashamount = 1;
+						flashr = flashg = flashb = 0;
+						auto soundsrc = (hitstruct.hitlocation - camera.position) / soundscalefactor;
+						float gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
 						alSourcefv(gSourceID[bodywhacksound], AL_POSITION, gLoc);
-
 						alSourcePlay(gSourceID[bodywhacksound]);
-
 					}
 
 					person[whichhit].longdead=1;
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp
index 363fbcc..2156ed5 100644
--- a/src/Skeleton.cpp
+++ b/src/Skeleton.cpp
@@ -181,7 +181,7 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation)
 					alSourcef(gSourceID[landsound],
 						AL_MAX_GAIN, gain);
 
-					float gLoc[3] {
+					float gLoc[] {
 						pos.x / soundscalefactor,
 						pos.y / soundscalefactor,
 						pos.z / soundscalefactor,